#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/enum.h"
#include "asterisk/app.h"
Go to the source code of this file.
Data Structures | |
struct | enum_result_datastore |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | enum_query_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | enum_result_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static void | erds_destroy (struct enum_result_datastore *data) |
static void | erds_destroy_cb (void *data) |
static int | function_enum (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | function_txtcidname (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ENUM related dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
unsigned int | enum_datastore_id |
static struct ast_custom_function | enum_function |
static struct ast_custom_function | enum_query_function |
ast_datastore_info | enum_result_datastore_info |
static struct ast_custom_function | enum_result_function |
static char * | synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n" |
static struct ast_custom_function | txtcidname_function |
Oleksiy Krivoshey <oleksiyk@gmail.com>
Russell Bryant <russelb@clemson.edu>
Brett Bryant <bbryant@digium.com>
Definition in file func_enum.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 391 of file func_enum.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 391 of file func_enum.c.
static int enum_query_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 144 of file func_enum.c.
References AST_APP_ARG, ast_atomic_fetchadd_int(), ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_alloc(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free, ast_get_enum(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), chan, ast_datastore::data, enum_result_datastore_info, LOG_ERROR, LOG_WARNING, parse(), and ast_channel::zone.
00145 { 00146 struct enum_result_datastore *erds; 00147 struct ast_datastore *datastore; 00148 char *parse, tech[128], dest[128]; 00149 int res = -1; 00150 00151 AST_DECLARE_APP_ARGS(args, 00152 AST_APP_ARG(number); 00153 AST_APP_ARG(tech); 00154 AST_APP_ARG(zone); 00155 ); 00156 00157 if (ast_strlen_zero(data)) { 00158 ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n"); 00159 goto finish; 00160 } 00161 00162 parse = ast_strdupa(data); 00163 00164 AST_STANDARD_APP_ARGS(args, parse); 00165 00166 if (!chan) { 00167 ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n"); 00168 goto finish; 00169 } 00170 00171 if (!args.zone) 00172 args.zone = "e164.zone"; 00173 00174 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech)); 00175 00176 if (!(erds = ast_calloc(1, sizeof(*erds)))) 00177 goto finish; 00178 00179 if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) { 00180 ast_free(erds); 00181 goto finish; 00182 } 00183 00184 erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1); 00185 00186 snprintf(buf, len, "%u", erds->id); 00187 00188 if (!(datastore = ast_channel_datastore_alloc(&enum_result_datastore_info, buf))) { 00189 ast_free(erds->context); 00190 ast_free(erds); 00191 goto finish; 00192 } 00193 00194 ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context); 00195 00196 datastore->data = erds; 00197 00198 ast_channel_lock(chan); 00199 ast_channel_datastore_add(chan, datastore); 00200 ast_channel_unlock(chan); 00201 00202 res = 0; 00203 00204 finish: 00205 00206 return res; 00207 }
static int enum_result_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 209 of file func_enum.c.
References AST_APP_ARG, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), chan, enum_result_datastore::context, ast_datastore::data, enum_result_datastore_info, LOG_ERROR, LOG_WARNING, enum_context::naptr_rrs, enum_context::naptr_rrs_count, num, parse(), enum_naptr_rr::result, enum_naptr_rr::sort_pos, and enum_naptr_rr::tech.
00210 { 00211 struct enum_result_datastore *erds; 00212 struct ast_datastore *datastore; 00213 char *parse, *p; 00214 unsigned int num; 00215 int res = -1, k; 00216 AST_DECLARE_APP_ARGS(args, 00217 AST_APP_ARG(id); 00218 AST_APP_ARG(resultnum); 00219 ); 00220 00221 if (ast_strlen_zero(data)) { 00222 ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n"); 00223 goto finish; 00224 } 00225 00226 if (!chan) { 00227 ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n"); 00228 goto finish; 00229 } 00230 00231 parse = ast_strdupa(data); 00232 00233 AST_STANDARD_APP_ARGS(args, parse); 00234 00235 if (ast_strlen_zero(args.id)) { 00236 ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n"); 00237 goto finish; 00238 } 00239 00240 if (ast_strlen_zero(args.resultnum)) { 00241 ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n"); 00242 goto finish; 00243 } 00244 00245 ast_channel_lock(chan); 00246 datastore = ast_channel_datastore_find(chan, &enum_result_datastore_info, args.id); 00247 ast_channel_unlock(chan); 00248 if (!datastore) { 00249 ast_log(LOG_WARNING, "No ENUM results found for query id!\n"); 00250 goto finish; 00251 } 00252 00253 erds = datastore->data; 00254 00255 if (!strcasecmp(args.resultnum, "getnum")) { 00256 snprintf(buf, len, "%u", erds->context->naptr_rrs_count); 00257 res = 0; 00258 goto finish; 00259 } 00260 00261 if (sscanf(args.resultnum, "%u", &num) != 1) { 00262 ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum); 00263 goto finish; 00264 } 00265 00266 if (!num || num > erds->context->naptr_rrs_count) { 00267 ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id); 00268 goto finish; 00269 } 00270 00271 for (k = 0; k < erds->context->naptr_rrs_count; k++) { 00272 if (num - 1 != erds->context->naptr_rrs[k].sort_pos) 00273 continue; 00274 00275 p = strchr(erds->context->naptr_rrs[k].result, ':'); 00276 00277 if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL")) 00278 ast_copy_string(buf, p + 1, len); 00279 else 00280 ast_copy_string(buf, erds->context->naptr_rrs[k].result, len); 00281 00282 break; 00283 } 00284 00285 res = 0; 00286 00287 finish: 00288 00289 return res; 00290 }
static void erds_destroy | ( | struct enum_result_datastore * | data | ) | [static] |
Definition at line 119 of file func_enum.c.
References ast_free, enum_result_datastore::context, enum_context::naptr_rrs, enum_context::naptr_rrs_count, enum_naptr_rr::result, and enum_naptr_rr::tech.
Referenced by erds_destroy_cb().
00120 { 00121 int k; 00122 00123 for (k = 0; k < data->context->naptr_rrs_count; k++) { 00124 ast_free(data->context->naptr_rrs[k].result); 00125 ast_free(data->context->naptr_rrs[k].tech); 00126 } 00127 00128 ast_free(data->context->naptr_rrs); 00129 ast_free(data->context); 00130 ast_free(data); 00131 }
static void erds_destroy_cb | ( | void * | data | ) | [static] |
Definition at line 133 of file func_enum.c.
References erds_destroy().
00134 { 00135 struct enum_result_datastore *erds = data; 00136 erds_destroy(erds); 00137 }
static int function_enum | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 51 of file func_enum.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_get_enum(), ast_log(), AST_MAX_EXTENSION, AST_STANDARD_APP_ARGS, ast_strlen_zero(), chan, LOG_WARNING, num, s, and ast_channel::zone.
00053 { 00054 AST_DECLARE_APP_ARGS(args, 00055 AST_APP_ARG(number); 00056 AST_APP_ARG(tech); 00057 AST_APP_ARG(options); 00058 AST_APP_ARG(record); 00059 AST_APP_ARG(zone); 00060 ); 00061 int res = 0; 00062 char tech[80]; 00063 char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = ""; 00064 char *s, *p; 00065 unsigned int record = 1; 00066 00067 buf[0] = '\0'; 00068 00069 if (ast_strlen_zero(data)) { 00070 ast_log(LOG_WARNING, "%s", synopsis); 00071 return -1; 00072 } 00073 00074 AST_STANDARD_APP_ARGS(args, data); 00075 00076 if (args.argc < 1) { 00077 ast_log(LOG_WARNING, "%s", synopsis); 00078 return -1; 00079 } 00080 00081 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech)); 00082 00083 if (!args.zone) 00084 args.zone = "e164.arpa"; 00085 00086 if (!args.options) 00087 args.options = ""; 00088 00089 if (args.record) 00090 record = atoi(args.record); 00091 00092 /* strip any '-' signs from number */ 00093 for (s = p = args.number; *s; s++) { 00094 if (*s != '-') { 00095 snprintf(tmp, sizeof(tmp), "%c", *s); 00096 strncat(num, tmp, sizeof(num) - strlen(num) - 1); 00097 } 00098 00099 } 00100 00101 res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, 1, NULL); 00102 00103 p = strchr(dest, ':'); 00104 if (p && strcasecmp(tech, "ALL")) 00105 ast_copy_string(buf, p + 1, len); 00106 else 00107 ast_copy_string(buf, dest, len); 00108 00109 return 0; 00110 }
static int function_txtcidname | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 331 of file func_enum.c.
References ast_copy_string(), ast_get_txt(), ast_log(), ast_strlen_zero(), chan, and LOG_WARNING.
00333 { 00334 int res; 00335 char tech[80]; 00336 char txt[256] = ""; 00337 char dest[80]; 00338 00339 buf[0] = '\0'; 00340 00341 00342 if (ast_strlen_zero(data)) { 00343 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n"); 00344 return -1; 00345 } 00346 00347 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, 00348 sizeof(txt)); 00349 00350 if (!ast_strlen_zero(txt)) 00351 ast_copy_string(buf, txt, len); 00352 00353 return 0; 00354 }
static int load_module | ( | void | ) | [static] |
Definition at line 379 of file func_enum.c.
References ast_custom_function_register, enum_function, enum_query_function, enum_result_function, and txtcidname_function.
00380 { 00381 int res = 0; 00382 00383 res |= ast_custom_function_register(&enum_result_function); 00384 res |= ast_custom_function_register(&enum_query_function); 00385 res |= ast_custom_function_register(&enum_function); 00386 res |= ast_custom_function_register(&txtcidname_function); 00387 00388 return res; 00389 }
static int unload_module | ( | void | ) | [static] |
Definition at line 367 of file func_enum.c.
References ast_custom_function_unregister(), enum_function, enum_query_function, enum_result_function, and txtcidname_function.
00368 { 00369 int res = 0; 00370 00371 res |= ast_custom_function_unregister(&enum_result_function); 00372 res |= ast_custom_function_unregister(&enum_query_function); 00373 res |= ast_custom_function_unregister(&enum_function); 00374 res |= ast_custom_function_unregister(&txtcidname_function); 00375 00376 return res; 00377 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ENUM related dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 391 of file func_enum.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 391 of file func_enum.c.
unsigned int enum_datastore_id |
Definition at line 112 of file func_enum.c.
struct ast_custom_function enum_function [static] |
struct ast_custom_function enum_query_function [static] |
Initial value:
{ .type = "ENUMQUERY", .destroy = erds_destroy_cb, }
Definition at line 139 of file func_enum.c.
Referenced by enum_query_read(), and enum_result_read().
struct ast_custom_function enum_result_function [static] |
char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n" [static] |
Definition at line 49 of file func_enum.c.
struct ast_custom_function txtcidname_function [static] |