Index: cdr.c =================================================================== --- cdr.c (revision 9349) +++ cdr.c (working copy) @@ -205,7 +205,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; @@ -233,32 +233,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); @@ -394,7 +415,7 @@ } for (i = 0; i < (sizeof(cdrcols) / sizeof(cdrcols[0])); i++) { - ast_cdr_getvar(cdr, cdrcols[i], &tmp, workspace, sizeof(workspace), 0); + ast_cdr_getvar(cdr, cdrcols[i], &tmp, workspace, sizeof(workspace), 0, 0); if (!tmp) continue; Index: apps/app_directed_pickup.c =================================================================== --- apps/app_directed_pickup.c (revision 9349) +++ apps/app_directed_pickup.c (working copy) @@ -79,7 +79,7 @@ origin = ast_get_channel_by_exten_locked(exten, context); if (origin && origin->cdr) { 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 9349) +++ include/asterisk/cdr.h (working copy) @@ -96,7 +96,7 @@ struct ast_cdr *next; }; -extern void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur); +extern void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw); extern int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur); extern int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur); extern void ast_cdr_free_vars(struct ast_cdr *cdr, int recur); Index: funcs/func_cdr.c =================================================================== --- funcs/func_cdr.c (revision 9349) +++ funcs/func_cdr.c (working copy) @@ -44,6 +44,7 @@ int argc; char *argv[2]; int recursive = 0; + int raw = 0; if (ast_strlen_zero(data)) return NULL; @@ -59,9 +60,11 @@ argc--; if (strchr(argv[argc], 'r')) recursive = 1; + if (strchr(argv[argc], 'u')) + raw = 1; } - ast_cdr_getvar(chan->cdr, argv[0], &ret, buf, len, recursive); + ast_cdr_getvar(chan->cdr, argv[0], &ret, buf, len, recursive, raw); return ret; } @@ -84,6 +87,7 @@ argc--; if (strchr(argv[argc], 'r')) recursive = 1; + /* u flag are not used for write */ } if (!strcasecmp(argv[0], "accountcode")) @@ -100,7 +104,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 u 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,