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 #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
00042 static char *tdesc = "Block Telemarketers with Special Information Tone";
00043
00044 static char *app = "Zapateller";
00045
00046 static char *synopsis = "Block telemarketers with SIT";
00047
00048 static char *descrip =
00049 " Zapateller(options): Generates special information tone to block\n"
00050 "telemarketers from calling you. Options is a pipe-delimited list of\n"
00051 "options. The following options are available:\n"
00052 "'answer' causes the line to be answered before playing the tone,\n"
00053 "'nocallerid' causes Zapateller to only play the tone if there\n"
00054 "is no callerid information available. Options should be separated by |\n"
00055 "characters\n";
00056
00057 STANDARD_LOCAL_USER;
00058
00059 LOCAL_USER_DECL;
00060
00061 static int zapateller_exec(struct ast_channel *chan, void *data)
00062 {
00063 int res = 0;
00064 struct localuser *u;
00065 int answer = 0, nocallerid = 0;
00066 char *c;
00067 char *stringp=NULL;
00068
00069 LOCAL_USER_ADD(u);
00070
00071 stringp=data;
00072 c = strsep(&stringp, "|");
00073 while(!ast_strlen_zero(c)) {
00074 if (!strcasecmp(c, "answer"))
00075 answer = 1;
00076 else if (!strcasecmp(c, "nocallerid"))
00077 nocallerid = 1;
00078
00079 c = strsep(&stringp, "|");
00080 }
00081
00082 ast_stopstream(chan);
00083 if (chan->_state != AST_STATE_UP) {
00084
00085 if (answer)
00086 res = ast_answer(chan);
00087 if (!res) {
00088 res = ast_safe_sleep(chan, 500);
00089 }
00090 }
00091 if (chan->cid.cid_num && nocallerid) {
00092 LOCAL_USER_REMOVE(u);
00093 return res;
00094 }
00095 if (!res)
00096 res = ast_tonepair(chan, 950, 0, 330, 0);
00097 if (!res)
00098 res = ast_tonepair(chan, 1400, 0, 330, 0);
00099 if (!res)
00100 res = ast_tonepair(chan, 1800, 0, 330, 0);
00101 if (!res)
00102 res = ast_tonepair(chan, 0, 0, 1000, 0);
00103 LOCAL_USER_REMOVE(u);
00104 return res;
00105 }
00106
00107 int unload_module(void)
00108 {
00109 int res;
00110
00111 res = ast_unregister_application(app);
00112
00113 STANDARD_HANGUP_LOCALUSERS;
00114
00115 return res;
00116 }
00117
00118 int load_module(void)
00119 {
00120 return ast_register_application(app, zapateller_exec, synopsis, descrip);
00121 }
00122
00123 char *description(void)
00124 {
00125 return tdesc;
00126 }
00127
00128 int usecount(void)
00129 {
00130 int res;
00131 STANDARD_USECOUNT(res);
00132 return res;
00133 }
00134
00135 char *key()
00136 {
00137 return ASTERISK_GPL_KEY;
00138 }