Fri Jul 3 20:36:14 2009

Asterisk developer's documentation


app_macro.c File Reference

Dial plan macro Implementation. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"

Include dependency graph for app_macro.c:

Go to the source code of this file.

Defines

#define MACRO_EXIT_RESULT   1024
#define MAX_ARGS   80

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int _macro_exec (struct ast_channel *chan, void *data, int exclusive)
static struct ast_exten * find_matching_priority (struct ast_context *c, const char *exten, int priority, const char *callerid)
static int load_module (void)
static int macro_exec (struct ast_channel *chan, void *data)
static int macro_exit_exec (struct ast_channel *chan, void *data)
static void macro_fixup (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
static int macroexclusive_exec (struct ast_channel *chan, void *data)
static int macroif_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 = "Extension Macros" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static char * app = "Macro"
static const struct
ast_module_info * 
ast_module_info = &__mod_info
static char * descrip
static char * exclusive_app = "MacroExclusive"
static char * exclusive_descrip
static char * exclusive_synopsis = "Exclusive Macro Implementation"
static char * exit_app = "MacroExit"
static char * exit_descrip
static char * exit_synopsis = "Exit From Macro"
static char * if_app = "MacroIf"
static char * if_descrip
static char * if_synopsis = "Conditional Macro Implementation"
struct ast_datastore_info macro_ds_info
static char * synopsis = "Macro Implementation"


Detailed Description

Dial plan macro Implementation.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_macro.c.


Define Documentation

#define MACRO_EXIT_RESULT   1024

Definition at line 51 of file app_macro.c.

Referenced by _macro_exec(), and macro_exit_exec().

#define MAX_ARGS   80

Definition at line 48 of file app_macro.c.

Referenced by _macro_exec(), agi_exec_full(), agi_handle_command(), and parse_args().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 594 of file app_macro.c.

static void __unreg_module ( void   )  [static]

Definition at line 594 of file app_macro.c.

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

Definition at line 168 of file app_macro.c.

References ast_channel::_softhangup, app2, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_datastore_add(), ast_channel_datastore_alloc(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_context_find(), ast_context_lockmacro(), ast_context_unlockmacro(), ast_copy_string(), ast_exists_extension(), AST_FLAG_IN_AUTOLOOP, ast_get_context_name(), ast_get_extension_app(), ast_get_extension_app_data(), ast_lock_context(), ast_log(), AST_MAX_CONTEXT, ast_module_user_add, ast_module_user_remove, AST_PBX_KEEPALIVE, ast_rdlock_contexts(), ast_set2_flag, ast_set_flag, AST_SOFTHANGUP_ASYNCGOTO, ast_spawn_extension(), ast_strdup, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_unlock_context(), ast_unlock_contexts(), ast_verbose(), ast_walk_contexts(), ast_channel::cid, ast_callerid::cid_num, cond, ast_channel::context, DATASTORE_INHERIT_FOREVER, ast_channel::exten, find_matching_priority(), free, ast_datastore::inheritance, LOG_DEBUG, LOG_ERROR, LOG_WARNING, MACRO_EXIT_RESULT, ast_channel::macrocontext, ast_channel::macroexten, ast_channel::macropriority, MAX_ARGS, ast_channel::name, offset, option_debug, option_verbose, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_checkcondition(), pbx_substitute_variables_helper(), ast_channel::priority, s, and VERBOSE_PREFIX_2.

Referenced by macro_exec(), and macroexclusive_exec().

00169 {
00170    const char *s;
00171    char *tmp;
00172    char *cur, *rest;
00173    char *macro;
00174    char fullmacro[80];
00175    char varname[80];
00176    char runningapp[80], runningdata[1024];
00177    char *oldargs[MAX_ARGS + 1] = { NULL, };
00178    int argc, x;
00179    int res=0;
00180    char oldexten[256]="";
00181    int oldpriority, gosub_level = 0;
00182    char pc[80], depthc[12];
00183    char oldcontext[AST_MAX_CONTEXT] = "";
00184    const char *inhangupc;
00185    int offset, depth = 0, maxdepth = 7;
00186    int setmacrocontext=0;
00187    int autoloopflag, inhangup = 0;
00188   
00189    char *save_macro_exten;
00190    char *save_macro_context;
00191    char *save_macro_priority;
00192    char *save_macro_offset;
00193    struct ast_module_user *u;
00194    struct ast_datastore *macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);
00195  
00196    if (ast_strlen_zero(data)) {
00197       ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n");
00198       return -1;
00199    }
00200 
00201    u = ast_module_user_add(chan);
00202 
00203    do {
00204       if (macro_store) {
00205          break;
00206       }
00207       if (!(macro_store = ast_channel_datastore_alloc(&macro_ds_info, NULL))) {
00208          ast_log(LOG_WARNING, "Unable to allocate new datastore.\n");
00209          break;
00210       }
00211       /* Just the existence of this datastore is enough. */
00212       macro_store->inheritance = DATASTORE_INHERIT_FOREVER;
00213       ast_channel_datastore_add(chan, macro_store);
00214    } while (0);
00215 
00216    /* does the user want a deeper rabbit hole? */
00217    s = pbx_builtin_getvar_helper(chan, "MACRO_RECURSION");
00218    if (s)
00219       sscanf(s, "%d", &maxdepth);
00220 
00221    /* Count how many levels deep the rabbit hole goes */
00222    s = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
00223    if (s)
00224       sscanf(s, "%d", &depth);
00225    /* Used for detecting whether to return when a Macro is called from another Macro after hangup */
00226    if (strcmp(chan->exten, "h") == 0)
00227       pbx_builtin_setvar_helper(chan, "MACRO_IN_HANGUP", "1");
00228    inhangupc = pbx_builtin_getvar_helper(chan, "MACRO_IN_HANGUP");
00229    if (!ast_strlen_zero(inhangupc))
00230       sscanf(inhangupc, "%d", &inhangup);
00231 
00232    if (depth >= maxdepth) {
00233       ast_log(LOG_ERROR, "Macro():  possible infinite loop detected.  Returning early.\n");
00234       ast_module_user_remove(u);
00235       return 0;
00236    }
00237    snprintf(depthc, sizeof(depthc), "%d", depth + 1);
00238    pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
00239 
00240    tmp = ast_strdupa(data);
00241    rest = tmp;
00242    macro = strsep(&rest, "|");
00243    if (ast_strlen_zero(macro)) {
00244       ast_log(LOG_WARNING, "Invalid macro name specified\n");
00245       ast_module_user_remove(u);
00246       return 0;
00247    }
00248 
00249    snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro);
00250    if (!ast_exists_extension(chan, fullmacro, "s", 1, chan->cid.cid_num)) {
00251       if (!ast_context_find(fullmacro)) 
00252          ast_log(LOG_WARNING, "No such context '%s' for macro '%s'\n", fullmacro, macro);
00253       else
00254          ast_log(LOG_WARNING, "Context '%s' for macro '%s' lacks 's' extension, priority 1\n", fullmacro, macro);
00255       ast_module_user_remove(u);
00256       return 0;
00257    }
00258 
00259    /* If we are to run the macro exclusively, take the mutex */
00260    if (exclusive) {
00261       ast_log(LOG_DEBUG, "Locking macrolock for '%s'\n", fullmacro);
00262       ast_autoservice_start(chan);
00263       if (ast_context_lockmacro(fullmacro)) {
00264          ast_log(LOG_WARNING, "Failed to lock macro '%s' as in-use\n", fullmacro);
00265          ast_autoservice_stop(chan);
00266          ast_module_user_remove(u);
00267 
00268          return 0;
00269       }
00270       ast_autoservice_stop(chan);
00271    }
00272    
00273    /* Save old info */
00274    oldpriority = chan->priority;
00275    ast_copy_string(oldexten, chan->exten, sizeof(oldexten));
00276    ast_copy_string(oldcontext, chan->context, sizeof(oldcontext));
00277    if (ast_strlen_zero(chan->macrocontext)) {
00278       ast_copy_string(chan->macrocontext, chan->context, sizeof(chan->macrocontext));
00279       ast_copy_string(chan->macroexten, chan->exten, sizeof(chan->macroexten));
00280       chan->macropriority = chan->priority;
00281       setmacrocontext=1;
00282    }
00283    argc = 1;
00284    /* Save old macro variables */
00285    save_macro_exten = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_EXTEN"));
00286    pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten);
00287 
00288    save_macro_context = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"));
00289    pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext);
00290 
00291    save_macro_priority = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY"));
00292    snprintf(pc, sizeof(pc), "%d", oldpriority);
00293    pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc);
00294   
00295    save_macro_offset = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"));
00296    pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
00297 
00298    /* Setup environment for new run */
00299    chan->exten[0] = 's';
00300    chan->exten[1] = '\0';
00301    ast_copy_string(chan->context, fullmacro, sizeof(chan->context));
00302    chan->priority = 1;
00303 
00304    while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) {
00305       const char *s;
00306       /* Save copy of old arguments if we're overwriting some, otherwise
00307          let them pass through to the other macro */
00308       snprintf(varname, sizeof(varname), "ARG%d", argc);
00309       s = pbx_builtin_getvar_helper(chan, varname);
00310       if (s)
00311          oldargs[argc] = ast_strdup(s);
00312       pbx_builtin_setvar_helper(chan, varname, cur);
00313       argc++;
00314    }
00315    autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
00316    ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
00317    while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
00318       struct ast_context *c;
00319       struct ast_exten *e;
00320       runningapp[0] = '\0';
00321       runningdata[0] = '\0';
00322 
00323       /* What application will execute? */
00324       if (ast_rdlock_contexts()) {
00325          ast_log(LOG_WARNING, "Failed to lock contexts list\n");
00326       } else {
00327          for (c = ast_walk_contexts(NULL), e = NULL; c; c = ast_walk_contexts(c)) {
00328             if (!strcmp(ast_get_context_name(c), chan->context)) {
00329                if (ast_lock_context(c)) {
00330                   ast_log(LOG_WARNING, "Unable to lock context?\n");
00331                } else {
00332                   e = find_matching_priority(c, chan->exten, chan->priority, chan->cid.cid_num);
00333                   if (e) { /* This will only be undefined for pbx_realtime, which is majorly broken. */
00334                      ast_copy_string(runningapp, ast_get_extension_app(e), sizeof(runningapp));
00335                      ast_copy_string(runningdata, ast_get_extension_app_data(e), sizeof(runningdata));
00336                   }
00337                   ast_unlock_context(c);
00338                }
00339                break;
00340             }
00341          }
00342       }
00343       ast_unlock_contexts();
00344 
00345       /* Reset the macro depth, if it was changed in the last iteration */
00346       pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
00347 
00348       if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) {
00349          /* Something bad happened, or a hangup has been requested. */
00350          if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
00351             (res == '*') || (res == '#')) {
00352             /* Just return result as to the previous application as if it had been dialed */
00353             ast_log(LOG_DEBUG, "Oooh, got something to jump out with ('%c')!\n", res);
00354             break;
00355          }
00356          switch(res) {
00357          case MACRO_EXIT_RESULT:
00358             res = 0;
00359             goto out;
00360          case AST_PBX_KEEPALIVE:
00361             if (option_debug)
00362                ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited KEEPALIVE in macro %s on '%s'\n", chan->context, chan->exten, chan->priority, macro, chan->name);
00363             else if (option_verbose > 1)
00364                ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE in macro '%s' on '%s'\n", chan->context, chan->exten, chan->priority, macro, chan->name);
00365             goto out;
00366          default:
00367             if (option_debug)
00368                ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro);
00369             else if (option_verbose > 1)
00370                ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s' in macro '%s'\n", chan->context, chan->exten, chan->priority, chan->name, macro);
00371             goto out;
00372          }
00373       }
00374 
00375       ast_log(LOG_DEBUG, "Executed application: %s\n", runningapp);
00376 
00377       if (!strcasecmp(runningapp, "GOSUB")) {
00378          gosub_level++;
00379          ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
00380       } else if (!strcasecmp(runningapp, "GOSUBIF")) {
00381          char tmp2[1024] = "", *cond, *app, *app2 = tmp2;
00382          pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
00383          cond = strsep(&app2, "?");
00384          app = strsep(&app2, ":");
00385          if (pbx_checkcondition(cond)) {
00386             if (!ast_strlen_zero(app)) {
00387                gosub_level++;
00388                ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
00389             }
00390          } else {
00391             if (!ast_strlen_zero(app2)) {
00392                gosub_level++;
00393                ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
00394             }
00395          }
00396       } else if (!strcasecmp(runningapp, "RETURN")) {
00397          gosub_level--;
00398          ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
00399       } else if (!strcasecmp(runningapp, "STACKPOP")) {
00400          gosub_level--;
00401          ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
00402       } else if (!strncasecmp(runningapp, "EXEC", 4)) {
00403          /* Must evaluate args to find actual app */
00404          char tmp2[1024] = "", *tmp3 = NULL;
00405          pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
00406          if (!strcasecmp(runningapp, "EXECIF")) {
00407             tmp3 = strchr(tmp2, '|');
00408             if (tmp3)
00409                *tmp3++ = '\0';
00410             if (!pbx_checkcondition(tmp2))
00411                tmp3 = NULL;
00412          } else
00413             tmp3 = tmp2;
00414 
00415          if (tmp3)
00416             ast_log(LOG_DEBUG, "Last app: %s\n", tmp3);
00417 
00418          if (tmp3 && !strncasecmp(tmp3, "GOSUB", 5)) {
00419             gosub_level++;
00420             ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
00421          } else if (tmp3 && !strncasecmp(tmp3, "RETURN", 6)) {
00422             gosub_level--;
00423             ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
00424          } else if (tmp3 && !strncasecmp(tmp3, "STACKPOP", 8)) {
00425             gosub_level--;
00426             ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
00427          }
00428       }
00429 
00430       if (gosub_level == 0 && strcasecmp(chan->context, fullmacro)) {
00431          if (option_verbose > 1)
00432             ast_verbose(VERBOSE_PREFIX_2 "Channel '%s' jumping out of macro '%s'\n", chan->name, macro);
00433          break;
00434       }
00435 
00436       /* don't stop executing extensions when we're in "h" */
00437       if (chan->_softhangup && !inhangup) {
00438          ast_log(LOG_DEBUG, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n",
00439             chan->exten, chan->macroexten, chan->priority);
00440          goto out;
00441       }
00442       chan->priority++;
00443    }
00444    out:
00445 
00446    /* Don't let the channel change now. */
00447    ast_channel_lock(chan);
00448 
00449    /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */
00450    snprintf(depthc, sizeof(depthc), "%d", depth);
00451    pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
00452    ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
00453 
00454    for (x = 1; x < argc; x++) {
00455       /* Restore old arguments and delete ours */
00456       snprintf(varname, sizeof(varname), "ARG%d", x);
00457       if (oldargs[x]) {
00458          pbx_builtin_setvar_helper(chan, varname, oldargs[x]);
00459          free(oldargs[x]);
00460       } else {
00461          pbx_builtin_setvar_helper(chan, varname, NULL);
00462       }
00463    }
00464 
00465    /* Restore macro variables */
00466    pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten);
00467    pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context);
00468    pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority);
00469    if (save_macro_exten)
00470       free(save_macro_exten);
00471    if (save_macro_context)
00472       free(save_macro_context);
00473    if (save_macro_priority)
00474       free(save_macro_priority);
00475 
00476    if (setmacrocontext) {
00477       chan->macrocontext[0] = '\0';
00478       chan->macroexten[0] = '\0';
00479       chan->macropriority = 0;
00480    }
00481 
00482    if (!strcasecmp(chan->context, fullmacro)) {
00483       /* If we're leaving the macro normally, restore original information */
00484       chan->priority = oldpriority;
00485       ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
00486       if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
00487          /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
00488          const char *offsets;
00489          ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
00490          if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
00491             /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
00492                normally if there is any problem */
00493             if (sscanf(offsets, "%d", &offset) == 1) {
00494                if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + offset + 1, chan->cid.cid_num)) {
00495                   chan->priority += offset;
00496                }
00497             }
00498          }
00499       }
00500    }
00501 
00502    pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset);
00503    if (save_macro_offset)
00504       free(save_macro_offset);
00505 
00506    /* Unlock the macro */
00507    if (exclusive) {
00508       ast_log(LOG_DEBUG, "Unlocking macrolock for '%s'\n", fullmacro);
00509       if (ast_context_unlockmacro(fullmacro)) {
00510          ast_log(LOG_ERROR, "Failed to unlock macro '%s' - that isn't good\n", fullmacro);
00511          res = 0;
00512       }
00513    }
00514    ast_channel_unlock(chan);
00515    
00516    ast_module_user_remove(u);
00517 
00518    return res;
00519 }

static struct ast_exten* find_matching_priority ( struct ast_context *  c,
const char *  exten,
int  priority,
const char *  callerid 
) [static, read]

Definition at line 133 of file app_macro.c.

References ast_extension_match(), ast_get_context_name(), ast_get_extension_cidmatch(), ast_get_extension_matchcid(), ast_get_extension_name(), ast_get_extension_priority(), ast_get_include_name(), ast_walk_context_extensions(), ast_walk_context_includes(), ast_walk_contexts(), and ast_walk_extension_priorities().

Referenced by _macro_exec().

00134 {
00135    struct ast_exten *e;
00136    struct ast_include *i;
00137    struct ast_context *c2;
00138 
00139    for (e=ast_walk_context_extensions(c, NULL); e; e=ast_walk_context_extensions(c, e)) {
00140       if (ast_extension_match(ast_get_extension_name(e), exten)) {
00141          int needmatch = ast_get_extension_matchcid(e);
00142          if ((needmatch && ast_extension_match(ast_get_extension_cidmatch(e), callerid)) ||
00143             (!needmatch)) {
00144             /* This is the matching extension we want */
00145             struct ast_exten *p;
00146             for (p=ast_walk_extension_priorities(e, NULL); p; p=ast_walk_extension_priorities(e, p)) {
00147                if (priority != ast_get_extension_priority(p))
00148                   continue;
00149                return p;
00150             }
00151          }
00152       }
00153    }
00154 
00155    /* No match; run through includes */
00156    for (i=ast_walk_context_includes(c, NULL); i; i=ast_walk_context_includes(c, i)) {
00157       for (c2=ast_walk_contexts(NULL); c2; c2=ast_walk_contexts(c2)) {
00158          if (!strcmp(ast_get_context_name(c2), ast_get_include_name(i))) {
00159             e = find_matching_priority(c2, exten, priority, callerid);
00160             if (e)
00161                return e;
00162          }
00163       }
00164    }
00165    return NULL;
00166 }

static int load_module ( void   )  [static]

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

Definition at line 521 of file app_macro.c.

References _macro_exec().

Referenced by load_module(), and macroif_exec().

00522 {
00523    return _macro_exec(chan, data, 0);
00524 }

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

Definition at line 563 of file app_macro.c.

References MACRO_EXIT_RESULT.

Referenced by load_module().

00564 {
00565    return MACRO_EXIT_RESULT;
00566 }

static void macro_fixup ( void *  data,
struct ast_channel *  old_chan,
struct ast_channel *  new_chan 
) [static]

Definition at line 115 of file app_macro.c.

References pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

00116 {
00117    int i;
00118    char varname[10];
00119    pbx_builtin_setvar_helper(new_chan, "MACRO_DEPTH", "0");
00120    pbx_builtin_setvar_helper(new_chan, "MACRO_CONTEXT", NULL);
00121    pbx_builtin_setvar_helper(new_chan, "MACRO_EXTEN", NULL);
00122    pbx_builtin_setvar_helper(new_chan, "MACRO_PRIORITY", NULL);
00123    pbx_builtin_setvar_helper(new_chan, "MACRO_OFFSET", NULL);
00124    for (i = 1; i < 100; i++) {
00125       snprintf(varname, sizeof(varname), "ARG%d", i);
00126       while (pbx_builtin_getvar_helper(new_chan, varname)) {
00127          /* Kill all levels of arguments */
00128          pbx_builtin_setvar_helper(new_chan, varname, NULL);
00129       }
00130    }
00131 }

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

Definition at line 526 of file app_macro.c.

References _macro_exec().

Referenced by load_module().

00527 {
00528    return _macro_exec(chan, data, 1);
00529 }

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

Definition at line 531 of file app_macro.c.

References ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, LOG_WARNING, macro_exec(), and pbx_checkcondition().

Referenced by load_module().

00532 {
00533    char *expr = NULL, *label_a = NULL, *label_b = NULL;
00534    int res = 0;
00535    struct ast_module_user *u;
00536 
00537    u = ast_module_user_add(chan);
00538 
00539    if (!(expr = ast_strdupa(data))) {
00540       ast_module_user_remove(u);
00541       return -1;
00542    }
00543 
00544    if ((label_a = strchr(expr, '?'))) {
00545       *label_a = '\0';
00546       label_a++;
00547       if ((label_b = strchr(label_a, ':'))) {
00548          *label_b = '\0';
00549          label_b++;
00550       }
00551       if (pbx_checkcondition(expr))
00552          res = macro_exec(chan, label_a);
00553       else if (label_b) 
00554          res = macro_exec(chan, label_b);
00555    } else
00556       ast_log(LOG_WARNING, "Invalid Syntax.\n");
00557 
00558    ast_module_user_remove(u);
00559 
00560    return res;
00561 }

static int unload_module ( void   )  [static]

Definition at line 568 of file app_macro.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00569 {
00570    int res;
00571 
00572    res = ast_unregister_application(if_app);
00573    res |= ast_unregister_application(exit_app);
00574    res |= ast_unregister_application(app);
00575    res |= ast_unregister_application(exclusive_app);
00576 
00577    ast_module_user_hangup_all();
00578 
00579    return res;
00580 }


Variable Documentation

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

Definition at line 594 of file app_macro.c.

char* app = "Macro" [static]

Definition at line 98 of file app_macro.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 594 of file app_macro.c.

char* descrip [static]

Definition at line 53 of file app_macro.c.

char* exclusive_app = "MacroExclusive" [static]

Definition at line 100 of file app_macro.c.

char* exclusive_descrip [static]

Definition at line 84 of file app_macro.c.

char* exclusive_synopsis = "Exclusive Macro Implementation" [static]

Definition at line 105 of file app_macro.c.

char* exit_app = "MacroExit" [static]

Definition at line 101 of file app_macro.c.

Referenced by milliwatt_exec().

char* exit_descrip [static]

Definition at line 91 of file app_macro.c.

char* exit_synopsis = "Exit From Macro" [static]

Definition at line 106 of file app_macro.c.

char* if_app = "MacroIf" [static]

Definition at line 99 of file app_macro.c.

char* if_descrip [static]

Initial value:

"  MacroIf(<expr>?macroname_a[|arg1][:macroname_b[|arg1]])\n"
"Executes macro defined in <macroname_a> if <expr> is true\n"
"(otherwise <macroname_b> if provided)\n"
"Arguments and return values as in application macro()\n"

Definition at line 78 of file app_macro.c.

char* if_synopsis = "Conditional Macro Implementation" [static]

Definition at line 104 of file app_macro.c.

Initial value:

 {
   .type = "MACRO",
   .chan_fixup = macro_fixup,
}

Definition at line 110 of file app_macro.c.

char* synopsis = "Macro Implementation" [static]

Definition at line 103 of file app_macro.c.


Generated on Fri Jul 3 20:36:15 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9