aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-12-16 01:18:53 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2017-12-18 04:38:23 +0100
commite554429d04bceaac626165d13b69948477482e06 (patch)
treec85c2ac1ba1efd27fc87fdce1bca6c453cf4efe2
parentff1713e115789f1fff7f6fdc7f34b321fab27064 (diff)
ctrl: separate handling of GET_REPLY, SET_REPLY and TRAPneels/ctrl_parsing
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.c54
1 files changed, 49 insertions, 5 deletions
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index f32a200c..31199bf4 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -411,20 +411,64 @@ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg)
osmo_escape_str(cmd->value, -1));
break;
case CTRL_TYPE_GET_REPLY:
+ var = strtok_r(NULL, " ", &saveptr);
+ val = strtok_r(NULL, "", &saveptr);
+ if (!var) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "GET REPLY incomplete";
+ LOGP(DLCTRL, LOGL_NOTICE, "GET REPLY incomplete\n");
+ goto err;
+ }
+ if (!osmo_separated_identifiers_valid(var, ".")) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "GET REPLY variable contains invalid characters";
+ LOGP(DLCTRL, LOGL_NOTICE, "GET 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: GET REPLY %s: %s\n", cmd->variable,
+ osmo_escape_str(cmd->reply, -1));
+ break;
case CTRL_TYPE_SET_REPLY:
+ var = strtok_r(NULL, " ", &saveptr);
+ val = strtok_r(NULL, "", &saveptr);
+ if (!var) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "SET REPLY incomplete";
+ LOGP(DLCTRL, LOGL_NOTICE, "GET REPLY incomplete\n");
+ goto err;
+ }
+ if (!osmo_separated_identifiers_valid(var, ".")) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "SET REPLY variable contains invalid characters";
+ LOGP(DLCTRL, LOGL_NOTICE, "SET 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: SET REPLY %s: %s\n", cmd->variable,
+ osmo_escape_str(cmd->reply, -1));
+ break;
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");
+ cmd->reply = "TRAP incomplete";
+ LOGP(DLCTRL, LOGL_NOTICE, "TRAP 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",
+ cmd->reply = "TRAP variable contains invalid characters";
+ LOGP(DLCTRL, LOGL_NOTICE, "TRAP variable contains invalid characters: \"%s\"\n",
osmo_escape_str(var, -1));
goto err;
}
@@ -432,7 +476,7 @@ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg)
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,
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: TRAP %s: \"%s\"\n", cmd->variable,
osmo_escape_str(cmd->reply, -1));
break;
case CTRL_TYPE_ERROR: