diff options
Diffstat (limited to 'src/reclaim/gnunet-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 715 |
1 files changed, 358 insertions, 357 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index b2f6b4c3c..5160aef7f 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.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 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @file src/reclaim/gnunet-reclaim.c | 22 | * @file src/reclaim/gnunet-reclaim.c |
@@ -168,175 +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 | reclaim_op = NULL; | 199 | reclaim_op = NULL; |
199 | if (NULL != ticket) | 200 | if (NULL != ticket) |
200 | { | 201 | { |
201 | ticket_str = | 202 | ticket_str = |
202 | GNUNET_STRINGS_data_to_string_alloc (ticket, | 203 | GNUNET_STRINGS_data_to_string_alloc(ticket, |
203 | sizeof ( | 204 | sizeof( |
204 | struct GNUNET_RECLAIM_Ticket)); | 205 | struct GNUNET_RECLAIM_Ticket)); |
205 | printf ("%s\n", ticket_str); | 206 | printf("%s\n", ticket_str); |
206 | GNUNET_free (ticket_str); | 207 | GNUNET_free(ticket_str); |
207 | } | 208 | } |
208 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 209 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
209 | } | 210 | } |
210 | 211 | ||
211 | static void | 212 | static void |
212 | store_attr_cont (void *cls, int32_t success, const char *emsg) | 213 | store_attr_cont(void *cls, int32_t success, const char *emsg) |
213 | { | 214 | { |
214 | reclaim_op = NULL; | 215 | reclaim_op = NULL; |
215 | if (GNUNET_SYSERR == success) | 216 | if (GNUNET_SYSERR == success) |
216 | { | 217 | { |
217 | fprintf (stderr, "%s\n", emsg); | 218 | fprintf(stderr, "%s\n", emsg); |
218 | } | 219 | } |
219 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 220 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
220 | } | 221 | } |
221 | 222 | ||
222 | static void | 223 | static void |
223 | process_attrs (void *cls, | 224 | process_attrs(void *cls, |
224 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 225 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
225 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 226 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
226 | { | 227 | { |
227 | char *value_str; | 228 | char *value_str; |
228 | char *id; | 229 | char *id; |
229 | const char *attr_type; | 230 | const char *attr_type; |
230 | 231 | ||
231 | if (NULL == identity) | 232 | if (NULL == identity) |
232 | { | 233 | { |
233 | reclaim_op = NULL; | 234 | reclaim_op = NULL; |
234 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 235 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
235 | return; | 236 | return; |
236 | } | 237 | } |
237 | if (NULL == attr) | 238 | if (NULL == attr) |
238 | { | 239 | { |
239 | ret = 1; | 240 | ret = 1; |
240 | return; | 241 | return; |
241 | } | 242 | } |
242 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 243 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
243 | attr->data, | 244 | attr->data, |
244 | attr->data_size); | 245 | attr->data_size); |
245 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 246 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); |
246 | 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)); |
247 | fprintf (stdout, | 248 | fprintf(stdout, |
248 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 249 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
249 | attr->name, | 250 | attr->name, |
250 | value_str, | 251 | value_str, |
251 | attr_type, | 252 | attr_type, |
252 | attr->version, | 253 | attr->version, |
253 | id); | 254 | id); |
254 | GNUNET_free (id); | 255 | GNUNET_free(id); |
255 | } | 256 | } |
256 | 257 | ||
257 | static void | 258 | static void |
258 | ticket_iter_err (void *cls) | 259 | ticket_iter_err(void *cls) |
259 | { | 260 | { |
260 | ticket_iterator = NULL; | 261 | ticket_iterator = NULL; |
261 | fprintf (stderr, "Failed to iterate over tickets\n"); | 262 | fprintf(stderr, "Failed to iterate over tickets\n"); |
262 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 263 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
263 | } | 264 | } |
264 | 265 | ||
265 | static void | 266 | static void |
266 | ticket_iter_fin (void *cls) | 267 | ticket_iter_fin(void *cls) |
267 | { | 268 | { |
268 | ticket_iterator = NULL; | 269 | ticket_iterator = NULL; |
269 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 270 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
270 | } | 271 | } |
271 | 272 | ||
272 | static void | 273 | static void |
273 | ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 274 | ticket_iter(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
274 | { | 275 | { |
275 | char *aud; | 276 | char *aud; |
276 | char *ref; | 277 | char *ref; |
277 | char *tkt; | 278 | char *tkt; |
278 | 279 | ||
279 | aud = | 280 | aud = |
280 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 281 | GNUNET_STRINGS_data_to_string_alloc(&ticket->audience, |
281 | sizeof (struct | 282 | sizeof(struct |
282 | GNUNET_CRYPTO_EcdsaPublicKey)); | 283 | GNUNET_CRYPTO_EcdsaPublicKey)); |
283 | 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)); |
284 | tkt = | 285 | tkt = |
285 | GNUNET_STRINGS_data_to_string_alloc (ticket, | 286 | GNUNET_STRINGS_data_to_string_alloc(ticket, |
286 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 287 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
287 | 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); |
288 | GNUNET_free (aud); | 289 | GNUNET_free(aud); |
289 | GNUNET_free (ref); | 290 | GNUNET_free(ref); |
290 | GNUNET_free (tkt); | 291 | GNUNET_free(tkt); |
291 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); | 292 | GNUNET_RECLAIM_ticket_iteration_next(ticket_iterator); |
292 | } | 293 | } |
293 | 294 | ||
294 | static void | 295 | static void |
295 | iter_error (void *cls) | 296 | iter_error(void *cls) |
296 | { | 297 | { |
297 | attr_iterator = NULL; | 298 | attr_iterator = NULL; |
298 | fprintf (stderr, "Failed to iterate over attributes\n"); | 299 | fprintf(stderr, "Failed to iterate over attributes\n"); |
299 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 300 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
300 | } | 301 | } |
301 | 302 | ||
302 | static void | 303 | static void |
303 | timeout_task (void *cls) | 304 | timeout_task(void *cls) |
304 | { | 305 | { |
305 | timeout = NULL; | 306 | timeout = NULL; |
306 | ret = 1; | 307 | ret = 1; |
307 | fprintf (stderr, "Timeout\n"); | 308 | fprintf(stderr, "Timeout\n"); |
308 | if (NULL == cleanup_task) | 309 | if (NULL == cleanup_task) |
309 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 310 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
310 | } | 311 | } |
311 | 312 | ||
312 | static void | 313 | static void |
313 | process_rvk (void *cls, int success, const char *msg) | 314 | process_rvk(void *cls, int success, const char *msg) |
314 | { | 315 | { |
315 | reclaim_op = NULL; | 316 | reclaim_op = NULL; |
316 | if (GNUNET_OK != success) | 317 | if (GNUNET_OK != success) |
317 | { | 318 | { |
318 | fprintf (stderr, "Revocation failed.\n"); | 319 | fprintf(stderr, "Revocation failed.\n"); |
319 | ret = 1; | 320 | ret = 1; |
320 | } | 321 | } |
321 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 322 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
322 | } | 323 | } |
323 | 324 | ||
324 | 325 | ||
325 | static void | 326 | static void |
326 | process_delete (void *cls, int success, const char *msg) | 327 | process_delete(void *cls, int success, const char *msg) |
327 | { | 328 | { |
328 | reclaim_op = NULL; | 329 | reclaim_op = NULL; |
329 | if (GNUNET_OK != success) | 330 | if (GNUNET_OK != success) |
330 | { | 331 | { |
331 | fprintf (stderr, "Deletion failed.\n"); | 332 | fprintf(stderr, "Deletion failed.\n"); |
332 | ret = 1; | 333 | ret = 1; |
333 | } | 334 | } |
334 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 335 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
335 | } | 336 | } |
336 | 337 | ||
337 | 338 | ||
338 | static void | 339 | static void |
339 | iter_finished (void *cls) | 340 | iter_finished(void *cls) |
340 | { | 341 | { |
341 | char *data; | 342 | char *data; |
342 | size_t data_size; | 343 | size_t data_size; |
@@ -344,97 +345,97 @@ iter_finished (void *cls) | |||
344 | 345 | ||
345 | attr_iterator = NULL; | 346 | attr_iterator = NULL; |
346 | if (list) | 347 | if (list) |
347 | { | 348 | { |
348 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 349 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
349 | return; | 350 | return; |
350 | } | 351 | } |
351 | 352 | ||
352 | if (issue_attrs) | 353 | if (issue_attrs) |
353 | { | 354 | { |
354 | reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle, | 355 | reclaim_op = GNUNET_RECLAIM_ticket_issue(reclaim_handle, |
355 | pkey, | 356 | pkey, |
356 | &rp_key, | 357 | &rp_key, |
357 | attr_list, | 358 | attr_list, |
358 | &ticket_issue_cb, | 359 | &ticket_issue_cb, |
359 | NULL); | 360 | NULL); |
360 | return; | 361 | return; |
361 | } | 362 | } |
362 | if (consume_ticket) | 363 | if (consume_ticket) |
363 | { | 364 | { |
364 | 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, | ||
365 | pkey, | 379 | pkey, |
366 | &ticket, | 380 | &ticket, |
367 | &process_attrs, | 381 | &process_rvk, |
368 | NULL); | 382 | NULL); |
369 | timeout = GNUNET_SCHEDULER_add_delayed ( | 383 | return; |
370 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 384 | } |
371 | &timeout_task, | ||
372 | NULL); | ||
373 | return; | ||
374 | } | ||
375 | if (revoke_ticket) | ||
376 | { | ||
377 | reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, | ||
378 | pkey, | ||
379 | &ticket, | ||
380 | &process_rvk, | ||
381 | NULL); | ||
382 | return; | ||
383 | } | ||
384 | if (attr_delete) | 385 | if (attr_delete) |
385 | { | ||
386 | if (NULL == attr_to_delete) | ||
387 | { | 386 | { |
388 | fprintf (stdout, "No such attribute ``%s''\n", attr_delete); | 387 | if (NULL == attr_to_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); | ||
389 | return; | 397 | return; |
390 | } | 398 | } |
391 | reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle, | ||
392 | pkey, | ||
393 | attr_to_delete, | ||
394 | &process_delete, | ||
395 | NULL); | ||
396 | return; | ||
397 | } | ||
398 | if (attr_name) | 399 | if (attr_name) |
399 | { | 400 | { |
400 | if (NULL == type_str) | 401 | if (NULL == type_str) |
401 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; | 402 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; |
402 | else | 403 | else |
403 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 404 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); |
404 | 405 | ||
405 | GNUNET_assert (GNUNET_SYSERR != | 406 | GNUNET_assert(GNUNET_SYSERR != |
406 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 407 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, |
407 | attr_value, | 408 | attr_value, |
408 | (void **) &data, | 409 | (void **)&data, |
409 | &data_size)); | 410 | &data_size)); |
410 | if (NULL != claim) | 411 | if (NULL != claim) |
411 | { | 412 | { |
412 | claim->type = type; | 413 | claim->type = type; |
413 | claim->data = data; | 414 | claim->data = data; |
414 | claim->data_size = data_size; | 415 | claim->data_size = data_size; |
415 | } | 416 | } |
416 | else | 417 | else |
417 | { | 418 | { |
418 | claim = | 419 | claim = |
419 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | 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; | ||
420 | } | 431 | } |
421 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, | 432 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
422 | pkey, | ||
423 | claim, | ||
424 | &exp_interval, | ||
425 | &store_attr_cont, | ||
426 | NULL); | ||
427 | GNUNET_free (data); | ||
428 | GNUNET_free (claim); | ||
429 | return; | ||
430 | } | ||
431 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
432 | } | 433 | } |
433 | 434 | ||
434 | static void | 435 | static void |
435 | iter_cb (void *cls, | 436 | iter_cb(void *cls, |
436 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 437 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
437 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 438 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
438 | { | 439 | { |
439 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 440 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
440 | char *attrs_tmp; | 441 | char *attrs_tmp; |
@@ -444,260 +445,260 @@ iter_cb (void *cls, | |||
444 | const char *attr_type; | 445 | const char *attr_type; |
445 | 446 | ||
446 | if ((NULL != attr_name) && (NULL != claim)) | 447 | if ((NULL != attr_name) && (NULL != claim)) |
447 | { | ||
448 | if (0 == strcasecmp (attr_name, attr->name)) | ||
449 | { | 448 | { |
450 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 449 | if (0 == strcasecmp(attr_name, attr->name)) |
451 | attr->type, | 450 | { |
452 | attr->data, | 451 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
453 | attr->data_size); | 452 | attr->type, |
453 | attr->data, | ||
454 | attr->data_size); | ||
455 | } | ||
454 | } | 456 | } |
455 | } | ||
456 | else if (issue_attrs) | 457 | else if (issue_attrs) |
457 | { | ||
458 | attrs_tmp = GNUNET_strdup (issue_attrs); | ||
459 | attr_str = strtok (attrs_tmp, ","); | ||
460 | while (NULL != attr_str) | ||
461 | { | 458 | { |
462 | if (0 != strcasecmp (attr_str, attr->name)) | 459 | attrs_tmp = GNUNET_strdup(issue_attrs); |
463 | { | 460 | attr_str = strtok(attrs_tmp, ","); |
464 | attr_str = strtok (NULL, ","); | 461 | while (NULL != attr_str) |
465 | continue; | 462 | { |
466 | } | 463 | if (0 != strcasecmp(attr_str, attr->name)) |
467 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 464 | { |
468 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 465 | attr_str = strtok(NULL, ","); |
469 | attr->type, | 466 | continue; |
470 | attr->data, | 467 | } |
471 | attr->data_size); | 468 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
472 | le->claim->version = attr->version; | 469 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
473 | le->claim->id = attr->id; | 470 | attr->type, |
474 | GNUNET_CONTAINER_DLL_insert (attr_list->list_head, | 471 | attr->data, |
475 | attr_list->list_tail, | 472 | attr->data_size); |
476 | le); | 473 | le->claim->version = attr->version; |
477 | break; | 474 | le->claim->id = attr->id; |
475 | GNUNET_CONTAINER_DLL_insert(attr_list->list_head, | ||
476 | attr_list->list_tail, | ||
477 | le); | ||
478 | break; | ||
479 | } | ||
480 | GNUNET_free(attrs_tmp); | ||
478 | } | 481 | } |
479 | GNUNET_free (attrs_tmp); | ||
480 | } | ||
481 | else if (attr_delete && (NULL == attr_to_delete)) | 482 | else if (attr_delete && (NULL == attr_to_delete)) |
482 | { | ||
483 | label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | ||
484 | if (0 == strcasecmp (attr_delete, label)) | ||
485 | { | 483 | { |
486 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 484 | label = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); |
487 | attr->type, | 485 | if (0 == strcasecmp(attr_delete, label)) |
488 | attr->data, | 486 | { |
489 | attr->data_size); | 487 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
490 | attr_to_delete->id = attr->id; | 488 | attr->type, |
489 | attr->data, | ||
490 | attr->data_size); | ||
491 | attr_to_delete->id = attr->id; | ||
492 | } | ||
493 | GNUNET_free(label); | ||
491 | } | 494 | } |
492 | GNUNET_free (label); | ||
493 | } | ||
494 | else if (list) | 495 | else if (list) |
495 | { | 496 | { |
496 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 497 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
497 | attr->data, | 498 | attr->data, |
498 | attr->data_size); | 499 | attr->data_size); |
499 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 500 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); |
500 | 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)); |
501 | fprintf (stdout, | 502 | fprintf(stdout, |
502 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 503 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
503 | attr->name, | 504 | attr->name, |
504 | attr_str, | 505 | attr_str, |
505 | attr_type, | 506 | attr_type, |
506 | attr->version, | 507 | attr->version, |
507 | id); | 508 | id); |
508 | GNUNET_free (id); | 509 | GNUNET_free(id); |
509 | } | 510 | } |
510 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); | 511 | GNUNET_RECLAIM_get_attributes_next(attr_iterator); |
511 | } | 512 | } |
512 | 513 | ||
513 | static void | 514 | static void |
514 | start_process () | 515 | start_process() |
515 | { | 516 | { |
516 | if (NULL == pkey) | 517 | if (NULL == pkey) |
517 | { | 518 | { |
518 | fprintf (stderr, "Ego %s not found\n", ego_name); | 519 | fprintf(stderr, "Ego %s not found\n", ego_name); |
519 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 520 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
520 | return; | 521 | return; |
521 | } | 522 | } |
522 | 523 | ||
523 | if (list_tickets) | 524 | if (list_tickets) |
524 | { | 525 | { |
525 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, | 526 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start(reclaim_handle, |
526 | pkey, | 527 | pkey, |
527 | &ticket_iter_err, | 528 | &ticket_iter_err, |
528 | NULL, | 529 | NULL, |
529 | &ticket_iter, | 530 | &ticket_iter, |
530 | NULL, | 531 | NULL, |
531 | &ticket_iter_fin, | 532 | &ticket_iter_fin, |
532 | NULL); | 533 | NULL); |
533 | return; | 534 | return; |
534 | } | 535 | } |
535 | 536 | ||
536 | if ((NULL != rp) && | 537 | if ((NULL != rp) && |
537 | GNUNET_OK != | 538 | GNUNET_OK != |
538 | 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)) |
539 | { | 540 | { |
540 | fprintf (stderr, "%s is not a public key!\n", rp); | 541 | fprintf(stderr, "%s is not a public key!\n", rp); |
541 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 542 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
542 | return; | 543 | return; |
543 | } | 544 | } |
544 | if (NULL != consume_ticket) | 545 | if (NULL != consume_ticket) |
545 | GNUNET_STRINGS_string_to_data (consume_ticket, | 546 | GNUNET_STRINGS_string_to_data(consume_ticket, |
546 | strlen (consume_ticket), | 547 | strlen(consume_ticket), |
547 | &ticket, | 548 | &ticket, |
548 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 549 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
549 | if (NULL != revoke_ticket) | 550 | if (NULL != revoke_ticket) |
550 | GNUNET_STRINGS_string_to_data (revoke_ticket, | 551 | GNUNET_STRINGS_string_to_data(revoke_ticket, |
551 | strlen (revoke_ticket), | 552 | strlen(revoke_ticket), |
552 | &ticket, | 553 | &ticket, |
553 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 554 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
554 | 555 | ||
555 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 556 | attr_list = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
556 | claim = NULL; | 557 | claim = NULL; |
557 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, | 558 | attr_iterator = GNUNET_RECLAIM_get_attributes_start(reclaim_handle, |
558 | pkey, | 559 | pkey, |
559 | &iter_error, | 560 | &iter_error, |
560 | NULL, | 561 | NULL, |
561 | &iter_cb, | 562 | &iter_cb, |
562 | NULL, | 563 | NULL, |
563 | &iter_finished, | 564 | &iter_finished, |
564 | NULL); | 565 | NULL); |
565 | } | 566 | } |
566 | 567 | ||
567 | static int init = GNUNET_YES; | 568 | static int init = GNUNET_YES; |
568 | 569 | ||
569 | static void | 570 | static void |
570 | ego_cb (void *cls, | 571 | ego_cb(void *cls, |
571 | struct GNUNET_IDENTITY_Ego *ego, | 572 | struct GNUNET_IDENTITY_Ego *ego, |
572 | void **ctx, | 573 | void **ctx, |
573 | const char *name) | 574 | const char *name) |
574 | { | 575 | { |
575 | if (NULL == name) | 576 | if (NULL == name) |
576 | { | ||
577 | if (GNUNET_YES == init) | ||
578 | { | 577 | { |
579 | init = GNUNET_NO; | 578 | if (GNUNET_YES == init) |
580 | start_process (); | 579 | { |
580 | init = GNUNET_NO; | ||
581 | start_process(); | ||
582 | } | ||
583 | return; | ||
581 | } | 584 | } |
585 | if (0 != strcmp(name, ego_name)) | ||
582 | return; | 586 | return; |
583 | } | 587 | pkey = GNUNET_IDENTITY_ego_get_private_key(ego); |
584 | if (0 != strcmp (name, ego_name)) | ||
585 | return; | ||
586 | pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
587 | } | 588 | } |
588 | 589 | ||
589 | 590 | ||
590 | static void | 591 | static void |
591 | run (void *cls, | 592 | run(void *cls, |
592 | char *const *args, | 593 | char *const *args, |
593 | const char *cfgfile, | 594 | const char *cfgfile, |
594 | const struct GNUNET_CONFIGURATION_Handle *c) | 595 | const struct GNUNET_CONFIGURATION_Handle *c) |
595 | { | 596 | { |
596 | ret = 0; | 597 | ret = 0; |
597 | if (NULL == ego_name) | 598 | if (NULL == ego_name) |
598 | { | 599 | { |
599 | ret = 1; | 600 | ret = 1; |
600 | fprintf (stderr, _ ("Ego is required\n")); | 601 | fprintf(stderr, _("Ego is required\n")); |
601 | return; | 602 | return; |
602 | } | 603 | } |
603 | 604 | ||
604 | if ((NULL == attr_value) && (NULL != attr_name)) | 605 | if ((NULL == attr_value) && (NULL != attr_name)) |
605 | { | 606 | { |
606 | ret = 1; | 607 | ret = 1; |
607 | fprintf (stderr, _ ("Attribute value missing!\n")); | 608 | fprintf(stderr, _("Attribute value missing!\n")); |
608 | return; | 609 | return; |
609 | } | 610 | } |
610 | 611 | ||
611 | if ((NULL == rp) && (NULL != issue_attrs)) | 612 | if ((NULL == rp) && (NULL != issue_attrs)) |
612 | { | 613 | { |
613 | ret = 1; | 614 | ret = 1; |
614 | fprintf (stderr, _ ("Requesting party key is required!\n")); | 615 | fprintf(stderr, _("Requesting party key is required!\n")); |
615 | return; | 616 | return; |
616 | } | 617 | } |
617 | 618 | ||
618 | reclaim_handle = GNUNET_RECLAIM_connect (c); | 619 | reclaim_handle = GNUNET_RECLAIM_connect(c); |
619 | // Get Ego | 620 | // Get Ego |
620 | identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL); | 621 | identity_handle = GNUNET_IDENTITY_connect(c, &ego_cb, NULL); |
621 | } | 622 | } |
622 | 623 | ||
623 | 624 | ||
624 | int | 625 | int |
625 | main (int argc, char *const argv[]) | 626 | main(int argc, char *const argv[]) |
626 | { | 627 | { |
627 | exp_interval = GNUNET_TIME_UNIT_HOURS; | 628 | exp_interval = GNUNET_TIME_UNIT_HOURS; |
628 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 629 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
629 | 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 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 694 | }; |
695 | argv, | 695 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, |
696 | "gnunet-reclaim", | 696 | argv, |
697 | _ ("re:claimID command line tool"), | 697 | "gnunet-reclaim", |
698 | options, | 698 | _("re:claimID command line tool"), |
699 | &run, | 699 | options, |
700 | NULL)) | 700 | &run, |
701 | NULL)) | ||
701 | return 1; | 702 | return 1; |
702 | else | 703 | else |
703 | return ret; | 704 | return ret; |