2 * ucimap - library for mapping uci sections into data structures
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 General Public License version 2
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.
19 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
22 #define BITFIELD_SIZE(_fields) (((_fields) / 8) + 1)
24 #define CLR_BIT(_name, _bit) do { \
25 _name[(_bit) / 8] &= ~(1 << ((_bit) % 8)); \
28 #define SET_BIT(_name, _bit) do { \
29 _name[(_bit) / 8] |= (1 << ((_bit) % 8)); \
32 #define TEST_BIT(_name, _bit) \
33 (_name[(_bit) / 8] & (1 << ((_bit) % 8)))
35 #define UCIMAP_OPTION(_type, _field) \
36 .type = UCIMAP_CUSTOM, \
38 .offset = offsetof(_type, _field)
40 struct uci_sectionmap
;
45 struct uci_sectionmap
**sections
;
46 unsigned int n_sections
;
47 struct list_head sdata
;
48 struct list_head fixup
;
50 void *priv
; /* user data */
57 UCIMAP_TYPE
= 0xf0, /* type mask */
65 UCIMAP_SUBTYPE
= 0xf, /* subtype mask */
73 struct ucimap_list
*list
;
77 struct list_head list
;
78 union ucimap_data data
;
81 struct uci_sectionmap
{
82 /* type string for the uci section */
85 /* length of the struct to map into */
86 unsigned int alloc_len
;
88 /* give the caller time to initialize the preallocated struct */
89 int (*init
)(struct uci_map
*map
, void *section
, struct uci_section
*s
);
91 /* pass the fully processed struct to the callback after the section end */
92 int (*add
)(struct uci_map
*map
, void *section
);
94 /* let the callback clean up its own stuff in the section */
95 int (*free
)(struct uci_map
*map
, void *section
);
97 /* list of option mappings for this section */
98 struct uci_optmap
*options
;
99 unsigned int n_options
;
100 unsigned int options_size
;
106 enum ucimap_type type
;
107 int (*parse
)(void *section
, struct uci_optmap
*om
, union ucimap_data
*data
, const char *string
);
117 struct uci_sectionmap
*sm
;
123 union ucimap_data item
[];
126 extern int ucimap_init(struct uci_map
*map
);
127 extern void ucimap_cleanup(struct uci_map
*map
);
128 extern void ucimap_set_changed(void *section
, void *field
);
129 extern int ucimap_store_section(struct uci_map
*map
, struct uci_package
*p
, void *section
);
130 extern void ucimap_parse(struct uci_map
*map
, struct uci_package
*pkg
);