[asterisk-addons-commits] russell: trunk r393 - in /trunk: cdr_addon_mysql.c configs/cdr_mysql.conf.sample

asterisk-addons-commits at lists.digium.com asterisk-addons-commits at lists.digium.com
Fri Jun 8 14:21:44 MST 2007


Author: russell
Date: Fri Jun  8 16:21:44 2007
New Revision: 393

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=393
Log:
Make logging the uniqueid field configurable as opposed to a compile time option.
(issue #9320, initial patch from ecaron, updated by me)

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=393&r1=392&r2=393
==============================================================================
--- trunk/cdr_addon_mysql.c (original)
+++ trunk/cdr_addon_mysql.c Fri Jun  8 16:21:44 2007
@@ -65,6 +65,7 @@
 static int totalrecords = 0;
 static int userfield = 0;
 static unsigned int timeout = 0;
+static unsigned int loguniqueid = 0;
 
 AST_MUTEX_DEFINE_STATIC(mysql_lock);
 
@@ -133,9 +134,7 @@
 	char sqlcmd[2048], timestr[128];
 	char *clid=NULL, *dcontext=NULL, *channel=NULL, *dstchannel=NULL, *lastapp=NULL, *lastdata=NULL, *tmp;
 	int retries = 5;
-#ifdef MYSQL_LOGUNIQUEID
 	char *uniqueid = NULL;
-#endif
 
 	ast_mutex_lock(&mysql_lock);
 
@@ -202,19 +201,13 @@
 		mysql_escape_string(lastapp, cdr->lastapp, strlen(cdr->lastapp));
 	if ((lastdata = alloca(strlen(cdr->lastdata) * 2 + 1)) != NULL)
 		mysql_escape_string(lastdata, cdr->lastdata, strlen(cdr->lastdata));
-#ifdef MYSQL_LOGUNIQUEID
-	if ((uniqueid = alloca(strlen(cdr->uniqueid) * 2 + 1)) != NULL)
+	if (loguniqueid && (uniqueid = alloca(strlen(cdr->uniqueid) * 2 + 1)) != NULL)
 		mysql_escape_string(uniqueid, cdr->uniqueid, strlen(cdr->uniqueid));
-#endif
 	if (userfield && ((userfielddata = alloca(strlen(cdr->userfield) * 2 + 1)) != NULL))
 		mysql_escape_string(userfielddata, cdr->userfield, strlen(cdr->userfield));
 
 	/* Check for all alloca failures above at once */
-#ifdef MYSQL_LOGUNIQUEID
-	if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!uniqueid)) {
-#else
-	if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata)) {
-#endif
+	if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!uniqueid) || (loguniqueid && !uniqueid)) {
 		ast_log(LOG_ERROR, "cdr_mysql:  Out of memory error (insert fails)\n");
 		ast_mutex_unlock(&mysql_lock);
 		return -1;
@@ -223,17 +216,15 @@
 	ast_log(LOG_DEBUG, "cdr_mysql: inserting a CDR record.\n");
 
 	if (userfield && userfielddata) {
-#ifdef MYSQL_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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->accountcode, userfielddata);
-#endif
+		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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext, channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->accountcode, userfielddata);
 	} else {
-#ifdef MYSQL_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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->accountcode);
-#endif
+		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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->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',%i,%i,'%s',%i,'%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, cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), cdr->amaflags, cdr->accountcode);
 	}
 	
 	ast_log(LOG_DEBUG, "cdr_mysql: SQL command as follows: %s\n", sqlcmd);
@@ -315,6 +306,17 @@
 	return 0;
 }
 
+static int my_load_config_bool(struct ast_config *cfg, const char *category, const char *variable, int *field, int def)
+{
+	const char *tmp;
+
+	tmp = ast_variable_retrieve(cfg, category, variable);
+
+	*field = tmp ? ast_true(tmp) : def;
+
+	return 0;
+}
+
 static int my_load_module(void)
 {
 	int res;
@@ -347,6 +349,8 @@
 	res |= my_load_config_number(cfg, "global", "port", &dbport, 0);
 	res |= my_load_config_number(cfg, "global", "timeout", &timeout, 0);
 	res |= my_load_config_number(cfg, "global", "userfield", &userfield, 0);
+
+	res |= my_load_config_bool(cfg, "global", "loguniqueid", &loguniqueid, 0);
 
 	res |= my_load_config_string(cfg, "global", "calldate_field", &calldate_field, "calldate");
 	res |= my_load_config_string(cfg, "global", "clid_field", &clid_field, "clid");	
@@ -364,10 +368,7 @@
 	res |= my_load_config_string(cfg, "global", "amaflags_field", &amaflags_field, "amaflags");
 	res |= my_load_config_string(cfg, "global", "accountcode_field", &accountcode_field, "accountcode");
 	res |= my_load_config_string(cfg, "global", "userfield_field", &userfield_field, "userfield");
-	
-#ifdef MYSQL_LOGUNIQUEID
 	res += my_load_config_string(cfg, "global", "uniqueid_field", &uniqueid_field, "uniqueid");
-#endif
 
 	if (res < 0)
 		return AST_MODULE_LOAD_FAILURE;
@@ -397,10 +398,7 @@
 	ast_log(LOG_DEBUG, "cdr_mysql: got amaflags field of %s\n", amaflags_field->str);
 	ast_log(LOG_DEBUG, "cdr_mysql: got accountcode field of %s\n", accountcode_field->str);
 	ast_log(LOG_DEBUG, "cdr_mysql: got userfield field of %s\n", userfield_field->str);
-
-#ifdef MYSQL_LOGUNIQUEID
 	ast_log(LOG_DEBUG, "cdr_mysql: got uniqueid field of %s\n", uniqueid_field->str);
-#endif
 
 	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=393&r1=392&r2=393
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Fri Jun  8 16:21:44 2007
@@ -20,6 +20,7 @@
 ;sock=/tmp/mysql.sock
 ;userfield=1
 ;
+;loguniqueid=no  ; Set to "yes" to enable logging the channel uniqueid
 ;
 ; You may also configure the field names used in the CDR table.
 ;



More information about the asterisk-addons-commits mailing list