diff options
-rw-r--r-- | toxcore/Messenger.c | 38 | ||||
-rw-r--r-- | toxcore/Messenger.h | 27 |
2 files changed, 60 insertions, 5 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 7de14edf..44570742 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -682,7 +682,7 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint | |||
682 | /* returns valid ip port of connected friend on success | 682 | /* returns valid ip port of connected friend on success |
683 | * returns zeroed out IP_Port on failure | 683 | * returns zeroed out IP_Port on failure |
684 | */ | 684 | */ |
685 | static IP_Port get_friend_ipport(Messenger *m, int friendnumber) | 685 | IP_Port get_friend_ipport(Messenger *m, int friendnumber) |
686 | { | 686 | { |
687 | IP_Port zero; | 687 | IP_Port zero; |
688 | memset(&zero, 0, sizeof(zero)); | 688 | memset(&zero, 0, sizeof(zero)); |
@@ -1266,6 +1266,26 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei | |||
1266 | 1266 | ||
1267 | /**************************************/ | 1267 | /**************************************/ |
1268 | 1268 | ||
1269 | /* Set the callback for msi packets. | ||
1270 | * | ||
1271 | * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) | ||
1272 | */ | ||
1273 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | ||
1274 | void *userdata) | ||
1275 | { | ||
1276 | m->msi_packet = function; | ||
1277 | m->msi_packet_userdata = userdata; | ||
1278 | } | ||
1279 | |||
1280 | /* Send an msi packet. | ||
1281 | * | ||
1282 | * return 1 on success | ||
1283 | * return 0 on failure | ||
1284 | */ | ||
1285 | int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length) | ||
1286 | { | ||
1287 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length); | ||
1288 | } | ||
1269 | 1289 | ||
1270 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ | 1290 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ |
1271 | static void LANdiscovery(Messenger *m) | 1291 | static void LANdiscovery(Messenger *m) |
@@ -1419,11 +1439,12 @@ void doFriends(Messenger *m) | |||
1419 | } | 1439 | } |
1420 | 1440 | ||
1421 | len = read_cryptpacket(m->net_crypto, m->friendlist[i].crypt_connection_id, temp); | 1441 | len = read_cryptpacket(m->net_crypto, m->friendlist[i].crypt_connection_id, temp); |
1422 | uint8_t packet_id = temp[0]; | ||
1423 | uint8_t *data = temp + 1; | ||
1424 | uint32_t data_length = len - 1; | ||
1425 | 1442 | ||
1426 | if (len > 0) { | 1443 | if (len > 0) { |
1444 | uint8_t packet_id = temp[0]; | ||
1445 | uint8_t *data = temp + 1; | ||
1446 | uint32_t data_length = len - 1; | ||
1447 | |||
1427 | switch (packet_id) { | 1448 | switch (packet_id) { |
1428 | case PACKET_ID_PING: { | 1449 | case PACKET_ID_PING: { |
1429 | m->friendlist[i].ping_lastrecv = temp_time; | 1450 | m->friendlist[i].ping_lastrecv = temp_time; |
@@ -1508,6 +1529,7 @@ void doFriends(Messenger *m) | |||
1508 | if (m->friendlist[i].receives_read_receipts) { | 1529 | if (m->friendlist[i].receives_read_receipts) { |
1509 | write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); | 1530 | write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); |
1510 | } | 1531 | } |
1532 | |||
1511 | if (m->friend_action) | 1533 | if (m->friend_action) |
1512 | (*m->friend_action)(m, i, action, action_length, m->friend_action_userdata); | 1534 | (*m->friend_action)(m, i, action, action_length, m->friend_action_userdata); |
1513 | 1535 | ||
@@ -1611,6 +1633,14 @@ void doFriends(Messenger *m) | |||
1611 | break; | 1633 | break; |
1612 | } | 1634 | } |
1613 | 1635 | ||
1636 | case PACKET_ID_MSI: { | ||
1637 | if (data_length == 0) | ||
1638 | break; | ||
1639 | |||
1640 | if (m->msi_packet) | ||
1641 | (*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata); | ||
1642 | } | ||
1643 | |||
1614 | default: { | 1644 | default: { |
1615 | break; | 1645 | break; |
1616 | } | 1646 | } |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 65fa19a5..f03a7478 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -44,6 +44,7 @@ | |||
44 | #define PACKET_ID_RECEIPT 65 | 44 | #define PACKET_ID_RECEIPT 65 |
45 | #define PACKET_ID_MESSAGE 64 | 45 | #define PACKET_ID_MESSAGE 64 |
46 | #define PACKET_ID_ACTION 63 | 46 | #define PACKET_ID_ACTION 63 |
47 | #define PACKET_ID_MSI 69 | ||
47 | #define PACKET_ID_FILE_SENDREQUEST 80 | 48 | #define PACKET_ID_FILE_SENDREQUEST 80 |
48 | #define PACKET_ID_FILE_CONTROL 81 | 49 | #define PACKET_ID_FILE_CONTROL 81 |
49 | #define PACKET_ID_FILE_DATA 82 | 50 | #define PACKET_ID_FILE_DATA 82 |
@@ -198,6 +199,9 @@ typedef struct Messenger { | |||
198 | void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *); | 199 | void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *); |
199 | void *file_filedata_userdata; | 200 | void *file_filedata_userdata; |
200 | 201 | ||
202 | void (*msi_packet)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | ||
203 | void *msi_packet_userdata; | ||
204 | |||
201 | } Messenger; | 205 | } Messenger; |
202 | 206 | ||
203 | /* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 207 | /* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
@@ -327,6 +331,11 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen); | |||
327 | */ | 331 | */ |
328 | int getname(Messenger *m, int friendnumber, uint8_t *name); | 332 | int getname(Messenger *m, int friendnumber, uint8_t *name); |
329 | 333 | ||
334 | /* returns valid ip port of connected friend on success | ||
335 | * returns zeroed out IP_Port on failure | ||
336 | */ | ||
337 | IP_Port get_friend_ipport(Messenger *m, int friendnumber); | ||
338 | |||
330 | /* Set our user status. | 339 | /* Set our user status. |
331 | * You are responsible for freeing status after. | 340 | * You are responsible for freeing status after. |
332 | * | 341 | * |
@@ -547,7 +556,23 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
547 | */ | 556 | */ |
548 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive); | 557 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive); |
549 | 558 | ||
550 | /*********************************/ | 559 | /*************** A/V related ******************/ |
560 | |||
561 | /* Set the callback for msi packets. | ||
562 | * | ||
563 | * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) | ||
564 | */ | ||
565 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | ||
566 | void *userdata); | ||
567 | |||
568 | /* Send an msi packet. | ||
569 | * | ||
570 | * return 1 on success | ||
571 | * return 0 on failure | ||
572 | */ | ||
573 | int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length); | ||
574 | |||
575 | /**********************************************/ | ||
551 | 576 | ||
552 | /* Run this at startup. | 577 | /* Run this at startup. |
553 | * return allocated instance of Messenger on success. | 578 | * return allocated instance of Messenger on success. |