summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index eb59b81a..30f3f658 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -27,7 +27,7 @@
27typedef struct { 27typedef struct {
28 uint8_t client_id[CLIENT_ID_SIZE]; 28 uint8_t client_id[CLIENT_ID_SIZE];
29 int crypt_connection_id; 29 int crypt_connection_id;
30 int friend_request_id; /* id of the friend request corresponding to the current friend request to the current friend. */ 30 int64_t friend_request_id; /* id of the friend request corresponding to the current friend request to the current friend. */
31 uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */ 31 uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */
32 uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */ 32 uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */
33 uint8_t name[MAX_NAME_LENGTH]; 33 uint8_t name[MAX_NAME_LENGTH];
@@ -94,24 +94,31 @@ int getclient_id(int friend_id, uint8_t *client_id)
94 return -1; 94 return -1;
95} 95}
96 96
97/* add a friend 97/*
98 set the data that will be sent along with friend request 98 * add a friend
99 client_id is the client id of the friend 99 * set the data that will be sent along with friend request
100 data is the data and length is the length 100 * client_id is the client id of the friend
101 returns the friend number if success 101 * data is the data and length is the length
102 return -1 if key length is wrong. 102 * returns the friend number if success
103 return -2 if user's own key 103 * return -1 if message length is too long
104 return -3 if already a friend 104 * return -2 if no message (message length must be >= 1 byte)
105 return -4 for other*/ 105 * return -3 if user's own key
106 * return -4 if friend request already sent or already a friend
107 * return -5 for unknown error
108 */
106int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) 109int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
107{ 110{
108 if (length == 0 || length >= 111 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
109 (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES)) 112 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
113 + crypto_box_ZEROBYTES))
110 return -1; 114 return -1;
111 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) 115 if (length < 1)
112 return -2; 116 return -2;
113 if (getfriend_id(client_id) != -1) 117 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
114 return -3; 118 return -3;
119 if (getfriend_id(client_id) != -1)
120 return -4;
121
115 uint32_t i; 122 uint32_t i;
116 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ 123 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
117 if(friendlist[i].status == 0) { 124 if(friendlist[i].status == 0) {
@@ -129,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
129 return i; 136 return i;
130 } 137 }
131 } 138 }
132 return -4; 139 return -5;
133} 140}
134 141
135int m_addfriend_norequest(uint8_t * client_id) 142int m_addfriend_norequest(uint8_t * client_id)
@@ -484,7 +491,7 @@ static void doInbound()
484/*Interval in seconds between LAN discovery packet sending*/ 491/*Interval in seconds between LAN discovery packet sending*/
485#define LAN_DISCOVERY_INTERVAL 60 492#define LAN_DISCOVERY_INTERVAL 60
486 493
487static uint32_t last_LANdiscovery; 494static int64_t last_LANdiscovery;
488 495
489/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ 496/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/
490static void LANdiscovery() 497static void LANdiscovery()