[PATCH] mysql host,user,password configurtion for DLR

"Oded Arbel" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi list.

A quick patch to add support for changing the mysql database hostname,
username and password for use in DLR (with mysql). 
Tested with defaults (hardcoded in the source) and settings in the
config file both for local and remote servers.

As usuall, "Works for me(tm)" and YMMV.

Oded Arbel
m-Wise Inc.
[email protected]

--
Finagle's Fourth Law:
        Once a job is fouled up, anything done to improve it only makes
it worse.
mysql-dlr.patch (application/octet-stream, 2.5 KB)
--- gw/bearerbox.c	Fri Feb  1 00:16:25 2002
+++ gw/bearerbox.c	Tue Mar  5 15:20:34 2002
@@ -451,7 +451,6 @@
     bb_status = BB_RUNNING;
     
     gwlib_init();
-    dlr_init();
     start_time = time(NULL);
 
     suspended = list_create();
@@ -470,6 +469,8 @@
     if (cfg_read(cfg) == -1)
         panic(0, "No configuration or bad configuration, aborting.");
 
+    dlr_init(cfg);
+    
     report_versions("bearerbox");
 
     flow_threads = list_create();
--- gw/dlr.c	Fri Jan  4 14:18:32 2002
+++ gw/dlr.c	Tue Mar  5 15:30:44 2002
@@ -92,15 +92,40 @@
 
 /* at startup initialize the list */
 
-void	dlr_init()
+void	dlr_init(Cfg* cfg)
 {
+#if (MYSQL_DLR)
+    CfgGroup *grp;
+    Octstr *mysql_host, *mysql_user, *mysql_pass;
+#endif
     dlr_mutex = mutex_create();
 
 #if (MYSQL_DLR)
+// read configuration from 
+    grp = cfg_get_single_group(cfg, octstr_imm("core"));
+    mysql_host = cfg_get(grp, octstr_imm("mysql-host"));
+    mysql_user = cfg_get(grp, octstr_imm("mysql-username"));
+    mysql_pass = cfg_get(grp, octstr_imm("mysql-password"));
+    
+// verify validity and use defaults 
+    if (!mysql_host)
+        mysql_host = octstr_create(DB_HOST);
+    
+    if (!mysql_user)
+        mysql_user = octstr_create(DB_USER);
+    
+    if (!mysql_pass)
+        mysql_pass = octstr_create(DB_PASSWORD);
+    
    mysql_init(&mysql);
-   connection = mysql_real_connect(&mysql, DB_HOST,DB_USER,DB_PASSWORD,DB_NAME,DB_PORT,DB_SOCKET,DB_CLIENTFLAG);
+   connection = mysql_real_connect(&mysql, 
+   	octstr_get_cstr(mysql_host), octstr_get_cstr(mysql_user), octstr_get_cstr(mysql_pass),
+   	DB_NAME,DB_PORT,DB_SOCKET,DB_CLIENTFLAG);
    if(connection == NULL)
    	error(0,"can not connect to MySQL database for DLR ! Error = %s",mysql_error(&mysql));
+   octstr_destroy(mysql_host);
+   octstr_destroy(mysql_user);
+   octstr_destroy(mysql_pass);
 #else
     dlr_waiting_list = list_create();
 #endif
--- gw/dlr.h	Thu Oct 11 19:18:33 2001
+++ gw/dlr.h	Tue Mar  5 15:20:56 2002
@@ -18,7 +18,7 @@
 #define	DLR_SMSC_SUCCESS	0x08
 #define	DLR_SMSC_FAIL		0x10
 
-void	dlr_init();
+void	dlr_init(Cfg* cfg);
 void	dlr_shutdown();
 
 void	dlr_add(char *smsc, char *ts, char *dst, char *keyword, char *id, int mask);
--- gwlib/cfg.def	Tue Mar  5 14:13:50 2002
+++ gwlib/cfg.def	Tue Mar  5 15:31:30 2002
@@ -50,6 +50,9 @@
     OCTSTR(ssl-server-cert-file)
     OCTSTR(ssl-server-key-file)
     OCTSTR(ssl-trusted-ca-file)
+    OCTSTR(mysql-host)
+    OCTSTR(mysql-username)
+    OCTSTR(mysql-password)
 )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.