uci: expose section ordering index when dumping complete packages
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 19 Jun 2013 09:33:17 +0000 (11:33 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 19 Jun 2013 09:33:17 +0000 (11:33 +0200)
uci.c

diff --git a/uci.c b/uci.c
index 9485cdf..35a0317 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -352,7 +352,7 @@ rpc_uci_dump_option(struct uci_option *o, const char *name)
  * corresponding section properties.
  */
 static void
  * corresponding section properties.
  */
 static void
-rpc_uci_dump_section(struct uci_section *s, const char *name)
+rpc_uci_dump_section(struct uci_section *s, const char *name, int index)
 {
        void *c;
        struct uci_option *o;
 {
        void *c;
        struct uci_option *o;
@@ -364,6 +364,9 @@ rpc_uci_dump_section(struct uci_section *s, const char *name)
        blobmsg_add_string(&buf, ".type", s->type);
        blobmsg_add_string(&buf, ".name", s->e.name);
 
        blobmsg_add_string(&buf, ".type", s->type);
        blobmsg_add_string(&buf, ".name", s->e.name);
 
+       if (index >= 0)
+               blobmsg_add_u32(&buf, ".index", index);
+
        uci_foreach_element(&s->options, e)
        {
                o = uci_to_option(e);
        uci_foreach_element(&s->options, e)
        {
                o = uci_to_option(e);
@@ -387,15 +390,18 @@ rpc_uci_dump_package(struct uci_package *p, const char *name,
 {
        void *c;
        struct uci_element *e;
 {
        void *c;
        struct uci_element *e;
+       int i = -1;
 
        c = blobmsg_open_table(&buf, name);
 
        uci_foreach_element(&p->sections, e)
        {
 
        c = blobmsg_open_table(&buf, name);
 
        uci_foreach_element(&p->sections, e)
        {
+               i++;
+
                if (!rpc_uci_match_section(uci_to_section(e), type, matches))
                        continue;
 
                if (!rpc_uci_match_section(uci_to_section(e), type, matches))
                        continue;
 
-               rpc_uci_dump_section(uci_to_section(e), e->name);
+               rpc_uci_dump_section(uci_to_section(e), e->name, i);
        }
 
        blobmsg_close_table(&buf, c);
        }
 
        blobmsg_close_table(&buf, c);
@@ -443,7 +449,7 @@ rpc_uci_get(struct ubus_context *ctx, struct ubus_object *obj,
                break;
 
        case UCI_TYPE_SECTION:
                break;
 
        case UCI_TYPE_SECTION:
-               rpc_uci_dump_section(ptr.s, "values");
+               rpc_uci_dump_section(ptr.s, "values", -1);
                break;
 
        case UCI_TYPE_OPTION:
                break;
 
        case UCI_TYPE_OPTION: