2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999-2006, Digium, Inc.
6 * Portions Copyright (C) 2005, Anthony Minessale II
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Call Detail Record related dialplan functions
23 * \author Anthony Minessale II
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/module.h"
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/utils.h"
36 #include "asterisk/app.h"
37 #include "asterisk/cdr.h"
40 OPT_RECURSIVE = (1 << 0),
41 OPT_UNPARSED = (1 << 1),
45 AST_APP_OPTIONS(cdr_func_options, {
46 AST_APP_OPTION('l', OPT_LAST),
47 AST_APP_OPTION('r', OPT_RECURSIVE),
48 AST_APP_OPTION('u', OPT_UNPARSED),
51 static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
52 char *buf, size_t len)
55 struct ast_flags flags = { 0 };
56 struct ast_cdr *cdr = chan ? chan->cdr : NULL;
57 AST_DECLARE_APP_ARGS(args,
58 AST_APP_ARG(variable);
62 if (ast_strlen_zero(parse))
68 AST_STANDARD_APP_ARGS(args, parse);
70 if (!ast_strlen_zero(args.options))
71 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
73 if (ast_test_flag(&flags, OPT_LAST))
77 ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
78 ast_test_flag(&flags, OPT_RECURSIVE),
79 ast_test_flag(&flags, OPT_UNPARSED));
84 static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
87 struct ast_flags flags = { 0 };
88 AST_DECLARE_APP_ARGS(args,
89 AST_APP_ARG(variable);
93 if (ast_strlen_zero(parse) || !value || !chan)
96 AST_STANDARD_APP_ARGS(args, parse);
98 if (!ast_strlen_zero(args.options))
99 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
101 if (!strcasecmp(args.variable, "accountcode"))
102 ast_cdr_setaccount(chan, value);
103 else if (!strcasecmp(args.variable, "userfield"))
104 ast_cdr_setuserfield(chan, value);
105 else if (!strcasecmp(args.variable, "amaflags"))
106 ast_cdr_setamaflags(chan, value);
108 ast_cdr_setvar(chan->cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
109 /* No need to worry about the u flag, as all fields for which setting
110 * 'u' would do anything are marked as readonly. */
115 static struct ast_custom_function cdr_function = {
117 .synopsis = "Gets or sets a CDR variable",
118 .syntax = "CDR(<name>[,options])",
123 " 'r' searches the entire stack of CDRs on the channel\n"
124 " 'u' retrieves the raw, unprocessed value\n"
125 " For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
126 " values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
127 " otherwise. Similarly, disposition and amaflags will return their raw\n"
128 " integral values.\n"
129 " Here is a list of all the available cdr field names:\n"
130 " clid lastdata disposition\n"
131 " src start amaflags\n"
132 " dst answer accountcode\n"
133 " dcontext end uniqueid\n"
134 " dstchannel duration userfield\n"
135 " lastapp billsec channel\n"
136 " All of the above variables are read-only, except for accountcode,\n"
137 " userfield, and amaflags. You may, however, supply\n"
138 " a name not on the above list, and create your own\n"
139 " variable, whose value can be changed with this function,\n"
140 " and this variable will be stored on the cdr.\n"
141 " raw values for disposition:\n"
146 " raw values for amaflags:\n"
149 " 3 = DOCUMENTATION\n",
152 static int unload_module(void)
154 return ast_custom_function_unregister(&cdr_function);
157 static int load_module(void)
159 return ast_custom_function_register(&cdr_function);
162 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Detail Record (CDR) dialplan function");