154 static char *
synopsis =
"Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n";
156 static int function_enum(
struct ast_channel *chan,
const char *cmd,
char *data,
157 char *buf,
size_t len)
169 unsigned int record = 1;
173 if (ast_strlen_zero(data)) {
174 ast_log(LOG_WARNING,
"%s",
synopsis);
181 ast_log(LOG_WARNING,
"%s",
synopsis);
185 if (args.tech && !ast_strlen_zero(args.tech)) {
192 args.zone =
"e164.arpa";
198 record = atoi(args.record) ? atoi(args.record) : record;
202 for (s = p = args.number; *s; s++) {
204 snprintf(tmp,
sizeof(tmp),
"%c", *s);
205 strncat(num, tmp,
sizeof(num) - strlen(num) - 1);
209 ast_get_enum(chan, num, dest,
sizeof(dest), tech,
sizeof(tech), args.zone, args.options, record, NULL);
211 p = strchr(dest,
':');
212 if (p && strcasecmp(tech,
"ALL") && !strchr(args.options,
'u')) {
220 static unsigned int enum_datastore_id;
237 ast_free(data->context);
241 static void erds_destroy_cb(
void *data)
249 .destroy = erds_destroy_cb,
252 static int enum_query_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
256 char *parse, tech[128], dest[128];
265 if (ast_strlen_zero(data)) {
266 ast_log(LOG_WARNING,
"ENUMQUERY requires at least a number as an argument...\n");
275 ast_log(LOG_ERROR,
"ENUMQUERY cannot be used without a channel!\n");
280 args.zone =
"e164.zone";
287 if (!(erds->context =
ast_calloc(1,
sizeof(*erds->context)))) {
294 snprintf(buf, len,
"%u", erds->id);
296 if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
297 ast_free(erds->context);
302 ast_get_enum(chan, args.number, dest,
sizeof(dest), tech,
sizeof(tech), args.zone,
"", 1, &erds->context);
304 datastore->
data = erds;
306 ast_channel_lock(chan);
308 ast_channel_unlock(chan);
317 static int enum_result_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
329 if (ast_strlen_zero(data)) {
330 ast_log(LOG_WARNING,
"ENUMRESULT requires two arguments (id and resultnum)\n");
335 ast_log(LOG_ERROR,
"ENUMRESULT can not be used without a channel!\n");
343 if (ast_strlen_zero(args.id)) {
344 ast_log(LOG_ERROR,
"A result ID must be provided to ENUMRESULT\n");
348 if (ast_strlen_zero(args.resultnum)) {
349 ast_log(LOG_ERROR,
"A result number must be given to ENUMRESULT!\n");
353 ast_channel_lock(chan);
355 ast_channel_unlock(chan);
357 ast_log(LOG_WARNING,
"No ENUM results found for query id!\n");
361 erds = datastore->
data;
363 if (!strcasecmp(args.resultnum,
"getnum")) {
369 if (sscanf(args.resultnum,
"%30u", &num) != 1) {
370 ast_log(LOG_ERROR,
"Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
375 ast_log(LOG_WARNING,
"Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
385 if (p && strcasecmp(erds->context->
naptr_rrs[k].
tech,
"ALL"))
402 .read = enum_query_read,
406 .
name =
"ENUMRESULT",
407 .read = enum_result_read,
411 .
name =
"ENUMLOOKUP",
412 .read = function_enum,
415 static int function_txtcidname(
struct ast_channel *chan,
const char *cmd,
416 char *data,
char *buf,
size_t len)
425 if (ast_strlen_zero(data)) {
426 ast_log(LOG_WARNING,
"Syntax: TXTCIDNAME(number[,zone-suffix])\n");
433 ast_log(LOG_WARNING,
"Syntax: TXTCIDNAME(number[,zone-suffix])\n");
438 args.zone =
"e164.arpa";
441 ast_get_txt(chan, args.number, buf, len, args.zone);
447 .
name =
"TXTCIDNAME",
448 .read = function_txtcidname,
451 static int unload_module(
void)
463 static int load_module(
void)
475 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"ENUM related dialplan functions",
476 .support_level = AST_MODULE_SUPPORT_CORE,
478 .unload = unload_module,
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct enum_naptr_rr * naptr_rrs
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Structure for a data store type.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
#define AST_MAX_EXTENSION
Core PBX routines and definitions.
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_get_txt(struct ast_channel *chan, const char *number, char *txt, int maxtxt, char *suffix)
Lookup DNS TXT record (used by app TXTCIDnum)
const ast_string_field synopsis
int ast_get_enum(struct ast_channel *chan, const char *number, char *location, int maxloc, char *technology, int maxtech, char *suffix, char *options, unsigned int record, struct enum_context **argcontext)
Lookup entry in ENUM.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.