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 struct ast_cdr *cdr = chan->cdr;
00048
00049 if (ast_strlen_zero(data))
00050 return NULL;
00051
00052 if (!cdr)
00053 return NULL;
00054
00055 mydata = ast_strdupa(data);
00056 argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
00057
00058
00059 if (argc > 1) {
00060 argc--;
00061 if (strchr(argv[argc], 'r'))
00062 recursive = 1;
00063 }
00064
00065
00066 while (cdr->next)
00067 cdr = cdr->next;
00068
00069 ast_cdr_getvar(cdr, argv[0], &ret, buf, len, recursive);
00070
00071 return ret;
00072 }
00073
00074 static void builtin_function_cdr_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
00075 {
00076 char *mydata;
00077 int argc;
00078 char *argv[2];
00079 int recursive = 0;
00080
00081 if (ast_strlen_zero(data) || !value)
00082 return;
00083
00084 mydata = ast_strdupa(data);
00085 argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
00086
00087
00088 if (argc > 1) {
00089 argc--;
00090 if (strchr(argv[argc], 'r'))
00091 recursive = 1;
00092 }
00093
00094 if (!strcasecmp(argv[0], "accountcode"))
00095 ast_cdr_setaccount(chan, value);
00096 else if (!strcasecmp(argv[0], "userfield"))
00097 ast_cdr_setuserfield(chan, value);
00098 else if (chan->cdr)
00099 ast_cdr_setvar(chan->cdr, argv[0], value, recursive);
00100 }
00101
00102 #ifndef BUILTIN_FUNC
00103 static
00104 #endif
00105 struct ast_custom_function cdr_function = {
00106 .name = "CDR",
00107 .synopsis = "Gets or sets a CDR variable",
00108 .desc= "Option 'r' searches the entire stack of CDRs on the channel\n",
00109 .syntax = "CDR(<name>[|options])",
00110 .read = builtin_function_cdr_read,
00111 .write = builtin_function_cdr_write,
00112 };
00113