[asterisk-commits] trunk r10953 - in /trunk: ./ apps/ funcs/
include/asterisk/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Feb 23 16:12:42 MST 2006
Author: tilghman
Date: Thu Feb 23 17:12:41 2006
New Revision: 10953
URL: http://svn.digium.com/view/asterisk?rev=10953&view=rev
Log:
Bug 6417 - Allow retrieval of raw CDR values
Modified:
trunk/apps/app_directed_pickup.c
trunk/cdr.c
trunk/funcs/func_cdr.c
trunk/include/asterisk/cdr.h
Modified: trunk/apps/app_directed_pickup.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_directed_pickup.c?rev=10953&r1=10952&r2=10953&view=diff
==============================================================================
--- trunk/apps/app_directed_pickup.c (original)
+++ trunk/apps/app_directed_pickup.c Thu Feb 23 17:12:41 2006
@@ -82,7 +82,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);
Modified: trunk/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr.c?rev=10953&r1=10952&r2=10953&view=diff
==============================================================================
--- trunk/cdr.c (original)
+++ trunk/cdr.c Thu Feb 23 17:12:41 2006
@@ -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);
@@ -375,7 +395,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;
Modified: trunk/funcs/func_cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_cdr.c?rev=10953&r1=10952&r2=10953&view=diff
==============================================================================
--- trunk/funcs/func_cdr.c (original)
+++ trunk/funcs/func_cdr.c Thu Feb 23 17:12:41 2006
@@ -41,10 +41,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 int cdr_read(struct ast_channel *chan, char *cmd, char *parse,
@@ -69,7 +71,8 @@
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 @@
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 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";
Modified: trunk/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/cdr.h?rev=10953&r1=10952&r2=10953&view=diff
==============================================================================
--- trunk/include/asterisk/cdr.h (original)
+++ trunk/include/asterisk/cdr.h Thu Feb 23 17:12:41 2006
@@ -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);
More information about the asterisk-commits
mailing list