Sat Aug 6 00:39:37 2011

Asterisk developer's documentation


app_stack.c File Reference

Stack applications Gosub, Return, etc. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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"

Go to the source code of this file.

Defines

#define STACKVAR   "~GOSUB~STACK~"

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int gosub_exec (struct ast_channel *chan, void *data)
static int gosubif_exec (struct ast_channel *chan, void *data)
static int load_module (void)
static int pop_exec (struct ast_channel *chan, void *data)
static int return_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Stack Routines" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static const char * app_gosub = "Gosub"
static const char * app_gosubif = "GosubIf"
static const char * app_pop = "StackPop"
static const char * app_return = "Return"
static const struct ast_module_infoast_module_info = &__mod_info
static const char * gosub_descrip
static const char * gosub_synopsis = "Jump to label, saving return address"
static const char * gosubif_descrip
static const char * gosubif_synopsis = "Conditionally jump to label, saving return address"
static const char * pop_descrip
static const char * pop_synopsis = "Remove one address from gosub stack"
static const char * return_descrip
static const char * return_synopsis = "Return from gosub routine"


Detailed Description

Stack applications Gosub, Return, etc.

Author:
Tilghman Lesher <app_stack_v002@the-tilghman.com>

Definition in file app_stack.c.


Define Documentation

#define STACKVAR   "~GOSUB~STACK~"

Definition at line 45 of file app_stack.c.

Referenced by gosub_exec(), pop_exec(), and return_exec().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 174 of file app_stack.c.

static void __unreg_module ( void   )  [static]

Definition at line 174 of file app_stack.c.

static int gosub_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 97 of file app_stack.c.

References ast_log(), AST_MAX_EXTENSION, ast_module_user_add, ast_module_user_remove, ast_parseable_goto(), ast_strlen_zero(), ast_module_user::chan, ast_channel::context, ast_channel::exten, LOG_ERROR, pbx_builtin_pushvar_helper(), ast_channel::priority, and STACKVAR.

Referenced by gosubif_exec(), and load_module().

00098 {
00099    char newlabel[AST_MAX_EXTENSION * 2 + 3 + 11];
00100    struct ast_module_user *u;
00101 
00102    if (ast_strlen_zero(data)) {
00103       ast_log(LOG_ERROR, "%s requires an argument: %s([[context|]exten|]priority)\n", app_gosub, app_gosub);
00104       return -1;
00105    }
00106 
00107    u = ast_module_user_add(chan);
00108    snprintf(newlabel, sizeof(newlabel), "%s|%s|%d", chan->context, chan->exten, chan->priority + 1);
00109 
00110    if (ast_parseable_goto(chan, data)) {
00111       ast_module_user_remove(u);
00112       return -1;
00113    }
00114 
00115    pbx_builtin_pushvar_helper(chan, STACKVAR, newlabel);
00116    ast_module_user_remove(u);
00117 
00118    return 0;
00119 }

static int gosubif_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 121 of file app_stack.c.

References ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, ast_strlen_zero(), ast_module_user::chan, gosub_exec(), LOG_WARNING, and pbx_checkcondition().

Referenced by load_module().

00122 {
00123    struct ast_module_user *u;
00124    char *condition="", *label1, *label2, *args;
00125    int res=0;
00126 
00127    if (ast_strlen_zero(data)) {
00128       ast_log(LOG_WARNING, "GosubIf requires an argument\n");
00129       return 0;
00130    }
00131 
00132    args = ast_strdupa(data);
00133 
00134    u = ast_module_user_add(chan);
00135 
00136    condition = strsep(&args, "?");
00137    label1 = strsep(&args, ":");
00138    label2 = args;
00139 
00140    if (pbx_checkcondition(condition)) {
00141       if (!ast_strlen_zero(label1)) {
00142          res = gosub_exec(chan, label1);
00143       }
00144    } else if (!ast_strlen_zero(label2)) {
00145       res = gosub_exec(chan, label2);
00146    }
00147 
00148    ast_module_user_remove(u);
00149    return res;
00150 }

static int load_module ( void   )  [static]

Definition at line 164 of file app_stack.c.

References ast_register_application(), gosub_exec(), gosubif_exec(), pop_exec(), and return_exec().

static int pop_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 74 of file app_stack.c.

References pbx_builtin_setvar_helper(), and STACKVAR.

Referenced by load_module().

00075 {
00076    pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
00077 
00078    return 0;
00079 }

static int return_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 81 of file app_stack.c.

References ast_log(), ast_parseable_goto(), ast_strlen_zero(), LOG_ERROR, LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and STACKVAR.

Referenced by load_module().

00082 {
00083    const char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
00084 
00085    if (ast_strlen_zero(label)) {
00086       ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");
00087       return -1;
00088    } else if (ast_parseable_goto(chan, label)) {
00089       ast_log(LOG_WARNING, "No next statement after Gosub?\n");
00090       return -1;
00091    }
00092 
00093    pbx_builtin_setvar_helper(chan, STACKVAR, NULL);
00094    return 0;
00095 }

static int unload_module ( void   )  [static]

Definition at line 152 of file app_stack.c.

References ast_module_user_hangup_all, and ast_unregister_application().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Stack Routines" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 174 of file app_stack.c.

const char* app_gosub = "Gosub" [static]

Definition at line 48 of file app_stack.c.

const char* app_gosubif = "GosubIf" [static]

Definition at line 49 of file app_stack.c.

const char* app_pop = "StackPop" [static]

Definition at line 51 of file app_stack.c.

const char* app_return = "Return" [static]

Definition at line 50 of file app_stack.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 174 of file app_stack.c.

const char* gosub_descrip [static]

Initial value:

"Gosub([[context|]exten|]priority)\n"
"  Jumps to the label specified, saving the return address.\n"

Definition at line 58 of file app_stack.c.

const char* gosub_synopsis = "Jump to label, saving return address" [static]

Definition at line 53 of file app_stack.c.

const char* gosubif_descrip [static]

Initial value:

"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"

Definition at line 61 of file app_stack.c.

const char* gosubif_synopsis = "Conditionally jump to label, saving return address" [static]

Definition at line 54 of file app_stack.c.

const char* pop_descrip [static]

Initial value:

"StackPop()\n"
"  Removes last label on the stack, discarding it.\n"

Definition at line 69 of file app_stack.c.

const char* pop_synopsis = "Remove one address from gosub stack" [static]

Definition at line 56 of file app_stack.c.

const char* return_descrip [static]

Initial value:

"Return()\n"
"  Jumps to the last label on the stack, removing it.\n"

Definition at line 66 of file app_stack.c.

const char* return_synopsis = "Return from gosub routine" [static]

Definition at line 55 of file app_stack.c.


Generated on Sat Aug 6 00:39:37 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7