Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
func_evalexten.c File Reference

Dialplan extension evaluation function. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Include dependency graph for func_evalexten.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int eval_exten_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int get_extension_data (char *name, int namesize, struct ast_channel *c, const char *context, const char *exten, int priority)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Extension evaluation function" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function eval_exten_function
 

Detailed Description

Dialplan extension evaluation function.

Author
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file func_evalexten.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 200 of file func_evalexten.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 200 of file func_evalexten.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 200 of file func_evalexten.c.

◆ eval_exten_read()

static int eval_exten_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 110 of file func_evalexten.c.

References ast_channel_caller(), ast_channel_context(), ast_channel_context_set(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_lock, ast_channel_priority(), ast_channel_priority_set(), ast_channel_unlock, ast_debug, ast_findlabel_extension(), ast_log, ast_strdupa, ast_strlen_zero, context, exten, get_extension_data(), len(), LOG_WARNING, NULL, parse(), pbx_substitute_variables_helper(), S_COR, and strsep().

111 {
112  char *exten, *pri, *context, *parse;
113  int ipri;
114  const char *realcontext, *realexten;
115  int realpriority;
116  char tmpbuf[len];
117 
118  if (ast_strlen_zero(data)) {
119  ast_log(LOG_WARNING, "The EVAL_EXTEN function requires an extension\n");
120  return -1;
121  }
122 
123  parse = ast_strdupa(data);
124  /* Split context,exten,pri */
125  context = strsep(&parse, ",");
126  exten = strsep(&parse, ",");
127  pri = strsep(&parse, ",");
128  if (!exten) {
129  /* Only a priority in this one */
130  pri = context;
131  exten = NULL;
132  context = NULL;
133  } else if (!pri) {
134  /* Only an extension and priority in this one */
135  pri = exten;
136  exten = context;
137  context = NULL;
138  }
139  ast_debug(1, "Context, extension, priority: %s, %s, %s\n", context, exten, pri);
140  if (sscanf(pri, "%30d", &ipri) != 1) {
141  ipri = ast_findlabel_extension(chan, context ? context : ast_channel_context(chan),
142  exten ? exten : ast_channel_exten(chan), pri,
143  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
144  if (ipri < 1) {
145  ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri);
146  return -1;
147  }
148  }
149  ast_debug(1, "Context, extension, priority: %s, %s, %d\n", context, exten, ipri);
150 
151  ast_channel_lock(chan);
152  realcontext = ast_strdupa(ast_channel_context(chan));
153  realexten = ast_strdupa(ast_channel_exten(chan));
154  realpriority = ast_channel_priority(chan);
155  ast_channel_unlock(chan);
156  if (ast_strlen_zero(exten)) {
157  exten = ast_strdupa(realexten);
158  }
159  if (ast_strlen_zero(context)) {
160  context = ast_strdupa(realcontext);
161  }
162 
163  if (get_extension_data(tmpbuf, len, chan, context, exten, ipri)) {
164  return -1; /* EVAL_EXTEN failed */
165  }
166  /* Substitute variables now, using the location of the evaluated extension */
167  /* strdupa required or we'll just overwrite what we read when we set these */
168  ast_channel_lock(chan);
169  ast_channel_context_set(chan, context);
170  ast_channel_exten_set(chan, exten);
171  ast_channel_priority_set(chan, ipri);
172  ast_channel_unlock(chan);
173 
174  pbx_substitute_variables_helper(chan, tmpbuf, buf, len);
175 
176  ast_channel_lock(chan);
177  ast_channel_context_set(chan, realcontext);
178  ast_channel_exten_set(chan, realexten);
179  ast_channel_priority_set(chan, realpriority);
180  ast_channel_unlock(chan);
181 
182  return 0;
183 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
int ast_channel_priority(const struct ast_channel *chan)
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#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:85
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static int get_extension_data(char *name, int namesize, struct ast_channel *c, const char *context, const char *exten, int priority)
const char * ast_channel_exten(const struct ast_channel *chan)
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4184
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
char * strsep(char **str, const char *delims)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211
const char * ast_channel_context(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
void ast_channel_priority_set(struct ast_channel *chan, int value)

◆ get_extension_data()

static int get_extension_data ( char *  name,
int  namesize,
struct ast_channel c,
const char *  context,
const char *  exten,
int  priority 
)
static

Definition at line 90 of file func_evalexten.c.

References ast_copy_string(), ast_get_extension_app_data(), ast_rdlock_contexts(), ast_unlock_contexts(), E_MATCH, NULL, pbx_find_extension(), pbx_find_info::stacklen, and tmp().

Referenced by eval_exten_read().

92 {
93  struct ast_exten *e;
94  struct pbx_find_info q = { .stacklen = 0 }; /* the rest is set in pbx_find_context */
98  if (e) {
99  if (name) {
100  const char *tmp = ast_get_extension_app_data(e);
101  if (tmp) {
102  ast_copy_string(name, tmp, namesize);
103  }
104  }
105  return 0;
106  }
107  return -1;
108 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
static int tmp()
Definition: bt_open.c:389
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:8601
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:8507
#define NULL
Definition: resample.c:96
static int priority
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static const char name[]
Definition: cdr_mysql.c:74
int stacklen
Definition: extconf.h:238
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_exten * pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
Definition: ael_main.c:152

◆ load_module()

static int load_module ( void  )
static

Definition at line 195 of file func_evalexten.c.

References ast_custom_function_register.

196 {
198 }
static struct ast_custom_function eval_exten_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 190 of file func_evalexten.c.

References ast_custom_function_unregister().

191 {
193 }
static struct ast_custom_function eval_exten_function
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Extension evaluation function" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 200 of file func_evalexten.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 200 of file func_evalexten.c.

◆ eval_exten_function

struct ast_custom_function eval_exten_function
static
Initial value:
= {
.name = "EVAL_EXTEN",
.read = eval_exten_read,
}
static int eval_exten_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 185 of file func_evalexten.c.