Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Macros | Functions | Variables
app_macro.c File Reference

Dial plan macro Implementation. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/extconf.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
Include dependency graph for app_macro.c:

Go to the source code of this file.

Macros

#define MACRO_EXIT_RESULT   1024
 
#define MAX_ARGS   80
 

Functions

static int _macro_exec (struct ast_channel *chan, const char *data, int exclusive)
 
 AST_MODULE_INFO_STANDARD_DEPRECATED (ASTERISK_GPL_KEY, "Extension Macros")
 
static struct ast_extenfind_matching_priority (struct ast_context *c, const char *exten, int priority, const char *callerid, int iter, int *had_error)
 
static int load_module (void)
 
static int macro_exec (struct ast_channel *chan, const char *data)
 
static int macro_exit_exec (struct ast_channel *chan, const char *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, const char *data)
 
static int macroif_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static char * app = "Macro"
 
static char * exclusive_app = "MacroExclusive"
 
static char * exit_app = "MacroExit"
 
static char * if_app = "MacroIf"
 
static const struct ast_datastore_info macro_ds_info
 

Detailed Description

Dial plan macro Implementation.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_macro.c.

Macro Definition Documentation

◆ MACRO_EXIT_RESULT

#define MACRO_EXIT_RESULT   1024

Definition at line 160 of file app_macro.c.

◆ MAX_ARGS

#define MAX_ARGS   80

Definition at line 157 of file app_macro.c.

Function Documentation

◆ _macro_exec()

static int _macro_exec ( struct ast_channel chan,
const char *  data,
int  exclusive 
)
static

Definition at line 238 of file app_macro.c.

239 {
240  const char *s;
241  char *tmp;
242  char *cur, *rest;
243  char *macro;
244  char fullmacro[80];
245  char varname[80];
246  char runningapp[80], runningdata[1024];
247  char *oldargs[MAX_ARGS + 1] = { NULL, };
248  int argc, x;
249  int res=0;
250  char oldexten[256]="";
251  int oldpriority, gosub_level = 0;
252  char pc[80], depthc[12];
253  char oldcontext[AST_MAX_CONTEXT] = "";
254  const char *inhangupc;
255  int offset, depth = 0, maxdepth = 7;
256  int setmacrocontext=0;
257  int autoloopflag, inhangup = 0;
258  struct ast_str *tmp_subst = NULL;
259  const char *my_macro_exten = NULL;
260  char *save_macro_exten;
261  char *save_macro_context;
262  char *save_macro_priority;
263  char *save_macro_offset;
264  int save_in_subroutine;
265  struct ast_datastore *macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);
266  int had_infinite_include_error = 0;
267  static int deprecation_notice = 0;
268 
269  if (ast_strlen_zero(data)) {
270  ast_log(LOG_WARNING, "Macro() requires arguments. See \"core show application macro\" for help.\n");
271  return -1;
272  }
273 
274  if (!deprecation_notice) {
275  deprecation_notice = 1;
276  ast_log(LOG_WARNING, "Macro() is deprecated and will be removed from a future version of Asterisk.\n");
277  ast_log(LOG_WARNING, "Dialplan should be updated to use Gosub instead.\n");
278  }
279 
280  do {
281  if (macro_store) {
282  break;
283  }
284  if (!(macro_store = ast_datastore_alloc(&macro_ds_info, NULL))) {
285  ast_log(LOG_WARNING, "Unable to allocate new datastore.\n");
286  break;
287  }
288  /* Just the existence of this datastore is enough. */
289  macro_store->inheritance = DATASTORE_INHERIT_FOREVER;
290  ast_channel_datastore_add(chan, macro_store);
291  } while (0);
292 
293  /* does the user want a deeper rabbit hole? */
294  ast_channel_lock(chan);
295  if ((s = pbx_builtin_getvar_helper(chan, "MACRO_RECURSION"))) {
296  sscanf(s, "%30d", &maxdepth);
297  }
298 
299  /* Count how many levels deep the rabbit hole goes */
300  if ((s = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH"))) {
301  sscanf(s, "%30d", &depth);
302  }
303 
304  /* Used for detecting whether to return when a Macro is called from another Macro after hangup */
305  if (strcmp(ast_channel_exten(chan), "h") == 0)
306  pbx_builtin_setvar_helper(chan, "MACRO_IN_HANGUP", "1");
307 
308  if ((inhangupc = pbx_builtin_getvar_helper(chan, "MACRO_IN_HANGUP"))) {
309  sscanf(inhangupc, "%30d", &inhangup);
310  }
311  ast_channel_unlock(chan);
312 
313  if (depth >= maxdepth) {
314  ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n");
315  return 0;
316  }
317  snprintf(depthc, sizeof(depthc), "%d", depth + 1);
318 
319  tmp = ast_strdupa(data);
320  rest = tmp;
321  macro = strsep(&rest, ",");
322  if (ast_strlen_zero(macro)) {
323  ast_log(LOG_WARNING, "Invalid macro name specified\n");
324  return 0;
325  }
326 
327  snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro);
328 
329  /* first search for the macro */
330  if (!ast_context_find(fullmacro)) {
331  ast_log(LOG_WARNING, "No such context '%s' for macro '%s'. Was called by %s@%s\n",
332  fullmacro, macro, ast_channel_exten(chan), ast_channel_context(chan));
333  return 0;
334  }
335 
336  /* now search for the right extension */
337  if (ast_exists_extension(chan, fullmacro, "s", 1,
338  S_COR(ast_channel_caller(chan)->id.number.valid,
339  ast_channel_caller(chan)->id.number.str, NULL))) {
340  /* We have a normal macro */
341  my_macro_exten = "s";
342  } else if (ast_exists_extension(chan, fullmacro, "~~s~~", 1,
343  S_COR(ast_channel_caller(chan)->id.number.valid,
344  ast_channel_caller(chan)->id.number.str, NULL))) {
345  /* We have an AEL generated macro */
346  my_macro_exten = "~~s~~";
347  }
348 
349  /* do we have a valid exten? */
350  if (!my_macro_exten) {
352  "Context '%s' for macro '%s' lacks 's' extension, priority 1\n",
353  fullmacro, macro);
354  return 0;
355  }
356 
357  /* If we are to run the macro exclusively, take the mutex */
358  if (exclusive) {
359  ast_debug(1, "Locking macrolock for '%s'\n", fullmacro);
360  ast_autoservice_start(chan);
361  if (ast_context_lockmacro(fullmacro)) {
362  ast_log(LOG_WARNING, "Failed to lock macro '%s' as in-use\n", fullmacro);
363  ast_autoservice_stop(chan);
364  return 0;
365  }
366  ast_autoservice_stop(chan);
367  }
368 
369  if (!(tmp_subst = ast_str_create(16))) {
370  return -1;
371  }
372 
373  /* Save old info */
374  ast_channel_lock(chan);
375  oldpriority = ast_channel_priority(chan);
376  ast_copy_string(oldexten, ast_channel_exten(chan), sizeof(oldexten));
377  ast_copy_string(oldcontext, ast_channel_context(chan), sizeof(oldcontext));
382  setmacrocontext=1;
383  }
384  argc = 1;
385  /* Save old macro variables */
386  save_macro_exten = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_EXTEN"));
387  pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten);
388 
389  save_macro_context = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"));
390  pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext);
391 
392  save_macro_priority = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY"));
393  snprintf(pc, sizeof(pc), "%d", oldpriority);
394  pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc);
395 
396  save_macro_offset = ast_strdup(pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"));
397  pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
398 
399  pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
400 
401  save_in_subroutine = ast_test_flag(ast_channel_flags(chan), AST_FLAG_SUBROUTINE_EXEC);
403 
404  /* Setup environment for new run */
405  ast_channel_exten_set(chan, my_macro_exten);
406  ast_channel_context_set(chan, fullmacro);
407  ast_channel_priority_set(chan, 1);
408 
409  while((cur = strsep(&rest, ",")) && (argc < MAX_ARGS)) {
410  const char *argp;
411  /* Save copy of old arguments if we're overwriting some, otherwise
412  let them pass through to the other macro */
413  snprintf(varname, sizeof(varname), "ARG%d", argc);
414  if ((argp = pbx_builtin_getvar_helper(chan, varname))) {
415  oldargs[argc] = ast_strdup(argp);
416  }
417  pbx_builtin_setvar_helper(chan, varname, cur);
418  argc++;
419  }
422  ast_channel_unlock(chan);
423 
425  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
426  struct ast_context *c;
427  struct ast_exten *e;
428  int foundx;
429  runningapp[0] = '\0';
430  runningdata[0] = '\0';
431 
432  /* What application will execute? */
433  if (ast_rdlock_contexts()) {
434  ast_log(LOG_WARNING, "Failed to lock contexts list\n");
435  } else {
436  for (c = ast_walk_contexts(NULL), e = NULL; c; c = ast_walk_contexts(c)) {
437  if (!strcmp(ast_get_context_name(c), ast_channel_context(chan))) {
438  if (ast_rdlock_context(c)) {
439  ast_log(LOG_WARNING, "Unable to lock context?\n");
440  } else {
442  S_COR(ast_channel_caller(chan)->id.number.valid,
443  ast_channel_caller(chan)->id.number.str, NULL),
444  0, &had_infinite_include_error);
445  if (e) { /* This will only be undefined for pbx_realtime, which is majorly broken. */
446  ast_copy_string(runningapp, ast_get_extension_app(e), sizeof(runningapp));
447  ast_copy_string(runningdata, ast_get_extension_app_data(e), sizeof(runningdata));
448  }
450  }
451  break;
452  }
453  }
454  }
456 
457  /* Reset the macro depth, if it was changed in the last iteration */
458  pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
459 
461  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL),
462  &foundx, 1);
463  if (res) {
464  /* Something bad happened, or a hangup has been requested. */
465  if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
466  (res == '*') || (res == '#')) {
467  /* Just return result as to the previous application as if it had been dialed */
468  ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
469  break;
470  }
471  switch(res) {
472  case MACRO_EXIT_RESULT:
473  res = 0;
474  goto out;
475  default:
476  ast_debug(2, "Spawn extension (%s,%s,%d) exited non-zero on '%s' in macro '%s'\n", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), ast_channel_name(chan), macro);
477  ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s' in macro '%s'\n", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), ast_channel_name(chan), macro);
478  goto out;
479  }
480  }
481 
482  ast_debug(1, "Executed application: %s\n", runningapp);
483 
484  if (!strcasecmp(runningapp, "GOSUB")) {
485  gosub_level++;
486  ast_debug(1, "Incrementing gosub_level\n");
487  } else if (!strcasecmp(runningapp, "GOSUBIF")) {
488  char *cond, *app_arg;
489  char *app2;
490  ast_str_substitute_variables(&tmp_subst, 0, chan, runningdata);
491  app2 = ast_str_buffer(tmp_subst);
492  cond = strsep(&app2, "?");
493  app_arg = strsep(&app2, ":");
494  if (pbx_checkcondition(cond)) {
495  if (!ast_strlen_zero(app_arg)) {
496  gosub_level++;
497  ast_debug(1, "Incrementing gosub_level\n");
498  }
499  } else {
500  if (!ast_strlen_zero(app2)) {
501  gosub_level++;
502  ast_debug(1, "Incrementing gosub_level\n");
503  }
504  }
505  } else if (!strcasecmp(runningapp, "RETURN")) {
506  gosub_level--;
507  ast_debug(1, "Decrementing gosub_level\n");
508  } else if (!strcasecmp(runningapp, "STACKPOP")) {
509  gosub_level--;
510  ast_debug(1, "Decrementing gosub_level\n");
511  } else if (!strncasecmp(runningapp, "EXEC", 4)) {
512  /* Must evaluate args to find actual app */
513  char *tmp2, *tmp3 = NULL;
514  ast_str_substitute_variables(&tmp_subst, 0, chan, runningdata);
515  tmp2 = ast_str_buffer(tmp_subst);
516  if (!strcasecmp(runningapp, "EXECIF")) {
517  if ((tmp3 = strchr(tmp2, '|'))) {
518  *tmp3++ = '\0';
519  }
520  if (!pbx_checkcondition(tmp2)) {
521  tmp3 = NULL;
522  }
523  } else {
524  tmp3 = tmp2;
525  }
526 
527  if (tmp3) {
528  ast_debug(1, "Last app: %s\n", tmp3);
529  }
530 
531  if (tmp3 && !strncasecmp(tmp3, "GOSUB", 5)) {
532  gosub_level++;
533  ast_debug(1, "Incrementing gosub_level\n");
534  } else if (tmp3 && !strncasecmp(tmp3, "RETURN", 6)) {
535  gosub_level--;
536  ast_debug(1, "Decrementing gosub_level\n");
537  } else if (tmp3 && !strncasecmp(tmp3, "STACKPOP", 8)) {
538  gosub_level--;
539  ast_debug(1, "Decrementing gosub_level\n");
540  }
541  }
542 
543  if (gosub_level == 0 && strcasecmp(ast_channel_context(chan), fullmacro)) {
544  ast_verb(2, "Channel '%s' jumping out of macro '%s'\n", ast_channel_name(chan), macro);
545  break;
546  }
547 
548  /* don't stop executing extensions when we're in "h" */
549  if (ast_check_hangup(chan) && !inhangup) {
550  ast_debug(1, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n",
551  ast_channel_exten(chan),
553  ast_channel_priority(chan));
554  goto out;
555  }
557  }
558  out:
559 
560  /* Don't let the channel change now. */
561  ast_channel_lock(chan);
562 
563  /* Reset the depth back to what it was when the routine was entered (like if we called Macro recursively) */
564  snprintf(depthc, sizeof(depthc), "%d", depth);
565  pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
567  ast_set2_flag(ast_channel_flags(chan), save_in_subroutine, AST_FLAG_SUBROUTINE_EXEC);
568 
569  for (x = 1; x < argc; x++) {
570  /* Restore old arguments and delete ours */
571  snprintf(varname, sizeof(varname), "ARG%d", x);
572  pbx_builtin_setvar_helper(chan, varname, oldargs[x]);
573  ast_free(oldargs[x]);
574  }
575 
576  /* Restore macro variables */
577  pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten);
578  pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context);
579  pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority);
580  ast_free(save_macro_exten);
581  ast_free(save_macro_context);
582  ast_free(save_macro_priority);
583 
584  if (setmacrocontext) {
586  ast_channel_macroexten_set(chan, "");
588  }
589 
590  if (!strcasecmp(ast_channel_context(chan), fullmacro)
592  const char *offsets;
593 
594  /* If we're leaving the macro normally, restore original information */
595  ast_channel_priority_set(chan, oldpriority);
596  ast_channel_context_set(chan, oldcontext);
597  ast_channel_exten_set(chan, oldexten);
598  if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
599  /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
600  normally if there is any problem */
601  if (sscanf(offsets, "%30d", &offset) == 1) {
603  ast_channel_priority(chan) + offset + 1,
604  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
605  ast_channel_priority_set(chan, ast_channel_priority(chan) + offset);
606  }
607  }
608  }
609  }
610 
611  pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset);
612  ast_free(save_macro_offset);
613 
614  /* Unlock the macro */
615  if (exclusive) {
616  ast_debug(1, "Unlocking macrolock for '%s'\n", fullmacro);
617  if (ast_context_unlockmacro(fullmacro)) {
618  ast_log(LOG_ERROR, "Failed to unlock macro '%s' - that isn't good\n", fullmacro);
619  res = 0;
620  }
621  }
622  ast_channel_unlock(chan);
623  ast_free(tmp_subst);
624 
625  return res;
626 }
static const char app2[]
#define MAX_ARGS
Definition: app_macro.c:157
static struct ast_exten * find_matching_priority(struct ast_context *c, const char *exten, int priority, const char *callerid, int iter, int *had_error)
Definition: app_macro.c:192
#define MACRO_EXIT_RESULT
Definition: app_macro.c:160
static const struct ast_datastore_info macro_ds_info
Definition: app_macro.c:169
ast_cond_t cond
Definition: app_meetme.c:1092
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
static void deprecation_notice(void)
Definition: chan_sip.c:35470
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2384
#define DATASTORE_INHERIT_FOREVER
Definition: channel.h:192
@ AST_SOFTHANGUP_ASYNCGOTO
Definition: channel.h:1126
#define ast_channel_lock(chan)
Definition: channel.h:2922
const char * ast_channel_context(const struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
void ast_channel_macroexten_set(struct ast_channel *chan, const char *value)
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
const char * ast_channel_name(const struct ast_channel *chan)
@ AST_FLAG_IN_AUTOLOOP
Definition: channel.h:997
@ AST_FLAG_SUBROUTINE_EXEC
Definition: channel.h:1058
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2398
#define AST_MAX_CONTEXT
Definition: channel.h:135
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
const char * ast_channel_macroexten(const struct ast_channel *chan)
void ast_channel_macropriority_set(struct ast_channel *chan, int value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value)
int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
const char * ast_channel_macrocontext(const struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
char * strsep(char **str, const char *delims)
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_WARNING
int ast_context_lockmacro(const char *macrocontext)
locks the macrolock in the given context
Definition: pbx.c:5164
int ast_context_unlockmacro(const char *macrocontext)
Unlocks the macrolock in the given context.
Definition: pbx.c:5185
struct ast_context * ast_walk_contexts(struct ast_context *con)
Definition: extconf.c:4025
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: extconf.c:4173
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4182
const char * ast_get_extension_app(struct ast_exten *e)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_unlock_context(struct ast_context *con)
const char * ast_get_context_name(struct ast_context *con)
Definition: ael_main.c:421
int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn)
Launch a new extension (i.e. new stack)
Definition: pbx.c:4207
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_rdlock_contexts(void)
Read locks the context list.
void * ast_get_extension_app_data(struct ast_exten *e)
int pbx_checkcondition(const char *condition)
Evaluate a condition.
int ast_unlock_contexts(void)
Unlocks contexts.
int ast_rdlock_context(struct ast_context *con)
Read locks a given context.
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
unsigned int inheritance
Definition: datastore.h:69
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
Definition: pbx.c:237
Support for dynamic strings.
Definition: strings.h:604
Number structure.
Definition: app_followme.c:154
static struct test_val c
FILE * out
Definition: utils/frame.c:33
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_set_flag(p, flag)
Definition: utils.h:70

References app2, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_caller(), ast_channel_context(), ast_channel_context_set(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_lock, ast_channel_macrocontext(), ast_channel_macrocontext_set(), ast_channel_macroexten(), ast_channel_macroexten_set(), ast_channel_macropriority_set(), ast_channel_name(), ast_channel_priority(), ast_channel_priority_set(), ast_channel_softhangup_internal_flag(), ast_channel_unlock, ast_check_hangup(), ast_context_find(), ast_context_lockmacro(), ast_context_unlockmacro(), ast_copy_string(), ast_datastore_alloc, ast_debug, ast_exists_extension(), AST_FLAG_IN_AUTOLOOP, AST_FLAG_SUBROUTINE_EXEC, ast_free, ast_get_context_name(), ast_get_extension_app(), ast_get_extension_app_data(), ast_log, AST_MAX_CONTEXT, ast_rdlock_context(), ast_rdlock_contexts(), ast_set2_flag, ast_set_flag, AST_SOFTHANGUP_ASYNCGOTO, ast_spawn_extension(), ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), ast_strdup, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_unlock_context(), ast_unlock_contexts(), ast_verb, ast_walk_contexts(), c, cond, ast_datastore::data, DATASTORE_INHERIT_FOREVER, deprecation_notice(), find_matching_priority(), ast_datastore::inheritance, LOG_ERROR, LOG_WARNING, macro_ds_info, MACRO_EXIT_RESULT, MAX_ARGS, NULL, out, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_checkcondition(), S_COR, strsep(), and tmp().

Referenced by macro_exec(), and macroexclusive_exec().

◆ AST_MODULE_INFO_STANDARD_DEPRECATED()

AST_MODULE_INFO_STANDARD_DEPRECATED ( ASTERISK_GPL_KEY  ,
"Extension Macros"   
)

◆ find_matching_priority()

static struct ast_exten* find_matching_priority ( struct ast_context c,
const char *  exten,
int  priority,
const char *  callerid,
int  iter,
int *  had_error 
)
static

Definition at line 192 of file app_macro.c.

194 {
195  struct ast_exten *e;
196  struct ast_context *c2;
197  int idx;
198 
199  if (iter >= AST_PBX_MAX_STACK) {
200  if (!(*had_error)) {
201  *had_error = 1;
202  ast_log(LOG_ERROR, "Potential infinite loop detected, will not recurse further.\n");
203  }
204  return NULL;
205  }
206 
209  int needmatch = ast_get_extension_matchcid(e);
210  if ((needmatch && ast_extension_match(ast_get_extension_cidmatch(e), callerid)) ||
211  (!needmatch)) {
212  /* This is the matching extension we want */
213  struct ast_exten *p;
216  continue;
217  return p;
218  }
219  }
220  }
221  }
222 
223  /* No match; run through includes */
224  for (idx = 0; idx < ast_context_includes_count(c); idx++) {
225  const struct ast_include *i = ast_context_includes_get(c, idx);
226 
227  for (c2=ast_walk_contexts(NULL); c2; c2=ast_walk_contexts(c2)) {
228  if (!strcmp(ast_get_context_name(c2), ast_get_include_name(i))) {
229  e = find_matching_priority(c2, exten, priority, callerid, iter + 1, had_error);
230  if (e)
231  return e;
232  }
233  }
234  }
235  return NULL;
236 }
static int priority
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
#define AST_PBX_MAX_STACK
Definition: extconf.h:226
int ast_get_extension_priority(struct ast_exten *exten)
const char * ast_get_include_name(const struct ast_include *include)
Definition: pbx_include.c:50
int ast_get_extension_matchcid(struct ast_exten *e)
const char * ast_get_extension_name(struct ast_exten *exten)
struct ast_exten * ast_walk_extension_priorities(struct ast_exten *exten, struct ast_exten *priority)
Definition: extconf.c:4062
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4296
struct ast_exten * ast_walk_context_extensions(struct ast_context *con, struct ast_exten *priority)
Definition: ael_main.c:427
int ast_context_includes_count(const struct ast_context *con)
const char * ast_get_extension_cidmatch(struct ast_exten *e)
const struct ast_include * ast_context_includes_get(const struct ast_context *con, int idx)
ast_include: include= support in extensions.conf
Definition: pbx_include.c:37

References ast_context_includes_count(), ast_context_includes_get(), 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_log, AST_PBX_MAX_STACK, ast_walk_context_extensions(), ast_walk_contexts(), ast_walk_extension_priorities(), c, exten, LOG_ERROR, NULL, and priority.

Referenced by _macro_exec().

◆ load_module()

static int load_module ( void  )
static

Definition at line 679 of file app_macro.c.

680 {
681  int res;
682 
687 
688  return res;
689 }
static int macro_exit_exec(struct ast_channel *chan, const char *data)
Definition: app_macro.c:662
static int macro_exec(struct ast_channel *chan, const char *data)
Definition: app_macro.c:628
static char * exclusive_app
Definition: app_macro.c:164
static int macroexclusive_exec(struct ast_channel *chan, const char *data)
Definition: app_macro.c:633
static char * if_app
Definition: app_macro.c:163
static char * exit_app
Definition: app_macro.c:165
static char * app
Definition: app_macro.c:162
static int macroif_exec(struct ast_channel *chan, const char *data)
Definition: app_macro.c:638
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

References app, ast_register_application_xml, exclusive_app, exit_app, if_app, macro_exec(), macro_exit_exec(), macroexclusive_exec(), and macroif_exec().

◆ macro_exec()

static int macro_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 628 of file app_macro.c.

629 {
630  return _macro_exec(chan, data, 0);
631 }
static int _macro_exec(struct ast_channel *chan, const char *data, int exclusive)
Definition: app_macro.c:238

References _macro_exec(), and ast_exten::data.

Referenced by load_module(), and macroif_exec().

◆ macro_exit_exec()

static int macro_exit_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 662 of file app_macro.c.

663 {
664  return MACRO_EXIT_RESULT;
665 }

References MACRO_EXIT_RESULT.

Referenced by load_module().

◆ macro_fixup()

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

Definition at line 174 of file app_macro.c.

175 {
176  int i;
177  char varname[10];
178  pbx_builtin_setvar_helper(new_chan, "MACRO_DEPTH", "0");
179  pbx_builtin_setvar_helper(new_chan, "MACRO_CONTEXT", NULL);
180  pbx_builtin_setvar_helper(new_chan, "MACRO_EXTEN", NULL);
181  pbx_builtin_setvar_helper(new_chan, "MACRO_PRIORITY", NULL);
182  pbx_builtin_setvar_helper(new_chan, "MACRO_OFFSET", NULL);
183  for (i = 1; i < 100; i++) {
184  snprintf(varname, sizeof(varname), "ARG%d", i);
185  while (pbx_builtin_getvar_helper(new_chan, varname)) {
186  /* Kill all levels of arguments */
187  pbx_builtin_setvar_helper(new_chan, varname, NULL);
188  }
189  }
190 }

References NULL, pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

◆ macroexclusive_exec()

static int macroexclusive_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 633 of file app_macro.c.

634 {
635  return _macro_exec(chan, data, 1);
636 }

References _macro_exec(), and ast_exten::data.

Referenced by load_module().

◆ macroif_exec()

static int macroif_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 638 of file app_macro.c.

639 {
640  char *expr = NULL, *label_a = NULL, *label_b = NULL;
641  int res = 0;
642 
643  expr = ast_strdupa(data);
644 
645  if ((label_a = strchr(expr, '?'))) {
646  *label_a = '\0';
647  label_a++;
648  if ((label_b = strchr(label_a, ':'))) {
649  *label_b = '\0';
650  label_b++;
651  }
652  if (pbx_checkcondition(expr))
653  res = macro_exec(chan, label_a);
654  else if (label_b)
655  res = macro_exec(chan, label_b);
656  } else
657  ast_log(LOG_WARNING, "Invalid Syntax.\n");
658 
659  return res;
660 }

References ast_log, ast_strdupa, ast_exten::data, LOG_WARNING, macro_exec(), NULL, and pbx_checkcondition().

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 667 of file app_macro.c.

668 {
669  int res;
670 
675 
676  return res;
677 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, ast_unregister_application(), exclusive_app, exit_app, and if_app.

Variable Documentation

◆ app

char* app = "Macro"
static

Definition at line 162 of file app_macro.c.

Referenced by load_module(), and unload_module().

◆ exclusive_app

char* exclusive_app = "MacroExclusive"
static

Definition at line 164 of file app_macro.c.

Referenced by load_module(), and unload_module().

◆ exit_app

char* exit_app = "MacroExit"
static

Definition at line 165 of file app_macro.c.

Referenced by load_module(), and unload_module().

◆ if_app

char* if_app = "MacroIf"
static

Definition at line 163 of file app_macro.c.

Referenced by load_module(), and unload_module().

◆ macro_ds_info

const struct ast_datastore_info macro_ds_info
static
Initial value:
= {
.type = "MACRO",
.chan_fixup = macro_fixup,
}
static void macro_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Definition: app_macro.c:174

Definition at line 167 of file app_macro.c.

Referenced by _macro_exec().