Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:48 2009

## Asterisk developer's documentation

# app_setcallerid.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  * Mark Spencer <markster@digium.com>
    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 App to set callerid
    00022  *
    00023  * \ingroup applications
    00024  */
    00025
    00026 #include <stdlib.h>
    00027 #include <stdio.h>
    00028 #include <string.h>
    00029
    00030 #include "asterisk.h"
    00031
    00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
    00033
    00034 #include "asterisk/lock.h"
    00035 #include "asterisk/file.h"
    00036 #include "asterisk/logger.h"
    00037 #include "asterisk/channel.h"
    00038 #include "asterisk/pbx.h"
    00039 #include "asterisk/module.h"
    00040 #include "asterisk/translate.h"
    00041 #include "asterisk/image.h"
    00042 #include "asterisk/callerid.h"
    00043
    00044 static char *app2 = "SetCallerPres";
    00045
    00046 static char *synopsis2 = "Set CallerID Presentation";
    00047
    00048 STANDARD_LOCAL_USER;
    00049
    00050 LOCAL_USER_DECL;
    00051
    00052 static char *descrip2 =
    00053 "  SetCallerPres(presentation): Set Caller*ID presentation on a call.\n"
    00054 "  Valid presentations are:\n"
    00055 "\n"
    00056 "      allowed_not_screened    : Presentation Allowed, Not Screened\n"
    00057 "      allowed_passed_screen   : Presentation Allowed, Passed Screen\n"
    00058 "      allowed_failed_screen   : Presentation Allowed, Failed Screen\n"
    00059 "      allowed                 : Presentation Allowed, Network Number\n"
    00060 "      prohib_not_screened     : Presentation Prohibited, Not Screened\n"
    00061 "      prohib_passed_screen    : Presentation Prohibited, Passed Screen\n"
    00062 "      prohib_failed_screen    : Presentation Prohibited, Failed Screen\n"
    00063 "      prohib                  : Presentation Prohibited, Network Number\n"
    00064 "      unavailable             : Number Unavailable\n"
    00065 "\n"
    00066 ;
    00067
    00068 static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
    00069 {
    00070    struct localuser *u;
    00071    int pres = -1;
    00072
    00073    LOCAL_USER_ADD(u);
    00074
    00075    pres = ast_parse_caller_presentation(data);
    00076
    00077    if (pres < 0) {
    00078       ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
    00079          (char *) data);
    00080       LOCAL_USER_REMOVE(u);
    00081       return 0;
    00082    }
    00083
    00084    chan->cid.cid_pres = pres;
    00085    LOCAL_USER_REMOVE(u);
    00086    return 0;
    00087 }
    00088
    00089
    00090
    00091 static char *tdesc = "Set CallerID Application";
    00092
    00093 static char *app = "SetCallerID";
    00094
    00095 static char *synopsis = "Set CallerID";
    00096
    00097 static char *descrip =
    00098 "  SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
    00099 "value.  Sets ANI as well if a flag is used. \n";
    00100
    00101 static int setcallerid_exec(struct ast_channel *chan, void *data)
    00102 {
    00103    int res = 0;
    00104    char *tmp = NULL;
    00105    char name[256];
    00106    char num[256];
    00107    struct localuser *u;
    00108    char *opt;
    00109    int anitoo = 0;
    00110
    00111    if (ast_strlen_zero(data)) {
    00112       ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
    00113       return 0;
    00114    }
    00115
    00116    LOCAL_USER_ADD(u);
    00117
    00118    tmp = ast_strdupa(data);
    00119    if (!tmp) {
    00120       ast_log(LOG_ERROR, "Out of memory\n");
    00121       LOCAL_USER_REMOVE(u);
    00122       return -1;
    00123    }
    00124
    00125    opt = strchr(tmp, '|');
    00126    if (opt) {
    00127       *opt = '\0';
    00128       opt++;
    00129       if (*opt == 'a')
    00130          anitoo = 1;
    00131    }
    00132
    00133    ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
    00134    ast_set_callerid(chan, num, name, anitoo ? num : NULL);
    00135
    00136    LOCAL_USER_REMOVE(u);
    00137
    00138    return res;
    00139 }
    00140
    00141 int unload_module(void)
    00142 {
    00143    int res;
    00144
    00145    res = ast_unregister_application(app2);
    00146    res |= ast_unregister_application(app);
    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(app2, setcallerid_pres_exec, synopsis2, descrip2);
    00158    res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
    00159
    00160    return res;
    00161 }
    00162
    00163 char *description(void)
    00164 {
    00165    return tdesc;
    00166 }
    00167
    00168 int usecount(void)
    00169 {
    00170    int res;
    00171    STANDARD_USECOUNT(res);
    00172    return res;
    00173 }
    00174
    00175 char *key()
    00176 {
    00177    return ASTERISK_GPL_KEY;
    00178 }