summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 5a194780..7de14edf 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -332,12 +332,36 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
332 332
333/* Send an action to an online friend. 333/* Send an action to an online friend.
334 * 334 *
335 * return 1 if packet was successfully put into the send queue. 335 * return the message id if packet was successfully put into the send queue.
336 * return 0 if it was not. 336 * return 0 if it was not.
337 */ 337 */
338int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length) 338uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length)
339{
340 if (friend_not_valid(m, friendnumber))
341 return 0;
342
343 uint32_t msgid = ++m->friendlist[friendnumber].message_id;
344
345 if (msgid == 0)
346 msgid = 1; // Otherwise, false error
347
348 if (m_sendaction_withid(m, friendnumber, msgid, action, length)) {
349 return msgid;
350 }
351
352 return 0;
353}
354
355uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
339{ 356{
340 return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, action, length); 357 if (length >= (MAX_DATA_SIZE - sizeof(theid)))
358 return 0;
359
360 uint8_t temp[MAX_DATA_SIZE];
361 theid = htonl(theid);
362 memcpy(temp, &theid, sizeof(theid));
363 memcpy(temp + sizeof(theid), action, length);
364 return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, temp, length + sizeof(theid));
341} 365}
342 366
343/* Send a name packet to friendnumber. 367/* Send a name packet to friendnumber.
@@ -1470,13 +1494,22 @@ void doFriends(Messenger *m)
1470 } 1494 }
1471 1495
1472 case PACKET_ID_ACTION: { 1496 case PACKET_ID_ACTION: {
1473 if (data_length == 0) 1497 uint8_t *message_id = data;
1498 uint8_t message_id_length = 4;
1499
1500 if (data_length <= message_id_length)
1474 break; 1501 break;
1475 1502
1476 data[data_length - 1] = 0;/* Make sure the NULL terminator is present. */ 1503 uint8_t *action = data + message_id_length;
1504 uint16_t action_length = data_length - message_id_length;
1505
1506 action[action_length - 1] = 0;/* Make sure the NULL terminator is present. */
1477 1507
1508 if (m->friendlist[i].receives_read_receipts) {
1509 write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
1510 }
1478 if (m->friend_action) 1511 if (m->friend_action)
1479 (*m->friend_action)(m, i, data, data_length, m->friend_action_userdata); 1512 (*m->friend_action)(m, i, action, action_length, m->friend_action_userdata);
1480 1513
1481 break; 1514 break;
1482 } 1515 }