[PATCH] libosmocore[master]: add ctrl_cmd_parse2() to return parsing errors

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Sat Dec 16 05:24:27 UTC 2017


Review at  https://gerrit.osmocom.org/5436

add ctrl_cmd_parse2() to return parsing errors

If a control command fails to parse, we so far discard specific error messages
and instead send just "Command parser error".

In ctrl_cmd_parse() we actually compose detailed error replies, but in the end
simply talloc_free() them and return NULL.

A first step to report these errors to the ctrl command issuer is to not return
NULL and instead return the cmd with type = CTRL_TYPE_ERROR. Add
ctrl_cmd_parse2() to return such instead of NULL.

To stay API compatible, provide ctrl_cmd_parse2() to return a cmd on errors.
ctrl_cmd_parse() retains identical behavior but becomes just a simple wrapper
around ctrl_cmd_parse2() which discards the cmd on error.

No need really to deprecate ctrl_cmd_parse() yet; especially as long as
compiler warnings might break jenkins builds.

Change-Id: I5047c9f977d70b03eea77cbcfd2b96d43ea46880
---
M include/osmocom/ctrl/control_cmd.h
M src/ctrl/control_cmd.c
2 files changed, 17 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/5436/1

diff --git a/include/osmocom/ctrl/control_cmd.h b/include/osmocom/ctrl/control_cmd.h
index 4372e25..865b006 100644
--- a/include/osmocom/ctrl/control_cmd.h
+++ b/include/osmocom/ctrl/control_cmd.h
@@ -103,6 +103,7 @@
 int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd);
 int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd);
 int ctrl_cmd_send_to_all(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd);
+struct ctrl_cmd *ctrl_cmd_parse2(void *ctx, struct msgb *msg);
 struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg);
 struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd);
 struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd);
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index f616479..c2ce2be 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -269,7 +269,22 @@
 	return NULL;
 }
 
+/*! Parse CTRL command struct from msgb, return NULL on any error.
+ * The caller is responsible to talloc_free() the returned struct pointer. */
 struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
+{
+	struct ctrl_cmd *res = ctrl_cmd_parse2(ctx, msg);
+	if (res->type == CTRL_TYPE_ERROR) {
+		talloc_free(res);
+		return NULL;
+	}
+	return res;
+}
+
+/*! Parse CTRL command struct from msgb, return 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_parse2(void *ctx, struct msgb *msg)
 {
 	char *str, *tmp, *saveptr = NULL;
 	char *var, *val;
@@ -382,8 +397,7 @@
 	cmd->id = "err";
 	cmd->reply = "OOM";
 err:
-	talloc_free(cmd);
-	return NULL;
+	return cmd;
 }
 
 struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)

-- 
To view, visit https://gerrit.osmocom.org/5436
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5047c9f977d70b03eea77cbcfd2b96d43ea46880
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list