diff options
author | irungentoo <irungentoo@gmail.com> | 2013-10-13 22:07:30 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-10-13 22:07:30 -0400 |
commit | a81b708eb57f53e5b051c5510cc2db03fdf16315 (patch) | |
tree | 764cc5443cd4a50b43afd5b73b5e58e0916135a8 /toxcore/Messenger.c | |
parent | dc1c019a2dc6717308a2bdfb4998af59d541441c (diff) |
A/V integration in progress.
Added functions to send/receive msi packets via secure messenger
connections.
Made function to get the ip/port of a friend in Messenger.c public
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 38 |
1 files changed, 34 insertions, 4 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 | } |