From 4405813297fa41d441ab2cb28387df09b90aea68 Mon Sep 17 00:00:00 2001 From: Bradley Latus Date: Tue, 8 Jun 2010 23:48:17 +0000 Subject: 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 --- cdr/cdr_tds.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) (limited to 'cdr/cdr_tds.c') diff --git a/cdr/cdr_tds.c b/cdr/cdr_tds.c index c615400d3..ab0f0659c 100644 --- a/cdr/cdr_tds.c +++ b/cdr/cdr_tds.c @@ -87,6 +87,7 @@ struct cdr_tds_config { AST_STRING_FIELD(table); AST_STRING_FIELD(charset); AST_STRING_FIELD(language); + AST_STRING_FIELD(hrtime); ); DBPROCESS *dbproc; unsigned int connected:1; @@ -149,7 +150,36 @@ retry: } if (settings->has_userfield) { - erc = dbfcmd(settings->dbproc, + if (settings->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); + + erc = dbfcmd(settings->dbproc, + "INSERT INTO %s " + "(" + "accountcode, src, dst, dcontext, clid, channel, " + "dstchannel, lastapp, lastdata, start, answer, [end], duration, " + "billsec, disposition, amaflags, uniqueid, userfield" + ") " + "VALUES " + "(" + "'%s', '%s', '%s', '%s', '%s', '%s', " + "'%s', '%s', '%s', %s, %s, %s, %lf, " + "%lf, '%s', '%s', '%s', '%s'" + ")", + settings->table, + accountcode, src, dst, dcontext, clid, channel, + dstchannel, lastapp, lastdata, start, answer, end, hrduration, + hrbillsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid, + userfield + ); + } else { + erc = dbfcmd(settings->dbproc, "INSERT INTO %s " "(" "accountcode, src, dst, dcontext, clid, channel, " @@ -168,8 +198,37 @@ retry: cdr->billsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid, userfield ); + } } else { - erc = dbfcmd(settings->dbproc, + if (settings->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); + + erc = dbfcmd(settings->dbproc, + "INSERT INTO %s " + "(" + "accountcode, src, dst, dcontext, clid, channel, " + "dstchannel, lastapp, lastdata, start, answer, [end], duration, " + "billsec, disposition, amaflags, uniqueid" + ") " + "VALUES " + "(" + "'%s', '%s', '%s', '%s', '%s', '%s', " + "'%s', '%s', '%s', %s, %s, %s, %lf, " + "%lf, '%s', '%s', '%s'" + ")", + settings->table, + accountcode, src, dst, dcontext, clid, channel, + dstchannel, lastapp, lastdata, start, answer, end, hrduration, + hrbillsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid + ); + } else { + erc = dbfcmd(settings->dbproc, "INSERT INTO %s " "(" "accountcode, src, dst, dcontext, clid, channel, " @@ -187,6 +246,7 @@ retry: dstchannel, lastapp, lastdata, start, answer, end, cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), ast_cdr_flags2str(cdr->amaflags), uniqueid ); + } } if (erc == FAIL) { @@ -502,6 +562,13 @@ static int tds_load_module(int reload) ast_string_field_set(settings, table, "cdr"); } + ptr = ast_variable_retrieve(cfg, "global", "hrtime"); + if (ptr && ast_true(ptr)) { + ast_string_field_set(settings, hrtime, ptr); + } else { + ast_log(LOG_NOTICE, "High Resolution Time not found, using integers for billsec and duration fields by default.\n"); + } + mssql_disconnect(); if (mssql_connect()) { -- cgit v1.2.3