Bug 6417 - Allow retrieval of raw CDR values
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@10953 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
a4734960e7
commit
53936916ec
|
@ -82,7 +82,7 @@ static int pickup_exec(struct ast_channel *chan, void *data)
|
|||
origin = ast_get_channel_by_exten_locked(exten, context);
|
||||
if (origin) {
|
||||
ast_cdr_getvar(origin->cdr, "dstchannel", &tmp, workspace,
|
||||
sizeof(workspace), 0);
|
||||
sizeof(workspace), 0, 0);
|
||||
if (tmp) {
|
||||
/* We have a possible channel... now we need to find it! */
|
||||
target = ast_get_channel_by_name_locked(tmp);
|
||||
|
|
58
cdr.c
58
cdr.c
|
@ -205,7 +205,7 @@ static const char *ast_cdr_getvar_internal(struct ast_cdr *cdr, const char *name
|
|||
}
|
||||
|
||||
/*! CDR channel variable retrieval */
|
||||
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur)
|
||||
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw)
|
||||
{
|
||||
struct tm tm;
|
||||
time_t t;
|
||||
|
@ -233,32 +233,52 @@ void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *wor
|
|||
else if (!strcasecmp(name, "lastdata"))
|
||||
ast_copy_string(workspace, cdr->lastdata, workspacelen);
|
||||
else if (!strcasecmp(name, "start")) {
|
||||
t = cdr->start.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
if (raw) {
|
||||
snprintf(workspace, workspacelen, "%ld.%06ld", (long)cdr->start.tv_sec, (long)cdr->start.tv_usec);
|
||||
} else {
|
||||
t = cdr->start.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(name, "answer")) {
|
||||
t = cdr->answer.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
if (raw) {
|
||||
snprintf(workspace, workspacelen, "%ld.%06ld", (long)cdr->answer.tv_sec, (long)cdr->answer.tv_usec);
|
||||
} else {
|
||||
t = cdr->answer.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(name, "end")) {
|
||||
t = cdr->end.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
if (raw) {
|
||||
snprintf(workspace, workspacelen, "%ld.%06ld", (long)cdr->end.tv_sec, (long)cdr->end.tv_usec);
|
||||
} else {
|
||||
t = cdr->end.tv_sec;
|
||||
if (t) {
|
||||
localtime_r(&t, &tm);
|
||||
strftime(workspace, workspacelen, fmt, &tm);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(name, "duration"))
|
||||
snprintf(workspace, workspacelen, "%d", cdr->duration);
|
||||
else if (!strcasecmp(name, "billsec"))
|
||||
snprintf(workspace, workspacelen, "%d", cdr->billsec);
|
||||
else if (!strcasecmp(name, "disposition"))
|
||||
ast_copy_string(workspace, ast_cdr_disp2str(cdr->disposition), workspacelen);
|
||||
else if (!strcasecmp(name, "amaflags"))
|
||||
ast_copy_string(workspace, ast_cdr_flags2str(cdr->amaflags), workspacelen);
|
||||
else if (!strcasecmp(name, "accountcode"))
|
||||
else if (!strcasecmp(name, "disposition")) {
|
||||
if (raw) {
|
||||
snprintf(workspace, workspacelen, "%d", cdr->disposition);
|
||||
} else {
|
||||
ast_copy_string(workspace, ast_cdr_disp2str(cdr->disposition), workspacelen);
|
||||
}
|
||||
} else if (!strcasecmp(name, "amaflags")) {
|
||||
if (raw) {
|
||||
snprintf(workspace, workspacelen, "%d", cdr->amaflags);
|
||||
} else {
|
||||
ast_copy_string(workspace, ast_cdr_flags2str(cdr->amaflags), workspacelen);
|
||||
}
|
||||
} else if (!strcasecmp(name, "accountcode"))
|
||||
ast_copy_string(workspace, cdr->accountcode, workspacelen);
|
||||
else if (!strcasecmp(name, "uniqueid"))
|
||||
ast_copy_string(workspace, cdr->uniqueid, workspacelen);
|
||||
|
@ -375,7 +395,7 @@ int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, cha
|
|||
}
|
||||
|
||||
for (i = 0; cdr_readonly_vars[i]; i++) {
|
||||
ast_cdr_getvar(cdr, cdr_readonly_vars[i], &tmp, workspace, sizeof(workspace), 0);
|
||||
ast_cdr_getvar(cdr, cdr_readonly_vars[i], &tmp, workspace, sizeof(workspace), 0, 0);
|
||||
if (!tmp)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -41,10 +41,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||
|
||||
enum {
|
||||
OPT_RECURSIVE = (1 << 0),
|
||||
OPT_UNPARSED = (1 << 1),
|
||||
} cdr_option_flags;
|
||||
|
||||
AST_APP_OPTIONS(cdr_func_options, {
|
||||
AST_APP_OPTION('r', OPT_RECURSIVE),
|
||||
AST_APP_OPTION('u', OPT_UNPARSED),
|
||||
});
|
||||
|
||||
static int cdr_read(struct ast_channel *chan, char *cmd, char *parse,
|
||||
|
@ -69,7 +71,8 @@ static int cdr_read(struct ast_channel *chan, char *cmd, char *parse,
|
|||
ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
|
||||
|
||||
ast_cdr_getvar(chan->cdr, args.variable, &ret, buf, len,
|
||||
ast_test_flag(&flags, OPT_RECURSIVE));
|
||||
ast_test_flag(&flags, OPT_RECURSIVE),
|
||||
ast_test_flag(&flags, OPT_UNPARSED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -96,8 +99,9 @@ static int cdr_write(struct ast_channel *chan, char *cmd, char *parse,
|
|||
else if (!strcasecmp(args.variable, "userfield"))
|
||||
ast_cdr_setuserfield(chan, value);
|
||||
else if (chan->cdr)
|
||||
ast_cdr_setvar(chan->cdr, args.variable, value,
|
||||
ast_test_flag(&flags, OPT_RECURSIVE));
|
||||
ast_cdr_setvar(chan->cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
|
||||
/* No need to worry about the u flag, as all fields for which setting
|
||||
* 'u' would do anything are marked as readonly. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -105,10 +109,17 @@ static int cdr_write(struct ast_channel *chan, char *cmd, char *parse,
|
|||
static struct ast_custom_function cdr_function = {
|
||||
.name = "CDR",
|
||||
.synopsis = "Gets or sets a CDR variable",
|
||||
.desc = "Option 'r' searches the entire stack of CDRs on the channel\n",
|
||||
.syntax = "CDR(<name>[|options])",
|
||||
.read = cdr_read,
|
||||
.write = cdr_write,
|
||||
.desc =
|
||||
"Options:\n"
|
||||
" 'r' searches the entire stack of CDRs on the channel\n"
|
||||
" 'u' retrieves the raw, unprocessed value\n"
|
||||
" For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
|
||||
" values, when the n option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
|
||||
" otherwise. Similarly, disposition and amaflags will return their raw\n"
|
||||
" integral values.\n",
|
||||
};
|
||||
|
||||
static char *tdesc = "CDR dialplan function";
|
||||
|
|
|
@ -96,7 +96,7 @@ struct ast_cdr {
|
|||
struct ast_cdr *next;
|
||||
};
|
||||
|
||||
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur);
|
||||
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
|
||||
int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
|
||||
int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
|
||||
void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
|
||||
|
|
Loading…
Reference in New Issue