[Asterisk-Dev] cdr_mysql and MySQL socket

Tamas Jalsovszky thomasj at eworld.hu
Mon Aug 4 12:26:10 MST 2003


Monday, August 4, 2003, 8:41:17 PM, John wrote:

JT> Please submit this through the bugs.digium.com interface to ensure 
JT> that the changes are made to the CVS tree.  Please read and submit a 
JT> disclaimer so that your code can be added to the repository 
JT> (instructions are on the main page of bugs.digium.com)

Disclaimer sent (Tamas Jalsovszky) through fax and patch reported to
bugs.digium.com (0000049).

JT> Thanks!  This looks like a very useful patch, and I want to make sure 
JT> it finds it's way into the tree.

JT> JT
Thanks,
        Thomas


>>Hello,
>>
>>         I found, that cdr_mysql connects to database through TCP
>>socket and doesn't allow to connect to Unix socket (in case mysql is
>>running on the same box as asterisk).
>>         If both (hostname and socket) options are set, cdr_mysql will
>>connect through hostname (according to mysql API:
>>http://www.mysql.com/doc/en/mysql_real_connect.html)
>>
>>         I include a patch which adds unix socket functionality.
>>
>>         Regards,
>>                 Thomas
>>
>>--- configs/cdr_mysql.conf.sample.orig  Mon Aug  4 15:46:21 2003
>>+++ configs/cdr_mysql.conf.sample       Mon Aug  4 15:34:04 2003
>>@@ -3,3 +3,4 @@
>>  ;dbname=asteriskcdrdb
>>  ;password=password
>>  ;user=asteriskcdruser
>>+;socket=/var/run/mysqld/mysqld.sock
>>
>>
>>--- cdr/cdr_mysql.c.orig        Thu Jul 24 19:45:32 2003
>>+++ cdr/cdr_mysql.c     Mon Aug  4 15:32:21 2003
>>@@ -94,7 +94,7 @@
>>    struct ast_config *cfg;
>>    struct ast_variable *var;
>>
>>-  char *hostname, *dbname, *dbuser, *password;
>>+  char *hostname, *dbname, *dbuser, *password, *unix_socket;
>>
>>    cfg = ast_load(config);
>>    if (!cfg) {
>>@@ -112,15 +112,16 @@
>>    dbname = ast_variable_retrieve(cfg,"global","dbname");
>>    dbuser = ast_variable_retrieve(cfg,"global","user");
>>    password = ast_variable_retrieve(cfg,"global","password");
>>+  unix_socket = ast_variable_retrieve(cfg,"global","socket");
>>    ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got user of %s\n",dbuser);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);
>>+  ast_log(LOG_DEBUG,"cdr_mysql: got unix_socket of %s\n",unix_socket);
>>
>>    if (hostname == NULL)
>>      {
>>-      ast_log(LOG_ERROR,"Database server hostname not specified.\n");
>>-      return -1;
>>+      ast_log(LOG_DEBUG,"Database server hostname not specified.\n");
>>      }
>>    if (dbuser == NULL)
>>      {
>>@@ -137,11 +138,19 @@
>>        ast_log(LOG_ERROR,"Database password not specified.\n");
>>        return -1;
>>      }
>>-
>>+  if (unix_socket == NULL)
>>+    {
>>+      ast_log(LOG_DEBUG,"Database unix_socket not specified.\n");
>>+    }
>>+  if (unix_socket == NULL && hostname == NULL)
>>+    {
>>+      ast_log(LOG_ERROR,"Database hostname and unix_socket not 
>>specified.\n");
>>+      return -1;
>>+    }
>>
>>    mysql = mysql_init(NULL);
>>
>>-  mysql = mysql_real_connect(mysql, hostname, dbuser, password, 
>>dbname, 0, NULL, 0);
>>+  mysql = mysql_real_connect(mysql, hostname, dbuser, password, 
>>dbname, 0, unix_socket, 0);
>>
>>    if (mysql == NULL) {
>>      ast_log(LOG_ERROR, "Failed to connect to mysql database.\n");
>>@@ -164,7 +173,7 @@
>>    struct ast_config *cfg;
>>    struct ast_variable *var;
>>
>>-  char *hostname, *dbname, *password, *dbuser;
>>+  char *hostname, *dbname, *password, *dbuser, *unix_socket;
>>
>>    mysql_close(mysql);
>>
>>@@ -185,15 +194,16 @@
>>    dbname = ast_variable_retrieve(cfg,"global","dbname");
>>    dbuser = ast_variable_retrieve(cfg,"global","user");
>>    password = ast_variable_retrieve(cfg,"global","password");
>>+  unix_socket = ast_variable_retrieve(cfg,"global","socket");
>>    ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got dbuser of %s\n",dbuser);
>>    ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);
>>+  ast_log(LOG_DEBUG,"cdr_mysql: got unix_socket of %s\n",unix_socket);
>>
>>    if (hostname == NULL)
>>      {
>>-      ast_log(LOG_ERROR,"Database server hostname not specified.\n");
>>-      return -1;
>>+      ast_log(LOG_DEBUG,"Database server hostname not specified.\n");
>>      }
>>    if (dbname == NULL)
>>      {
>>@@ -205,16 +215,24 @@
>>        ast_log(LOG_ERROR,"Database dbuser not specified.\n");
>>        return -1;
>>      }
>>-
>>    if (password == NULL)
>>      {
>>        ast_log(LOG_ERROR,"Database password not specified.\n");
>>        return -1;
>>      }
>>+  if (unix_socket == NULL)
>>+    {
>>+      ast_log(LOG_DEBUG,"Database unix_socket not specified.\n");
>>+    }
>>+  if (unix_socket == NULL && hostname == NULL)
>>+    {
>>+      ast_log(LOG_ERROR,"Database hostname and unix_socket not 
>>specified.\n");
>>+      return -1;
>>+    }
>>
>>   mysql = mysql_init(NULL);
>>
>>- mysql = mysql_real_connect(mysql, hostname, dbuser, password, 
>>dbname, 0, NULL, 0);
>>+ mysql = mysql_real_connect(mysql, hostname, dbuser, password, 
>>dbname, 0, unix_socket, 0);
>>
>>   if (mysql == NULL) {
>>     ast_log(LOG_ERROR, "Failed to connect to mysql database.\n");
>>
>>_______________________________________________
>>Asterisk-Dev mailing list
>>Asterisk-Dev at lists.digium.com
>>http://lists.digium.com/mailman/listinfo/asterisk-dev




More information about the asterisk-dev mailing list