add an option to cdr.conf that enables ending CDRs before executing

the "h" extension as opposed to afterwards (issue #6193)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@12896 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Russell Bryant 20 years ago
parent d3527e5020
commit 4e6af293f9

13
cdr.c

@ -657,6 +657,11 @@ void ast_cdr_end(struct ast_cdr *cdr)
ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan); ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan);
if (ast_tvzero(cdr->end)) if (ast_tvzero(cdr->end))
cdr->end = ast_tvnow(); cdr->end = ast_tvnow();
cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
if (!ast_tvzero(cdr->answer))
cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
else
cdr->billsec = 0;
cdr = cdr->next; cdr = cdr->next;
} }
} }
@ -804,11 +809,6 @@ static void post_cdr(struct ast_cdr *cdr)
ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan); ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
if (ast_tvzero(cdr->start)) if (ast_tvzero(cdr->start))
ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan); ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
if (!ast_tvzero(cdr->answer))
cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
else
cdr->billsec = 0;
ast_set_flag(cdr, AST_CDR_FLAG_POSTED); ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
AST_LIST_LOCK(&be_list); AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE(&be_list, i, list) { AST_LIST_TRAVERSE(&be_list, i, list) {
@ -1121,6 +1121,7 @@ static int do_reload(void)
const char *batchsafeshutdown_value; const char *batchsafeshutdown_value;
const char *size_value; const char *size_value;
const char *time_value; const char *time_value;
const char *end_before_h_value;
int cfg_size; int cfg_size;
int cfg_time; int cfg_time;
int was_enabled; int was_enabled;
@ -1171,6 +1172,8 @@ static int do_reload(void)
else else
batchtime = cfg_time; batchtime = cfg_time;
} }
if ((end_before_h_value = ast_variable_retrieve(config, "general", "endbeforehexten")))
ast_set2_flag(&ast_options, ast_true(end_before_h_value), AST_OPT_END_CDR_BEFORE_H_EXTEN);
} }
if (enabled && !batchmode) { if (enabled && !batchmode) {

@ -49,6 +49,13 @@
; is "yes". ; is "yes".
;safeshutdown=yes ;safeshutdown=yes
; ;
; Normally, CDR's are not closed out until after all extensions are finished
; executing. By enabling this option, the CDR will be ended before executing
; the "h" extension so that CDR values such as "end" and "billsec" may be
; retrieved inside of of this extension.
;endbeforehexten=no
;[csv] ;[csv]
;usegmtime=yes ;log date/time in GMT ;usegmtime=yes ;log date/time in GMT
;loguniqueid=yes ;log uniqueid ;loguniqueid=yes ;log uniqueid

@ -69,7 +69,9 @@ enum ast_option_flags {
/*! Transmit Silence during Record() */ /*! Transmit Silence during Record() */
AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17), AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
/*! Suppress some warnings */ /*! Suppress some warnings */
AST_OPT_FLAG_DONT_WARN = (1 << 18) AST_OPT_FLAG_DONT_WARN = (1 << 18),
/*! End CDRs before the 'h' extension */
AST_OPT_END_CDR_BEFORE_H_EXTEN = (1 << 19)
}; };
#define ast_opt_exec_includes ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) #define ast_opt_exec_includes ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES)
@ -91,6 +93,7 @@ enum ast_option_flags {
#define ast_opt_reconnect ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT) #define ast_opt_reconnect ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT)
#define ast_opt_transmit_silence ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) #define ast_opt_transmit_silence ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE)
#define ast_opt_dont_warn ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN) #define ast_opt_dont_warn ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN)
#define ast_opt_end_cdr_before_h_exten ast_test_flag(&ast_options, AST_OPT_END_CDR_BEFORE_H_EXTEN)
extern struct ast_flags ast_options; extern struct ast_flags ast_options;

@ -2278,6 +2278,8 @@ static int __ast_pbx_run(struct ast_channel *c)
ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name); ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
out: out:
if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) { if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
if (c->cdr && ast_opt_end_cdr_before_h_exten)
ast_cdr_end(c->cdr);
c->exten[0] = 'h'; c->exten[0] = 'h';
c->exten[1] = '\0'; c->exten[1] = '\0';
c->priority = 1; c->priority = 1;

Loading…
Cancel
Save