Allow enumlookup to return a status variable (bug #4788)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6300 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 20 years ago
parent e415ff3f87
commit 4f37e6b4b0

@ -1,7 +1,7 @@
/* /*
* Asterisk -- A telephony toolkit for Linux. * Asterisk -- A telephony toolkit for Linux.
* *
* Time of day - Report the time of day * Enumlookup - lookup entry in ENUM
* *
* Copyright (C) 1999 - 2005, Digium, Inc. * Copyright (C) 1999 - 2005, Digium, Inc.
* *
@ -42,11 +42,15 @@ static char *descrip =
" EnumLookup(exten): Looks up an extension via ENUM and sets\n" " EnumLookup(exten): Looks up an extension via ENUM and sets\n"
"the variable 'ENUM'. For VoIP URIs this variable will \n" "the variable 'ENUM'. For VoIP URIs this variable will \n"
"look like 'TECHNOLOGY/URI' with the appropriate technology.\n" "look like 'TECHNOLOGY/URI' with the appropriate technology.\n"
"Returns -1 on hangup, or 0 on completion regardless of whether the \n" "Returns -1 on hangup, or 0 on completion\n"
"lookup was successful. \n"
"Currently, the enumservices SIP, H323, IAX, IAX2 and TEL are recognized. \n" "Currently, the enumservices SIP, H323, IAX, IAX2 and TEL are recognized. \n"
"A good SIP, H323, IAX or IAX2 entry will result in normal priority handling, \n" "\nReturns status in the ENUMSTATUS channel variable:\n"
"whereas a good TEL entry will increase the priority by 51 (if existing).\n" " ERROR Failed to do a lookup\n"
" <tech> Technology of the successful lookup: SIP, H323, IAX, IAX2 or TEL\n"
" BADURI Got URI Asterisk does not understand.\n"
"\nOld, depreciated, behaviour:\n"
"\nA SIP, H323, IAX or IAX2 entry will result in normal priority handling, \n"
"whereas a TEL entry will increase the priority by 51 (if existing).\n"
"If the lookup was *not* successful and there exists a priority n + 101,\n" "If the lookup was *not* successful and there exists a priority n + 101,\n"
"then that priority will be taken next.\n" ; "then that priority will be taken next.\n" ;
@ -59,6 +63,7 @@ STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
/*--- enumlookup_exec: Look up number in ENUM and return result */
static int enumlookup_exec(struct ast_channel *chan, void *data) static int enumlookup_exec(struct ast_channel *chan, void *data)
{ {
int res=0; int res=0;
@ -67,9 +72,10 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
char tmp[256]; char tmp[256];
char *c,*t; char *c,*t;
struct localuser *u; struct localuser *u;
if (!data || ast_strlen_zero(data)) { if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n"); ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
res = 1; res = 0;
} }
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
if (!res) { if (!res) {
@ -77,6 +83,14 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
printf("ENUM got '%d'\n", res); printf("ENUM got '%d'\n", res);
} }
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
if (!res) { /* Failed to do a lookup */
/* Look for a "busy" place */
if (option_priority_jumping && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
chan->priority += 100;
pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "ERROR");
return 0;
}
pbx_builtin_setvar_helper(chan, "ENUMSTATUS", tech);
/* Parse it out */ /* Parse it out */
if (res > 0) { if (res > 0) {
if (!strcasecmp(tech, "SIP")) { if (!strcasecmp(tech, "SIP")) {
@ -126,25 +140,21 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
*t = 0; *t = 0;
pbx_builtin_setvar_helper(chan, "ENUM", tmp); pbx_builtin_setvar_helper(chan, "ENUM", tmp);
ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp); ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 51, chan->cid.cid_num)) if (option_priority_jumping && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 51, chan->cid.cid_num))
chan->priority += 50; chan->priority += 50;
else else
res = 0; res = 0;
} }
} else if (!ast_strlen_zero(tech)) { } else if (!ast_strlen_zero(tech)) {
ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech); ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "BADURI");
res = 0; res = 0;
} }
} }
if (!res) { return 0;
/* Look for a "busy" place */
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
chan->priority += 100;
} else if (res > 0)
res = 0;
return res;
} }
/*--- load_config: Load enum.conf and find out how to handle H.323 */
static int load_config(void) static int load_config(void)
{ {
struct ast_config *cfg; struct ast_config *cfg;
@ -165,12 +175,14 @@ static int load_config(void)
} }
/*--- unload_module: Unload this application from PBX */
int unload_module(void) int unload_module(void)
{ {
STANDARD_HANGUP_LOCALUSERS; STANDARD_HANGUP_LOCALUSERS;
return ast_unregister_application(app); return ast_unregister_application(app);
} }
/*--- load_module: Load this application into PBX */
int load_module(void) int load_module(void)
{ {
int res; int res;
@ -183,12 +195,14 @@ int load_module(void)
return(0); return(0);
} }
/*--- reload: Reload configuration file */
int reload(void) int reload(void)
{ {
return(load_config()); return(load_config());
} }
/*--- description: Describe module */
char *description(void) char *description(void)
{ {
return tdesc; return tdesc;

Loading…
Cancel
Save