summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Rouesnel <w.rouesnel@gmail.com>2014-12-09 03:32:31 +1100
committerWill Rouesnel <w.rouesnel@gmail.com>2014-12-09 07:51:49 +1100
commit8a56cb3b5814d8152613fefb74a11bb28dc70f7a (patch)
treeeaccf6de5baf0bfe3bfaa91ffebcf46caaffa22d
parentf1db6e7d6cb94584fbe03a30aebca36666b6e033 (diff)
Change prototype for custom_packet_handler functions
Change the custom_packet_handler callback function interface to be consistent with other callback interfaces. The new interface takes the Messenger object calling as the first parameter, and moves the user data object to be the last parameter. This makes it comparable to the callbacks for file transfer and the like, and should simplify building interfaces. The new prototype is: int (*)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object)
-rw-r--r--toxav/rtp.c2
-rw-r--r--toxcore/Messenger.c8
-rw-r--r--toxcore/Messenger.h14
-rw-r--r--toxcore/tox.c4
-rw-r--r--toxcore/tox.h4
5 files changed, 17 insertions, 15 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 6eb61a81..3696fd0a 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -341,7 +341,7 @@ RTPMessage *msg_parse ( const uint8_t *data, int length )
341/** 341/**
342 * Callback for networking core. 342 * Callback for networking core.
343 */ 343 */
344int rtp_handle_packet ( void *object, const uint8_t *data, uint32_t length ) 344int rtp_handle_packet ( Messenger* m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object )
345{ 345{
346 RTPSession *session = object; 346 RTPSession *session = object;
347 RTPMessage *msg; 347 RTPMessage *msg;
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 704a34b4..45b6fa25 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1441,13 +1441,13 @@ static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_
1441 1441
1442 if (m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function) 1442 if (m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function)
1443 return m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function( 1443 return m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function(
1444 m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].object, packet, length); 1444 m, friend_num, packet, length, m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].object);
1445 1445
1446 return 1; 1446 return 1;
1447} 1447}
1448 1448
1449int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, 1449int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
1450 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) 1450 int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object)
1451{ 1451{
1452 if (friend_not_valid(m, friendnumber)) 1452 if (friend_not_valid(m, friendnumber))
1453 return -1; 1453 return -1;
@@ -1490,13 +1490,13 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
1490 1490
1491 if (m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function) 1491 if (m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function)
1492 return m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function( 1492 return m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function(
1493 m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].object, packet, length); 1493 m, friend_num, packet, length, m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].object);
1494 1494
1495 return 1; 1495 return 1;
1496} 1496}
1497 1497
1498int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, 1498int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
1499 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) 1499 int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object)
1500{ 1500{
1501 if (friend_not_valid(m, friendnumber)) 1501 if (friend_not_valid(m, friendnumber))
1502 return -1; 1502 return -1;
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index fd4646e9..2d31f0b9 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -189,6 +189,8 @@ enum {
189 FILECONTROL_RESUME_BROKEN 189 FILECONTROL_RESUME_BROKEN
190}; 190};
191 191
192typedef struct Messenger Messenger;
193
192typedef struct { 194typedef struct {
193 uint8_t client_id[crypto_box_PUBLICKEYBYTES]; 195 uint8_t client_id[crypto_box_PUBLICKEYBYTES];
194 int friendcon_id; 196 int friendcon_id;
@@ -222,18 +224,18 @@ typedef struct {
222 AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend. 224 AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend.
223 225
224 struct { 226 struct {
225 int (*function)(void *object, const uint8_t *data, uint32_t len); 227 int (*function)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object);
226 void *object; 228 void *object;
227 } lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE]; 229 } lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
228 230
229 struct { 231 struct {
230 int (*function)(void *object, const uint8_t *data, uint32_t len); 232 int (*function)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object);
231 void *object; 233 void *object;
232 } lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE]; 234 } lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
233} Friend; 235} Friend;
234 236
235 237
236typedef struct Messenger { 238struct Messenger {
237 239
238 Networking_Core *net; 240 Networking_Core *net;
239 Net_Crypto *net_crypto; 241 Net_Crypto *net_crypto;
@@ -310,7 +312,7 @@ typedef struct Messenger {
310 void *msi_packet_userdata; 312 void *msi_packet_userdata;
311 313
312 Messenger_Options options; 314 Messenger_Options options;
313} Messenger; 315};
314 316
315/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] 317/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
316 * 318 *
@@ -841,7 +843,7 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
841 * return 0 on success. 843 * return 0 on success.
842 */ 844 */
843int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, 845int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
844 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); 846 int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object);
845 847
846/* High level function to send custom lossy packets. 848/* High level function to send custom lossy packets.
847 * 849 *
@@ -859,7 +861,7 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
859 * return 0 on success. 861 * return 0 on success.
860 */ 862 */
861int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, 863int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
862 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); 864 int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object);
863 865
864/* High level function to send custom lossless packets. 866/* High level function to send custom lossless packets.
865 * 867 *
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 933f0f71..b85a47b2 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -490,7 +490,7 @@ void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key)
490 * return 0 on success. 490 * return 0 on success.
491 */ 491 */
492int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, 492int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
493 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) 493 int (*packet_handler_callback)(Messenger *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object)
494{ 494{
495 Messenger *m = tox; 495 Messenger *m = tox;
496 496
@@ -527,7 +527,7 @@ int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *d
527 * return 0 on success. 527 * return 0 on success.
528 */ 528 */
529int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, 529int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
530 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) 530 int (*packet_handler_callback)(Messenger *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object)
531{ 531{
532 Messenger *m = tox; 532 Messenger *m = tox;
533 533
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 58d86a83..2caa77e9 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -385,7 +385,7 @@ void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key);
385 * return 0 on success. 385 * return 0 on success.
386 */ 386 */
387int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, 387int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
388 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); 388 int (*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object);
389 389
390/* Function to send custom lossy packets. 390/* Function to send custom lossy packets.
391 * First byte of data must be in the range: 200-254. 391 * First byte of data must be in the range: 200-254.
@@ -405,7 +405,7 @@ int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *d
405 * return 0 on success. 405 * return 0 on success.
406 */ 406 */
407int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, 407int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
408 int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); 408 int (*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object);
409 409
410/* Function to send custom lossless packets. 410/* Function to send custom lossless packets.
411 * First byte of data must be in the range: 160-191. 411 * First byte of data must be in the range: 160-191.