Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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 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

Function Documentation

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

255 {
256  struct enum_result_datastore *erds;
257  struct ast_datastore *datastore;
258  char *parse, tech[128], dest[128];
259  int res = -1;
260 
263  AST_APP_ARG(tech);
264  AST_APP_ARG(zone);
265  );
266 
267  if (ast_strlen_zero(data)) {
268  ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
269  goto finish;
270  }
271 
272  parse = ast_strdupa(data);
273 
274  AST_STANDARD_APP_ARGS(args, parse);
275 
276  if (!chan) {
277  ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
278  goto finish;
279  }
280 
281  if (!args.zone)
282  args.zone = "e164.zone";
283 
284  ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
285 
286  if (!(erds = ast_calloc(1, sizeof(*erds))))
287  goto finish;
288 
289  if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
290  ast_free(erds);
291  goto finish;
292  }
293 
294  erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);
295 
296  snprintf(buf, len, "%u", erds->id);
297 
298  if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
299  ast_free(erds->context);
300  ast_free(erds);
301  goto finish;
302  }
303 
304  ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);
305 
306  datastore->data = erds;
307 
308  ast_channel_lock(chan);
309  ast_channel_datastore_add(chan, datastore);
310  ast_channel_unlock(chan);
311 
312  res = 0;
313 
314 finish:
315 
316  return res;
317 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static struct ast_datastore_info enum_result_datastore_info
Definition: func_enum.c:249
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Definition: app.h:572
Structure for a data store object.
Definition: datastore.h:54
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
Definition: lock.h:603
Number structure.
Definition: app_followme.c:109
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
struct enum_context * context
Definition: func_enum.c:225
static unsigned int enum_datastore_id
Definition: func_enum.c:222
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
Definition: datastore.c:98
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
#define ast_free(a)
Definition: astmm.h:97
void * data
Definition: datastore.h:56
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:632
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int id
Definition: func_enum.c:226
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Definition: app.h:604
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2590
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, 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.

320 {
321  struct enum_result_datastore *erds;
322  struct ast_datastore *datastore;
323  char *parse, *p;
324  unsigned int num;
325  int res = -1, k;
327  AST_APP_ARG(id);
328  AST_APP_ARG(resultnum);
329  );
330 
331  if (ast_strlen_zero(data)) {
332  ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
333  goto finish;
334  }
335 
336  if (!chan) {
337  ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n");
338  goto finish;
339  }
340 
341  parse = ast_strdupa(data);
342 
343  AST_STANDARD_APP_ARGS(args, parse);
344 
345  if (ast_strlen_zero(args.id)) {
346  ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n");
347  goto finish;
348  }
349 
350  if (ast_strlen_zero(args.resultnum)) {
351  ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n");
352  goto finish;
353  }
354 
355  ast_channel_lock(chan);
357  ast_channel_unlock(chan);
358  if (!datastore) {
359  ast_log(LOG_WARNING, "No ENUM results found for query id!\n");
360  goto finish;
361  }
362 
363  erds = datastore->data;
364 
365  if (!strcasecmp(args.resultnum, "getnum")) {
366  snprintf(buf, len, "%d", erds->context->naptr_rrs_count);
367  res = 0;
368  goto finish;
369  }
370 
371  if (sscanf(args.resultnum, "%30u", &num) != 1) {
372  ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
373  goto finish;
374  }
375 
376  if (!num || num > erds->context->naptr_rrs_count) {
377  ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
378  goto finish;
379  }
380 
381  for (k = 0; k < erds->context->naptr_rrs_count; k++) {
382  if (num - 1 != erds->context->naptr_rrs[k].sort_pos)
383  continue;
384 
385  p = strchr(erds->context->naptr_rrs[k].result, ':');
386 
387  if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL"))
388  ast_copy_string(buf, p + 1, len);
389  else
390  ast_copy_string(buf, erds->context->naptr_rrs[k].result, len);
391 
392  break;
393  }
394 
395  res = 0;
396 
397 finish:
398 
399  return res;
400 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static struct ast_datastore_info enum_result_datastore_info
Definition: func_enum.c:249
struct enum_naptr_rr * naptr_rrs
Definition: enum.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Structure for a data store object.
Definition: datastore.h:54
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:2604
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
struct enum_context * context
Definition: func_enum.c:225
char * tech
Definition: enum.h:36
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
void * data
Definition: datastore.h:56
char * result
Definition: enum.h:35
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int naptr_rrs_count
Definition: enum.h:52
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
int sort_pos
Definition: enum.h:37
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().

230 {
231  int k;
232 
233  for (k = 0; k < data->context->naptr_rrs_count; k++) {
234  ast_free(data->context->naptr_rrs[k].result);
235  ast_free(data->context->naptr_rrs[k].tech);
236  }
237 
238  ast_free(data->context->naptr_rrs);
239  ast_free(data->context);
240  ast_free(data);
241 }
struct enum_naptr_rr * naptr_rrs
Definition: enum.h:51
struct enum_context * context
Definition: func_enum.c:225
char * tech
Definition: enum.h:36
#define ast_free(a)
Definition: astmm.h:97
char * result
Definition: enum.h:35
int naptr_rrs_count
Definition: enum.h:52
static void erds_destroy_cb ( void *  data)
static

Definition at line 243 of file func_enum.c.

References erds_destroy().

244 {
245  struct enum_result_datastore *erds = data;
246  erds_destroy(erds);
247 }
static void erds_destroy(struct enum_result_datastore *data)
Definition: func_enum.c:229
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.

160 {
163  AST_APP_ARG(tech);
164  AST_APP_ARG(options);
165  AST_APP_ARG(record);
166  AST_APP_ARG(zone);
167  );
168  char tech[80];
169  char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
170  char *s, *p;
171  unsigned int record = 1;
172 
173  buf[0] = '\0';
174 
175  if (ast_strlen_zero(data)) {
176  ast_log(LOG_WARNING, "%s", synopsis);
177  return -1;
178  }
179 
181 
182  if (args.argc < 1) {
183  ast_log(LOG_WARNING, "%s", synopsis);
184  return -1;
185  }
186 
187  if (args.tech && !ast_strlen_zero(args.tech)) {
188  ast_copy_string(tech,args.tech, sizeof(tech));
189  } else {
190  ast_copy_string(tech,"sip",sizeof(tech));
191  }
192 
193  if (!args.zone) {
194  args.zone = "e164.arpa";
195  }
196  if (!args.options) {
197  args.options = "";
198  }
199  if (args.record) {
200  record = atoi(args.record) ? atoi(args.record) : record;
201  }
202 
203  /* strip any '-' signs from number */
204  for (s = p = args.number; *s; s++) {
205  if (*s != '-') {
206  snprintf(tmp, sizeof(tmp), "%c", *s);
207  strncat(num, tmp, sizeof(num) - strlen(num) - 1);
208  }
209 
210  }
211  ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
212 
213  p = strchr(dest, ':');
214  if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
215  ast_copy_string(buf, p + 1, len);
216  } else {
217  ast_copy_string(buf, dest, len);
218  }
219  return 0;
220 }
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Number structure.
Definition: app_followme.c:109
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_MAX_EXTENSION
Definition: channel.h:135
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static char * synopsis
Definition: func_enum.c:156
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:632
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
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.

419 {
422  AST_APP_ARG(zone);
423  );
424 
425  buf[0] = '\0';
426 
427  if (ast_strlen_zero(data)) {
428  ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
429  return -1;
430  }
431 
433 
434  if (args.argc < 1) {
435  ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
436  return -1;
437  }
438 
439  if (!args.zone) {
440  args.zone = "e164.arpa";
441  }
442 
443  ast_get_txt(chan, args.number, buf, len, args.zone);
444 
445  return 0;
446 }
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Number structure.
Definition: app_followme.c:109
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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:927
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int load_module ( void  )
static

Definition at line 465 of file func_enum.c.

References ast_custom_function_register.

466 {
467  int res = 0;
468 
473 
474  return res;
475 }
static struct ast_custom_function enum_query_function
Definition: func_enum.c:402
static struct ast_custom_function enum_function
Definition: func_enum.c:412
static struct ast_custom_function txtcidname_function
Definition: func_enum.c:448
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static struct ast_custom_function enum_result_function
Definition: func_enum.c:407
static int unload_module ( void  )
static

Definition at line 453 of file func_enum.c.

References ast_custom_function_unregister().

454 {
455  int res = 0;
456 
461 
462  return res;
463 }
static struct ast_custom_function enum_query_function
Definition: func_enum.c:402
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function enum_function
Definition: func_enum.c:412
static struct ast_custom_function txtcidname_function
Definition: func_enum.c:448
static struct ast_custom_function enum_result_function
Definition: func_enum.c:407

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 477 of file func_enum.c.

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,
}
static int function_enum(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_enum.c:158

Definition at line 412 of file func_enum.c.

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:254

Definition at line 402 of file func_enum.c.

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:243

Definition at line 249 of file func_enum.c.

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:319

Definition at line 407 of file func_enum.c.

char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options[,record#[,zone-suffix]]]])\n"
static
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:417

Definition at line 448 of file func_enum.c.