#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/config.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_variable * | realtime_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_variable * | realtime_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 , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_switch | realtime_switch |
Definition in file pbx_realtime.c.
#define EXT_DATA_SIZE 256 |
Definition at line 54 of file pbx_realtime.c.
#define MODE_CANMATCH 2 |
Definition at line 52 of file pbx_realtime.c.
Referenced by realtime_canmatch(), and realtime_switch_common().
#define MODE_MATCH 0 |
Definition at line 50 of file pbx_realtime.c.
Referenced by realtime_exec(), realtime_exists(), and realtime_switch_common().
#define MODE_MATCHMORE 1 |
Definition at line 51 of file pbx_realtime.c.
Referenced by realtime_matchmore(), and realtime_switch_common().
static void __reg_module | ( | void | ) | [static] |
Definition at line 275 of file pbx_realtime.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 275 of file pbx_realtime.c.
static int load_module | ( | void | ) | [static] |
Definition at line 268 of file pbx_realtime.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_switch(), and realtime_switch.
00269 { 00270 if (ast_register_switch(&realtime_switch)) 00271 return AST_MODULE_LOAD_FAILURE; 00272 return AST_MODULE_LOAD_SUCCESS; 00273 }
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 155 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_CANMATCH, realtime_common(), and var.
00156 { 00157 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH); 00158 if (var) { 00159 ast_variables_destroy(var); 00160 return 1; 00161 } 00162 return 0; 00163 }
static struct ast_variable* realtime_common | ( | const char * | context, | |
const char * | exten, | |||
int | priority, | |||
const char * | data, | |||
int | mode | |||
) | [static] |
Definition at line 123 of file pbx_realtime.c.
References ast_strdupa, buf, realtime_switch_common(), S_OR, table, and var.
Referenced by realtime_canmatch(), realtime_exec(), realtime_exists(), and realtime_matchmore().
00124 { 00125 const char *ctx = NULL; 00126 char *table; 00127 struct ast_variable *var=NULL; 00128 char *buf = ast_strdupa(data); 00129 if (buf) { 00130 char *opts = strchr(buf, '/'); 00131 if (opts) 00132 *opts++ = '\0'; 00133 table = strchr(buf, '@'); 00134 if (table) { 00135 *table++ = '\0'; 00136 ctx = buf; 00137 } 00138 ctx = S_OR(ctx, context); 00139 table = S_OR(table, "extensions"); 00140 var = realtime_switch_common(table, ctx, exten, priority, mode); 00141 } 00142 return var; 00143 }
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 165 of file pbx_realtime.c.
References app, ast_compat_pbx_realtime, ast_strdupa, MODE_MATCH, ast_variable::name, ast_variable::next, realtime_common(), ast_variable::value, and var.
00166 { 00167 int res = -1; 00168 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH); 00169 00170 if (var) { 00171 char *tmp=""; 00172 char *app = NULL; 00173 struct ast_variable *v; 00174 00175 for (v = var; v ; v = v->next) { 00176 if (!strcasecmp(v->name, "app")) 00177 app = ast_strdupa(v->value); 00178 else if (!strcasecmp(v->name, "appdata")) { 00179 if (ast_compat_pbx_realtime) { 00180 char *ptr; 00181 int in = 0; 00182 tmp = alloca(strlen(v->value) * 2 + 1); 00183 for (ptr = tmp; *v->value; v->value++) { 00184 if (*v->value == ',') { 00185 *ptr++ = '\\'; 00186 *ptr++ = ','; 00187 } else if (*v->value == '|' && !in) { 00188 *ptr++ = ','; 00189 } else { 00190 *ptr++ = *v->value; 00191 } 00192 00193 /* Don't escape '|', meaning 'or', inside expressions ($[ ]) */ 00194 if (v->value[0] == '[' && v->value[-1] == '$') { 00195 in++; 00196 } else if (v->value[0] == ']' && in) { 00197 in--; 00198 } 00199 } 00200 *ptr = '\0'; 00201 } else { 00202 tmp = ast_strdupa(v->value); 00203 } 00204 } 00205 } 00206 ast_variables_destroy(var); 00207 if (!ast_strlen_zero(app)) { 00208 struct ast_app *a = pbx_findapp(app); 00209 if (a) { 00210 char appdata[512]; 00211 char tmp1[80]; 00212 char tmp2[80]; 00213 char tmp3[EXT_DATA_SIZE]; 00214 00215 appdata[0] = 0; /* just in case the substitute var func isn't called */ 00216 if(!ast_strlen_zero(tmp)) 00217 pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1); 00218 ast_verb(3, "Executing %s(\"%s\", \"%s\")\n", 00219 term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)), 00220 term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)), 00221 term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3))); 00222 manager_event(EVENT_FLAG_DIALPLAN, "Newexten", 00223 "Channel: %s\r\n" 00224 "Context: %s\r\n" 00225 "Extension: %s\r\n" 00226 "Priority: %d\r\n" 00227 "Application: %s\r\n" 00228 "AppData: %s\r\n" 00229 "Uniqueid: %s\r\n", 00230 chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid); 00231 00232 res = pbx_exec(chan, a, appdata); 00233 } else 00234 ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context); 00235 } else { 00236 ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context); 00237 } 00238 } 00239 return res; 00240 }
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 145 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_MATCH, realtime_common(), and var.
00146 { 00147 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH); 00148 if (var) { 00149 ast_variables_destroy(var); 00150 return 1; 00151 } 00152 return 0; 00153 }
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 242 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_MATCHMORE, realtime_common(), and var.
00243 { 00244 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE); 00245 if (var) { 00246 ast_variables_destroy(var); 00247 return 1; 00248 } 00249 return 0; 00250 }
static struct ast_variable* realtime_switch_common | ( | const char * | table, | |
const char * | context, | |||
const char * | exten, | |||
int | priority, | |||
int | mode | |||
) | [static] |
Definition at line 70 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, SENTINEL, and var.
Referenced by realtime_common().
00071 { 00072 struct ast_variable *var; 00073 struct ast_config *cfg; 00074 char pri[20]; 00075 char *ematch; 00076 char rexten[AST_MAX_EXTENSION + 20]=""; 00077 int match; 00078 snprintf(pri, sizeof(pri), "%d", priority); 00079 switch(mode) { 00080 case MODE_MATCHMORE: 00081 ematch = "exten LIKE"; 00082 snprintf(rexten, sizeof(rexten), "%s_%%", exten); 00083 break; 00084 case MODE_CANMATCH: 00085 ematch = "exten LIKE"; 00086 snprintf(rexten, sizeof(rexten), "%s%%", exten); 00087 break; 00088 case MODE_MATCH: 00089 default: 00090 ematch = "exten"; 00091 ast_copy_string(rexten, exten, sizeof(rexten)); 00092 } 00093 var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL); 00094 if (!var) { 00095 cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL); 00096 if (cfg) { 00097 char *cat = ast_category_browse(cfg, NULL); 00098 00099 while(cat) { 00100 switch(mode) { 00101 case MODE_MATCHMORE: 00102 match = ast_extension_close(cat, exten, 1); 00103 break; 00104 case MODE_CANMATCH: 00105 match = ast_extension_close(cat, exten, 0); 00106 break; 00107 case MODE_MATCH: 00108 default: 00109 match = ast_extension_match(cat, exten); 00110 } 00111 if (match) { 00112 var = ast_category_detach_variables(ast_category_get(cfg, cat)); 00113 break; 00114 } 00115 cat = ast_category_browse(cfg, cat); 00116 } 00117 ast_config_destroy(cfg); 00118 } 00119 } 00120 return var; 00121 }
static int unload_module | ( | void | ) | [static] |
Definition at line 262 of file pbx_realtime.c.
References ast_unregister_switch(), and realtime_switch.
00263 { 00264 ast_unregister_switch(&realtime_switch); 00265 return 0; 00266 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 275 of file pbx_realtime.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 275 of file pbx_realtime.c.
struct ast_switch realtime_switch [static] |