1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-14 05:03:03 +01:00

fix a few avatar bugs

This commit is contained in:
Jfreegman 2015-04-04 21:15:34 -04:00 committed by cnhenry
parent 5496890b34
commit bbdf4c96b9
5 changed files with 16 additions and 17 deletions

View File

@ -27,6 +27,7 @@
#include "misc_tools.h"
#include "file_transfers.h"
#include "friendlist.h"
#include "avatars.h"
extern FriendsList Friends;
@ -36,7 +37,6 @@ static struct Avatar {
char path[PATH_MAX + 1];
size_t path_len;
off_t size;
bool is_set;
} Avatar;
@ -55,8 +55,7 @@ int avatar_send(Tox *m, uint32_t friendnum)
TOX_ERR_FILE_SEND err;
uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_AVATAR, (size_t) Avatar.size,
NULL, (uint8_t *) Avatar.name, Avatar.name_len, &err);
if (!Avatar.is_set)
if (Avatar.size == 0)
return 0;
if (err != TOX_ERR_FILE_SEND_OK) {
@ -74,14 +73,8 @@ int avatar_send(Tox *m, uint32_t friendnum)
if (ft->file == NULL)
return -1;
ft->file_size = Avatar.size;
if (ft->file_size == 0) {
fclose(ft->file);
return -1;
}
memcpy(ft->file_name, Avatar.name, Avatar.name_len + 1);
ft->file_size = Avatar.size;
ft->state = FILE_TRANSFER_PENDING;
ft->filenum = filenum;
ft->friendnum = friendnum;
@ -109,8 +102,6 @@ static void avatar_send_all(Tox *m)
*/
int avatar_set(Tox *m, const char *path, size_t path_len)
{
avatar_clear();
if (path_len == 0 || path_len >= sizeof(Avatar.path))
return -1;
@ -128,12 +119,16 @@ int avatar_set(Tox *m, const char *path, size_t path_len)
fclose(fp);
off_t size = file_size(path);
if (size == 0 || size > MAX_AVATAR_FILE_SIZE)
return -1;
get_file_name(Avatar.name, sizeof(Avatar.name), path);
Avatar.name_len = strlen(Avatar.name);
memcpy(Avatar.path, path, sizeof(Avatar.path));
Avatar.path_len = path_len;
Avatar.size = file_size(path);
Avatar.is_set = 1;
Avatar.size = size;
avatar_send_all(m);

View File

@ -23,6 +23,8 @@
#ifndef AVATARS_H
#define AVATARS_H
#define MAX_AVATAR_FILE_SIZE 65536
/* Sends avatar to friendnum.
*
* Returns 0 on success.

View File

@ -225,7 +225,9 @@ void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
get_file_name(filename, sizeof(filename), path);
if (avatar_set(m, path, len) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0,
"Failed to set avatar. Avatars must be in PNG format and may not exceed %d bytes.",
MAX_AVATAR_FILE_SIZE);
return;
}

View File

@ -144,7 +144,7 @@ static void help_draw_global(ToxWindow *self)
wprintw(win, " /add <addr> <msg> : Add contact with optional message\n");
wprintw(win, " /accept <id> : Accept friend request\n");
wprintw(win, " /avatar <path> : Set a personal avatar\n");
wprintw(win, " /avatar <path> : Set an avatar (leave path empty to unset)\n");
wprintw(win, " /decline <id> : Decline friend request\n");
wprintw(win, " /requests : List pending friend requests\n");
wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n");

View File

@ -123,8 +123,8 @@ void exit_toxic_success(Tox *m)
{
store_data(m, DATA_FILE);
memset(&user_password, 0, sizeof(struct user_password));
kill_all_windows(m);
kill_all_file_transfers(m);
kill_all_windows(m);
terminate_notify();
#ifdef AUDIO