mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
SRV and ENUM fixes (bug #'s 350 and 351)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1606 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
#include <asterisk/logger.h>
|
#include <asterisk/logger.h>
|
||||||
#include <asterisk/channel.h>
|
#include <asterisk/channel.h>
|
||||||
#include <asterisk/pbx.h>
|
#include <asterisk/pbx.h>
|
||||||
|
#include <asterisk/options.h>
|
||||||
|
#include <asterisk/config.h>
|
||||||
#include <asterisk/module.h>
|
#include <asterisk/module.h>
|
||||||
#include <asterisk/enum.h>
|
#include <asterisk/enum.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -35,14 +37,21 @@ static char *synopsis = "Lookup number in ENUM";
|
|||||||
|
|
||||||
static char *descrip =
|
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'. Returns -1 on hangup, or 0 on completion\n"
|
"the variable 'ENUM'. For VoIP URIs this variable will \n"
|
||||||
"regardless of whether the lookup was successful. Currently, the\n"
|
"look like 'TECHNOLOGY/URI' with the appropriate technology.\n"
|
||||||
"enumservices SIP and TEL are recognized. A good SIP entry\n"
|
"Returns -1 on hangup, or 0 on completion regardless of whether the \n"
|
||||||
"will result in normal priority handling, whereas a good TEL entry\n"
|
"lookup was successful. \n"
|
||||||
"will increase the priority by 51 (if existing)\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"
|
"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" ;
|
||||||
|
|
||||||
|
#define ENUM_CONFIG "enum.conf"
|
||||||
|
|
||||||
|
static char h323driver[80];
|
||||||
|
#define H323DRIVERDEFAULT "H323"
|
||||||
|
|
||||||
STANDARD_LOCAL_USER;
|
STANDARD_LOCAL_USER;
|
||||||
|
|
||||||
LOCAL_USER_DECL;
|
LOCAL_USER_DECL;
|
||||||
@@ -73,19 +82,23 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
|
|||||||
c += 4;
|
c += 4;
|
||||||
snprintf(tmp, sizeof(tmp), "SIP/%s", c);
|
snprintf(tmp, sizeof(tmp), "SIP/%s", c);
|
||||||
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
|
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
|
||||||
} else if (!strcasecmp(tech, "H323")) {
|
} else if (!strcasecmp(tech, "h323")) {
|
||||||
c = dest;
|
c = dest;
|
||||||
if (!strncmp(c, "h323:", 5))
|
if (!strncmp(c, "h323:", 5))
|
||||||
c += 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);
|
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
|
||||||
} else if (!strcasecmp(tech, "IAX")) {
|
} else if (!strcasecmp(tech, "iax")) {
|
||||||
c = dest;
|
c = dest;
|
||||||
if (!strncmp(c, "iax:", 4))
|
if (!strncmp(c, "iax:", 4))
|
||||||
c += 4;
|
c += 4;
|
||||||
snprintf(tmp, sizeof(tmp), "IAX/%s", c);
|
snprintf(tmp, sizeof(tmp), "IAX/%s", c);
|
||||||
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
|
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
|
||||||
} else if (!strcasecmp(tech, "IAX2")) {
|
} else if (!strcasecmp(tech, "iax2")) {
|
||||||
c = dest;
|
c = dest;
|
||||||
if (!strncmp(c, "iax2:", 5))
|
if (!strncmp(c, "iax2:", 5))
|
||||||
c += 5;
|
c += 5;
|
||||||
@@ -129,6 +142,28 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
|
|||||||
return res;
|
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)
|
int unload_module(void)
|
||||||
{
|
{
|
||||||
STANDARD_HANGUP_LOCALUSERS;
|
STANDARD_HANGUP_LOCALUSERS;
|
||||||
@@ -137,9 +172,22 @@ int unload_module(void)
|
|||||||
|
|
||||||
int load_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)
|
char *description(void)
|
||||||
{
|
{
|
||||||
return tdesc;
|
return tdesc;
|
||||||
@@ -156,3 +204,4 @@ char *key()
|
|||||||
{
|
{
|
||||||
return ASTERISK_GPL_KEY;
|
return ASTERISK_GPL_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,3 +9,8 @@
|
|||||||
; in the order they are listed here.
|
; in the order they are listed here.
|
||||||
;
|
;
|
||||||
search => e164.arpa
|
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
|
||||||
|
18
enum.c
18
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)) ||
|
if ((!strncasecmp(services, "e2u+sip", 7)) ||
|
||||||
(!strncasecmp(services, "sip+e2u", 7))) {
|
(!strncasecmp(services, "sip+e2u", 7))) {
|
||||||
strncpy(tech, "sip", techsize -1);
|
strncpy(tech, "sip", techsize -1);
|
||||||
} else if ((!strncasecmp(services, "e2u+h323", 7)) ||
|
} else if ((!strncasecmp(services, "e2u+h323", 8)) ||
|
||||||
(!strncasecmp(services, "h323+e2u", 7))) {
|
(!strncasecmp(services, "h323+e2u", 8))) {
|
||||||
strncpy(tech, "h323", techsize -1);
|
strncpy(tech, "h323", techsize -1);
|
||||||
} else if ((!strncasecmp(services, "e2u+iax", 7)) ||
|
} else if ((!strncasecmp(services, "e2u+iax", 7)) ||
|
||||||
(!strncasecmp(services, "iax+e2u", 7))) {
|
(!strncasecmp(services, "iax+e2u", 7))) {
|
||||||
strncpy(tech, "iax", techsize -1);
|
strncpy(tech, "iax", techsize -1);
|
||||||
} else if ((!strncasecmp(services, "e2u+iax2", 7)) ||
|
} else if ((!strncasecmp(services, "e2u+iax2", 8)) ||
|
||||||
(!strncasecmp(services, "iax2+e2u", 7))) {
|
(!strncasecmp(services, "iax2+e2u", 8))) {
|
||||||
strncpy(tech, "iax2", techsize -1);
|
strncpy(tech, "iax2", techsize -1);
|
||||||
} else if ((!strncasecmp(services, "e2u+tel", 7)) ||
|
} else if ((!strncasecmp(services, "e2u+tel", 7)) ||
|
||||||
(!strncasecmp(services, "tel+e2u", 7))) {
|
(!strncasecmp(services, "tel+e2u", 7))) {
|
||||||
strncpy(tech, "tel", techsize -1);
|
strncpy(tech, "tel", techsize -1);
|
||||||
} else if (strncasecmp(services, "e2u+voice:", 10)) {
|
} 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");
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,9 +205,6 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize
|
|||||||
}
|
}
|
||||||
*d = 0;
|
*d = 0;
|
||||||
strncpy(dst, temp, dstsize);
|
strncpy(dst, temp, dstsize);
|
||||||
d = strchr(services, ':');
|
|
||||||
if (d)
|
|
||||||
strncpy(tech, d+1, techsize -1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
srv.c
5
srv.c
@@ -113,9 +113,10 @@ int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, co
|
|||||||
if (chan)
|
if (chan)
|
||||||
ret |= ast_autoservice_stop(chan);
|
ret |= ast_autoservice_stop(chan);
|
||||||
|
|
||||||
if (ret <= 0)
|
if (ret <= 0) {
|
||||||
return ret;
|
|
||||||
strcpy(host, "");
|
strcpy(host, "");
|
||||||
*port = -1;
|
*port = -1;
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user