- cleanup
[oweals/gnunet.git] / src / ats / gnunet-ats.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 /**
22  * @file ats/gnunet-ats.c
23  * @brief ATS command line tool
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_ats_service.h"
29
30 /**
31  * Final status code.
32  */
33 static int ret;
34
35 static char * peer_str;
36
37 static int all_peers;
38
39 /**
40  * Main function that will be run by the scheduler.
41  *
42  * @param cls closure
43  * @param args remaining command-line arguments
44  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
45  * @param cfg configuration
46  */
47 static void
48 run (void *cls, char *const *args, const char *cfgfile,
49      const struct GNUNET_CONFIGURATION_Handle *cfg)
50 {
51   if (GNUNET_YES == all_peers)
52   {
53     /* list information for all peers */
54     printf ("To be implemented!\n");
55
56     /* TODO: get all peers */
57
58     /* TODO: get addresses for each peer */
59   }
60   else if (NULL != peer_str)
61   {
62     /* list information for a specific peer */
63     printf ("To be implemented!\n");
64     struct GNUNET_PeerIdentity id;
65     if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string2(peer_str, strlen (peer_str), &id.hashPubKey))
66     {
67       printf ("`%s' is not a valid peer identity\n", peer_str);
68       GNUNET_free (peer_str);
69       return;
70     }
71
72     printf ("Peer `%s':\n", GNUNET_i2s_full (&id));
73
74     /* TODO: get addresses for each peer */
75     GNUNET_free (peer_str);
76   }
77 }
78
79
80 /**
81  * The main function.
82  *
83  * @param argc number of arguments from the command line
84  * @param argv command line arguments
85  * @return 0 ok, 1 on error
86  */
87 int
88 main (int argc, char *const *argv)
89 {
90   int res;
91   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
92     {'P', "peer", "PEER",
93      gettext_noop ("list information for the given peer"),
94      1, &GNUNET_GETOPT_set_string, &peer_str},
95     {'A', "all", NULL,
96      gettext_noop ("list information for all peers"),
97      0, &GNUNET_GETOPT_set_one, &all_peers},
98     GNUNET_GETOPT_OPTION_END
99   };
100
101   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
102     return 2;
103
104   res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats",
105                               gettext_noop ("Print information about ATS state"), options, &run,
106                               NULL);
107   GNUNET_free ((void *) argv);
108
109   if (GNUNET_OK == res)
110     return ret;
111   else
112     return 1;
113
114 }
115
116 /* end of gnunet-ats.c */