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$")
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 pres = ast_parse_caller_presentation(data);
00075
00076 if (pres < 0) {
00077 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
00078 (char *) data);
00079 ast_module_user_remove(u);
00080 return 0;
00081 }
00082
00083 chan->cid.cid_pres = pres;
00084 ast_module_user_remove(u);
00085 return 0;
00086 }
00087
00088 static char *app = "SetCallerID";
00089
00090 static char *synopsis = "Set CallerID";
00091
00092 static char *descrip =
00093 " SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
00094 "value. Sets ANI as well if a flag is used. \n";
00095
00096 static int setcallerid_exec(struct ast_channel *chan, void *data)
00097 {
00098 int res = 0;
00099 char *tmp = NULL;
00100 char name[256];
00101 char num[256];
00102 struct ast_module_user *u;
00103 char *opt;
00104 int anitoo = 0;
00105 static int dep_warning = 0;
00106
00107 if (ast_strlen_zero(data)) {
00108 ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
00109 return 0;
00110 }
00111
00112 u = ast_module_user_add(chan);
00113
00114 if (!dep_warning) {
00115 dep_warning = 1;
00116 ast_log(LOG_WARNING, "SetCallerID is deprecated. Please use Set(CALLERID(all)=...) or Set(CALLERID(ani)=...) instead.\n");
00117 }
00118
00119 tmp = ast_strdupa(data);
00120
00121 opt = strchr(tmp, '|');
00122 if (opt) {
00123 *opt = '\0';
00124 opt++;
00125 if (*opt == 'a')
00126 anitoo = 1;
00127 }
00128
00129 ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
00130 ast_set_callerid(chan, num, name, anitoo ? num : NULL);
00131
00132 ast_module_user_remove(u);
00133
00134 return res;
00135 }
00136
00137 static int unload_module(void)
00138 {
00139 int res;
00140
00141 res = ast_unregister_application(app2);
00142 res |= ast_unregister_application(app);
00143
00144 ast_module_user_hangup_all();
00145
00146 return res;
00147 }
00148
00149 static int load_module(void)
00150 {
00151 int res;
00152
00153 res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
00154 res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
00155
00156 return res;
00157 }
00158
00159 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Application");