Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Enumerations | Functions | Variables
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"
#include "asterisk/stasis_channels.h"
Include dependency graph for pbx_realtime.c:

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_CHEAT = (1 << 0) , OPTION_NUMGAMES = (1 << 1) , OPTION_PATTERNS_DISABLED = (1 << 0) }
 

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Realtime Switch")
 
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 int extension_length_comparator (struct ast_category *p, struct ast_category *q)
 
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

struct ao2_containercache
 
pthread_t cleanup_thread = 0
 
static struct ast_switch realtime_switch
 
static const 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

◆ EXT_DATA_SIZE

#define EXT_DATA_SIZE   256

Definition at line 59 of file pbx_realtime.c.

◆ MODE_CANMATCH

#define MODE_CANMATCH   2

Definition at line 57 of file pbx_realtime.c.

◆ MODE_MATCH

#define MODE_MATCH   0

Definition at line 55 of file pbx_realtime.c.

◆ MODE_MATCHMORE

#define MODE_MATCHMORE   1

Definition at line 56 of file pbx_realtime.c.

Enumeration Type Documentation

◆ option_flags

Enumerator
OPTION_CHEAT 
OPTION_NUMGAMES 
OPTION_PATTERNS_DISABLED 

Definition at line 61 of file pbx_realtime.c.

61 {
62 OPTION_PATTERNS_DISABLED = (1 << 0),
63};
@ OPTION_PATTERNS_DISABLED
Definition: pbx_realtime.c:62

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Realtime Switch"   
)

◆ cache_cmp()

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

Definition at line 86 of file pbx_realtime.c.

87{
88 struct cache_entry *e = obj, *f = arg;
89 return e->priority != f->priority ? 0 :
90 strcmp(e->exten, f->exten) ? 0 :
91 strcmp(e->context, f->context) ? 0 :
93}
@ CMP_MATCH
Definition: astobj2.h:1027
Definition: pbx_realtime.c:69
char exten[2]
Definition: pbx_realtime.c:74
char * context
Definition: pbx_realtime.c:73
int priority
Definition: pbx_realtime.c:72

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

Referenced by load_module().

◆ cache_hash()

static int cache_hash ( const void *  obj,
const int  flags 
)
static

Definition at line 80 of file pbx_realtime.c.

81{
82 const struct cache_entry *e = obj;
83 return ast_str_case_hash(e->exten) + e->priority;
84}
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:1303

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

Referenced by load_module().

◆ cleanup()

static void * cleanup ( void *  unused)
static

Definition at line 124 of file pbx_realtime.c.

125{
126 struct timespec forever = { 999999999, 0 }, one_second = { 1, 0 };
127 struct timeval now;
128
129 for (;;) {
130 pthread_testcancel();
131 if (ao2_container_count(cache) == 0) {
132 nanosleep(&forever, NULL);
133 }
134 pthread_testcancel();
135 now = ast_tvnow();
137 pthread_testcancel();
138 nanosleep(&one_second, NULL);
139 }
140
141 return NULL;
142}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
struct ao2_container * cache
Definition: pbx_realtime.c:77
static int purge_old_fn(void *obj, void *arg, int flags)
Definition: pbx_realtime.c:117
#define NULL
Definition: resample.c:96
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

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

Referenced by __get_from_jb(), aeap_user_data_create(), ast_aeap_user_data_register(), ast_event_new(), ast_rtcp_write(), ast_rtp_dtmf_end_with_duration(), ast_sockaddr_resolve(), AST_TEST_DEFINE(), astobj2_test_1_helper(), broadcast_exec(), build_user(), create_cts(), create_message_types(), digest_check_auth(), digest_create_request_with_auth(), handle_uri(), invalid_record_test(), load_module(), nominal_test(), off_nominal_test(), pjsip_outbound_registration_metrics_init(), query_set_test(), sendtext_exec(), set_outbound_authentication_credentials(), set_outbound_initial_authentication_credentials(), sfu_topologies_on_source_change(), and softmix_bridge_stream_sources_update().

◆ dup_vars()

static struct ast_variable * dup_vars ( struct ast_variable v)
static

Definition at line 95 of file pbx_realtime.c.

96{
97 struct ast_variable *new, *list = NULL;
98 for (; v; v = v->next) {
99 if (!(new = ast_variable_new(v->name, v->value, v->file))) {
101 return NULL;
102 }
103 /* Reversed list in cache, but when we duplicate out of the cache,
104 * it's back to correct order. */
105 new->next = list;
106 list = new;
107 }
108 return list;
109}
#define ast_variable_new(name, value, filename)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

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

Referenced by realtime_common().

◆ extension_length_comparator()

static int extension_length_comparator ( struct ast_category p,
struct ast_category q 
)
static

Definition at line 144 of file pbx_realtime.c.

145{
146 const char *extenp = S_OR(ast_variable_find(p, "exten"), "");
147 const char *extenq = S_OR(ast_variable_find(q, "exten"), "");
148
149 return strlen(extenp) - strlen(extenq);
150}
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
Definition: main/config.c:833
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80

References ast_variable_find(), and S_OR.

Referenced by realtime_switch_common().

◆ free_entry()

static void free_entry ( void *  obj)
static

Definition at line 111 of file pbx_realtime.c.

112{
113 struct cache_entry *e = obj;
115}
struct ast_variable * var
Definition: pbx_realtime.c:71

References ast_variables_destroy(), and cache_entry::var.

Referenced by realtime_common().

◆ load_module()

static int load_module ( void  )
static

Definition at line 413 of file pbx_realtime.c.

414{
417 if (!cache) {
419 }
420
423 }
424
428}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
Definition: module.h:102
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
int ast_register_switch(struct ast_switch *sw)
Register an alternative dialplan switch.
Definition: pbx_switch.c:58
pthread_t cleanup_thread
Definition: pbx_realtime.c:78
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
static int cache_hash(const void *obj, const int flags)
Definition: pbx_realtime.c:80
static struct ast_switch realtime_switch
Definition: pbx_realtime.c:392
static int cache_cmp(void *obj, void *arg, int flags)
Definition: pbx_realtime.c:86
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:584

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_pthread_create, ast_register_switch(), cache, cache_cmp(), cache_hash(), cleanup(), cleanup_thread, NULL, and realtime_switch.

◆ purge_old_fn()

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

Definition at line 117 of file pbx_realtime.c.

118{
119 struct cache_entry *e = obj;
120 struct timeval *now = arg;
121 return ast_tvdiff_ms(*now, e->when) >= 1000 ? CMP_MATCH : 0;
122}
struct timeval when
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:107

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

Referenced by cleanup().

◆ realtime_canmatch()

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 299 of file pbx_realtime.c.

300{
302 if (var) {
304 return 1;
305 }
306 return 0;
307}
#define var
Definition: ast_expr2f.c:605
static int priority
static struct ast_variable * realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
Definition: pbx_realtime.c:229
#define MODE_CANMATCH
Definition: pbx_realtime.c:57

References ast_variables_destroy(), voicemailpwcheck::context, MODE_CANMATCH, priority, realtime_common(), and var.

◆ realtime_common()

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

Definition at line 229 of file pbx_realtime.c.

230{
231 const char *ctx = NULL;
232 char *table;
233 struct ast_variable *var=NULL;
234 struct ast_flags flags = { 0, };
235 struct cache_entry *ce;
236 struct {
237 struct cache_entry ce;
239 } cache_search = { { .priority = priority, .context = (char *) context }, };
240 char *buf = ast_strdupa(data);
241 /* "Realtime" prefix is stripped off in the parent engine. The
242 * remaining string is: [[context@]table][/opts] */
243 char *opts = strchr(buf, '/');
244 if (opts)
245 *opts++ = '\0';
246 table = strchr(buf, '@');
247 if (table) {
248 *table++ = '\0';
249 ctx = buf;
250 }
251 ctx = S_OR(ctx, context);
252 table = S_OR(table, "extensions");
253 if (!ast_strlen_zero(opts)) {
254 ast_app_parse_options(switch_opts, &flags, NULL, opts);
255 }
256 ast_copy_string(cache_search.exten, exten, sizeof(cache_search.exten));
257 if (mode == MODE_MATCH && (ce = ao2_find(cache, &cache_search, OBJ_POINTER))) {
258 var = dup_vars(ce->var);
259 ao2_ref(ce, -1);
260 } else {
261 var = realtime_switch_common(table, ctx, exten, priority, mode, flags);
262 do {
263 struct ast_variable *new;
264 /* Only cache matches */
265 if (mode != MODE_MATCH) {
266 break;
267 }
268 if (!(new = dup_vars(var))) {
269 break;
270 }
271 if (!(ce = ao2_alloc(sizeof(*ce) + strlen(exten) + strlen(context), free_entry))) {
273 break;
274 }
275 ce->context = ce->exten + strlen(exten) + 1;
276 strcpy(ce->exten, exten); /* SAFE */
277 strcpy(ce->context, context); /* SAFE */
278 ce->priority = priority;
279 ce->var = new;
280 ce->when = ast_tvnow();
281 ao2_link(cache, ce);
282 pthread_kill(cleanup_thread, SIGURG);
283 ao2_ref(ce, -1);
284 } while (0);
285 }
286 return var;
287}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
#define OBJ_POINTER
Definition: astobj2.h:1150
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static char * table
Definition: cdr_odbc.c:55
#define AST_MAX_EXTENSION
Definition: channel.h:134
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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: main/app.c:3066
static const struct ast_app_option switch_opts[128]
Definition: pbx_realtime.c:67
static struct ast_variable * dup_vars(struct ast_variable *v)
Definition: pbx_realtime.c:95
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:166
static void free_entry(void *obj)
Definition: pbx_realtime.c:111
#define MODE_MATCH
Definition: pbx_realtime.c:55
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200

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(), buf, cache, cleanup_thread, voicemailpwcheck::context, cache_entry::context, dup_vars(), cache_entry::exten, ast_flags::flags, free_entry(), MODE_MATCH, NULL, OBJ_POINTER, priority, cache_entry::priority, realtime_switch_common(), S_OR, switch_opts, table, var, cache_entry::var, and cache_entry::when.

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

◆ realtime_exec()

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 309 of file pbx_realtime.c.

310{
311 int res = -1;
312 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
313
314 if (var) {
315 char *appdata_tmp = "";
316 char *app = NULL;
317 struct ast_variable *v;
318
319 for (v = var; v ; v = v->next) {
320 if (!strcasecmp(v->name, "app"))
321 app = ast_strdupa(v->value);
322 else if (!strcasecmp(v->name, "appdata")) {
323 appdata_tmp = ast_strdupa(v->value);
324 }
325 }
327 if (!ast_strlen_zero(app)) {
328 struct ast_app *a = pbx_findapp(app);
329 if (a) {
330 char appdata[512];
331 char tmp1[80];
332 char tmp2[80];
333 char tmp3[EXT_DATA_SIZE];
334
335 appdata[0] = 0; /* just in case the substitute var func isn't called */
336 if(!ast_strlen_zero(appdata_tmp))
337 pbx_substitute_variables_helper(chan, appdata_tmp, appdata, sizeof(appdata) - 1);
338 ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
340 term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
341 term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
342 term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
344 char *tmp_appl;
345 char *tmp_data;
346
347 ast_channel_lock(chan);
348 /* Force a new dialplan segment that will be unique to use so we can update it with the
349 * information we want. In the future when a channel snapshot is published this will
350 * occur again and unset this flag.
351 */
353
354 /* pbx_exec sets application name and data, but we don't want to log
355 * every exec. Just update the snapshot here instead. Publishing the
356 * snapshot retrieves data from the channel object directly, so save
357 * current values prior to publishing so they can be restored after.
358 */
359 tmp_appl = ast_channel_appl(chan) ? ast_strdupa(ast_channel_appl(chan)) : NULL;
360 tmp_data = ast_channel_data(chan) ? ast_strdupa(ast_channel_data(chan)) : NULL;
361
363 ast_channel_data_set(chan, !ast_strlen_zero(appdata) ? appdata : "(NULL)");
364
366
367 ast_channel_appl_set(chan, tmp_appl);
368 ast_channel_data_set(chan, tmp_data);
369
370 ast_channel_unlock(chan);
371 }
372 res = pbx_exec(chan, a, appdata);
373 } else
374 ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
375 } else {
376 ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context);
377 }
378 }
379 return res;
380}
static const char app[]
Definition: app_adsiprog.c:56
#define ast_log
Definition: astobj2.c:42
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
const char * ast_channel_data(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2968
void ast_channel_data_set(struct ast_channel *chan, const char *value)
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2969
void ast_channel_snapshot_invalidate_segment(struct ast_channel *chan, enum ast_channel_snapshot_segment_invalidation segment)
Invalidate a channel snapshot segment from being reused.
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
@ AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211
#define EXT_DATA_SIZE
Definition: pbx_realtime.c:59
ast_app: A registered application
Definition: pbx_app.c:45
#define COLOR_BRCYAN
Definition: term.h:63
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
Definition: term.c:235
#define COLOR_BRMAGENTA
Definition: term.h:61
static struct test_val a

References a, app, ast_channel_appl(), ast_channel_appl_set(), ast_channel_context(), ast_channel_data(), ast_channel_data_set(), ast_channel_exten(), ast_channel_lock, ast_channel_name(), ast_channel_priority(), ast_channel_publish_snapshot(), AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN, ast_channel_snapshot_invalidate_segment(), ast_channel_snapshot_type(), ast_channel_unlock, ast_log, ast_strdupa, ast_strlen_zero(), ast_variables_destroy(), ast_verb, COLOR_BRCYAN, COLOR_BRMAGENTA, voicemailpwcheck::context, EXT_DATA_SIZE, LOG_NOTICE, LOG_WARNING, MODE_MATCH, ast_variable::name, ast_variable::next, NULL, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), priority, realtime_common(), S_OR, term_color(), ast_variable::value, and var.

◆ realtime_exists()

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 289 of file pbx_realtime.c.

290{
291 struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
292 if (var) {
294 return 1;
295 }
296 return 0;
297}

References ast_variables_destroy(), voicemailpwcheck::context, MODE_MATCH, priority, realtime_common(), and var.

◆ realtime_matchmore()

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 382 of file pbx_realtime.c.

383{
385 if (var) {
387 return 1;
388 }
389 return 0;
390}
#define MODE_MATCHMORE
Definition: pbx_realtime.c:56

References ast_variables_destroy(), voicemailpwcheck::context, MODE_MATCHMORE, priority, realtime_common(), and var.

◆ realtime_switch_common()

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 166 of file pbx_realtime.c.

167{
168 struct ast_variable *var;
169 struct ast_config *cfg;
170 char pri[20];
171 char *ematch;
172 char rexten[AST_MAX_EXTENSION + 20]="";
173 int match;
174 /* Optimization: since we don't support hints in realtime, it's silly to
175 * query for a hint here, since we won't actually do anything with it.
176 * This just wastes CPU time and resources. */
177 if (priority < 0) {
178 return NULL;
179 }
180 snprintf(pri, sizeof(pri), "%d", priority);
181 switch(mode) {
182 case MODE_MATCHMORE:
183 ematch = "exten LIKE";
184 snprintf(rexten, sizeof(rexten), "%s_%%", exten);
185 break;
186 case MODE_CANMATCH:
187 ematch = "exten LIKE";
188 snprintf(rexten, sizeof(rexten), "%s%%", exten);
189 break;
190 case MODE_MATCH:
191 default:
192 ematch = "exten";
193 ast_copy_string(rexten, exten, sizeof(rexten));
194 }
195 var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL);
196 if (!var && !ast_test_flag(&flags, OPTION_PATTERNS_DISABLED)) {
197 cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL);
198 if (cfg) {
199 char *cat = NULL;
200
201 /* Sort so that longer patterns are checked first */
203
204 while ((cat = ast_category_browse(cfg, cat))) {
205 const char *realtime_exten = ast_variable_retrieve(cfg, cat, "exten");
206
207 switch(mode) {
208 case MODE_MATCHMORE:
209 match = ast_extension_close(realtime_exten, exten, 1);
210 break;
211 case MODE_CANMATCH:
212 match = ast_extension_close(realtime_exten, exten, 0);
213 break;
214 case MODE_MATCH:
215 default:
216 match = ast_extension_match(realtime_exten, exten);
217 }
218 if (match) {
220 break;
221 }
222 }
224 }
225 }
226 return var;
227}
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2362
#define SENTINEL
Definition: compiler.h:87
struct ast_variable * ast_category_detach_variables(struct ast_category *cat)
Definition: main/config.c:1449
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3326
void ast_config_sort_categories(struct ast_config *config, int descending, int(*comparator)(struct ast_category *p, struct ast_category *q))
Sorts categories in a config in the order of a numerical value contained within them.
Definition: main/config.c:1269
struct ast_config * ast_load_realtime_multientry(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
Definition: main/config.c:3637
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:784
struct ast_variable * ast_load_realtime(const char *family,...) attribute_sentinel
Definition: main/config.c:3521
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1120
int ast_extension_close(const char *pattern, const char *data, int needmore)
Definition: pbx.c:2432
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4295
static int extension_length_comparator(struct ast_category *p, struct ast_category *q)
Definition: pbx_realtime.c:144
#define ast_test_flag(p, flag)
Definition: utils.h:63

References ast_category_browse(), ast_category_detach_variables(), ast_category_get(), ast_config_destroy(), ast_config_sort_categories(), ast_copy_string(), ast_extension_close(), ast_extension_match(), ast_load_realtime(), ast_load_realtime_multientry(), AST_MAX_EXTENSION, ast_test_flag, ast_variable_retrieve(), voicemailpwcheck::context, extension_length_comparator(), match(), MODE_CANMATCH, MODE_MATCH, MODE_MATCHMORE, NULL, OPTION_PATTERNS_DISABLED, priority, SENTINEL, table, and var.

Referenced by realtime_common().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 402 of file pbx_realtime.c.

403{
405 pthread_cancel(cleanup_thread);
406 pthread_kill(cleanup_thread, SIGURG);
407 pthread_join(cleanup_thread, NULL);
408 /* Destroy all remaining entries */
409 ao2_ref(cache, -1);
410 return 0;
411}
void ast_unregister_switch(struct ast_switch *sw)
Unregister an alternative switch.
Definition: pbx_switch.c:76

References ao2_ref, ast_unregister_switch(), cache, cleanup_thread, NULL, and realtime_switch.

Variable Documentation

◆ cache

struct ao2_container* cache

Definition at line 77 of file pbx_realtime.c.

Referenced by __frame_free(), add_to_cache(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_frame_free(), AST_TEST_DEFINE(), cache_dtor(), cache_put(), check_cache_aggregate(), cleanup(), expire_objects_from_cache(), load_module(), mark_all_as_stale_in_cache(), mark_object_as_stale_in_cache(), memory_cache_full_update(), memory_cache_populate(), memory_cache_stale_check(), memory_cache_stale_check_object(), memory_cache_stale_update_full(), memory_cache_stale_update_object(), object_add_to_cache_callback(), object_stale_callback(), realtime_common(), remove_all_from_cache(), remove_from_cache(), remove_oldest_from_cache(), schedule_cache_expiration(), sorcery_memory_cache_ami_expire(), sorcery_memory_cache_ami_expire_object(), sorcery_memory_cache_ami_populate(), sorcery_memory_cache_ami_stale(), sorcery_memory_cache_ami_stale_object(), sorcery_memory_cache_close(), sorcery_memory_cache_complete_name(), sorcery_memory_cache_complete_object_name(), sorcery_memory_cache_create(), sorcery_memory_cache_delete(), sorcery_memory_cache_destructor(), sorcery_memory_cache_dump(), sorcery_memory_cache_expire(), sorcery_memory_cache_hash(), sorcery_memory_cache_load(), sorcery_memory_cache_open(), sorcery_memory_cache_populate(), sorcery_memory_cache_reload(), sorcery_memory_cache_retrieve_fields(), sorcery_memory_cache_retrieve_id(), sorcery_memory_cache_retrieve_multiple(), sorcery_memory_cache_retrieve_prefix(), sorcery_memory_cache_retrieve_regex(), sorcery_memory_cache_show(), sorcery_memory_cache_stale(), sorcery_memory_cached_object_alloc(), stale_cache_update_task_data_alloc(), stale_update_task_data_alloc(), stasis_cache_create_full(), stasis_cache_dump(), stasis_cache_dump_all(), stasis_cache_dump_by_eid(), stasis_cache_get(), stasis_cache_get_all(), stasis_cache_get_by_eid(), stasis_caching_topic_create(), and unload_module().

◆ cleanup_thread

pthread_t cleanup_thread = 0

Definition at line 78 of file pbx_realtime.c.

Referenced by load_module(), realtime_common(), and unload_module().

◆ realtime_switch

struct ast_switch realtime_switch
static

Definition at line 392 of file pbx_realtime.c.

Referenced by load_module(), and unload_module().

◆ switch_opts

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

Definition at line 67 of file pbx_realtime.c.

Referenced by realtime_common().