Commit 5d265742 5d265742fc88ce0c3753086f4480f0f0c1ceec6e by Sergey Poznyakoff

(util_finish): Do not allow to switch to

a higher state in case of command failure.
(util_do_command): Run the command only if it is allowed in
the current state.
1 parent 6533f0c4
......@@ -410,7 +410,13 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
va_end (ap);
free (buf);
/* Reset the state. */
new_state = (rc == RESP_OK) ? command->success : command->failure;
if (rc == RESP_OK)
new_state = command->success;
else if (command->failure <= state)
new_state = command->failure;
else
new_state = STATE_NONE;
if (new_state != STATE_NONE)
state = new_state;
return status;
......@@ -555,6 +561,10 @@ util_do_command (char *prompt)
}
command->tag = tag;
if (command->states && (command->states & state) == 0)
return util_finish (command, RESP_BAD, "Wrong state");
len = strlen (sp);
if (len && sp[len - 1] == '\n')
sp[len - 1] = '\0';
......