The following patch adds new options and alters the default behavior of the ENUM* functions. The TXCIDNAME lookup function has also gotten a

new paramater. The new options for ENUM* functions include 'u', 's', 'i', and 'd' which return the full uri, trigger isn specific rewriting, look 
for branches into an infrastructure enum tree, or do a direct dns lookup of a number respectively. The new paramater for TXCIDNAME adds a 
zone-suffix argument for looking up caller id's in DNS that aren't e164.arpa.

This patch is based on the original code from otmar, modified by snuffy, and tested by jtodd, me, and others.

(closes issue #8089)
Reported by: otmar
Patches:
      20080508_bug8089-1.diff 
	- original code by otmar (license 480), 
	- revised by snuffy (license 35)
Tested by: oej, otmar, jtodd, Corydon76, snuffy, alexnikolov, bbryant


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@115584 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Brett Bryant 2008-05-09 19:54:45 +00:00
parent 8b1d52c9a5
commit 65b8381550
3 changed files with 619 additions and 258 deletions

View File

@ -78,16 +78,21 @@ static int function_enum(struct ast_channel *chan, const char *cmd, char *data,
return -1;
}
ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
if (args.tech && !ast_strlen_zero(args.tech)) {
ast_copy_string(tech,args.tech, sizeof(tech));
} else {
ast_copy_string(tech,"sip",sizeof(tech));
}
if (!args.zone)
if (!args.zone) {
args.zone = "e164.arpa";
if (!args.options)
}
if (!args.options) {
args.options = "";
if (args.record)
record = atoi(args.record);
}
if (args.record) {
record = atoi(args.record) ? atoi(args.record) : record;
}
/* strip any '-' signs from number */
for (s = p = args.number; *s; s++) {
@ -97,15 +102,14 @@ static int function_enum(struct ast_channel *chan, const char *cmd, char *data,
}
}
res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, 1, NULL);
res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
p = strchr(dest, ':');
if (p && strcasecmp(tech, "ALL"))
if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
ast_copy_string(buf, p + 1, len);
else
} else {
ast_copy_string(buf, dest, len);
}
return 0;
}
@ -323,6 +327,10 @@ static struct ast_custom_function enum_function = {
.desc =
"Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
"Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
"Option 'u' returns the full URI and does not strip off the URI-scheme.\n"
"Option 's' triggers ISN specific rewriting\n"
"Option 'i' looks for branches into an Infrastructure ENUM tree\n"
"Option 'd' for a direct DNS lookup without any flipping of digits\n"
"Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
"For more information, see doc/asterisk.pdf",
.read = function_enum,
@ -332,23 +340,30 @@ static int function_txtcidname(struct ast_channel *chan, const char *cmd,
char *data, char *buf, size_t len)
{
int res;
char tech[80];
char txt[256] = "";
char dest[80];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(number);
AST_APP_ARG(zone);
);
buf[0] = '\0';
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
return -1;
}
res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
sizeof(txt));
AST_STANDARD_APP_ARGS(args, data);
if (!ast_strlen_zero(txt))
ast_copy_string(buf, txt, len);
if (args.argc < 1) {
ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
return -1;
}
if (!args.zone) {
args.zone = "e164.arpa";
}
res = ast_get_txt(chan, args.number, buf, len, args.zone);
return 0;
}
@ -356,11 +371,11 @@ static int function_txtcidname(struct ast_channel *chan, const char *cmd,
static struct ast_custom_function txtcidname_function = {
.name = "TXTCIDNAME",
.synopsis = "TXTCIDNAME looks up a caller name via DNS",
.syntax = "TXTCIDNAME(<number>)",
.syntax = "TXTCIDNAME(<number>[,zone-suffix])",
.desc =
"This function looks up the given phone number in DNS to retrieve\n"
"the caller id name. The result will either be blank or be the value\n"
"found in the TXT record in DNS.\n",
"found in the TXT record in DNS. The default zone-suffix is e164.arpa.\n",
.read = function_txtcidname,
};

View File

@ -45,7 +45,8 @@ struct enum_context {
char *txt; /*!< TXT record in TXT lookup */
int txtlen; /*!< Length */
char *naptrinput; /*!< The number to lookup */
int position; /*!< used as counter for RRs or specifies position of required RR */
int position; /*!< specifies position of required RR */
int count; /*!< used as counter for RRs */
int options; /*!< options , see ENUMLOOKUP_OPTIONS_* defined above */
struct enum_naptr_rr *naptr_rrs; /*!< array of parsed NAPTR RRs */
int naptr_rrs_count; /*!< Size of array naptr_rrs */
@ -57,12 +58,18 @@ struct enum_context {
\param number E164 number with or without the leading +
\param location Number returned (or SIP uri)
\param maxloc Max length
\param technology Technology (from url scheme in response)
\param technology Technology (from url scheme in response)
You can set it to get particular answer RR, if there are many techs in DNS response, example: "sip"
If you need any record, then set it to empty string
If you need any record, then set it to "ALL" string
\param maxtech Max length
\param suffix Zone suffix (if is NULL then use enum.conf 'search' variable)
\param options Options ('c' to count number of NAPTR RR)
\param suffix Zone suffix (WARNING: No defaults here any more)
\param options Options
'c' - Count number of NAPTR RR
number - Position of the requested RR in the answer list
'u' - Full URI return (does not strip URI scheme)
'i' - Infrastructure ENUM lookup
's' - ISN based lookup
'd' - Direct DNS query
\param record The position of required RR in the answer list
\param argcontext Argument for caching results into an enum_context pointer (NULL is used for not caching)
\retval 1 if found
@ -75,14 +82,11 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *location, i
/*! \brief Lookup DNS TXT record (used by app TXTCIDnum
\param chan Channel
\param number E164 number with or without the leading +
\param location Number returned (or SIP uri)
\param maxloc Max length of number
\param technology Technology (not used in TXT records)
\param maxtech Max length
\param txt Text string (return value)
\param maxtxt Max length of "txt"
\param suffix Zone suffix
*/
int ast_get_txt(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology, int maxtech, char *txt, int maxtxt);
int ast_get_txt(struct ast_channel *chan, const char *number, char *txt, int maxtxt, char *suffix);
int ast_enum_init(void);
int ast_enum_reload(void);

File diff suppressed because it is too large Load Diff