diff options
author | zugz (tox) <mbays+tox@sdf.org> | 2018-09-09 23:21:20 +0200 |
---|---|---|
committer | zugz (tox) <mbays+tox@sdf.org> | 2018-10-20 11:03:10 +0200 |
commit | 744dc2f5da2c54ad1e4d7d6ce229bc1756d81263 (patch) | |
tree | 35f6590fe3150118bc6b1336fbb0a7db06543668 /toxcore/state.c | |
parent | aa5c7828802b3fcaedfd8d6fe9a08ca714b9aa2b (diff) |
Make saving and loading the responsibility of Tox rather than Messenger
Diffstat (limited to 'toxcore/state.c')
-rw-r--r-- | toxcore/state.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/toxcore/state.c b/toxcore/state.c index 29b4af88..919c2e8c 100644 --- a/toxcore/state.c +++ b/toxcore/state.c | |||
@@ -16,10 +16,10 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute | |||
16 | 16 | ||
17 | while (length >= size_head) { | 17 | while (length >= size_head) { |
18 | uint32_t length_sub; | 18 | uint32_t length_sub; |
19 | lendian_to_host32(&length_sub, data); | 19 | lendian_bytes_to_host32(&length_sub, data); |
20 | 20 | ||
21 | uint32_t cookie_type; | 21 | uint32_t cookie_type; |
22 | lendian_to_host32(&cookie_type, data + sizeof(uint32_t)); | 22 | lendian_bytes_to_host32(&cookie_type, data + sizeof(uint32_t)); |
23 | 23 | ||
24 | data += size_head; | 24 | data += size_head; |
25 | length -= size_head; | 25 | length -= size_head; |
@@ -63,9 +63,9 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute | |||
63 | 63 | ||
64 | uint8_t *state_write_section_header(uint8_t *data, uint16_t cookie_type, uint32_t len, uint32_t section_type) | 64 | uint8_t *state_write_section_header(uint8_t *data, uint16_t cookie_type, uint32_t len, uint32_t section_type) |
65 | { | 65 | { |
66 | host_to_lendian32(data, len); | 66 | host_to_lendian_bytes32(data, len); |
67 | data += sizeof(uint32_t); | 67 | data += sizeof(uint32_t); |
68 | host_to_lendian32(data, (host_tolendian16(cookie_type) << 16) | host_tolendian16(section_type)); | 68 | host_to_lendian_bytes32(data, (host_to_lendian16(cookie_type) << 16) | host_to_lendian16(section_type)); |
69 | data += sizeof(uint32_t); | 69 | data += sizeof(uint32_t); |
70 | return data; | 70 | return data; |
71 | } | 71 | } |
@@ -79,12 +79,12 @@ uint16_t lendian_to_host16(uint16_t lendian) | |||
79 | #endif | 79 | #endif |
80 | } | 80 | } |
81 | 81 | ||
82 | uint16_t host_tolendian16(uint16_t host) | 82 | uint16_t host_to_lendian16(uint16_t host) |
83 | { | 83 | { |
84 | return lendian_to_host16(host); | 84 | return lendian_to_host16(host); |
85 | } | 85 | } |
86 | 86 | ||
87 | void host_to_lendian32(uint8_t *dest, uint32_t num) | 87 | void host_to_lendian_bytes32(uint8_t *dest, uint32_t num) |
88 | { | 88 | { |
89 | #ifdef WORDS_BIGENDIAN | 89 | #ifdef WORDS_BIGENDIAN |
90 | num = ((num << 8) & 0xFF00FF00) | ((num >> 8) & 0xFF00FF); | 90 | num = ((num << 8) & 0xFF00FF00) | ((num >> 8) & 0xFF00FF); |
@@ -93,7 +93,7 @@ void host_to_lendian32(uint8_t *dest, uint32_t num) | |||
93 | memcpy(dest, &num, sizeof(uint32_t)); | 93 | memcpy(dest, &num, sizeof(uint32_t)); |
94 | } | 94 | } |
95 | 95 | ||
96 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) | 96 | void lendian_bytes_to_host32(uint32_t *dest, const uint8_t *lendian) |
97 | { | 97 | { |
98 | uint32_t d; | 98 | uint32_t d; |
99 | memcpy(&d, lendian, sizeof(uint32_t)); | 99 | memcpy(&d, lendian, sizeof(uint32_t)); |
@@ -103,3 +103,21 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) | |||
103 | #endif | 103 | #endif |
104 | *dest = d; | 104 | *dest = d; |
105 | } | 105 | } |
106 | |||
107 | void host_to_lendian_bytes16(uint8_t *dest, uint16_t num) | ||
108 | { | ||
109 | #ifdef WORDS_BIGENDIAN | ||
110 | num = (num << 8) | (num >> 8); | ||
111 | #endif | ||
112 | memcpy(dest, &num, sizeof(uint16_t)); | ||
113 | } | ||
114 | |||
115 | void lendian_bytes_to_host16(uint16_t *dest, const uint8_t *lendian) | ||
116 | { | ||
117 | uint16_t d; | ||
118 | memcpy(&d, lendian, sizeof(uint16_t)); | ||
119 | #ifdef WORDS_BIGENDIAN | ||
120 | d = (d << 8) | (d >> 8); | ||
121 | #endif | ||
122 | *dest = d; | ||
123 | } | ||