Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:54 2009

## 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: 61680 $") */
    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 ? chan->cdr : NULL;
    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    /* check for a trailing flags argument */
    00059    if (argc > 1) {
    00060       argc--;
    00061       if (strchr(argv[argc], 'r'))
    00062          recursive = 1;
    00063    }
    00064
    00065    /* Find last entry */
    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 || !chan)
    00082       return;
    00083
    00084    mydata = ast_strdupa(data);
    00085    argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
    00086
    00087    /* check for a trailing flags argument */
    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