This commit is contained in:
irungentoo 2014-09-28 09:31:23 -04:00
commit 72d6a92efd
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
4 changed files with 49 additions and 19 deletions

View File

@ -560,19 +560,35 @@ int m_set_userstatus(Messenger *m, uint8_t status)
return 0;
}
int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length)
int m_unset_avatar(Messenger *m)
{
if (length > AVATAR_MAX_DATA_LENGTH)
return -1;
if (format == AVATAR_FORMAT_NONE) {
if (m->avatar_data != NULL)
free(m->avatar_data);
m->avatar_data = NULL;
m->avatar_data_length = 0;
m->avatar_format = format;
m->avatar_format = AVATAR_FORMAT_NONE;
memset(m->avatar_hash, 0, AVATAR_HASH_LENGTH);
} else {
if (length == 0 || data == NULL)
uint32_t i;
for (i = 0; i < m->numfriends; ++i)
m->friendlist[i].avatar_info_sent = 0;
return 0;
}
int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length)
{
if (format == AVATAR_FORMAT_NONE) {
m_unset_avatar(m);
return 0;
}
if (length > AVATAR_MAX_DATA_LENGTH || length == 0)
return -1;
if (data == NULL)
return -1;
uint8_t *tmp = realloc(m->avatar_data, length);
@ -586,7 +602,6 @@ int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t len
memcpy(m->avatar_data, data, length);
m_avatar_hash(m->avatar_hash, m->avatar_data, m->avatar_data_length);
}
uint32_t i;

View File

@ -496,6 +496,11 @@ uint8_t m_get_self_userstatus(const Messenger *m);
*/
int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length);
/* Unsets the user avatar.
returns 0 on success (currently always returns 0) */
int m_unset_avatar(Messenger *m);
/* Get avatar data from the current user.
* Copies the current user avatar data to the destination buffer and sets the image format
* accordingly.

View File

@ -833,6 +833,12 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt
return m_set_avatar(m, format, data, length);
}
int tox_unset_avatar(Tox *tox)
{
Messenger *m = tox;
return m_unset_avatar(m);
}
int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash)
{
const Messenger *m = tox;

View File

@ -590,6 +590,10 @@ void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint
*/
int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length);
/* Unsets the user avatar.
returns 0 on success (currently always returns 0) */
int tox_unset_avatar(Tox *tox);
/* Get avatar data from the current user.
* Copies the current user avatar data to the destination buffer and sets the image format