summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-03-16 13:24:39 -0400
committerirungentoo <irungentoo@gmail.com>2014-03-16 13:24:39 -0400
commit5babb281c05a48c0b4bbfe3c6be1527f439beec2 (patch)
treea38000591bc2e938a8dcd7783593bd614b31f14c
parent95c8e9c2fb6c01a872871366e11aef18d49dc967 (diff)
Friend request callback now contains the Tox object.
-rw-r--r--auto_tests/friends_test.c2
-rw-r--r--auto_tests/tox_test.c15
-rw-r--r--testing/Messenger_test.c2
-rw-r--r--testing/nTox.c2
-rw-r--r--toxav/phone.c2
-rw-r--r--toxcore/Messenger.c6
-rw-r--r--toxcore/Messenger.h3
-rw-r--r--toxcore/friend_requests.c8
-rw-r--r--toxcore/friend_requests.h7
-rw-r--r--toxcore/network.c2
-rw-r--r--toxcore/tox.c3
-rw-r--r--toxcore/tox.h8
12 files changed, 35 insertions, 25 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c
index 5071319e..2448f97c 100644
--- a/auto_tests/friends_test.c
+++ b/auto_tests/friends_test.c
@@ -116,7 +116,7 @@ int parent_friend_request(DHT *dht)
116 return 0; 116 return 0;
117} 117}
118 118
119void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) 119void child_got_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
120{ 120{
121 fputs("OK\nsending status to parent", stdout); 121 fputs("OK\nsending status to parent", stdout);
122 fflush(stdout); 122 fflush(stdout);
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 7e74fba7..e8c10b7e 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -19,12 +19,13 @@
19#define c_sleep(x) usleep(1000*x) 19#define c_sleep(x) usleep(1000*x)
20#endif 20#endif
21 21
22void accept_friend_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) 22void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
23{ 23{
24 Tox *t = userdata; 24 if (*((uint32_t *)userdata) != 974536)
25 return;
25 26
26 if (length == 7 && memcmp("Gentoo", data, 7) == 0) { 27 if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
27 tox_add_friend_norequest(t, public_key); 28 tox_add_friend_norequest(m, public_key);
28 } 29 }
29} 30}
30uint32_t messages_received; 31uint32_t messages_received;
@@ -114,7 +115,8 @@ START_TEST(test_few_clients)
114 Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT); 115 Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
115 Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT); 116 Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
116 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); 117 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
117 tox_callback_friend_request(tox2, accept_friend_request, tox2); 118 uint32_t to_compare = 974536;
119 tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
118 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 120 uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
119 tox_get_address(tox2, address); 121 tox_get_address(tox2, address);
120 int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7); 122 int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7);
@@ -140,7 +142,7 @@ START_TEST(test_few_clients)
140 } 142 }
141 143
142 printf("tox clients connected\n"); 144 printf("tox clients connected\n");
143 uint32_t to_compare = 974536; 145 to_compare = 974536;
144 tox_callback_friend_message(tox3, print_message, &to_compare); 146 tox_callback_friend_message(tox3, print_message, &to_compare);
145 tox_send_message(tox2, 0, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); 147 tox_send_message(tox2, 0, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
146 148
@@ -267,7 +269,8 @@ START_TEST(test_many_clients)
267 for (i = 0; i < NUM_TOXES; ++i) { 269 for (i = 0; i < NUM_TOXES; ++i) {
268 toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT); 270 toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
269 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 271 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
270 tox_callback_friend_request(toxes[i], accept_friend_request, toxes[i]); 272 uint32_t to_comp = 974536;
273 tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
271 } 274 }
272 275
273 struct { 276 struct {
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 895a23d9..b875f832 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -66,7 +66,7 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len
66 * networking_requesthandler and so cannot take a Messenger * */ 66 * networking_requesthandler and so cannot take a Messenger * */
67static Messenger *m; 67static Messenger *m;
68 68
69void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) 69void print_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
70{ 70{
71 printf("Friend request received from: \n"); 71 printf("Friend request received from: \n");
72 printf("ClientID: "); 72 printf("ClientID: ");
diff --git a/testing/nTox.c b/testing/nTox.c
index 343db236..dc9d5113 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -862,7 +862,7 @@ void do_refresh()
862 refresh(); 862 refresh();
863} 863}
864 864
865void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) 865void print_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
866{ 866{
867 new_lines("[i] received friend request with message:"); 867 new_lines("[i] received friend request with message:");
868 new_lines((char *)data); 868 new_lines((char *)data);
diff --git a/toxav/phone.c b/toxav/phone.c
index 98e97873..bceaad9f 100644
--- a/toxav/phone.c
+++ b/toxav/phone.c
@@ -1064,7 +1064,7 @@ int av_terminate_session(av_session_t *_phone)
1064/****** AV HELPER FUNCTIONS ******/ 1064/****** AV HELPER FUNCTIONS ******/
1065 1065
1066/* Auto accept friend request */ 1066/* Auto accept friend request */
1067void av_friend_requ(uint8_t *_public_key, uint8_t *_data, uint16_t _length, void *_userdata) 1067void av_friend_requ(Tox *_messenger, uint8_t *_public_key, uint8_t *_data, uint16_t _length, void *_userdata)
1068{ 1068{
1069 av_session_t *_phone = _userdata; 1069 av_session_t *_phone = _userdata;
1070 av_allocate_friend (_phone, -1, 0); 1070 av_allocate_friend (_phone, -1, 0);
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index e48fa5fc..7ce6bb3c 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -721,9 +721,11 @@ void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno)
721 721
722/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */ 722/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */
723/* Set the function that will be executed when a friend request is received. */ 723/* Set the function that will be executed when a friend request is received. */
724void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata) 724void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *),
725 void *userdata)
725{ 726{
726 callback_friendrequest(&(m->fr), function, userdata); 727 void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *) = function;
728 callback_friendrequest(&(m->fr), handle_friendrequest, m, userdata);
727} 729}
728 730
729/* Set the function that will be executed when a message from a friend is received. */ 731/* Set the function that will be executed when a message from a friend is received. */
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 32b1f1b3..9e91ccee 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -437,7 +437,8 @@ void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno);
437/* Set the function that will be executed when a friend request is received. 437/* Set the function that will be executed when a friend request is received.
438 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) 438 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
439 */ 439 */
440void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); 440void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *),
441 void *userdata);
441 442
442/* Set the function that will be executed when a message from a friend is received. 443/* Set the function that will be executed when a message from a friend is received.
443 * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length) 444 * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c
index 987b1a4a..7574a881 100644
--- a/toxcore/friend_requests.c
+++ b/toxcore/friend_requests.c
@@ -72,11 +72,12 @@ uint32_t get_nospam(Friend_Requests *fr)
72 72
73 73
74/* Set the function that will be executed when a friend request is received. */ 74/* Set the function that will be executed when a friend request is received. */
75void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), 75void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *),
76 void *userdata) 76 void *object, void *userdata)
77{ 77{
78 fr->handle_friendrequest = function; 78 fr->handle_friendrequest = function;
79 fr->handle_friendrequest_isset = 1; 79 fr->handle_friendrequest_isset = 1;
80 fr->handle_friendrequest_object = object;
80 fr->handle_friendrequest_userdata = userdata; 81 fr->handle_friendrequest_userdata = userdata;
81} 82}
82/* Set the function used to check if a friend request should be displayed to the user or not. */ 83/* Set the function used to check if a friend request should be displayed to the user or not. */
@@ -145,7 +146,8 @@ static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t
145 memcpy(message, packet + 4, length - 4); 146 memcpy(message, packet + 4, length - 4);
146 message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */ 147 message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */
147 148
148 (*fr->handle_friendrequest)(source_pubkey, message, length - 4, fr->handle_friendrequest_userdata); 149 (*fr->handle_friendrequest)(fr->handle_friendrequest_object, source_pubkey, message, length - 4,
150 fr->handle_friendrequest_userdata);
149 return 0; 151 return 0;
150} 152}
151 153
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h
index 732dc4a2..722c7431 100644
--- a/toxcore/friend_requests.h
+++ b/toxcore/friend_requests.h
@@ -30,8 +30,9 @@
30 30
31typedef struct { 31typedef struct {
32 uint32_t nospam; 32 uint32_t nospam;
33 void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t, void *); 33 void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *);
34 uint8_t handle_friendrequest_isset; 34 uint8_t handle_friendrequest_isset;
35 void *handle_friendrequest_object;
35 void *handle_friendrequest_userdata; 36 void *handle_friendrequest_userdata;
36 37
37 int (*filter_function)(uint8_t *, void *); 38 int (*filter_function)(uint8_t *, void *);
@@ -57,8 +58,8 @@ uint32_t get_nospam(Friend_Requests *fr);
57/* Set the function that will be executed when a friend request for us is received. 58/* Set the function that will be executed when a friend request for us is received.
58 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata) 59 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata)
59 */ 60 */
60void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), 61void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *),
61 void *userdata); 62 void *object, void *userdata);
62 63
63/* Set the function used to check if a friend request should be displayed to the user or not. 64/* Set the function used to check if a friend request should be displayed to the user or not.
64 * Function format is int function(uint8_t * public_key, void * userdata) 65 * Function format is int function(uint8_t * public_key, void * userdata)
diff --git a/toxcore/network.c b/toxcore/network.c
index 35b55bf1..e2e0bff4 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -435,7 +435,7 @@ int networking_wait_cleanup(Networking_Core *net, uint8_t *data)
435 if (s->send_fail_reset) { 435 if (s->send_fail_reset) {
436 net->send_fail_eagain = 0; 436 net->send_fail_eagain = 0;
437 } 437 }
438 438
439 return 1; 439 return 1;
440} 440}
441 441
diff --git a/toxcore/tox.c b/toxcore/tox.c
index aec0d902..9a5be0ad 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -353,7 +353,8 @@ uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size)
353/* Set the function that will be executed when a friend request is received. 353/* Set the function that will be executed when a friend request is received.
354 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) 354 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
355 */ 355 */
356void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata) 356void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *),
357 void *userdata)
357{ 358{
358 Messenger *m = tox; 359 Messenger *m = tox;
359 m_callback_friendrequest(m, function, userdata); 360 m_callback_friendrequest(m, function, userdata);
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 1c84c1cb..41f868dd 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -98,9 +98,9 @@ typedef struct Tox Tox;
98#endif 98#endif
99 99
100/* NOTE: Strings in Tox are all UTF-8, (This means that there is no terminating NULL character.) 100/* NOTE: Strings in Tox are all UTF-8, (This means that there is no terminating NULL character.)
101 * 101 *
102 * The exact buffer you send will be received at the other end without modification. 102 * The exact buffer you send will be received at the other end without modification.
103 * 103 *
104 * Do not treat Tox strings as C strings. 104 * Do not treat Tox strings as C strings.
105 */ 105 */
106 106
@@ -228,7 +228,6 @@ int tox_get_name_size(Tox *tox, int32_t friendnumber);
228int tox_get_self_name_size(Tox *tox); 228int tox_get_self_name_size(Tox *tox);
229 229
230/* Set our user status. 230/* Set our user status.
231 * You are responsible for freeing status after.
232 * 231 *
233 * userstatus must be one of TOX_USERSTATUS values. 232 * userstatus must be one of TOX_USERSTATUS values.
234 * 233 *
@@ -300,7 +299,8 @@ uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size);
300/* Set the function that will be executed when a friend request is received. 299/* Set the function that will be executed when a friend request is received.
301 * Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata) 300 * Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata)
302 */ 301 */
303void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); 302void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *),
303 void *userdata);
304 304
305/* Set the function that will be executed when a message from a friend is received. 305/* Set the function that will be executed when a message from a friend is received.
306 * Function format is: function(Tox *tox, int friendnumber, uint8_t * message, uint32_t length, void *userdata) 306 * Function format is: function(Tox *tox, int friendnumber, uint8_t * message, uint32_t length, void *userdata)