#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"
Include dependency graph for app_stack.c:
Go to the source code of this file.
Defines | |
#define | STACKVAR "~GOSUB~STACK~" |
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Stack Routines") | |
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 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 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" |
Definition in file app_stack.c.
#define STACKVAR "~GOSUB~STACK~" |
Definition at line 45 of file app_stack.c.
Referenced by gosub_exec(), pop_exec(), and return_exec().
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Stack Routines" | ||||
) |
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, pbx_checkcondition(), and strsep().
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().
00165 { 00166 ast_register_application(app_pop, pop_exec, pop_synopsis, pop_descrip); 00167 ast_register_application(app_return, return_exec, return_synopsis, return_descrip); 00168 ast_register_application(app_gosubif, gosubif_exec, gosubif_synopsis, gosubif_descrip); 00169 ast_register_application(app_gosub, gosub_exec, gosub_synopsis, gosub_descrip); 00170 00171 return 0; 00172 }
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().
00153 { 00154 ast_unregister_application(app_return); 00155 ast_unregister_application(app_pop); 00156 ast_unregister_application(app_gosubif); 00157 ast_unregister_application(app_gosub); 00158 00159 ast_module_user_hangup_all(); 00160 00161 return 0; 00162 }
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 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.