diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/reclaim/gnunet-reclaim.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/reclaim/gnunet-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 708 |
1 files changed, 354 insertions, 354 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index 5160aef7f..c5f0ed4fa 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -168,176 +168,176 @@ static char *attr_delete; | |||
168 | static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; | 168 | static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; |
169 | 169 | ||
170 | static void | 170 | static void |
171 | do_cleanup(void *cls) | 171 | do_cleanup (void *cls) |
172 | { | 172 | { |
173 | cleanup_task = NULL; | 173 | cleanup_task = NULL; |
174 | if (NULL != timeout) | 174 | if (NULL != timeout) |
175 | GNUNET_SCHEDULER_cancel(timeout); | 175 | GNUNET_SCHEDULER_cancel (timeout); |
176 | if (NULL != reclaim_op) | 176 | if (NULL != reclaim_op) |
177 | GNUNET_RECLAIM_cancel(reclaim_op); | 177 | GNUNET_RECLAIM_cancel (reclaim_op); |
178 | if (NULL != attr_iterator) | 178 | if (NULL != attr_iterator) |
179 | GNUNET_RECLAIM_get_attributes_stop(attr_iterator); | 179 | GNUNET_RECLAIM_get_attributes_stop (attr_iterator); |
180 | if (NULL != ticket_iterator) | 180 | if (NULL != ticket_iterator) |
181 | GNUNET_RECLAIM_ticket_iteration_stop(ticket_iterator); | 181 | GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator); |
182 | if (NULL != reclaim_handle) | 182 | if (NULL != reclaim_handle) |
183 | GNUNET_RECLAIM_disconnect(reclaim_handle); | 183 | GNUNET_RECLAIM_disconnect (reclaim_handle); |
184 | if (NULL != identity_handle) | 184 | if (NULL != identity_handle) |
185 | GNUNET_IDENTITY_disconnect(identity_handle); | 185 | GNUNET_IDENTITY_disconnect (identity_handle); |
186 | if (NULL != abe_key) | 186 | if (NULL != abe_key) |
187 | GNUNET_free(abe_key); | 187 | GNUNET_free (abe_key); |
188 | if (NULL != attr_list) | 188 | if (NULL != attr_list) |
189 | GNUNET_free(attr_list); | 189 | GNUNET_free (attr_list); |
190 | if (NULL != attr_to_delete) | 190 | if (NULL != attr_to_delete) |
191 | GNUNET_free(attr_to_delete); | 191 | GNUNET_free (attr_to_delete); |
192 | } | 192 | } |
193 | 193 | ||
194 | static void | 194 | static void |
195 | ticket_issue_cb(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 195 | ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
196 | { | 196 | { |
197 | char *ticket_str; | 197 | char *ticket_str; |
198 | 198 | ||
199 | reclaim_op = NULL; | 199 | reclaim_op = NULL; |
200 | if (NULL != ticket) | 200 | if (NULL != ticket) |
201 | { | 201 | { |
202 | ticket_str = | 202 | ticket_str = |
203 | GNUNET_STRINGS_data_to_string_alloc(ticket, | 203 | GNUNET_STRINGS_data_to_string_alloc (ticket, |
204 | sizeof( | 204 | sizeof( |
205 | struct GNUNET_RECLAIM_Ticket)); | 205 | struct GNUNET_RECLAIM_Ticket)); |
206 | printf("%s\n", ticket_str); | 206 | printf ("%s\n", ticket_str); |
207 | GNUNET_free(ticket_str); | 207 | GNUNET_free (ticket_str); |
208 | } | 208 | } |
209 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 209 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
210 | } | 210 | } |
211 | 211 | ||
212 | static void | 212 | static void |
213 | store_attr_cont(void *cls, int32_t success, const char *emsg) | 213 | store_attr_cont (void *cls, int32_t success, const char *emsg) |
214 | { | 214 | { |
215 | reclaim_op = NULL; | 215 | reclaim_op = NULL; |
216 | if (GNUNET_SYSERR == success) | 216 | if (GNUNET_SYSERR == success) |
217 | { | 217 | { |
218 | fprintf(stderr, "%s\n", emsg); | 218 | fprintf (stderr, "%s\n", emsg); |
219 | } | 219 | } |
220 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 220 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
221 | } | 221 | } |
222 | 222 | ||
223 | static void | 223 | static void |
224 | process_attrs(void *cls, | 224 | process_attrs (void *cls, |
225 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 225 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
226 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 226 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
227 | { | 227 | { |
228 | char *value_str; | 228 | char *value_str; |
229 | char *id; | 229 | char *id; |
230 | const char *attr_type; | 230 | const char *attr_type; |
231 | 231 | ||
232 | if (NULL == identity) | 232 | if (NULL == identity) |
233 | { | 233 | { |
234 | reclaim_op = NULL; | 234 | reclaim_op = NULL; |
235 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 235 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | if (NULL == attr) | 238 | if (NULL == attr) |
239 | { | 239 | { |
240 | ret = 1; | 240 | ret = 1; |
241 | return; | 241 | return; |
242 | } | 242 | } |
243 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, | 243 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, |
244 | attr->data, | 244 | attr->data, |
245 | attr->data_size); | 245 | attr->data_size); |
246 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); | 246 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
247 | id = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); | 247 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(uint64_t)); |
248 | fprintf(stdout, | 248 | fprintf (stdout, |
249 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 249 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
250 | attr->name, | 250 | attr->name, |
251 | value_str, | 251 | value_str, |
252 | attr_type, | 252 | attr_type, |
253 | attr->version, | 253 | attr->version, |
254 | id); | 254 | id); |
255 | GNUNET_free(id); | 255 | GNUNET_free (id); |
256 | } | 256 | } |
257 | 257 | ||
258 | static void | 258 | static void |
259 | ticket_iter_err(void *cls) | 259 | ticket_iter_err (void *cls) |
260 | { | 260 | { |
261 | ticket_iterator = NULL; | 261 | ticket_iterator = NULL; |
262 | fprintf(stderr, "Failed to iterate over tickets\n"); | 262 | fprintf (stderr, "Failed to iterate over tickets\n"); |
263 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 263 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
264 | } | 264 | } |
265 | 265 | ||
266 | static void | 266 | static void |
267 | ticket_iter_fin(void *cls) | 267 | ticket_iter_fin (void *cls) |
268 | { | 268 | { |
269 | ticket_iterator = NULL; | 269 | ticket_iterator = NULL; |
270 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 270 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
271 | } | 271 | } |
272 | 272 | ||
273 | static void | 273 | static void |
274 | ticket_iter(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 274 | ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
275 | { | 275 | { |
276 | char *aud; | 276 | char *aud; |
277 | char *ref; | 277 | char *ref; |
278 | char *tkt; | 278 | char *tkt; |
279 | 279 | ||
280 | aud = | 280 | aud = |
281 | GNUNET_STRINGS_data_to_string_alloc(&ticket->audience, | 281 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, |
282 | sizeof(struct | 282 | sizeof(struct |
283 | GNUNET_CRYPTO_EcdsaPublicKey)); | 283 | GNUNET_CRYPTO_EcdsaPublicKey)); |
284 | ref = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t)); | 284 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(uint64_t)); |
285 | tkt = | 285 | tkt = |
286 | GNUNET_STRINGS_data_to_string_alloc(ticket, | 286 | GNUNET_STRINGS_data_to_string_alloc (ticket, |
287 | sizeof(struct GNUNET_RECLAIM_Ticket)); | 287 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
288 | fprintf(stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud); | 288 | fprintf (stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud); |
289 | GNUNET_free(aud); | 289 | GNUNET_free (aud); |
290 | GNUNET_free(ref); | 290 | GNUNET_free (ref); |
291 | GNUNET_free(tkt); | 291 | GNUNET_free (tkt); |
292 | GNUNET_RECLAIM_ticket_iteration_next(ticket_iterator); | 292 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); |
293 | } | 293 | } |
294 | 294 | ||
295 | static void | 295 | static void |
296 | iter_error(void *cls) | 296 | iter_error (void *cls) |
297 | { | 297 | { |
298 | attr_iterator = NULL; | 298 | attr_iterator = NULL; |
299 | fprintf(stderr, "Failed to iterate over attributes\n"); | 299 | fprintf (stderr, "Failed to iterate over attributes\n"); |
300 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 300 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
301 | } | 301 | } |
302 | 302 | ||
303 | static void | 303 | static void |
304 | timeout_task(void *cls) | 304 | timeout_task (void *cls) |
305 | { | 305 | { |
306 | timeout = NULL; | 306 | timeout = NULL; |
307 | ret = 1; | 307 | ret = 1; |
308 | fprintf(stderr, "Timeout\n"); | 308 | fprintf (stderr, "Timeout\n"); |
309 | if (NULL == cleanup_task) | 309 | if (NULL == cleanup_task) |
310 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 310 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
311 | } | 311 | } |
312 | 312 | ||
313 | static void | 313 | static void |
314 | process_rvk(void *cls, int success, const char *msg) | 314 | process_rvk (void *cls, int success, const char *msg) |
315 | { | 315 | { |
316 | reclaim_op = NULL; | 316 | reclaim_op = NULL; |
317 | if (GNUNET_OK != success) | 317 | if (GNUNET_OK != success) |
318 | { | 318 | { |
319 | fprintf(stderr, "Revocation failed.\n"); | 319 | fprintf (stderr, "Revocation failed.\n"); |
320 | ret = 1; | 320 | ret = 1; |
321 | } | 321 | } |
322 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 322 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | static void | 326 | static void |
327 | process_delete(void *cls, int success, const char *msg) | 327 | process_delete (void *cls, int success, const char *msg) |
328 | { | 328 | { |
329 | reclaim_op = NULL; | 329 | reclaim_op = NULL; |
330 | if (GNUNET_OK != success) | 330 | if (GNUNET_OK != success) |
331 | { | 331 | { |
332 | fprintf(stderr, "Deletion failed.\n"); | 332 | fprintf (stderr, "Deletion failed.\n"); |
333 | ret = 1; | 333 | ret = 1; |
334 | } | 334 | } |
335 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 335 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
336 | } | 336 | } |
337 | 337 | ||
338 | 338 | ||
339 | static void | 339 | static void |
340 | iter_finished(void *cls) | 340 | iter_finished (void *cls) |
341 | { | 341 | { |
342 | char *data; | 342 | char *data; |
343 | size_t data_size; | 343 | size_t data_size; |
@@ -345,97 +345,97 @@ iter_finished(void *cls) | |||
345 | 345 | ||
346 | attr_iterator = NULL; | 346 | attr_iterator = NULL; |
347 | if (list) | 347 | if (list) |
348 | { | 348 | { |
349 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 349 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
350 | return; | 350 | return; |
351 | } | 351 | } |
352 | 352 | ||
353 | if (issue_attrs) | 353 | if (issue_attrs) |
354 | { | 354 | { |
355 | reclaim_op = GNUNET_RECLAIM_ticket_issue(reclaim_handle, | 355 | reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle, |
356 | pkey, | 356 | pkey, |
357 | &rp_key, | 357 | &rp_key, |
358 | attr_list, | 358 | attr_list, |
359 | &ticket_issue_cb, | 359 | &ticket_issue_cb, |
360 | NULL); | 360 | NULL); |
361 | return; | 361 | return; |
362 | } | 362 | } |
363 | if (consume_ticket) | 363 | if (consume_ticket) |
364 | { | 364 | { |
365 | reclaim_op = GNUNET_RECLAIM_ticket_consume(reclaim_handle, | 365 | reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, |
366 | pkey, | ||
367 | &ticket, | ||
368 | &process_attrs, | ||
369 | NULL); | ||
370 | timeout = GNUNET_SCHEDULER_add_delayed( | ||
371 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
372 | &timeout_task, | ||
373 | NULL); | ||
374 | return; | ||
375 | } | ||
376 | if (revoke_ticket) | ||
377 | { | ||
378 | reclaim_op = GNUNET_RECLAIM_ticket_revoke(reclaim_handle, | ||
379 | pkey, | 366 | pkey, |
380 | &ticket, | 367 | &ticket, |
381 | &process_rvk, | 368 | &process_attrs, |
382 | NULL); | 369 | NULL); |
383 | return; | 370 | timeout = GNUNET_SCHEDULER_add_delayed ( |
384 | } | 371 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
372 | &timeout_task, | ||
373 | NULL); | ||
374 | return; | ||
375 | } | ||
376 | if (revoke_ticket) | ||
377 | { | ||
378 | reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, | ||
379 | pkey, | ||
380 | &ticket, | ||
381 | &process_rvk, | ||
382 | NULL); | ||
383 | return; | ||
384 | } | ||
385 | if (attr_delete) | 385 | if (attr_delete) |
386 | { | ||
387 | if (NULL == attr_to_delete) | ||
386 | { | 388 | { |
387 | if (NULL == attr_to_delete) | 389 | fprintf (stdout, "No such attribute ``%s''\n", attr_delete); |
388 | { | ||
389 | fprintf(stdout, "No such attribute ``%s''\n", attr_delete); | ||
390 | return; | ||
391 | } | ||
392 | reclaim_op = GNUNET_RECLAIM_attribute_delete(reclaim_handle, | ||
393 | pkey, | ||
394 | attr_to_delete, | ||
395 | &process_delete, | ||
396 | NULL); | ||
397 | return; | 390 | return; |
398 | } | 391 | } |
392 | reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle, | ||
393 | pkey, | ||
394 | attr_to_delete, | ||
395 | &process_delete, | ||
396 | NULL); | ||
397 | return; | ||
398 | } | ||
399 | if (attr_name) | 399 | if (attr_name) |
400 | { | 400 | { |
401 | if (NULL == type_str) | 401 | if (NULL == type_str) |
402 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; | 402 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; |
403 | else | 403 | else |
404 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); | 404 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); |
405 | 405 | ||
406 | GNUNET_assert(GNUNET_SYSERR != | 406 | GNUNET_assert (GNUNET_SYSERR != |
407 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, | 407 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, |
408 | attr_value, | 408 | attr_value, |
409 | (void **)&data, | 409 | (void **) &data, |
410 | &data_size)); | 410 | &data_size)); |
411 | if (NULL != claim) | 411 | if (NULL != claim) |
412 | { | 412 | { |
413 | claim->type = type; | 413 | claim->type = type; |
414 | claim->data = data; | 414 | claim->data = data; |
415 | claim->data_size = data_size; | 415 | claim->data_size = data_size; |
416 | } | ||
417 | else | ||
418 | { | ||
419 | claim = | ||
420 | GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr_name, type, data, data_size); | ||
421 | } | ||
422 | reclaim_op = GNUNET_RECLAIM_attribute_store(reclaim_handle, | ||
423 | pkey, | ||
424 | claim, | ||
425 | &exp_interval, | ||
426 | &store_attr_cont, | ||
427 | NULL); | ||
428 | GNUNET_free(data); | ||
429 | GNUNET_free(claim); | ||
430 | return; | ||
431 | } | 416 | } |
432 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 417 | else |
418 | { | ||
419 | claim = | ||
420 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | ||
421 | } | ||
422 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, | ||
423 | pkey, | ||
424 | claim, | ||
425 | &exp_interval, | ||
426 | &store_attr_cont, | ||
427 | NULL); | ||
428 | GNUNET_free (data); | ||
429 | GNUNET_free (claim); | ||
430 | return; | ||
431 | } | ||
432 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
433 | } | 433 | } |
434 | 434 | ||
435 | static void | 435 | static void |
436 | iter_cb(void *cls, | 436 | iter_cb (void *cls, |
437 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 437 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
438 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 438 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
439 | { | 439 | { |
440 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 440 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
441 | char *attrs_tmp; | 441 | char *attrs_tmp; |
@@ -445,260 +445,260 @@ iter_cb(void *cls, | |||
445 | const char *attr_type; | 445 | const char *attr_type; |
446 | 446 | ||
447 | if ((NULL != attr_name) && (NULL != claim)) | 447 | if ((NULL != attr_name) && (NULL != claim)) |
448 | { | ||
449 | if (0 == strcasecmp (attr_name, attr->name)) | ||
448 | { | 450 | { |
449 | if (0 == strcasecmp(attr_name, attr->name)) | 451 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, |
450 | { | 452 | attr->type, |
451 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, | 453 | attr->data, |
452 | attr->type, | 454 | attr->data_size); |
453 | attr->data, | ||
454 | attr->data_size); | ||
455 | } | ||
456 | } | 455 | } |
456 | } | ||
457 | else if (issue_attrs) | 457 | else if (issue_attrs) |
458 | { | ||
459 | attrs_tmp = GNUNET_strdup (issue_attrs); | ||
460 | attr_str = strtok (attrs_tmp, ","); | ||
461 | while (NULL != attr_str) | ||
458 | { | 462 | { |
459 | attrs_tmp = GNUNET_strdup(issue_attrs); | 463 | if (0 != strcasecmp (attr_str, attr->name)) |
460 | attr_str = strtok(attrs_tmp, ","); | 464 | { |
461 | while (NULL != attr_str) | 465 | attr_str = strtok (NULL, ","); |
462 | { | 466 | continue; |
463 | if (0 != strcasecmp(attr_str, attr->name)) | 467 | } |
464 | { | 468 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
465 | attr_str = strtok(NULL, ","); | 469 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, |
466 | continue; | 470 | attr->type, |
467 | } | 471 | attr->data, |
468 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 472 | attr->data_size); |
469 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, | 473 | le->claim->version = attr->version; |
470 | attr->type, | 474 | le->claim->id = attr->id; |
471 | attr->data, | 475 | GNUNET_CONTAINER_DLL_insert (attr_list->list_head, |
472 | attr->data_size); | 476 | attr_list->list_tail, |
473 | le->claim->version = attr->version; | 477 | le); |
474 | le->claim->id = attr->id; | 478 | break; |
475 | GNUNET_CONTAINER_DLL_insert(attr_list->list_head, | ||
476 | attr_list->list_tail, | ||
477 | le); | ||
478 | break; | ||
479 | } | ||
480 | GNUNET_free(attrs_tmp); | ||
481 | } | 479 | } |
480 | GNUNET_free (attrs_tmp); | ||
481 | } | ||
482 | else if (attr_delete && (NULL == attr_to_delete)) | 482 | else if (attr_delete && (NULL == attr_to_delete)) |
483 | { | ||
484 | label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(uint64_t)); | ||
485 | if (0 == strcasecmp (attr_delete, label)) | ||
483 | { | 486 | { |
484 | label = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); | 487 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, |
485 | if (0 == strcasecmp(attr_delete, label)) | 488 | attr->type, |
486 | { | 489 | attr->data, |
487 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, | 490 | attr->data_size); |
488 | attr->type, | 491 | attr_to_delete->id = attr->id; |
489 | attr->data, | ||
490 | attr->data_size); | ||
491 | attr_to_delete->id = attr->id; | ||
492 | } | ||
493 | GNUNET_free(label); | ||
494 | } | 492 | } |
493 | GNUNET_free (label); | ||
494 | } | ||
495 | else if (list) | 495 | else if (list) |
496 | { | 496 | { |
497 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, | 497 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, |
498 | attr->data, | 498 | attr->data, |
499 | attr->data_size); | 499 | attr->data_size); |
500 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); | 500 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
501 | id = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); | 501 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(uint64_t)); |
502 | fprintf(stdout, | 502 | fprintf (stdout, |
503 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 503 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
504 | attr->name, | 504 | attr->name, |
505 | attr_str, | 505 | attr_str, |
506 | attr_type, | 506 | attr_type, |
507 | attr->version, | 507 | attr->version, |
508 | id); | 508 | id); |
509 | GNUNET_free(id); | 509 | GNUNET_free (id); |
510 | } | 510 | } |
511 | GNUNET_RECLAIM_get_attributes_next(attr_iterator); | 511 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); |
512 | } | 512 | } |
513 | 513 | ||
514 | static void | 514 | static void |
515 | start_process() | 515 | start_process () |
516 | { | 516 | { |
517 | if (NULL == pkey) | 517 | if (NULL == pkey) |
518 | { | 518 | { |
519 | fprintf(stderr, "Ego %s not found\n", ego_name); | 519 | fprintf (stderr, "Ego %s not found\n", ego_name); |
520 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 520 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
521 | return; | 521 | return; |
522 | } | 522 | } |
523 | 523 | ||
524 | if (list_tickets) | 524 | if (list_tickets) |
525 | { | 525 | { |
526 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start(reclaim_handle, | 526 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, |
527 | pkey, | 527 | pkey, |
528 | &ticket_iter_err, | 528 | &ticket_iter_err, |
529 | NULL, | 529 | NULL, |
530 | &ticket_iter, | 530 | &ticket_iter, |
531 | NULL, | 531 | NULL, |
532 | &ticket_iter_fin, | 532 | &ticket_iter_fin, |
533 | NULL); | 533 | NULL); |
534 | return; | 534 | return; |
535 | } | 535 | } |
536 | 536 | ||
537 | if ((NULL != rp) && | 537 | if ((NULL != rp) && |
538 | GNUNET_OK != | 538 | (GNUNET_OK != |
539 | GNUNET_CRYPTO_ecdsa_public_key_from_string(rp, strlen(rp), &rp_key)) | 539 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key)) ) |
540 | { | 540 | { |
541 | fprintf(stderr, "%s is not a public key!\n", rp); | 541 | fprintf (stderr, "%s is not a public key!\n", rp); |
542 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); | 542 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
543 | return; | 543 | return; |
544 | } | 544 | } |
545 | if (NULL != consume_ticket) | 545 | if (NULL != consume_ticket) |
546 | GNUNET_STRINGS_string_to_data(consume_ticket, | 546 | GNUNET_STRINGS_string_to_data (consume_ticket, |
547 | strlen(consume_ticket), | 547 | strlen (consume_ticket), |
548 | &ticket, | 548 | &ticket, |
549 | sizeof(struct GNUNET_RECLAIM_Ticket)); | 549 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
550 | if (NULL != revoke_ticket) | 550 | if (NULL != revoke_ticket) |
551 | GNUNET_STRINGS_string_to_data(revoke_ticket, | 551 | GNUNET_STRINGS_string_to_data (revoke_ticket, |
552 | strlen(revoke_ticket), | 552 | strlen (revoke_ticket), |
553 | &ticket, | 553 | &ticket, |
554 | sizeof(struct GNUNET_RECLAIM_Ticket)); | 554 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
555 | 555 | ||
556 | attr_list = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 556 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
557 | claim = NULL; | 557 | claim = NULL; |
558 | attr_iterator = GNUNET_RECLAIM_get_attributes_start(reclaim_handle, | 558 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, |
559 | pkey, | 559 | pkey, |
560 | &iter_error, | 560 | &iter_error, |
561 | NULL, | 561 | NULL, |
562 | &iter_cb, | 562 | &iter_cb, |
563 | NULL, | 563 | NULL, |
564 | &iter_finished, | 564 | &iter_finished, |
565 | NULL); | 565 | NULL); |
566 | } | 566 | } |
567 | 567 | ||
568 | static int init = GNUNET_YES; | 568 | static int init = GNUNET_YES; |
569 | 569 | ||
570 | static void | 570 | static void |
571 | ego_cb(void *cls, | 571 | ego_cb (void *cls, |
572 | struct GNUNET_IDENTITY_Ego *ego, | 572 | struct GNUNET_IDENTITY_Ego *ego, |
573 | void **ctx, | 573 | void **ctx, |
574 | const char *name) | 574 | const char *name) |
575 | { | 575 | { |
576 | if (NULL == name) | 576 | if (NULL == name) |
577 | { | ||
578 | if (GNUNET_YES == init) | ||
577 | { | 579 | { |
578 | if (GNUNET_YES == init) | 580 | init = GNUNET_NO; |
579 | { | 581 | start_process (); |
580 | init = GNUNET_NO; | ||
581 | start_process(); | ||
582 | } | ||
583 | return; | ||
584 | } | 582 | } |
585 | if (0 != strcmp(name, ego_name)) | ||
586 | return; | 583 | return; |
587 | pkey = GNUNET_IDENTITY_ego_get_private_key(ego); | 584 | } |
585 | if (0 != strcmp (name, ego_name)) | ||
586 | return; | ||
587 | pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
588 | } | 588 | } |
589 | 589 | ||
590 | 590 | ||
591 | static void | 591 | static void |
592 | run(void *cls, | 592 | run (void *cls, |
593 | char *const *args, | 593 | char *const *args, |
594 | const char *cfgfile, | 594 | const char *cfgfile, |
595 | const struct GNUNET_CONFIGURATION_Handle *c) | 595 | const struct GNUNET_CONFIGURATION_Handle *c) |
596 | { | 596 | { |
597 | ret = 0; | 597 | ret = 0; |
598 | if (NULL == ego_name) | 598 | if (NULL == ego_name) |
599 | { | 599 | { |
600 | ret = 1; | 600 | ret = 1; |
601 | fprintf(stderr, _("Ego is required\n")); | 601 | fprintf (stderr, _ ("Ego is required\n")); |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | 604 | ||
605 | if ((NULL == attr_value) && (NULL != attr_name)) | 605 | if ((NULL == attr_value) && (NULL != attr_name)) |
606 | { | 606 | { |
607 | ret = 1; | 607 | ret = 1; |
608 | fprintf(stderr, _("Attribute value missing!\n")); | 608 | fprintf (stderr, _ ("Attribute value missing!\n")); |
609 | return; | 609 | return; |
610 | } | 610 | } |
611 | 611 | ||
612 | if ((NULL == rp) && (NULL != issue_attrs)) | 612 | if ((NULL == rp) && (NULL != issue_attrs)) |
613 | { | 613 | { |
614 | ret = 1; | 614 | ret = 1; |
615 | fprintf(stderr, _("Requesting party key is required!\n")); | 615 | fprintf (stderr, _ ("Requesting party key is required!\n")); |
616 | return; | 616 | return; |
617 | } | 617 | } |
618 | 618 | ||
619 | reclaim_handle = GNUNET_RECLAIM_connect(c); | 619 | reclaim_handle = GNUNET_RECLAIM_connect (c); |
620 | // Get Ego | 620 | // Get Ego |
621 | identity_handle = GNUNET_IDENTITY_connect(c, &ego_cb, NULL); | 621 | identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL); |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | int | 625 | int |
626 | main(int argc, char *const argv[]) | 626 | main (int argc, char *const argv[]) |
627 | { | 627 | { |
628 | exp_interval = GNUNET_TIME_UNIT_HOURS; | 628 | exp_interval = GNUNET_TIME_UNIT_HOURS; |
629 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 629 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
630 | GNUNET_GETOPT_option_string('a', | 630 | GNUNET_GETOPT_option_string ('a', |
631 | "add", | 631 | "add", |
632 | "NAME", | 632 | "NAME", |
633 | gettext_noop("Add an attribute NAME"), | 633 | gettext_noop ("Add an attribute NAME"), |
634 | &attr_name), | 634 | &attr_name), |
635 | GNUNET_GETOPT_option_string('d', | 635 | GNUNET_GETOPT_option_string ('d', |
636 | "delete", | 636 | "delete", |
637 | "ID", | 637 | "ID", |
638 | gettext_noop("Delete the attribute with ID"), | 638 | gettext_noop ("Delete the attribute with ID"), |
639 | &attr_delete), | 639 | &attr_delete), |
640 | GNUNET_GETOPT_option_string('V', | 640 | GNUNET_GETOPT_option_string ('V', |
641 | "value", | 641 | "value", |
642 | "VALUE", | 642 | "VALUE", |
643 | gettext_noop("The attribute VALUE"), | 643 | gettext_noop ("The attribute VALUE"), |
644 | &attr_value), | 644 | &attr_value), |
645 | GNUNET_GETOPT_option_string('e', | 645 | GNUNET_GETOPT_option_string ('e', |
646 | "ego", | 646 | "ego", |
647 | "EGO", | 647 | "EGO", |
648 | gettext_noop("The EGO to use"), | 648 | gettext_noop ("The EGO to use"), |
649 | &ego_name), | 649 | &ego_name), |
650 | GNUNET_GETOPT_option_string('r', | 650 | GNUNET_GETOPT_option_string ('r', |
651 | "rp", | 651 | "rp", |
652 | "RP", | 652 | "RP", |
653 | gettext_noop( | 653 | gettext_noop ( |
654 | "Specify the relying party for issue"), | 654 | "Specify the relying party for issue"), |
655 | &rp), | 655 | &rp), |
656 | GNUNET_GETOPT_option_flag('D', | 656 | GNUNET_GETOPT_option_flag ('D', |
657 | "dump", | 657 | "dump", |
658 | gettext_noop("List attributes for EGO"), | 658 | gettext_noop ("List attributes for EGO"), |
659 | &list), | 659 | &list), |
660 | GNUNET_GETOPT_option_string( | 660 | GNUNET_GETOPT_option_string ( |
661 | 'i', | 661 | 'i', |
662 | "issue", | 662 | "issue", |
663 | "A1,A2,...", | 663 | "A1,A2,...", |
664 | gettext_noop( | 664 | gettext_noop ( |
665 | "Issue a ticket for a set of attributes separated by comma"), | 665 | "Issue a ticket for a set of attributes separated by comma"), |
666 | &issue_attrs), | 666 | &issue_attrs), |
667 | GNUNET_GETOPT_option_string('C', | 667 | GNUNET_GETOPT_option_string ('C', |
668 | "consume", | 668 | "consume", |
669 | "TICKET", | 669 | "TICKET", |
670 | gettext_noop("Consume a ticket"), | 670 | gettext_noop ("Consume a ticket"), |
671 | &consume_ticket), | 671 | &consume_ticket), |
672 | GNUNET_GETOPT_option_string('R', | 672 | GNUNET_GETOPT_option_string ('R', |
673 | "revoke", | 673 | "revoke", |
674 | "TICKET", | 674 | "TICKET", |
675 | gettext_noop("Revoke a ticket"), | 675 | gettext_noop ("Revoke a ticket"), |
676 | &revoke_ticket), | 676 | &revoke_ticket), |
677 | GNUNET_GETOPT_option_string('t', | 677 | GNUNET_GETOPT_option_string ('t', |
678 | "type", | 678 | "type", |
679 | "TYPE", | 679 | "TYPE", |
680 | gettext_noop("Type of attribute"), | 680 | gettext_noop ("Type of attribute"), |
681 | &type_str), | 681 | &type_str), |
682 | GNUNET_GETOPT_option_flag('T', | 682 | GNUNET_GETOPT_option_flag ('T', |
683 | "tickets", | 683 | "tickets", |
684 | gettext_noop("List tickets of ego"), | 684 | gettext_noop ("List tickets of ego"), |
685 | &list_tickets), | 685 | &list_tickets), |
686 | GNUNET_GETOPT_option_relative_time('E', | 686 | GNUNET_GETOPT_option_relative_time ('E', |
687 | "expiration", | 687 | "expiration", |
688 | "INTERVAL", | 688 | "INTERVAL", |
689 | gettext_noop( | 689 | gettext_noop ( |
690 | "Expiration interval of the attribute"), | 690 | "Expiration interval of the attribute"), |
691 | &exp_interval), | 691 | &exp_interval), |
692 | 692 | ||
693 | GNUNET_GETOPT_OPTION_END | 693 | GNUNET_GETOPT_OPTION_END |
694 | }; | 694 | }; |
695 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, | 695 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, |
696 | argv, | 696 | argv, |
697 | "gnunet-reclaim", | 697 | "gnunet-reclaim", |
698 | _("re:claimID command line tool"), | 698 | _ ("re:claimID command line tool"), |
699 | options, | 699 | options, |
700 | &run, | 700 | &run, |
701 | NULL)) | 701 | NULL)) |
702 | return 1; | 702 | return 1; |
703 | else | 703 | else |
704 | return ret; | 704 | return ret; |