aboutsummaryrefslogtreecommitdiffstats
path: root/cdr/cdr_tds.c
diff options
context:
space:
mode:
authorsnuffy <snuffy@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-08 23:48:17 +0000
committersnuffy <snuffy@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-08 23:48:17 +0000
commitb9d2b2684d6dfde3759cbbc84dfb6aa11d0e3b60 (patch)
treeb9c0a6d9e565124104804ec2cb1e31a3c6b5ea41 /cdr/cdr_tds.c
parent6db8e08fa31bc24296db13621a207e435834fdcd (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: http://svn.digium.com/svn/asterisk/trunk@269153 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr/cdr_tds.c')
-rw-r--r--cdr/cdr_tds.c71
1 files changed, 69 insertions, 2 deletions
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()) {