diff options
Diffstat (limited to 'src/chat/gnunet-chat.c')
-rw-r--r-- | src/chat/gnunet-chat.c | 96 |
1 files changed, 83 insertions, 13 deletions
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c index 4abc58c9f..fb958d98a 100644 --- a/src/chat/gnunet-chat.c +++ b/src/chat/gnunet-chat.c | |||
@@ -114,14 +114,27 @@ receive_cb (void *cls, struct GNUNET_CHAT_Room *room, | |||
114 | const char *message, struct GNUNET_TIME_Absolute timestamp, | 114 | const char *message, struct GNUNET_TIME_Absolute timestamp, |
115 | enum GNUNET_CHAT_MsgOptions options) | 115 | enum GNUNET_CHAT_MsgOptions options) |
116 | { | 116 | { |
117 | char *non_unique_nick; | ||
117 | char *nick; | 118 | char *nick; |
119 | int nick_is_a_dup; | ||
118 | char *time; | 120 | char *time; |
119 | const char *fmt; | 121 | const char *fmt; |
120 | 122 | ||
121 | if (NULL != sender) | 123 | if (NULL == sender) |
122 | nick = GNUNET_PSEUDONYM_id_to_name (cfg, sender); | ||
123 | else | ||
124 | nick = GNUNET_strdup (_("anonymous")); | 124 | nick = GNUNET_strdup (_("anonymous")); |
125 | else | ||
126 | { | ||
127 | if (GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, | ||
128 | sender, NULL, NULL, &non_unique_nick, &nick_is_a_dup) | ||
129 | || (nick_is_a_dup == GNUNET_YES)) | ||
130 | { | ||
131 | GNUNET_free (non_unique_nick); | ||
132 | non_unique_nick = GNUNET_strdup (_("anonymous")); | ||
133 | } | ||
134 | nick = GNUNET_PSEUDONYM_name_uniquify (cfg, sender, non_unique_nick, NULL); | ||
135 | GNUNET_free (non_unique_nick); | ||
136 | } | ||
137 | |||
125 | fmt = NULL; | 138 | fmt = NULL; |
126 | switch ((int) options) | 139 | switch ((int) options) |
127 | { | 140 | { |
@@ -188,9 +201,20 @@ confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room, | |||
188 | const GNUNET_HashCode * receiver) | 201 | const GNUNET_HashCode * receiver) |
189 | { | 202 | { |
190 | char *nick; | 203 | char *nick; |
204 | char *unique_nick; | ||
205 | int nick_is_a_dup; | ||
191 | 206 | ||
192 | nick = GNUNET_PSEUDONYM_id_to_name (cfg, receiver); | 207 | if (GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
193 | FPRINTF (stdout, _("'%s' acknowledged message #%d\n"), nick, orig_seq_number); | 208 | receiver, NULL, NULL, &nick, &nick_is_a_dup) |
209 | || (nick_is_a_dup == GNUNET_YES)) | ||
210 | { | ||
211 | GNUNET_free (nick); | ||
212 | nick = GNUNET_strdup (_("anonymous")); | ||
213 | } | ||
214 | unique_nick = GNUNET_PSEUDONYM_name_uniquify (cfg, receiver, nick, NULL); | ||
215 | GNUNET_free (nick); | ||
216 | FPRINTF (stdout, _("'%s' acknowledged message #%d\n"), unique_nick, orig_seq_number); | ||
217 | GNUNET_free (unique_nick); | ||
194 | return GNUNET_OK; | 218 | return GNUNET_OK; |
195 | } | 219 | } |
196 | 220 | ||
@@ -210,7 +234,8 @@ member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info, | |||
210 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, | 234 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, |
211 | enum GNUNET_CHAT_MsgOptions options) | 235 | enum GNUNET_CHAT_MsgOptions options) |
212 | { | 236 | { |
213 | char *nick; | 237 | char *nick, *non_unique_nick; |
238 | int nick_is_a_dup; | ||
214 | GNUNET_HashCode id; | 239 | GNUNET_HashCode id; |
215 | struct UserList *pos; | 240 | struct UserList *pos; |
216 | struct UserList *prev; | 241 | struct UserList *prev; |
@@ -218,7 +243,16 @@ member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info, | |||
218 | GNUNET_CRYPTO_hash (member_id, | 243 | GNUNET_CRYPTO_hash (member_id, |
219 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 244 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
220 | &id); | 245 | &id); |
221 | nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id); | 246 | if (GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
247 | &id, NULL, NULL, &non_unique_nick, &nick_is_a_dup) | ||
248 | || (nick_is_a_dup == GNUNET_YES)) | ||
249 | { | ||
250 | GNUNET_free (non_unique_nick); | ||
251 | non_unique_nick = GNUNET_strdup (_("anonymous")); | ||
252 | } | ||
253 | nick = GNUNET_PSEUDONYM_name_uniquify (cfg, &id, non_unique_nick, NULL); | ||
254 | GNUNET_free (non_unique_nick); | ||
255 | |||
222 | FPRINTF (stdout, | 256 | FPRINTF (stdout, |
223 | member_info != | 257 | member_info != |
224 | NULL ? _("`%s' entered the room\n") : _("`%s' left the room\n"), | 258 | NULL ? _("`%s' entered the room\n") : _("`%s' left the room\n"), |
@@ -267,6 +301,7 @@ static int | |||
267 | do_join (const char *arg, const void *xtra) | 301 | do_join (const char *arg, const void *xtra) |
268 | { | 302 | { |
269 | char *my_name; | 303 | char *my_name; |
304 | int my_name_is_a_dup; | ||
270 | GNUNET_HashCode me; | 305 | GNUNET_HashCode me; |
271 | 306 | ||
272 | if (arg[0] == '#') | 307 | if (arg[0] == '#') |
@@ -284,7 +319,16 @@ do_join (const char *arg, const void *xtra) | |||
284 | FPRINTF (stdout, "%s", _("Could not change username\n")); | 319 | FPRINTF (stdout, "%s", _("Could not change username\n")); |
285 | return GNUNET_SYSERR; | 320 | return GNUNET_SYSERR; |
286 | } | 321 | } |
287 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 322 | if ((GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
323 | &me, NULL, NULL, &my_name, &my_name_is_a_dup)) || | ||
324 | (my_name_is_a_dup == GNUNET_YES)) | ||
325 | { | ||
326 | GNUNET_free (my_name); | ||
327 | my_name = GNUNET_strdup (_("anonymous")); | ||
328 | } | ||
329 | /* Don't uniquify our own name - other people will have a different | ||
330 | * suffix for our own name anyway. | ||
331 | */ | ||
288 | FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, | 332 | FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, |
289 | my_name); | 333 | my_name); |
290 | GNUNET_free (my_name); | 334 | GNUNET_free (my_name); |
@@ -296,6 +340,7 @@ static int | |||
296 | do_nick (const char *msg, const void *xtra) | 340 | do_nick (const char *msg, const void *xtra) |
297 | { | 341 | { |
298 | char *my_name; | 342 | char *my_name; |
343 | int my_name_is_a_dup; | ||
299 | GNUNET_HashCode me; | 344 | GNUNET_HashCode me; |
300 | 345 | ||
301 | GNUNET_CHAT_leave_room (room); | 346 | GNUNET_CHAT_leave_room (room); |
@@ -316,7 +361,13 @@ do_nick (const char *msg, const void *xtra) | |||
316 | FPRINTF (stdout, "%s", _("Could not change username\n")); | 361 | FPRINTF (stdout, "%s", _("Could not change username\n")); |
317 | return GNUNET_SYSERR; | 362 | return GNUNET_SYSERR; |
318 | } | 363 | } |
319 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 364 | if ((GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
365 | &me, NULL, NULL, &my_name, &my_name_is_a_dup)) || | ||
366 | (my_name_is_a_dup == GNUNET_YES)) | ||
367 | { | ||
368 | GNUNET_free (my_name); | ||
369 | my_name = GNUNET_strdup (_("anonymous")); | ||
370 | } | ||
320 | FPRINTF (stdout, _("Changed username to `%s'\n"), my_name); | 371 | FPRINTF (stdout, _("Changed username to `%s'\n"), my_name); |
321 | GNUNET_free (my_name); | 372 | GNUNET_free (my_name); |
322 | return GNUNET_OK; | 373 | return GNUNET_OK; |
@@ -327,6 +378,8 @@ static int | |||
327 | do_names (const char *msg, const void *xtra) | 378 | do_names (const char *msg, const void *xtra) |
328 | { | 379 | { |
329 | char *name; | 380 | char *name; |
381 | char *unique_name; | ||
382 | int name_is_a_dup; | ||
330 | struct UserList *pos; | 383 | struct UserList *pos; |
331 | GNUNET_HashCode pid; | 384 | GNUNET_HashCode pid; |
332 | 385 | ||
@@ -337,9 +390,17 @@ do_names (const char *msg, const void *xtra) | |||
337 | GNUNET_CRYPTO_hash (&pos->pkey, | 390 | GNUNET_CRYPTO_hash (&pos->pkey, |
338 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 391 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
339 | &pid); | 392 | &pid); |
340 | name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid); | 393 | if (GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
341 | FPRINTF (stdout, "`%s' ", name); | 394 | &pid, NULL, NULL, &name, &name_is_a_dup) |
395 | || (name_is_a_dup == GNUNET_YES)) | ||
396 | { | ||
397 | GNUNET_free (name); | ||
398 | name = GNUNET_strdup (_("anonymous")); | ||
399 | } | ||
400 | unique_name = GNUNET_PSEUDONYM_name_uniquify (cfg, &pid, name, NULL); | ||
342 | GNUNET_free (name); | 401 | GNUNET_free (name); |
402 | FPRINTF (stdout, "`%s' ", unique_name); | ||
403 | GNUNET_free (unique_name); | ||
343 | pos = pos->next; | 404 | pos = pos->next; |
344 | } | 405 | } |
345 | FPRINTF (stdout, "%s", "\n"); | 406 | FPRINTF (stdout, "%s", "\n"); |
@@ -376,7 +437,9 @@ do_send_pm (const char *msg, const void *xtra) | |||
376 | msg += strlen (user) + 1; | 437 | msg += strlen (user) + 1; |
377 | if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid)) | 438 | if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid)) |
378 | { | 439 | { |
379 | FPRINTF (stderr, _("Unknown user `%s'\n"), user); | 440 | FPRINTF (stderr, |
441 | _("Unknown user `%s'. Make sure you specify its numeric suffix, if any.\n"), | ||
442 | user); | ||
380 | GNUNET_free (user); | 443 | GNUNET_free (user); |
381 | return GNUNET_OK; | 444 | return GNUNET_OK; |
382 | } | 445 | } |
@@ -598,6 +661,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
598 | { | 661 | { |
599 | GNUNET_HashCode me; | 662 | GNUNET_HashCode me; |
600 | char *my_name; | 663 | char *my_name; |
664 | int my_name_is_a_dup; | ||
601 | 665 | ||
602 | cfg = c; | 666 | cfg = c; |
603 | /* check arguments */ | 667 | /* check arguments */ |
@@ -626,7 +690,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
626 | ret = -1; | 690 | ret = -1; |
627 | return; | 691 | return; |
628 | } | 692 | } |
629 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 693 | if ((GNUNET_OK != GNUNET_PSEUDONYM_get_info (cfg, |
694 | &me, NULL, NULL, &my_name, &my_name_is_a_dup)) || | ||
695 | (my_name_is_a_dup == GNUNET_YES)) | ||
696 | { | ||
697 | GNUNET_free (my_name); | ||
698 | my_name = GNUNET_strdup (_("anonymous")); | ||
699 | } | ||
630 | FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, | 700 | FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, |
631 | my_name); | 701 | my_name); |
632 | GNUNET_free (my_name); | 702 | GNUNET_free (my_name); |