]> pilppa.com Git - uci.git/commitdiff
implement uci get
authorFelix Fietkau <nbd@openwrt.org>
Sun, 27 Jan 2008 23:10:55 +0000 (00:10 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 27 Jan 2008 23:10:55 +0000 (00:10 +0100)
cli.c
uci.h

diff --git a/cli.c b/cli.c
index b7ddd511676ed82fdfe9ce77c841bb6a8cc74ad0..4e0c5b715d9bbebfc7f8d18de6cfc730a19eaa93 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -94,12 +94,54 @@ static int uci_do_export(int argc, char **argv)
        return 0;
 }
 
+
+
+static int uci_do_get(int argc, char **argv)
+{
+       char *package = NULL;
+       char *section = NULL;
+       char *option = NULL;
+       struct uci_package *p = NULL;
+       struct uci_element *e = NULL;
+       char *value = NULL;
+
+       package = strtok(argv[1], ".");
+       if (!package)
+               return 1;
+
+       section = strtok(NULL, ".");
+       if (section)
+               option = strtok(NULL, ".");
+
+       if (uci_load(ctx, package, &p) != UCI_OK) {
+               uci_perror(ctx, "uci");
+               return 1;
+       }
+       if (uci_lookup(ctx, &e, package, section, option) != UCI_OK)
+               return 1;
+       switch(e->type) {
+       case UCI_TYPE_SECTION:
+               value = uci_to_section(e)->type;
+               break;
+       case UCI_TYPE_OPTION:
+               value = uci_to_option(e)->value;
+               break;
+       default:
+               /* should not happen */
+               return 1;
+       }
+       printf("%s\n", value);
+       return 0;
+}
+
 static int uci_cmd(int argc, char **argv)
 {
        if (!strcasecmp(argv[0], "show"))
                return uci_show(argc, argv);
        if (!strcasecmp(argv[0], "export"))
                return uci_do_export(argc, argv);
+       if (!strcasecmp(argv[0], "get"))
+               return uci_do_get(argc, argv);
        return 255;
 }
 
diff --git a/uci.h b/uci.h
index a6572c5d3a4355672cb993ade6bcf5082c3a87f3..021e5b3e2197df6578664961906e73e103af4be9 100644 (file)
--- a/uci.h
+++ b/uci.h
@@ -144,9 +144,9 @@ extern char **uci_list_configs(struct uci_context *ctx);
 
 /* UCI data structures */
 enum uci_type {
-       uci_type_package = 0,
-       uci_type_section = 1,
-       uci_type_option = 2
+       UCI_TYPE_PACKAGE = 0,
+       UCI_TYPE_SECTION = 1,
+       UCI_TYPE_OPTION = 2
 };
 
 struct uci_element
@@ -290,6 +290,11 @@ struct uci_history
 /* returns true if a list is empty */
 #define uci_list_empty(list) ((list)->next == (list))
 
+/* wrappers for dynamic type handling */
+#define uci_type_package UCI_TYPE_PACKAGE
+#define uci_type_section UCI_TYPE_SECTION
+#define uci_type_option UCI_TYPE_OPTION
+
 /* element typecasting */
 #ifdef UCI_DEBUG_TYPECAST
 static const char *uci_typestr[] = {