summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
authorcharmlesscoin <charmlesscoin@gmail.com>2013-08-02 12:33:11 -0400
committercharmlesscoin <charmlesscoin@gmail.com>2013-08-02 12:33:11 -0400
commit4b49df896f5dde6d5818b52dc19be896fd6e8ea0 (patch)
treeef631245768111f4ddb87757ed1f2dbec56cdcb7 /core/Messenger.c
parenteba7fdb9ba0dc76a06098c03a80fb218b2c53cc3 (diff)
added #defines for friend.status as well as for erroring on m_addfriend*
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 8f1ed41a..8e6d3dda 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -105,19 +105,19 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
105 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES 105 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
106 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES 106 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
107 + crypto_box_ZEROBYTES)) 107 + crypto_box_ZEROBYTES))
108 return -1; 108 return FAERR_TOOLONG;
109 if (length < 1) 109 if (length < 1)
110 return -2; 110 return FAERR_NOMESSAGE;
111 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) 111 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
112 return -3; 112 return FAERR_OWNKEY;
113 if (getfriend_id(client_id) != -1) 113 if (getfriend_id(client_id) != -1)
114 return -4; 114 return FAERR_ALREADYSENT;
115 115
116 uint32_t i; 116 uint32_t i;
117 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ 117 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
118 if(friendlist[i].status == 0) { 118 if(friendlist[i].status == NOFRIEND) {
119 DHT_addfriend(client_id); 119 DHT_addfriend(client_id);
120 friendlist[i].status = 1; 120 friendlist[i].status = FRIEND_ADDED;
121 friendlist[i].crypt_connection_id = -1; 121 friendlist[i].crypt_connection_id = -1;
122 friendlist[i].friend_request_id = -1; 122 friendlist[i].friend_request_id = -1;
123 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 123 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@@ -130,7 +130,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
130 return i; 130 return i;
131 } 131 }
132 } 132 }
133 return -5; 133 return FAERR_GENERAL;
134} 134}
135 135
136int m_addfriend_norequest(uint8_t * client_id) 136int m_addfriend_norequest(uint8_t * client_id)
@@ -139,9 +139,9 @@ int m_addfriend_norequest(uint8_t * client_id)
139 return -1; 139 return -1;
140 uint32_t i; 140 uint32_t i;
141 for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ 141 for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
142 if(friendlist[i].status == 0) { 142 if(friendlist[i].status == NOFRIEND) {
143 DHT_addfriend(client_id); 143 DHT_addfriend(client_id);
144 friendlist[i].status = 2; 144 friendlist[i].status = FRIEND_REQUESTED;
145 friendlist[i].crypt_connection_id = -1; 145 friendlist[i].crypt_connection_id = -1;
146 friendlist[i].friend_request_id = -1; 146 friendlist[i].friend_request_id = -1;
147 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 147 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@@ -169,7 +169,7 @@ int m_delfriend(int friendnumber)
169 uint32_t i; 169 uint32_t i;
170 170
171 for (i = numfriends; i != 0; --i) { 171 for (i = numfriends; i != 0; --i) {
172 if (friendlist[i-1].status != 0) 172 if (friendlist[i-1].status != NOFRIEND)
173 break; 173 break;
174 } 174 }
175 numfriends = i; 175 numfriends = i;
@@ -185,7 +185,7 @@ int m_delfriend(int friendnumber)
185int m_friendstatus(int friendnumber) 185int m_friendstatus(int friendnumber)
186{ 186{
187 if (friendnumber < 0 || friendnumber >= numfriends) 187 if (friendnumber < 0 || friendnumber >= numfriends)
188 return 0; 188 return NOFRIEND;
189 return friendlist[friendnumber].status; 189 return friendlist[friendnumber].status;
190} 190}
191 191
@@ -196,7 +196,7 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length)
196{ 196{
197 if (friendnumber < 0 || friendnumber >= numfriends) 197 if (friendnumber < 0 || friendnumber >= numfriends)
198 return 0; 198 return 0;
199 if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != 4) 199 if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE)
200 /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */ 200 /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */
201 return 0; 201 return 0;
202 uint8_t temp[MAX_DATA_SIZE]; 202 uint8_t temp[MAX_DATA_SIZE];
@@ -385,15 +385,15 @@ static void doFriends()
385 int len; 385 int len;
386 uint8_t temp[MAX_DATA_SIZE]; 386 uint8_t temp[MAX_DATA_SIZE];
387 for (i = 0; i < numfriends; ++i) { 387 for (i = 0; i < numfriends; ++i) {
388 if (friendlist[i].status == 1) { 388 if (friendlist[i].status == FRIEND_ADDED) {
389 int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); 389 int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
390 if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */ 390 if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */
391 friendlist[i].status = 2; 391 friendlist[i].status = FRIEND_REQUESTED;
392 else if (fr > 0) 392 else if (fr > 0)
393 friendlist[i].status = 2; 393 friendlist[i].status = FRIEND_REQUESTED;
394 } 394 }
395 if (friendlist[i].status == 2 || friendlist[i].status == 3) { /* friend is not online */ 395 if (friendlist[i].status == FRIEND_REQUESTED || friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
396 if (friendlist[i].status == 2) { 396 if (friendlist[i].status == FRIEND_REQUESTED) {
397 if (friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/ 397 if (friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/
398 send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); 398 send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
399 friendlist[i].friend_request_id = unix_time(); 399 friendlist[i].friend_request_id = unix_time();
@@ -406,7 +406,7 @@ static void doFriends()
406 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip); 406 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
407 break; 407 break;
408 case 3: /* Connection is established */ 408 case 3: /* Connection is established */
409 friendlist[i].status = 4; 409 friendlist[i].status = FRIEND_ONLINE;
410 break; 410 break;
411 case 4: 411 case 4:
412 crypto_kill(friendlist[i].crypt_connection_id); 412 crypto_kill(friendlist[i].crypt_connection_id);
@@ -416,7 +416,7 @@ static void doFriends()
416 break; 416 break;
417 } 417 }
418 } 418 }
419 while (friendlist[i].status == 4) { /* friend is online */ 419 while (friendlist[i].status == FRIEND_ONLINE) { /* friend is online */
420 if (friendlist[i].name_sent == 0) { 420 if (friendlist[i].name_sent == 0) {
421 if (m_sendname(i, self_name, self_name_length)) 421 if (m_sendname(i, self_name, self_name_length))
422 friendlist[i].name_sent = 1; 422 friendlist[i].name_sent = 1;
@@ -456,7 +456,7 @@ static void doFriends()
456 if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */ 456 if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */
457 crypto_kill(friendlist[i].crypt_connection_id); 457 crypto_kill(friendlist[i].crypt_connection_id);
458 friendlist[i].crypt_connection_id = -1; 458 friendlist[i].crypt_connection_id = -1;
459 friendlist[i].status = 3; 459 friendlist[i].status = FRIEND_CONFIRMED;
460 } 460 }
461 break; 461 break;
462 } 462 }
@@ -477,7 +477,7 @@ static void doInbound()
477 friendlist[friend_id].crypt_connection_id = 477 friendlist[friend_id].crypt_connection_id =
478 accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key); 478 accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key);
479 479
480 friendlist[friend_id].status = 3; 480 friendlist[friend_id].status = FRIEND_CONFIRMED;
481 } 481 }
482 } 482 }
483} 483}