[asterisk-addons-commits] mmichelson: trunk r495 - in /trunk: ./ configs/
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Wed Dec 12 10:58:29 CST 2007
Author: mmichelson
Date: Wed Dec 12 10:58:29 2007
New Revision: 495
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=495
Log:
A few changes:
1. remove "cdr_mysql:" from console messages since the module name is printed in the message already
2. Improve efficiency by not building queries if not connected to the database
3. Add MySQL error number and text for failure to connect to the database
4. Add a clarification to cdr_mysql.conf.sample to indicate that 127.0.0.1 may be used instead of "localhost"
(closes issue #11513, reported and patched by IgorG)
Modified:
trunk/cdr_addon_mysql.c
trunk/configs/cdr_mysql.conf.sample
Modified: trunk/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr_addon_mysql.c?view=diff&rev=495&r1=494&r2=495
==============================================================================
--- trunk/cdr_addon_mysql.c (original)
+++ trunk/cdr_addon_mysql.c Wed Dec 12 10:58:29 2007
@@ -165,12 +165,12 @@
mysql_init(&mysql);
/* Add option to quickly timeout the connection */
if (timeout && mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&timeout) != 0) {
- ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+ ast_log(LOG_ERROR, "mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
}
#if MYSQL_VERSION_ID >= 50013
/* Add option for automatic reconnection */
if (mysql_options(&mysql, MYSQL_OPT_RECONNECT, &my_bool_true) != 0) {
- ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+ ast_log(LOG_ERROR, "mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
}
#endif
tmp = dbsock ? dbsock->str : NULL;
@@ -182,7 +182,7 @@
connect_time = time(NULL);
records = 0;
} else {
- ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s.\n", hostname->str);
+ ast_log(LOG_ERROR, "Cannot connect to database server %s: (%d) %s\n", hostname->str, mysql_errno(&mysql), mysql_error(&mysql));
connected = 0;
}
} else {
@@ -194,16 +194,16 @@
switch (mysql_errno(&mysql)) {
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
- ast_log(LOG_ERROR, "cdr_mysql: Server has gone away. Attempting to reconnect.\n");
+ ast_log(LOG_ERROR, "Server has gone away. Attempting to reconnect.\n");
break;
default:
- ast_log(LOG_ERROR, "cdr_mysql: Unknown connection error: (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+ ast_log(LOG_ERROR, "Unknown connection error: (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
}
retries--;
if (retries)
goto db_reconnect;
else
- ast_log(LOG_ERROR, "cdr_mysql: Retried to connect fives times, giving up.\n");
+ ast_log(LOG_ERROR, "Retried to connect fives times, giving up.\n");
}
}
@@ -239,30 +239,30 @@
/* Check for all alloca failures above at once */
if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!src) || (!dst) || (!accountcode) || (loguniqueid && !uniqueid) || (userfield && !userfielddata)) {
- ast_log(LOG_ERROR, "cdr_mysql: Out of memory error (insert fails)\n");
+ ast_log(LOG_ERROR, "Out of memory error (insert fails)\n");
ast_mutex_unlock(&mysql_lock);
return -1;
}
-
- ast_debug(1, "cdr_mysql: inserting a CDR record.\n");
-
- if (userfield && userfielddata) {
- if (loguniqueid)
- snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, uniqueid_field->str, userfield_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, uniqueid, userfielddata);
- else
- snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, userfield_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, userfielddata);
- } else {
- if (loguniqueid)
- snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, uniqueid_field->str, timestr, clid, src, dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, uniqueid);
- else
- snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode);
- }
-
- ast_debug(1, "cdr_mysql: SQL command as follows: %s\n", sqlcmd);
if (connected) {
+ ast_debug(1, "Inserting a CDR record.\n");
+
+ if (userfield && userfielddata) {
+ if (loguniqueid)
+ snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, uniqueid_field->str, userfield_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, uniqueid, userfielddata);
+ else
+ snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, userfield_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, userfielddata);
+ } else {
+ if (loguniqueid)
+ snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, uniqueid_field->str, timestr, clid, src, dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode, uniqueid);
+ else
+ snprintf(sqlcmd, sizeof(sqlcmd), "INSERT INTO %s (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s')", dbtable->str, calldate_field->str, clid_field->str, src_field->str, dst_field->str, dcontext_field->str, channel_field->str, dstchannel_field->str, lastapp_field->str, lastdata_field->str, duration_field->str, billsec_field->str, disposition_field->str, amaflags_field->str, accountcode_field->str, timestr, clid, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, accountcode);
+ }
+
+ ast_debug(1, "SQL command as follows: %s\n", sqlcmd);
+
if (mysql_real_query(&mysql, sqlcmd, strlen(sqlcmd))) {
- ast_log(LOG_ERROR, "mysql_cdr: Failed to insert into database: (%d) %s", mysql_errno(&mysql), mysql_error(&mysql));
+ ast_log(LOG_ERROR, "Failed to insert into database: (%d) %s", mysql_errno(&mysql), mysql_error(&mysql));
mysql_close(&mysql);
connected = 0;
} else {
@@ -417,30 +417,30 @@
ast_config_destroy(cfg);
- ast_debug(1, "cdr_mysql: got hostname of %s\n", hostname->str);
- ast_debug(1, "cdr_mysql: got port of %d\n", dbport);
- ast_debug(1, "cdr_mysql: got a timeout of %d\n", timeout);
+ ast_debug(1, "Got hostname of %s\n", hostname->str);
+ ast_debug(1, "Got port of %d\n", dbport);
+ ast_debug(1, "Got a timeout of %d\n", timeout);
if (dbsock)
- ast_debug(1, "cdr_mysql: got sock file of %s\n", dbsock->str);
- ast_debug(1, "cdr_mysql: got user of %s\n", dbuser->str);
- ast_debug(1, "cdr_mysql: got dbname of %s\n", dbname->str);
- ast_debug(1, "cdr_mysql: got password of %s\n", password->str);
-
- ast_debug(1, "cdr_mysql: got calldate field of %s\n", calldate_field->str);
- ast_debug(1, "cdr_mysql: got clid field of %s\n", clid_field->str);
- ast_debug(1, "cdr_mysql: got src field of %s\n", src_field->str);
- ast_debug(1, "cdr_mysql: got dst field of %s\n", dst_field->str);
- ast_debug(1, "cdr_mysql: got dcontext field of %s\n", dcontext_field->str);
- ast_debug(1, "cdr_mysql: got channel field of %s\n", channel_field->str);
- ast_debug(1, "cdr_mysql: got dstchannel field of %s\n", dstchannel_field->str);
- ast_debug(1, "cdr_mysql: got lastapp field of %s\n", lastapp_field->str);
- ast_debug(1, "cdr_mysql: got lastdata field of %s\n", lastdata_field->str);
- ast_debug(1, "cdr_mysql: got duration field of %s\n", duration_field->str);
- ast_debug(1, "cdr_mysql: got billsec field of %s\n", billsec_field->str);
- ast_debug(1, "cdr_mysql: got amaflags field of %s\n", amaflags_field->str);
- ast_debug(1, "cdr_mysql: got accountcode field of %s\n", accountcode_field->str);
- ast_debug(1, "cdr_mysql: got userfield field of %s\n", userfield_field->str);
- ast_debug(1, "cdr_mysql: got uniqueid field of %s\n", uniqueid_field->str);
+ ast_debug(1, "Got sock file of %s\n", dbsock->str);
+ ast_debug(1, "Got user of %s\n", dbuser->str);
+ ast_debug(1, "Got dbname of %s\n", dbname->str);
+ ast_debug(1, "Got password of %s\n", password->str);
+
+ ast_debug(1, "Got calldate field of %s\n", calldate_field->str);
+ ast_debug(1, "Got clid field of %s\n", clid_field->str);
+ ast_debug(1, "Got src field of %s\n", src_field->str);
+ ast_debug(1, "Got dst field of %s\n", dst_field->str);
+ ast_debug(1, "Got dcontext field of %s\n", dcontext_field->str);
+ ast_debug(1, "Got channel field of %s\n", channel_field->str);
+ ast_debug(1, "Got dstchannel field of %s\n", dstchannel_field->str);
+ ast_debug(1, "Got lastapp field of %s\n", lastapp_field->str);
+ ast_debug(1, "Got lastdata field of %s\n", lastdata_field->str);
+ ast_debug(1, "Got duration field of %s\n", duration_field->str);
+ ast_debug(1, "Got billsec field of %s\n", billsec_field->str);
+ ast_debug(1, "Got amaflags field of %s\n", amaflags_field->str);
+ ast_debug(1, "Got accountcode field of %s\n", accountcode_field->str);
+ ast_debug(1, "Got userfield field of %s\n", userfield_field->str);
+ ast_debug(1, "Got uniqueid field of %s\n", uniqueid_field->str);
mysql_init(&mysql);
Modified: trunk/configs/cdr_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/trunk/configs/cdr_mysql.conf.sample?view=diff&rev=495&r1=494&r2=495
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Wed Dec 12 10:58:29 2007
@@ -4,11 +4,11 @@
; setting hostname=localhost
;
; port and sock are both optional parameters. If hostname is specified
-; and is not "localhost", then cdr_mysql will attempt to connect to the
-; port specified or use the default port. If hostname is not specified
-; or if hostname is "localhost", then cdr_mysql will attempt to connect
-; to the socket file specified by sock or otherwise use the default socket
-; file.
+; and is not "localhost" (you can use address 127.0.0.1 instead), then
+; cdr_mysql will attempt to connect to the port specified or use the
+; default port. If hostname is not specified or if hostname is
+; "localhost", then cdr_mysql will attempt to connect to the socket file
+; specified by sock or otherwise use the default socket file.
;
;[global]
;hostname=database.host.name
More information about the asterisk-addons-commits
mailing list