Bug 5858 - Make the chanvars.c functions return a 'const char *'

This should prevent us from unintentionally changing variable
values when they're returned from pbx_builtin_getvar_helper.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7304 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Tilghman Lesher 20 years ago
parent 6a6b88c0e3
commit 870f98f02d

16
app.c

@ -1006,7 +1006,7 @@ int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordf
/* Channel group core functions */ /* Channel group core functions */
int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max) int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max)
{ {
int res=0; int res=0;
char tmp[256]; char tmp[256];
@ -1035,7 +1035,7 @@ int ast_app_group_split_group(char *data, char *group, int group_max, char *cate
return res; return res;
} }
int ast_app_group_set_channel(struct ast_channel *chan, char *data) int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
{ {
int res=0; int res=0;
char group[80] = ""; char group[80] = "";
@ -1049,13 +1049,13 @@ int ast_app_group_set_channel(struct ast_channel *chan, char *data)
return res; return res;
} }
int ast_app_group_get_count(char *group, char *category) int ast_app_group_get_count(const char *group, const char *category)
{ {
struct ast_channel *chan; struct ast_channel *chan;
int count = 0; int count = 0;
char *test; const char *test;
char cat[80]; char cat[80];
char *s; const char *s;
if (ast_strlen_zero(group)) if (ast_strlen_zero(group))
return 0; return 0;
@ -1074,14 +1074,14 @@ int ast_app_group_get_count(char *group, char *category)
return count; return count;
} }
int ast_app_group_match_get_count(char *groupmatch, char *category) int ast_app_group_match_get_count(const char *groupmatch, const char *category)
{ {
regex_t regexbuf; regex_t regexbuf;
struct ast_channel *chan; struct ast_channel *chan;
int count = 0; int count = 0;
char *test; const char *test;
char cat[80]; char cat[80];
char *s; const char *s;
if (ast_strlen_zero(groupmatch)) if (ast_strlen_zero(groupmatch))
return 0; return 0;

@ -468,7 +468,7 @@ static int chanspy_exec(struct ast_channel *chan, void *data)
prev=NULL; prev=NULL;
while(peer) { while(peer) {
if (peer != chan) { if (peer != chan) {
char *group = NULL; const char *group = NULL;
int igrp = 1; int igrp = 1;
if (peer == prev && !chosen) { if (peer == prev && !chosen) {

@ -56,7 +56,6 @@ static int group_count_exec(struct ast_channel *chan, void *data)
char group[80] = ""; char group[80] = "";
char category[80] = ""; char category[80] = "";
char ret[80] = ""; char ret[80] = "";
char *grp;
static int deprecation_warning = 0; static int deprecation_warning = 0;
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
@ -69,7 +68,7 @@ static int group_count_exec(struct ast_channel *chan, void *data)
ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
if (ast_strlen_zero(group)) { if (ast_strlen_zero(group)) {
grp = pbx_builtin_getvar_helper(chan, category); const char *grp = pbx_builtin_getvar_helper(chan, category);
strncpy(group, grp, sizeof(group) - 1); strncpy(group, grp, sizeof(group) - 1);
} }

@ -89,6 +89,8 @@ LOCAL_USER_DECL;
static int macro_exec(struct ast_channel *chan, void *data) static int macro_exec(struct ast_channel *chan, void *data)
{ {
const char *s;
char *tmp; char *tmp;
char *cur, *rest; char *cur, *rest;
char *macro; char *macro;
@ -101,8 +103,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
int oldpriority; int oldpriority;
char pc[80], depthc[12]; char pc[80], depthc[12];
char oldcontext[AST_MAX_CONTEXT] = ""; char oldcontext[AST_MAX_CONTEXT] = "";
char *offsets; int offset, depth = 0;
int offset, depth;
int setmacrocontext=0; int setmacrocontext=0;
int autoloopflag; int autoloopflag;
@ -120,13 +121,9 @@ static int macro_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
/* Count how many levels deep the rabbit hole goes */ /* Count how many levels deep the rabbit hole goes */
tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH"); s = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
if (tmp) { if (s)
sscanf(tmp, "%d", &depth); sscanf(s, "%d", &depth);
} else {
depth = 0;
}
if (depth >= 7) { if (depth >= 7) {
ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n"); ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n");
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
@ -193,12 +190,13 @@ static int macro_exec(struct ast_channel *chan, void *data)
chan->priority = 1; chan->priority = 1;
while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) { while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) {
const char *s;
/* Save copy of old arguments if we're overwriting some, otherwise /* Save copy of old arguments if we're overwriting some, otherwise
let them pass through to the other macro */ let them pass through to the other macro */
snprintf(varname, sizeof(varname), "ARG%d", argc); snprintf(varname, sizeof(varname), "ARG%d", argc);
oldargs[argc] = pbx_builtin_getvar_helper(chan, varname); s = pbx_builtin_getvar_helper(chan, varname);
if (oldargs[argc]) if (s)
oldargs[argc] = strdup(oldargs[argc]); oldargs[argc] = strdup(s);
pbx_builtin_setvar_helper(chan, varname, cur); pbx_builtin_setvar_helper(chan, varname, cur);
argc++; argc++;
} }
@ -286,6 +284,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
ast_copy_string(chan->context, oldcontext, sizeof(chan->context)); ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) { if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
/* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */ /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
const char *offsets;
ast_copy_string(chan->exten, oldexten, sizeof(chan->exten)); ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) { if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
/* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue

@ -143,8 +143,8 @@ static struct ast_conference {
int locked; /* Is the conference locked? */ int locked; /* Is the conference locked? */
pthread_t recordthread; /* thread for recording */ pthread_t recordthread; /* thread for recording */
pthread_attr_t attr; /* thread attribute */ pthread_attr_t attr; /* thread attribute */
char *recordingfilename; /* Filename to record the Conference into */ const char *recordingfilename; /* Filename to record the Conference into */
char *recordingformat; /* Format to record the Conference in */ const char *recordingformat; /* Format to record the Conference in */
char pin[AST_MAX_EXTENSION]; /* If protected by a PIN */ char pin[AST_MAX_EXTENSION]; /* If protected by a PIN */
char pinadmin[AST_MAX_EXTENSION]; /* If protected by a admin PIN */ char pinadmin[AST_MAX_EXTENSION]; /* If protected by a admin PIN */
struct ast_conference *next; struct ast_conference *next;
@ -813,8 +813,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
int duration=20; int duration=20;
struct ast_dsp *dsp=NULL; struct ast_dsp *dsp=NULL;
struct ast_app *app; struct ast_app *app;
char *agifile; const char *agifile;
char *agifiledefault = "conf-background.agi"; const char *agifiledefault = "conf-background.agi";
char meetmesecs[30] = ""; char meetmesecs[30] = "";
char exitcontext[AST_MAX_CONTEXT] = ""; char exitcontext[AST_MAX_CONTEXT] = "";
char recordingtmp[AST_MAX_EXTENSION] = ""; char recordingtmp[AST_MAX_EXTENSION] = "";
@ -1086,7 +1086,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
/* Find a pointer to the agi app and execute the script */ /* Find a pointer to the agi app and execute the script */
app = pbx_findapp("agi"); app = pbx_findapp("agi");
if (app) { if (app) {
ret = pbx_exec(chan, app, agifile, 1); char *s = ast_strdupa(agifile);
ret = pbx_exec(chan, app, s, 1);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (agi)\n"); ast_log(LOG_WARNING, "Could not find application (agi)\n");
ret = -2; ret = -2;

@ -1992,7 +1992,6 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
char oldcontext[AST_MAX_CONTEXT]=""; char oldcontext[AST_MAX_CONTEXT]="";
char queuename[256]=""; char queuename[256]="";
char *newnum; char *newnum;
char *monitorfilename;
struct ast_channel *peer; struct ast_channel *peer;
struct ast_channel *which; struct ast_channel *which;
struct localuser *lpeer; struct localuser *lpeer;
@ -2209,7 +2208,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
} }
/* Begin Monitoring */ /* Begin Monitoring */
if (qe->parent->monfmt && *qe->parent->monfmt) { if (qe->parent->monfmt && *qe->parent->monfmt) {
monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME"); const char *monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME");
if (pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC") || pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC_ARGS")) if (pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC") || pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC_ARGS"))
which = qe->chan; which = qe->chan;
else else
@ -2845,7 +2844,7 @@ static int queue_exec(struct ast_channel *chan, void *data)
char *options = NULL; char *options = NULL;
char *url = NULL; char *url = NULL;
char *announceoverride = NULL; char *announceoverride = NULL;
char *user_priority; const char *user_priority;
int prio; int prio;
char *queuetimeoutstr = NULL; char *queuetimeoutstr = NULL;
enum queue_result reason = QUEUE_UNKNOWN; enum queue_result reason = QUEUE_UNKNOWN;

@ -82,7 +82,7 @@ static int pop_exec(struct ast_channel *chan, void *data)
static int return_exec(struct ast_channel *chan, void *data) static int return_exec(struct ast_channel *chan, void *data)
{ {
char *label = pbx_builtin_getvar_helper(chan, STACKVAR); const char *label = pbx_builtin_getvar_helper(chan, STACKVAR);
if (ast_strlen_zero(label)) { if (ast_strlen_zero(label)) {
ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n"); ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");

@ -122,7 +122,7 @@ static int execif_exec(struct ast_channel *chan, void *data) {
#define VAR_SIZE 64 #define VAR_SIZE 64
static char *get_index(struct ast_channel *chan, const char *prefix, int index) { static const char *get_index(struct ast_channel *chan, const char *prefix, int index) {
char varname[VAR_SIZE]; char varname[VAR_SIZE];
snprintf(varname, VAR_SIZE, "%s_%d", prefix, index); snprintf(varname, VAR_SIZE, "%s_%d", prefix, index);
@ -209,9 +209,9 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
{ {
int res=0; int res=0;
struct localuser *u; struct localuser *u;
char *while_pri = NULL; const char *while_pri = NULL;
char *goto_str = NULL, *my_name = NULL; char *my_name = NULL;
char *condition = NULL, *label = NULL; const char *condition = NULL, *label = NULL;
char varname[VAR_SIZE], end_varname[VAR_SIZE]; char varname[VAR_SIZE], end_varname[VAR_SIZE];
const char *prefix = "WHILE"; const char *prefix = "WHILE";
size_t size=0; size_t size=0;
@ -271,6 +271,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
if (!end && !ast_true(condition)) { if (!end && !ast_true(condition)) {
/* Condition Met (clean up helper vars) */ /* Condition Met (clean up helper vars) */
const char *goto_str;
pbx_builtin_setvar_helper(chan, varname, NULL); pbx_builtin_setvar_helper(chan, varname, NULL);
pbx_builtin_setvar_helper(chan, my_name, NULL); pbx_builtin_setvar_helper(chan, my_name, NULL);
snprintf(end_varname,VAR_SIZE,"END_%s",varname); snprintf(end_varname,VAR_SIZE,"END_%s",varname);
@ -291,6 +292,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
} }
if (!end && !while_pri) { if (!end && !while_pri) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32; size = strlen(chan->context) + strlen(chan->exten) + 32;
goto_str = alloca(size); goto_str = alloca(size);
memset(goto_str, 0, size); memset(goto_str, 0, size);
@ -302,6 +304,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
/* END of loop */ /* END of loop */
snprintf(end_varname, VAR_SIZE, "END_%s", varname); snprintf(end_varname, VAR_SIZE, "END_%s", varname);
if (! pbx_builtin_getvar_helper(chan, end_varname)) { if (! pbx_builtin_getvar_helper(chan, end_varname)) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32; size = strlen(chan->context) + strlen(chan->exten) + 32;
goto_str = alloca(size); goto_str = alloca(size);
memset(goto_str, 0, size); memset(goto_str, 0, size);

@ -296,7 +296,6 @@ static int conf_exec(struct ast_channel *chan, void *data)
char confstr[80] = "", *tmp = NULL; char confstr[80] = "", *tmp = NULL;
struct ast_channel *tempchan = NULL, *lastchan = NULL,*ichan = NULL; struct ast_channel *tempchan = NULL, *lastchan = NULL,*ichan = NULL;
struct ast_frame *f; struct ast_frame *f;
char *mygroup;
char *desired_group; char *desired_group;
int input=0,search_group=0; int input=0,search_group=0;
@ -335,6 +334,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
break; break;
if (tempchan && search_group) { if (tempchan && search_group) {
const char *mygroup;
if((mygroup = pbx_builtin_getvar_helper(tempchan, "GROUP")) && (!strcmp(mygroup, desired_group))) { if((mygroup = pbx_builtin_getvar_helper(tempchan, "GROUP")) && (!strcmp(mygroup, desired_group))) {
ast_verbose(VERBOSE_PREFIX_3 "Found Matching Channel %s in group %s\n", tempchan->name, desired_group); ast_verbose(VERBOSE_PREFIX_3 "Found Matching Channel %s in group %s\n", tempchan->name, desired_group);
} else { } else {

@ -2770,7 +2770,7 @@ void ast_change_name(struct ast_channel *chan, char *newname)
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child) void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
{ {
struct ast_var_t *current, *newvar; struct ast_var_t *current, *newvar;
char *varname; const char *varname;
AST_LIST_TRAVERSE(&parent->varshead, current, entries) { AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
int vartype = 0; int vartype = 0;
@ -3159,7 +3159,7 @@ struct ast_channel *ast_bridged_channel(struct ast_channel *chan)
return bridged; return bridged;
} }
static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer, char *sound, int remain) static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain)
{ {
int res=0, min=0, sec=0,check=0; int res=0, min=0, sec=0,check=0;

@ -1686,7 +1686,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
AST_APP_ARG(options); AST_APP_ARG(options);
AST_APP_ARG(extension); AST_APP_ARG(extension);
); );
char *tmpoptions = NULL; const char *tmpoptions = NULL;
char *context = NULL; char *context = NULL;
int play_announcement = 1; int play_announcement = 1;
char agent_goodbye[AST_MAX_FILENAME_LEN]; char agent_goodbye[AST_MAX_FILENAME_LEN];
@ -2231,7 +2231,7 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
int nowarnings = 0; int nowarnings = 0;
int changeoutgoing = 0; int changeoutgoing = 0;
int res = 0; int res = 0;
char agent[AST_MAX_AGENT], *tmp; char agent[AST_MAX_AGENT];
if (data) { if (data) {
if (strchr(data, 'd')) if (strchr(data, 'd'))
@ -2242,6 +2242,7 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
changeoutgoing = 1; changeoutgoing = 1;
} }
if (chan->cid.cid_num) { if (chan->cid.cid_num) {
const char *tmp;
char agentvar[AST_MAX_BUF]; char agentvar[AST_MAX_BUF];
snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num); snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num);
if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) { if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) {

@ -9137,7 +9137,6 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
char odata[256]; char odata[256];
char req[256]; char req[256];
char *ncontext; char *ncontext;
char *dialstatus;
struct iax2_dpcache *dp; struct iax2_dpcache *dp;
struct ast_app *dial; struct ast_app *dial;
#if 0 #if 0
@ -9145,7 +9144,7 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
#endif #endif
if (priority == 2) { if (priority == 2) {
/* Indicate status, can be overridden in dialplan */ /* Indicate status, can be overridden in dialplan */
dialstatus = pbx_builtin_getvar_helper(chan, "DIALSTATUS"); const char *dialstatus = pbx_builtin_getvar_helper(chan, "DIALSTATUS");
if (dialstatus) { if (dialstatus) {
dial = pbx_findapp(dialstatus); dial = pbx_findapp(dialstatus);
if (dial) if (dial)

@ -889,7 +889,7 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
struct mgcp_endpoint *p; struct mgcp_endpoint *p;
struct mgcp_subchannel *sub; struct mgcp_subchannel *sub;
char tone[50] = ""; char tone[50] = "";
char *distinctive_ring = NULL; const char *distinctive_ring = NULL;
struct varshead *headp; struct varshead *headp;
struct ast_var_t *current; struct ast_var_t *current;

@ -462,11 +462,11 @@ struct sip_pkt;
/*! \brief Parameters to the transmit_invite function */ /*! \brief Parameters to the transmit_invite function */
struct sip_invite_param { struct sip_invite_param {
char *distinctive_ring; /*!< Distinctive ring header */ const char *distinctive_ring; /*!< Distinctive ring header */
char *osptoken; /*!< OSP token for this call */ char *osptoken; /*!< OSP token for this call */
int addsipheaders; /*!< Add extra SIP headers */ int addsipheaders; /*!< Add extra SIP headers */
char *uri_options; /*!< URI options to add to the URI */ const char *uri_options; /*!< URI options to add to the URI */
char *vxml_url; /*!< VXML url for Cisco phones */ const char *vxml_url; /*!< VXML url for Cisco phones */
char *auth; /*!< Authentication */ char *auth; /*!< Authentication */
char *authheader; /*!< Auth header */ char *authheader; /*!< Auth header */
enum sip_auth_type auth_type; /*!< Authentication type */ enum sip_auth_type auth_type; /*!< Authentication type */
@ -2478,7 +2478,7 @@ static int sip_hangup(struct ast_channel *ast)
static int sip_answer(struct ast_channel *ast) static int sip_answer(struct ast_channel *ast)
{ {
int res = 0,fmt; int res = 0,fmt;
char *codec; const char *codec;
struct sip_pvt *p = ast->tech_pvt; struct sip_pvt *p = ast->tech_pvt;
ast_mutex_lock(&p->lock); ast_mutex_lock(&p->lock);

@ -1932,7 +1932,7 @@ static int zt_call(struct ast_channel *ast, char *rdest, int timeout)
break; break;
case SIG_FEATDMF_TA: case SIG_FEATDMF_TA:
{ {
char *cic = NULL, *ozz = NULL; const char *cic, *ozz;
/* If you have to go through a Tandem Access point you need to use this */ /* If you have to go through a Tandem Access point you need to use this */
ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ"); ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");

@ -59,31 +59,27 @@ void ast_var_delete(struct ast_var_t *var)
free(var); free(var);
} }
char *ast_var_name(struct ast_var_t *var) const char *ast_var_name(const struct ast_var_t *var)
{ {
char *name; const char *name;
if (var == NULL) if (var == NULL || (name = var->name) == NULL)
return NULL;
if (var->name == NULL)
return NULL; return NULL;
/* Return the name without the initial underscores */ /* Return the name without the initial underscores */
if (var->name[0] == '_') { if (name[0] == '_') {
if (var->name[1] == '_') name++;
name = (char*)&(var->name[2]); if (name[0] == '_')
else name++;
name = (char*)&(var->name[1]); }
} else
name = var->name;
return name; return name;
} }
char *ast_var_full_name(struct ast_var_t *var) const char *ast_var_full_name(const struct ast_var_t *var)
{ {
return (var ? var->name : NULL); return (var ? var->name : NULL);
} }
char *ast_var_value(struct ast_var_t *var) const char *ast_var_value(const struct ast_var_t *var)
{ {
return (var ? var->value : NULL); return (var ? var->value : NULL);
} }

@ -539,7 +539,7 @@ static struct ast_codec_alias_table {
{"g723.1","g723"}, {"g723.1","g723"},
}; };
static char *ast_expand_codec_alias(char *in) { static const char *ast_expand_codec_alias(const char *in) {
int x = 0; int x = 0;
for (x = 0; x < sizeof(ast_codec_alias_table) / sizeof(struct ast_codec_alias_table) ; x++) { for (x = 0; x < sizeof(ast_codec_alias_table) / sizeof(struct ast_codec_alias_table) ; x++) {
@ -549,7 +549,7 @@ static char *ast_expand_codec_alias(char *in) {
return in; return in;
} }
int ast_getformatbyname(char *name) int ast_getformatbyname(const char *name)
{ {
int x = 0, all = 0, format = 0; int x = 0, all = 0, format = 0;

@ -40,7 +40,7 @@ static char *group_count_function_read(struct ast_channel *chan, char *cmd, char
int count; int count;
char group[80] = ""; char group[80] = "";
char category[80] = ""; char category[80] = "";
char *grp; const char *grp;
ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
@ -101,7 +101,7 @@ struct ast_custom_function group_match_count_function = {
static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{ {
char varname[256]; char varname[256];
char *group; const char *group;
if (!ast_strlen_zero(data)) { if (!ast_strlen_zero(data)) {
snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data); snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data);

@ -167,16 +167,16 @@ char *ast_read_textfile(const char *file);
#define GROUP_CATEGORY_PREFIX "GROUP" #define GROUP_CATEGORY_PREFIX "GROUP"
/*! Split a group string into group and category, returning a default category if none is provided. */ /*! Split a group string into group and category, returning a default category if none is provided. */
int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max); int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max);
/*! Set the group for a channel, splitting the provided data into group and category, if specified. */ /*! Set the group for a channel, splitting the provided data into group and category, if specified. */
int ast_app_group_set_channel(struct ast_channel *chan, char *data); int ast_app_group_set_channel(struct ast_channel *chan, const char *data);
/*! Get the current channel count of the specified group and category. */ /*! Get the current channel count of the specified group and category. */
int ast_app_group_get_count(char *group, char *category); int ast_app_group_get_count(const char *group, const char *category);
/*! Get the current channel count of all groups that match the specified pattern and category. */ /*! Get the current channel count of all groups that match the specified pattern and category. */
int ast_app_group_match_get_count(char *groupmatch, char *category); int ast_app_group_match_get_count(const char *groupmatch, const char *category);
/*! /*!
\brief Define an application argument \brief Define an application argument

@ -454,9 +454,9 @@ struct ast_bridge_config {
long timelimit; long timelimit;
long play_warning; long play_warning;
long warning_freq; long warning_freq;
char *warning_sound; const char *warning_sound;
char *end_sound; const char *end_sound;
char *start_sound; const char *start_sound;
int firstpass; int firstpass;
unsigned int flags; unsigned int flags;
}; };

@ -35,8 +35,8 @@ AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
struct ast_var_t *ast_var_assign(const char *name, const char *value); struct ast_var_t *ast_var_assign(const char *name, const char *value);
void ast_var_delete(struct ast_var_t *var); void ast_var_delete(struct ast_var_t *var);
char *ast_var_name(struct ast_var_t *var); const char *ast_var_name(const struct ast_var_t *var);
char *ast_var_full_name(struct ast_var_t *var); const char *ast_var_full_name(const struct ast_var_t *var);
char *ast_var_value(struct ast_var_t *var); const char *ast_var_value(const struct ast_var_t *var);
#endif /* _ASTERISK_CHANVARS_H */ #endif /* _ASTERISK_CHANVARS_H */

@ -389,7 +389,7 @@ extern char* ast_getformatname_multiple(char *buf, size_t size, int format);
* \param name string of format * \param name string of format
* \return This returns the form of the format in binary on success, 0 on error. * \return This returns the form of the format in binary on success, 0 on error.
*/ */
extern int ast_getformatbyname(char *name); extern int ast_getformatbyname(const char *name);
/*! \brief Get a name from a format /*! \brief Get a name from a format
* Gets a name from a format * Gets a name from a format

@ -605,7 +605,7 @@ struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw); struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size); int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
extern char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name); extern const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
extern void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value); extern void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
extern void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value); extern void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);
extern void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp); extern void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp);
@ -620,11 +620,11 @@ int ast_extension_patmatch(const char *pattern, const char *data);
set to 1, sets to auto fall through. If newval set to 0, sets to no auto set to 1, sets to auto fall through. If newval set to 0, sets to no auto
fall through (reads extension instead). Returns previous value. */ fall through (reads extension instead). Returns previous value. */
extern int pbx_set_autofallthrough(int newval); extern int pbx_set_autofallthrough(int newval);
int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority); int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
/* I can find neither parsable nor parseable at dictionary.com, but google gives me 169000 hits for parseable and only 49,800 for parsable */ /* I can find neither parsable nor parseable at dictionary.com, but google gives me 169000 hits for parseable and only 49,800 for parsable */
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string); int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority); int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority); int ast_async_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
struct ast_custom_function* ast_custom_function_find(char *name); struct ast_custom_function* ast_custom_function_find(char *name);
int ast_custom_function_unregister(struct ast_custom_function *acf); int ast_custom_function_unregister(struct ast_custom_function *acf);

@ -726,7 +726,7 @@ static int action_getvar(struct mansession *s, struct message *m)
char *name = astman_get_header(m, "Channel"); char *name = astman_get_header(m, "Channel");
char *varname = astman_get_header(m, "Variable"); char *varname = astman_get_header(m, "Variable");
char *id = astman_get_header(m,"ActionID"); char *id = astman_get_header(m,"ActionID");
char *varval; const char *varval;
char *varval2=NULL; char *varval2=NULL;
if (!strlen(varname)) { if (!strlen(varname)) {

24
pbx.c

@ -1129,9 +1129,9 @@ icky:
ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables)); ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
#endif #endif
if (strcasecmp(ast_var_name(variables),var)==0) { if (strcasecmp(ast_var_name(variables),var)==0) {
*ret=ast_var_value(variables); const char *s = ast_var_value(variables);
if (*ret) { if (s) {
ast_copy_string(workspace, *ret, workspacelen); ast_copy_string(workspace, s, workspacelen);
*ret = workspace; *ret = workspace;
} }
break; break;
@ -1145,9 +1145,9 @@ icky:
ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables)); ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
#endif #endif
if (strcasecmp(ast_var_name(variables),var)==0) { if (strcasecmp(ast_var_name(variables),var)==0) {
*ret = ast_var_value(variables); const char *s = ast_var_value(variables);
if (*ret) { if (s) {
ast_copy_string(workspace, *ret, workspacelen); ast_copy_string(workspace, s, workspacelen);
*ret = workspace; *ret = workspace;
} }
} }
@ -2413,7 +2413,7 @@ static int __ast_pbx_run(struct ast_channel *c)
ast_cdr_update(c); ast_cdr_update(c);
} }
} else { } else {
char *status; const char *status;
status = pbx_builtin_getvar_helper(c, "DIALSTATUS"); status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
if (!status) if (!status)
@ -5846,7 +5846,7 @@ static int pbx_builtin_goto(struct ast_channel *chan, void *data)
int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size) int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size)
{ {
struct ast_var_t *variables; struct ast_var_t *variables;
char *var, *val; const char *var, *val;
int total = 0; int total = 0;
if (!chan) if (!chan)
@ -5870,7 +5870,7 @@ int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t
return total; return total;
} }
char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name) const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
{ {
struct ast_var_t *variables; struct ast_var_t *variables;
struct varshead *headp; struct varshead *headp;
@ -6383,7 +6383,7 @@ int ast_context_verify_includes(struct ast_context *con)
} }
static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *exten, int priority, int async) static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
{ {
int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority); int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
@ -6400,11 +6400,11 @@ static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *e
return -3; return -3;
} }
int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) { int ast_goto_if_exists(struct ast_channel *chan, const char* context, const char *exten, int priority) {
return __ast_goto_if_exists(chan, context, exten, priority, 0); return __ast_goto_if_exists(chan, context, exten, priority, 0);
} }
int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) { int ast_async_goto_if_exists(struct ast_channel *chan, const char * context, const char *exten, int priority) {
return __ast_goto_if_exists(chan, context, exten, priority, 1); return __ast_goto_if_exists(chan, context, exten, priority, 1);
} }

@ -180,18 +180,14 @@ struct ast_bridge_thread_obj
static void check_goto_on_transfer(struct ast_channel *chan) static void check_goto_on_transfer(struct ast_channel *chan)
{ {
struct ast_channel *xferchan; struct ast_channel *xferchan;
char *goto_on_transfer; const char *val = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
char *x, *goto_on_transfer;
goto_on_transfer = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR"); struct ast_frame *f;
if (!ast_strlen_zero(goto_on_transfer) && (xferchan = ast_channel_alloc(0))) {
char *x;
struct ast_frame *f;
if (!ast_strlen_zero(val) && (goto_on_transfer = ast_strdupa(val)) && (xferchan = ast_channel_alloc(0))) {
for (x = goto_on_transfer; x && *x; x++) for (x = goto_on_transfer; x && *x; x++)
if (*x == '^') if (*x == '^')
*x = '|'; *x = '|';
strcpy(xferchan->name, chan->name); strcpy(xferchan->name, chan->name);
/* Make formats okay */ /* Make formats okay */
xferchan->readformat = chan->readformat; xferchan->readformat = chan->readformat;
@ -446,7 +442,7 @@ int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int
static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense) static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
{ {
char *touch_monitor = NULL, *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_format = NULL; char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL;
int x = 0; int x = 0;
size_t len; size_t len;
struct ast_channel *caller_chan = NULL, *callee_chan = NULL; struct ast_channel *caller_chan = NULL, *callee_chan = NULL;
@ -494,11 +490,12 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee
} }
if (caller_chan && callee_chan) { if (caller_chan && callee_chan) {
touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT"); const char *touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT");
const char *touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
if (!touch_format) if (!touch_format)
touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_FORMAT"); touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_FORMAT");
touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
if (!touch_monitor) if (!touch_monitor)
touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR"); touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR");
@ -541,7 +538,7 @@ static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *p
{ {
struct ast_channel *transferer; struct ast_channel *transferer;
struct ast_channel *transferee; struct ast_channel *transferee;
char *transferer_real_context; const char *transferer_real_context;
char newext[256]; char newext[256];
int res; int res;
@ -670,7 +667,7 @@ static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, st
struct ast_channel *newchan, *xferchan=NULL; struct ast_channel *newchan, *xferchan=NULL;
int outstate=0; int outstate=0;
struct ast_bridge_config bconfig; struct ast_bridge_config bconfig;
char *transferer_real_context; const char *transferer_real_context;
char xferto[256],dialstr[265]; char xferto[256],dialstr[265];
char *cid_num; char *cid_num;
char *cid_name; char *cid_name;
@ -981,7 +978,7 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
struct ast_flags features; struct ast_flags features;
int res = FEATURE_RETURN_PASSDIGITS; int res = FEATURE_RETURN_PASSDIGITS;
struct ast_call_feature *feature; struct ast_call_feature *feature;
char *dynamic_features=pbx_builtin_getvar_helper(chan,"DYNAMIC_FEATURES"); const char *dynamic_features=pbx_builtin_getvar_helper(chan,"DYNAMIC_FEATURES");
if (sense == FEATURE_SENSE_CHAN) if (sense == FEATURE_SENSE_CHAN)
ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL); ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
@ -1047,9 +1044,7 @@ static void set_config_flags(struct ast_channel *chan, struct ast_channel *peer,
} }
if (chan && peer && !(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) { if (chan && peer && !(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) {
char *dynamic_features; const char *dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
if (dynamic_features) { if (dynamic_features) {
char *tmp = ast_strdupa(dynamic_features); char *tmp = ast_strdupa(dynamic_features);
@ -1261,7 +1256,6 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
struct ast_option_header *aoh; struct ast_option_header *aoh;
struct timeval start = { 0 , 0 }; struct timeval start = { 0 , 0 };
struct ast_bridge_config backup_config; struct ast_bridge_config backup_config;
char *monitor_exec;
memset(&backup_config, 0, sizeof(backup_config)); memset(&backup_config, 0, sizeof(backup_config));
@ -1274,14 +1268,24 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL); pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
if (monitor_ok) { if (monitor_ok) {
const char *monitor_exec;
struct ast_channel *src = NULL;
if (!monitor_app) { if (!monitor_app) {
if (!(monitor_app = pbx_findapp("Monitor"))) if (!(monitor_app = pbx_findapp("Monitor")))
monitor_ok=0; monitor_ok=0;
} }
if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR")))
pbx_exec(chan, monitor_app, monitor_exec, 1); src = chan;
else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR"))) else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
pbx_exec(peer, monitor_app, monitor_exec, 1); src = peer;
if (src) {
char *tmp = ast_strdupa(monitor_exec);
if (tmp) {
pbx_exec(src, monitor_app, tmp, 1);
} else {
ast_log(LOG_ERROR, "Monitor failed: out of memory\n");
}
}
} }
set_config_flags(chan, peer, config); set_config_flags(chan, peer, config);

@ -212,7 +212,6 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
/* Stop monitoring a channel */ /* Stop monitoring a channel */
int ast_monitor_stop(struct ast_channel *chan, int need_lock) int ast_monitor_stop(struct ast_channel *chan, int need_lock)
{ {
char *execute, *execute_args;
int delfiles = 0; int delfiles = 0;
if (need_lock) { if (need_lock) {
@ -261,6 +260,7 @@ int ast_monitor_stop(struct ast_channel *chan, int need_lock)
char *name = chan->monitor->filename_base; char *name = chan->monitor->filename_base;
int directory = strchr(name, '/') ? 1 : 0; int directory = strchr(name, '/') ? 1 : 0;
char *dir = directory ? "" : ast_config_AST_MONITOR_DIR; char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
const char *execute, *execute_args;
/* Set the execute application */ /* Set the execute application */
execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC"); execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");

Loading…
Cancel
Save