2 * Asterisk -- A telephony toolkit for Linux.
4 * Time of day - Report the time of day
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 #include <asterisk/lock.h>
15 #include <asterisk/file.h>
16 #include <asterisk/logger.h>
17 #include <asterisk/channel.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/module.h>
20 #include <asterisk/enum.h>
30 static char *tdesc = "ENUM Lookup";
32 static char *app = "EnumLookup";
34 static char *synopsis = "Lookup number in ENUM";
36 static char *descrip =
37 " EnumLookup(exten): Looks up an extension via ENUM and sets\n"
38 "the variable 'ENUM'. Returns -1 on hangup, or 0 on completion\n"
39 "regardless of whether the lookup was successful. Currently, the\n"
40 "enumservices SIP and TEL are recognized. A good SIP entry\n"
41 "will result in normal priority handling, whereas a good TEL entry\n"
42 "will increase the priority by 51 (if existing)\n"
43 "If the lookup was *not* successful and there exists a priority n + 101,\n"
44 "then that priority will be taken next.\n" ;
50 static int enumlookup_exec(struct ast_channel *chan, void *data)
58 if (!data || !strlen(data)) {
59 ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
64 res = ast_get_enum(chan, data, dest, sizeof(dest), tech, sizeof(tech));
65 printf("ENUM got '%d'\n", res);
70 if (!strcasecmp(tech, "SIP")) {
72 if (!strncmp(c, "sip:", 4))
74 snprintf(tmp, sizeof(tmp), "SIP/%s", c);
75 pbx_builtin_setvar_helper(chan, "ENUM", tmp);
76 } else if (!strcasecmp(tech, "H323")) {
78 if (!strncmp(c, "h323:", 5))
80 snprintf(tmp, sizeof(tmp), "H323/%s", c);
81 pbx_builtin_setvar_helper(chan, "ENUM", tmp);
82 } else if (!strcasecmp(tech, "IAX")) {
84 if (!strncmp(c, "iax:", 4))
86 snprintf(tmp, sizeof(tmp), "IAX/%s", c);
87 pbx_builtin_setvar_helper(chan, "ENUM", tmp);
88 } else if (!strcasecmp(tech, "IAX2")) {
90 if (!strncmp(c, "iax2:", 5))
92 snprintf(tmp, sizeof(tmp), "IAX2/%s", c);
93 pbx_builtin_setvar_helper(chan, "ENUM", tmp);
94 } else if (!strcasecmp(tech, "tel")) {
96 if (!strncmp(c, "tel:", 4))
100 ast_log(LOG_NOTICE, "tel: uri must start with a \"+\" (got '%s')\n", c);
103 /* now copy over the number, skipping all non-digits and stop at ; or NULL */
105 while( *c && (*c != ';') && (t - tmp < (sizeof(tmp) - 1))) {
111 pbx_builtin_setvar_helper(chan, "ENUM", tmp);
112 ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
113 if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 51, chan->callerid))
114 chan->priority += 50;
118 } else if (strlen(tech)) {
119 ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
124 /* Look for a "busy" place */
125 if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
126 chan->priority += 100;
132 int unload_module(void)
134 STANDARD_HANGUP_LOCALUSERS;
135 return ast_unregister_application(app);
138 int load_module(void)
140 return ast_register_application(app, enumlookup_exec, synopsis, descrip);
143 char *description(void)
151 STANDARD_USECOUNT(res);
157 return ASTERISK_GPL_KEY;