Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 480 of file func_enum.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 480 of file func_enum.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 480 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 252 of file func_enum.c.

253{
254 struct enum_result_datastore *erds;
255 struct ast_datastore *datastore;
256 char *parse, tech[128], dest[128];
257 int res = -1;
258
261 AST_APP_ARG(tech);
262 AST_APP_ARG(zone);
263 );
264
265 if (ast_strlen_zero(data)) {
266 ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
267 goto finish;
268 }
269
270 parse = ast_strdupa(data);
271
273
274 if (!chan) {
275 ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
276 goto finish;
277 }
278
279 if (!args.zone)
280 args.zone = "e164.zone";
281
282 ast_copy_string(tech, args.tech ? args.tech : "pjsip", sizeof(tech));
283
284 if (!(erds = ast_calloc(1, sizeof(*erds))))
285 goto finish;
286
287 if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
288 ast_free(erds);
289 goto finish;
290 }
291
292 erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);
293
294 snprintf(buf, len, "%u", erds->id);
295
296 if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
297 ast_free(erds->context);
298 ast_free(erds);
299 goto finish;
300 }
301
302 ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);
303
304 datastore->data = erds;
305
306 ast_channel_lock(chan);
307 ast_channel_datastore_add(chan, datastore);
308 ast_channel_unlock(chan);
309
310 res = 0;
311
312finish:
313
314 return res;
315}
#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:2404
#define ast_channel_lock(chan)
Definition: channel.h:2968
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#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:220
static const struct ast_datastore_info enum_result_datastore_info
Definition: func_enum.c:247
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:757
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:223
unsigned int id
Definition: func_enum.c:224
Number structure.
Definition: app_followme.c:154
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 317 of file func_enum.c.

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

228{
229 int k;
230
231 for (k = 0; k < data->context->naptr_rrs_count; k++) {
232 ast_free(data->context->naptr_rrs[k].result);
233 ast_free(data->context->naptr_rrs[k].tech);
234 }
235
236 ast_free(data->context->naptr_rrs);
237 ast_free(data->context);
238 ast_free(data);
239}

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 241 of file func_enum.c.

242{
243 struct enum_result_datastore *erds = data;
244 erds_destroy(erds);
245}
static void erds_destroy(struct enum_result_datastore *data)
Definition: func_enum.c:227

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 156 of file func_enum.c.

158{
161 AST_APP_ARG(tech);
163 AST_APP_ARG(record);
164 AST_APP_ARG(zone);
165 );
166 char tech[80];
167 char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
168 char *s, *p;
169 unsigned int record = 1;
170
171 buf[0] = '\0';
172
173 if (ast_strlen_zero(data)) {
175 return -1;
176 }
177
179
180 if (args.argc < 1) {
182 return -1;
183 }
184
185 if (args.tech && !ast_strlen_zero(args.tech)) {
186 ast_copy_string(tech,args.tech, sizeof(tech));
187 } else {
188 ast_copy_string(tech,"pjsip",sizeof(tech));
189 }
190
191 if (!args.zone) {
192 args.zone = "e164.arpa";
193 }
194 if (!args.options) {
195 args.options = "";
196 }
197 if (args.record) {
198 record = atoi(args.record) ? atoi(args.record) : record;
199 }
200
201 /* strip any '-' signs from number */
202 for (s = p = args.number; *s; s++) {
203 if (*s != '-') {
204 snprintf(tmp, sizeof(tmp), "%c", *s);
205 strncat(num, tmp, sizeof(num) - strlen(num) - 1);
206 }
207
208 }
209 ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
210
211 p = strchr(dest, ':');
212 if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
213 ast_copy_string(buf, p + 1, len);
214 } else {
215 ast_copy_string(buf, dest, len);
216 }
217 return 0;
218}
static int tmp()
Definition: bt_open.c:389
#define AST_MAX_EXTENSION
Definition: channel.h:134
static char * synopsis
Definition: func_enum.c:154
#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, synopsis, and tmp().

◆ function_txtcidname()

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

Definition at line 415 of file func_enum.c.

417{
420 AST_APP_ARG(zone);
421 );
422
423 buf[0] = '\0';
424
425 if (ast_strlen_zero(data)) {
426 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
427 return -1;
428 }
429
431
432 if (args.argc < 1) {
433 ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
434 return -1;
435 }
436
437 if (!args.zone) {
438 args.zone = "e164.arpa";
439 }
440
441 ast_get_txt(chan, args.number, buf, len, args.zone);
442
443 return 0;
444}
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 463 of file func_enum.c.

464{
465 int res = 0;
466
471
472 return res;
473}
static struct ast_custom_function txtcidname_function
Definition: func_enum.c:446
static struct ast_custom_function enum_query_function
Definition: func_enum.c:400
static struct ast_custom_function enum_result_function
Definition: func_enum.c:405
static struct ast_custom_function enum_function
Definition: func_enum.c:410
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

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 451 of file func_enum.c.

452{
453 int res = 0;
454
459
460 return res;
461}
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 480 of file func_enum.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 480 of file func_enum.c.

◆ enum_datastore_id

unsigned int enum_datastore_id
static

Definition at line 220 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:156

Definition at line 410 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:252

Definition at line 400 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:241

Definition at line 247 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:317

Definition at line 405 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:415

Definition at line 446 of file func_enum.c.

Referenced by load_module(), and unload_module().