Let's also include aclocal.m4
[asterisk-bristuff.git] / funcs / func_enum.c
blob55493790896427fcd784d20fcbf97fb9eb27959e
1 /*
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.
21 /*! \file
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
32 #include "asterisk.h"
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include <stdlib.h>
37 #include <stdio.h>
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";
53 static int function_enum(struct ast_channel *chan, char *cmd, char *data,
54 char *buf, size_t len)
56 AST_DECLARE_APP_ARGS(args,
57 AST_APP_ARG(number);
58 AST_APP_ARG(tech);
59 AST_APP_ARG(options);
60 AST_APP_ARG(record);
61 AST_APP_ARG(zone);
63 int res = 0;
64 char tech[80];
65 char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
66 struct ast_module_user *u;
67 char *s, *p;
68 unsigned int record = 1;
70 buf[0] = '\0';
72 if (ast_strlen_zero(data)) {
73 ast_log(LOG_WARNING, synopsis);
74 return -1;
77 AST_STANDARD_APP_ARGS(args, data);
79 if (args.argc < 1) {
80 ast_log(LOG_WARNING, synopsis);
81 return -1;
84 u = ast_module_user_add(chan);
86 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
88 if (!args.zone)
89 args.zone = "e164.arpa";
91 if (!args.options)
92 args.options = "";
94 if (args.record)
95 record = atoi(args.record);
97 /* strip any '-' signs from number */
98 for (s = p = args.number; *s; s++) {
99 if (*s != '-') {
100 snprintf(tmp, sizeof(tmp), "%c", *s);
101 strncat(num, tmp, sizeof(num) - strlen(num) - 1);
106 res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone,
107 args.options, record);
109 p = strchr(dest, ':');
110 if (p && strcasecmp(tech, "ALL"))
111 ast_copy_string(buf, p + 1, len);
112 else
113 ast_copy_string(buf, dest, len);
115 ast_module_user_remove(u);
117 return 0;
120 static struct ast_custom_function enum_function = {
121 .name = "ENUMLOOKUP",
122 .synopsis =
123 "ENUMLOOKUP allows for general or specific querying of NAPTR records"
124 " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
125 .syntax =
126 "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
127 .desc =
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 doc/enum.txt",
132 .read = function_enum,
135 static int function_txtcidname(struct ast_channel *chan, char *cmd,
136 char *data, char *buf, size_t len)
138 int res;
139 char tech[80];
140 char txt[256] = "";
141 char dest[80];
142 struct ast_module_user *u;
144 buf[0] = '\0';
147 if (ast_strlen_zero(data)) {
148 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
149 return -1;
152 u = ast_module_user_add(chan);
154 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
155 sizeof(txt));
157 if (!ast_strlen_zero(txt))
158 ast_copy_string(buf, txt, len);
160 ast_module_user_remove(u);
162 return 0;
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>)",
169 .desc =
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 int unload_module(void)
178 int res = 0;
180 res |= ast_custom_function_unregister(&enum_function);
181 res |= ast_custom_function_unregister(&txtcidname_function);
183 ast_module_user_hangup_all();
185 return res;
188 static int load_module(void)
190 int res = 0;
192 res |= ast_custom_function_register(&enum_function);
193 res |= ast_custom_function_register(&txtcidname_function);
195 return res;
198 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ENUM related dialplan functions");