[PATCH] rpcd: plugin: don't query ubusd for known object name

Daniel Danzberger daniel at dd-wrt.com
Tue Jul 26 23:09:31 PDT 2022


The object name is already known and stored in the ubus object,
so there is no need ubus_lookup() all objects and reverse resolve
the id to it's name on every plugin handler call.

Signed-off-by: Daniel Danzberger <daniel at dd-wrt.com>
---
 plugin.c | 41 ++---------------------------------------
 1 file changed, 2 insertions(+), 39 deletions(-)

diff --git a/plugin.c b/plugin.c
index ea6e60f..7cd59c4 100644
--- a/plugin.c
+++ b/plugin.c
@@ -20,37 +20,6 @@
 
 static struct blob_buf buf;
 
-struct rpc_plugin_lookup_context {
-	uint32_t id;
-	char *name;
-	bool found;
-};
-
-static void
-rpc_plugin_lookup_plugin_cb(struct ubus_context *ctx,
-                            struct ubus_object_data *obj, void *priv)
-{
-	struct rpc_plugin_lookup_context *c = priv;
-
-	if (c->id == obj->id)
-	{
-		c->found = true;
-		sprintf(c->name, "%s", obj->path);
-	}
-}
-
-static bool
-rpc_plugin_lookup_plugin(struct ubus_context *ctx, struct ubus_object *obj,
-                         char *strptr)
-{
-	struct rpc_plugin_lookup_context c = { .id = obj->id, .name = strptr };
-
-	if (ubus_lookup(ctx, NULL, rpc_plugin_lookup_plugin_cb, &c))
-		return false;
-
-	return c.found;
-}
-
 static void
 rpc_plugin_json_array_to_blob(struct array_list *a, struct blob_buf *blob);
 
@@ -204,7 +173,7 @@ rpc_plugin_call(struct ubus_context *ctx, struct ubus_object *obj,
 {
 	int rv = UBUS_STATUS_UNKNOWN_ERROR;
 	struct call_context *c;
-	char *plugin, *mptr;
+	char *mptr;
 
 	c = calloc_a(sizeof(*c), &mptr, strlen(method) + 1);
 
@@ -218,13 +187,7 @@ rpc_plugin_call(struct ubus_context *ctx, struct ubus_object *obj,
 	if (!c->input || !c->tok)
 		goto fail;
 
-	plugin = c->path + sprintf(c->path, "%s/", RPC_PLUGIN_DIRECTORY);
-
-	if (!rpc_plugin_lookup_plugin(ctx, obj, plugin))
-	{
-		rv = UBUS_STATUS_NOT_FOUND;
-		goto fail;
-	}
+	sprintf(c->path, "%s/%s", RPC_PLUGIN_DIRECTORY, obj->name);
 
 	c->argv[0] = c->path;
 	c->argv[1] = "call";
-- 
2.35.1




More information about the openwrt-devel mailing list