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
This commit is contained in:
Tilghman Lesher
2005-12-03 19:25:33 +00:00
parent 6a6b88c0e3
commit 870f98f02d
27 changed files with 117 additions and 116 deletions

View File

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

View File

@@ -56,7 +56,6 @@ static int group_count_exec(struct ast_channel *chan, void *data)
char group[80] = "";
char category[80] = "";
char ret[80] = "";
char *grp;
static int deprecation_warning = 0;
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));
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);
}

View File

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

View File

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

View File

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

View File

@@ -82,7 +82,7 @@ static int pop_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)) {
ast_log(LOG_ERROR, "Return without Gosub: stack is empty\n");

View File

@@ -122,7 +122,7 @@ static int execif_exec(struct ast_channel *chan, void *data) {
#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];
snprintf(varname, VAR_SIZE, "%s_%d", prefix, index);
@@ -209,15 +209,15 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
{
int res=0;
struct localuser *u;
char *while_pri = NULL;
char *goto_str = NULL, *my_name = NULL;
char *condition = NULL, *label = NULL;
const char *while_pri = NULL;
char *my_name = NULL;
const char *condition = NULL, *label = NULL;
char varname[VAR_SIZE], end_varname[VAR_SIZE];
const char *prefix = "WHILE";
size_t size=0;
int used_index_i = -1, x=0;
char used_index[VAR_SIZE] = "0", new_index[VAR_SIZE] = "0";
if (!chan) {
/* huh ? */
return -1;
@@ -271,6 +271,7 @@ static int _while_exec(struct ast_channel *chan, void *data, int end)
if (!end && !ast_true(condition)) {
/* Condition Met (clean up helper vars) */
const char *goto_str;
pbx_builtin_setvar_helper(chan, varname, NULL);
pbx_builtin_setvar_helper(chan, my_name, NULL);
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) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32;
goto_str = alloca(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 */
snprintf(end_varname, VAR_SIZE, "END_%s", varname);
if (! pbx_builtin_getvar_helper(chan, end_varname)) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32;
goto_str = alloca(size);
memset(goto_str, 0, size);

View File

@@ -296,7 +296,6 @@ static int conf_exec(struct ast_channel *chan, void *data)
char confstr[80] = "", *tmp = NULL;
struct ast_channel *tempchan = NULL, *lastchan = NULL,*ichan = NULL;
struct ast_frame *f;
char *mygroup;
char *desired_group;
int input=0,search_group=0;
@@ -335,6 +334,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
break;
if (tempchan && search_group) {
const char *mygroup;
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);
} else {