aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-02 17:04:28 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-02 17:04:28 +0000
commit5b8852e4400e5f519018c4aa73f2ef5e4bcf8a86 (patch)
tree9d57db23fd56bf50f8d4bbfdbff83b8244390189 /src/conversation/gnunet-conversation.c
parentdc30009133e6c1021ac293469e69ff4043155b15 (diff)
downloadgnunet-5b8852e4400e5f519018c4aa73f2ef5e4bcf8a86.tar.gz
gnunet-5b8852e4400e5f519018c4aa73f2ef5e4bcf8a86.zip
-indentation, minor stylistic fixes
Diffstat (limited to 'src/conversation/gnunet-conversation.c')
-rw-r--r--src/conversation/gnunet-conversation.c297
1 files changed, 178 insertions, 119 deletions
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index f778c4c01..dffe9b4b6 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -24,9 +24,9 @@
24 * @author Simon Dieterle 24 * @author Simon Dieterle
25 * @author Andreas Fuchs 25 * @author Andreas Fuchs
26 */ 26 */
27#include <gnunet/platform.h> 27#include "platform.h"
28#include <gnunet/gnunet_constants.h> 28#include "gnunet_util_lib.h"
29#include <gnunet/gnunet_util_lib.h> 29#include "gnunet_constants.h"
30#include "gnunet_conversation_service.h" 30#include "gnunet_conversation_service.h"
31#include <fcntl.h> 31#include <fcntl.h>
32 32
@@ -75,29 +75,37 @@ static int do_help (const char *args, const void *xtra);
75 * @param handle to the conversation session 75 * @param handle to the conversation session
76 * @param caller peer that calls you 76 * @param caller peer that calls you
77 */ 77 */
78void 78static void
79call_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, 79call_handler (void *cls,
80 struct GNUNET_CONVERSATION_Handle *handle,
80 const struct GNUNET_PeerIdentity *caller) 81 const struct GNUNET_PeerIdentity *caller)
81{ 82{
82 FPRINTF (stdout, _("Incoming call from peer: %s\n"), 83 FPRINTF (stdout,
84 _("Incoming call from peer: %s\n"),
83 GNUNET_i2s_full (caller)); 85 GNUNET_i2s_full (caller));
84} 86}
85 87
88
86/** 89/**
87 * Method called whenever a call is rejected 90 * Method called whenever a call is rejected
88 * 91 *
89 * @param cls closure 92 * @param cls closure
90 * @param handle to the conversation session 93 * @param handle to the conversation session
94 * @param reason given reason why the call was rejected
91 * @param peer peer that rejected your call 95 * @param peer peer that rejected your call
92 */ 96 */
93void 97static void
94reject_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, int reason, 98reject_handler (void *cls,
99 struct GNUNET_CONVERSATION_Handle *handle,
100 enum GNUNET_CONVERSATION_RejectReason reason,
95 const struct GNUNET_PeerIdentity *peer) 101 const struct GNUNET_PeerIdentity *peer)
96{ 102{
97 FPRINTF (stdout, _("Peer %s rejected your call. Reason: %d\n"), 103 FPRINTF (stdout,
104 _("Peer %s rejected your call. Reason: %d\n"),
98 GNUNET_i2s_full (peer), reason); 105 GNUNET_i2s_full (peer), reason);
99} 106}
100 107
108
101/** 109/**
102 * Method called whenever a notification is there 110 * Method called whenever a notification is there
103 * 111 *
@@ -106,48 +114,48 @@ reject_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, int reason
106 * @param type the type of the notification 114 * @param type the type of the notification
107 * @param peer peer that the notification is about 115 * @param peer peer that the notification is about
108 */ 116 */
109void 117static void
110notification_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, int type, 118notification_handler (void *cls,
119 struct GNUNET_CONVERSATION_Handle *handle,
120 enum GNUNET_CONVERSATION_NotificationType type,
111 const struct GNUNET_PeerIdentity *peer) 121 const struct GNUNET_PeerIdentity *peer)
112{ 122{
113 switch (type) 123 switch (type)
114 { 124 {
115 case GNUNET_CONVERSATION_NT_SERVICE_BLOCKED: 125 case GNUNET_CONVERSATION_NT_SERVICE_BLOCKED:
116 FPRINTF (stdout, _("The service is already in use. Try again later.")); 126 FPRINTF (stdout,
117 127 _("The service is already in use. Try again later."));
118 break; 128 break;
119 129 case GNUNET_CONVERSATION_NT_NO_PEER:
120 case GNUNET_CONVERSATION_NT_NO_PEER: 130 FPRINTF (stdout,
121 FPRINTF (stdout, _("The Peer you were calling is no correct peer.\n")); 131 _("The Peer you were calling is no correct peer.\n"));
122 132 break;
123 break; 133 case GNUNET_CONVERSATION_NT_NO_ANSWER:
124 134 FPRINTF (stdout,
125 case GNUNET_CONVERSATION_NT_NO_ANSWER: 135 _("Peer %s did not answer your call.\n"),
126 FPRINTF (stdout, _("Peer %s did not answer your call.\n"), 136 GNUNET_i2s_full (peer));
127 GNUNET_i2s_full (peer)); 137 break;
128 138 case GNUNET_CONVERSATION_NT_AVAILABLE_AGAIN:
129 break; 139 FPRINTF (stdout,
130 140 _("Peer %s is now available.\n"),
131 case GNUNET_CONVERSATION_NT_AVAILABLE_AGAIN: 141 GNUNET_i2s_full (peer));
132 FPRINTF (stdout, _("Peer %s is now available.\n"), 142 break;
133 GNUNET_i2s_full (peer)); 143 case GNUNET_CONVERSATION_NT_CALL_ACCEPTED:
134 144 FPRINTF (stdout,
135 break; 145 _("Peer %s has accepted your call.\n"),
136 146 GNUNET_i2s_full (peer));
137 case GNUNET_CONVERSATION_NT_CALL_ACCEPTED: 147 break;
138 FPRINTF (stdout, _("Peer %s has accepted your call.\n"), 148 case GNUNET_CONVERSATION_NT_CALL_TERMINATED:
139 GNUNET_i2s_full (peer)); 149 FPRINTF (stdout,
140 150 _("Peer %s has terminated the call.\n"),
141 break; 151 GNUNET_i2s_full (peer));
142 152 break;
143 case GNUNET_CONVERSATION_NT_CALL_TERMINATED: 153 default:
144 FPRINTF (stdout, _("Peer %s has terminated the call.\n"), 154 GNUNET_break (0);
145 GNUNET_i2s_full (peer)); 155 }
146 break;
147 }
148
149} 156}
150 157
158
151/** 159/**
152 * Method called whenever a notification for missed calls is there 160 * Method called whenever a notification for missed calls is there
153 * 161 *
@@ -155,94 +163,118 @@ notification_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, int
155 * @param handle to the conversation session 163 * @param handle to the conversation session
156 * @param missed_calls a list of missed calls 164 * @param missed_calls a list of missed calls
157 */ 165 */
158void 166static void
159missed_call_handler (void *cls, struct GNUNET_CONVERSATION_Handle *handle, 167missed_call_handler (void *cls,
168 struct GNUNET_CONVERSATION_Handle *handle,
160 struct GNUNET_CONVERSATION_MissedCallNotification *missed_calls) 169 struct GNUNET_CONVERSATION_MissedCallNotification *missed_calls)
161{ 170{
162 FPRINTF (stdout, _("You have missed calls.\n")); 171 FPRINTF (stdout, _("You have missed calls.\n"));
163} 172}
164 173
174
165/** 175/**
166* Terminating the client 176 * Terminating the client
167*/ 177 */
168static int 178static int
169do_quit (const char *args, const void *xtra) 179do_quit (const char *args,
180 const void *xtra)
170{ 181{
171 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
172} 183}
173 184
185
174/** 186/**
175* 187 *
176*/ 188 */
177static int 189static int
178do_unknown (const char *msg, const void *xtra) 190do_unknown (const char *msg,
191 const void *xtra)
179{ 192{
180 FPRINTF (stderr, _("Unknown command `%s'\n"), msg); 193 FPRINTF (stderr, _("Unknown command `%s'\n"), msg);
181 return GNUNET_OK; 194 return GNUNET_OK;
182} 195}
183 196
197
184/** 198/**
185* Initiating a new call 199 * Initiating a new call
186*/ 200 */
187static int 201static int
188do_call (const char *arg, const void *xtra) 202do_call (const char *arg,
203 const void *xtra)
189{ 204{
190 char *callee = GNUNET_strdup (arg); 205 char *callee = GNUNET_strdup (arg);
191 FPRINTF (stdout, _("Initiating call to: %s\n"), callee);
192 GNUNET_CONVERSATION_call (conversation, callee, GNUNET_YES);
193 206
207 FPRINTF (stdout,
208 _("Initiating call to: %s\n"),
209 callee);
210 GNUNET_CONVERSATION_call (conversation,
211 callee,
212 GNUNET_YES);
194 return GNUNET_OK; 213 return GNUNET_OK;
195} 214}
196 215
216
197/** 217/**
198* Initiating a new call 218 * Initiating a new call
199*/ 219 */
200static int 220static int
201do_call_peer (const char *arg, const void *xtra) 221do_call_peer (const char *arg,
222 const void *xtra)
202{ 223{
203 char *callee = GNUNET_strdup (arg); 224 char *callee = GNUNET_strdup (arg);
204 FPRINTF (stdout, _("Initiating call to: %s\n"), callee);
205 GNUNET_CONVERSATION_call (conversation, callee, GNUNET_NO);
206 225
226 FPRINTF (stdout,
227 _("Initiating call to: %s\n"),
228 callee);
229 GNUNET_CONVERSATION_call (conversation, callee, GNUNET_NO);
230
207 return GNUNET_OK; 231 return GNUNET_OK;
208} 232}
209 233
234
210/** 235/**
211* Accepting an incoming call 236 * Accepting an incoming call
212*/ 237 */
213static int 238static int
214do_accept (const char *args, const void *xtra) 239do_accept (const char *args,
240 const void *xtra)
215{ 241{
216 FPRINTF (stdout, _("Accepting the call\n")); 242 FPRINTF (stdout,
243 _("Accepting the call\n"));
217 GNUNET_CONVERSATION_accept (conversation); 244 GNUNET_CONVERSATION_accept (conversation);
218 245
219 return GNUNET_OK; 246 return GNUNET_OK;
220} 247}
221 248
249
222/** 250/**
223* Rejecting a call 251 * Rejecting a call
224*/ 252 */
225static int 253static int
226do_reject (const char *args, const void *xtra) 254do_reject (const char *args,
255 const void *xtra)
227{ 256{
228 FPRINTF (stdout, _("Rejecting the call\n")); 257 FPRINTF (stdout,
258 _("Rejecting the call\n"));
229 GNUNET_CONVERSATION_reject (conversation); 259 GNUNET_CONVERSATION_reject (conversation);
230
231 return GNUNET_OK; 260 return GNUNET_OK;
232} 261}
233 262
263
234/** 264/**
235* Terminating a call 265 * Terminating a call
236*/ 266 */
237static int 267static int
238do_hang_up (const char *args, const void *xtra) 268do_hang_up (const char *args,
269 const void *xtra)
239{ 270{
240 FPRINTF (stdout, _("Terminating the call\n")); 271 FPRINTF (stdout,
241 GNUNET_CONVERSATION_hangup (conversation); 272 _("Terminating the call\n"));
242 273 GNUNET_CONVERSATION_hangup (conversation);
243 return GNUNET_OK; 274 return GNUNET_OK;
244} 275}
245 276
277
246/** 278/**
247 * List of supported commands. 279 * List of supported commands.
248 */ 280 */
@@ -264,61 +296,78 @@ static struct VoipCommand commands[] = {
264 {NULL, NULL, NULL}, 296 {NULL, NULL, NULL},
265}; 297};
266 298
299
267/** 300/**
268* 301 *
269*/ 302 */
270static int 303static int
271do_help (const char *args, const void *xtra) 304do_help (const char *args,
305 const void *xtra)
272{ 306{
273 int i; 307 int i;
274 308
275 i = 0; 309 i = 0;
276 while ((NULL != args) && (0 != strlen (args)) && 310 while ((NULL != args) && (0 != strlen (args)) &&
277 (commands[i].Action != &do_help)) 311 (commands[i].Action != &do_help))
312 {
313 if (0 ==
314 strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
278 { 315 {
279 if (0 == 316 FPRINTF (stdout,
280 strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) 317 "%s\n",
281 { 318 gettext (commands[i].helptext));
282 FPRINTF (stdout, "%s\n", gettext (commands[i].helptext)); 319 return GNUNET_OK;
283 return GNUNET_OK;
284 }
285 i++;
286 } 320 }
321 i++;
322 }
287 i = 0; 323 i = 0;
288 FPRINTF (stdout, "%s", "Available commands:"); 324 FPRINTF (stdout,
325 "%s",
326 "Available commands:");
289 while (commands[i].Action != &do_help) 327 while (commands[i].Action != &do_help)
290 { 328 {
291 FPRINTF (stdout, " %s", gettext (commands[i].command)); 329 FPRINTF (stdout,
292 i++; 330 " %s",
293 } 331 gettext (commands[i].command));
294 FPRINTF (stdout, "%s", "\n"); 332 i++;
295 FPRINTF (stdout, "%s\n", gettext (commands[i].helptext)); 333 }
334 FPRINTF (stdout,
335 "%s",
336 "\n");
337 FPRINTF (stdout,
338 "%s\n",
339 gettext (commands[i].helptext));
296 return GNUNET_OK; 340 return GNUNET_OK;
297} 341}
298 342
343
299/** 344/**
300* 345 *
301*/ 346 */
302static void 347static void
303do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 348do_stop_task (void *cls,
349 const struct GNUNET_SCHEDULER_TaskContext *tc)
304{ 350{
305 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running shutdown task\n"); 351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
352 "Running shutdown task\n");
306 GNUNET_CONVERSATION_disconnect (conversation); 353 GNUNET_CONVERSATION_disconnect (conversation);
307 354
308 if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK) 355 if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK)
309 { 356 {
310 GNUNET_SCHEDULER_cancel (handle_cmd_task); 357 GNUNET_SCHEDULER_cancel (handle_cmd_task);
311 handle_cmd_task = GNUNET_SCHEDULER_NO_TASK; 358 handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
312 } 359 }
313 360 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running shutdown task finished\n"); 361 "Running shutdown task finished\n");
315} 362}
316 363
364
317/** 365/**
318* 366 *
319*/ 367 */
320void 368static void
321handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 369handle_command (void *cls,
370 const struct GNUNET_SCHEDULER_TaskContext *tc)
322{ 371{
323 char message[MAX_MESSAGE_LENGTH + 1]; 372 char message[MAX_MESSAGE_LENGTH + 1];
324 int i; 373 int i;
@@ -357,6 +406,7 @@ out:
357 GNUNET_SCHEDULER_shutdown (); 406 GNUNET_SCHEDULER_shutdown ();
358} 407}
359 408
409
360/** 410/**
361 * Main function that will be run by the scheduler. 411 * Main function that will be run by the scheduler.
362 * 412 *
@@ -366,17 +416,24 @@ out:
366 * @param c configuration 416 * @param c configuration
367 */ 417 */
368static void 418static void
369run (void *cls, char *const *args, const char *cfgfile, 419run (void *cls,
420 char *const *args,
421 const char *cfgfile,
370 const struct GNUNET_CONFIGURATION_Handle *c) 422 const struct GNUNET_CONFIGURATION_Handle *c)
371{ 423{
372 if (NULL == 424 if (NULL ==
373 (conversation = 425 (conversation =
374 GNUNET_CONVERSATION_connect (c, NULL, &call_handler, &reject_handler, 426 GNUNET_CONVERSATION_connect (c, NULL,
375 &notification_handler, &missed_call_handler))) 427 &call_handler,
376 { 428 &reject_handler,
377 FPRINTF (stderr, "%s", _("Could not access CONVERSATION service. Exiting.\n")); 429 &notification_handler,
378 return; 430 &missed_call_handler)))
379 } 431 {
432 FPRINTF (stderr,
433 "%s",
434 _("Could not access CONVERSATION service. Exiting.\n"));
435 return;
436 }
380 437
381 handle_cmd_task = 438 handle_cmd_task =
382 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, 439 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
@@ -385,7 +442,9 @@ run (void *cls, char *const *args, const char *cfgfile,
385 NULL); 442 NULL);
386} 443}
387 444
388/** * The main function to conversation. 445
446/**
447 * The main function to conversation.
389 * 448 *
390 * @param argc number of arguments from the command line 449 * @param argc number of arguments from the command line
391 * @param argv command line arguments 450 * @param argv command line arguments