summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
+}