diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 8 | ||||
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/tox.c | 117 | ||||
-rw-r--r-- | toxcore/tox.h | 3 |
4 files changed, 120 insertions, 10 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 1bcc1f51..55464cb5 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -760,12 +760,10 @@ int m_get_self_statusmessage_size(const Messenger *m) | |||
760 | return m->statusmessage_length; | 760 | return m->statusmessage_length; |
761 | } | 761 | } |
762 | 762 | ||
763 | int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf, uint32_t maxlen) | 763 | int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf) |
764 | { | 764 | { |
765 | int msglen = MIN(maxlen, m->statusmessage_length); | 765 | memcpy(buf, m->statusmessage, m->statusmessage_length); |
766 | memcpy(buf, m->statusmessage, msglen); | 766 | return m->statusmessage_length; |
767 | memset(buf + msglen, 0, maxlen - msglen); | ||
768 | return msglen; | ||
769 | } | 767 | } |
770 | 768 | ||
771 | uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber) | 769 | uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber) |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 91faff66..1139fb74 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -479,7 +479,7 @@ int m_get_self_statusmessage_size(const Messenger *m); | |||
479 | * retruns -1 on failure. | 479 | * retruns -1 on failure. |
480 | */ | 480 | */ |
481 | int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); | 481 | int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); |
482 | int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf, uint32_t maxlen); | 482 | int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf); |
483 | 483 | ||
484 | /* return one of USERSTATUS values. | 484 | /* return one of USERSTATUS values. |
485 | * Values unknown to your application should be represented as USERSTATUS_NONE. | 485 | * Values unknown to your application should be represented as USERSTATUS_NONE. |
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 | } | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index 056dcd31..2dc1594c 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -730,7 +730,6 @@ size_t tox_self_get_name_size(Tox const *tox); | |||
730 | */ | 730 | */ |
731 | void tox_self_get_name(Tox const *tox, uint8_t *name); | 731 | void tox_self_get_name(Tox const *tox, uint8_t *name); |
732 | 732 | ||
733 | |||
734 | /** | 733 | /** |
735 | * Set the client's status message. | 734 | * Set the client's status message. |
736 | * | 735 | * |
@@ -760,7 +759,7 @@ size_t tox_self_get_status_message_size(Tox const *tox); | |||
760 | * Call tox_self_status_message_size to find out how much memory to allocate for | 759 | * Call tox_self_status_message_size to find out how much memory to allocate for |
761 | * the result. | 760 | * the result. |
762 | * | 761 | * |
763 | * @param name A valid memory location large enough to hold the status message. | 762 | * @param status A valid memory location large enough to hold the status message. |
764 | * If this parameter is NULL, the function has no effect. | 763 | * If this parameter is NULL, the function has no effect. |
765 | */ | 764 | */ |
766 | void tox_self_get_status_message(Tox const *tox, uint8_t *status); | 765 | void tox_self_get_status_message(Tox const *tox, uint8_t *status); |