#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_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static unsigned int | enum_datastore_id |
static struct ast_custom_function | enum_function |
static struct ast_custom_function | enum_query_function |
static struct 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 477 of file func_enum.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 477 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 254 of file func_enum.c.
References args, AST_APP_ARG, ast_atomic_fetchadd_int(), ast_calloc, ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_datastore_alloc, AST_DECLARE_APP_ARGS, ast_free, ast_get_enum(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_datastore::data, enum_result_datastore_info, LOG_ERROR, LOG_WARNING, and parse().
00255 { 00256 struct enum_result_datastore *erds; 00257 struct ast_datastore *datastore; 00258 char *parse, tech[128], dest[128]; 00259 int res = -1; 00260 00261 AST_DECLARE_APP_ARGS(args, 00262 AST_APP_ARG(number); 00263 AST_APP_ARG(tech); 00264 AST_APP_ARG(zone); 00265 ); 00266 00267 if (ast_strlen_zero(data)) { 00268 ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n"); 00269 goto finish; 00270 } 00271 00272 parse = ast_strdupa(data); 00273 00274 AST_STANDARD_APP_ARGS(args, parse); 00275 00276 if (!chan) { 00277 ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n"); 00278 goto finish; 00279 } 00280 00281 if (!args.zone) 00282 args.zone = "e164.zone"; 00283 00284 ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech)); 00285 00286 if (!(erds = ast_calloc(1, sizeof(*erds)))) 00287 goto finish; 00288 00289 if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) { 00290 ast_free(erds); 00291 goto finish; 00292 } 00293 00294 erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1); 00295 00296 snprintf(buf, len, "%u", erds->id); 00297 00298 if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) { 00299 ast_free(erds->context); 00300 ast_free(erds); 00301 goto finish; 00302 } 00303 00304 ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context); 00305 00306 datastore->data = erds; 00307 00308 ast_channel_lock(chan); 00309 ast_channel_datastore_add(chan, datastore); 00310 ast_channel_unlock(chan); 00311 00312 res = 0; 00313 00314 finish: 00315 00316 return res; 00317 }
static int enum_result_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 319 of file func_enum.c.
References args, 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(), enum_result_datastore::context, ast_datastore::data, enum_result_datastore_info, LOG_ERROR, LOG_WARNING, enum_context::naptr_rrs, enum_context::naptr_rrs_count, parse(), enum_naptr_rr::result, enum_naptr_rr::sort_pos, and enum_naptr_rr::tech.
00320 { 00321 struct enum_result_datastore *erds; 00322 struct ast_datastore *datastore; 00323 char *parse, *p; 00324 unsigned int num; 00325 int res = -1, k; 00326 AST_DECLARE_APP_ARGS(args, 00327 AST_APP_ARG(id); 00328 AST_APP_ARG(resultnum); 00329 ); 00330 00331 if (ast_strlen_zero(data)) { 00332 ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n"); 00333 goto finish; 00334 } 00335 00336 if (!chan) { 00337 ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n"); 00338 goto finish; 00339 } 00340 00341 parse = ast_strdupa(data); 00342 00343 AST_STANDARD_APP_ARGS(args, parse); 00344 00345 if (ast_strlen_zero(args.id)) { 00346 ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n"); 00347 goto finish; 00348 } 00349 00350 if (ast_strlen_zero(args.resultnum)) { 00351 ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n"); 00352 goto finish; 00353 } 00354 00355 ast_channel_lock(chan); 00356 datastore = ast_channel_datastore_find(chan, &enum_result_datastore_info, args.id); 00357 ast_channel_unlock(chan); 00358 if (!datastore) { 00359 ast_log(LOG_WARNING, "No ENUM results found for query id!\n"); 00360 goto finish; 00361 } 00362 00363 erds = datastore->data; 00364 00365 if (!strcasecmp(args.resultnum, "getnum")) { 00366 snprintf(buf, len, "%u", erds->context->naptr_rrs_count); 00367 res = 0; 00368 goto finish; 00369 } 00370 00371 if (sscanf(args.resultnum, "%30u", &num) != 1) { 00372 ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum); 00373 goto finish; 00374 } 00375 00376 if (!num || num > erds->context->naptr_rrs_count) { 00377 ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id); 00378 goto finish; 00379 } 00380 00381 for (k = 0; k < erds->context->naptr_rrs_count; k++) { 00382 if (num - 1 != erds->context->naptr_rrs[k].sort_pos) 00383 continue; 00384 00385 p = strchr(erds->context->naptr_rrs[k].result, ':'); 00386 00387 if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL")) 00388 ast_copy_string(buf, p + 1, len); 00389 else 00390 ast_copy_string(buf, erds->context->naptr_rrs[k].result, len); 00391 00392 break; 00393 } 00394 00395 res = 0; 00396 00397 finish: 00398 00399 return res; 00400 }
static void erds_destroy | ( | struct enum_result_datastore * | data | ) | [static] |
Definition at line 229 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().
00230 { 00231 int k; 00232 00233 for (k = 0; k < data->context->naptr_rrs_count; k++) { 00234 ast_free(data->context->naptr_rrs[k].result); 00235 ast_free(data->context->naptr_rrs[k].tech); 00236 } 00237 00238 ast_free(data->context->naptr_rrs); 00239 ast_free(data->context); 00240 ast_free(data); 00241 }
static void erds_destroy_cb | ( | void * | data | ) | [static] |
Definition at line 243 of file func_enum.c.
References erds_destroy().
00244 { 00245 struct enum_result_datastore *erds = data; 00246 erds_destroy(erds); 00247 }
static int function_enum | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 158 of file func_enum.c.
References args, 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(), and LOG_WARNING.
00160 { 00161 AST_DECLARE_APP_ARGS(args, 00162 AST_APP_ARG(number); 00163 AST_APP_ARG(tech); 00164 AST_APP_ARG(options); 00165 AST_APP_ARG(record); 00166 AST_APP_ARG(zone); 00167 ); 00168 char tech[80]; 00169 char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = ""; 00170 char *s, *p; 00171 unsigned int record = 1; 00172 00173 buf[0] = '\0'; 00174 00175 if (ast_strlen_zero(data)) { 00176 ast_log(LOG_WARNING, "%s", synopsis); 00177 return -1; 00178 } 00179 00180 AST_STANDARD_APP_ARGS(args, data); 00181 00182 if (args.argc < 1) { 00183 ast_log(LOG_WARNING, "%s", synopsis); 00184 return -1; 00185 } 00186 00187 if (args.tech && !ast_strlen_zero(args.tech)) { 00188 ast_copy_string(tech,args.tech, sizeof(tech)); 00189 } else { 00190 ast_copy_string(tech,"sip",sizeof(tech)); 00191 } 00192 00193 if (!args.zone) { 00194 args.zone = "e164.arpa"; 00195 } 00196 if (!args.options) { 00197 args.options = ""; 00198 } 00199 if (args.record) { 00200 record = atoi(args.record) ? atoi(args.record) : record; 00201 } 00202 00203 /* strip any '-' signs from number */ 00204 for (s = p = args.number; *s; s++) { 00205 if (*s != '-') { 00206 snprintf(tmp, sizeof(tmp), "%c", *s); 00207 strncat(num, tmp, sizeof(num) - strlen(num) - 1); 00208 } 00209 00210 } 00211 ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL); 00212 00213 p = strchr(dest, ':'); 00214 if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) { 00215 ast_copy_string(buf, p + 1, len); 00216 } else { 00217 ast_copy_string(buf, dest, len); 00218 } 00219 return 0; 00220 }
static int function_txtcidname | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 417 of file func_enum.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_txt(), ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), and LOG_WARNING.
00419 { 00420 AST_DECLARE_APP_ARGS(args, 00421 AST_APP_ARG(number); 00422 AST_APP_ARG(zone); 00423 ); 00424 00425 buf[0] = '\0'; 00426 00427 if (ast_strlen_zero(data)) { 00428 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n"); 00429 return -1; 00430 } 00431 00432 AST_STANDARD_APP_ARGS(args, data); 00433 00434 if (args.argc < 1) { 00435 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n"); 00436 return -1; 00437 } 00438 00439 if (!args.zone) { 00440 args.zone = "e164.arpa"; 00441 } 00442 00443 ast_get_txt(chan, args.number, buf, len, args.zone); 00444 00445 return 0; 00446 }
static int load_module | ( | void | ) | [static] |
Definition at line 465 of file func_enum.c.
References ast_custom_function_register, enum_function, enum_query_function, enum_result_function, and txtcidname_function.
00466 { 00467 int res = 0; 00468 00469 res |= ast_custom_function_register(&enum_result_function); 00470 res |= ast_custom_function_register(&enum_query_function); 00471 res |= ast_custom_function_register(&enum_function); 00472 res |= ast_custom_function_register(&txtcidname_function); 00473 00474 return res; 00475 }
static int unload_module | ( | void | ) | [static] |
Definition at line 453 of file func_enum.c.
References ast_custom_function_unregister(), enum_function, enum_query_function, enum_result_function, and txtcidname_function.
00454 { 00455 int res = 0; 00456 00457 res |= ast_custom_function_unregister(&enum_result_function); 00458 res |= ast_custom_function_unregister(&enum_query_function); 00459 res |= ast_custom_function_unregister(&enum_function); 00460 res |= ast_custom_function_unregister(&txtcidname_function); 00461 00462 return res; 00463 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 477 of file func_enum.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 477 of file func_enum.c.
unsigned int enum_datastore_id [static] |
Definition at line 222 of file func_enum.c.
struct ast_custom_function enum_function [static] |
Initial value:
{ .name = "ENUMLOOKUP", .read = function_enum, }
Definition at line 412 of file func_enum.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function enum_query_function [static] |
Initial value:
{ .name = "ENUMQUERY", .read = enum_query_read, }
Definition at line 402 of file func_enum.c.
Referenced by load_module(), and unload_module().
struct ast_datastore_info enum_result_datastore_info [static] |
Initial value:
{ .type = "ENUMQUERY", .destroy = erds_destroy_cb, }
Definition at line 249 of file func_enum.c.
Referenced by enum_query_read(), and enum_result_read().
struct ast_custom_function enum_result_function [static] |
Initial value:
{ .name = "ENUMRESULT", .read = enum_result_read, }
Definition at line 407 of file func_enum.c.
Referenced by load_module(), and unload_module().
char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n" [static] |
Definition at line 156 of file func_enum.c.
struct ast_custom_function txtcidname_function [static] |
Initial value:
{ .name = "TXTCIDNAME", .read = function_txtcidname, }
Definition at line 448 of file func_enum.c.
Referenced by load_module(), and unload_module().