aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/gnunet-peerinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo-tool/gnunet-peerinfo.c')
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c664
1 files changed, 333 insertions, 331 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index bd029b2d1..7fa7ab2f5 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -35,7 +35,7 @@
35/** 35/**
36 * How long until we time out during address lookup? 36 * How long until we time out during address lookup?
37 */ 37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
39 39
40/** 40/**
41 * Structure we use to collect printable address information. 41 * Structure we use to collect printable address information.
@@ -45,7 +45,8 @@ struct PrintContext;
45/** 45/**
46 * Record we keep for each printable address. 46 * Record we keep for each printable address.
47 */ 47 */
48struct AddressRecord { 48struct AddressRecord
49{
49 /** 50 /**
50 * Current address-to-string context (if active, otherwise NULL). 51 * Current address-to-string context (if active, otherwise NULL).
51 */ 52 */
@@ -71,7 +72,8 @@ struct AddressRecord {
71/** 72/**
72 * Structure we use to collect printable address information. 73 * Structure we use to collect printable address information.
73 */ 74 */
74struct PrintContext { 75struct PrintContext
76{
75 /** 77 /**
76 * Kept in DLL. 78 * Kept in DLL.
77 */ 79 */
@@ -217,7 +219,7 @@ static struct GNUNET_HELLO_Message *my_hello;
217 * @param cls unused 219 * @param cls unused
218 */ 220 */
219static void 221static void
220state_machine(void *cls); 222state_machine (void *cls);
221 223
222 224
223/* ********************* 'get_info' ******************* */ 225/* ********************* 'get_info' ******************* */
@@ -228,30 +230,30 @@ state_machine(void *cls);
228 * @param pc printing context 230 * @param pc printing context
229 */ 231 */
230static void 232static void
231dump_pc(struct PrintContext *pc) 233dump_pc (struct PrintContext *pc)
232{ 234{
233 unsigned int i; 235 unsigned int i;
234 236
235 printf(_("%sPeer `%s'\n"), 237 printf (_ ("%sPeer `%s'\n"),
236 (GNUNET_YES == pc->friend_only) ? "F2F: " : "", 238 (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
237 GNUNET_i2s_full(&pc->peer)); 239 GNUNET_i2s_full (&pc->peer));
238 for (i = 0; i < pc->num_addresses; i++) 240 for (i = 0; i < pc->num_addresses; i++)
241 {
242 if (NULL != pc->address_list[i].result)
239 { 243 {
240 if (NULL != pc->address_list[i].result) 244 printf (_ ("\tExpires: %s \t %s\n"),
241 { 245 GNUNET_STRINGS_absolute_time_to_string (
242 printf(_("\tExpires: %s \t %s\n"), 246 pc->address_list[i].expiration),
243 GNUNET_STRINGS_absolute_time_to_string( 247 pc->address_list[i].result);
244 pc->address_list[i].expiration), 248 GNUNET_free (pc->address_list[i].result);
245 pc->address_list[i].result);
246 GNUNET_free(pc->address_list[i].result);
247 }
248 } 249 }
249 printf("\n"); 250 }
250 GNUNET_free_non_null(pc->address_list); 251 printf ("\n");
251 GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc); 252 GNUNET_free_non_null (pc->address_list);
252 GNUNET_free(pc); 253 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
254 GNUNET_free (pc);
253 if ((NULL == pc_head) && (NULL == pic)) 255 if ((NULL == pc_head) && (NULL == pic))
254 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 256 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
255} 257}
256 258
257 259
@@ -269,29 +271,29 @@ dump_pc(struct PrintContext *pc)
269 * if #GNUNET_SYSERR: address is invalid 271 * if #GNUNET_SYSERR: address is invalid
270 */ 272 */
271static void 273static void
272process_resolved_address(void *cls, const char *address, int res) 274process_resolved_address (void *cls, const char *address, int res)
273{ 275{
274 struct AddressRecord *ar = cls; 276 struct AddressRecord *ar = cls;
275 struct PrintContext *pc = ar->pc; 277 struct PrintContext *pc = ar->pc;
276 278
277 if (NULL != address) 279 if (NULL != address)
280 {
281 if (0 != strlen (address))
278 { 282 {
279 if (0 != strlen(address)) 283 if (NULL != ar->result)
280 { 284 GNUNET_free (ar->result);
281 if (NULL != ar->result) 285 ar->result = GNUNET_strdup (address);
282 GNUNET_free(ar->result);
283 ar->result = GNUNET_strdup(address);
284 }
285 return;
286 } 286 }
287 return;
288 }
287 ar->atsc = NULL; 289 ar->atsc = NULL;
288 if (GNUNET_SYSERR == res) 290 if (GNUNET_SYSERR == res)
289 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 291 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
290 _("Failure: Cannot convert address to string for peer `%s'\n"), 292 _ ("Failure: Cannot convert address to string for peer `%s'\n"),
291 GNUNET_i2s(&ar->pc->peer)); 293 GNUNET_i2s (&ar->pc->peer));
292 pc->num_addresses++; 294 pc->num_addresses++;
293 if (pc->num_addresses == pc->address_list_size) 295 if (pc->num_addresses == pc->address_list_size)
294 dump_pc(pc); 296 dump_pc (pc);
295} 297}
296 298
297 299
@@ -304,9 +306,9 @@ process_resolved_address(void *cls, const char *address, int res)
304 * @return #GNUNET_OK to keep the address and continue 306 * @return #GNUNET_OK to keep the address and continue
305 */ 307 */
306static int 308static int
307count_address(void *cls, 309count_address (void *cls,
308 const struct GNUNET_HELLO_Address *address, 310 const struct GNUNET_HELLO_Address *address,
309 struct GNUNET_TIME_Absolute expiration) 311 struct GNUNET_TIME_Absolute expiration)
310{ 312{
311 struct PrintContext *pc = cls; 313 struct PrintContext *pc = cls;
312 314
@@ -324,28 +326,28 @@ count_address(void *cls,
324 * @return #GNUNET_OK to keep the address and continue 326 * @return #GNUNET_OK to keep the address and continue
325 */ 327 */
326static int 328static int
327print_address(void *cls, 329print_address (void *cls,
328 const struct GNUNET_HELLO_Address *address, 330 const struct GNUNET_HELLO_Address *address,
329 struct GNUNET_TIME_Absolute expiration) 331 struct GNUNET_TIME_Absolute expiration)
330{ 332{
331 struct PrintContext *pc = cls; 333 struct PrintContext *pc = cls;
332 struct AddressRecord *ar; 334 struct AddressRecord *ar;
333 335
334 GNUNET_assert(0 < pc->off); 336 GNUNET_assert (0 < pc->off);
335 ar = &pc->address_list[--pc->off]; 337 ar = &pc->address_list[--pc->off];
336 ar->pc = pc; 338 ar->pc = pc;
337 ar->expiration = expiration; 339 ar->expiration = expiration;
338 GNUNET_asprintf(&ar->result, 340 GNUNET_asprintf (&ar->result,
339 "%s:%u:%u", 341 "%s:%u:%u",
340 address->transport_name, 342 address->transport_name,
341 address->address_length, 343 address->address_length,
342 address->local_info); 344 address->local_info);
343 ar->atsc = GNUNET_TRANSPORT_address_to_string(cfg, 345 ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
344 address, 346 address,
345 no_resolve, 347 no_resolve,
346 TIMEOUT, 348 TIMEOUT,
347 &process_resolved_address, 349 &process_resolved_address,
348 ar); 350 ar);
349 return GNUNET_OK; 351 return GNUNET_OK;
350} 352}
351 353
@@ -360,50 +362,50 @@ print_address(void *cls,
360 * @param err_msg error message 362 * @param err_msg error message
361 */ 363 */
362static void 364static void
363print_peer_info(void *cls, 365print_peer_info (void *cls,
364 const struct GNUNET_PeerIdentity *peer, 366 const struct GNUNET_PeerIdentity *peer,
365 const struct GNUNET_HELLO_Message *hello, 367 const struct GNUNET_HELLO_Message *hello,
366 const char *err_msg) 368 const char *err_msg)
367{ 369{
368 struct PrintContext *pc; 370 struct PrintContext *pc;
369 int friend_only; 371 int friend_only;
370 372
371 if (NULL == peer) 373 if (NULL == peer)
374 {
375 pic = NULL; /* end of iteration */
376 if (NULL != err_msg)
372 { 377 {
373 pic = NULL; /* end of iteration */ 378 fprintf (stderr,
374 if (NULL != err_msg) 379 _ ("Error in communication with PEERINFO service: %s\n"),
375 { 380 err_msg);
376 fprintf(stderr,
377 _("Error in communication with PEERINFO service: %s\n"),
378 err_msg);
379 }
380 if (NULL == pc_head)
381 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL);
382 return;
383 } 381 }
382 if (NULL == pc_head)
383 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
384 return;
385 }
384 friend_only = GNUNET_NO; 386 friend_only = GNUNET_NO;
385 if (NULL != hello) 387 if (NULL != hello)
386 friend_only = GNUNET_HELLO_is_friend_only(hello); 388 friend_only = GNUNET_HELLO_is_friend_only (hello);
387 if ((GNUNET_YES == be_quiet) || (NULL == hello)) 389 if ((GNUNET_YES == be_quiet) || (NULL == hello))
388 { 390 {
389 printf("%s%s\n", 391 printf ("%s%s\n",
390 (GNUNET_YES == friend_only) ? "F2F: " : "", 392 (GNUNET_YES == friend_only) ? "F2F: " : "",
391 GNUNET_i2s_full(peer)); 393 GNUNET_i2s_full (peer));
392 return; 394 return;
393 } 395 }
394 pc = GNUNET_new(struct PrintContext); 396 pc = GNUNET_new (struct PrintContext);
395 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); 397 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
396 pc->peer = *peer; 398 pc->peer = *peer;
397 pc->friend_only = friend_only; 399 pc->friend_only = friend_only;
398 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &count_address, pc); 400 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc);
399 if (0 == pc->off) 401 if (0 == pc->off)
400 { 402 {
401 dump_pc(pc); 403 dump_pc (pc);
402 return; 404 return;
403 } 405 }
404 pc->address_list_size = pc->off; 406 pc->address_list_size = pc->off;
405 pc->address_list = GNUNET_malloc(sizeof(struct AddressRecord) * pc->off); 407 pc->address_list = GNUNET_malloc (sizeof(struct AddressRecord) * pc->off);
406 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &print_address, pc); 408 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
407} 409}
408 410
409/* ************************* DUMP Hello ************************** */ 411/* ************************* DUMP Hello ************************** */
@@ -417,9 +419,9 @@ print_peer_info(void *cls,
417 * @return #GNUNET_OK 419 * @return #GNUNET_OK
418 */ 420 */
419static int 421static int
420count_addr(void *cls, 422count_addr (void *cls,
421 const struct GNUNET_HELLO_Address *address, 423 const struct GNUNET_HELLO_Address *address,
422 struct GNUNET_TIME_Absolute expiration) 424 struct GNUNET_TIME_Absolute expiration)
423{ 425{
424 int *c = cls; 426 int *c = cls;
425 427
@@ -437,50 +439,50 @@ count_addr(void *cls,
437 * @param err_msg error message 439 * @param err_msg error message
438 */ 440 */
439static void 441static void
440dump_my_hello() 442dump_my_hello ()
441{ 443{
442 unsigned int size; 444 unsigned int size;
443 unsigned int c_addr; 445 unsigned int c_addr;
444 446
445 size = GNUNET_HELLO_size(my_hello); 447 size = GNUNET_HELLO_size (my_hello);
446 if (0 == size) 448 if (0 == size)
447 { 449 {
448 fprintf(stderr, _("Failure: Received invalid %s\n"), "HELLO"); 450 fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO");
449 return; 451 return;
450 } 452 }
451 if (GNUNET_SYSERR == GNUNET_DISK_fn_write(dump_hello, 453 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello,
452 my_hello, 454 my_hello,
453 size, 455 size,
454 GNUNET_DISK_PERM_USER_READ | 456 GNUNET_DISK_PERM_USER_READ
455 GNUNET_DISK_PERM_USER_WRITE | 457 | GNUNET_DISK_PERM_USER_WRITE
456 GNUNET_DISK_PERM_GROUP_READ | 458 | GNUNET_DISK_PERM_GROUP_READ
457 GNUNET_DISK_PERM_OTHER_READ)) 459 | GNUNET_DISK_PERM_OTHER_READ))
458 { 460 {
459 fprintf(stderr, 461 fprintf (stderr,
460 _("Failed to write HELLO with %u bytes to file `%s'\n"), 462 _ ("Failed to write HELLO with %u bytes to file `%s'\n"),
461 size, 463 size,
462 dump_hello); 464 dump_hello);
463 if (0 != unlink(dump_hello)) 465 if (0 != unlink (dump_hello))
464 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | 466 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING
465 GNUNET_ERROR_TYPE_BULK, 467 | GNUNET_ERROR_TYPE_BULK,
466 "unlink", 468 "unlink",
467 dump_hello); 469 dump_hello);
468 } 470 }
469 c_addr = 0; 471 c_addr = 0;
470 GNUNET_HELLO_iterate_addresses(my_hello, GNUNET_NO, count_addr, &c_addr); 472 GNUNET_HELLO_iterate_addresses (my_hello, GNUNET_NO, count_addr, &c_addr);
471 473
472 if (!be_quiet) 474 if (! be_quiet)
473 { 475 {
474 fprintf( 476 fprintf (
475 stderr, 477 stderr,
476 _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"), 478 _ ("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
477 (GNUNET_YES == GNUNET_HELLO_is_friend_only(my_hello)) ? "friend-only" 479 (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only"
478 : "public", 480 : "public",
479 c_addr, 481 c_addr,
480 size, 482 size,
481 dump_hello); 483 dump_hello);
482 } 484 }
483 GNUNET_free(dump_hello); 485 GNUNET_free (dump_hello);
484 dump_hello = NULL; 486 dump_hello = NULL;
485} 487}
486 488
@@ -497,32 +499,32 @@ dump_my_hello()
497 * @param err_msg error message 499 * @param err_msg error message
498 */ 500 */
499static void 501static void
500print_my_uri(void *cls, 502print_my_uri (void *cls,
501 const struct GNUNET_PeerIdentity *peer, 503 const struct GNUNET_PeerIdentity *peer,
502 const struct GNUNET_HELLO_Message *hello, 504 const struct GNUNET_HELLO_Message *hello,
503 const char *err_msg) 505 const char *err_msg)
504{ 506{
505 char *uri; 507 char *uri;
506 508
507 if (NULL == peer) 509 if (NULL == peer)
508 { 510 {
509 pic = NULL; 511 pic = NULL;
510 if (NULL != err_msg) 512 if (NULL != err_msg)
511 fprintf(stderr, 513 fprintf (stderr,
512 _("Error in communication with PEERINFO service: %s\n"), 514 _ ("Error in communication with PEERINFO service: %s\n"),
513 err_msg); 515 err_msg);
514 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 516 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
515 return; 517 return;
516 } 518 }
517 519
518 if (NULL == hello) 520 if (NULL == hello)
519 return; 521 return;
520 uri = GNUNET_HELLO_compose_uri(hello, &GPI_plugins_find); 522 uri = GNUNET_HELLO_compose_uri (hello, &GPI_plugins_find);
521 if (NULL != uri) 523 if (NULL != uri)
522 { 524 {
523 printf("%s\n", (const char *)uri); 525 printf ("%s\n", (const char *) uri);
524 GNUNET_free(uri); 526 GNUNET_free (uri);
525 } 527 }
526} 528}
527 529
528 530
@@ -535,10 +537,10 @@ print_my_uri(void *cls,
535 * @param cls closure, NULL 537 * @param cls closure, NULL
536 */ 538 */
537static void 539static void
538add_continuation(void *cls) 540add_continuation (void *cls)
539{ 541{
540 ac = NULL; 542 ac = NULL;
541 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 543 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
542} 544}
543 545
544 546
@@ -552,24 +554,24 @@ add_continuation(void *cls)
552 * #GNUNET_NO on other errors 554 * #GNUNET_NO on other errors
553 */ 555 */
554static int 556static int
555parse_hello_uri(const char *put_uri) 557parse_hello_uri (const char *put_uri)
556{ 558{
557 struct GNUNET_HELLO_Message *hello = NULL; 559 struct GNUNET_HELLO_Message *hello = NULL;
558 560
559 int ret = GNUNET_HELLO_parse_uri(put_uri, 561 int ret = GNUNET_HELLO_parse_uri (put_uri,
560 &my_peer_identity.public_key, 562 &my_peer_identity.public_key,
561 &hello, 563 &hello,
562 &GPI_plugins_find); 564 &GPI_plugins_find);
563 565
564 if (NULL != hello) 566 if (NULL != hello)
565 { 567 {
566 /* WARNING: this adds the address from URI WITHOUT verification! */ 568 /* WARNING: this adds the address from URI WITHOUT verification! */
567 if (GNUNET_OK == ret) 569 if (GNUNET_OK == ret)
568 ac = GNUNET_PEERINFO_add_peer(peerinfo, hello, &add_continuation, NULL); 570 ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL);
569 else 571 else
570 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 572 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
571 GNUNET_free(hello); 573 GNUNET_free (hello);
572 } 574 }
573 return ret; 575 return ret;
574} 576}
575 577
@@ -584,59 +586,59 @@ parse_hello_uri(const char *put_uri)
584 * @param cls unused 586 * @param cls unused
585 */ 587 */
586static void 588static void
587shutdown_task(void *cls) 589shutdown_task (void *cls)
588{ 590{
589 struct PrintContext *pc; 591 struct PrintContext *pc;
590 struct AddressRecord *ar; 592 struct AddressRecord *ar;
591 unsigned int i; 593 unsigned int i;
592 594
593 if (NULL != ac) 595 if (NULL != ac)
594 { 596 {
595 GNUNET_MQ_send_cancel(ac); 597 GNUNET_MQ_send_cancel (ac);
596 ac = NULL; 598 ac = NULL;
597 } 599 }
598 if (NULL != tt) 600 if (NULL != tt)
599 { 601 {
600 GNUNET_SCHEDULER_cancel(tt); 602 GNUNET_SCHEDULER_cancel (tt);
601 tt = NULL; 603 tt = NULL;
602 } 604 }
603 if (NULL != pic) 605 if (NULL != pic)
604 { 606 {
605 GNUNET_PEERINFO_iterate_cancel(pic); 607 GNUNET_PEERINFO_iterate_cancel (pic);
606 pic = NULL; 608 pic = NULL;
607 } 609 }
608 if (NULL != gh) 610 if (NULL != gh)
609 { 611 {
610 GNUNET_TRANSPORT_hello_get_cancel(gh); 612 GNUNET_TRANSPORT_hello_get_cancel (gh);
611 gh = NULL; 613 gh = NULL;
612 } 614 }
613 while (NULL != (pc = pc_head)) 615 while (NULL != (pc = pc_head))
616 {
617 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
618 for (i = 0; i < pc->address_list_size; i++)
614 { 619 {
615 GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc); 620 ar = &pc->address_list[i];
616 for (i = 0; i < pc->address_list_size; i++) 621 GNUNET_free_non_null (ar->result);
617 { 622 if (NULL != ar->atsc)
618 ar = &pc->address_list[i]; 623 {
619 GNUNET_free_non_null(ar->result); 624 GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc);
620 if (NULL != ar->atsc) 625 ar->atsc = NULL;
621 { 626 }
622 GNUNET_TRANSPORT_address_to_string_cancel(ar->atsc);
623 ar->atsc = NULL;
624 }
625 }
626 GNUNET_free_non_null(pc->address_list);
627 GNUNET_free(pc);
628 } 627 }
629 GPI_plugins_unload(); 628 GNUNET_free_non_null (pc->address_list);
629 GNUNET_free (pc);
630 }
631 GPI_plugins_unload ();
630 if (NULL != peerinfo) 632 if (NULL != peerinfo)
631 { 633 {
632 GNUNET_PEERINFO_disconnect(peerinfo); 634 GNUNET_PEERINFO_disconnect (peerinfo);
633 peerinfo = NULL; 635 peerinfo = NULL;
634 } 636 }
635 if (NULL != my_hello) 637 if (NULL != my_hello)
636 { 638 {
637 GNUNET_free(my_hello); 639 GNUNET_free (my_hello);
638 my_hello = NULL; 640 my_hello = NULL;
639 } 641 }
640} 642}
641 643
642 644
@@ -648,22 +650,22 @@ shutdown_task(void *cls)
648 * @param hello the HELLO message 650 * @param hello the HELLO message
649 */ 651 */
650static void 652static void
651hello_callback(void *cls, const struct GNUNET_MessageHeader *hello) 653hello_callback (void *cls, const struct GNUNET_MessageHeader *hello)
652{ 654{
653 if (NULL == hello) 655 if (NULL == hello)
654 { 656 {
655 fprintf(stderr, "Failed to get my own HELLO from this peer!\n"); 657 fprintf (stderr, "Failed to get my own HELLO from this peer!\n");
656 GNUNET_SCHEDULER_shutdown(); 658 GNUNET_SCHEDULER_shutdown ();
657 return; 659 return;
658 } 660 }
659 my_hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(hello); 661 my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
660 GNUNET_assert(GNUNET_OK == 662 GNUNET_assert (GNUNET_OK ==
661 GNUNET_HELLO_get_id(my_hello, &my_peer_identity)); 663 GNUNET_HELLO_get_id (my_hello, &my_peer_identity));
662 GNUNET_TRANSPORT_hello_get_cancel(gh); 664 GNUNET_TRANSPORT_hello_get_cancel (gh);
663 gh = NULL; 665 gh = NULL;
664 if (NULL != dump_hello) 666 if (NULL != dump_hello)
665 dump_my_hello(); 667 dump_my_hello ();
666 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 668 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
667} 669}
668 670
669 671
@@ -676,41 +678,41 @@ hello_callback(void *cls, const struct GNUNET_MessageHeader *hello)
676 * @param c configuration 678 * @param c configuration
677 */ 679 */
678static void 680static void
679run(void *cls, 681run (void *cls,
680 char *const *args, 682 char *const *args,
681 const char *cfgfile, 683 const char *cfgfile,
682 const struct GNUNET_CONFIGURATION_Handle *c) 684 const struct GNUNET_CONFIGURATION_Handle *c)
683{ 685{
684 cfg = c; 686 cfg = c;
685 if ((NULL != args[0]) && (NULL == put_uri) && 687 if ((NULL != args[0]) && (NULL == put_uri) &&
686 (args[0] == strcasestr(args[0], "gnunet://hello/"))) 688 (args[0] == strcasestr (args[0], "gnunet://hello/")))
687 { 689 {
688 put_uri = GNUNET_strdup(args[0]); 690 put_uri = GNUNET_strdup (args[0]);
689 args++; 691 args++;
690 } 692 }
691 if (NULL != args[0]) 693 if (NULL != args[0])
692 { 694 {
693 fprintf(stderr, _("Invalid command line argument `%s'\n"), args[0]); 695 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
694 return; 696 return;
695 } 697 }
696 if (NULL == (peerinfo = GNUNET_PEERINFO_connect(cfg))) 698 if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg)))
697 { 699 {
698 fprintf(stderr, "%s", "Could not access PEERINFO service. Exiting.\n"); 700 fprintf (stderr, "%s", "Could not access PEERINFO service. Exiting.\n");
699 return; 701 return;
700 } 702 }
701 if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) || 703 if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) ||
702 (NULL != dump_hello)) 704 (NULL != dump_hello))
703 { 705 {
704 gh = GNUNET_TRANSPORT_hello_get(cfg, 706 gh = GNUNET_TRANSPORT_hello_get (cfg,
705 GNUNET_TRANSPORT_AC_ANY, 707 GNUNET_TRANSPORT_AC_ANY,
706 &hello_callback, 708 &hello_callback,
707 NULL); 709 NULL);
708 } 710 }
709 else 711 else
710 { 712 {
711 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 713 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
712 } 714 }
713 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 715 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
714} 716}
715 717
716 718
@@ -721,61 +723,61 @@ run(void *cls,
721 * @param cls unused 723 * @param cls unused
722 */ 724 */
723static void 725static void
724state_machine(void *cls) 726state_machine (void *cls)
725{ 727{
726 tt = NULL; 728 tt = NULL;
727 729
728 if (NULL != put_uri) 730 if (NULL != put_uri)
731 {
732 GPI_plugins_load (cfg);
733 if (GNUNET_SYSERR == parse_hello_uri (put_uri))
729 { 734 {
730 GPI_plugins_load(cfg); 735 fprintf (stderr, _ ("Invalid URI `%s'\n"), put_uri);
731 if (GNUNET_SYSERR == parse_hello_uri(put_uri)) 736 GNUNET_SCHEDULER_shutdown ();
732 {
733 fprintf(stderr, _("Invalid URI `%s'\n"), put_uri);
734 GNUNET_SCHEDULER_shutdown();
735 }
736 GNUNET_free(put_uri);
737 put_uri = NULL;
738 } 737 }
738 GNUNET_free (put_uri);
739 put_uri = NULL;
740 }
739 else if (GNUNET_YES == get_info) 741 else if (GNUNET_YES == get_info)
740 { 742 {
741 get_info = GNUNET_NO; 743 get_info = GNUNET_NO;
742 GPI_plugins_load(cfg); 744 GPI_plugins_load (cfg);
743 pic = GNUNET_PEERINFO_iterate(peerinfo, 745 pic = GNUNET_PEERINFO_iterate (peerinfo,
744 include_friend_only, 746 include_friend_only,
745 NULL, 747 NULL,
746 &print_peer_info, 748 &print_peer_info,
747 NULL); 749 NULL);
748 } 750 }
749 else if (GNUNET_YES == get_self) 751 else if (GNUNET_YES == get_self)
750 { 752 {
751 get_self = GNUNET_NO; 753 get_self = GNUNET_NO;
752 if (be_quiet) 754 if (be_quiet)
753 printf("%s\n", GNUNET_i2s_full(&my_peer_identity)); 755 printf ("%s\n", GNUNET_i2s_full (&my_peer_identity));
754 else 756 else
755 printf(_("I am peer `%s'.\n"), GNUNET_i2s_full(&my_peer_identity)); 757 printf (_ ("I am peer `%s'.\n"), GNUNET_i2s_full (&my_peer_identity));
756 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 758 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
757 } 759 }
758 else if (GNUNET_YES == get_uri) 760 else if (GNUNET_YES == get_uri)
759 { 761 {
760 GPI_plugins_load(cfg); 762 GPI_plugins_load (cfg);
761 pic = GNUNET_PEERINFO_iterate(peerinfo, 763 pic = GNUNET_PEERINFO_iterate (peerinfo,
762 include_friend_only, 764 include_friend_only,
763 &my_peer_identity, 765 &my_peer_identity,
764 &print_my_uri, 766 &print_my_uri,
765 NULL); 767 NULL);
766 get_uri = GNUNET_NO; 768 get_uri = GNUNET_NO;
767 } 769 }
768 else if (GNUNET_YES == default_operation) 770 else if (GNUNET_YES == default_operation)
769 { 771 {
770 /* default operation list all */ 772 /* default operation list all */
771 default_operation = GNUNET_NO; 773 default_operation = GNUNET_NO;
772 get_info = GNUNET_YES; 774 get_info = GNUNET_YES;
773 tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); 775 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
774 } 776 }
775 else 777 else
776 { 778 {
777 GNUNET_SCHEDULER_shutdown(); 779 GNUNET_SCHEDULER_shutdown ();
778 } 780 }
779 default_operation = GNUNET_NO; 781 default_operation = GNUNET_NO;
780} 782}
781 783
@@ -788,71 +790,71 @@ state_machine(void *cls)
788 * @return 0 ok, 1 on error 790 * @return 0 ok, 1 on error
789 */ 791 */
790int 792int
791main(int argc, char *const *argv) 793main (int argc, char *const *argv)
792{ 794{
793 struct GNUNET_GETOPT_CommandLineOption options[] = 795 struct GNUNET_GETOPT_CommandLineOption options[] =
794 { GNUNET_GETOPT_option_flag('n', 796 { GNUNET_GETOPT_option_flag ('n',
795 "numeric", 797 "numeric",
796 gettext_noop("don't resolve host names"), 798 gettext_noop ("don't resolve host names"),
797 &no_resolve), 799 &no_resolve),
798 800
799 GNUNET_GETOPT_option_flag('q', 801 GNUNET_GETOPT_option_flag ('q',
800 "quiet", 802 "quiet",
801 gettext_noop( 803 gettext_noop (
802 "output only the identity strings"), 804 "output only the identity strings"),
803 &be_quiet), 805 &be_quiet),
804 GNUNET_GETOPT_option_flag('f', 806 GNUNET_GETOPT_option_flag ('f',
805 "friends", 807 "friends",
806 gettext_noop( 808 gettext_noop (
807 "include friend-only information"), 809 "include friend-only information"),
808 &include_friend_only), 810 &include_friend_only),
809 811
810 GNUNET_GETOPT_option_flag('s', 812 GNUNET_GETOPT_option_flag ('s',
811 "self", 813 "self",
812 gettext_noop("output our own identity only"), 814 gettext_noop ("output our own identity only"),
813 &get_self), 815 &get_self),
814 816
815 GNUNET_GETOPT_option_flag('i', 817 GNUNET_GETOPT_option_flag ('i',
816 "info", 818 "info",
817 gettext_noop("list all known peers"), 819 gettext_noop ("list all known peers"),
818 &get_info), 820 &get_info),
819 821
820 GNUNET_GETOPT_option_string('d', 822 GNUNET_GETOPT_option_string ('d',
821 "dump-hello", 823 "dump-hello",
822 NULL, 824 NULL,
823 gettext_noop("dump hello to file"), 825 gettext_noop ("dump hello to file"),
824 &dump_hello), 826 &dump_hello),
825 827
826 GNUNET_GETOPT_option_flag('g', 828 GNUNET_GETOPT_option_flag ('g',
827 "get-hello", 829 "get-hello",
828 gettext_noop("also output HELLO uri(s)"), 830 gettext_noop ("also output HELLO uri(s)"),
829 &get_uri), 831 &get_uri),
830 832
831 GNUNET_GETOPT_option_string('p', 833 GNUNET_GETOPT_option_string ('p',
832 "put-hello", 834 "put-hello",
833 "HELLO", 835 "HELLO",
834 gettext_noop( 836 gettext_noop (
835 "add given HELLO uri to the database"), 837 "add given HELLO uri to the database"),
836 &put_uri), 838 &put_uri),
837 839
838 GNUNET_GETOPT_OPTION_END }; 840 GNUNET_GETOPT_OPTION_END };
839 int ret; 841 int ret;
840 842
841 default_operation = GNUNET_YES; 843 default_operation = GNUNET_YES;
842 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 844 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
843 return 2; 845 return 2;
844 846
845 ret = (GNUNET_OK == 847 ret = (GNUNET_OK ==
846 GNUNET_PROGRAM_run(argc, 848 GNUNET_PROGRAM_run (argc,
847 argv, 849 argv,
848 "gnunet-peerinfo", 850 "gnunet-peerinfo",
849 gettext_noop("Print information about peers."), 851 gettext_noop ("Print information about peers."),
850 options, 852 options,
851 &run, 853 &run,
852 NULL)) 854 NULL))
853 ? 0 855 ? 0
854 : 1; 856 : 1;
855 GNUNET_free((void *)argv); 857 GNUNET_free ((void *) argv);
856 return ret; 858 return ret;
857} 859}
858 860