Sat Aug 6 00:40:02 2011

Asterisk developer's documentation


pbx_realtime.c File Reference

Realtime PBX Module. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/frame.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/md5.h"
#include "asterisk/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/utils.h"
#include "asterisk/crypto.h"
#include "asterisk/astdb.h"

Go to the source code of this file.

Defines

#define EXT_DATA_SIZE   256
#define MODE_CANMATCH   2
#define MODE_MATCH   0
#define MODE_MATCHMORE   1

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int realtime_canmatch (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static struct ast_variablerealtime_common (const char *context, const char *exten, int priority, const char *data, int mode)
static int realtime_exec (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int realtime_exists (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int realtime_matchmore (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static struct ast_variablerealtime_switch_common (const char *table, const char *context, const char *exten, int priority, int mode)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Realtime Switch" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_switch realtime_switch


Detailed Description

Realtime PBX Module.

Definition in file pbx_realtime.c.


Define Documentation

#define EXT_DATA_SIZE   256

Definition at line 62 of file pbx_realtime.c.

#define MODE_CANMATCH   2

Definition at line 60 of file pbx_realtime.c.

Referenced by realtime_canmatch(), and realtime_switch_common().

#define MODE_MATCH   0

Definition at line 58 of file pbx_realtime.c.

Referenced by realtime_exec(), realtime_exists(), and realtime_switch_common().

#define MODE_MATCHMORE   1

Definition at line 59 of file pbx_realtime.c.

Referenced by realtime_matchmore(), and realtime_switch_common().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 258 of file pbx_realtime.c.

static void __unreg_module ( void   )  [static]

Definition at line 258 of file pbx_realtime.c.

static int load_module ( void   )  [static]

Definition at line 252 of file pbx_realtime.c.

References ast_register_switch(), and realtime_switch.

00253 {
00254    ast_register_switch(&realtime_switch);
00255    return 0;
00256 }

static int realtime_canmatch ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 164 of file pbx_realtime.c.

References ast_variables_destroy(), MODE_CANMATCH, realtime_common(), and var.

00165 {
00166    struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH);
00167    if (var) {
00168       ast_variables_destroy(var);
00169       return 1;
00170    }
00171    return 0;
00172 }

static struct ast_variable* realtime_common ( const char *  context,
const char *  exten,
int  priority,
const char *  data,
int  mode 
) [static]

Definition at line 132 of file pbx_realtime.c.

References ast_strdupa, realtime_switch_common(), S_OR, table, and var.

Referenced by realtime_canmatch(), realtime_exec(), realtime_exists(), and realtime_matchmore().

00133 {
00134    const char *ctx = NULL;
00135    char *table;
00136    struct ast_variable *var=NULL;
00137    char *buf = ast_strdupa(data);
00138    if (buf) {
00139       char *opts = strchr(buf, '/');
00140       if (opts)
00141          *opts++ = '\0';
00142       table = strchr(buf, '@');
00143       if (table) {
00144          *table++ = '\0';
00145          ctx = buf;
00146       }
00147       ctx = S_OR(ctx, context);
00148       table = S_OR(table, "extensions");
00149       var = realtime_switch_common(table, ctx, exten, priority, mode);
00150    }
00151    return var;
00152 }

static int realtime_exec ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 174 of file pbx_realtime.c.

References app, ast_log(), ast_strdupa, ast_strlen_zero(), ast_variables_destroy(), ast_verbose(), COLOR_BRCYAN, COLOR_BRMAGENTA, EVENT_FLAG_CALL, EXT_DATA_SIZE, LOG_NOTICE, LOG_WARNING, manager_event(), MODE_MATCH, ast_variable::name, ast_variable::next, option_verbose, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), realtime_common(), S_OR, term_color(), ast_variable::value, var, and VERBOSE_PREFIX_3.

00175 {
00176    int res = -1;
00177    struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
00178 
00179    if (var) {
00180       char *tmp="";
00181       char *app = NULL;
00182       struct ast_variable *v;
00183 
00184       for (v = var; v ; v = v->next) {
00185          if (!strcasecmp(v->name, "app"))
00186             app = ast_strdupa(v->value);
00187          else if (!strcasecmp(v->name, "appdata"))
00188             tmp = ast_strdupa(v->value);
00189       }
00190       ast_variables_destroy(var);
00191       if (!ast_strlen_zero(app)) {
00192          struct ast_app *a = pbx_findapp(app);
00193          if (a) {
00194             char appdata[512]="";
00195             char tmp1[80];
00196             char tmp2[80];
00197             char tmp3[EXT_DATA_SIZE];
00198 
00199             if(!ast_strlen_zero(tmp))
00200                pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1);
00201             if (option_verbose > 2)
00202                ast_verbose( VERBOSE_PREFIX_3 "Executing %s(\"%s\", \"%s\")\n",
00203                    term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
00204                    term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
00205                    term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
00206             manager_event(EVENT_FLAG_CALL, "Newexten",
00207                        "Channel: %s\r\n"
00208                        "Context: %s\r\n"
00209                        "Extension: %s\r\n"
00210                        "Priority: %d\r\n"
00211                        "Application: %s\r\n"
00212                        "AppData: %s\r\n"
00213                        "Uniqueid: %s\r\n",
00214                        chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid);
00215             
00216             res = pbx_exec(chan, a, appdata);
00217          } else
00218             ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
00219       } else {
00220          ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context);
00221       }
00222    }
00223    return res;
00224 }

static int realtime_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 154 of file pbx_realtime.c.

References ast_variables_destroy(), MODE_MATCH, realtime_common(), and var.

00155 {
00156    struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
00157    if (var) {
00158       ast_variables_destroy(var);
00159       return 1;
00160    }
00161    return 0;
00162 }

static int realtime_matchmore ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
) [static]

Definition at line 226 of file pbx_realtime.c.

References ast_variables_destroy(), MODE_MATCHMORE, realtime_common(), and var.

00227 {
00228    struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE);
00229    if (var) {
00230       ast_variables_destroy(var);
00231       return 1;
00232    }
00233    return 0;
00234 }

static struct ast_variable* realtime_switch_common ( const char *  table,
const char *  context,
const char *  exten,
int  priority,
int  mode 
) [static]

Definition at line 79 of file pbx_realtime.c.

References ast_category_browse(), ast_category_detach_variables(), ast_category_get(), ast_config_destroy(), ast_copy_string(), ast_extension_close(), ast_extension_match(), ast_load_realtime(), ast_load_realtime_multientry(), AST_MAX_EXTENSION, match(), MODE_CANMATCH, MODE_MATCH, MODE_MATCHMORE, and var.

Referenced by realtime_common().

00080 {
00081    struct ast_variable *var;
00082    struct ast_config *cfg;
00083    char pri[20];
00084    char *ematch;
00085    char rexten[AST_MAX_EXTENSION + 20]="";
00086    int match;
00087    snprintf(pri, sizeof(pri), "%d", priority);
00088    switch(mode) {
00089    case MODE_MATCHMORE:
00090       ematch = "exten LIKE";
00091       snprintf(rexten, sizeof(rexten), "%s_%%", exten);
00092       break;
00093    case MODE_CANMATCH:
00094       ematch = "exten LIKE";
00095       snprintf(rexten, sizeof(rexten), "%s%%", exten);
00096       break;
00097    case MODE_MATCH:
00098    default:
00099       ematch = "exten";
00100       ast_copy_string(rexten, exten, sizeof(rexten));
00101    }
00102    var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, NULL);
00103    if (!var) {
00104       cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, NULL); 
00105       if (cfg) {
00106          char *cat = ast_category_browse(cfg, NULL);
00107 
00108          while(cat) {
00109             switch(mode) {
00110             case MODE_MATCHMORE:
00111                match = ast_extension_close(cat, exten, 1);
00112                break;
00113             case MODE_CANMATCH:
00114                match = ast_extension_close(cat, exten, 0);
00115                break;
00116             case MODE_MATCH:
00117             default:
00118                match = ast_extension_match(cat, exten);
00119             }
00120             if (match) {
00121                var = ast_category_detach_variables(ast_category_get(cfg, cat));
00122                break;
00123             }
00124             cat = ast_category_browse(cfg, cat);
00125          }
00126          ast_config_destroy(cfg);
00127       }
00128    }
00129    return var;
00130 }

static int unload_module ( void   )  [static]

Definition at line 246 of file pbx_realtime.c.

References ast_unregister_switch(), and realtime_switch.

00247 {
00248    ast_unregister_switch(&realtime_switch);
00249    return 0;
00250 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Realtime Switch" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 258 of file pbx_realtime.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 258 of file pbx_realtime.c.

struct ast_switch realtime_switch [static]

Definition at line 236 of file pbx_realtime.c.

Referenced by load_module(), and unload_module().


Generated on Sat Aug 6 00:40:02 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7