Few more code clean ups.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@54534 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Joshua Colp 18 years ago
parent fd3630715b
commit db868d0807

@ -95,30 +95,31 @@ static int exec_exec(struct ast_channel *chan, void *data)
char *s, *appname, *endargs, args[MAXRESULT] = ""; char *s, *appname, *endargs, args[MAXRESULT] = "";
struct ast_app *app; struct ast_app *app;
u = ast_module_user_add(chan); if (ast_strlen_zero(data))
return 0;
/* Check and parse arguments */ u = ast_module_user_add(chan);
if (data) {
s = ast_strdupa(data); s = ast_strdupa(data);
appname = strsep(&s, "("); appname = strsep(&s, "(");
if (s) { if (s) {
endargs = strrchr(s, ')'); endargs = strrchr(s, ')');
if (endargs) if (endargs)
*endargs = '\0'; *endargs = '\0';
pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
} }
if (appname) { if (appname) {
app = pbx_findapp(appname); app = pbx_findapp(appname);
if (app) { if (app) {
res = pbx_exec(chan, app, args); res = pbx_exec(chan, app, args);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
res = -1; res = -1;
}
} }
} }
ast_module_user_remove(u); ast_module_user_remove(u);
return res; return res;
} }
@ -129,31 +130,32 @@ static int tryexec_exec(struct ast_channel *chan, void *data)
char *s, *appname, *endargs, args[MAXRESULT] = ""; char *s, *appname, *endargs, args[MAXRESULT] = "";
struct ast_app *app; struct ast_app *app;
if (ast_strlen_zero(data))
return 0;
u = ast_module_user_add(chan); u = ast_module_user_add(chan);
/* Check and parse arguments */ s = ast_strdupa(data);
if (data) { appname = strsep(&s, "(");
s = ast_strdupa(data); if (s) {
appname = strsep(&s, "("); endargs = strrchr(s, ')');
if (s) { if (endargs)
endargs = strrchr(s, ')'); *endargs = '\0';
if (endargs) pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
*endargs = '\0'; }
pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); if (appname) {
} app = pbx_findapp(appname);
if (appname) { if (app) {
app = pbx_findapp(appname); res = pbx_exec(chan, app, args);
if (app) { pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS");
res = pbx_exec(chan, app, args); } else {
pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
} else { pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
}
} }
} }
ast_module_user_remove(u); ast_module_user_remove(u);
return 0; return 0;
} }

@ -75,31 +75,37 @@ static int flash_exec(struct ast_channel *chan, void *data)
int x; int x;
struct ast_module_user *u; struct ast_module_user *u;
struct zt_params ztp; struct zt_params ztp;
if (strcasecmp(chan->tech->type, "Zap")) {
ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
return -1;
}
u = ast_module_user_add(chan); u = ast_module_user_add(chan);
if (!strcasecmp(chan->tech->type, "Zap")) {
memset(&ztp, 0, sizeof(ztp)); memset(&ztp, 0, sizeof(ztp));
res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp); res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
if (!res) { if (!res) {
if (ztp.sigtype & __ZT_SIG_FXS) { if (ztp.sigtype & __ZT_SIG_FXS) {
x = ZT_FLASH; x = ZT_FLASH;
res = ioctl(chan->fds[0], ZT_HOOK, &x); res = ioctl(chan->fds[0], ZT_HOOK, &x);
if (!res || (errno == EINPROGRESS)) { if (!res || (errno == EINPROGRESS)) {
if (res) { if (res) {
/* Wait for the event to finish */ /* Wait for the event to finish */
zt_wait_event(chan->fds[0]); zt_wait_event(chan->fds[0]);
} }
res = ast_safe_sleep(chan, 1000); res = ast_safe_sleep(chan, 1000);
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name); ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
} else
ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
} else } else
ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name); ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
} else } else
ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno)); ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
} else } else
ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name); ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
ast_module_user_remove(u); ast_module_user_remove(u);
return res; return res;
} }

@ -96,9 +96,7 @@ static int sendimage_exec(struct ast_channel *chan, void *data)
return 0; return 0;
} }
res = ast_send_image(chan, args.filename); if (!(res = ast_send_image(chan, args.filename)))
if (!res)
pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK"); pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
ast_module_user_remove(u); ast_module_user_remove(u);

Loading…
Cancel
Save