summaryrefslogtreecommitdiff
path: root/cdr/cdr_odbc.c
diff options
context:
space:
mode:
authorBradley Latus <brad.latus@gmail.com>2010-06-08 23:48:17 +0000
committerBradley Latus <brad.latus@gmail.com>2010-06-08 23:48:17 +0000
commit4405813297fa41d441ab2cb28387df09b90aea68 (patch)
treeb9c0a6d9e565124104804ec2cb1e31a3c6b5ea41 /cdr/cdr_odbc.c
parent3c26b511e03ac9dde860787f2cf3cf2ad06df495 (diff)
Add High Resolution Times to CDRs for Asterisk
People expressed an interest in having access to the exact length of calls to a finer degree than seconds. See the CHANGES and UPGRADE.txt for usage also updated the sample configs to note the change. Patch by snuffy. (closes issue #16559) Reported by: cianmaher Tested by: cianmaher, snuffy Review: https://reviewboard.asterisk.org/r/461/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@269153 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'cdr/cdr_odbc.c')
-rw-r--r--cdr/cdr_odbc.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c
index e0f830c2a..fde134fa8 100644
--- a/cdr/cdr_odbc.c
+++ b/cdr/cdr_odbc.c
@@ -53,6 +53,7 @@ enum {
CONFIG_LOGUNIQUEID = 1 << 0,
CONFIG_USEGMTIME = 1 << 1,
CONFIG_DISPOSITIONSTRING = 1 << 2,
+ CONFIG_HRTIME = 1 << 3,
};
static struct ast_flags config = { 0 };
@@ -96,8 +97,23 @@ static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dstchannel), 0, cdr->dstchannel, 0, NULL);
SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastapp), 0, cdr->lastapp, 0, NULL);
SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->lastdata), 0, cdr->lastdata, 0, NULL);
- SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->duration, 0, NULL);
- SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->billsec, 0, NULL);
+
+ if (ast_test_flag(&config, CONFIG_HRTIME)) {
+ double hrbillsec = 0.0;
+ double hrduration;
+
+ if (!ast_tvzero(cdr->answer)) {
+ hrbillsec = (double) ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0;
+ }
+ hrduration = (double) ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0;
+
+ SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrbillsec, 0, NULL);
+ SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrduration, 0, NULL);
+ } else {
+ SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->duration, 0, NULL);
+ SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->billsec, 0, NULL);
+ }
+
if (ast_test_flag(&config, CONFIG_DISPOSITIONSTRING))
SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ast_cdr_disp2str(cdr->disposition)) + 1, 0, ast_cdr_disp2str(cdr->disposition), 0, NULL);
else
@@ -203,6 +219,14 @@ static int odbc_load_module(int reload)
ast_debug(1, "cdr_odbc: Logging in local time\n");
}
+ if (((tmp = ast_variable_retrieve(cfg, "global", "hrtime"))) && ast_true(tmp)) {
+ ast_set_flag(&config, CONFIG_HRTIME);
+ ast_debug(1, "cdr_odbc: Logging billsec and duration fields as floats\n");
+ } else {
+ ast_clear_flag(&config, CONFIG_HRTIME);
+ ast_debug(1, "cdr_odbc: Logging billsec and duration fields as integers\n");
+ }
+
if ((tmp = ast_variable_retrieve(cfg, "global", "table")) == NULL) {
ast_log(LOG_WARNING, "cdr_odbc: table not specified. Assuming cdr\n");
tmp = "cdr";