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