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),
43 OPT_SKIPLOCKED
= (1 << 3),
46 AST_APP_OPTIONS(cdr_func_options
, {
47 AST_APP_OPTION('l', OPT_LAST
),
48 AST_APP_OPTION('r', OPT_RECURSIVE
),
49 AST_APP_OPTION('s', OPT_SKIPLOCKED
),
50 AST_APP_OPTION('u', OPT_UNPARSED
),
53 static int cdr_read(struct ast_channel
*chan
, const char *cmd
, char *parse
,
54 char *buf
, size_t len
)
57 struct ast_flags flags
= { 0 };
58 struct ast_cdr
*cdr
= chan
? chan
->cdr
: NULL
;
59 AST_DECLARE_APP_ARGS(args
,
60 AST_APP_ARG(variable
);
64 if (ast_strlen_zero(parse
))
70 AST_STANDARD_APP_ARGS(args
, parse
);
72 if (!ast_strlen_zero(args
.options
))
73 ast_app_parse_options(cdr_func_options
, &flags
, NULL
, args
.options
);
75 if (ast_test_flag(&flags
, OPT_LAST
))
79 if (ast_test_flag(&flags
, OPT_SKIPLOCKED
))
80 while (ast_test_flag(cdr
, AST_CDR_FLAG_LOCKED
) && cdr
->next
)
83 ast_cdr_getvar(cdr
, args
.variable
, &ret
, buf
, len
,
84 ast_test_flag(&flags
, OPT_RECURSIVE
),
85 ast_test_flag(&flags
, OPT_UNPARSED
));
90 static int cdr_write(struct ast_channel
*chan
, const char *cmd
, char *parse
,
93 struct ast_cdr
*cdr
= chan
? chan
->cdr
: NULL
;
94 struct ast_flags flags
= { 0 };
95 AST_DECLARE_APP_ARGS(args
,
96 AST_APP_ARG(variable
);
100 if (ast_strlen_zero(parse
) || !value
|| !chan
)
106 AST_STANDARD_APP_ARGS(args
, parse
);
108 if (!ast_strlen_zero(args
.options
))
109 ast_app_parse_options(cdr_func_options
, &flags
, NULL
, args
.options
);
111 if (ast_test_flag(&flags
, OPT_LAST
))
115 if (!strcasecmp(args
.variable
, "accountcode")) /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */
116 ast_cdr_setaccount(chan
, value
);
117 else if (!strcasecmp(args
.variable
, "userfield"))
118 ast_cdr_setuserfield(chan
, value
);
119 else if (!strcasecmp(args
.variable
, "amaflags"))
120 ast_cdr_setamaflags(chan
, value
);
122 ast_cdr_setvar(cdr
, args
.variable
, value
, ast_test_flag(&flags
, OPT_RECURSIVE
));
123 /* No need to worry about the u flag, as all fields for which setting
124 * 'u' would do anything are marked as readonly. */
129 static struct ast_custom_function cdr_function
= {
131 .synopsis
= "Gets or sets a CDR variable",
132 .syntax
= "CDR(<name>[,options])",
137 " 'l' uses the most recent CDR on a channel with multiple records\n"
138 " 'r' searches the entire stack of CDRs on the channel\n"
139 " 's' skips any CDR's that are marked 'LOCKED' due to forkCDR() calls.\n"
140 " (on setting/writing CDR vars only)\n"
141 " 'u' retrieves the raw, unprocessed value\n"
142 " For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
143 " values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
144 " otherwise. Similarly, disposition and amaflags will return their raw\n"
145 " integral values.\n"
146 " Here is a list of all the available cdr field names:\n"
147 " clid lastdata disposition\n"
148 " src start amaflags\n"
149 " dst answer accountcode\n"
150 " dcontext end uniqueid\n"
151 " dstchannel duration userfield\n"
152 " lastapp billsec channel\n"
153 " All of the above variables are read-only, except for accountcode,\n"
154 " userfield, and amaflags. You may, however, supply\n"
155 " a name not on the above list, and create your own\n"
156 " variable, whose value can be changed with this function,\n"
157 " and this variable will be stored on the cdr.\n"
158 " For setting CDR values, the 'l' flag does not apply to\n"
159 " setting the accountcode, userfield, or amaflags.\n"
160 " raw values for disposition:\n"
165 " raw values for amaflags:\n"
168 " 3 = DOCUMENTATION\n",
171 static int unload_module(void)
173 return ast_custom_function_unregister(&cdr_function
);
176 static int load_module(void)
178 return ast_custom_function_register(&cdr_function
);
181 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Call Detail Record (CDR) dialplan function");