Summary: | ASTERISK-00045: cdr_mysql and MySQL socket | ||
Reporter: | jalsot (jalsot) | Labels: | |
Date Opened: | 2003-08-04 14:38:04 | Date Closed: | 2008-01-15 14:31:56.000-0600 |
Priority: | Major | Regression? | No |
Status: | Closed/Complete | Components: | Core/General |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) cdr_mysql_socket.patch ( 1) cdr_mysql_socket.patch2 | |
Description: | This patch allows to cdr_mysql module to connect to a MySQL server through MySQL UN*X socket (if the MySQL runs on the same box as Asterisk). This provides better performance while the connection is not TCP/IP but simple socket. The patch introduces a new configuration parameter called 'socket' to cdr_mysql module. 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) ****** ADDITIONAL INFORMATION ****** Patches: --- 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"); | ||
Comments: | By: jalsot (jalsot) 2003-08-06 02:48:37 Disclaimer sent by fax on 2003-08-04 21:13:37 CET (name: Tamas Jalsovszky) By: Tilghman Lesher (tilghman) 2003-08-10 15:43:51 Note that according to the MySQL API documentation, if the hostname is set to "localhost", then cdr_mysql will attempt to connect via the Unix socket interface. This may need to be notated in the cdr_mysql.conf.sample file, but the socket interface is already functional this way. By: jalsot (jalsot) 2003-08-11 16:22:29 You are right! It should be notated. I have a box where 2 mysql databases are running. I can't say which database to chose, so I expanded cdr_mysql with functionality of chosing the right socket. This patch is probably not functional with new cdr_mysql.c file. I will submit a new patch soon. By: x martinp (martinp) 2003-08-12 22:09:52 waiting for it By: jalsot (jalsot) 2003-08-13 03:19:09 I uploaded a new patch for mysql socket (cdr_mysql_socket.patch2) I found also a bug in the current cdr_mysql.c code. e.g: tmp = ast_variable_retrieve(cfg,"global","hostname"); hostname = malloc(strlen(tmp) + 1); if ((tmp != NULL) && (hostname != NULL)) { strcpy(hostname,tmp); } else if (tmp == NULL) { ast_log(LOG_ERROR,"Database server hostname not specified.\n"); return -1; } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } if the hostname option not found in config file, ast_variable_retrieve returns NULL and I get Segmentation fault (probably strlen(NULL) doesn't work). My patch includes a small fix for that. tmp = ast_variable_retrieve(cfg,"global","hostname"); if (tmp != NULL) { hostname = malloc(strlen(tmp) + 1); if (hostname == NULL) { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } strcpy(hostname,tmp); } else { ast_log(LOG_DEBUG,"Database server hostname not specified.\n"); } Maybe a port option should be also great, shouldn't be? By: Mark Spencer (markster) 2003-08-14 23:40:36 Patch applied from tilghman By: Mark Spencer (markster) 2003-08-16 11:56:23 Resolved by Tilghman patches By: Digium Subversion (svnbot) 2008-01-15 14:31:56.000-0600 Repository: asterisk Revision: 1337 U trunk/cdr/cdr_mysql.c ------------------------------------------------------------------------ r1337 | markster | 2008-01-15 14:31:55 -0600 (Tue, 15 Jan 2008) | 2 lines Special NULL case for mysql (bug ASTERISK-45) ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=1337 |