diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-10 17:31:58 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-10 17:31:58 -0400 |
commit | 0b18dcda6f6bd181a164755a82decc7ae08c603e (patch) | |
tree | 6044ddb6585c43a3665e06e43e353205e8931367 /core/Messenger.c | |
parent | f471602d5d7ed9b5d8c92f7a55d2e6589c15577c (diff) |
Per friend request data added.
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 0660ba94..da845560 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -31,13 +31,14 @@ typedef struct | |||
31 | int crypt_connection_id; | 31 | int crypt_connection_id; |
32 | int friend_request_id; //id of the friend request corresponding to the current friend request to the current friend. | 32 | int friend_request_id; //id of the friend request corresponding to the current friend request to the current friend. |
33 | uint8_t status;//0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. | 33 | uint8_t status;//0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. |
34 | uint8_t info[MAX_DATA_SIZE]; //the data that is sent during the friend requests we do | ||
35 | uint16_t info_size; //length of the info | ||
34 | 36 | ||
35 | }Friend; | 37 | }Friend; |
36 | 38 | ||
37 | 39 | ||
38 | uint8_t info[MAX_DATA_SIZE]; //the data that is sent during the friend requests we do | ||
39 | 40 | ||
40 | uint16_t info_size; //length of the info | 41 | |
41 | 42 | ||
42 | #define MAX_NUM_FRIENDS 256 | 43 | #define MAX_NUM_FRIENDS 256 |
43 | 44 | ||
@@ -68,11 +69,19 @@ int getfriend_id(uint8_t * client_id) | |||
68 | 69 | ||
69 | 70 | ||
70 | //add a friend | 71 | //add a friend |
71 | //client_id is the client i of the friend | 72 | //set the data that will be sent along with friend request |
73 | //client_id is the client id of the friend | ||
74 | //data is the data and length is the length | ||
72 | //returns the friend number if success | 75 | //returns the friend number if success |
73 | //return -1 if failure. | 76 | //return -1 if failure. |
74 | int m_addfriend(uint8_t * client_id) | 77 | int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) |
75 | { | 78 | { |
79 | if(length == 0 || length > MAX_DATA_SIZE - 1 - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES | ||
80 | - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES) | ||
81 | { | ||
82 | return -1; | ||
83 | } | ||
84 | |||
76 | if(getfriend_id(client_id) != -1) | 85 | if(getfriend_id(client_id) != -1) |
77 | { | 86 | { |
78 | return -1; | 87 | return -1; |
@@ -86,6 +95,10 @@ int m_addfriend(uint8_t * client_id) | |||
86 | friendlist[i].status = 1; | 95 | friendlist[i].status = 1; |
87 | friendlist[i].friend_request_id = -1; | 96 | friendlist[i].friend_request_id = -1; |
88 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); | 97 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); |
98 | |||
99 | memcpy(friendlist[i].info, data, length); | ||
100 | friendlist[i].info_size = length; | ||
101 | |||
89 | numfriends++; | 102 | numfriends++; |
90 | return i; | 103 | return i; |
91 | } | 104 | } |
@@ -176,19 +189,6 @@ int m_sendmessage(int friendnumber, uint8_t * message, uint32_t length) | |||
176 | 189 | ||
177 | } | 190 | } |
178 | 191 | ||
179 | //set the data that will be sent along with friend requests | ||
180 | //return -1 if failure | ||
181 | //return 0 if success | ||
182 | int m_setinfo(uint8_t * data, uint16_t length) | ||
183 | { | ||
184 | if(length == 0 || length > MAX_DATA_SIZE - 1 - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES) | ||
185 | { | ||
186 | return -1; | ||
187 | } | ||
188 | memcpy(info, data, length); | ||
189 | info_size = length; | ||
190 | return 0; | ||
191 | } | ||
192 | 192 | ||
193 | void (*friend_request)(uint8_t *, uint8_t *, uint16_t); | 193 | void (*friend_request)(uint8_t *, uint8_t *, uint16_t); |
194 | 194 | ||
@@ -235,7 +235,8 @@ void doFriends() | |||
235 | //printf("\n%u %u %u\n", friendip.ip.i, request, friendlist[i].friend_request_id); | 235 | //printf("\n%u %u %u\n", friendip.ip.i, request, friendlist[i].friend_request_id); |
236 | if(friendip.ip.i > 1 && request == -1) | 236 | if(friendip.ip.i > 1 && request == -1) |
237 | { | 237 | { |
238 | friendlist[i].friend_request_id = send_friendrequest(friendlist[i].client_id, friendip, info, info_size); | 238 | friendlist[i].friend_request_id = send_friendrequest(friendlist[i].client_id, |
239 | friendip, friendlist[i].info, friendlist[i].info_size); | ||
239 | friendlist[i].status = 2; | 240 | friendlist[i].status = 2; |
240 | } | 241 | } |
241 | } | 242 | } |