Issue #80898 - Restoring func_enum (otmar)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@46635 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Olle Johansson 19 years ago
parent 1aa8c2cffc
commit f003df1315

@ -65,6 +65,7 @@ static int function_enum(struct ast_channel *chan, char *cmd, char *data,
char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = ""; char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
struct ast_module_user *u; struct ast_module_user *u;
char *s, *p; char *s, *p;
unsigned int record = 1;
buf[0] = '\0'; buf[0] = '\0';
@ -88,7 +89,10 @@ static int function_enum(struct ast_channel *chan, char *cmd, char *data,
args.zone = "e164.arpa"; args.zone = "e164.arpa";
if (!args.options) if (!args.options)
args.options = "1"; args.options = "";
if (args.record)
record = atoi(args.record);
/* strip any '-' signs from number */ /* strip any '-' signs from number */
for (s = p = args.number; *s; s++) { for (s = p = args.number; *s; s++) {
@ -100,7 +104,7 @@ static int function_enum(struct ast_channel *chan, char *cmd, char *data,
} }
res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone,
args.options); args.options, record);
p = strchr(dest, ':'); p = strchr(dest, ':');
if (p && strcasecmp(tech, "ALL")) if (p && strcasecmp(tech, "ALL"))

@ -35,9 +35,11 @@
If you need any record, then set it to empty string If you need any record, then set it to empty string
\param maxtech Max length \param maxtech Max length
\param suffix Zone suffix (if is NULL then use enum.conf 'search' variable) \param suffix Zone suffix (if is NULL then use enum.conf 'search' variable)
\param options Options ('c' to count number of NAPTR RR, or number - the position of required RR in the answer list \param options Options ('c' to count number of NAPTR RR)
\param record The position of required RR in the answer list
*/ */
int ast_get_enum(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology, int maxtech, char* suffix, char* options); int ast_get_enum(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology,
int maxtech, char* suffix, char* options, unsigned int record);
/*! \brief Lookup DNS TXT record (used by app TXTCIDnum /*! \brief Lookup DNS TXT record (used by app TXTCIDnum
\param chan Channel \param chan Channel

@ -387,7 +387,7 @@ static int enum_callback(void *context, unsigned char *answer, int len, unsigned
} }
/*! \brief ENUM lookup */ /*! \brief ENUM lookup */
int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char* suffix, char* options) int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char* suffix, char* options, unsigned int record)
{ {
struct enum_context context; struct enum_context context;
char tmp[259 + 512]; char tmp[259 + 512];
@ -412,7 +412,7 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
context.tech = tech; context.tech = tech;
context.techlen = techlen; context.techlen = techlen;
context.options = 0; context.options = 0;
context.position = 1; context.position = record;
context.naptr_rrs = NULL; context.naptr_rrs = NULL;
context.naptr_rrs_count = 0; context.naptr_rrs_count = 0;
@ -420,13 +420,12 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
if (*options == 'c') { if (*options == 'c') {
context.options = ENUMLOOKUP_OPTIONS_COUNT; context.options = ENUMLOOKUP_OPTIONS_COUNT;
context.position = 0; context.position = 0;
} else {
context.position = atoi(options);
if (context.position < 1)
context.position = 1;
} }
} }
ast_log(LOG_DEBUG, "ast_get_enum(): n='%s', tech='%s', suffix='%s', options='%d', record='%d'\n",
number, tech, suffix, context.options, context.position);
if (pos > 128) if (pos > 128)
pos = 128; pos = 128;
@ -466,6 +465,12 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
if (chan && ast_autoservice_start(chan) < 0) if (chan && ast_autoservice_start(chan) < 0)
return -1; return -1;
if(suffix) {
ast_copy_string(tmp + newpos, suffix, sizeof(tmp) - newpos);
ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback);
ast_log(LOG_DEBUG, "ast_get_enum: ast_search_dns(%s) returned %d\n", tmp, ret);
} else {
ret = -1; /* this is actually dead code since the demise of app_enum.c */
for (;;) { for (;;) {
ast_mutex_lock(&enumlock); ast_mutex_lock(&enumlock);
if (version != enumver) { if (version != enumver) {
@ -475,16 +480,19 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
} else { } else {
s = s->next; s = s->next;
} }
ast_copy_string(tmp + newpos, suffix ? suffix : s->toplev, sizeof(tmp) - newpos);
ast_mutex_unlock(&enumlock); ast_mutex_unlock(&enumlock);
if (!s) if (!s)
break; break;
ast_copy_string(tmp + newpos, s->toplev, sizeof(tmp) - newpos);
ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback); ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback);
ast_log(LOG_DEBUG, "ast_get_enum: ast_search_dns(%s) returned %d\n", tmp, ret);
if (ret > 0) if (ret > 0)
break; break;
if (suffix != NULL)
break;
} }
}
if (ret < 0) { if (ret < 0) {
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno));

Loading…
Cancel
Save