diff --git a/.travis.yml b/.travis.yml index a13045e..294c660 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,15 @@ script: notifications: email: false - - irc: + + irc: channels: - "chat.freenode.net#tox-groupchats" on_success: always on_failure: always + irc: + channels: + - "chat.freenode.net#tox-groupchats" + on_success: always + on_failure: always diff --git a/cfg/targets/install.mk b/cfg/targets/install.mk index cdc0067..12050ff 100644 --- a/cfg/targets/install.mk +++ b/cfg/targets/install.mk @@ -13,7 +13,8 @@ install: $(BUILD_DIR)/toxic @for f in $(DATAFILES) ; do \ install -m 0644 $(MISC_DIR)/$$f $(abspath $(DESTDIR)/$(DATADIR)/$$f) ;\ file=$(abspath $(DESTDIR)/$(DATADIR)/$$f) ;\ - sed -i'' -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file ;\ + sed -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file > temp_file && \ + mv temp_file $$file ;\ done @mkdir -p $(abspath $(DESTDIR)/$(DATADIR))/sounds @for f in $(SNDFILES) ; do \ @@ -30,8 +31,10 @@ install: $(BUILD_DIR)/toxic file=$$section/$$f ;\ mkdir -p $$section ;\ install -m 0644 $(DOC_DIR)/$$f $$file ;\ - sed -i'' -e 's:__VERSION__:'$(VERSION)':g' $$file ;\ - sed -i'' -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file ;\ + sed -e 's:__VERSION__:'$(VERSION)':g' $$file > temp_file && \ + mv temp_file $$file ;\ + sed -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file > temp_file && \ + mv temp_file $$file ;\ gzip -f -9 $$file ;\ done diff --git a/src/avatars.c b/src/avatars.c index fb7007d..8dfa302 100644 --- a/src/avatars.c +++ b/src/avatars.c @@ -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); diff --git a/src/avatars.h b/src/avatars.h index 4ef2c60..af3c4af 100644 --- a/src/avatars.h +++ b/src/avatars.h @@ -23,6 +23,8 @@ #ifndef AVATARS_H #define AVATARS_H +#define MAX_AVATAR_FILE_SIZE 65536 + /* Sends avatar to friendnum. * * Returns 0 on success. diff --git a/src/global_commands.c b/src/global_commands.c index 14dca74..76df5fc 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -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; } diff --git a/src/help.c b/src/help.c index e948380..b5c06e7 100644 --- a/src/help.c +++ b/src/help.c @@ -144,7 +144,7 @@ static void help_draw_global(ToxWindow *self) wprintw(win, " /add : Add contact with optional message\n"); wprintw(win, " /accept : Accept friend request\n"); - wprintw(win, " /avatar : Set a personal avatar\n"); + wprintw(win, " /avatar : Set an avatar (leave path empty to unset)\n"); wprintw(win, " /decline : Decline friend request\n"); wprintw(win, " /requests : List pending friend requests\n"); wprintw(win, " /connect : Manually connect to a DHT node\n"); diff --git a/src/toxic.c b/src/toxic.c index 33c1220..bf19d2f 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -124,8 +124,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