cdr_addon_mysql.c.diff
--- cdr_addon_mysql.c	2003-09-29 23:27:12.000000000 +0200
+++ cdr_addon_mysql_new.c	2004-01-22 16:22:22.000000000 +0100
@@ -37,10 +37,11 @@
 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 char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL, *userfielddata = NULL;
 static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0;
 static int dbport = 0;
 static int connected = 0;
+static int userfield = 0;
 
 static ast_mutex_t mysql_lock = AST_MUTEX_INITIALIZER;
 
@@ -109,6 +110,9 @@
 			mysql_real_escape_string(&mysql, uniqueid, cdr->uniqueid, strlen(cdr->uniqueid));
 #endif
 
+		if (userfield && ((userfielddata = alloca(strlen(cdr->userfield) * 2 + 1)) != NULL))
+			mysql_real_escape_string(&mysql, 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)) {
@@ -122,11 +126,23 @@
 
 		ast_log(LOG_DEBUG,"cdr_mysql: inserting a CDR record.\n");
 
+		if (userfield)
+		{
+#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);
+#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);
+#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 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);
 #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 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);
 #endif  
+		}
+		
 		ast_log(LOG_DEBUG,"cdr_mysql: SQL command as follows:  %s\n",sqlcmd);
 	
 		if (mysql_real_query(&mysql,sqlcmd,strlen(sqlcmd))) {
@@ -281,7 +297,15 @@
 			dbport = 0;
 		}
 	}
-
+	
+	tmp = ast_variable_retrieve(cfg,"global","userfield");
+	if (tmp) {
+		if (sscanf(tmp,"%d",&userfield) < 1) {
+			ast_log(LOG_WARNING,"Invalid MySQL configurtation file\n");
+			userfield = 0;
+		}
+	}
+	
 	ast_destroy(cfg);
 
 	ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);






cdr_mysql.conf.sample.diff
--- cdr_mysql.conf.sample	2003-09-27 00:50:59.000000000 +0200
+++ cdr_mysql_new.conf.sample	2004-01-22 16:22:45.000000000 +0100
@@ -17,3 +17,4 @@
 ;user=asteriskcdruser
 ;port=3306
 ;sock=/tmp/mysql.sock
+;userfield=1





cdr_mysql.txt.diff
--- cdr_mysql.txt	2003-12-03 00:42:26.000000000 +0100
+++ cdr_mysql_new.txt	2004-01-22 16:23:04.000000000 +0100
@@ -23,7 +23,8 @@
   disposition varchar(45) NOT NULL default '',
   amaflags int(11) NOT NULL default '0',
   accountcode varchar(20) NOT NULL default '',
-  uniqueid varchar(32) NOT NULL default ''
+  uniqueid varchar(32) NOT NULL default '',
+  userfield varchar(255) NOT NULL default ''
 );
 
 The calls will automatically be logged as long as the module is loaded.
