Sat Mar 24 23:26:04 2007

Asterisk developer's documentation


func_cdr.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Portions Copyright (C) 2005, Anthony Minessale II
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief  Call Detail Record related dialplan functions
00022  * 
00023  */
00024 
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <sys/types.h>
00028 
00029 #include "asterisk.h"
00030 
00031 /* ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $") */
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    /* check for a trailing flags argument */
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    /* check for a trailing flags argument */
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 

Generated on Sat Mar 24 23:26:04 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6