Fri Jun 19 12:10:37 2009

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_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 = "a9c98e5d177805051735cb5b0b16b0a0" , .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
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>

Definition in file func_enum.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 406 of file func_enum.c.

static void __unreg_module ( void   )  [static]

Definition at line 406 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 148 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(), chan, ast_datastore::data, enum_result_datastore_info, LOG_ERROR, LOG_WARNING, parse(), and ast_channel::zone.

00149 {
00150    struct enum_result_datastore *erds;
00151    struct ast_datastore *datastore;
00152    char *parse, tech[128], dest[128];
00153    int res = -1;
00154 
00155    AST_DECLARE_APP_ARGS(args,
00156       AST_APP_ARG(number);
00157       AST_APP_ARG(tech);
00158       AST_APP_ARG(zone);
00159    );
00160 
00161    if (ast_strlen_zero(data)) {
00162       ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
00163       goto finish;
00164    }
00165 
00166    parse = ast_strdupa(data);
00167     
00168    AST_STANDARD_APP_ARGS(args, parse);
00169 
00170    if (!chan) {
00171       ast_log(LOG_ERROR, "ENUMQUERY cannot be used without a channel!\n");
00172       goto finish;
00173    }
00174 
00175    if (!args.zone)
00176       args.zone = "e164.zone";
00177 
00178    ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
00179 
00180    if (!(erds = ast_calloc(1, sizeof(*erds))))
00181       goto finish;
00182 
00183    if (!(erds->context = ast_calloc(1, sizeof(*erds->context)))) {
00184       ast_free(erds);
00185       goto finish;
00186    }
00187 
00188    erds->id = ast_atomic_fetchadd_int((int *) &enum_datastore_id, 1);
00189 
00190    snprintf(buf, len, "%u", erds->id);
00191 
00192    if (!(datastore = ast_datastore_alloc(&enum_result_datastore_info, buf))) {
00193       ast_free(erds->context);
00194       ast_free(erds);
00195       goto finish;
00196    }
00197 
00198    ast_get_enum(chan, args.number, dest, sizeof(dest), tech, sizeof(tech), args.zone, "", 1, &erds->context);
00199 
00200    datastore->data = erds;
00201 
00202    ast_channel_lock(chan);
00203    ast_channel_datastore_add(chan, datastore);
00204    ast_channel_unlock(chan);
00205    
00206    res = 0;
00207     
00208 finish:
00209 
00210    return res;
00211 }

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

Definition at line 213 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(), chan, enum_result_datastore::context, ast_datastore::data, enum_result_datastore_info, 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.

00214 {
00215    struct enum_result_datastore *erds;
00216    struct ast_datastore *datastore;
00217    char *parse, *p;
00218    unsigned int num;
00219    int res = -1, k;
00220    AST_DECLARE_APP_ARGS(args, 
00221       AST_APP_ARG(id);
00222       AST_APP_ARG(resultnum);
00223    );
00224 
00225    if (ast_strlen_zero(data)) {
00226       ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
00227       goto finish;
00228    }
00229 
00230    if (!chan) {
00231       ast_log(LOG_ERROR, "ENUMRESULT can not be used without a channel!\n");
00232       goto finish;
00233    }
00234    
00235    parse = ast_strdupa(data);
00236 
00237    AST_STANDARD_APP_ARGS(args, parse);
00238 
00239    if (ast_strlen_zero(args.id)) {
00240       ast_log(LOG_ERROR, "A result ID must be provided to ENUMRESULT\n");
00241       goto finish;
00242    }
00243 
00244    if (ast_strlen_zero(args.resultnum)) {
00245       ast_log(LOG_ERROR, "A result number must be given to ENUMRESULT!\n");
00246       goto finish;
00247    }
00248 
00249    ast_channel_lock(chan);
00250    datastore = ast_channel_datastore_find(chan, &enum_result_datastore_info, args.id);
00251    ast_channel_unlock(chan);
00252    if (!datastore) {
00253       ast_log(LOG_WARNING, "No ENUM results found for query id!\n");
00254       goto finish;
00255    }
00256 
00257    erds = datastore->data;
00258 
00259    if (!strcasecmp(args.resultnum, "getnum")) {
00260       snprintf(buf, len, "%u", erds->context->naptr_rrs_count);
00261       res = 0;
00262       goto finish;
00263    }
00264 
00265    if (sscanf(args.resultnum, "%u", &num) != 1) {
00266       ast_log(LOG_ERROR, "Invalid value '%s' for resultnum to ENUMRESULT!\n", args.resultnum);
00267       goto finish;
00268    }
00269 
00270    if (!num || num > erds->context->naptr_rrs_count) {
00271       ast_log(LOG_WARNING, "Result number %u is not valid for ENUM query results for ID %s!\n", num, args.id);
00272       goto finish;
00273    }
00274 
00275    for (k = 0; k < erds->context->naptr_rrs_count; k++) {
00276       if (num - 1 != erds->context->naptr_rrs[k].sort_pos)
00277          continue;
00278 
00279       p = strchr(erds->context->naptr_rrs[k].result, ':');
00280               
00281       if (p && strcasecmp(erds->context->naptr_rrs[k].tech, "ALL"))
00282          ast_copy_string(buf, p + 1, len);
00283       else
00284          ast_copy_string(buf, erds->context->naptr_rrs[k].result, len);
00285 
00286       break;
00287    }
00288 
00289    res = 0;
00290 
00291 finish:
00292 
00293    return res;
00294 }

static void erds_destroy ( struct enum_result_datastore data  )  [static]

Definition at line 123 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().

00124 {
00125    int k;
00126 
00127    for (k = 0; k < data->context->naptr_rrs_count; k++) {
00128       ast_free(data->context->naptr_rrs[k].result);
00129       ast_free(data->context->naptr_rrs[k].tech);
00130    }
00131 
00132    ast_free(data->context->naptr_rrs);
00133    ast_free(data->context);
00134    ast_free(data);
00135 }

static void erds_destroy_cb ( void *  data  )  [static]

Definition at line 137 of file func_enum.c.

References erds_destroy().

00138 {
00139    struct enum_result_datastore *erds = data;
00140    erds_destroy(erds);
00141 }

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

Definition at line 51 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(), chan, LOG_WARNING, num, s, and ast_channel::zone.

00053 {
00054    AST_DECLARE_APP_ARGS(args,
00055       AST_APP_ARG(number);
00056       AST_APP_ARG(tech);
00057       AST_APP_ARG(options);
00058       AST_APP_ARG(record);
00059       AST_APP_ARG(zone);
00060    );
00061    int res = 0;
00062    char tech[80];
00063    char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
00064    char *s, *p;
00065    unsigned int record = 1;
00066 
00067    buf[0] = '\0';
00068 
00069    if (ast_strlen_zero(data)) {
00070       ast_log(LOG_WARNING, "%s", synopsis);
00071       return -1;
00072    }
00073 
00074    AST_STANDARD_APP_ARGS(args, data);
00075 
00076    if (args.argc < 1) {
00077       ast_log(LOG_WARNING, "%s", synopsis);
00078       return -1;
00079    }
00080 
00081    if (args.tech && !ast_strlen_zero(args.tech)) {
00082       ast_copy_string(tech,args.tech, sizeof(tech));
00083    } else {
00084       ast_copy_string(tech,"sip",sizeof(tech));
00085    }
00086 
00087    if (!args.zone) {
00088       args.zone = "e164.arpa";
00089    }
00090    if (!args.options) {
00091       args.options = "";
00092    }
00093    if (args.record) {
00094       record = atoi(args.record) ? atoi(args.record) : record;
00095    }
00096 
00097    /* strip any '-' signs from number */
00098    for (s = p = args.number; *s; s++) {
00099       if (*s != '-') {
00100          snprintf(tmp, sizeof(tmp), "%c", *s);
00101          strncat(num, tmp, sizeof(num) - strlen(num) - 1);
00102       }
00103 
00104    }
00105    res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone, args.options, record, NULL);
00106 
00107    p = strchr(dest, ':');
00108    if (p && strcasecmp(tech, "ALL") && !strchr(args.options, 'u')) {
00109       ast_copy_string(buf, p + 1, len);
00110    } else {
00111       ast_copy_string(buf, dest, len);
00112    }
00113    return 0;
00114 }

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

Definition at line 339 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(), chan, LOG_WARNING, and ast_channel::zone.

00341 {
00342    int res;
00343    AST_DECLARE_APP_ARGS(args,
00344       AST_APP_ARG(number);
00345       AST_APP_ARG(zone);
00346    );
00347 
00348    buf[0] = '\0';
00349 
00350    if (ast_strlen_zero(data)) {
00351       ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
00352       return -1;
00353    }
00354 
00355    AST_STANDARD_APP_ARGS(args, data);
00356 
00357    if (args.argc < 1) {
00358       ast_log(LOG_WARNING, "Syntax: TXTCIDNAME(number[,zone-suffix])\n");
00359       return -1;
00360    }
00361 
00362    if (!args.zone) {
00363       args.zone = "e164.arpa";
00364    }
00365 
00366    res = ast_get_txt(chan, args.number, buf, len, args.zone);
00367 
00368    return 0;
00369 }

static int load_module ( void   )  [static]

Definition at line 394 of file func_enum.c.

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

00395 {
00396    int res = 0;
00397 
00398    res |= ast_custom_function_register(&enum_result_function);
00399    res |= ast_custom_function_register(&enum_query_function);
00400    res |= ast_custom_function_register(&enum_function);
00401    res |= ast_custom_function_register(&txtcidname_function);
00402 
00403    return res;
00404 }

static int unload_module ( void   )  [static]

Definition at line 382 of file func_enum.c.

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

00383 {
00384    int res = 0;
00385 
00386    res |= ast_custom_function_unregister(&enum_result_function);
00387    res |= ast_custom_function_unregister(&enum_query_function);
00388    res |= ast_custom_function_unregister(&enum_function);
00389    res |= ast_custom_function_unregister(&txtcidname_function);
00390 
00391    return res;
00392 }


Variable Documentation

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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 406 of file func_enum.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 406 of file func_enum.c.

unsigned int enum_datastore_id

Definition at line 116 of file func_enum.c.

struct ast_custom_function enum_function [static]

Definition at line 321 of file func_enum.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function enum_query_function [static]

Definition at line 296 of file func_enum.c.

Referenced by load_module(), and unload_module().

struct ast_datastore_info enum_result_datastore_info

Initial value:

 {
   .type = "ENUMQUERY",
   .destroy = erds_destroy_cb,
}

Definition at line 143 of file func_enum.c.

Referenced by enum_query_read(), and enum_result_read().

struct ast_custom_function enum_result_function [static]

Definition at line 308 of file func_enum.c.

Referenced by load_module(), and unload_module().

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

Definition at line 49 of file func_enum.c.

struct ast_custom_function txtcidname_function [static]

Definition at line 371 of file func_enum.c.

Referenced by load_module(), and unload_module().


Generated on Fri Jun 19 12:10:37 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7