Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:48 2009

## Asterisk developer's documentation

# app_setcdruserfield.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  * Justin Huff <jjhuff@mspin.net>
    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 Applictions connected with CDR engine
    00022  *
    00023  * \ingroup applications
    00024  */
    00025
    00026 #include <sys/types.h>
    00027 #include <stdlib.h>
    00028 #include <string.h>
    00029
    00030 #include "asterisk.h"
    00031
    00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
    00033
    00034 #include "asterisk/channel.h"
    00035 #include "asterisk/cdr.h"
    00036 #include "asterisk/module.h"
    00037 #include "asterisk/pbx.h"
    00038 #include "asterisk/logger.h"
    00039 #include "asterisk/config.h"
    00040 #include "asterisk/manager.h"
    00041 #include "asterisk/utils.h"
    00042
    00043
    00044 static char *tdesc = "CDR user field apps";
    00045
    00046 static char *setcdruserfield_descrip =
    00047                "[Synopsis]\n"
    00048                "SetCDRUserField(value)\n\n"
    00049                "[Description]\n"
    00050                "SetCDRUserField(value): Set the CDR 'user field' to value\n"
    00051                "       The Call Data Record (CDR) user field is an extra field you\n"
    00052                "       can use for data not stored anywhere else in the record.\n"
    00053                "       CDR records can be used for billing or storing other arbitrary data\n"
    00054                "       (I.E. telephone survey responses)\n"
    00055                "       Also see AppendCDRUserField().\n";
    00056
    00057
    00058 static char *setcdruserfield_app = "SetCDRUserField";
    00059 static char *setcdruserfield_synopsis = "Set the CDR user field";
    00060
    00061 static char *appendcdruserfield_descrip =
    00062                "[Synopsis]\n"
    00063                "AppendCDRUserField(value)\n\n"
    00064                "[Description]\n"
    00065                "AppendCDRUserField(value): Append value to the CDR user field\n"
    00066                "       The Call Data Record (CDR) user field is an extra field you\n"
    00067                "       can use for data not stored anywhere else in the record.\n"
    00068                "       CDR records can be used for billing or storing other arbitrary data\n"
    00069                "       (I.E. telephone survey responses)\n"
    00070                "       Also see SetCDRUserField().\n";
    00071
    00072 static char *appendcdruserfield_app = "AppendCDRUserField";
    00073 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
    00074
    00075 STANDARD_LOCAL_USER;
    00076
    00077 LOCAL_USER_DECL;
    00078
    00079 static int action_setcdruserfield(struct mansession *s, struct message *m)
    00080 {
    00081    struct ast_channel *c = NULL;
    00082    char *userfield = astman_get_header(m, "UserField");
    00083    char *channel = astman_get_header(m, "Channel");
    00084    char *append = astman_get_header(m, "Append");
    00085
    00086    if (ast_strlen_zero(channel)) {
    00087       astman_send_error(s, m, "No Channel specified");
    00088       return 0;
    00089    }
    00090    if (ast_strlen_zero(userfield)) {
    00091       astman_send_error(s, m, "No UserField specified");
    00092       return 0;
    00093    }
    00094    c = ast_get_channel_by_name_locked(channel);
    00095    if (!c) {
    00096       astman_send_error(s, m, "No such channel");
    00097       return 0;
    00098    }
    00099    if (ast_true(append))
    00100       ast_cdr_appenduserfield(c, userfield);
    00101    else
    00102       ast_cdr_setuserfield(c, userfield);
    00103    ast_mutex_unlock(&c->lock);
    00104    astman_send_ack(s, m, "CDR Userfield Set");
    00105    return 0;
    00106 }
    00107
    00108 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
    00109 {
    00110    struct localuser *u;
    00111    int res = 0;
    00112
    00113    LOCAL_USER_ADD(u);
    00114
    00115    if (chan->cdr && data) {
    00116       ast_cdr_setuserfield(chan, (char*)data);
    00117    }
    00118
    00119    LOCAL_USER_REMOVE(u);
    00120
    00121    return res;
    00122 }
    00123
    00124 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
    00125 {
    00126    struct localuser *u;
    00127    int res = 0;
    00128
    00129    LOCAL_USER_ADD(u);
    00130
    00131    if (chan->cdr && data) {
    00132       ast_cdr_appenduserfield(chan, (char*)data);
    00133    }
    00134
    00135    LOCAL_USER_REMOVE(u);
    00136
    00137    return res;
    00138 }
    00139
    00140 int unload_module(void)
    00141 {
    00142    int res;
    00143
    00144    res = ast_unregister_application(setcdruserfield_app);
    00145    res |= ast_unregister_application(appendcdruserfield_app);
    00146    res |= ast_manager_unregister("SetCDRUserField");
    00147
    00148    STANDARD_HANGUP_LOCALUSERS;
    00149
    00150    return res;
    00151 }
    00152
    00153 int load_module(void)
    00154 {
    00155    int res;
    00156
    00157    res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
    00158    res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
    00159    res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
    00160
    00161    return res;
    00162 }
    00163
    00164 char *description(void)
    00165 {
    00166    return tdesc;
    00167 }
    00168
    00169 int usecount(void)
    00170 {
    00171    int res;
    00172    STANDARD_USECOUNT(res);
    00173    return res;
    00174 }
    00175
    00176 char *key()
    00177 {
    00178    return ASTERISK_GPL_KEY;
    00179 }