Sat Aug 6 00:39:21 2011

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  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 211528 $")
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/image.h"
00044 #include "asterisk/callerid.h"
00045 
00046 static char *app2 = "SetCallerPres";
00047 
00048 static char *synopsis2 = "Set CallerID Presentation";
00049 
00050 
00051 static char *descrip2 = 
00052 "  SetCallerPres(presentation): Set Caller*ID presentation on a call.\n"
00053 "  Valid presentations are:\n"
00054 "\n"
00055 "      allowed_not_screened    : Presentation Allowed, Not Screened\n"
00056 "      allowed_passed_screen   : Presentation Allowed, Passed Screen\n" 
00057 "      allowed_failed_screen   : Presentation Allowed, Failed Screen\n" 
00058 "      allowed                 : Presentation Allowed, Network Number\n"
00059 "      prohib_not_screened     : Presentation Prohibited, Not Screened\n" 
00060 "      prohib_passed_screen    : Presentation Prohibited, Passed Screen\n"
00061 "      prohib_failed_screen    : Presentation Prohibited, Failed Screen\n"
00062 "      prohib                  : Presentation Prohibited, Network Number\n"
00063 "      unavailable             : Number Unavailable\n"
00064 "\n"
00065 ;
00066 
00067 static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
00068 {
00069    struct ast_module_user *u;
00070    int pres = -1;
00071 
00072    u = ast_module_user_add(chan);
00073 
00074    /* For interface consistency, permit the argument to be specified as a number */
00075    if (sscanf(data, "%30d", &pres) != 1 || pres < 0 || pres > 255 || (pres & 0x9c)) {
00076       pres = ast_parse_caller_presentation(data);
00077    }
00078 
00079    if (pres < 0) {
00080       ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
00081          (char *) data);
00082       ast_module_user_remove(u);
00083       return 0;
00084    }
00085    
00086    chan->cid.cid_pres = pres;
00087    ast_module_user_remove(u);
00088    return 0;
00089 }
00090 
00091 static char *app = "SetCallerID";
00092 
00093 static char *synopsis = "Set CallerID";
00094 
00095 static char *descrip = 
00096 "  SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
00097 "value.  Sets ANI as well if a flag is used. \n";
00098 
00099 static int setcallerid_exec(struct ast_channel *chan, void *data)
00100 {
00101    int res = 0;
00102    char *tmp = NULL;
00103    char name[256];
00104    char num[256];
00105    struct ast_module_user *u;
00106    char *opt;
00107    int anitoo = 0;
00108    static int dep_warning = 0;
00109 
00110    if (ast_strlen_zero(data)) {
00111       ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
00112       return 0;
00113    }
00114    
00115    u = ast_module_user_add(chan);
00116 
00117    if (!dep_warning) {
00118       dep_warning = 1;
00119       ast_log(LOG_WARNING, "SetCallerID is deprecated.  Please use Set(CALLERID(all)=...) or Set(CALLERID(ani)=...) instead.\n");
00120    }
00121 
00122    tmp = ast_strdupa(data);
00123    
00124    opt = strchr(tmp, '|');
00125    if (opt) {
00126       *opt = '\0';
00127       opt++;
00128       if (*opt == 'a')
00129          anitoo = 1;
00130    }
00131    
00132    ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
00133    ast_set_callerid(chan, num, name, anitoo ? num : NULL);
00134 
00135    ast_module_user_remove(u);
00136    
00137    return res;
00138 }
00139 
00140 static int unload_module(void)
00141 {
00142    int res;
00143 
00144    res = ast_unregister_application(app2);
00145    res |= ast_unregister_application(app);
00146 
00147    ast_module_user_hangup_all();
00148 
00149    return res;
00150 }
00151 
00152 static int load_module(void)
00153 {
00154    int res;
00155    
00156    res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
00157    res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
00158 
00159    return res;
00160 }
00161 
00162 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Application");

Generated on Sat Aug 6 00:39:21 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7