summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-09 17:19:41 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-12 09:19:02 +0000
commit37f8f566d53a3e2603467aa0bbe1e29581ddd561 (patch)
treeed49d6b26816a47b37cf3a691909cdf5178d2b6f
parent0b7e29e0197f18ea38a62f8f89a1fe60edb462a0 (diff)
Fix style in some header files.
* Enums must by typedef'd. * Comments at end of `#define` must be `//` comments. * Typedef structs must not be anonymous. * `;` at the end of a `#define` is invalid. * Callback typedefs must list their parameter names. * No nested structs. * No inline use of function pointer types. Only typedef'd callback types are allowed. * Enum types are spelled in Camelsnake_Case. * The argument to `#error` must be a string literal.
-rw-r--r--toxcore/Messenger.h158
-rw-r--r--toxcore/friend_connection.h4
-rw-r--r--toxcore/friend_requests.h5
-rw-r--r--toxcore/list.h12
-rw-r--r--toxcore/logger.c6
-rw-r--r--toxcore/logger.h8
-rw-r--r--toxcore/onion.h10
-rw-r--r--toxcore/onion_announce.h2
-rw-r--r--toxcore/onion_client.h2
9 files changed, 108 insertions, 99 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 47025fcc..833e6b2b 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -44,10 +44,10 @@
44 44
45#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) 45#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
46 46
47enum { 47typedef enum Message_Type {
48 MESSAGE_NORMAL, 48 MESSAGE_NORMAL,
49 MESSAGE_ACTION 49 MESSAGE_ACTION
50}; 50} Message_Type;
51 51
52/* NOTE: Packet ids below 24 must never be used. */ 52/* NOTE: Packet ids below 24 must never be used. */
53#define PACKET_ID_ONLINE 24 53#define PACKET_ID_ONLINE 24
@@ -57,7 +57,7 @@ enum {
57#define PACKET_ID_USERSTATUS 50 57#define PACKET_ID_USERSTATUS 50
58#define PACKET_ID_TYPING 51 58#define PACKET_ID_TYPING 51
59#define PACKET_ID_MESSAGE 64 59#define PACKET_ID_MESSAGE 64
60#define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) /* 65 */ 60#define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) // 65
61#define PACKET_ID_MSI 69 61#define PACKET_ID_MSI 69
62#define PACKET_ID_FILE_SENDREQUEST 80 62#define PACKET_ID_FILE_SENDREQUEST 80
63#define PACKET_ID_FILE_CONTROL 81 63#define PACKET_ID_FILE_CONTROL 81
@@ -71,9 +71,9 @@ enum {
71/* All packets starting with a byte in this range can be used for anything. */ 71/* All packets starting with a byte in this range can be used for anything. */
72#define PACKET_ID_LOSSLESS_RANGE_START 160 72#define PACKET_ID_LOSSLESS_RANGE_START 160
73#define PACKET_ID_LOSSLESS_RANGE_SIZE 32 73#define PACKET_ID_LOSSLESS_RANGE_SIZE 32
74#define PACKET_LOSSY_AV_RESERVED 8 /* Number of lossy packet types at start of range reserved for A/V. */ 74#define PACKET_LOSSY_AV_RESERVED 8 // Number of lossy packet types at start of range reserved for A/V.
75 75
76typedef struct { 76typedef struct Messenger_Options {
77 bool ipv6enabled; 77 bool ipv6enabled;
78 bool udp_disabled; 78 bool udp_disabled;
79 TCP_Proxy_Info proxy_info; 79 TCP_Proxy_Info proxy_info;
@@ -95,18 +95,18 @@ struct Receipts {
95}; 95};
96 96
97/* Status definitions. */ 97/* Status definitions. */
98enum { 98typedef enum Friend_Status {
99 NOFRIEND, 99 NOFRIEND,
100 FRIEND_ADDED, 100 FRIEND_ADDED,
101 FRIEND_REQUESTED, 101 FRIEND_REQUESTED,
102 FRIEND_CONFIRMED, 102 FRIEND_CONFIRMED,
103 FRIEND_ONLINE, 103 FRIEND_ONLINE,
104}; 104} Friend_Status;
105 105
106/* Errors for m_addfriend 106/* Errors for m_addfriend
107 * FAERR - Friend Add Error 107 * FAERR - Friend Add Error
108 */ 108 */
109enum { 109typedef enum Friend_Add_Error {
110 FAERR_TOOLONG = -1, 110 FAERR_TOOLONG = -1,
111 FAERR_NOMESSAGE = -2, 111 FAERR_NOMESSAGE = -2,
112 FAERR_OWNKEY = -3, 112 FAERR_OWNKEY = -3,
@@ -114,24 +114,24 @@ enum {
114 FAERR_BADCHECKSUM = -6, 114 FAERR_BADCHECKSUM = -6,
115 FAERR_SETNEWNOSPAM = -7, 115 FAERR_SETNEWNOSPAM = -7,
116 FAERR_NOMEM = -8 116 FAERR_NOMEM = -8
117}; 117} Friend_Add_Error;
118 118
119 119
120/* Default start timeout in seconds between friend requests. */ 120/* Default start timeout in seconds between friend requests. */
121#define FRIENDREQUEST_TIMEOUT 5; 121#define FRIENDREQUEST_TIMEOUT 5
122 122
123enum { 123typedef enum Connection_Status {
124 CONNECTION_NONE, 124 CONNECTION_NONE,
125 CONNECTION_TCP, 125 CONNECTION_TCP,
126 CONNECTION_UDP, 126 CONNECTION_UDP,
127 CONNECTION_UNKNOWN 127 CONNECTION_UNKNOWN
128}; 128} Connection_Status;
129 129
130/* USERSTATUS - 130/* USERSTATUS -
131 * Represents userstatuses someone can have. 131 * Represents userstatuses someone can have.
132 */ 132 */
133 133
134typedef enum { 134typedef enum Userstatus {
135 USERSTATUS_NONE, 135 USERSTATUS_NONE,
136 USERSTATUS_AWAY, 136 USERSTATUS_AWAY,
137 USERSTATUS_BUSY, 137 USERSTATUS_BUSY,
@@ -150,57 +150,76 @@ struct File_Transfers {
150 unsigned int slots_allocated; /* number of slots allocated to this transfer. */ 150 unsigned int slots_allocated; /* number of slots allocated to this transfer. */
151 uint8_t id[FILE_ID_LENGTH]; 151 uint8_t id[FILE_ID_LENGTH];
152}; 152};
153enum { 153typedef enum Filestatus {
154 FILESTATUS_NONE, 154 FILESTATUS_NONE,
155 FILESTATUS_NOT_ACCEPTED, 155 FILESTATUS_NOT_ACCEPTED,
156 FILESTATUS_TRANSFERRING, 156 FILESTATUS_TRANSFERRING,
157 //FILESTATUS_BROKEN, 157 // FILESTATUS_BROKEN,
158 FILESTATUS_FINISHED 158 FILESTATUS_FINISHED
159}; 159} Filestatus;
160 160
161enum { 161typedef enum File_Pause {
162 FILE_PAUSE_NOT, 162 FILE_PAUSE_NOT,
163 FILE_PAUSE_US, 163 FILE_PAUSE_US,
164 FILE_PAUSE_OTHER, 164 FILE_PAUSE_OTHER,
165 FILE_PAUSE_BOTH 165 FILE_PAUSE_BOTH
166}; 166} File_Pause;
167 167
168enum { 168typedef enum Filecontrol {
169 FILECONTROL_ACCEPT, 169 FILECONTROL_ACCEPT,
170 FILECONTROL_PAUSE, 170 FILECONTROL_PAUSE,
171 FILECONTROL_KILL, 171 FILECONTROL_KILL,
172 FILECONTROL_SEEK 172 FILECONTROL_SEEK
173}; 173} Filecontrol;
174 174
175enum { 175typedef enum Filekind {
176 FILEKIND_DATA, 176 FILEKIND_DATA,
177 FILEKIND_AVATAR 177 FILEKIND_AVATAR
178}; 178} Filekind;
179 179
180 180
181typedef struct Messenger Messenger; 181typedef struct Messenger Messenger;
182 182
183typedef void m_self_connection_status_cb(Messenger *, unsigned int, void *); 183typedef void m_self_connection_status_cb(Messenger *m, unsigned int connection_status, void *user_data);
184typedef void m_friend_status_cb(Messenger *, uint32_t, unsigned int, void *); 184typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data);
185typedef void m_friend_connection_status_cb(Messenger *, uint32_t, unsigned int, void *); 185typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status,
186typedef void m_friend_message_cb(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *); 186 void *user_data);
187typedef void m_file_recv_control_cb(Messenger *, uint32_t, uint32_t, unsigned int, void *); 187typedef void m_friend_message_cb(Messenger *m, uint32_t friend_number, unsigned int message_type,
188typedef void m_friend_request_cb(Messenger *, const uint8_t *, const uint8_t *, size_t, void *); 188 const uint8_t *message, size_t length, void *user_data);
189typedef void m_friend_name_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *); 189typedef void m_file_recv_control_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, unsigned int control,
190typedef void m_friend_status_message_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *); 190 void *user_data);
191typedef void m_friend_typing_cb(Messenger *m, uint32_t, bool, void *); 191typedef void m_friend_request_cb(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length,
192typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t, uint32_t, void *); 192 void *user_data);
193typedef void m_file_recv_cb(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); 193typedef void m_friend_name_cb(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length,
194typedef void m_file_chunk_request_cb(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *); 194 void *user_data);
195typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); 195typedef void m_friend_status_message_cb(Messenger *m, uint32_t friend_number, const uint8_t *message, size_t length,
196typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *); 196 void *user_data);
197typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *); 197typedef void m_friend_typing_cb(Messenger *m, uint32_t friend_number, bool is_typing, void *user_data);
198typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t, uint8_t, void *); 198typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t friend_number, uint32_t message_id, void *user_data);
199typedef void m_conference_invite_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 199typedef void m_file_recv_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint32_t kind,
200typedef void m_msi_packet_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 200 uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data);
201typedef void m_file_chunk_request_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
202 size_t length, void *user_data);
203typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
204 const uint8_t *data, size_t length, void *user_data);
205typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length,
206 void *user_data);
207typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length,
208 void *user_data);
209typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number,
210 uint8_t connection_status, void *user_data);
211typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
212 void *user_data);
213typedef void m_msi_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length,
214 void *user_data);
201typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object); 215typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object);
202 216
203typedef struct { 217typedef struct RTP_Packet_Handler {
218 m_lossy_rtp_packet_cb *function;
219 void *object;
220} RTP_Packet_Handler;
221
222typedef struct Friend {
204 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; 223 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
205 int friendcon_id; 224 int friendcon_id;
206 225
@@ -228,10 +247,7 @@ typedef struct {
228 uint32_t num_sending_files; 247 uint32_t num_sending_files;
229 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; 248 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
230 249
231 struct { 250 RTP_Packet_Handler lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
232 m_lossy_rtp_packet_cb *function;
233 void *object;
234 } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
235 251
236 struct Receipts *receipts_start; 252 struct Receipts *receipts_start;
237 struct Receipts *receipts_end; 253 struct Receipts *receipts_end;
@@ -494,37 +510,35 @@ void m_callback_log(Messenger *m, logger_cb *function, void *context, void *user
494/* Set the function that will be executed when a friend request is received. 510/* Set the function that will be executed when a friend request is received.
495 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length) 511 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length)
496 */ 512 */
497void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, 513void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);
498 void *));
499 514
500/* Set the function that will be executed when a message from a friend is received. 515/* Set the function that will be executed when a message from a friend is received.
501 * Function format is: function(uint32_t friendnumber, unsigned int type, uint8_t * message, uint32_t length) 516 * Function format is: function(uint32_t friendnumber, unsigned int type, uint8_t * message, uint32_t length)
502 */ 517 */
503void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, const uint8_t *, 518void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function);
504 size_t, void *));
505 519
506/* Set the callback for name changes. 520/* Set the callback for name changes.
507 * Function(uint32_t friendnumber, uint8_t *newname, size_t length) 521 * Function(uint32_t friendnumber, uint8_t *newname, size_t length)
508 * You are not responsible for freeing newname. 522 * You are not responsible for freeing newname.
509 */ 523 */
510void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); 524void m_callback_namechange(Messenger *m, m_friend_name_cb *function);
511 525
512/* Set the callback for status message changes. 526/* Set the callback for status message changes.
513 * Function(uint32_t friendnumber, uint8_t *newstatus, size_t length) 527 * Function(uint32_t friendnumber, uint8_t *newstatus, size_t length)
514 * 528 *
515 * You are not responsible for freeing newstatus 529 * You are not responsible for freeing newstatus
516 */ 530 */
517void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); 531void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function);
518 532
519/* Set the callback for status type changes. 533/* Set the callback for status type changes.
520 * Function(uint32_t friendnumber, Userstatus kind) 534 * Function(uint32_t friendnumber, Userstatus kind)
521 */ 535 */
522void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)); 536void m_callback_userstatus(Messenger *m, m_friend_status_cb *function);
523 537
524/* Set the callback for typing changes. 538/* Set the callback for typing changes.
525 * Function(uint32_t friendnumber, uint8_t is_typing) 539 * Function(uint32_t friendnumber, uint8_t is_typing)
526 */ 540 */
527void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, bool, void *)); 541void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
528 542
529/* Set the callback for read receipts. 543/* Set the callback for read receipts.
530 * Function(uint32_t friendnumber, uint32_t receipt) 544 * Function(uint32_t friendnumber, uint32_t receipt)
@@ -535,7 +549,7 @@ void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_
535 * Since core doesn't track ids for you, receipt may not correspond to any message. 549 * Since core doesn't track ids for you, receipt may not correspond to any message.
536 * In that case, you should discard it. 550 * In that case, you should discard it.
537 */ 551 */
538void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *)); 552void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);
539 553
540/* Set the callback for connection status changes. 554/* Set the callback for connection status changes.
541 * function(uint32_t friendnumber, uint8_t status) 555 * function(uint32_t friendnumber, uint8_t status)
@@ -548,17 +562,17 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32
548 * being previously online" part. 562 * being previously online" part.
549 * It's assumed that when adding friends, their connection status is offline. 563 * It's assumed that when adding friends, their connection status is offline.
550 */ 564 */
551void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)); 565void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function);
552 566
553/* Same as previous but for internal A/V core usage only */ 567/* Same as previous but for internal A/V core usage only */
554void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *), 568void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function,
555 void *userdata); 569 void *userdata);
556 570
557 571
558/* Set the callback for typing changes. 572/* Set the callback for typing changes.
559 * Function(unsigned int connection_status (0 = not connected, 1 = TCP only, 2 = UDP + TCP)) 573 * Function(unsigned int connection_status (0 = not connected, 1 = TCP only, 2 = UDP + TCP))
560 */ 574 */
561void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *)); 575void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);
562 576
563/**********CONFERENCES************/ 577/**********CONFERENCES************/
564 578
@@ -566,8 +580,7 @@ void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, uns
566 * 580 *
567 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) 581 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
568 */ 582 */
569void m_callback_conference_invite(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t, 583void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function);
570 void *));
571 584
572/* Send a conference invite packet. 585/* Send a conference invite packet.
573 * 586 *
@@ -583,8 +596,7 @@ int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, cons
583 * 596 *
584 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) 597 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata)
585 */ 598 */
586void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, 599void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function);
587 const uint8_t *, size_t, void *));
588 600
589 601
590/* Set the callback for file control requests. 602/* Set the callback for file control requests.
@@ -592,22 +604,21 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uin
592 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata) 604 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata)
593 * 605 *
594 */ 606 */
595void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *)); 607void callback_file_control(Messenger *m, m_file_recv_control_cb *function);
596 608
597/* Set the callback for file data. 609/* Set the callback for file data.
598 * 610 *
599 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, uint8_t *data, size_t length, void *userdata) 611 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, uint8_t *data, size_t length, void *userdata)
600 * 612 *
601 */ 613 */
602void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, 614void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function);
603 size_t, void *));
604 615
605/* Set the callback for file request chunk. 616/* Set the callback for file request chunk.
606 * 617 *
607 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata) 618 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata)
608 * 619 *
609 */ 620 */
610void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *)); 621void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function);
611 622
612 623
613/* Copy the file transfer file id to file_id 624/* Copy the file transfer file id to file_id
@@ -686,8 +697,7 @@ uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t fi
686 * 697 *
687 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) 698 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
688 */ 699 */
689void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *), 700void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata);
690 void *userdata);
691 701
692/* Send an msi packet. 702/* Send an msi packet.
693 * 703 *
@@ -701,16 +711,15 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
701 * return -1 on failure. 711 * return -1 on failure.
702 * return 0 on success. 712 * return 0 on success.
703 */ 713 */
704int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, 714int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte,
705 uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object); 715 m_lossy_rtp_packet_cb *packet_handler_callback, void *object);
706 716
707/**********************************************/ 717/**********************************************/
708 718
709/* Set handlers for custom lossy packets. 719/* Set handlers for custom lossy packets.
710 * 720 *
711 */ 721 */
712void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 722void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *packet_handler_callback);
713 uint32_t friendnumber, const uint8_t *data, size_t len, void *object));
714 723
715/* High level function to send custom lossy packets. 724/* High level function to send custom lossy packets.
716 * 725 *
@@ -727,8 +736,7 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
727/* Set handlers for custom lossless packets. 736/* Set handlers for custom lossless packets.
728 * 737 *
729 */ 738 */
730void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 739void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *packet_handler_callback);
731 uint32_t friendnumber, const uint8_t *data, size_t len, void *object));
732 740
733/* High level function to send custom lossless packets. 741/* High level function to send custom lossless packets.
734 * 742 *
@@ -743,12 +751,12 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
743 751
744/**********************************************/ 752/**********************************************/
745 753
746enum { 754typedef enum Messenger_Error {
747 MESSENGER_ERROR_NONE, 755 MESSENGER_ERROR_NONE,
748 MESSENGER_ERROR_PORT, 756 MESSENGER_ERROR_PORT,
749 MESSENGER_ERROR_TCP_SERVER, 757 MESSENGER_ERROR_TCP_SERVER,
750 MESSENGER_ERROR_OTHER 758 MESSENGER_ERROR_OTHER
751}; 759} Messenger_Error;
752 760
753/* Run this at startup. 761/* Run this at startup.
754 * return allocated instance of Messenger on success. 762 * return allocated instance of Messenger on success.
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h
index a29cc7be..024befee 100644
--- a/toxcore/friend_connection.h
+++ b/toxcore/friend_connection.h
@@ -55,11 +55,11 @@
55#define SHARE_RELAYS_INTERVAL (5 * 60) 55#define SHARE_RELAYS_INTERVAL (5 * 60)
56 56
57 57
58enum { 58typedef enum Friendconn_Status {
59 FRIENDCONN_STATUS_NONE, 59 FRIENDCONN_STATUS_NONE,
60 FRIENDCONN_STATUS_CONNECTING, 60 FRIENDCONN_STATUS_CONNECTING,
61 FRIENDCONN_STATUS_CONNECTED 61 FRIENDCONN_STATUS_CONNECTED
62}; 62} Friendconn_Status;
63 63
64typedef struct Friend_Connections Friend_Connections; 64typedef struct Friend_Connections Friend_Connections;
65 65
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h
index 97cd3164..77c3af68 100644
--- a/toxcore/friend_requests.h
+++ b/toxcore/friend_requests.h
@@ -41,14 +41,15 @@ uint32_t get_nospam(const Friend_Requests *fr);
41 */ 41 */
42int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk); 42int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk);
43 43
44typedef void fr_friend_request_cb(void *, const uint8_t *, const uint8_t *, size_t, void *); 44typedef void fr_friend_request_cb(void *object, const uint8_t *public_key, const uint8_t *message, size_t length,
45 void *user_data);
45 46
46/* Set the function that will be executed when a friend request for us is received. 47/* Set the function that will be executed when a friend request for us is received.
47 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata) 48 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata)
48 */ 49 */
49void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object); 50void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object);
50 51
51typedef int filter_function_cb(const uint8_t *, void *); 52typedef int filter_function_cb(const uint8_t *public_key, void *user_data);
52 53
53/* Set the function used to check if a friend request should be displayed to the user or not. 54/* Set the function used to check if a friend request should be displayed to the user or not.
54 * Function format is int function(uint8_t * public_key, void * userdata) 55 * Function format is int function(uint8_t * public_key, void * userdata)
diff --git a/toxcore/list.h b/toxcore/list.h
index 8c6ddbf3..628b46a0 100644
--- a/toxcore/list.h
+++ b/toxcore/list.h
@@ -28,12 +28,12 @@
28 28
29#include <stdint.h> 29#include <stdint.h>
30 30
31typedef struct { 31typedef struct BS_List {
32 uint32_t n; //number of elements 32 uint32_t n; // number of elements
33 uint32_t capacity; //number of elements memory is allocated for 33 uint32_t capacity; // number of elements memory is allocated for
34 uint32_t element_size; //size of the elements 34 uint32_t element_size; // size of the elements
35 uint8_t *data; //array of elements 35 uint8_t *data; // array of elements
36 int *ids; //array of element ids 36 int *ids; // array of element ids
37} BS_List; 37} BS_List;
38 38
39/* Initialize a list, element_size is the size of the elements in the list and 39/* Initialize a list, element_size is the size of the elements in the list and
diff --git a/toxcore/logger.c b/toxcore/logger.c
index edde806f..d7f84ad1 100644
--- a/toxcore/logger.c
+++ b/toxcore/logger.c
@@ -41,7 +41,7 @@ struct Logger {
41}; 41};
42 42
43#ifdef USE_STDERR_LOGGER 43#ifdef USE_STDERR_LOGGER
44static const char *logger_level_name(LOGGER_LEVEL level) 44static const char *logger_level_name(Logger_Level level)
45{ 45{
46 switch (level) { 46 switch (level) {
47 case LOG_TRACE: 47 case LOG_TRACE:
@@ -63,7 +63,7 @@ static const char *logger_level_name(LOGGER_LEVEL level)
63 return "<unknown>"; 63 return "<unknown>";
64} 64}
65 65
66static void logger_stderr_handler(void *context, LOGGER_LEVEL level, const char *file, int line, const char *func, 66static void logger_stderr_handler(void *context, Logger_Level level, const char *file, int line, const char *func,
67 const char *message, void *userdata) 67 const char *message, void *userdata)
68{ 68{
69 // GL stands for "global logger". 69 // GL stands for "global logger".
@@ -97,7 +97,7 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
97 log->userdata = userdata; 97 log->userdata = userdata;
98} 98}
99 99
100void logger_write(const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, 100void logger_write(const Logger *log, Logger_Level level, const char *file, int line, const char *func,
101 const char *format, ...) 101 const char *format, ...)
102{ 102{
103 if (!log) { 103 if (!log) {
diff --git a/toxcore/logger.h b/toxcore/logger.h
index acd21fb8..38cc0ac9 100644
--- a/toxcore/logger.h
+++ b/toxcore/logger.h
@@ -32,17 +32,17 @@
32#define MIN_LOGGER_LEVEL LOG_INFO 32#define MIN_LOGGER_LEVEL LOG_INFO
33#endif 33#endif
34 34
35typedef enum { 35typedef enum Logger_Level {
36 LOG_TRACE, 36 LOG_TRACE,
37 LOG_DEBUG, 37 LOG_DEBUG,
38 LOG_INFO, 38 LOG_INFO,
39 LOG_WARNING, 39 LOG_WARNING,
40 LOG_ERROR 40 LOG_ERROR
41} LOGGER_LEVEL; 41} Logger_Level;
42 42
43typedef struct Logger Logger; 43typedef struct Logger Logger;
44 44
45typedef void logger_cb(void *context, LOGGER_LEVEL level, const char *file, int line, 45typedef void logger_cb(void *context, Logger_Level level, const char *file, int line,
46 const char *func, const char *message, void *userdata); 46 const char *func, const char *message, void *userdata);
47 47
48/** 48/**
@@ -72,7 +72,7 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
72 * assertion failure otherwise. 72 * assertion failure otherwise.
73 */ 73 */
74void logger_write( 74void logger_write(
75 const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, 75 const Logger *log, Logger_Level level, const char *file, int line, const char *func,
76 const char *format, ...) GNU_PRINTF(6, 7); 76 const char *format, ...) GNU_PRINTF(6, 7);
77 77
78 78
diff --git a/toxcore/onion.h b/toxcore/onion.h
index 8762d1e1..0e025a1c 100644
--- a/toxcore/onion.h
+++ b/toxcore/onion.h
@@ -26,7 +26,9 @@
26 26
27#include "DHT.h" 27#include "DHT.h"
28 28
29typedef struct { 29typedef int onion_recv_1_cb(void *object, IP_Port dest, const uint8_t *data, uint16_t length);
30
31typedef struct Onion {
30 DHT *dht; 32 DHT *dht;
31 Networking_Core *net; 33 Networking_Core *net;
32 uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE]; 34 uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
@@ -36,7 +38,7 @@ typedef struct {
36 Shared_Keys shared_keys_2; 38 Shared_Keys shared_keys_2;
37 Shared_Keys shared_keys_3; 39 Shared_Keys shared_keys_3;
38 40
39 int (*recv_1_function)(void *, IP_Port, const uint8_t *, uint16_t); 41 onion_recv_1_cb *recv_1_function;
40 void *callback_object; 42 void *callback_object;
41} Onion; 43} Onion;
42 44
@@ -56,7 +58,7 @@ typedef struct {
56 58
57#define ONION_PATH_LENGTH 3 59#define ONION_PATH_LENGTH 3
58 60
59typedef struct { 61typedef struct Onion_Path {
60 uint8_t shared_key1[CRYPTO_SHARED_KEY_SIZE]; 62 uint8_t shared_key1[CRYPTO_SHARED_KEY_SIZE];
61 uint8_t shared_key2[CRYPTO_SHARED_KEY_SIZE]; 63 uint8_t shared_key2[CRYPTO_SHARED_KEY_SIZE];
62 uint8_t shared_key3[CRYPTO_SHARED_KEY_SIZE]; 64 uint8_t shared_key3[CRYPTO_SHARED_KEY_SIZE];
@@ -150,8 +152,6 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data,
150 */ 152 */
151int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce); 153int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce);
152 154
153typedef int onion_recv_1_cb(void *, IP_Port, const uint8_t *, uint16_t);
154
155/* Set the callback to be called when the dest ip_port doesn't have TOX_AF_INET6 or TOX_AF_INET as the family. 155/* Set the callback to be called when the dest ip_port doesn't have TOX_AF_INET6 or TOX_AF_INET as the family.
156 * 156 *
157 * Format: function(void *object, IP_Port dest, uint8_t *data, uint16_t length) 157 * Format: function(void *object, IP_Port dest, uint8_t *data, uint16_t length)
diff --git a/toxcore/onion_announce.h b/toxcore/onion_announce.h
index 36484ff2..84e76a38 100644
--- a/toxcore/onion_announce.h
+++ b/toxcore/onion_announce.h
@@ -40,7 +40,7 @@
40#define ONION_DATA_RESPONSE_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE) 40#define ONION_DATA_RESPONSE_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
41 41
42#if ONION_PING_ID_SIZE != CRYPTO_PUBLIC_KEY_SIZE 42#if ONION_PING_ID_SIZE != CRYPTO_PUBLIC_KEY_SIZE
43#error announce response packets assume that ONION_PING_ID_SIZE is equal to CRYPTO_PUBLIC_KEY_SIZE 43#error "announce response packets assume that ONION_PING_ID_SIZE is equal to CRYPTO_PUBLIC_KEY_SIZE"
44#endif 44#endif
45 45
46#define ONION_DATA_REQUEST_MIN_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE) 46#define ONION_DATA_REQUEST_MIN_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 560c2851..6e73c3ab 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -30,7 +30,7 @@
30#include "ping_array.h" 30#include "ping_array.h"
31 31
32#define MAX_ONION_CLIENTS 8 32#define MAX_ONION_CLIENTS 8
33#define MAX_ONION_CLIENTS_ANNOUNCE 12 /* Number of nodes to announce ourselves to. */ 33#define MAX_ONION_CLIENTS_ANNOUNCE 12 // Number of nodes to announce ourselves to.
34#define ONION_NODE_PING_INTERVAL 15 34#define ONION_NODE_PING_INTERVAL 15
35#define ONION_NODE_TIMEOUT ONION_NODE_PING_INTERVAL 35#define ONION_NODE_TIMEOUT ONION_NODE_PING_INTERVAL
36 36