Wed Jan 8 2020 09:50:17

Asterisk developer's documentation


pbx_realtime.c File Reference

Realtime PBX Module. More...

#include "asterisk.h"
#include <signal.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/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/utils.h"
#include "asterisk/astdb.h"
#include "asterisk/app.h"
#include "asterisk/astobj2.h"

Go to the source code of this file.

Data Structures

struct  cache_entry
 

Macros

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

Enumerations

enum  option_flags {
  OPTION_A = (1 << 0), OPTION_B = (1 << 1), OPTION_C = (1 << 2), OPTION_WAIT = (1 << 0),
  OPTION_PATTERNS_DISABLED = (1 << 0)
}
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int cache_cmp (void *obj, void *arg, int flags)
 
static int cache_hash (const void *obj, const int flags)
 
static void * cleanup (void *unused)
 
static struct ast_variabledup_vars (struct ast_variable *v)
 
static void free_entry (void *obj)
 
static int load_module (void)
 
static int purge_old_fn (void *obj, void *arg, int flags)
 
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, struct ast_flags flags)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static struct ast_module_infoast_module_info = &__mod_info
 
struct ao2_containercache
 
pthread_t cleanup_thread = 0
 
static struct ast_switch realtime_switch
 
static struct ast_app_option switch_opts [128] = { [ 'p' ] = { .flag = OPTION_PATTERNS_DISABLED }, }
 

Detailed Description

Realtime PBX Module.

Definition in file pbx_realtime.c.

Macro Definition Documentation

#define EXT_DATA_SIZE   256

Definition at line 60 of file pbx_realtime.c.

Referenced by realtime_exec().

#define MODE_CANMATCH   2

Definition at line 58 of file pbx_realtime.c.

Referenced by realtime_canmatch(), and realtime_switch_common().

#define MODE_MATCH   0
#define MODE_MATCHMORE   1

Definition at line 57 of file pbx_realtime.c.

Referenced by realtime_matchmore(), and realtime_switch_common().

Enumeration Type Documentation

Enumerator
OPTION_A 
OPTION_B 
OPTION_C 
OPTION_WAIT 
OPTION_PATTERNS_DISABLED 

Definition at line 62 of file pbx_realtime.c.

62  {
63  OPTION_PATTERNS_DISABLED = (1 << 0),
64 };

Function Documentation

static void __reg_module ( void  )
static

Definition at line 423 of file pbx_realtime.c.

static void __unreg_module ( void  )
static

Definition at line 423 of file pbx_realtime.c.

static int cache_cmp ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 87 of file pbx_realtime.c.

References CMP_MATCH, cache_entry::context, cache_entry::exten, f, and cache_entry::priority.

Referenced by load_module().

88 {
89  struct cache_entry *e = obj, *f = arg;
90  return e->priority != f->priority ? 0 :
91  strcmp(e->exten, f->exten) ? 0 :
92  strcmp(e->context, f->context) ? 0 :
93  CMP_MATCH;
94 }
int priority
Definition: pbx_realtime.c:73
Definition: pbx_realtime.c:70
char exten[2]
Definition: pbx_realtime.c:75
static struct ast_format f[]
Definition: format_g726.c:181
char * context
Definition: pbx_realtime.c:74
static int cache_hash ( const void *  obj,
const int  flags 
)
static

Definition at line 81 of file pbx_realtime.c.

References ast_str_case_hash(), cache_entry::exten, and cache_entry::priority.

Referenced by load_module().

82 {
83  const struct cache_entry *e = obj;
84  return ast_str_case_hash(e->exten) + e->priority;
85 }
int priority
Definition: pbx_realtime.c:73
Definition: pbx_realtime.c:70
char exten[2]
Definition: pbx_realtime.c:75
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:989
static void* cleanup ( void *  unused)
static

Definition at line 125 of file pbx_realtime.c.

References ao2_callback, ao2_container_count(), ast_tvnow(), OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, and purge_old_fn().

Referenced by _sip_tcp_helper_thread(), ast_rtp_dtmf_end_with_duration(), ast_sockaddr_resolve(), build_user(), handle_uri(), load_module(), and realtime_peer().

126 {
127  struct timespec forever = { 999999999, 0 }, one_second = { 1, 0 };
128  struct timeval now;
129 
130  for (;;) {
131  pthread_testcancel();
132  if (ao2_container_count(cache) == 0) {
133  nanosleep(&forever, NULL);
134  }
135  pthread_testcancel();
136  now = ast_tvnow();
138  pthread_testcancel();
139  nanosleep(&one_second, NULL);
140  }
141 
142  return NULL;
143 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
static int purge_old_fn(void *obj, void *arg, int flags)
Definition: pbx_realtime.c:118
struct ao2_container * cache
Definition: pbx_realtime.c:78
static struct ast_variable* dup_vars ( struct ast_variable v)
static

Definition at line 96 of file pbx_realtime.c.

References ast_variable_new(), ast_variables_destroy(), ast_variable::file, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by realtime_common().

97 {
98  struct ast_variable *new, *list = NULL;
99  for (; v; v = v->next) {
100  if (!(new = ast_variable_new(v->name, v->value, v->file))) {
101  ast_variables_destroy(list);
102  return NULL;
103  }
104  /* Reversed list in cache, but when we duplicate out of the cache,
105  * it's back to correct order. */
106  new->next = list;
107  list = new;
108  }
109  return list;
110 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
const char * file
Definition: config.h:85
struct ast_variable * next
Definition: config.h:82
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
static void free_entry ( void *  obj)
static

Definition at line 112 of file pbx_realtime.c.

References ast_variables_destroy(), and cache_entry::var.

Referenced by realtime_common().

113 {
114  struct cache_entry *e = obj;
116 }
Definition: pbx_realtime.c:70
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
struct ast_variable * var
Definition: pbx_realtime.c:72
static int load_module ( void  )
static

Definition at line 408 of file pbx_realtime.c.

References ao2_container_alloc, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_pthread_create, ast_register_switch(), cache_cmp(), cache_hash(), and cleanup().

409 {
410  if (!(cache = ao2_container_alloc(573, cache_hash, cache_cmp))) {
412  }
413 
414  if (ast_pthread_create(&cleanup_thread, NULL, cleanup, NULL)) {
416  }
417 
421 }
static int cache_cmp(void *obj, void *arg, int flags)
Definition: pbx_realtime.c:87
static int cache_hash(const void *obj, const int flags)
Definition: pbx_realtime.c:81
pthread_t cleanup_thread
Definition: pbx_realtime.c:79
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:418
int ast_register_switch(struct ast_switch *sw)
Register an alternative dialplan switch.
Definition: pbx.c:6439
static void * cleanup(void *unused)
Definition: pbx_realtime.c:125
struct ao2_container * cache
Definition: pbx_realtime.c:78
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
static struct ast_switch realtime_switch
Definition: pbx_realtime.c:387
static int purge_old_fn ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 118 of file pbx_realtime.c.

References ast_tvdiff_ms(), CMP_MATCH, and cache_entry::when.

Referenced by cleanup().

119 {
120  struct cache_entry *e = obj;
121  struct timeval *now = arg;
122  return ast_tvdiff_ms(*now, e->when) >= 1000 ? CMP_MATCH : 0;
123 }
struct timeval when
Definition: pbx_realtime.c:71
Definition: pbx_realtime.c:70
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
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 289 of file pbx_realtime.c.

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

290 {
291  struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH);
292  if (var) {
294  return 1;
295  }
296  return 0;
297 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
#define MODE_CANMATCH
Definition: pbx_realtime.c:58
static struct ast_variable * realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
Definition: pbx_realtime.c:219
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static struct ast_variable* realtime_common ( const char *  context,
const char *  exten,
int  priority,
const char *  data,
int  mode 
)
static

Definition at line 219 of file pbx_realtime.c.

References ao2_alloc, ao2_find, ao2_link, ao2_ref, ast_app_parse_options(), ast_copy_string(), AST_MAX_EXTENSION, ast_strdupa, ast_strlen_zero(), ast_tvnow(), ast_variables_destroy(), cache_entry::context, dup_vars(), cache_entry::exten, free_entry(), MODE_MATCH, OBJ_POINTER, cache_entry::priority, realtime_switch_common(), S_OR, switch_opts, table, cache_entry::var, var, and cache_entry::when.

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

220 {
221  const char *ctx = NULL;
222  char *table;
223  struct ast_variable *var=NULL;
224  struct ast_flags flags = { 0, };
225  struct cache_entry *ce;
226  struct {
227  struct cache_entry ce;
228  char exten[AST_MAX_EXTENSION];
229  } cache_search = { { .priority = priority, .context = (char *) context }, };
230  char *buf = ast_strdupa(data);
231  /* "Realtime" prefix is stripped off in the parent engine. The
232  * remaining string is: [[context@]table][/opts] */
233  char *opts = strchr(buf, '/');
234  if (opts)
235  *opts++ = '\0';
236  table = strchr(buf, '@');
237  if (table) {
238  *table++ = '\0';
239  ctx = buf;
240  }
241  ctx = S_OR(ctx, context);
242  table = S_OR(table, "extensions");
243  if (!ast_strlen_zero(opts)) {
244  ast_app_parse_options(switch_opts, &flags, NULL, opts);
245  }
246  ast_copy_string(cache_search.exten, exten, sizeof(cache_search.exten));
247  if (mode == MODE_MATCH && (ce = ao2_find(cache, &cache_search, OBJ_POINTER))) {
248  var = dup_vars(ce->var);
249  ao2_ref(ce, -1);
250  } else {
251  var = realtime_switch_common(table, ctx, exten, priority, mode, flags);
252  do {
253  struct ast_variable *new;
254  /* Only cache matches */
255  if (mode != MODE_MATCH) {
256  break;
257  }
258  if (!(new = dup_vars(var))) {
259  break;
260  }
261  if (!(ce = ao2_alloc(sizeof(*ce) + strlen(exten) + strlen(context), free_entry))) {
263  break;
264  }
265  ce->context = ce->exten + strlen(exten) + 1;
266  strcpy(ce->exten, exten); /* SAFE */
267  strcpy(ce->context, context); /* SAFE */
268  ce->priority = priority;
269  ce->var = new;
270  ce->when = ast_tvnow();
271  ao2_link(cache, ce);
272  pthread_kill(cleanup_thread, SIGURG);
273  ao2_ref(ce, -1);
274  } while (0);
275  }
276  return var;
277 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
int priority
Definition: pbx_realtime.c:73
struct timeval when
Definition: pbx_realtime.c:71
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
unsigned int flags
Definition: utils.h:201
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
static struct ast_variable * dup_vars(struct ast_variable *v)
Definition: pbx_realtime.c:96
static struct ast_variable * realtime_switch_common(const char *table, const char *context, const char *exten, int priority, int mode, struct ast_flags flags)
Definition: pbx_realtime.c:160
Definition: pbx_realtime.c:70
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
pthread_t cleanup_thread
Definition: pbx_realtime.c:79
static char * table
Definition: cdr_odbc.c:50
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_MAX_EXTENSION
Definition: channel.h:135
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static struct ast_app_option switch_opts[128]
Definition: pbx_realtime.c:68
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
char exten[2]
Definition: pbx_realtime.c:75
struct ast_variable * var
Definition: pbx_realtime.c:72
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
#define MODE_MATCH
Definition: pbx_realtime.c:56
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
static void free_entry(void *obj)
Definition: pbx_realtime.c:112
Structure used to handle boolean flags.
Definition: utils.h:200
struct ao2_container * cache
Definition: pbx_realtime.c:78
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
char * context
Definition: pbx_realtime.c:74
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 299 of file pbx_realtime.c.

References app, ast_alloca, ast_compat_pbx_realtime, ast_log(), ast_strdupa, 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_variable::name, ast_channel::name, ast_variable::next, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), ast_channel::priority, realtime_common(), S_OR, term_color(), ast_channel::uniqueid, and ast_variable::value.

300 {
301  int res = -1;
302  struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
303 
304  if (var) {
305  char *tmp="";
306  char *app = NULL;
307  struct ast_variable *v;
308 
309  for (v = var; v ; v = v->next) {
310  if (!strcasecmp(v->name, "app"))
311  app = ast_strdupa(v->value);
312  else if (!strcasecmp(v->name, "appdata")) {
314  char *ptr;
315  int in = 0;
316  tmp = ast_alloca(strlen(v->value) * 2 + 1);
317  for (ptr = tmp; *v->value; v->value++) {
318  if (*v->value == ',') {
319  *ptr++ = '\\';
320  *ptr++ = ',';
321  } else if (*v->value == '|' && !in) {
322  *ptr++ = ',';
323  } else {
324  *ptr++ = *v->value;
325  }
326 
327  /* Don't escape '|', meaning 'or', inside expressions ($[ ]) */
328  if (v->value[0] == '[' && v->value[-1] == '$') {
329  in++;
330  } else if (v->value[0] == ']' && in) {
331  in--;
332  }
333  }
334  *ptr = '\0';
335  } else {
336  tmp = ast_strdupa(v->value);
337  }
338  }
339  }
341  if (!ast_strlen_zero(app)) {
342  struct ast_app *a = pbx_findapp(app);
343  if (a) {
344  char appdata[512];
345  char tmp1[80];
346  char tmp2[80];
347  char tmp3[EXT_DATA_SIZE];
348 
349  appdata[0] = 0; /* just in case the substitute var func isn't called */
350  if(!ast_strlen_zero(tmp))
351  pbx_substitute_variables_helper(chan, tmp, appdata, sizeof(appdata) - 1);
352  ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
353  chan->exten, chan->context, chan->priority,
354  term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
355  term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
356  term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
358  "Channel: %s\r\n"
359  "Context: %s\r\n"
360  "Extension: %s\r\n"
361  "Priority: %d\r\n"
362  "Application: %s\r\n"
363  "AppData: %s\r\n"
364  "Uniqueid: %s\r\n",
365  chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid);
366 
367  res = pbx_exec(chan, a, appdata);
368  } else
369  ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
370  } else {
371  ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context);
372  }
373  }
374  return res;
375 }
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: pbx.c:4676
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: pbx.c:1537
int priority
Definition: channel.h:841
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx.c:1497
const ast_string_field uniqueid
Definition: channel.h:787
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
#define EVENT_FLAG_DIALPLAN
Definition: manager.h:82
#define ast_verb(level,...)
Definition: logger.h:243
#define COLOR_BRCYAN
Definition: term.h:60
const char * value
Definition: config.h:79
static const char app[]
Definition: app_adsiprog.c:49
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_compat_pbx_realtime
Definition: options.h:142
const char * name
Definition: config.h:77
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Definition: term.c:184
#define COLOR_BRMAGENTA
Definition: term.h:58
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct ast_variable * realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
Definition: pbx_realtime.c:219
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define MODE_MATCH
Definition: pbx_realtime.c:56
#define EXT_DATA_SIZE
Definition: pbx_realtime.c:60
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
ast_app: A registered application
Definition: pbx.c:971
struct ast_variable * next
Definition: config.h:82
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
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 279 of file pbx_realtime.c.

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

280 {
281  struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
282  if (var) {
284  return 1;
285  }
286  return 0;
287 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
static struct ast_variable * realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
Definition: pbx_realtime.c:219
#define MODE_MATCH
Definition: pbx_realtime.c:56
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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 377 of file pbx_realtime.c.

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

378 {
379  struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE);
380  if (var) {
382  return 1;
383  }
384  return 0;
385 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
static struct ast_variable * realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
Definition: pbx_realtime.c:219
#define MODE_MATCHMORE
Definition: pbx_realtime.c:57
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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

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

161 {
162  struct ast_variable *var;
163  struct ast_config *cfg;
164  char pri[20];
165  char *ematch;
166  char rexten[AST_MAX_EXTENSION + 20]="";
167  int match;
168  /* Optimization: since we don't support hints in realtime, it's silly to
169  * query for a hint here, since we won't actually do anything with it.
170  * This just wastes CPU time and resources. */
171  if (priority < 0) {
172  return NULL;
173  }
174  snprintf(pri, sizeof(pri), "%d", priority);
175  switch(mode) {
176  case MODE_MATCHMORE:
177  ematch = "exten LIKE";
178  snprintf(rexten, sizeof(rexten), "%s_%%", exten);
179  break;
180  case MODE_CANMATCH:
181  ematch = "exten LIKE";
182  snprintf(rexten, sizeof(rexten), "%s%%", exten);
183  break;
184  case MODE_MATCH:
185  default:
186  ematch = "exten";
187  ast_copy_string(rexten, exten, sizeof(rexten));
188  }
189  var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL);
190  if (!var && !ast_test_flag(&flags, OPTION_PATTERNS_DISABLED)) {
191  cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL);
192  if (cfg) {
193  char *cat = ast_category_browse(cfg, NULL);
194 
195  while(cat) {
196  switch(mode) {
197  case MODE_MATCHMORE:
198  match = ast_extension_close(cat, exten, 1);
199  break;
200  case MODE_CANMATCH:
201  match = ast_extension_close(cat, exten, 0);
202  break;
203  case MODE_MATCH:
204  default:
205  match = ast_extension_match(cat, exten);
206  }
207  if (match) {
209  break;
210  }
211  cat = ast_category_browse(cfg, cat);
212  }
213  ast_config_destroy(cfg);
214  }
215  }
216  return var;
217 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
struct ast_variable * ast_category_detach_variables(struct ast_category *cat)
Definition: config.c:856
#define ast_test_flag(p, flag)
Definition: utils.h:63
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
struct ast_variable * ast_load_realtime(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
Definition: config.c:2548
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static char * table
Definition: cdr_odbc.c:50
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Retrieve a category if it exists.
Definition: config.c:709
#define SENTINEL
Definition: compiler.h:75
#define MODE_CANMATCH
Definition: pbx_realtime.c:58
#define AST_MAX_EXTENSION
Definition: channel.h:135
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
#define MODE_MATCH
Definition: pbx_realtime.c:56
int ast_extension_close(const char *pattern, const char *data, int needmore)
Definition: pbx.c:2948
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
#define MODE_MATCHMORE
Definition: pbx_realtime.c:57
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
struct ast_config * ast_load_realtime_multientry(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
Definition: config.c:2650
static int unload_module ( void  )
static

Definition at line 397 of file pbx_realtime.c.

References ao2_ref, and ast_unregister_switch().

398 {
400  pthread_cancel(cleanup_thread);
401  pthread_kill(cleanup_thread, SIGURG);
402  pthread_join(cleanup_thread, NULL);
403  /* Destroy all remaining entries */
404  ao2_ref(cache, -1);
405  return 0;
406 }
void ast_unregister_switch(struct ast_switch *sw)
Unregister an alternative switch.
Definition: pbx.c:6457
pthread_t cleanup_thread
Definition: pbx_realtime.c:79
#define ao2_ref(o, delta)
Definition: astobj2.h:472
struct ao2_container * cache
Definition: pbx_realtime.c:78
static struct ast_switch realtime_switch
Definition: pbx_realtime.c:387

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 423 of file pbx_realtime.c.

Definition at line 423 of file pbx_realtime.c.

struct ao2_container* cache

Definition at line 78 of file pbx_realtime.c.

pthread_t cleanup_thread = 0

Definition at line 79 of file pbx_realtime.c.

struct ast_switch realtime_switch
static

Definition at line 387 of file pbx_realtime.c.

struct ast_app_option switch_opts[128] = { [ 'p' ] = { .flag = OPTION_PATTERNS_DISABLED }, }
static

Definition at line 68 of file pbx_realtime.c.

Referenced by realtime_common().