X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Fgnunet-gns.c;h=d7e8309dd5d2a5065f39ec54bbf03b7ece6db653;hb=f4d040c0f0dd2fef3d73b1f4532c76219f760f75;hp=95733618c8d7b9fa174d7297376a903ae22d53f4;hpb=e6d0c3119a3348eeb539a7e52113e12a7bb37a5f;p=oweals%2Fgnunet.git diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 95733618c..d7e8309dd 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -22,8 +22,6 @@ * @brief command line tool to access distributed GNS * @author Christian Grothoff * - * TODO: - * - everything */ #include "platform.h" #include @@ -46,7 +44,6 @@ static char *shorten_name; */ static char *lookup_name; - /** * record type to look up (-t option) */ @@ -60,10 +57,29 @@ static char *auth_name; /** * raw output */ -static int raw = 0; +static int raw; +/** + * Requested record type. + */ static enum GNUNET_GNS_RecordType rtype; +/** + * Handle to lookup request + */ +static struct GNUNET_GNS_LookupRequest *lookup_request; + +/** + * Handle to shorten request + */ +static struct GNUNET_GNS_ShortenRequest *shorten_request; + +/** + * Handle to get authority request + */ +static struct GNUNET_GNS_GetAuthRequest *getauth_request; + + /** * Task run on shutdown. Cleans up everything. * @@ -74,6 +90,21 @@ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if (NULL != lookup_request) + { + GNUNET_GNS_cancel_lookup_request (lookup_request); + lookup_request = NULL; + } + if (NULL != shorten_request) + { + GNUNET_GNS_cancel_shorten_request (shorten_request); + shorten_request = NULL; + } + if (NULL != getauth_request) + { + GNUNET_GNS_cancel_get_auth_request (getauth_request); + getauth_request = NULL; + } if (NULL != gns) { GNUNET_GNS_disconnect (gns); @@ -82,57 +113,84 @@ do_shutdown (void *cls, } +/** + * Function called with the result of a shorten operation. + * Prints the result. + * + * @param cls a 'const char *' with the original (long) name + * @param nshort the shortened name + */ static void -process_shorten_result(void* cls, const char* nshort) +process_shorten_result (void* cls, const char *nshort) { + const char *original_name = cls; + + shorten_request = NULL; if (raw) printf("%s", nshort); else - printf("%s shortened to %s\n", (char*) cls, nshort); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + printf("%s shortened to %s\n", original_name, nshort); + GNUNET_SCHEDULER_shutdown (); } + +/** + * Function called with the result of a GADS lookup. + * + * @param cls the 'const char *' name that was resolved + * @param rd_count number of records returned + * @param rd array of 'rd_count' records with the results + */ static void -process_lookup_result(void* cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +process_lookup_result (void* cls, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { - int i; - char* name = (char*) cls; + const char* name = cls; + uint32_t i; const char* typename; char* string_val; - - if (!raw) { - if (rd_count == 0) + + lookup_request = NULL; + if (!raw) + { + if (0 == rd_count) printf("No results.\n"); else printf("%s:\n", name); } - - - for (i=0; i