diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 61 | ||||
-rw-r--r-- | toxcore/Messenger.h | 41 |
2 files changed, 52 insertions, 50 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 22adb088..33d087de 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1333,17 +1333,30 @@ static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_ | |||
1333 | if (friend_not_valid(m, friend_num)) | 1333 | if (friend_not_valid(m, friend_num)) |
1334 | return 1; | 1334 | return 1; |
1335 | 1335 | ||
1336 | if (m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function) | 1336 | if (packet[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) { |
1337 | return m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function( | 1337 | if (m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % PACKET_LOSSY_AV_RESERVED].function) |
1338 | m, friend_num, packet, length, m->friendlist[friend_num].lossy_packethandlers[packet[0] % | 1338 | return m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % PACKET_LOSSY_AV_RESERVED].function( |
1339 | PACKET_ID_LOSSY_RANGE_SIZE].object); | 1339 | m, friend_num, packet, length, m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % |
1340 | PACKET_LOSSY_AV_RESERVED].object); | ||
1341 | |||
1342 | return 1; | ||
1343 | } | ||
1344 | |||
1345 | if (m->lossy_packethandler) | ||
1346 | m->lossy_packethandler(m, friend_num, packet, length, m->lossy_packethandler_userdata); | ||
1340 | 1347 | ||
1341 | return 1; | 1348 | return 1; |
1342 | } | 1349 | } |
1343 | 1350 | ||
1344 | int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, | 1351 | void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, |
1345 | int (*packet_handler_callback)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object), | 1352 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object) |
1346 | void *object) | 1353 | { |
1354 | m->lossy_packethandler = packet_handler_callback; | ||
1355 | m->lossy_packethandler_userdata = object; | ||
1356 | } | ||
1357 | |||
1358 | int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, | ||
1359 | uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object) | ||
1347 | { | 1360 | { |
1348 | if (friend_not_valid(m, friendnumber)) | 1361 | if (friend_not_valid(m, friendnumber)) |
1349 | return -1; | 1362 | return -1; |
@@ -1351,14 +1364,16 @@ int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint | |||
1351 | if (byte < PACKET_ID_LOSSY_RANGE_START) | 1364 | if (byte < PACKET_ID_LOSSY_RANGE_START) |
1352 | return -1; | 1365 | return -1; |
1353 | 1366 | ||
1354 | if (byte >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) | 1367 | if (byte >= (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) |
1355 | return -1; | 1368 | return -1; |
1356 | 1369 | ||
1357 | m->friendlist[friendnumber].lossy_packethandlers[byte % PACKET_ID_LOSSY_RANGE_SIZE].function = packet_handler_callback; | 1370 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = |
1358 | m->friendlist[friendnumber].lossy_packethandlers[byte % PACKET_ID_LOSSY_RANGE_SIZE].object = object; | 1371 | packet_handler_callback; |
1372 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].object = object; | ||
1359 | return 0; | 1373 | return 0; |
1360 | } | 1374 | } |
1361 | 1375 | ||
1376 | |||
1362 | int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) | 1377 | int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) |
1363 | { | 1378 | { |
1364 | if (friend_not_valid(m, friendnumber)) | 1379 | if (friend_not_valid(m, friendnumber)) |
@@ -1384,31 +1399,17 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin | |||
1384 | if (packet[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) | 1399 | if (packet[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) |
1385 | return -1; | 1400 | return -1; |
1386 | 1401 | ||
1387 | if (m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function) | 1402 | if (m->lossless_packethandler) |
1388 | return m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function( | 1403 | m->lossless_packethandler(m, friend_num, packet, length, m->lossless_packethandler_userdata); |
1389 | m, friend_num, packet, length, m->friendlist[friend_num].lossless_packethandlers[packet[0] % | ||
1390 | PACKET_ID_LOSSLESS_RANGE_SIZE].object); | ||
1391 | 1404 | ||
1392 | return 1; | 1405 | return 1; |
1393 | } | 1406 | } |
1394 | 1407 | ||
1395 | int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, | 1408 | void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, |
1396 | int (*packet_handler_callback)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object), | 1409 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object) |
1397 | void *object) | ||
1398 | { | 1410 | { |
1399 | if (friend_not_valid(m, friendnumber)) | 1411 | m->lossless_packethandler = packet_handler_callback; |
1400 | return -1; | 1412 | m->lossless_packethandler_userdata = object; |
1401 | |||
1402 | if (byte < PACKET_ID_LOSSLESS_RANGE_START) | ||
1403 | return -1; | ||
1404 | |||
1405 | if (byte >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) | ||
1406 | return -1; | ||
1407 | |||
1408 | m->friendlist[friendnumber].lossless_packethandlers[byte % PACKET_ID_LOSSLESS_RANGE_SIZE].function = | ||
1409 | packet_handler_callback; | ||
1410 | m->friendlist[friendnumber].lossless_packethandlers[byte % PACKET_ID_LOSSLESS_RANGE_SIZE].object = object; | ||
1411 | return 0; | ||
1412 | } | 1413 | } |
1413 | 1414 | ||
1414 | int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) | 1415 | int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 48235900..5d5e5879 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -63,6 +63,7 @@ | |||
63 | /* All packets starting with a byte in this range can be used for anything. */ | 63 | /* All packets starting with a byte in this range can be used for anything. */ |
64 | #define PACKET_ID_LOSSLESS_RANGE_START 160 | 64 | #define PACKET_ID_LOSSLESS_RANGE_START 160 |
65 | #define PACKET_ID_LOSSLESS_RANGE_SIZE 32 | 65 | #define PACKET_ID_LOSSLESS_RANGE_SIZE 32 |
66 | #define PACKET_LOSSY_AV_RESERVED 8 /* Number of lossy packet types at start of range reserved for A/V. */ | ||
66 | 67 | ||
67 | typedef struct { | 68 | typedef struct { |
68 | uint8_t ipv6enabled; | 69 | uint8_t ipv6enabled; |
@@ -179,14 +180,9 @@ typedef struct { | |||
179 | struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; | 180 | struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; |
180 | 181 | ||
181 | struct { | 182 | struct { |
182 | int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object); | 183 | int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object); |
183 | void *object; | 184 | void *object; |
184 | } lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE]; | 185 | } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED]; |
185 | |||
186 | struct { | ||
187 | int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object); | ||
188 | void *object; | ||
189 | } lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE]; | ||
190 | 186 | ||
191 | struct Receipts *receipts_start; | 187 | struct Receipts *receipts_start; |
192 | struct Receipts *receipts_end; | 188 | struct Receipts *receipts_end; |
@@ -260,6 +256,11 @@ struct Messenger { | |||
260 | void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); | 256 | void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); |
261 | void *msi_packet_userdata; | 257 | void *msi_packet_userdata; |
262 | 258 | ||
259 | void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); | ||
260 | void *lossy_packethandler_userdata; | ||
261 | void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); | ||
262 | void *lossless_packethandler_userdata; | ||
263 | |||
263 | Messenger_Options options; | 264 | Messenger_Options options; |
264 | }; | 265 | }; |
265 | 266 | ||
@@ -631,16 +632,21 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, uint32_t | |||
631 | */ | 632 | */ |
632 | int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); | 633 | int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); |
633 | 634 | ||
634 | /**********************************************/ | 635 | /* Set handlers for lossy rtp packets. |
635 | |||
636 | /* Set handlers for custom lossy packets (RTP packets for example.) | ||
637 | * | 636 | * |
638 | * return -1 on failure. | 637 | * return -1 on failure. |
639 | * return 0 on success. | 638 | * return 0 on success. |
640 | */ | 639 | */ |
641 | int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, | 640 | int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, |
642 | int (*packet_handler_callback)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object), | 641 | uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object); |
643 | void *object); | 642 | |
643 | /**********************************************/ | ||
644 | |||
645 | /* Set handlers for custom lossy packets. | ||
646 | * | ||
647 | */ | ||
648 | void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, | ||
649 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object); | ||
644 | 650 | ||
645 | /* High level function to send custom lossy packets. | 651 | /* High level function to send custom lossy packets. |
646 | * | 652 | * |
@@ -652,14 +658,9 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin | |||
652 | 658 | ||
653 | /* Set handlers for custom lossless packets. | 659 | /* Set handlers for custom lossless packets. |
654 | * | 660 | * |
655 | * byte must be in PACKET_ID_LOSSLESS_RANGE_START PACKET_ID_LOSSLESS_RANGE_SIZE range. | ||
656 | * | ||
657 | * return -1 on failure. | ||
658 | * return 0 on success. | ||
659 | */ | 661 | */ |
660 | int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, | 662 | void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, |
661 | int (*packet_handler_callback)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint32_t len, void *object), | 663 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object); |
662 | void *object); | ||
663 | 664 | ||
664 | /* High level function to send custom lossless packets. | 665 | /* High level function to send custom lossless packets. |
665 | * | 666 | * |