From 7434b2bf6cdb1ad1a6e955a254dfbf68e74df742 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 2 Sep 2013 14:52:49 +0200 Subject: [PATCH] luci2: convert to plugin library --- luci2.c | 40 ++++++++++++++++++++++++---------------- luci2.h | 2 -- main.c | 2 -- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/luci2.c b/luci2.c index 76dd60e..bb68a4b 100644 --- a/luci2.c +++ b/luci2.c @@ -32,8 +32,9 @@ #include #include "luci2.h" -#include "exec.h" -#include "session.h" +#include "plugin.h" + +static const struct rpc_daemon_ops *ops; static struct blob_buf buf; static struct uci_context *cursor; @@ -964,7 +965,7 @@ rpc_luci2_upgrade_test(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { const char *cmd[4] = { "sysupgrade", "--test", "/tmp/firmware.bin", NULL }; - return rpc_exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); + return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } static int @@ -994,7 +995,7 @@ rpc_luci2_backup_restore(struct ubus_context *ctx, struct ubus_object *obj, const char *cmd[4] = { "sysupgrade", "--restore-backup", "/tmp/backup.tar.gz", NULL }; - return rpc_exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); + return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } static int @@ -1110,8 +1111,8 @@ rpc_luci2_backup_list(struct ubus_context *ctx, struct ubus_object *obj, memset(state, 0, sizeof(*state)); - return rpc_exec(cmd, NULL, backup_parse_list, NULL, backup_finish_list, - state, ctx, req); + return ops->exec(cmd, NULL, backup_parse_list, NULL, backup_finish_list, + state, ctx, req); } static int @@ -1848,8 +1849,8 @@ opkg_exec_list(const char *action, struct blob_attr *msg, if (state->req_count <= 0 || state->req_count > 100) state->req_count = 100; - return rpc_exec(cmd, NULL, opkg_parse_list, NULL, opkg_finish_list, - state, ctx, req); + return ops->exec(cmd, NULL, opkg_parse_list, NULL, opkg_finish_list, + state, ctx, req); } @@ -1883,7 +1884,7 @@ rpc_luci2_opkg_update(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { const char *cmd[3] = { "opkg", "update", NULL }; - return rpc_exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); + return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } static int @@ -1903,7 +1904,7 @@ rpc_luci2_opkg_install(struct ubus_context *ctx, struct ubus_object *obj, cmd[3] = blobmsg_data(tb[RPC_OP_PACKAGE]); - return rpc_exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); + return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } static int @@ -1923,7 +1924,7 @@ rpc_luci2_opkg_remove(struct ubus_context *ctx, struct ubus_object *obj, cmd[3] = blobmsg_data(tb[RPC_OP_PACKAGE]); - return rpc_exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); + return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } static int @@ -1987,16 +1988,16 @@ menu_access(struct blob_attr *sid, struct blob_attr *acls, struct blob_buf *e) blobmsg_for_each_attr(acl, acls, rem) { - if (!rpc_session_access(blobmsg_data(sid), "luci-ui", - blobmsg_data(acl), "read")) + if (!ops->access(blobmsg_data(sid), "luci-ui", + blobmsg_data(acl), "read")) { rv = false; break; } blobmsg_add_u8(e, blobmsg_data(acl), - rpc_session_access(blobmsg_data(sid), "luci-ui", - blobmsg_data(acl), "write")); + ops->access(blobmsg_data(sid), "luci-ui", + blobmsg_data(acl), "write")); } blobmsg_close_table(e, c); @@ -2076,7 +2077,8 @@ skip: } -int rpc_luci2_api_init(struct ubus_context *ctx) +static int +rpc_luci2_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) { int rv = 0; @@ -2197,6 +2199,8 @@ int rpc_luci2_api_init(struct ubus_context *ctx) if (!cursor) return UBUS_STATUS_UNKNOWN_ERROR; + ops = o; + rv |= ubus_add_object(ctx, &system_obj); rv |= ubus_add_object(ctx, &network_obj); rv |= ubus_add_object(ctx, &opkg_obj); @@ -2204,3 +2208,7 @@ int rpc_luci2_api_init(struct ubus_context *ctx) return rv; } + +const struct rpc_plugin rpc_plugin = { + .init = rpc_luci2_api_init +}; diff --git a/luci2.h b/luci2.h index 0e7fc89..480c973 100644 --- a/luci2.h +++ b/luci2.h @@ -30,6 +30,4 @@ /* location of menu definitions */ #define RPC_LUCI2_MENU_FILES "/usr/share/luci2/menu.d/*.json" -int rpc_luci2_api_init(struct ubus_context *ctx); - #endif diff --git a/main.c b/main.c index e8d6805..5f5c17f 100644 --- a/main.c +++ b/main.c @@ -25,7 +25,6 @@ #include "session.h" #include "uci.h" -#include "luci2.h" #include "plugin.h" static struct ubus_context *ctx; @@ -62,7 +61,6 @@ int main(int argc, char **argv) rpc_session_api_init(ctx); rpc_uci_api_init(ctx); - rpc_luci2_api_init(ctx); rpc_plugin_api_init(ctx); uloop_run(); -- 2.11.0