2004-11-22 03:25:27 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* 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.
|
2004-11-22 03:25:27 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2004-11-22 03:25:27 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Realtime PBX Module
|
2004-11-22 03:25:27 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \arg See also: \ref AstARA
|
2004-11-22 03:25:27 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>extended</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2010-05-27 19:25:16 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#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"
|
2008-12-15 21:17:07 +00:00
|
|
|
#include "asterisk/app.h"
|
2010-05-27 19:25:16 +00:00
|
|
|
#include "asterisk/astobj2.h"
|
2013-04-08 14:26:37 +00:00
|
|
|
#include "asterisk/stasis_channels.h"
|
2004-11-22 03:25:27 +00:00
|
|
|
|
2004-11-24 03:07:08 +00:00
|
|
|
#define MODE_MATCH 0
|
|
|
|
#define MODE_MATCHMORE 1
|
|
|
|
#define MODE_CANMATCH 2
|
2004-11-22 14:33:42 +00:00
|
|
|
|
2004-12-06 17:21:44 +00:00
|
|
|
#define EXT_DATA_SIZE 256
|
|
|
|
|
2009-06-15 17:34:30 +00:00
|
|
|
enum option_flags {
|
2008-12-15 21:17:07 +00:00
|
|
|
OPTION_PATTERNS_DISABLED = (1 << 0),
|
2009-06-15 17:34:30 +00:00
|
|
|
};
|
2008-12-15 21:17:07 +00:00
|
|
|
|
|
|
|
AST_APP_OPTIONS(switch_opts, {
|
|
|
|
AST_APP_OPTION('p', OPTION_PATTERNS_DISABLED),
|
|
|
|
});
|
|
|
|
|
2010-05-27 19:25:16 +00:00
|
|
|
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);
|
|
|
|
}
|
2010-05-27 20:08:49 +00:00
|
|
|
|
|
|
|
return NULL;
|
2010-05-27 19:25:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 16:47:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2010-05-27 19:25:16 +00:00
|
|
|
|
2004-11-22 03:25:27 +00:00
|
|
|
/* Realtime switch looks up extensions in the supplied realtime table.
|
|
|
|
|
|
|
|
[context@][realtimetable][/options]
|
|
|
|
|
2017-12-22 14:23:22 +00:00
|
|
|
If the realtimetable is omitted it is assumed to be "extensions". If no context is
|
2004-11-22 03:25:27 +00:00
|
|
|
specified the context is assumed to be whatever is the container.
|
|
|
|
|
|
|
|
The realtime table should have entries for context,exten,priority,app,args
|
2017-12-22 14:23:22 +00:00
|
|
|
|
2004-11-24 03:07:08 +00:00
|
|
|
The realtime table currently does not support callerid fields.
|
2004-11-22 03:25:27 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-15 21:17:07 +00:00
|
|
|
static struct ast_variable *realtime_switch_common(const char *table, const char *context, const char *exten, int priority, int mode, struct ast_flags flags)
|
2004-11-22 03:25:27 +00:00
|
|
|
{
|
|
|
|
struct ast_variable *var;
|
2004-11-24 03:07:08 +00:00
|
|
|
struct ast_config *cfg;
|
2004-11-22 03:25:27 +00:00
|
|
|
char pri[20];
|
2004-11-22 18:39:40 +00:00
|
|
|
char *ematch;
|
|
|
|
char rexten[AST_MAX_EXTENSION + 20]="";
|
2004-11-24 03:07:08 +00:00
|
|
|
int match;
|
2008-11-25 18:01:02 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
2004-11-22 03:25:27 +00:00
|
|
|
snprintf(pri, sizeof(pri), "%d", priority);
|
2004-11-22 18:39:40 +00:00
|
|
|
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";
|
2006-10-25 14:44:50 +00:00
|
|
|
ast_copy_string(rexten, exten, sizeof(rexten));
|
2004-11-22 18:39:40 +00:00
|
|
|
}
|
2008-06-19 20:48:33 +00:00
|
|
|
var = ast_load_realtime(table, ematch, rexten, "context", context, "priority", pri, SENTINEL);
|
2008-12-15 21:17:07 +00:00
|
|
|
if (!var && !ast_test_flag(&flags, OPTION_PATTERNS_DISABLED)) {
|
2017-12-22 14:23:22 +00:00
|
|
|
cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, SENTINEL);
|
2004-11-24 03:07:08 +00:00
|
|
|
if (cfg) {
|
2017-02-21 16:47:28 +00:00
|
|
|
char *cat = NULL;
|
|
|
|
|
2017-02-21 16:47:41 +00:00
|
|
|
/* Sort so that longer patterns are checked first */
|
|
|
|
ast_config_sort_categories(cfg, 1, extension_length_comparator);
|
|
|
|
|
2017-02-21 16:47:28 +00:00
|
|
|
while ((cat = ast_category_browse(cfg, cat))) {
|
|
|
|
const char *realtime_exten = ast_variable_retrieve(cfg, cat, "exten");
|
2005-01-25 06:10:20 +00:00
|
|
|
|
2004-11-24 03:07:08 +00:00
|
|
|
switch(mode) {
|
|
|
|
case MODE_MATCHMORE:
|
2017-02-21 16:47:28 +00:00
|
|
|
match = ast_extension_close(realtime_exten, exten, 1);
|
2004-11-24 03:07:08 +00:00
|
|
|
break;
|
|
|
|
case MODE_CANMATCH:
|
2017-02-21 16:47:28 +00:00
|
|
|
match = ast_extension_close(realtime_exten, exten, 0);
|
2004-11-24 03:07:08 +00:00
|
|
|
break;
|
|
|
|
case MODE_MATCH:
|
|
|
|
default:
|
2017-02-21 16:47:28 +00:00
|
|
|
match = ast_extension_match(realtime_exten, exten);
|
2004-11-24 03:07:08 +00:00
|
|
|
}
|
|
|
|
if (match) {
|
2014-10-13 16:12:17 +00:00
|
|
|
var = ast_category_detach_variables(ast_category_get(cfg, cat, NULL));
|
2004-11-24 03:07:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_config_destroy(cfg);
|
2004-11-24 03:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-22 03:25:27 +00:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:55:25 +00:00
|
|
|
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;
|
2008-12-15 21:17:07 +00:00
|
|
|
struct ast_flags flags = { 0, };
|
2010-05-27 19:25:16 +00:00
|
|
|
struct cache_entry *ce;
|
|
|
|
struct {
|
|
|
|
struct cache_entry ce;
|
|
|
|
char exten[AST_MAX_EXTENSION];
|
|
|
|
} cache_search = { { .priority = priority, .context = (char *) context }, };
|
2006-05-10 21:55:25 +00:00
|
|
|
char *buf = ast_strdupa(data);
|
2012-07-31 20:21:43 +00:00
|
|
|
/* "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);
|
2010-05-27 19:25:16 +00:00
|
|
|
ao2_ref(ce, -1);
|
2012-07-31 20:21:43 +00:00
|
|
|
} while (0);
|
2006-05-10 21:55:25 +00:00
|
|
|
}
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2004-11-22 03:25:27 +00:00
|
|
|
static int realtime_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
|
|
|
|
{
|
2006-05-10 21:55:25 +00:00
|
|
|
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
|
|
|
|
if (var) {
|
2006-05-10 21:12:55 +00:00
|
|
|
ast_variables_destroy(var);
|
2006-05-10 21:55:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int realtime_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
|
|
|
|
{
|
2006-05-10 21:55:25 +00:00
|
|
|
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_CANMATCH);
|
|
|
|
if (var) {
|
2006-05-10 21:12:55 +00:00
|
|
|
ast_variables_destroy(var);
|
2006-05-10 21:55:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
|
|
|
|
2006-03-30 21:29:39 +00:00
|
|
|
static int realtime_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
|
2004-11-22 03:25:27 +00:00
|
|
|
{
|
2006-05-10 21:55:25 +00:00
|
|
|
int res = -1;
|
|
|
|
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCH);
|
|
|
|
|
2004-11-22 03:25:27 +00:00
|
|
|
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 = "";
|
2007-10-12 15:41:27 +00:00
|
|
|
char *app = NULL;
|
2006-05-10 21:55:25 +00:00
|
|
|
struct ast_variable *v;
|
|
|
|
|
2006-05-10 21:12:55 +00:00
|
|
|
for (v = var; v ; v = v->next) {
|
2004-11-22 03:25:27 +00:00
|
|
|
if (!strcasecmp(v->name, "app"))
|
2007-10-12 15:41:27 +00:00
|
|
|
app = ast_strdupa(v->value);
|
2008-05-22 21:42:50 +00:00
|
|
|
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);
|
2008-05-22 21:42:50 +00:00
|
|
|
}
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_variables_destroy(var);
|
2004-11-22 03:25:27 +00:00
|
|
|
if (!ast_strlen_zero(app)) {
|
2006-05-10 21:55:25 +00:00
|
|
|
struct ast_app *a = pbx_findapp(app);
|
2004-11-22 03:25:27 +00:00
|
|
|
if (a) {
|
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
|
|
|
char appdata[512];
|
2006-05-10 21:55:25 +00:00
|
|
|
char tmp1[80];
|
|
|
|
char tmp2[80];
|
|
|
|
char tmp3[EXT_DATA_SIZE];
|
2013-03-22 14:06:46 +00:00
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
2006-05-10 21:55:25 +00:00
|
|
|
|
2007-11-12 18:44:36 +00:00
|
|
|
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);
|
2010-08-27 21:50:15 +00:00
|
|
|
ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_exten(chan), ast_channel_context(chan), ast_channel_priority(chan),
|
2006-05-10 21:55:25 +00:00
|
|
|
term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
|
2012-01-09 22:15:50 +00:00
|
|
|
term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
|
2006-05-10 21:55:25 +00:00
|
|
|
term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
|
2014-08-06 12:55:28 +00:00
|
|
|
if (ast_channel_snapshot_type()) {
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
snapshot = ast_channel_snapshot_create(chan);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
}
|
2013-03-22 14:06:46 +00:00
|
|
|
if (snapshot) {
|
|
|
|
/* pbx_exec sets application name and data, but we don't want to log
|
|
|
|
* every exec. Just update the snapshot here instead.
|
|
|
|
*/
|
|
|
|
ast_string_field_set(snapshot, appl, app);
|
|
|
|
ast_string_field_set(snapshot, data, !ast_strlen_zero(appdata) ? appdata : "(NULL)");
|
2013-03-28 15:45:18 +00:00
|
|
|
msg = stasis_message_create(ast_channel_snapshot_type(), snapshot);
|
2013-03-22 14:06:46 +00:00
|
|
|
if (msg) {
|
|
|
|
stasis_publish(ast_channel_topic(chan), msg);
|
|
|
|
}
|
|
|
|
}
|
2006-03-30 21:29:39 +00:00
|
|
|
res = pbx_exec(chan, a, appdata);
|
2004-11-22 03:25:27 +00:00
|
|
|
} else
|
|
|
|
ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
|
2007-10-12 15:41:27 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "No application specified for realtime extension '%s' in context '%s'\n", exten, context);
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int realtime_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
|
|
|
|
{
|
2006-05-10 21:55:25 +00:00
|
|
|
struct ast_variable *var = realtime_common(context, exten, priority, data, MODE_MATCHMORE);
|
|
|
|
if (var) {
|
2006-03-31 09:53:05 +00:00
|
|
|
ast_variables_destroy(var);
|
2006-05-10 21:55:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_switch realtime_switch =
|
|
|
|
{
|
2012-04-04 18:08:28 +00:00
|
|
|
.name = "Realtime",
|
|
|
|
.description = "Realtime Dialplan Switch",
|
|
|
|
.exists = realtime_exists,
|
|
|
|
.canmatch = realtime_canmatch,
|
|
|
|
.exec = realtime_exec,
|
|
|
|
.matchmore = realtime_matchmore,
|
2004-11-22 03:25:27 +00:00
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2004-11-22 03:25:27 +00:00
|
|
|
{
|
|
|
|
ast_unregister_switch(&realtime_switch);
|
2010-05-27 19:25:16 +00:00
|
|
|
pthread_cancel(cleanup_thread);
|
|
|
|
pthread_kill(cleanup_thread, SIGURG);
|
|
|
|
pthread_join(cleanup_thread, NULL);
|
|
|
|
/* Destroy all remaining entries */
|
|
|
|
ao2_ref(cache, -1);
|
2004-11-22 03:25:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2004-11-22 03:25:27 +00:00
|
|
|
{
|
2010-05-27 19:25:16 +00:00
|
|
|
if (!(cache = ao2_container_alloc(573, cache_hash, cache_cmp))) {
|
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_pthread_create(&cleanup_thread, NULL, cleanup, NULL)) {
|
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-12-26 20:02:27 +00:00
|
|
|
if (ast_register_switch(&realtime_switch))
|
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2004-11-22 03:25:27 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 16:47:17 +00:00
|
|
|
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Realtime Switch");
|