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/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9978 )
Change subject: ctrl: Introduce ctrl_cmd_parse3 API
......................................................................
ctrl: Introduce ctrl_cmd_parse3 API
Callers require to know whether the returned ERROR cmd was received or
generated locally, in order to send it or do something with it locally.
Related: OS#3394
Change-Id: Ide9170e5c31967c353f8fe4e8227e64130b91eae
---
M include/osmocom/ctrl/control_cmd.h
M src/ctrl/control_cmd.c
M src/ctrl/libosmoctrl.map
3 files changed, 22 insertions(+), 1 deletion(-)
Approvals:
Harald Welte: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/include/osmocom/ctrl/control_cmd.h b/include/osmocom/ctrl/control_cmd.h
index 08376f3..93055c7 100644
--- a/include/osmocom/ctrl/control_cmd.h
+++ b/include/osmocom/ctrl/control_cmd.h
@@ -124,6 +124,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_parse3(void *ctx, struct msgb *msg, bool *parse_failed);
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);
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index 14ff906..33496bd 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -316,9 +316,25 @@
* \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 @@
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 @@
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;
}
diff --git a/src/ctrl/libosmoctrl.map b/src/ctrl/libosmoctrl.map
index 5b888a2..f995467 100644
--- a/src/ctrl/libosmoctrl.map
+++ b/src/ctrl/libosmoctrl.map
@@ -13,6 +13,7 @@
ctrl_cmd_make;
ctrl_cmd_parse;
ctrl_cmd_parse2;
+ctrl_cmd_parse3;
ctrl_cmd_send;
ctrl_cmd_send_to_all;
ctrl_cmd_send_trap;
--
To view, visit https://gerrit.osmocom.org/9978
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide9170e5c31967c353f8fe4e8227e64130b91eae
Gerrit-Change-Number: 9978
Gerrit-PatchSet: 3
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180716/a1d3353f/attachment.htm>