![rizzo](/assets/img/avatar_default.png)
As partly documented in loader.c and include/asterisk/module.h, modules are now expected to return all of their methods and flags into a structure 'mod_data', and are normally loaded with RTLD_NOW | RTLD_LOCAL, so symbols are resolved immediately and conflicts should be less likely. Only in a small number of cases (res_*, typically) modules are loaded RTLD_GLOBAL, so they can export symbols. The core of the change is only the two files loader.c and include/asterisk/module.h, all the rest is simply adaptation of the existing modules to the new API, a rather mechanical (but believe me, time and finger-consuming!) process whose detail you can figure out by svn diff'ing any single module. Expect some minor compilation issue after this change, please report it on mantis http://bugs.digium.com/view.php?id=6968 so we collect all the feedback in one place. I am just sorry that this change missed SVN version number 20000! git-svn-id: http://svn.digium.com/svn/asterisk/trunk@20003 f38db490-d61c-443f-a65b-d21fe96a405b
187 lines
4.7 KiB
C
187 lines
4.7 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (c) 2004-2006 Tilghman Lesher <app_stack_v002@the-tilghman.com>.
|
|
*
|
|
* This code is released by the author with no restrictions on usage.
|
|
*
|
|
* 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 Stack applications Gosub, Return, etc.
|
|
*
|
|
* \author Tilghman Lesher <app_stack_v002@the-tilghman.com>
|
|
*
|
|
* \ingroup applications
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
#include "asterisk.h"
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
#include "asterisk/options.h"
|
|
#include "asterisk/logger.h"
|
|
#include "asterisk/channel.h"
|
|
#include "asterisk/chanvars.h"
|
|
#include "asterisk/pbx.h"
|
|
#include "asterisk/module.h"
|
|
#include "asterisk/config.h"
|
|
|
|
#define STACKVAR "~GOSUB~STACK~"
|
|
|
|
|
|
static const char *app_gosub = "Gosub";
|
|
static const char *app_gosubif = "GosubIf";
|
|
static const char *app_return = "Return";
|
|
static const char *app_pop = "StackPop";
|
|
|
|
static const char *gosub_synopsis = "Jump to label, saving return address";
|
|
static const char *gosubif_synopsis = "Jump to label, saving return address";
|
|
static const char *return_synopsis = "Return from gosub routine";
|
|
static const char *pop_synopsis = "Remove one address from gosub stack";
|
|
|
|
static const char *gosub_descrip =
|
|
"Gosub([[context|]exten|]priority)\n"
|
|
" Jumps to the label specified, saving the return address.\n";
|
|
static const char *gosubif_descrip =
|
|
"GosubIf(condition?labeliftrue[:labeliffalse])\n"
|
|
" If the condition is true, then jump to labeliftrue. If false, jumps to\n"
|
|
"labeliffalse, if specified. In either case, a jump saves the return point\n"
|
|
"in the dialplan, to be returned to with a Return.\n";
|
|
static const char *return_descrip =
|
|
"Return()\n"
|
|
" Jumps to the last label on the stack, removing it.\n";
|
|
static const char *pop_descrip =
|
|
"StackPop()\n"
|
|
" Removes last label on the stack, discarding it.\n";
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
static int pop_exec(struct ast_channel *chan, void *data)
|
|
{
|
|
pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int return_exec(struct ast_channel *chan, void *data)
|
|
{
|
|
const char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
|
|
|
|
if (ast_strlen_zero(label)) {
|
|
ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");
|
|
return -1;
|
|
} else if (ast_parseable_goto(chan, label)) {
|
|
ast_log(LOG_WARNING, "No next statement after Gosub?\n");
|
|
return -1;
|
|
}
|
|
|
|
pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
|
|
return 0;
|
|
}
|
|
|
|
static int gosub_exec(struct ast_channel *chan, void *data)
|
|
{
|
|
char newlabel[AST_MAX_EXTENSION * 2 + 3 + 11];
|
|
struct localuser *u;
|
|
|
|
if (ast_strlen_zero(data)) {
|
|
ast_log(LOG_ERROR, "%s requires an argument: %s([[context|]exten|]priority)\n", app_gosub, app_gosub);
|
|
return -1;
|
|
}
|
|
|
|
LOCAL_USER_ADD(u);
|
|
snprintf(newlabel, sizeof(newlabel), "%s|%s|%d", chan->context, chan->exten, chan->priority + 1);
|
|
|
|
if (ast_parseable_goto(chan, data)) {
|
|
LOCAL_USER_REMOVE(u);
|
|
return -1;
|
|
}
|
|
|
|
pbx_builtin_pushvar_helper(chan, STACKVAR, newlabel);
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int gosubif_exec(struct ast_channel *chan, void *data)
|
|
{
|
|
struct localuser *u;
|
|
char *condition="", *label1, *label2, *args;
|
|
int res=0;
|
|
|
|
if (ast_strlen_zero(data)) {
|
|
ast_log(LOG_WARNING, "GosubIf requires an argument\n");
|
|
return 0;
|
|
}
|
|
|
|
if (!(args = ast_strdupa(data)))
|
|
return -1;
|
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
condition = strsep(&args, "?");
|
|
label1 = strsep(&args, ":");
|
|
label2 = args;
|
|
|
|
if (pbx_checkcondition(condition)) {
|
|
if (label1) {
|
|
res = gosub_exec(chan, label1);
|
|
}
|
|
} else if (label2) {
|
|
res = gosub_exec(chan, label2);
|
|
}
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
return res;
|
|
}
|
|
|
|
static int unload_module(void *mod)
|
|
{
|
|
ast_unregister_application(app_return);
|
|
ast_unregister_application(app_pop);
|
|
ast_unregister_application(app_gosubif);
|
|
ast_unregister_application(app_gosub);
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int load_module(void *mod)
|
|
{
|
|
ast_register_application(app_pop, pop_exec, pop_synopsis, pop_descrip);
|
|
ast_register_application(app_return, return_exec, return_synopsis, return_descrip);
|
|
ast_register_application(app_gosubif, gosubif_exec, gosubif_synopsis, gosubif_descrip);
|
|
ast_register_application(app_gosub, gosub_exec, gosub_synopsis, gosub_descrip);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const char *description(void)
|
|
{
|
|
return "Stack Routines";
|
|
}
|
|
|
|
static const char *key(void)
|
|
{
|
|
return ASTERISK_GPL_KEY;
|
|
}
|
|
|
|
STD_MOD1;
|