diff options
-rw-r--r-- | other/analysis/gen-file.sh | 3 | ||||
-rw-r--r-- | toxav/toxav.c | 5 | ||||
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.h | 1 | ||||
-rw-r--r-- | toxcore/tox.c | 486 |
5 files changed, 375 insertions, 122 deletions
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh index 89144eff..8c320acf 100644 --- a/other/analysis/gen-file.sh +++ b/other/analysis/gen-file.sh | |||
@@ -40,9 +40,6 @@ echo "#include <cstdio>" >> amalgamation.cc | |||
40 | echo "#include <memory>" >> amalgamation.cc | 40 | echo "#include <memory>" >> amalgamation.cc |
41 | echo "#include <random>" >> amalgamation.cc | 41 | echo "#include <random>" >> amalgamation.cc |
42 | 42 | ||
43 | echo "#define TOX_DEFINED" >> amalgamation.cc | ||
44 | echo "typedef struct Messenger Tox;" >> amalgamation.cc | ||
45 | |||
46 | put auto_tests/check_compat.h | 43 | put auto_tests/check_compat.h |
47 | 44 | ||
48 | FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'" | 45 | FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'" |
diff --git a/toxav/toxav.c b/toxav/toxav.c index 57d14942..f26834b1 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -123,13 +123,16 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error) | |||
123 | { | 123 | { |
124 | TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK; | 124 | TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK; |
125 | ToxAV *av = nullptr; | 125 | ToxAV *av = nullptr; |
126 | Messenger *m = (Messenger *)tox; | ||
127 | 126 | ||
128 | if (tox == nullptr) { | 127 | if (tox == nullptr) { |
129 | rc = TOXAV_ERR_NEW_NULL; | 128 | rc = TOXAV_ERR_NEW_NULL; |
130 | goto END; | 129 | goto END; |
131 | } | 130 | } |
132 | 131 | ||
132 | // TODO(iphydf): Don't rely on toxcore internals. | ||
133 | Messenger *m; | ||
134 | m = *(Messenger **)tox; | ||
135 | |||
133 | if (m->msi_packet) { | 136 | if (m->msi_packet) { |
134 | rc = TOXAV_ERR_NEW_MULTIPLE; | 137 | rc = TOXAV_ERR_NEW_MULTIPLE; |
135 | goto END; | 138 | goto END; |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index cfa76172..7ff2c2b3 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1985,7 +1985,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
1985 | return nullptr; | 1985 | return nullptr; |
1986 | } | 1986 | } |
1987 | 1987 | ||
1988 | logger_callback_log(m->log, options->log_callback, m, options->log_user_data); | 1988 | logger_callback_log(m->log, options->log_callback, options->log_context, options->log_user_data); |
1989 | 1989 | ||
1990 | unsigned int net_err = 0; | 1990 | unsigned int net_err = 0; |
1991 | 1991 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index cd872a2d..548d8654 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -61,6 +61,7 @@ typedef struct Messenger_Options { | |||
61 | bool local_discovery_enabled; | 61 | bool local_discovery_enabled; |
62 | 62 | ||
63 | logger_cb *log_callback; | 63 | logger_cb *log_callback; |
64 | void *log_context; | ||
64 | void *log_user_data; | 65 | void *log_user_data; |
65 | } Messenger_Options; | 66 | } Messenger_Options; |
66 | 67 | ||
diff --git a/toxcore/tox.c b/toxcore/tox.c index 750a52fa..bf84f022 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -29,13 +29,10 @@ | |||
29 | #define _XOPEN_SOURCE 600 | 29 | #define _XOPEN_SOURCE 600 |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #ifndef TOX_DEFINED | ||
33 | #define TOX_DEFINED | ||
34 | typedef struct Messenger Tox; | ||
35 | #endif | ||
36 | #include "tox.h" | 32 | #include "tox.h" |
37 | 33 | ||
38 | #include <assert.h> | 34 | #include <assert.h> |
35 | #include <stdlib.h> | ||
39 | #include <string.h> | 36 | #include <string.h> |
40 | 37 | ||
41 | #include "Messenger.h" | 38 | #include "Messenger.h" |
@@ -78,6 +75,240 @@ typedef struct Messenger Tox; | |||
78 | #error "TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH" | 75 | #error "TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH" |
79 | #endif | 76 | #endif |
80 | 77 | ||
78 | struct Tox { | ||
79 | Messenger *m; | ||
80 | tox_self_connection_status_cb *self_connection_status_callback; | ||
81 | tox_friend_name_cb *friend_name_callback; | ||
82 | tox_friend_status_message_cb *friend_status_message_callback; | ||
83 | tox_friend_status_cb *friend_status_callback; | ||
84 | tox_friend_connection_status_cb *friend_connection_status_callback; | ||
85 | tox_friend_typing_cb *friend_typing_callback; | ||
86 | tox_friend_read_receipt_cb *friend_read_receipt_callback; | ||
87 | tox_friend_request_cb *friend_request_callback; | ||
88 | tox_friend_message_cb *friend_message_callback; | ||
89 | tox_file_recv_control_cb *file_recv_control_callback; | ||
90 | tox_file_chunk_request_cb *file_chunk_request_callback; | ||
91 | tox_file_recv_cb *file_recv_callback; | ||
92 | tox_file_recv_chunk_cb *file_recv_chunk_callback; | ||
93 | tox_conference_invite_cb *conference_invite_callback; | ||
94 | tox_conference_message_cb *conference_message_callback; | ||
95 | tox_conference_title_cb *conference_title_callback; | ||
96 | tox_conference_peer_name_cb *conference_peer_name_callback; | ||
97 | tox_conference_peer_list_changed_cb *conference_peer_list_changed_callback; | ||
98 | tox_friend_lossy_packet_cb *friend_lossy_packet_callback; | ||
99 | tox_friend_lossless_packet_cb *friend_lossless_packet_callback; | ||
100 | }; | ||
101 | |||
102 | struct Tox_Userdata { | ||
103 | Tox *tox; | ||
104 | void *user_data; | ||
105 | }; | ||
106 | |||
107 | static void tox_self_connection_status_handler(Messenger *m, unsigned int connection_status, void *user_data) | ||
108 | { | ||
109 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
110 | |||
111 | if (tox_data->tox->self_connection_status_callback != nullptr) { | ||
112 | tox_data->tox->self_connection_status_callback(tox_data->tox, (Tox_Connection)connection_status, tox_data->user_data); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | static void tox_friend_name_handler(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length, | ||
117 | void *user_data) | ||
118 | { | ||
119 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
120 | |||
121 | if (tox_data->tox->friend_name_callback != nullptr) { | ||
122 | tox_data->tox->friend_name_callback(tox_data->tox, friend_number, name, length, tox_data->user_data); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | static void tox_friend_status_message_handler(Messenger *m, uint32_t friend_number, const uint8_t *message, | ||
127 | size_t length, void *user_data) | ||
128 | { | ||
129 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
130 | |||
131 | if (tox_data->tox->friend_status_message_callback != nullptr) { | ||
132 | tox_data->tox->friend_status_message_callback(tox_data->tox, friend_number, message, length, tox_data->user_data); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | static void tox_friend_status_handler(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data) | ||
137 | { | ||
138 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
139 | |||
140 | if (tox_data->tox->friend_status_callback != nullptr) { | ||
141 | tox_data->tox->friend_status_callback(tox_data->tox, friend_number, (Tox_User_Status)status, tox_data->user_data); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | static void tox_friend_connection_status_handler(Messenger *m, uint32_t friend_number, unsigned int connection_status, | ||
146 | void *user_data) | ||
147 | { | ||
148 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
149 | |||
150 | if (tox_data->tox->friend_connection_status_callback != nullptr) { | ||
151 | tox_data->tox->friend_connection_status_callback(tox_data->tox, friend_number, (Tox_Connection)connection_status, | ||
152 | tox_data->user_data); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | static void tox_friend_typing_handler(Messenger *m, uint32_t friend_number, bool is_typing, void *user_data) | ||
157 | { | ||
158 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
159 | |||
160 | if (tox_data->tox->friend_typing_callback != nullptr) { | ||
161 | tox_data->tox->friend_typing_callback(tox_data->tox, friend_number, is_typing, tox_data->user_data); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | static void tox_friend_read_receipt_handler(Messenger *m, uint32_t friend_number, uint32_t message_id, void *user_data) | ||
166 | { | ||
167 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
168 | |||
169 | if (tox_data->tox->friend_read_receipt_callback != nullptr) { | ||
170 | tox_data->tox->friend_read_receipt_callback(tox_data->tox, friend_number, message_id, tox_data->user_data); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | static void tox_friend_request_handler(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length, | ||
175 | void *user_data) | ||
176 | { | ||
177 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
178 | |||
179 | if (tox_data->tox->friend_request_callback != nullptr) { | ||
180 | tox_data->tox->friend_request_callback(tox_data->tox, public_key, message, length, tox_data->user_data); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | static void tox_friend_message_handler(Messenger *m, uint32_t friend_number, unsigned int type, const uint8_t *message, | ||
185 | size_t length, void *user_data) | ||
186 | { | ||
187 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
188 | |||
189 | if (tox_data->tox->friend_message_callback != nullptr) { | ||
190 | tox_data->tox->friend_message_callback(tox_data->tox, friend_number, (Tox_Message_Type)type, message, length, | ||
191 | tox_data->user_data); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | static void tox_file_recv_control_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, | ||
196 | unsigned int control, void *user_data) | ||
197 | { | ||
198 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
199 | |||
200 | if (tox_data->tox->file_recv_control_callback != nullptr) { | ||
201 | tox_data->tox->file_recv_control_callback(tox_data->tox, friend_number, file_number, (Tox_File_Control)control, | ||
202 | tox_data->user_data); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | static void tox_file_chunk_request_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, | ||
207 | uint64_t position, size_t length, void *user_data) | ||
208 | { | ||
209 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
210 | |||
211 | if (tox_data->tox->file_chunk_request_callback != nullptr) { | ||
212 | tox_data->tox->file_chunk_request_callback(tox_data->tox, friend_number, file_number, position, length, | ||
213 | tox_data->user_data); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | static void tox_file_recv_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, uint32_t kind, | ||
218 | uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data) | ||
219 | { | ||
220 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
221 | |||
222 | if (tox_data->tox->file_recv_callback != nullptr) { | ||
223 | tox_data->tox->file_recv_callback(tox_data->tox, friend_number, file_number, kind, file_size, filename, filename_length, | ||
224 | tox_data->user_data); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | static void tox_file_recv_chunk_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position, | ||
229 | const uint8_t *data, size_t length, void *user_data) | ||
230 | { | ||
231 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
232 | |||
233 | if (tox_data->tox->file_recv_chunk_callback != nullptr) { | ||
234 | tox_data->tox->file_recv_chunk_callback(tox_data->tox, friend_number, file_number, position, data, length, | ||
235 | tox_data->user_data); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | static void tox_conference_invite_handler(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie, | ||
240 | size_t length, void *user_data) | ||
241 | { | ||
242 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
243 | |||
244 | if (tox_data->tox->conference_invite_callback != nullptr) { | ||
245 | tox_data->tox->conference_invite_callback(tox_data->tox, friend_number, (Tox_Conference_Type)type, cookie, length, | ||
246 | tox_data->user_data); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | static void tox_conference_message_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type, | ||
251 | const uint8_t *message, size_t length, void *user_data) | ||
252 | { | ||
253 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
254 | |||
255 | if (tox_data->tox->conference_message_callback != nullptr) { | ||
256 | tox_data->tox->conference_message_callback(tox_data->tox, conference_number, peer_number, (Tox_Message_Type)type, | ||
257 | message, length, tox_data->user_data); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | static void tox_conference_title_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number, | ||
262 | const uint8_t *title, size_t length, void *user_data) | ||
263 | { | ||
264 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
265 | |||
266 | if (tox_data->tox->conference_title_callback != nullptr) { | ||
267 | tox_data->tox->conference_title_callback(tox_data->tox, conference_number, peer_number, title, length, | ||
268 | tox_data->user_data); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | static void tox_conference_peer_name_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number, | ||
273 | const uint8_t *name, size_t length, void *user_data) | ||
274 | { | ||
275 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
276 | |||
277 | if (tox_data->tox->conference_peer_name_callback != nullptr) { | ||
278 | tox_data->tox->conference_peer_name_callback(tox_data->tox, conference_number, peer_number, name, length, | ||
279 | tox_data->user_data); | ||
280 | } | ||
281 | } | ||
282 | |||
283 | static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conference_number, void *user_data) | ||
284 | { | ||
285 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
286 | |||
287 | if (tox_data->tox->conference_peer_list_changed_callback != nullptr) { | ||
288 | tox_data->tox->conference_peer_list_changed_callback(tox_data->tox, conference_number, tox_data->user_data); | ||
289 | } | ||
290 | } | ||
291 | |||
292 | static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, | ||
293 | void *user_data) | ||
294 | { | ||
295 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
296 | |||
297 | if (tox_data->tox->friend_lossy_packet_callback != nullptr) { | ||
298 | tox_data->tox->friend_lossy_packet_callback(tox_data->tox, friend_number, data, length, tox_data->user_data); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | static void tox_friend_lossless_packet_handler(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, | ||
303 | void *user_data) | ||
304 | { | ||
305 | struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; | ||
306 | |||
307 | if (tox_data->tox->friend_lossless_packet_callback != nullptr) { | ||
308 | tox_data->tox->friend_lossless_packet_callback(tox_data->tox, friend_number, data, length, tox_data->user_data); | ||
309 | } | ||
310 | } | ||
311 | |||
81 | 312 | ||
82 | bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch) | 313 | bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch) |
83 | { | 314 | { |
@@ -87,6 +318,13 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch) | |||
87 | 318 | ||
88 | Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | 319 | Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) |
89 | { | 320 | { |
321 | Tox *tox = (Tox *)calloc(1, sizeof(Tox)); | ||
322 | |||
323 | if (tox == nullptr) { | ||
324 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); | ||
325 | return nullptr; | ||
326 | } | ||
327 | |||
90 | Messenger_Options m_options = {0}; | 328 | Messenger_Options m_options = {0}; |
91 | 329 | ||
92 | bool load_savedata_sk = false, load_savedata_tox = false; | 330 | bool load_savedata_sk = false, load_savedata_tox = false; |
@@ -103,6 +341,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
103 | 341 | ||
104 | case TOX_ERR_OPTIONS_NEW_MALLOC: | 342 | case TOX_ERR_OPTIONS_NEW_MALLOC: |
105 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); | 343 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); |
344 | free(tox); | ||
106 | return nullptr; | 345 | return nullptr; |
107 | } | 346 | } |
108 | } | 347 | } |
@@ -114,6 +353,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
114 | if (tox_options_get_savedata_data(opts) == nullptr || tox_options_get_savedata_length(opts) == 0) { | 353 | if (tox_options_get_savedata_data(opts) == nullptr || tox_options_get_savedata_length(opts) == 0) { |
115 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | 354 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); |
116 | tox_options_free(default_options); | 355 | tox_options_free(default_options); |
356 | free(tox); | ||
117 | return nullptr; | 357 | return nullptr; |
118 | } | 358 | } |
119 | } | 359 | } |
@@ -122,6 +362,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
122 | if (tox_options_get_savedata_length(opts) != TOX_SECRET_KEY_SIZE) { | 362 | if (tox_options_get_savedata_length(opts) != TOX_SECRET_KEY_SIZE) { |
123 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | 363 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); |
124 | tox_options_free(default_options); | 364 | tox_options_free(default_options); |
365 | free(tox); | ||
125 | return nullptr; | 366 | return nullptr; |
126 | } | 367 | } |
127 | 368 | ||
@@ -130,12 +371,14 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
130 | if (tox_options_get_savedata_length(opts) < TOX_ENC_SAVE_MAGIC_LENGTH) { | 371 | if (tox_options_get_savedata_length(opts) < TOX_ENC_SAVE_MAGIC_LENGTH) { |
131 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | 372 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); |
132 | tox_options_free(default_options); | 373 | tox_options_free(default_options); |
374 | free(tox); | ||
133 | return nullptr; | 375 | return nullptr; |
134 | } | 376 | } |
135 | 377 | ||
136 | if (crypto_memcmp(tox_options_get_savedata_data(opts), TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { | 378 | if (crypto_memcmp(tox_options_get_savedata_data(opts), TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { |
137 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); | 379 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); |
138 | tox_options_free(default_options); | 380 | tox_options_free(default_options); |
381 | free(tox); | ||
139 | return nullptr; | 382 | return nullptr; |
140 | } | 383 | } |
141 | 384 | ||
@@ -151,6 +394,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
151 | m_options.local_discovery_enabled = tox_options_get_local_discovery_enabled(opts); | 394 | m_options.local_discovery_enabled = tox_options_get_local_discovery_enabled(opts); |
152 | 395 | ||
153 | m_options.log_callback = (logger_cb *)tox_options_get_log_callback(opts); | 396 | m_options.log_callback = (logger_cb *)tox_options_get_log_callback(opts); |
397 | m_options.log_context = tox; | ||
154 | m_options.log_user_data = tox_options_get_log_user_data(opts); | 398 | m_options.log_user_data = tox_options_get_log_user_data(opts); |
155 | 399 | ||
156 | switch (tox_options_get_proxy_type(opts)) { | 400 | switch (tox_options_get_proxy_type(opts)) { |
@@ -169,6 +413,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
169 | default: | 413 | default: |
170 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE); | 414 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE); |
171 | tox_options_free(default_options); | 415 | tox_options_free(default_options); |
416 | free(tox); | ||
172 | return nullptr; | 417 | return nullptr; |
173 | } | 418 | } |
174 | 419 | ||
@@ -176,6 +421,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
176 | if (tox_options_get_proxy_port(opts) == 0) { | 421 | if (tox_options_get_proxy_port(opts) == 0) { |
177 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_PORT); | 422 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_PORT); |
178 | tox_options_free(default_options); | 423 | tox_options_free(default_options); |
424 | free(tox); | ||
179 | return nullptr; | 425 | return nullptr; |
180 | } | 426 | } |
181 | 427 | ||
@@ -189,6 +435,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
189 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); | 435 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); |
190 | // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. | 436 | // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. |
191 | tox_options_free(default_options); | 437 | tox_options_free(default_options); |
438 | free(tox); | ||
192 | return nullptr; | 439 | return nullptr; |
193 | } | 440 | } |
194 | 441 | ||
@@ -196,8 +443,11 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
196 | } | 443 | } |
197 | 444 | ||
198 | unsigned int m_error; | 445 | unsigned int m_error; |
199 | Messenger *m = new_messenger(&m_options, &m_error); | 446 | Messenger *const m = new_messenger(&m_options, &m_error); |
447 | tox->m = m; | ||
200 | 448 | ||
449 | // TODO(iphydf): Clarify this code, check for NULL before new_groupchats, so | ||
450 | // new_groupchats can assume m is non-NULL. | ||
201 | if (!new_groupchats(m)) { | 451 | if (!new_groupchats(m)) { |
202 | kill_messenger(m); | 452 | kill_messenger(m); |
203 | 453 | ||
@@ -210,6 +460,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
210 | } | 460 | } |
211 | 461 | ||
212 | tox_options_free(default_options); | 462 | tox_options_free(default_options); |
463 | free(tox); | ||
213 | return nullptr; | 464 | return nullptr; |
214 | } | 465 | } |
215 | 466 | ||
@@ -223,8 +474,29 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) | |||
223 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); | 474 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); |
224 | } | 475 | } |
225 | 476 | ||
477 | m_callback_namechange(m, tox_friend_name_handler); | ||
478 | m_callback_core_connection(m, tox_self_connection_status_handler); | ||
479 | m_callback_statusmessage(m, tox_friend_status_message_handler); | ||
480 | m_callback_userstatus(m, tox_friend_status_handler); | ||
481 | m_callback_connectionstatus(m, tox_friend_connection_status_handler); | ||
482 | m_callback_typingchange(m, tox_friend_typing_handler); | ||
483 | m_callback_read_receipt(m, tox_friend_read_receipt_handler); | ||
484 | m_callback_friendrequest(m, tox_friend_request_handler); | ||
485 | m_callback_friendmessage(m, tox_friend_message_handler); | ||
486 | callback_file_control(m, tox_file_recv_control_handler); | ||
487 | callback_file_reqchunk(m, tox_file_chunk_request_handler); | ||
488 | callback_file_sendrequest(m, tox_file_recv_handler); | ||
489 | callback_file_data(m, tox_file_recv_chunk_handler); | ||
490 | g_callback_group_invite((Group_Chats *)m->conferences_object, tox_conference_invite_handler); | ||
491 | g_callback_group_message((Group_Chats *)m->conferences_object, tox_conference_message_handler); | ||
492 | g_callback_group_title((Group_Chats *)m->conferences_object, tox_conference_title_handler); | ||
493 | g_callback_peer_name((Group_Chats *)m->conferences_object, tox_conference_peer_name_handler); | ||
494 | g_callback_peer_list_changed((Group_Chats *)m->conferences_object, tox_conference_peer_list_changed_handler); | ||
495 | custom_lossy_packet_registerhandler(m, tox_friend_lossy_packet_handler); | ||
496 | custom_lossless_packet_registerhandler(m, tox_friend_lossless_packet_handler); | ||
497 | |||
226 | tox_options_free(default_options); | 498 | tox_options_free(default_options); |
227 | return m; | 499 | return tox; |
228 | } | 500 | } |
229 | 501 | ||
230 | void tox_kill(Tox *tox) | 502 | void tox_kill(Tox *tox) |
@@ -233,21 +505,22 @@ void tox_kill(Tox *tox) | |||
233 | return; | 505 | return; |
234 | } | 506 | } |
235 | 507 | ||
236 | Messenger *m = tox; | 508 | Messenger *m = tox->m; |
237 | kill_groupchats((Group_Chats *)m->conferences_object); | 509 | kill_groupchats((Group_Chats *)m->conferences_object); |
238 | kill_messenger(m); | 510 | kill_messenger(m); |
511 | free(tox); | ||
239 | } | 512 | } |
240 | 513 | ||
241 | size_t tox_get_savedata_size(const Tox *tox) | 514 | size_t tox_get_savedata_size(const Tox *tox) |
242 | { | 515 | { |
243 | const Messenger *m = tox; | 516 | const Messenger *m = tox->m; |
244 | return messenger_size(m); | 517 | return messenger_size(m); |
245 | } | 518 | } |
246 | 519 | ||
247 | void tox_get_savedata(const Tox *tox, uint8_t *savedata) | 520 | void tox_get_savedata(const Tox *tox, uint8_t *savedata) |
248 | { | 521 | { |
249 | if (savedata) { | 522 | if (savedata) { |
250 | const Messenger *m = tox; | 523 | const Messenger *m = tox->m; |
251 | messenger_save(m, savedata); | 524 | messenger_save(m, savedata); |
252 | } | 525 | } |
253 | } | 526 | } |
@@ -279,7 +552,7 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub | |||
279 | for (i = 0; i < count; ++i) { | 552 | for (i = 0; i < count; ++i) { |
280 | root[i].port = net_htons(port); | 553 | root[i].port = net_htons(port); |
281 | 554 | ||
282 | Messenger *m = tox; | 555 | Messenger *m = tox->m; |
283 | onion_add_bs_path_node(m->onion_c, root[i], public_key); | 556 | onion_add_bs_path_node(m->onion_c, root[i], public_key); |
284 | dht_bootstrap(m->dht, root[i], public_key); | 557 | dht_bootstrap(m->dht, root[i], public_key); |
285 | } | 558 | } |
@@ -323,7 +596,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t | |||
323 | for (i = 0; i < count; ++i) { | 596 | for (i = 0; i < count; ++i) { |
324 | root[i].port = net_htons(port); | 597 | root[i].port = net_htons(port); |
325 | 598 | ||
326 | Messenger *m = tox; | 599 | Messenger *m = tox->m; |
327 | add_tcp_relay(m->net_crypto, root[i], public_key); | 600 | add_tcp_relay(m->net_crypto, root[i], public_key); |
328 | } | 601 | } |
329 | 602 | ||
@@ -340,7 +613,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t | |||
340 | 613 | ||
341 | Tox_Connection tox_self_get_connection_status(const Tox *tox) | 614 | Tox_Connection tox_self_get_connection_status(const Tox *tox) |
342 | { | 615 | { |
343 | const Messenger *m = tox; | 616 | const Messenger *m = tox->m; |
344 | 617 | ||
345 | unsigned int ret = onion_connection_status(m->onion_c); | 618 | unsigned int ret = onion_connection_status(m->onion_c); |
346 | 619 | ||
@@ -358,46 +631,46 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox) | |||
358 | 631 | ||
359 | void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) | 632 | void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) |
360 | { | 633 | { |
361 | Messenger *m = tox; | 634 | tox->self_connection_status_callback = callback; |
362 | m_callback_core_connection(m, (m_self_connection_status_cb *)callback); | ||
363 | } | 635 | } |
364 | 636 | ||
365 | uint32_t tox_iteration_interval(const Tox *tox) | 637 | uint32_t tox_iteration_interval(const Tox *tox) |
366 | { | 638 | { |
367 | const Messenger *m = tox; | 639 | const Messenger *m = tox->m; |
368 | return messenger_run_interval(m); | 640 | return messenger_run_interval(m); |
369 | } | 641 | } |
370 | 642 | ||
371 | void tox_iterate(Tox *tox, void *user_data) | 643 | void tox_iterate(Tox *tox, void *user_data) |
372 | { | 644 | { |
373 | Messenger *m = tox; | 645 | Messenger *m = tox->m; |
374 | do_messenger(m, user_data); | 646 | struct Tox_Userdata tox_data = { tox, user_data }; |
375 | do_groupchats((Group_Chats *)m->conferences_object, user_data); | 647 | do_messenger(m, &tox_data); |
648 | do_groupchats((Group_Chats *)m->conferences_object, &tox_data); | ||
376 | } | 649 | } |
377 | 650 | ||
378 | void tox_self_get_address(const Tox *tox, uint8_t *address) | 651 | void tox_self_get_address(const Tox *tox, uint8_t *address) |
379 | { | 652 | { |
380 | if (address) { | 653 | if (address) { |
381 | const Messenger *m = tox; | 654 | const Messenger *m = tox->m; |
382 | getaddress(m, address); | 655 | getaddress(m, address); |
383 | } | 656 | } |
384 | } | 657 | } |
385 | 658 | ||
386 | void tox_self_set_nospam(Tox *tox, uint32_t nospam) | 659 | void tox_self_set_nospam(Tox *tox, uint32_t nospam) |
387 | { | 660 | { |
388 | Messenger *m = tox; | 661 | Messenger *m = tox->m; |
389 | set_nospam(m->fr, net_htonl(nospam)); | 662 | set_nospam(m->fr, net_htonl(nospam)); |
390 | } | 663 | } |
391 | 664 | ||
392 | uint32_t tox_self_get_nospam(const Tox *tox) | 665 | uint32_t tox_self_get_nospam(const Tox *tox) |
393 | { | 666 | { |
394 | const Messenger *m = tox; | 667 | const Messenger *m = tox->m; |
395 | return net_ntohl(get_nospam(m->fr)); | 668 | return net_ntohl(get_nospam(m->fr)); |
396 | } | 669 | } |
397 | 670 | ||
398 | void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) | 671 | void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) |
399 | { | 672 | { |
400 | const Messenger *m = tox; | 673 | const Messenger *m = tox->m; |
401 | 674 | ||
402 | if (public_key) { | 675 | if (public_key) { |
403 | memcpy(public_key, nc_get_self_public_key(m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); | 676 | memcpy(public_key, nc_get_self_public_key(m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); |
@@ -406,7 +679,7 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) | |||
406 | 679 | ||
407 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) | 680 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) |
408 | { | 681 | { |
409 | const Messenger *m = tox; | 682 | const Messenger *m = tox->m; |
410 | 683 | ||
411 | if (secret_key) { | 684 | if (secret_key) { |
412 | memcpy(secret_key, nc_get_self_secret_key(m->net_crypto), CRYPTO_SECRET_KEY_SIZE); | 685 | memcpy(secret_key, nc_get_self_secret_key(m->net_crypto), CRYPTO_SECRET_KEY_SIZE); |
@@ -420,7 +693,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set | |||
420 | return 0; | 693 | return 0; |
421 | } | 694 | } |
422 | 695 | ||
423 | Messenger *m = tox; | 696 | Messenger *m = tox->m; |
424 | 697 | ||
425 | if (setname(m, name, length) == 0) { | 698 | if (setname(m, name, length) == 0) { |
426 | // TODO(irungentoo): function to set different per group names? | 699 | // TODO(irungentoo): function to set different per group names? |
@@ -435,14 +708,14 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set | |||
435 | 708 | ||
436 | size_t tox_self_get_name_size(const Tox *tox) | 709 | size_t tox_self_get_name_size(const Tox *tox) |
437 | { | 710 | { |
438 | const Messenger *m = tox; | 711 | const Messenger *m = tox->m; |
439 | return m_get_self_name_size(m); | 712 | return m_get_self_name_size(m); |
440 | } | 713 | } |
441 | 714 | ||
442 | void tox_self_get_name(const Tox *tox, uint8_t *name) | 715 | void tox_self_get_name(const Tox *tox, uint8_t *name) |
443 | { | 716 | { |
444 | if (name) { | 717 | if (name) { |
445 | const Messenger *m = tox; | 718 | const Messenger *m = tox->m; |
446 | getself_name(m, name); | 719 | getself_name(m, name); |
447 | } | 720 | } |
448 | } | 721 | } |
@@ -454,7 +727,7 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t | |||
454 | return 0; | 727 | return 0; |
455 | } | 728 | } |
456 | 729 | ||
457 | Messenger *m = tox; | 730 | Messenger *m = tox->m; |
458 | 731 | ||
459 | if (m_set_statusmessage(m, status_message, length) == 0) { | 732 | if (m_set_statusmessage(m, status_message, length) == 0) { |
460 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); | 733 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); |
@@ -467,27 +740,27 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t | |||
467 | 740 | ||
468 | size_t tox_self_get_status_message_size(const Tox *tox) | 741 | size_t tox_self_get_status_message_size(const Tox *tox) |
469 | { | 742 | { |
470 | const Messenger *m = tox; | 743 | const Messenger *m = tox->m; |
471 | return m_get_self_statusmessage_size(m); | 744 | return m_get_self_statusmessage_size(m); |
472 | } | 745 | } |
473 | 746 | ||
474 | void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) | 747 | void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) |
475 | { | 748 | { |
476 | if (status_message) { | 749 | if (status_message) { |
477 | const Messenger *m = tox; | 750 | const Messenger *m = tox->m; |
478 | m_copy_self_statusmessage(m, status_message); | 751 | m_copy_self_statusmessage(m, status_message); |
479 | } | 752 | } |
480 | } | 753 | } |
481 | 754 | ||
482 | void tox_self_set_status(Tox *tox, Tox_User_Status status) | 755 | void tox_self_set_status(Tox *tox, Tox_User_Status status) |
483 | { | 756 | { |
484 | Messenger *m = tox; | 757 | Messenger *m = tox->m; |
485 | m_set_userstatus(m, status); | 758 | m_set_userstatus(m, status); |
486 | } | 759 | } |
487 | 760 | ||
488 | Tox_User_Status tox_self_get_status(const Tox *tox) | 761 | Tox_User_Status tox_self_get_status(const Tox *tox) |
489 | { | 762 | { |
490 | const Messenger *m = tox; | 763 | const Messenger *m = tox->m; |
491 | const uint8_t status = m_get_self_userstatus(m); | 764 | const uint8_t status = m_get_self_userstatus(m); |
492 | return (Tox_User_Status)status; | 765 | return (Tox_User_Status)status; |
493 | } | 766 | } |
@@ -538,7 +811,7 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message | |||
538 | return UINT32_MAX; | 811 | return UINT32_MAX; |
539 | } | 812 | } |
540 | 813 | ||
541 | Messenger *m = tox; | 814 | Messenger *m = tox->m; |
542 | int32_t ret = m_addfriend(m, address, message, length); | 815 | int32_t ret = m_addfriend(m, address, message, length); |
543 | 816 | ||
544 | if (ret >= 0) { | 817 | if (ret >= 0) { |
@@ -557,7 +830,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F | |||
557 | return UINT32_MAX; | 830 | return UINT32_MAX; |
558 | } | 831 | } |
559 | 832 | ||
560 | Messenger *m = tox; | 833 | Messenger *m = tox->m; |
561 | int32_t ret = m_addfriend_norequest(m, public_key); | 834 | int32_t ret = m_addfriend_norequest(m, public_key); |
562 | 835 | ||
563 | if (ret >= 0) { | 836 | if (ret >= 0) { |
@@ -571,7 +844,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F | |||
571 | 844 | ||
572 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) | 845 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) |
573 | { | 846 | { |
574 | Messenger *m = tox; | 847 | Messenger *m = tox->m; |
575 | int ret = m_delfriend(m, friend_number); | 848 | int ret = m_delfriend(m, friend_number); |
576 | 849 | ||
577 | // TODO(irungentoo): handle if realloc fails? | 850 | // TODO(irungentoo): handle if realloc fails? |
@@ -591,7 +864,7 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox | |||
591 | return UINT32_MAX; | 864 | return UINT32_MAX; |
592 | } | 865 | } |
593 | 866 | ||
594 | const Messenger *m = tox; | 867 | const Messenger *m = tox->m; |
595 | int32_t ret = getfriend_id(m, public_key); | 868 | int32_t ret = getfriend_id(m, public_key); |
596 | 869 | ||
597 | if (ret == -1) { | 870 | if (ret == -1) { |
@@ -610,7 +883,7 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t * | |||
610 | return 0; | 883 | return 0; |
611 | } | 884 | } |
612 | 885 | ||
613 | const Messenger *m = tox; | 886 | const Messenger *m = tox->m; |
614 | 887 | ||
615 | if (get_real_pk(m, friend_number, public_key) == -1) { | 888 | if (get_real_pk(m, friend_number, public_key) == -1) { |
616 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND); | 889 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND); |
@@ -623,13 +896,13 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t * | |||
623 | 896 | ||
624 | bool tox_friend_exists(const Tox *tox, uint32_t friend_number) | 897 | bool tox_friend_exists(const Tox *tox, uint32_t friend_number) |
625 | { | 898 | { |
626 | const Messenger *m = tox; | 899 | const Messenger *m = tox->m; |
627 | return m_friend_exists(m, friend_number); | 900 | return m_friend_exists(m, friend_number); |
628 | } | 901 | } |
629 | 902 | ||
630 | uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) | 903 | uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) |
631 | { | 904 | { |
632 | const Messenger *m = tox; | 905 | const Messenger *m = tox->m; |
633 | uint64_t timestamp = m_get_last_online(m, friend_number); | 906 | uint64_t timestamp = m_get_last_online(m, friend_number); |
634 | 907 | ||
635 | if (timestamp == UINT64_MAX) { | 908 | if (timestamp == UINT64_MAX) { |
@@ -643,14 +916,14 @@ uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_ | |||
643 | 916 | ||
644 | size_t tox_self_get_friend_list_size(const Tox *tox) | 917 | size_t tox_self_get_friend_list_size(const Tox *tox) |
645 | { | 918 | { |
646 | const Messenger *m = tox; | 919 | const Messenger *m = tox->m; |
647 | return count_friendlist(m); | 920 | return count_friendlist(m); |
648 | } | 921 | } |
649 | 922 | ||
650 | void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) | 923 | void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) |
651 | { | 924 | { |
652 | if (friend_list) { | 925 | if (friend_list) { |
653 | const Messenger *m = tox; | 926 | const Messenger *m = tox->m; |
654 | // TODO(irungentoo): size parameter? | 927 | // TODO(irungentoo): size parameter? |
655 | copy_friendlist(m, friend_list, tox_self_get_friend_list_size(tox)); | 928 | copy_friendlist(m, friend_list, tox_self_get_friend_list_size(tox)); |
656 | } | 929 | } |
@@ -658,7 +931,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) | |||
658 | 931 | ||
659 | size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 932 | size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
660 | { | 933 | { |
661 | const Messenger *m = tox; | 934 | const Messenger *m = tox->m; |
662 | int ret = m_get_name_size(m, friend_number); | 935 | int ret = m_get_name_size(m, friend_number); |
663 | 936 | ||
664 | if (ret == -1) { | 937 | if (ret == -1) { |
@@ -677,7 +950,7 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, | |||
677 | return 0; | 950 | return 0; |
678 | } | 951 | } |
679 | 952 | ||
680 | const Messenger *m = tox; | 953 | const Messenger *m = tox->m; |
681 | int ret = getname(m, friend_number, name); | 954 | int ret = getname(m, friend_number, name); |
682 | 955 | ||
683 | if (ret == -1) { | 956 | if (ret == -1) { |
@@ -691,13 +964,12 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, | |||
691 | 964 | ||
692 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) | 965 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) |
693 | { | 966 | { |
694 | Messenger *m = tox; | 967 | tox->friend_name_callback = callback; |
695 | m_callback_namechange(m, callback); | ||
696 | } | 968 | } |
697 | 969 | ||
698 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 970 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
699 | { | 971 | { |
700 | const Messenger *m = tox; | 972 | const Messenger *m = tox->m; |
701 | int ret = m_get_statusmessage_size(m, friend_number); | 973 | int ret = m_get_statusmessage_size(m, friend_number); |
702 | 974 | ||
703 | if (ret == -1) { | 975 | if (ret == -1) { |
@@ -717,7 +989,7 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 | |||
717 | return 0; | 989 | return 0; |
718 | } | 990 | } |
719 | 991 | ||
720 | const Messenger *m = tox; | 992 | const Messenger *m = tox->m; |
721 | // TODO(irungentoo): size parameter? | 993 | // TODO(irungentoo): size parameter? |
722 | int ret = m_copy_statusmessage(m, friend_number, status_message, m_get_statusmessage_size(m, friend_number)); | 994 | int ret = m_copy_statusmessage(m, friend_number, status_message, m_get_statusmessage_size(m, friend_number)); |
723 | 995 | ||
@@ -732,13 +1004,12 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 | |||
732 | 1004 | ||
733 | void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) | 1005 | void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) |
734 | { | 1006 | { |
735 | Messenger *m = tox; | 1007 | tox->friend_status_message_callback = callback; |
736 | m_callback_statusmessage(m, callback); | ||
737 | } | 1008 | } |
738 | 1009 | ||
739 | Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1010 | Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
740 | { | 1011 | { |
741 | const Messenger *m = tox; | 1012 | const Messenger *m = tox->m; |
742 | 1013 | ||
743 | int ret = m_get_userstatus(m, friend_number); | 1014 | int ret = m_get_userstatus(m, friend_number); |
744 | 1015 | ||
@@ -753,13 +1024,12 @@ Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, To | |||
753 | 1024 | ||
754 | void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) | 1025 | void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) |
755 | { | 1026 | { |
756 | Messenger *m = tox; | 1027 | tox->friend_status_callback = callback; |
757 | m_callback_userstatus(m, (m_friend_status_cb *)callback); | ||
758 | } | 1028 | } |
759 | 1029 | ||
760 | Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1030 | Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
761 | { | 1031 | { |
762 | const Messenger *m = tox; | 1032 | const Messenger *m = tox->m; |
763 | 1033 | ||
764 | int ret = m_get_friend_connectionstatus(m, friend_number); | 1034 | int ret = m_get_friend_connectionstatus(m, friend_number); |
765 | 1035 | ||
@@ -774,13 +1044,12 @@ Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_ | |||
774 | 1044 | ||
775 | void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) | 1045 | void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) |
776 | { | 1046 | { |
777 | Messenger *m = tox; | 1047 | tox->friend_connection_status_callback = callback; |
778 | m_callback_connectionstatus(m, (m_friend_connection_status_cb *)callback); | ||
779 | } | 1048 | } |
780 | 1049 | ||
781 | bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1050 | bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
782 | { | 1051 | { |
783 | const Messenger *m = tox; | 1052 | const Messenger *m = tox->m; |
784 | int ret = m_get_istyping(m, friend_number); | 1053 | int ret = m_get_istyping(m, friend_number); |
785 | 1054 | ||
786 | if (ret == -1) { | 1055 | if (ret == -1) { |
@@ -794,13 +1063,12 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien | |||
794 | 1063 | ||
795 | void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) | 1064 | void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) |
796 | { | 1065 | { |
797 | Messenger *m = tox; | 1066 | tox->friend_typing_callback = callback; |
798 | m_callback_typingchange(m, callback); | ||
799 | } | 1067 | } |
800 | 1068 | ||
801 | bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) | 1069 | bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) |
802 | { | 1070 | { |
803 | Messenger *m = tox; | 1071 | Messenger *m = tox->m; |
804 | 1072 | ||
805 | if (m_set_usertyping(m, friend_number, typing) == -1) { | 1073 | if (m_set_usertyping(m, friend_number, typing) == -1) { |
806 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_TYPING_FRIEND_NOT_FOUND); | 1074 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_TYPING_FRIEND_NOT_FOUND); |
@@ -855,7 +1123,7 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T | |||
855 | return 0; | 1123 | return 0; |
856 | } | 1124 | } |
857 | 1125 | ||
858 | Messenger *m = tox; | 1126 | Messenger *m = tox->m; |
859 | uint32_t message_id = 0; | 1127 | uint32_t message_id = 0; |
860 | set_message_error(m_send_message_generic(m, friend_number, type, message, length, &message_id), error); | 1128 | set_message_error(m_send_message_generic(m, friend_number, type, message, length, &message_id), error); |
861 | return message_id; | 1129 | return message_id; |
@@ -863,20 +1131,17 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T | |||
863 | 1131 | ||
864 | void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) | 1132 | void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) |
865 | { | 1133 | { |
866 | Messenger *m = tox; | 1134 | tox->friend_read_receipt_callback = callback; |
867 | m_callback_read_receipt(m, callback); | ||
868 | } | 1135 | } |
869 | 1136 | ||
870 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) | 1137 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) |
871 | { | 1138 | { |
872 | Messenger *m = tox; | 1139 | tox->friend_request_callback = callback; |
873 | m_callback_friendrequest(m, callback); | ||
874 | } | 1140 | } |
875 | 1141 | ||
876 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) | 1142 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) |
877 | { | 1143 | { |
878 | Messenger *m = tox; | 1144 | tox->friend_message_callback = callback; |
879 | m_callback_friendmessage(m, (m_friend_message_cb *)callback); | ||
880 | } | 1145 | } |
881 | 1146 | ||
882 | bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) | 1147 | bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) |
@@ -892,7 +1157,7 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) | |||
892 | bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, | 1157 | bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, |
893 | Tox_Err_File_Control *error) | 1158 | Tox_Err_File_Control *error) |
894 | { | 1159 | { |
895 | Messenger *m = tox; | 1160 | Messenger *m = tox->m; |
896 | int ret = file_control(m, friend_number, file_number, control); | 1161 | int ret = file_control(m, friend_number, file_number, control); |
897 | 1162 | ||
898 | if (ret == 0) { | 1163 | if (ret == 0) { |
@@ -941,7 +1206,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, To | |||
941 | bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, | 1206 | bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, |
942 | Tox_Err_File_Seek *error) | 1207 | Tox_Err_File_Seek *error) |
943 | { | 1208 | { |
944 | Messenger *m = tox; | 1209 | Messenger *m = tox->m; |
945 | int ret = file_seek(m, friend_number, file_number, position); | 1210 | int ret = file_seek(m, friend_number, file_number, position); |
946 | 1211 | ||
947 | if (ret == 0) { | 1212 | if (ret == 0) { |
@@ -982,8 +1247,7 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6 | |||
982 | 1247 | ||
983 | void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) | 1248 | void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) |
984 | { | 1249 | { |
985 | Messenger *m = tox; | 1250 | tox->file_recv_control_callback = callback; |
986 | callback_file_control(m, (m_file_recv_control_cb *)callback); | ||
987 | } | 1251 | } |
988 | 1252 | ||
989 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, | 1253 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, |
@@ -994,7 +1258,7 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_ | |||
994 | return 0; | 1258 | return 0; |
995 | } | 1259 | } |
996 | 1260 | ||
997 | const Messenger *m = tox; | 1261 | const Messenger *m = tox->m; |
998 | int ret = file_get_id(m, friend_number, file_number, file_id); | 1262 | int ret = file_get_id(m, friend_number, file_number, file_id); |
999 | 1263 | ||
1000 | if (ret == 0) { | 1264 | if (ret == 0) { |
@@ -1027,7 +1291,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t | |||
1027 | file_id = f_id; | 1291 | file_id = f_id; |
1028 | } | 1292 | } |
1029 | 1293 | ||
1030 | Messenger *m = tox; | 1294 | Messenger *m = tox->m; |
1031 | long int file_num = new_filesender(m, friend_number, kind, file_size, file_id, filename, filename_length); | 1295 | long int file_num = new_filesender(m, friend_number, kind, file_size, file_id, filename, filename_length); |
1032 | 1296 | ||
1033 | if (file_num >= 0) { | 1297 | if (file_num >= 0) { |
@@ -1060,7 +1324,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t | |||
1060 | bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, | 1324 | bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, |
1061 | size_t length, Tox_Err_File_Send_Chunk *error) | 1325 | size_t length, Tox_Err_File_Send_Chunk *error) |
1062 | { | 1326 | { |
1063 | Messenger *m = tox; | 1327 | Messenger *m = tox->m; |
1064 | int ret = file_data(m, friend_number, file_number, position, data, length); | 1328 | int ret = file_data(m, friend_number, file_number, position, data, length); |
1065 | 1329 | ||
1066 | if (ret == 0) { | 1330 | if (ret == 0) { |
@@ -1104,55 +1368,47 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
1104 | 1368 | ||
1105 | void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) | 1369 | void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) |
1106 | { | 1370 | { |
1107 | Messenger *m = tox; | 1371 | tox->file_chunk_request_callback = callback; |
1108 | callback_file_reqchunk(m, callback); | ||
1109 | } | 1372 | } |
1110 | 1373 | ||
1111 | void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) | 1374 | void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) |
1112 | { | 1375 | { |
1113 | Messenger *m = tox; | 1376 | tox->file_recv_callback = callback; |
1114 | callback_file_sendrequest(m, callback); | ||
1115 | } | 1377 | } |
1116 | 1378 | ||
1117 | void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) | 1379 | void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) |
1118 | { | 1380 | { |
1119 | Messenger *m = tox; | 1381 | tox->file_recv_chunk_callback = callback; |
1120 | callback_file_data(m, callback); | ||
1121 | } | 1382 | } |
1122 | 1383 | ||
1123 | void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) | 1384 | void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) |
1124 | { | 1385 | { |
1125 | Messenger *m = tox; | 1386 | tox->conference_invite_callback = callback; |
1126 | g_callback_group_invite((Group_Chats *)m->conferences_object, (g_conference_invite_cb *)callback); | ||
1127 | } | 1387 | } |
1128 | 1388 | ||
1129 | void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) | 1389 | void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) |
1130 | { | 1390 | { |
1131 | Messenger *m = tox; | 1391 | tox->conference_message_callback = callback; |
1132 | g_callback_group_message((Group_Chats *)m->conferences_object, (g_conference_message_cb *)callback); | ||
1133 | } | 1392 | } |
1134 | 1393 | ||
1135 | void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) | 1394 | void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) |
1136 | { | 1395 | { |
1137 | Messenger *m = tox; | 1396 | tox->conference_title_callback = callback; |
1138 | g_callback_group_title((Group_Chats *)m->conferences_object, callback); | ||
1139 | } | 1397 | } |
1140 | 1398 | ||
1141 | void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) | 1399 | void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) |
1142 | { | 1400 | { |
1143 | Messenger *m = tox; | 1401 | tox->conference_peer_name_callback = callback; |
1144 | g_callback_peer_name((Group_Chats *)m->conferences_object, callback); | ||
1145 | } | 1402 | } |
1146 | 1403 | ||
1147 | void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) | 1404 | void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) |
1148 | { | 1405 | { |
1149 | Messenger *m = tox; | 1406 | tox->conference_peer_list_changed_callback = callback; |
1150 | g_callback_peer_list_changed((Group_Chats *)m->conferences_object, callback); | ||
1151 | } | 1407 | } |
1152 | 1408 | ||
1153 | uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) | 1409 | uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) |
1154 | { | 1410 | { |
1155 | Messenger *m = tox; | 1411 | Messenger *m = tox->m; |
1156 | int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT); | 1412 | int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT); |
1157 | 1413 | ||
1158 | if (ret == -1) { | 1414 | if (ret == -1) { |
@@ -1166,7 +1422,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) | |||
1166 | 1422 | ||
1167 | bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) | 1423 | bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) |
1168 | { | 1424 | { |
1169 | Messenger *m = tox; | 1425 | Messenger *m = tox->m; |
1170 | int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number); | 1426 | int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number); |
1171 | 1427 | ||
1172 | if (ret == -1) { | 1428 | if (ret == -1) { |
@@ -1180,7 +1436,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere | |||
1180 | 1436 | ||
1181 | uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) | 1437 | uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) |
1182 | { | 1438 | { |
1183 | const Messenger *m = tox; | 1439 | const Messenger *m = tox->m; |
1184 | int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number); | 1440 | int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number); |
1185 | 1441 | ||
1186 | if (ret == -1) { | 1442 | if (ret == -1) { |
@@ -1195,7 +1451,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T | |||
1195 | size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1451 | size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1196 | Tox_Err_Conference_Peer_Query *error) | 1452 | Tox_Err_Conference_Peer_Query *error) |
1197 | { | 1453 | { |
1198 | const Messenger *m = tox; | 1454 | const Messenger *m = tox->m; |
1199 | int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number); | 1455 | int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number); |
1200 | 1456 | ||
1201 | switch (ret) { | 1457 | switch (ret) { |
@@ -1215,7 +1471,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num | |||
1215 | bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, | 1471 | bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, |
1216 | Tox_Err_Conference_Peer_Query *error) | 1472 | Tox_Err_Conference_Peer_Query *error) |
1217 | { | 1473 | { |
1218 | const Messenger *m = tox; | 1474 | const Messenger *m = tox->m; |
1219 | int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name); | 1475 | int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name); |
1220 | 1476 | ||
1221 | switch (ret) { | 1477 | switch (ret) { |
@@ -1235,7 +1491,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui | |||
1235 | bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1491 | bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1236 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) | 1492 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) |
1237 | { | 1493 | { |
1238 | const Messenger *m = tox; | 1494 | const Messenger *m = tox->m; |
1239 | int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key); | 1495 | int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key); |
1240 | 1496 | ||
1241 | switch (ret) { | 1497 | switch (ret) { |
@@ -1255,7 +1511,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb | |||
1255 | bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1511 | bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1256 | Tox_Err_Conference_Peer_Query *error) | 1512 | Tox_Err_Conference_Peer_Query *error) |
1257 | { | 1513 | { |
1258 | const Messenger *m = tox; | 1514 | const Messenger *m = tox->m; |
1259 | int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number); | 1515 | int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number); |
1260 | 1516 | ||
1261 | switch (ret) { | 1517 | switch (ret) { |
@@ -1279,7 +1535,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb | |||
1279 | bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, | 1535 | bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, |
1280 | Tox_Err_Conference_Invite *error) | 1536 | Tox_Err_Conference_Invite *error) |
1281 | { | 1537 | { |
1282 | Messenger *m = tox; | 1538 | Messenger *m = tox->m; |
1283 | int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number); | 1539 | int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number); |
1284 | 1540 | ||
1285 | switch (ret) { | 1541 | switch (ret) { |
@@ -1303,7 +1559,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference | |||
1303 | uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, | 1559 | uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, |
1304 | Tox_Err_Conference_Join *error) | 1560 | Tox_Err_Conference_Join *error) |
1305 | { | 1561 | { |
1306 | Messenger *m = tox; | 1562 | Messenger *m = tox->m; |
1307 | int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); | 1563 | int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); |
1308 | 1564 | ||
1309 | switch (ret) { | 1565 | switch (ret) { |
@@ -1339,7 +1595,7 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co | |||
1339 | bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, | 1595 | bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, |
1340 | size_t length, Tox_Err_Conference_Send_Message *error) | 1596 | size_t length, Tox_Err_Conference_Send_Message *error) |
1341 | { | 1597 | { |
1342 | Messenger *m = tox; | 1598 | Messenger *m = tox->m; |
1343 | int ret = 0; | 1599 | int ret = 0; |
1344 | 1600 | ||
1345 | if (type == TOX_MESSAGE_TYPE_NORMAL) { | 1601 | if (type == TOX_MESSAGE_TYPE_NORMAL) { |
@@ -1372,7 +1628,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa | |||
1372 | 1628 | ||
1373 | size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) | 1629 | size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) |
1374 | { | 1630 | { |
1375 | const Messenger *m = tox; | 1631 | const Messenger *m = tox->m; |
1376 | int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number); | 1632 | int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number); |
1377 | 1633 | ||
1378 | switch (ret) { | 1634 | switch (ret) { |
@@ -1392,7 +1648,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, | |||
1392 | bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, | 1648 | bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, |
1393 | Tox_Err_Conference_Title *error) | 1649 | Tox_Err_Conference_Title *error) |
1394 | { | 1650 | { |
1395 | const Messenger *m = tox; | 1651 | const Messenger *m = tox->m; |
1396 | int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title); | 1652 | int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title); |
1397 | 1653 | ||
1398 | switch (ret) { | 1654 | switch (ret) { |
@@ -1412,7 +1668,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_ | |||
1412 | bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, | 1668 | bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, |
1413 | Tox_Err_Conference_Title *error) | 1669 | Tox_Err_Conference_Title *error) |
1414 | { | 1670 | { |
1415 | Messenger *m = tox; | 1671 | Messenger *m = tox->m; |
1416 | int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length); | 1672 | int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length); |
1417 | 1673 | ||
1418 | switch (ret) { | 1674 | switch (ret) { |
@@ -1435,13 +1691,13 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_ | |||
1435 | 1691 | ||
1436 | size_t tox_conference_get_chatlist_size(const Tox *tox) | 1692 | size_t tox_conference_get_chatlist_size(const Tox *tox) |
1437 | { | 1693 | { |
1438 | const Messenger *m = tox; | 1694 | const Messenger *m = tox->m; |
1439 | return count_chatlist((Group_Chats *)m->conferences_object); | 1695 | return count_chatlist((Group_Chats *)m->conferences_object); |
1440 | } | 1696 | } |
1441 | 1697 | ||
1442 | void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) | 1698 | void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) |
1443 | { | 1699 | { |
1444 | const Messenger *m = tox; | 1700 | const Messenger *m = tox->m; |
1445 | size_t list_size = tox_conference_get_chatlist_size(tox); | 1701 | size_t list_size = tox_conference_get_chatlist_size(tox); |
1446 | copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size); | 1702 | copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size); |
1447 | } | 1703 | } |
@@ -1449,7 +1705,7 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) | |||
1449 | Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, | 1705 | Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, |
1450 | Tox_Err_Conference_Get_Type *error) | 1706 | Tox_Err_Conference_Get_Type *error) |
1451 | { | 1707 | { |
1452 | const Messenger *m = tox; | 1708 | const Messenger *m = tox->m; |
1453 | int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number); | 1709 | int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number); |
1454 | 1710 | ||
1455 | if (ret == -1) { | 1711 | if (ret == -1) { |
@@ -1463,8 +1719,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_ | |||
1463 | 1719 | ||
1464 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id /* TOX_CONFERENCE_ID_SIZE bytes */) | 1720 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id /* TOX_CONFERENCE_ID_SIZE bytes */) |
1465 | { | 1721 | { |
1466 | const Messenger *m = tox; | 1722 | return conference_get_uid((Group_Chats *)tox->m->conferences_object, conference_number, id); |
1467 | return conference_get_uid((Group_Chats *)m->conferences_object, conference_number, id); | ||
1468 | } | 1723 | } |
1469 | 1724 | ||
1470 | // TODO(iphydf): Delete in 0.3.0. | 1725 | // TODO(iphydf): Delete in 0.3.0. |
@@ -1480,8 +1735,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere | |||
1480 | return UINT32_MAX; | 1735 | return UINT32_MAX; |
1481 | } | 1736 | } |
1482 | 1737 | ||
1483 | const Messenger *m = tox; | 1738 | int32_t ret = conference_by_uid((Group_Chats *)tox->m->conferences_object, id); |
1484 | int32_t ret = conference_by_uid((Group_Chats *)m->conferences_object, id); | ||
1485 | 1739 | ||
1486 | if (ret == -1) { | 1740 | if (ret == -1) { |
1487 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND); | 1741 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND); |
@@ -1552,7 +1806,7 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ | |||
1552 | return 0; | 1806 | return 0; |
1553 | } | 1807 | } |
1554 | 1808 | ||
1555 | Messenger *m = tox; | 1809 | Messenger *m = tox->m; |
1556 | 1810 | ||
1557 | if (length == 0) { | 1811 | if (length == 0) { |
1558 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); | 1812 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); |
@@ -1579,8 +1833,7 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ | |||
1579 | 1833 | ||
1580 | void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) | 1834 | void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) |
1581 | { | 1835 | { |
1582 | Messenger *m = tox; | 1836 | tox->friend_lossy_packet_callback = callback; |
1583 | custom_lossy_packet_registerhandler(m, callback); | ||
1584 | } | 1837 | } |
1585 | 1838 | ||
1586 | bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, | 1839 | bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, |
@@ -1591,7 +1844,7 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin | |||
1591 | return 0; | 1844 | return 0; |
1592 | } | 1845 | } |
1593 | 1846 | ||
1594 | Messenger *m = tox; | 1847 | Messenger *m = tox->m; |
1595 | 1848 | ||
1596 | if (length == 0) { | 1849 | if (length == 0) { |
1597 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); | 1850 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); |
@@ -1611,21 +1864,20 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin | |||
1611 | 1864 | ||
1612 | void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) | 1865 | void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) |
1613 | { | 1866 | { |
1614 | Messenger *m = tox; | 1867 | tox->friend_lossless_packet_callback = callback; |
1615 | custom_lossless_packet_registerhandler(m, callback); | ||
1616 | } | 1868 | } |
1617 | 1869 | ||
1618 | void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) | 1870 | void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) |
1619 | { | 1871 | { |
1620 | if (dht_id) { | 1872 | if (dht_id) { |
1621 | const Messenger *m = tox; | 1873 | const Messenger *m = tox->m; |
1622 | memcpy(dht_id, dht_get_self_public_key(m->dht), CRYPTO_PUBLIC_KEY_SIZE); | 1874 | memcpy(dht_id, dht_get_self_public_key(m->dht), CRYPTO_PUBLIC_KEY_SIZE); |
1623 | } | 1875 | } |
1624 | } | 1876 | } |
1625 | 1877 | ||
1626 | uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) | 1878 | uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) |
1627 | { | 1879 | { |
1628 | const Messenger *m = tox; | 1880 | const Messenger *m = tox->m; |
1629 | uint16_t port = net_htons(net_port(m->net)); | 1881 | uint16_t port = net_htons(net_port(m->net)); |
1630 | 1882 | ||
1631 | if (port) { | 1883 | if (port) { |
@@ -1639,7 +1891,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) | |||
1639 | 1891 | ||
1640 | uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) | 1892 | uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) |
1641 | { | 1893 | { |
1642 | const Messenger *m = tox; | 1894 | const Messenger *m = tox->m; |
1643 | 1895 | ||
1644 | if (m->tcp_server) { | 1896 | if (m->tcp_server) { |
1645 | SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK); | 1897 | SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK); |