diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2017-12-16 01:18:53 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-12-20 15:50:30 +0000 |
commit | a5e2162cf16f2e9208b60431bc4799b4bcdd4b42 (patch) | |
tree | 82713ff94d9f9278bc4b2cf6375e49c9c2e8aff3 | |
parent | 3da9aa6b6792407d57816ec4a4cdfd0b4b3434b8 (diff) |
ctrl: separate handling of GET_REPLY, SET_REPLY and TRAP
So far, error reporting just says "Trap/Reply", more accurately report 'GET
REPLY', 'SET REPLY' and 'TRAP' as appropriate.
Change-Id: Ic25a251502499aeda4e2952ec4190a1fa0bebb01
-rw-r--r-- | src/ctrl/control_cmd.c | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c index f32a200c..c747e84d 100644 --- a/src/ctrl/control_cmd.c +++ b/src/ctrl/control_cmd.c @@ -410,31 +410,34 @@ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg) LOGP(DLCTRL, LOGL_DEBUG, "Command: SET %s = \"%s\"\n", cmd->variable, osmo_escape_str(cmd->value, -1)); break; - case CTRL_TYPE_GET_REPLY: - case CTRL_TYPE_SET_REPLY: - case CTRL_TYPE_TRAP: - var = strtok_r(NULL, " ", &saveptr); - val = strtok_r(NULL, "", &saveptr); - if (!var || !val) { - cmd->type = CTRL_TYPE_ERROR; - cmd->reply = "Trap/Reply incomplete"; - LOGP(DLCTRL, LOGL_NOTICE, "Trap/Reply incomplete\n"); - goto err; - } - if (!osmo_separated_identifiers_valid(var, ".")) { - cmd->type = CTRL_TYPE_ERROR; - cmd->reply = "Trap/Reply variable contains invalid characters"; - LOGP(DLCTRL, LOGL_NOTICE, "Trap/Reply variable contains invalid characters: \"%s\"\n", - osmo_escape_str(var, -1)); - goto err; - } - cmd->variable = talloc_strdup(cmd, var); - cmd->reply = talloc_strdup(cmd, val); - if (!cmd->variable || !cmd->reply) - goto oom; - LOGP(DLCTRL, LOGL_DEBUG, "Command: TRAP/REPLY %s: \"%s\"\n", cmd->variable, - osmo_escape_str(cmd->reply, -1)); - break; +#define REPLY_CASE(TYPE, NAME) \ + case TYPE: \ + var = strtok_r(NULL, " ", &saveptr); \ + val = strtok_r(NULL, "", &saveptr); \ + if (!var) { \ + cmd->type = CTRL_TYPE_ERROR; \ + cmd->reply = NAME " incomplete"; \ + LOGP(DLCTRL, LOGL_NOTICE, NAME " incomplete\n"); \ + goto err; \ + } \ + if (!osmo_separated_identifiers_valid(var, ".")) { \ + cmd->type = CTRL_TYPE_ERROR; \ + cmd->reply = NAME " variable contains invalid characters"; \ + LOGP(DLCTRL, LOGL_NOTICE, NAME " variable contains invalid characters: \"%s\"\n", \ + osmo_escape_str(var, -1)); \ + goto err; \ + } \ + cmd->variable = talloc_strdup(cmd, var); \ + cmd->reply = talloc_strdup(cmd, val); \ + if (!cmd->variable || !cmd->reply) \ + goto oom; \ + LOGP(DLCTRL, LOGL_DEBUG, "Command: " NAME " %s: %s\n", cmd->variable, \ + osmo_escape_str(cmd->reply, -1)); \ + break + REPLY_CASE(CTRL_TYPE_GET_REPLY, "GET REPLY"); + REPLY_CASE(CTRL_TYPE_SET_REPLY, "SET REPLY"); + REPLY_CASE(CTRL_TYPE_TRAP, "TRAP"); +#undef REPLY_CASE case CTRL_TYPE_ERROR: var = strtok_r(NULL, "", &saveptr); if (!var) { |