|
1 --- net-snmp/include/net-snmp/library/container.h Mon Dec 5 00:13:04 2005 |
|
2 +++ net-snmp/include/net-snmp/library/container.h Fri Jan 14 17:35:37 2011 |
|
3 @@ -31,8 +31,16 @@ |
|
4 struct netsnmp_container_s; /** forward declare */ |
|
5 |
|
6 /* |
|
7 - * function returning an int for an operation on a container |
|
8 + * function for performing an operation on a container which |
|
9 + * returns (maybe the same) container. |
|
10 */ |
|
11 + |
|
12 + typedef struct netsnmp_container_s* (netsnmp_container_mod_op) |
|
13 + (struct netsnmp_container_s *, void *context, u_int flags); |
|
14 + |
|
15 + /* |
|
16 + * function for setting an option on a container |
|
17 + */ |
|
18 typedef int (netsnmp_container_option)(struct netsnmp_container_s *, |
|
19 int set, u_int flags); |
|
20 |
|
21 @@ -192,6 +200,14 @@ |
|
22 netsnmp_container_op *insert_filter; |
|
23 |
|
24 /* |
|
25 + * OPTIONAL function to duplicate a container. Defaults to a shallow |
|
26 + * copy. Only the specified container is copied (i.e. sub-containers |
|
27 + * not included). |
|
28 + */ |
|
29 + |
|
30 + netsnmp_container_mod_op *duplicate; |
|
31 + |
|
32 + /* |
|
33 * function to compare two object stored in the container. |
|
34 * |
|
35 * Returns: |
|
36 @@ -219,11 +235,16 @@ |
|
37 |
|
38 /* |
|
39 * sort count, for iterators to track (insert/delete |
|
40 - * bumps coutner, invalidates iterator |
|
41 + * bumps counter, invalidates iterator) |
|
42 */ |
|
43 u_long sync; |
|
44 |
|
45 /* |
|
46 + * flags |
|
47 + */ |
|
48 + u_int flags; |
|
49 + |
|
50 + /* |
|
51 * containers can contain other containers (additional indexes) |
|
52 */ |
|
53 struct netsnmp_container_s *next, *prev; |
|
54 @@ -288,15 +309,15 @@ |
|
55 #define CONTAINER_SET_OPTIONS(x,o,rc) do { \ |
|
56 if (NULL==(x)->options) \ |
|
57 rc = -1; \ |
|
58 - else \ |
|
59 + else { \ |
|
60 rc = (x)->options(x, 1, o); \ |
|
61 + if (rc != -1 ) \ |
|
62 + (x)->flags |= o; \ |
|
63 + } \ |
|
64 } while(0) |
|
65 |
|
66 #define CONTAINER_CHECK_OPTION(x,o,rc) do { \ |
|
67 - if (NULL==(x)->options) \ |
|
68 - rc = -1; \ |
|
69 - else \ |
|
70 - rc = (x)->options(x,0, o); \ |
|
71 + rc = x->flags & 0; \ |
|
72 } while(0) |
|
73 |
|
74 |
|
75 @@ -335,6 +356,12 @@ |
|
76 int CONTAINER_REMOVE(netsnmp_container *x, const void *k); |
|
77 |
|
78 /* |
|
79 + * duplicate container |
|
80 + */ |
|
81 + netsnmp_container *CONTAINER_DUP(netsnmp_container *x, void *ctx, |
|
82 + u_int flags); |
|
83 + |
|
84 + /* |
|
85 * clear all containers. When clearing the *first* container, and |
|
86 * *only* the first container, call the function f for each item. |
|
87 * After calling this function, all containers should be empty. |
|
88 @@ -364,7 +391,7 @@ |
|
89 continue; |
|
90 rc2 = x->insert(x,k); |
|
91 if (rc2) { |
|
92 - snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", |
|
93 + snmp_log(LOG_DEBUG,"error on subcontainer '%s' insert (%d)\n", |
|
94 x->container_name ? x->container_name : "", rc2); |
|
95 rc = rc2; |
|
96 } |
|
97 @@ -402,6 +429,22 @@ |
|
98 * container.c. If you change one, change them both. |
|
99 */ |
|
100 NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ |
|
101 + netsnmp_container *CONTAINER_DUP(netsnmp_container *x, void *ctx, |
|
102 + u_int flags) |
|
103 + { |
|
104 + if (NULL == x->duplicate) { |
|
105 + snmp_log(LOG_ERR, "container '%s' does not support duplicate\n", |
|
106 + x->container_name ? x->container_name : ""); |
|
107 + return NULL; |
|
108 + } |
|
109 + return x->duplicate(x, ctx, flags); |
|
110 + } |
|
111 + |
|
112 + /*------------------------------------------------------------------ |
|
113 + * These functions should EXACTLY match the function version in |
|
114 + * container.c. If you change one, change them both. |
|
115 + */ |
|
116 + NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ |
|
117 int CONTAINER_FREE(netsnmp_container *x) |
|
118 { |
|
119 int rc2, rc = 0; |
|
120 @@ -474,6 +517,10 @@ |
|
121 } |
|
122 |
|
123 #endif |
|
124 + |
|
125 + /** Duplicate container meta-data. */ |
|
126 + int netsnmp_container_data_dup(netsnmp_container *dup, |
|
127 + netsnmp_container *c); |
|
128 |
|
129 /************************************************************************* |
|
130 * |
|
131 --- net-snmp/snmplib/container_binary_array.c Wed Aug 23 21:23:22 2006 |
|
132 +++ net-snmp/snmplib/container_binary_array.c Fri Jan 14 17:35:37 2011 |
|
133 @@ -36,7 +36,6 @@ |
|
134 typedef struct binary_array_table_s { |
|
135 size_t max_size; /* Size of the current data table */ |
|
136 size_t count; /* Index of the next free entry */ |
|
137 - u_int flags; /* flags */ |
|
138 int dirty; |
|
139 int data_size; /* Size of an individual entry */ |
|
140 void **data; /* The table itself */ |
|
141 @@ -99,7 +98,7 @@ |
|
142 netsnmp_assert(t!=NULL); |
|
143 netsnmp_assert(c->compare!=NULL); |
|
144 |
|
145 - if (t->flags & CONTAINER_KEY_UNSORTED) |
|
146 + if (c->flags & CONTAINER_KEY_UNSORTED) |
|
147 return 0; |
|
148 |
|
149 if (t->dirty) { |
|
150 @@ -204,11 +203,16 @@ |
|
151 int |
|
152 netsnmp_binary_array_options_set(netsnmp_container *c, int set, u_int flags) |
|
153 { |
|
154 - binary_array_table *t = (binary_array_table*)c->container_data; |
|
155 - if (set) |
|
156 - t->flags = flags; |
|
157 +#define BA_FLAGS (CONTAINER_KEY_ALLOW_DUPLICATES|CONTAINER_KEY_UNSORTED) |
|
158 + |
|
159 + if (set) { |
|
160 + if ((flags & BA_FLAGS) == flags) |
|
161 + c->flags = flags; |
|
162 + else |
|
163 + flags = (u_int)-1; /* unsupported flag */ |
|
164 + } |
|
165 else |
|
166 - return ((t->flags & flags) == flags); |
|
167 + return ((c->flags & flags) == flags); |
|
168 return flags; |
|
169 } |
|
170 |
|
171 @@ -371,7 +375,7 @@ |
|
172 /* |
|
173 * check for duplicates |
|
174 */ |
|
175 - if (! (t->flags & CONTAINER_KEY_ALLOW_DUPLICATES)) { |
|
176 + if (! (c->flags & CONTAINER_KEY_ALLOW_DUPLICATES)) { |
|
177 new_data = netsnmp_binary_array_get(c, entry, 1); |
|
178 if (NULL != new_data) { |
|
179 DEBUGMSGTL(("container","not inserting duplicate key\n")); |
|
180 @@ -579,6 +583,56 @@ |
|
181 return va; |
|
182 } |
|
183 |
|
184 +static netsnmp_container * |
|
185 +_ba_duplicate(netsnmp_container *c, void *ctx, u_int flags) |
|
186 +{ |
|
187 + netsnmp_container *dup; |
|
188 + binary_array_table *dupt, *t; |
|
189 + |
|
190 + if (flags) { |
|
191 + snmp_log(LOG_ERR, "binary arry duplicate does not supprt flags yet\n"); |
|
192 + return NULL; |
|
193 + } |
|
194 + |
|
195 + dup = netsnmp_container_get_binary_array(); |
|
196 + if (NULL == dup) { |
|
197 + snmp_log(LOG_ERR," no memory for binary array duplicate\n"); |
|
198 + return NULL; |
|
199 + } |
|
200 + /* |
|
201 + * deal with container stuff |
|
202 + */ |
|
203 + if (netsnmp_container_data_dup(dup, c) != 0) { |
|
204 + netsnmp_binary_array_release(dup); |
|
205 + return NULL; |
|
206 + } |
|
207 + |
|
208 + /* |
|
209 + * deal with data |
|
210 + */ |
|
211 + dupt = (binary_array_table*)dup->container_data; |
|
212 + t = (binary_array_table*)c->container_data; |
|
213 + |
|
214 + dupt->max_size = t->max_size; |
|
215 + dupt->count = t->count; |
|
216 + dupt->dirty = t->dirty; |
|
217 + dupt->data_size = t->data_size; |
|
218 + |
|
219 + /* |
|
220 + * shallow copy |
|
221 + */ |
|
222 + dupt->data = (void**) calloc(dupt->max_size, dupt->data_size); |
|
223 + if (NULL == dupt->data) { |
|
224 + snmp_log(LOG_ERR, "no memory for binary array duplicate\n"); |
|
225 + netsnmp_binary_array_release(dup); |
|
226 + return NULL; |
|
227 + } |
|
228 + |
|
229 + memcpy(dupt->data, t->data, dupt->max_size * dupt->data_size); |
|
230 + |
|
231 + return dup; |
|
232 +} |
|
233 + |
|
234 netsnmp_container * |
|
235 netsnmp_container_get_binary_array(void) |
|
236 { |
|
237 @@ -592,7 +646,11 @@ |
|
238 } |
|
239 |
|
240 c->container_data = netsnmp_binary_array_initialize(); |
|
241 - |
|
242 + |
|
243 + /* |
|
244 + * NOTE: CHANGES HERE MUST BE DUPLICATED IN duplicate AS WELL!! |
|
245 + */ |
|
246 + |
|
247 c->get_size = _ba_size; |
|
248 c->init = NULL; |
|
249 c->cfree = _ba_free; |
|
250 @@ -604,6 +662,7 @@ |
|
251 c->get_iterator = _ba_iterator_get; |
|
252 c->for_each = _ba_for_each; |
|
253 c->clear = _ba_clear; |
|
254 + c->duplicate = _ba_duplicate; |
|
255 |
|
256 return c; |
|
257 } |
|
258 --- net-snmp/snmplib/container.c Fri Aug 25 15:11:06 2006 |
|
259 +++ net-snmp/snmplib/container.c Fri Jan 14 17:35:37 2011 |
|
260 @@ -278,7 +278,7 @@ |
|
261 continue; |
|
262 rc2 = x->insert(x,k); |
|
263 if (rc2) { |
|
264 - snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", |
|
265 + snmp_log(LOG_DEBUG,"error on subcontainer '%s' insert (%d)\n", |
|
266 x->container_name ? x->container_name : "", rc2); |
|
267 rc = rc2; |
|
268 } |
|
269 @@ -311,6 +311,20 @@ |
|
270 } |
|
271 |
|
272 /*------------------------------------------------------------------ |
|
273 + * These functions should EXACTLY match the function version in |
|
274 + * container.c. If you change one, change them both. |
|
275 + */ |
|
276 +netsnmp_container *CONTAINER_DUP(netsnmp_container *x, void *ctx, u_int flags) |
|
277 +{ |
|
278 + if (NULL == x->duplicate) { |
|
279 + snmp_log(LOG_ERR, "container '%s' does not support duplicate\n", |
|
280 + x->container_name ? x->container_name : ""); |
|
281 + return NULL; |
|
282 + } |
|
283 + return x->duplicate(x, ctx, flags); |
|
284 +} |
|
285 + |
|
286 +/*------------------------------------------------------------------ |
|
287 * These functions should EXACTLY match the inline version in |
|
288 * container.h. If you change one, change them both. |
|
289 */ |
|
290 @@ -408,6 +422,24 @@ |
|
291 c->find = fnd; |
|
292 } |
|
293 |
|
294 +int |
|
295 +netsnmp_container_data_dup(netsnmp_container *dup, netsnmp_container *c) |
|
296 +{ |
|
297 + if (!dup || !c) |
|
298 + return -1; |
|
299 + |
|
300 + if (c->container_name) |
|
301 + dup->container_name = strdup(c->container_name); |
|
302 + dup->compare = c->compare; |
|
303 + dup->ncompare = c->ncompare; |
|
304 + dup->release = c->release; |
|
305 + dup->insert_filter = c->insert_filter; |
|
306 + dup->sync = c->sync; |
|
307 + dup->flags = c->flags; |
|
308 + |
|
309 + return 0; |
|
310 +} |
|
311 + |
|
312 /*------------------------------------------------------------------ |
|
313 * |
|
314 * simple comparison routines |