Newer
Older
Kevin P. Fleming
committed
/*
* Asterisk -- An open source telephony toolkit.
Kevin P. Fleming
committed
*
Kevin P. Fleming
committed
*
Russell Bryant
committed
* Mark Spencer <markster@digium.com>
Kevin P. Fleming
committed
* Oleksiy Krivoshey <oleksiyk@gmail.com>
Russell Bryant
committed
* Russell Bryant <russelb@clemson.edu>
Kevin P. Fleming
committed
*
* 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.
*
Kevin P. Fleming
committed
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
*
* \brief ENUM Functions
*
* \author Mark Spencer <markster@digium.com>
* \author Oleksiy Krivoshey <oleksiyk@gmail.com>
* \author Russell Bryant <russelb@clemson.edu>
*
* \arg See also AstENUM
Kevin P. Fleming
committed
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
Kevin P. Fleming
committed
#include <stdlib.h>
#include <stdio.h>
Kevin P. Fleming
committed
#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/logger.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/enum.h"
Kevin P. Fleming
committed
static char *synopsis = "Syntax: ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])\n";
Kevin P. Fleming
committed
LOCAL_USER_DECL;
static int function_enum(struct ast_channel *chan, char *cmd, char *data,
char *buf, size_t len)
Kevin P. Fleming
committed
{
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);
);
int res = 0;
char tech[80];
char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
struct localuser *u;
char *s, *p;
buf[0] = '\0';
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, synopsis);
return -1;
}
AST_STANDARD_APP_ARGS(args, data);
if (args.argc < 1) {
ast_log(LOG_WARNING, synopsis);
return -1;
}
ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
Kevin P. Fleming
committed
if (!args.zone)
args.zone = "e164.arpa";
if (!args.options)
args.options = "1";
/* strip any '-' signs from number */
Kevin P. Fleming
committed
for (s = p = args.number; *s; s++) {
if (*s != '-') {
snprintf(tmp, sizeof(tmp), "%c", *s);
strncat(num, tmp, sizeof(num));
}
res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone,
p = strchr(dest, ':');
if (p && strcasecmp(tech, "ALL"))
ast_copy_string(buf, p + 1, len);
else
ast_copy_string(buf, dest, len);
Kevin P. Fleming
committed
}
static struct ast_custom_function enum_function = {
.name = "ENUMLOOKUP",
.synopsis =
"ENUMLOOKUP allows for general or specific querying of NAPTR records"
" or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
.syntax =
"ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
.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"
"Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
"For more information, see doc/enum.txt",
Kevin P. Fleming
committed
};
static int function_txtcidname(struct ast_channel *chan, char *cmd,
char *data, char *buf, size_t len)
Russell Bryant
committed
{
int res;
char tech[80];
char txt[256] = "";
char dest[80];
struct localuser *u;
buf[0] = '\0';
Russell Bryant
committed
ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
Russell Bryant
committed
}
LOCAL_USER_ADD(u);
res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
sizeof(txt));
Russell Bryant
committed
if (!ast_strlen_zero(txt))
ast_copy_string(buf, txt, len);
Russell Bryant
committed
LOCAL_USER_REMOVE(u);
Russell Bryant
committed
}
static struct ast_custom_function txtcidname_function = {
.name = "TXTCIDNAME",
.synopsis = "TXTCIDNAME looks up a caller name via DNS",
.syntax = "TXTCIDNAME(<number>)",
.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",
.read = function_txtcidname,
Russell Bryant
committed
};
static char *tdesc = "ENUM related dialplan functions";
Kevin P. Fleming
committed
static int unload_module(void *mod)
Kevin P. Fleming
committed
{
int res = 0;
res |= ast_custom_function_unregister(&enum_function);
res |= ast_custom_function_unregister(&txtcidname_function);
return res;
Kevin P. Fleming
committed
}
static int load_module(void *mod)
Kevin P. Fleming
committed
{
int res = 0;
res |= ast_custom_function_register(&enum_function);
res |= ast_custom_function_register(&txtcidname_function);
Russell Bryant
committed
return res;
Kevin P. Fleming
committed
}
static const char *description(void)
Kevin P. Fleming
committed
{
Kevin P. Fleming
committed
}
static const char *key(void)
Kevin P. Fleming
committed
{
Kevin P. Fleming
committed
}
STD_MOD(MOD_1, NULL, NULL, NULL);