Realtime PBX Module. More...
#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"#include "asterisk/app.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 |
Enumerations | |
| enum | { OPTION_PATTERNS_DISABLED = (1 << 0) } |
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, struct ast_flags flags) |
| 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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| enum { ... } | option_flags |
| static struct ast_switch | realtime_switch |
| static struct ast_app_option | switch_opts [128] = { [ 'p' ] = { .flag = OPTION_PATTERNS_DISABLED },} |
Realtime PBX Module.
Definition in file pbx_realtime.c.
| #define EXT_DATA_SIZE 256 |
Definition at line 55 of file pbx_realtime.c.
| #define MODE_CANMATCH 2 |
Definition at line 53 of file pbx_realtime.c.
Referenced by realtime_canmatch(), and realtime_switch_common().
| #define MODE_MATCH 0 |
Definition at line 51 of file pbx_realtime.c.
Referenced by realtime_exec(), realtime_exists(), and realtime_switch_common().
| #define MODE_MATCHMORE 1 |
Definition at line 52 of file pbx_realtime.c.
Referenced by realtime_matchmore(), and realtime_switch_common().
| anonymous enum |
Definition at line 57 of file pbx_realtime.c.
00057 { 00058 OPTION_PATTERNS_DISABLED = (1 << 0), 00059 } option_flags;
| static void __reg_module | ( | void | ) | [static] |
Definition at line 296 of file pbx_realtime.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 296 of file pbx_realtime.c.
| static int load_module | ( | void | ) | [static] |
Definition at line 289 of file pbx_realtime.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, and ast_register_switch().
00290 { 00291 if (ast_register_switch(&realtime_switch)) 00292 return AST_MODULE_LOAD_FAILURE; 00293 return AST_MODULE_LOAD_SUCCESS; 00294 }
| 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 176 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_CANMATCH, realtime_common(), and var.
00177 { 00178 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH); 00179 if (var) { 00180 ast_variables_destroy(var); 00181 return 1; 00182 } 00183 return 0; 00184 }
| static struct ast_variable* realtime_common | ( | const char * | context, | |
| const char * | exten, | |||
| int | priority, | |||
| const char * | data, | |||
| int | mode | |||
| ) | [static, read] |
Definition at line 138 of file pbx_realtime.c.
References ast_app_parse_options(), ast_strlen_zero(), buf, realtime_switch_common(), S_OR, switch_opts, table, and var.
Referenced by realtime_canmatch(), realtime_exec(), realtime_exists(), and realtime_matchmore().
00139 { 00140 const char *ctx = NULL; 00141 char *table; 00142 struct ast_variable *var=NULL; 00143 struct ast_flags flags = { 0, }; 00144 char *buf = ast_strdupa(data); 00145 if (buf) { 00146 /* "Realtime" prefix is stripped off in the parent engine. The 00147 * remaining string is: [[context@]table][/opts] */ 00148 char *opts = strchr(buf, '/'); 00149 if (opts) 00150 *opts++ = '\0'; 00151 table = strchr(buf, '@'); 00152 if (table) { 00153 *table++ = '\0'; 00154 ctx = buf; 00155 } 00156 ctx = S_OR(ctx, context); 00157 table = S_OR(table, "extensions"); 00158 if (!ast_strlen_zero(opts)) { 00159 ast_app_parse_options(switch_opts, &flags, NULL, opts); 00160 } 00161 var = realtime_switch_common(table, ctx, exten, priority, mode, flags); 00162 } 00163 return var; 00164 }
| 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 186 of file pbx_realtime.c.
References app, ast_compat_pbx_realtime, ast_log(), ast_strlen_zero(), ast_variables_destroy(), ast_verb, COLOR_BRCYAN, COLOR_BRMAGENTA, ast_channel::context, EVENT_FLAG_DIALPLAN, EXT_DATA_SIZE, ast_channel::exten, LOG_NOTICE, LOG_WARNING, manager_event, MODE_MATCH, ast_channel::name, ast_variable::name, ast_variable::next, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), ast_channel::priority, realtime_common(), S_OR, term_color(), ast_channel::uniqueid, ast_variable::value, and var.
00187 { 00188 int res = -1; 00189 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH); 00190 00191 if (var) { 00192 char *tmp=""; 00193 char *app = NULL; 00194 struct ast_variable *v; 00195 00196 for (v = var; v ; v = v->next) { 00197 if (!strcasecmp(v->name, "app")) 00198 app = ast_strdupa(v->value); 00199 else if (!strcasecmp(v->name, "appdata")) { 00200 if (ast_compat_pbx_realtime) { 00201 char *ptr; 00202 int in = 0; 00203 tmp = alloca(strlen(v->value) * 2 + 1); 00204 for (ptr = tmp; *v->value; v->value++) { 00205 if (*v->value == ',') { 00206 *ptr++ = '\\'; 00207 *ptr++ = ','; 00208 } else if (*v->value == '|' && !in) { 00209 *ptr++ = ','; 00210 } else { 00211 *ptr++ = *v->value; 00212 } 00213 00214 /* Don't escape '|', meaning 'or', inside expressions ($[ ]) */ 00215 if (v->value[0] == '[' && v->value[-1] == '$') { 00216 in++; 00217 } else if (v->value[0] == ']' && in) { 00218 in--; 00219 } 00220 } 00221 *ptr = '\0'; 00222 } else { 00223 tmp = ast_strdupa(v->value); 00224 } 00225 } 00226 } 00227 ast_variables_destroy(var); 00228 if (!ast_strlen_zero(app)) { 00229 struct ast_app *a = pbx_findapp(app); 00230 if (a) { 00231 char appdata[512]; 00232 char tmp1[80]; 00233 char tmp2[80]; 00234 char tmp3[EXT_DATA_SIZE]; 00235 00236 appdata[0] = 0; /* just in case the substitute var func isn't called */ 00237 if(!ast_strlen_zero(tmp)) 00238 pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1); 00239 ast_verb(3, "Executing %s(\"%s\", \"%s\")\n", 00240 term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)), 00241 term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)), 00242 term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3))); 00243 manager_event(EVENT_FLAG_DIALPLAN, "Newexten", 00244 "Channel: %s\r\n" 00245 "Context: %s\r\n" 00246 "Extension: %s\r\n" 00247 "Priority: %d\r\n" 00248 "Application: %s\r\n" 00249 "AppData: %s\r\n" 00250 "Uniqueid: %s\r\n", 00251 chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid); 00252 00253 res = pbx_exec(chan, a, appdata); 00254 } else 00255 ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context); 00256 } else { 00257 ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context); 00258 } 00259 } 00260 return res; 00261 }
| 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 166 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_MATCH, realtime_common(), and var.
00167 { 00168 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH); 00169 if (var) { 00170 ast_variables_destroy(var); 00171 return 1; 00172 } 00173 return 0; 00174 }
| 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 263 of file pbx_realtime.c.
References ast_variables_destroy(), MODE_MATCHMORE, realtime_common(), and var.
00264 { 00265 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE); 00266 if (var) { 00267 ast_variables_destroy(var); 00268 return 1; 00269 } 00270 return 0; 00271 }
| static struct ast_variable* realtime_switch_common | ( | const char * | table, | |
| const char * | context, | |||
| const char * | exten, | |||
| int | priority, | |||
| int | mode, | |||
| struct ast_flags | flags | |||
| ) | [static, read] |
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, ast_test_flag, match(), MODE_CANMATCH, MODE_MATCH, MODE_MATCHMORE, OPTION_PATTERNS_DISABLED, SENTINEL, 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 /* Optimization: since we don't support hints in realtime, it's silly to 00088 * query for a hint here, since we won't actually do anything with it. 00089 * This just wastes CPU time and resources. */ 00090 if (priority < 0) { 00091 return NULL; 00092 } 00093 snprintf(pri, sizeof(pri), "%d", priority); 00094 switch(mode) { 00095 case MODE_MATCHMORE: 00096 ematch = "exten LIKE"; 00097 snprintf(rexten, sizeof(rexten), "%s_%%", exten); 00098 break; 00099 case MODE_CANMATCH: 00100 ematch = "exten LIKE"; 00101 snprintf(rexten, sizeof(rexten), "%s%%", exten); 00102 break; 00103 case MODE_MATCH: 00104 default: 00105 ematch = "exten"; 00106 ast_copy_string(rexten, exten, sizeof(rexten)); 00107 } 00108 var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL); 00109 if (!var && !ast_test_flag(&flags, OPTION_PATTERNS_DISABLED)) { 00110 cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL); 00111 if (cfg) { 00112 char *cat = ast_category_browse(cfg, NULL); 00113 00114 while(cat) { 00115 switch(mode) { 00116 case MODE_MATCHMORE: 00117 match = ast_extension_close(cat, exten, 1); 00118 break; 00119 case MODE_CANMATCH: 00120 match = ast_extension_close(cat, exten, 0); 00121 break; 00122 case MODE_MATCH: 00123 default: 00124 match = ast_extension_match(cat, exten); 00125 } 00126 if (match) { 00127 var = ast_category_detach_variables(ast_category_get(cfg, cat)); 00128 break; 00129 } 00130 cat = ast_category_browse(cfg, cat); 00131 } 00132 ast_config_destroy(cfg); 00133 } 00134 } 00135 return var; 00136 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 283 of file pbx_realtime.c.
References ast_unregister_switch().
00284 { 00285 ast_unregister_switch(&realtime_switch); 00286 return 0; 00287 }
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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 296 of file pbx_realtime.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 296 of file pbx_realtime.c.
| enum { ... } option_flags |
struct ast_switch realtime_switch [static] |
Definition at line 273 of file pbx_realtime.c.
struct ast_app_option switch_opts[128] = { [ 'p' ] = { .flag = OPTION_PATTERNS_DISABLED },} [static] |
Definition at line 63 of file pbx_realtime.c.
Referenced by realtime_common().
1.6.2