summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-04-03 17:00:11 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-04-05 03:11:52 +0200
commit7c0031fc8063771e604976233fb7b46d2b85c077 (patch)
tree52d4fb6939905eab6bba4b0c4cf05e0d4ca66f97 /src
parentcdbc9afe5da5fe728ce8fa62e36ded17efe70032 (diff)
cosmetic: flatten ctrl_handle_msg()
Change-Id: I3a711f5c974b7f56e27b333d390d1a706fb57007
Diffstat (limited to 'src')
-rw-r--r--src/ctrl/control_if.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index df8abbc6..cc613ee7 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -365,6 +365,7 @@ int ctrl_handle_msg(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, stru
struct ctrl_cmd *cmd;
struct ipaccess_head *iph;
struct ipaccess_head_ext *iph_ext;
+ int result;
if (msg->len < sizeof(*iph) + sizeof(*iph_ext)) {
LOGP(DLCTRL, LOGL_ERROR, "The message is too short.\n");
@@ -398,28 +399,29 @@ int ctrl_handle_msg(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, stru
cmd->reply = "Command parser error.";
}
- if (cmd->type != CTRL_TYPE_ERROR) {
- cmd->ccon = ccon;
- if (ctrl_cmd_handle(ctrl, cmd, ctrl->data) == CTRL_CMD_HANDLED) {
+ /* In case of error, reply with the error message right away. */
+ if (cmd->type == CTRL_TYPE_ERROR)
+ goto send_reply;
- if (cmd->defer) {
- /* The command is still stored as ctrl_cmd_def.cmd, in the def_cmds list.
- * Just leave hanging for deferred handling. Reply will happen later. */
- return 0;
- }
+ cmd->ccon = ccon;
+ result = ctrl_cmd_handle(ctrl, cmd, ctrl->data);
- /* On CTRL_CMD_HANDLED, no reply needs to be sent back. */
- talloc_free(cmd);
- cmd = NULL;
- }
- }
- if (cmd) {
- /* There is a reply or error that should be reported back to the sender. */
- ctrl_cmd_send(&ccon->write_queue, cmd);
- talloc_free(cmd);
+ if (cmd->defer) {
+ /* The command is still stored as ctrl_cmd_def.cmd, in the def_cmds list.
+ * Just leave hanging for deferred handling. Reply will happen later. */
+ return 0;
}
+ /* On CTRL_CMD_HANDLED, no reply needs to be sent back. */
+ if (result == CTRL_CMD_HANDLED)
+ goto just_free;
+
+send_reply:
+ /* There is a reply or error that should be reported back to the sender. */
+ ctrl_cmd_send(&ccon->write_queue, cmd);
+just_free:
+ talloc_free(cmd);
return 0;
}