summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 9a07ecdc..072c17e3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -147,19 +147,19 @@ void line_eval(char *line)
147 free(bin_string); 147 free(bin_string);
148 char numstring[100]; 148 char numstring[100];
149 switch (num) { 149 switch (num) {
150 case -1: 150 case FAERR_TOOLONG:
151 sprintf(numstring, "[i] Message is too long."); 151 sprintf(numstring, "[i] Message is too long.");
152 break; 152 break;
153 case -2: 153 case FAERR_NOMESSAGE:
154 sprintf(numstring, "[i] Please add a message to your request."); 154 sprintf(numstring, "[i] Please add a message to your request.");
155 break; 155 break;
156 case -3: 156 case FAERR_OWNKEY:
157 sprintf(numstring, "[i] That appears to be your own ID."); 157 sprintf(numstring, "[i] That appears to be your own ID.");
158 break; 158 break;
159 case -4: 159 case FAERR_ALREADYSENT:
160 sprintf(numstring, "[i] Friend request already sent."); 160 sprintf(numstring, "[i] Friend request already sent.");
161 break; 161 break;
162 case -5: 162 case FAERR_UNKNOWN:
163 sprintf(numstring, "[i] Undefined error when adding friend."); 163 sprintf(numstring, "[i] Undefined error when adding friend.");
164 break; 164 break;
165 default: 165 default:
@@ -345,34 +345,38 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
345void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) 345void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
346{ 346{
347 char name[MAX_NAME_LENGTH]; 347 char name[MAX_NAME_LENGTH];
348 getname(friendnumber, (uint8_t*)name); 348 if(getname(friendnumber, (uint8_t*)name) != -1) {
349 char msg[100+length]; 349 char msg[100+length];
350 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); 350 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
351 new_lines(msg); 351 new_lines(msg);
352 }
352} 353}
353 354
354void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) 355void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
355{ 356{
356 char name[MAX_NAME_LENGTH]; 357 char name[MAX_NAME_LENGTH];
357 getname(friendnumber, (uint8_t*)name); 358 if(getname(friendnumber, (uint8_t*)name) != -1) {
358 char msg[100+length+strlen(name)+1]; 359 char msg[100+length+strlen(name)+1];
359 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); 360 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
360 new_lines(msg); 361 new_lines(msg);
362 }
361} 363}
362 364
363void load_key(char *path) 365void load_key(char *path)
364{ 366{
365 FILE *data_file = fopen(path, "r"); 367 FILE *data_file = fopen(path, "r");
368 int size = 0;
366 369
367 if (data_file) { 370 if (data_file) {
368 //load keys 371 //load keys
369 fseek(data_file, 0, SEEK_END); 372 fseek(data_file, 0, SEEK_END);
370 int size = ftell(data_file); 373 size = ftell(data_file);
371 fseek(data_file, 0, SEEK_SET); 374 rewind(data_file);
375
372 uint8_t data[size]; 376 uint8_t data[size];
373 if (fread(data, sizeof(uint8_t), size, data_file) != size){ 377 if (fread(data, sizeof(uint8_t), size, data_file) != size){
374 printf("[i] could not read data file\n[i] exiting\n"); 378 fputs("[!] could not read data file! exiting...\n", stderr);
375 exit(1); 379 goto FILE_ERROR;
376 } 380 }
377 Messenger_load(data, size); 381 Messenger_load(data, size);
378 382
@@ -389,11 +393,17 @@ void load_key(char *path)
389 } 393 }
390 394
391 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ 395 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
392 puts("[i] could not write data file! exiting..."); 396 fputs("[!] could not write data file! exiting...", stderr);
393 exit(1); 397 goto FILE_ERROR;
394 } 398 }
395 } 399 }
396 fclose(data_file); 400
401 return;
402
403FILE_ERROR:
404 if(fclose(data_file) < 0)
405 perror("[!] fclose failed");
406 exit(1);
397} 407}
398 408
399void print_help(void) 409void print_help(void)