diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-16 20:59:53 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-16 20:59:53 -0400 |
commit | dd12d464de48ca478540457cee4207c38ce69982 (patch) | |
tree | 66d110bc5b965e3aae449893cc36800e1e318289 | |
parent | 0b7479e75804dccf837e33ed68f36a78f55bf099 (diff) |
Functions to get name of peer in group chat added.
Group message callback modified.
-rw-r--r-- | testing/nTox.c | 6 | ||||
-rw-r--r-- | toxcore/Messenger.c | 24 | ||||
-rw-r--r-- | toxcore/Messenger.h | 14 | ||||
-rw-r--r-- | toxcore/group_chats.c | 20 | ||||
-rw-r--r-- | toxcore/group_chats.h | 13 | ||||
-rw-r--r-- | toxcore/tox.c | 16 | ||||
-rw-r--r-- | toxcore/tox.h | 12 |
7 files changed, 93 insertions, 12 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index e87b4b83..cf79b3c4 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -588,10 +588,12 @@ void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *use | |||
588 | new_lines(msg); | 588 | new_lines(msg); |
589 | } | 589 | } |
590 | 590 | ||
591 | void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata) | 591 | void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata) |
592 | { | 592 | { |
593 | char msg[256 + length]; | 593 | char msg[256 + length]; |
594 | sprintf(msg, "[g] %u: %s", groupnumber, message); | 594 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
595 | tox_group_peername(m, groupnumber, peernumber, name); | ||
596 | sprintf(msg, "[g] %u: <%s>: %s", groupnumber, name, message); | ||
595 | new_lines(msg); | 597 | new_lines(msg); |
596 | } | 598 | } |
597 | 599 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index a27a44dc..0aacc703 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -686,9 +686,9 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, u | |||
686 | 686 | ||
687 | /* Set the callback for group messages. | 687 | /* Set the callback for group messages. |
688 | * | 688 | * |
689 | * Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | 689 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
690 | */ | 690 | */ |
691 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 691 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *), |
692 | void *userdata) | 692 | void *userdata) |
693 | { | 693 | { |
694 | m->group_message = function; | 694 | m->group_message = function; |
@@ -705,7 +705,7 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m | |||
705 | } | 705 | } |
706 | 706 | ||
707 | if (m->group_message) | 707 | if (m->group_message) |
708 | (*m->group_message)(m, i, message, length, m->group_invite_userdata); | 708 | (*m->group_message)(m, i, peer_number, message, length, m->group_invite_userdata); |
709 | } | 709 | } |
710 | 710 | ||
711 | /* Creates a new groupchat and puts it in the chats array. | 711 | /* Creates a new groupchat and puts it in the chats array. |
@@ -786,6 +786,24 @@ int del_groupchat(Messenger *m, int groupnumber) | |||
786 | return 0; | 786 | return 0; |
787 | } | 787 | } |
788 | 788 | ||
789 | /* Copy the name of peernumber who is in groupnumber to name. | ||
790 | * name must be at least MAX_NICK_BYTES long. | ||
791 | * | ||
792 | * return length of name if success | ||
793 | * return -1 if failure | ||
794 | */ | ||
795 | int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name) | ||
796 | { | ||
797 | if ((unsigned int)groupnumber >= m->numchats) | ||
798 | return -1; | ||
799 | |||
800 | if (m->chats == NULL) | ||
801 | return -1; | ||
802 | |||
803 | if (m->chats[groupnumber] == NULL) | ||
804 | return -1; | ||
805 | return group_peername(m->chats[groupnumber], peernumber, name); | ||
806 | } | ||
789 | /* return 1 if that friend was invited to the group | 807 | /* return 1 if that friend was invited to the group |
790 | * return 0 if the friend was not or error. | 808 | * return 0 if the friend was not or error. |
791 | */ | 809 | */ |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index bfcc69df..2aabd90d 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -159,7 +159,7 @@ typedef struct Messenger { | |||
159 | void *friend_connectionstatuschange_userdata; | 159 | void *friend_connectionstatuschange_userdata; |
160 | void (*group_invite)(struct Messenger *m, int, uint8_t *, void *); | 160 | void (*group_invite)(struct Messenger *m, int, uint8_t *, void *); |
161 | void *group_invite_userdata; | 161 | void *group_invite_userdata; |
162 | void (*group_message)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | 162 | void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *); |
163 | void *group_message_userdata; | 163 | void *group_message_userdata; |
164 | 164 | ||
165 | } Messenger; | 165 | } Messenger; |
@@ -382,9 +382,9 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, u | |||
382 | 382 | ||
383 | /* Set the callback for group messages. | 383 | /* Set the callback for group messages. |
384 | * | 384 | * |
385 | * Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | 385 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
386 | */ | 386 | */ |
387 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 387 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *), |
388 | void *userdata); | 388 | void *userdata); |
389 | 389 | ||
390 | /* Creates a new groupchat and puts it in the chats array. | 390 | /* Creates a new groupchat and puts it in the chats array. |
@@ -401,6 +401,14 @@ int add_groupchat(Messenger *m); | |||
401 | */ | 401 | */ |
402 | int del_groupchat(Messenger *m, int groupnumber); | 402 | int del_groupchat(Messenger *m, int groupnumber); |
403 | 403 | ||
404 | /* Copy the name of peernumber who is in groupnumber to name. | ||
405 | * name must be at least MAX_NICK_BYTES long. | ||
406 | * | ||
407 | * return length of name if success | ||
408 | * return -1 if failure | ||
409 | */ | ||
410 | int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name); | ||
411 | |||
404 | /* invite friendnumber to groupnumber | 412 | /* invite friendnumber to groupnumber |
405 | * return 0 on success | 413 | * return 0 on success |
406 | * return -1 on failure | 414 | * return -1 on failure |
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index f37c6a9c..23018cab 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c | |||
@@ -278,6 +278,26 @@ static int delpeer(Group_Chat *chat, uint8_t *client_id) | |||
278 | 278 | ||
279 | return -1; | 279 | return -1; |
280 | } | 280 | } |
281 | |||
282 | /* Copy the name of peernum to name. | ||
283 | * name must be at least MAX_NICK_BYTES long. | ||
284 | * | ||
285 | * return length of name if success | ||
286 | * return -1 if failure | ||
287 | */ | ||
288 | int group_peername(Group_Chat *chat, int peernum, uint8_t *name) | ||
289 | { | ||
290 | if ((uint32_t)peernum >= chat->numpeers) | ||
291 | return -1; | ||
292 | if (chat->group[peernum].nick_len == 0) { | ||
293 | memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/ | ||
294 | return 10; | ||
295 | } | ||
296 | memcpy(name, chat->group[peernum].nick, chat->group[peernum].nick_len); | ||
297 | return chat->group[peernum].nick_len; | ||
298 | } | ||
299 | |||
300 | |||
281 | /* min time between pings sent to one peer in seconds */ | 301 | /* min time between pings sent to one peer in seconds */ |
282 | #define PING_TIMEOUT 5 | 302 | #define PING_TIMEOUT 5 |
283 | static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum) | 303 | static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum) |
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index 78a5488c..7089458c 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h | |||
@@ -31,6 +31,8 @@ | |||
31 | extern "C" { | 31 | extern "C" { |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define MAX_NICK_BYTES 128 | ||
35 | |||
34 | typedef struct { | 36 | typedef struct { |
35 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | 37 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; |
36 | uint64_t pingid; | 38 | uint64_t pingid; |
@@ -39,6 +41,9 @@ typedef struct { | |||
39 | uint64_t last_recv; | 41 | uint64_t last_recv; |
40 | uint64_t last_recv_msgping; | 42 | uint64_t last_recv_msgping; |
41 | uint32_t last_message_number; | 43 | uint32_t last_message_number; |
44 | |||
45 | uint8_t nick[MAX_NICK_BYTES]; | ||
46 | uint16_t nick_len; | ||
42 | } Group_Peer; | 47 | } Group_Peer; |
43 | 48 | ||
44 | typedef struct { | 49 | typedef struct { |
@@ -65,6 +70,14 @@ typedef struct Group_Chat { | |||
65 | 70 | ||
66 | } Group_Chat; | 71 | } Group_Chat; |
67 | 72 | ||
73 | /* Copy the name of peernum to name. | ||
74 | * name must be at least MAX_NICK_BYTES long. | ||
75 | * | ||
76 | * return length of name if success | ||
77 | * return -1 if failure | ||
78 | */ | ||
79 | int group_peername(Group_Chat *chat, int peernum, uint8_t *name); | ||
80 | |||
68 | /* | 81 | /* |
69 | * Set callback function for chat messages. | 82 | * Set callback function for chat messages. |
70 | * | 83 | * |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 80d64626..78074db1 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -379,9 +379,9 @@ void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, | |||
379 | } | 379 | } |
380 | /* Set the callback for group messages. | 380 | /* Set the callback for group messages. |
381 | * | 381 | * |
382 | * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | 382 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
383 | */ | 383 | */ |
384 | void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 384 | void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *), |
385 | void *userdata) | 385 | void *userdata) |
386 | { | 386 | { |
387 | Messenger *m = tox; | 387 | Messenger *m = tox; |
@@ -407,6 +407,18 @@ int tox_del_groupchat(void *tox, int groupnumber) | |||
407 | Messenger *m = tox; | 407 | Messenger *m = tox; |
408 | return del_groupchat(m, groupnumber); | 408 | return del_groupchat(m, groupnumber); |
409 | } | 409 | } |
410 | |||
411 | /* Copy the name of peernumber who is in groupnumber to name. | ||
412 | * name must be at least MAX_NICK_BYTES long. | ||
413 | * | ||
414 | * return length of name if success | ||
415 | * return -1 if failure | ||
416 | */ | ||
417 | int tox_group_peername(void *tox, int groupnumber, int peernumber, uint8_t *name) | ||
418 | { | ||
419 | Messenger *m = tox; | ||
420 | return m_group_peername(m, groupnumber, peernumber, name); | ||
421 | } | ||
410 | /* invite friendnumber to groupnumber | 422 | /* invite friendnumber to groupnumber |
411 | * return 0 on success | 423 | * return 0 on success |
412 | * return -1 on failure | 424 | * return -1 on failure |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 89242f1f..cc7fc5ec 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -357,9 +357,9 @@ void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t | |||
357 | 357 | ||
358 | /* Set the callback for group messages. | 358 | /* Set the callback for group messages. |
359 | * | 359 | * |
360 | * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | 360 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
361 | */ | 361 | */ |
362 | void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), | 362 | void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t *, uint16_t, void *), |
363 | void *userdata); | 363 | void *userdata); |
364 | 364 | ||
365 | /* Creates a new groupchat and puts it in the chats array. | 365 | /* Creates a new groupchat and puts it in the chats array. |
@@ -376,6 +376,14 @@ int tox_add_groupchat(Tox *tox); | |||
376 | */ | 376 | */ |
377 | int tox_del_groupchat(Tox *tox, int groupnumber); | 377 | int tox_del_groupchat(Tox *tox, int groupnumber); |
378 | 378 | ||
379 | /* Copy the name of peernumber who is in groupnumber to name. | ||
380 | * name must be at least TOX_MAX_NAME_LENGTH long. | ||
381 | * | ||
382 | * return length of name if success | ||
383 | * return -1 if failure | ||
384 | */ | ||
385 | int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name); | ||
386 | |||
379 | /* invite friendnumber to groupnumber | 387 | /* invite friendnumber to groupnumber |
380 | * return 0 on success | 388 | * return 0 on success |
381 | * return -1 on failure | 389 | * return -1 on failure |