Skip to content

Commit 4b1cfa3

Browse files
committed
refactor: Change all enum-like #define sequences into enums.
The only one I'm not so sure about is `Tcp_Socks5_Proxy_Hs`, which has repeats. Should we ignore repeats?
1 parent d3c2704 commit 4b1cfa3

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

toxcore/TCP_client.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,16 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C
185185
return -1;
186186
}
187187

188-
#define TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5 0x05
189-
#define TCP_SOCKS5_PROXY_HS_COMM_ESTABLISH_REQUEST 0x01
190-
#define TCP_SOCKS5_PROXY_HS_COMM_REQUEST_GRANTED 0x00
191-
#define TCP_SOCKS5_PROXY_HS_AUTH_METHODS_SUPPORTED 0x01
192-
#define TCP_SOCKS5_PROXY_HS_NO_AUTH 0x00
193-
#define TCP_SOCKS5_PROXY_HS_RESERVED 0x00
194-
#define TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV4 0x01
195-
#define TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 0x04
188+
enum Tcp_Socks5_Proxy_Hs {
189+
TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5 = 0x05,
190+
TCP_SOCKS5_PROXY_HS_COMM_ESTABLISH_REQUEST = 0x01,
191+
TCP_SOCKS5_PROXY_HS_COMM_REQUEST_GRANTED = 0x00,
192+
TCP_SOCKS5_PROXY_HS_AUTH_METHODS_SUPPORTED = 0x01,
193+
TCP_SOCKS5_PROXY_HS_NO_AUTH = 0x00,
194+
TCP_SOCKS5_PROXY_HS_RESERVED = 0x00,
195+
TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV4 = 0x01,
196+
TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 = 0x04,
197+
};
196198

197199
non_null()
198200
static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)

toxcore/net_crypto.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,31 @@
4343

4444
/*** Messages. */
4545

46-
#define PACKET_ID_PADDING 0 // Denotes padding
47-
#define PACKET_ID_REQUEST 1 // Used to request unreceived packets
48-
#define PACKET_ID_KILL 2 // Used to kill connection
49-
50-
#define PACKET_ID_ONLINE 24
51-
#define PACKET_ID_OFFLINE 25
52-
#define PACKET_ID_NICKNAME 48
53-
#define PACKET_ID_STATUSMESSAGE 49
54-
#define PACKET_ID_USERSTATUS 50
55-
#define PACKET_ID_TYPING 51
56-
#define PACKET_ID_MESSAGE 64
57-
#define PACKET_ID_ACTION 65 // PACKET_ID_MESSAGE + MESSAGE_ACTION
58-
#define PACKET_ID_MSI 69 // Used by AV to setup calls and etc
59-
#define PACKET_ID_FILE_SENDREQUEST 80
60-
#define PACKET_ID_FILE_CONTROL 81
61-
#define PACKET_ID_FILE_DATA 82
62-
#define PACKET_ID_INVITE_GROUPCHAT 95
63-
#define PACKET_ID_INVITE_CONFERENCE 96
64-
#define PACKET_ID_ONLINE_PACKET 97
65-
#define PACKET_ID_DIRECT_CONFERENCE 98
66-
#define PACKET_ID_MESSAGE_CONFERENCE 99
67-
#define PACKET_ID_REJOIN_CONFERENCE 100
68-
#define PACKET_ID_LOSSY_CONFERENCE 199
46+
typedef enum Packet_Id {
47+
PACKET_ID_PADDING = 0, // Denotes padding
48+
PACKET_ID_REQUEST = 1, // Used to request unreceived packets
49+
PACKET_ID_KILL = 2, // Used to kill connection
50+
51+
PACKET_ID_ONLINE = 24,
52+
PACKET_ID_OFFLINE = 25,
53+
PACKET_ID_NICKNAME = 48,
54+
PACKET_ID_STATUSMESSAGE = 49,
55+
PACKET_ID_USERSTATUS = 50,
56+
PACKET_ID_TYPING = 51,
57+
PACKET_ID_MESSAGE = 64,
58+
PACKET_ID_ACTION = 65, // PACKET_ID_MESSAGE + MESSAGE_ACTION
59+
PACKET_ID_MSI = 69, // Used by AV to setup calls and etc
60+
PACKET_ID_FILE_SENDREQUEST = 80,
61+
PACKET_ID_FILE_CONTROL = 81,
62+
PACKET_ID_FILE_DATA = 82,
63+
PACKET_ID_INVITE_GROUPCHAT = 95,
64+
PACKET_ID_INVITE_CONFERENCE = 96,
65+
PACKET_ID_ONLINE_PACKET = 97,
66+
PACKET_ID_DIRECT_CONFERENCE = 98,
67+
PACKET_ID_MESSAGE_CONFERENCE = 99,
68+
PACKET_ID_REJOIN_CONFERENCE = 100,
69+
PACKET_ID_LOSSY_CONFERENCE = 199,
70+
} Packet_Id;
6971

7072
/** Maximum size of receiving and sending packet buffers. */
7173
#define CRYPTO_PACKET_BUFFER_SIZE 32768 // Must be a power of 2

0 commit comments

Comments
 (0)