summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-05 10:31:29 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-05 23:09:28 +0000
commit8739f7fccb7cafc54ca0f5fa074c9a740f7048ba (patch)
tree88e9f53fa6e734cd8095487d1896c56f844c782c /toxcore/Messenger.h
parent64d0297acc7d6a1697683052e15cc76383312c38 (diff)
Make tox.c unambiguously parseable.
Rules: 1. Constants are uppercase names: THE_CONSTANT. 2. SUE[1] types start with an uppercase letter and have at least one lowercase letter in it: The_Type, THE_Type. 3. Function types end in "_cb": tox_friend_connection_cb. 4. Variable and function names are all lowercase: the_function. This makes it easier for humans reading the code to determine what an identifier means. I'm not convinced by the enum type name change, but I don't know a better rule. Currently, a lot of enum types are spelled like constants, which is confusing. [1] struct/union/enum
Diffstat (limited to 'toxcore/Messenger.h')
-rw-r--r--toxcore/Messenger.h70
1 files changed, 44 insertions, 26 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 402eb916..47025fcc 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -136,8 +136,7 @@ typedef enum {
136 USERSTATUS_AWAY, 136 USERSTATUS_AWAY,
137 USERSTATUS_BUSY, 137 USERSTATUS_BUSY,
138 USERSTATUS_INVALID 138 USERSTATUS_INVALID
139} 139} Userstatus;
140USERSTATUS;
141 140
142#define FILE_ID_LENGTH 32 141#define FILE_ID_LENGTH 32
143 142
@@ -181,6 +180,26 @@ enum {
181 180
182typedef struct Messenger Messenger; 181typedef struct Messenger Messenger;
183 182
183typedef void m_self_connection_status_cb(Messenger *, unsigned int, void *);
184typedef void m_friend_status_cb(Messenger *, uint32_t, unsigned int, void *);
185typedef void m_friend_connection_status_cb(Messenger *, uint32_t, unsigned int, void *);
186typedef void m_friend_message_cb(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *);
187typedef void m_file_recv_control_cb(Messenger *, uint32_t, uint32_t, unsigned int, void *);
188typedef void m_friend_request_cb(Messenger *, const uint8_t *, const uint8_t *, size_t, void *);
189typedef void m_friend_name_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
190typedef void m_friend_status_message_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
191typedef void m_friend_typing_cb(Messenger *m, uint32_t, bool, void *);
192typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t, uint32_t, void *);
193typedef void m_file_recv_cb(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
194typedef void m_file_chunk_request_cb(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
195typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
196typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
197typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
198typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t, uint8_t, void *);
199typedef void m_conference_invite_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
200typedef void m_msi_packet_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
201typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object);
202
184typedef struct { 203typedef struct {
185 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; 204 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
186 int friendcon_id; 205 int friendcon_id;
@@ -195,7 +214,7 @@ typedef struct {
195 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; 214 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
196 uint16_t statusmessage_length; 215 uint16_t statusmessage_length;
197 uint8_t statusmessage_sent; 216 uint8_t statusmessage_sent;
198 USERSTATUS userstatus; 217 Userstatus userstatus;
199 uint8_t userstatus_sent; 218 uint8_t userstatus_sent;
200 uint8_t user_istyping; 219 uint8_t user_istyping;
201 uint8_t user_istyping_sent; 220 uint8_t user_istyping_sent;
@@ -210,7 +229,7 @@ typedef struct {
210 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; 229 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
211 230
212 struct { 231 struct {
213 int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object); 232 m_lossy_rtp_packet_cb *function;
214 void *object; 233 void *object;
215 } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED]; 234 } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
216 235
@@ -239,7 +258,7 @@ struct Messenger {
239 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; 258 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
240 uint16_t statusmessage_length; 259 uint16_t statusmessage_length;
241 260
242 USERSTATUS userstatus; 261 Userstatus userstatus;
243 262
244 Friend *friendlist; 263 Friend *friendlist;
245 uint32_t numfriends; 264 uint32_t numfriends;
@@ -249,32 +268,31 @@ struct Messenger {
249 uint8_t has_added_relays; // If the first connection has occurred in do_messenger 268 uint8_t has_added_relays; // If the first connection has occurred in do_messenger
250 Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config 269 Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
251 270
252 void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *); 271 m_friend_message_cb *friend_message;
253 void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 272 m_friend_name_cb *friend_namechange;
254 void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 273 m_friend_status_message_cb *friend_statusmessagechange;
255 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 274 m_friend_status_cb *friend_userstatuschange;
256 void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *); 275 m_friend_typing_cb *friend_typingchange;
257 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *); 276 m_friend_read_receipt_cb *read_receipt;
258 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 277 m_friend_connection_status_cb *friend_connectionstatuschange;
259 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *); 278 m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
260 void *friend_connectionstatuschange_internal_userdata; 279 void *friend_connectionstatuschange_internal_userdata;
261 280
262 void *conferences_object; /* Set by new_groupchats()*/ 281 void *conferences_object; /* Set by new_groupchats()*/
263 void (*conference_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 282 m_conference_invite_cb *conference_invite;
264 283
265 void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, 284 m_file_recv_cb *file_sendrequest;
266 void *); 285 m_file_recv_control_cb *file_filecontrol;
267 void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *); 286 m_file_recv_chunk_cb *file_filedata;
268 void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); 287 m_file_chunk_request_cb *file_reqchunk;
269 void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
270 288
271 void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 289 m_msi_packet_cb *msi_packet;
272 void *msi_packet_userdata; 290 void *msi_packet_userdata;
273 291
274 void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 292 m_friend_lossy_packet_cb *lossy_packethandler;
275 void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 293 m_friend_lossless_packet_cb *lossless_packethandler;
276 294
277 void (*core_connection_change)(struct Messenger *m, unsigned int, void *); 295 m_self_connection_status_cb *core_connection_change;
278 unsigned int last_connection_status; 296 unsigned int last_connection_status;
279 297
280 Messenger_Options options; 298 Messenger_Options options;
@@ -440,9 +458,9 @@ int m_get_self_statusmessage_size(const Messenger *m);
440int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); 458int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
441int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf); 459int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
442 460
443/* return one of USERSTATUS values. 461/* return one of Userstatus values.
444 * Values unknown to your application should be represented as USERSTATUS_NONE. 462 * Values unknown to your application should be represented as USERSTATUS_NONE.
445 * As above, the self variant will return our own USERSTATUS. 463 * As above, the self variant will return our own Userstatus.
446 * If friendnumber is invalid, this shall return USERSTATUS_INVALID. 464 * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
447 */ 465 */
448uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber); 466uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
@@ -499,7 +517,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t
499void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); 517void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *));
500 518
501/* Set the callback for status type changes. 519/* Set the callback for status type changes.
502 * Function(uint32_t friendnumber, USERSTATUS kind) 520 * Function(uint32_t friendnumber, Userstatus kind)
503 */ 521 */
504void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)); 522void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *));
505 523