diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-15 20:56:22 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-15 20:56:22 -0400 |
commit | b15230583c31799d650584b05f4cfce8cd726aea (patch) | |
tree | c9d56f3fd9bad409374302e6eb92e9343cb859c1 | |
parent | 36cb9b003d2f9e8162c39ffa3ab1afa3743b13a4 (diff) |
Fixed loading and a small problem with the length of crypto requests.
-rw-r--r-- | core/Messenger.c | 10 | ||||
-rw-r--r-- | core/friend_requests.c | 2 | ||||
-rw-r--r-- | core/net_crypto.c | 4 | ||||
-rw-r--r-- | testing/toxic/main.c | 8 |
4 files changed, 19 insertions, 5 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index bed59d4d..4ed8bc41 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -810,10 +810,18 @@ int Messenger_load(Messenger *m, uint8_t * data, uint32_t length) | |||
810 | 810 | ||
811 | uint32_t i; | 811 | uint32_t i; |
812 | for (i = 0; i < num; ++i) { | 812 | for (i = 0; i < num; ++i) { |
813 | if(temp[i].status != 0) { | 813 | if(temp[i].status >= 3) { |
814 | int fnum = m_addfriend_norequest(m, temp[i].client_id); | 814 | int fnum = m_addfriend_norequest(m, temp[i].client_id); |
815 | setfriendname(m, fnum, temp[i].name); | 815 | setfriendname(m, fnum, temp[i].name); |
816 | /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */ | 816 | /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */ |
817 | } else if (temp[i].status != 0) { | ||
818 | /* TODO: this is not a good way to do this. */ | ||
819 | uint8_t address[FRIEND_ADDRESS_SIZE]; | ||
820 | memcpy(address, temp[i].client_id, crypto_box_PUBLICKEYBYTES); | ||
821 | memcpy(address + crypto_box_PUBLICKEYBYTES, &(temp[i].friendrequest_nospam), sizeof(uint32_t)); | ||
822 | uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); | ||
823 | memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum)); | ||
824 | m_addfriend(m, address, temp[i].info, temp[i].info_size); | ||
817 | } | 825 | } |
818 | } | 826 | } |
819 | free(temp); | 827 | free(temp); |
diff --git a/core/friend_requests.c b/core/friend_requests.c index ae19ebdd..d4f8dd63 100644 --- a/core/friend_requests.c +++ b/core/friend_requests.c | |||
@@ -35,7 +35,7 @@ int send_friendrequest(uint8_t * public_key, uint32_t nospam_num, uint8_t * data | |||
35 | { | 35 | { |
36 | if(length - sizeof(nospam_num) > MAX_DATA_SIZE) | 36 | if(length - sizeof(nospam_num) > MAX_DATA_SIZE) |
37 | return -1; | 37 | return -1; |
38 | 38 | ||
39 | uint8_t temp[MAX_DATA_SIZE]; | 39 | uint8_t temp[MAX_DATA_SIZE]; |
40 | memcpy(temp, &nospam_num, sizeof(nospam_num)); | 40 | memcpy(temp, &nospam_num, sizeof(nospam_num)); |
41 | memcpy(temp + sizeof(nospam_num), data, length); | 41 | memcpy(temp + sizeof(nospam_num), data, length); |
diff --git a/core/net_crypto.c b/core/net_crypto.c index 376708ab..a05208ef 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -228,7 +228,7 @@ int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t | |||
228 | memcpy(temp + 1, data, length); | 228 | memcpy(temp + 1, data, length); |
229 | temp[0] = request_id; | 229 | temp[0] = request_id; |
230 | random_nonce(nonce); | 230 | random_nonce(nonce); |
231 | int len = encrypt_data(public_key, self_secret_key, nonce, temp, length, | 231 | int len = encrypt_data(public_key, self_secret_key, nonce, temp, length + 1, |
232 | 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet); | 232 | 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet); |
233 | if (len == -1) | 233 | if (len == -1) |
234 | return -1; | 234 | return -1; |
@@ -287,7 +287,7 @@ static int cryptopacket_handle(IP_Port source, uint8_t * packet, uint32_t length | |||
287 | if (len == -1 || len == 0) | 287 | if (len == -1 || len == 0) |
288 | return 1; | 288 | return 1; |
289 | if (!cryptopackethandlers[number]) return 1; | 289 | if (!cryptopackethandlers[number]) return 1; |
290 | cryptopackethandlers[number](source, public_key, data, len - 1); | 290 | cryptopackethandlers[number](source, public_key, data, len); |
291 | 291 | ||
292 | } else { /* if request is not for us, try routing it. */ | 292 | } else { /* if request is not for us, try routing it. */ |
293 | if(route_packet(packet + 1, packet, length) == length) | 293 | if(route_packet(packet + 1, packet, length) == length) |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 4d52469a..38c20df6 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -147,6 +147,8 @@ static void do_tox(Messenger *m, ToxWindow * prompt) | |||
147 | doMessenger(m); | 147 | doMessenger(m); |
148 | } | 148 | } |
149 | 149 | ||
150 | int f_loadfromfile; | ||
151 | |||
150 | /* | 152 | /* |
151 | * Store Messenger to given location | 153 | * Store Messenger to given location |
152 | * Return 0 stored successfully | 154 | * Return 0 stored successfully |
@@ -156,6 +158,8 @@ static void do_tox(Messenger *m, ToxWindow * prompt) | |||
156 | */ | 158 | */ |
157 | int store_data(Messenger *m, char *path) | 159 | int store_data(Messenger *m, char *path) |
158 | { | 160 | { |
161 | if (f_loadfromfile == 0) /*If file loading/saving is disabled*/ | ||
162 | return 0; | ||
159 | FILE *fd; | 163 | FILE *fd; |
160 | size_t len; | 164 | size_t len; |
161 | uint8_t *buf; | 165 | uint8_t *buf; |
@@ -186,6 +190,8 @@ int store_data(Messenger *m, char *path) | |||
186 | 190 | ||
187 | static void load_data(Messenger *m, char *path) | 191 | static void load_data(Messenger *m, char *path) |
188 | { | 192 | { |
193 | if (f_loadfromfile == 0) /*If file loading/saving is disabled*/ | ||
194 | return; | ||
189 | FILE *fd; | 195 | FILE *fd; |
190 | size_t len; | 196 | size_t len; |
191 | uint8_t *buf; | 197 | uint8_t *buf; |
@@ -233,7 +239,7 @@ int main(int argc, char *argv[]) | |||
233 | char *user_config_dir = get_user_config_dir(); | 239 | char *user_config_dir = get_user_config_dir(); |
234 | int config_err = 0; | 240 | int config_err = 0; |
235 | 241 | ||
236 | int f_loadfromfile = 1; | 242 | f_loadfromfile = 1; |
237 | int f_flag = 0; | 243 | int f_flag = 0; |
238 | int i = 0; | 244 | int i = 0; |
239 | for (i = 0; i < argc; ++i) { | 245 | for (i = 0; i < argc; ++i) { |