summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c53
1 files changed, 34 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
563int 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
563int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) 581int 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