diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-02-06 23:27:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-02-06 23:27:01 +0000 |
commit | a0b3e179abb44828f76843739487b2686b14cc8e (patch) | |
tree | 52b2cfb63a66b13ce39bd1bf8bed04ff74ae102a /src/chat/gnunet-chat.c | |
parent | 7b3d9e8f57db9db2053dd7e25c9dbd92514819e0 (diff) | |
download | gnunet-a0b3e179abb44828f76843739487b2686b14cc8e.tar.gz gnunet-a0b3e179abb44828f76843739487b2686b14cc8e.zip |
more chat code from Mantis #1657
Diffstat (limited to 'src/chat/gnunet-chat.c')
-rw-r--r-- | src/chat/gnunet-chat.c | 120 |
1 files changed, 75 insertions, 45 deletions
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c index 450996382..22bdcc237 100644 --- a/src/chat/gnunet-chat.c +++ b/src/chat/gnunet-chat.c | |||
@@ -78,6 +78,20 @@ static int do_help (const char *args, const void *xtra); | |||
78 | 78 | ||
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Callback used for notification that we have joined the room. | ||
82 | * | ||
83 | * @param cls closure | ||
84 | * @return GNUNET_OK | ||
85 | */ | ||
86 | static int | ||
87 | join_cb (void *cls) | ||
88 | { | ||
89 | fprintf (stdout, _("Joined\n")); | ||
90 | return GNUNET_OK; | ||
91 | } | ||
92 | |||
93 | |||
94 | /** | ||
81 | * Callback used for notification about incoming messages. | 95 | * Callback used for notification about incoming messages. |
82 | * | 96 | * |
83 | * @param cls closure, NULL | 97 | * @param cls closure, NULL |
@@ -93,11 +107,13 @@ static int | |||
93 | receive_cb (void *cls, | 107 | receive_cb (void *cls, |
94 | struct GNUNET_CHAT_Room *room, | 108 | struct GNUNET_CHAT_Room *room, |
95 | const GNUNET_HashCode *sender, | 109 | const GNUNET_HashCode *sender, |
96 | const struct GNUNET_CONTAINER_MetaData *meta, | 110 | const struct GNUNET_CONTAINER_MetaData *member_info, |
97 | const char *message, | 111 | const char *message, |
112 | struct GNUNET_TIME_Absolute timestamp, | ||
98 | enum GNUNET_CHAT_MsgOptions options) | 113 | enum GNUNET_CHAT_MsgOptions options) |
99 | { | 114 | { |
100 | char *nick; | 115 | char *nick; |
116 | char *time; | ||
101 | const char *fmt; | 117 | const char *fmt; |
102 | 118 | ||
103 | if (NULL != sender) | 119 | if (NULL != sender) |
@@ -109,43 +125,43 @@ receive_cb (void *cls, | |||
109 | { | 125 | { |
110 | case GNUNET_CHAT_MSG_OPTION_NONE: | 126 | case GNUNET_CHAT_MSG_OPTION_NONE: |
111 | case GNUNET_CHAT_MSG_ANONYMOUS: | 127 | case GNUNET_CHAT_MSG_ANONYMOUS: |
112 | fmt = _("`%s' said: %s\n"); | 128 | fmt = _("(%s) `%s' said: %s\n"); |
113 | break; | 129 | break; |
114 | case GNUNET_CHAT_MSG_PRIVATE: | 130 | case GNUNET_CHAT_MSG_PRIVATE: |
115 | fmt = _("`%s' said to you: %s\n"); | 131 | fmt = _("(%s) `%s' said to you: %s\n"); |
116 | break; | 132 | break; |
117 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS: | 133 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS: |
118 | fmt = _("`%s' said to you: %s\n"); | 134 | fmt = _("(%s) `%s' said to you: %s\n"); |
119 | break; | 135 | break; |
120 | case GNUNET_CHAT_MSG_AUTHENTICATED: | 136 | case GNUNET_CHAT_MSG_AUTHENTICATED: |
121 | fmt = _("`%s' said for sure: %s\n"); | 137 | fmt = _("(%s) `%s' said for sure: %s\n"); |
122 | break; | 138 | break; |
123 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED: | 139 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED: |
124 | fmt = _("`%s' said to you for sure: %s\n"); | 140 | fmt = _("(%s) `%s' said to you for sure: %s\n"); |
125 | break; | 141 | break; |
126 | case GNUNET_CHAT_MSG_ACKNOWLEDGED: | 142 | case GNUNET_CHAT_MSG_ACKNOWLEDGED: |
127 | fmt = _("`%s' was confirmed that you received: %s\n"); | 143 | fmt = _("(%s) `%s' was confirmed that you received: %s\n"); |
128 | break; | 144 | break; |
129 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 145 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
130 | fmt = _("`%s' was confirmed that you and only you received: %s\n"); | 146 | fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n"); |
131 | break; | 147 | break; |
132 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 148 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
133 | fmt = _("`%s' was confirmed that you received from him or her: %s\n"); | 149 | fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n"); |
134 | break; | 150 | break; |
135 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 151 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
136 | fmt = | 152 | fmt = _("(%s) `%s' was confirmed that you and only you received from him or her: %s\n"); |
137 | _ | ||
138 | ("`%s' was confirmed that you and only you received from him or her: %s\n"); | ||
139 | break; | 153 | break; |
140 | case GNUNET_CHAT_MSG_OFF_THE_RECORD: | 154 | case GNUNET_CHAT_MSG_OFF_THE_RECORD: |
141 | fmt = _("`%s' said off the record: %s\n"); | 155 | fmt = _("(%s) `%s' said off the record: %s\n"); |
142 | break; | 156 | break; |
143 | default: | 157 | default: |
144 | fmt = _("<%s> said using an unknown message type: %s\n"); | 158 | fmt = _("(%s) <%s> said using an unknown message type: %s\n"); |
145 | break; | 159 | break; |
146 | } | 160 | } |
147 | fprintf (stdout, fmt, nick, message); | 161 | time = GNUNET_STRINGS_absolute_time_to_string (timestamp); |
162 | fprintf (stdout, fmt, time, nick, message); | ||
148 | GNUNET_free (nick); | 163 | GNUNET_free (nick); |
164 | GNUNET_free (time); | ||
149 | return GNUNET_OK; | 165 | return GNUNET_OK; |
150 | } | 166 | } |
151 | 167 | ||
@@ -168,9 +184,7 @@ confirmation_cb (void *cls, | |||
168 | struct GNUNET_CHAT_Room *room, | 184 | struct GNUNET_CHAT_Room *room, |
169 | uint32_t orig_seq_number, | 185 | uint32_t orig_seq_number, |
170 | struct GNUNET_TIME_Absolute timestamp, | 186 | struct GNUNET_TIME_Absolute timestamp, |
171 | const GNUNET_HashCode *receiver, | 187 | const GNUNET_HashCode *receiver) |
172 | const GNUNET_HashCode *msg_hash, | ||
173 | const struct GNUNET_CRYPTO_RsaSignature *receipt) | ||
174 | { | 188 | { |
175 | char *nick; | 189 | char *nick; |
176 | 190 | ||
@@ -248,18 +262,6 @@ member_list_cb (void *cls, | |||
248 | 262 | ||
249 | 263 | ||
250 | static int | 264 | static int |
251 | do_transmit (const char *msg, const void *xtra) | ||
252 | { | ||
253 | uint32_t seq; | ||
254 | GNUNET_CHAT_send_message (room, | ||
255 | msg, | ||
256 | GNUNET_CHAT_MSG_OPTION_NONE, | ||
257 | NULL, &seq); | ||
258 | return GNUNET_OK; | ||
259 | } | ||
260 | |||
261 | |||
262 | static int | ||
263 | do_join (const char *arg, const void *xtra) | 265 | do_join (const char *arg, const void *xtra) |
264 | { | 266 | { |
265 | char *my_name; | 267 | char *my_name; |
@@ -276,6 +278,7 @@ do_join (const char *arg, const void *xtra) | |||
276 | meta, | 278 | meta, |
277 | room_name, | 279 | room_name, |
278 | -1, | 280 | -1, |
281 | &join_cb, NULL, | ||
279 | &receive_cb, NULL, | 282 | &receive_cb, NULL, |
280 | &member_list_cb, NULL, | 283 | &member_list_cb, NULL, |
281 | &confirmation_cb, NULL, &me); | 284 | &confirmation_cb, NULL, &me); |
@@ -285,7 +288,7 @@ do_join (const char *arg, const void *xtra) | |||
285 | return GNUNET_SYSERR; | 288 | return GNUNET_SYSERR; |
286 | } | 289 | } |
287 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 290 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); |
288 | fprintf (stdout, _("Joined room `%s' as user `%s'\n"), room_name, my_name); | 291 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name); |
289 | GNUNET_free (my_name); | 292 | GNUNET_free (my_name); |
290 | return GNUNET_OK; | 293 | return GNUNET_OK; |
291 | } | 294 | } |
@@ -315,6 +318,7 @@ do_nick (const char *msg, const void *xtra) | |||
315 | meta, | 318 | meta, |
316 | room_name, | 319 | room_name, |
317 | -1, | 320 | -1, |
321 | &join_cb, NULL, | ||
318 | &receive_cb, NULL, | 322 | &receive_cb, NULL, |
319 | &member_list_cb, NULL, | 323 | &member_list_cb, NULL, |
320 | &confirmation_cb, NULL, &me); | 324 | &confirmation_cb, NULL, &me); |
@@ -355,7 +359,19 @@ do_names (const char *msg, const void *xtra) | |||
355 | 359 | ||
356 | 360 | ||
357 | static int | 361 | static int |
358 | do_pm (const char *msg, const void *xtra) | 362 | do_send (const char *msg, const void *xtra) |
363 | { | ||
364 | uint32_t seq; | ||
365 | GNUNET_CHAT_send_message (room, | ||
366 | msg, | ||
367 | GNUNET_CHAT_MSG_OPTION_NONE, | ||
368 | NULL, &seq); | ||
369 | return GNUNET_OK; | ||
370 | } | ||
371 | |||
372 | |||
373 | static int | ||
374 | do_send_pm (const char *msg, const void *xtra) | ||
359 | { | 375 | { |
360 | char *user; | 376 | char *user; |
361 | GNUNET_HashCode uid; | 377 | GNUNET_HashCode uid; |
@@ -404,7 +420,7 @@ do_pm (const char *msg, const void *xtra) | |||
404 | 420 | ||
405 | 421 | ||
406 | static int | 422 | static int |
407 | do_transmit_sig (const char *msg, const void *xtra) | 423 | do_send_sig (const char *msg, const void *xtra) |
408 | { | 424 | { |
409 | uint32_t seq; | 425 | uint32_t seq; |
410 | GNUNET_CHAT_send_message (room, | 426 | GNUNET_CHAT_send_message (room, |
@@ -416,7 +432,7 @@ do_transmit_sig (const char *msg, const void *xtra) | |||
416 | 432 | ||
417 | 433 | ||
418 | static int | 434 | static int |
419 | do_transmit_ack (const char *msg, const void *xtra) | 435 | do_send_ack (const char *msg, const void *xtra) |
420 | { | 436 | { |
421 | uint32_t seq; | 437 | uint32_t seq; |
422 | GNUNET_CHAT_send_message (room, | 438 | GNUNET_CHAT_send_message (room, |
@@ -428,6 +444,18 @@ do_transmit_ack (const char *msg, const void *xtra) | |||
428 | 444 | ||
429 | 445 | ||
430 | static int | 446 | static int |
447 | do_send_anonymous (const char *msg, const void *xtra) | ||
448 | { | ||
449 | uint32_t seq; | ||
450 | GNUNET_CHAT_send_message (room, | ||
451 | msg, | ||
452 | GNUNET_CHAT_MSG_ANONYMOUS, | ||
453 | NULL, &seq); | ||
454 | return GNUNET_OK; | ||
455 | } | ||
456 | |||
457 | |||
458 | static int | ||
431 | do_quit (const char *args, const void *xtra) | 459 | do_quit (const char *args, const void *xtra) |
432 | { | 460 | { |
433 | return GNUNET_SYSERR; | 461 | return GNUNET_SYSERR; |
@@ -454,19 +482,24 @@ static struct ChatCommand commands[] = { | |||
454 | gettext_noop | 482 | gettext_noop |
455 | ("Use `/nick nickname' to change your nickname. This will cause you to" | 483 | ("Use `/nick nickname' to change your nickname. This will cause you to" |
456 | " leave the current room and immediately rejoin it with the new name.")}, | 484 | " leave the current room and immediately rejoin it with the new name.")}, |
457 | {"/msg ", &do_pm, | 485 | {"/msg ", &do_send_pm, |
458 | gettext_noop | 486 | gettext_noop |
459 | ("Use `/msg nickname message' to send a private message to the specified" | 487 | ("Use `/msg nickname message' to send a private message to the specified" |
460 | " user")}, | 488 | " user")}, |
461 | {"/notice ", &do_pm, | 489 | {"/notice ", &do_send_pm, |
462 | gettext_noop ("The `/notice' command is an alias for `/msg'")}, | 490 | gettext_noop ("The `/notice' command is an alias for `/msg'")}, |
463 | {"/query ", &do_pm, | 491 | {"/query ", &do_send_pm, |
464 | gettext_noop ("The `/query' command is an alias for `/msg'")}, | 492 | gettext_noop ("The `/query' command is an alias for `/msg'")}, |
465 | {"/sig ", &do_transmit_sig, | 493 | {"/sig ", &do_send_sig, |
466 | gettext_noop ("Use `/sig message' to send a signed public message")}, | 494 | gettext_noop ("Use `/sig message' to send a signed public message")}, |
467 | {"/ack ", &do_transmit_ack, | 495 | {"/ack ", &do_send_ack, |
468 | gettext_noop | 496 | gettext_noop |
469 | ("Use `/ack message' to require signed acknowledgment of the message")}, | 497 | ("Use `/ack message' to require signed acknowledgment of the message")}, |
498 | {"/anonymous ", &do_send_anonymous, | ||
499 | gettext_noop | ||
500 | ("Use `/anonymous message' to send a public anonymous message")}, | ||
501 | {"/anon ", &do_send_anonymous, | ||
502 | gettext_noop ("The `/anon' command is an alias for `/anonymous'")}, | ||
470 | {"/quit", &do_quit, | 503 | {"/quit", &do_quit, |
471 | gettext_noop ("Use `/quit' to terminate gnunet-chat")}, | 504 | gettext_noop ("Use `/quit' to terminate gnunet-chat")}, |
472 | {"/leave", &do_quit, | 505 | {"/leave", &do_quit, |
@@ -479,13 +512,9 @@ static struct ChatCommand commands[] = { | |||
479 | /* Add standard commands: | 512 | /* Add standard commands: |
480 | /whois (print metadata), | 513 | /whois (print metadata), |
481 | /ignore (set flag, check on receive!) */ | 514 | /ignore (set flag, check on receive!) */ |
482 | /* Add special commands (currently supported): | ||
483 | + anonymous msgs | ||
484 | + authenticated msgs | ||
485 | */ | ||
486 | /* the following three commands must be last! */ | 515 | /* the following three commands must be last! */ |
487 | {"/", &do_unknown, NULL}, | 516 | {"/", &do_unknown, NULL}, |
488 | {"", &do_transmit, NULL}, | 517 | {"", &do_send, NULL}, |
489 | {NULL, NULL, NULL}, | 518 | {NULL, NULL, NULL}, |
490 | }; | 519 | }; |
491 | 520 | ||
@@ -615,6 +644,7 @@ run (void *cls, | |||
615 | meta, | 644 | meta, |
616 | room_name, | 645 | room_name, |
617 | -1, | 646 | -1, |
647 | &join_cb, NULL, | ||
618 | &receive_cb, NULL, | 648 | &receive_cb, NULL, |
619 | &member_list_cb, NULL, | 649 | &member_list_cb, NULL, |
620 | &confirmation_cb, NULL, &me); | 650 | &confirmation_cb, NULL, &me); |
@@ -628,7 +658,7 @@ run (void *cls, | |||
628 | return; | 658 | return; |
629 | } | 659 | } |
630 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 660 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); |
631 | fprintf (stdout, _("Joined room `%s' as user `%s'\n"), room_name, my_name); | 661 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name); |
632 | GNUNET_free (my_name); | 662 | GNUNET_free (my_name); |
633 | handle_cmd_task = | 663 | handle_cmd_task = |
634 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, | 664 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, |