Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:03 2009

## Asterisk developer's documentation

# app_enumlookup.c File Reference

Enumlookup - lookup entry in ENUM. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <unistd.h>`
`#include <ctype.h>`
`#include "asterisk.h"`
`#include "asterisk/lock.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/options.h"`
`#include "asterisk/config.h"`
`#include "asterisk/module.h"`
`#include "asterisk/enum.h"`
`#include "asterisk/utils.h"`
`#include "asterisk/app.h"`

Include dependency graph for app_enumlookup.c:

Go to the source code of this file.

## Defines

#define | ENUM_CONFIG "enum.conf"
#define | H323DRIVERDEFAULT "H323"

## Functions

char * | description (void)
| Provides a description of the module.
static int | enumlookup_exec (struct ast_channel *chan, void *data)
char * | key ()
| Returns the ASTERISK_GPL_KEY.
static int | load_config (void)
int | load_module (void)
| Initialize the module.
int | reload (void)
| Reload stuff.
int | unload_module (void)
| Cleanup all module structures, sockets, etc.
int | usecount (void)
| Provides a usecount.

## Variables

static char * | app = "EnumLookup"
static char * | descrip
static char | h323driver [80] = ""
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Lookup number in ENUM"
static char * | tdesc = "ENUM Lookup"

## Detailed Description

Enumlookup - lookup entry in ENUM.

Definition in file app_enumlookup.c.

## Define Documentation

#define ENUM_CONFIG "enum.conf"

Definition at line 68 of file app_enumlookup.c.

Referenced by load_config().

#define H323DRIVERDEFAULT "H323"

Definition at line 71 of file app_enumlookup.c.

Referenced by load_config().

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 254 of file app_enumlookup.c.

    00255 {
    00256    return tdesc;
    00257 }

static int enumlookup_exec | ( | struct ast_channel * | chan,
|  | void * | data |
| ) |  |  | `[static]`

Definition at line 78 of file app_enumlookup.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_enum(), ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, dep_warning, ast_channel::exten, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_NOTICE, LOG_WARNING, option_priority_jumping, parse(), pbx_builtin_setvar_helper(), ast_channel::priority, and t.

Referenced by load_module().

    00079 {
    00080    int res=0,priority_jump=0;
    00081    char tech[80];
    00082    char dest[80];
    00083    char tmp[256];
    00084    char *c,*t = NULL;
    00085    static int dep_warning=0;
    00086    struct localuser *u;
    00087    char *parse;
    00088    AST_DECLARE_APP_ARGS(args,
    00089       AST_APP_ARG(d);
    00090       AST_APP_ARG(o);
    00091    );
    00092
    00093    if (ast_strlen_zero(data)) {
    00094       ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
    00095       return -1;
    00096    }
    00097
    00098    if (!dep_warning) {
    00099       ast_log(LOG_WARNING, "The application EnumLookup is deprecated.  Please use the ENUMLOOKUP() function instead.\n");
    00100       dep_warning = 1;
    00101    }
    00102
    00103    LOCAL_USER_ADD(u);
    00104
    00105    parse = ast_strdupa(data);
    00106    if (!parse) {
    00107       ast_log(LOG_ERROR, "Out of memory!\n");
    00108       LOCAL_USER_REMOVE(u);
    00109       return -1;
    00110    }
    00111
    00112    AST_STANDARD_APP_ARGS(args, parse);
    00113
    00114    tech[0] = '\0';
    00115    dest[0] = '\0';
    00116
    00117    if (args.o) {
    00118       if (strchr(args.o, 'j'))
    00119          priority_jump = 1;
    00120    }
    00121
    00122    res = ast_get_enum(chan, args.d, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
    00123
    00124    if (!res) { /* Failed to do a lookup */
    00125       if (priority_jump || option_priority_jumping) {
    00126          /* Look for a "busy" place */
    00127          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
    00128       }
    00129       pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "ERROR");
    00130       LOCAL_USER_REMOVE(u);
    00131       return 0;
    00132    }
    00133    pbx_builtin_setvar_helper(chan, "ENUMSTATUS", tech);
    00134    /* Parse it out */
    00135    if (res > 0) {
    00136       if (!strcasecmp(tech, "SIP")) {
    00137          c = dest;
    00138          if (!strncmp(c, "sip:", 4))
    00139             c += 4;
    00140          snprintf(tmp, sizeof(tmp), "SIP/%s", c);
    00141          pbx_builtin_setvar_helper(chan, "ENUM", tmp);
    00142       } else if (!strcasecmp(tech, "h323")) {
    00143          c = dest;
    00144          if (!strncmp(c, "h323:", 5))
    00145             c += 5;
    00146          snprintf(tmp, sizeof(tmp), "%s/%s", h323driver, c);
    00147 /* do a s!;.*!! on the H323 URI */
    00148          t = strchr(c,';');
    00149                        if (t)
    00150             *t = 0;
    00151          pbx_builtin_setvar_helper(chan, "ENUM", tmp);
    00152       } else if (!strcasecmp(tech, "iax")) {
    00153          c = dest;
    00154          if (!strncmp(c, "iax:", 4))
    00155             c += 4;
    00156          snprintf(tmp, sizeof(tmp), "IAX/%s", c);
    00157          pbx_builtin_setvar_helper(chan, "ENUM", tmp);
    00158       } else if (!strcasecmp(tech, "iax2")) {
    00159          c = dest;
    00160          if (!strncmp(c, "iax2:", 5))
    00161             c += 5;
    00162          snprintf(tmp, sizeof(tmp), "IAX2/%s", c);
    00163          pbx_builtin_setvar_helper(chan, "ENUM", tmp);
    00164       } else if (!strcasecmp(tech, "tel")) {
    00165          c = dest;
    00166          if (!strncmp(c, "tel:", 4))
    00167             c += 4;
    00168
    00169          if (c[0] != '+') {
    00170             ast_log(LOG_NOTICE, "tel: uri must start with a \"+\" (got '%s')\n", c);
    00171             res = 0;
    00172          } else {
    00173 /* now copy over the number, skipping all non-digits and stop at ; or NULL */
    00174                                t = tmp;
    00175             while( *c && (*c != ';') && (t - tmp < (sizeof(tmp) - 1))) {
    00176                if (isdigit(*c))
    00177                   *t++ = *c;
    00178                c++;
    00179             }
    00180             *t = 0;
    00181             pbx_builtin_setvar_helper(chan, "ENUM", tmp);
    00182             ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
    00183             if (priority_jump || option_priority_jumping) {
    00184                if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 51))
    00185                   res = 0;
    00186             }
    00187          }
    00188       } else if (!ast_strlen_zero(tech)) {
    00189          ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
    00190          pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "BADURI");
    00191          res = 0;
    00192       }
    00193    }
    00194
    00195    LOCAL_USER_REMOVE(u);
    00196
    00197    return 0;
    00198 }

char* key | ( | void |  | ) |

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

     char *key(void) {
             return ASTERISK_GPL_KEY;
     }

Returns:
  ASTERISK_GPL_KEY

Definition at line 266 of file app_enumlookup.c.

References ASTERISK_GPL_KEY.

    00267 {
    00268    return ASTERISK_GPL_KEY;
    00269 }

static int load_config | ( | void |  | ) | `[static]`

Definition at line 201 of file app_enumlookup.c.

References ast_config_destroy(), ast_config_load(), ast_log(), ast_variable_retrieve(), cfg, ENUM_CONFIG, H323DRIVERDEFAULT, LOG_NOTICE, and s.

    00202 {
    00203    struct ast_config *cfg;
    00204    char *s;
    00205
    00206    cfg = ast_config_load(ENUM_CONFIG);
    00207    if (cfg) {
    00208       if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) {
    00209          strncpy(h323driver, H323DRIVERDEFAULT, sizeof(h323driver) - 1);
    00210       } else {
    00211          strncpy(h323driver, s, sizeof(h323driver) - 1);
    00212       }
    00213       ast_config_destroy(cfg);
    00214       return 0;
    00215    }
    00216    ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n");
    00217    return 0;
    00218 }

int load_module | ( | void |  | ) |

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
  This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
  int Always 0.

TE STUFF END

Definition at line 234 of file app_enumlookup.c.

References ast_register_application(), enumlookup_exec(), and load_config().

    00235 {
    00236    int res;
    00237
    00238    res = ast_register_application(app, enumlookup_exec, synopsis, descrip);
    00239
    00240    if (!res)
    00241       res = load_config();
    00242
    00243    return res;
    00244 }

int reload | ( | void |  | ) |

Reload stuff.

This function is where any reload routines take place. Re-read config files, change signalling, whatever is appropriate on a reload.

Returns:
  The return value is not used.

Definition at line 247 of file app_enumlookup.c.

References load_config().

    00248 {
    00249    return load_config();
    00250 }

int unload_module | ( | void |  | ) |

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
  Zero on success, or non-zero on error.

Definition at line 222 of file app_enumlookup.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00223 {
    00224    int res;
    00225
    00226    res = ast_unregister_application(app);
    00227
    00228    STANDARD_HANGUP_LOCALUSERS;
    00229
    00230    return res;
    00231 }

int usecount | ( | void |  | ) |

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
  The module's usecount.

Definition at line 259 of file app_enumlookup.c.

References STANDARD_USECOUNT.

    00260 {
    00261    int res;
    00262    STANDARD_USECOUNT(res);
    00263    return res;
    00264 }

## Variable Documentation

char* app = "EnumLookup"`[static]`

Definition at line 51 of file app_enumlookup.c.

char* descrip`[static]`

Definition at line 55 of file app_enumlookup.c.

char h323driver[80] = ""`[static]`

Definition at line 70 of file app_enumlookup.c.

LOCAL_USER_DECL

Definition at line 75 of file app_enumlookup.c.

STANDARD_LOCAL_USER

Definition at line 73 of file app_enumlookup.c.

char* synopsis = "Lookup number in ENUM"`[static]`

Definition at line 53 of file app_enumlookup.c.

char* tdesc = "ENUM Lookup"`[static]`

Definition at line 49 of file app_enumlookup.c.