summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-04-16 16:57:40 +0200
committerHarald Welte <laforge@gnumonks.org>2017-04-26 09:22:19 +0000
commitd6b1f85fd81c3dd267186830a671db88c360054f (patch)
tree7db79c03c19990fe5ca4715d1e7b0139586a3965
parenta81055db1dc2046f57f1c78f055f693b5a4e3308 (diff)
ctrl: Allow installation of additional node lookup helpers
The existing code assumes that the main application knows about all control command nodes and can thus present one lookup function. As libraries are getting their own control interface handling, this is too restrictive, and we need a way how library code can dynamically register more node lookup helpers. We can now do this by means of a ctrl_lookup_register() function. Change-Id: Ib69908d1c57f5bb721d5496e3b4a5258fca450e3
-rw-r--r--include/osmocom/ctrl/control_if.h2
-rw-r--r--src/ctrl/control_if.c41
2 files changed, 43 insertions, 0 deletions
diff --git a/include/osmocom/ctrl/control_if.h b/include/osmocom/ctrl/control_if.h
index f2af1dba..a740a961 100644
--- a/include/osmocom/ctrl/control_if.h
+++ b/include/osmocom/ctrl/control_if.h
@@ -29,3 +29,5 @@ struct ctrl_handle *ctrl_interface_setup_dynip(void *data,
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);
+
+int ctrl_lookup_register(ctrl_cmd_lookup lookup);
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index d2eb3e90..f1cc7ab6 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -61,6 +61,13 @@
vector ctrl_node_vec;
+/* global list of control interface lookup helpers */
+struct lookup_helper {
+ struct llist_head list;
+ ctrl_cmd_lookup lookup;
+};
+static LLIST_HEAD(ctrl_lookup_helpers);
+
int ctrl_parse_get_num(vector vline, int i, long *num)
{
char *token, *tmp;
@@ -225,6 +232,7 @@ int ctrl_cmd_handle(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd,
}
for (i=0;i<vector_active(vline);i++) {
+ struct lookup_helper *lh;
int rc;
if (ctrl->lookup)
@@ -232,6 +240,14 @@ int ctrl_cmd_handle(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd,
else
rc = 0;
+ if (!rc) {
+ llist_for_each_entry(lh, &ctrl_lookup_helpers, list) {
+ rc = lh->lookup(data, vline, &node, &cmd->node, &i);
+ if (rc)
+ break;
+ }
+ }
+
if (rc == 1) {
/* do nothing */
} else if (rc == -ENODEV)
@@ -733,3 +749,28 @@ err:
talloc_free(ctrl);
return NULL;
}
+
+/*! \brief Install a lookup helper function for control nodes
+ * This function is used by e.g. library code to install lookup helpers
+ * for additional nodes in the control interface.
+ * \param[in] lookup The lookup helper function
+ * \retuns - on success; negative on error.
+ */
+int ctrl_lookup_register(ctrl_cmd_lookup lookup)
+{
+ struct lookup_helper *lh;
+
+ /* avoid double registration */
+ llist_for_each_entry(lh, &ctrl_lookup_helpers, list) {
+ if (lh->lookup == lookup)
+ return -EEXIST;
+ }
+
+ lh = talloc_zero(NULL, struct lookup_helper);
+ if (!lh)
+ return -ENOMEM;
+
+ lh->lookup = lookup;
+ llist_add_tail(&lh->list, &ctrl_lookup_helpers);
+ return 0;
+}