DISA -- Direct Inward System Access Application. More...
#include "asterisk.h"#include <math.h>#include <sys/time.h>#include "asterisk/lock.h"#include "asterisk/file.h"#include "asterisk/channel.h"#include "asterisk/app.h"#include "asterisk/indications.h"#include "asterisk/pbx.h"#include "asterisk/module.h"#include "asterisk/translate.h"#include "asterisk/ulaw.h"#include "asterisk/callerid.h"#include "asterisk/stringfields.h"
Go to the source code of this file.
Enumerations | |
| enum | { NOANSWER_FLAG = (1 << 0), POUND_TO_END_FLAG = (1 << 1) } |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | disa_exec (struct ast_channel *chan, const char *data) |
| static int | load_module (void) |
| static void | play_dialtone (struct ast_channel *chan, char *mailbox) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "DISA (Direct Inward System Access) Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
| static const char | app [] = "DISA" |
| static struct ast_app_option | app_opts [128] = { [ 'n' ] = { .flag = NOANSWER_FLAG }, [ 'p' ] = { .flag = POUND_TO_END_FLAG },} |
| static struct ast_module_info * | ast_module_info = &__mod_info |
DISA -- Direct Inward System Access Application.
Definition in file app_disa.c.
| anonymous enum |
Definition at line 119 of file app_disa.c.
{
NOANSWER_FLAG = (1 << 0),
POUND_TO_END_FLAG = (1 << 1),
};
| static void __reg_module | ( | void | ) | [static] |
Definition at line 417 of file app_disa.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 417 of file app_disa.c.
| static int disa_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Definition at line 147 of file app_disa.c.
References app_opts, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_callerid_split(), AST_CDR_FLAG_POSTED, ast_cdr_reset(), ast_channel_caller(), ast_channel_cdr(), ast_channel_flags(), ast_channel_hangupcause_set(), ast_channel_name(), ast_channel_pbx(), ast_clear_flag, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_explicit_goto(), AST_FLAG_END_DTMF_ONLY, AST_FLAGS_ALL, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_ignore_pattern(), ast_indicate(), ast_log(), ast_matchmore_extension(), AST_MAX_EXTENSION, ast_playtones_stop(), ast_read(), ast_safe_sleep(), ast_set_callerid(), ast_set_flag, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strlen_zero(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_waitfor(), context, ast_frame::data, ast_pbx::dtimeoutms, exten, f, firstdigittimeout, ast_flags::flags, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, mailbox, NOANSWER_FLAG, pbx_builtin_setvar_helper(), play_dialtone(), POUND_TO_END_FLAG, ast_pbx::rtimeoutms, S_COR, ast_frame::subclass, and ast_frame::uint32.
Referenced by load_module().
{
int i = 0, j, k = 0, did_ignore = 0, special_noanswer = 0;
int firstdigittimeout = (ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 20000);
int digittimeout = (ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 10000);
struct ast_flags flags;
char *tmp, exten[AST_MAX_EXTENSION] = "", acctcode[20]="";
char pwline[256];
char ourcidname[256],ourcidnum[256];
struct ast_frame *f;
struct timeval lastdigittime;
int res;
FILE *fp;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(passcode);
AST_APP_ARG(context);
AST_APP_ARG(cid);
AST_APP_ARG(mailbox);
AST_APP_ARG(options);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "DISA requires an argument (passcode/passcode file)\n");
return -1;
}
ast_debug(1, "Digittimeout: %d\n", digittimeout);
ast_debug(1, "Responsetimeout: %d\n", firstdigittimeout);
tmp = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, tmp);
if (ast_strlen_zero(args.context))
args.context = "disa";
if (ast_strlen_zero(args.mailbox))
args.mailbox = "";
if (!ast_strlen_zero(args.options)) {
ast_app_parse_options(app_opts, &flags, NULL, args.options);
} else {
/* Coverity - This uninit_use should be ignored since this macro initializes the flags */
ast_clear_flag(&flags, AST_FLAGS_ALL);
}
ast_debug(1, "Mailbox: %s\n",args.mailbox);
if (!ast_test_flag(&flags, NOANSWER_FLAG)) {
if (ast_channel_state(chan) != AST_STATE_UP) {
/* answer */
ast_answer(chan);
}
} else special_noanswer = 1;
ast_debug(1, "Context: %s\n",args.context);
if (!strcasecmp(args.passcode, "no-password")) {
k |= 1; /* We have the password */
ast_debug(1, "DISA no-password login success\n");
}
lastdigittime = ast_tvnow();
play_dialtone(chan, args.mailbox);
ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
for (;;) {
/* if outa time, give em reorder */
if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > ((k&2) ? digittimeout : firstdigittimeout)) {
ast_debug(1,"DISA %s entry timeout on chan %s\n",
((k&1) ? "extension" : "password"),ast_channel_name(chan));
break;
}
if ((res = ast_waitfor(chan, -1)) < 0) {
ast_debug(1, "Waitfor returned %d\n", res);
continue;
}
if (!(f = ast_read(chan))) {
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
return -1;
}
if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP)) {
if (f->data.uint32)
ast_channel_hangupcause_set(chan, f->data.uint32);
ast_frfree(f);
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
return -1;
}
/* If the frame coming in is not DTMF, just drop it and continue */
if (f->frametype != AST_FRAME_DTMF) {
ast_frfree(f);
continue;
}
j = f->subclass.integer; /* save digit */
ast_frfree(f);
if (!i) {
k |= 2; /* We have the first digit */
ast_playtones_stop(chan);
}
lastdigittime = ast_tvnow();
/* got a DTMF tone */
if (i < AST_MAX_EXTENSION) { /* if still valid number of digits */
if (!(k&1)) { /* if in password state */
if (j == '#') { /* end of password */
/* see if this is an integer */
if (sscanf(args.passcode,"%30d",&j) < 1) { /* nope, it must be a filename */
fp = fopen(args.passcode,"r");
if (!fp) {
ast_log(LOG_WARNING,"DISA password file %s not found on chan %s\n",args.passcode,ast_channel_name(chan));
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
return -1;
}
pwline[0] = 0;
while(fgets(pwline,sizeof(pwline) - 1,fp)) {
if (!pwline[0])
continue;
if (pwline[strlen(pwline) - 1] == '\n')
pwline[strlen(pwline) - 1] = 0;
if (!pwline[0])
continue;
/* skip comments */
if (pwline[0] == '#')
continue;
if (pwline[0] == ';')
continue;
AST_STANDARD_APP_ARGS(args, pwline);
ast_debug(1, "Mailbox: %s\n",args.mailbox);
/* password must be in valid format (numeric) */
if (sscanf(args.passcode,"%30d", &j) < 1)
continue;
/* if we got it */
if (!strcmp(exten,args.passcode)) {
if (ast_strlen_zero(args.context))
args.context = "disa";
if (ast_strlen_zero(args.mailbox))
args.mailbox = "";
break;
}
}
fclose(fp);
}
/* compare the two */
if (strcmp(exten,args.passcode)) {
ast_log(LOG_WARNING,"DISA on chan %s got bad password %s\n",ast_channel_name(chan),exten);
goto reorder;
}
/* password good, set to dial state */
ast_debug(1,"DISA on chan %s password is good\n",ast_channel_name(chan));
play_dialtone(chan, args.mailbox);
k|=1; /* In number mode */
i = 0; /* re-set buffer pointer */
exten[sizeof(acctcode)] = 0;
ast_copy_string(acctcode, exten, sizeof(acctcode));
exten[0] = 0;
ast_debug(1,"Successful DISA log-in on chan %s\n", ast_channel_name(chan));
continue;
}
} else {
if (j == '#') { /* end of extension .. maybe */
if (i == 0
&& (ast_matchmore_extension(chan, args.context, "#", 1,
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))
|| ast_exists_extension(chan, args.context, "#", 1,
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) ) {
/* Let the # be the part of, or the entire extension */
} else {
break;
}
}
}
exten[i++] = j; /* save digit */
exten[i] = 0;
if (!(k&1))
continue; /* if getting password, continue doing it */
/* if this exists */
/* user wants end of number, remove # */
if (ast_test_flag(&flags, POUND_TO_END_FLAG) && j == '#') {
exten[--i] = 0;
break;
}
if (ast_ignore_pattern(args.context, exten)) {
play_dialtone(chan, "");
did_ignore = 1;
} else
if (did_ignore) {
ast_playtones_stop(chan);
did_ignore = 0;
}
/* if can do some more, do it */
if (!ast_matchmore_extension(chan, args.context, exten, 1,
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
break;
}
}
}
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
if (k == 3) {
int recheck = 0;
struct ast_flags cdr_flags = { AST_CDR_FLAG_POSTED };
if (!ast_exists_extension(chan, args.context, exten, 1,
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
pbx_builtin_setvar_helper(chan, "INVALID_EXTEN", exten);
exten[0] = 'i';
exten[1] = '\0';
recheck = 1;
}
if (!recheck
|| ast_exists_extension(chan, args.context, exten, 1,
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
ast_playtones_stop(chan);
/* We're authenticated and have a target extension */
if (!ast_strlen_zero(args.cid)) {
ast_callerid_split(args.cid, ourcidname, sizeof(ourcidname), ourcidnum, sizeof(ourcidnum));
ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
}
if (!ast_strlen_zero(acctcode))
ast_channel_accountcode_set(chan, acctcode);
if (special_noanswer) cdr_flags.flags = 0;
ast_cdr_reset(ast_channel_cdr(chan), &cdr_flags);
ast_explicit_goto(chan, args.context, exten, 1);
return 0;
}
}
/* Received invalid, but no "i" extension exists in the given context */
reorder:
/* Play congestion for a bit */
ast_indicate(chan, AST_CONTROL_CONGESTION);
ast_safe_sleep(chan, 10*1000);
ast_playtones_stop(chan);
return -1;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 411 of file app_disa.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and disa_exec().
{
return ast_register_application_xml(app, disa_exec) ?
AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
}
| static void play_dialtone | ( | struct ast_channel * | chan, |
| char * | mailbox | ||
| ) | [static] |
Definition at line 129 of file app_disa.c.
References ast_app_has_voicemail(), ast_channel_zone(), ast_get_indication_tone(), ast_playtones_start(), ast_tone_zone_sound_unref(), ast_tonepair_start(), and ast_tone_zone_sound::data.
Referenced by disa_exec().
{
struct ast_tone_zone_sound *ts = NULL;
if (ast_app_has_voicemail(mailbox, NULL)) {
ts = ast_get_indication_tone(ast_channel_zone(chan), "dialrecall");
} else {
ts = ast_get_indication_tone(ast_channel_zone(chan), "dial");
}
if (ts) {
ast_playtones_start(chan, 0, ts->data, 0);
ts = ast_tone_zone_sound_unref(ts);
} else {
ast_tonepair_start(chan, 350, 440, 0, 0);
}
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 406 of file app_disa.c.
References ast_unregister_application().
{
return ast_unregister_application(app);
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "DISA (Direct Inward System Access) Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 417 of file app_disa.c.
const char app[] = "DISA" [static] |
Definition at line 117 of file app_disa.c.
struct ast_app_option app_opts[128] = { [ 'n' ] = { .flag = NOANSWER_FLAG }, [ 'p' ] = { .flag = POUND_TO_END_FLAG },} [static] |
Definition at line 127 of file app_disa.c.
Referenced by disa_exec().
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 417 of file app_disa.c.