diff options
Diffstat (limited to 'testing/nTox_win32.c')
-rw-r--r-- | testing/nTox_win32.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index d2642df1..7739c0a6 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -39,6 +39,8 @@ char line[STRING_LENGTH]; | |||
39 | char users_id[200]; | 39 | char users_id[200]; |
40 | int friend_request_received; | 40 | int friend_request_received; |
41 | 41 | ||
42 | Messenger *messenger; | ||
43 | |||
42 | void do_header() | 44 | void do_header() |
43 | { | 45 | { |
44 | system("cls"); | 46 | system("cls"); |
@@ -48,7 +50,7 @@ void do_header() | |||
48 | printf("\n---------------------------------"); | 50 | printf("\n---------------------------------"); |
49 | } | 51 | } |
50 | 52 | ||
51 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | 53 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) |
52 | { | 54 | { |
53 | friend_request_received = 1; | 55 | friend_request_received = 1; |
54 | printf("\n\n[i] received friend request with message\n"); | 56 | printf("\n\n[i] received friend request with message\n"); |
@@ -61,10 +63,10 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
61 | ++num_requests; | 63 | ++num_requests; |
62 | } | 64 | } |
63 | 65 | ||
64 | void print_message(int friendnumber, uint8_t * string, uint16_t length) | 66 | void print_message(Messenger *messenger, int friendnumber, uint8_t * string, uint16_t length, void *userdata) |
65 | { | 67 | { |
66 | char name[MAX_NAME_LENGTH]; | 68 | char name[MAX_NAME_LENGTH]; |
67 | getname(friendnumber, (uint8_t*)name); | 69 | getname(messenger, friendnumber, (uint8_t*)name); |
68 | char msg[100+length+strlen(name)+1]; | 70 | char msg[100+length+strlen(name)+1]; |
69 | time_t rawtime; | 71 | time_t rawtime; |
70 | struct tm * timeinfo; | 72 | struct tm * timeinfo; |
@@ -77,19 +79,19 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
77 | printf(msg); | 79 | printf(msg); |
78 | } | 80 | } |
79 | 81 | ||
80 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | 82 | void print_nickchange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata) |
81 | { | 83 | { |
82 | char name[MAX_NAME_LENGTH]; | 84 | char name[MAX_NAME_LENGTH]; |
83 | getname(friendnumber, (uint8_t*)name); | 85 | getname(messenger, friendnumber, (uint8_t*)name); |
84 | char msg[100+length]; | 86 | char msg[100+length]; |
85 | sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); | 87 | sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); |
86 | printf(msg); | 88 | printf(msg); |
87 | } | 89 | } |
88 | 90 | ||
89 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | 91 | void print_statuschange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata) |
90 | { | 92 | { |
91 | char name[MAX_NAME_LENGTH]; | 93 | char name[MAX_NAME_LENGTH]; |
92 | getname(friendnumber, (uint8_t*)name); | 94 | getname(messenger, friendnumber, (uint8_t*)name); |
93 | char msg[100+length+strlen(name)+1]; | 95 | char msg[100+length+strlen(name)+1]; |
94 | sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string); | 96 | sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string); |
95 | printf(msg); | 97 | printf(msg); |
@@ -109,11 +111,11 @@ void load_key() | |||
109 | exit(1); | 111 | exit(1); |
110 | } | 112 | } |
111 | 113 | ||
112 | Messenger_load(data, size); | 114 | Messenger_load(messenger, data, size); |
113 | } else { | 115 | } else { |
114 | int size = Messenger_size(); | 116 | int size = Messenger_size(messenger); |
115 | uint8_t data[size]; | 117 | uint8_t data[size]; |
116 | Messenger_save(data); | 118 | Messenger_save(messenger, data); |
117 | fclose(data_file); | 119 | fclose(data_file); |
118 | data_file = fopen("data", "w"); | 120 | data_file = fopen("data", "w"); |
119 | 121 | ||
@@ -133,7 +135,7 @@ void add_friend() | |||
133 | for (i = 0; i < 128; i++) | 135 | for (i = 0; i < 128; i++) |
134 | temp_id[i] = line[i+3]; | 136 | temp_id[i] = line[i+3]; |
135 | 137 | ||
136 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 138 | int num = m_addfriend(messenger, hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
137 | 139 | ||
138 | if (num >= 0) { | 140 | if (num >= 0) { |
139 | char numstring[100]; | 141 | char numstring[100]; |
@@ -167,8 +169,8 @@ void list_friends() | |||
167 | 169 | ||
168 | for (i = 0; i <= maxnumfriends; i++) { | 170 | for (i = 0; i <= maxnumfriends; i++) { |
169 | char name[MAX_NAME_LENGTH]; | 171 | char name[MAX_NAME_LENGTH]; |
170 | getname(i, (uint8_t*)name); | 172 | getname(messenger, i, (uint8_t*)name); |
171 | if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4) | 173 | if (m_friendstatus(messenger, i) > 0 && m_friendstatus(messenger, i) < 4) |
172 | printf("[%d] %s\n", i, (uint8_t*)name); | 174 | printf("[%d] %s\n", i, (uint8_t*)name); |
173 | } | 175 | } |
174 | 176 | ||
@@ -178,9 +180,9 @@ void list_friends() | |||
178 | 180 | ||
179 | for (i = 0; i <= maxnumfriends; i++) { | 181 | for (i = 0; i <= maxnumfriends; i++) { |
180 | char name[MAX_NAME_LENGTH]; | 182 | char name[MAX_NAME_LENGTH]; |
181 | getname(i, (uint8_t*)name); | 183 | getname(messenger, i, (uint8_t*)name); |
182 | 184 | ||
183 | if (m_friendstatus(i) == 4) | 185 | if (m_friendstatus(messenger, i) == 4) |
184 | printf("[%d] %s\n", i, (uint8_t*)name); | 186 | printf("[%d] %s\n", i, (uint8_t*)name); |
185 | } | 187 | } |
186 | 188 | ||
@@ -199,7 +201,7 @@ void delete_friend() | |||
199 | } | 201 | } |
200 | 202 | ||
201 | int num = atoi(numstring); | 203 | int num = atoi(numstring); |
202 | m_delfriend(num); | 204 | m_delfriend(messenger, num); |
203 | --maxnumfriends; | 205 | --maxnumfriends; |
204 | printf("\n\n"); | 206 | printf("\n\n"); |
205 | } | 207 | } |
@@ -228,7 +230,7 @@ void message_friend() | |||
228 | 230 | ||
229 | int num = atoi(numstring); | 231 | int num = atoi(numstring); |
230 | 232 | ||
231 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) | 233 | if(m_sendmessage(messenger, num, (uint8_t*) message, sizeof(message)) != 1) |
232 | printf("\n[i] could not send message (they may be offline): %s\n", message); | 234 | printf("\n[i] could not send message (they may be offline): %s\n", message); |
233 | 235 | ||
234 | else | 236 | else |
@@ -250,7 +252,7 @@ void change_nickname() | |||
250 | } | 252 | } |
251 | 253 | ||
252 | name[i-3] = 0; | 254 | name[i-3] = 0; |
253 | setname(name, i); | 255 | setname(messenger, name, i); |
254 | char numstring[100]; | 256 | char numstring[100]; |
255 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | 257 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); |
256 | printf(numstring); | 258 | printf(numstring); |
@@ -275,7 +277,7 @@ void change_status(int savetofile) | |||
275 | } | 277 | } |
276 | 278 | ||
277 | status[i-3] = 0; | 279 | status[i-3] = 0; |
278 | m_set_statusmessage(status, strlen((char*)status)); | 280 | m_set_statusmessage(messenger, status, strlen((char*)status)); |
279 | char numstring[100]; | 281 | char numstring[100]; |
280 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 282 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
281 | printf(numstring); | 283 | printf(numstring); |
@@ -297,7 +299,7 @@ void accept_friend_request() | |||
297 | sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it"); | 299 | sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it"); |
298 | printf(numchar); | 300 | printf(numchar); |
299 | } else { | 301 | } else { |
300 | int num = m_addfriend_norequest(pending_requests[numf].id); | 302 | int num = m_addfriend_norequest(messenger, pending_requests[numf].id); |
301 | if (num != -1) { | 303 | if (num != -1) { |
302 | pending_requests[numf].accepted = 1; | 304 | pending_requests[numf].accepted = 1; |
303 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); | 305 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); |
@@ -347,7 +349,7 @@ void line_eval(char* line) | |||
347 | 349 | ||
348 | else if (inpt_command == 'a') { | 350 | else if (inpt_command == 'a') { |
349 | if (friend_request_received == 1) | 351 | if (friend_request_received == 1) |
350 | accept_friend_request(line); | 352 | accept_friend_request(); |
351 | } | 353 | } |
352 | /* EXIT */ | 354 | /* EXIT */ |
353 | else if (inpt_command == 'q') { | 355 | else if (inpt_command == 'q') { |
@@ -373,7 +375,8 @@ int main(int argc, char *argv[]) | |||
373 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); | 375 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); |
374 | exit(0); | 376 | exit(0); |
375 | } | 377 | } |
376 | if (initMessenger() == -1) { | 378 | messenger = initMessenger(); |
379 | if (messenger == 0) { | ||
377 | printf("initMessenger failed"); | 380 | printf("initMessenger failed"); |
378 | exit(0); | 381 | exit(0); |
379 | } | 382 | } |
@@ -394,7 +397,7 @@ int main(int argc, char *argv[]) | |||
394 | while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) { | 397 | while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) { |
395 | sscanf(line, "%s", (char*)name); | 398 | sscanf(line, "%s", (char*)name); |
396 | } | 399 | } |
397 | setname(name, strlen((char*)name)+1); | 400 | setname(messenger, name, strlen((char*)name)+1); |
398 | nameloaded = 1; | 401 | nameloaded = 1; |
399 | printf("%s\n", name); | 402 | printf("%s\n", name); |
400 | fclose(name_file); | 403 | fclose(name_file); |
@@ -407,16 +410,16 @@ int main(int argc, char *argv[]) | |||
407 | while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) { | 410 | while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) { |
408 | sscanf(line, "%s", (char*)status); | 411 | sscanf(line, "%s", (char*)status); |
409 | } | 412 | } |
410 | m_set_statusmessage(status, strlen((char*)status)+1); | 413 | m_set_statusmessage(messenger, status, strlen((char*)status)+1); |
411 | statusloaded = 1; | 414 | statusloaded = 1; |
412 | printf("%s\n", status); | 415 | printf("%s\n", status); |
413 | fclose(status_file); | 416 | fclose(status_file); |
414 | } | 417 | } |
415 | 418 | ||
416 | m_callback_friendrequest(print_request); | 419 | m_callback_friendrequest(messenger, print_request, &status_file); |
417 | m_callback_friendmessage(print_message); | 420 | m_callback_friendmessage(messenger, print_message, &status_file); |
418 | m_callback_namechange(print_nickchange); | 421 | m_callback_namechange(messenger, print_nickchange, &status_file); |
419 | m_callback_statusmessage(print_statuschange); | 422 | m_callback_statusmessage(messenger, print_statuschange, &status_file); |
420 | char idstring1[PUB_KEY_BYTES][5]; | 423 | char idstring1[PUB_KEY_BYTES][5]; |
421 | char idstring2[PUB_KEY_BYTES][5]; | 424 | char idstring2[PUB_KEY_BYTES][5]; |
422 | int i; | 425 | int i; |
@@ -474,7 +477,7 @@ int main(int argc, char *argv[]) | |||
474 | printf("\n---------------------------------\n\n"); | 477 | printf("\n---------------------------------\n\n"); |
475 | on = 1; | 478 | on = 1; |
476 | } | 479 | } |
477 | doMessenger(); | 480 | doMessenger(messenger); |
478 | Sleep(1); | 481 | Sleep(1); |
479 | } | 482 | } |
480 | return 0; | 483 | return 0; |