128 }
else if (*
var ==
')') {
130 }
else if (*
var ==
':' && parens == 0) {
132 sscanf(
var,
"%30d:%30d", offset, length);
150 static char *
substring(
const char *
value,
int offset,
int length,
char *workspace,
size_t workspace_len)
152 char *ret = workspace;
160 if (offset == 0 && length >= lr)
164 offset = lr + offset;
174 if (length >= 0 && length < lr - offset)
176 else if (length < 0) {
177 if (lr > offset - length)
178 ret[lr + length - offset] =
'\0';
193 if (offset == 0 && length >= lr)
197 offset = lr + offset;
214 if (length >= 0 && length < lr) {
216 }
else if (length < 0) {
243 *ret = cret ? workspace :
NULL;
249 const char not_found =
'\0';
254 int i, need_substring;
288 if (!strncmp(
var,
"CALL", 4)) {
289 if (!strncmp(
var + 4,
"ING", 3)) {
290 if (!strcmp(
var + 7,
"PRES")) {
294 }
else if (!strcmp(
var + 7,
"ANI2")) {
297 }
else if (!strcmp(
var + 7,
"TON")) {
300 }
else if (!strcmp(
var + 7,
"TNS")) {
305 }
else if (!strcmp(
var,
"HINT")) {
307 }
else if (!strcmp(
var,
"HINTNAME")) {
309 }
else if (!strcmp(
var,
"EXTEN")) {
311 }
else if (!strcmp(
var,
"CONTEXT")) {
313 }
else if (!strcmp(
var,
"PRIORITY")) {
316 }
else if (!strcmp(
var,
"CHANNEL")) {
318 }
else if (!strcmp(
var,
"UNIQUEID")) {
320 }
else if (!strcmp(
var,
"HANGUPCAUSE")) {
325 if (s == ¬_found) {
326 if (!strcmp(
var,
"EPOCH")) {
329 }
else if (!strcmp(
var,
"SYSTEMNAME")) {
331 }
else if (!strcmp(
var,
"ASTCACHEDIR")) {
333 }
else if (!strcmp(
var,
"ASTETCDIR")) {
335 }
else if (!strcmp(
var,
"ASTMODDIR")) {
337 }
else if (!strcmp(
var,
"ASTVARLIBDIR")) {
339 }
else if (!strcmp(
var,
"ASTDBDIR")) {
341 }
else if (!strcmp(
var,
"ASTKEYDIR")) {
343 }
else if (!strcmp(
var,
"ASTDATADIR")) {
345 }
else if (!strcmp(
var,
"ASTAGIDIR")) {
347 }
else if (!strcmp(
var,
"ASTSPOOLDIR")) {
349 }
else if (!strcmp(
var,
"ASTRUNDIR")) {
351 }
else if (!strcmp(
var,
"ASTLOGDIR")) {
353 }
else if (!strcmp(
var,
"ASTSBINDIR")) {
355 }
else if (!strcmp(
var,
"ENTITYID")) {
361 for (i = 0; s == ¬_found && i <
ARRAY_LEN(places); i++) {
376 if (s == ¬_found || s ==
NULL) {
385 if (need_substring) {
387 ast_debug(2,
"Final result of '%s' is '%s'\n",
var, ret);
400 const char *whereweare;
407 if (!substr1 || !substr3) {
418 const char *nextvar =
NULL;
419 const char *nextexp =
NULL;
420 const char *nextthing;
433 nextthing = strchr(whereweare,
'$');
435 pos = nextthing - whereweare;
436 switch (nextthing[1]) {
452 pos = strlen(whereweare);
471 vars = vare = nextvar + 2;
476 while (brackets && *vare) {
477 if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
481 }
else if (vare[0] ==
'{') {
483 }
else if (vare[0] ==
'}') {
485 }
else if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
538 ast_log(
LOG_ERROR,
"Unable to allocate bogus channel for function value substitution.\n");
542 ast_debug(2,
"Function %s result is '%s'\n",
553 }
else if (nextexp) {
557 vars = vare = nextexp + 2;
562 while (brackets && *vare) {
563 if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
567 }
else if (vare[0] ==
'[') {
569 }
else if (vare[0] ==
']') {
571 }
else if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
637 const char *whereweare;
638 const char *orig_cp2 = cp2;
645 char *nextvar =
NULL;
646 char *nextexp =
NULL;
657 nextthing = strchr(whereweare,
'$');
659 pos = nextthing - whereweare;
660 switch (nextthing[1]) {
676 pos = strlen(whereweare);
685 memcpy(cp2, whereweare, pos);
703 vars = vare = nextvar + 2;
708 while (brackets && *vare) {
709 if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
713 }
else if (vare[0] ==
'{') {
715 }
else if (vare[0] ==
'}') {
717 }
else if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
763 ast_log(
LOG_ERROR,
"Unable to allocate bogus channel for function value substitution.\n");
767 ast_debug(2,
"Function %s result is '%s'\n", vars, cp4 ? cp4 :
"(null)");
771 if (
exten && !strcmp(vars,
"EXTEN")) {
774 }
else if (
context && !strcmp(vars,
"CONTEXT")) {
777 }
else if (pri && !strcmp(vars,
"PRIORITY")) {
787 length = strlen(cp4);
790 memcpy(cp2, cp4, length);
795 }
else if (nextexp) {
799 vars = vare = nextexp + 2;
804 while (brackets && *vare) {
805 if ((vare[0] ==
'$') && (vare[1] ==
'[')) {
809 }
else if (vare[0] ==
'[') {
811 }
else if (vare[0] ==
']') {
813 }
else if ((vare[0] ==
'$') && (vare[1] ==
'{')) {
843 ast_debug(1,
"Expression result is '%s'\n", cp2);
851 *used = cp2 - orig_cp2;
873 e->
command =
"dialplan show globals";
875 "Usage: dialplan show globals\n"
876 " List current global dialplan variables and their values\n";
888 ast_cli(
a->fd,
"\n -- %d variable(s)\n", i);
901 e->
command =
"dialplan show chanvar";
903 "Usage: dialplan show chanvar <channel>\n"
904 " List current channel variables and their values\n";
910 if (
a->argc != e->
args + 1) {
916 ast_cli(
a->fd,
"Channel '%s' not found\n",
a->argv[e->
args]);
936 char workspace[1024];
940 e->
command =
"dialplan eval function";
942 "Usage: dialplan eval function <name(args)>\n"
943 " Evaluate a dialplan function call\n"
944 " A dummy channel is used to evaluate\n"
945 " the function call, so only global\n"
946 " variables should be used.\n";
952 if (
a->argc != e->
args + 1) {
958 ast_cli(
a->fd,
"Unable to allocate bogus channel for function evaluation.\n");
962 fn = (
char *)
a->argv[3];
970 ast_cli(
a->fd,
"Return Value: %s (%d)\n", ret ?
"Failure" :
"Success", ret);
971 ast_cli(
a->fd,
"Result: %s\n", workspace);
980 e->
command =
"dialplan set global";
982 "Usage: dialplan set global <name> <value>\n"
983 " Set global dialplan variable <name> to <value>\n";
989 if (
a->argc != e->
args + 2)
993 ast_cli(
a->fd,
"\n -- Global variable '%s' set to '%s'\n",
a->argv[3],
a->argv[4]);
1001 const char *chan_name, *var_name, *var_value;
1005 e->
command =
"dialplan set chanvar";
1007 "Usage: dialplan set chanvar <channel> <varname> <value>\n"
1008 " Set channel variable <varname> to <value>\n";
1014 if (
a->argc != e->
args + 3)
1017 chan_name =
a->argv[e->
args];
1018 var_name =
a->argv[e->
args + 1];
1019 var_value =
a->argv[e->
args + 2];
1022 ast_cli(
a->fd,
"Channel '%s' not found\n", chan_name);
1030 ast_cli(
a->fd,
"\n -- Channel variable '%s' set to '%s' for '%s'\n", var_name, var_value, chan_name);
1069 const char *ret =
NULL;
1081 for (i = 0; i < 2; i++) {
1141 const char *nametail =
name;
1143 int old_value_existed = 0;
1145 if (
name[strlen(
name) - 1] ==
')') {
1160 if (*nametail ==
'_') {
1162 if (*nametail ==
'_')
1167 if (strcmp(
ast_var_name(newvariable), nametail) == 0) {
1183 }
else if (old_value_existed) {
1212 if (strchr(
name,
' ')) {
1213 ast_log(
LOG_WARNING,
"Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n",
name, mydata);
1241 for (x = 0; x <
args.argc; x++) {
1243 if (
pair.argc == 2) {
1246 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);
Prototypes for public functions only of internal interest,.
int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
Evaluate the given expression.
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_strdupa(s)
duplicate a string in memory from the stack
static char exten[AST_MAX_EXTENSION]
static char context[AST_MAX_CONTEXT]
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define ast_channel_lock(chan)
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
int ast_channel_hangupcause(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
#define ast_dummy_channel_alloc()
Create a fake channel structure.
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define ast_channel_unlock(chan)
const char * ast_var_name(const struct ast_var_t *var)
#define ast_var_assign(name, value)
const char * ast_var_value(const struct ast_var_t *var)
void ast_var_delete(struct ast_var_t *var)
Standard Command Line Interface.
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_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_publish_varset for a channel.
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
char * strsep(char **str, const char *delims)
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
A set of macros to manage forward-linked lists.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Asterisk locking-related definitions:
#define ast_rwlock_wrlock(a)
#define ast_rwlock_rdlock(a)
#define AST_RWLOCK_DEFINE_STATIC(rwlock)
#define ast_rwlock_unlock(a)
Asterisk module definitions.
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.
int ast_unregister_application(const char *app)
Unregister an application.
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_KEY_DIR
const char * ast_config_AST_CACHE_DIR
const char * ast_config_AST_MODULE_DIR
const char * ast_config_AST_RUN_DIR
const char * ast_config_AST_DATA_DIR
const char * ast_config_AST_CONFIG_DIR
const char * ast_config_AST_SPOOL_DIR
const char * ast_config_AST_AGI_DIR
const char * ast_config_AST_VAR_DIR
const char * ast_config_AST_SYSTEM_NAME
const char * ast_config_AST_SBIN_DIR
const char * ast_config_AST_LOG_DIR
const char * ast_config_AST_DB
Core PBX routines and definitions.
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
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
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.
Private include file for pbx.
int load_pbx_variables(void)
void pbx_substitute_variables_helper_full_location(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used, char *context, char *exten, int pri)
Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the contex...
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)
static char * handle_set_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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.
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...
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
static struct ast_cli_entry vars_cli[]
static ast_rwlock_t globalslock
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
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.
static void unload_pbx_variables(void)
static char * handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
const char * ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
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.
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)
static char * handle_eval_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI support for executing function.
void pbx_builtin_clear_globals(void)
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_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.
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.
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
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.
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,...
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
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.
static struct varshead globals
static char * substituted(struct ast_channel *channel, const char *string)
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
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.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
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.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Main Channel structure associated with a channel.
descriptor for a cli entry.
int args
This gets set in ast_cli_register()
Support for dynamic strings.
struct ast_var_t::@239 entries
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
struct ast_eid ast_eid_default
Global EID.