a few syntax changes and safer code

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@103682 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jeff Peeler
2008-02-14 19:47:39 +00:00
parent a38a5d9ab6
commit 5404ab35e2

View File

@@ -230,16 +230,16 @@ static void ast_eivr_getvariable(struct ast_channel *chan, char *data, char *out
{ {
/* original input data: "G,var1,var2," */ /* original input data: "G,var1,var2," */
/* data passed as "data": "var1,var2" */ /* data passed as "data": "var1,var2" */
char *inbuf, *variable; char *inbuf, *variable;
const char *value; const char *value;
char *saveptr;
int j; int j;
struct ast_str *newstring = ast_str_alloca(outbuflen);
outbuf[0] = 0; outbuf[0] = '\0';
for (j = 1, inbuf = data; ; j++, inbuf = NULL) { for (j = 1, inbuf = data; ; j++) {
variable = strtok_r(inbuf, ",", &saveptr); variable = strsep(&inbuf, ",");
if (variable == NULL) { if (variable == NULL) {
int outstrlen = strlen(outbuf); int outstrlen = strlen(outbuf);
if(outstrlen && outbuf[outstrlen - 1] == ',') { if(outstrlen && outbuf[outstrlen - 1] == ',') {
@@ -251,10 +251,8 @@ static void ast_eivr_getvariable(struct ast_channel *chan, char *data, char *out
value = pbx_builtin_getvar_helper(chan, variable); value = pbx_builtin_getvar_helper(chan, variable);
if(!value) if(!value)
value = ""; value = "";
strncat(outbuf,variable,outbuflen); ast_str_append(&newstring, 0, "%s=%s,", variable, value);
strncat(outbuf,"=",outbuflen); ast_copy_string(outbuf, newstring->str, outbuflen);
strncat(outbuf,value,outbuflen);
strncat(outbuf,",",outbuflen);
} }
}; };
@@ -265,28 +263,24 @@ static void ast_eivr_setvariable(struct ast_channel *chan, char *data)
char *inbuf, *variable; char *inbuf, *variable;
char *saveptr;
int j; int j;
for(j=1, inbuf=data; ; j++, inbuf=NULL) { for (j = 1, inbuf = data; ; j++, inbuf = NULL) {
variable = strtok_r(inbuf, ",", &saveptr); variable = strsep(&inbuf, ",");
ast_chan_log(LOG_DEBUG, chan, "Setting up a variable: %s\n", variable); ast_chan_log(LOG_DEBUG, chan, "Setting up a variable: %s\n", variable);
if(variable) { if(variable) {
/* variable contains "varname=value" */ /* variable contains "varname=value" */
strncpy(buf, variable, sizeof(buf)); ast_copy_string(buf, variable, sizeof(buf));
value = strchr(buf, '='); value = strchr(buf, '=');
if(!value) if(!value)
value=""; value="";
else { else
value[0] = 0; *value++ = '\0';
value++;
}
pbx_builtin_setvar_helper(chan, buf, value); pbx_builtin_setvar_helper(chan, buf, value);
} }
else break; else
break;
} }
}; };
static struct playlist_entry *make_entry(const char *filename) static struct playlist_entry *make_entry(const char *filename)