aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/peerinfo-tool
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/peerinfo-tool')
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c664
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo_plugins.c111
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo_plugins.h6
-rw-r--r--src/peerinfo-tool/plugin_rest_peerinfo.c541
4 files changed, 665 insertions, 657 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
diff --git a/src/peerinfo-tool/gnunet-peerinfo_plugins.c b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
index 13730629e..9449dd67e 100644
--- a/src/peerinfo-tool/gnunet-peerinfo_plugins.c
+++ b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * Entry in doubly-linked list of all of our plugins. 32 * Entry in doubly-linked list of all of our plugins.
33 */ 33 */
34struct TransportPlugin { 34struct TransportPlugin
35{
35 /** 36 /**
36 * This is a doubly-linked list. 37 * This is a doubly-linked list.
37 */ 38 */
@@ -86,7 +87,7 @@ static struct TransportPlugin *plugins_tail;
86 * @param cfg configuration to use 87 * @param cfg configuration to use
87 */ 88 */
88void 89void
89GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg) 90GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
90{ 91{
91 struct TransportPlugin *plug; 92 struct TransportPlugin *plug;
92 struct TransportPlugin *next; 93 struct TransportPlugin *next;
@@ -97,41 +98,41 @@ GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
97 if (NULL != plugins_head) 98 if (NULL != plugins_head)
98 return; /* already loaded */ 99 return; /* already loaded */
99 if (GNUNET_OK != 100 if (GNUNET_OK !=
100 GNUNET_CONFIGURATION_get_value_string(cfg, "TRANSPORT", "PLUGINS", 101 GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS",
101 &plugs)) 102 &plugs))
102 return; 103 return;
103 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"), 104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Starting transport plugins `%s'\n"),
104 plugs); 105 plugs);
105 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) 106 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
106 { 107 {
107 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"), 108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' transport plugin\n"),
108 pos); 109 pos);
109 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", pos); 110 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
110 plug = GNUNET_new(struct TransportPlugin); 111 plug = GNUNET_new (struct TransportPlugin);
111 plug->short_name = GNUNET_strdup(pos); 112 plug->short_name = GNUNET_strdup (pos);
112 plug->lib_name = libname; 113 plug->lib_name = libname;
113 plug->env.cfg = cfg; 114 plug->env.cfg = cfg;
114 plug->env.cls = plug->short_name; 115 plug->env.cls = plug->short_name;
115 GNUNET_CONTAINER_DLL_insert(plugins_head, plugins_tail, plug); 116 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
116 } 117 }
117 GNUNET_free(plugs); 118 GNUNET_free (plugs);
118 next = plugins_head; 119 next = plugins_head;
119 while (next != NULL) 120 while (next != NULL)
121 {
122 plug = next;
123 next = plug->next;
124 plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
125 if (plug->api == NULL)
120 { 126 {
121 plug = next; 127 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
122 next = plug->next; 128 _ ("Failed to load transport plugin for `%s'\n"),
123 plug->api = GNUNET_PLUGIN_load(plug->lib_name, &plug->env); 129 plug->lib_name);
124 if (plug->api == NULL) 130 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
125 { 131 GNUNET_free (plug->short_name);
126 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 132 GNUNET_free (plug->lib_name);
127 _("Failed to load transport plugin for `%s'\n"), 133 GNUNET_free (plug);
128 plug->lib_name);
129 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
130 GNUNET_free(plug->short_name);
131 GNUNET_free(plug->lib_name);
132 GNUNET_free(plug);
133 }
134 } 134 }
135 }
135} 136}
136 137
137 138
@@ -139,18 +140,18 @@ GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
139 * Unload all plugins 140 * Unload all plugins
140 */ 141 */
141void 142void
142GPI_plugins_unload() 143GPI_plugins_unload ()
143{ 144{
144 struct TransportPlugin *plug; 145 struct TransportPlugin *plug;
145 146
146 while (NULL != (plug = plugins_head)) 147 while (NULL != (plug = plugins_head))
147 { 148 {
148 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); 149 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
149 GNUNET_free(plug->lib_name); 150 GNUNET_free (plug->lib_name);
150 GNUNET_free(plug->short_name); 151 GNUNET_free (plug->short_name);
151 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); 152 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
152 GNUNET_free(plug); 153 GNUNET_free (plug);
153 } 154 }
154} 155}
155 156
156 157
@@ -161,32 +162,32 @@ GPI_plugins_unload()
161 * @return the plugin's API, NULL if the plugin is not loaded 162 * @return the plugin's API, NULL if the plugin is not loaded
162 */ 163 */
163struct GNUNET_TRANSPORT_PluginFunctions * 164struct GNUNET_TRANSPORT_PluginFunctions *
164GPI_plugins_find(const char *name) 165GPI_plugins_find (const char *name)
165{ 166{
166 struct TransportPlugin *head = plugins_head; 167 struct TransportPlugin *head = plugins_head;
167 168
168 char *stripped = GNUNET_strdup(name); 169 char *stripped = GNUNET_strdup (name);
169 char *head_stripped; 170 char *head_stripped;
170 char *sep = strchr(stripped, '_'); 171 char *sep = strchr (stripped, '_');
171 172
172 if (NULL != sep) 173 if (NULL != sep)
173 sep[0] = '\0'; 174 sep[0] = '\0';
174 175
175 while (head != NULL) 176 while (head != NULL)
177 {
178 head_stripped = GNUNET_strdup (head->short_name);
179 char *head_sep = strchr (head_stripped, '_');
180 if (NULL != head_sep)
181 head_sep[0] = '\0';
182 if (0 == strcmp (head_stripped, stripped))
176 { 183 {
177 head_stripped = GNUNET_strdup(head->short_name); 184 GNUNET_free (head_stripped);
178 char *head_sep = strchr(head_stripped, '_'); 185 break;
179 if (NULL != head_sep)
180 head_sep[0] = '\0';
181 if (0 == strcmp(head_stripped, stripped))
182 {
183 GNUNET_free(head_stripped);
184 break;
185 }
186 GNUNET_free(head_stripped);
187 head = head->next;
188 } 186 }
189 GNUNET_free(stripped); 187 GNUNET_free (head_stripped);
188 head = head->next;
189 }
190 GNUNET_free (stripped);
190 if (NULL == head) 191 if (NULL == head)
191 return NULL; 192 return NULL;
192 return head->api; 193 return head->api;
diff --git a/src/peerinfo-tool/gnunet-peerinfo_plugins.h b/src/peerinfo-tool/gnunet-peerinfo_plugins.h
index b278cfa21..ed8da87d5 100644
--- a/src/peerinfo-tool/gnunet-peerinfo_plugins.h
+++ b/src/peerinfo-tool/gnunet-peerinfo_plugins.h
@@ -34,14 +34,14 @@
34 * @param cfg configuration to use 34 * @param cfg configuration to use
35 */ 35 */
36void 36void
37GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg); 37GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
38 38
39 39
40/** 40/**
41 * Unload all plugins 41 * Unload all plugins
42 */ 42 */
43void 43void
44GPI_plugins_unload(void); 44GPI_plugins_unload (void);
45 45
46 46
47/** 47/**
@@ -51,7 +51,7 @@ GPI_plugins_unload(void);
51 * @return the plugin's API, NULL if the plugin is not loaded 51 * @return the plugin's API, NULL if the plugin is not loaded
52 */ 52 */
53struct GNUNET_TRANSPORT_PluginFunctions * 53struct GNUNET_TRANSPORT_PluginFunctions *
54GPI_plugins_find(const char *name); 54GPI_plugins_find (const char *name);
55 55
56 56
57#endif 57#endif
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c
index 238946d54..176e24e42 100644
--- a/src/peerinfo-tool/plugin_rest_peerinfo.c
+++ b/src/peerinfo-tool/plugin_rest_peerinfo.c
@@ -61,7 +61,7 @@
61/** 61/**
62 * How long until we time out during address lookup? 62 * How long until we time out during address lookup?
63 */ 63 */
64#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 64#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
65/** 65/**
66 * The configuration handle 66 * The configuration handle
67 */ 67 */
@@ -70,12 +70,13 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
70/** 70/**
71 * HTTP methods allows for this plugin 71 * HTTP methods allows for this plugin
72 */ 72 */
73static char* allow_methods; 73static char*allow_methods;
74 74
75/** 75/**
76 * @brief struct returned by the initialization function of the plugin 76 * @brief struct returned by the initialization function of the plugin
77 */ 77 */
78struct Plugin { 78struct Plugin
79{
79 const struct GNUNET_CONFIGURATION_Handle *cfg; 80 const struct GNUNET_CONFIGURATION_Handle *cfg;
80}; 81};
81 82
@@ -83,7 +84,8 @@ struct Plugin {
83/** 84/**
84 * Record we keep for each printable address. 85 * Record we keep for each printable address.
85 */ 86 */
86struct AddressRecord { 87struct AddressRecord
88{
87 /** 89 /**
88 * Current address-to-string context (if active, otherwise NULL). 90 * Current address-to-string context (if active, otherwise NULL).
89 */ 91 */
@@ -109,7 +111,8 @@ struct AddressRecord {
109/** 111/**
110 * Structure we use to collect printable address information. 112 * Structure we use to collect printable address information.
111 */ 113 */
112struct PrintContext { 114struct PrintContext
115{
113 /** 116 /**
114 * Kept in DLL. 117 * Kept in DLL.
115 */ 118 */
@@ -169,7 +172,8 @@ static struct PrintContext *pc_tail;
169/** 172/**
170 * The request handle 173 * The request handle
171 */ 174 */
172struct RequestHandle { 175struct RequestHandle
176{
173 /** 177 /**
174 * JSON temporary array 178 * JSON temporary array
175 */ 179 */
@@ -252,51 +256,51 @@ struct RequestHandle {
252 * @param handle Handle to clean up 256 * @param handle Handle to clean up
253 */ 257 */
254static void 258static void
255cleanup_handle(void *cls) 259cleanup_handle (void *cls)
256{ 260{
257 struct RequestHandle *handle = cls; 261 struct RequestHandle *handle = cls;
258 262
259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Cleaning up\n"); 264 "Cleaning up\n");
261 if (NULL != handle->timeout_task) 265 if (NULL != handle->timeout_task)
262 { 266 {
263 GNUNET_SCHEDULER_cancel(handle->timeout_task); 267 GNUNET_SCHEDULER_cancel (handle->timeout_task);
264 handle->timeout_task = NULL; 268 handle->timeout_task = NULL;
265 } 269 }
266 if (NULL != handle->url) 270 if (NULL != handle->url)
267 GNUNET_free(handle->url); 271 GNUNET_free (handle->url);
268 if (NULL != handle->emsg) 272 if (NULL != handle->emsg)
269 GNUNET_free(handle->emsg); 273 GNUNET_free (handle->emsg);
270 if (NULL != handle->address) 274 if (NULL != handle->address)
271 GNUNET_free((char*)handle->address); 275 GNUNET_free ((char*) handle->address);
272 if (NULL != handle->expiration_str) 276 if (NULL != handle->expiration_str)
273 GNUNET_free(handle->expiration_str); 277 GNUNET_free (handle->expiration_str);
274 if (NULL != handle->pubkey) 278 if (NULL != handle->pubkey)
275 GNUNET_free(handle->pubkey); 279 GNUNET_free (handle->pubkey);
276 280
277 if (NULL != handle->temp_array) 281 if (NULL != handle->temp_array)
278 { 282 {
279 json_decref(handle->temp_array); 283 json_decref (handle->temp_array);
280 handle->temp_array = NULL; 284 handle->temp_array = NULL;
281 } 285 }
282 if (NULL != handle->response) 286 if (NULL != handle->response)
283 { 287 {
284 json_decref(handle->response); 288 json_decref (handle->response);
285 handle->response = NULL; 289 handle->response = NULL;
286 } 290 }
287 291
288 if (NULL != handle->list_it) 292 if (NULL != handle->list_it)
289 { 293 {
290 GNUNET_PEERINFO_iterate_cancel(handle->list_it); 294 GNUNET_PEERINFO_iterate_cancel (handle->list_it);
291 handle->list_it = NULL; 295 handle->list_it = NULL;
292 } 296 }
293 if (NULL != handle->peerinfo_handle) 297 if (NULL != handle->peerinfo_handle)
294 { 298 {
295 GNUNET_PEERINFO_disconnect(handle->peerinfo_handle); 299 GNUNET_PEERINFO_disconnect (handle->peerinfo_handle);
296 handle->peerinfo_handle = NULL; 300 handle->peerinfo_handle = NULL;
297 } 301 }
298 302
299 GNUNET_free(handle); 303 GNUNET_free (handle);
300} 304}
301 305
302 306
@@ -306,26 +310,26 @@ cleanup_handle(void *cls)
306 * @param cls the `struct RequestHandle` 310 * @param cls the `struct RequestHandle`
307 */ 311 */
308static void 312static void
309do_error(void *cls) 313do_error (void *cls)
310{ 314{
311 struct RequestHandle *handle = cls; 315 struct RequestHandle *handle = cls;
312 struct MHD_Response *resp; 316 struct MHD_Response *resp;
313 json_t *json_error = json_object(); 317 json_t *json_error = json_object ();
314 char *response; 318 char *response;
315 319
316 if (NULL == handle->emsg) 320 if (NULL == handle->emsg)
317 handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN); 321 handle->emsg = GNUNET_strdup (GNUNET_REST_PEERINFO_ERROR_UNKNOWN);
318 322
319 json_object_set_new(json_error, "error", json_string(handle->emsg)); 323 json_object_set_new (json_error, "error", json_string (handle->emsg));
320 324
321 if (0 == handle->response_code) 325 if (0 == handle->response_code)
322 handle->response_code = MHD_HTTP_OK; 326 handle->response_code = MHD_HTTP_OK;
323 response = json_dumps(json_error, 0); 327 response = json_dumps (json_error, 0);
324 resp = GNUNET_REST_create_response(response); 328 resp = GNUNET_REST_create_response (response);
325 handle->proc(handle->proc_cls, resp, handle->response_code); 329 handle->proc (handle->proc_cls, resp, handle->response_code);
326 json_decref(json_error); 330 json_decref (json_error);
327 GNUNET_free(response); 331 GNUNET_free (response);
328 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 332 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
329} 333}
330 334
331 335
@@ -335,26 +339,26 @@ do_error(void *cls)
335 * @param cls the `struct RequestHandle` 339 * @param cls the `struct RequestHandle`
336 */ 340 */
337static void 341static void
338peerinfo_list_finished(void *cls) 342peerinfo_list_finished (void *cls)
339{ 343{
340 struct RequestHandle *handle = cls; 344 struct RequestHandle *handle = cls;
341 char *result_str; 345 char *result_str;
342 struct MHD_Response *resp; 346 struct MHD_Response *resp;
343 347
344 if (NULL == handle->response) 348 if (NULL == handle->response)
345 { 349 {
346 handle->response_code = MHD_HTTP_NOT_FOUND; 350 handle->response_code = MHD_HTTP_NOT_FOUND;
347 handle->emsg = GNUNET_strdup("No peers found"); 351 handle->emsg = GNUNET_strdup ("No peers found");
348 GNUNET_SCHEDULER_add_now(&do_error, handle); 352 GNUNET_SCHEDULER_add_now (&do_error, handle);
349 return; 353 return;
350 } 354 }
351 355
352 result_str = json_dumps(handle->response, 0); 356 result_str = json_dumps (handle->response, 0);
353 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
354 resp = GNUNET_REST_create_response(result_str); 358 resp = GNUNET_REST_create_response (result_str);
355 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 359 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
356 GNUNET_free_non_null(result_str); 360 GNUNET_free_non_null (result_str);
357 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 361 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
358} 362}
359 363
360 364
@@ -367,16 +371,16 @@ peerinfo_list_finished(void *cls)
367 * @return #GNUNET_OK to keep the address and continue 371 * @return #GNUNET_OK to keep the address and continue
368 */ 372 */
369static int 373static int
370count_address(void *cls, 374count_address (void *cls,
371 const struct GNUNET_HELLO_Address *address, 375 const struct GNUNET_HELLO_Address *address,
372 struct GNUNET_TIME_Absolute expiration) 376 struct GNUNET_TIME_Absolute expiration)
373{ 377{
374 struct PrintContext *pc = cls; 378 struct PrintContext *pc = cls;
375 379
376 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) 380 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
377 { 381 {
378 return GNUNET_OK; /* ignore expired address */ 382 return GNUNET_OK; /* ignore expired address */
379 } 383 }
380 384
381 pc->off++; 385 pc->off++;
382 return GNUNET_OK; 386 return GNUNET_OK;
@@ -389,7 +393,7 @@ count_address(void *cls,
389 * @param pc printing context 393 * @param pc printing context
390 */ 394 */
391static void 395static void
392dump_pc(struct PrintContext *pc) 396dump_pc (struct PrintContext *pc)
393{ 397{
394 struct RequestHandle *handle; 398 struct RequestHandle *handle;
395 unsigned int i; 399 unsigned int i;
@@ -401,62 +405,63 @@ dump_pc(struct PrintContext *pc)
401 json_t *friend_and_peer_json; 405 json_t *friend_and_peer_json;
402 char *friend_and_peer; 406 char *friend_and_peer;
403 407
404 temp_array = json_array(); 408 temp_array = json_array ();
405 response_entry = json_object(); 409 response_entry = json_object ();
406 410
407 for (i = 0; i < pc->num_addresses; i++) 411 for (i = 0; i < pc->num_addresses; i++)
412 {
413 if (NULL != pc->address_list[i].result)
408 { 414 {
409 if (NULL != pc->address_list[i].result) 415 object = json_object ();
410 { 416 address = json_string (pc->address_list[i].result);
411 object = json_object(); 417 expires = json_string (
412 address = json_string(pc->address_list[i].result); 418 GNUNET_STRINGS_absolute_time_to_string (
413 expires = json_string( 419 pc->address_list[i].expiration));
414 GNUNET_STRINGS_absolute_time_to_string(pc->address_list[i].expiration)); 420 json_object_set (object, "address", address);
415 json_object_set(object, "address", address); 421 json_object_set (object, "expires", expires);
416 json_object_set(object, "expires", expires); 422
417 423 json_decref (address);
418 json_decref(address); 424 json_decref (expires);
419 json_decref(expires); 425
420 426 json_array_append (temp_array, object);
421 json_array_append(temp_array, object); 427 json_decref (object);
422 json_decref(object); 428 GNUNET_free (pc->address_list[i].result);
423 GNUNET_free(pc->address_list[i].result);
424 }
425 }
426
427 if (0 < json_array_size(temp_array))
428 {
429 GNUNET_asprintf(&friend_and_peer,
430 "%s%s",
431 (GNUNET_YES == pc->friend_only) ? "F2F:" : "",
432 GNUNET_i2s_full(&pc->peer));
433 friend_and_peer_json = json_string(friend_and_peer);
434 json_object_set(response_entry,
435 GNUNET_REST_PEERINFO_PEER,
436 friend_and_peer_json);
437 json_object_set(response_entry,
438 GNUNET_REST_PEERINFO_ARRAY,
439 temp_array);
440 json_array_append(pc->handle->response, response_entry);
441 json_decref(friend_and_peer_json);
442 GNUNET_free(friend_and_peer);
443 } 429 }
444 430 }
445 json_decref(temp_array); 431
446 json_decref(response_entry); 432 if (0 < json_array_size (temp_array))
447 433 {
448 GNUNET_free_non_null(pc->address_list); 434 GNUNET_asprintf (&friend_and_peer,
449 GNUNET_CONTAINER_DLL_remove(pc_head, 435 "%s%s",
450 pc_tail, 436 (GNUNET_YES == pc->friend_only) ? "F2F:" : "",
451 pc); 437 GNUNET_i2s_full (&pc->peer));
438 friend_and_peer_json = json_string (friend_and_peer);
439 json_object_set (response_entry,
440 GNUNET_REST_PEERINFO_PEER,
441 friend_and_peer_json);
442 json_object_set (response_entry,
443 GNUNET_REST_PEERINFO_ARRAY,
444 temp_array);
445 json_array_append (pc->handle->response, response_entry);
446 json_decref (friend_and_peer_json);
447 GNUNET_free (friend_and_peer);
448 }
449
450 json_decref (temp_array);
451 json_decref (response_entry);
452
453 GNUNET_free_non_null (pc->address_list);
454 GNUNET_CONTAINER_DLL_remove (pc_head,
455 pc_tail,
456 pc);
452 handle = pc->handle; 457 handle = pc->handle;
453 GNUNET_free(pc); 458 GNUNET_free (pc);
454 459
455 if ((NULL == pc_head) && 460 if ((NULL == pc_head) &&
456 (NULL == handle->list_it)) 461 (NULL == handle->list_it))
457 { 462 {
458 GNUNET_SCHEDULER_add_now(&peerinfo_list_finished, handle); 463 GNUNET_SCHEDULER_add_now (&peerinfo_list_finished, handle);
459 } 464 }
460} 465}
461 466
462 467
@@ -471,31 +476,31 @@ dump_pc(struct PrintContext *pc)
471 * if #GNUNET_SYSERR: address is invalid 476 * if #GNUNET_SYSERR: address is invalid
472 */ 477 */
473static void 478static void
474process_resolved_address(void *cls, 479process_resolved_address (void *cls,
475 const char *address, 480 const char *address,
476 int res) 481 int res)
477{ 482{
478 struct AddressRecord *ar = cls; 483 struct AddressRecord *ar = cls;
479 struct PrintContext *pc = ar->pc; 484 struct PrintContext *pc = ar->pc;
480 485
481 if (NULL != address) 486 if (NULL != address)
487 {
488 if (0 != strlen (address))
482 { 489 {
483 if (0 != strlen(address)) 490 if (NULL != ar->result)
484 { 491 GNUNET_free (ar->result);
485 if (NULL != ar->result) 492 ar->result = GNUNET_strdup (address);
486 GNUNET_free(ar->result);
487 ar->result = GNUNET_strdup(address);
488 }
489 return;
490 } 493 }
494 return;
495 }
491 ar->atsc = NULL; 496 ar->atsc = NULL;
492 if (GNUNET_SYSERR == res) 497 if (GNUNET_SYSERR == res)
493 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 498 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
494 _("Failure: Cannot convert address to string for peer `%s'\n"), 499 _ ("Failure: Cannot convert address to string for peer `%s'\n"),
495 GNUNET_i2s(&ar->pc->peer)); 500 GNUNET_i2s (&ar->pc->peer));
496 pc->num_addresses++; 501 pc->num_addresses++;
497 if (pc->num_addresses == pc->address_list_size) 502 if (pc->num_addresses == pc->address_list_size)
498 dump_pc(ar->pc); 503 dump_pc (ar->pc);
499} 504}
500 505
501 506
@@ -508,33 +513,33 @@ process_resolved_address(void *cls,
508 * @return #GNUNET_OK to keep the address and continue 513 * @return #GNUNET_OK to keep the address and continue
509 */ 514 */
510static int 515static int
511print_address(void *cls, 516print_address (void *cls,
512 const struct GNUNET_HELLO_Address *address, 517 const struct GNUNET_HELLO_Address *address,
513 struct GNUNET_TIME_Absolute expiration) 518 struct GNUNET_TIME_Absolute expiration)
514{ 519{
515 struct PrintContext *pc = cls; 520 struct PrintContext *pc = cls;
516 struct AddressRecord *ar; 521 struct AddressRecord *ar;
517 522
518 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) 523 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
519 { 524 {
520 return GNUNET_OK; /* ignore expired address */ 525 return GNUNET_OK; /* ignore expired address */
521 } 526 }
522 527
523 GNUNET_assert(0 < pc->off); 528 GNUNET_assert (0 < pc->off);
524 ar = &pc->address_list[--pc->off]; 529 ar = &pc->address_list[--pc->off];
525 ar->pc = pc; 530 ar->pc = pc;
526 ar->expiration = expiration; 531 ar->expiration = expiration;
527 GNUNET_asprintf(&ar->result, 532 GNUNET_asprintf (&ar->result,
528 "%s:%u:%u", 533 "%s:%u:%u",
529 address->transport_name, 534 address->transport_name,
530 address->address_length, 535 address->address_length,
531 address->local_info); 536 address->local_info);
532 ar->atsc = GNUNET_TRANSPORT_address_to_string(cfg, 537 ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
533 address, 538 address,
534 GNUNET_NO, 539 GNUNET_NO,
535 TIMEOUT, 540 TIMEOUT,
536 &process_resolved_address, 541 &process_resolved_address,
537 ar); 542 ar);
538 return GNUNET_OK; 543 return GNUNET_OK;
539} 544}
540 545
@@ -549,64 +554,64 @@ print_address(void *cls,
549 * @param err_msg message 554 * @param err_msg message
550 */ 555 */
551void 556void
552peerinfo_list_iteration(void *cls, 557peerinfo_list_iteration (void *cls,
553 const struct GNUNET_PeerIdentity *peer, 558 const struct GNUNET_PeerIdentity *peer,
554 const struct GNUNET_HELLO_Message *hello, 559 const struct GNUNET_HELLO_Message *hello,
555 const char *err_msg) 560 const char *err_msg)
556{ 561{
557 struct RequestHandle *handle = cls; 562 struct RequestHandle *handle = cls;
558 struct PrintContext *pc; 563 struct PrintContext *pc;
559 int friend_only; 564 int friend_only;
560 565
561 if (NULL == handle->response) 566 if (NULL == handle->response)
562 { 567 {
563 handle->response = json_array(); 568 handle->response = json_array ();
564 } 569 }
565 570
566 if (NULL == peer) 571 if (NULL == peer)
572 {
573 handle->list_it = NULL;
574 handle->emsg = GNUNET_strdup ("Error in communication with peerinfo");
575 if (NULL != err_msg)
567 { 576 {
568 handle->list_it = NULL; 577 GNUNET_free (handle->emsg);
569 handle->emsg = GNUNET_strdup("Error in communication with peerinfo"); 578 handle->emsg = GNUNET_strdup (err_msg);
570 if (NULL != err_msg) 579 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
571 {
572 GNUNET_free(handle->emsg);
573 handle->emsg = GNUNET_strdup(err_msg);
574 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
575 }
576 if (NULL == pc_head)
577 GNUNET_SCHEDULER_add_now(&do_error, handle);
578 return;
579 } 580 }
581 if (NULL == pc_head)
582 GNUNET_SCHEDULER_add_now (&do_error, handle);
583 return;
584 }
580 if (NULL == hello) 585 if (NULL == hello)
581 return; 586 return;
582 587
583 friend_only = GNUNET_NO; 588 friend_only = GNUNET_NO;
584 if (NULL != hello) 589 if (NULL != hello)
585 friend_only = GNUNET_HELLO_is_friend_only(hello); 590 friend_only = GNUNET_HELLO_is_friend_only (hello);
586 591
587 pc = GNUNET_new(struct PrintContext); 592 pc = GNUNET_new (struct PrintContext);
588 GNUNET_CONTAINER_DLL_insert(pc_head, 593 GNUNET_CONTAINER_DLL_insert (pc_head,
589 pc_tail, 594 pc_tail,
590 pc); 595 pc);
591 pc->peer = *peer; 596 pc->peer = *peer;
592 pc->friend_only = friend_only; 597 pc->friend_only = friend_only;
593 pc->handle = handle; 598 pc->handle = handle;
594 GNUNET_HELLO_iterate_addresses(hello, 599 GNUNET_HELLO_iterate_addresses (hello,
595 GNUNET_NO, 600 GNUNET_NO,
596 &count_address, 601 &count_address,
597 pc); 602 pc);
598 if (0 == pc->off) 603 if (0 == pc->off)
599 { 604 {
600 dump_pc(pc); 605 dump_pc (pc);
601 return; 606 return;
602 } 607 }
603 pc->address_list_size = pc->off; 608 pc->address_list_size = pc->off;
604 pc->address_list = GNUNET_malloc( 609 pc->address_list = GNUNET_malloc (
605 sizeof(struct AddressRecord) * pc->off); 610 sizeof(struct AddressRecord) * pc->off);
606 GNUNET_HELLO_iterate_addresses(hello, 611 GNUNET_HELLO_iterate_addresses (hello,
607 GNUNET_NO, 612 GNUNET_NO,
608 &print_address, 613 &print_address,
609 pc); 614 pc);
610} 615}
611 616
612/** 617/**
@@ -617,50 +622,50 @@ peerinfo_list_iteration(void *cls,
617 * @param cls the RequestHandle 622 * @param cls the RequestHandle
618 */ 623 */
619void 624void
620peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, 625peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle,
621 const char* url, 626 const char*url,
622 void *cls) 627 void *cls)
623{ 628{
624 struct RequestHandle *handle = cls; 629 struct RequestHandle *handle = cls;
625 struct GNUNET_HashCode key; 630 struct GNUNET_HashCode key;
626 const struct GNUNET_PeerIdentity *specific_peer; 631 const struct GNUNET_PeerIdentity *specific_peer;
627 //GNUNET_PEER_Id peer_id; 632 // GNUNET_PEER_Id peer_id;
628 int include_friend_only; 633 int include_friend_only;
629 char* include_friend_only_str; 634 char*include_friend_only_str;
630 635
631 include_friend_only = GNUNET_NO; 636 include_friend_only = GNUNET_NO;
632 GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_FRIEND, 637 GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND,
633 strlen(GNUNET_REST_PEERINFO_FRIEND), 638 strlen (GNUNET_REST_PEERINFO_FRIEND),
634 &key); 639 &key);
635 if (GNUNET_YES 640 if (GNUNET_YES
636 == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, 641 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
637 &key)) 642 &key))
643 {
644 include_friend_only_str = GNUNET_CONTAINER_multihashmap_get (
645 con_handle->url_param_map, &key);
646 if (0 == strcmp (include_friend_only_str, "yes"))
638 { 647 {
639 include_friend_only_str = GNUNET_CONTAINER_multihashmap_get( 648 include_friend_only = GNUNET_YES;
640 con_handle->url_param_map, &key);
641 if (0 == strcmp(include_friend_only_str, "yes"))
642 {
643 include_friend_only = GNUNET_YES;
644 }
645 } 649 }
650 }
646 651
647 specific_peer = NULL; 652 specific_peer = NULL;
648 GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_PEER, 653 GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER,
649 strlen(GNUNET_REST_PEERINFO_PEER), 654 strlen (GNUNET_REST_PEERINFO_PEER),
650 &key); 655 &key);
651 if (GNUNET_YES 656 if (GNUNET_YES
652 == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, 657 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
653 &key)) 658 &key))
654 { 659 {
655 //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); 660 // peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
656 //specific_peer = GNUNET_PEER_resolve2(peer_id); 661 // specific_peer = GNUNET_PEER_resolve2(peer_id);
657 } 662 }
658 663
659 handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, 664 handle->list_it = GNUNET_PEERINFO_iterate (handle->peerinfo_handle,
660 include_friend_only, 665 include_friend_only,
661 specific_peer, 666 specific_peer,
662 &peerinfo_list_iteration, 667 &peerinfo_list_iteration,
663 handle); 668 handle);
664} 669}
665 670
666 671
@@ -673,20 +678,20 @@ peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle,
673 * @param cls the RequestHandle 678 * @param cls the RequestHandle
674 */ 679 */
675static void 680static void
676options_cont(struct GNUNET_REST_RequestHandle *con_handle, 681options_cont (struct GNUNET_REST_RequestHandle *con_handle,
677 const char* url, 682 const char*url,
678 void *cls) 683 void *cls)
679{ 684{
680 struct MHD_Response *resp; 685 struct MHD_Response *resp;
681 struct RequestHandle *handle = cls; 686 struct RequestHandle *handle = cls;
682 687
683 //independent of path return all options 688 // independent of path return all options
684 resp = GNUNET_REST_create_response(NULL); 689 resp = GNUNET_REST_create_response (NULL);
685 MHD_add_response_header(resp, 690 MHD_add_response_header (resp,
686 "Access-Control-Allow-Methods", 691 "Access-Control-Allow-Methods",
687 allow_methods); 692 allow_methods);
688 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 693 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
689 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 694 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
690 return; 695 return;
691} 696}
692 697
@@ -697,7 +702,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle,
697 * @param handle the request handle 702 * @param handle the request handle
698 */ 703 */
699static void 704static void
700init_cont(struct RequestHandle *handle) 705init_cont (struct RequestHandle *handle)
701{ 706{
702 struct GNUNET_REST_RequestHandlerError err; 707 struct GNUNET_REST_RequestHandlerError err;
703 static const struct GNUNET_REST_RequestHandler handlers[] = { 708 static const struct GNUNET_REST_RequestHandler handlers[] = {
@@ -706,14 +711,14 @@ init_cont(struct RequestHandle *handle)
706 GNUNET_REST_HANDLER_END 711 GNUNET_REST_HANDLER_END
707 }; 712 };
708 713
709 if (GNUNET_NO == GNUNET_REST_handle_request(handle->rest_handle, 714 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle,
710 handlers, 715 handlers,
711 &err, 716 &err,
712 handle)) 717 handle))
713 { 718 {
714 handle->response_code = err.error_code; 719 handle->response_code = err.error_code;
715 GNUNET_SCHEDULER_add_now(&do_error, handle); 720 GNUNET_SCHEDULER_add_now (&do_error, handle);
716 } 721 }
717} 722}
718 723
719 724
@@ -729,30 +734,31 @@ init_cont(struct RequestHandle *handle)
729 * @return GNUNET_OK if request accepted 734 * @return GNUNET_OK if request accepted
730 */ 735 */
731static void 736static void
732rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, 737rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
733 GNUNET_REST_ResultProcessor proc, 738 GNUNET_REST_ResultProcessor proc,
734 void *proc_cls) 739 void *proc_cls)
735{ 740{
736 struct RequestHandle *handle = GNUNET_new(struct RequestHandle); 741 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
737 742
738 handle->response_code = 0; 743 handle->response_code = 0;
739 handle->timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60); 744 handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
745 60);
740 handle->proc_cls = proc_cls; 746 handle->proc_cls = proc_cls;
741 handle->proc = proc; 747 handle->proc = proc;
742 handle->rest_handle = rest_handle; 748 handle->rest_handle = rest_handle;
743 749
744 handle->url = GNUNET_strdup(rest_handle->url); 750 handle->url = GNUNET_strdup (rest_handle->url);
745 if (handle->url[strlen(handle->url) - 1] == '/') 751 if (handle->url[strlen (handle->url) - 1] == '/')
746 handle->url[strlen(handle->url) - 1] = '\0'; 752 handle->url[strlen (handle->url) - 1] = '\0';
747 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
748 handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg); 754 handle->peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
749 init_cont(handle); 755 init_cont (handle);
750 handle->timeout_task = 756 handle->timeout_task =
751 GNUNET_SCHEDULER_add_delayed(handle->timeout, 757 GNUNET_SCHEDULER_add_delayed (handle->timeout,
752 &do_error, 758 &do_error,
753 handle); 759 handle);
754 760
755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
756} 762}
757 763
758 764
@@ -763,7 +769,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
763 * @return NULL on error, otherwise the plugin context 769 * @return NULL on error, otherwise the plugin context
764 */ 770 */
765void * 771void *
766libgnunet_plugin_rest_peerinfo_init(void *cls) 772libgnunet_plugin_rest_peerinfo_init (void *cls)
767{ 773{
768 static struct Plugin plugin; 774 static struct Plugin plugin;
769 struct GNUNET_REST_Plugin *api; 775 struct GNUNET_REST_Plugin *api;
@@ -771,22 +777,22 @@ libgnunet_plugin_rest_peerinfo_init(void *cls)
771 cfg = cls; 777 cfg = cls;
772 if (NULL != plugin.cfg) 778 if (NULL != plugin.cfg)
773 return NULL; /* can only initialize once! */ 779 return NULL; /* can only initialize once! */
774 memset(&plugin, 0, sizeof(struct Plugin)); 780 memset (&plugin, 0, sizeof(struct Plugin));
775 plugin.cfg = cfg; 781 plugin.cfg = cfg;
776 api = GNUNET_new(struct GNUNET_REST_Plugin); 782 api = GNUNET_new (struct GNUNET_REST_Plugin);
777 api->cls = &plugin; 783 api->cls = &plugin;
778 api->name = GNUNET_REST_API_NS_PEERINFO; 784 api->name = GNUNET_REST_API_NS_PEERINFO;
779 api->process_request = &rest_process_request; 785 api->process_request = &rest_process_request;
780 GNUNET_asprintf(&allow_methods, 786 GNUNET_asprintf (&allow_methods,
781 "%s, %s, %s, %s, %s", 787 "%s, %s, %s, %s, %s",
782 MHD_HTTP_METHOD_GET, 788 MHD_HTTP_METHOD_GET,
783 MHD_HTTP_METHOD_POST, 789 MHD_HTTP_METHOD_POST,
784 MHD_HTTP_METHOD_PUT, 790 MHD_HTTP_METHOD_PUT,
785 MHD_HTTP_METHOD_DELETE, 791 MHD_HTTP_METHOD_DELETE,
786 MHD_HTTP_METHOD_OPTIONS); 792 MHD_HTTP_METHOD_OPTIONS);
787 793
788 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 _("Peerinfo REST API initialized\n")); 795 _ ("Peerinfo REST API initialized\n"));
790 return api; 796 return api;
791} 797}
792 798
@@ -798,19 +804,18 @@ libgnunet_plugin_rest_peerinfo_init(void *cls)
798 * @return always NULL 804 * @return always NULL
799 */ 805 */
800void * 806void *
801libgnunet_plugin_rest_peerinfo_done(void *cls) 807libgnunet_plugin_rest_peerinfo_done (void *cls)
802{ 808{
803 struct GNUNET_REST_Plugin *api = cls; 809 struct GNUNET_REST_Plugin *api = cls;
804 struct Plugin *plugin = api->cls; 810 struct Plugin *plugin = api->cls;
805 811
806 plugin->cfg = NULL; 812 plugin->cfg = NULL;
807 813
808 GNUNET_free_non_null(allow_methods); 814 GNUNET_free_non_null (allow_methods);
809 GNUNET_free(api); 815 GNUNET_free (api);
810 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
811 "Peerinfo REST plugin is finished\n"); 817 "Peerinfo REST plugin is finished\n");
812 return NULL; 818 return NULL;
813} 819}
814 820
815/* end of plugin_rest_peerinfo.c */ 821/* end of plugin_rest_peerinfo.c */
816