2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @brief command line tool to access distributed GNS
23 * @author Christian Grothoff
29 #include <gnunet_util_lib.h>
30 #include <gnunet_dnsparser_lib.h>
31 #include <gnunet_namestore_service.h>
32 #include <gnunet_gns_service.h>
35 * Handle to GNS service.
37 static struct GNUNET_GNS_Handle *gns;
40 * GNS name to shorten. (-s option)
45 * Task run on shutdown. Cleans up everything.
48 * @param tc scheduler context
51 do_shutdown (void *cls,
52 const struct GNUNET_SCHEDULER_TaskContext *tc)
56 GNUNET_GNS_disconnect (gns);
63 process_shorten_result(void* cls, const char* nshort)
65 printf("%s shortened to %s\n", (char*) cls, nshort);
69 * Main function that will be run.
72 * @param args remaining command-line arguments
73 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
74 * @param cfg configuration
77 run (void *cls, char *const *args, const char *cfgfile,
78 const struct GNUNET_CONFIGURATION_Handle *cfg)
80 gns = GNUNET_GNS_connect (cfg);
83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
84 _("Failed to connect to GNS\n"));
91 GNUNET_GNS_shorten(gns, name, &process_shorten_result, name);
94 // FIXME: do work here...
95 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
100 * The main function for gnunet-gns.
102 * @param argc number of arguments from the command line
103 * @param argv command line arguments
104 * @return 0 ok, 1 on error
107 main (int argc, char *const *argv)
109 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
110 {'s', "shorten", NULL,
111 gettext_noop ("try to shorten a given GNS name"), 1,
112 &GNUNET_GETOPT_set_string, &name},
113 GNUNET_GETOPT_OPTION_END
118 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
121 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
122 _("GNUnet GNS access tool"),
124 &run, NULL)) ? 0 : 1;
129 /* end of gnunet-gns.c */