2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006
6 * Mark Spencer <markster@digium.com>
7 * Oleksiy Krivoshey <oleksiyk@gmail.com>
8 * Russell Bryant <russelb@clemson.edu>
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
16 * This program is free software, distributed under the terms of
17 * the GNU General Public License Version 2. See the LICENSE file
18 * at the top of the source tree.
23 * \brief ENUM Functions
25 * \author Mark Spencer <markster@digium.com>
26 * \author Oleksiy Krivoshey <oleksiyk@gmail.com>
27 * \author Russell Bryant <russelb@clemson.edu>
29 * \arg See also AstENUM
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
39 #include "asterisk/module.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/utils.h"
43 #include "asterisk/lock.h"
44 #include "asterisk/file.h"
45 #include "asterisk/logger.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/options.h"
48 #include "asterisk/enum.h"
49 #include "asterisk/app.h"
51 static char *synopsis = "Syntax: ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])\n";
57 static int function_enum(struct ast_channel *chan, char *cmd, char *data,
58 char *buf, size_t len)
60 AST_DECLARE_APP_ARGS(args,
77 if (ast_strlen_zero(data)) {
78 ast_log(LOG_WARNING, synopsis);
82 AST_STANDARD_APP_ARGS(args, data);
85 ast_log(LOG_WARNING, synopsis);
89 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
92 args.zone = "e164.arpa";
97 /* strip any '-' signs from number */
98 for (p = args.number, s = p; *s; *s++) {
104 LOCAL_USER_ACF_ADD(u);
106 res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), zone,
109 LOCAL_USER_REMOVE(u);
111 p = strchr(dest, ':');
112 if (p && strcasecmp(tech, "ALL"))
113 ast_copy_string(buf, p + 1, len);
115 ast_copy_string(buf, dest, len);
120 static struct ast_custom_function enum_function = {
121 .name = "ENUMLOOKUP",
123 "ENUMLOOKUP allows for general or specific querying of NAPTR records"
124 " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
126 "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
128 "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
129 "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
130 "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
131 "For more information, see README.enum",
132 .read = function_enum,
135 static int function_txtcidname(struct ast_channel *chan, char *cmd,
136 char *data, char *buf, size_t len)
146 LOCAL_USER_ACF_ADD(u);
148 if (ast_strlen_zero(data)) {
149 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
150 LOCAL_USER_REMOVE(u);
154 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
157 if (!ast_strlen_zero(txt))
158 ast_copy_string(buf, txt, len);
160 LOCAL_USER_REMOVE(u);
165 static struct ast_custom_function txtcidname_function = {
166 .name = "TXTCIDNAME",
167 .synopsis = "TXTCIDNAME looks up a caller name via DNS",
168 .syntax = "TXTCIDNAME(<number>)",
170 "This function looks up the given phone number in DNS to retrieve\n"
171 "the caller id name. The result will either be blank or be the value\n"
172 "found in the TXT record in DNS.\n",
173 .read = function_txtcidname,
176 static char *tdesc = "ENUM related dialplan functions";
178 int unload_module(void)
182 res |= ast_custom_function_unregister(&enum_function);
183 res |= ast_custom_function_unregister(&txtcidname_function);
185 STANDARD_HANGUP_LOCALUSERS;
190 int load_module(void)
194 res |= ast_custom_function_register(&enum_function);
195 res |= ast_custom_function_register(&txtcidname_function);
200 char *description(void)
209 STANDARD_USECOUNT(res);
216 return ASTERISK_GPL_KEY;