Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Functions | Variables
func_enum.c File Reference

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"
Include dependency graph for func_enum.c:

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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "enum", }
 
static const struct ast_module_infoast_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 const 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
 

Detailed Description

ENUM Functions.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Oleksiy Krivoshey oleks.nosp@m.iyk@.nosp@m.gmail.nosp@m..com
Russell Bryant russe.nosp@m.lb@c.nosp@m.lemso.nosp@m.n.ed.nosp@m.u
Brett Bryant bbrya.nosp@m.nt@d.nosp@m.igium.nosp@m..com

Definition in file func_enum.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 492 of file func_enum.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 492 of file func_enum.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 492 of file func_enum.c.

◆ enum_query_read()

static int enum_query_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 264 of file func_enum.c.

265{
266 struct enum_result_datastore *erds;
267 struct ast_datastore *datastore;
268 char *parse, tech[128], dest[128];
269 int res = -1;
270
273 AST_APP_ARG(tech);
274 AST_APP_ARG(zone);
275 );
276
277 if (ast_strlen_zero(data)) {
278 ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
279 goto finish;
280 }
281
282 parse = ast_strdupa(data);
283
285
286 if (!chan) {
287 ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
288 goto finish;
289 }
290
291 if (!args.zone)
292 args.zone = "e164.zone";
293
294 ast_copy_string(tech, args.tech ? args.tech : "pjsip", sizeof(tech));
295
296 if (!(erds = ast_calloc(1, sizeof(*erds))))
297 goto finish;
298
299 if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
300 ast_free(erds);
301 goto finish;
302 }
303
304 erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);
305
306 snprintf(buf, len, "%u", erds->id);
307
308 if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
309 ast_free(erds->context);
310 ast_free(erds);
311 goto finish;
312 }
313
314 ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);
315
316 datastore->data = erds;
317
318 ast_channel_lock(chan);
319 ast_channel_datastore_add(chan, datastore);
320 ast_channel_unlock(chan);
321
322 res = 0;
323
324finish:
325
326 return res;
327}
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2414
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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.
Definition: enum.c:649
static unsigned int enum_datastore_id
Definition: func_enum.c:232
static const struct ast_datastore_info enum_result_datastore_info
Definition: func_enum.c:259
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_ERROR
#define LOG_WARNING
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:761
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
struct enum_context * context
Definition: func_enum.c:235
unsigned int id
Definition: func_enum.c:236
Number structure.
Definition: app_followme.c:157
const char * args

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(), buf, enum_result_datastore::context, ast_datastore::data, enum_datastore_id, enum_result_datastore_info, enum_result_datastore::id, len(), LOG_ERROR, and LOG_WARNING.

◆ enum_result_read()

static int enum_result_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 329 of file func_enum.c.

330{
331 struct enum_result_datastore *erds;
332 struct ast_datastore *datastore;
333 char *parse, *p;
334 unsigned int num;
335 int res = -1, k;
337 AST_APP_ARG(id);
338 AST_APP_ARG(resultnum);
339 );
340
341 if (ast_strlen_zero(data)) {
342 ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
343 goto finish;
344 }
345
346 if (!chan) {
347 ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n");
348 goto finish;
349 }
350
351 parse = ast_strdupa(data);
352
354
355 if (ast_strlen_zero(args.id)) {
356 ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n");
357 goto finish;
358 }
359
360 if (ast_strlen_zero(args.resultnum)) {
361 ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n");
362 goto finish;
363 }
364
365 ast_channel_lock(chan);
367 ast_channel_unlock(chan);
368 if (!datastore) {
369 ast_log(LOG_WARNING, "No ENUM results found for query id!\n");
370 goto finish;
371 }
372
373 erds = datastore->data;
374
375 if (!strcasecmp(args.resultnum, "getnum")) {
376 snprintf(buf, len, "%d", erds->context->naptr_rrs_count);
377 res = 0;
378 goto finish;
379 }
380
381 if (sscanf(args.resultnum, "%30u", &num) != 1) {
382 ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
383 goto finish;
384 }
385
386 if (!num || num > erds->context->naptr_rrs_count) {
387 ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
388 goto finish;
389 }
390
391 for (k = 0; k < erds->context->naptr_rrs_count; k++) {
392 if (num - 1 != erds->context->naptr_rrs[k].sort_pos)
393 continue;
394
395 p = strchr(erds->context->naptr_rrs[k].result, ':');
396
397 if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL"))
398 ast_copy_string(buf, p + 1, len);
399 else
401
402 break;
403 }
404
405 res = 0;
406
407finish:
408
409 return res;
410}
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.
Definition: channel.c:2428
int naptr_rrs_count
Definition: enum.h:54
struct enum_naptr_rr * naptr_rrs
Definition: enum.h:53
char * result
Definition: enum.h:37
char * tech
Definition: enum.h:38
int sort_pos
Definition: enum.h:39

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(), buf, enum_result_datastore::context, ast_datastore::data, enum_result_datastore_info, len(), LOG_ERROR, LOG_WARNING, enum_context::naptr_rrs, enum_context::naptr_rrs_count, enum_naptr_rr::result, enum_naptr_rr::sort_pos, and enum_naptr_rr::tech.

◆ erds_destroy()

static void erds_destroy ( struct enum_result_datastore data)
static

Definition at line 239 of file func_enum.c.

240{
241 int k;
242
243 for (k = 0; k < data->context->naptr_rrs_count; k++) {
244 ast_free(data->context->naptr_rrs[k].result);
245 ast_free(data->context->naptr_rrs[k].tech);
246 }
247
248 ast_free(data->context->naptr_rrs);
249 ast_free(data->context);
250 ast_free(data);
251}

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().

◆ erds_destroy_cb()

static void erds_destroy_cb ( void *  data)
static

Definition at line 253 of file func_enum.c.

254{
255 struct enum_result_datastore *erds = data;
256 erds_destroy(erds);
257}
static void erds_destroy(struct enum_result_datastore *data)
Definition: func_enum.c:239

References erds_destroy().

◆ function_enum()

static int function_enum ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 168 of file func_enum.c.

170{
173 AST_APP_ARG(tech);
175 AST_APP_ARG(record);
176 AST_APP_ARG(zone);
177 );
178 char tech[80];
179 char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
180 char *s, *p;
181 unsigned int record = 1;
182
183 buf[0] = '\0';
184
185 if (ast_strlen_zero(data)) {
187 return -1;
188 }
189
191
192 if (args.argc < 1) {
194 return -1;
195 }
196
197 if (args.tech && !ast_strlen_zero(args.tech)) {
198 ast_copy_string(tech,args.tech, sizeof(tech));
199 } else {
200 ast_copy_string(tech,"pjsip",sizeof(tech));
201 }
202
203 if (!args.zone) {
204 args.zone = "e164.arpa";
205 }
206 if (!args.options) {
207 args.options = "";
208 }
209 if (args.record) {
210 record = atoi(args.record) ? atoi(args.record) : record;
211 }
212
213 /* strip any '-' signs from number */
214 for (s = p = args.number; *s; s++) {
215 if (*s != '-') {
216 snprintf(tmp, sizeof(tmp), "%c", *s);
217 strncat(num, tmp, sizeof(num) - strlen(num) - 1);
218 }
219
220 }
221 ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
222
223 p = strchr(dest, ':');
224 if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
225 ast_copy_string(buf, p + 1, len);
226 } else {
227 ast_copy_string(buf, dest, len);
228 }
229 return 0;
230}
#define AST_MAX_EXTENSION
Definition: channel.h:134
static char * synopsis
Definition: func_enum.c:166
#define NULL
Definition: resample.c:96
static struct test_options options

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(), buf, len(), LOG_WARNING, NULL, options, and synopsis.

◆ function_txtcidname()

static int function_txtcidname ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 427 of file func_enum.c.

429{
432 AST_APP_ARG(zone);
433 );
434
435 buf[0] = '\0';
436
437 if (ast_strlen_zero(data)) {
438 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
439 return -1;
440 }
441
443
444 if (args.argc < 1) {
445 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
446 return -1;
447 }
448
449 if (!args.zone) {
450 args.zone = "e164.arpa";
451 }
452
453 ast_get_txt(chan, args.number, buf, len, args.zone);
454
455 return 0;
456}
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)
Definition: enum.c:995

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_txt(), ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), buf, len(), and LOG_WARNING.

◆ load_module()

static int load_module ( void  )
static

Definition at line 475 of file func_enum.c.

476{
477 int res = 0;
478
483
484 return res;
485}
static struct ast_custom_function txtcidname_function
Definition: func_enum.c:458
static struct ast_custom_function enum_query_function
Definition: func_enum.c:412
static struct ast_custom_function enum_result_function
Definition: func_enum.c:417
static struct ast_custom_function enum_function
Definition: func_enum.c:422
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559

References ast_custom_function_register, enum_function, enum_query_function, enum_result_function, and txtcidname_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 463 of file func_enum.c.

464{
465 int res = 0;
466
471
472 return res;
473}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), enum_function, enum_query_function, enum_result_function, and txtcidname_function.

Variable Documentation

◆ __mod_info

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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "enum", }
static

Definition at line 492 of file func_enum.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 492 of file func_enum.c.

◆ enum_datastore_id

unsigned int enum_datastore_id
static

Definition at line 232 of file func_enum.c.

Referenced by enum_query_read().

◆ enum_function

struct ast_custom_function enum_function
static
Initial value:
= {
.name = "ENUMLOOKUP",
.read = function_enum,
}
static int function_enum(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_enum.c:168

Definition at line 422 of file func_enum.c.

Referenced by load_module(), and unload_module().

◆ enum_query_function

struct ast_custom_function enum_query_function
static
Initial value:
= {
.name = "ENUMQUERY",
.read = enum_query_read,
}
static int enum_query_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_enum.c:264

Definition at line 412 of file func_enum.c.

Referenced by load_module(), and unload_module().

◆ enum_result_datastore_info

const struct ast_datastore_info enum_result_datastore_info
static
Initial value:
= {
.type = "ENUMQUERY",
.destroy = erds_destroy_cb,
}
static void erds_destroy_cb(void *data)
Definition: func_enum.c:253

Definition at line 259 of file func_enum.c.

Referenced by enum_query_read(), and enum_result_read().

◆ enum_result_function

struct ast_custom_function enum_result_function
static
Initial value:
= {
.name = "ENUMRESULT",
}
static int enum_result_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_enum.c:329

Definition at line 417 of file func_enum.c.

Referenced by load_module(), and unload_module().

◆ synopsis

char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n"
static

◆ txtcidname_function

struct ast_custom_function txtcidname_function
static
Initial value:
= {
.name = "TXTCIDNAME",
}
static int function_txtcidname(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_enum.c:427

Definition at line 458 of file func_enum.c.

Referenced by load_module(), and unload_module().