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,
75 if (ast_strlen_zero(data)) {
76 ast_log(LOG_WARNING, synopsis);
80 AST_STANDARD_APP_ARGS(args, data);
83 ast_log(LOG_WARNING, synopsis);
87 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
90 args.zone = "e164.arpa";
95 /* strip any '-' signs from number */
96 for (p = args.number, s = p; *s; *s++) {
102 LOCAL_USER_ACF_ADD(u);
104 res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), args.zone,
107 LOCAL_USER_REMOVE(u);
109 p = strchr(dest, ':');
110 if (p && strcasecmp(tech, "ALL"))
111 ast_copy_string(buf, p + 1, len);
113 ast_copy_string(buf, dest, len);
118 static struct ast_custom_function enum_function = {
119 .name = "ENUMLOOKUP",
121 "ENUMLOOKUP allows for general or specific querying of NAPTR records"
122 " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
124 "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
126 "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
127 "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
128 "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
129 "For more information, see README.enum",
130 .read = function_enum,
133 static int function_txtcidname(struct ast_channel *chan, char *cmd,
134 char *data, char *buf, size_t len)
144 LOCAL_USER_ACF_ADD(u);
146 if (ast_strlen_zero(data)) {
147 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
148 LOCAL_USER_REMOVE(u);
152 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
155 if (!ast_strlen_zero(txt))
156 ast_copy_string(buf, txt, len);
158 LOCAL_USER_REMOVE(u);
163 static struct ast_custom_function txtcidname_function = {
164 .name = "TXTCIDNAME",
165 .synopsis = "TXTCIDNAME looks up a caller name via DNS",
166 .syntax = "TXTCIDNAME(<number>)",
168 "This function looks up the given phone number in DNS to retrieve\n"
169 "the caller id name. The result will either be blank or be the value\n"
170 "found in the TXT record in DNS.\n",
171 .read = function_txtcidname,
174 static char *tdesc = "ENUM related dialplan functions";
176 int unload_module(void)
180 res |= ast_custom_function_unregister(&enum_function);
181 res |= ast_custom_function_unregister(&txtcidname_function);
183 STANDARD_HANGUP_LOCALUSERS;
188 int load_module(void)
192 res |= ast_custom_function_register(&enum_function);
193 res |= ast_custom_function_register(&txtcidname_function);
198 char *description(void)
207 STANDARD_USECOUNT(res);
214 return ASTERISK_GPL_KEY;