diff options
author | Joshua Colp <jcolp@digium.com> | 2015-04-28 06:55:30 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2015-04-28 06:55:30 -0500 |
commit | b2153f1f498cb57571e7587ef241ddd86ba167ad (patch) | |
tree | 660c105c1beb16d91559901de59f660c67553cfe /cdr | |
parent | e43fa9868b2f21289c601cf1c477e6f7c0b7e716 (diff) | |
parent | 358080e86ebd1258a288ede50d9ae9f29d7fcd90 (diff) |
Merge "cdr/cdr_odbc.c: Added to record new columns add on CDR 1.8 Asterisk Version"
Diffstat (limited to 'cdr')
-rw-r--r-- | cdr/cdr_odbc.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c index 8f326f932..4d601ef9a 100644 --- a/cdr/cdr_odbc.c +++ b/cdr/cdr_odbc.c @@ -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 columns\n"); + } else { + ast_clear_flag(&config, CONFIG_NEWCDRCOLUMNS); + ast_debug(1, "cdr_odbc: Not add new cdr columns\n"); + } } while (0); if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) { |