123 for (; *
var; var++) {
127 }
else if (*var ==
')') {
129 }
else if (*var ==
':' && parens == 0) {
131 sscanf(var,
"%30d:%30d", offset, length);
149 static char *
substring(
const char *
value,
int offset,
int length,
char *workspace,
size_t workspace_len)
151 char *ret = workspace;
159 if (offset == 0 && length >= lr)
163 offset = lr + offset;
173 if (length >= 0 && length < lr - offset)
175 else if (length < 0) {
176 if (lr > offset - length)
177 ret[lr + length - offset] =
'\0';
192 if (offset == 0 && length >= lr)
196 offset = lr + offset;
213 if (length >= 0 && length < lr) {
215 }
else if (length < 0) {
242 *ret = cret ? workspace :
NULL;
248 const char not_found =
'\0';
253 int i, need_substring;
254 struct varshead *places[2] = { headp, &globals };
287 if (!strncmp(var,
"CALL", 4)) {
288 if (!strncmp(var + 4,
"ING", 3)) {
289 if (!strcmp(var + 7,
"PRES")) {
293 }
else if (!strcmp(var + 7,
"ANI2")) {
296 }
else if (!strcmp(var + 7,
"TON")) {
299 }
else if (!strcmp(var + 7,
"TNS")) {
304 }
else if (!strcmp(var,
"HINT")) {
306 }
else if (!strcmp(var,
"HINTNAME")) {
308 }
else if (!strcmp(var,
"EXTEN")) {
310 }
else if (!strcmp(var,
"CONTEXT")) {
312 }
else if (!strcmp(var,
"PRIORITY")) {
315 }
else if (!strcmp(var,
"CHANNEL")) {
317 }
else if (!strcmp(var,
"UNIQUEID")) {
319 }
else if (!strcmp(var,
"HANGUPCAUSE")) {
324 if (s == ¬_found) {
325 if (!strcmp(var,
"EPOCH")) {
328 }
else if (!strcmp(var,
"SYSTEMNAME")) {
330 }
else if (!strcmp(var,
"ASTCACHEDIR")) {
332 }
else if (!strcmp(var,
"ASTETCDIR")) {
334 }
else if (!strcmp(var,
"ASTMODDIR")) {
336 }
else if (!strcmp(var,
"ASTVARLIBDIR")) {
338 }
else if (!strcmp(var,
"ASTDBDIR")) {
340 }
else if (!strcmp(var,
"ASTKEYDIR")) {
342 }
else if (!strcmp(var,
"ASTDATADIR")) {
344 }
else if (!strcmp(var,
"ASTAGIDIR")) {
346 }
else if (!strcmp(var,
"ASTSPOOLDIR")) {
348 }
else if (!strcmp(var,
"ASTRUNDIR")) {
350 }
else if (!strcmp(var,
"ASTLOGDIR")) {
352 }
else if (!strcmp(var,
"ENTITYID")) {
358 for (i = 0; s == ¬_found && i <
ARRAY_LEN(places); i++) {
362 if (places[i] == &globals)
370 if (places[i] == &globals)
373 if (s == ¬_found || s ==
NULL) {
374 ast_debug(5,
"Result of '%s' is NULL\n", var);
377 ast_debug(5,
"Result of '%s' is '%s'\n", var, s);
382 if (need_substring) {
384 ast_debug(2,
"Final result of '%s' is '%s'\n", var, ret);
397 const char *whereweare;
404 if (!substr1 || !substr3) {
415 const char *nextvar =
NULL;
416 const char *nextexp =
NULL;
417 const char *nextthing;
430 nextthing = strchr(whereweare,
'$');
432 pos = nextthing - whereweare;
433 switch (nextthing[1]) {
449 pos = strlen(whereweare);
468 vars = vare = nextvar + 2;
473 while (brackets && *vare) {
474 if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
478 }
else if (vare[0] ==
'{') {
480 }
else if (vare[0] ==
'}') {
482 }
else if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
535 ast_log(
LOG_ERROR,
"Unable to allocate bogus channel for function value substitution.\n");
539 ast_debug(2,
"Function %s result is '%s'\n",
550 }
else if (nextexp) {
554 vars = vare = nextexp + 2;
559 while (brackets && *vare) {
560 if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
564 }
else if (vare[0] ==
'[') {
566 }
else if (vare[0] ==
']') {
568 }
else if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
629 const char *whereweare;
630 const char *orig_cp2 = cp2;
637 char *nextvar =
NULL;
638 char *nextexp =
NULL;
649 nextthing = strchr(whereweare,
'$');
651 pos = nextthing - whereweare;
652 switch (nextthing[1]) {
668 pos = strlen(whereweare);
677 memcpy(cp2, whereweare, pos);
695 vars = vare = nextvar + 2;
700 while (brackets && *vare) {
701 if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
705 }
else if (vare[0] ==
'{') {
707 }
else if (vare[0] ==
'}') {
709 }
else if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
755 ast_log(
LOG_ERROR,
"Unable to allocate bogus channel for function value substitution.\n");
759 ast_debug(2,
"Function %s result is '%s'\n", vars, cp4 ? cp4 :
"(null)");
767 length = strlen(cp4);
770 memcpy(cp2, cp4, length);
775 }
else if (nextexp) {
779 vars = vare = nextexp + 2;
784 while (brackets && *vare) {
785 if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
789 }
else if (vare[0] ==
'[') {
791 }
else if (vare[0] ==
']') {
793 }
else if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
821 length =
ast_expr(vars, cp2, count, c);
823 ast_debug(1,
"Expression result is '%s'\n", cp2);
831 *used = cp2 - orig_cp2;
853 e->
command =
"dialplan show globals";
855 "Usage: dialplan show globals\n" 856 " List current global dialplan variables and their values\n";
868 ast_cli(a->
fd,
"\n -- %d variable(s)\n", i);
881 e->
command =
"dialplan show chanvar";
883 "Usage: dialplan show chanvar <channel>\n" 884 " List current channel variables and their values\n";
914 e->
command =
"dialplan set global";
916 "Usage: dialplan set global <name> <value>\n" 917 " Set global dialplan variable <name> to <value>\n";
927 ast_cli(a->
fd,
"\n -- Global variable '%s' set to '%s'\n", a->
argv[3], a->
argv[4]);
935 const char *chan_name, *var_name, *var_value;
939 e->
command =
"dialplan set chanvar";
941 "Usage: dialplan set chanvar <channel> <varname> <value>\n" 942 " Set channel variable <varname> to <value>\n";
956 ast_cli(a->
fd,
"Channel '%s' not found\n", chan_name);
964 ast_cli(a->
fd,
"\n -- Channel variable '%s' set to '%s' for '%s'\n", var_name, var_value, chan_name);
1003 const char *ret =
NULL;
1015 for (i = 0; i < 2; i++) {
1018 if (places[i] == &globals)
1026 if (places[i] == &globals)
1043 if (name[strlen(name)-1] ==
')') {
1060 if (headp == &globals)
1061 ast_verb(2,
"Setting global variable '%s' to '%s'\n", name, value);
1075 const char *nametail =
name;
1077 int old_value_existed = 0;
1079 if (name[strlen(name) - 1] ==
')') {
1094 if (*nametail ==
'_') {
1096 if (*nametail ==
'_')
1101 if (strcmp(
ast_var_name(newvariable), nametail) == 0) {
1112 if (headp == &globals) {
1113 ast_verb(2,
"Setting global variable '%s' to '%s'\n", name, value);
1117 }
else if (old_value_existed) {
1139 name =
strsep(&mydata,
"=");
1146 if (strchr(name,
' ')) {
1147 ast_log(
LOG_WARNING,
"Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata);
1175 for (x = 0; x <
args.argc; x++) {
1177 if (
pair.argc == 2) {
1180 ast_log(
LOG_WARNING,
"Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n",
pair.
name,
pair.value);
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
static char * substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
takes a substring. It is ok to call with value == workspace.
const char * ast_config_AST_KEY_DIR
#define ast_rwlock_rdlock(a)
#define ast_channel_lock(chan)
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
const char * ast_config_AST_CACHE_DIR
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define AST_RWLOCK_DEFINE_STATIC(rwlock)
static void unload_pbx_variables(void)
Private include file for pbx.
static char * handle_set_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
const char * ast_config_AST_DB
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
#define ast_channel_unref(c)
Decrease channel reference count.
void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, without removing any previously set value...
const char * ast_var_value(const struct ast_var_t *var)
const char * ast_config_AST_MODULE_DIR
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
const char * ast_var_name(const struct ast_var_t *var)
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static struct ast_cli_entry vars_cli[]
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
void pbx_builtin_clear_globals(void)
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
const char * ast_config_AST_RUN_DIR
static char * handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct varshead * ast_channel_varshead(struct ast_channel *chan)
void ast_cli(int fd, const char *fmt,...)
int ast_str_get_hint(struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
void ast_str_substitute_variables_full(struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
#define ast_rwlock_unlock(a)
int ast_unregister_application(const char *app)
Unregister an application.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
int ast_channel_priority(const struct ast_channel *chan)
#define ast_verb(level,...)
int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf)
Create a human-readable string, specifying all variables and their corresponding values.
int args
This gets set in ast_cli_register()
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
#define ast_strlen_zero(foo)
const char * ast_config_AST_SYSTEM_NAME
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_debug(level,...)
Log a DEBUG message.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_AGI_DIR
#define ast_dummy_channel_alloc()
Create a fake channel structure.
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define ast_strdupa(s)
duplicate a string in memory from the stack
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
const char * ast_channel_exten(const struct ast_channel *chan)
Core PBX routines and definitions.
static char * handle_show_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI support for listing chanvar's variables in a parseable way.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_config_AST_DATA_DIR
int load_pbx_variables(void)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
const char * ast_config_AST_CONFIG_DIR
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_varset for a channel.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
void ast_var_delete(struct ast_var_t *var)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
static struct varshead globals
const char * ast_config_AST_LOG_DIR
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define ast_channel_unlock(chan)
struct ast_var_t::@249 entries
#define ast_var_assign(name, value)
int pbx_builtin_setvar_multiple(struct ast_channel *chan, const char *vdata)
Parse and set multiple channel variables, where the pairs are separated by the ',' character...
Prototypes for public functions only of internal interest,.
const char * ast_config_AST_SPOOL_DIR
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
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_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
Evaluate the given expression.
#define ast_rwlock_wrlock(a)
struct ast_eid ast_eid_default
Global EID.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
char * strsep(char **str, const char *delims)
Standard Command Line Interface.
int ast_channel_hangupcause(const struct ast_channel *chan)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
static ast_rwlock_t globalslock
const char * ast_channel_name(const struct ast_channel *chan)
char * ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
Command completion for the list of active channels.
int ast_register_application2(const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
Register an application.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
const char * ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
char * ast_str_set_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Set a dynamic string to a non-NULL terminated substring.
const char * ast_channel_context(const struct ast_channel *chan)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
Support for Asterisk built-in variables in the dialplan.
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Asterisk module definitions.
const char * ast_config_AST_VAR_DIR
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.
static char * handle_show_globals(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI support for listing global variables in a parseable way.
int pbx_builtin_setvar(struct ast_channel *chan, const char *data)
Parse and set a single channel variable, where the name and value are separated with an '=' character...
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define AST_APP_ARG(name)
Define an application argument.