From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/peerinfo-tool/gnunet-peerinfo.c | 664 ++++++++++++++-------------- src/peerinfo-tool/gnunet-peerinfo_plugins.c | 111 ++--- src/peerinfo-tool/gnunet-peerinfo_plugins.h | 6 +- src/peerinfo-tool/plugin_rest_peerinfo.c | 541 +++++++++++----------- 4 files changed, 665 insertions(+), 657 deletions(-) (limited to 'src/peerinfo-tool') 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 @@ /** * How long until we time out during address lookup? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** * Structure we use to collect printable address information. @@ -45,7 +45,8 @@ struct PrintContext; /** * Record we keep for each printable address. */ -struct AddressRecord { +struct AddressRecord +{ /** * Current address-to-string context (if active, otherwise NULL). */ @@ -71,7 +72,8 @@ struct AddressRecord { /** * Structure we use to collect printable address information. */ -struct PrintContext { +struct PrintContext +{ /** * Kept in DLL. */ @@ -217,7 +219,7 @@ static struct GNUNET_HELLO_Message *my_hello; * @param cls unused */ static void -state_machine(void *cls); +state_machine (void *cls); /* ********************* 'get_info' ******************* */ @@ -228,30 +230,30 @@ state_machine(void *cls); * @param pc printing context */ static void -dump_pc(struct PrintContext *pc) +dump_pc (struct PrintContext *pc) { unsigned int i; - printf(_("%sPeer `%s'\n"), - (GNUNET_YES == pc->friend_only) ? "F2F: " : "", - GNUNET_i2s_full(&pc->peer)); + printf (_ ("%sPeer `%s'\n"), + (GNUNET_YES == pc->friend_only) ? "F2F: " : "", + GNUNET_i2s_full (&pc->peer)); for (i = 0; i < pc->num_addresses; i++) + { + if (NULL != pc->address_list[i].result) { - if (NULL != pc->address_list[i].result) - { - printf(_("\tExpires: %s \t %s\n"), - GNUNET_STRINGS_absolute_time_to_string( - pc->address_list[i].expiration), - pc->address_list[i].result); - GNUNET_free(pc->address_list[i].result); - } + printf (_ ("\tExpires: %s \t %s\n"), + GNUNET_STRINGS_absolute_time_to_string ( + pc->address_list[i].expiration), + pc->address_list[i].result); + GNUNET_free (pc->address_list[i].result); } - printf("\n"); - GNUNET_free_non_null(pc->address_list); - GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc); - GNUNET_free(pc); + } + printf ("\n"); + GNUNET_free_non_null (pc->address_list); + GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); + GNUNET_free (pc); if ((NULL == pc_head) && (NULL == pic)) - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); } @@ -269,29 +271,29 @@ dump_pc(struct PrintContext *pc) * if #GNUNET_SYSERR: address is invalid */ static void -process_resolved_address(void *cls, const char *address, int res) +process_resolved_address (void *cls, const char *address, int res) { struct AddressRecord *ar = cls; struct PrintContext *pc = ar->pc; if (NULL != address) + { + if (0 != strlen (address)) { - if (0 != strlen(address)) - { - if (NULL != ar->result) - GNUNET_free(ar->result); - ar->result = GNUNET_strdup(address); - } - return; + if (NULL != ar->result) + GNUNET_free (ar->result); + ar->result = GNUNET_strdup (address); } + return; + } ar->atsc = NULL; if (GNUNET_SYSERR == res) - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Failure: Cannot convert address to string for peer `%s'\n"), - GNUNET_i2s(&ar->pc->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Failure: Cannot convert address to string for peer `%s'\n"), + GNUNET_i2s (&ar->pc->peer)); pc->num_addresses++; if (pc->num_addresses == pc->address_list_size) - dump_pc(pc); + dump_pc (pc); } @@ -304,9 +306,9 @@ process_resolved_address(void *cls, const char *address, int res) * @return #GNUNET_OK to keep the address and continue */ static int -count_address(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +count_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; @@ -324,28 +326,28 @@ count_address(void *cls, * @return #GNUNET_OK to keep the address and continue */ static int -print_address(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +print_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; struct AddressRecord *ar; - GNUNET_assert(0 < pc->off); + GNUNET_assert (0 < pc->off); ar = &pc->address_list[--pc->off]; ar->pc = pc; ar->expiration = expiration; - GNUNET_asprintf(&ar->result, - "%s:%u:%u", - address->transport_name, - address->address_length, - address->local_info); - ar->atsc = GNUNET_TRANSPORT_address_to_string(cfg, - address, - no_resolve, - TIMEOUT, - &process_resolved_address, - ar); + GNUNET_asprintf (&ar->result, + "%s:%u:%u", + address->transport_name, + address->address_length, + address->local_info); + ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, + address, + no_resolve, + TIMEOUT, + &process_resolved_address, + ar); return GNUNET_OK; } @@ -360,50 +362,50 @@ print_address(void *cls, * @param err_msg error message */ static void -print_peer_info(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) +print_peer_info (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct PrintContext *pc; int friend_only; if (NULL == peer) + { + pic = NULL; /* end of iteration */ + if (NULL != err_msg) { - pic = NULL; /* end of iteration */ - if (NULL != err_msg) - { - fprintf(stderr, - _("Error in communication with PEERINFO service: %s\n"), - err_msg); - } - if (NULL == pc_head) - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - return; + fprintf (stderr, + _ ("Error in communication with PEERINFO service: %s\n"), + err_msg); } + if (NULL == pc_head) + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + return; + } friend_only = GNUNET_NO; if (NULL != hello) - friend_only = GNUNET_HELLO_is_friend_only(hello); + friend_only = GNUNET_HELLO_is_friend_only (hello); if ((GNUNET_YES == be_quiet) || (NULL == hello)) - { - printf("%s%s\n", - (GNUNET_YES == friend_only) ? "F2F: " : "", - GNUNET_i2s_full(peer)); - return; - } - pc = GNUNET_new(struct PrintContext); - GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); + { + printf ("%s%s\n", + (GNUNET_YES == friend_only) ? "F2F: " : "", + GNUNET_i2s_full (peer)); + return; + } + pc = GNUNET_new (struct PrintContext); + GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); pc->peer = *peer; pc->friend_only = friend_only; - GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &count_address, pc); + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc); if (0 == pc->off) - { - dump_pc(pc); - return; - } + { + dump_pc (pc); + return; + } pc->address_list_size = pc->off; - pc->address_list = GNUNET_malloc(sizeof(struct AddressRecord) * pc->off); - GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &print_address, pc); + pc->address_list = GNUNET_malloc (sizeof(struct AddressRecord) * pc->off); + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc); } /* ************************* DUMP Hello ************************** */ @@ -417,9 +419,9 @@ print_peer_info(void *cls, * @return #GNUNET_OK */ static int -count_addr(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +count_addr (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { int *c = cls; @@ -437,50 +439,50 @@ count_addr(void *cls, * @param err_msg error message */ static void -dump_my_hello() +dump_my_hello () { unsigned int size; unsigned int c_addr; - size = GNUNET_HELLO_size(my_hello); + size = GNUNET_HELLO_size (my_hello); if (0 == size) - { - fprintf(stderr, _("Failure: Received invalid %s\n"), "HELLO"); - return; - } - if (GNUNET_SYSERR == GNUNET_DISK_fn_write(dump_hello, - my_hello, - size, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ)) - { - fprintf(stderr, - _("Failed to write HELLO with %u bytes to file `%s'\n"), - size, - dump_hello); - if (0 != unlink(dump_hello)) - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | - GNUNET_ERROR_TYPE_BULK, - "unlink", - dump_hello); - } + { + fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO"); + return; + } + if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, + my_hello, + size, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ)) + { + fprintf (stderr, + _ ("Failed to write HELLO with %u bytes to file `%s'\n"), + size, + dump_hello); + if (0 != unlink (dump_hello)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING + | GNUNET_ERROR_TYPE_BULK, + "unlink", + dump_hello); + } c_addr = 0; - GNUNET_HELLO_iterate_addresses(my_hello, GNUNET_NO, count_addr, &c_addr); - - if (!be_quiet) - { - fprintf( - stderr, - _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"), - (GNUNET_YES == GNUNET_HELLO_is_friend_only(my_hello)) ? "friend-only" - : "public", - c_addr, - size, - dump_hello); - } - GNUNET_free(dump_hello); + GNUNET_HELLO_iterate_addresses (my_hello, GNUNET_NO, count_addr, &c_addr); + + if (! be_quiet) + { + fprintf ( + stderr, + _ ("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"), + (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only" + : "public", + c_addr, + size, + dump_hello); + } + GNUNET_free (dump_hello); dump_hello = NULL; } @@ -497,32 +499,32 @@ dump_my_hello() * @param err_msg error message */ static void -print_my_uri(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) +print_my_uri (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { char *uri; if (NULL == peer) - { - pic = NULL; - if (NULL != err_msg) - fprintf(stderr, - _("Error in communication with PEERINFO service: %s\n"), - err_msg); - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - return; - } + { + pic = NULL; + if (NULL != err_msg) + fprintf (stderr, + _ ("Error in communication with PEERINFO service: %s\n"), + err_msg); + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + return; + } if (NULL == hello) return; - uri = GNUNET_HELLO_compose_uri(hello, &GPI_plugins_find); + uri = GNUNET_HELLO_compose_uri (hello, &GPI_plugins_find); if (NULL != uri) - { - printf("%s\n", (const char *)uri); - GNUNET_free(uri); - } + { + printf ("%s\n", (const char *) uri); + GNUNET_free (uri); + } } @@ -535,10 +537,10 @@ print_my_uri(void *cls, * @param cls closure, NULL */ static void -add_continuation(void *cls) +add_continuation (void *cls) { ac = NULL; - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); } @@ -552,24 +554,24 @@ add_continuation(void *cls) * #GNUNET_NO on other errors */ static int -parse_hello_uri(const char *put_uri) +parse_hello_uri (const char *put_uri) { struct GNUNET_HELLO_Message *hello = NULL; - int ret = GNUNET_HELLO_parse_uri(put_uri, - &my_peer_identity.public_key, - &hello, - &GPI_plugins_find); + int ret = GNUNET_HELLO_parse_uri (put_uri, + &my_peer_identity.public_key, + &hello, + &GPI_plugins_find); if (NULL != hello) - { - /* WARNING: this adds the address from URI WITHOUT verification! */ - if (GNUNET_OK == ret) - ac = GNUNET_PEERINFO_add_peer(peerinfo, hello, &add_continuation, NULL); - else - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - GNUNET_free(hello); - } + { + /* WARNING: this adds the address from URI WITHOUT verification! */ + if (GNUNET_OK == ret) + ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL); + else + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + GNUNET_free (hello); + } return ret; } @@ -584,59 +586,59 @@ parse_hello_uri(const char *put_uri) * @param cls unused */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { struct PrintContext *pc; struct AddressRecord *ar; unsigned int i; if (NULL != ac) - { - GNUNET_MQ_send_cancel(ac); - ac = NULL; - } + { + GNUNET_MQ_send_cancel (ac); + ac = NULL; + } if (NULL != tt) - { - GNUNET_SCHEDULER_cancel(tt); - tt = NULL; - } + { + GNUNET_SCHEDULER_cancel (tt); + tt = NULL; + } if (NULL != pic) - { - GNUNET_PEERINFO_iterate_cancel(pic); - pic = NULL; - } + { + GNUNET_PEERINFO_iterate_cancel (pic); + pic = NULL; + } if (NULL != gh) - { - GNUNET_TRANSPORT_hello_get_cancel(gh); - gh = NULL; - } + { + GNUNET_TRANSPORT_hello_get_cancel (gh); + gh = NULL; + } while (NULL != (pc = pc_head)) + { + GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); + for (i = 0; i < pc->address_list_size; i++) { - GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc); - for (i = 0; i < pc->address_list_size; i++) - { - ar = &pc->address_list[i]; - GNUNET_free_non_null(ar->result); - if (NULL != ar->atsc) - { - GNUNET_TRANSPORT_address_to_string_cancel(ar->atsc); - ar->atsc = NULL; - } - } - GNUNET_free_non_null(pc->address_list); - GNUNET_free(pc); + ar = &pc->address_list[i]; + GNUNET_free_non_null (ar->result); + if (NULL != ar->atsc) + { + GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc); + ar->atsc = NULL; + } } - GPI_plugins_unload(); + GNUNET_free_non_null (pc->address_list); + GNUNET_free (pc); + } + GPI_plugins_unload (); if (NULL != peerinfo) - { - GNUNET_PEERINFO_disconnect(peerinfo); - peerinfo = NULL; - } + { + GNUNET_PEERINFO_disconnect (peerinfo); + peerinfo = NULL; + } if (NULL != my_hello) - { - GNUNET_free(my_hello); - my_hello = NULL; - } + { + GNUNET_free (my_hello); + my_hello = NULL; + } } @@ -648,22 +650,22 @@ shutdown_task(void *cls) * @param hello the HELLO message */ static void -hello_callback(void *cls, const struct GNUNET_MessageHeader *hello) +hello_callback (void *cls, const struct GNUNET_MessageHeader *hello) { if (NULL == hello) - { - fprintf(stderr, "Failed to get my own HELLO from this peer!\n"); - GNUNET_SCHEDULER_shutdown(); - return; - } - my_hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(hello); - GNUNET_assert(GNUNET_OK == - GNUNET_HELLO_get_id(my_hello, &my_peer_identity)); - GNUNET_TRANSPORT_hello_get_cancel(gh); + { + fprintf (stderr, "Failed to get my own HELLO from this peer!\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello); + GNUNET_assert (GNUNET_OK == + GNUNET_HELLO_get_id (my_hello, &my_peer_identity)); + GNUNET_TRANSPORT_hello_get_cancel (gh); gh = NULL; if (NULL != dump_hello) - dump_my_hello(); - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); + dump_my_hello (); + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); } @@ -676,41 +678,41 @@ hello_callback(void *cls, const struct GNUNET_MessageHeader *hello) * @param c configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { cfg = c; if ((NULL != args[0]) && (NULL == put_uri) && - (args[0] == strcasestr(args[0], "gnunet://hello/"))) - { - put_uri = GNUNET_strdup(args[0]); - args++; - } + (args[0] == strcasestr (args[0], "gnunet://hello/"))) + { + put_uri = GNUNET_strdup (args[0]); + args++; + } if (NULL != args[0]) - { - fprintf(stderr, _("Invalid command line argument `%s'\n"), args[0]); - return; - } - if (NULL == (peerinfo = GNUNET_PEERINFO_connect(cfg))) - { - fprintf(stderr, "%s", "Could not access PEERINFO service. Exiting.\n"); - return; - } + { + fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); + return; + } + if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg))) + { + fprintf (stderr, "%s", "Could not access PEERINFO service. Exiting.\n"); + return; + } if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) || (NULL != dump_hello)) - { - gh = GNUNET_TRANSPORT_hello_get(cfg, - GNUNET_TRANSPORT_AC_ANY, - &hello_callback, - NULL); - } + { + gh = GNUNET_TRANSPORT_hello_get (cfg, + GNUNET_TRANSPORT_AC_ANY, + &hello_callback, + NULL); + } else - { - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - } - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + { + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + } + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } @@ -721,61 +723,61 @@ run(void *cls, * @param cls unused */ static void -state_machine(void *cls) +state_machine (void *cls) { tt = NULL; if (NULL != put_uri) + { + GPI_plugins_load (cfg); + if (GNUNET_SYSERR == parse_hello_uri (put_uri)) { - GPI_plugins_load(cfg); - if (GNUNET_SYSERR == parse_hello_uri(put_uri)) - { - fprintf(stderr, _("Invalid URI `%s'\n"), put_uri); - GNUNET_SCHEDULER_shutdown(); - } - GNUNET_free(put_uri); - put_uri = NULL; + fprintf (stderr, _ ("Invalid URI `%s'\n"), put_uri); + GNUNET_SCHEDULER_shutdown (); } + GNUNET_free (put_uri); + put_uri = NULL; + } else if (GNUNET_YES == get_info) - { - get_info = GNUNET_NO; - GPI_plugins_load(cfg); - pic = GNUNET_PEERINFO_iterate(peerinfo, - include_friend_only, - NULL, - &print_peer_info, - NULL); - } + { + get_info = GNUNET_NO; + GPI_plugins_load (cfg); + pic = GNUNET_PEERINFO_iterate (peerinfo, + include_friend_only, + NULL, + &print_peer_info, + NULL); + } else if (GNUNET_YES == get_self) - { - get_self = GNUNET_NO; - if (be_quiet) - printf("%s\n", GNUNET_i2s_full(&my_peer_identity)); - else - printf(_("I am peer `%s'.\n"), GNUNET_i2s_full(&my_peer_identity)); - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - } + { + get_self = GNUNET_NO; + if (be_quiet) + printf ("%s\n", GNUNET_i2s_full (&my_peer_identity)); + else + printf (_ ("I am peer `%s'.\n"), GNUNET_i2s_full (&my_peer_identity)); + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + } else if (GNUNET_YES == get_uri) - { - GPI_plugins_load(cfg); - pic = GNUNET_PEERINFO_iterate(peerinfo, - include_friend_only, - &my_peer_identity, - &print_my_uri, - NULL); - get_uri = GNUNET_NO; - } + { + GPI_plugins_load (cfg); + pic = GNUNET_PEERINFO_iterate (peerinfo, + include_friend_only, + &my_peer_identity, + &print_my_uri, + NULL); + get_uri = GNUNET_NO; + } else if (GNUNET_YES == default_operation) - { - /* default operation list all */ - default_operation = GNUNET_NO; - get_info = GNUNET_YES; - tt = GNUNET_SCHEDULER_add_now(&state_machine, NULL); - } + { + /* default operation list all */ + default_operation = GNUNET_NO; + get_info = GNUNET_YES; + tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); + } else - { - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_SCHEDULER_shutdown (); + } default_operation = GNUNET_NO; } @@ -788,71 +790,71 @@ state_machine(void *cls) * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_option_flag('n', - "numeric", - gettext_noop("don't resolve host names"), - &no_resolve), - - GNUNET_GETOPT_option_flag('q', - "quiet", - gettext_noop( - "output only the identity strings"), - &be_quiet), - GNUNET_GETOPT_option_flag('f', - "friends", - gettext_noop( - "include friend-only information"), - &include_friend_only), - - GNUNET_GETOPT_option_flag('s', - "self", - gettext_noop("output our own identity only"), - &get_self), - - GNUNET_GETOPT_option_flag('i', - "info", - gettext_noop("list all known peers"), - &get_info), - - GNUNET_GETOPT_option_string('d', - "dump-hello", - NULL, - gettext_noop("dump hello to file"), - &dump_hello), - - GNUNET_GETOPT_option_flag('g', - "get-hello", - gettext_noop("also output HELLO uri(s)"), - &get_uri), - - GNUNET_GETOPT_option_string('p', - "put-hello", - "HELLO", - gettext_noop( - "add given HELLO uri to the database"), - &put_uri), + { GNUNET_GETOPT_option_flag ('n', + "numeric", + gettext_noop ("don't resolve host names"), + &no_resolve), + + GNUNET_GETOPT_option_flag ('q', + "quiet", + gettext_noop ( + "output only the identity strings"), + &be_quiet), + GNUNET_GETOPT_option_flag ('f', + "friends", + gettext_noop ( + "include friend-only information"), + &include_friend_only), + + GNUNET_GETOPT_option_flag ('s', + "self", + gettext_noop ("output our own identity only"), + &get_self), + + GNUNET_GETOPT_option_flag ('i', + "info", + gettext_noop ("list all known peers"), + &get_info), + + GNUNET_GETOPT_option_string ('d', + "dump-hello", + NULL, + gettext_noop ("dump hello to file"), + &dump_hello), + + GNUNET_GETOPT_option_flag ('g', + "get-hello", + gettext_noop ("also output HELLO uri(s)"), + &get_uri), + + GNUNET_GETOPT_option_string ('p', + "put-hello", + "HELLO", + gettext_noop ( + "add given HELLO uri to the database"), + &put_uri), GNUNET_GETOPT_OPTION_END }; int ret; default_operation = GNUNET_YES; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-peerinfo", - gettext_noop("Print information about peers."), - options, - &run, - NULL)) + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-peerinfo", + gettext_noop ("Print information about peers."), + options, + &run, + NULL)) ? 0 : 1; - GNUNET_free((void *)argv); + GNUNET_free ((void *) argv); return ret; } 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 @@ /** * Entry in doubly-linked list of all of our plugins. */ -struct TransportPlugin { +struct TransportPlugin +{ /** * This is a doubly-linked list. */ @@ -86,7 +87,7 @@ static struct TransportPlugin *plugins_tail; * @param cfg configuration to use */ void -GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg) +GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TransportPlugin *plug; struct TransportPlugin *next; @@ -97,41 +98,41 @@ GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg) if (NULL != plugins_head) return; /* already loaded */ if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string(cfg, "TRANSPORT", "PLUGINS", - &plugs)) + GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS", + &plugs)) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"), - plugs); - for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"), - pos); - GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", pos); - plug = GNUNET_new(struct TransportPlugin); - plug->short_name = GNUNET_strdup(pos); - plug->lib_name = libname; - plug->env.cfg = cfg; - plug->env.cls = plug->short_name; - GNUNET_CONTAINER_DLL_insert(plugins_head, plugins_tail, plug); - } - GNUNET_free(plugs); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Starting transport plugins `%s'\n"), + plugs); + for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' transport plugin\n"), + pos); + GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos); + plug = GNUNET_new (struct TransportPlugin); + plug->short_name = GNUNET_strdup (pos); + plug->lib_name = libname; + plug->env.cfg = cfg; + plug->env.cls = plug->short_name; + GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); + } + GNUNET_free (plugs); next = plugins_head; while (next != NULL) + { + plug = next; + next = plug->next; + plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env); + if (plug->api == NULL) { - plug = next; - next = plug->next; - plug->api = GNUNET_PLUGIN_load(plug->lib_name, &plug->env); - if (plug->api == NULL) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to load transport plugin for `%s'\n"), - plug->lib_name); - GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); - GNUNET_free(plug->short_name); - GNUNET_free(plug->lib_name); - GNUNET_free(plug); - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to load transport plugin for `%s'\n"), + plug->lib_name); + GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); + GNUNET_free (plug->short_name); + GNUNET_free (plug->lib_name); + GNUNET_free (plug); } + } } @@ -139,18 +140,18 @@ GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg) * Unload all plugins */ void -GPI_plugins_unload() +GPI_plugins_unload () { struct TransportPlugin *plug; while (NULL != (plug = plugins_head)) - { - GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); - GNUNET_free(plug->lib_name); - GNUNET_free(plug->short_name); - GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); - GNUNET_free(plug); - } + { + GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); + GNUNET_free (plug->lib_name); + GNUNET_free (plug->short_name); + GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); + GNUNET_free (plug); + } } @@ -161,32 +162,32 @@ GPI_plugins_unload() * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GPI_plugins_find(const char *name) +GPI_plugins_find (const char *name) { struct TransportPlugin *head = plugins_head; - char *stripped = GNUNET_strdup(name); + char *stripped = GNUNET_strdup (name); char *head_stripped; - char *sep = strchr(stripped, '_'); + char *sep = strchr (stripped, '_'); if (NULL != sep) sep[0] = '\0'; while (head != NULL) + { + head_stripped = GNUNET_strdup (head->short_name); + char *head_sep = strchr (head_stripped, '_'); + if (NULL != head_sep) + head_sep[0] = '\0'; + if (0 == strcmp (head_stripped, stripped)) { - head_stripped = GNUNET_strdup(head->short_name); - char *head_sep = strchr(head_stripped, '_'); - if (NULL != head_sep) - head_sep[0] = '\0'; - if (0 == strcmp(head_stripped, stripped)) - { - GNUNET_free(head_stripped); - break; - } - GNUNET_free(head_stripped); - head = head->next; + GNUNET_free (head_stripped); + break; } - GNUNET_free(stripped); + GNUNET_free (head_stripped); + head = head->next; + } + GNUNET_free (stripped); if (NULL == head) return NULL; 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 @@ * @param cfg configuration to use */ void -GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg); +GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg); /** * Unload all plugins */ void -GPI_plugins_unload(void); +GPI_plugins_unload (void); /** @@ -51,7 +51,7 @@ GPI_plugins_unload(void); * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GPI_plugins_find(const char *name); +GPI_plugins_find (const char *name); #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 @@ /** * How long until we time out during address lookup? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** * The configuration handle */ @@ -70,12 +70,13 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; /** * HTTP methods allows for this plugin */ -static char* allow_methods; +static char*allow_methods; /** * @brief struct returned by the initialization function of the plugin */ -struct Plugin { +struct Plugin +{ const struct GNUNET_CONFIGURATION_Handle *cfg; }; @@ -83,7 +84,8 @@ struct Plugin { /** * Record we keep for each printable address. */ -struct AddressRecord { +struct AddressRecord +{ /** * Current address-to-string context (if active, otherwise NULL). */ @@ -109,7 +111,8 @@ struct AddressRecord { /** * Structure we use to collect printable address information. */ -struct PrintContext { +struct PrintContext +{ /** * Kept in DLL. */ @@ -169,7 +172,8 @@ static struct PrintContext *pc_tail; /** * The request handle */ -struct RequestHandle { +struct RequestHandle +{ /** * JSON temporary array */ @@ -252,51 +256,51 @@ struct RequestHandle { * @param handle Handle to clean up */ static void -cleanup_handle(void *cls) +cleanup_handle (void *cls) { struct RequestHandle *handle = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up\n"); if (NULL != handle->timeout_task) - { - GNUNET_SCHEDULER_cancel(handle->timeout_task); - handle->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (handle->timeout_task); + handle->timeout_task = NULL; + } if (NULL != handle->url) - GNUNET_free(handle->url); + GNUNET_free (handle->url); if (NULL != handle->emsg) - GNUNET_free(handle->emsg); + GNUNET_free (handle->emsg); if (NULL != handle->address) - GNUNET_free((char*)handle->address); + GNUNET_free ((char*) handle->address); if (NULL != handle->expiration_str) - GNUNET_free(handle->expiration_str); + GNUNET_free (handle->expiration_str); if (NULL != handle->pubkey) - GNUNET_free(handle->pubkey); + GNUNET_free (handle->pubkey); if (NULL != handle->temp_array) - { - json_decref(handle->temp_array); - handle->temp_array = NULL; - } + { + json_decref (handle->temp_array); + handle->temp_array = NULL; + } if (NULL != handle->response) - { - json_decref(handle->response); - handle->response = NULL; - } + { + json_decref (handle->response); + handle->response = NULL; + } if (NULL != handle->list_it) - { - GNUNET_PEERINFO_iterate_cancel(handle->list_it); - handle->list_it = NULL; - } + { + GNUNET_PEERINFO_iterate_cancel (handle->list_it); + handle->list_it = NULL; + } if (NULL != handle->peerinfo_handle) - { - GNUNET_PEERINFO_disconnect(handle->peerinfo_handle); - handle->peerinfo_handle = NULL; - } + { + GNUNET_PEERINFO_disconnect (handle->peerinfo_handle); + handle->peerinfo_handle = NULL; + } - GNUNET_free(handle); + GNUNET_free (handle); } @@ -306,26 +310,26 @@ cleanup_handle(void *cls) * @param cls the `struct RequestHandle` */ static void -do_error(void *cls) +do_error (void *cls) { struct RequestHandle *handle = cls; struct MHD_Response *resp; - json_t *json_error = json_object(); + json_t *json_error = json_object (); char *response; if (NULL == handle->emsg) - handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN); + handle->emsg = GNUNET_strdup (GNUNET_REST_PEERINFO_ERROR_UNKNOWN); - json_object_set_new(json_error, "error", json_string(handle->emsg)); + json_object_set_new (json_error, "error", json_string (handle->emsg)); if (0 == handle->response_code) handle->response_code = MHD_HTTP_OK; - response = json_dumps(json_error, 0); - resp = GNUNET_REST_create_response(response); - handle->proc(handle->proc_cls, resp, handle->response_code); - json_decref(json_error); - GNUNET_free(response); - GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); + response = json_dumps (json_error, 0); + resp = GNUNET_REST_create_response (response); + handle->proc (handle->proc_cls, resp, handle->response_code); + json_decref (json_error); + GNUNET_free (response); + GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); } @@ -335,26 +339,26 @@ do_error(void *cls) * @param cls the `struct RequestHandle` */ static void -peerinfo_list_finished(void *cls) +peerinfo_list_finished (void *cls) { struct RequestHandle *handle = cls; char *result_str; struct MHD_Response *resp; if (NULL == handle->response) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup("No peers found"); - GNUNET_SCHEDULER_add_now(&do_error, handle); - return; - } - - result_str = json_dumps(handle->response, 0); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); - resp = GNUNET_REST_create_response(result_str); - handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_free_non_null(result_str); - GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup ("No peers found"); + GNUNET_SCHEDULER_add_now (&do_error, handle); + return; + } + + result_str = json_dumps (handle->response, 0); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); + resp = GNUNET_REST_create_response (result_str); + handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_free_non_null (result_str); + GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); } @@ -367,16 +371,16 @@ peerinfo_list_finished(void *cls) * @return #GNUNET_OK to keep the address and continue */ static int -count_address(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +count_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; - if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) - { - return GNUNET_OK; /* ignore expired address */ - } + if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) + { + return GNUNET_OK; /* ignore expired address */ + } pc->off++; return GNUNET_OK; @@ -389,7 +393,7 @@ count_address(void *cls, * @param pc printing context */ static void -dump_pc(struct PrintContext *pc) +dump_pc (struct PrintContext *pc) { struct RequestHandle *handle; unsigned int i; @@ -401,62 +405,63 @@ dump_pc(struct PrintContext *pc) json_t *friend_and_peer_json; char *friend_and_peer; - temp_array = json_array(); - response_entry = json_object(); + temp_array = json_array (); + response_entry = json_object (); for (i = 0; i < pc->num_addresses; i++) + { + if (NULL != pc->address_list[i].result) { - if (NULL != pc->address_list[i].result) - { - object = json_object(); - address = json_string(pc->address_list[i].result); - expires = json_string( - GNUNET_STRINGS_absolute_time_to_string(pc->address_list[i].expiration)); - json_object_set(object, "address", address); - json_object_set(object, "expires", expires); - - json_decref(address); - json_decref(expires); - - json_array_append(temp_array, object); - json_decref(object); - GNUNET_free(pc->address_list[i].result); - } - } - - if (0 < json_array_size(temp_array)) - { - GNUNET_asprintf(&friend_and_peer, - "%s%s", - (GNUNET_YES == pc->friend_only) ? "F2F:" : "", - GNUNET_i2s_full(&pc->peer)); - friend_and_peer_json = json_string(friend_and_peer); - json_object_set(response_entry, - GNUNET_REST_PEERINFO_PEER, - friend_and_peer_json); - json_object_set(response_entry, - GNUNET_REST_PEERINFO_ARRAY, - temp_array); - json_array_append(pc->handle->response, response_entry); - json_decref(friend_and_peer_json); - GNUNET_free(friend_and_peer); + object = json_object (); + address = json_string (pc->address_list[i].result); + expires = json_string ( + GNUNET_STRINGS_absolute_time_to_string ( + pc->address_list[i].expiration)); + json_object_set (object, "address", address); + json_object_set (object, "expires", expires); + + json_decref (address); + json_decref (expires); + + json_array_append (temp_array, object); + json_decref (object); + GNUNET_free (pc->address_list[i].result); } - - json_decref(temp_array); - json_decref(response_entry); - - GNUNET_free_non_null(pc->address_list); - GNUNET_CONTAINER_DLL_remove(pc_head, - pc_tail, - pc); + } + + if (0 < json_array_size (temp_array)) + { + GNUNET_asprintf (&friend_and_peer, + "%s%s", + (GNUNET_YES == pc->friend_only) ? "F2F:" : "", + GNUNET_i2s_full (&pc->peer)); + friend_and_peer_json = json_string (friend_and_peer); + json_object_set (response_entry, + GNUNET_REST_PEERINFO_PEER, + friend_and_peer_json); + json_object_set (response_entry, + GNUNET_REST_PEERINFO_ARRAY, + temp_array); + json_array_append (pc->handle->response, response_entry); + json_decref (friend_and_peer_json); + GNUNET_free (friend_and_peer); + } + + json_decref (temp_array); + json_decref (response_entry); + + GNUNET_free_non_null (pc->address_list); + GNUNET_CONTAINER_DLL_remove (pc_head, + pc_tail, + pc); handle = pc->handle; - GNUNET_free(pc); + GNUNET_free (pc); if ((NULL == pc_head) && (NULL == handle->list_it)) - { - GNUNET_SCHEDULER_add_now(&peerinfo_list_finished, handle); - } + { + GNUNET_SCHEDULER_add_now (&peerinfo_list_finished, handle); + } } @@ -471,31 +476,31 @@ dump_pc(struct PrintContext *pc) * if #GNUNET_SYSERR: address is invalid */ static void -process_resolved_address(void *cls, - const char *address, - int res) +process_resolved_address (void *cls, + const char *address, + int res) { struct AddressRecord *ar = cls; struct PrintContext *pc = ar->pc; if (NULL != address) + { + if (0 != strlen (address)) { - if (0 != strlen(address)) - { - if (NULL != ar->result) - GNUNET_free(ar->result); - ar->result = GNUNET_strdup(address); - } - return; + if (NULL != ar->result) + GNUNET_free (ar->result); + ar->result = GNUNET_strdup (address); } + return; + } ar->atsc = NULL; if (GNUNET_SYSERR == res) - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Failure: Cannot convert address to string for peer `%s'\n"), - GNUNET_i2s(&ar->pc->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Failure: Cannot convert address to string for peer `%s'\n"), + GNUNET_i2s (&ar->pc->peer)); pc->num_addresses++; if (pc->num_addresses == pc->address_list_size) - dump_pc(ar->pc); + dump_pc (ar->pc); } @@ -508,33 +513,33 @@ process_resolved_address(void *cls, * @return #GNUNET_OK to keep the address and continue */ static int -print_address(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +print_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; struct AddressRecord *ar; - if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) - { - return GNUNET_OK; /* ignore expired address */ - } + if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) + { + return GNUNET_OK; /* ignore expired address */ + } - GNUNET_assert(0 < pc->off); + GNUNET_assert (0 < pc->off); ar = &pc->address_list[--pc->off]; ar->pc = pc; ar->expiration = expiration; - GNUNET_asprintf(&ar->result, - "%s:%u:%u", - address->transport_name, - address->address_length, - address->local_info); - ar->atsc = GNUNET_TRANSPORT_address_to_string(cfg, - address, - GNUNET_NO, - TIMEOUT, - &process_resolved_address, - ar); + GNUNET_asprintf (&ar->result, + "%s:%u:%u", + address->transport_name, + address->address_length, + address->local_info); + ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, + address, + GNUNET_NO, + TIMEOUT, + &process_resolved_address, + ar); return GNUNET_OK; } @@ -549,64 +554,64 @@ print_address(void *cls, * @param err_msg message */ void -peerinfo_list_iteration(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) +peerinfo_list_iteration (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct RequestHandle *handle = cls; struct PrintContext *pc; int friend_only; if (NULL == handle->response) - { - handle->response = json_array(); - } + { + handle->response = json_array (); + } if (NULL == peer) + { + handle->list_it = NULL; + handle->emsg = GNUNET_strdup ("Error in communication with peerinfo"); + if (NULL != err_msg) { - handle->list_it = NULL; - handle->emsg = GNUNET_strdup("Error in communication with peerinfo"); - if (NULL != err_msg) - { - GNUNET_free(handle->emsg); - handle->emsg = GNUNET_strdup(err_msg); - handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; - } - if (NULL == pc_head) - GNUNET_SCHEDULER_add_now(&do_error, handle); - return; + GNUNET_free (handle->emsg); + handle->emsg = GNUNET_strdup (err_msg); + handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; } + if (NULL == pc_head) + GNUNET_SCHEDULER_add_now (&do_error, handle); + return; + } if (NULL == hello) return; friend_only = GNUNET_NO; if (NULL != hello) - friend_only = GNUNET_HELLO_is_friend_only(hello); + friend_only = GNUNET_HELLO_is_friend_only (hello); - pc = GNUNET_new(struct PrintContext); - GNUNET_CONTAINER_DLL_insert(pc_head, - pc_tail, - pc); + pc = GNUNET_new (struct PrintContext); + GNUNET_CONTAINER_DLL_insert (pc_head, + pc_tail, + pc); pc->peer = *peer; pc->friend_only = friend_only; pc->handle = handle; - GNUNET_HELLO_iterate_addresses(hello, - GNUNET_NO, - &count_address, - pc); + GNUNET_HELLO_iterate_addresses (hello, + GNUNET_NO, + &count_address, + pc); if (0 == pc->off) - { - dump_pc(pc); - return; - } + { + dump_pc (pc); + return; + } pc->address_list_size = pc->off; - pc->address_list = GNUNET_malloc( + pc->address_list = GNUNET_malloc ( sizeof(struct AddressRecord) * pc->off); - GNUNET_HELLO_iterate_addresses(hello, - GNUNET_NO, - &print_address, - pc); + GNUNET_HELLO_iterate_addresses (hello, + GNUNET_NO, + &print_address, + pc); } /** @@ -617,50 +622,50 @@ peerinfo_list_iteration(void *cls, * @param cls the RequestHandle */ void -peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, - const char* url, - void *cls) +peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, + const char*url, + void *cls) { struct RequestHandle *handle = cls; struct GNUNET_HashCode key; const struct GNUNET_PeerIdentity *specific_peer; - //GNUNET_PEER_Id peer_id; + // GNUNET_PEER_Id peer_id; int include_friend_only; - char* include_friend_only_str; + char*include_friend_only_str; include_friend_only = GNUNET_NO; - GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_FRIEND, - strlen(GNUNET_REST_PEERINFO_FRIEND), - &key); + GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND, + strlen (GNUNET_REST_PEERINFO_FRIEND), + &key); if (GNUNET_YES - == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, - &key)) + == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, + &key)) + { + include_friend_only_str = GNUNET_CONTAINER_multihashmap_get ( + con_handle->url_param_map, &key); + if (0 == strcmp (include_friend_only_str, "yes")) { - include_friend_only_str = GNUNET_CONTAINER_multihashmap_get( - con_handle->url_param_map, &key); - if (0 == strcmp(include_friend_only_str, "yes")) - { - include_friend_only = GNUNET_YES; - } + include_friend_only = GNUNET_YES; } + } specific_peer = NULL; - GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_PEER, - strlen(GNUNET_REST_PEERINFO_PEER), - &key); + GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER, + strlen (GNUNET_REST_PEERINFO_PEER), + &key); if (GNUNET_YES - == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, - &key)) - { - //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); - //specific_peer = GNUNET_PEER_resolve2(peer_id); - } - - handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, - include_friend_only, - specific_peer, - &peerinfo_list_iteration, - handle); + == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, + &key)) + { + // peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); + // specific_peer = GNUNET_PEER_resolve2(peer_id); + } + + handle->list_it = GNUNET_PEERINFO_iterate (handle->peerinfo_handle, + include_friend_only, + specific_peer, + &peerinfo_list_iteration, + handle); } @@ -673,20 +678,20 @@ peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ static void -options_cont(struct GNUNET_REST_RequestHandle *con_handle, - const char* url, - void *cls) +options_cont (struct GNUNET_REST_RequestHandle *con_handle, + const char*url, + void *cls) { struct MHD_Response *resp; struct RequestHandle *handle = cls; - //independent of path return all options - resp = GNUNET_REST_create_response(NULL); - MHD_add_response_header(resp, - "Access-Control-Allow-Methods", - allow_methods); - handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); + // independent of path return all options + resp = GNUNET_REST_create_response (NULL); + MHD_add_response_header (resp, + "Access-Control-Allow-Methods", + allow_methods); + handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); return; } @@ -697,7 +702,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle, * @param handle the request handle */ static void -init_cont(struct RequestHandle *handle) +init_cont (struct RequestHandle *handle) { struct GNUNET_REST_RequestHandlerError err; static const struct GNUNET_REST_RequestHandler handlers[] = { @@ -706,14 +711,14 @@ init_cont(struct RequestHandle *handle) GNUNET_REST_HANDLER_END }; - if (GNUNET_NO == GNUNET_REST_handle_request(handle->rest_handle, - handlers, - &err, - handle)) - { - handle->response_code = err.error_code; - GNUNET_SCHEDULER_add_now(&do_error, handle); - } + if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, + handlers, + &err, + handle)) + { + handle->response_code = err.error_code; + GNUNET_SCHEDULER_add_now (&do_error, handle); + } } @@ -729,30 +734,31 @@ init_cont(struct RequestHandle *handle) * @return GNUNET_OK if request accepted */ static void -rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, - GNUNET_REST_ResultProcessor proc, - void *proc_cls) +rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, + GNUNET_REST_ResultProcessor proc, + void *proc_cls) { - struct RequestHandle *handle = GNUNET_new(struct RequestHandle); + struct RequestHandle *handle = GNUNET_new (struct RequestHandle); handle->response_code = 0; - handle->timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60); + handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + 60); handle->proc_cls = proc_cls; handle->proc = proc; handle->rest_handle = rest_handle; - handle->url = GNUNET_strdup(rest_handle->url); - if (handle->url[strlen(handle->url) - 1] == '/') - handle->url[strlen(handle->url) - 1] = '\0'; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); - handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg); - init_cont(handle); + handle->url = GNUNET_strdup (rest_handle->url); + if (handle->url[strlen (handle->url) - 1] == '/') + handle->url[strlen (handle->url) - 1] = '\0'; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); + handle->peerinfo_handle = GNUNET_PEERINFO_connect (cfg); + init_cont (handle); handle->timeout_task = - GNUNET_SCHEDULER_add_delayed(handle->timeout, - &do_error, - handle); + GNUNET_SCHEDULER_add_delayed (handle->timeout, + &do_error, + handle); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); } @@ -763,7 +769,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, * @return NULL on error, otherwise the plugin context */ void * -libgnunet_plugin_rest_peerinfo_init(void *cls) +libgnunet_plugin_rest_peerinfo_init (void *cls) { static struct Plugin plugin; struct GNUNET_REST_Plugin *api; @@ -771,22 +777,22 @@ libgnunet_plugin_rest_peerinfo_init(void *cls) cfg = cls; if (NULL != plugin.cfg) return NULL; /* can only initialize once! */ - memset(&plugin, 0, sizeof(struct Plugin)); + memset (&plugin, 0, sizeof(struct Plugin)); plugin.cfg = cfg; - api = GNUNET_new(struct GNUNET_REST_Plugin); + api = GNUNET_new (struct GNUNET_REST_Plugin); api->cls = &plugin; api->name = GNUNET_REST_API_NS_PEERINFO; api->process_request = &rest_process_request; - GNUNET_asprintf(&allow_methods, - "%s, %s, %s, %s, %s", - MHD_HTTP_METHOD_GET, - MHD_HTTP_METHOD_POST, - MHD_HTTP_METHOD_PUT, - MHD_HTTP_METHOD_DELETE, - MHD_HTTP_METHOD_OPTIONS); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - _("Peerinfo REST API initialized\n")); + GNUNET_asprintf (&allow_methods, + "%s, %s, %s, %s, %s", + MHD_HTTP_METHOD_GET, + MHD_HTTP_METHOD_POST, + MHD_HTTP_METHOD_PUT, + MHD_HTTP_METHOD_DELETE, + MHD_HTTP_METHOD_OPTIONS); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _ ("Peerinfo REST API initialized\n")); return api; } @@ -798,19 +804,18 @@ libgnunet_plugin_rest_peerinfo_init(void *cls) * @return always NULL */ void * -libgnunet_plugin_rest_peerinfo_done(void *cls) +libgnunet_plugin_rest_peerinfo_done (void *cls) { struct GNUNET_REST_Plugin *api = cls; struct Plugin *plugin = api->cls; plugin->cfg = NULL; - GNUNET_free_non_null(allow_methods); - GNUNET_free(api); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peerinfo REST plugin is finished\n"); + GNUNET_free_non_null (allow_methods); + GNUNET_free (api); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peerinfo REST plugin is finished\n"); return NULL; } /* end of plugin_rest_peerinfo.c */ - -- cgit v1.2.3