2005-09-14 01:36:15 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-09-14 01:36:15 +00:00
|
|
|
*
|
2006-02-12 04:28:58 +00:00
|
|
|
* Copyright (C) 1999 - 2006
|
2005-09-14 01:36:15 +00:00
|
|
|
*
|
2005-10-18 03:02:06 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2005-09-14 01:36:15 +00:00
|
|
|
* Oleksiy Krivoshey <oleksiyk@gmail.com>
|
2005-10-18 03:02:06 +00:00
|
|
|
* Russell Bryant <russelb@clemson.edu>
|
2007-05-15 23:05:20 +00:00
|
|
|
* Brett Bryant <bbryant@digium.com>
|
2005-09-14 01:36:15 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2005-09-14 01:36:15 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief ENUM Functions
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
|
|
|
* \author Oleksiy Krivoshey <oleksiyk@gmail.com>
|
|
|
|
* \author Russell Bryant <russelb@clemson.edu>
|
2007-05-15 23:05:20 +00:00
|
|
|
* \author Brett Bryant <bbryant@digium.com>
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \arg See also AstENUM
|
2007-01-24 09:05:29 +00:00
|
|
|
*
|
|
|
|
* \ingroup functions
|
2005-09-14 01:36:15 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2005-09-14 01:36:15 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-11 21:38:22 -05:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2006-02-11 03:14:05 +00:00
|
|
|
|
2005-09-14 01:36:15 +00:00
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/enum.h"
|
2006-02-12 04:28:58 +00:00
|
|
|
#include "asterisk/app.h"
|
2005-09-14 01:36:15 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<function name="ENUMQUERY" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Initiate an ENUM query.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="method-type">
|
|
|
|
<para>If no <replaceable>method-type</replaceable> is given, the default will be
|
|
|
|
<literal>sip</literal>.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="zone-suffix">
|
|
|
|
<para>If no <replaceable>zone-suffix</replaceable> is given, the default will be
|
|
|
|
<literal>e164.arpa</literal></para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>This will do a ENUM lookup of the given phone number.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="ENUMRESULT" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Retrieve results from a ENUMQUERY.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="id" required="true">
|
|
|
|
<para>The identifier returned by the ENUMQUERY function.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="resultnum" required="true">
|
|
|
|
<para>The number of the result that you want to retrieve.</para>
|
|
|
|
<para>Results start at <literal>1</literal>. If this argument is specified
|
|
|
|
as <literal>getnum</literal>, then it will return the total number of results
|
2011-08-09 17:08:33 +00:00
|
|
|
that are available or -1 on error.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>This function will retrieve results from a previous use
|
|
|
|
of the ENUMQUERY function.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="ENUMLOOKUP" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
General or specific querying of NAPTR records for ENUM or ENUM-like DNS pointers.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="method-type">
|
|
|
|
<para>If no <replaceable>method-type</replaceable> is given, the default will be
|
|
|
|
<literal>sip</literal>.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="options">
|
|
|
|
<optionlist>
|
|
|
|
<option name="c">
|
|
|
|
<para>Returns an integer count of the number of NAPTRs of a certain RR type.</para>
|
|
|
|
<para>Combination of <literal>c</literal> and Method-type of <literal>ALL</literal> will
|
2011-08-09 17:08:33 +00:00
|
|
|
return a count of all NAPTRs for the record or -1 on error.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</option>
|
|
|
|
<option name="u">
|
|
|
|
<para>Returns the full URI and does not strip off the URI-scheme.</para>
|
|
|
|
</option>
|
|
|
|
<option name="s">
|
|
|
|
<para>Triggers ISN specific rewriting.</para>
|
|
|
|
</option>
|
|
|
|
<option name="i">
|
|
|
|
<para>Looks for branches into an Infrastructure ENUM tree.</para>
|
|
|
|
</option>
|
|
|
|
<option name="d">
|
|
|
|
<para>for a direct DNS lookup without any flipping of digits.</para>
|
|
|
|
</option>
|
|
|
|
</optionlist>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="record#">
|
|
|
|
<para>If no <replaceable>record#</replaceable> is given,
|
|
|
|
defaults to <literal>1</literal>.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="zone-suffix">
|
|
|
|
<para>If no <replaceable>zone-suffix</replaceable> is given, the default will be
|
|
|
|
<literal>e164.arpa</literal></para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
2011-02-02 19:30:49 +00:00
|
|
|
<para>For more information see <filename>doc/AST.pdf</filename>.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="TXTCIDNAME" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
TXTCIDNAME looks up a caller name via DNS.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="zone-suffix">
|
|
|
|
<para>If no <replaceable>zone-suffix</replaceable> is given, the default will be
|
|
|
|
<literal>e164.arpa</literal></para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>This function looks up the given phone number in DNS to retrieve
|
|
|
|
the caller id name. The result will either be blank or be the value
|
|
|
|
found in the TXT record in DNS.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
***/
|
|
|
|
|
2007-07-31 01:10:47 +00:00
|
|
|
static char *synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n";
|
2005-09-14 01:36:15 +00:00
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int function_enum(struct ast_channel *chan, const char *cmd, char *data,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *buf, size_t len)
|
2005-09-14 01:36:15 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(number);
|
|
|
|
AST_APP_ARG(tech);
|
|
|
|
AST_APP_ARG(options);
|
|
|
|
AST_APP_ARG(record);
|
|
|
|
AST_APP_ARG(zone);
|
|
|
|
);
|
|
|
|
char tech[80];
|
2006-03-21 05:54:04 +00:00
|
|
|
char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
|
2006-02-12 04:28:58 +00:00
|
|
|
char *s, *p;
|
2006-10-31 11:01:06 +00:00
|
|
|
unsigned int record = 1;
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
if (ast_strlen_zero(data)) {
|
2008-03-18 15:43:34 +00:00
|
|
|
ast_log(LOG_WARNING, "%s", synopsis);
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, data);
|
|
|
|
|
|
|
|
if (args.argc < 1) {
|
2008-03-18 15:43:34 +00:00
|
|
|
ast_log(LOG_WARNING, "%s", synopsis);
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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
2008-05-09 19:54:45 +00:00
|
|
|
if (args.tech && !ast_strlen_zero(args.tech)) {
|
|
|
|
ast_copy_string(tech,args.tech, sizeof(tech));
|
|
|
|
} else {
|
|
|
|
ast_copy_string(tech,"sip",sizeof(tech));
|
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
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
2008-05-09 19:54:45 +00:00
|
|
|
if (!args.zone) {
|
2006-02-22 23:07:34 +00:00
|
|
|
args.zone = "e164.arpa";
|
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
2008-05-09 19:54:45 +00:00
|
|
|
}
|
|
|
|
if (!args.options) {
|
2006-10-31 11:01:06 +00:00
|
|
|
args.options = "";
|
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
2008-05-09 19:54:45 +00:00
|
|
|
}
|
|
|
|
if (args.record) {
|
|
|
|
record = atoi(args.record) ? atoi(args.record) : record;
|
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
/* strip any '-' signs from number */
|
2006-02-22 22:53:49 +00:00
|
|
|
for (s = p = args.number; *s; s++) {
|
2006-03-21 05:54:04 +00:00
|
|
|
if (*s != '-') {
|
|
|
|
snprintf(tmp, sizeof(tmp), "%c", *s);
|
2008-03-07 06:54:47 +00:00
|
|
|
strncat(num, tmp, sizeof(num) - strlen(num) - 1);
|
2006-03-21 05:54:04 +00:00
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2006-03-21 05:54:04 +00:00
|
|
|
}
|
2011-05-03 20:45:32 +00:00
|
|
|
ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
p = strchr(dest, ':');
|
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
2008-05-09 19:54:45 +00:00
|
|
|
if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_copy_string(buf, p + 1, len);
|
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
2008-05-09 19:54:45 +00:00
|
|
|
} else {
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_copy_string(buf, dest, len);
|
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
2008-05-09 19:54:45 +00:00
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
return 0;
|
2005-09-14 01:36:15 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 17:34:30 +00:00
|
|
|
static unsigned int enum_datastore_id;
|
2007-05-15 23:05:20 +00:00
|
|
|
|
|
|
|
struct enum_result_datastore {
|
|
|
|
struct enum_context *context;
|
|
|
|
unsigned int id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void erds_destroy(struct enum_result_datastore *data)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for (k = 0; k < data->context->naptr_rrs_count; k++) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(data->context->naptr_rrs[k].result);
|
|
|
|
ast_free(data->context->naptr_rrs[k].tech);
|
2007-05-15 23:05:20 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(data->context->naptr_rrs);
|
|
|
|
ast_free(data->context);
|
|
|
|
ast_free(data);
|
2007-05-15 23:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void erds_destroy_cb(void *data)
|
|
|
|
{
|
|
|
|
struct enum_result_datastore *erds = data;
|
|
|
|
erds_destroy(erds);
|
|
|
|
}
|
|
|
|
|
2009-06-15 17:34:30 +00:00
|
|
|
static const struct ast_datastore_info enum_result_datastore_info = {
|
2007-05-15 23:05:20 +00:00
|
|
|
.type = "ENUMQUERY",
|
|
|
|
.destroy = erds_destroy_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int enum_query_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct enum_result_datastore *erds;
|
|
|
|
struct ast_datastore *datastore;
|
|
|
|
char *parse, tech[128], dest[128];
|
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(number);
|
|
|
|
AST_APP_ARG(tech);
|
|
|
|
AST_APP_ARG(zone);
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ast_strlen_zero(data)) {
|
|
|
|
ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse = ast_strdupa(data);
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!args.zone)
|
|
|
|
args.zone = "e164.zone";
|
|
|
|
|
|
|
|
ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
|
|
|
|
|
|
|
|
if (!(erds = ast_calloc(1, sizeof(*erds))))
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(erds);
|
2007-05-15 23:05:20 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);
|
|
|
|
|
|
|
|
snprintf(buf, len, "%u", erds->id);
|
|
|
|
|
2008-08-05 16:56:11 +00:00
|
|
|
if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(erds->context);
|
|
|
|
ast_free(erds);
|
2007-05-15 23:05:20 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);
|
|
|
|
|
|
|
|
datastore->data = erds;
|
|
|
|
|
2007-08-28 18:41:18 +00:00
|
|
|
ast_channel_lock(chan);
|
2007-05-15 23:05:20 +00:00
|
|
|
ast_channel_datastore_add(chan, datastore);
|
2007-08-28 18:41:18 +00:00
|
|
|
ast_channel_unlock(chan);
|
2007-05-15 23:05:20 +00:00
|
|
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int enum_result_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct enum_result_datastore *erds;
|
|
|
|
struct ast_datastore *datastore;
|
|
|
|
char *parse, *p;
|
|
|
|
unsigned int num;
|
|
|
|
int res = -1, k;
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(id);
|
|
|
|
AST_APP_ARG(resultnum);
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ast_strlen_zero(data)) {
|
|
|
|
ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse = ast_strdupa(data);
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (ast_strlen_zero(args.id)) {
|
|
|
|
ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_strlen_zero(args.resultnum)) {
|
|
|
|
ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2007-08-28 18:41:18 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
datastore = ast_channel_datastore_find(chan, &enum_result_datastore_info, args.id);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
if (!datastore) {
|
2007-05-15 23:05:20 +00:00
|
|
|
ast_log(LOG_WARNING, "No ENUM results found for query id!\n");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
erds = datastore->data;
|
|
|
|
|
|
|
|
if (!strcasecmp(args.resultnum, "getnum")) {
|
2011-08-09 17:08:33 +00:00
|
|
|
snprintf(buf, len, "%d", erds->context->naptr_rrs_count);
|
2007-05-15 23:05:20 +00:00
|
|
|
res = 0;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(args.resultnum, "%30u", &num) != 1) {
|
2007-05-15 23:05:20 +00:00
|
|
|
ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num || num > erds->context->naptr_rrs_count) {
|
|
|
|
ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k = 0; k < erds->context->naptr_rrs_count; k++) {
|
|
|
|
if (num - 1 != erds->context->naptr_rrs[k].sort_pos)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = strchr(erds->context->naptr_rrs[k].result, ':');
|
|
|
|
|
|
|
|
if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL"))
|
|
|
|
ast_copy_string(buf, p + 1, len);
|
|
|
|
else
|
|
|
|
ast_copy_string(buf, erds->context->naptr_rrs[k].result, len);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_custom_function enum_query_function = {
|
|
|
|
.name = "ENUMQUERY",
|
|
|
|
.read = enum_query_read,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ast_custom_function enum_result_function = {
|
|
|
|
.name = "ENUMRESULT",
|
|
|
|
.read = enum_result_read,
|
|
|
|
};
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function enum_function = {
|
2006-02-12 04:28:58 +00:00
|
|
|
.name = "ENUMLOOKUP",
|
|
|
|
.read = function_enum,
|
2005-09-14 01:36:15 +00:00
|
|
|
};
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int function_txtcidname(struct ast_channel *chan, const char *cmd,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, char *buf, size_t len)
|
2005-10-18 03:02:06 +00:00
|
|
|
{
|
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
2008-05-09 19:54:45 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(number);
|
|
|
|
AST_APP_ARG(zone);
|
|
|
|
);
|
2005-10-18 03:02:06 +00:00
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
2005-11-08 01:55:31 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
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
2008-05-09 19:54:45 +00:00
|
|
|
ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, data);
|
|
|
|
|
|
|
|
if (args.argc < 1) {
|
|
|
|
ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
2005-10-18 03:02:06 +00:00
|
|
|
}
|
|
|
|
|
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
2008-05-09 19:54:45 +00:00
|
|
|
if (!args.zone) {
|
|
|
|
args.zone = "e164.arpa";
|
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2011-05-03 20:45:32 +00:00
|
|
|
ast_get_txt(chan, args.number, buf, len, args.zone);
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-10-18 03:02:06 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function txtcidname_function = {
|
2006-02-12 04:28:58 +00:00
|
|
|
.name = "TXTCIDNAME",
|
|
|
|
.read = function_txtcidname,
|
2005-10-18 03:02:06 +00:00
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2005-09-14 01:36:15 +00:00
|
|
|
{
|
2006-02-11 03:14:05 +00:00
|
|
|
int res = 0;
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2007-05-15 23:05:20 +00:00
|
|
|
res |= ast_custom_function_unregister(&enum_result_function);
|
|
|
|
res |= ast_custom_function_unregister(&enum_query_function);
|
2006-02-11 03:14:05 +00:00
|
|
|
res |= ast_custom_function_unregister(&enum_function);
|
|
|
|
res |= ast_custom_function_unregister(&txtcidname_function);
|
2005-10-18 21:06:48 +00:00
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
return res;
|
2005-09-14 01:36:15 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2005-09-14 01:36:15 +00:00
|
|
|
{
|
2006-02-11 03:14:05 +00:00
|
|
|
int res = 0;
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2007-05-15 23:05:20 +00:00
|
|
|
res |= ast_custom_function_register(&enum_result_function);
|
|
|
|
res |= ast_custom_function_register(&enum_query_function);
|
2006-02-11 03:14:05 +00:00
|
|
|
res |= ast_custom_function_register(&enum_function);
|
|
|
|
res |= ast_custom_function_register(&txtcidname_function);
|
2005-10-18 03:02:06 +00:00
|
|
|
|
|
|
|
return res;
|
2005-09-14 01:36:15 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ENUM related dialplan functions");
|