2 * libuci - Library for the Unified Configuration Interface
3 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 * this program is free software; you can redistribute it and/or modify
6 * it under the terms of the gnu lesser general public license version 2.1
7 * as published by the free software foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
21 #define UCI_CONFDIR "/etc/config"
44 struct uci_parse_context;
48 * uci_alloc: Allocate a new uci context
50 extern struct uci_context *uci_alloc(void);
53 * uci_perror: Print the last uci error that occured
55 * @str: string to print before the error message
57 extern void uci_perror(struct uci_context *ctx, const char *str);
60 * uci_load: Parse an uci config file and store it in the uci context
63 * @name: name of the config file (relative to the config directory)
65 int uci_load(struct uci_context *ctx, const char *name);
68 * uci_cleanup: Clean up after an error
72 int uci_cleanup(struct uci_context *ctx);
75 /* UCI data structures */
81 /* for error handling only */
82 struct uci_parse_context *pctx;
91 struct uci_parse_context
97 struct uci_config *cfg;
105 struct uci_list list;
106 struct uci_list sections;
107 struct uci_context *ctx;
113 struct uci_list list;
114 struct uci_list options;
115 struct uci_config *config;
122 struct uci_list list;
123 struct uci_section *section;
128 /* linked list handling */
130 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
133 #define uci_list_empty(list) (list->next == ptr)
134 #define uci_list_entry(_type, _ptr) \
135 ((struct uci_ ## _type *) ((char *)(_ptr) - offsetof(struct uci_ ## _type,list)))
137 #define uci_foreach_entry(_type, _list, _ptr) \
138 for(_ptr = uci_list_entry(_type, (_list)->next); \
139 &_ptr->list != (_list); \
140 _ptr = uci_list_entry(_type, _ptr->list.next))