summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-12 21:37:58 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-13 01:07:02 +0100
commita8823830d39bdbde8d4f4f34bfcb26dc4bf79741 (patch)
tree086d51b0db42c8fdbef669d002739f607db52f01 /toxcore
parent0aa2840164fc782f150cd45f8668ca623e6002cf (diff)
Add some astyle options to make it do more.
It now enforces a bit more formatting. In particular, padding inside parentheses is removed. I would like it to remove padding after unary operators, but there seems to be no option for that.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c57
-rw-r--r--toxcore/Messenger.c2
-rw-r--r--toxcore/TCP_server.c3
-rw-r--r--toxcore/network.c19
-rw-r--r--toxcore/onion_client.c2
-rw-r--r--toxcore/ping.c4
-rw-r--r--toxcore/util.c6
7 files changed, 51 insertions, 42 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index beff0499..7e2445b3 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -642,7 +642,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
642 if (num_nodes < MAX_SENT_NODES) { 642 if (num_nodes < MAX_SENT_NODES) {
643 memcpy(nodes_list[num_nodes].public_key, 643 memcpy(nodes_list[num_nodes].public_key,
644 client->public_key, 644 client->public_key,
645 crypto_box_PUBLICKEYBYTES ); 645 crypto_box_PUBLICKEYBYTES);
646 646
647 nodes_list[num_nodes].ip_port = ipptp->ip_port; 647 nodes_list[num_nodes].ip_port = ipptp->ip_port;
648 num_nodes++; 648 num_nodes++;
@@ -827,11 +827,11 @@ static void sort_client_list(Client_data *list, unsigned int length, const uint8
827 * than public_key. 827 * than public_key.
828 * 828 *
829 * returns True(1) when the item was stored, False(0) otherwise */ 829 * returns True(1) when the item was stored, False(0) otherwise */
830static int replace_all( Client_data *list, 830static int replace_all(Client_data *list,
831 uint16_t length, 831 uint16_t length,
832 const uint8_t *public_key, 832 const uint8_t *public_key,
833 IP_Port ip_port, 833 IP_Port ip_port,
834 const uint8_t *comp_public_key ) 834 const uint8_t *comp_public_key)
835{ 835{
836 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) { 836 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) {
837 return 0; 837 return 0;
@@ -1197,11 +1197,11 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
1197 uint8_t nonce[crypto_box_NONCEBYTES]; 1197 uint8_t nonce[crypto_box_NONCEBYTES];
1198 new_nonce(nonce); 1198 new_nonce(nonce);
1199 1199
1200 int len = encrypt_data_symmetric( shared_key, 1200 int len = encrypt_data_symmetric(shared_key,
1201 nonce, 1201 nonce,
1202 plain, 1202 plain,
1203 sizeof(plain), 1203 sizeof(plain),
1204 encrypt ); 1204 encrypt);
1205 1205
1206 if (len != sizeof(encrypt)) { 1206 if (len != sizeof(encrypt)) {
1207 return -1; 1207 return -1;
@@ -1252,11 +1252,11 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1252 1252
1253 plain[0] = num_nodes; 1253 plain[0] = num_nodes;
1254 memcpy(plain + 1 + nodes_length, sendback_data, length); 1254 memcpy(plain + 1 + nodes_length, sendback_data, length);
1255 int len = encrypt_data_symmetric( shared_encryption_key, 1255 int len = encrypt_data_symmetric(shared_encryption_key,
1256 nonce, 1256 nonce,
1257 plain, 1257 plain,
1258 1 + nodes_length + length, 1258 1 + nodes_length + length,
1259 encrypt ); 1259 encrypt);
1260 1260
1261 if (len != 1 + nodes_length + length + crypto_box_MACBYTES) { 1261 if (len != 1 + nodes_length + length + crypto_box_MACBYTES) {
1262 return -1; 1262 return -1;
@@ -1288,11 +1288,11 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
1288 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 1288 uint8_t shared_key[crypto_box_BEFORENMBYTES];
1289 1289
1290 DHT_get_shared_key_recv(dht, shared_key, packet + 1); 1290 DHT_get_shared_key_recv(dht, shared_key, packet + 1);
1291 int len = decrypt_data_symmetric( shared_key, 1291 int len = decrypt_data_symmetric(shared_key,
1292 packet + 1 + crypto_box_PUBLICKEYBYTES, 1292 packet + 1 + crypto_box_PUBLICKEYBYTES,
1293 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, 1293 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
1294 crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES, 1294 crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES,
1295 plain ); 1295 plain);
1296 1296
1297 if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)) { 1297 if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)) {
1298 return 1; 1298 return 1;
@@ -1515,9 +1515,9 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1515 --dht->num_friends; 1515 --dht->num_friends;
1516 1516
1517 if (dht->num_friends != friend_num) { 1517 if (dht->num_friends != friend_num) {
1518 memcpy( &dht->friends_list[friend_num], 1518 memcpy(&dht->friends_list[friend_num],
1519 &dht->friends_list[dht->num_friends], 1519 &dht->friends_list[dht->num_friends],
1520 sizeof(DHT_Friend) ); 1520 sizeof(DHT_Friend));
1521 } 1521 }
1522 1522
1523 if (dht->num_friends == 0) { 1523 if (dht->num_friends == 0) {
@@ -1819,13 +1819,15 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1819#ifdef FRIEND_IPLIST_PAD 1819#ifdef FRIEND_IPLIST_PAD
1820 memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port)); 1820 memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port));
1821 1821
1822 if (num_ipv6s == MAX_FRIEND_CLIENTS) 1822 if (num_ipv6s == MAX_FRIEND_CLIENTS) {
1823 return MAX_FRIEND_CLIENTS; 1823 return MAX_FRIEND_CLIENTS;
1824 }
1824 1825
1825 int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s; 1826 int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s;
1826 1827
1827 if (num_ipv4s_used > num_ipv4s) 1828 if (num_ipv4s_used > num_ipv4s) {
1828 num_ipv4s_used = num_ipv4s; 1829 num_ipv4s_used = num_ipv4s;
1830 }
1829 1831
1830 memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port)); 1832 memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port));
1831 return num_ipv6s + num_ipv4s_used; 1833 return num_ipv6s + num_ipv4s_used;
@@ -2654,8 +2656,9 @@ void do_DHT(DHT *dht)
2654#endif 2656#endif
2655#ifdef ENABLE_ASSOC_DHT 2657#ifdef ENABLE_ASSOC_DHT
2656 2658
2657 if (dht->assoc) 2659 if (dht->assoc) {
2658 do_Assoc(dht->assoc, dht); 2660 do_Assoc(dht->assoc, dht);
2661 }
2659 2662
2660#endif 2663#endif
2661 dht->last_run = unix_time(); 2664 dht->last_run = unix_time();
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index b72fac93..8f5432da 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1892,7 +1892,7 @@ Messenger *new_messenger(Logger *log, Messenger_Options *options, unsigned int *
1892 *error = MESSENGER_ERROR_OTHER; 1892 *error = MESSENGER_ERROR_OTHER;
1893 } 1893 }
1894 1894
1895 if ( ! m ) { 1895 if (! m) {
1896 return NULL; 1896 return NULL;
1897 } 1897 }
1898 1898
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index d4b5ddd1..0a347342 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -1184,8 +1184,9 @@ static void do_TCP_confirmed(TCP_Server *TCP_server)
1184{ 1184{
1185#ifdef TCP_SERVER_USE_EPOLL 1185#ifdef TCP_SERVER_USE_EPOLL
1186 1186
1187 if (TCP_server->last_run_pinged == unix_time()) 1187 if (TCP_server->last_run_pinged == unix_time()) {
1188 return; 1188 return;
1189 }
1189 1190
1190 TCP_server->last_run_pinged = unix_time(); 1191 TCP_server->last_run_pinged = unix_time();
1191#endif 1192#endif
diff --git a/toxcore/network.c b/toxcore/network.c
index 1e6661cb..e42c962b 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -56,8 +56,9 @@ static const char *inet_ntop(sa_family_t family, void *addr, char *buf, size_t b
56 56
57 DWORD len = bufsize; 57 DWORD len = bufsize;
58 58
59 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) 59 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) {
60 return NULL; 60 return NULL;
61 }
61 62
62 return buf; 63 return buf;
63 } else if (family == AF_INET6) { 64 } else if (family == AF_INET6) {
@@ -69,8 +70,9 @@ static const char *inet_ntop(sa_family_t family, void *addr, char *buf, size_t b
69 70
70 DWORD len = bufsize; 71 DWORD len = bufsize;
71 72
72 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) 73 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) {
73 return NULL; 74 return NULL;
75 }
74 76
75 return buf; 77 return buf;
76 } 78 }
@@ -86,8 +88,9 @@ static int inet_pton(sa_family_t family, const char *addrString, void *addrbuf)
86 88
87 INT len = sizeof(saddr); 89 INT len = sizeof(saddr);
88 90
89 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len)) 91 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len)) {
90 return 0; 92 return 0;
93 }
91 94
92 *(struct in_addr *)addrbuf = saddr.sin_addr; 95 *(struct in_addr *)addrbuf = saddr.sin_addr;
93 96
@@ -98,8 +101,9 @@ static int inet_pton(sa_family_t family, const char *addrString, void *addrbuf)
98 101
99 INT len = sizeof(saddr); 102 INT len = sizeof(saddr);
100 103
101 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len)) 104 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len)) {
102 return 0; 105 return 0;
106 }
103 107
104 *(struct in6_addr *)addrbuf = saddr.sin6_addr; 108 *(struct in6_addr *)addrbuf = saddr.sin6_addr;
105 109
@@ -480,8 +484,9 @@ int networking_at_startup(void)
480#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) 484#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
481 WSADATA wsaData; 485 WSADATA wsaData;
482 486
483 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) 487 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) {
484 return -1; 488 return -1;
489 }
485 490
486#endif 491#endif
487 srand((uint32_t)current_time_actual()); 492 srand((uint32_t)current_time_actual());
@@ -645,7 +650,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
645 if (ip.family == AF_INET6) { 650 if (ip.family == AF_INET6) {
646 int is_dualstack = set_socket_dualstack(temp->sock); 651 int is_dualstack = set_socket_dualstack(temp->sock);
647 LOGGER_DEBUG(log, "Dual-stack socket: %s", 652 LOGGER_DEBUG(log, "Dual-stack socket: %s",
648 is_dualstack ? "enabled" : "Failed to enable, won't be able to receive from/send to IPv4 addresses" ); 653 is_dualstack ? "enabled" : "Failed to enable, won't be able to receive from/send to IPv4 addresses");
649 /* multicast local nodes */ 654 /* multicast local nodes */
650 struct ipv6_mreq mreq; 655 struct ipv6_mreq mreq;
651 memset(&mreq, 0, sizeof(mreq)); 656 memset(&mreq, 0, sizeof(mreq));
@@ -656,7 +661,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
656 int res = setsockopt(temp->sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)); 661 int res = setsockopt(temp->sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq));
657 662
658 LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%u, %s)" : 663 LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%u, %s)" :
659 "Local multicast group FF02::1 joined successfully", errno, strerror(errno) ); 664 "Local multicast group FF02::1 joined successfully", errno, strerror(errno));
660 } 665 }
661 666
662 /* a hanging program or a different user might block the standard port; 667 /* a hanging program or a different user might block the standard port;
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index a140e008..0dca8525 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -642,7 +642,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
642 if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) 642 if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT)
643 || id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2 643 || id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2
644 || is_timeout(list_nodes[1].timestamp, ONION_NODE_TIMEOUT) 644 || is_timeout(list_nodes[1].timestamp, ONION_NODE_TIMEOUT)
645 || id_closest(reference_id, list_nodes[1].public_key, nodes[i].public_key) == 2 ) { 645 || id_closest(reference_id, list_nodes[1].public_key, nodes[i].public_key) == 2) {
646 /* check if node is already in list. */ 646 /* check if node is already in list. */
647 for (j = 0; j < list_length; ++j) { 647 for (j = 0; j < list_length; ++j) {
648 if (public_key_cmp(list_nodes[j].public_key, nodes[i].public_key) == 0) { 648 if (public_key_cmp(list_nodes[j].public_key, nodes[i].public_key) == 0) {
diff --git a/toxcore/ping.c b/toxcore/ping.c
index d2a01f5d..d15ccd47 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -125,7 +125,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key
125 rc = encrypt_data_symmetric(shared_encryption_key, 125 rc = encrypt_data_symmetric(shared_encryption_key,
126 pk + 1 + crypto_box_PUBLICKEYBYTES, 126 pk + 1 + crypto_box_PUBLICKEYBYTES,
127 ping_plain, sizeof(ping_plain), 127 ping_plain, sizeof(ping_plain),
128 pk + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES ); 128 pk + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
129 129
130 if (rc != PING_PLAIN_SIZE + crypto_box_MACBYTES) { 130 if (rc != PING_PLAIN_SIZE + crypto_box_MACBYTES) {
131 return 1; 131 return 1;
@@ -158,7 +158,7 @@ static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet
158 packet + 1 + crypto_box_PUBLICKEYBYTES, 158 packet + 1 + crypto_box_PUBLICKEYBYTES,
159 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, 159 packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
160 PING_PLAIN_SIZE + crypto_box_MACBYTES, 160 PING_PLAIN_SIZE + crypto_box_MACBYTES,
161 ping_plain ); 161 ping_plain);
162 162
163 if (rc != sizeof(ping_plain)) { 163 if (rc != sizeof(ping_plain)) {
164 return 1; 164 return 1;
diff --git a/toxcore/util.c b/toxcore/util.c
index 40bf2849..f9fe7852 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -86,7 +86,7 @@ void host_to_net(uint8_t *num, uint16_t numbytes)
86uint16_t lendian_to_host16(uint16_t lendian) 86uint16_t lendian_to_host16(uint16_t lendian)
87{ 87{
88#ifdef WORDS_BIGENDIAN 88#ifdef WORDS_BIGENDIAN
89 return (lendian << 8) | (lendian >> 8 ); 89 return (lendian << 8) | (lendian >> 8);
90#else 90#else
91 return lendian; 91 return lendian;
92#endif 92#endif
@@ -95,7 +95,7 @@ uint16_t lendian_to_host16(uint16_t lendian)
95void host_to_lendian32(uint8_t *dest, uint32_t num) 95void host_to_lendian32(uint8_t *dest, uint32_t num)
96{ 96{
97#ifdef WORDS_BIGENDIAN 97#ifdef WORDS_BIGENDIAN
98 num = ((num << 8) & 0xFF00FF00 ) | ((num >> 8) & 0xFF00FF ); 98 num = ((num << 8) & 0xFF00FF00) | ((num >> 8) & 0xFF00FF);
99 num = (num << 16) | (num >> 16); 99 num = (num << 16) | (num >> 16);
100#endif 100#endif
101 memcpy(dest, &num, sizeof(uint32_t)); 101 memcpy(dest, &num, sizeof(uint32_t));
@@ -106,7 +106,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian)
106 uint32_t d; 106 uint32_t d;
107 memcpy(&d, lendian, sizeof(uint32_t)); 107 memcpy(&d, lendian, sizeof(uint32_t));
108#ifdef WORDS_BIGENDIAN 108#ifdef WORDS_BIGENDIAN
109 d = ((d << 8) & 0xFF00FF00 ) | ((d >> 8) & 0xFF00FF ); 109 d = ((d << 8) & 0xFF00FF00) | ((d >> 8) & 0xFF00FF);
110 d = (d << 16) | (d >> 16); 110 d = (d << 16) | (d >> 16);
111#endif 111#endif
112 *dest = d; 112 *dest = d;