#include <glob.h>
#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;
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
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
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
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);
}
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
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
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
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);
}
-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;
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);
return rv;
}
+
+const struct rpc_plugin rpc_plugin = {
+ .init = rpc_luci2_api_init
+};