[asterisk-commits] cdr/cdr odbc.c: Added to record new columns add on CDR 1.8 A... (asterisk[11])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 28 06:55:10 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: cdr/cdr_odbc.c: Added to record new columns add on CDR 1.8 Asterisk Version
......................................................................


cdr/cdr_odbc.c: Added to record new columns add on CDR 1.8 Asterisk Version

Add new column to INSERT new columns added in cdr 1.8 version. The columns are:
 * peeraccount
 * linkedid
 * sequence
This feature is configurable in cdr_odbc.conf using a new configuration
option, 'newcdrcolumns'.

ASTERISK-24976 #close

Change-Id: Ibe0c7540a88305c6012786f438a0813ad8b19127
---
M UPGRADE.txt
M cdr/cdr_odbc.c
M configs/cdr_odbc.conf.sample
3 files changed, 33 insertions(+), 5 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/UPGRADE.txt b/UPGRADE.txt
index f529b82..da01149 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -51,6 +51,11 @@
    ring-ring-ring pattern would exceed the pattern limits and stop
    Caller-ID detection.
 
+cdr_odbc:
+ - Added support for post-1.8 CDR columns 'peeraccount', 'linkedid', and
+   'sequence'. Support for the new columns can be enabled via the newcdrcolumns
+   option in cdr_odbc.conf.
+
 from 11.15 to 11.16
 chan_dahdi:
  - The CALLERID(ani2) value for incoming calls is now populated in featdmf
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c
index e940b93..207807f 100644
--- a/cdr/cdr_odbc.c
+++ b/cdr/cdr_odbc.c
@@ -55,6 +55,7 @@
 	CONFIG_DISPOSITIONSTRING = 1 << 2,
 	CONFIG_HRTIME =            1 << 3,
 	CONFIG_REGISTERED =        1 << 4,
+	CONFIG_NEWCDRCOLUMNS =     1 << 5,
 };
 
 static struct ast_flags config = { 0 };
@@ -63,23 +64,29 @@
 {
 	struct ast_cdr *cdr = data;
 	SQLRETURN ODBC_res;
-	char sqlcmd[2048] = "", timestr[128];
+	char sqlcmd[2048] = "", timestr[128], new_columns[120] = "", new_values[7] = "";
 	struct ast_tm tm;
 	SQLHSTMT stmt;
+	int i = 0;
 
 	ast_localtime(&cdr->start, &tm, ast_test_flag(&config, CONFIG_USEGMTIME) ? "GMT" : NULL);
 	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
+	if (ast_test_flag(&config, CONFIG_NEWCDRCOLUMNS)) {
+		snprintf(new_columns, sizeof(new_columns), "%s", ",peeraccount,linkedid,sequence");
+		snprintf(new_values, sizeof(new_values), "%s", ",?,?,?");
+	}
+
 	if (ast_test_flag(&config, CONFIG_LOGUNIQUEID)) {
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
 		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
-		"lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
-		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr);
+		"lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield%s) "
+		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,? %s)", table, new_columns, timestr, new_values);
 	} else {
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
 		"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,"
-		"duration,billsec,disposition,amaflags,accountcode) "
-		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr);
+		"duration,billsec,disposition,amaflags,accountcode%s) "
+		"VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?%s)", table, new_columns, timestr, new_values);
 	}
 
 	ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
@@ -122,9 +129,17 @@
 	SQLBindParameter(stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->amaflags, 0, NULL);
 	SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->accountcode), 0, cdr->accountcode, 0, NULL);
 
+	i = 14;
 	if (ast_test_flag(&config, CONFIG_LOGUNIQUEID)) {
 		SQLBindParameter(stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL);
 		SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
+		i = 16;
+	}
+
+	if (ast_test_flag(&config, CONFIG_NEWCDRCOLUMNS)) {
+		SQLBindParameter(stmt, i, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->peeraccount), 0, cdr->peeraccount, 0, NULL);
+		SQLBindParameter(stmt, i + 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->linkedid), 0, cdr->linkedid, 0, NULL);
+		SQLBindParameter(stmt, i + 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->sequence, 0, NULL);
 	}
 
 	ODBC_res = SQLExecDirect(stmt, (unsigned char *)sqlcmd, SQL_NTS);
@@ -251,6 +266,13 @@
 				ast_set_flag(&config, CONFIG_REGISTERED);
 			}
 		}
+		if (((tmp = ast_variable_retrieve(cfg, "global", "newcdrcolumns"))) && ast_true(tmp)) {
+			ast_set_flag(&config, CONFIG_NEWCDRCOLUMNS);
+			ast_debug(1, "cdr_odbc: Add new cdr fields\n");
+		} else {
+			ast_clear_flag(&config, CONFIG_NEWCDRCOLUMNS);
+			ast_debug(1, "cdr_odbc: Not add new cdr fields\n");
+		}
 	} while (0);
 
 	if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) {
diff --git a/configs/cdr_odbc.conf.sample b/configs/cdr_odbc.conf.sample
index 93bd6ff..663ce09 100644
--- a/configs/cdr_odbc.conf.sample
+++ b/configs/cdr_odbc.conf.sample
@@ -9,3 +9,4 @@
 ;table=cdr		;"cdr" is default table name
 ;usegmtime=no             ; set to "yes" to log in GMT
 ;hrtime=yes		;Enables microsecond accuracy with the billsec and duration fields
+;newcdrcolumns=yes ; Enable logging of post-1.8 CDR columns (peeraccount, linkedid, sequence)

-- 
To view, visit https://gerrit.asterisk.org/257
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe0c7540a88305c6012786f438a0813ad8b19127
Gerrit-PatchSet: 3
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Rodrigo Ramirez Norambuena <decipher.hk at gmail.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list