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