diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 30 | ||||
-rw-r--r-- | testing/nTox_win32.c | 67 | ||||
-rw-r--r-- | testing/nTox_win32.h | 2 | ||||
-rw-r--r-- | testing/toxic/main.c | 2 |
4 files changed, 56 insertions, 45 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 24d40ead..13db58d7 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 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/>. | 20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | #include "nTox.h" | 23 | #include "nTox.h" |
24 | #include "misc_tools.h" | 24 | #include "misc_tools.h" |
@@ -54,7 +54,7 @@ void get_id(char *data) | |||
54 | { | 54 | { |
55 | if (self_public_key[i] < (PUB_KEY_BYTES / 2)) | 55 | if (self_public_key[i] < (PUB_KEY_BYTES / 2)) |
56 | strcpy(idstring1[i],"0"); | 56 | strcpy(idstring1[i],"0"); |
57 | else | 57 | else |
58 | strcpy(idstring1[i], ""); | 58 | strcpy(idstring1[i], ""); |
59 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 59 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
60 | } | 60 | } |
@@ -71,9 +71,9 @@ void get_id(char *data) | |||
71 | void new_lines(char *line) | 71 | void new_lines(char *line) |
72 | { | 72 | { |
73 | int i = 0; | 73 | int i = 0; |
74 | for (i = HISTORY-1; i > 0; i--) | 74 | for (i = HISTORY-1; i > 0; i--) |
75 | strncpy(lines[i], lines[i-1], STRING_LENGTH - 1); | 75 | strncpy(lines[i], lines[i-1], STRING_LENGTH - 1); |
76 | 76 | ||
77 | strncpy(lines[0], line, STRING_LENGTH - 1); | 77 | strncpy(lines[0], line, STRING_LENGTH - 1); |
78 | do_refresh(); | 78 | do_refresh(); |
79 | } | 79 | } |
@@ -133,7 +133,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
133 | if (inpt_command == 'f') { // add friend command: /f ID | 133 | if (inpt_command == 'f') { // add friend command: /f ID |
134 | int i; | 134 | int i; |
135 | char temp_id[128]; | 135 | char temp_id[128]; |
136 | for (i = 0; i < 128; i++) | 136 | for (i = 0; i < 128; i++) |
137 | temp_id[i] = line[i+prompt_offset]; | 137 | temp_id[i] = line[i+prompt_offset]; |
138 | 138 | ||
139 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 139 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
@@ -166,8 +166,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
166 | } | 166 | } |
167 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage | 167 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage |
168 | size_t len = strlen(line); | 168 | size_t len = strlen(line); |
169 | if(len < 3) | 169 | if(len < 3) |
170 | return; | 170 | return; |
171 | 171 | ||
172 | char numstring[len-3]; | 172 | char numstring[len-3]; |
173 | char message[len-3]; | 173 | char message[len-3]; |
@@ -248,7 +248,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
248 | else if (inpt_command == 'q') { //exit | 248 | else if (inpt_command == 'q') { //exit |
249 | endwin(); | 249 | endwin(); |
250 | exit(EXIT_SUCCESS); | 250 | exit(EXIT_SUCCESS); |
251 | } else { | 251 | } else { |
252 | new_lines("[i] invalid command"); | 252 | new_lines("[i] invalid command"); |
253 | } | 253 | } |
254 | } else { | 254 | } else { |
@@ -335,7 +335,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
335 | new_lines(format_message((char*)string, friendnumber)); | 335 | new_lines(format_message((char*)string, friendnumber)); |
336 | } | 336 | } |
337 | 337 | ||
338 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | 338 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) |
339 | { | 339 | { |
340 | char name[MAX_NAME_LENGTH]; | 340 | char name[MAX_NAME_LENGTH]; |
341 | getname(friendnumber, (uint8_t*)name); | 341 | getname(friendnumber, (uint8_t*)name); |
@@ -344,7 +344,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
344 | new_lines(msg); | 344 | new_lines(msg); |
345 | } | 345 | } |
346 | 346 | ||
347 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | 347 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
348 | { | 348 | { |
349 | char name[MAX_NAME_LENGTH]; | 349 | char name[MAX_NAME_LENGTH]; |
350 | getname(friendnumber, (uint8_t*)name); | 350 | getname(friendnumber, (uint8_t*)name); |
@@ -353,7 +353,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | |||
353 | new_lines(msg); | 353 | new_lines(msg); |
354 | } | 354 | } |
355 | 355 | ||
356 | void load_key() | 356 | void load_key() |
357 | { | 357 | { |
358 | FILE *data_file = NULL; | 358 | FILE *data_file = NULL; |
359 | data_file = fopen("data","r"); | 359 | data_file = fopen("data","r"); |
@@ -368,7 +368,7 @@ void load_key() | |||
368 | exit(1); | 368 | exit(1); |
369 | } | 369 | } |
370 | Messenger_load(data, size); | 370 | Messenger_load(data, size); |
371 | } else { | 371 | } else { |
372 | //else save new keys | 372 | //else save new keys |
373 | int size = Messenger_size(); | 373 | int size = Messenger_size(); |
374 | uint8_t data[size]; | 374 | uint8_t data[size]; |
@@ -418,9 +418,9 @@ int main(int argc, char *argv[]) | |||
418 | int resolved_address = resolve_addr(argv[1]); | 418 | int resolved_address = resolve_addr(argv[1]); |
419 | if (resolved_address != 0) | 419 | if (resolved_address != 0) |
420 | bootstrap_ip_port.ip.i = resolved_address; | 420 | bootstrap_ip_port.ip.i = resolved_address; |
421 | else | 421 | else |
422 | exit(1); | 422 | exit(1); |
423 | 423 | ||
424 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 424 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
425 | nodelay(stdscr, TRUE); | 425 | nodelay(stdscr, TRUE); |
426 | while(true) { | 426 | while(true) { |
@@ -441,7 +441,7 @@ int main(int argc, char *argv[]) | |||
441 | if (c == '\n') { | 441 | if (c == '\n') { |
442 | line_eval(lines, line); | 442 | line_eval(lines, line); |
443 | strcpy(line, ""); | 443 | strcpy(line, ""); |
444 | } else if (c == 127) { | 444 | } else if (c == 8 || c == 127) { |
445 | line[strlen(line)-1] = '\0'; | 445 | line[strlen(line)-1] = '\0'; |
446 | } else if (isalnum(c) || ispunct(c) || c == ' ') { | 446 | } else if (isalnum(c) || ispunct(c) || c == ' ') { |
447 | strcpy(line, appender(line, (char) c)); | 447 | strcpy(line, appender(line, (char) c)); |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 3b6fb043..5501ecf5 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -32,6 +32,7 @@ uint32_t maxnumfriends; | |||
32 | 32 | ||
33 | char line[STRING_LENGTH]; | 33 | char line[STRING_LENGTH]; |
34 | char users_id[200]; | 34 | char users_id[200]; |
35 | int friend_request_received; | ||
35 | 36 | ||
36 | void do_header() | 37 | void do_header() |
37 | { | 38 | { |
@@ -44,10 +45,11 @@ void do_header() | |||
44 | 45 | ||
45 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | 46 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) |
46 | { | 47 | { |
48 | friend_request_received = 1; | ||
47 | printf("\n\n[i] received friend request with message\n"); | 49 | printf("\n\n[i] received friend request with message\n"); |
48 | printf((char *)data); | 50 | printf("'%s'",(char *)data); |
49 | char numchar[100]; | 51 | char numchar[100]; |
50 | sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests); | 52 | sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests); |
51 | printf(numchar); | 53 | printf(numchar); |
52 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 54 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); |
53 | ++num_requests; | 55 | ++num_requests; |
@@ -151,23 +153,32 @@ void add_friend() | |||
151 | 153 | ||
152 | void list_friends() | 154 | void list_friends() |
153 | { | 155 | { |
154 | int activefriends = 0; | ||
155 | int i; | 156 | int i; |
157 | |||
158 | printf("\n[i] Friend List"); | ||
159 | |||
160 | printf("----- PENDING -----\n\n"); | ||
156 | 161 | ||
157 | for (i = 0; i <= maxnumfriends; i++) { | 162 | for (i = 0; i <= maxnumfriends; i++) { |
158 | if (m_friendstatus(i) == 4) | 163 | char name[MAX_NAME_LENGTH]; |
159 | activefriends++; | 164 | getname(i, (uint8_t*)name); |
165 | if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4) | ||
166 | printf("[%d] %s\n", i, (uint8_t*)name); | ||
160 | } | 167 | } |
168 | |||
169 | printf("\n"); | ||
161 | 170 | ||
162 | printf("\n[i] Friend List | Total: %d\n\n", activefriends); | 171 | printf("----- ACTIVE -----\n\n"); |
163 | 172 | ||
164 | for (i = 0; i <= 256; i++) {/* TODO: fix this properly*/ | 173 | for (i = 0; i <= maxnumfriends; i++) { |
165 | char name[MAX_NAME_LENGTH]; | 174 | char name[MAX_NAME_LENGTH]; |
166 | getname(i, (uint8_t*)name); | 175 | getname(i, (uint8_t*)name); |
167 | 176 | ||
168 | if (m_friendstatus(i) == 4) | 177 | if (m_friendstatus(i) == 4) |
169 | printf("[%d] %s\n\n", i, (uint8_t*)name); | 178 | printf("[%d] %s\n", i, (uint8_t*)name); |
170 | } | 179 | } |
180 | |||
181 | printf("\n"); | ||
171 | } | 182 | } |
172 | 183 | ||
173 | void delete_friend() | 184 | void delete_friend() |
@@ -244,7 +255,7 @@ void change_nickname() | |||
244 | fclose(name_file); | 255 | fclose(name_file); |
245 | } | 256 | } |
246 | 257 | ||
247 | void change_status() | 258 | void change_status(int savetofile) |
248 | { | 259 | { |
249 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 260 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
250 | int i = 0; | 261 | int i = 0; |
@@ -263,20 +274,21 @@ void change_status() | |||
263 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 274 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
264 | printf(numstring); | 275 | printf(numstring); |
265 | 276 | ||
266 | FILE* status_file = NULL; | 277 | if (savetofile == 1) { |
267 | status_file = fopen("statusfile.txt", "w"); | 278 | FILE* status_file = NULL; |
268 | fprintf(status_file, "%s", (char*)status); | 279 | status_file = fopen("statusfile.txt", "w"); |
269 | fclose(status_file); | 280 | fprintf(status_file, "%s", (char*)status); |
281 | fclose(status_file); | ||
282 | } | ||
270 | } | 283 | } |
271 | 284 | ||
272 | void accept_friend_request() | 285 | void accept_friend_request() |
273 | { | 286 | { |
287 | friend_request_received = 0; | ||
274 | uint8_t numf = atoi(line + 3); | 288 | uint8_t numf = atoi(line + 3); |
275 | char numchar[100]; | 289 | 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]); | 290 | int num = m_addfriend_norequest(pending_requests[numf]); |
279 | sprintf(numchar, "\n[i] added friendnumber %d\n\n", num); | 291 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); |
280 | printf(numchar); | 292 | printf(numchar); |
281 | ++maxnumfriends; | 293 | ++maxnumfriends; |
282 | } | 294 | } |
@@ -288,7 +300,7 @@ void line_eval(char* line) | |||
288 | char inpt_command = line[1]; | 300 | char inpt_command = line[1]; |
289 | 301 | ||
290 | if(inpt_command == 'f') { | 302 | if(inpt_command == 'f') { |
291 | add_friend(line); | 303 | add_friend(); |
292 | } | 304 | } |
293 | 305 | ||
294 | else if (inpt_command == 'r') { | 306 | else if (inpt_command == 'r') { |
@@ -297,32 +309,33 @@ void line_eval(char* line) | |||
297 | } | 309 | } |
298 | 310 | ||
299 | else if (inpt_command == 'l') { | 311 | else if (inpt_command == 'l') { |
300 | list_friends(line); | 312 | list_friends(); |
301 | } | 313 | } |
302 | 314 | ||
303 | else if (inpt_command == 'd') { | 315 | else if (inpt_command == 'd') { |
304 | delete_friend(line); | 316 | delete_friend(); |
305 | } | 317 | } |
306 | /* Send message to friend */ | 318 | /* Send message to friend */ |
307 | else if (inpt_command == 'm') { | 319 | else if (inpt_command == 'm') { |
308 | message_friend(line); | 320 | message_friend(); |
309 | } | 321 | } |
310 | 322 | ||
311 | else if (inpt_command == 'n') { | 323 | else if (inpt_command == 'n') { |
312 | change_nickname(line); | 324 | change_nickname(); |
313 | } | 325 | } |
314 | 326 | ||
315 | else if (inpt_command == 's') { | 327 | else if (inpt_command == 's') { |
316 | change_status(line); | 328 | change_status(1); |
317 | } | 329 | } |
318 | 330 | ||
319 | else if (inpt_command == 'a') { | 331 | else if (inpt_command == 'a') { |
320 | accept_friend_request(line); | 332 | if (friend_request_received == 1) |
333 | accept_friend_request(line); | ||
321 | } | 334 | } |
322 | /* EXIT */ | 335 | /* EXIT */ |
323 | else if (inpt_command == 'q') { | 336 | else if (inpt_command == 'q') { |
324 | uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline"; | 337 | strcpy(line, "---Offline"); |
325 | m_set_userstatus(status, strlen((char*)status)); | 338 | change_status(0); |
326 | exit(EXIT_SUCCESS); | 339 | exit(EXIT_SUCCESS); |
327 | } | 340 | } |
328 | } | 341 | } |
@@ -368,8 +381,7 @@ int main(int argc, char *argv[]) | |||
368 | nameloaded = 1; | 381 | nameloaded = 1; |
369 | printf("%s\n", name); | 382 | printf("%s\n", name); |
370 | fclose(name_file); | 383 | fclose(name_file); |
371 | } | 384 | } |
372 | |||
373 | 385 | ||
374 | FILE* status_file = NULL; | 386 | FILE* status_file = NULL; |
375 | status_file = fopen("statusfile.txt", "r"); | 387 | status_file = fopen("statusfile.txt", "r"); |
@@ -383,7 +395,6 @@ int main(int argc, char *argv[]) | |||
383 | printf("%s\n", status); | 395 | printf("%s\n", status); |
384 | fclose(status_file); | 396 | fclose(status_file); |
385 | } | 397 | } |
386 | |||
387 | 398 | ||
388 | m_callback_friendrequest(print_request); | 399 | m_callback_friendrequest(print_request); |
389 | m_callback_friendmessage(print_message); | 400 | m_callback_friendmessage(print_message); |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 211ac95f..271403b8 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -39,7 +39,7 @@ void list_friends(); | |||
39 | void delete_friend(); | 39 | void delete_friend(); |
40 | void message_friend(); | 40 | void message_friend(); |
41 | void change_nickname(); | 41 | void change_nickname(); |
42 | void change_status(); | 42 | void change_status(int savetofile); |
43 | void accept_friend_request(); | 43 | void accept_friend_request(); |
44 | void line_eval(char* line); | 44 | void line_eval(char* line); |
45 | void get_input(); | 45 | void get_input(); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index bcfc487f..391b0b39 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -50,7 +50,7 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) { | |||
50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { | 50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { |
51 | size_t i; | 51 | size_t i; |
52 | 52 | ||
53 | wprintw(prompt->window, "\n(message) %d: %s!\n", friendnumber, string); | 53 | wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); |
54 | 54 | ||
55 | for(i=0; i<w_num; i++) { | 55 | for(i=0; i<w_num; i++) { |
56 | if(windows[i].onMessage != NULL) | 56 | if(windows[i].onMessage != NULL) |