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 #include <stdlib.h>
00026 #include <string.h>
00027 #include <sys/types.h>
00028
00029 #include "asterisk.h"
00030
00031
00032
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/utils.h"
00037 #include "asterisk/app.h"
00038 #include "asterisk/cdr.h"
00039
00040 static char *builtin_function_cdr_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00041 {
00042 char *ret;
00043 char *mydata;
00044 int argc;
00045 char *argv[2];
00046 int recursive = 0;
00047
00048 if (ast_strlen_zero(data))
00049 return NULL;
00050
00051 if (!chan->cdr)
00052 return NULL;
00053
00054 mydata = ast_strdupa(data);
00055 argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
00056
00057
00058 if (argc > 1) {
00059 argc--;
00060 if (strchr(argv[argc], 'r'))
00061 recursive = 1;
00062 }
00063
00064 ast_cdr_getvar(chan->cdr, argv[0], &ret, buf, len, recursive);
00065
00066 return ret;
00067 }
00068
00069 static void builtin_function_cdr_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
00070 {
00071 char *mydata;
00072 int argc;
00073 char *argv[2];
00074 int recursive = 0;
00075
00076 if (ast_strlen_zero(data) || !value)
00077 return;
00078
00079 mydata = ast_strdupa(data);
00080 argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
00081
00082
00083 if (argc > 1) {
00084 argc--;
00085 if (strchr(argv[argc], 'r'))
00086 recursive = 1;
00087 }
00088
00089 if (!strcasecmp(argv[0], "accountcode"))
00090 ast_cdr_setaccount(chan, value);
00091 else if (!strcasecmp(argv[0], "userfield"))
00092 ast_cdr_setuserfield(chan, value);
00093 else if (chan->cdr)
00094 ast_cdr_setvar(chan->cdr, argv[0], value, recursive);
00095 }
00096
00097 #ifndef BUILTIN_FUNC
00098 static
00099 #endif
00100 struct ast_custom_function cdr_function = {
00101 .name = "CDR",
00102 .synopsis = "Gets or sets a CDR variable",
00103 .desc= "Option 'r' searches the entire stack of CDRs on the channel\n",
00104 .syntax = "CDR(<name>[|options])",
00105 .read = builtin_function_cdr_read,
00106 .write = builtin_function_cdr_write,
00107 };
00108