gnunet-social cli
[oweals/gnunet.git] / src / social / gnunet-social.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2016 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * CLI tool to interact with the social service.
23  *
24  * @author Gabor X Toth
25  */
26
27 #include <inttypes.h>
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_social_service.h"
32
33 /* operations corresponding to API calls */
34
35 /** --host-enter */
36 static int op_host_enter;
37
38 /** --host-leave */
39 static int op_host_leave;
40
41 /** --host-announce */
42 static int op_host_announce;
43
44 /** --guest-enter */
45 static int op_guest_enter;
46
47 /** --guest-leave */
48 static int op_guest_leave;
49
50 /** --guest-talk */
51 static int op_guest_talk;
52
53 /** --history-replay */
54 static char *op_history_replay;
55
56 /** --history-replay-latest */
57 static char *op_history_replay_latest;
58
59 /* options */
60
61 /** --place */
62 static char *place;
63
64 /** --listen */
65 static int listen;
66
67 /** --method */
68 static char *method;
69
70 /** --data */
71 static char *data;
72
73 /** --prefix */
74 static char *prefix;
75
76 /** --start */
77 static uint64_t start;
78
79 /** --end */
80 static uint64_t end;
81
82 /** --limit */
83 static int limit;
84
85
86 /**
87  * Main function that will be run by the scheduler.
88  *
89  * @param cls closure
90  * @param args remaining command-line arguments
91  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
92  * @param cfg configuration
93  */
94 static void
95 run (void *cls, char *const *args, const char *cfgfile,
96      const struct GNUNET_CONFIGURATION_Handle *cfg)
97 {
98   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "TODO\n");
99 }
100
101
102 /**
103  * The main function to obtain peer information.
104  *
105  * @param argc number of arguments from the command line
106  * @param argv command line arguments
107  * @return 0 ok, 1 on error
108  */
109 int
110 main (int argc, char *const *argv)
111 {
112   int res;
113   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
114      {'p', "place", "PUBKEY",
115       gettext_noop ("public key of place"),
116       GNUNET_YES, &GNUNET_GETOPT_set_string, &place},
117
118      {'l', "listen", NULL,
119      gettext_noop ("listen for incoming messages"),
120      GNUNET_NO, &GNUNET_GETOPT_set_one, &listen},
121
122      {'m', "method", "METHOD_NAME",
123       gettext_noop ("method name to transmit"),
124       GNUNET_YES, &GNUNET_GETOPT_set_string, &method},
125
126      {'d', "data", "DATA",
127       gettext_noop ("message body to transmit"),
128       GNUNET_YES, &GNUNET_GETOPT_set_string, &method},
129
130      {'p', "prefix", "METHOD_PREFIX",
131       gettext_noop ("method prefix filter for history replay"),
132       GNUNET_YES, &GNUNET_GETOPT_set_string, &method},
133
134      {'s', "start", NULL,
135      gettext_noop ("start message ID for history replay"),
136      GNUNET_NO, &GNUNET_GETOPT_set_ulong, &start},
137
138      {'e', "end", NULL,
139      gettext_noop ("end message ID for history replay"),
140      GNUNET_NO, &GNUNET_GETOPT_set_ulong, &end},
141
142      {'n', "limit", NULL,
143      gettext_noop ("number of messages to replay from history"),
144      GNUNET_NO, &GNUNET_GETOPT_set_ulong, &end},
145
146     GNUNET_GETOPT_OPTION_END
147   };
148
149   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
150     return 2;
151
152   const char *help =
153     "enter/leave and send/receive messages in places of the social service";
154   const char *usage =
155     "gnunet-social --place <pubkey> --host-enter [--listen]\n"
156     "gnunet-social --place <pubkey> --host-leave\n"
157     "gnunet-social --place <pubkey> --host-announce --method <method_name> --data <message_body>\n"
158     "\n"
159     "gnunet-social --place <pubkey> --guest-enter [--listen]\n"
160     "gnunet-social --place <pubkey> --guest-leave\n"
161     "gnunet-social --place <pubkey> --guest-talk --method <method_nmae> --data <data>\n"
162     "\n"
163     "gnunet-social --place <pubkey> --history-replay --start <msgid> --end <msgid>  [--prefix <method_prefix>]\n"
164     "gnunet-social --place <pubkey> --history-replay-latest --limit <msg_limit> [--prefix <method_prefix>]\n"
165     "\n"
166     "gnunet-social --place <pubkey> --look-at <full_name>\n"
167     "gnunet-social --place <pubkey> --look-for <name_prefix>\n";
168
169   res = GNUNET_PROGRAM_run (argc, argv, usage,
170                             gettext_noop (help),
171                             options, &run, NULL);
172
173   GNUNET_free ((void *) argv);
174
175   if (GNUNET_OK == res)
176     return 0;
177   else
178     return 1;
179 }