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