From 2f5a613718f5297febddb3ca7dc860ab6ed8c513 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 23 Nov 2013 19:30:29 +0000 Subject: [PATCH] uci: add state call to retrieve uci state variables --- uci.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/uci.c b/uci.c index 060ed2b..a49c8d0 100644 --- a/uci.c +++ b/uci.c @@ -520,9 +520,8 @@ rpc_uci_dump_package(struct uci_package *p, const char *name, static int -rpc_uci_get(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) +rpc_uci_getcommon(struct ubus_context *ctx, struct ubus_request_data *req, + struct blob_attr *msg, bool use_state) { struct blob_attr *tb[__RPC_G_MAX]; struct uci_package *p = NULL; @@ -539,6 +538,9 @@ rpc_uci_get(struct ubus_context *ctx, struct ubus_object *obj, ptr.package = blobmsg_data(tb[RPC_G_CONFIG]); + if (use_state) + uci_set_savedir(cursor, "/var/state"); + if (uci_load(cursor, ptr.package, &p)) return rpc_uci_status(); @@ -581,6 +583,22 @@ out: return rpc_uci_status(); } +static int +rpc_uci_get(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + return rpc_uci_getcommon(ctx, req, msg, false); +} + +static int +rpc_uci_state(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + return rpc_uci_getcommon(ctx, req, msg, true); +} + static int rpc_uci_add(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1444,6 +1462,7 @@ int rpc_uci_api_init(struct ubus_context *ctx) static const struct ubus_method uci_methods[] = { { .name = "configs", .handler = rpc_uci_configs }, UBUS_METHOD("get", rpc_uci_get, rpc_uci_get_policy), + UBUS_METHOD("state", rpc_uci_state, rpc_uci_get_policy), UBUS_METHOD("add", rpc_uci_add, rpc_uci_add_policy), UBUS_METHOD("set", rpc_uci_set, rpc_uci_set_policy), UBUS_METHOD("delete", rpc_uci_delete, rpc_uci_delete_policy), -- 2.25.1