Thu Apr 28 2011 17:16:06

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"
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)
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
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ENUM related dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
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

Detailed Description

ENUM Functions.

Author:
Mark Spencer <markster@digium.com>
Oleksiy Krivoshey <oleksiyk@gmail.com>
Russell Bryant <russelb@clemson.edu>
Brett Bryant <bbryant@digium.com>
  • See also AstENUM

Definition in file func_enum.c.


Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 475 of file func_enum.c.

static void __unreg_module ( void  ) [static]

Definition at line 475 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 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.

{
   struct enum_result_datastore *erds;
   struct ast_datastore *datastore;
   char *parse, tech[128], dest[128];
   int res = -1;

   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(number);
      AST_APP_ARG(tech);
      AST_APP_ARG(zone);
   );

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
      goto finish;
   }

   parse = ast_strdupa(data);
    
   AST_STANDARD_APP_ARGS(args, parse);

   if (!chan) {
      ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
      goto finish;
   }

   if (!args.zone)
      args.zone = "e164.zone";

   ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));

   if (!(erds = ast_calloc(1, sizeof(*erds))))
      goto finish;

   if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
      ast_free(erds);
      goto finish;
   }

   erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);

   snprintf(buf, len, "%u", erds->id);

   if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
      ast_free(erds->context);
      ast_free(erds);
      goto finish;
   }

   ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);

   datastore->data = erds;

   ast_channel_lock(chan);
   ast_channel_datastore_add(chan, datastore);
   ast_channel_unlock(chan);
   
   res = 0;
    
finish:

   return res;
}
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.

{
   struct enum_result_datastore *erds;
   struct ast_datastore *datastore;
   char *parse, *p;
   unsigned int num;
   int res = -1, k;
   AST_DECLARE_APP_ARGS(args, 
      AST_APP_ARG(id);
      AST_APP_ARG(resultnum);
   );

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
      goto finish;
   }

   if (!chan) {
      ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n");
      goto finish;
   }
   
   parse = ast_strdupa(data);

   AST_STANDARD_APP_ARGS(args, parse);

   if (ast_strlen_zero(args.id)) {
      ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n");
      goto finish;
   }

   if (ast_strlen_zero(args.resultnum)) {
      ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n");
      goto finish;
   }

   ast_channel_lock(chan);
   datastore = ast_channel_datastore_find(chan, &enum_result_datastore_info, args.id);
   ast_channel_unlock(chan);
   if (!datastore) {
      ast_log(LOG_WARNING, "No ENUM results found for query id!\n");
      goto finish;
   }

   erds = datastore->data;

   if (!strcasecmp(args.resultnum, "getnum")) {
      snprintf(buf, len, "%u", erds->context->naptr_rrs_count);
      res = 0;
      goto finish;
   }

   if (sscanf(args.resultnum, "%30u", &num) != 1) {
      ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
      goto finish;
   }

   if (!num || num > erds->context->naptr_rrs_count) {
      ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
      goto finish;
   }

   for (k = 0; k < erds->context->naptr_rrs_count; k++) {
      if (num - 1 != erds->context->naptr_rrs[k].sort_pos)
         continue;

      p = strchr(erds->context->naptr_rrs[k].result, ':');
              
      if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL"))
         ast_copy_string(buf, p + 1, len);
      else
         ast_copy_string(buf, erds->context->naptr_rrs[k].result, len);

      break;
   }

   res = 0;

finish:

   return res;
}
static void erds_destroy ( struct enum_result_datastore data) [static]
static void erds_destroy_cb ( void *  data) [static]

Definition at line 240 of file func_enum.c.

References erds_destroy().

{
   struct enum_result_datastore *erds = data;
   erds_destroy(erds);
}
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.

{
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(number);
      AST_APP_ARG(tech);
      AST_APP_ARG(options);
      AST_APP_ARG(record);
      AST_APP_ARG(zone);
   );
   int res = 0;
   char tech[80];
   char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
   char *s, *p;
   unsigned int record = 1;

   buf[0] = '\0';

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "%s", synopsis);
      return -1;
   }

   AST_STANDARD_APP_ARGS(args, data);

   if (args.argc < 1) {
      ast_log(LOG_WARNING, "%s", synopsis);
      return -1;
   }

   if (args.tech && !ast_strlen_zero(args.tech)) {
      ast_copy_string(tech,args.tech, sizeof(tech));
   } else {
      ast_copy_string(tech,"sip",sizeof(tech));
   }

   if (!args.zone) {
      args.zone = "e164.arpa";
   }
   if (!args.options) {
      args.options = "";
   }
   if (args.record) {
      record = atoi(args.record) ? atoi(args.record) : record;
   }

   /* strip any '-' signs from number */
   for (s = p = args.number; *s; s++) {
      if (*s != '-') {
         snprintf(tmp, sizeof(tmp), "%c", *s);
         strncat(num, tmp, sizeof(num) - strlen(num) - 1);
      }

   }
   res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);

   p = strchr(dest, ':');
   if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
      ast_copy_string(buf, p + 1, len);
   } else {
      ast_copy_string(buf, dest, len);
   }
   return 0;
}
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.

{
   int res;
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(number);
      AST_APP_ARG(zone);
   );

   buf[0] = '\0';

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
      return -1;
   }

   AST_STANDARD_APP_ARGS(args, data);

   if (args.argc < 1) {
      ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
      return -1;
   }

   if (!args.zone) {
      args.zone = "e164.arpa";
   }

   res = ast_get_txt(chan, args.number, buf, len, args.zone);

   return 0;
}
static int load_module ( void  ) [static]
static int unload_module ( void  ) [static]

Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ENUM related dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 475 of file func_enum.c.

Definition at line 475 of file func_enum.c.

unsigned int enum_datastore_id

Definition at line 219 of file func_enum.c.

Initial value:
 {
   .name = "ENUMLOOKUP",
   .read = function_enum,
}

Definition at line 409 of file func_enum.c.

Initial value:
 {
   .name = "ENUMQUERY",
   .read = enum_query_read,
}

Definition at line 399 of file func_enum.c.

Initial value:
 {
   .type = "ENUMQUERY",
   .destroy = erds_destroy_cb,
}

Definition at line 246 of file func_enum.c.

Initial value:
 {
   .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.

Initial value:
 {
   .name = "TXTCIDNAME",
   .read = function_txtcidname,
}

Definition at line 446 of file func_enum.c.