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