summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
authorJfreegman <Jfreegman@gmail.com>2013-08-01 15:27:08 -0400
committerJfreegman <Jfreegman@gmail.com>2013-08-01 15:27:08 -0400
commit8abc0a346209512901254f981dab62c67a632f4a (patch)
treefaf445c6c9f4f8596d56118a335e0d1858a6957b /core/Messenger.c
parenta604de901702eabcdc73507025e77e34db6a9266 (diff)
added error code for no message on friend add & updated nTox.c/nTox_win32.c
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 49f638df..f8a794ce 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -94,25 +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 message length is too long 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 >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES 111 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
109 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES 112 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
110 + crypto_box_ZEROBYTES)) 113 + crypto_box_ZEROBYTES))
111 return -1; 114 return -1;
112 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) 115 if (length < 1)
113 return -2; 116 return -2;
114 if (getfriend_id(client_id) != -1) 117 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
115 return -3; 118 return -3;
119 if (getfriend_id(client_id) != -1)
120 return -4;
121
116 uint32_t i; 122 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*/ 123 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) { 124 if(friendlist[i].status == 0) {
@@ -130,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
130 return i; 136 return i;
131 } 137 }
132 } 138 }
133 return -4; 139 return -5;
134} 140}
135 141
136int m_addfriend_norequest(uint8_t * client_id) 142int m_addfriend_norequest(uint8_t * client_id)