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

merge with upstream

This commit is contained in:
Jfreegman 2015-04-07 17:28:12 -04:00
commit de38df32c2
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
7 changed files with 29 additions and 22 deletions

View File

@ -16,3 +16,8 @@ notifications:
on_success: always on_success: always
on_failure: always on_failure: always
irc:
channels:
- "chat.freenode.net#tox-groupchats"
on_success: always
on_failure: always

View File

@ -13,7 +13,8 @@ install: $(BUILD_DIR)/toxic
@for f in $(DATAFILES) ; do \ @for f in $(DATAFILES) ; do \
install -m 0644 $(MISC_DIR)/$$f $(abspath $(DESTDIR)/$(DATADIR)/$$f) ;\ install -m 0644 $(MISC_DIR)/$$f $(abspath $(DESTDIR)/$(DATADIR)/$$f) ;\
file=$(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 done
@mkdir -p $(abspath $(DESTDIR)/$(DATADIR))/sounds @mkdir -p $(abspath $(DESTDIR)/$(DATADIR))/sounds
@for f in $(SNDFILES) ; do \ @for f in $(SNDFILES) ; do \
@ -30,8 +31,10 @@ install: $(BUILD_DIR)/toxic
file=$$section/$$f ;\ file=$$section/$$f ;\
mkdir -p $$section ;\ mkdir -p $$section ;\
install -m 0644 $(DOC_DIR)/$$f $$file ;\ install -m 0644 $(DOC_DIR)/$$f $$file ;\
sed -i'' -e 's:__VERSION__:'$(VERSION)':g' $$file ;\ sed -e 's:__VERSION__:'$(VERSION)':g' $$file > temp_file && \
sed -i'' -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file ;\ mv temp_file $$file ;\
sed -e 's:__DATADIR__:'$(abspath $(DATADIR))':g' $$file > temp_file && \
mv temp_file $$file ;\
gzip -f -9 $$file ;\ gzip -f -9 $$file ;\
done done

View File

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

View File

@ -23,6 +23,8 @@
#ifndef AVATARS_H #ifndef AVATARS_H
#define AVATARS_H #define AVATARS_H
#define MAX_AVATAR_FILE_SIZE 65536
/* Sends avatar to friendnum. /* Sends avatar to friendnum.
* *
* Returns 0 on success. * 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); get_file_name(filename, sizeof(filename), path);
if (avatar_set(m, path, len) == -1) { 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; 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, " /add <addr> <msg> : Add contact with optional message\n");
wprintw(win, " /accept <id> : Accept friend request\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, " /decline <id> : Decline friend request\n");
wprintw(win, " /requests : List pending friend requests\n"); wprintw(win, " /requests : List pending friend requests\n");
wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n"); wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n");

View File

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