summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-06-09 20:42:13 -0400
committerirungentoo <irungentoo@gmail.com>2014-06-09 20:42:13 -0400
commitb74922adb04ea388994d546d70040d658577be75 (patch)
tree20a2f38909634e6d3cb427df5a7df4f1b1b732d0 /toxcore
parent7a11c10429beb7337e8598bf204233e775b407b5 (diff)
Removed very old savefile compatibility to cleanup the code.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c41
1 files changed, 7 insertions, 34 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 38cf2040..037b0e66 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2429,7 +2429,6 @@ void do_messenger(Messenger *m)
2429 2429
2430/* new messenger format for load/save, more robust and forward compatible */ 2430/* new messenger format for load/save, more robust and forward compatible */
2431 2431
2432#define MESSENGER_STATE_COOKIE_GLOBAL_OLD 0x15ed1b1e
2433#define MESSENGER_STATE_COOKIE_GLOBAL 0x15ed1b1f 2432#define MESSENGER_STATE_COOKIE_GLOBAL 0x15ed1b1f
2434 2433
2435#define MESSENGER_STATE_COOKIE_TYPE 0x01ce 2434#define MESSENGER_STATE_COOKIE_TYPE 0x01ce
@@ -2457,21 +2456,6 @@ struct SAVED_FRIEND {
2457 uint64_t ping_lastrecv; 2456 uint64_t ping_lastrecv;
2458}; 2457};
2459 2458
2460/* for backwards compatibility with last version of SAVED_FRIEND.
2461 must never be bigger than SAVED_FRIEND. */
2462struct SAVED_FRIEND_OLD {
2463 uint8_t status;
2464 uint8_t client_id[CLIENT_ID_SIZE];
2465 uint8_t info[1024];
2466 uint16_t info_size;
2467 uint8_t name[MAX_NAME_LENGTH];
2468 uint16_t name_length;
2469 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
2470 uint16_t statusmessage_length;
2471 uint8_t userstatus;
2472 uint32_t friendrequest_nospam;
2473};
2474
2475static uint32_t saved_friendslist_size(Messenger *m) 2459static uint32_t saved_friendslist_size(Messenger *m)
2476{ 2460{
2477 return count_friendlist(m) * sizeof(struct SAVED_FRIEND); 2461 return count_friendlist(m) * sizeof(struct SAVED_FRIEND);
@@ -2521,37 +2505,26 @@ static uint32_t friends_list_save(Messenger *m, uint8_t *data)
2521 2505
2522static int friends_list_load(Messenger *m, uint8_t *data, uint32_t length) 2506static int friends_list_load(Messenger *m, uint8_t *data, uint32_t length)
2523{ 2507{
2524 int old_data = 0;
2525
2526 if (length % sizeof(struct SAVED_FRIEND) != 0) { 2508 if (length % sizeof(struct SAVED_FRIEND) != 0) {
2527 if (length % sizeof(struct SAVED_FRIEND_OLD) != 0) 2509 return -1;
2528 return -1;
2529
2530 old_data = 1;
2531 } 2510 }
2532 2511
2533 /* if old data file is being used, offset size of current SAVED_FRIEND struct with size of old one */ 2512 uint32_t num = length / sizeof(struct SAVED_FRIEND);
2534 uint32_t diff = old_data ? sizeof(struct SAVED_FRIEND) - sizeof(struct SAVED_FRIEND_OLD) : 0;
2535 uint32_t struct_size = sizeof(struct SAVED_FRIEND) - diff;
2536 uint32_t num = length / struct_size;
2537 uint32_t i; 2513 uint32_t i;
2538 2514
2539 for (i = 0; i < num; ++i) { 2515 for (i = 0; i < num; ++i) {
2540 struct SAVED_FRIEND temp; 2516 struct SAVED_FRIEND temp;
2541 memcpy(&temp, data + i * struct_size, struct_size); 2517 memcpy(&temp, data + i * sizeof(struct SAVED_FRIEND), sizeof(struct SAVED_FRIEND));
2542 2518
2543 if (temp.status >= 3) { 2519 if (temp.status >= 3) {
2544 int fnum = m_addfriend_norequest(m, temp.client_id); 2520 int fnum = m_addfriend_norequest(m, temp.client_id);
2545 setfriendname(m, fnum, temp.name, ntohs(temp.name_length)); 2521 setfriendname(m, fnum, temp.name, ntohs(temp.name_length));
2546 set_friend_statusmessage(m, fnum, temp.statusmessage, ntohs(temp.statusmessage_length)); 2522 set_friend_statusmessage(m, fnum, temp.statusmessage, ntohs(temp.statusmessage_length));
2547 set_friend_userstatus(m, fnum, temp.userstatus); 2523 set_friend_userstatus(m, fnum, temp.userstatus);
2548 2524 uint8_t lastonline[sizeof(uint64_t)];
2549 if (!old_data) { 2525 memcpy(lastonline, &temp.ping_lastrecv, sizeof(uint64_t));
2550 uint8_t lastonline[sizeof(uint64_t)]; 2526 net_to_host(lastonline, sizeof(uint64_t));
2551 memcpy(lastonline, &temp.ping_lastrecv, sizeof(uint64_t)); 2527 memcpy(&m->friendlist[fnum].ping_lastrecv, lastonline, sizeof(uint64_t));
2552 net_to_host(lastonline, sizeof(uint64_t));
2553 memcpy(&m->friendlist[fnum].ping_lastrecv, lastonline, sizeof(uint64_t));
2554 }
2555 } else if (temp.status != 0) { 2528 } else if (temp.status != 0) {
2556 /* TODO: This is not a good way to do this. */ 2529 /* TODO: This is not a good way to do this. */
2557 uint8_t address[FRIEND_ADDRESS_SIZE]; 2530 uint8_t address[FRIEND_ADDRESS_SIZE];