/* * CallWeaver -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * Portions Copyright (C) 2005, Anthony Minessale II * * See http://www.callweaver.org for more information about * the CallWeaver project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. */ /*! \file * * \brief Call Detail Record related dialplan functions * */ #ifdef HAVE_CONFIG_H #include "confdefs.h" #endif #include #include #include #include #include "callweaver.h" CALLWEAVER_FILE_VERSION("$HeadURL$", "$Revision$") #include "callweaver/channel.h" #include "callweaver/pbx.h" #include "callweaver/logger.h" #include "callweaver/utils.h" #include "callweaver/app.h" #include "callweaver/cdr.h" #include "callweaver/module.h" static void *cdr_function; static const char *cdr_func_name = "CDR"; static const char *cdr_func_synopsis = "Gets or sets a CDR variable"; static const char *cdr_func_syntax = "CDR(name[, options])"; static const char *cdr_func_desc= "Option 'r' searches the entire stack of CDRs on the channel\n"; static char *builtin_function_cdr_read(struct cw_channel *chan, int argc, char **argv, char *buf, size_t len) { char *ret; int recursive = 0; if (argc < 1 || argc > 2 || !argv[0][0]) { cw_log(LOG_ERROR, "Syntax: %s\n", cdr_func_syntax); return NULL; } if (!chan->cdr) return NULL; /* check for a trailing flags argument */ if (argc > 1) { argc--; if (strchr(argv[argc], 'r')) recursive = 1; } cw_cdr_getvar(chan->cdr, argv[0], &ret, buf, len, recursive); return ret; } static void builtin_function_cdr_write(struct cw_channel *chan, int argc, char **argv, const char *value) { int recursive = 0; if (argc < 1 || argc > 2 || !argv[0][0]) { cw_log(LOG_ERROR, "Syntax: %s\n", cdr_func_syntax); return; } /* check for a trailing flags argument */ if (argc > 1) { argc--; if (strchr(argv[argc], 'r')) recursive = 1; } if (!strcasecmp(argv[0], "accountcode")) cw_cdr_setaccount(chan, value); else if (!strcasecmp(argv[0], "userfield")) cw_cdr_setuserfield(chan, value); else if (chan->cdr) cw_cdr_setvar(chan->cdr, argv[0], value, recursive); } static char *tdesc = "CDR related dialplan function"; int unload_module(void) { return cw_unregister_function(cdr_function); } int load_module(void) { cdr_function = cw_register_function(cdr_func_name, builtin_function_cdr_read, builtin_function_cdr_write, cdr_func_synopsis, cdr_func_syntax, cdr_func_desc); return 0; } char *description(void) { return tdesc; } int usecount(void) { return 0; } /* Local Variables: mode: C c-file-style: "linux" indent-tabs-mode: nil End: */