diff options
author | snuffy <snuffy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-06-08 23:48:17 +0000 |
---|---|---|
committer | snuffy <snuffy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-06-08 23:48:17 +0000 |
commit | b9d2b2684d6dfde3759cbbc84dfb6aa11d0e3b60 (patch) | |
tree | b9c0a6d9e565124104804ec2cb1e31a3c6b5ea41 /funcs | |
parent | 6db8e08fa31bc24296db13621a207e435834fdcd (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 'funcs')
-rw-r--r-- | funcs/func_cdr.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 211187278..3d0c846f9 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -106,6 +106,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") </parameter> <parameter name="options" required="false"> <optionlist> + <option name="f"> + <para>Returns billsec or duration fields as floating point values.</para> + </option> <option name="l"> <para>Uses the most recent CDR on a channel with multiple records</para> </option> @@ -174,9 +177,11 @@ enum cdr_option_flags { OPT_UNPARSED = (1 << 1), OPT_LAST = (1 << 2), OPT_SKIPLOCKED = (1 << 3), + OPT_FLOAT = (1 << 4), }; AST_APP_OPTIONS(cdr_func_options, { + AST_APP_OPTION('f', OPT_FLOAT), AST_APP_OPTION('l', OPT_LAST), AST_APP_OPTION('r', OPT_RECURSIVE), AST_APP_OPTION('s', OPT_SKIPLOCKED), @@ -213,9 +218,38 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next) cdr = cdr->next; - ast_cdr_getvar(cdr, args.variable, &ret, buf, len, - ast_test_flag(&flags, OPT_RECURSIVE), - ast_test_flag(&flags, OPT_UNPARSED)); + if (!strcasecmp("billsec", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) { + if (!ast_tvzero(cdr->answer)) { + double hrtime; + + if(!ast_tvzero(cdr->end)) + hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0); + else + hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->answer) / 1000000.0); + + snprintf(buf, len, "%lf", hrtime); + } else { + snprintf(buf, len, "%lf", 0.0); + } + ret = buf; + } else if (!strcasecmp("duration", args.variable) && ast_test_flag(&flags, OPT_FLOAT)) { + double hrtime; + + if(!ast_tvzero(cdr->end)) + hrtime = (double)(ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0); + else + hrtime = (double)(ast_tvdiff_us(ast_tvnow(), cdr->start) / 1000000.0); + + snprintf(buf, len, "%lf", hrtime); + + if (!ast_strlen_zero(buf)) { + ret = buf; + } + } else { + ast_cdr_getvar(cdr, args.variable, &ret, buf, len, + ast_test_flag(&flags, OPT_RECURSIVE), + ast_test_flag(&flags, OPT_UNPARSED)); + } return ret ? 0 : -1; } |