diff options
Diffstat (limited to 'src/chat/gnunet-chat.c')
-rw-r--r-- | src/chat/gnunet-chat.c | 116 |
1 files changed, 45 insertions, 71 deletions
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c index 6dba4dda5..c656d1cad 100644 --- a/src/chat/gnunet-chat.c +++ b/src/chat/gnunet-chat.c | |||
@@ -107,12 +107,10 @@ join_cb (void *cls) | |||
107 | * accept (but user is away), GNUNET_SYSERR to signal denied delivery | 107 | * accept (but user is away), GNUNET_SYSERR to signal denied delivery |
108 | */ | 108 | */ |
109 | static int | 109 | static int |
110 | receive_cb (void *cls, | 110 | receive_cb (void *cls, struct GNUNET_CHAT_Room *room, |
111 | struct GNUNET_CHAT_Room *room, | ||
112 | const GNUNET_HashCode * sender, | 111 | const GNUNET_HashCode * sender, |
113 | const struct GNUNET_CONTAINER_MetaData *member_info, | 112 | const struct GNUNET_CONTAINER_MetaData *member_info, |
114 | const char *message, | 113 | const char *message, struct GNUNET_TIME_Absolute timestamp, |
115 | struct GNUNET_TIME_Absolute timestamp, | ||
116 | enum GNUNET_CHAT_MsgOptions options) | 114 | enum GNUNET_CHAT_MsgOptions options) |
117 | { | 115 | { |
118 | char *nick; | 116 | char *nick; |
@@ -183,8 +181,7 @@ receive_cb (void *cls, | |||
183 | * confirmations from anyone for this message | 181 | * confirmations from anyone for this message |
184 | */ | 182 | */ |
185 | static int | 183 | static int |
186 | confirmation_cb (void *cls, | 184 | confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room, |
187 | struct GNUNET_CHAT_Room *room, | ||
188 | uint32_t orig_seq_number, | 185 | uint32_t orig_seq_number, |
189 | struct GNUNET_TIME_Absolute timestamp, | 186 | struct GNUNET_TIME_Absolute timestamp, |
190 | const GNUNET_HashCode * receiver) | 187 | const GNUNET_HashCode * receiver) |
@@ -208,8 +205,7 @@ confirmation_cb (void *cls, | |||
208 | * @return GNUNET_OK | 205 | * @return GNUNET_OK |
209 | */ | 206 | */ |
210 | static int | 207 | static int |
211 | member_list_cb (void *cls, | 208 | member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info, |
212 | const struct GNUNET_CONTAINER_MetaData *member_info, | ||
213 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, | 209 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, |
214 | enum GNUNET_CHAT_MsgOptions options) | 210 | enum GNUNET_CHAT_MsgOptions options) |
215 | { | 211 | { |
@@ -222,8 +218,10 @@ member_list_cb (void *cls, | |||
222 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 218 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
223 | &id); | 219 | &id); |
224 | nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id); | 220 | nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id); |
225 | fprintf (stdout, member_info != NULL | 221 | fprintf (stdout, |
226 | ? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick); | 222 | member_info != |
223 | NULL ? _("`%s' entered the room\n") : _("`%s' left the room\n"), | ||
224 | nick); | ||
227 | GNUNET_free (nick); | 225 | GNUNET_free (nick); |
228 | if (NULL != member_info) | 226 | if (NULL != member_info) |
229 | { | 227 | { |
@@ -240,10 +238,9 @@ member_list_cb (void *cls, | |||
240 | prev = NULL; | 238 | prev = NULL; |
241 | pos = users; | 239 | pos = users; |
242 | while ((NULL != pos) && | 240 | while ((NULL != pos) && |
243 | (0 != memcmp (&pos->pkey, | 241 | (0 != |
244 | member_id, | 242 | memcmp (&pos->pkey, member_id, |
245 | sizeof (struct | 243 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))) |
246 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))) | ||
247 | { | 244 | { |
248 | prev = pos; | 245 | prev = pos; |
249 | pos = pos->next; | 246 | pos = pos->next; |
@@ -277,15 +274,10 @@ do_join (const char *arg, const void *xtra) | |||
277 | free_user_list (); | 274 | free_user_list (); |
278 | GNUNET_free (room_name); | 275 | GNUNET_free (room_name); |
279 | room_name = GNUNET_strdup (arg); | 276 | room_name = GNUNET_strdup (arg); |
280 | room = GNUNET_CHAT_join_room (cfg, | 277 | room = |
281 | nickname, | 278 | GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL, |
282 | meta, | 279 | &receive_cb, NULL, &member_list_cb, NULL, |
283 | room_name, | 280 | &confirmation_cb, NULL, &me); |
284 | -1, | ||
285 | &join_cb, NULL, | ||
286 | &receive_cb, NULL, | ||
287 | &member_list_cb, NULL, | ||
288 | &confirmation_cb, NULL, &me); | ||
289 | if (NULL == room) | 281 | if (NULL == room) |
290 | { | 282 | { |
291 | fprintf (stdout, _("Could not change username\n")); | 283 | fprintf (stdout, _("Could not change username\n")); |
@@ -311,21 +303,13 @@ do_nick (const char *msg, const void *xtra) | |||
311 | GNUNET_CONTAINER_meta_data_destroy (meta); | 303 | GNUNET_CONTAINER_meta_data_destroy (meta); |
312 | nickname = GNUNET_strdup (msg); | 304 | nickname = GNUNET_strdup (msg); |
313 | meta = GNUNET_CONTAINER_meta_data_create (); | 305 | meta = GNUNET_CONTAINER_meta_data_create (); |
314 | GNUNET_CONTAINER_meta_data_insert (meta, | 306 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE, |
315 | "<gnunet>", | 307 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
316 | EXTRACTOR_METATYPE_TITLE, | ||
317 | EXTRACTOR_METAFORMAT_UTF8, | ||
318 | "text/plain", | ||
319 | nickname, strlen (nickname) + 1); | 308 | nickname, strlen (nickname) + 1); |
320 | room = GNUNET_CHAT_join_room (cfg, | 309 | room = |
321 | nickname, | 310 | GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL, |
322 | meta, | 311 | &receive_cb, NULL, &member_list_cb, NULL, |
323 | room_name, | 312 | &confirmation_cb, NULL, &me); |
324 | -1, | ||
325 | &join_cb, NULL, | ||
326 | &receive_cb, NULL, | ||
327 | &member_list_cb, NULL, | ||
328 | &confirmation_cb, NULL, &me); | ||
329 | if (NULL == room) | 313 | if (NULL == room) |
330 | { | 314 | { |
331 | fprintf (stdout, _("Could not change username\n")); | 315 | fprintf (stdout, _("Could not change username\n")); |
@@ -411,8 +395,8 @@ do_send_pm (const char *msg, const void *xtra) | |||
411 | GNUNET_free (user); | 395 | GNUNET_free (user); |
412 | return GNUNET_OK; | 396 | return GNUNET_OK; |
413 | } | 397 | } |
414 | GNUNET_CHAT_send_message (room, | 398 | GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, |
415 | msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, &seq); | 399 | &seq); |
416 | GNUNET_free (user); | 400 | GNUNET_free (user); |
417 | return GNUNET_OK; | 401 | return GNUNET_OK; |
418 | } | 402 | } |
@@ -423,8 +407,8 @@ do_send_sig (const char *msg, const void *xtra) | |||
423 | { | 407 | { |
424 | uint32_t seq; | 408 | uint32_t seq; |
425 | 409 | ||
426 | GNUNET_CHAT_send_message (room, | 410 | GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, |
427 | msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, &seq); | 411 | &seq); |
428 | return GNUNET_OK; | 412 | return GNUNET_OK; |
429 | } | 413 | } |
430 | 414 | ||
@@ -434,8 +418,8 @@ do_send_ack (const char *msg, const void *xtra) | |||
434 | { | 418 | { |
435 | uint32_t seq; | 419 | uint32_t seq; |
436 | 420 | ||
437 | GNUNET_CHAT_send_message (room, | 421 | GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, |
438 | msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, &seq); | 422 | &seq); |
439 | return GNUNET_OK; | 423 | return GNUNET_OK; |
440 | } | 424 | } |
441 | 425 | ||
@@ -520,8 +504,8 @@ do_help (const char *args, const void *xtra) | |||
520 | int i; | 504 | int i; |
521 | 505 | ||
522 | i = 0; | 506 | i = 0; |
523 | while ((NULL != args) && | 507 | while ((NULL != args) && (0 != strlen (args)) && |
524 | (0 != strlen (args)) && (commands[i].Action != &do_help)) | 508 | (commands[i].Action != &do_help)) |
525 | { | 509 | { |
526 | if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) | 510 | if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) |
527 | { | 511 | { |
@@ -577,8 +561,9 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
577 | goto next; | 561 | goto next; |
578 | i = 0; | 562 | i = 0; |
579 | while ((NULL != commands[i].command) && | 563 | while ((NULL != commands[i].command) && |
580 | (0 != strncasecmp (commands[i].command, | 564 | (0 != |
581 | message, strlen (commands[i].command)))) | 565 | strncasecmp (commands[i].command, message, |
566 | strlen (commands[i].command)))) | ||
582 | i++; | 567 | i++; |
583 | if (GNUNET_OK != | 568 | if (GNUNET_OK != |
584 | commands[i].Action (&message[strlen (commands[i].command)], NULL)) | 569 | commands[i].Action (&message[strlen (commands[i].command)], NULL)) |
@@ -606,9 +591,8 @@ out: | |||
606 | * @param c configuration | 591 | * @param c configuration |
607 | */ | 592 | */ |
608 | static void | 593 | static void |
609 | run (void *cls, | 594 | run (void *cls, char *const *args, const char *cfgfile, |
610 | char *const *args, | 595 | const struct GNUNET_CONFIGURATION_Handle *c) |
611 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | ||
612 | { | 596 | { |
613 | GNUNET_HashCode me; | 597 | GNUNET_HashCode me; |
614 | char *my_name; | 598 | char *my_name; |
@@ -624,21 +608,13 @@ run (void *cls, | |||
624 | if (NULL == room_name) | 608 | if (NULL == room_name) |
625 | room_name = GNUNET_strdup ("gnunet"); | 609 | room_name = GNUNET_strdup ("gnunet"); |
626 | meta = GNUNET_CONTAINER_meta_data_create (); | 610 | meta = GNUNET_CONTAINER_meta_data_create (); |
627 | GNUNET_CONTAINER_meta_data_insert (meta, | 611 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE, |
628 | "<gnunet>", | 612 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
629 | EXTRACTOR_METATYPE_TITLE, | ||
630 | EXTRACTOR_METAFORMAT_UTF8, | ||
631 | "text/plain", | ||
632 | nickname, strlen (nickname) + 1); | 613 | nickname, strlen (nickname) + 1); |
633 | room = GNUNET_CHAT_join_room (cfg, | 614 | room = |
634 | nickname, | 615 | GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL, |
635 | meta, | 616 | &receive_cb, NULL, &member_list_cb, NULL, |
636 | room_name, | 617 | &confirmation_cb, NULL, &me); |
637 | -1, | ||
638 | &join_cb, NULL, | ||
639 | &receive_cb, NULL, | ||
640 | &member_list_cb, NULL, | ||
641 | &confirmation_cb, NULL, &me); | ||
642 | if (NULL == room) | 618 | if (NULL == room) |
643 | { | 619 | { |
644 | fprintf (stderr, _("Failed to join room `%s'\n"), room_name); | 620 | fprintf (stderr, _("Failed to join room `%s'\n"), room_name); |
@@ -655,8 +631,8 @@ run (void *cls, | |||
655 | handle_cmd_task = | 631 | handle_cmd_task = |
656 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, | 632 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, |
657 | &handle_command, NULL); | 633 | &handle_command, NULL); |
658 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 634 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task, |
659 | &do_stop_task, NULL); | 635 | NULL); |
660 | } | 636 | } |
661 | 637 | ||
662 | 638 | ||
@@ -688,11 +664,9 @@ main (int argc, char *const *argv) | |||
688 | fcntl (0, F_SETFL, flags); | 664 | fcntl (0, F_SETFL, flags); |
689 | #endif | 665 | #endif |
690 | return (GNUNET_OK == | 666 | return (GNUNET_OK == |
691 | GNUNET_PROGRAM_run (argc, | 667 | GNUNET_PROGRAM_run (argc, argv, "gnunet-chat", |
692 | argv, | 668 | gettext_noop ("Join a chat on GNUnet."), options, |
693 | "gnunet-chat", | 669 | &run, NULL)) ? ret : 1; |
694 | gettext_noop ("Join a chat on GNUnet."), | ||
695 | options, &run, NULL)) ? ret : 1; | ||
696 | } | 670 | } |
697 | 671 | ||
698 | /* end of gnunet-chat.c */ | 672 | /* end of gnunet-chat.c */ |