diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index faa6cfa5..50ceb92e 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -1,7 +1,7 @@ | |||
1 | #include "nTox.h" | 1 | #include "nTox.h" |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <time.h> | 3 | #include <time.h> |
4 | 4 | #include <string.h> | |
5 | #ifdef WIN32 | 5 | #ifdef WIN32 |
6 | #define c_sleep(x) Sleep(1*x) | 6 | #define c_sleep(x) Sleep(1*x) |
7 | #else | 7 | #else |
@@ -212,42 +212,50 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | |||
212 | free(name); | 212 | free(name); |
213 | new_lines(msg); | 213 | new_lines(msg); |
214 | } | 214 | } |
215 | int load_key(){ | ||
216 | FILE *data_file = NULL; | ||
217 | if ((data_file = fopen("data","r"))) { | ||
218 | //load keys | ||
219 | fseek(data_file, 0, SEEK_END); | ||
220 | int size = ftell(data_file); | ||
221 | fseek(data_file, 0, SEEK_SET); | ||
222 | uint8_t data[size]; | ||
223 | if(fread(data, sizeof(uint8_t), size, data_file) != size){ | ||
224 | printf("Error reading file\n"); | ||
225 | exit(0); | ||
226 | } | ||
227 | Messenger_load(data, size); | ||
228 | } else { | ||
229 | //else save new keys | ||
230 | int size = Messenger_size(); | ||
231 | uint8_t data[size]; | ||
232 | Messenger_save(data); | ||
233 | data_file = fopen("data","w"); | ||
234 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ | ||
235 | printf("Error writing file\n"); | ||
236 | exit(0); | ||
237 | } | ||
238 | } | ||
239 | fclose(data_file); | ||
240 | return 0; | ||
241 | } | ||
215 | int main(int argc, char *argv[]) | 242 | int main(int argc, char *argv[]) |
216 | { | 243 | { |
217 | if (argc < 4) { | 244 | if (argc < 4) { |
218 | printf("[!] Usage: %s [IP] [port] [public_key]\n", argv[0]); | 245 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); |
219 | exit(0); | 246 | exit(0); |
220 | } | 247 | } |
221 | int c; | 248 | int c; |
222 | int on = 0; | 249 | int on = 0; |
223 | initMessenger(); | 250 | initMessenger(); |
224 | FILE *data_file = NULL; | ||
225 | //if keyfiles exist | 251 | //if keyfiles exist |
226 | if ((data_file = fopen("data","r"))) { | 252 | if(argc > 4){ |
227 | //load keys | 253 | if(strncmp(argv[4], "nokey", 6) < 0){ |
228 | fseek(data_file, 0, SEEK_END); | 254 | load_key(); |
229 | int size = ftell(data_file); | ||
230 | fseek(data_file, 0, SEEK_SET); | ||
231 | uint8_t data[size]; | ||
232 | if(fread(data, sizeof(uint8_t), size, data_file) != size) | ||
233 | { | ||
234 | printf("Error reading file\n"); | ||
235 | exit(0); | ||
236 | } | ||
237 | Messenger_load(data, size); | ||
238 | } else { | ||
239 | //else save new keys | ||
240 | int size = Messenger_size(); | ||
241 | uint8_t data[size]; | ||
242 | Messenger_save(data); | ||
243 | data_file = fopen("data","w"); | ||
244 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size) | ||
245 | { | ||
246 | printf("Error writing file\n"); | ||
247 | exit(0); | ||
248 | } | 255 | } |
256 | } else { | ||
257 | load_key(); | ||
249 | } | 258 | } |
250 | fclose(data_file); | ||
251 | m_callback_friendrequest(print_request); | 259 | m_callback_friendrequest(print_request); |
252 | m_callback_friendmessage(print_message); | 260 | m_callback_friendmessage(print_message); |
253 | m_callback_namechange(print_nickchange); | 261 | m_callback_namechange(print_nickchange); |