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
28 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
33 #include <sys/types.h>
35 #include "asterisk/module.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/utils.h"
40 #include "asterisk/app.h"
41 #include "asterisk/cdr.h"
44 OPT_RECURSIVE
= (1 << 0),
45 OPT_UNPARSED
= (1 << 1),
47 OPT_SKIPLOCKED
= (1 << 3),
50 AST_APP_OPTIONS(cdr_func_options
, {
51 AST_APP_OPTION('l', OPT_LAST
),
52 AST_APP_OPTION('r', OPT_RECURSIVE
),
53 AST_APP_OPTION('s', OPT_SKIPLOCKED
),
54 AST_APP_OPTION('u', OPT_UNPARSED
),
57 static int cdr_read(struct ast_channel
*chan
, char *cmd
, char *parse
,
58 char *buf
, size_t len
)
61 struct ast_flags flags
= { 0 };
62 struct ast_cdr
*cdr
= chan
? chan
->cdr
: NULL
;
63 AST_DECLARE_APP_ARGS(args
,
64 AST_APP_ARG(variable
);
68 if (ast_strlen_zero(parse
))
74 AST_STANDARD_APP_ARGS(args
, parse
);
76 if (!ast_strlen_zero(args
.options
))
77 ast_app_parse_options(cdr_func_options
, &flags
, NULL
, args
.options
);
79 if (ast_test_flag(&flags
, OPT_LAST
))
83 if (ast_test_flag(&flags
, OPT_SKIPLOCKED
))
84 while (ast_test_flag(cdr
, AST_CDR_FLAG_LOCKED
) && cdr
->next
)
87 ast_cdr_getvar(cdr
, args
.variable
, &ret
, buf
, len
,
88 ast_test_flag(&flags
, OPT_RECURSIVE
),
89 ast_test_flag(&flags
, OPT_UNPARSED
));
94 static int cdr_write(struct ast_channel
*chan
, char *cmd
, char *parse
,
97 struct ast_cdr
*cdr
= chan
? chan
->cdr
: NULL
;
98 struct ast_flags flags
= { 0 };
99 AST_DECLARE_APP_ARGS(args
,
100 AST_APP_ARG(variable
);
101 AST_APP_ARG(options
);
104 if (ast_strlen_zero(parse
) || !value
|| !chan
)
110 AST_STANDARD_APP_ARGS(args
, parse
);
112 if (!ast_strlen_zero(args
.options
))
113 ast_app_parse_options(cdr_func_options
, &flags
, NULL
, args
.options
);
115 if (ast_test_flag(&flags
, OPT_LAST
))
119 if (!strcasecmp(args
.variable
, "accountcode")) /* the 'l' flag doesn't apply to setting the accountcode, userfield, or amaflags */
120 ast_cdr_setaccount(chan
, value
);
121 else if (!strcasecmp(args
.variable
, "userfield"))
122 ast_cdr_setuserfield(chan
, value
);
123 else if (!strcasecmp(args
.variable
, "amaflags"))
124 ast_cdr_setamaflags(chan
, value
);
126 ast_cdr_setvar(cdr
, args
.variable
, value
, ast_test_flag(&flags
, OPT_RECURSIVE
));
127 /* No need to worry about the u flag, as all fields for which setting
128 * 'u' would do anything are marked as readonly. */
133 static struct ast_custom_function cdr_function
= {
135 .synopsis
= "Gets or sets a CDR variable",
136 .syntax
= "CDR(<name>[|options])",
141 " 'l' uses the most recent CDR on a channel with multiple records\n"
142 " 'r' searches the entire stack of CDRs on the channel\n"
143 " 's' skips any CDR's that are marked 'LOCKED' due to forkCDR() calls.\n"
144 " (on setting/writing CDR vars only)\n"
145 " 'u' retrieves the raw, unprocessed value\n"
146 " For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
147 " values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
148 " otherwise. Similarly, disposition and amaflags will return their raw\n"
149 " integral values.\n"
150 " Here is a list of all the available cdr field names:\n"
151 " clid lastdata disposition\n"
152 " src start amaflags\n"
153 " dst answer accountcode\n"
154 " dcontext end uniqueid\n"
155 " dstchannel duration userfield\n"
156 " lastapp billsec channel\n"
157 " All of the above variables are read-only, except for accountcode,\n"
158 " userfield, and amaflags. You may, however, supply\n"
159 " a name not on the above list, and create your own\n"
160 " variable, whose value can be changed with this function,\n"
161 " and this variable will be stored on the cdr.\n"
162 " For setting CDR values, the 'l' flag does not apply to\n"
163 " setting the accountcode, userfield, or amaflags.\n"
164 " raw values for disposition:\n"
169 " raw values for amaflags:\n"
172 " 3 = DOCUMENTATION\n",
175 static int unload_module(void)
177 return ast_custom_function_unregister(&cdr_function
);
180 static int load_module(void)
182 return ast_custom_function_register(&cdr_function
);
185 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "CDR dialplan function");