dect
/
asterisk
Archived
13
0
Fork 0

simplify logic in various functions, remove unnecessary variables

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@21099 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
rizzo 2006-04-18 13:37:07 +00:00
parent 37bc058d8d
commit 3f25044e55
1 changed files with 31 additions and 60 deletions

81
pbx.c
View File

@ -5396,8 +5396,7 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data)
*/ */
static int pbx_builtin_goto(struct ast_channel *chan, void *data) static int pbx_builtin_goto(struct ast_channel *chan, void *data)
{ {
int res; int res = ast_parseable_goto(chan, (const char *) data);
res = ast_parseable_goto(chan, (const char *) data);
if (!res && (option_verbose > 2)) if (!res && (option_verbose > 2))
ast_verbose( VERBOSE_PREFIX_3 "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1); ast_verbose( VERBOSE_PREFIX_3 "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
return res; return res;
@ -5560,8 +5559,7 @@ int pbx_builtin_setvar(struct ast_channel *chan, void *data)
for (x = 0; x < argc; x++) { for (x = 0; x < argc; x++) {
name = argv[x]; name = argv[x];
if ((value = strchr(name, '='))) { if ((value = strchr(name, '='))) {
*value = '\0'; *value++ = '\0';
value++;
pbx_builtin_setvar_helper((global) ? NULL : chan, name, value); pbx_builtin_setvar_helper((global) ? NULL : chan, name, value);
} else } else
ast_log(LOG_WARNING, "Ignoring entry '%s' with no = (and not last 'options' entry)\n", name); ast_log(LOG_WARNING, "Ignoring entry '%s' with no = (and not last 'options' entry)\n", name);
@ -5574,25 +5572,21 @@ int pbx_builtin_importvar(struct ast_channel *chan, void *data)
{ {
char *name; char *name;
char *value; char *value;
char *stringp=NULL;
char *channel; char *channel;
struct ast_channel *chan2;
char tmp[VAR_BUF_SIZE]=""; char tmp[VAR_BUF_SIZE]="";
char *s;
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n"); ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
return 0; return 0;
} }
stringp = ast_strdupa(data); value = ast_strdupa(data);
name = strsep(&stringp,"="); name = strsep(&value,"=");
channel = strsep(&stringp,"|"); channel = strsep(&value,"|");
value = strsep(&stringp,"\0"); if (channel && value && name) { /*! \todo XXX should do !ast_strlen_zero(..) of the args ? */
if (channel && value && name) { struct ast_channel *chan2 = ast_get_channel_by_name_locked(channel);
chan2 = ast_get_channel_by_name_locked(channel);
if (chan2) { if (chan2) {
s = alloca(strlen(value) + 4); char *s = alloca(strlen(value) + 4);
if (s) { if (s) {
sprintf(s, "${%s}", value); sprintf(s, "${%s}", value);
pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1); pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
@ -5605,22 +5599,20 @@ int pbx_builtin_importvar(struct ast_channel *chan, void *data)
return(0); return(0);
} }
/*! \todo XXX overwrites data ? */
static int pbx_builtin_setglobalvar(struct ast_channel *chan, void *data) static int pbx_builtin_setglobalvar(struct ast_channel *chan, void *data)
{ {
char *name; char *name;
char *value; char *stringp = data;
char *stringp = NULL;
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n"); ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
return 0; return 0;
} }
stringp = data;
name = strsep(&stringp, "="); name = strsep(&stringp, "=");
value = strsep(&stringp, "\0"); /*! \todo XXX watch out, leading whitespace ? */
pbx_builtin_setvar_helper(NULL, name, stringp);
pbx_builtin_setvar_helper(NULL, name, value);
return(0); return(0);
} }
@ -5630,7 +5622,6 @@ static int pbx_builtin_noop(struct ast_channel *chan, void *data)
return 0; return 0;
} }
void pbx_builtin_clear_globals(void) void pbx_builtin_clear_globals(void)
{ {
struct ast_var_t *vardata; struct ast_var_t *vardata;
@ -5643,27 +5634,17 @@ void pbx_builtin_clear_globals(void)
int pbx_checkcondition(char *condition) int pbx_checkcondition(char *condition)
{ {
if (condition) { if (ast_strlen_zero(condition)) /* NULL or empty strings are false */
if (*condition == '\0') {
/* Empty strings are false */
return 0; return 0;
} else if (*condition >= '0' && *condition <= '9') { else if (*condition >= '0' && *condition <= '9') /* Numbers are evaluated for truth */
/* Numbers are evaluated for truth */
return atoi(condition); return atoi(condition);
} else { else /* Strings are true */
/* Strings are true */
return 1; return 1;
} }
} else {
/* NULL is also false */
return 0;
}
}
static int pbx_builtin_gotoif(struct ast_channel *chan, void *data) static int pbx_builtin_gotoif(struct ast_channel *chan, void *data)
{ {
char *condition, *branch1, *branch2, *branch; char *condition, *branch1, *branch2, *branch;
char *s;
int rc; int rc;
char *stringp=NULL; char *stringp=NULL;
@ -5672,8 +5653,7 @@ static int pbx_builtin_gotoif(struct ast_channel *chan, void *data)
return 0; return 0;
} }
s = ast_strdupa(data); stringp = ast_strdupa(data);
stringp = s;
condition = strsep(&stringp,"?"); condition = strsep(&stringp,"?");
branch1 = strsep(&stringp,":"); branch1 = strsep(&stringp,":");
branch2 = strsep(&stringp,""); branch2 = strsep(&stringp,"");
@ -5691,18 +5671,15 @@ static int pbx_builtin_gotoif(struct ast_channel *chan, void *data)
static int pbx_builtin_saynumber(struct ast_channel *chan, void *data) static int pbx_builtin_saynumber(struct ast_channel *chan, void *data)
{ {
int res = 0;
char tmp[256]; char tmp[256];
char *number = (char *) NULL; char *number = tmp;
char *options = (char *) NULL; char *options;
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n"); ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
return -1; return -1;
} }
ast_copy_string(tmp, (char *) data, sizeof(tmp)); ast_copy_string(tmp, data, sizeof(tmp));
number=tmp;
strsep(&number, "|"); strsep(&number, "|");
options = strsep(&number, "|"); options = strsep(&number, "|");
if (options) { if (options) {
@ -5712,7 +5689,7 @@ static int pbx_builtin_saynumber(struct ast_channel *chan, void *data)
return -1; return -1;
} }
} }
return res = ast_say_number(chan, atoi((char *) tmp), "", chan->language, options); return ast_say_number(chan, atoi(tmp), "", chan->language, options);
} }
static int pbx_builtin_saydigits(struct ast_channel *chan, void *data) static int pbx_builtin_saydigits(struct ast_channel *chan, void *data)
@ -5982,9 +5959,8 @@ int ast_async_goto_if_exists(struct ast_channel *chan, const char * context, con
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
{ {
char *s;
char *exten, *pri, *context; char *exten, *pri, *context;
char *stringp=NULL; char *stringp;
int ipri; int ipri;
int mode = 0; int mode = 0;
@ -5992,24 +5968,19 @@ int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n"); ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n");
return -1; return -1;
} }
s = ast_strdupa(goto_string); stringp = ast_strdupa(goto_string);
stringp=s; context = strsep(&stringp, "|"); /* guaranteed non-null */
context = strsep(&stringp, "|");
exten = strsep(&stringp, "|"); exten = strsep(&stringp, "|");
if (!exten) { pri = strsep(&stringp, "|");
/* Only a priority in this one */ if (!exten) { /* Only a priority in this one */
pri = context; pri = context;
exten = NULL; exten = NULL;
context = NULL; context = NULL;
} else { } else if (!pri) { /* Only an extension and priority in this one */
pri = strsep(&stringp, "|");
if (!pri) {
/* Only an extension and priority in this one */
pri = exten; pri = exten;
exten = context; exten = context;
context = NULL; context = NULL;
} }
}
if (*pri == '+') { if (*pri == '+') {
mode = 1; mode = 1;
pri++; pri++;