diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-26 05:38:35 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-26 05:38:35 -0700 |
commit | 8c70b7c11d6d5acc08e234554f187b18876fd5d3 (patch) | |
tree | 8ef350879553acd22c20887016f4249815ab1d0f /core/Messenger.c | |
parent | 63375b68b63d33c8437f313b2041b559c32c945b (diff) | |
parent | 1577a1eb61b6e2839aec962025d78e8703be3661 (diff) |
Merge pull request #103 from SilentSand/master
Licensing
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 042d5325..d58e895c 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -1,26 +1,25 @@ | |||
1 | /* Messenger.c | 1 | /* Messenger.c |
2 | * | 2 | * |
3 | * An implementation of a simple text chat only messenger on the tox network core. | 3 | * An implementation of a simple text chat only messenger on the tox network core. |
4 | * | 4 | * |
5 | 5 | * Copyright (C) 2013 Tox project All Rights Reserved. | |
6 | Copyright (C) 2013 Tox project All Rights Reserved. | 6 | * |
7 | 7 | * This file is part of Tox. | |
8 | This file is part of Tox. | 8 | * |
9 | 9 | * Tox is free software: you can redistribute it and/or modify | |
10 | Tox is free software: you can redistribute it and/or modify | 10 | * it under the terms of the GNU General Public License as published by |
11 | it under the terms of the GNU General Public License as published by | 11 | * the Free Software Foundation, either version 3 of the License, or |
12 | the Free Software Foundation, either version 3 of the License, or | 12 | * (at your option) any later version. |
13 | (at your option) any later version. | 13 | * |
14 | 14 | * Tox is distributed in the hope that it will be useful, | |
15 | Tox is distributed in the hope that it will be useful, | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | * GNU General Public License for more details. |
18 | GNU General Public License for more details. | 18 | * |
19 | 19 | * You should have received a copy of the GNU General Public License | |
20 | You should have received a copy of the GNU General Public License | 20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
21 | along with Tox. If not, see <http://www.gnu.org/licenses/>. | 21 | * |
22 | 22 | */ | |
23 | */ | ||
24 | 23 | ||
25 | #include "Messenger.h" | 24 | #include "Messenger.h" |
26 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 25 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
@@ -39,8 +38,6 @@ typedef struct | |||
39 | uint8_t userstatus_sent; | 38 | uint8_t userstatus_sent; |
40 | uint16_t info_size; /* length of the info */ | 39 | uint16_t info_size; /* length of the info */ |
41 | }Friend; | 40 | }Friend; |
42 | |||
43 | |||
44 | 41 | ||
45 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 42 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; |
46 | 43 | ||
@@ -58,7 +55,6 @@ static uint32_t numfriends; | |||
58 | 0 if we are offline | 55 | 0 if we are offline |
59 | static uint8_t online; */ | 56 | static uint8_t online; */ |
60 | 57 | ||
61 | |||
62 | /* return the friend id associated to that public key. | 58 | /* return the friend id associated to that public key. |
63 | return -1 if no such friend */ | 59 | return -1 if no such friend */ |
64 | int getfriend_id(uint8_t * client_id) | 60 | int getfriend_id(uint8_t * client_id) |
@@ -77,7 +73,6 @@ int getfriend_id(uint8_t * client_id) | |||
77 | return -1; | 73 | return -1; |
78 | } | 74 | } |
79 | 75 | ||
80 | |||
81 | /* copies the public key associated to that friend id into client_id buffer. | 76 | /* copies the public key associated to that friend id into client_id buffer. |
82 | make sure that client_id is of size CLIENT_ID_SIZE. | 77 | make sure that client_id is of size CLIENT_ID_SIZE. |
83 | return 0 if success | 78 | return 0 if success |
@@ -97,7 +92,6 @@ int getclient_id(int friend_id, uint8_t * client_id) | |||
97 | return -1; | 92 | return -1; |
98 | } | 93 | } |
99 | 94 | ||
100 | |||
101 | /* add a friend | 95 | /* add a friend |
102 | set the data that will be sent along with friend request | 96 | set the data that will be sent along with friend request |
103 | client_id is the client id of the friend | 97 | client_id is the client id of the friend |
@@ -192,7 +186,6 @@ int m_delfriend(int friendnumber) | |||
192 | return 0; | 186 | return 0; |
193 | } | 187 | } |
194 | 188 | ||
195 | |||
196 | /* return 4 if friend is online | 189 | /* return 4 if friend is online |
197 | return 3 if friend is confirmed | 190 | return 3 if friend is confirmed |
198 | return 2 if the friend request was sent | 191 | return 2 if the friend request was sent |
@@ -207,7 +200,6 @@ int m_friendstatus(int friendnumber) | |||
207 | return friendlist[friendnumber].status; | 200 | return friendlist[friendnumber].status; |
208 | } | 201 | } |
209 | 202 | ||
210 | |||
211 | /* send a text chat message to an online friend | 203 | /* send a text chat message to an online friend |
212 | return 1 if packet was successfully put into the send queue | 204 | return 1 if packet was successfully put into the send queue |
213 | return 0 if it was not */ | 205 | return 0 if it was not */ |
@@ -240,7 +232,6 @@ static int m_sendname(int friendnumber, uint8_t * name) | |||
240 | /* set the name of a friend | 232 | /* set the name of a friend |
241 | return 0 if success | 233 | return 0 if success |
242 | return -1 if failure */ | 234 | return -1 if failure */ |
243 | |||
244 | static int setfriendname(int friendnumber, uint8_t * name) | 235 | static int setfriendname(int friendnumber, uint8_t * name) |
245 | { | 236 | { |
246 | if(friendnumber >= numfriends || friendnumber < 0) | 237 | if(friendnumber >= numfriends || friendnumber < 0) |
@@ -251,7 +242,6 @@ static int setfriendname(int friendnumber, uint8_t * name) | |||
251 | return 0; | 242 | return 0; |
252 | } | 243 | } |
253 | 244 | ||
254 | |||
255 | /* Set our nickname | 245 | /* Set our nickname |
256 | name must be a string of maximum MAX_NAME_LENGTH length. | 246 | name must be a string of maximum MAX_NAME_LENGTH length. |
257 | return 0 if success | 247 | return 0 if success |
@@ -353,6 +343,7 @@ static int set_friend_userstatus(int friendnumber, uint8_t * status, uint16_t le | |||
353 | friendlist[friendnumber].userstatus_length = length; | 343 | friendlist[friendnumber].userstatus_length = length; |
354 | return 0; | 344 | return 0; |
355 | } | 345 | } |
346 | |||
356 | /* | 347 | /* |
357 | static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); | 348 | static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); |
358 | static uint8_t friend_request_isset = 0; | 349 | static uint8_t friend_request_isset = 0; |
@@ -363,7 +354,6 @@ void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)) | |||
363 | callback_friendrequest(function); | 354 | callback_friendrequest(function); |
364 | } | 355 | } |
365 | 356 | ||
366 | |||
367 | static void (*friend_message)(int, uint8_t *, uint16_t); | 357 | static void (*friend_message)(int, uint8_t *, uint16_t); |
368 | static uint8_t friend_message_isset = 0; | 358 | static uint8_t friend_message_isset = 0; |
369 | 359 | ||
@@ -374,7 +364,6 @@ void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t)) | |||
374 | friend_message_isset = 1; | 364 | friend_message_isset = 1; |
375 | } | 365 | } |
376 | 366 | ||
377 | |||
378 | static void (*friend_namechange)(int, uint8_t *, uint16_t); | 367 | static void (*friend_namechange)(int, uint8_t *, uint16_t); |
379 | static uint8_t friend_namechange_isset = 0; | 368 | static uint8_t friend_namechange_isset = 0; |
380 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) | 369 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) |
@@ -521,8 +510,6 @@ static void doFriends() | |||
521 | } | 510 | } |
522 | } | 511 | } |
523 | 512 | ||
524 | |||
525 | |||
526 | static void doInbound() | 513 | static void doInbound() |
527 | { | 514 | { |
528 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; | 515 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; |