diff options
-rw-r--r-- | toxcore/Messenger.c | 53 | ||||
-rw-r--r-- | toxcore/Messenger.h | 5 | ||||
-rw-r--r-- | toxcore/tox.c | 6 | ||||
-rw-r--r-- | toxcore/tox.h | 4 |
4 files changed, 49 insertions, 19 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 99b95f67..3fc2cc63 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -574,33 +574,48 @@ int m_set_userstatus(Messenger *m, uint8_t status) | |||
574 | return 0; | 574 | return 0; |
575 | } | 575 | } |
576 | 576 | ||
577 | int m_unset_avatar(Messenger *m) | ||
578 | { | ||
579 | if (m->avatar_data != NULL) | ||
580 | free(m->avatar_data); | ||
581 | |||
582 | m->avatar_data = NULL; | ||
583 | m->avatar_data_length = 0; | ||
584 | m->avatar_format = AVATAR_FORMAT_NONE; | ||
585 | memset(m->avatar_hash, 0, AVATAR_HASH_LENGTH); | ||
586 | |||
587 | uint32_t i; | ||
588 | |||
589 | for (i = 0; i < m->numfriends; ++i) | ||
590 | m->friendlist[i].avatar_info_sent = 0; | ||
591 | |||
592 | return 0; | ||
593 | } | ||
594 | |||
577 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) | 595 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) |
578 | { | 596 | { |
579 | if (length > AVATAR_MAX_DATA_LENGTH) | 597 | if (format == AVATAR_FORMAT_NONE) { |
598 | m_unset_avatar(m); | ||
599 | return 0; | ||
600 | } | ||
601 | |||
602 | if (length > AVATAR_MAX_DATA_LENGTH || length == 0) | ||
580 | return -1; | 603 | return -1; |
581 | 604 | ||
582 | if (format == AVATAR_FORMAT_NONE) { | 605 | if (data == NULL) |
583 | free(m->avatar_data); | 606 | return -1; |
584 | m->avatar_data = NULL; | ||
585 | m->avatar_data_length = 0; | ||
586 | m->avatar_format = format; | ||
587 | memset(m->avatar_hash, 0, AVATAR_HASH_LENGTH); | ||
588 | } else { | ||
589 | if (length == 0 || data == NULL) | ||
590 | return -1; | ||
591 | 607 | ||
592 | uint8_t *tmp = realloc(m->avatar_data, length); | 608 | uint8_t *tmp = realloc(m->avatar_data, length); |
593 | 609 | ||
594 | if (tmp == NULL) | 610 | if (tmp == NULL) |
595 | return -1; | 611 | return -1; |
596 | 612 | ||
597 | m->avatar_format = format; | 613 | m->avatar_format = format; |
598 | m->avatar_data = tmp; | 614 | m->avatar_data = tmp; |
599 | m->avatar_data_length = length; | 615 | m->avatar_data_length = length; |
600 | memcpy(m->avatar_data, data, length); | 616 | memcpy(m->avatar_data, data, length); |
601 | 617 | ||
602 | m_avatar_hash(m->avatar_hash, m->avatar_data, m->avatar_data_length); | 618 | m_avatar_hash(m->avatar_hash, m->avatar_data, m->avatar_data_length); |
603 | } | ||
604 | 619 | ||
605 | uint32_t i; | 620 | uint32_t i; |
606 | 621 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index e6877002..4a806e8c 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -518,6 +518,11 @@ uint8_t m_get_self_userstatus(const Messenger *m); | |||
518 | */ | 518 | */ |
519 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length); | 519 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length); |
520 | 520 | ||
521 | /* Unsets the user avatar. | ||
522 | |||
523 | returns 0 on success (currently always returns 0) */ | ||
524 | int m_unset_avatar(Messenger *m); | ||
525 | |||
521 | /* Get avatar data from the current user. | 526 | /* Get avatar data from the current user. |
522 | * Copies the current user avatar data to the destination buffer and sets the image format | 527 | * Copies the current user avatar data to the destination buffer and sets the image format |
523 | * accordingly. | 528 | * accordingly. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index e8ec593b..a0873a4c 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -820,6 +820,12 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt | |||
820 | return m_set_avatar(m, format, data, length); | 820 | return m_set_avatar(m, format, data, length); |
821 | } | 821 | } |
822 | 822 | ||
823 | int tox_unset_avatar(Tox *tox) | ||
824 | { | ||
825 | Messenger *m = tox; | ||
826 | return m_unset_avatar(m); | ||
827 | } | ||
828 | |||
823 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) | 829 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) |
824 | { | 830 | { |
825 | const Messenger *m = tox; | 831 | const Messenger *m = tox; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 61cfdf70..af6f282c 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -586,6 +586,10 @@ void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint | |||
586 | */ | 586 | */ |
587 | int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length); | 587 | int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length); |
588 | 588 | ||
589 | /* Unsets the user avatar. | ||
590 | |||
591 | returns 0 on success (currently always returns 0) */ | ||
592 | int tox_unset_avatar(Tox *tox); | ||
589 | 593 | ||
590 | /* Get avatar data from the current user. | 594 | /* Get avatar data from the current user. |
591 | * Copies the current user avatar data to the destination buffer and sets the image format | 595 | * Copies the current user avatar data to the destination buffer and sets the image format |