diff options
author | irungentoo <irungentoo@gmail.com> | 2014-09-28 09:31:23 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-09-28 09:31:23 -0400 |
commit | 72d6a92efd8cad191282c8a2e294a768c49d5f25 (patch) | |
tree | 01fc6c0c48bfdd7f0b53ff9914667720784fccbc | |
parent | 5550cc6f310877e060f8a663881072b2d4d1ee6f (diff) | |
parent | 83842e66487646f41788b2c311431ee1be2d4fe2 (diff) |
Merge branch 'unset_avatar' of https://github.com/JFreegman/toxcore
-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 c3f85beb..75210830 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -560,33 +560,48 @@ int m_set_userstatus(Messenger *m, uint8_t status) | |||
560 | return 0; | 560 | return 0; |
561 | } | 561 | } |
562 | 562 | ||
563 | int m_unset_avatar(Messenger *m) | ||
564 | { | ||
565 | if (m->avatar_data != NULL) | ||
566 | free(m->avatar_data); | ||
567 | |||
568 | m->avatar_data = NULL; | ||
569 | m->avatar_data_length = 0; | ||
570 | m->avatar_format = AVATAR_FORMAT_NONE; | ||
571 | memset(m->avatar_hash, 0, AVATAR_HASH_LENGTH); | ||
572 | |||
573 | uint32_t i; | ||
574 | |||
575 | for (i = 0; i < m->numfriends; ++i) | ||
576 | m->friendlist[i].avatar_info_sent = 0; | ||
577 | |||
578 | return 0; | ||
579 | } | ||
580 | |||
563 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) | 581 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) |
564 | { | 582 | { |
565 | if (length > AVATAR_MAX_DATA_LENGTH) | 583 | if (format == AVATAR_FORMAT_NONE) { |
584 | m_unset_avatar(m); | ||
585 | return 0; | ||
586 | } | ||
587 | |||
588 | if (length > AVATAR_MAX_DATA_LENGTH || length == 0) | ||
566 | return -1; | 589 | return -1; |
567 | 590 | ||
568 | if (format == AVATAR_FORMAT_NONE) { | 591 | if (data == NULL) |
569 | free(m->avatar_data); | 592 | return -1; |
570 | m->avatar_data = NULL; | ||
571 | m->avatar_data_length = 0; | ||
572 | m->avatar_format = format; | ||
573 | memset(m->avatar_hash, 0, AVATAR_HASH_LENGTH); | ||
574 | } else { | ||
575 | if (length == 0 || data == NULL) | ||
576 | return -1; | ||
577 | 593 | ||
578 | uint8_t *tmp = realloc(m->avatar_data, length); | 594 | uint8_t *tmp = realloc(m->avatar_data, length); |
579 | 595 | ||
580 | if (tmp == NULL) | 596 | if (tmp == NULL) |
581 | return -1; | 597 | return -1; |
582 | 598 | ||
583 | m->avatar_format = format; | 599 | m->avatar_format = format; |
584 | m->avatar_data = tmp; | 600 | m->avatar_data = tmp; |
585 | m->avatar_data_length = length; | 601 | m->avatar_data_length = length; |
586 | memcpy(m->avatar_data, data, length); | 602 | memcpy(m->avatar_data, data, length); |
587 | 603 | ||
588 | m_avatar_hash(m->avatar_hash, m->avatar_data, m->avatar_data_length); | 604 | m_avatar_hash(m->avatar_hash, m->avatar_data, m->avatar_data_length); |
589 | } | ||
590 | 605 | ||
591 | uint32_t i; | 606 | uint32_t i; |
592 | 607 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 38543b36..4a5a5ae7 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -496,6 +496,11 @@ uint8_t m_get_self_userstatus(const Messenger *m); | |||
496 | */ | 496 | */ |
497 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length); | 497 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length); |
498 | 498 | ||
499 | /* Unsets the user avatar. | ||
500 | |||
501 | returns 0 on success (currently always returns 0) */ | ||
502 | int m_unset_avatar(Messenger *m); | ||
503 | |||
499 | /* Get avatar data from the current user. | 504 | /* Get avatar data from the current user. |
500 | * Copies the current user avatar data to the destination buffer and sets the image format | 505 | * Copies the current user avatar data to the destination buffer and sets the image format |
501 | * accordingly. | 506 | * accordingly. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index e709ee89..19e1c0a4 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -833,6 +833,12 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt | |||
833 | return m_set_avatar(m, format, data, length); | 833 | return m_set_avatar(m, format, data, length); |
834 | } | 834 | } |
835 | 835 | ||
836 | int tox_unset_avatar(Tox *tox) | ||
837 | { | ||
838 | Messenger *m = tox; | ||
839 | return m_unset_avatar(m); | ||
840 | } | ||
841 | |||
836 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) | 842 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) |
837 | { | 843 | { |
838 | const Messenger *m = tox; | 844 | const Messenger *m = tox; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 4cde9455..ccb5a83e 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -590,6 +590,10 @@ void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint | |||
590 | */ | 590 | */ |
591 | int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length); | 591 | int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length); |
592 | 592 | ||
593 | /* Unsets the user avatar. | ||
594 | |||
595 | returns 0 on success (currently always returns 0) */ | ||
596 | int tox_unset_avatar(Tox *tox); | ||
593 | 597 | ||
594 | /* Get avatar data from the current user. | 598 | /* Get avatar data from the current user. |
595 | * Copies the current user avatar data to the destination buffer and sets the image format | 599 | * Copies the current user avatar data to the destination buffer and sets the image format |