Asterisk - The Open Source Telephony Project GIT-master-f36a736
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

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Extension evaluation function")
 
static int eval_exten_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int eval_sub_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_custom_function eval_exten_function
 
static struct ast_custom_function eval_sub_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

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Extension evaluation function"   
)

◆ 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 146 of file func_evalexten.c.

147{
148 char *exten, *pri, *context, *parse;
149 int ipri;
150 char tmpbuf[len];
151
152 if (ast_strlen_zero(data)) {
153 ast_log(LOG_WARNING, "The EVAL_EXTEN function requires an extension\n");
154 return -1;
155 }
156
157 parse = ast_strdupa(data);
158 /* Split context,exten,pri */
159 context = strsep(&parse, ",");
160 exten = strsep(&parse, ",");
161 pri = strsep(&parse, ",");
162
163 if (pbx_parse_location(chan, &context, &exten, &pri, &ipri, NULL, NULL)) {
164 return -1;
165 }
166
167 if (ast_strlen_zero(exten) || ast_strlen_zero(context)) { /* only lock if we really need to */
168 ast_channel_lock(chan);
169 if (ast_strlen_zero(exten)) {
170 exten = ast_strdupa(ast_channel_exten(chan));
171 }
174 }
175 ast_channel_unlock(chan);
176 }
177
178 if (ast_get_extension_data(tmpbuf, len, chan, context, exten, ipri)) {
179 return -1; /* EVAL_EXTEN failed */
180 }
181
182 pbx_substitute_variables_helper_full_location(chan, (chan) ? ast_channel_varshead(chan) : NULL, tmpbuf, buf, len, NULL, context, exten, ipri);
183
184 return 0;
185}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2968
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2969
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * strsep(char **str, const char *delims)
#define LOG_WARNING
int ast_get_extension_data(char *buf, int bufsize, struct ast_channel *c, const char *context, const char *exten, int priority)
Fill a string buffer with the data at a dialplan extension.
Definition: pbx.c:8567
void pbx_substitute_variables_helper_full_location(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used, const char *context, const char *exten, int pri)
Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the contex...
int pbx_parse_location(struct ast_channel *chan, char **context, char **exten, char **pri, int *ipri, int *mode, char *rest)
Parses a dialplan location into context, extension, priority.
Definition: pbx.c:8791
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_unlock, ast_channel_varshead(), ast_get_extension_data(), ast_log, ast_strdupa, ast_strlen_zero(), buf, voicemailpwcheck::context, len(), LOG_WARNING, NULL, pbx_parse_location(), pbx_substitute_variables_helper_full_location(), and strsep().

◆ eval_sub_read()

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

Definition at line 187 of file func_evalexten.c.

188{
189 int gosub_res;
190 const char *retval;
191
192 if (ast_strlen_zero(data)) {
193 ast_log(LOG_WARNING, "The EVAL_SUB function requires an extension\n");
194 *buf = '\0';
195 return -1;
196 }
197
198 /* Ignore hangups since we want to retrieve a value, and this function could be called at hangup time */
199 gosub_res = ast_app_exec_sub(NULL, chan, data, 1);
200 if (gosub_res) {
201 ast_log(LOG_WARNING, "Failed to execute Gosub(%s)\n", data);
202 *buf = '\0';
203 return -1;
204 }
205
206 ast_channel_lock(chan);
207 retval = pbx_builtin_getvar_helper(chan, "GOSUB_RETVAL");
208 ast_copy_string(buf, S_OR(retval, ""), len); /* Overwrite, even if empty, to ensure a stale GOSUB_RETVAL isn't returned as our value */
209 ast_channel_unlock(chan);
210
211 return 0;
212}
static ENTRY retval
Definition: hsearch.c:50
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:297
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

References ast_app_exec_sub(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log, ast_strlen_zero(), buf, len(), LOG_WARNING, NULL, pbx_builtin_getvar_helper(), retval, and S_OR.

◆ load_module()

static int load_module ( void  )
static

Definition at line 232 of file func_evalexten.c.

233{
234 int res = 0;
237 return res;
238}
static struct ast_custom_function eval_exten_function
static struct ast_custom_function eval_sub_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, eval_exten_function, and eval_sub_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 224 of file func_evalexten.c.

225{
226 int res = 0;
229 return res;
230}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), eval_exten_function, and eval_sub_function.

Variable Documentation

◆ 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 214 of file func_evalexten.c.

Referenced by load_module(), and unload_module().

◆ eval_sub_function

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

Definition at line 219 of file func_evalexten.c.

Referenced by load_module(), and unload_module().