aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r--src/gns/gnunet-gns.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
new file mode 100644
index 000000000..3fdd8d29f
--- /dev/null
+++ b/src/gns/gnunet-gns.c
@@ -0,0 +1,121 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20/**
21 * @file gnunet-gns.c
22 * @brief command line tool to access distributed GNS
23 * @author Christian Grothoff
24 *
25 * TODO:
26 * - everything
27 */
28#include "platform.h"
29#include <gnunet_util_lib.h>
30#include <gnunet_dnsparser_lib.h>
31#include <gnunet_namestore_service.h>
32#include <gnunet_gns_service.h>
33
34/**
35 * Handle to GNS service.
36 */
37static struct GNUNET_GNS_Handle *gns;
38
39/**
40 * GNS name to shorten. (-s option)
41 */
42static struct char *name;
43
44/**
45 * Task run on shutdown. Cleans up everything.
46 *
47 * @param cls unused
48 * @param tc scheduler context
49 */
50static void
51do_shutdown (void *cls,
52 const struct GNUNET_SCHEDULER_TaskContext *tc)
53{
54 if (NULL != gns)
55 {
56 GNUNET_GNS_disconnect (gns);
57 gns = NULL;
58 }
59}
60
61
62/**
63 * Main function that will be run.
64 *
65 * @param cls closure
66 * @param args remaining command-line arguments
67 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
68 * @param cfg configuration
69 */
70static void
71run (void *cls, char *const *args, const char *cfgfile,
72 const struct GNUNET_CONFIGURATION_Handle *cfg)
73{
74 gns = GNUNET_GNS_connect (cfg);
75 if (NULL == gns)
76 {
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
78 _("Failed to connect to GNS\n"));
79 return;
80 }
81 if (NULL == s)
82 {
83 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
84 return;
85 }
86 // FIXME: do work here...
87 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
88}
89
90
91/**
92 * The main function for gnunet-gns.
93 *
94 * @param argc number of arguments from the command line
95 * @param argv command line arguments
96 * @return 0 ok, 1 on error
97 */
98int
99main (int argc, char *const *argv)
100{
101 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
102 {'s', "shorten", NULL,
103 gettext_noop ("try to shorten a given GNS name"), 0,
104 &GNUNET_GETOPT_set_string, &name},
105 GNUNET_GETOPT_OPTION_END
106 };
107
108 int ret;
109
110 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
111 ret =
112 (GNUNET_OK ==
113 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
114 _("GNUnet GNS access tool"),
115 options,
116 &run, NULL)) ? 0 : 1;
117
118 return ret;
119}
120
121/* end of gnunet-gns.c */