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

Fixed conflicts

This commit is contained in:
mannol 2014-07-10 01:29:18 +02:00
commit df676423a7
32 changed files with 614 additions and 543 deletions

View File

@ -1,7 +1,7 @@
# Toxic [![Build Status](https://travis-ci.org/Tox/toxic.png?branch=master)](https://travis-ci.org/Tox/toxic)
Toxic is an ncurses-based instant messaging client for [Tox](https://tox.im) which formerly resided in the [Tox core repository](https://github.com/irungentoo/toxcore), and is now available as a standalone application.
Toxic is a [Tox](https://tox.im)-based instant messenging client which formerly resided in the [Tox core repository](https://github.com/irungentoo/toxcore), and is now available as a standalone application.
![Toxic Screenshot](https://i.imgur.com/LdXXM62.png "Main Screen").
![Toxic Screenshot](https://i.imgur.com/YOZ5NIB.png "Main Screen").
## Installation
@ -23,6 +23,7 @@ Toxic is an ncurses-based instant messaging client for [Tox](https://tox.im) whi
* You can add specific flags to the Makefile with `USER_CFLAGS=""` and/or `USER_LDFLAGS=""`
* You can pass your own flags to the Makefile with `CFLAGS=""` and/or `LDFLAGS=""` (this will supersede the default ones)
* Audio call support is automatically enabled if all dependencies are found
* If you want to build toxic without audio call support, you can use `make DISABLE_AV=1`
### Packaging
* For packaging purpose, you can use `DESTDIR=""` to specify a directory where to store installed files

View File

@ -15,7 +15,7 @@ MANFILES = toxic.1 toxic.conf.5
LIBS = libtoxcore ncursesw
CFLAGS = -std=gnu99 -pthread -Wimplicit-function-declaration -Wreturn-type -O1
CFLAGS = -std=gnu99 -pthread -Wall
CFLAGS += -DTOXICVER="\"$(VERSION)\"" -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED
CFLAGS += -DPACKAGE_DATADIR="\"$(abspath $(DATADIR))\""
CFLAGS += $(USER_CFLAGS)
@ -35,6 +35,9 @@ UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S), Linux)
-include $(CFG_DIR)/Linux.mk
endif
ifeq ($(UNAME_S), FreeBSD)
-include $(CFG_DIR)/FreeBSD.mk
endif
ifeq ($(UNAME_S), Darwin)
-include $(CFG_DIR)/Darwin.mk
endif
@ -54,7 +57,8 @@ ifneq ($(filter arm%, $(UNAME_M)),)
-include $(CFG_DIR)/arm.mk
endif
# Check if we can build audio
# Check if we want/can build audio
ifneq ($(DISABLE_AV), 1)
CHECK_AUDIO_LIBS = $(shell pkg-config $(AUDIO_LIBS) || echo -n "error")
ifneq ($(CHECK_AUDIO_LIBS), error)
LIBS += $(AUDIO_LIBS)
@ -68,6 +72,7 @@ $(warning WARNING -- You need these libraries for audio support)
$(warning WARNING -- $(MISSING_AUDIO_LIBS))
endif
endif
endif
# Check if we can build Toxic
CHECK_LIBS = $(shell pkg-config $(LIBS) || echo -n "error")
@ -88,7 +93,8 @@ endif
all: toxic
toxic: $(OBJ)
$(CC) $(CFLAGS) -o toxic $(OBJ) $(LDFLAGS)
@echo " LD $@"
@$(CC) $(CFLAGS) -o toxic $(OBJ) $(LDFLAGS)
install: toxic
mkdir -p $(abspath $(DESTDIR)/$(BINDIR))
@ -112,8 +118,9 @@ install: toxic
done
%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -o $*.o -c $(SRC_DIR)/$*.c
$(CC) -MM $(CFLAGS) $(SRC_DIR)/$*.c > $*.d
@echo " CC $@"
@$(CC) $(CFLAGS) -o $*.o -c $(SRC_DIR)/$*.c
@$(CC) -MM $(CFLAGS) $(SRC_DIR)/$*.c > $*.d
clean:
rm -rf *.d *.o toxic
@ -122,4 +129,4 @@ clean:
-include $(OBJ:.o=.d)
.PHONY: clean all install
.PHONY: clean all install

3
cfg/FreeBSD.mk Normal file
View File

@ -0,0 +1,3 @@
# Specials options for freebsd systems
LIBS := $(filter-out ncursesw, $(LIBS))
LDFLAGS += -lncursesw

View File

@ -8,6 +8,7 @@ help:
@echo " help: This help"
@echo
@echo "-- Variables --"
@echo " DISABLE_AV: Set to \"1\" to force building without audio call support"
@echo " USER_CFLAGS: Add custom flags to default CFLAGS"
@echo " USER_LDFLAGS: Add custom flags to default LDFLAGS"
@echo " PREFIX: Specify a prefix directory for binaries, data files,... (default is \"$(abspath $(PREFIX))\")"

View File

@ -52,7 +52,7 @@
typedef struct _Call {
pthread_t ttid; /* Transmission thread id */
_Bool ttas, has_output; /* Transmission thread active status (0 - stopped, 1- running) */
int in_idx, out_idx;
uint32_t in_idx, out_idx;
pthread_mutex_t mutex;
} Call;
@ -97,7 +97,7 @@ void callback_peer_timeout ( int32_t call_index, void *arg );
int stop_transmission(int call_index);
void write_device_callback(ToxAv* av, int32_t call_index, int16_t* data, int size);
static void print_err (ToxWindow *self, uint8_t *error_str)
static void print_err (ToxWindow *self, char *error_str)
{
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
}
@ -105,7 +105,7 @@ static void print_err (ToxWindow *self, uint8_t *error_str)
ToxAv *init_audio(ToxWindow *self, Tox *tox)
{
ASettins.cs = av_DefaultSettings;
ASettins.cs.max_video_height= ASettins.cs.max_video_width = 0;
ASettins.cs.max_video_height = ASettins.cs.max_video_width = 0;
ASettins.errors = ae_None;
@ -324,8 +324,8 @@ void callback_peer_timeout ( int32_t call_index, void* arg )
*/
void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
char msg[MAX_STR_SIZE];
char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -362,7 +362,7 @@ on_error:
void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *error_str;
char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -393,7 +393,7 @@ on_error:
void cmd_reject(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *error_str;
char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -424,7 +424,7 @@ on_error:
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *error_str;
char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -453,7 +453,7 @@ on_error:
void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *error_str;
char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -486,8 +486,8 @@ on_error:
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
char msg[MAX_STR_SIZE];
char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -520,8 +520,8 @@ on_error:
/* This changes primary device only */
void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
char msg[MAX_STR_SIZE];
char *error_str;
if ( argc != 2 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -566,8 +566,8 @@ on_error:
void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
char msg[MAX_STR_SIZE];
char *error_str;
if ( argc != 2 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -635,8 +635,8 @@ void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (
void cmd_mute(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
char msg[MAX_STR_SIZE];
char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -682,9 +682,8 @@ void cmd_mute(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[
}
void cmd_sense(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
{
char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Must have value!";
@ -735,4 +734,4 @@ void stop_current_call(ToxWindow* self)
break;
}
}
}
}

View File

@ -62,7 +62,7 @@ static void kill_infobox(ToxWindow *self);
#endif /* _SUPPORT_AUDIO */
/* Array of chat command names used for tab completion. */
static const uint8_t chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/accept" },
{ "/add" },
{ "/clear" },
@ -104,15 +104,21 @@ static void set_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing)
ctx->self_is_typing = is_typing;
}
void kill_chat_window(ToxWindow *self, Tox *m)
static void chat_set_window_name(ToxWindow *self, char *nick, int len)
{
if (len > MAX_WINDOW_NAME_LENGTH) {
strcpy(&nick[MAX_WINDOW_NAME_LENGTH - 3], "...");
nick[MAX_WINDOW_NAME_LENGTH] = '\0';
}
snprintf(self->name, sizeof(self->name), "%s", nick);
}
void kill_chat_window(ToxWindow *self)
{
set_active_window(0);
ChatContext *ctx = self->chatwin;
StatusBar *statusbar = self->stb;
if (ctx->self_is_typing)
set_typingstatus(self, m, 0);
log_disable(ctx->log);
line_info_cleanup(ctx->hst);
@ -120,42 +126,34 @@ void kill_chat_window(ToxWindow *self, Tox *m)
stop_current_call(self);
#endif
int f_num = self->num;
delwin(ctx->linewin);
delwin(ctx->history);
delwin(self->window);
delwin(statusbar->topline);
del_window(self);
disable_chatwin(f_num);
free(ctx->log);
free(ctx->hst);
free(ctx);
free(self->help);
free(statusbar);
disable_chatwin(self->num);
del_window(self);
}
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const uint8_t *msg, uint16_t len)
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg, uint16_t len)
{
if (self->num != num)
return;
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_get_name(m, num, nick);
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, 0);
write_to_log(msg, nick, ctx->log, false);
alert_window(self, WINDOW_ALERT_1, true);
}
@ -184,20 +182,17 @@ static void chat_onTypingChange(ToxWindow *self, Tox *m, int32_t num, uint8_t is
friends[num].is_typing = is_typing;
}
static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const uint8_t *action, uint16_t len)
static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *action, uint16_t len)
{
if (self->num != num)
return;
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_get_name(m, num, nick);
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);;
nick[n_len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
@ -205,12 +200,23 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const uint8_t *a
alert_window(self, WINDOW_ALERT_1, true);
}
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const uint8_t *nick, uint16_t len)
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
{
if (self->num != num)
return;
snprintf(self->name, sizeof(self->name), "%s", nick);
if (len > TOX_MAX_NAME_LENGTH)
return;
StatusBar *statusbar = self->stb;
char tmpname[TOX_MAX_NAME_LENGTH];
strcpy(tmpname, nick);
int n_len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
tmpname[n_len] = '\0';
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", tmpname);
chat_set_window_name(self, tmpname, n_len);
}
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
@ -222,7 +228,7 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t st
statusbar->status = status;
}
static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const uint8_t *status, uint16_t len)
static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const char *status, uint16_t len)
{
if (self->num != num)
return;
@ -234,20 +240,20 @@ static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const uint8
}
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
uint64_t filesize, const uint8_t *pathname, uint16_t path_len)
uint64_t filesize, const char *pathname, uint16_t path_len)
{
if (self->num != num)
return;
uint8_t msg[MAX_STR_SIZE * 2];
uint8_t *errmsg;
char msg[MAX_STR_SIZE * 2];
char *errmsg;
/* holds the filename appended to the user specified path */
uint8_t filename_path[MAX_STR_SIZE] = {0};
char filename_path[MAX_STR_SIZE] = {0};
/* holds the lone filename */
uint8_t filename_nopath[MAX_STR_SIZE];
get_file_name(filename_nopath, pathname);
char filename_nopath[MAX_STR_SIZE];
get_file_name(filename_nopath, sizeof(filename_nopath), pathname);
int len = strlen(filename_nopath);
snprintf(msg, sizeof(msg), "File transfer request for '%s' (%llu bytes).", filename_nopath,
@ -272,7 +278,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
return;
}
uint8_t filename[MAX_STR_SIZE];
char filename[MAX_STR_SIZE];
if (filename_path[0])
strcpy(filename, filename_path);
@ -325,14 +331,14 @@ static void chat_close_file_receiver(int32_t num, uint8_t filenum)
}
static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t receive_send,
uint8_t filenum, uint8_t control_type, const uint8_t *data, uint16_t length)
uint8_t filenum, uint8_t control_type, const char *data, uint16_t length)
{
if (self->num != num)
return;
const uint8_t *filename;
uint8_t msg[MAX_STR_SIZE] = {0};
int i; /* file_sender index */
const char *filename;
char msg[MAX_STR_SIZE] = {0};
int i = 0; /* file_sender index */
if (receive_send == 0) {
filename = friends[num].file_receiver.filenames[filenum];
@ -375,7 +381,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
alert_window(self, WINDOW_ALERT_2, true);
}
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const uint8_t *data,
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
uint16_t length)
{
if (self->num != num)
@ -400,30 +406,29 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
uint64_t size = friends[num].file_receiver.size[filenum];
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
uint8_t msg[MAX_STR_SIZE];
const uint8_t *name = friends[num].file_receiver.filenames[filenum];
char msg[MAX_STR_SIZE];
const char *name = friends[num].file_receiver.filenames[filenum];
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
}
}
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, const uint8_t *group_pub_key)
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, const char *group_pub_key)
{
if (self->num != friendnumber)
return;
uint8_t name[TOX_MAX_NAME_LENGTH];
uint8_t msg[MAX_STR_SIZE + TOX_MAX_NAME_LENGTH];
int n_len = tox_get_name(m, friendnumber, name);
char msg[MAX_STR_SIZE + TOX_MAX_NAME_LENGTH];
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
name[n_len] = '\0';
char name[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, name, friendnumber);
snprintf(msg, sizeof(msg), "%s has invited you to a group chat.", name);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, "Type \"/join\" to join the chat.", SYS_MSG, 0, 0);
memcpy(friends[friendnumber].groupchat_key, group_pub_key, TOX_CLIENT_ID_SIZE);
memcpy(friends[friendnumber].groupchat_key, group_pub_key,
sizeof(friends[friendnumber].groupchat_key));
friends[friendnumber].groupchat_pending = true;
alert_window(self, WINDOW_ALERT_2, true);
@ -440,9 +445,7 @@ void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
/* call_index is set here and reset on call end */
self->call_idx = call_index;
line_info_add(self, NULL, NULL, NULL, "Incoming audio call! Type: \"/answer\" or \"/reject\"", SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_0, true);
}
@ -547,6 +550,7 @@ static void init_infobox(ToxWindow *self)
int x2, y2;
getmaxyx(self->window, y2, x2);
(void) y2;
memset(&ctx->infobox, 0, sizeof(struct infobox));
@ -624,22 +628,22 @@ static void draw_infobox(ToxWindow *self)
#endif /* _SUPPORT_AUDIO */
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action)
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
{
if (action == NULL)
return;
uint8_t selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, selfname);
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
selfname[len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, action, ACTION, 0, 0);
if (tox_send_action(m, self->num, action, strlen(action)) == 0) {
uint8_t *errmsg = " * Failed to send action.";
if (tox_send_action(m, self->num, (uint8_t *) action, strlen(action)) == 0) {
char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, selfname, NULL, errmsg, SYS_MSG, 0, RED);
} else {
write_to_log(action, selfname, ctx->log, true);
@ -694,7 +698,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else if (key == '\n') {
rm_trailing_spaces_buf(ctx);
uint8_t line[MAX_STR_SIZE];
char line[MAX_STR_SIZE];
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1)
memset(&line, 0, sizeof(line));
@ -704,7 +708,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (line[0] == '/') {
if (strcmp(line, "/close") == 0) {
kill_chat_window(self, m);
kill_chat_window(self);
return;
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
send_action(self, ctx, m, line + strlen("/me "));
@ -712,17 +716,17 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
}
} else if (!string_is_empty(line)) {
uint8_t selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, selfname);
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
selfname[len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, line, OUT_MSG, 0, 0);
if (!statusbar->is_online || tox_send_message(m, self->num, line, strlen(line)) == 0) {
uint8_t *errmsg = " * Failed to send message.";
if (!statusbar->is_online || tox_send_message(m, self->num, (uint8_t *) line, strlen(line)) == 0) {
char *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
} else {
write_to_log(line, selfname, ctx->log, false);
@ -789,7 +793,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, " %s ", self->name);
wprintw(statusbar->topline, " %s ", statusbar->nick);
wattroff(statusbar->topline, A_BOLD);
if (friends[self->num].is_typing)
@ -797,16 +801,16 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
} else {
wprintw(statusbar->topline, " o");
wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, " %s ", self->name);
wprintw(statusbar->topline, " %s ", statusbar->nick);
wattroff(statusbar->topline, A_BOLD);
}
/* Reset statusbar->statusmsg on window resize */
if (x2 != self->x) {
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
pthread_mutex_lock(&Winthread.lock);
tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
pthread_mutex_unlock(&Winthread.lock);
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
@ -841,20 +845,21 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
int y, x;
getyx(self->window, y, x);
(void) x;
int new_x = ctx->start ? x2 - 1 : ctx->pos;
wmove(self->window, y + 1, new_x);
#ifdef _SUPPORT_AUDIO
wrefresh(self->window);
if (ctx->infobox.active)
#ifdef _SUPPORT_AUDIO
if (ctx->infobox.active) {
draw_infobox(self);
wrefresh(self->window);
}
#endif
if (self->help->active) {
wrefresh(self->window);
if (self->help->active)
help_onDraw(self);
}
}
static void chat_onInit(ToxWindow *self, Tox *m)
@ -870,12 +875,17 @@ static void chat_onInit(ToxWindow *self, Tox *m)
statusbar->status = tox_get_user_status(m, self->num);
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
uint16_t s_len = tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
uint16_t s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
statusmsg[s_len] = '\0';
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
statusbar->statusmsg_len = s_len;
char nick[TOX_MAX_NAME_LENGTH];
int n_len = get_nick_truncate(m, nick, self->num);
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
statusbar->nick_len = n_len;
/* Init subwindows */
ChatContext *ctx = self->chatwin;
@ -883,15 +893,12 @@ static void chat_onInit(ToxWindow *self, Tox *m)
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
ctx->hst = malloc(sizeof(struct history));
ctx->log = malloc(sizeof(struct chatlog));
ctx->hst = calloc(1, sizeof(struct history));
ctx->log = calloc(1, sizeof(struct chatlog));
if (ctx->log == NULL || ctx->hst == NULL)
exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);
memset(ctx->hst, 0, sizeof(struct history));
memset(ctx->log, 0, sizeof(struct chatlog));
line_info_init(ctx->hst);
if (friends[self->num].logging_on)
@ -943,13 +950,9 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
ret.device_selection[0] = ret.device_selection[1] = -1;
#endif /* _SUPPORT_AUDIO */
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
int len = tox_get_name(m, friendnum, name);
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
name[len] = '\0';
strcpy(ret.name, name);
char nick[TOX_MAX_NAME_LENGTH];
int n_len = get_nick_truncate(m, nick, friendnum);
chat_set_window_name(&ret, nick, n_len);
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
StatusBar *stb = calloc(1, sizeof(StatusBar));

View File

@ -40,7 +40,7 @@ extern uint8_t max_file_senders_index;
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (argc < 1) {
errmsg = "Invalid syntax";
@ -62,14 +62,14 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
return;
}
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Invited friend to Room #%d.", groupnum);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open.";
@ -77,7 +77,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
return;
}
uint8_t *groupkey = friends[self->num].groupchat_key;
char *groupkey = friends[self->num].groupchat_key;
if (!friends[self->num].groupchat_pending) {
errmsg = "No pending group chat invite.";
@ -85,7 +85,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
return;
}
int groupnum = tox_join_groupchat(m, self->num, groupkey);
int groupnum = tox_join_groupchat(m, self->num, (uint8_t *) groupkey);
if (groupnum == -1) {
errmsg = "Group chat instance failed to initialize.";
@ -103,7 +103,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (argc != 1) {
errmsg = "Invalid syntax.";
@ -125,10 +125,10 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
return;
}
uint8_t *filename = friends[self->num].file_receiver.filenames[filenum];
char *filename = friends[self->num].file_receiver.filenames[filenum];
if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) {
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1f%%)", filename, 0.0);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 1;
@ -148,7 +148,7 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (max_file_senders_index >= (MAX_FILES - 1)) {
errmsg = "Please wait for some of your outgoing file transfers to complete.";
@ -162,7 +162,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
return;
}
uint8_t *path = argv[1];
char *path = argv[1];
if (path[0] != '\"') {
errmsg = "File path must be enclosed in quotes.";
@ -170,8 +170,9 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
return;
}
path[strlen(++path) - 1] = L'\0';
int path_len = strlen(path);
++path;
int path_len = strlen(path) - 1;
path[path_len] = '\0';
if (path_len > MAX_STR_SIZE) {
errmsg = "File path exceeds character limit.";
@ -191,9 +192,9 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
uint64_t filesize = ftell(file_to_send);
fseek(file_to_send, 0, SEEK_SET);
uint8_t filename[MAX_STR_SIZE];
get_file_name(filename, path);
int filenum = tox_new_file_sender(m, self->num, filesize, filename, strlen(filename));
char filename[MAX_STR_SIZE];
get_file_name(filename, sizeof(filename), path);
int filenum = tox_new_file_sender(m, self->num, filesize, (const uint8_t *) filename, strlen(filename));
if (filenum == -1) {
errmsg = "Error sending file.";
@ -216,7 +217,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, self->num), file_to_send);
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Sending file: '%s'", path);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);

View File

@ -63,8 +63,8 @@ typedef struct _Device {
const char *ddevice_names[2]; /* Default device */
const char *devices_names[2][MAX_DEVICES]; /* Container of available devices */
static int size[2]; /* Size of above containers */
Device *running[2][MAX_DEVICES]={NULL}; /* Running devices */
uint32_t primary_device[2] = {0}; /* Primary device */
Device *running[2][MAX_DEVICES]; /* Running devices */
uint32_t primary_device[2]; /* Primary device */
static ToxAv* av = NULL;
@ -117,7 +117,7 @@ DeviceError init_devices(ToxAv* av_)
av = av_;
return ae_None;
return (DeviceError) ae_None;
}
DeviceError terminate_devices()
@ -128,7 +128,7 @@ DeviceError terminate_devices()
pthread_mutex_destroy(&mutex);
return ae_None;
return (DeviceError) ae_None;
}
DeviceError device_mute(DeviceType type, uint32_t device_idx)
@ -410,7 +410,7 @@ void print_devices(ToxWindow* self, DeviceType type)
{
int i = 0;
for ( ; i < size[type]; i ++) {
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "%d: %s", i, devices_names[type][i]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
@ -429,4 +429,4 @@ void* get_device_callback_data(uint32_t device_idx)
return NULL;
return running[input][device_idx]->cb_data;
}
}

View File

@ -81,4 +81,4 @@ DeviceError write_out(uint32_t device_idx, int16_t* data, uint32_t lenght, uint8
void print_devices(ToxWindow* self, DeviceType type);
DeviceError selection_valid(DeviceType type, int32_t selection);
#endif /* _device_h */
#endif /* _device_h */

View File

@ -45,10 +45,12 @@
#define TOX_DNS3_TXT_PREFIX "v=tox3;id="
#define DNS3_KEY_SZ 32
extern struct _Winthread Winthread;
/* TODO: process keys from key file instead of hard-coding like a noob */
static struct dns3_server {
uint8_t *name;
uint8_t key[DNS3_KEY_SZ];
char *name;
char key[DNS3_KEY_SZ];
} dns3_servers[] = {
{
"utox.org",
@ -68,27 +70,26 @@ static struct dns3_server {
static struct _thread_data {
ToxWindow *self;
uint8_t id_bin[TOX_FRIEND_ADDRESS_SIZE];
uint8_t addr[MAX_STR_SIZE];
uint8_t msg[MAX_STR_SIZE];
char id_bin[TOX_FRIEND_ADDRESS_SIZE];
char addr[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
uint8_t busy;
Tox *m;
} t_data;
static struct _dns_thread {
pthread_t tid;
pthread_mutex_t lock;
} dns_thread;
static int dns_error(ToxWindow *self, uint8_t *errmsg)
static int dns_error(ToxWindow *self, char *errmsg)
{
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "User lookup failed: %s", errmsg);
pthread_mutex_lock(&dns_thread.lock);
pthread_mutex_lock(&Winthread.lock);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
pthread_mutex_unlock(&dns_thread.lock);
pthread_mutex_unlock(&Winthread.lock);
return -1;
}
@ -103,11 +104,11 @@ static void kill_dns_thread(void *dns_obj)
}
/* puts TXT from dns response in buf. Returns length of TXT on success, -1 on fail.*/
static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, uint8_t *buf)
static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, char *buf)
{
uint8_t *ans_pt = answer + sizeof(HEADER);
uint8_t *ans_end = answer + ans_len;
uint8_t exp_ans[PACKETSZ];
char exp_ans[PACKETSZ];
int len = dn_expand(answer, ans_end, ans_pt, exp_ans, sizeof(exp_ans));
@ -171,10 +172,10 @@ static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, uint
and the domain in dombuf.
return length of username on success, -1 on failure */
static int parse_addr(uint8_t *addr, uint8_t *namebuf, uint8_t *dombuf)
static int parse_addr(char *addr, char *namebuf, char *dombuf)
{
uint8_t tmpaddr[MAX_STR_SIZE];
uint8_t *tmpname, *tmpdom;
char tmpaddr[MAX_STR_SIZE];
char *tmpname, *tmpdom;
strcpy(tmpaddr, addr);
tmpname = strtok(tmpaddr, "@");
@ -195,8 +196,8 @@ void *dns3_lookup_thread(void *data)
{
ToxWindow *self = t_data.self;
uint8_t domain[MAX_STR_SIZE];
uint8_t name[MAX_STR_SIZE];
char domain[MAX_STR_SIZE];
char name[MAX_STR_SIZE];
int namelen = parse_addr(t_data.addr, name, domain);
@ -206,7 +207,8 @@ void *dns3_lookup_thread(void *data)
}
/* get domain name/pub key */
uint8_t *DNS_pubkey, *domname = NULL;
char *DNS_pubkey = NULL;
char *domname = NULL;
int i;
for (i = 0; i < NUM_DNS3_SERVERS; ++i) {
@ -222,17 +224,18 @@ void *dns3_lookup_thread(void *data)
kill_dns_thread(NULL);
}
void *dns_obj = tox_dns3_new(DNS_pubkey);
void *dns_obj = tox_dns3_new((uint8_t *) DNS_pubkey);
if (dns_obj == NULL) {
dns_error(self, "Core failed to create DNS object.");
kill_dns_thread(NULL);
}
uint8_t string[MAX_DNS_REQST_SIZE];
char string[MAX_DNS_REQST_SIZE];
uint32_t request_id;
int str_len = tox_generate_dns3_string(dns_obj, string, sizeof(string), &request_id, name, namelen);
int str_len = tox_generate_dns3_string(dns_obj, (uint8_t *) string, sizeof(string), &request_id,
(uint8_t *) name, namelen);
if (str_len == -1) {
dns_error(self, "Core failed to generate DNS3 string.");
@ -242,7 +245,7 @@ void *dns3_lookup_thread(void *data)
string[str_len] = '\0';
u_char answer[PACKETSZ];
uint8_t d_string[MAX_DNS_REQST_SIZE];
char d_string[MAX_DNS_REQST_SIZE];
/* format string and create dns query */
snprintf(d_string, sizeof(d_string), "_%s._tox.%s", string, domname);
@ -253,13 +256,13 @@ void *dns3_lookup_thread(void *data)
kill_dns_thread(dns_obj);
}
uint8_t ans_id[MAX_DNS_REQST_SIZE];
char ans_id[MAX_DNS_REQST_SIZE];
/* extract TXT from DNS response */
if (parse_dns_response(self, answer, ans_len, ans_id) == -1)
kill_dns_thread(dns_obj);
uint8_t encrypted_id[MAX_DNS_REQST_SIZE];
char encrypted_id[MAX_DNS_REQST_SIZE];
int prfx_len = strlen(TOX_DNS3_TXT_PREFIX);
/* extract the encrypted ID from TXT response */
@ -270,24 +273,25 @@ void *dns3_lookup_thread(void *data)
memcpy(encrypted_id, ans_id + prfx_len, ans_len - prfx_len);
if (tox_decrypt_dns3_TXT(dns_obj, t_data.id_bin, encrypted_id, strlen(encrypted_id), request_id) == -1) {
if (tox_decrypt_dns3_TXT(dns_obj, (uint8_t *) t_data.id_bin, (uint8_t *) encrypted_id,
strlen(encrypted_id), request_id) == -1) {
dns_error(self, "Core failed to decrypt DNS response.");
kill_dns_thread(dns_obj);
}
pthread_mutex_lock(&dns_thread.lock);
pthread_mutex_lock(&Winthread.lock);
cmd_add_helper(self, t_data.m, t_data.id_bin, t_data.msg);
pthread_mutex_unlock(&dns_thread.lock);
pthread_mutex_unlock(&Winthread.lock);
kill_dns_thread(dns_obj);
return 0;
}
/* creates new thread for dns3 lookup. Only allows one lookup at a time. */
void dns3_lookup(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *addr, uint8_t *msg)
void dns3_lookup(ToxWindow *self, Tox *m, char *id_bin, char *addr, char *msg)
{
if (t_data.busy) {
uint8_t *err = "Please wait for previous user lookup to finish.";
char *err = "Please wait for previous user lookup to finish.";
line_info_add(self, NULL, NULL, NULL, err, SYS_MSG, 0, 0);
return;
}
@ -299,9 +303,10 @@ void dns3_lookup(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *addr, uint8_
t_data.m = m;
t_data.busy = 1;
pthread_mutex_unlock(&Winthread.lock);
if (pthread_create(&dns_thread.tid, NULL, dns3_lookup_thread, NULL) != 0)
exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_CREATE);
if (pthread_mutex_init(&dns_thread.lock, NULL) != 0)
exit_toxic_err("failed in dns3_lookup", FATALERR_MUTEX_INIT);
pthread_mutex_lock(&Winthread.lock);
}

View File

@ -27,6 +27,6 @@
#define _dns_h
/* creates new thread for dns3 lookup. Only allows one lookup at a time. */
void dns3_lookup(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *addr, uint8_t *msg);
void dns3_lookup(ToxWindow *self, Tox *m, char *id_bin, char *addr, char *msg);
#endif /* #define _dns_h */

View File

@ -91,7 +91,7 @@ static int parse_command(WINDOW *w, ToxWindow *self, char *cmd, char (*args)[MAX
end = strchr(cmd + 1, '\"');
if (end++ == NULL) { /* Increment past the end quote */
uint8_t *errmsg = "Invalid argument. Did you forget a closing \"?";
char *errmsg = "Invalid argument. Did you forget a closing \"?";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
return -1;
}
@ -134,7 +134,7 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, char *cmd, int mode)
if (string_is_empty(cmd))
return;
char args[MAX_NUM_ARGS][MAX_STR_SIZE] = {0};
char args[MAX_NUM_ARGS][MAX_STR_SIZE];
int num_args = parse_command(w, self, cmd, args);
if (num_args == -1)
@ -158,6 +158,5 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, char *cmd, int mode)
if (do_command(w, self, m, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
return;
uint8_t *errmsg = "Invalid command.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, "Invalid command.", SYS_MSG, 0, 0);
}

View File

@ -46,7 +46,7 @@ static void set_max_file_senders_index(void)
max_file_senders_index = j;
}
static void close_file_sender(ToxWindow *self, Tox *m, int i, uint8_t *msg, int CTRL, int filenum, int32_t friendnum)
static void close_file_sender(ToxWindow *self, Tox *m, int i, char *msg, int CTRL, int filenum, int32_t friendnum)
{
if (self->chatwin != NULL) {
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
@ -77,7 +77,7 @@ void close_all_file_senders(Tox *m)
void do_file_senders(Tox *m)
{
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
int i;
for (i = 0; i < max_file_senders_index; ++i) {
@ -85,7 +85,7 @@ void do_file_senders(Tox *m)
continue;
ToxWindow *self = file_senders[i].toxwin;
uint8_t *pathname = file_senders[i].pathname;
char *pathname = file_senders[i].pathname;
int filenum = file_senders[i].filenum;
int32_t friendnum = file_senders[i].friendnum;
FILE *fp = file_senders[i].file;
@ -98,7 +98,7 @@ void do_file_senders(Tox *m)
}
while (true) {
if (tox_file_send_data(m, friendnum, filenum, file_senders[i].nextpiece,
if (tox_file_send_data(m, friendnum, filenum, (uint8_t *) file_senders[i].nextpiece,
file_senders[i].piecelen) == -1)
break;

View File

@ -27,7 +27,7 @@
#include "windows.h"
#define FILE_PIECE_SIZE 2048 /* must be >= (MAX_CRYPTO_DATA_SIZE - 2) in toxcore/net_crypto.h */
#define MAX_FILES 256
#define MAX_FILES 255
#define TIMEOUT_FILESENDER 120
typedef struct {
@ -36,9 +36,9 @@ typedef struct {
int32_t friendnum;
bool active;
int filenum;
uint8_t nextpiece[FILE_PIECE_SIZE];
char nextpiece[FILE_PIECE_SIZE];
uint16_t piecelen;
uint8_t pathname[MAX_STR_SIZE];
char pathname[MAX_STR_SIZE];
uint64_t timestamp;
uint64_t last_progress;
uint64_t size;

View File

@ -96,7 +96,7 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp)
&friends[num].last_online.tm);
}
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const uint8_t *str, uint16_t len)
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *str, uint16_t len)
{
if (num >= max_friends_index)
return;
@ -105,17 +105,15 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const uin
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} else {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
int n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(prompt, timefrmt, nick, NULL, str, IN_MSG, 0, 0);
uint8_t *msg = "* Warning: Too many windows are open.";
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
}
@ -133,13 +131,17 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num,
sort_friendlist_index();
}
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const uint8_t *nick, uint16_t len)
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
{
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
return;
snprintf(friends[num].name, sizeof(friends[num].name), "%s", nick);
friends[num].namelength = strlen(friends[num].name);
char tempname[TOX_MAX_NAME_LENGTH];
strcpy(tempname, nick);
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
tempname[len] = '\0';
snprintf(friends[num].name, sizeof(friends[num].name), "%s", tempname);
friends[num].namelength = len;
sort_friendlist_index();
}
@ -151,7 +153,7 @@ static void friendlist_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint
friends[num].status = status;
}
static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, const uint8_t *status, uint16_t len)
static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, const char *status, uint16_t len)
{
if (len > TOX_MAX_STATUSMESSAGE_LENGTH || num >= max_friends_index)
return;
@ -174,17 +176,19 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
friends[i].chatwin = -1;
friends[i].online = false;
friends[i].status = TOX_USERSTATUS_NONE;
friends[i].namelength = tox_get_name(m, num, friends[i].name);
friends[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
tox_get_client_id(m, num, friends[i].pub_key);
tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key);
update_friend_last_online(i, tox_get_last_online(m, i));
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME);
char tempname[TOX_MAX_NAME_LENGTH] = {0};
int len = get_nick_truncate(m, tempname, num);
if (len == -1 || tempname[0] == '\0') {
strcpy(friends[i].name, UNKNOWN_NAME);
friends[i].namelength = strlen(UNKNOWN_NAME);
} else { /* Enforce toxic's maximum name length */
friends[i].namelength = MIN(friends[i].namelength, TOXIC_MAX_NAME_LENGTH);
friends[i].name[friends[i].namelength] = '\0';
friends[i].namelength = len;
snprintf(friends[i].name, sizeof(friends[i].name), "%s", tempname);
}
num_friends = tox_count_friendlist(m);
@ -201,7 +205,7 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
}
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
uint64_t filesize, const uint8_t *filename, uint16_t filename_len)
uint64_t filesize, const char *filename, uint16_t filename_len)
{
if (num >= max_friends_index)
return;
@ -212,12 +216,10 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
} else {
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
uint8_t nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
@ -226,7 +228,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
}
}
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const uint8_t *group_pub_key)
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const char *group_pub_key)
{
if (num >= max_friends_index)
return;
@ -235,12 +237,10 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} else {
uint8_t nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
@ -285,7 +285,7 @@ static void delete_friend(Tox *m, int32_t f_num)
/* activates delete friend popup */
static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num)
{
pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH - 1, 8, 8);
pendingdelete.active = true;
pendingdelete.num = f_num;
}
@ -345,7 +345,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
set_active_window(friends[f].chatwin);
} else {
uint8_t *msg = "* Warning: Too many windows are open.";
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
@ -458,10 +458,10 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
/* Reset friends[f].statusmsg on window resize */
if (fix_statuses) {
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
pthread_mutex_lock(&Winthread.lock);
tox_get_status_message(m, friends[f].num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
tox_get_status_message(m, friends[f].num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
pthread_mutex_unlock(&Winthread.lock);
snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg);
@ -499,7 +499,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
if (last_seen != 0) {
int day_dist = (cur_loc_tm.tm_yday - friends[f].last_online.tm.tm_yday) % 365;
const uint8_t *hourmin = friends[f].last_online.hour_min_str;
const char *hourmin = friends[f].last_online.hour_min_str;
switch (day_dist) {
case 0:
@ -522,8 +522,6 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
}
self->x = x2;
wrefresh(self->window);
draw_popup();
if (num_friends) {
wmove(self->window, y2 - 1, 1);
@ -537,6 +535,9 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
for (i = 0; i < TOX_CLIENT_ID_SIZE; ++i)
wprintw(self->window, "%02X", friends[selected_num].pub_key[i] & 0xff);
}
wrefresh(self->window);
draw_popup();
}
void disable_chatwin(int32_t f_num)
@ -560,17 +561,14 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
if (toxav_get_call_state(av, call_index) == av_CallStarting) /* Only open windows when call is incoming */
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
} else {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
int n_len = tox_get_name(m, id, nick);
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, friends[id].num);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Audio action from: %s!", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
uint8_t *errmsg = "* Warning: Too many windows are open.";
char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_0, true);

View File

@ -30,7 +30,7 @@
#include "file_senders.h"
struct FileReceiver {
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
char filenames[MAX_FILES][MAX_STR_SIZE];
FILE *files[MAX_FILES];
bool pending[MAX_FILES];
uint64_t size[MAX_FILES];
@ -41,17 +41,17 @@ struct FileReceiver {
struct LastOnline {
uint64_t last_on;
struct tm tm;
uint8_t hour_min_str[TIME_STR_SIZE]; /* holds 12/24-hour time string e.g. "10:43 PM" */
char hour_min_str[TIME_STR_SIZE]; /* holds 12/24-hour time string e.g. "10:43 PM" */
};
typedef struct {
uint8_t name[TOX_MAX_NAME_LENGTH];
uint16_t namelength;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
char name[TOXIC_MAX_NAME_LENGTH];
int namelength;
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmsg_len;
uint8_t groupchat_key[TOX_CLIENT_ID_SIZE];
char groupchat_key[TOX_CLIENT_ID_SIZE];
bool groupchat_pending;
uint8_t pub_key[TOX_CLIENT_ID_SIZE];
char pub_key[TOX_CLIENT_ID_SIZE];
int32_t num;
int chatwin;
bool active;

View File

@ -40,13 +40,13 @@ extern ToxWindow *prompt;
extern ToxicFriend friends[MAX_FRIENDS_NUM];
extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern char pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_frnd_requests;
/* command functions */
void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *msg;
char *msg;
if (argc != 1) {
msg = "Invalid syntax.";
@ -68,7 +68,7 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
return;
}
int32_t friendnum = tox_add_friend_norequest(m, pending_frnd_requests[req]);
int32_t friendnum = tox_add_friend_norequest(m, (uint8_t *) pending_frnd_requests[req]);
if (friendnum == -1)
msg = "Failed to add friend.";
@ -90,10 +90,10 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
void cmd_add_helper(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *msg)
void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
{
uint8_t *errmsg;
int32_t f_num = tox_add_friend(m, id_bin, msg, strlen(msg));
char *errmsg;
int32_t f_num = tox_add_friend(m, (uint8_t *) id_bin, (uint8_t *) msg, (uint16_t) strlen(msg));
switch (f_num) {
case TOX_FAERR_TOOLONG:
@ -135,7 +135,7 @@ void cmd_add_helper(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *msg)
void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (argc < 1) {
errmsg = "Invalid syntax.";
@ -144,10 +144,10 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
}
char *id = argv[1];
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
if (argc > 1) {
uint8_t *temp = argv[2];
char *temp = argv[2];
if (temp[0] != '\"') {
errmsg = "Message must be enclosed in quotes.";
@ -155,17 +155,18 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
return;
}
temp[strlen(++temp) - 1] = L'\0';
++temp;
temp[strlen(temp) - 1] = '\0';
snprintf(msg, sizeof(msg), "%s", temp);
} else {
uint8_t selfname[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, selfname);
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfname);
selfname[n_len] = '\0';
snprintf(msg, sizeof(msg), "Hello, my name is %s. Care to Tox?", selfname);
}
uint8_t id_bin[TOX_FRIEND_ADDRESS_SIZE] = {0};
uint16_t id_len = strlen(id);
char id_bin[TOX_FRIEND_ADDRESS_SIZE] = {0};
uint16_t id_len = (uint16_t) strlen(id);
/* try to add tox ID */
if (id_len == 2 * TOX_FRIEND_ADDRESS_SIZE) {
@ -203,7 +204,7 @@ void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
/* check arguments */
if (argc != 3) {
@ -212,9 +213,9 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
return;
}
char *ip = argv[1];
char *port = argv[2];
char *key = argv[3];
const char *ip = argv[1];
const char *port = argv[2];
const char *key = argv[3];
if (atoi(port) == 0) {
errmsg = "Invalid syntax.";
@ -222,15 +223,14 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
return;
}
uint8_t *binary_string = hex_string_to_bin(key);
tox_bootstrap_from_address(m, ip, TOX_ENABLE_IPV6_DEFAULT,
htons(atoi(port)), binary_string);
char *binary_string = hex_string_to_bin(key);
tox_bootstrap_from_address(m, ip, TOX_ENABLE_IPV6_DEFAULT, htons(atoi(port)), (uint8_t *) binary_string);
free(binary_string);
}
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open.";
@ -253,14 +253,14 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
return;
}
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Group chat created as %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *msg;
char *msg;
struct chatlog *log = self->chatwin->log;
if (argc == 0) {
@ -273,7 +273,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
return;
}
uint8_t *swch = argv[1];
char *swch = argv[1];
if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
@ -281,8 +281,8 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
friends[self->num].logging_on = true;
log_enable(self->name, friends[self->num].pub_key, log);
} else if (self->is_prompt) {
uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, myid);
char myid[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, (uint8_t *) myid);
log_enable(self->name, myid, log);
} else if (self->is_groupchat) {
log_enable(self->name, NULL, log);
@ -309,8 +309,8 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0};
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, address);
char address[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, (uint8_t *) address);
size_t i;
@ -325,7 +325,7 @@ void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
/* check arguments */
if (argc < 1) {
@ -334,13 +334,13 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
return;
}
uint8_t *nick = argv[1];
char *nick = argv[1];
int len = strlen(nick);
if (nick[0] == '\"') {
++nick;
len -= 2;
nick[len] = L'\0';
nick[len] = '\0';
}
if (!valid_nick(nick)) {
@ -350,18 +350,17 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
}
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
nick[len] = '\0';
nick[len] = L'\0';
tox_set_name(m, nick, len);
prompt_update_nick(prompt, nick, len);
tox_set_name(m, (uint8_t *) nick, (uint16_t) len);
prompt_update_nick(prompt, nick);
store_data(m, DATA_FILE);
}
void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *errmsg;
char *errmsg;
if (argc < 1) {
errmsg = "Wrong number of arguments.";
@ -369,7 +368,7 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
return;
}
uint8_t *msg = argv[1];
char *msg = argv[1];
if (msg[0] != '\"') {
errmsg = "Note must be enclosed in quotes.";
@ -377,10 +376,11 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
return;
}
msg[strlen(++msg) - 1] = L'\0';
uint16_t len = strlen(msg);
tox_set_status_message(m, msg, len);
prompt_update_statusmessage(prompt, msg, len);
++msg;
int len = strlen(msg) - 1;
msg[len] = '\0';
tox_set_status_message(m, (uint8_t *) msg, (uint16_t) len);
prompt_update_statusmessage(prompt, msg);
}
void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -395,8 +395,8 @@ void cmd_quit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *msg = NULL;
uint8_t *errmsg;
char *msg = NULL;
char *errmsg;
if (argc >= 2) {
msg = argv[2];
@ -414,7 +414,6 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
char *status = argv[1];
str_to_lower(status);
int len = strlen(status);
TOX_USERSTATUS status_kind;
@ -434,9 +433,10 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
prompt_update_status(prompt, status_kind);
if (msg != NULL) {
msg[strlen(++msg) - 1] = L'\0'; /* remove opening and closing quotes */
uint16_t len = strlen(msg);
tox_set_status_message(m, msg, len);
prompt_update_statusmessage(prompt, msg, len);
++msg;
int len = strlen(msg) - 1;
msg[len] = '\0'; /* remove opening and closing quotes */
tox_set_status_message(m, (uint8_t *) msg, (uint16_t) len);
prompt_update_statusmessage(prompt, msg);
}
}

View File

@ -39,7 +39,7 @@ void cmd_prompt_help(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_ST
void cmd_quit(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_status(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_add_helper(ToxWindow *self, Tox *m, uint8_t *id_bin, uint8_t *msg);
void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg);
#ifdef _SUPPORT_AUDIO
void cmd_list_devices(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -50,7 +50,7 @@ static int max_groupchat_index = 0;
extern struct user_settings *user_settings;
/* temporary until group chats have unique commands */
extern const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
extern const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
{
@ -69,9 +69,6 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t));
groupchats[i].oldpeer_name_lengths = malloc(sizeof(uint16_t));
memset(groupchats[i].peer_names, 0, sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
memset(groupchats[i].peer_name_lengths, 0, sizeof(uint16_t));
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
groupchats[i].oldpeer_name_lengths[0] = (uint16_t) strlen(UNKNOWN_NAME);
@ -96,7 +93,6 @@ void kill_groupchat_window(ToxWindow *self)
delwin(ctx->linewin);
delwin(ctx->history);
delwin(ctx->sidebar);
delwin(self->window);
free(ctx->log);
free(ctx->hst);
free(ctx);
@ -106,7 +102,6 @@ void kill_groupchat_window(ToxWindow *self)
static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
{
set_active_window(0);
tox_del_groupchat(m, groupnum);
free(groupchats[groupnum].peer_names);
@ -127,16 +122,15 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
}
static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum,
const uint8_t *msg, uint16_t len)
const char *msg, uint16_t len)
{
if (self->num != groupnum)
return;
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
int n_len = tox_group_peername(m, groupnum, peernum, nick);
char nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
nick[n_len] = '\0';
@ -144,13 +138,13 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
int alert_type = WINDOW_ALERT_1;
bool beep = false;
uint8_t selfnick[TOX_MAX_NAME_LENGTH];
uint16_t sn_len = tox_get_self_name(m, selfnick);
char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick);
selfnick[sn_len] = '\0';
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH);
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH - 1);
if (nick_match) {
alert_type = WINDOW_ALERT_0;
@ -160,14 +154,14 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
alert_window(self, alert_type, beep);
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, nick_clr);
write_to_log(msg, nick, ctx->log, false);
}
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const uint8_t *action,
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *action,
uint16_t len)
{
if (self->num != groupnum)
@ -179,8 +173,8 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
int alert_type = WINDOW_ALERT_1;
bool beep = false;
uint8_t selfnick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, selfnick);
char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick);
selfnick[n_len] = '\0';
bool nick_match = strcasestr(action, selfnick);
@ -192,13 +186,12 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
alert_window(self, alert_type, beep);
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
n_len = tox_group_peername(m, groupnum, peernum, nick);
char nick[TOX_MAX_NAME_LENGTH];
n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
nick[n_len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
@ -226,14 +219,11 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
exit_toxic_err("failed in copy_peernames", FATALERR_MEMORY);
}
memset(groupchats[gnum].peer_names, 0, sizeof(uint8_t) * npeers * N);
memset(groupchats[gnum].peer_name_lengths, 0, sizeof(uint16_t) * npeers);
uint16_t unknown_len = strlen(UNKNOWN_NAME);
uint16_t unknown_len = (uint16_t) strlen(UNKNOWN_NAME);
int i;
for (i = 0; i < npeers; ++i) {
if (string_is_empty(peerlist[i])) {
if (string_is_empty((char *) peerlist[i])) {
memcpy(&groupchats[gnum].peer_names[i * N], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
groupchats[gnum].peer_name_lengths[i] = unknown_len;
} else {
@ -253,7 +243,7 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
}
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum, int peernum,
uint8_t change)
uint8_t change)
{
if (self->num != groupnum)
return;
@ -296,49 +286,49 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
ChatContext *ctx = self->chatwin;
uint8_t *event;
uint8_t timefrmt[TIME_STR_SIZE];
char *event;
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
switch (change) {
case TOX_CHAT_CHANGE_PEER_ADD:
event = "has joined the room";
line_info_add(self, timefrmt, peername, NULL, event, CONNECTION, 0, GREEN);
write_to_log(event, peername, ctx->log, true);
line_info_add(self, timefrmt, (char *) peername, NULL, event, CONNECTION, 0, GREEN);
write_to_log(event, (char *) peername, ctx->log, true);
break;
case TOX_CHAT_CHANGE_PEER_DEL:
event = "has left the room";
line_info_add(self, timefrmt, oldpeername, NULL, event, CONNECTION, 0, 0);
line_info_add(self, timefrmt, (char *) oldpeername, NULL, event, CONNECTION, 0, 0);
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
write_to_log(event, oldpeername, ctx->log, true);
write_to_log(event, (char *) oldpeername, ctx->log, true);
break;
case TOX_CHAT_CHANGE_PEER_NAME:
event = " is now known as ";
line_info_add(self, timefrmt, oldpeername, peername, event, NAME_CHANGE, 0, 0);
line_info_add(self, timefrmt, (char *) oldpeername, (char *) peername, event, NAME_CHANGE, 0, 0);
uint8_t tmp_event[TOXIC_MAX_NAME_LENGTH * 2 + 32];
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", peername);
write_to_log(tmp_event, oldpeername, ctx->log, true);
char tmp_event[TOXIC_MAX_NAME_LENGTH * 2 + 32];
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", (char *) peername);
write_to_log(tmp_event, (char *) oldpeername, ctx->log, true);
break;
}
alert_window(self, WINDOW_ALERT_2, false);
}
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action)
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
{
if (action == NULL) {
wprintw(ctx->history, "Invalid syntax.\n");
return;
}
if (tox_group_action_send(m, self->num, action, strlen(action)) == -1) {
uint8_t *errmsg = " * Failed to send action.";
if (tox_group_action_send(m, self->num, (uint8_t *) action, strlen(action)) == -1) {
char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
}
}
@ -404,7 +394,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else if (key == '\n') {
rm_trailing_spaces_buf(ctx);
uint8_t line[MAX_STR_SIZE];
char line[MAX_STR_SIZE];
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1)
memset(&line, 0, sizeof(line));
@ -422,8 +412,8 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
}
} else if (!string_is_empty(line)) {
if (tox_group_message_send(m, self->num, line, strlen(line)) == -1) {
uint8_t *errmsg = " * Failed to send message.";
if (tox_group_message_send(m, self->num, (uint8_t *) line, strlen(line)) == -1) {
char *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
}
}
@ -474,7 +464,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
int peer = i + groupchats[self->num].side_pos;
/* truncate nick to fit in side panel without modifying list */
uint8_t tmpnck[TOX_MAX_NAME_LENGTH];
char tmpnck[TOX_MAX_NAME_LENGTH];
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], SIDEBAR_WIDTH - 2);
tmpnck[SIDEBAR_WIDTH - 2] = '\0';
@ -483,13 +473,14 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
int y, x;
getyx(self->window, y, x);
(void) x;
int new_x = ctx->start ? x2 - 1 : ctx->pos;
wmove(self->window, y + 1, new_x);
if (self->help->active) {
wrefresh(self->window);
wrefresh(self->window);
if (self->help->active)
help_onDraw(self);
}
}
static void groupchat_onInit(ToxWindow *self, Tox *m)
@ -503,15 +494,12 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
ctx->hst = malloc(sizeof(struct history));
ctx->log = malloc(sizeof(struct chatlog));
ctx->hst = calloc(1, sizeof(struct history));
ctx->log = calloc(1, sizeof(struct chatlog));
if (ctx->log == NULL || ctx->hst == NULL)
exit_toxic_err("failed in groupchat_onInit", FATALERR_MEMORY);
memset(ctx->hst, 0, sizeof(struct history));
memset(ctx->log, 0, sizeof(struct chatlog));
line_info_init(ctx->hst);
if (user_settings->autolog == AUTOLOG_ON)
@ -538,7 +526,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum)
ret.onGroupNamelistChange = &groupchat_onGroupNamelistChange;
ret.onGroupAction = &groupchat_onGroupAction;
snprintf(ret.name, sizeof(ret.name), "Room #%d", groupnum);
snprintf(ret.name, sizeof(ret.name), "Group %d", groupnum);
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
Help *help = calloc(1, sizeof(Help));

View File

@ -105,6 +105,8 @@ static void help_draw_bottom_menu(WINDOW *win)
{
int y2, x2;
getmaxyx(win, y2, x2);
(void) x2;
wmove(win, y2 - 2, 1);
wattron(win, A_BOLD | COLOR_PAIR(BLUE));
@ -203,11 +205,11 @@ static void help_draw_keys(ToxWindow *self)
wprintw(win, "Key bindings:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " Ctrl+O / Ctrl+P : Navigate through the windows/tabs\n");
wprintw(win, " Page Up / Page Down : Scroll window history one line\n");
wprintw(win, " Ctrl+F / Ctrl+V : Scroll window history half a page\n");
wprintw(win, " Ctrl+H : Move to the bottom of window history\n");
wprintw(win, " Ctrl+[ / Ctrl+] : Scroll peer list in groupchats\n");
wprintw(win, " Ctrl+O and Ctrl+P : Navigate through the tabs\n");
wprintw(win, " Page Up and Page Down : Scroll window history one line\n");
wprintw(win, " Ctrl+F and Ctrl+V : Scroll window history half a page\n");
wprintw(win, " Ctrl+H : Move to the bottom of window history\n");
wprintw(win, " Ctrl+[ and Ctrl+] : Scroll peer list in groupchats\n");
help_draw_bottom_menu(win);
@ -233,7 +235,11 @@ void help_onKey(ToxWindow *self, wint_t key)
break;
case 'g':
#ifdef _SUPPORT_AUDIO
help_init_window(self, 21, 80);
#else
help_init_window(self, 17, 80);
#endif
self->help->type = HELP_GLOBAL;
break;
@ -252,7 +258,6 @@ void help_onKey(ToxWindow *self, wint_t key)
void help_onDraw(ToxWindow *self)
{
curs_set(0);
wclear(self->help->win);
switch(self->help->type) {
case HELP_MENU:

View File

@ -34,34 +34,39 @@ extern struct user_settings *user_settings;
void line_info_init(struct history *hst)
{
hst->line_root = malloc(sizeof(struct line_info));
hst->line_root = calloc(1, sizeof(struct line_info));
if (hst->line_root == NULL)
exit_toxic_err("failed in line_info_init", FATALERR_MEMORY);
memset(hst->line_root, 0, sizeof(struct line_info));
hst->line_start = hst->line_root;
hst->line_end = hst->line_start;
hst->queue_sz = 0;
}
/* resets line_start */
/* resets line_start (page end) */
static void line_info_reset_start(ToxWindow *self, struct history *hst)
{
struct line_info *line = hst->line_end;
if (line->prev == NULL)
return;
int y2, x2;
getmaxyx(self->window, y2, x2);
struct line_info *line = hst->line_end;
uint16_t lncnt = 0;
int side_offst = self->is_groupchat ? SIDEBAR_WIDTH : 0;
int top_offst = self->is_chat ? 2 : 0;
int top_offst = self->is_chat || self->is_prompt ? 2 : 0;
int max_y = (y2 - CHATBOX_HEIGHT - top_offst);
while (line->prev && lncnt < max_y) {
lncnt += (1 + line->newlines) +( line->len / (x2 - side_offst));
int curlines = 0;
int nxtlines = line->newlines + (line->len / (x2 - side_offst));
do {
curlines += 1 + nxtlines;
line = line->prev;
}
nxtlines = line->newlines + (line->len / (x2 - side_offst));
} while (line->prev && curlines + nxtlines < max_y);
hst->line_start = line;
}
@ -75,6 +80,13 @@ void line_info_cleanup(struct history *hst)
free(tmp1);
tmp1 = tmp2;
}
int i;
for (i = 0; i < hst->queue_sz; ++i) {
if (hst->queue[i])
free(hst->queue[i]);
}
}
/* moves root forward and frees previous root */
@ -121,17 +133,15 @@ static struct line_info *line_info_ret_queue(struct history *hst)
}
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, const uint8_t *msg,
uint8_t type, uint8_t bold, uint8_t colour)
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, const char *msg, uint8_t type,
uint8_t bold, uint8_t colour)
{
struct history *hst = self->chatwin->hst;
struct line_info *new_line = malloc(sizeof(struct line_info));
struct line_info *new_line = calloc(1, sizeof(struct line_info));
if (new_line == NULL)
exit_toxic_err("failed in line_info_add", FATALERR_MEMORY);
memset(new_line, 0, sizeof(struct line_info));
int len = 1; /* there will always be a newline */
/* for type-specific formatting in print function */
@ -208,6 +218,7 @@ static void line_info_check_queue(ToxWindow *self)
int y, y2, x, x2;
getmaxyx(self->window, y2, x2);
getyx(self->chatwin->history, y, x);
(void) x;
if (x2 <= SIDEBAR_WIDTH)
return;
@ -252,7 +263,6 @@ void line_info_print(ToxWindow *self)
wmove(win, 2, 0);
struct line_info *line = hst->line_start->next;
int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0;
int numlines = 0;
while (line && numlines++ <= y2) {
@ -373,7 +383,7 @@ void line_info_print(ToxWindow *self)
line_info_print(self);
}
void line_info_set(ToxWindow *self, uint32_t id, uint8_t *msg)
void line_info_set(ToxWindow *self, uint32_t id, char *msg)
{
struct line_info *line = self->chatwin->hst->line_end;
@ -387,10 +397,10 @@ void line_info_set(ToxWindow *self, uint32_t id, uint8_t *msg)
}
}
static void line_info_goto_root(struct history *hst)
/* static void line_info_goto_root(struct history *hst)
{
hst->line_start = hst->line_root;
}
} */
static void line_info_scroll_up(struct history *hst)
{
@ -410,6 +420,7 @@ static void line_info_page_up(ToxWindow *self, struct history *hst)
{
int x2, y2;
getmaxyx(self->window, y2, x2);
(void) x2;
int jump_dist = y2 / 2;
int i;
@ -421,6 +432,7 @@ static void line_info_page_down(ToxWindow *self, struct history *hst)
{
int x2, y2;
getmaxyx(self->window, y2, x2);
(void) x2;
int jump_dist = y2 / 2;
int i;

View File

@ -27,7 +27,7 @@
#include "toxic.h"
#define MAX_HISTORY 10000
#define MIN_HISTORY 20
#define MIN_HISTORY 40
#define MAX_QUEUE 128
enum {
@ -41,10 +41,10 @@ enum {
} LINE_TYPE;
struct line_info {
uint8_t timestamp[TIME_STR_SIZE];
uint8_t name1[TOXIC_MAX_NAME_LENGTH];
uint8_t name2[TOXIC_MAX_NAME_LENGTH];
uint8_t msg[TOX_MAX_MESSAGE_LENGTH];
char timestamp[TIME_STR_SIZE];
char name1[TOXIC_MAX_NAME_LENGTH];
char name2[TOXIC_MAX_NAME_LENGTH];
char msg[TOX_MAX_MESSAGE_LENGTH];
uint8_t type;
uint8_t bold;
uint8_t colour;
@ -68,7 +68,7 @@ struct history {
};
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, const uint8_t *msg,
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, const char *msg,
uint8_t type, uint8_t bold, uint8_t colour);
/* Prints a section of history starting at line_start */
@ -81,7 +81,7 @@ void line_info_cleanup(struct history *hst);
void line_info_clear(struct history *hst);
/* puts msg in specified line_info msg buffer */
void line_info_set(ToxWindow *self, uint32_t id, uint8_t *msg);
void line_info_set(ToxWindow *self, uint32_t id, char *msg);
void line_info_init(struct history *hst);
bool line_info_onKey(ToxWindow *self, wint_t key); /* returns true if key is a match */

View File

@ -34,7 +34,7 @@
extern struct user_settings *user_settings;
/* Creates/fetches log file by appending to the config dir the name and a pseudo-unique identity */
void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
void init_logging_session(char *name, char *key, struct chatlog *log)
{
if (!log->log_on)
return;
@ -46,7 +46,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name);
/* use first 4 digits of key as log ident. If no key use a timestamp */
uint8_t ident[32];
char ident[32];
if (key != NULL) {
path_len += (KEY_IDENT_DIGITS * 2 + 5);
@ -65,7 +65,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
return;
}
uint8_t log_path[MAX_STR_SIZE];
char log_path[MAX_STR_SIZE];
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log",
user_config_dir, CONFIGDIR, name, ident);
@ -82,7 +82,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
fprintf(log->file, "\n*** NEW SESSION ***\n\n");
}
void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool event)
void write_to_log(const char *msg, char *name, struct chatlog *log, bool event)
{
if (!log->log_on)
return;
@ -92,7 +92,7 @@ void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool e
return;
}
uint8_t name_frmt[TOXIC_MAX_NAME_LENGTH + 3];
char name_frmt[TOXIC_MAX_NAME_LENGTH + 3];
if (event)
snprintf(name_frmt, sizeof(name_frmt), "* %s", name);
@ -100,7 +100,7 @@ void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool e
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
const char *t = user_settings->time == TIME_12 ? "%Y/%m/%d [%I:%M:%S %p]" : "%Y/%m/%d [%H:%M:%S]";
uint8_t s[MAX_STR_SIZE];
char s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, t, get_time());
fprintf(log->file, "%s %s %s\n", s, name_frmt, msg);
@ -112,7 +112,7 @@ void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool e
}
}
void log_enable(uint8_t *name, uint8_t *key, struct chatlog *log)
void log_enable(char *name, char *key, struct chatlog *log)
{
log->log_on = true;

View File

@ -33,13 +33,13 @@ struct chatlog {
};
/* Creates/fetches log file by appending to the config dir the name and a pseudo-unique identity */
void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log);
void init_logging_session(char *name, char *key, struct chatlog *log);
/* formats/writes line to log file */
void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool event);
void write_to_log(const char *msg, char *name, struct chatlog *log, bool event);
/* enables logging for specified log and creates/fetches file if necessary */
void log_enable(uint8_t *name, uint8_t *key, struct chatlog *log);
void log_enable(char *name, char *key, struct chatlog *log);
/* disables logging for specified log and closes file */
void log_disable(struct chatlog *log);

View File

@ -46,17 +46,23 @@ uint64_t get_unix_time(void)
return current_unix_time;
}
/* Returns 1 if connection has timed out, 0 otherwise */
int timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout)
{
return timestamp + timeout <= curtime;
}
/* Get the current local time */
struct tm *get_time(void)
{
struct tm *timeinfo;
uint64_t t = get_unix_time();
timeinfo = localtime((const time_t*)&t);
timeinfo = localtime((const time_t*) &t);
return timeinfo;
}
/*Puts the current time in buf in the format of [HH:mm:ss] */
void get_time_str(uint8_t *buf, int bufsize)
void get_time_str(char *buf, int bufsize)
{
if (user_settings->timestamps == TIMESTAMPS_OFF) {
buf[0] = '\0';
@ -68,14 +74,14 @@ void get_time_str(uint8_t *buf, int bufsize)
}
/* Converts seconds to string in format HH:mm:ss; truncates hours and minutes when necessary */
void get_elapsed_time_str(uint8_t *buf, int bufsize, uint64_t secs)
void get_elapsed_time_str(char *buf, int bufsize, uint64_t secs)
{
if (!secs)
return;
uint64_t seconds = secs % 60;
uint64_t minutes = (secs % 3600) / 60;
uint64_t hours = secs / 3600;
long int seconds = secs % 60;
long int minutes = (secs % 3600) / 60;
long int hours = secs / 3600;
if (!minutes && !hours)
snprintf(buf, bufsize, "%.2ld", seconds);
@ -108,7 +114,7 @@ int string_is_empty(char *string)
}
/* convert a multibyte string to a wide character string and puts in buf. */
int mbs_to_wcs_buf(wchar_t *buf, const uint8_t *string, size_t n)
int mbs_to_wcs_buf(wchar_t *buf, const char *string, size_t n)
{
size_t len = mbstowcs(NULL, string, 0) + 1;
@ -122,7 +128,7 @@ int mbs_to_wcs_buf(wchar_t *buf, const uint8_t *string, size_t n)
}
/* converts wide character string into a multibyte string and puts in buf. */
int wcs_to_mbs_buf(uint8_t *buf, const wchar_t *string, size_t n)
int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n)
{
size_t len = wcstombs(NULL, string, 0) + 1;
@ -135,12 +141,6 @@ int wcs_to_mbs_buf(uint8_t *buf, const wchar_t *string, size_t n)
return len;
}
/* Returns 1 if connection has timed out, 0 otherwise */
int timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout)
{
return timestamp + timeout <= curtime;
}
/* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self, int type, bool is_beep)
{
@ -175,7 +175,7 @@ int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2)
- cannot start with a space
- must not contain a forward slash (for logfile naming purposes)
- must not contain contiguous spaces */
int valid_nick(uint8_t *nick)
int valid_nick(char *nick)
{
if (!nick[0] || nick[0] == ' ')
return 0;
@ -194,17 +194,17 @@ int valid_nick(uint8_t *nick)
}
/* gets base file name from path or original file name if no path is supplied */
void get_file_name(uint8_t *namebuf, const uint8_t *pathname)
void get_file_name(char *namebuf, int bufsize, const char *pathname)
{
int idx = strlen(pathname) - 1;
uint8_t tmpname[MAX_STR_SIZE];
char tmpname[MAX_STR_SIZE];
snprintf(tmpname, sizeof(tmpname), "%s", pathname);
while (idx >= 0 && pathname[idx] == '/')
tmpname[idx--] = '\0';
uint8_t *filename = strrchr(tmpname, '/');
char *filename = strrchr(tmpname, '/');
if (filename != NULL) {
if (!strlen(++filename))
@ -213,14 +213,24 @@ void get_file_name(uint8_t *namebuf, const uint8_t *pathname)
filename = tmpname;
}
snprintf(namebuf, MAX_STR_SIZE, "%s", filename);
snprintf(namebuf, bufsize, "%s", filename);
}
/* converts str to all lowercase */
void str_to_lower(uint8_t *str)
void str_to_lower(char *str)
{
int i;
for (i = 0; str[i]; ++i)
str[i] = tolower(str[i]);
}
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
Returns nick len on success, -1 on failure */
int get_nick_truncate(Tox *m, char *buf, int friendnum)
{
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
buf[len] = '\0';
return len;
}

View File

@ -40,10 +40,10 @@ char *hex_string_to_bin(const char *hex_string);
uint64_t get_unix_time(void);
/*Puts the current time in buf in the format of [HH:mm:ss] */
void get_time_str(uint8_t *buf, int bufsize);
void get_time_str(char *buf, int bufsize);
/* Converts seconds to string in format HH:mm:ss; truncates hours and minutes when necessary */
void get_elapsed_time_str(uint8_t *buf, int bufsize, uint64_t secs);
void get_elapsed_time_str(char *buf, int bufsize, uint64_t secs);
/* get the current local time */
struct tm *get_time(void);
@ -55,13 +55,13 @@ void update_unix_time(void);
int string_is_empty(char *string);
/* convert a multibyte string to a wide character string (must provide buffer) */
int char_to_wcs_buf(wchar_t *buf, const uint8_t *string, size_t n);
int char_to_wcs_buf(wchar_t *buf, const char *string, size_t n);
/* converts wide character string into a multibyte string and puts in buf. */
int wcs_to_mbs_buf(uint8_t *buf, const wchar_t *string, size_t n);
int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n);
/* convert a multibyte string to a wide character string and puts in buf) */
int mbs_to_wcs_buf(wchar_t *buf, const uint8_t *string, size_t n);
int mbs_to_wcs_buf(wchar_t *buf, const char *string, size_t n);
/* Returns 1 if connection has timed out, 0 otherwise */
int timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime);
@ -77,12 +77,16 @@ int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2);
- cannot start with a space
- must not contain a forward slash (for logfile naming purposes)
- must not contain contiguous spaces */
int valid_nick(uint8_t *nick);
int valid_nick(char *nick);
/* gets base file name from path or original file name if no path is supplied */
void get_file_name(uint8_t *namebuf, const uint8_t *pathname);
void get_file_name(char *namebuf, int bufsize, const char *pathname);
/* converts str to all lowercase */
void str_to_lower(uint8_t *str);
void str_to_lower(char *str);
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
Returns nick len on success, -1 on failure */
int get_nick_truncate(Tox *m, char *buf, int friendnum);
#endif /* #define _misc_tools_h */

View File

@ -36,15 +36,15 @@
#include "input.h"
#include "help.h"
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0};
uint8_t num_frnd_requests = 0;
char pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
uint16_t num_frnd_requests = 0;
extern ToxWindow *prompt;
struct _Winthread Winthread;
extern struct user_settings *user_settings;
/* Array of global command names used for tab completion. */
const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/accept" },
{ "/add" },
{ "/clear" },
@ -69,8 +69,28 @@ const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
#endif /* _SUPPORT_AUDIO */
};
void kill_prompt_window(ToxWindow *self) {
ChatContext *ctx = self->chatwin;
StatusBar *statusbar = self->stb;
log_disable(ctx->log);
line_info_cleanup(ctx->hst);
delwin(ctx->linewin);
delwin(ctx->history);
delwin(statusbar->topline);
free(ctx->log);
free(ctx->hst);
free(ctx);
free(self->help);
free(statusbar);
del_window(self);
}
/* Updates own nick in prompt statusbar */
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
void prompt_update_nick(ToxWindow *prompt, char *nick)
{
StatusBar *statusbar = prompt->stb;
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
@ -78,7 +98,7 @@ void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
}
/* Updates own statusmessage in prompt statusbar */
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len)
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg)
{
StatusBar *statusbar = prompt->stb;
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
@ -101,7 +121,7 @@ void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
/* Adds friend request to pending friend requests.
Returns request number on success, -1 if queue is full or other error. */
static int add_friend_request(const uint8_t *public_key)
static int add_friend_request(const char *public_key)
{
if (num_frnd_requests >= MAX_FRIENDS_NUM)
return -1;
@ -169,7 +189,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else if (key == '\n') {
rm_trailing_spaces_buf(ctx);
uint8_t line[MAX_STR_SIZE] = {0};
char line[MAX_STR_SIZE] = {0};
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1)
memset(&line, 0, sizeof(line));
@ -207,7 +227,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
if (statusbar->is_online) {
int colour = WHITE;
const uint8_t *status_text = "Unknown";
const char *status_text = "Unknown";
switch (statusbar->status) {
case TOX_USERSTATUS_NONE:
@ -239,7 +259,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
wprintw(statusbar->topline, " %s", statusbar->nick);
wattroff(statusbar->topline, A_BOLD);
} else {
wprintw(statusbar->topline, "[Offline]");
wprintw(statusbar->topline, " [Offline]");
wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, " %s ", statusbar->nick);
wattroff(statusbar->topline, A_BOLD);
@ -252,13 +272,15 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
int y, x;
getyx(self->window, y, x);
(void) x;
int new_x = ctx->start ? x2 - 1 : ctx->pos;
wmove(self->window, y + 1, new_x);
if (self->help->active) {
wrefresh(self->window);
wrefresh(self->window);
if (self->help->active)
help_onDraw(self);
}
}
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
@ -268,20 +290,15 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
int n_len = tox_get_name(m, friendnum, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
char nick[TOX_MAX_NAME_LENGTH] = {0}; /* stop removing this initiation */
get_nick_truncate(m, nick, friendnum);
if (!nick[0]) {
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
n_len = strlen(UNKNOWN_NAME);
}
nick[n_len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
uint8_t *msg;
char *msg;
if (status == 1) {
msg = "has come online";
@ -295,15 +312,15 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
}
}
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const uint8_t *key, const uint8_t *data,
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, const char *data,
uint16_t length)
{
ChatContext *ctx = self->chatwin;
uint8_t timefrmt[TIME_STR_SIZE];
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
uint8_t msg[MAX_STR_SIZE];
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data);
line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0);
write_to_log(msg, "", ctx->log, true);
@ -311,7 +328,7 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const uint8_t *key,
int n = add_friend_request(key);
if (n == -1) {
uint8_t *errmsg = "Friend request queue is full. Discarding request.";
char *errmsg = "Friend request queue is full. Discarding request.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
write_to_log(errmsg, "", ctx->log, true);
return;
@ -326,18 +343,19 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
{
int x2, y2;
getmaxyx(self->window, y2, x2);
(void) y2;
/* Init statusbar info */
StatusBar *statusbar = self->stb;
statusbar->status = TOX_USERSTATUS_NONE;
statusbar->is_online = false;
uint8_t nick[TOX_MAX_NAME_LENGTH];
uint8_t statusmsg[MAX_STR_SIZE];
char nick[TOX_MAX_NAME_LENGTH];
char statusmsg[MAX_STR_SIZE];
pthread_mutex_lock(&Winthread.lock);
uint16_t n_len = tox_get_self_name(m, nick);
uint16_t s_len = tox_get_self_status_message(m, statusmsg, MAX_STR_SIZE);
uint16_t n_len = tox_get_self_name(m, (uint8_t *) nick);
uint16_t s_len = tox_get_self_status_message(m, (uint8_t *) statusmsg, MAX_STR_SIZE);
uint8_t status = tox_get_self_user_status(m);
pthread_mutex_unlock(&Winthread.lock);
@ -345,9 +363,9 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
statusmsg[s_len] = '\0';
/* load prev status message or show toxic version if it has never been set */
uint8_t ver[strlen(TOXICVER) + 1];
char ver[strlen(TOXICVER) + 1];
strcpy(ver, TOXICVER);
const uint8_t *toxic_ver = strtok(ver, "_");
const char *toxic_ver = strtok(ver, "_");
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) {
snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver);
@ -355,9 +373,9 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
statusmsg[s_len] = '\0';
}
prompt_update_statusmessage(prompt, statusmsg, s_len);
prompt_update_statusmessage(prompt, statusmsg);
prompt_update_status(prompt, status);
prompt_update_nick(prompt, nick, n_len);
prompt_update_nick(prompt, nick);
/* Init statusbar subwindow */
statusbar->topline = subwin(self->window, 2, x2, 0, 0);
@ -365,19 +383,18 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
static void print_welcome_msg(ToxWindow *self)
{
ChatContext *ctx = self->chatwin;
line_info_add(self, NULL, NULL, NULL, " |_ _|____ _(_) ___ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | |/ _ \\ \\/ / |/ __|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | | (_) > <| | (__ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " |_|\\___/_/\\_\\_|\\___|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " _____ _____ _____ ____ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " |_ _/ _ \\ \\/ /_ _/ ___|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | || | | \\ / | | | ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | || |_| / \\ | | |___ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " |_| \\___/_/\\_\\___\\____|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
uint8_t *msg = "Welcome to Toxic, a free open source messenger client for Tox. Type /help for a"\
" list of commands and key bindings. Further help may be found via the man page.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, 0);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 1, 0);
char *msg = "Welcome to Toxic, a free, open source Tox-based instant messenging client.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
msg = "Type \"/help\" for assistance. Further help may be found via the man page.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
}
static void prompt_onInit(ToxWindow *self, Tox *m)
@ -390,20 +407,17 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
ctx->log = malloc(sizeof(struct chatlog));
ctx->hst = malloc(sizeof(struct history));
ctx->log = calloc(1, sizeof(struct chatlog));
ctx->hst = calloc(1, sizeof(struct history));
if (ctx->log == NULL || ctx->hst == NULL)
exit_toxic_err("failed in prompt_onInit", FATALERR_MEMORY);
memset(ctx->log, 0, sizeof(struct chatlog));
memset(ctx->hst, 0, sizeof(struct history));
line_info_init(ctx->hst);
if (user_settings->autolog == AUTOLOG_ON) {
uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, myid);
char myid[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, (uint8_t *) myid);
log_enable(self->name, myid, ctx->log);
}

View File

@ -35,9 +35,10 @@
ToxWindow new_prompt(void);
void prep_prompt_win(void);
void prompt_init_statusbar(ToxWindow *self, Tox *m);
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len);
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len);
void prompt_update_nick(ToxWindow *prompt, char *nick);
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg);
void prompt_update_status(ToxWindow *prompt, uint8_t status);
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected);
void kill_prompt_window(ToxWindow *self);
#endif /* end of include guard: PROMPT_H_UZYGWFFL */

View File

@ -67,6 +67,8 @@ ToxAv *av;
char *DATA_FILE = NULL;
ToxWindow *prompt = NULL;
#define AUTOSAVE_FREQ 60
struct arg_opts {
int ignore_data_file;
int use_ipv4;
@ -76,12 +78,11 @@ struct arg_opts {
} arg_opts;
struct _Winthread Winthread;
struct user_settings *user_settings = NULL;
static void ignore_SIGINT(int sig)
static void catch_SIGINT(int sig)
{
return;
Winthread.sig_exit_toxic = true;
}
static void flag_window_resize(int sig)
@ -94,15 +95,10 @@ void exit_toxic_success(Tox *m)
store_data(m, DATA_FILE);
close_all_file_senders(m);
kill_all_windows();
log_disable(prompt->chatwin->log);
line_info_cleanup(prompt->chatwin->hst);
free(DATA_FILE);
free(prompt->stb);
free(prompt->help);
free(prompt->chatwin->log);
free(prompt->chatwin->hst);
free(prompt->chatwin);
free(user_settings);
#ifdef _SUPPORT_AUDIO
terminate_audio();
#endif /* _SUPPORT_AUDIO */
@ -224,10 +220,10 @@ static struct _toxNodes {
int lines;
char nodes[MAXNODES][NODELEN];
uint16_t ports[MAXNODES];
uint8_t keys[MAXNODES][TOX_CLIENT_ID_SIZE];
char keys[MAXNODES][TOX_CLIENT_ID_SIZE];
} toxNodes;
static int nodelist_load(char *filename)
static int nodelist_load(const char *filename)
{
if (!filename)
return 1;
@ -253,7 +249,7 @@ static int nodelist_load(char *filename)
toxNodes.nodes[toxNodes.lines][NODELEN - 1] = 0;
toxNodes.ports[toxNodes.lines] = htons(atoi(port));
uint8_t *key_binary = hex_string_to_bin(key_ascii);
char *key_binary = hex_string_to_bin(key_ascii);
memcpy(toxNodes.keys[toxNodes.lines], key_binary, TOX_CLIENT_ID_SIZE);
free(key_binary);
@ -273,7 +269,7 @@ static int nodelist_load(char *filename)
int init_connection_helper(Tox *m, int line)
{
return tox_bootstrap_from_address(m, toxNodes.nodes[line], TOX_ENABLE_IPV6_DEFAULT,
toxNodes.ports[line], toxNodes.keys[line]);
toxNodes.ports[line], (uint8_t *) toxNodes.keys[line]);
}
/* Connects to a random DHT node listed in the DHTnodes file
@ -329,7 +325,7 @@ int init_connection(Tox *m)
static void do_connection(Tox *m, ToxWindow *prompt)
{
uint8_t msg[MAX_STR_SIZE] = {0};
char msg[MAX_STR_SIZE] = {0};
static int conn_err = 0;
static bool was_connected = false;
@ -388,8 +384,8 @@ int store_data(Tox *m, char *path)
return 1;
FILE *fd;
size_t len;
uint8_t *buf;
int len;
char *buf;
len = tox_size(m);
buf = malloc(len);
@ -397,7 +393,7 @@ int store_data(Tox *m, char *path)
if (buf == NULL)
return 2;
tox_save(m, buf);
tox_save(m, (uint8_t *) buf);
fd = fopen(path, "wb");
@ -423,8 +419,8 @@ static void load_data(Tox *m, char *path)
return;
FILE *fd;
size_t len;
uint8_t *buf;
int len;
char *buf;
if ((fd = fopen(path, "rb")) != NULL) {
fseek(fd, 0, SEEK_END);
@ -444,7 +440,7 @@ static void load_data(Tox *m, char *path)
exit_toxic_err("failed in load_data", FATALERR_FREAD);
}
tox_load(m, buf, len);
tox_load(m, (uint8_t *) buf, len);
load_friendlist(m);
free(buf);
@ -462,23 +458,32 @@ static void do_toxic(Tox *m, ToxWindow *prompt)
pthread_mutex_lock(&Winthread.lock);
do_connection(m, prompt);
do_file_senders(m);
pthread_mutex_unlock(&Winthread.lock);
tox_do(m); /* main tox-core loop */
pthread_mutex_unlock(&Winthread.lock);
}
#define INACTIVE_WIN_REFRESH_RATE 10
void *thread_winref(void *data)
{
Tox *m = (Tox *) data;
uint8_t draw_count = 0;
while (true) {
draw_active_window(m);
draw_count++;
if (Winthread.flag_resize) {
on_window_resize();
Winthread.flag_resize = false;
} else {
} else if (draw_count >= INACTIVE_WIN_REFRESH_RATE) {
refresh_inactive_windows();
draw_count = 0;
}
if (Winthread.sig_exit_toxic) {
pthread_mutex_lock(&Winthread.lock);
exit_toxic_success(m);
}
}
}
@ -563,7 +568,7 @@ int main(int argc, char *argv[])
/* Make sure all written files are read/writeable only by the current user. */
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
signal(SIGINT, ignore_SIGINT);
signal(SIGINT, catch_SIGINT);
config_err = create_user_config_dir(user_config_dir);
@ -613,7 +618,7 @@ int main(int argc, char *argv[])
if (pthread_create(&Winthread.tid, NULL, thread_winref, (void *) m) != 0)
exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);
uint8_t *msg;
char *msg;
#ifdef _SUPPORT_AUDIO
@ -635,13 +640,24 @@ int main(int argc, char *argv[])
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
sort_friendlist_index();
prompt_init_statusbar(prompt, m);
uint64_t last_save = get_unix_time();
while (true) {
update_unix_time();
do_toxic(m, prompt);
uint64_t cur_time = get_unix_time();
if (timed_out(last_save, cur_time, AUTOSAVE_FREQ)) {
pthread_mutex_lock(&Winthread.lock);
store_data(m, DATA_FILE);
pthread_mutex_unlock(&Winthread.lock);
last_save = cur_time;
}
usleep(40000);
}

View File

@ -183,19 +183,19 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
if (ctx->pos <= 0 || ctx->len <= 0 || ctx->len >= MAX_STR_SIZE)
return -1;
const uint8_t *L = (uint8_t *) list;
const char *L = (char *) list;
uint8_t ubuf[MAX_STR_SIZE];
char ubuf[MAX_STR_SIZE];
/* work with multibyte string copy of buf for simplicity */
if (wcs_to_mbs_buf(ubuf, ctx->line, MAX_STR_SIZE) == -1)
if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1)
return -1;
/* isolate substring from space behind pos to pos */
uint8_t tmp[MAX_STR_SIZE];
char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf);
tmp[ctx->pos] = '\0';
uint8_t *sub = strrchr(tmp, ' ');
char *sub = strrchr(tmp, ' ');
int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": " */
if (!sub++) {
@ -209,7 +209,7 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
return -1;
int s_len = strlen(sub);
const uint8_t *match;
const char *match;
bool is_match = false;
int i;
@ -217,7 +217,7 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
for (i = 0; i < n_items; ++i) {
match = &L[i * size];
if (is_match = strncasecmp(match, sub, s_len) == 0)
if ((is_match = strncasecmp(match, sub, s_len) == 0))
break;
}
@ -225,7 +225,7 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
return -1;
/* put match in correct spot in buf and append endchars (space or ": ") */
const uint8_t *endchrs = n_endchrs == 1 ? " " : ": ";
const char *endchrs = n_endchrs == 1 ? " " : ": ";
int m_len = strlen(match);
int strt = ctx->pos - s_len;
int diff = m_len - s_len + n_endchrs;
@ -233,7 +233,7 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
if (ctx->len + diff > MAX_STR_SIZE)
return -1;
uint8_t tmpend[MAX_STR_SIZE];
char tmpend[MAX_STR_SIZE];
strcpy(tmpend, &ubuf[ctx->pos]);
strcpy(&ubuf[strt], match);
strcpy(&ubuf[strt + m_len], endchrs);

View File

@ -49,7 +49,7 @@ void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFriendRequest != NULL)
windows[i].onFriendRequest(&windows[i], m, public_key, data, length);
windows[i].onFriendRequest(&windows[i], m, (const char *) public_key, (const char *) data, length);
}
}
@ -79,7 +79,7 @@ void on_message(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t le
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onMessage != NULL)
windows[i].onMessage(&windows[i], m, friendnumber, string, length);
windows[i].onMessage(&windows[i], m, friendnumber, (const char *) string, length);
}
}
@ -89,7 +89,7 @@ void on_action(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t len
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onAction != NULL)
windows[i].onAction(&windows[i], m, friendnumber, string, length);
windows[i].onAction(&windows[i], m, friendnumber, (const char *) string, length);
}
}
@ -102,11 +102,10 @@ void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onNickChange != NULL)
windows[i].onNickChange(&windows[i], m, friendnumber, string, length);
windows[i].onNickChange(&windows[i], m, friendnumber, (const char *) string, length);
}
if (store_data(m, DATA_FILE))
wprintw(prompt->window, "\nCould not store Tox data\n");
store_data(m, DATA_FILE);
}
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
@ -115,7 +114,7 @@ void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string,
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onStatusMessageChange != NULL)
windows[i].onStatusMessageChange(&windows[i], friendnumber, string, length);
windows[i].onStatusMessageChange(&windows[i], friendnumber, (const char *) string, length);
}
}
@ -138,8 +137,7 @@ void on_friendadded(Tox *m, int32_t friendnumber, bool sort)
windows[i].onFriendAdded(&windows[i], m, friendnumber, sort);
}
if (store_data(m, DATA_FILE))
wprintw(prompt->window, "\nCould not store Tox data\n");
store_data(m, DATA_FILE);
}
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length,
@ -149,7 +147,7 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *mes
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupMessage != NULL)
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, message, length);
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, (const char *) message, length);
}
}
@ -160,7 +158,7 @@ void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *acti
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupAction != NULL)
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, action, length);
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, (const char *) action, length);
}
}
@ -170,7 +168,7 @@ void on_groupinvite(Tox *m, int32_t friendnumber, const uint8_t *group_pub_key,
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupInvite != NULL)
windows[i].onGroupInvite(&windows[i], m, friendnumber, group_pub_key);
windows[i].onGroupInvite(&windows[i], m, friendnumber, (const char *) group_pub_key);
}
}
@ -192,7 +190,7 @@ void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint6
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFileSendRequest != NULL)
windows[i].onFileSendRequest(&windows[i], m, friendnumber, filenumber, filesize,
filename, filename_length);
(const char *) filename, filename_length);
}
}
@ -204,7 +202,7 @@ void on_file_control (Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFileControl != NULL)
windows[i].onFileControl(&windows[i], m, friendnumber, receive_send, filenumber,
control_type, data, length);
control_type, (const char *) data, length);
}
}
@ -215,7 +213,7 @@ void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFileData != NULL)
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, data, length);
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, (const char *) data, length);
}
}
@ -254,17 +252,12 @@ int add_window(Tox *m, ToxWindow w)
return -1;
}
/* Deletes window w and cleans up */
void del_window(ToxWindow *w)
void set_active_window(int index)
{
active_window = windows; /* Go to prompt screen */
if (index < 0 || index >= MAX_WINDOWS_NUM)
return;
delwin(w->window);
memset(w, 0, sizeof(ToxWindow));
clear();
refresh();
--num_active_windows;
active_window = windows + index;
}
/* Shows next window when tab or back-tab is pressed */
@ -288,12 +281,17 @@ void set_next_window(int ch)
}
}
void set_active_window(int index)
/* Deletes window w and cleans up */
void del_window(ToxWindow *w)
{
if (index < 0 || index >= MAX_WINDOWS_NUM)
return;
set_active_window(0); /* Go to prompt screen */
active_window = windows + index;
delwin(w->window);
memset(w, 0, sizeof(ToxWindow));
clear();
refresh();
--num_active_windows;
}
ToxWindow *init_windows(Tox *m)
@ -322,7 +320,7 @@ void on_window_resize(void)
int i;
for (i == 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (!windows[i].active)
continue;
@ -334,6 +332,9 @@ void on_window_resize(void)
if (windows[i].is_friendlist)
continue;
if (w->help->active)
wclear(w->help->win);
if (w->is_groupchat)
delwin(w->chatwin->sidebar);
else
@ -439,7 +440,6 @@ void draw_active_window(Tox *m)
touchwin(a->window);
a->onDraw(a, m);
wrefresh(a->window);
/* Handle input */
bool ltr;
@ -495,6 +495,8 @@ int get_num_active_windows(void)
/* destroys all chat and groupchat windows (should only be called on shutdown) */
void kill_all_windows(void)
{
kill_prompt_window(prompt);
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {

View File

@ -36,6 +36,7 @@
#include "toxic.h"
#define MAX_WINDOWS_NUM 32
#define MAX_WINDOW_NAME_LENGTH 16
#define CURS_Y_OFFSET 1 /* y-axis cursor offset for chat contexts */
#define CHATBOX_HEIGHT 2
@ -65,6 +66,7 @@ enum {
struct _Winthread {
pthread_t tid;
pthread_mutex_t lock;
bool sig_exit_toxic;
bool flag_resize;
};
@ -78,21 +80,21 @@ struct ToxWindow {
void(*onKey)(ToxWindow *, Tox *, wint_t, bool);
void(*onDraw)(ToxWindow *, Tox *);
void(*onInit)(ToxWindow *, Tox *);
void(*onFriendRequest)(ToxWindow *, Tox *, const uint8_t *, const uint8_t *, uint16_t);
void(*onFriendRequest)(ToxWindow *, Tox *, const char *, const char *, uint16_t);
void(*onFriendAdded)(ToxWindow *, Tox *, int32_t, bool);
void(*onConnectionChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onMessage)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onNickChange)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onMessage)(ToxWindow *, Tox *, int32_t, const char *, uint16_t);
void(*onNickChange)(ToxWindow *, Tox *, int32_t, const char *, uint16_t);
void(*onStatusChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onStatusMessageChange)(ToxWindow *, int32_t, const uint8_t *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const uint8_t *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const uint8_t *, uint16_t);
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, const uint8_t *);
void(*onStatusMessageChange)(ToxWindow *, int32_t, const char *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int32_t, const char *, uint16_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, const char *);
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int, int, uint8_t);
void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t);
void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t);
void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, const uint8_t *, uint16_t);
void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, const char *, uint16_t);
void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, const char *, uint16_t);
void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t);
void(*onTypingChange)(ToxWindow *, Tox *, int32_t, uint8_t);
#ifdef _SUPPORT_AUDIO
@ -115,7 +117,7 @@ struct ToxWindow {
#endif /* _SUPPORT_AUDIO */
char name[TOX_MAX_NAME_LENGTH];
char name[TOXIC_MAX_NAME_LENGTH];
int32_t num; /* corresponds to friendnumber in chat windows */
bool active;
int x;
@ -139,10 +141,10 @@ struct ToxWindow {
/* statusbar info holder */
struct StatusBar {
WINDOW *topline;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmsg_len;
uint8_t nick[TOX_MAX_NAME_LENGTH];
uint16_t nick_len;
char nick[TOXIC_MAX_NAME_LENGTH];
int nick_len;
uint8_t status;
bool is_online;
};