]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
cdr/cdr_odbc.c: Added to record new columns add on CDR 1.8 Asterisk Version 58/258/3
authorRodrigo Ramírez Norambuena <decipher.hk@gmail.com>
Wed, 15 Apr 2015 23:55:33 +0000 (20:55 -0300)
committerMatt Jordan <mjordan@digium.com>
Mon, 27 Apr 2015 14:38:29 +0000 (09:38 -0500)
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

UPGRADE.txt
cdr/cdr_odbc.c
configs/samples/cdr_odbc.conf.sample

index 1a056b8911b24c735c8d02f95a2d342f808cf261..d0db4dbcadde5f599475f6691425d48b3e48aaf6 100644 (file)
@@ -50,6 +50,11 @@ res_pjsip_dlg_options:
    should have no adverse effects for those upgrading; this note merely
    serves as an indication that a new module exists.
 
+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 13.2.0 to 13.3.0:
 
 chan_dahdi:
index b8640f6bcaa623864f71a801276d920fed2fd669..1524efd1764410b13f51342fec6f4d3bd25e17ad 100644 (file)
@@ -64,6 +64,7 @@ enum {
        CONFIG_DISPOSITIONSTRING = 1 << 2,
        CONFIG_HRTIME =            1 << 3,
        CONFIG_REGISTERED =        1 << 4,
+       CONFIG_NEWCDRCOLUMNS =     1 << 5,
 };
 
 static struct ast_flags config = { 0 };
@@ -72,23 +73,29 @@ static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
 {
        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);
@@ -134,9 +141,17 @@ static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
        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);
@@ -260,6 +275,13 @@ static int odbc_load_module(int reload)
                                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)) {
index 93bd6fff874e0177838afa45dabc521d39776a4d..663ce09563201fd5f45f2dedff1b3aabf3617bea 100644 (file)
@@ -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)