diff options
Diffstat (limited to 'src/ctrl/control_cmd.c')
-rw-r--r-- | src/ctrl/control_cmd.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c index 14ff9065..33496bd8 100644 --- a/src/ctrl/control_cmd.c +++ b/src/ctrl/control_cmd.c @@ -316,9 +316,25 @@ static bool id_str_valid(const char *str) * \param[in] msg message buffer containing command to be decoded * \returns callee-allocated decoded CTRL command; NULL on allocation failure, * ctrl->type == CTRL_TYPE_ERROR and an error message in ctrl->reply on any error. - * The caller is responsible to talloc_free() the returned struct pointer. */ + * The caller is responsible to talloc_free() the returned struct pointer. + * If information of the origin of the ERROR cmd returned is required (received + * or local parsing failure), use \ref ctrl_cmd_parse3 instead. */ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg) { + bool unused; + return ctrl_cmd_parse3(ctx, msg, &unused); +} + +/*! Parse/Decode CTRL from \ref msgb into command struct. + * \param[in] ctx talloc context from which to allocate + * \param[in] msg message buffer containing command to be decoded + * \param[out] parse_failed Whether returned ERROR cmd was generatd locally + * (due to parse failure) or was received. + * \returns callee-allocated decoded CTRL command; NULL on allocation failure, + * ctrl->type == CTRL_TYPE_ERROR and an error message in ctrl->reply on any error. + * The caller is responsible to talloc_free() the returned struct pointer. */ +struct ctrl_cmd *ctrl_cmd_parse3(void *ctx, struct msgb *msg, bool *parse_failed) +{ char *str, *tmp, *saveptr = NULL; char *var, *val; struct ctrl_cmd *cmd; @@ -326,6 +342,7 @@ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg) cmd = talloc_zero(ctx, struct ctrl_cmd); if (!cmd) { LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate.\n"); + *parse_failed = true; return NULL; } @@ -483,12 +500,14 @@ struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg) goto err; } + *parse_failed = false; return cmd; oom: cmd->type = CTRL_TYPE_ERROR; cmd->id = "err"; cmd->reply = "OOM"; err: + *parse_failed = true; return cmd; } |