diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 6 | ||||
-rw-r--r-- | testing/Messenger_test.c | 10 | ||||
-rw-r--r-- | testing/experiment/group_chats_test1.c | 21 | ||||
-rw-r--r-- | testing/misc_tools.c | 18 | ||||
-rw-r--r-- | testing/tox_sync.c | 5 |
5 files changed, 33 insertions, 27 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index a8ad8426..5ddb5945 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -205,8 +205,10 @@ int main(int argc, char *argv[]) | |||
205 | 205 | ||
206 | if (scanf("%s", temp_id) != 1) | 206 | if (scanf("%s", temp_id) != 1) |
207 | exit(0); | 207 | exit(0); |
208 | 208 | ||
209 | DHT_addfriend(dht, hex_string_to_bin(temp_id)); | 209 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
210 | DHT_addfriend(dht, bin_id); | ||
211 | free(bin_id); | ||
210 | 212 | ||
211 | perror("Initialization"); | 213 | perror("Initialization"); |
212 | 214 | ||
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 969d6b1f..707bb8db 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -161,14 +161,16 @@ int main(int argc, char *argv[]) | |||
161 | 161 | ||
162 | setname(m, (uint8_t *)"Anon", 5); | 162 | setname(m, (uint8_t *)"Anon", 5); |
163 | 163 | ||
164 | char temp_id[128]; | 164 | char temp_hex_id[128]; |
165 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); | 165 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); |
166 | 166 | ||
167 | if (scanf("%s", temp_id) != 1) { | 167 | if (scanf("%s", temp_hex_id) != 1) { |
168 | return 1; | 168 | return 1; |
169 | } | 169 | } |
170 | 170 | ||
171 | int num = m_addfriend(m, hex_string_to_bin(temp_id), (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 171 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); |
172 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | ||
173 | free(bin_id); | ||
172 | 174 | ||
173 | perror("Initialization"); | 175 | perror("Initialization"); |
174 | 176 | ||
diff --git a/testing/experiment/group_chats_test1.c b/testing/experiment/group_chats_test1.c index a74f808a..fc10ab64 100644 --- a/testing/experiment/group_chats_test1.c +++ b/testing/experiment/group_chats_test1.c | |||
@@ -1,4 +1,6 @@ | |||
1 | #include "../../toxcore/group_chats.h" | 1 | #include "../../toxcore/group_chats.h" |
2 | #include "../misc_tools.c" // hex_string_to_bin | ||
3 | |||
2 | #define NUM_CHATS 8 | 4 | #define NUM_CHATS 8 |
3 | 5 | ||
4 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 6 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) |
@@ -54,19 +56,6 @@ void print_group(Group_Chat *chat) | |||
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | unsigned char *hex_string_to_bin(char hex_string[]) | ||
58 | { | ||
59 | size_t len = strlen(hex_string); | ||
60 | unsigned char *val = malloc(len); | ||
61 | char *pos = hex_string; | ||
62 | int i; | ||
63 | |||
64 | for (i = 0; i < len; ++i, pos += 2) | ||
65 | sscanf(pos, "%2hhx", &val[i]); | ||
66 | |||
67 | return val; | ||
68 | } | ||
69 | |||
70 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | 59 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) |
71 | { | 60 | { |
72 | printf("%u: %s | %u\n", peer_number, message, length); | 61 | printf("%u: %s | %u\n", peer_number, message, length); |
@@ -95,8 +84,12 @@ int main(int argc, char *argv[]) | |||
95 | * bootstrap_ip_port.ip.c[2] = 0; | 84 | * bootstrap_ip_port.ip.c[2] = 0; |
96 | * bootstrap_ip_port.ip.c[3] = 1; */ | 85 | * bootstrap_ip_port.ip.c[3] = 1; */ |
97 | bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); | 86 | bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); |
87 | |||
88 | uint8_t *bootstrap_id = hex_string_to_bin(argv[3]); | ||
98 | 89 | ||
99 | chat_bootstrap(chat, bootstrap_ip_port, hex_string_to_bin(argv[3])); | 90 | chat_bootstrap(chat, bootstrap_ip_port, bootstrap_id); |
91 | |||
92 | free(bootstrap_id); | ||
100 | 93 | ||
101 | while (1) { | 94 | while (1) { |
102 | 95 | ||
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index efe1a555..5e322a90 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -28,22 +28,28 @@ | |||
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | #include <stdio.h> | 30 | #include <stdio.h> |
31 | #include <stdint.h> | ||
31 | 32 | ||
32 | #ifdef DEBUG | 33 | #ifdef DEBUG |
33 | #include <assert.h> | 34 | #include <assert.h> |
34 | #endif // DEBUG | 35 | #endif // DEBUG |
35 | 36 | ||
36 | /* TODO: rewrite */ | 37 | // You are responsible for freeing the return value! |
37 | unsigned char *hex_string_to_bin(char hex_string[]) | 38 | uint8_t *hex_string_to_bin(char *hex_string) |
38 | { | 39 | { |
39 | size_t i, len = strlen(hex_string); | 40 | // byte is represented by exactly 2 hex digits, so lenth of binary string |
40 | unsigned char *val = malloc(len); | 41 | // is half of that of the hex one. only hex string with even length |
42 | // valid. the more proper implementation would be to check if strlen(hex_string) | ||
43 | // is odd and return error code if it is. we assume strlen is even. if it's not | ||
44 | // then the last byte just won't be written in 'ret'. | ||
45 | size_t i, len = strlen(hex_string)/2; | ||
46 | uint8_t *ret = malloc(len); | ||
41 | char *pos = hex_string; | 47 | char *pos = hex_string; |
42 | 48 | ||
43 | for (i = 0; i < len; ++i, pos += 2) | 49 | for (i = 0; i < len; ++i, pos += 2) |
44 | sscanf(pos, "%2hhx", &val[i]); | 50 | sscanf(pos, "%2hhx", &ret[i]); |
45 | 51 | ||
46 | return val; | 52 | return ret; |
47 | } | 53 | } |
48 | 54 | ||
49 | int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) | 55 | int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) |
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index ccb5d20d..5d38d2e5 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -221,6 +221,7 @@ int main(int argc, char *argv[]) | |||
221 | uint16_t port = htons(atoi(argv[argvoffset + 2])); | 221 | uint16_t port = htons(atoi(argv[argvoffset + 2])); |
222 | unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); | 222 | unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); |
223 | int res = tox_bootstrap_from_address(tox, argv[argvoffset + 1], ipv6enabled, port, binary_string); | 223 | int res = tox_bootstrap_from_address(tox, argv[argvoffset + 1], ipv6enabled, port, binary_string); |
224 | free(binary_string); | ||
224 | 225 | ||
225 | if (!res) { | 226 | if (!res) { |
226 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); | 227 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); |
@@ -242,7 +243,9 @@ int main(int argc, char *argv[]) | |||
242 | return 1; | 243 | return 1; |
243 | } | 244 | } |
244 | 245 | ||
245 | int num = tox_add_friend(tox, hex_string_to_bin(temp_id), (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 246 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
247 | int num = tox_add_friend(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | ||
248 | free(bin_id); | ||
246 | 249 | ||
247 | if (num < 0) { | 250 | if (num < 0) { |
248 | printf("\nSomething went wrong when adding friend.\n"); | 251 | printf("\nSomething went wrong when adding friend.\n"); |