diff options
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r-- | toxcore/tox.c | 117 |
1 files changed, 115 insertions, 2 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index dbd8a96c..71397b9e 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -185,8 +185,10 @@ size_t tox_save_size(Tox const *tox) | |||
185 | 185 | ||
186 | void tox_save(Tox const *tox, uint8_t *data) | 186 | void tox_save(Tox const *tox, uint8_t *data) |
187 | { | 187 | { |
188 | const Messenger *m = tox; | 188 | if (data) { |
189 | messenger_save(m, data); | 189 | const Messenger *m = tox; |
190 | messenger_save(m, data); | ||
191 | } | ||
190 | } | 192 | } |
191 | 193 | ||
192 | static int address_to_ip(Messenger *m, char const *address, IP_Port *ip_port, IP_Port *ip_port_v4) | 194 | static int address_to_ip(Messenger *m, char const *address, IP_Port *ip_port, IP_Port *ip_port_v4) |
@@ -216,6 +218,11 @@ static int address_to_ip(Messenger *m, char const *address, IP_Port *ip_port, IP | |||
216 | 218 | ||
217 | bool tox_bootstrap(Tox *tox, char const *address, uint16_t port, uint8_t const *public_key, TOX_ERR_BOOTSTRAP *error) | 219 | bool tox_bootstrap(Tox *tox, char const *address, uint16_t port, uint8_t const *public_key, TOX_ERR_BOOTSTRAP *error) |
218 | { | 220 | { |
221 | if (!address || !public_key) { | ||
222 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); | ||
223 | return 0; | ||
224 | } | ||
225 | |||
219 | Messenger *m = tox; | 226 | Messenger *m = tox; |
220 | bool ret = tox_add_tcp_relay(tox, address, port, public_key, error); | 227 | bool ret = tox_add_tcp_relay(tox, address, port, public_key, error); |
221 | 228 | ||
@@ -239,6 +246,11 @@ bool tox_bootstrap(Tox *tox, char const *address, uint16_t port, uint8_t const * | |||
239 | bool tox_add_tcp_relay(Tox *tox, char const *address, uint16_t port, uint8_t const *public_key, | 246 | bool tox_add_tcp_relay(Tox *tox, char const *address, uint16_t port, uint8_t const *public_key, |
240 | TOX_ERR_BOOTSTRAP *error) | 247 | TOX_ERR_BOOTSTRAP *error) |
241 | { | 248 | { |
249 | if (!address || !public_key) { | ||
250 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); | ||
251 | return 0; | ||
252 | } | ||
253 | |||
242 | Messenger *m = tox; | 254 | Messenger *m = tox; |
243 | IP_Port ip_port, ip_port_v4; | 255 | IP_Port ip_port, ip_port_v4; |
244 | 256 | ||
@@ -294,3 +306,104 @@ void tox_iteration(Tox *tox) | |||
294 | do_groupchats(m->group_chat_object); | 306 | do_groupchats(m->group_chat_object); |
295 | } | 307 | } |
296 | 308 | ||
309 | void tox_self_get_address(Tox const *tox, uint8_t *address) | ||
310 | { | ||
311 | if (address) { | ||
312 | const Messenger *m = tox; | ||
313 | getaddress(m, address); | ||
314 | } | ||
315 | } | ||
316 | |||
317 | void tox_self_set_nospam(Tox *tox, uint32_t nospam) | ||
318 | { | ||
319 | Messenger *m = tox; | ||
320 | set_nospam(&(m->fr), nospam); | ||
321 | } | ||
322 | |||
323 | uint32_t tox_self_get_nospam(Tox const *tox) | ||
324 | { | ||
325 | const Messenger *m = tox; | ||
326 | return get_nospam(&(m->fr)); | ||
327 | } | ||
328 | |||
329 | void tox_self_get_public_key(Tox const *tox, uint8_t *public_key) | ||
330 | { | ||
331 | const Messenger *m = tox; | ||
332 | |||
333 | if (public_key) | ||
334 | memcpy(public_key, m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
335 | } | ||
336 | |||
337 | void tox_self_get_private_key(Tox const *tox, uint8_t *private_key) | ||
338 | { | ||
339 | const Messenger *m = tox; | ||
340 | |||
341 | if (private_key) | ||
342 | memcpy(private_key, m->net_crypto->self_secret_key, crypto_box_SECRETKEYBYTES); | ||
343 | } | ||
344 | |||
345 | bool tox_self_set_name(Tox *tox, uint8_t const *name, size_t length, TOX_ERR_SET_INFO *error) | ||
346 | { | ||
347 | if (!name && length != 0) { | ||
348 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); | ||
349 | return 0; | ||
350 | } | ||
351 | |||
352 | Messenger *m = tox; | ||
353 | |||
354 | if (setname(m, name, length) == 0) { | ||
355 | //TODO: function to set different per group names? | ||
356 | send_name_all_groups(m->group_chat_object); | ||
357 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); | ||
358 | return 1; | ||
359 | } else { | ||
360 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG); | ||
361 | return 0; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | size_t tox_self_get_name_size(Tox const *tox) | ||
366 | { | ||
367 | const Messenger *m = tox; | ||
368 | return m_get_self_name_size(m); | ||
369 | } | ||
370 | |||
371 | void tox_self_get_name(Tox const *tox, uint8_t *name) | ||
372 | { | ||
373 | if (name) { | ||
374 | const Messenger *m = tox; | ||
375 | getself_name(m, name); | ||
376 | } | ||
377 | } | ||
378 | |||
379 | bool tox_self_set_status_message(Tox *tox, uint8_t const *status, size_t length, TOX_ERR_SET_INFO *error) | ||
380 | { | ||
381 | if (!status && length != 0) { | ||
382 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | Messenger *m = tox; | ||
387 | |||
388 | if (m_set_statusmessage(m, status, length) == 0) { | ||
389 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); | ||
390 | return 1; | ||
391 | } else { | ||
392 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG); | ||
393 | return 0; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | size_t tox_self_get_status_message_size(Tox const *tox) | ||
398 | { | ||
399 | const Messenger *m = tox; | ||
400 | return m_get_self_statusmessage_size(m); | ||
401 | } | ||
402 | |||
403 | void tox_self_get_status_message(Tox const *tox, uint8_t *status) | ||
404 | { | ||
405 | if (status) { | ||
406 | const Messenger *m = tox; | ||
407 | m_copy_self_statusmessage(m, status); | ||
408 | } | ||
409 | } | ||