summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-17 10:52:04 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-08-18 00:01:53 +0100
commita5e35180c7b42d30c82825cd67c8118ce048f65a (patch)
treeb74e8ece4f78a988ab0a1300cc08bd35fcd63662 /toxcore/TCP_connection.c
parentdb22522741cccdeba657776844538c71cf8e8e7a (diff)
Make tox_callback_friend_name stateless.
See #27 and #40 for details.
Diffstat (limited to 'toxcore/TCP_connection.c')
-rw-r--r--toxcore/TCP_connection.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 027779dd..d564762a 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -346,7 +346,7 @@ int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_num
346/* Set the callback for TCP data packets. 346/* Set the callback for TCP data packets.
347 */ 347 */
348void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, 348void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id,
349 const uint8_t *data, uint16_t length), void *object) 349 const uint8_t *data, uint16_t length, void *userdata), void *object)
350{ 350{
351 tcp_c->tcp_data_callback = tcp_data_callback; 351 tcp_c->tcp_data_callback = tcp_data_callback;
352 tcp_c->tcp_data_callback_object = object; 352 tcp_c->tcp_data_callback_object = object;
@@ -364,7 +364,7 @@ void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oo
364/* Set the callback for TCP oob data packets. 364/* Set the callback for TCP oob data packets.
365 */ 365 */
366void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, 366void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object,
367 const uint8_t *data, uint16_t length), void *object) 367 const uint8_t *data, uint16_t length, void *userdata), void *object)
368{ 368{
369 tcp_c->tcp_onion_callback = tcp_onion_callback; 369 tcp_c->tcp_onion_callback = tcp_onion_callback;
370 tcp_c->tcp_onion_callback_object = object; 370 tcp_c->tcp_onion_callback_object = object;
@@ -879,7 +879,8 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
879 return 0; 879 return 0;
880} 880}
881 881
882static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length) 882static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length,
883 void *userdata)
883{ 884{
884 885
885 if (length == 0) 886 if (length == 0)
@@ -900,12 +901,13 @@ static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_i
900 return -1; 901 return -1;
901 902
902 if (tcp_c->tcp_data_callback) 903 if (tcp_c->tcp_data_callback)
903 tcp_c->tcp_data_callback(tcp_c->tcp_data_callback_object, con_to->id, data, length); 904 tcp_c->tcp_data_callback(tcp_c->tcp_data_callback_object, con_to->id, data, length, userdata);
904 905
905 return 0; 906 return 0;
906} 907}
907 908
908static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length) 909static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
910 void *userdata)
909{ 911{
910 if (length == 0) 912 if (length == 0)
911 return -1; 913 return -1;
@@ -925,7 +927,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
925 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); 927 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
926 928
927 if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { 929 if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) {
928 return tcp_data_callback(object, connections_number, 0, data, length); 930 return tcp_data_callback(object, connections_number, 0, data, length, userdata);
929 } else { 931 } else {
930 if (tcp_c->tcp_oob_callback) 932 if (tcp_c->tcp_oob_callback)
931 tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length); 933 tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length);
@@ -934,12 +936,12 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
934 return 0; 936 return 0;
935} 937}
936 938
937static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length) 939static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
938{ 940{
939 TCP_Connections *tcp_c = object; 941 TCP_Connections *tcp_c = object;
940 942
941 if (tcp_c->tcp_onion_callback) 943 if (tcp_c->tcp_onion_callback)
942 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length); 944 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata);
943 945
944 return 0; 946 return 0;
945} 947}
@@ -1265,7 +1267,7 @@ TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *
1265 return temp; 1267 return temp;
1266} 1268}
1267 1269
1268static void do_tcp_conns(TCP_Connections *tcp_c) 1270static void do_tcp_conns(TCP_Connections *tcp_c, void *userdata)
1269{ 1271{
1270 unsigned int i; 1272 unsigned int i;
1271 1273
@@ -1274,7 +1276,7 @@ static void do_tcp_conns(TCP_Connections *tcp_c)
1274 1276
1275 if (tcp_con) { 1277 if (tcp_con) {
1276 if (tcp_con->status != TCP_CONN_SLEEPING) { 1278 if (tcp_con->status != TCP_CONN_SLEEPING) {
1277 do_TCP_connection(tcp_con->connection); 1279 do_TCP_connection(tcp_con->connection, userdata);
1278 1280
1279 /* callbacks can change TCP connection address. */ 1281 /* callbacks can change TCP connection address. */
1280 tcp_con = get_tcp_connection(tcp_c, i); 1282 tcp_con = get_tcp_connection(tcp_c, i);
@@ -1343,9 +1345,9 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c)
1343 } 1345 }
1344} 1346}
1345 1347
1346void do_tcp_connections(TCP_Connections *tcp_c) 1348void do_tcp_connections(TCP_Connections *tcp_c, void *userdata)
1347{ 1349{
1348 do_tcp_conns(tcp_c); 1350 do_tcp_conns(tcp_c, userdata);
1349 kill_nonused_tcp(tcp_c); 1351 kill_nonused_tcp(tcp_c);
1350} 1352}
1351 1353