summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xauto_tests/friends_test.c16
-rw-r--r--core/Messenger.c40
-rw-r--r--core/Messenger.h40
-rw-r--r--core/friend_requests.c9
-rw-r--r--core/friend_requests.h2
-rw-r--r--testing/Messenger_test.c8
-rw-r--r--testing/nTox.c16
-rw-r--r--testing/toxic/main.c20
8 files changed, 84 insertions, 67 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c
index 317714d6..3c15b35b 100755
--- a/auto_tests/friends_test.c
+++ b/auto_tests/friends_test.c
@@ -65,13 +65,13 @@ void do_tox(void)
65 doMessenger(m); 65 doMessenger(m);
66} 66}
67 67
68void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length) 68void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata)
69{ 69{
70 puts("OK"); 70 puts("OK");
71 request_flags |= SECOND_FLAG; 71 request_flags |= SECOND_FLAG;
72} 72}
73 73
74void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length) 74void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata)
75{ 75{
76 puts("OK"); 76 puts("OK");
77 request_flags |= FIRST_FLAG; 77 request_flags |= FIRST_FLAG;
@@ -108,7 +108,7 @@ int parent_friend_request(void)
108 return 0; 108 return 0;
109} 109}
110 110
111void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length) 111void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata)
112{ 112{
113 fputs("OK\nsending status to parent", stdout); 113 fputs("OK\nsending status to parent", stdout);
114 fflush(stdout); 114 fflush(stdout);
@@ -116,7 +116,7 @@ void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length)
116 request_flags |= FIRST_FLAG; 116 request_flags |= FIRST_FLAG;
117} 117}
118 118
119void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length) 119void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void* userdata)
120{ 120{
121 request_flags |= SECOND_FLAG; 121 request_flags |= SECOND_FLAG;
122} 122}
@@ -175,8 +175,8 @@ int main(int argc, char *argv[])
175 Messenger_save(m, child_id); 175 Messenger_save(m, child_id);
176 msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); 176 msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
177 177
178 m_callback_friendrequest(m, child_got_request); 178 m_callback_friendrequest(m, child_got_request, NULL);
179 m_callback_statusmessage(m, child_got_statuschange); 179 m_callback_statusmessage(m, child_got_statuschange, NULL);
180 180
181 /* wait on the friend request */ 181 /* wait on the friend request */
182 while(!(request_flags & FIRST_FLAG)) 182 while(!(request_flags & FIRST_FLAG))
@@ -207,8 +207,8 @@ int main(int argc, char *argv[])
207 m = initMessenger(); 207 m = initMessenger();
208 208
209 msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); 209 msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
210 m_callback_statusmessage(m, parent_confirm_status); 210 m_callback_statusmessage(m, parent_confirm_status, NULL);
211 m_callback_friendmessage(m, parent_confirm_message); 211 m_callback_friendmessage(m, parent_confirm_message, NULL);
212 212
213 /* hacky way to give the child time to set up */ 213 /* hacky way to give the child time to set up */
214 c_sleep(50); 214 c_sleep(50);
diff --git a/core/Messenger.c b/core/Messenger.c
index a6189941..ebde5a78 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -395,52 +395,59 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno)
395/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); 395/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t);
396static uint8_t friend_request_isset = 0; */ 396static uint8_t friend_request_isset = 0; */
397/* set the function that will be executed when a friend request is received. */ 397/* set the function that will be executed when a friend request is received. */
398void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t)) 398void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata)
399{ 399{
400 callback_friendrequest(function); 400 callback_friendrequest(function, userdata);
401} 401}
402 402
403/* set the function that will be executed when a message from a friend is received. */ 403/* set the function that will be executed when a message from a friend is received. */
404void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) 404void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata)
405{ 405{
406 m->friend_message = function; 406 m->friend_message = function;
407 m->friend_message_isset = 1; 407 m->friend_message_isset = 1;
408 m->friend_message_userdata = userdata;
408} 409}
409 410
410void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) 411void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata)
411{ 412{
412 m->friend_action = function; 413 m->friend_action = function;
413 m->friend_action_isset = 1; 414 m->friend_action_isset = 1;
415 m->friend_action_userdata = userdata;
414} 416}
415 417
416void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) 418void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata)
417{ 419{
418 m->friend_namechange = function; 420 m->friend_namechange = function;
419 m->friend_namechange_isset = 1; 421 m->friend_namechange_isset = 1;
422 m->friend_namechange_userdata = userdata;
420} 423}
421 424
422void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) 425void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata)
423{ 426{
424 m->friend_statusmessagechange = function; 427 m->friend_statusmessagechange = function;
425 m->friend_statusmessagechange_isset = 1; 428 m->friend_statusmessagechange_isset = 1;
429 m->friend_statuschange_userdata = userdata;
426} 430}
427 431
428void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS)) 432void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void*), void* userdata)
429{ 433{
430 m->friend_userstatuschange = function; 434 m->friend_userstatuschange = function;
431 m->friend_userstatuschange_isset = 1; 435 m->friend_userstatuschange_isset = 1;
436 m->friend_userstatuschange_userdata = userdata;
432} 437}
433 438
434void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t)) 439void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void*), void* userdata)
435{ 440{
436 m->read_receipt = function; 441 m->read_receipt = function;
437 m->read_receipt_isset = 1; 442 m->read_receipt_isset = 1;
443 m->read_receipt_userdata = userdata;
438} 444}
439 445
440void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t)) 446void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void*), void* userdata)
441{ 447{
442 m->friend_connectionstatuschange = function; 448 m->friend_connectionstatuschange = function;
443 m->friend_connectionstatuschange_isset = 1; 449 m->friend_connectionstatuschange_isset = 1;
450 m->friend_connectionstatuschange_userdata = userdata;
444} 451}
445 452
446static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status) 453static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status)
@@ -452,7 +459,7 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
452 const uint8_t was_connected = m->friendlist[friendnumber].status == FRIEND_ONLINE; 459 const uint8_t was_connected = m->friendlist[friendnumber].status == FRIEND_ONLINE;
453 const uint8_t is_connected = status == FRIEND_ONLINE; 460 const uint8_t is_connected = status == FRIEND_ONLINE;
454 if (is_connected != was_connected) 461 if (is_connected != was_connected)
455 m->friend_connectionstatuschange(m, friendnumber, is_connected); 462 m->friend_connectionstatuschange(m, friendnumber, is_connected, m->friend_connectionstatuschange_userdata);
456} 463}
457 464
458void set_friend_status(Messenger *m, int friendnumber, uint8_t status) 465void set_friend_status(Messenger *m, int friendnumber, uint8_t status)
@@ -569,7 +576,7 @@ void doFriends(Messenger *m)
569 if (data_length >= MAX_NAME_LENGTH || data_length == 0) 576 if (data_length >= MAX_NAME_LENGTH || data_length == 0)
570 break; 577 break;
571 if(m->friend_namechange_isset) 578 if(m->friend_namechange_isset)
572 m->friend_namechange(m, i, data, data_length); 579 m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata);
573 memcpy(m->friendlist[i].name, data, data_length); 580 memcpy(m->friendlist[i].name, data, data_length);
574 m->friendlist[i].name[data_length - 1] = 0; /* make sure the NULL terminator is present. */ 581 m->friendlist[i].name[data_length - 1] = 0; /* make sure the NULL terminator is present. */
575 break; 582 break;
@@ -580,7 +587,8 @@ void doFriends(Messenger *m)
580 uint8_t *status = calloc(MIN(data_length, MAX_STATUSMESSAGE_LENGTH), 1); 587 uint8_t *status = calloc(MIN(data_length, MAX_STATUSMESSAGE_LENGTH), 1);
581 memcpy(status, data, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); 588 memcpy(status, data, MIN(data_length, MAX_STATUSMESSAGE_LENGTH));
582 if (m->friend_statusmessagechange_isset) 589 if (m->friend_statusmessagechange_isset)
583 m->friend_statusmessagechange(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); 590 m->friend_statusmessagechange(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH),
591 m->friend_statuschange_userdata);
584 set_friend_statusmessage(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); 592 set_friend_statusmessage(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH));
585 free(status); 593 free(status);
586 break; 594 break;
@@ -590,7 +598,7 @@ void doFriends(Messenger *m)
590 break; 598 break;
591 USERSTATUS status = data[0]; 599 USERSTATUS status = data[0];
592 if (m->friend_userstatuschange_isset) 600 if (m->friend_userstatuschange_isset)
593 m->friend_userstatuschange(m, i, status); 601 m->friend_userstatuschange(m, i, status, m->friend_userstatuschange_userdata);
594 set_friend_userstatus(m, i, status); 602 set_friend_userstatus(m, i, status);
595 break; 603 break;
596 } 604 }
@@ -603,12 +611,12 @@ void doFriends(Messenger *m)
603 write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); 611 write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
604 } 612 }
605 if (m->friend_message_isset) 613 if (m->friend_message_isset)
606 (*m->friend_message)(m, i, message, message_length); 614 (*m->friend_message)(m, i, message, message_length, m->friend_message_userdata);
607 break; 615 break;
608 } 616 }
609 case PACKET_ID_ACTION: { 617 case PACKET_ID_ACTION: {
610 if (m->friend_action_isset) 618 if (m->friend_action_isset)
611 (*m->friend_action)(m, i, data, data_length); 619 (*m->friend_action)(m, i, data, data_length, m->friend_action_userdata);
612 break; 620 break;
613 } 621 }
614 case PACKET_ID_RECEIPT: { 622 case PACKET_ID_RECEIPT: {
@@ -618,7 +626,7 @@ void doFriends(Messenger *m)
618 memcpy(&msgid, data, sizeof(msgid)); 626 memcpy(&msgid, data, sizeof(msgid));
619 msgid = ntohl(msgid); 627 msgid = ntohl(msgid);
620 if (m->read_receipt_isset) 628 if (m->read_receipt_isset)
621 (*m->read_receipt)(m, i, msgid); 629 (*m->read_receipt)(m, i, msgid, m->read_receipt_userdata);
622 break; 630 break;
623 } 631 }
624 } 632 }
diff --git a/core/Messenger.h b/core/Messenger.h
index 36e24596..fa69d104 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -105,22 +105,30 @@ typedef struct Messenger {
105 Friend *friendlist; 105 Friend *friendlist;
106 uint32_t numfriends; 106 uint32_t numfriends;
107 107
108 void (*friend_message)(struct Messenger *m, int, uint8_t *, uint16_t); 108 void (*friend_message)(struct Messenger *m, int, uint8_t *, uint16_t, void*);
109 uint8_t friend_message_isset; 109 uint8_t friend_message_isset;
110 void (*friend_action)(struct Messenger *m, int, uint8_t *, uint16_t); 110 void* friend_message_userdata;
111 void (*friend_action)(struct Messenger *m, int, uint8_t *, uint16_t, void*);
111 uint8_t friend_action_isset; 112 uint8_t friend_action_isset;
112 void (*friend_namechange)(struct Messenger *m, int, uint8_t *, uint16_t); 113 void* friend_action_userdata;
114 void (*friend_namechange)(struct Messenger *m, int, uint8_t *, uint16_t, void*);
113 uint8_t friend_namechange_isset; 115 uint8_t friend_namechange_isset;
114 void (*friend_statusmessagechange)(struct Messenger *m, int, uint8_t *, uint16_t); 116 void* friend_namechange_userdata;
117 void (*friend_statusmessagechange)(struct Messenger *m, int, uint8_t *, uint16_t, void*);
115 uint8_t friend_statusmessagechange_isset; 118 uint8_t friend_statusmessagechange_isset;
116 void (*friend_userstatuschange)(struct Messenger *m, int, USERSTATUS); 119 void* friend_statusmessagechange_userdata;
120 void (*friend_userstatuschange)(struct Messenger *m, int, USERSTATUS, void*);
117 uint8_t friend_userstatuschange_isset; 121 uint8_t friend_userstatuschange_isset;
118 void (*read_receipt)(struct Messenger *m, int, uint32_t); 122 void* friend_userstatuschange_userdata;
123 void (*read_receipt)(struct Messenger *m, int, uint32_t, void*);
119 uint8_t read_receipt_isset; 124 uint8_t read_receipt_isset;
120 void (*friend_statuschange)(struct Messenger *m, int, uint8_t); 125 void* read_receipt_userdata;
126 void (*friend_statuschange)(struct Messenger *m, int, uint8_t, void*);
121 uint8_t friend_statuschange_isset; 127 uint8_t friend_statuschange_isset;
122 void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t); 128 void* friend_statuschange_userdata;
129 void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void*);
123 uint8_t friend_connectionstatuschange_isset; 130 uint8_t friend_connectionstatuschange_isset;
131 void* friend_connectionstatuschange_userdata;
124 132
125 133
126} Messenger; 134} Messenger;
@@ -230,29 +238,29 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno);
230 238
231/* set the function that will be executed when a friend request is received. 239/* set the function that will be executed when a friend request is received.
232 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */ 240 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */
233void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t)); 241void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata);
234 242
235/* set the function that will be executed when a message from a friend is received. 243/* set the function that will be executed when a message from a friend is received.
236 function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ 244 function format is: function(int friendnumber, uint8_t * message, uint32_t length) */
237void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)); 245void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata);
238 246
239/* set the function that will be executed when an action from a friend is received. 247/* set the function that will be executed when an action from a friend is received.
240 function format is: function(int friendnumber, uint8_t * action, uint32_t length) */ 248 function format is: function(int friendnumber, uint8_t * action, uint32_t length) */
241void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)); 249void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata);
242 250
243/* set the callback for name changes 251/* set the callback for name changes
244 function(int friendnumber, uint8_t *newname, uint16_t length) 252 function(int friendnumber, uint8_t *newname, uint16_t length)
245 you are not responsible for freeing newname */ 253 you are not responsible for freeing newname */
246void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)); 254void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata);
247 255
248/* set the callback for status message changes 256/* set the callback for status message changes
249 function(int friendnumber, uint8_t *newstatus, uint16_t length) 257 function(int friendnumber, uint8_t *newstatus, uint16_t length)
250 you are not responsible for freeing newstatus */ 258 you are not responsible for freeing newstatus */
251void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)); 259void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata);
252 260
253/* set the callback for status type changes 261/* set the callback for status type changes
254 function(int friendnumber, USERSTATUS kind) */ 262 function(int friendnumber, USERSTATUS kind) */
255void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS)); 263void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void*), void* userdata);
256 264
257/* set the callback for read receipts 265/* set the callback for read receipts
258 function(int friendnumber, uint32_t receipt) 266 function(int friendnumber, uint32_t receipt)
@@ -261,7 +269,7 @@ void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USE
261 has been received on the other side. since core doesn't 269 has been received on the other side. since core doesn't
262 track ids for you, receipt may not correspond to any message 270 track ids for you, receipt may not correspond to any message
263 in that case, you should discard it. */ 271 in that case, you should discard it. */
264void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t)); 272void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void*), void* userdata);
265 273
266/* set the callback for connection status changes 274/* set the callback for connection status changes
267 function(int friendnumber, uint8_t status) 275 function(int friendnumber, uint8_t status)
@@ -271,7 +279,7 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, u
271 note that this callback is not called when adding friends, thus the "after 279 note that this callback is not called when adding friends, thus the "after
272 being previously online" part. it's assumed that when adding friends, 280 being previously online" part. it's assumed that when adding friends,
273 their connection status is offline. */ 281 their connection status is offline. */
274void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t)); 282void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void*), void* userdata);
275 283
276/* run this at startup 284/* run this at startup
277 * returns allocated instance of Messenger on success 285 * returns allocated instance of Messenger on success
diff --git a/core/friend_requests.c b/core/friend_requests.c
index 422cc028..5e9b447c 100644
--- a/core/friend_requests.c
+++ b/core/friend_requests.c
@@ -57,14 +57,15 @@ int send_friendrequest(uint8_t * public_key, uint8_t * data, uint32_t length)
57 return num; 57 return num;
58} 58}
59 59
60static void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t); 60static void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t, void*);
61static uint8_t handle_friendrequest_isset = 0; 61static uint8_t handle_friendrequest_isset = 0;
62 62static void* handle_friendrequest_userdata;
63/* set the function that will be executed when a friend request is received. */ 63/* set the function that will be executed when a friend request is received. */
64void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)) 64void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata)
65{ 65{
66 handle_friendrequest = function; 66 handle_friendrequest = function;
67 handle_friendrequest_isset = 1; 67 handle_friendrequest_isset = 1;
68 handle_friendrequest_userdata = userdata;
68} 69}
69 70
70 71
@@ -121,7 +122,7 @@ static int friendreq_handlepacket(IP_Port source, uint8_t * packet, uint32_t len
121 return 1; 122 return 1;
122 123
123 addto_receivedlist(public_key); 124 addto_receivedlist(public_key);
124 (*handle_friendrequest)(public_key, data, len); 125 (*handle_friendrequest)(public_key, data, len, handle_friendrequest_userdata);
125 } else { /* if request is not for us, try routing it. */ 126 } else { /* if request is not for us, try routing it. */
126 if(route_packet(packet + 1, packet, length) == length) 127 if(route_packet(packet + 1, packet, length) == length)
127 return 0; 128 return 0;
diff --git a/core/friend_requests.h b/core/friend_requests.h
index 708d8f66..f18107ce 100644
--- a/core/friend_requests.h
+++ b/core/friend_requests.h
@@ -37,7 +37,7 @@ int send_friendrequest(uint8_t *public_key, uint8_t *data, uint32_t length);
37 37
38/* set the function that will be executed when a friend request for us is received. 38/* set the function that will be executed when a friend request for us is received.
39 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */ 39 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */
40void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)); 40void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata);
41 41
42/* sets up friendreq packet handlers */ 42/* sets up friendreq packet handlers */
43void friendreq_init(void); 43void friendreq_init(void);
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 51542c6d..fa5d6890 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -55,7 +55,7 @@
55 * networking_requesthandler and so cannot take a Messenger * */ 55 * networking_requesthandler and so cannot take a Messenger * */
56static Messenger *m; 56static Messenger *m;
57 57
58void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) 58void print_request(uint8_t * public_key, uint8_t * data, uint16_t length, void* userdata)
59{ 59{
60 printf("Friend request received from: \n"); 60 printf("Friend request received from: \n");
61 printf("ClientID: "); 61 printf("ClientID: ");
@@ -80,7 +80,7 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
80 } 80 }
81} 81}
82 82
83void print_message(Messenger *m, int friendnumber, uint8_t * string, uint16_t length) 83void print_message(Messenger *m, int friendnumber, uint8_t * string, uint16_t length, void* userdata)
84{ 84{
85 printf("Message with length %u received from %u: %s \n", length, friendnumber, string); 85 printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
86 m_sendmessage(m, friendnumber, (uint8_t*)"Test1", 6); 86 m_sendmessage(m, friendnumber, (uint8_t*)"Test1", 6);
@@ -114,8 +114,8 @@ int main(int argc, char *argv[])
114 fclose(file); 114 fclose(file);
115 115
116 } 116 }
117 m_callback_friendrequest(m, print_request); 117 m_callback_friendrequest(m, print_request, NULL);
118 m_callback_friendmessage(m, print_message); 118 m_callback_friendmessage(m, print_message, NULL);
119 119
120 printf("OUR ID: "); 120 printf("OUR ID: ");
121 uint32_t i; 121 uint32_t i;
diff --git a/testing/nTox.c b/testing/nTox.c
index 1322067e..59d1cbf6 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -336,7 +336,7 @@ void do_refresh()
336 refresh(); 336 refresh();
337} 337}
338 338
339void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) 339void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata)
340{ 340{
341 new_lines("[i] received friend request with message:"); 341 new_lines("[i] received friend request with message:");
342 new_lines((char *)data); 342 new_lines((char *)data);
@@ -349,12 +349,12 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
349 do_refresh(); 349 do_refresh();
350} 350}
351 351
352void print_message(Messenger *m, int friendnumber, uint8_t * string, uint16_t length) 352void print_message(Messenger *m, int friendnumber, uint8_t * string, uint16_t length, void* userdata)
353{ 353{
354 new_lines(format_message(m, (char*)string, friendnumber)); 354 new_lines(format_message(m, (char*)string, friendnumber));
355} 355}
356 356
357void print_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 357void print_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
358{ 358{
359 char name[MAX_NAME_LENGTH]; 359 char name[MAX_NAME_LENGTH];
360 if(getname(m, friendnumber, (uint8_t*)name) != -1) { 360 if(getname(m, friendnumber, (uint8_t*)name) != -1) {
@@ -364,7 +364,7 @@ void print_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t
364 } 364 }
365} 365}
366 366
367void print_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 367void print_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
368{ 368{
369 char name[MAX_NAME_LENGTH]; 369 char name[MAX_NAME_LENGTH];
370 if(getname(m, friendnumber, (uint8_t*)name) != -1) { 370 if(getname(m, friendnumber, (uint8_t*)name) != -1) {
@@ -467,10 +467,10 @@ int main(int argc, char *argv[])
467 467
468 load_key(m, filename); 468 load_key(m, filename);
469 469
470 m_callback_friendrequest(m, print_request); 470 m_callback_friendrequest(m, print_request, NULL);
471 m_callback_friendmessage(m, print_message); 471 m_callback_friendmessage(m, print_message, NULL);
472 m_callback_namechange(m, print_nickchange); 472 m_callback_namechange(m, print_nickchange, NULL);
473 m_callback_statusmessage(m, print_statuschange); 473 m_callback_statusmessage(m, print_statuschange, NULL);
474 474
475 initscr(); 475 initscr();
476 noecho(); 476 noecho();
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index b6eadf2e..397f9391 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -46,7 +46,7 @@ int w_num;
46int active_window; 46int active_window;
47 47
48/* CALLBACKS START */ 48/* CALLBACKS START */
49void on_request(uint8_t *public_key, uint8_t *data, uint16_t length) 49void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata)
50{ 50{
51 int n = add_req(public_key); 51 int n = add_req(public_key);
52 wprintw(prompt->window, "\nFriend request from:\n"); 52 wprintw(prompt->window, "\nFriend request from:\n");
@@ -65,7 +65,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length)
65 } 65 }
66} 66}
67 67
68void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 68void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
69{ 69{
70 int i; 70 int i;
71 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { 71 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) {
@@ -74,7 +74,7 @@ void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length
74 } 74 }
75} 75}
76 76
77void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 77void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
78{ 78{
79 int i; 79 int i;
80 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { 80 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) {
@@ -83,7 +83,7 @@ void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length)
83 } 83 }
84} 84}
85 85
86void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 86void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
87{ 87{
88 wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); 88 wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string);
89 int i; 89 int i;
@@ -93,7 +93,7 @@ void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t len
93 } 93 }
94} 94}
95 95
96void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) 96void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata)
97{ 97{
98 wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); 98 wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string);
99 int i; 99 int i;
@@ -134,11 +134,11 @@ static void init_tox()
134 m = initMessenger(); 134 m = initMessenger();
135 135
136 /* Callbacks */ 136 /* Callbacks */
137 m_callback_friendrequest(m, on_request); 137 m_callback_friendrequest(m, on_request, NULL);
138 m_callback_friendmessage(m, on_message); 138 m_callback_friendmessage(m, on_message, NULL);
139 m_callback_namechange(m, on_nickchange); 139 m_callback_namechange(m, on_nickchange, NULL);
140 m_callback_statusmessage(m, on_statuschange); 140 m_callback_statusmessage(m, on_statuschange, NULL);
141 m_callback_action(m, on_action); 141 m_callback_action(m, on_action, NULL);
142} 142}
143 143
144#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ 144#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */