app_setcallerid.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 114242 $")
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
00075 if (sscanf(data, "%d", &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");