From 9e8f015acd3a731f1c2e872b73ed2734b14df3a0 Mon Sep 17 00:00:00 2001 From: file Date: Thu, 15 Feb 2007 02:02:30 +0000 Subject: Few more code clean ups. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@54534 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_exec.c | 78 +++++++++++++++++++++++++++++--------------------------- apps/app_flash.c | 46 ++++++++++++++++++--------------- apps/app_image.c | 4 +-- 3 files changed, 67 insertions(+), 61 deletions(-) (limited to 'apps') diff --git a/apps/app_exec.c b/apps/app_exec.c index 0aafac343..507045cc3 100644 --- a/apps/app_exec.c +++ b/apps/app_exec.c @@ -95,30 +95,31 @@ static int exec_exec(struct ast_channel *chan, void *data) char *s, *appname, *endargs, args[MAXRESULT] = ""; struct ast_app *app; - u = ast_module_user_add(chan); + if (ast_strlen_zero(data)) + return 0; - /* Check and parse arguments */ - if (data) { - s = ast_strdupa(data); - appname = strsep(&s, "("); - if (s) { - endargs = strrchr(s, ')'); - if (endargs) - *endargs = '\0'; - pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); - } - if (appname) { - app = pbx_findapp(appname); - if (app) { - res = pbx_exec(chan, app, args); - } else { - ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); - res = -1; - } + u = ast_module_user_add(chan); + + s = ast_strdupa(data); + appname = strsep(&s, "("); + if (s) { + endargs = strrchr(s, ')'); + if (endargs) + *endargs = '\0'; + pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); + } + if (appname) { + app = pbx_findapp(appname); + if (app) { + res = pbx_exec(chan, app, args); + } else { + ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); + res = -1; } } ast_module_user_remove(u); + return res; } @@ -129,31 +130,32 @@ static int tryexec_exec(struct ast_channel *chan, void *data) char *s, *appname, *endargs, args[MAXRESULT] = ""; struct ast_app *app; + if (ast_strlen_zero(data)) + return 0; + u = ast_module_user_add(chan); - /* Check and parse arguments */ - if (data) { - s = ast_strdupa(data); - appname = strsep(&s, "("); - if (s) { - endargs = strrchr(s, ')'); - if (endargs) - *endargs = '\0'; - pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); - } - if (appname) { - app = pbx_findapp(appname); - if (app) { - res = pbx_exec(chan, app, args); - pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); - } else { - ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); - pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); - } + s = ast_strdupa(data); + appname = strsep(&s, "("); + if (s) { + endargs = strrchr(s, ')'); + if (endargs) + *endargs = '\0'; + pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); + } + if (appname) { + app = pbx_findapp(appname); + if (app) { + res = pbx_exec(chan, app, args); + pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); + } else { + ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); + pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); } } ast_module_user_remove(u); + return 0; } diff --git a/apps/app_flash.c b/apps/app_flash.c index dea8f329b..5f90093bb 100644 --- a/apps/app_flash.c +++ b/apps/app_flash.c @@ -75,31 +75,37 @@ static int flash_exec(struct ast_channel *chan, void *data) int x; struct ast_module_user *u; 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); - if (!strcasecmp(chan->tech->type, "Zap")) { - memset(&ztp, 0, sizeof(ztp)); - res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp); - if (!res) { - if (ztp.sigtype & __ZT_SIG_FXS) { - x = ZT_FLASH; - res = ioctl(chan->fds[0], ZT_HOOK, &x); - if (!res || (errno == EINPROGRESS)) { - if (res) { - /* Wait for the event to finish */ - zt_wait_event(chan->fds[0]); - } - res = ast_safe_sleep(chan, 1000); - if (option_verbose > 2) - 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)); + + memset(&ztp, 0, sizeof(ztp)); + res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp); + if (!res) { + if (ztp.sigtype & __ZT_SIG_FXS) { + x = ZT_FLASH; + res = ioctl(chan->fds[0], ZT_HOOK, &x); + if (!res || (errno == EINPROGRESS)) { + if (res) { + /* Wait for the event to finish */ + zt_wait_event(chan->fds[0]); + } + res = ast_safe_sleep(chan, 1000); + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name); } 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 - 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 - 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); + return res; } diff --git a/apps/app_image.c b/apps/app_image.c index f5f327197..7f7086eea 100644 --- a/apps/app_image.c +++ b/apps/app_image.c @@ -96,9 +96,7 @@ static int sendimage_exec(struct ast_channel *chan, void *data) return 0; } - res = ast_send_image(chan, args.filename); - - if (!res) + if (!(res = ast_send_image(chan, args.filename))) pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK"); ast_module_user_remove(u); -- cgit v1.2.3