fc34090297e605e5783f95308b41fd49d545e701
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)
41 #define UCIMAP_SECTION(_name, _field) \
42 .alloc_len = sizeof(_name), \
43 .smap_offset = offsetof(_name, _field)
45 struct uci_sectionmap
;
50 struct uci_sectionmap
**sections
;
51 unsigned int n_sections
;
52 struct list_head sdata
;
53 struct list_head fixup
;
55 void *priv
; /* user data */
62 UCIMAP_TYPE
= 0xf0, /* type mask */
70 UCIMAP_SUBTYPE
= 0xf, /* subtype mask */
78 struct ucimap_list
*list
;
81 struct ucimap_section_data
{
82 struct list_head list
;
84 struct uci_sectionmap
*sm
;
85 const char *section_name
;
87 /* list of allocations done by ucimap */
88 struct uci_alloc
*allocmap
;
89 unsigned long allocmap_len
;
91 /* map for changed fields */
98 struct list_head list
;
99 union ucimap_data data
;
102 struct uci_sectionmap
{
103 /* type string for the uci section */
106 /* length of the struct to map into */
107 unsigned int alloc_len
;
109 /* sectionmap offset */
110 unsigned int smap_offset
;
112 /* allocate a new data structure and return a pointer to the section map data */
113 struct ucimap_section_data
*(*alloc
)(struct uci_map
*map
,
114 struct uci_sectionmap
*sm
, struct uci_section
*s
);
116 /* give the caller time to initialize the preallocated struct */
117 int (*init
)(struct uci_map
*map
, void *section
, struct uci_section
*s
);
119 /* pass the fully processed struct to the callback after the section end */
120 int (*add
)(struct uci_map
*map
, void *section
);
122 /* let the callback clean up its own stuff in the section */
123 int (*free
)(struct uci_map
*map
, void *section
);
125 /* list of option mappings for this section */
126 struct uci_optmap
*options
;
127 unsigned int n_options
;
128 unsigned int options_size
;
134 enum ucimap_type type
;
135 int (*parse
)(void *section
, struct uci_optmap
*om
, union ucimap_data
*data
, const char *string
);
136 int (*format
)(void *section
, struct uci_optmap
*om
, union ucimap_data
*data
, char **string
);
146 struct uci_sectionmap
*sm
;
152 union ucimap_data item
[];
155 extern int ucimap_init(struct uci_map
*map
);
156 extern void ucimap_cleanup(struct uci_map
*map
);
157 extern void ucimap_set_changed(struct ucimap_section_data
*sd
, void *field
);
158 extern int ucimap_store_section(struct uci_map
*map
, struct uci_package
*p
, struct ucimap_section_data
*sd
);
159 extern void ucimap_parse(struct uci_map
*map
, struct uci_package
*pkg
);