diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-01 17:38:29 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-01 17:38:29 -0700 |
commit | af8e84345171538e70e2e3562e1c51da32e306df (patch) | |
tree | bf683baa454e74241ead3f319105e3490c965481 /core | |
parent | 276e3f9271241839083bfa22a4ba422c4b28785d (diff) | |
parent | 8abc0a346209512901254f981dab62c67a632f4a (diff) |
Merge pull request #229 from JFreegman/master
fixed friend add bugs and gave no message its own error
Diffstat (limited to 'core')
-rw-r--r-- | core/Messenger.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index eb59b81a..f8a794ce 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -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 | */ | ||
106 | int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) | 109 | int 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 | ||
135 | int m_addfriend_norequest(uint8_t * client_id) | 142 | int m_addfriend_norequest(uint8_t * client_id) |