summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-09 13:40:36 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-09 20:36:39 +0000
commitc8697ccc20e12b0f4a2394c10f01ce147eeca269 (patch)
tree88a2fbf4455b9fdfc58d15865340b1a184191483 /toxcore/Messenger.c
parent751d0948abfd69629d32fabb1f505ff7ad7fb078 (diff)
Move `load_state` and its helper functions to their own module.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 9014d56d..404827c6 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -35,6 +35,7 @@
35 35
36#include "logger.h" 36#include "logger.h"
37#include "network.h" 37#include "network.h"
38#include "state.h"
38#include "util.h" 39#include "util.h"
39 40
40static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, 41static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
@@ -3075,7 +3076,7 @@ void messenger_save(const Messenger *m, uint8_t *data)
3075 messenger_save_subheader(data, 0, MESSENGER_STATE_TYPE_END); 3076 messenger_save_subheader(data, 0, MESSENGER_STATE_TYPE_END);
3076} 3077}
3077 3078
3078static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) 3079static State_Load_Status messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
3079{ 3080{
3080 Messenger *m = (Messenger *)outer; 3081 Messenger *m = (Messenger *)outer;
3081 3082
@@ -3086,10 +3087,10 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3086 load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + CRYPTO_PUBLIC_KEY_SIZE); 3087 load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + CRYPTO_PUBLIC_KEY_SIZE);
3087 3088
3088 if (public_key_cmp((&data[sizeof(uint32_t)]), nc_get_self_public_key(m->net_crypto)) != 0) { 3089 if (public_key_cmp((&data[sizeof(uint32_t)]), nc_get_self_public_key(m->net_crypto)) != 0) {
3089 return -1; 3090 return STATE_LOAD_STATUS_ERROR;
3090 } 3091 }
3091 } else { 3092 } else {
3092 return -1; /* critical */ 3093 return STATE_LOAD_STATUS_ERROR; /* critical */
3093 } 3094 }
3094 3095
3095 break; 3096 break;
@@ -3152,10 +3153,10 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3152 3153
3153 case MESSENGER_STATE_TYPE_END: { 3154 case MESSENGER_STATE_TYPE_END: {
3154 if (length != 0) { 3155 if (length != 0) {
3155 return -1; 3156 return STATE_LOAD_STATUS_ERROR;
3156 } 3157 }
3157 3158
3158 return -2; 3159 return STATE_LOAD_STATUS_END;
3159 } 3160 }
3160 3161
3161 default: 3162 default:
@@ -3164,7 +3165,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3164 break; 3165 break;
3165 } 3166 }
3166 3167
3167 return 0; 3168 return STATE_LOAD_STATUS_CONTINUE;
3168} 3169}
3169 3170
3170/* Load the messenger from data of size length. */ 3171/* Load the messenger from data of size length. */
@@ -3181,7 +3182,7 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
3181 lendian_to_host32(data32 + 1, data + sizeof(uint32_t)); 3182 lendian_to_host32(data32 + 1, data + sizeof(uint32_t));
3182 3183
3183 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) { 3184 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) {
3184 return load_state(messenger_load_state_callback, m->log, m, data + cookie_len, 3185 return state_load(m->log, messenger_load_state_callback, m, data + cookie_len,
3185 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); 3186 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE);
3186 } 3187 }
3187 3188