Fixed problems with ast_cdr_serialize_variables().

* Fixed return value of ast_cdr_serialize_variables() on error.  It needs
to return 0 indicating no CDR variables found.

* Made ast_cdr_serialize_variables() check the return value of
cdr_object_format_property() and assert if nonzero.  A member of the
cdr_readonly_vars[] was not handled.

* Removed unused elements from cdr_readonly_vars[]: total_duration,
total_billsec, first_start, and first_answer.
........

Merged revisions 397900 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397901 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2013-08-28 22:56:03 +00:00
parent 87bf699dc9
commit 94e4733d89

View File

@@ -2862,11 +2862,29 @@ static int cdr_object_select_all_by_channel_cb(void *obj, void *arg, int flags)
} }
/* Read Only CDR variables */ /* Read Only CDR variables */
static const char * const cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", static const char * const cdr_readonly_vars[] = {
"channel", "dstchannel", "lastapp", "lastdata", "start", "answer", "end", "duration", "clid",
"billsec", "disposition", "amaflags", "accountcode", "uniqueid", "linkedid", "src",
"userfield", "sequence", "total_duration", "total_billsec", "first_start", "dst",
"first_answer", NULL }; "dcontext",
"channel",
"dstchannel",
"lastapp",
"lastdata",
"start",
"answer",
"end",
"duration",
"billsec",
"disposition",
"amaflags",
"accountcode",
"uniqueid",
"linkedid",
"userfield",
"sequence",
NULL
};
int ast_cdr_setvar(const char *channel_name, const char *name, const char *value) int ast_cdr_setvar(const char *channel_name, const char *name, const char *value)
{ {
@@ -3036,12 +3054,12 @@ int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf,
int total = 0, x = 0, i; int total = 0, x = 0, i;
if (!workspace) { if (!workspace) {
return 1; return 0;
} }
if (!cdr) { if (!cdr) {
ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name); ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name);
return 1; return 0;
} }
ast_str_reset(*buf); ast_str_reset(*buf);
@@ -3067,7 +3085,11 @@ int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf,
for (i = 0; cdr_readonly_vars[i]; i++) { for (i = 0; cdr_readonly_vars[i]; i++) {
/* null out the workspace, because the cdr_get_tv() won't write anything if time is NULL, so you get old vals */ /* null out the workspace, because the cdr_get_tv() won't write anything if time is NULL, so you get old vals */
workspace[0] = 0; workspace[0] = 0;
cdr_object_format_property(it_cdr, cdr_readonly_vars[i], workspace, sizeof(workspace)); if (cdr_object_format_property(it_cdr, cdr_readonly_vars[i], workspace, sizeof(workspace))) {
/* Unhandled read-only CDR variable. */
ast_assert(0);
continue;
}
if (!ast_strlen_zero(workspace) if (!ast_strlen_zero(workspace)
&& ast_str_append(buf, 0, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, workspace, sep) < 0) { && ast_str_append(buf, 0, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, workspace, sep) < 0) {