00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 146838 $")
00031
00032 #include "asterisk/module.h"
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/utils.h"
00036 #include "asterisk/app.h"
00037 #include "asterisk/cdr.h"
00038
00039 enum {
00040 OPT_RECURSIVE = (1 << 0),
00041 OPT_UNPARSED = (1 << 1),
00042 OPT_LAST = (1 << 2),
00043 OPT_SKIPLOCKED = (1 << 3),
00044 } cdr_option_flags;
00045
00046 AST_APP_OPTIONS(cdr_func_options, {
00047 AST_APP_OPTION('l', OPT_LAST),
00048 AST_APP_OPTION('r', OPT_RECURSIVE),
00049 AST_APP_OPTION('s', OPT_SKIPLOCKED),
00050 AST_APP_OPTION('u', OPT_UNPARSED),
00051 });
00052
00053 static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
00054 char *buf, size_t len)
00055 {
00056 char *ret;
00057 struct ast_flags flags = { 0 };
00058 struct ast_cdr *cdr = chan ? chan->cdr : NULL;
00059 AST_DECLARE_APP_ARGS(args,
00060 AST_APP_ARG(variable);
00061 AST_APP_ARG(options);
00062 );
00063
00064 if (ast_strlen_zero(parse))
00065 return -1;
00066
00067 if (!cdr)
00068 return -1;
00069
00070 AST_STANDARD_APP_ARGS(args, parse);
00071
00072 if (!ast_strlen_zero(args.options))
00073 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
00074
00075 if (ast_test_flag(&flags, OPT_LAST))
00076 while (cdr->next)
00077 cdr = cdr->next;
00078
00079 if (ast_test_flag(&flags, OPT_SKIPLOCKED))
00080 while (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED) && cdr->next)
00081 cdr = cdr->next;
00082
00083 ast_cdr_getvar(cdr, args.variable, &ret, buf, len,
00084 ast_test_flag(&flags, OPT_RECURSIVE),
00085 ast_test_flag(&flags, OPT_UNPARSED));
00086
00087 return ret ? 0 : -1;
00088 }
00089
00090 static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
00091 const char *value)
00092 {
00093 struct ast_cdr *cdr = chan ? chan->cdr : NULL;
00094 struct ast_flags flags = { 0 };
00095 AST_DECLARE_APP_ARGS(args,
00096 AST_APP_ARG(variable);
00097 AST_APP_ARG(options);
00098 );
00099
00100 if (ast_strlen_zero(parse) || !value || !chan)
00101 return -1;
00102
00103 if (!cdr)
00104 return -1;
00105
00106 AST_STANDARD_APP_ARGS(args, parse);
00107
00108 if (!ast_strlen_zero(args.options))
00109 ast_app_parse_options(cdr_func_options, &flags, NULL, args.options);
00110
00111 if (ast_test_flag(&flags, OPT_LAST))
00112 while (cdr->next)
00113 cdr = cdr->next;
00114
00115 if (!strcasecmp(args.variable, "accountcode"))
00116 ast_cdr_setaccount(chan, value);
00117 else if (!strcasecmp(args.variable, "userfield"))
00118 ast_cdr_setuserfield(chan, value);
00119 else if (!strcasecmp(args.variable, "amaflags"))
00120 ast_cdr_setamaflags(chan, value);
00121 else
00122 ast_cdr_setvar(cdr, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
00123
00124
00125
00126 return 0;
00127 }
00128
00129 static struct ast_custom_function cdr_function = {
00130 .name = "CDR",
00131 .synopsis = "Gets or sets a CDR variable",
00132 .syntax = "CDR(<name>[,options])",
00133 .read = cdr_read,
00134 .write = cdr_write,
00135 .desc =
00136 "Options:\n"
00137 " 'l' uses the most recent CDR on a channel with multiple records\n"
00138 " 'r' searches the entire stack of CDRs on the channel\n"
00139 " 's' skips any CDR's that are marked 'LOCKED' due to forkCDR() calls.\n"
00140 " (on setting/writing CDR vars only)\n"
00141 " 'u' retrieves the raw, unprocessed value\n"
00142 " For example, 'start', 'answer', and 'end' will be retrieved as epoch\n"
00143 " values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
00144 " otherwise. Similarly, disposition and amaflags will return their raw\n"
00145 " integral values.\n"
00146 " Here is a list of all the available cdr field names:\n"
00147 " clid lastdata disposition\n"
00148 " src start amaflags\n"
00149 " dst answer accountcode\n"
00150 " dcontext end uniqueid\n"
00151 " dstchannel duration userfield\n"
00152 " lastapp billsec channel\n"
00153 " All of the above variables are read-only, except for accountcode,\n"
00154 " userfield, and amaflags. You may, however, supply\n"
00155 " a name not on the above list, and create your own\n"
00156 " variable, whose value can be changed with this function,\n"
00157 " and this variable will be stored on the cdr.\n"
00158 " For setting CDR values, the 'l' flag does not apply to\n"
00159 " setting the accountcode, userfield, or amaflags.\n"
00160 " raw values for disposition:\n"
00161 " 1 = NO ANSWER\n"
00162 " 2 = BUSY\n"
00163 " 3 = FAILED\n"
00164 " 4 = ANSWERED\n"
00165 " raw values for amaflags:\n"
00166 " 1 = OMIT\n"
00167 " 2 = BILLING\n"
00168 " 3 = DOCUMENTATION\n",
00169 };
00170
00171 static int unload_module(void)
00172 {
00173 return ast_custom_function_unregister(&cdr_function);
00174 }
00175
00176 static int load_module(void)
00177 {
00178 return ast_custom_function_register(&cdr_function);
00179 }
00180
00181 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Detail Record (CDR) dialplan function");