diff options
Diffstat (limited to 'src/reclaim-attribute/reclaim_attribute.c')
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.c | 340 |
1 files changed, 170 insertions, 170 deletions
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 96e61d431..9ef648708 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file reclaim-attribute/reclaim_attribute.c | 22 | * @file reclaim-attribute/reclaim_attribute.c |
@@ -32,8 +32,7 @@ | |||
32 | /** | 32 | /** |
33 | * Handle for a plugin | 33 | * Handle for a plugin |
34 | */ | 34 | */ |
35 | struct Plugin | 35 | struct Plugin { |
36 | { | ||
37 | /** | 36 | /** |
38 | * Name of the plugin | 37 | * Name of the plugin |
39 | */ | 38 | */ |
@@ -72,18 +71,18 @@ static int initialized; | |||
72 | * @param lib_ret the plugin API pointer | 71 | * @param lib_ret the plugin API pointer |
73 | */ | 72 | */ |
74 | static void | 73 | static void |
75 | add_plugin (void *cls, const char *library_name, void *lib_ret) | 74 | add_plugin(void *cls, const char *library_name, void *lib_ret) |
76 | { | 75 | { |
77 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; | 76 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; |
78 | struct Plugin *plugin; | 77 | struct Plugin *plugin; |
79 | 78 | ||
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
81 | "Loading attribute plugin `%s'\n", | 80 | "Loading attribute plugin `%s'\n", |
82 | library_name); | 81 | library_name); |
83 | plugin = GNUNET_new (struct Plugin); | 82 | plugin = GNUNET_new(struct Plugin); |
84 | plugin->api = api; | 83 | plugin->api = api; |
85 | plugin->library_name = GNUNET_strdup (library_name); | 84 | plugin->library_name = GNUNET_strdup(library_name); |
86 | GNUNET_array_append (attr_plugins, num_plugins, plugin); | 85 | GNUNET_array_append(attr_plugins, num_plugins, plugin); |
87 | } | 86 | } |
88 | 87 | ||
89 | 88 | ||
@@ -91,15 +90,15 @@ add_plugin (void *cls, const char *library_name, void *lib_ret) | |||
91 | * Load plugins | 90 | * Load plugins |
92 | */ | 91 | */ |
93 | static void | 92 | static void |
94 | init () | 93 | init() |
95 | { | 94 | { |
96 | if (GNUNET_YES == initialized) | 95 | if (GNUNET_YES == initialized) |
97 | return; | 96 | return; |
98 | initialized = GNUNET_YES; | 97 | initialized = GNUNET_YES; |
99 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_attribute_", | 98 | GNUNET_PLUGIN_load_all("libgnunet_plugin_reclaim_attribute_", |
100 | NULL, | 99 | NULL, |
101 | &add_plugin, | 100 | &add_plugin, |
102 | NULL); | 101 | NULL); |
103 | } | 102 | } |
104 | 103 | ||
105 | 104 | ||
@@ -110,20 +109,20 @@ init () | |||
110 | * @return corresponding number, UINT32_MAX on error | 109 | * @return corresponding number, UINT32_MAX on error |
111 | */ | 110 | */ |
112 | uint32_t | 111 | uint32_t |
113 | GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) | 112 | GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(const char *typename) |
114 | { | 113 | { |
115 | unsigned int i; | 114 | unsigned int i; |
116 | struct Plugin *plugin; | 115 | struct Plugin *plugin; |
117 | uint32_t ret; | 116 | uint32_t ret; |
118 | 117 | ||
119 | init (); | 118 | init(); |
120 | for (i = 0; i < num_plugins; i++) | 119 | for (i = 0; i < num_plugins; i++) |
121 | { | 120 | { |
122 | plugin = attr_plugins[i]; | 121 | plugin = attr_plugins[i]; |
123 | if (UINT32_MAX != | 122 | if (UINT32_MAX != |
124 | (ret = plugin->api->typename_to_number (plugin->api->cls, typename))) | 123 | (ret = plugin->api->typename_to_number(plugin->api->cls, typename))) |
125 | return ret; | 124 | return ret; |
126 | } | 125 | } |
127 | return UINT32_MAX; | 126 | return UINT32_MAX; |
128 | } | 127 | } |
129 | 128 | ||
@@ -135,20 +134,20 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) | |||
135 | * @return corresponding typestring, NULL on error | 134 | * @return corresponding typestring, NULL on error |
136 | */ | 135 | */ |
137 | const char * | 136 | const char * |
138 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) | 137 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(uint32_t type) |
139 | { | 138 | { |
140 | unsigned int i; | 139 | unsigned int i; |
141 | struct Plugin *plugin; | 140 | struct Plugin *plugin; |
142 | const char *ret; | 141 | const char *ret; |
143 | 142 | ||
144 | init (); | 143 | init(); |
145 | for (i = 0; i < num_plugins; i++) | 144 | for (i = 0; i < num_plugins; i++) |
146 | { | 145 | { |
147 | plugin = attr_plugins[i]; | 146 | plugin = attr_plugins[i]; |
148 | if (NULL != | 147 | if (NULL != |
149 | (ret = plugin->api->number_to_typename (plugin->api->cls, type))) | 148 | (ret = plugin->api->number_to_typename(plugin->api->cls, type))) |
150 | return ret; | 149 | return ret; |
151 | } | 150 | } |
152 | return NULL; | 151 | return NULL; |
153 | } | 152 | } |
154 | 153 | ||
@@ -164,25 +163,25 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) | |||
164 | * @return #GNUNET_OK on success | 163 | * @return #GNUNET_OK on success |
165 | */ | 164 | */ |
166 | int | 165 | int |
167 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, | 166 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value(uint32_t type, |
168 | const char *s, | 167 | const char *s, |
169 | void **data, | 168 | void **data, |
170 | size_t *data_size) | 169 | size_t *data_size) |
171 | { | 170 | { |
172 | unsigned int i; | 171 | unsigned int i; |
173 | struct Plugin *plugin; | 172 | struct Plugin *plugin; |
174 | 173 | ||
175 | init (); | 174 | init(); |
176 | for (i = 0; i < num_plugins; i++) | 175 | for (i = 0; i < num_plugins; i++) |
177 | { | 176 | { |
178 | plugin = attr_plugins[i]; | 177 | plugin = attr_plugins[i]; |
179 | if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, | 178 | if (GNUNET_OK == plugin->api->string_to_value(plugin->api->cls, |
180 | type, | 179 | type, |
181 | s, | 180 | s, |
182 | data, | 181 | data, |
183 | data_size)) | 182 | data_size)) |
184 | return GNUNET_OK; | 183 | return GNUNET_OK; |
185 | } | 184 | } |
186 | return GNUNET_SYSERR; | 185 | return GNUNET_SYSERR; |
187 | } | 186 | } |
188 | 187 | ||
@@ -196,24 +195,24 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, | |||
196 | * @return NULL on error, otherwise human-readable representation of the claim | 195 | * @return NULL on error, otherwise human-readable representation of the claim |
197 | */ | 196 | */ |
198 | char * | 197 | char * |
199 | GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | 198 | GNUNET_RECLAIM_ATTRIBUTE_value_to_string(uint32_t type, |
200 | const void *data, | 199 | const void *data, |
201 | size_t data_size) | 200 | size_t data_size) |
202 | { | 201 | { |
203 | unsigned int i; | 202 | unsigned int i; |
204 | struct Plugin *plugin; | 203 | struct Plugin *plugin; |
205 | char *ret; | 204 | char *ret; |
206 | 205 | ||
207 | init (); | 206 | init(); |
208 | for (i = 0; i < num_plugins; i++) | 207 | for (i = 0; i < num_plugins; i++) |
209 | { | 208 | { |
210 | plugin = attr_plugins[i]; | 209 | plugin = attr_plugins[i]; |
211 | if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, | 210 | if (NULL != (ret = plugin->api->value_to_string(plugin->api->cls, |
212 | type, | 211 | type, |
213 | data, | 212 | data, |
214 | data_size))) | 213 | data_size))) |
215 | return ret; | 214 | return ret; |
216 | } | 215 | } |
217 | return NULL; | 216 | return NULL; |
218 | } | 217 | } |
219 | 218 | ||
@@ -228,29 +227,29 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | |||
228 | * @return the new attribute | 227 | * @return the new attribute |
229 | */ | 228 | */ |
230 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * | 229 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * |
231 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, | 230 | GNUNET_RECLAIM_ATTRIBUTE_claim_new(const char *attr_name, |
232 | uint32_t type, | 231 | uint32_t type, |
233 | const void *data, | 232 | const void *data, |
234 | size_t data_size) | 233 | size_t data_size) |
235 | { | 234 | { |
236 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 235 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
237 | char *write_ptr; | 236 | char *write_ptr; |
238 | char *attr_name_tmp = GNUNET_strdup (attr_name); | 237 | char *attr_name_tmp = GNUNET_strdup(attr_name); |
239 | 238 | ||
240 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | 239 | GNUNET_STRINGS_utf8_tolower(attr_name, attr_name_tmp); |
241 | 240 | ||
242 | attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + | 241 | attr = GNUNET_malloc(sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + |
243 | strlen (attr_name_tmp) + 1 + data_size); | 242 | strlen(attr_name_tmp) + 1 + data_size); |
244 | attr->type = type; | 243 | attr->type = type; |
245 | attr->data_size = data_size; | 244 | attr->data_size = data_size; |
246 | attr->version = 0; | 245 | attr->version = 0; |
247 | write_ptr = (char *) &attr[1]; | 246 | write_ptr = (char *)&attr[1]; |
248 | GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); | 247 | GNUNET_memcpy(write_ptr, attr_name_tmp, strlen(attr_name_tmp) + 1); |
249 | attr->name = write_ptr; | 248 | attr->name = write_ptr; |
250 | write_ptr += strlen (attr->name) + 1; | 249 | write_ptr += strlen(attr->name) + 1; |
251 | GNUNET_memcpy (write_ptr, data, data_size); | 250 | GNUNET_memcpy(write_ptr, data, data_size); |
252 | attr->data = write_ptr; | 251 | attr->data = write_ptr; |
253 | GNUNET_free (attr_name_tmp); | 252 | GNUNET_free(attr_name_tmp); |
254 | return attr; | 253 | return attr; |
255 | } | 254 | } |
256 | 255 | ||
@@ -264,20 +263,21 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, | |||
264 | * @param data_size claim payload size | 263 | * @param data_size claim payload size |
265 | */ | 264 | */ |
266 | void | 265 | void |
267 | GNUNET_RECLAIM_ATTRIBUTE_list_add ( | 266 | GNUNET_RECLAIM_ATTRIBUTE_list_add( |
268 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, | 267 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, |
269 | const char *attr_name, | 268 | const char *attr_name, |
270 | uint32_t type, | 269 | uint32_t type, |
271 | const void *data, | 270 | const void *data, |
272 | size_t data_size) | 271 | size_t data_size) |
273 | { | 272 | { |
274 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 273 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
275 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 274 | |
275 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
276 | le->claim = | 276 | le->claim = |
277 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | 277 | GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr_name, type, data, data_size); |
278 | GNUNET_CONTAINER_DLL_insert (claim_list->list_head, | 278 | GNUNET_CONTAINER_DLL_insert(claim_list->list_head, |
279 | claim_list->list_tail, | 279 | claim_list->list_tail, |
280 | le); | 280 | le); |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
@@ -288,13 +288,14 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add ( | |||
288 | * @return the required buffer size | 288 | * @return the required buffer size |
289 | */ | 289 | */ |
290 | size_t | 290 | size_t |
291 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( | 291 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size( |
292 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 292 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) |
293 | { | 293 | { |
294 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 294 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
295 | size_t len = 0; | 295 | size_t len = 0; |
296 | |||
296 | for (le = attrs->list_head; NULL != le; le = le->next) | 297 | for (le = attrs->list_head; NULL != le; le = le->next) |
297 | len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | 298 | len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(le->claim); |
298 | return len; | 299 | return len; |
299 | } | 300 | } |
300 | 301 | ||
@@ -307,9 +308,9 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( | |||
307 | * @return length of serialized data | 308 | * @return length of serialized data |
308 | */ | 309 | */ |
309 | size_t | 310 | size_t |
310 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | 311 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize( |
311 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 312 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
312 | char *result) | 313 | char *result) |
313 | { | 314 | { |
314 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 315 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
315 | size_t len; | 316 | size_t len; |
@@ -319,11 +320,11 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | |||
319 | write_ptr = result; | 320 | write_ptr = result; |
320 | total_len = 0; | 321 | total_len = 0; |
321 | for (le = attrs->list_head; NULL != le; le = le->next) | 322 | for (le = attrs->list_head; NULL != le; le = le->next) |
322 | { | 323 | { |
323 | len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); | 324 | len = GNUNET_RECLAIM_ATTRIBUTE_serialize(le->claim, write_ptr); |
324 | total_len += len; | 325 | total_len += len; |
325 | write_ptr += len; | 326 | write_ptr += len; |
326 | } | 327 | } |
327 | return total_len; | 328 | return total_len; |
328 | } | 329 | } |
329 | 330 | ||
@@ -336,32 +337,31 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | |||
336 | * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller | 337 | * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller |
337 | */ | 338 | */ |
338 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * | 339 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * |
339 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) | 340 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize(const char *data, size_t data_size) |
340 | { | 341 | { |
341 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 342 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; |
342 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 343 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
343 | size_t attr_len; | 344 | size_t attr_len; |
344 | const char *read_ptr; | 345 | const char *read_ptr; |
345 | 346 | ||
346 | if (data_size < sizeof (struct Attribute)) | 347 | if (data_size < sizeof(struct Attribute)) |
347 | return NULL; | 348 | return NULL; |
348 | 349 | ||
349 | attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 350 | attrs = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
350 | read_ptr = data; | 351 | read_ptr = data; |
351 | while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) | 352 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) |
352 | { | 353 | { |
353 | 354 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | |
354 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 355 | le->claim = |
355 | le->claim = | 356 | GNUNET_RECLAIM_ATTRIBUTE_deserialize(read_ptr, |
356 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, | 357 | data_size - (read_ptr - data)); |
357 | data_size - (read_ptr - data)); | 358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 359 | "Deserialized attribute %s\n", |
359 | "Deserialized attribute %s\n", | 360 | le->claim->name); |
360 | le->claim->name); | 361 | GNUNET_CONTAINER_DLL_insert(attrs->list_head, attrs->list_tail, le); |
361 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | 362 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(le->claim); |
362 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | 363 | read_ptr += attr_len; |
363 | read_ptr += attr_len; | 364 | } |
364 | } | ||
365 | return attrs; | 365 | return attrs; |
366 | } | 366 | } |
367 | 367 | ||
@@ -372,28 +372,28 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) | |||
372 | * @return copied claim list | 372 | * @return copied claim list |
373 | */ | 373 | */ |
374 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * | 374 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * |
375 | GNUNET_RECLAIM_ATTRIBUTE_list_dup ( | 375 | GNUNET_RECLAIM_ATTRIBUTE_list_dup( |
376 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 376 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) |
377 | { | 377 | { |
378 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 378 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
379 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; | 379 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; |
380 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; | 380 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; |
381 | 381 | ||
382 | result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 382 | result = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
383 | for (le = attrs->list_head; NULL != le; le = le->next) | 383 | for (le = attrs->list_head; NULL != le; le = le->next) |
384 | { | 384 | { |
385 | result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 385 | result_le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
386 | result_le->claim = | 386 | result_le->claim = |
387 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, | 387 | GNUNET_RECLAIM_ATTRIBUTE_claim_new(le->claim->name, |
388 | le->claim->type, | 388 | le->claim->type, |
389 | le->claim->data, | 389 | le->claim->data, |
390 | le->claim->data_size); | 390 | le->claim->data_size); |
391 | result_le->claim->version = le->claim->version; | 391 | result_le->claim->version = le->claim->version; |
392 | result_le->claim->id = le->claim->id; | 392 | result_le->claim->id = le->claim->id; |
393 | GNUNET_CONTAINER_DLL_insert (result->list_head, | 393 | GNUNET_CONTAINER_DLL_insert(result->list_head, |
394 | result->list_tail, | 394 | result->list_tail, |
395 | result_le); | 395 | result_le); |
396 | } | 396 | } |
397 | return result; | 397 | return result; |
398 | } | 398 | } |
399 | 399 | ||
@@ -404,20 +404,20 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( | |||
404 | * @param attrs list to destroy | 404 | * @param attrs list to destroy |
405 | */ | 405 | */ |
406 | void | 406 | void |
407 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( | 407 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy( |
408 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 408 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) |
409 | { | 409 | { |
410 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 410 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
411 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; | 411 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; |
412 | 412 | ||
413 | for (le = attrs->list_head; NULL != le;) | 413 | for (le = attrs->list_head; NULL != le;) |
414 | { | 414 | { |
415 | GNUNET_free (le->claim); | 415 | GNUNET_free(le->claim); |
416 | tmp_le = le; | 416 | tmp_le = le; |
417 | le = le->next; | 417 | le = le->next; |
418 | GNUNET_free (tmp_le); | 418 | GNUNET_free(tmp_le); |
419 | } | 419 | } |
420 | GNUNET_free (attrs); | 420 | GNUNET_free(attrs); |
421 | } | 421 | } |
422 | 422 | ||
423 | 423 | ||
@@ -428,10 +428,10 @@ GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( | |||
428 | * @return the required buffer size | 428 | * @return the required buffer size |
429 | */ | 429 | */ |
430 | size_t | 430 | size_t |
431 | GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( | 431 | GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size( |
432 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 432 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
433 | { | 433 | { |
434 | return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size; | 434 | return sizeof(struct Attribute) + strlen(attr->name) + attr->data_size; |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
@@ -443,32 +443,32 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( | |||
443 | * @return length of serialized data | 443 | * @return length of serialized data |
444 | */ | 444 | */ |
445 | size_t | 445 | size_t |
446 | GNUNET_RECLAIM_ATTRIBUTE_serialize ( | 446 | GNUNET_RECLAIM_ATTRIBUTE_serialize( |
447 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 447 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
448 | char *result) | 448 | char *result) |
449 | { | 449 | { |
450 | size_t data_len_ser; | 450 | size_t data_len_ser; |
451 | size_t name_len; | 451 | size_t name_len; |
452 | struct Attribute *attr_ser; | 452 | struct Attribute *attr_ser; |
453 | char *write_ptr; | 453 | char *write_ptr; |
454 | 454 | ||
455 | attr_ser = (struct Attribute *) result; | 455 | attr_ser = (struct Attribute *)result; |
456 | attr_ser->attribute_type = htons (attr->type); | 456 | attr_ser->attribute_type = htons(attr->type); |
457 | attr_ser->attribute_version = htonl (attr->version); | 457 | attr_ser->attribute_version = htonl(attr->version); |
458 | attr_ser->attribute_id = GNUNET_htonll (attr->id); | 458 | attr_ser->attribute_id = GNUNET_htonll(attr->id); |
459 | name_len = strlen (attr->name); | 459 | name_len = strlen(attr->name); |
460 | attr_ser->name_len = htons (name_len); | 460 | attr_ser->name_len = htons(name_len); |
461 | write_ptr = (char *) &attr_ser[1]; | 461 | write_ptr = (char *)&attr_ser[1]; |
462 | GNUNET_memcpy (write_ptr, attr->name, name_len); | 462 | GNUNET_memcpy(write_ptr, attr->name, name_len); |
463 | write_ptr += name_len; | 463 | write_ptr += name_len; |
464 | // TODO plugin-ize | 464 | // TODO plugin-ize |
465 | // data_len_ser = plugin->serialize_attribute_value (attr, | 465 | // data_len_ser = plugin->serialize_attribute_value (attr, |
466 | // &attr_ser[1]); | 466 | // &attr_ser[1]); |
467 | data_len_ser = attr->data_size; | 467 | data_len_ser = attr->data_size; |
468 | GNUNET_memcpy (write_ptr, attr->data, attr->data_size); | 468 | GNUNET_memcpy(write_ptr, attr->data, attr->data_size); |
469 | attr_ser->data_size = htons (data_len_ser); | 469 | attr_ser->data_size = htons(data_len_ser); |
470 | 470 | ||
471 | return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size; | 471 | return sizeof(struct Attribute) + strlen(attr->name) + attr->data_size; |
472 | } | 472 | } |
473 | 473 | ||
474 | 474 | ||
@@ -481,7 +481,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize ( | |||
481 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | 481 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller |
482 | */ | 482 | */ |
483 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * | 483 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * |
484 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | 484 | GNUNET_RECLAIM_ATTRIBUTE_deserialize(const char *data, size_t data_size) |
485 | { | 485 | { |
486 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 486 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
487 | struct Attribute *attr_ser; | 487 | struct Attribute *attr_ser; |
@@ -489,32 +489,32 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | |||
489 | size_t name_len; | 489 | size_t name_len; |
490 | char *write_ptr; | 490 | char *write_ptr; |
491 | 491 | ||
492 | if (data_size < sizeof (struct Attribute)) | 492 | if (data_size < sizeof(struct Attribute)) |
493 | return NULL; | 493 | return NULL; |
494 | 494 | ||
495 | attr_ser = (struct Attribute *) data; | 495 | attr_ser = (struct Attribute *)data; |
496 | data_len = ntohs (attr_ser->data_size); | 496 | data_len = ntohs(attr_ser->data_size); |
497 | name_len = ntohs (attr_ser->name_len); | 497 | name_len = ntohs(attr_ser->name_len); |
498 | if (data_size < sizeof (struct Attribute) + data_len + name_len) | 498 | if (data_size < sizeof(struct Attribute) + data_len + name_len) |
499 | { | 499 | { |
500 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 500 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
501 | "Buffer too small to deserialize\n"); | 501 | "Buffer too small to deserialize\n"); |
502 | return NULL; | 502 | return NULL; |
503 | } | 503 | } |
504 | attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + | 504 | attr = GNUNET_malloc(sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + |
505 | data_len + name_len + 1); | 505 | data_len + name_len + 1); |
506 | attr->type = ntohs (attr_ser->attribute_type); | 506 | attr->type = ntohs(attr_ser->attribute_type); |
507 | attr->version = ntohl (attr_ser->attribute_version); | 507 | attr->version = ntohl(attr_ser->attribute_version); |
508 | attr->id = GNUNET_ntohll (attr_ser->attribute_id); | 508 | attr->id = GNUNET_ntohll(attr_ser->attribute_id); |
509 | attr->data_size = data_len; | 509 | attr->data_size = data_len; |
510 | 510 | ||
511 | write_ptr = (char *) &attr[1]; | 511 | write_ptr = (char *)&attr[1]; |
512 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | 512 | GNUNET_memcpy(write_ptr, &attr_ser[1], name_len); |
513 | write_ptr[name_len] = '\0'; | 513 | write_ptr[name_len] = '\0'; |
514 | attr->name = write_ptr; | 514 | attr->name = write_ptr; |
515 | 515 | ||
516 | write_ptr += name_len + 1; | 516 | write_ptr += name_len + 1; |
517 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); | 517 | GNUNET_memcpy(write_ptr, (char *)&attr_ser[1] + name_len, attr->data_size); |
518 | attr->data = write_ptr; | 518 | attr->data = write_ptr; |
519 | return attr; | 519 | return attr; |
520 | } | 520 | } |