[Asterisk-cvs] asterisk-addons cdr_addon_mysql.c, 1.5, 1.6 res_config_mysql.c, 1.3, 1.4

markster at lists.digium.com markster at lists.digium.com
Thu Jan 20 19:40:23 CST 2005


Update of /usr/cvsroot/asterisk-addons
In directory mongoose.digium.com:/tmp/cvs-serv19101

Modified Files:
	cdr_addon_mysql.c res_config_mysql.c 
Log Message:
Misc MySQL CDR/config updates (bug #3388 et al)


Index: cdr_addon_mysql.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/cdr_addon_mysql.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cdr_addon_mysql.c	9 Jul 2004 16:24:28 -0000	1.5
+++ cdr_addon_mysql.c	21 Jan 2005 01:43:19 -0000	1.6
@@ -38,8 +38,8 @@
 static char *desc = "MySQL CDR Backend";
 static char *name = "mysql";
 static char *config = "cdr_mysql.conf";
-static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL;
-static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0;
+static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL, *dbtable = NULL;
+static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0, dbtable_alloc = 0;
 static int dbport = 0;
 static int connected = 0;
 static time_t connect_time = 0;
@@ -69,6 +69,8 @@
 
 		if (dbuser && *dbuser)
 			snprintf(status2, 99, " with username %s", dbuser);
+		if (dbtable && *dbtable)
+			snprintf(status2, 99, " using table %s", dbtable);
 		if (ctime > 31536000) {
 			ast_cli(fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 31536000, (ctime % 31536000) / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
 		} else if (ctime > 86400) {
@@ -111,7 +113,7 @@
 	localtime_r(&cdr->start.tv_sec,&tm);
 	strftime(timestr,128,DATE_FORMAT,&tm);
 
-	if ((!connected) && (hostname || dbsock) && dbuser && password && dbname) {
+	if ((!connected) && (hostname || dbsock) && dbuser && password && dbname && dbtable ) {
 		/* Attempt to connect */
 		mysql_init(&mysql);
 		if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
@@ -180,17 +182,17 @@
 		if (userfield && userfielddata)
 		{
 #ifdef MYSQL_LOGUNIQUEID
-			sprintf(sqlcmd,"INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s','%s')",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);
+			sprintf(sqlcmd,"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s','%s')",dbtable,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
-			sprintf(sqlcmd,"INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,userfield) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s')",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);
+			sprintf(sqlcmd,"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,userfield) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s')",dbtable,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  
 		}
 		else
 		{
 #ifdef MYSQL_LOGUNIQUEID
-			sprintf(sqlcmd,"INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s')",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);
+			sprintf(sqlcmd,"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s','%s')",dbtable,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
-			sprintf(sqlcmd,"INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s')",timestr,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata,cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode);
+			sprintf(sqlcmd,"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,'%s',%i,'%s')",dbtable,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  
 		}
 		
@@ -242,6 +244,11 @@
 		dbsock = NULL;
 		dbsock_alloc = 0;
 	}
+	if (dbtable && dbtable_alloc) {
+		free(dbtable);
+		dbtable = NULL;
+		dbtable_alloc = 0;
+	}
 	if (password && password_alloc) {
 		free(password);
 		password = NULL;
@@ -331,6 +338,21 @@
 		dbsock = NULL;
 	}
 
+	tmp = ast_variable_retrieve(cfg,"global","table");
+	if (tmp) {
+		dbtable = malloc(strlen(tmp) + 1);
+		if (dbtable != NULL) {
+			dbtable_alloc = 1;
+			strcpy(dbtable,tmp);
+		} else {
+			ast_log(LOG_ERROR,"Out of memory error.\n");
+			return -1;
+		}
+	} else {
+		ast_log(LOG_NOTICE,"MySQL database table not specified.  Assuming \"cdr\"\n");
+		dbtable = "cdr";
+	}
+
 	tmp = ast_variable_retrieve(cfg,"global","password");
 	if (tmp) {
 		password = malloc(strlen(tmp) + 1);

Index: res_config_mysql.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_config_mysql.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- res_config_mysql.c	20 Jan 2005 04:54:33 -0000	1.3
+++ res_config_mysql.c	21 Jan 2005 01:43:19 -0000	1.4
@@ -344,7 +344,7 @@
 	return -1;
 }
 
-static struct ast_config *config_mysql(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur)
+static struct ast_config *config_mysql(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, int recur)
 {
 	MYSQL_RES *result;
 	MYSQL_ROW row;
@@ -402,7 +402,7 @@
 		cat_started = 0;
 
 		cur_cat = *new_cat_p;
-		cur_v = *new_v_p;
+		cur_v = NULL;
 
 		if(cur_cat) {
 			cat_started = 1;
@@ -417,7 +417,7 @@
 
 		while((row = mysql_fetch_row(result))) {
 			if(!strcmp(row[1], "#include") && recur < MAX_INCLUDE_LEVEL) {
-				config_mysql(database, table, row[2], new, &cur_cat, &cur_v, recur + 1);
+				config_mysql(database, table, row[2], new, &cur_cat, recur + 1);
 			} else {
 				if(strcmp(last, row[0]) || last_cat_metric != atoi(row[3])) {
 					strncpy(last, row[0], sizeof(last) - 1);




More information about the svn-commits mailing list