X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Fgnunet-gns.c;h=d7e8309dd5d2a5065f39ec54bbf03b7ece6db653;hb=f4d040c0f0dd2fef3d73b1f4532c76219f760f75;hp=a56b229b5a5228e9957740784187f8c9036f5f88;hpb=9761c89280fe637c7dd78d6701d45695be93fcec;p=oweals%2Fgnunet.git diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index a56b229b5..d7e8309dd 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -19,36 +19,66 @@ */ /** * @file gnunet-gns.c - * @brief command line tool to manipulate the local zone + * @brief command line tool to access distributed GNS * @author Christian Grothoff * - * TODO: - * - everything */ #include "platform.h" #include +#include #include +#include /** - * Handle to the namestore. + * Handle to GNS service. */ -static struct GNUNET_NAMESTORE_Handle *ns; +static struct GNUNET_GNS_Handle *gns; /** - * Hash of the public key of our zone. + * GNS name to shorten. (-s option) */ -static GNUNET_HashCode zone; +static char *shorten_name; /** - * Private key for the our zone. + * GNS name to lookup. (-u option) */ -static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey; +static char *lookup_name; /** - * Keyfile to manipulate. + * record type to look up (-t option) */ -static char *keyfile; - +static char *lookup_type; + +/** + * name to look up authority for (-a option) + */ +static char *auth_name; + +/** + * raw output + */ +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. @@ -60,19 +90,107 @@ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - if (NULL != ns) + if (NULL != lookup_request) { - GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO); - ns = NULL; + GNUNET_GNS_cancel_lookup_request (lookup_request); + lookup_request = NULL; } - if (NULL != zone_pkey) + if (NULL != shorten_request) { - GNUNET_CRYPTO_rsa_key_free (zone_pkey); - zone_pkey = NULL; + 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); + gns = NULL; } } +/** + * 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) +{ + const char *original_name = cls; + + shorten_request = NULL; + if (raw) + printf("%s", nshort); + else + 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) +{ + const char* name = cls; + uint32_t i; + const char* typename; + char* string_val; + + lookup_request = NULL; + if (!raw) + { + if (0 == rd_count) + printf("No results.\n"); + else + printf("%s:\n", name); + } + for (i=0; i