asterisk/pbx/pbx_realtime.c

431 lines
12 KiB
C
Raw Normal View History

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Realtime PBX Module
*
* \arg See also: \ref AstARA
*/
/*** MODULEINFO
<support_level>extended</support_level>
***/
#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"
#define MODE_MATCH 0
#define MODE_MATCHMORE 1
#define MODE_CANMATCH 2
#define EXT_DATA_SIZE 256
enum option_flags {
OPTION_PATTERNS_DISABLED = (1 << 0),
};
AST_APP_OPTIONS(switch_opts, {
AST_APP_OPTION('p', OPTION_PATTERNS_DISABLED),
});
struct cache_entry {
struct timeval when;
struct ast_variable *var;
int priority;
char *context;
char exten[2];
};
struct ao2_container *cache;
pthread_t cleanup_thread = 0;
static int cache_hash(const void *obj, const int flags)
{
const struct cache_entry *e = obj;
return ast_str_case_hash(e->exten) + e->priority;
}
static int cache_cmp(void *obj, void *arg, int flags)
{
struct cache_entry *e = obj, *f = arg;
return e->priority != f->priority ? 0 :
strcmp(e->exten, f->exten) ? 0 :
strcmp(e->context, f->context) ? 0 :
CMP_MATCH;
}
static struct ast_variable *dup_vars(struct ast_variable *v)
{
struct ast_variable *new, *list = NULL;
for (; v; v = v->next) {
if (!(new = ast_variable_new(v->name, v->value, v->file))) {
ast_variables_destroy(list);
return NULL;
}
/* Reversed list in cache, but when we duplicate out of the cache,
* it's back to correct order. */
new->next = list;
list = new;
}
return list;
}
static void free_entry(void *obj)
{
struct cache_entry *e = obj;
ast_variables_destroy(e->var);
}
static int purge_old_fn(void *obj, void *arg, int flags)
{
struct cache_entry *e = obj;
struct timeval *now = arg;
return ast_tvdiff_ms(*now, e->when) >= 1000 ? CMP_MATCH : 0;
}
static void *cleanup(void *unused)
{
struct timespec forever = { 999999999, 0 }, one_second = { 1, 0 };
struct timeval now;
for (;;) {
pthread_testcancel();
if (ao2_container_count(cache) == 0) {
nanosleep(&forever, NULL);
}
pthread_testcancel();
now = ast_tvnow();
ao2_callback(cache, OBJ_MULTIPLE | OBJ_UNLINK | OBJ_NODATA, purge_old_fn, &now);
pthread_testcancel();
nanosleep(&one_second, NULL);
}
return NULL;
}
static int extension_length_comparator(struct ast_category *p, struct ast_category *q)
{
const char *extenp = S_OR(ast_variable_find(p, "exten"), "");
const char *extenq = S_OR(ast_variable_find(q, "exten"), "");
return strlen(extenp) - strlen(extenq);
}
/* Realtime switch looks up extensions in the supplied realtime table.
[context@][realtimetable][/options]
If the realtimetable is omitted it is assumed to be "extensions". If no context is
specified the context is assumed to be whatever is the container.
The realtime table should have entries for context,exten,priority,app,args
The realtime table currently does not support callerid fields.
*/
static struct ast_variable *realtime_switch_common(const char *table, const char *context, const char *exten, int priority, int mode, struct ast_flags flags)
{
struct ast_variable *var;
struct ast_config *cfg;
char pri[20];
char *ematch;
char rexten[AST_MAX_EXTENSION + 20]="";
int match;
/* Optimization: since we don't support hints in realtime, it's silly to
* query for a hint here, since we won't actually do anything with it.
* This just wastes CPU time and resources. */
if (priority < 0) {
return NULL;
}
snprintf(pri, sizeof(pri), "%d", priority);
switch(mode) {
case MODE_MATCHMORE:
ematch = "exten LIKE";
snprintf(rexten, sizeof(rexten), "%s_%%", exten);
break;
case MODE_CANMATCH:
ematch = "exten LIKE";
snprintf(rexten, sizeof(rexten), "%s%%", exten);
break;
case MODE_MATCH:
default:
ematch = "exten";
ast_copy_string(rexten, exten, sizeof(rexten));
}
var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL);
if (!var && !ast_test_flag(&flags, OPTION_PATTERNS_DISABLED)) {
cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL);
if (cfg) {
char *cat = NULL;
/* Sort so that longer patterns are checked first */
ast_config_sort_categories(cfg, 1, extension_length_comparator);
while ((cat = ast_category_browse(cfg, cat))) {
const char *realtime_exten = ast_variable_retrieve(cfg, cat, "exten");
switch(mode) {
case MODE_MATCHMORE:
match = ast_extension_close(realtime_exten, exten, 1);
break;
case MODE_CANMATCH:
match = ast_extension_close(realtime_exten, exten, 0);
break;
case MODE_MATCH:
default:
match = ast_extension_match(realtime_exten, exten);
}
if (match) {
manager/config: Support templates and non-unique category names via AMI This patch provides the capability to manipulate templates and categories with non-unique names via AMI. Summary of changes: GetConfig and GetConfigJSON: Added "Filter" parameter: A comma separated list of name_regex=value_regex expressions which will cause only categories whose variables match all expressions to be considered. The special variable name TEMPLATES can be used to control whether templates are included. Passing 'include' as the value will include templates along with normal categories. Passing 'restrict' as the value will restrict the operation to ONLY templates. Not specifying a TEMPLATES expression results in the current default behavior which is to not include templates. UpdateConfig: NewCat now includes options for allowing duplicate category names, indicating if the category should be created as a template, and specifying templates the category should inherit from. The rest of the actions now accept a filter string as defined above. If there are non-unique category names, you can now update specific ones based on variable values. To facilitate the new capabilities in manager, corresponding changes had to be made to config, most notably the addition of filter criteria to many of the APIs. In some cases it was easy to change the references to use the new prototype but others would have required touching too many files for this patch so a wrapper with the original prototype was created. Macros couldn't be used in this case because it would break binary compatibility with modules such as res_digium_phone that are linked to real symbols. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4033/ ........ Merged revisions 425383 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 425384 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425385 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-10-13 16:12:17 +00:00
var = ast_category_detach_variables(ast_category_get(cfg, cat, NULL));
break;
}
}
ast_config_destroy(cfg);
}
}
return var;
}
static struct ast_variable *realtime_common(const char *context, const char *exten, int priority, const char *data, int mode)
{
const char *ctx = NULL;
char *table;
struct ast_variable *var=NULL;
struct ast_flags flags = { 0, };
struct cache_entry *ce;
struct {
struct cache_entry ce;
char exten[AST_MAX_EXTENSION];
} cache_search = { { .priority = priority, .context = (char *) context }, };
char *buf = ast_strdupa(data);
/* "Realtime" prefix is stripped off in the parent engine. The
* remaining string is: [[context@]table][/opts] */
char *opts = strchr(buf, '/');
if (opts)
*opts++ = '\0';
table = strchr(buf, '@');
if (table) {
*table++ = '\0';
ctx = buf;
}
ctx = S_OR(ctx, context);
table = S_OR(table, "extensions");
if (!ast_strlen_zero(opts)) {
ast_app_parse_options(switch_opts, &flags, NULL, opts);
}
ast_copy_string(cache_search.exten, exten, sizeof(cache_search.exten));
if (mode == MODE_MATCH && (ce = ao2_find(cache, &cache_search, OBJ_POINTER))) {
var = dup_vars(ce->var);
ao2_ref(ce, -1);
} else {
var = realtime_switch_common(table, ctx, exten, priority, mode, flags);
do {
struct ast_variable *new;
/* Only cache matches */
if (mode != MODE_MATCH) {
break;
}
if (!(new = dup_vars(var))) {
break;
}
if (!(ce = ao2_alloc(sizeof(*ce) + strlen(exten) + strlen(context), free_entry))) {
ast_variables_destroy(new);
break;
}
ce->context = ce->exten + strlen(exten) + 1;
strcpy(ce->exten, exten); /* SAFE */
strcpy(ce->context, context); /* SAFE */
ce->priority = priority;
ce->var = new;
ce->when = ast_tvnow();
ao2_link(cache, ce);
pthread_kill(cleanup_thread, SIGURG);
ao2_ref(ce, -1);
} while (0);
}
return var;
}
static int realtime_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
if (var) {
ast_variables_destroy(var);
return 1;
}
return 0;
}
static int realtime_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH);
if (var) {
ast_variables_destroy(var);
return 1;
}
return 0;
}
static int realtime_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{
int res = -1;
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
if (var) {
Remove many deprecated modules Billing records are fair, To get paid is quite bright, You should really use ODBC; Good-bye cdr_sqlite. Microsoft did once push H.323, Hell, we all remember NetMeeting. But try to compile chan_h323 now And you will take quite a beating. The XMPP and SIP war was fierce, And in the distant fray Was birthed res_jabber/chan_jingle; But neither to stay. For everyone did care and chase what Google professed. "Free Internet Calling" was what devotees cried, But Google did change the specs so often That the developers were happy the day chan_gtalk died. And then there was that odd application Dedicated to the Polish tongue. app_saycountpl was subsumed by Say; One could say its bell was rung. To read and parse a file from the dialplan You could (I guess) use an application. app_readfile did fill that purpose, but I think A function is perhaps better in its creation. Barging is rude, I'm not sure why we do it. Inwardly, the caller will probably sigh. But if you really must do it, Don't use app_dahdibarge, use ChanSpy. We all despise the sound of tinny robots It makes our queues so cold. To control such an abomination It's better to not use Wait/SetMusicOnHold. It's often nice to know properties of a channel It makes our calls right We have a nice function called CHANNEL And so SIPCHANINFO is sent off into the night. And now things get odd; Apparently one could delimit with a colon Properties from the SIPPEER function! Commas are in; all others are done. Finally, a word on pipes and commas. We're sorry. We can't say it enough. But those compatibility options in asterisk.conf; To maintain them forever was just too tough. This patch removes: * cdr_sqlite * chan_gtalk * chan_jingle * chan_h323 * res_jabber * app_saycountpl * app_readfile * app_dahdibarge It removes the following applications/functions: * WaitMusicOnHold * SetMusicOnHold * SIPCHANINFO It removes the colon delimiter from the SIPPEER function. Finally, it also removes all compatibility options that were configurable from asterisk.conf, as these all applied to compatibility with Asterisk 1.4 systems. Review: https://reviewboard.asterisk.org/r/3698/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418019 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-04 13:26:37 +00:00
char *appdata_tmp = "";
char *app = NULL;
struct ast_variable *v;
for (v = var; v ; v = v->next) {
if (!strcasecmp(v->name, "app"))
app = ast_strdupa(v->value);
else if (!strcasecmp(v->name, "appdata")) {
Remove many deprecated modules Billing records are fair, To get paid is quite bright, You should really use ODBC; Good-bye cdr_sqlite. Microsoft did once push H.323, Hell, we all remember NetMeeting. But try to compile chan_h323 now And you will take quite a beating. The XMPP and SIP war was fierce, And in the distant fray Was birthed res_jabber/chan_jingle; But neither to stay. For everyone did care and chase what Google professed. "Free Internet Calling" was what devotees cried, But Google did change the specs so often That the developers were happy the day chan_gtalk died. And then there was that odd application Dedicated to the Polish tongue. app_saycountpl was subsumed by Say; One could say its bell was rung. To read and parse a file from the dialplan You could (I guess) use an application. app_readfile did fill that purpose, but I think A function is perhaps better in its creation. Barging is rude, I'm not sure why we do it. Inwardly, the caller will probably sigh. But if you really must do it, Don't use app_dahdibarge, use ChanSpy. We all despise the sound of tinny robots It makes our queues so cold. To control such an abomination It's better to not use Wait/SetMusicOnHold. It's often nice to know properties of a channel It makes our calls right We have a nice function called CHANNEL And so SIPCHANINFO is sent off into the night. And now things get odd; Apparently one could delimit with a colon Properties from the SIPPEER function! Commas are in; all others are done. Finally, a word on pipes and commas. We're sorry. We can't say it enough. But those compatibility options in asterisk.conf; To maintain them forever was just too tough. This patch removes: * cdr_sqlite * chan_gtalk * chan_jingle * chan_h323 * res_jabber * app_saycountpl * app_readfile * app_dahdibarge It removes the following applications/functions: * WaitMusicOnHold * SetMusicOnHold * SIPCHANINFO It removes the colon delimiter from the SIPPEER function. Finally, it also removes all compatibility options that were configurable from asterisk.conf, as these all applied to compatibility with Asterisk 1.4 systems. Review: https://reviewboard.asterisk.org/r/3698/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418019 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-04 13:26:37 +00:00
appdata_tmp = ast_strdupa(v->value);
}
}
ast_variables_destroy(var);
if (!ast_strlen_zero(app)) {
struct ast_app *a = pbx_findapp(app);
if (a) {
char appdata[512];
char tmp1[80];
char tmp2[80];
char tmp3[EXT_DATA_SIZE];
appdata[0] = 0; /* just in case the substitute var func isn't called */
Remove many deprecated modules Billing records are fair, To get paid is quite bright, You should really use ODBC; Good-bye cdr_sqlite. Microsoft did once push H.323, Hell, we all remember NetMeeting. But try to compile chan_h323 now And you will take quite a beating. The XMPP and SIP war was fierce, And in the distant fray Was birthed res_jabber/chan_jingle; But neither to stay. For everyone did care and chase what Google professed. "Free Internet Calling" was what devotees cried, But Google did change the specs so often That the developers were happy the day chan_gtalk died. And then there was that odd application Dedicated to the Polish tongue. app_saycountpl was subsumed by Say; One could say its bell was rung. To read and parse a file from the dialplan You could (I guess) use an application. app_readfile did fill that purpose, but I think A function is perhaps better in its creation. Barging is rude, I'm not sure why we do it. Inwardly, the caller will probably sigh. But if you really must do it, Don't use app_dahdibarge, use ChanSpy. We all despise the sound of tinny robots It makes our queues so cold. To control such an abomination It's better to not use Wait/SetMusicOnHold. It's often nice to know properties of a channel It makes our calls right We have a nice function called CHANNEL And so SIPCHANINFO is sent off into the night. And now things get odd; Apparently one could delimit with a colon Properties from the SIPPEER function! Commas are in; all others are done. Finally, a word on pipes and commas. We're sorry. We can't say it enough. But those compatibility options in asterisk.conf; To maintain them forever was just too tough. This patch removes: * cdr_sqlite * chan_gtalk * chan_jingle * chan_h323 * res_jabber * app_saycountpl * app_readfile * app_dahdibarge It removes the following applications/functions: * WaitMusicOnHold * SetMusicOnHold * SIPCHANINFO It removes the colon delimiter from the SIPPEER function. Finally, it also removes all compatibility options that were configurable from asterisk.conf, as these all applied to compatibility with Asterisk 1.4 systems. Review: https://reviewboard.asterisk.org/r/3698/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418019 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-04 13:26:37 +00:00
if(!ast_strlen_zero(appdata_tmp))
pbx_substitute_variables_helper(chan, appdata_tmp, appdata, sizeof(appdata) - 1);
ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
ast_channel_exten(chan), ast_channel_context(chan), ast_channel_priority(chan),
term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
Replace direct access to channel name with accessor functions There are many benefits to making the ast_channel an opaque handle, from increasing maintainability to presenting ways to kill masquerades. This patch kicks things off by taking things a field at a time, renaming the field to '__do_not_use_${fieldname}' and then writing setters/getters and converting the existing code to using them. When all fields are done, we can move ast_channel to a C file from channel.h and lop off the '__do_not_use_'. This patch sets up main/channel_interal_api.c to be the only file that actually accesses the ast_channel's fields directly. The intent would be for any API functions in channel.c to use the accessor functions. No more monkeying around with channel internals. We should use our own APIs. The interesting changes in this patch are the addition of channel_internal_api.c, the moving of the AST_DATA stuff from channel.c to channel_internal_api.c (note: the AST_DATA stuff will have to be reworked to use accessor functions when ast_channel is really opaque), and some re-working of the way channel iterators/callbacks are handled so as to avoid creating fake ast_channels on the stack to pass in matching data by directly accessing fields (since "name" is a stringfield and the fake channel doesn't init the stringfields, you can't use the ast_channel_name_set() function). I went with ast_channel_name(chan) for a getter, and ast_channel_name_set(chan, name) for a setter. The majority of the grunt-work for this change was done by writing a semantic patch using Coccinelle ( http://coccinelle.lip6.fr/ ). Review: https://reviewboard.asterisk.org/r/1655/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350223 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-01-09 22:15:50 +00:00
term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
if (ast_channel_snapshot_type()) {
char *tmp_appl;
char *tmp_data;
ast_channel_lock(chan);
/* Force a new dialplan segment that will be unique to use so we can update it with the
* information we want. In the future when a channel snapshot is published this will
* occur again and unset this flag.
*/
ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);
Move more channel events to Stasis; move res_json.c to main/json.c. This patch started out simply as fixing the bouncing tests introduced in r382685, but required some other changes to give it a decent implementation. To fix the bouncing tests, the UserEvent and Newexten AMI events needed to be refactored to dispatch via Stasis. Dispatching directly to AMI resulted in those events sometimes getting ahead of the associated Newchannel events, which would understandably confuse anyone. I found that instead of creating a zillion different message types and structures associated with them, it would be preferable to define a message type that has a channel snapshot and a blob of structured data with a small bit of additional information. The JSON object model provides a very nice way of representing structured data, so I went with that. * Move JSON support from res_json.c to main/json.c * Made libjansson-dev a required dependency * Added an ast_channel_blob message type, which has a channel snapshot and JSON blob of data. * Changed UserEvent and Newexten events so that they are dispatched via ast_channel_blob messages on the channel's topic. * Got rid of the ast_channel_varset message; used ast_channel_blob instead. * Extracted the manager functions converting Stasis channel events to AMI events into manager_channel.c. (issue ASTERISK-21096) Review: https://reviewboard.asterisk.org/r/2381/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383579 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-03-22 14:06:46 +00:00
/* pbx_exec sets application name and data, but we don't want to log
* every exec. Just update the snapshot here instead. Publishing the
* snapshot retrieves data from the channel object directly, so save
* current values prior to publishing so they can be restored after.
Move more channel events to Stasis; move res_json.c to main/json.c. This patch started out simply as fixing the bouncing tests introduced in r382685, but required some other changes to give it a decent implementation. To fix the bouncing tests, the UserEvent and Newexten AMI events needed to be refactored to dispatch via Stasis. Dispatching directly to AMI resulted in those events sometimes getting ahead of the associated Newchannel events, which would understandably confuse anyone. I found that instead of creating a zillion different message types and structures associated with them, it would be preferable to define a message type that has a channel snapshot and a blob of structured data with a small bit of additional information. The JSON object model provides a very nice way of representing structured data, so I went with that. * Move JSON support from res_json.c to main/json.c * Made libjansson-dev a required dependency * Added an ast_channel_blob message type, which has a channel snapshot and JSON blob of data. * Changed UserEvent and Newexten events so that they are dispatched via ast_channel_blob messages on the channel's topic. * Got rid of the ast_channel_varset message; used ast_channel_blob instead. * Extracted the manager functions converting Stasis channel events to AMI events into manager_channel.c. (issue ASTERISK-21096) Review: https://reviewboard.asterisk.org/r/2381/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383579 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-03-22 14:06:46 +00:00
*/
tmp_appl = ast_channel_appl(chan) ? ast_strdupa(ast_channel_appl(chan)) : NULL;
tmp_data = ast_channel_data(chan) ? ast_strdupa(ast_channel_data(chan)) : NULL;
ast_channel_appl_set(chan, app);
ast_channel_data_set(chan, !ast_strlen_zero(appdata) ? appdata : "(NULL)");
ast_channel_publish_snapshot(chan);
ast_channel_appl_set(chan, tmp_appl);
ast_channel_data_set(chan, tmp_data);
ast_channel_unlock(chan);
Move more channel events to Stasis; move res_json.c to main/json.c. This patch started out simply as fixing the bouncing tests introduced in r382685, but required some other changes to give it a decent implementation. To fix the bouncing tests, the UserEvent and Newexten AMI events needed to be refactored to dispatch via Stasis. Dispatching directly to AMI resulted in those events sometimes getting ahead of the associated Newchannel events, which would understandably confuse anyone. I found that instead of creating a zillion different message types and structures associated with them, it would be preferable to define a message type that has a channel snapshot and a blob of structured data with a small bit of additional information. The JSON object model provides a very nice way of representing structured data, so I went with that. * Move JSON support from res_json.c to main/json.c * Made libjansson-dev a required dependency * Added an ast_channel_blob message type, which has a channel snapshot and JSON blob of data. * Changed UserEvent and Newexten events so that they are dispatched via ast_channel_blob messages on the channel's topic. * Got rid of the ast_channel_varset message; used ast_channel_blob instead. * Extracted the manager functions converting Stasis channel events to AMI events into manager_channel.c. (issue ASTERISK-21096) Review: https://reviewboard.asterisk.org/r/2381/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383579 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-03-22 14:06:46 +00:00
}
res = pbx_exec(chan, a, appdata);
} else
ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
} else {
ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context);
}
}
return res;
}
static int realtime_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE);
if (var) {
ast_variables_destroy(var);
return 1;
}
return 0;
}
static struct ast_switch realtime_switch =
{
.name = "Realtime",
.description = "Realtime Dialplan Switch",
.exists = realtime_exists,
.canmatch = realtime_canmatch,
.exec = realtime_exec,
.matchmore = realtime_matchmore,
};
static int unload_module(void)
{
ast_unregister_switch(&realtime_switch);
pthread_cancel(cleanup_thread);
pthread_kill(cleanup_thread, SIGURG);
pthread_join(cleanup_thread, NULL);
/* Destroy all remaining entries */
ao2_ref(cache, -1);
return 0;
}
static int load_module(void)
{
cache = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 573,
cache_hash, NULL, cache_cmp);
if (!cache) {
return AST_MODULE_LOAD_FAILURE;
}
if (ast_pthread_create(&cleanup_thread, NULL, cleanup, NULL)) {
return AST_MODULE_LOAD_FAILURE;
}
if (ast_register_switch(&realtime_switch))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Realtime Switch");