diff --git a/apps/app_enumlookup.c b/apps/app_enumlookup.c index fb0956721dfea311b51e98f81d55bc8696910ab8..22e76012d55619c2761f823f583c3125b23bf8e9 100755 --- a/apps/app_enumlookup.c +++ b/apps/app_enumlookup.c @@ -16,6 +16,8 @@ #include <asterisk/logger.h> #include <asterisk/channel.h> #include <asterisk/pbx.h> +#include <asterisk/options.h> +#include <asterisk/config.h> #include <asterisk/module.h> #include <asterisk/enum.h> #include <stdlib.h> @@ -35,14 +37,21 @@ static char *synopsis = "Lookup number in ENUM"; static char *descrip = " EnumLookup(exten): Looks up an extension via ENUM and sets\n" -"the variable 'ENUM'. Returns -1 on hangup, or 0 on completion\n" -"regardless of whether the lookup was successful. Currently, the\n" -"enumservices SIP and TEL are recognized. A good SIP entry\n" -"will result in normal priority handling, whereas a good TEL entry\n" -"will increase the priority by 51 (if existing)\n" +"the variable 'ENUM'. For VoIP URIs this variable will \n" +"look like 'TECHNOLOGY/URI' with the appropriate technology.\n" +"Returns -1 on hangup, or 0 on completion regardless of whether the \n" +"lookup was successful. \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" +"whereas a good 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" "then that priority will be taken next.\n" ; +#define ENUM_CONFIG "enum.conf" + +static char h323driver[80]; +#define H323DRIVERDEFAULT "H323" + STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -73,19 +82,23 @@ static int enumlookup_exec(struct ast_channel *chan, void *data) c += 4; snprintf(tmp, sizeof(tmp), "SIP/%s", c); pbx_builtin_setvar_helper(chan, "ENUM", tmp); - } else if (!strcasecmp(tech, "H323")) { + } else if (!strcasecmp(tech, "h323")) { c = dest; if (!strncmp(c, "h323:", 5)) c += 5; - snprintf(tmp, sizeof(tmp), "H323/%s", c); + snprintf(tmp, sizeof(tmp), "%s/%s", h323driver, c); +/* do a s!;.*!! on the H323 URI */ + t = strchr(c,';'); + if (t) + *t = 0; pbx_builtin_setvar_helper(chan, "ENUM", tmp); - } else if (!strcasecmp(tech, "IAX")) { + } else if (!strcasecmp(tech, "iax")) { c = dest; if (!strncmp(c, "iax:", 4)) c += 4; snprintf(tmp, sizeof(tmp), "IAX/%s", c); pbx_builtin_setvar_helper(chan, "ENUM", tmp); - } else if (!strcasecmp(tech, "IAX2")) { + } else if (!strcasecmp(tech, "iax2")) { c = dest; if (!strncmp(c, "iax2:", 5)) c += 5; @@ -129,6 +142,28 @@ static int enumlookup_exec(struct ast_channel *chan, void *data) return res; } +static int load_config(void) +{ + struct ast_config *cfg; + char *s; + + ast_log(LOG_WARNING, "reading enum config\n"); + + cfg = ast_load(ENUM_CONFIG); + if (cfg) { + if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) { + strcpy(h323driver, H323DRIVERDEFAULT); + } else { + strcpy(h323driver, s); + } + ast_destroy(cfg); + return 0; + } + ast_log(LOG_WARNING, "Error reading enum config\n"); + return -1; +} + + int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; @@ -137,9 +172,22 @@ int unload_module(void) int load_module(void) { - return ast_register_application(app, enumlookup_exec, synopsis, descrip); + int res; + res = ast_register_application(app, enumlookup_exec, synopsis, descrip); + if (res) + return(res); + if ((res=load_config())) { + return(res); + } + return(0); } +int reload(void) +{ + return(load_config()); +} + + char *description(void) { return tdesc; @@ -156,3 +204,4 @@ char *key() { return ASTERISK_GPL_KEY; } + diff --git a/configs/enum.conf.sample b/configs/enum.conf.sample index d8c412f2c3b444fae5144198b2f6ae98876b5a01..eece818b00e3baa6e600df6d15bf5de229cfc409 100755 --- a/configs/enum.conf.sample +++ b/configs/enum.conf.sample @@ -9,3 +9,8 @@ ; in the order they are listed here. ; search => e164.arpa +; +; As there are more H323 drivers available you have to select to which +; drive a H323 URI will map. Default is "H323". +; +h323driver => H323 diff --git a/enum.c b/enum.c index 601754d9ed2fef729faeb82aff66e75596eba7d8..ce5310f48941dc7d0f4792cb04ee5b3f649eb039 100755 --- a/enum.c +++ b/enum.c @@ -112,20 +112,23 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize if ((!strncasecmp(services, "e2u+sip", 7)) || (!strncasecmp(services, "sip+e2u", 7))) { strncpy(tech, "sip", techsize -1); - } else if ((!strncasecmp(services, "e2u+h323", 7)) || - (!strncasecmp(services, "h323+e2u", 7))) { + } else if ((!strncasecmp(services, "e2u+h323", 8)) || + (!strncasecmp(services, "h323+e2u", 8))) { strncpy(tech, "h323", techsize -1); } else if ((!strncasecmp(services, "e2u+iax", 7)) || (!strncasecmp(services, "iax+e2u", 7))) { strncpy(tech, "iax", techsize -1); - } else if ((!strncasecmp(services, "e2u+iax2", 7)) || - (!strncasecmp(services, "iax2+e2u", 7))) { + } else if ((!strncasecmp(services, "e2u+iax2", 8)) || + (!strncasecmp(services, "iax2+e2u", 8))) { strncpy(tech, "iax2", techsize -1); } else if ((!strncasecmp(services, "e2u+tel", 7)) || (!strncasecmp(services, "tel+e2u", 7))) { strncpy(tech, "tel", techsize -1); - } else if (strncasecmp(services, "e2u+voice:", 10)) { - ast_log(LOG_WARNING, "Services must be e2u+sip, sip+e2u, e2u+h323, h323+e2u, e2u+iax, iax+e2u, e2u+iax2, iax2+e2u, e2u+tel, tel+e2u or e2u+voice:\n"); + } else if (!strncasecmp(services, "e2u+voice:", 10)) { + strncpy(tech, services+10, techsize -1); + } else { + ast_log(LOG_WARNING, + "Services must be e2u+${tech}, ${tech}+e2u, or e2u+voice: where $tech is from (sip, h323, tel, iax, iax2). \n"); return -1; } @@ -202,9 +205,6 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize } *d = 0; strncpy(dst, temp, dstsize); - d = strchr(services, ':'); - if (d) - strncpy(tech, d+1, techsize -1); return 0; } diff --git a/srv.c b/srv.c index 25011ad52ff014614ca1df4a80a24886a5421f53..9a4b7a736202aecba91f4cd2320aca6e9b96f923 100755 --- a/srv.c +++ b/srv.c @@ -113,9 +113,10 @@ int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, co if (chan) ret |= ast_autoservice_stop(chan); - if (ret <= 0) + if (ret <= 0) { + strcpy(host, ""); + *port = -1; return ret; - strcpy(host, ""); - *port = -1; + } return ret; }