summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-18 01:31:55 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-24 21:53:50 +0100
commit15cb4261665bab4ef02a5b1b9db48b9477c9b87a (patch)
treed0c40a45afa19fff26ce1eb5bb703e18a9acdd4a /toxcore/TCP_connection.c
parent0d347c2b2e69aa09b079f6daaa00007fef4fe52f (diff)
Make toxcore code C++ compatible.
It is still C code, so still compatible with C compilers as well. This change lets us see more clearly where implicit conversions occur by making them explicit.
Diffstat (limited to 'toxcore/TCP_connection.c')
-rw-r--r--toxcore/TCP_connection.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index e838c281..234a8d79 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -70,7 +70,13 @@ const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
70 * return -1 if realloc fails. 70 * return -1 if realloc fails.
71 * return 0 if it succeeds. 71 * return 0 if it succeeds.
72 */ 72 */
73#define realloc_tox_array(array, element_size, num, temp_pointer) (num ? (temp_pointer = realloc(array, ((num) * (element_size))), temp_pointer ? (array = temp_pointer, 0) : (-1) ) : (free(array), array = NULL, 0)) 73#define realloc_tox_array(array, element_type, num, temp_pointer) \
74 (num \
75 ? (temp_pointer = (element_type *)realloc( \
76 array, \
77 (num) * sizeof(element_type)), \
78 temp_pointer ? (array = temp_pointer, 0) : -1) \
79 : (free(array), array = NULL, 0))
74 80
75 81
76/* return 1 if the connections_number is not valid. 82/* return 1 if the connections_number is not valid.
@@ -132,7 +138,7 @@ static int create_connection(TCP_Connections *tcp_c)
132 138
133 TCP_Connection_to *temp_pointer; 139 TCP_Connection_to *temp_pointer;
134 140
135 if (realloc_tox_array(tcp_c->connections, sizeof(TCP_Connection_to), tcp_c->connections_length + 1, 141 if (realloc_tox_array(tcp_c->connections, TCP_Connection_to, tcp_c->connections_length + 1,
136 temp_pointer) == 0) { 142 temp_pointer) == 0) {
137 id = tcp_c->connections_length; 143 id = tcp_c->connections_length;
138 ++tcp_c->connections_length; 144 ++tcp_c->connections_length;
@@ -161,7 +167,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
161 167
162 TCP_con *temp_pointer; 168 TCP_con *temp_pointer;
163 169
164 if (realloc_tox_array(tcp_c->tcp_connections, sizeof(TCP_con), tcp_c->tcp_connections_length + 1, temp_pointer) == 0) { 170 if (realloc_tox_array(tcp_c->tcp_connections, TCP_con, tcp_c->tcp_connections_length + 1, temp_pointer) == 0) {
165 id = tcp_c->tcp_connections_length; 171 id = tcp_c->tcp_connections_length;
166 ++tcp_c->tcp_connections_length; 172 ++tcp_c->tcp_connections_length;
167 memset(&(tcp_c->tcp_connections[id]), 0, sizeof(TCP_con)); 173 memset(&(tcp_c->tcp_connections[id]), 0, sizeof(TCP_con));
@@ -193,7 +199,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
193 if (tcp_c->connections_length != i) { 199 if (tcp_c->connections_length != i) {
194 tcp_c->connections_length = i; 200 tcp_c->connections_length = i;
195 TCP_Connection_to *temp_pointer; 201 TCP_Connection_to *temp_pointer;
196 realloc_tox_array(tcp_c->connections, sizeof(TCP_Connection_to), tcp_c->connections_length, temp_pointer); 202 realloc_tox_array(tcp_c->connections, TCP_Connection_to, tcp_c->connections_length, temp_pointer);
197 } 203 }
198 204
199 return 0; 205 return 0;
@@ -222,7 +228,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
222 if (tcp_c->tcp_connections_length != i) { 228 if (tcp_c->tcp_connections_length != i) {
223 tcp_c->tcp_connections_length = i; 229 tcp_c->tcp_connections_length = i;
224 TCP_con *temp_pointer; 230 TCP_con *temp_pointer;
225 realloc_tox_array(tcp_c->tcp_connections, sizeof(TCP_con), tcp_c->tcp_connections_length, temp_pointer); 231 realloc_tox_array(tcp_c->tcp_connections, TCP_con, tcp_c->tcp_connections_length, temp_pointer);
226 } 232 }
227 233
228 return 0; 234 return 0;
@@ -896,8 +902,8 @@ static int send_tcp_relay_routing_request(TCP_Connections *tcp_c, int tcp_connec
896 902
897static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key) 903static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
898{ 904{
899 TCP_Client_Connection *TCP_client_con = object; 905 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
900 TCP_Connections *tcp_c = TCP_client_con->custom_object; 906 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
901 907
902 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 908 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
903 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 909 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -929,8 +935,8 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
929 935
930static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status) 936static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
931{ 937{
932 TCP_Client_Connection *TCP_client_con = object; 938 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
933 TCP_Connections *tcp_c = TCP_client_con->custom_object; 939 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
934 940
935 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 941 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
936 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 942 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -968,13 +974,12 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
968static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, 974static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length,
969 void *userdata) 975 void *userdata)
970{ 976{
971
972 if (length == 0) { 977 if (length == 0) {
973 return -1; 978 return -1;
974 } 979 }
975 980
976 TCP_Client_Connection *TCP_client_con = object; 981 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
977 TCP_Connections *tcp_c = TCP_client_con->custom_object; 982 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
978 983
979 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 984 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
980 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 985 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1003,8 +1008,8 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
1003 return -1; 1008 return -1;
1004 } 1009 }
1005 1010
1006 TCP_Client_Connection *TCP_client_con = object; 1011 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
1007 TCP_Connections *tcp_c = TCP_client_con->custom_object; 1012 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
1008 1013
1009 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 1014 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
1010 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 1015 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1031,7 +1036,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
1031 1036
1032static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata) 1037static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
1033{ 1038{
1034 TCP_Connections *tcp_c = object; 1039 TCP_Connections *tcp_c = (TCP_Connections *)object;
1035 1040
1036 if (tcp_c->tcp_onion_callback) { 1041 if (tcp_c->tcp_onion_callback) {
1037 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata); 1042 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata);
@@ -1365,7 +1370,7 @@ TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *
1365 return NULL; 1370 return NULL;
1366 } 1371 }
1367 1372
1368 TCP_Connections *temp = calloc(1, sizeof(TCP_Connections)); 1373 TCP_Connections *temp = (TCP_Connections *)calloc(1, sizeof(TCP_Connections));
1369 1374
1370 if (temp == NULL) { 1375 if (temp == NULL) {
1371 return NULL; 1376 return NULL;