Index: cdr.c =================================================================== --- cdr.c (revision 9326) +++ cdr.c (working copy) @@ -208,7 +208,7 @@ } /*! 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; @@ -236,32 +236,52 @@ 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); @@ -378,7 +398,7 @@ } 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; Index: apps/app_directed_pickup.c =================================================================== --- apps/app_directed_pickup.c (revision 9326) +++ apps/app_directed_pickup.c (working copy) @@ -84,7 +84,7 @@ 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); Index: include/asterisk/cdr.h =================================================================== --- include/asterisk/cdr.h (revision 9326) +++ include/asterisk/cdr.h (working copy) @@ -96,7 +96,7 @@ 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); Index: funcs/func_cdr.c =================================================================== --- funcs/func_cdr.c (revision 9326) +++ funcs/func_cdr.c (working copy) @@ -40,10 +40,12 @@ 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 char *builtin_function_cdr_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) @@ -71,7 +73,9 @@ if(!ast_strlen_zero(args.options) ) { 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) ) ? 1 : 0 ); + ast_cdr_getvar(chan->cdr, args.variable, &ret, buf, len, + (ast_test_flag(&flags, OPT_RECURSIVE) ) ? 1 : 0, + (ast_test_flag(&flags, OPT_UNPARSED) ) ? 1 : 0 ); return ret; } @@ -104,7 +108,9 @@ 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) ) ? 1 : 0 ); + ast_cdr_setvar(chan->cdr, args.variable, value, (ast_test_flag(&flags, OPT_RECURSIVE) ) ? 1 : 0 ); + /* No need to worry about the u flag, as all fields for which setting + * 'u' would do anything are marked as readonly. */ } #ifndef BUILTIN_FUNC @@ -113,7 +119,14 @@ 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", + .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", .syntax = "CDR([|options])", .read = builtin_function_cdr_read, .write = builtin_function_cdr_write,