refactor, cleanup, eliminate un-needed checks. Found by Klockwork (www.klocwork.com)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8470 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-05-19 19:08:03 +00:00
parent 21b5d73ad0
commit 9a64686104
1 changed files with 61 additions and 66 deletions

View File

@ -268,9 +268,10 @@ static switch_status_t play_and_collect(switch_core_session_t *session, switch_i
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_input_args_t args = { 0 }; switch_input_args_t args = { 0 };
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sound=[%s]\n", sound); if (!session || !menu || switch_strlen_zero(sound)) {
return status;
}
if (session != NULL && menu != NULL && !switch_strlen_zero(sound)) {
memset(menu->buf, 0, menu->inlen + 1); memset(menu->buf, 0, menu->inlen + 1);
menu->ptr = menu->buf; menu->ptr = menu->buf;
@ -286,8 +287,9 @@ static switch_status_t play_and_collect(switch_core_session_t *session, switch_i
status = switch_ivr_play_file(session, NULL, sound, &args); status = switch_ivr_play_file(session, NULL, sound, &args);
if (!need) {
if (need) { return status;
}
menu->ptr += strlen(menu->buf); menu->ptr += strlen(menu->buf);
if (strlen(menu->buf) < need) { if (strlen(menu->buf) < need) {
@ -297,14 +299,12 @@ static switch_status_t play_and_collect(switch_core_session_t *session, switch_i
need, "#", &terminator, menu->inter_timeout, 0, 0); need, "#", &terminator, menu->inter_timeout, 0, 0);
} }
if (menu->confirm_macro && status == SWITCH_STATUS_SUCCESS && *menu->buf != '\0') {
if (menu->confirm_macro && status == SWITCH_STATUS_SUCCESS && !switch_strlen_zero(menu->buf)) {
switch_input_args_t confirm_args = { 0 }, *ap = NULL; switch_input_args_t confirm_args = { 0 }, *ap = NULL;
char buf[10] = ""; char buf[10] = "";
char terminator_key; char terminator_key;
int att = menu->confirm_attempts; int att = menu->confirm_attempts;
while (att) { while (att) {
confirm_args.buf = buf; confirm_args.buf = buf;
confirm_args.buflen = sizeof(buf); confirm_args.buflen = sizeof(buf);
@ -339,9 +339,6 @@ static switch_status_t play_and_collect(switch_core_session_t *session, switch_i
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "digits '%s'\n", menu->buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "digits '%s'\n", menu->buf);
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "returning [%d]\n", status);
return status; return status;
} }
@ -357,7 +354,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
switch_channel_t *channel; switch_channel_t *channel;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
if (session == NULL || stack == NULL || switch_strlen_zero(name)) { if (!session || !stack || switch_strlen_zero(name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid menu context\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid menu context\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -395,8 +392,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
memset(menu->buf, 0, menu->inlen + 1); memset(menu->buf, 0, menu->inlen + 1);
status = play_and_collect(session, menu, greeting_sound, menu->inlen); status = play_and_collect(session, menu, greeting_sound, menu->inlen);
if (!switch_strlen_zero(menu->buf)) { if (*menu->buf != '\0') {
for (ap = menu->actions; ap; ap = ap->next) { for (ap = menu->actions; ap; ap = ap->next) {
int ok = 0; int ok = 0;
@ -485,7 +481,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
} }
} }
if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { // top level if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { // top level
if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN)) { // catch the fallback and recover if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN)) { // catch the fallback and recover
switch_clear_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN); switch_clear_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN);