Modify the main page of the doxygen documentation to link to a new page dedicated
[asterisk-bristuff.git] / funcs / func_cdr.c
blob3ea1a300831661daa8720e8635890976f515028b
1 /*
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.
19 /*! \file
21 * \brief Call Detail Record related dialplan functions
23 * \author Anthony Minessale II
25 * \ingroup functions
28 #include "asterisk.h"
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"
39 enum {
40 OPT_RECURSIVE = (1 << 0),
41 OPT_UNPARSED = (1 << 1),
42 OPT_LAST = (1 << 2),
43 OPT_SKIPLOCKED = (1 << 3),
44 } cdr_option_flags;
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),
51 });
53 static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
54 char *buf, size_t len)
56 char *ret;
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);
61 AST_APP_ARG(options);
64 if (ast_strlen_zero(parse))
65 return -1;
67 if (!cdr)
68 return -1;
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))
76 while (cdr->next)
77 cdr = cdr->next;
79 if (ast_test_flag(&flags, OPT_SKIPLOCKED))
80 while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next)
81 cdr = 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));
87 return 0;
90 static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
91 const char *value)
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);
97 AST_APP_ARG(options);
100 if (ast_strlen_zero(parse) || !value || !chan)
101 return -1;
103 if (!cdr)
104 return -1;
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))
112 while (cdr->next)
113 cdr = cdr->next;
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);
121 else
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. */
126 return 0;
129 static struct ast_custom_function cdr_function = {
130 .name = "CDR",
131 .synopsis = "Gets or sets a CDR variable",
132 .syntax = "CDR(<name>[,options])",
133 .read = cdr_read,
134 .write = cdr_write,
135 .desc =
136 "Options:\n"
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"
161 " 1 = NO ANSWER\n"
162 " 2 = BUSY\n"
163 " 3 = FAILED\n"
164 " 4 = ANSWERED\n"
165 " raw values for amaflags:\n"
166 " 1 = OMIT\n"
167 " 2 = BILLING\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");