Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2020 The TokTok team. |
3 | | * Copyright © 2014 Tox project. |
4 | | */ |
5 | | |
6 | | /** |
7 | | * The state module is responsible for parsing the Tox save data format and for |
8 | | * saving state in that format. |
9 | | * |
10 | | * This module provides functions for iterating over serialised data sections |
11 | | * and reading/writing numbers in the correct format (little endian). |
12 | | * |
13 | | * Note that unlike the Tox network protocol, the save data stores its values in |
14 | | * little endian, which is native to most desktop and server architectures in |
15 | | * 2018. |
16 | | */ |
17 | | #ifndef C_TOXCORE_TOXCORE_STATE_H |
18 | | #define C_TOXCORE_TOXCORE_STATE_H |
19 | | |
20 | | #include "logger.h" |
21 | | |
22 | | #ifdef __cplusplus |
23 | | extern "C" { |
24 | | #endif |
25 | | |
26 | 2.14k | #define STATE_COOKIE_GLOBAL 0x15ed1b1f |
27 | | |
28 | 11.0k | #define STATE_COOKIE_TYPE 0x01ce |
29 | | |
30 | | typedef enum State_Type { |
31 | | STATE_TYPE_NOSPAMKEYS = 1, |
32 | | STATE_TYPE_DHT = 2, |
33 | | STATE_TYPE_FRIENDS = 3, |
34 | | STATE_TYPE_NAME = 4, |
35 | | STATE_TYPE_STATUSMESSAGE = 5, |
36 | | STATE_TYPE_STATUS = 6, |
37 | | STATE_TYPE_GROUPS = 7, |
38 | | STATE_TYPE_TCP_RELAY = 10, |
39 | | STATE_TYPE_PATH_NODE = 11, |
40 | | STATE_TYPE_CONFERENCES = 20, |
41 | | STATE_TYPE_END = 255, |
42 | | } State_Type; |
43 | | |
44 | | // Returned by the state_load_cb to instruct the loader on what to do next. |
45 | | typedef enum State_Load_Status { |
46 | | // Continue loading state data sections. |
47 | | STATE_LOAD_STATUS_CONTINUE, |
48 | | // An error occurred. Stop loading sections. |
49 | | STATE_LOAD_STATUS_ERROR, |
50 | | // We're at the end of the save data, terminate loading successfully. |
51 | | STATE_LOAD_STATUS_END, |
52 | | } State_Load_Status; |
53 | | |
54 | | typedef State_Load_Status state_load_cb(void *outer, const uint8_t *data, uint32_t length, uint16_t type); |
55 | | |
56 | | /** state load/save */ |
57 | | non_null() |
58 | | int state_load(const Logger *log, state_load_cb *state_load_callback, void *outer, |
59 | | const uint8_t *data, uint32_t length, uint16_t cookie_inner); |
60 | | |
61 | | non_null() |
62 | | uint8_t *state_write_section_header(uint8_t *data, uint16_t cookie_type, uint32_t len, uint32_t section_type); |
63 | | |
64 | | // Utilities for state data serialisation. |
65 | | |
66 | | uint16_t lendian_to_host16(uint16_t lendian); |
67 | | uint16_t host_to_lendian16(uint16_t host); |
68 | | |
69 | | non_null() |
70 | | void host_to_lendian_bytes64(uint8_t *dest, uint64_t num); |
71 | | non_null() |
72 | | void lendian_bytes_to_host64(uint64_t *dest, const uint8_t *lendian); |
73 | | |
74 | | non_null() |
75 | | void host_to_lendian_bytes32(uint8_t *dest, uint32_t num); |
76 | | non_null() |
77 | | void lendian_bytes_to_host32(uint32_t *dest, const uint8_t *lendian); |
78 | | |
79 | | non_null() |
80 | | void host_to_lendian_bytes16(uint8_t *dest, uint16_t num); |
81 | | non_null() |
82 | | void lendian_bytes_to_host16(uint16_t *dest, const uint8_t *lendian); |
83 | | |
84 | | #ifdef __cplusplus |
85 | | } /* extern "C" */ |
86 | | #endif |
87 | | |
88 | | #endif /* C_TOXCORE_TOXCORE_STATE_H */ |