diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 12 | ||||
-rw-r--r-- | testing/nTox_win32.c | 294 | ||||
-rw-r--r-- | testing/nTox_win32.h | 7 |
3 files changed, 192 insertions, 121 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 588450e2..f1940614 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -60,11 +60,11 @@ void print_clientlist() | |||
60 | } | 60 | } |
61 | p_ip = close_clientlist[i].ip_port; | 61 | p_ip = close_clientlist[i].ip_port; |
62 | printf("\nIP: %u.%u.%u.%u Port: %u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 62 | printf("\nIP: %u.%u.%u.%u Port: %u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); |
63 | printf("\nTimestamp: %u", close_clientlist[i].timestamp); | 63 | printf("\nTimestamp: %llu",(long long unsigned int) close_clientlist[i].timestamp); |
64 | printf("\nLast pinged: %u\n", close_clientlist[i].last_pinged); | 64 | printf("\nLast pinged: %llu\n",(long long unsigned int) close_clientlist[i].last_pinged); |
65 | p_ip = close_clientlist[i].ret_ip_port; | 65 | p_ip = close_clientlist[i].ret_ip_port; |
66 | printf("OUR IP: %u.%u.%u.%u Port: %u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 66 | printf("OUR IP: %u.%u.%u.%u Port: %u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); |
67 | printf("Timestamp: %u\n", close_clientlist[i].ret_timestamp); | 67 | printf("Timestamp: %llu\n",(long long unsigned int) close_clientlist[i].ret_timestamp); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
@@ -93,11 +93,11 @@ void print_friendlist() | |||
93 | } | 93 | } |
94 | p_ip = friends_list[k].client_list[i].ip_port; | 94 | p_ip = friends_list[k].client_list[i].ip_port; |
95 | printf("\nIP: %u.%u.%u.%u:%u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 95 | printf("\nIP: %u.%u.%u.%u:%u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); |
96 | printf("\nTimestamp: %u", friends_list[k].client_list[i].timestamp); | 96 | printf("\nTimestamp: %llu",(long long unsigned int) friends_list[k].client_list[i].timestamp); |
97 | printf("\nLast pinged: %u\n", friends_list[k].client_list[i].last_pinged); | 97 | printf("\nLast pinged: %llu\n",(long long unsigned int) friends_list[k].client_list[i].last_pinged); |
98 | p_ip = friends_list[k].client_list[i].ret_ip_port; | 98 | p_ip = friends_list[k].client_list[i].ret_ip_port; |
99 | printf("ret IP: %u.%u.%u.%u:%u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 99 | printf("ret IP: %u.%u.%u.%u:%u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); |
100 | printf("Timestamp: %u\n", friends_list[k].client_list[i].ret_timestamp); | 100 | printf("Timestamp: %llu\n", (long long unsigned int)friends_list[k].client_list[i].ret_timestamp); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | } | 103 | } |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 42780923..3b6fb043 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; |
30 | uint8_t num_requests = 0; | 30 | uint8_t num_requests = 0; |
31 | uint32_t maxnumfriends; | ||
31 | 32 | ||
32 | char line[STRING_LENGTH]; | 33 | char line[STRING_LENGTH]; |
33 | char users_id[200]; | 34 | char users_id[200]; |
@@ -105,6 +106,7 @@ void load_key() | |||
105 | int size = Messenger_size(); | 106 | int size = Messenger_size(); |
106 | uint8_t data[size]; | 107 | uint8_t data[size]; |
107 | Messenger_save(data); | 108 | Messenger_save(data); |
109 | fclose(data_file); | ||
108 | data_file = fopen("data", "w"); | 110 | data_file = fopen("data", "w"); |
109 | 111 | ||
110 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { | 112 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { |
@@ -115,32 +117,178 @@ void load_key() | |||
115 | fclose(data_file); | 117 | fclose(data_file); |
116 | } | 118 | } |
117 | 119 | ||
120 | void add_friend() | ||
121 | { | ||
122 | int i; | ||
123 | char temp_id[128]; | ||
124 | |||
125 | for (i = 0; i < 128; i++) | ||
126 | temp_id[i] = line[i+3]; | ||
127 | |||
128 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | ||
129 | |||
130 | if (num >= 0) { | ||
131 | char numstring[100]; | ||
132 | sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num); | ||
133 | printf(numstring); | ||
134 | ++maxnumfriends; | ||
135 | } | ||
136 | else if (num == -1) | ||
137 | printf("\n[i] Message is too long.\n\n"); | ||
138 | |||
139 | else if (num == -2) | ||
140 | printf("\n[i] Please add a message to your friend request.\n\n"); | ||
141 | |||
142 | else if (num == -3) | ||
143 | printf("\n[i] That appears to be your own ID.\n\n"); | ||
144 | |||
145 | else if (num == -4) | ||
146 | printf("\n[i] Friend request already sent.\n\n"); | ||
147 | |||
148 | else if (num == -5) | ||
149 | printf("\n[i] Undefined error when adding friend\n\n"); | ||
150 | } | ||
151 | |||
152 | void list_friends() | ||
153 | { | ||
154 | int activefriends = 0; | ||
155 | int i; | ||
156 | |||
157 | for (i = 0; i <= maxnumfriends; i++) { | ||
158 | if (m_friendstatus(i) == 4) | ||
159 | activefriends++; | ||
160 | } | ||
161 | |||
162 | printf("\n[i] Friend List | Total: %d\n\n", activefriends); | ||
163 | |||
164 | for (i = 0; i <= 256; i++) {/* TODO: fix this properly*/ | ||
165 | char name[MAX_NAME_LENGTH]; | ||
166 | getname(i, (uint8_t*)name); | ||
167 | |||
168 | if (m_friendstatus(i) == 4) | ||
169 | printf("[%d] %s\n\n", i, (uint8_t*)name); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | void delete_friend() | ||
174 | { | ||
175 | size_t len = strlen(line); | ||
176 | char numstring[len-3]; | ||
177 | int i; | ||
178 | |||
179 | for (i = 0; i < len; i++) { | ||
180 | if (line[i+3] != ' ') | ||
181 | numstring[i] = line[i+3]; | ||
182 | } | ||
183 | |||
184 | int num = atoi(numstring); | ||
185 | m_delfriend(num); | ||
186 | --maxnumfriends; | ||
187 | printf("\n\n"); | ||
188 | } | ||
189 | |||
190 | void message_friend() | ||
191 | { | ||
192 | size_t len = strlen(line); | ||
193 | char numstring[len-3]; | ||
194 | char message[len-3]; | ||
195 | int i; | ||
196 | |||
197 | for (i = 0; i < len; i++) { | ||
198 | |||
199 | if (line[i+3] != ' ') | ||
200 | numstring[i] = line[i+3]; | ||
201 | |||
202 | else { | ||
203 | int j; | ||
204 | |||
205 | for (j = (i+1); j < len; j++) | ||
206 | message[j-i-1] = line[j+3]; | ||
207 | |||
208 | break; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | int num = atoi(numstring); | ||
213 | |||
214 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) | ||
215 | printf("\n[i] could not send message (they may be offline): %s\n", message); | ||
216 | |||
217 | else | ||
218 | printf("\n"); | ||
219 | } | ||
220 | |||
221 | void change_nickname() | ||
222 | { | ||
223 | uint8_t name[MAX_NAME_LENGTH]; | ||
224 | int i = 0; | ||
225 | size_t len = strlen(line); | ||
226 | |||
227 | for (i = 3; i < len; i++) { | ||
228 | |||
229 | if (line[i] == 0 || line[i] == '\n') | ||
230 | break; | ||
231 | |||
232 | name[i-3] = line[i]; | ||
233 | } | ||
234 | |||
235 | name[i-3] = 0; | ||
236 | setname(name, i); | ||
237 | char numstring[100]; | ||
238 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | ||
239 | printf(numstring); | ||
240 | |||
241 | FILE *name_file = NULL; | ||
242 | name_file = fopen("namefile.txt", "w"); | ||
243 | fprintf(name_file, "%s", (char*)name); | ||
244 | fclose(name_file); | ||
245 | } | ||
246 | |||
247 | void change_status() | ||
248 | { | ||
249 | uint8_t status[MAX_USERSTATUS_LENGTH]; | ||
250 | int i = 0; | ||
251 | size_t len = strlen(line); | ||
252 | |||
253 | for (i = 3; i < len; i++) { | ||
254 | if (line[i] == 0 || line[i] == '\n') | ||
255 | break; | ||
256 | |||
257 | status[i-3] = line[i]; | ||
258 | } | ||
259 | |||
260 | status[i-3] = 0; | ||
261 | m_set_userstatus(status, strlen((char*)status)); | ||
262 | char numstring[100]; | ||
263 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | ||
264 | printf(numstring); | ||
265 | |||
266 | FILE* status_file = NULL; | ||
267 | status_file = fopen("statusfile.txt", "w"); | ||
268 | fprintf(status_file, "%s", (char*)status); | ||
269 | fclose(status_file); | ||
270 | } | ||
271 | |||
272 | void accept_friend_request() | ||
273 | { | ||
274 | uint8_t numf = atoi(line + 3); | ||
275 | char numchar[100]; | ||
276 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); | ||
277 | printf(numchar); | ||
278 | int num = m_addfriend_norequest(pending_requests[numf]); | ||
279 | sprintf(numchar, "\n[i] added friendnumber %d\n\n", num); | ||
280 | printf(numchar); | ||
281 | ++maxnumfriends; | ||
282 | } | ||
283 | |||
118 | void line_eval(char* line) | 284 | void line_eval(char* line) |
119 | { | 285 | { |
120 | if(line[0] == '/') { | 286 | if(line[0] == '/') { |
287 | |||
121 | char inpt_command = line[1]; | 288 | char inpt_command = line[1]; |
122 | /* Add friend */ | 289 | |
123 | if(inpt_command == 'f') { | 290 | if(inpt_command == 'f') { |
124 | int i; | 291 | add_friend(line); |
125 | char temp_id[128]; | ||
126 | for (i = 0; i < 128; i++) | ||
127 | temp_id[i] = line[i+3]; | ||
128 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | ||
129 | if (num >= 0) { | ||
130 | char numstring[100]; | ||
131 | sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num); | ||
132 | printf(numstring); | ||
133 | } | ||
134 | else if (num == -1) | ||
135 | printf("\n[i] Message is too long.\n\n"); | ||
136 | else if (num == -2) | ||
137 | printf("\n[i] Please add a message to your friend request.\n\n"); | ||
138 | else if (num == -3) | ||
139 | printf("\n[i] That appears to be your own ID.\n\n"); | ||
140 | else if (num == -4) | ||
141 | printf("\n[i] Friend request already sent.\n\n"); | ||
142 | else if (num == -5) | ||
143 | printf("\n[i] Undefined error when adding friend\n\n"); | ||
144 | } | 292 | } |
145 | 293 | ||
146 | else if (inpt_command == 'r') { | 294 | else if (inpt_command == 'r') { |
@@ -149,111 +297,27 @@ void line_eval(char* line) | |||
149 | } | 297 | } |
150 | 298 | ||
151 | else if (inpt_command == 'l') { | 299 | else if (inpt_command == 'l') { |
152 | int activefriends = 0; | 300 | list_friends(line); |
153 | int i; | ||
154 | |||
155 | for (i = 0; i <= getnumfriends(); i++) | ||
156 | { | ||
157 | if (m_friendstatus(i) == 4) | ||
158 | activefriends++; | ||
159 | } | ||
160 | |||
161 | printf("\n[i] Friend List | Total: %d\n\n", activefriends); | ||
162 | |||
163 | for (i = 0; i <= getnumfriends(); i++) { | ||
164 | char name[MAX_NAME_LENGTH]; | ||
165 | getname(i, (uint8_t*)name); | ||
166 | if (m_friendstatus(i) == 4) | ||
167 | printf("[%d] %s\n\n", i, (uint8_t*)name); | ||
168 | } | ||
169 | } | 301 | } |
170 | 302 | ||
171 | else if (inpt_command == 'd') { | 303 | else if (inpt_command == 'd') { |
172 | size_t len = strlen(line); | 304 | delete_friend(line); |
173 | char numstring[len-3]; | ||
174 | int i; | ||
175 | for (i = 0; i < len; i++) { | ||
176 | if (line[i+3] != ' ') { | ||
177 | numstring[i] = line[i+3]; | ||
178 | } | ||
179 | } | ||
180 | int num = atoi(numstring); | ||
181 | m_delfriend(num); | ||
182 | printf("\n\n"); | ||
183 | } | 305 | } |
184 | /* Send message to friend */ | 306 | /* Send message to friend */ |
185 | else if (inpt_command == 'm') { | 307 | else if (inpt_command == 'm') { |
186 | size_t len = strlen(line); | 308 | message_friend(line); |
187 | char numstring[len-3]; | ||
188 | char message[len-3]; | ||
189 | int i; | ||
190 | for (i = 0; i < len; i++) { | ||
191 | if (line[i+3] != ' ') { | ||
192 | numstring[i] = line[i+3]; | ||
193 | } else { | ||
194 | int j; | ||
195 | for (j = (i+1); j < len; j++) | ||
196 | message[j-i-1] = line[j+3]; | ||
197 | break; | ||
198 | } | ||
199 | } | ||
200 | int num = atoi(numstring); | ||
201 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | ||
202 | printf("\n[i] could not send message (they may be offline): %s\n", message); | ||
203 | } else { | ||
204 | //simply for aesthetics | ||
205 | printf("\n"); | ||
206 | } | ||
207 | } | 309 | } |
208 | 310 | ||
209 | else if (inpt_command == 'n') { | 311 | else if (inpt_command == 'n') { |
210 | uint8_t name[MAX_NAME_LENGTH]; | 312 | change_nickname(line); |
211 | int i = 0; | ||
212 | size_t len = strlen(line); | ||
213 | for (i = 3; i < len; i++) { | ||
214 | if (line[i] == 0 || line[i] == '\n') break; | ||
215 | name[i-3] = line[i]; | ||
216 | } | ||
217 | name[i-3] = 0; | ||
218 | setname(name, i); | ||
219 | char numstring[100]; | ||
220 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | ||
221 | printf(numstring); | ||
222 | |||
223 | FILE *name_file = NULL; | ||
224 | name_file = fopen("namefile.txt", "w"); | ||
225 | fprintf(name_file, "%s", (char*)name); | ||
226 | fclose(name_file); | ||
227 | } | 313 | } |
228 | 314 | ||
229 | else if (inpt_command == 's') { | 315 | else if (inpt_command == 's') { |
230 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 316 | change_status(line); |
231 | int i = 0; | ||
232 | size_t len = strlen(line); | ||
233 | for (i = 3; i < len; i++) { | ||
234 | if (line[i] == 0 || line[i] == '\n') break; | ||
235 | status[i-3] = line[i]; | ||
236 | } | ||
237 | status[i-3] = 0; | ||
238 | m_set_userstatus(status, strlen((char*)status)); | ||
239 | char numstring[100]; | ||
240 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | ||
241 | printf(numstring); | ||
242 | |||
243 | FILE* status_file = NULL; | ||
244 | status_file = fopen("statusfile.txt", "w"); | ||
245 | fprintf(status_file, "%s", (char*)status); | ||
246 | fclose(status_file); | ||
247 | } | 317 | } |
248 | 318 | ||
249 | else if (inpt_command == 'a') { | 319 | else if (inpt_command == 'a') { |
250 | uint8_t numf = atoi(line + 3); | 320 | accept_friend_request(line); |
251 | char numchar[100]; | ||
252 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); | ||
253 | printf(numchar); | ||
254 | int num = m_addfriend_norequest(pending_requests[numf]); | ||
255 | sprintf(numchar, "\n[i] added friendnumber %d\n\n", num); | ||
256 | printf(numchar); | ||
257 | } | 321 | } |
258 | /* EXIT */ | 322 | /* EXIT */ |
259 | else if (inpt_command == 'q') { | 323 | else if (inpt_command == 'q') { |
@@ -261,8 +325,6 @@ void line_eval(char* line) | |||
261 | m_set_userstatus(status, strlen((char*)status)); | 325 | m_set_userstatus(status, strlen((char*)status)); |
262 | exit(EXIT_SUCCESS); | 326 | exit(EXIT_SUCCESS); |
263 | } | 327 | } |
264 | } else { | ||
265 | //nothing atm | ||
266 | } | 328 | } |
267 | } | 329 | } |
268 | 330 | ||
@@ -305,8 +367,9 @@ int main(int argc, char *argv[]) | |||
305 | setname(name, strlen((char*)name)+1); | 367 | setname(name, strlen((char*)name)+1); |
306 | nameloaded = 1; | 368 | nameloaded = 1; |
307 | printf("%s\n", name); | 369 | printf("%s\n", name); |
370 | fclose(name_file); | ||
308 | } | 371 | } |
309 | fclose(name_file); | 372 | |
310 | 373 | ||
311 | FILE* status_file = NULL; | 374 | FILE* status_file = NULL; |
312 | status_file = fopen("statusfile.txt", "r"); | 375 | status_file = fopen("statusfile.txt", "r"); |
@@ -318,8 +381,9 @@ int main(int argc, char *argv[]) | |||
318 | m_set_userstatus(status, strlen((char*)status)+1); | 381 | m_set_userstatus(status, strlen((char*)status)+1); |
319 | statusloaded = 1; | 382 | statusloaded = 1; |
320 | printf("%s\n", status); | 383 | printf("%s\n", status); |
384 | fclose(status_file); | ||
321 | } | 385 | } |
322 | fclose(status_file); | 386 | |
323 | 387 | ||
324 | m_callback_friendrequest(print_request); | 388 | m_callback_friendrequest(print_request); |
325 | m_callback_friendmessage(print_message); | 389 | m_callback_friendmessage(print_message); |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 374348a4..211ac95f 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -34,6 +34,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length); | |||
34 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); | 34 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); |
35 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); | 35 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); |
36 | void load_key(); | 36 | void load_key(); |
37 | void add_friend(); | ||
38 | void list_friends(); | ||
39 | void delete_friend(); | ||
40 | void message_friend(); | ||
41 | void change_nickname(); | ||
42 | void change_status(); | ||
43 | void accept_friend_request(); | ||
37 | void line_eval(char* line); | 44 | void line_eval(char* line); |
38 | void get_input(); | 45 | void get_input(); |
39 | 46 | ||