X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=libuci.h;fp=libuci.h;h=e4990a207b246f9e62bd32629a8d8bf40d8c65a5;hp=9411b5453460c1f223ca166671dac456454b7960;hb=60c0c8e8fe97a3c2a46093657af7c1d168a53c46;hpb=4535c379ced2bdb6a4b414f71080fa0c6f5180aa diff --git a/libuci.h b/libuci.h index 9411b54..e4990a2 100644 --- a/libuci.h +++ b/libuci.h @@ -29,31 +29,16 @@ enum UCI_ERR_LAST }; -struct uci_config; -struct uci_parse_context; - -struct uci_context +struct uci_list { - struct uci_config *root; - - /* for error handling only */ - struct uci_parse_context *pctx; - - /* private: */ - int errno; - jmp_buf trap; + void *next; + void *prev; }; -struct uci_parse_context -{ - int line; - int byte; - - /* private: */ - FILE *file; - char *buf; - int bufsz; -}; +struct uci_config; +struct uci_section; +struct uci_option; +struct uci_parse_context; /** @@ -83,4 +68,69 @@ int uci_parse(struct uci_context *ctx, const char *name); */ int uci_cleanup(struct uci_context *ctx); + +/* UCI data structures */ + +struct uci_context +{ + struct uci_list root; + + /* for error handling only */ + struct uci_parse_context *pctx; + + /* private: */ + int errno; + jmp_buf trap; +}; + +struct uci_parse_context +{ + int line; + int byte; + + /* private: */ + FILE *file; + char *buf; + int bufsz; +}; + +struct uci_config +{ + struct uci_list list; + struct uci_list sections; + struct uci_context *ctx; + char *name; +}; + +struct uci_section +{ + struct uci_list list; + struct uci_list options; + struct uci_config *config; + char *type; + char *name; +}; + +struct uci_option +{ + struct uci_list list; + struct uci_section *section; + char *name; + char *value; +}; + +/* linked list handling */ +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + +#define uci_list_entry(type, ptr) \ + ((struct uci_#type *) ((char *)(ptr) - offsetof(struct uci_#type,list))) + + +#define uci_foreach_entry(type, list, ptr) \ + for(ptr = uci_list_entry(type, (list)->next); \ + &ptr->list != list; \ + ptr = uci_list_entry(type, ptr->list.next)) + #endif