summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorGregory Mullen (grayhatter) <greg@grayhatter.com>2016-08-20 15:25:26 -0700
committerGregory Mullen (grayhatter) <greg@grayhatter.com>2016-08-22 03:12:47 -0700
commita6f2e9539b9f73e40076fe85d8f1152b279142e7 (patch)
tree85caf73237df61a020e1d56420cf46403a43957a /toxcore
parent3f0c1017714eb8b5114ee5d0caaa5bc453217d09 (diff)
Make Message received receipts stateless
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c16
-rw-r--r--toxcore/Messenger.h3
-rw-r--r--toxcore/tox.c4
-rw-r--r--toxcore/tox.h2
4 files changed, 12 insertions, 13 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index ac54f34f..b87e61c6 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -344,7 +344,7 @@ static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint
344 m->friendlist[friendnumber].friendcon_id), number); 344 m->friendlist[friendnumber].friendcon_id), number);
345} 345}
346 346
347static int do_receipts(Messenger *m, int32_t friendnumber) 347static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
348{ 348{
349 if (friend_not_valid(m, friendnumber)) 349 if (friend_not_valid(m, friendnumber))
350 return -1; 350 return -1;
@@ -357,8 +357,9 @@ static int do_receipts(Messenger *m, int32_t friendnumber)
357 if (friend_received_packet(m, friendnumber, receipts->packet_num) == -1) 357 if (friend_received_packet(m, friendnumber, receipts->packet_num) == -1)
358 break; 358 break;
359 359
360 if (m->read_receipt) 360 if (m->read_receipt) {
361 (*m->read_receipt)(m, friendnumber, receipts->msg_id, m->read_receipt_userdata); 361 (*m->read_receipt)(m, friendnumber, receipts->msg_id, userdata);
362 }
362 363
363 free(receipts); 364 free(receipts);
364 m->friendlist[friendnumber].receipts_start = temp_r; 365 m->friendlist[friendnumber].receipts_start = temp_r;
@@ -796,10 +797,9 @@ void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_
796 m->friend_typingchange = function; 797 m->friend_typingchange = function;
797} 798}
798 799
799void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *), void *userdata) 800void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *))
800{ 801{
801 m->read_receipt = function; 802 m->read_receipt = function;
802 m->read_receipt_userdata = userdata;
803} 803}
804 804
805void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *), 805void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *),
@@ -2168,7 +2168,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void
2168 return 0; 2168 return 0;
2169} 2169}
2170 2170
2171void do_friends(Messenger *m) 2171static void do_friends(Messenger *m, void *userdata)
2172{ 2172{
2173 uint32_t i; 2173 uint32_t i;
2174 uint64_t temp_time = unix_time(); 2174 uint64_t temp_time = unix_time();
@@ -2217,7 +2217,7 @@ void do_friends(Messenger *m)
2217 } 2217 }
2218 2218
2219 check_friend_tcp_udp(m, i); 2219 check_friend_tcp_udp(m, i);
2220 do_receipts(m, i); 2220 do_receipts(m, i, userdata);
2221 do_reqchunk_filecb(m, i); 2221 do_reqchunk_filecb(m, i);
2222 2222
2223 m->friendlist[i].last_seen_time = (uint64_t) time(NULL); 2223 m->friendlist[i].last_seen_time = (uint64_t) time(NULL);
@@ -2311,7 +2311,7 @@ void do_messenger(Messenger *m, void *userdata)
2311 do_net_crypto(m->net_crypto, userdata); 2311 do_net_crypto(m->net_crypto, userdata);
2312 do_onion_client(m->onion_c); 2312 do_onion_client(m->onion_c);
2313 do_friend_connections(m->fr_c); 2313 do_friend_connections(m->fr_c);
2314 do_friends(m); 2314 do_friends(m, userdata);
2315 connection_status_cb(m, userdata); 2315 connection_status_cb(m, userdata);
2316 2316
2317#ifdef TOX_LOGGER 2317#ifdef TOX_LOGGER
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 0141f1ea..6ac06f2f 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -242,7 +242,6 @@ struct Messenger {
242 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 242 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
243 void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *); 243 void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *);
244 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *); 244 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
245 void *read_receipt_userdata;
246 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 245 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
247 void *friend_connectionstatuschange_userdata; 246 void *friend_connectionstatuschange_userdata;
248 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *); 247 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *);
@@ -507,7 +506,7 @@ void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_
507 * Since core doesn't track ids for you, receipt may not correspond to any message. 506 * Since core doesn't track ids for you, receipt may not correspond to any message.
508 * In that case, you should discard it. 507 * In that case, you should discard it.
509 */ 508 */
510void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *), void *userdata); 509void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *));
511 510
512/* Set the callback for connection status changes. 511/* Set the callback for connection status changes.
513 * function(uint32_t friendnumber, uint8_t status) 512 * function(uint32_t friendnumber, uint8_t status)
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 2cccf125..b1308d90 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -890,10 +890,10 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, TOX_MESSAGE_T
890 return message_id; 890 return message_id;
891} 891}
892 892
893void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function, void *user_data) 893void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function)
894{ 894{
895 Messenger *m = tox; 895 Messenger *m = tox;
896 m_callback_read_receipt(m, function, user_data); 896 m_callback_read_receipt(m, function);
897} 897}
898 898
899void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *function, void *user_data) 899void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *function, void *user_data)
diff --git a/toxcore/tox.h b/toxcore/tox.h
index e392ecff..16e83207 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -1531,7 +1531,7 @@ typedef void tox_friend_read_receipt_cb(Tox *tox, uint32_t friend_number, uint32
1531 * This event is triggered when the friend receives the message sent with 1531 * This event is triggered when the friend receives the message sent with
1532 * tox_friend_send_message with the corresponding message ID. 1532 * tox_friend_send_message with the corresponding message ID.
1533 */ 1533 */
1534void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback, void *user_data); 1534void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback);
1535 1535
1536 1536
1537/******************************************************************************* 1537/*******************************************************************************