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";
55 static int function_enum(struct ast_channel *chan, char *cmd, char *data,
56 char *buf, size_t len)
58 AST_DECLARE_APP_ARGS(args,
73 if (ast_strlen_zero(data)) {
74 ast_log(LOG_WARNING, synopsis);
78 AST_STANDARD_APP_ARGS(args, data);
81 ast_log(LOG_WARNING, synopsis);
85 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
88 args.zone = "e164.arpa";
93 /* strip any '-' signs from number */
94 for (s = p = args.number; *s; s++) {
102 res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), args.zone,
105 LOCAL_USER_REMOVE(u);
107 p = strchr(dest, ':');
108 if (p && strcasecmp(tech, "ALL"))
109 ast_copy_string(buf, p + 1, len);
111 ast_copy_string(buf, dest, len);
116 static struct ast_custom_function enum_function = {
117 .name = "ENUMLOOKUP",
119 "ENUMLOOKUP allows for general or specific querying of NAPTR records"
120 " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
122 "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
124 "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
125 "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
126 "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
127 "For more information, see doc/enum.txt",
128 .read = function_enum,
131 static int function_txtcidname(struct ast_channel *chan, char *cmd,
132 char *data, char *buf, size_t len)
144 if (ast_strlen_zero(data)) {
145 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
146 LOCAL_USER_REMOVE(u);
150 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
153 if (!ast_strlen_zero(txt))
154 ast_copy_string(buf, txt, len);
156 LOCAL_USER_REMOVE(u);
161 static struct ast_custom_function txtcidname_function = {
162 .name = "TXTCIDNAME",
163 .synopsis = "TXTCIDNAME looks up a caller name via DNS",
164 .syntax = "TXTCIDNAME(<number>)",
166 "This function looks up the given phone number in DNS to retrieve\n"
167 "the caller id name. The result will either be blank or be the value\n"
168 "found in the TXT record in DNS.\n",
169 .read = function_txtcidname,
172 static char *tdesc = "ENUM related dialplan functions";
174 int unload_module(void)
178 res |= ast_custom_function_unregister(&enum_function);
179 res |= ast_custom_function_unregister(&txtcidname_function);
181 STANDARD_HANGUP_LOCALUSERS;
186 int load_module(void)
190 res |= ast_custom_function_register(&enum_function);
191 res |= ast_custom_function_register(&txtcidname_function);
196 char *description(void)
205 STANDARD_USECOUNT(res);
212 return ASTERISK_GPL_KEY;