uci: add state call to retrieve uci state variables
[project/rpcd.git] / uci.c
diff --git a/uci.c b/uci.c
index a133ff2..a49c8d0 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -520,9 +520,8 @@ rpc_uci_dump_package(struct uci_package *p, const char *name,
 
 
 static int
 
 
 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;
 {
        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]);
 
 
        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();
 
        if (uci_load(cursor, ptr.package, &p))
                return rpc_uci_status();
 
@@ -582,6 +584,22 @@ out:
 }
 
 static int
 }
 
 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,
             struct blob_attr *msg)
 rpc_uci_add(struct ubus_context *ctx, struct ubus_object *obj,
             struct ubus_request_data *req, const char *method,
             struct blob_attr *msg)
@@ -682,6 +700,7 @@ rpc_uci_merge_set(struct blob_attr *opt, struct uci_ptr *ptr)
 
        ptr->o = NULL;
        ptr->option = blobmsg_name(opt);
 
        ptr->o = NULL;
        ptr->option = blobmsg_name(opt);
+       ptr->value = NULL;
 
        if (rpc_uci_lookup(ptr) || !ptr->s)
                return;
 
        if (rpc_uci_lookup(ptr) || !ptr->s)
                return;
@@ -1443,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),
        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),
                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),