summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/CMakeLists.txt2
-rw-r--r--testing/cmake/nTox_win32.cmake9
-rw-r--r--testing/nTox_win32.c505
-rw-r--r--testing/nTox_win32.h48
4 files changed, 1 insertions, 563 deletions
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index e3cdc838..02faac38 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -11,7 +11,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
11include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake) 11include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake)
12 12
13if(WIN32) 13if(WIN32)
14# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) 14 #Do nothing
15else() 15else()
16 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) 16 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
17 add_subdirectory(toxic) 17 add_subdirectory(toxic)
diff --git a/testing/cmake/nTox_win32.cmake b/testing/cmake/nTox_win32.cmake
deleted file mode 100644
index 0e33913f..00000000
--- a/testing/cmake/nTox_win32.cmake
+++ /dev/null
@@ -1,9 +0,0 @@
1cmake_minimum_required(VERSION 2.6.0)
2project(nTox_win32 C)
3
4set(exe_name nTox_win32)
5
6add_executable(${exe_name}
7 nTox_win32.c misc_tools.c)
8
9linkCoreLibraries(${exe_name})
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
deleted file mode 100644
index c26d9d16..00000000
--- a/testing/nTox_win32.c
+++ /dev/null
@@ -1,505 +0,0 @@
1/* nTox_win32.c
2 *
3 * Textual frontend for Tox - Windows version
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include "nTox_win32.h"
25#include "misc_tools.h"
26
27#include <process.h>
28
29typedef struct {
30 uint8_t id[CLIENT_ID_SIZE];
31 uint8_t accepted;
32} Friend_request;
33
34Friend_request pending_requests[256];
35uint8_t num_requests = 0;
36uint32_t maxnumfriends;
37
38char line[STRING_LENGTH];
39char users_id[200];
40int friend_request_received;
41
42Messenger *messenger;
43
44void do_header()
45{
46 system("cls");
47 printf(users_id);
48 printf("\n---------------------------------");
49 printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)");
50 printf("\n---------------------------------");
51}
52
53void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
54{
55 friend_request_received = 1;
56 printf("\n\n[i] received friend request with message\n");
57 printf("'%s'", (char *)data);
58 char numchar[100];
59 sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests);
60 printf(numchar);
61 memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE);
62 pending_requests[num_requests].accepted = 0;
63 ++num_requests;
64}
65
66void print_message(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
67{
68 char name[MAX_NAME_LENGTH];
69 getname(messenger, friendnumber, (uint8_t *)name);
70 char msg[100 + length + strlen(name) + 1];
71 time_t rawtime;
72 struct tm *timeinfo;
73 time (&rawtime);
74 timeinfo = localtime (&rawtime);
75 char *temp = asctime(timeinfo);
76 size_t len = strlen(temp);
77 temp[len - 1] = '\0';
78 sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp
79 printf(msg);
80}
81
82void print_nickchange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
83{
84 char name[MAX_NAME_LENGTH];
85 getname(messenger, friendnumber, (uint8_t *)name);
86 char msg[100 + length];
87 sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
88 printf(msg);
89}
90
91void print_statuschange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
92{
93 char name[MAX_NAME_LENGTH];
94 getname(messenger, friendnumber, (uint8_t *)name);
95 char msg[100 + length + strlen(name) + 1];
96 sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
97 printf(msg);
98}
99
100void load_key()
101{
102 FILE *data_file = NULL;
103 data_file = fopen("data", "r");
104
105 if (data_file) {
106 fseek(data_file, 0, SEEK_END);
107 int size = ftell(data_file);
108 fseek(data_file, 0, SEEK_SET);
109 uint8_t data[size];
110
111 if (fread(data, sizeof(uint8_t), size, data_file) != size) {
112 printf("\n[i] Could not read the data file. Exiting.");
113 exit(1);
114 }
115
116 Messenger_load(messenger, data, size);
117 } else {
118 int size = Messenger_size(messenger);
119 uint8_t data[size];
120 Messenger_save(messenger, data);
121 fclose(data_file);
122 data_file = fopen("data", "w");
123
124 if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
125 printf("\n[i] Could not write data to file. Exiting.");
126 exit(1);
127 }
128 }
129
130 fclose(data_file);
131}
132
133void add_friend()
134{
135 int i;
136 char temp_id[128];
137
138 for (i = 0; i < 128; i++)
139 temp_id[i] = line[i + 3];
140
141 int num = m_addfriend(messenger, hex_string_to_bin(temp_id), (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
142
143 if (num >= 0) {
144 char numstring[100];
145 sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
146 printf(numstring);
147 ++maxnumfriends;
148 } else if (num == -1)
149 printf("\n[i] Message is too long.\n\n");
150
151 else if (num == -2)
152 printf("\n[i] Please add a message to your friend request.\n\n");
153
154 else if (num == -3)
155 printf("\n[i] That appears to be your own ID.\n\n");
156
157 else if (num == -4)
158 printf("\n[i] Friend request already sent.\n\n");
159
160 else if (num == -5)
161 printf("\n[i] Undefined error when adding friend\n\n");
162}
163
164void list_friends()
165{
166 int i;
167
168 printf("\n[i] Friend List");
169
170 printf("----- PENDING -----\n\n");
171
172 for (i = 0; i <= maxnumfriends; i++) {
173 char name[MAX_NAME_LENGTH];
174 getname(messenger, i, (uint8_t *)name);
175
176 if (m_friendstatus(messenger, i) > 0 && m_friendstatus(messenger, i) < 4)
177 printf("[%d] %s\n", i, (uint8_t *)name);
178 }
179
180 printf("\n");
181
182 printf("----- ACTIVE -----\n\n");
183
184 for (i = 0; i <= maxnumfriends; i++) {
185 char name[MAX_NAME_LENGTH];
186 getname(messenger, i, (uint8_t *)name);
187
188 if (m_friendstatus(messenger, i) == 4)
189 printf("[%d] %s\n", i, (uint8_t *)name);
190 }
191
192 printf("\n");
193}
194
195void delete_friend()
196{
197 size_t len = strlen(line);
198 char numstring[len - 3];
199 int i;
200
201 for (i = 0; i < len; i++) {
202 if (line[i + 3] != ' ')
203 numstring[i] = line[i + 3];
204 }
205
206 int num = atoi(numstring);
207 m_delfriend(messenger, num);
208 --maxnumfriends;
209 printf("\n\n");
210}
211
212void message_friend()
213{
214 size_t len = strlen(line);
215 char numstring[len - 3];
216 char message[len - 3];
217 int i;
218
219 for (i = 0; i < len; i++) {
220
221 if (line[i + 3] != ' ')
222 numstring[i] = line[i + 3];
223
224 else {
225 int j;
226
227 for (j = (i + 1); j < len; j++)
228 message[j - i - 1] = line[j + 3];
229
230 break;
231 }
232 }
233
234 int num = atoi(numstring);
235
236 if (m_sendmessage(messenger, num, (uint8_t *) message, sizeof(message)) != 1)
237 printf("\n[i] could not send message (they may be offline): %s\n", message);
238
239 else
240 printf("\n");
241}
242
243void change_nickname()
244{
245 uint8_t name[MAX_NAME_LENGTH];
246 int i = 0;
247 size_t len = strlen(line);
248
249 for (i = 3; i < len; i++) {
250
251 if (line[i] == 0 || line[i] == '\n')
252 break;
253
254 name[i - 3] = line[i];
255 }
256
257 name[i - 3] = 0;
258 setname(messenger, name, i);
259 char numstring[100];
260 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char *)name);
261 printf(numstring);
262
263 FILE *name_file = NULL;
264 name_file = fopen("namefile.txt", "w");
265 fprintf(name_file, "%s", (char *)name);
266 fclose(name_file);
267}
268
269void change_status(int savetofile)
270{
271 uint8_t status[MAX_STATUSMESSAGE_LENGTH];
272 int i = 0;
273 size_t len = strlen(line);
274
275 for (i = 3; i < len; i++) {
276 if (line[i] == 0 || line[i] == '\n')
277 break;
278
279 status[i - 3] = line[i];
280 }
281
282 status[i - 3] = 0;
283 m_set_statusmessage(messenger, status, strlen((char *)status));
284 char numstring[100];
285 sprintf(numstring, "\n[i] changed status to %s\n\n", (char *)status);
286 printf(numstring);
287
288 if (savetofile == 1) {
289 FILE *status_file = NULL;
290 status_file = fopen("statusfile.txt", "w");
291 fprintf(status_file, "%s", (char *)status);
292 fclose(status_file);
293 }
294}
295
296void accept_friend_request()
297{
298 friend_request_received = 0;
299 uint8_t numf = atoi(line + 3);
300 char numchar[100];
301
302 if (numf >= num_requests || pending_requests[numf].accepted) {
303 sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it");
304 printf(numchar);
305 } else {
306 int num = m_addfriend_norequest(messenger, pending_requests[numf].id);
307
308 if (num != -1) {
309 pending_requests[numf].accepted = 1;
310 sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num);
311 printf(numchar);
312 ++maxnumfriends;
313 } else {
314 sprintf(numchar, "[i] failed to add friend");
315 printf(numchar);
316 }
317 }
318}
319
320void line_eval(char *line)
321{
322 if (line[0] == '/') {
323
324 char inpt_command = line[1];
325
326 if (inpt_command == 'f') {
327 add_friend();
328 }
329
330 else if (inpt_command == 'r') {
331 do_header();
332 printf("\n\n");
333 }
334
335 else if (inpt_command == 'l') {
336 list_friends();
337 }
338
339 else if (inpt_command == 'd') {
340 delete_friend();
341 }
342 /* Send message to friend */
343 else if (inpt_command == 'm') {
344 message_friend();
345 }
346
347 else if (inpt_command == 'n') {
348 change_nickname();
349 }
350
351 else if (inpt_command == 's') {
352 change_status(1);
353 }
354
355 else if (inpt_command == 'a') {
356 if (friend_request_received == 1)
357 accept_friend_request();
358 }
359 /* EXIT */
360 else if (inpt_command == 'q') {
361 strcpy(line, "---Offline");
362 change_status(0);
363 exit(EXIT_SUCCESS);
364 }
365 }
366}
367
368void get_input()
369{
370 while (1) {
371 fgets(line, STRING_LENGTH, stdin);
372 line_eval(line);
373 strcpy(line, "");
374 }
375}
376
377int main(int argc, char *argv[])
378{
379 if (argc < 4) {
380 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
381 exit(0);
382 }
383
384 messenger = initMessenger();
385
386 if (messenger == 0) {
387 printf("initMessenger failed");
388 exit(0);
389 }
390
391 if (argc > 4) {
392 if (strncmp(argv[4], "nokey", 6) < 0) {
393 }
394 } else {
395 load_key();
396 }
397
398 int nameloaded = 0;
399 int statusloaded = 0;
400
401 FILE *name_file = NULL;
402 name_file = fopen("namefile.txt", "r");
403
404 if (name_file) {
405 uint8_t name[MAX_NAME_LENGTH];
406
407 while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
408 sscanf(line, "%s", (char *)name);
409 }
410
411 setname(messenger, name, strlen((char *)name) + 1);
412 nameloaded = 1;
413 printf("%s\n", name);
414 fclose(name_file);
415 }
416
417 FILE *status_file = NULL;
418 status_file = fopen("statusfile.txt", "r");
419
420 if (status_file) {
421 uint8_t status[MAX_STATUSMESSAGE_LENGTH];
422
423 while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) {
424 sscanf(line, "%s", (char *)status);
425 }
426
427 m_set_statusmessage(messenger, status, strlen((char *)status) + 1);
428 statusloaded = 1;
429 printf("%s\n", status);
430 fclose(status_file);
431 }
432
433 m_callback_friendrequest(messenger, print_request, &status_file);
434 m_callback_friendmessage(messenger, print_message, &status_file);
435 m_callback_namechange(messenger, print_nickchange, &status_file);
436 m_callback_statusmessage(messenger, print_statuschange, &status_file);
437 char idstring1[PUB_KEY_BYTES][5];
438 char idstring2[PUB_KEY_BYTES][5];
439 int i;
440
441 for (i = 0; i < PUB_KEY_BYTES; i++) {
442 if (self_public_key[i] < (PUB_KEY_BYTES / 2))
443 strcpy(idstring1[i], "0");
444 else
445 strcpy(idstring1[i], "");
446
447 sprintf(idstring2[i], "%hhX", self_public_key[i]);
448 }
449
450 strcpy(users_id, "[i] your ID: ");
451 int j;
452
453 for (j = 0; j < PUB_KEY_BYTES; j++) {
454 strcat(users_id, idstring1[j]);
455 strcat(users_id, idstring2[j]);
456 }
457
458 do_header();
459
460 IP_Port bootstrap_ip_port;
461 bootstrap_ip_port.port = htons(atoi(argv[2]));
462 int resolved_address = resolve_addr(argv[1]);
463
464 if (resolved_address != 0)
465 bootstrap_ip_port.ip.i = resolved_address;
466 else
467 exit(1);
468
469 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
470
471 int c;
472 int on = 0;
473
474 _beginthread(get_input, 0, NULL);
475
476 if (nameloaded == 1) {
477 printf("\nNickname automatically loaded");
478 printf("\n---------------------------------");
479 }
480
481 if (statusloaded == 1) {
482 printf("\nStatus automatically loaded");
483 printf("\n---------------------------------");
484 }
485
486 while (1) {
487 if (on == 1 && DHT_isconnected() == -1) {
488 printf("\n---------------------------------");
489 printf("\n[i] Disconnected from the DHT");
490 printf("\n---------------------------------\n\n");
491 on = 0;
492 }
493
494 if (on == 0 && DHT_isconnected()) {
495 printf("\n[i] Connected to DHT");
496 printf("\n---------------------------------\n\n");
497 on = 1;
498 }
499
500 doMessenger(messenger);
501 Sleep(1);
502 }
503
504 return 0;
505}
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h
deleted file mode 100644
index b174edcc..00000000
--- a/testing/nTox_win32.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/* nTox_win32.h
2 *
3 * Textual frontend for Tox - Windows version
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef NTOX_WIN32_H
24#define NTOX_WIN32_H
25
26#include "../core/Messenger.h"
27#include "../core/network.h"
28
29#define STRING_LENGTH 256
30#define PUB_KEY_BYTES 32
31
32void do_header();
33void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata);
34void print_message(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
35void print_nickchange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
36void print_statuschange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
37void load_key();
38void add_friend();
39void list_friends();
40void delete_friend();
41void message_friend();
42void change_nickname();
43void change_status(int savetofile);
44void accept_friend_request();
45void line_eval(char *line);
46void get_input();
47
48#endif