[PATCH] libosmocore[master]: control_if: Add helper function for 'local execution' of con...

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.org
Thu Apr 27 07:52:23 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/2376

to look at the new patch set (#3).

control_if: Add helper function for 'local execution' of control command

Sometimes (particularly when testing), we may want to parse+execute an
arbitrary control command simply form a string buffer, rather than from
a msgb.  Let's add a helper for that.

Change-Id: Iaca748e0d942bb2a1ee7c2776b37485e1439eb0c
---
M include/osmocom/ctrl/control_if.h
M src/ctrl/control_if.c
M tests/Makefile.am
3 files changed, 30 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/76/2376/3

diff --git a/include/osmocom/ctrl/control_if.h b/include/osmocom/ctrl/control_if.h
index 0d37959..4cd3369 100644
--- a/include/osmocom/ctrl/control_if.h
+++ b/include/osmocom/ctrl/control_if.h
@@ -30,5 +30,6 @@
 					       ctrl_cmd_lookup lookup);
 struct ctrl_connection *osmo_ctrl_conn_alloc(void *ctx, void *data);
 int ctrl_cmd_handle(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd, void *data);
+struct ctrl_cmd *ctrl_cmd_exec_from_string(struct ctrl_handle *ch, const char *cmdstr);
 
 int ctrl_lookup_register(ctrl_cmd_lookup lookup);
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index 28f696b..c8b4722 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -810,3 +810,31 @@
 	llist_add_tail(&lh->list, &ctrl_lookup_helpers);
 	return 0;
 }
+
+/*! \brief Helper for "local execution" of a CTRL command from a string
+ *  The function will parse + execute the given control command string
+ *  and return a corresponding ctrl_cmd.  Caller is responsible to
+ *  talloc_free() the return value.
+ *  \param[in] Control Interface Command String
+ *  \returns parsed command, including reply; NULL on error */
+struct ctrl_cmd *ctrl_cmd_exec_from_string(struct ctrl_handle *ch, const char *cmdstr)
+{
+	struct msgb *msg = msgb_alloc(1024, "ctrl-cmd");
+	struct ctrl_cmd *cmd;
+
+	if (!msg)
+		return NULL;
+	msg->l2h = msg->data;
+	osmo_strlcpy((char *)msg->data, cmdstr, msgb_tailroom(msg));
+	msgb_put(msg, strlen(cmdstr));
+
+	cmd = ctrl_cmd_parse(ch, msg);
+	msgb_free(msg);
+	if (!cmd)
+		return NULL;
+	if (ctrl_cmd_handle(ch, cmd, NULL) < 0) {
+		talloc_free(cmd);
+		return NULL;
+	}
+	return cmd;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 352b5a7..ab80c1a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -139,7 +139,7 @@
 oap_oap_test_LDADD = $(top_builddir)/src/gsm/libosmogsm.la $(top_builddir)/src/libosmocore.la
 
 fsm_fsm_test_SOURCES = fsm/fsm_test.c
-fsm_fsm_test_LDADD = $(top_builddir)/src/libosmocore.la
+fsm_fsm_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/ctrl/libosmoctrl.la
 
 write_queue_wqueue_test_SOURCES = write_queue/wqueue_test.c
 write_queue_wqueue_test_LDADD = $(top_builddir)/src/libosmocore.la

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iaca748e0d942bb2a1ee7c2776b37485e1439eb0c
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list