/* This file is part of GNUnet. (C) 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file gnunet-gns.c * @brief command line tool to access distributed GNS * @author Christian Grothoff * */ #include "platform.h" #include #include #include #include /** * Handle to GNS service. */ static struct GNUNET_GNS_Handle *gns; /** * GNS name to shorten. (-s option) */ static char *shorten_name; /** * GNS name to lookup. (-u option) */ static char *lookup_name; /** * record type to look up (-t option) */ 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. * * @param cls unused * @param tc scheduler context */ 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); 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