mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 05:03:03 +01:00
begin port to new API
This commit is contained in:
parent
22dd883f28
commit
ae87b2eb2d
211
src/chat.c
211
src/chat.c
@ -105,14 +105,14 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
#endif /* AUDIO */
|
||||
};
|
||||
|
||||
static void set_self_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing)
|
||||
static void set_self_typingstatus(ToxWindow *self, Tox *m, bool is_typing)
|
||||
{
|
||||
if (user_settings->show_typing_self == SHOW_TYPING_OFF)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
tox_set_user_is_typing(m, self->num, is_typing);
|
||||
tox_self_set_typing(m, self->num, is_typing, NULL);
|
||||
ctx->self_is_typing = is_typing;
|
||||
}
|
||||
|
||||
@ -145,19 +145,11 @@ void kill_chat_window(ToxWindow *self, Tox *m)
|
||||
del_window(self);
|
||||
}
|
||||
|
||||
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg, uint16_t len)
|
||||
static void recv_message_helper(ToxWindow *self, Tox *m, uint32_t num, const char *msg, size_t len,
|
||||
const char *nick, const char *timefrmt)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", msg);
|
||||
write_to_log(msg, nick, ctx->log, false);
|
||||
|
||||
@ -165,13 +157,44 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, "%s", msg);
|
||||
else
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, nick, "%s", msg);
|
||||
}
|
||||
|
||||
static void recv_action_helper(ToxWindow *self, Tox *m, uint32_t num, const char *action, size_t len,
|
||||
const char *nick, const char *timefrmt)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
|
||||
write_to_log(action, nick, ctx->log, true);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
||||
else
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action );
|
||||
}
|
||||
|
||||
static void chat_onMessage(ToxWindow *self, Tox *m, uint32_t num, TOX_MESSAGE_TYPE type, const char *msg, size_t len)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
if (type == TOX_MESSAGE_TYPE_NORMAL)
|
||||
return recv_message_helper(self, m, num, msg, len, nick, timefrmt);
|
||||
|
||||
if (type == TOX_MESSAGE_TYPE_ACTION)
|
||||
return recv_action_helper(self, m, num, msg, len, nick, timefrmt);
|
||||
}
|
||||
|
||||
static void chat_resume_file_transfers(Tox *m, int fnum);
|
||||
static void chat_stop_file_senders(int fnum);
|
||||
|
||||
static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||
static void chat_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, TOX_CONNECTION connection_status)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -186,18 +209,18 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
if (status == 1) { /* Friend goes online */
|
||||
statusbar->is_online = true;
|
||||
statusbar->connection = connection_status;
|
||||
|
||||
if (connection_status != TOX_CONNECTION_NONE) {
|
||||
Friends.list[num].is_typing = user_settings->show_typing_other == SHOW_TYPING_ON
|
||||
? tox_get_is_typing(m, num) : 0;
|
||||
? tox_friend_get_typing(m, num, NULL) : false;
|
||||
chat_resume_file_transfers(m, num);
|
||||
|
||||
msg = "has come online";
|
||||
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
|
||||
write_to_log(msg, nick, ctx->log, true);
|
||||
} else { /* Friend goes offline */
|
||||
statusbar->is_online = false;
|
||||
Friends.list[num].is_typing = 0;
|
||||
} else {
|
||||
Friends.list[num].is_typing = false;
|
||||
|
||||
if (self->chatwin->self_is_typing)
|
||||
set_self_typingstatus(self, m, 0);
|
||||
@ -210,7 +233,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
|
||||
}
|
||||
}
|
||||
|
||||
static void chat_onTypingChange(ToxWindow *self, Tox *m, int32_t num, uint8_t is_typing)
|
||||
static void chat_onTypingChange(ToxWindow *self, Tox *m, uint32_t num, bool is_typing)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -218,29 +241,7 @@ static void chat_onTypingChange(ToxWindow *self, Tox *m, int32_t num, uint8_t is
|
||||
Friends.list[num].is_typing = is_typing;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
|
||||
write_to_log(action, nick, ctx->log, true);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
||||
else
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action );
|
||||
}
|
||||
|
||||
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
|
||||
static void chat_onNickChange(ToxWindow *self, Tox *m, uint32_t num, const char *nick, size_t length)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -248,13 +249,13 @@ static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *
|
||||
StatusBar *statusbar = self->stb;
|
||||
|
||||
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
||||
len = strlen(statusbar->nick);
|
||||
statusbar->nick_len = len;
|
||||
length = strlen(statusbar->nick);
|
||||
statusbar->nick_len = length;
|
||||
|
||||
set_window_title(self, statusbar->nick, len);
|
||||
set_window_title(self, statusbar->nick, length);
|
||||
}
|
||||
|
||||
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||
static void chat_onStatusChange(ToxWindow *self, Tox *m, uint32_t num, TOX_USER_STATUS status)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -263,7 +264,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 char *status, uint16_t len)
|
||||
static void chat_onStatusMessageChange(ToxWindow *self, uint32_t num, const char *status, size_t length)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -274,13 +275,13 @@ static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const char
|
||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||
}
|
||||
|
||||
static void chat_onReadReceipt(ToxWindow *self, Tox *m, int32_t num, uint32_t receipt)
|
||||
static void chat_onReadReceipt(ToxWindow *self, Tox *m, uint32_t num, uint32_t receipt)
|
||||
{
|
||||
cqueue_remove(self, m, receipt);
|
||||
}
|
||||
|
||||
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
|
||||
uint64_t filesize, const char *pathname, uint16_t path_len)
|
||||
static void chat_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t num, uint32_t filenum, uint64_t position,
|
||||
size_t length);
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -416,8 +417,23 @@ static void close_all_file_receivers(Tox *m, int friendnum)
|
||||
}
|
||||
}
|
||||
|
||||
static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t receive_send,
|
||||
uint8_t filenum, uint8_t control_type, const char *data, uint16_t length)
|
||||
static void chat_onFileRecvChunk(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, uint64_t position,
|
||||
const char *data, size_t length)
|
||||
{
|
||||
FILE *fp = Friends.list[friendnum].file_receiver[filenum].file;
|
||||
|
||||
if (fp) {
|
||||
if (fwrite(data, length, 1, fp) != 1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Error writing to file.");
|
||||
chat_close_file_receiver(m, filenum, friendnum, TOX_FILECONTROL_KILL);
|
||||
}
|
||||
}
|
||||
|
||||
Friends.list[friendnum].file_receiver[filenum].bps += length;
|
||||
Friends.list[friendnum].file_receiver[filenum].bytes_recv += length;
|
||||
}
|
||||
|
||||
static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t num, uint32_t filenum, TOX_FILE_CONTROL control)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
@ -447,7 +463,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
|
||||
filename = file_senders[send_idx].filename;
|
||||
}
|
||||
|
||||
switch (control_type) {
|
||||
switch (control) {
|
||||
case TOX_FILECONTROL_ACCEPT:
|
||||
if (receive_send != 1)
|
||||
break;
|
||||
@ -479,10 +495,10 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
|
||||
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, error, NT_NOFOCUS | NT_WNDALERT_2,
|
||||
box_notify2(self, notif_error, NT_NOFOCUS | NT_WNDALERT_2,
|
||||
self->active_box, "File transfer for '%s' failed!", filename );
|
||||
else
|
||||
box_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
|
||||
box_notify(self, notif_error, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
|
||||
self->name, "File transfer for '%s' failed!", filename );
|
||||
|
||||
if (receive_send == 0)
|
||||
@ -501,7 +517,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
|
||||
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename_nopath);
|
||||
chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_FINISHED);
|
||||
} else {
|
||||
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", filename);
|
||||
snprintf(msg, sizeof(msg), "File '%s' successfully sent.", filename);
|
||||
close_file_sender(self, m, send_idx, NULL, TOX_FILECONTROL_FINISHED, filenum, num);
|
||||
}
|
||||
|
||||
@ -543,27 +559,17 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||
}
|
||||
|
||||
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
|
||||
uint16_t length)
|
||||
static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, uint32_t kind,
|
||||
uint64_t file_size, const char *filename, size_t name_length)
|
||||
{
|
||||
if (self->num != num)
|
||||
if (self->num != friendnum)
|
||||
return;
|
||||
|
||||
FILE *fp = Friends.list[num].file_receiver[filenum].file;
|
||||
|
||||
if (fp) {
|
||||
if (fwrite(data, length, 1, fp) != 1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Error writing to file.");
|
||||
chat_close_file_receiver(m, filenum, num, TOX_FILECONTROL_KILL);
|
||||
}
|
||||
}
|
||||
|
||||
Friends.list[num].file_receiver[filenum].bps += length;
|
||||
Friends.list[num].file_receiver[filenum].bytes_recv += length;
|
||||
}
|
||||
|
||||
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
|
||||
uint16_t length)
|
||||
size_t length)
|
||||
{
|
||||
if (self->num != friendnumber)
|
||||
return;
|
||||
@ -845,7 +851,9 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
|
||||
return;
|
||||
|
||||
char selfname[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
|
||||
tox_self_get_name(m, (uint8_t *) selfname);
|
||||
|
||||
size_t len = tox_self_get_name_size(m);
|
||||
selfname[len] = '\0';
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
@ -876,7 +884,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
if (ltr) { /* char is printable */
|
||||
input_new_char(self, key, x, y, x2, y2);
|
||||
|
||||
if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->is_online)
|
||||
if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->connection != TOX_CONNECTION_NONE)
|
||||
set_self_typingstatus(self, m, 1);
|
||||
|
||||
return;
|
||||
@ -912,7 +920,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
||||
}
|
||||
} else {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
|
||||
} else if (key == '\n') {
|
||||
@ -937,7 +945,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
}
|
||||
} else if (!string_is_empty(line)) {
|
||||
char selfname[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
|
||||
tox_self_get_name(m, (uint8_t *) selfname);
|
||||
|
||||
size_t len = tox_self_get_name_size(m);
|
||||
selfname[len] = '\0';
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
@ -977,26 +987,20 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
wmove(statusbar->topline, 0, 0);
|
||||
|
||||
/* Draw name, status and note in statusbar */
|
||||
if (statusbar->is_online) {
|
||||
int colour = WHITE;
|
||||
uint8_t status = statusbar->status;
|
||||
if (statusbar->connection != TOX_CONNECTION_NONE) {
|
||||
int colour = MAGENTA;
|
||||
TOX_USER_STATUS status = statusbar->status;
|
||||
|
||||
switch (status) {
|
||||
case TOX_USERSTATUS_NONE:
|
||||
case TOX_USER_STATUS_NONE:
|
||||
colour = GREEN;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_AWAY:
|
||||
case TOX_USER_STATUS_AWAY:
|
||||
colour = YELLOW;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_BUSY:
|
||||
case TOX_USER_STATUS_BUSY:
|
||||
colour = RED;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_INVALID:
|
||||
colour = MAGENTA;
|
||||
break;
|
||||
}
|
||||
|
||||
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
||||
@ -1021,10 +1025,11 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
/* Reset statusbar->statusmsg on window resize */
|
||||
if (x2 != self->x) {
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH] = {'\0'};
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
int s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
||||
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
@ -1035,7 +1040,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
self->x = x2;
|
||||
|
||||
/* Truncate note if it doesn't fit in statusbar */
|
||||
uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
|
||||
size_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
|
||||
|
||||
if (statusbar->statusmsg_len > maxlen) {
|
||||
statusbar->statusmsg[maxlen - 3] = '\0';
|
||||
@ -1088,11 +1093,13 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
/* Init statusbar info */
|
||||
StatusBar *statusbar = self->stb;
|
||||
|
||||
statusbar->status = tox_get_user_status(m, self->num);
|
||||
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
|
||||
statusbar->status = tox_friend_get_status(m, self->num, NULL);
|
||||
statusbar->connection = tox_friend_get_connection_status(m, self->num, NULL);
|
||||
|
||||
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);
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
||||
|
||||
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
||||
statusmsg[s_len] = '\0';
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
@ -1100,7 +1107,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH + 1];
|
||||
int n_len = get_nick_truncate(m, nick, self->num);
|
||||
size_t n_len = get_nick_truncate(m, nick, self->num);
|
||||
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
||||
statusbar->nick_len = n_len;
|
||||
|
||||
@ -1120,8 +1127,8 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
|
||||
line_info_init(ctx->hst);
|
||||
|
||||
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, (uint8_t *) myid);
|
||||
char myid[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(m, (uint8_t *) myid);
|
||||
|
||||
log_enable(nick, myid, Friends.list[self->num].pub_key, ctx->log, LOG_CHAT);
|
||||
load_chat_history(self, ctx->log);
|
||||
@ -1135,7 +1142,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||
}
|
||||
|
||||
ToxWindow new_chat(Tox *m, int32_t friendnum)
|
||||
ToxWindow new_chat(Tox *m, uint32_t friendnum)
|
||||
{
|
||||
ToxWindow ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
@ -1153,10 +1160,10 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
|
||||
ret.onNickChange = &chat_onNickChange;
|
||||
ret.onStatusChange = &chat_onStatusChange;
|
||||
ret.onStatusMessageChange = &chat_onStatusMessageChange;
|
||||
ret.onAction = &chat_onAction;
|
||||
ret.onFileSendRequest = &chat_onFileSendRequest;
|
||||
ret.onFileChunkRequest = &chat_onFileChunkRequest;
|
||||
ret.onFileRecvChunk = &chat_onFileRecvChunk;
|
||||
ret.onFileControl = &chat_onFileControl;
|
||||
ret.onFileData = &chat_onFileData;
|
||||
ret.onFileRecv = &chat_onFileRecv;
|
||||
ret.onReadReceipt = &chat_onReadReceipt;
|
||||
|
||||
#ifdef AUDIO
|
||||
@ -1180,7 +1187,7 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
|
||||
ret.active_box = -1;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
int n_len = get_nick_truncate(m, nick, friendnum);
|
||||
size_t n_len = get_nick_truncate(m, nick, friendnum);
|
||||
set_window_title(&ret, nick, n_len);
|
||||
|
||||
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
||||
|
30
src/dns.c
30
src/dns.c
@ -75,7 +75,7 @@ static struct dns3_server_backup {
|
||||
|
||||
static struct thread_data {
|
||||
ToxWindow *self;
|
||||
char id_bin[TOX_FRIEND_ADDRESS_SIZE];
|
||||
char id_bin[TOX_ADDRESS_SIZE];
|
||||
char addr[MAX_STR_SIZE];
|
||||
char msg[MAX_STR_SIZE];
|
||||
uint8_t busy;
|
||||
@ -168,39 +168,39 @@ static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, char
|
||||
uint8_t *ans_pt = answer + sizeof(HEADER);
|
||||
uint8_t *ans_end = answer + ans_len;
|
||||
char exp_ans[PACKETSZ];
|
||||
|
||||
|
||||
int len = dn_expand(answer, ans_end, ans_pt, exp_ans, sizeof(exp_ans));
|
||||
|
||||
if (len == -1)
|
||||
return dns_error(self, "dn_expand failed.");
|
||||
return dns_error(self, "dn_expand failed.");
|
||||
|
||||
ans_pt += len;
|
||||
|
||||
if (ans_pt > ans_end - 4)
|
||||
return dns_error(self, "DNS reply was too short.");
|
||||
return dns_error(self, "DNS reply was too short.");
|
||||
|
||||
int type;
|
||||
GETSHORT(type, ans_pt);
|
||||
|
||||
if (type != T_TXT)
|
||||
return dns_error(self, "Broken DNS reply.");
|
||||
|
||||
return dns_error(self, "Broken DNS reply.");
|
||||
|
||||
|
||||
ans_pt += INT16SZ; /* class */
|
||||
uint32_t size = 0;
|
||||
|
||||
/* recurse through CNAME rr's */
|
||||
do {
|
||||
do {
|
||||
ans_pt += size;
|
||||
len = dn_expand(answer, ans_end, ans_pt, exp_ans, sizeof(exp_ans));
|
||||
|
||||
if (len == -1)
|
||||
return dns_error(self, "Second dn_expand failed.");
|
||||
return dns_error(self, "Second dn_expand failed.");
|
||||
|
||||
ans_pt += len;
|
||||
|
||||
if (ans_pt > ans_end - 10)
|
||||
return dns_error(self, "DNS reply was too short.");
|
||||
return dns_error(self, "DNS reply was too short.");
|
||||
|
||||
GETSHORT(type, ans_pt);
|
||||
ans_pt += INT16SZ;
|
||||
@ -208,12 +208,12 @@ static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, char
|
||||
GETSHORT(size, ans_pt);
|
||||
|
||||
if (ans_pt + size < answer || ans_pt + size > ans_end)
|
||||
return dns_error(self, "RR overflow.");
|
||||
return dns_error(self, "RR overflow.");
|
||||
|
||||
} while (type == T_CNAME);
|
||||
|
||||
if (type != T_TXT)
|
||||
return dns_error(self, "DNS response failed.");
|
||||
return dns_error(self, "DNS response failed.");
|
||||
|
||||
uint32_t txt_len = *ans_pt;
|
||||
|
||||
@ -230,7 +230,7 @@ static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, char
|
||||
return txt_len;
|
||||
}
|
||||
|
||||
/* Takes address addr in the form "username@domain", puts the username in namebuf,
|
||||
/* Takes address addr in the form "username@domain", puts the username in namebuf,
|
||||
and the domain in dombuf.
|
||||
|
||||
return length of username on success, -1 on failure */
|
||||
@ -322,7 +322,7 @@ void *dns3_lookup_thread(void *data)
|
||||
char string[MAX_DNS_REQST_SIZE + 1];
|
||||
uint32_t request_id;
|
||||
|
||||
int str_len = tox_generate_dns3_string(dns_obj, (uint8_t *) string, sizeof(string), &request_id,
|
||||
int str_len = tox_generate_dns3_string(dns_obj, (uint8_t *) string, sizeof(string), &request_id,
|
||||
(uint8_t *) name, namelen);
|
||||
|
||||
if (str_len == -1) {
|
||||
@ -361,7 +361,7 @@ void *dns3_lookup_thread(void *data)
|
||||
|
||||
memcpy(encrypted_id, ans_id + prfx_len, ans_len - prfx_len);
|
||||
|
||||
if (tox_decrypt_dns3_TXT(dns_obj, (uint8_t *) t_data.id_bin, (uint8_t *) encrypted_id,
|
||||
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.");
|
||||
killdns_thread(dns_obj);
|
||||
@ -378,7 +378,7 @@ void *dns3_lookup_thread(void *data)
|
||||
/* creates new thread for dns3 lookup. Only allows one lookup at a time. */
|
||||
void dns3_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *msg)
|
||||
{
|
||||
if (arg_opts.proxy_type != TOX_PROXY_NONE && arg_opts.force_tcp) {
|
||||
if (arg_opts.proxy_type != TOX_PROXY_TYPE_NONE && arg_opts.force_tcp) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "DNS lookups are disabled.");
|
||||
return;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ void prep_prog_line(char *progline)
|
||||
strcat(progline, "] 0%");
|
||||
}
|
||||
|
||||
/* prints a progress bar for file transfers.
|
||||
/* prints a progress bar for file transfers.
|
||||
if friendnum is -1 we're sending the file, otherwise we're receiving. */
|
||||
void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_done)
|
||||
{
|
||||
@ -136,7 +136,7 @@ static void refresh_sender_prog(Tox *m)
|
||||
continue;
|
||||
|
||||
int filenum = file_senders[i].filenum;
|
||||
int32_t friendnum = file_senders[i].friendnum;
|
||||
uint32_t friendnum = file_senders[i].friendnum;
|
||||
double remain = (double) tox_file_data_remaining(m, friendnum, filenum, 0);
|
||||
|
||||
/* must be called once per second */
|
||||
@ -175,11 +175,11 @@ void reset_file_sender_queue(void)
|
||||
|
||||
/* set CTRL to -1 if we don't want to send a control signal.
|
||||
set msg to NULL if we don't want to display a message */
|
||||
void close_file_sender(ToxWindow *self, Tox *m, int i, const char *msg, int CTRL, int filenum, int32_t friendnum)
|
||||
void close_file_sender(ToxWindow *self, Tox *m, int i, const char *msg, int CTRL, int filenum, uint32_t friendnum)
|
||||
{
|
||||
if (msg != NULL)
|
||||
if (msg != NULL)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||
|
||||
|
||||
if (CTRL > 0)
|
||||
tox_file_send_control(m, friendnum, 0, filenum, CTRL, 0, 0);
|
||||
|
||||
@ -192,7 +192,7 @@ void close_file_sender(ToxWindow *self, Tox *m, int i, const char *msg, int CTRL
|
||||
|
||||
void close_all_file_senders(Tox *m)
|
||||
{
|
||||
int i;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < max_file_senders_index; ++i) {
|
||||
if (file_senders[i].active) {
|
||||
@ -206,17 +206,21 @@ void close_all_file_senders(Tox *m)
|
||||
}
|
||||
}
|
||||
|
||||
static void send_file_data(ToxWindow *self, Tox *m, int i, int32_t friendnum, int filenum, const char *filename)
|
||||
static void send_file_data(ToxWindow *self, Tox *m, uint8_t i, uint32_t friendnum, uint32_t filenum,
|
||||
const char *filename)
|
||||
{
|
||||
FILE *fp = file_senders[i].file;
|
||||
|
||||
while (true) {
|
||||
if (tox_file_send_data(m, friendnum, filenum, (uint8_t *) file_senders[i].nextpiece,
|
||||
file_senders[i].piecelen) == -1)
|
||||
TOX_ERR_FILE_SEND_CHUNK err;
|
||||
if (!tox_file_send_chunk(m, friendnum, filenum, (uint8_t *) file_senders[i].nextpiece,
|
||||
file_senders[i].piecelen, &err) {
|
||||
fprintf(stderr, "tox_file_send_chunk failed with error %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
file_senders[i].timestamp = get_unix_time();
|
||||
file_senders[i].bps += file_senders[i].piecelen;
|
||||
file_senders[i].bps += file_senders[i].piecelen;
|
||||
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
|
||||
tox_file_data_size(m, friendnum), fp);
|
||||
|
||||
@ -259,7 +263,7 @@ void do_file_senders(Tox *m)
|
||||
ToxWindow *self = file_senders[i].toxwin;
|
||||
char *filename = file_senders[i].filename;
|
||||
int filenum = file_senders[i].filenum;
|
||||
int32_t friendnum = file_senders[i].friendnum;
|
||||
uint32_t friendnum = file_senders[i].friendnum;
|
||||
|
||||
/* kill file transfer if chatwindow is closed */
|
||||
if (self->chatwin == NULL) {
|
||||
@ -273,7 +277,7 @@ void do_file_senders(Tox *m)
|
||||
char msg[MAX_STR_SIZE];
|
||||
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", filename);
|
||||
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
|
||||
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, error, NT_NOFOCUS | NT_WNDALERT_2, self->active_box, "%s", msg);
|
||||
else
|
||||
|
@ -37,7 +37,7 @@
|
||||
typedef struct {
|
||||
FILE *file;
|
||||
ToxWindow *toxwin;
|
||||
int32_t friendnum;
|
||||
uint32_t friendnum;
|
||||
bool active;
|
||||
bool noconnection; /* set when the connection has been interrupted */
|
||||
bool paused; /* set when transfer has been explicitly paused */
|
||||
@ -45,7 +45,7 @@ typedef struct {
|
||||
bool started; /* set after TOX_FILECONTROL_ACCEPT received */
|
||||
int filenum;
|
||||
char nextpiece[FILE_PIECE_SIZE];
|
||||
uint16_t piecelen;
|
||||
size_t piecelen;
|
||||
char filename[MAX_STR_SIZE];
|
||||
uint64_t timestamp; /* marks the last time data was successfully transfered */
|
||||
uint64_t last_progress; /* marks the last time the progress bar was refreshed */
|
||||
@ -59,7 +59,7 @@ typedef struct {
|
||||
Assumes progline is of size MAX_STR_SIZE */
|
||||
void prep_prog_line(char *progline);
|
||||
|
||||
/* prints a progress bar for file transfers.
|
||||
/* prints a progress bar for file transfers.
|
||||
if friendnum is -1 we're sending the file, otherwise we're receiving. */
|
||||
void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_remain);
|
||||
|
||||
|
277
src/friendlist.c
277
src/friendlist.c
@ -59,16 +59,15 @@ static struct Blocked {
|
||||
int num_selected;
|
||||
int max_idx;
|
||||
int num_blocked;
|
||||
|
||||
int *index;
|
||||
uint32_t *index;
|
||||
BlockedFriend *list;
|
||||
} Blocked;
|
||||
|
||||
static struct pendingDel {
|
||||
int num;
|
||||
static struct PendingDel {
|
||||
uint32_t num;
|
||||
bool active;
|
||||
WINDOW *popup;
|
||||
} pendingdelete;
|
||||
} PendingDelete;
|
||||
|
||||
static void realloc_friends(int n)
|
||||
{
|
||||
@ -81,7 +80,7 @@ static void realloc_friends(int n)
|
||||
}
|
||||
|
||||
ToxicFriend *f = realloc(Friends.list, n * sizeof(ToxicFriend));
|
||||
int *f_idx = realloc(Friends.index, n * sizeof(int));
|
||||
uint32_t *f_idx = realloc(Friends.index, n * sizeof(uint32_t));
|
||||
|
||||
if (f == NULL || f_idx == NULL)
|
||||
exit_toxic_err("failed in realloc_friends", FATALERR_MEMORY);
|
||||
@ -101,7 +100,7 @@ static void realloc_blocklist(int n)
|
||||
}
|
||||
|
||||
BlockedFriend *b = realloc(Blocked.list, n * sizeof(BlockedFriend));
|
||||
int *b_idx = realloc(Blocked.index, n * sizeof(int));
|
||||
uint32_t *b_idx = realloc(Blocked.index, n * sizeof(uint32_t));
|
||||
|
||||
if (b == NULL || b_idx == NULL)
|
||||
exit_toxic_err("failed in realloc_blocklist", FATALERR_MEMORY);
|
||||
@ -125,9 +124,6 @@ void kill_friendlist(void)
|
||||
|
||||
static int save_blocklist(char *path)
|
||||
{
|
||||
if (arg_opts.ignore_data_file)
|
||||
return 0;
|
||||
|
||||
if (path == NULL)
|
||||
return -1;
|
||||
|
||||
@ -252,11 +248,11 @@ int load_blocklist(char *path)
|
||||
#define S_WEIGHT 100000
|
||||
static int index_name_cmp(const void *n1, const void *n2)
|
||||
{
|
||||
int res = qsort_strcasecmp_hlpr(Friends.list[*(int *) n1].name, Friends.list[*(int *) n2].name);
|
||||
int res = qsort_strcasecmp_hlpr(Friends.list[*(size_t *) n1].name, Friends.list[*(size_t *) n2].name);
|
||||
|
||||
/* Use weight to make qsort always put online friends before offline */
|
||||
res = Friends.list[*(int *) n1].online ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
||||
res = Friends.list[*(int *) n2].online ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
||||
res = Friends.list[*(size_t *) n1].connection_status != TOX_CONNECTION_NONE ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
||||
res = Friends.list[*(size_t *) n2].connection_status != TOX_CONNECTION_NONE ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -265,19 +261,19 @@ static int index_name_cmp(const void *n1, const void *n2)
|
||||
void sort_friendlist_index(void)
|
||||
{
|
||||
int i;
|
||||
int n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
for (i = 0; i < Friends.max_idx; ++i) {
|
||||
if (Friends.list[i].active)
|
||||
Friends.index[n++] = Friends.list[i].num;
|
||||
}
|
||||
|
||||
qsort(Friends.index, Friends.num_friends, sizeof(int), index_name_cmp);
|
||||
qsort(Friends.index, Friends.num_friends, sizeof(uint32_t), index_name_cmp);
|
||||
}
|
||||
|
||||
static int index_name_cmp_block(const void *n1, const void *n2)
|
||||
{
|
||||
return qsort_strcasecmp_hlpr(Blocked.list[*(int *) n1].name, Blocked.list[*(int *) n2].name);
|
||||
return qsort_strcasecmp_hlpr(Blocked.list[*(size_t *) n1].name, Blocked.list[*(size_t *) n2].name);
|
||||
}
|
||||
|
||||
static void sort_blocklist_index(void)
|
||||
@ -290,7 +286,7 @@ static void sort_blocklist_index(void)
|
||||
Blocked.index[n++] = Blocked.list[i].num;
|
||||
}
|
||||
|
||||
qsort(Blocked.index, Blocked.num_blocked, sizeof(int), index_name_cmp_block);
|
||||
qsort(Blocked.index, Blocked.num_blocked, sizeof(uint32_t), index_name_cmp_block);
|
||||
}
|
||||
|
||||
static void update_friend_last_online(int32_t num, uint64_t timestamp)
|
||||
@ -304,42 +300,48 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp)
|
||||
&Friends.list[num].last_online.tm);
|
||||
}
|
||||
|
||||
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *str, uint16_t len)
|
||||
static void friendlist_onMessage(ToxWindow *self, Tox *m, uint32_t num, TOX_MESSAGE_TYPE type, const char *str,
|
||||
size_t length)
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
|
||||
if (Friends.list[num].chatwin == -1) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
} else {
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
if (Friends.list[num].chatwin != -1)
|
||||
return;
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", str);
|
||||
|
||||
const char *msg = "* Warning: Too many windows are open.";
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
|
||||
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
return;
|
||||
}
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", str);
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Warning: Too many windows are open.");
|
||||
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
|
||||
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, TOX_CONNECTION connection_status)
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
|
||||
Friends.list[num].online = status;
|
||||
if (connection_status == TOX_CONNECTION_NONE)
|
||||
--Friends.num_online;
|
||||
else
|
||||
++Friends.num_online;
|
||||
|
||||
Friends.list[num].connection_status = connection_status;
|
||||
update_friend_last_online(num, get_unix_time());
|
||||
store_data(m, DATA_FILE);
|
||||
sort_friendlist_index();
|
||||
}
|
||||
|
||||
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
|
||||
static void friendlist_onNickChange(ToxWindow *self, Tox *m, uint32_t num, const char *nick, size_t length)
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
@ -354,9 +356,9 @@ static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const
|
||||
|
||||
/* get data for chatlog renaming */
|
||||
char newnamecpy[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
char myid[TOX_ADDRESS_SIZE];
|
||||
strcpy(newnamecpy, Friends.list[num].name);
|
||||
tox_get_address(m, (uint8_t *) myid);
|
||||
tox_self_get_address(m, (uint8_t *) myid);
|
||||
|
||||
if (strcmp(oldname, newnamecpy) != 0)
|
||||
rename_logfile(oldname, newnamecpy, myid, Friends.list[num].pub_key, Friends.list[num].chatwin);
|
||||
@ -364,7 +366,7 @@ static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const
|
||||
sort_friendlist_index();
|
||||
}
|
||||
|
||||
static void friendlist_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||
static void friendlist_onStatusChange(ToxWindow *self, Tox *m, uint32_t num, TOX_USER_STATUS status)
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
@ -372,22 +374,21 @@ static void friendlist_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint
|
||||
Friends.list[num].status = status;
|
||||
}
|
||||
|
||||
static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, const char *status, uint16_t len)
|
||||
static void friendlist_onStatusMessageChange(ToxWindow *self, uint32_t num, const char *note, size_t length)
|
||||
{
|
||||
if (len > TOX_MAX_STATUSMESSAGE_LENGTH || num >= Friends.max_idx)
|
||||
if (len > TOX_MAX_STATUS_MESSAGE_LENGTH || num >= Friends.max_idx)
|
||||
return;
|
||||
|
||||
snprintf(Friends.list[num].statusmsg, sizeof(Friends.list[num].statusmsg), "%s", status);
|
||||
snprintf(Friends.list[num].statusmsg, sizeof(Friends.list[num].statusmsg), "%s", note);
|
||||
Friends.list[num].statusmsg_len = strlen(Friends.list[num].statusmsg);
|
||||
}
|
||||
|
||||
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
|
||||
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort)
|
||||
{
|
||||
if (Friends.max_idx < 0)
|
||||
return;
|
||||
|
||||
|
||||
Friends.num_friends = tox_count_friendlist(m);
|
||||
Friends.num_friends = tox_self_get_friend_list_size(m);
|
||||
realloc_friends(Friends.max_idx + 1);
|
||||
memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend));
|
||||
|
||||
@ -400,11 +401,12 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
|
||||
Friends.list[i].num = num;
|
||||
Friends.list[i].active = true;
|
||||
Friends.list[i].chatwin = -1;
|
||||
Friends.list[i].online = false;
|
||||
Friends.list[i].status = TOX_USERSTATUS_NONE;
|
||||
Friends.list[i].connection_status = TOX_CONNECTION_NONE;
|
||||
Friends.list[i].status = TOX_USER_STATUS_NONE;
|
||||
Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
||||
tox_get_client_id(m, num, (uint8_t *) Friends.list[i].pub_key);
|
||||
update_friend_last_online(i, tox_get_last_online(m, i));
|
||||
|
||||
tox_friend_get_public_key(m, num, (uint8_t *) Friends.list[i].pub_key, NULL);
|
||||
update_friend_last_online(i, 0);
|
||||
|
||||
char tempname[TOX_MAX_NAME_LENGTH] = {0};
|
||||
int len = get_nick_truncate(m, tempname, num);
|
||||
@ -428,7 +430,7 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
|
||||
}
|
||||
|
||||
/* puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number */
|
||||
static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
|
||||
static void friendlist_add_blocked(Tox *m, uint32_t fnum, uint32_t bnum)
|
||||
{
|
||||
Friends.num_friends = tox_count_friendlist(m);
|
||||
realloc_friends(Friends.max_idx + 1);
|
||||
@ -443,7 +445,7 @@ static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
|
||||
Friends.list[i].num = fnum;
|
||||
Friends.list[i].active = true;
|
||||
Friends.list[i].chatwin = -1;
|
||||
Friends.list[i].status = TOX_USERSTATUS_NONE;
|
||||
Friends.list[i].status = TOX_USER_STATUS_NONE;
|
||||
Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
||||
Friends.list[i].namelength = Blocked.list[bnum].namelength;
|
||||
update_friend_last_online(i, Blocked.list[bnum].last_on);
|
||||
@ -460,46 +462,52 @@ static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
|
||||
}
|
||||
}
|
||||
|
||||
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
|
||||
uint64_t filesize, const char *filename, uint16_t filename_len)
|
||||
static void friendlist_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t num, uint32_t filenum,
|
||||
uint64_t position, size_t length);
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
|
||||
if (Friends.list[num].chatwin == -1) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
} else {
|
||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||
if (Friends.list[num].chatwin != -1)
|
||||
return;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
|
||||
"* File transfer from %s failed: too many windows are open.", nick);
|
||||
|
||||
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
return;
|
||||
}
|
||||
|
||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
|
||||
"* File transfer from %s failed: too many windows are open.", nick);
|
||||
|
||||
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
|
||||
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t type, const char *group_pub_key,
|
||||
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, uint32_t num, uint8_t type, const char *group_pub_key,
|
||||
uint16_t length)
|
||||
{
|
||||
if (num >= Friends.max_idx)
|
||||
return;
|
||||
|
||||
if (Friends.list[num].chatwin == -1) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
} else {
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
|
||||
"* Group chat invite from %s failed: too many windows are open.", nick);
|
||||
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
if (Friends.list[num].chatwin != -1)
|
||||
return;
|
||||
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
||||
return
|
||||
}
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, nick, num);
|
||||
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
|
||||
"* Group chat invite from %s failed: too many windows are open.", nick);
|
||||
|
||||
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
|
||||
/* move friendlist/blocklist cursor up and down */
|
||||
@ -516,7 +524,7 @@ static void select_friend(ToxWindow *self, wint_t key, int *selected, int num)
|
||||
}
|
||||
}
|
||||
|
||||
static void delete_friend(Tox *m, int32_t f_num)
|
||||
static void delete_friend(Tox *m, uint32_t f_num)
|
||||
{
|
||||
if (Friends.list[f_num].chatwin >= 0) {
|
||||
ToxWindow *toxwin = get_window_ptr(Friends.list[f_num].chatwin);
|
||||
@ -530,7 +538,6 @@ static void delete_friend(Tox *m, int32_t f_num)
|
||||
if (Friends.list[f_num].group_invite.key != NULL)
|
||||
free(Friends.list[f_num].group_invite.key);
|
||||
|
||||
tox_del_friend(m, f_num);
|
||||
memset(&Friends.list[f_num], 0, sizeof(ToxicFriend));
|
||||
|
||||
int i;
|
||||
@ -548,64 +555,68 @@ static void delete_friend(Tox *m, int32_t f_num)
|
||||
if (Friends.num_friends && Friends.num_selected == Friends.num_friends)
|
||||
--Friends.num_selected;
|
||||
|
||||
TOX_ERR_FRIEND_DELETE err;
|
||||
if (tox_friend_delete(m, f_num, &err) != 1)
|
||||
fprintf(stderr, "tox_friend_delete failed with error %d\n", err);
|
||||
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
|
||||
/* activates delete friend popup */
|
||||
static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num)
|
||||
static void del_friend_activate(ToxWindow *self, Tox *m, uint32_t f_num)
|
||||
{
|
||||
pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
|
||||
pendingdelete.active = true;
|
||||
pendingdelete.num = f_num;
|
||||
PendingDelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
|
||||
PendingDelete.active = true;
|
||||
PendingDelete.num = f_num;
|
||||
}
|
||||
|
||||
static void delete_blocked_friend(int32_t bnum);
|
||||
static void delete_blocked_friend(uint32_t bnum);
|
||||
|
||||
/* deactivates delete friend popup and deletes friend if instructed */
|
||||
static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
if (key == 'y') {
|
||||
if (blocklist_view == 0) {
|
||||
delete_friend(m, pendingdelete.num);
|
||||
delete_friend(m, PendingDelete.num);
|
||||
sort_friendlist_index();
|
||||
} else {
|
||||
delete_blocked_friend(pendingdelete.num);
|
||||
delete_blocked_friend(PendingDelete.num);
|
||||
sort_blocklist_index();
|
||||
}
|
||||
}
|
||||
|
||||
delwin(pendingdelete.popup);
|
||||
memset(&pendingdelete, 0, sizeof(pendingdelete));
|
||||
delwin(PendingDelete.popup);
|
||||
memset(&PendingDelete, 0, sizeof(PendingDelete));
|
||||
clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void draw_del_popup(void)
|
||||
{
|
||||
if (!pendingdelete.active)
|
||||
if (!PendingDelete.active)
|
||||
return;
|
||||
|
||||
wattron(pendingdelete.popup, A_BOLD);
|
||||
box(pendingdelete.popup, ACS_VLINE, ACS_HLINE);
|
||||
wattroff(pendingdelete.popup, A_BOLD);
|
||||
wattron(PendingDelete.popup, A_BOLD);
|
||||
box(PendingDelete.popup, ACS_VLINE, ACS_HLINE);
|
||||
wattroff(PendingDelete.popup, A_BOLD);
|
||||
|
||||
wmove(pendingdelete.popup, 1, 1);
|
||||
wprintw(pendingdelete.popup, "Delete contact ");
|
||||
wattron(pendingdelete.popup, A_BOLD);
|
||||
wmove(PendingDelete.popup, 1, 1);
|
||||
wprintw(PendingDelete.popup, "Delete contact ");
|
||||
wattron(PendingDelete.popup, A_BOLD);
|
||||
|
||||
if (blocklist_view == 0)
|
||||
wprintw(pendingdelete.popup, "%s", Friends.list[pendingdelete.num].name);
|
||||
wprintw(PendingDelete.popup, "%s", Friends.list[PendingDelete.num].name);
|
||||
else
|
||||
wprintw(pendingdelete.popup, "%s", Blocked.list[pendingdelete.num].name);
|
||||
wprintw(PendingDelete.popup, "%s", Blocked.list[PendingDelete.num].name);
|
||||
|
||||
wattroff(pendingdelete.popup, A_BOLD);
|
||||
wprintw(pendingdelete.popup, "? y/n");
|
||||
wattroff(PendingDelete.popup, A_BOLD);
|
||||
wprintw(PendingDelete.popup, "? y/n");
|
||||
|
||||
wrefresh(pendingdelete.popup);
|
||||
wrefresh(PendingDelete.popup);
|
||||
}
|
||||
|
||||
/* deletes contact from blocked list */
|
||||
static void delete_blocked_friend(int32_t bnum)
|
||||
static void delete_blocked_friend(uint32_t bnum)
|
||||
{
|
||||
memset(&Blocked.list[bnum], 0, sizeof(BlockedFriend));
|
||||
|
||||
@ -626,7 +637,7 @@ static void delete_blocked_friend(int32_t bnum)
|
||||
}
|
||||
|
||||
/* deletes contact from friendlist and puts in blocklist */
|
||||
void block_friend(Tox *m, int32_t fnum)
|
||||
void block_friend(Tox *m, uint32_t fnum)
|
||||
{
|
||||
if (Friends.num_friends <= 0)
|
||||
return;
|
||||
@ -645,7 +656,7 @@ void block_friend(Tox *m, int32_t fnum)
|
||||
Blocked.list[i].namelength = Friends.list[fnum].namelength;
|
||||
Blocked.list[i].last_on = Friends.list[fnum].last_online.last_on;
|
||||
memcpy(Blocked.list[i].pub_key, Friends.list[fnum].pub_key, TOX_PUBLIC_KEY_SIZE);
|
||||
memcpy(Blocked.list[i].name, Friends.list[fnum].name, Friends.list[fnum].namelength + 1);
|
||||
memcpy(Blocked.list[i].name, Friends.list[fnum].name, Friends.list[fnum].namelength + 1);
|
||||
|
||||
++Blocked.num_blocked;
|
||||
|
||||
@ -662,15 +673,16 @@ void block_friend(Tox *m, int32_t fnum)
|
||||
}
|
||||
|
||||
/* removes friend from blocklist, puts back in friendlist */
|
||||
static void unblock_friend(Tox *m, int32_t bnum)
|
||||
static void unblock_friend(Tox *m, uint32_t bnum)
|
||||
{
|
||||
if (Blocked.num_blocked <= 0)
|
||||
return;
|
||||
|
||||
int32_t friendnum = tox_add_friend_norequest(m, (uint8_t *) Blocked.list[bnum].pub_key);
|
||||
TOX_ERR_FRIEND_ADD err;
|
||||
uint32_t friendnum = tox_friend_add_norequest(m, (uint8_t *) Blocked.list[bnum].pub_key, &err);
|
||||
|
||||
if (friendnum == -1) {
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend");
|
||||
if (err != TOX_ERR_FRIEND_ADD_OK) {
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend (error %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -707,7 +719,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
f = Friends.index[Friends.num_selected];
|
||||
|
||||
/* lock screen and force decision on deletion popup */
|
||||
if (pendingdelete.active) {
|
||||
if (PendingDelete.active) {
|
||||
if (key == 'y' || key == 'n')
|
||||
del_friend_deactivate(self, m, key);
|
||||
|
||||
@ -731,7 +743,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
} else {
|
||||
const char *msg = "* Warning: Too many windows are open.";
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
|
||||
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
|
||||
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -773,7 +785,7 @@ static void blocklist_onDraw(ToxWindow *self, Tox *m, int y2, int x2)
|
||||
if ((y2 - FLIST_OFST) <= 0)
|
||||
return;
|
||||
|
||||
int selected_num = 0;
|
||||
uint32_t selected_num = 0;
|
||||
|
||||
/* Determine which portion of friendlist to draw based on current position */
|
||||
int page = Blocked.num_selected / (y2 - FLIST_OFST);
|
||||
@ -783,7 +795,7 @@ static void blocklist_onDraw(ToxWindow *self, Tox *m, int y2, int x2)
|
||||
int i;
|
||||
|
||||
for (i = start; i < Blocked.num_blocked && i < end; ++i) {
|
||||
int f = Blocked.index[i];
|
||||
uint32_t f = Blocked.index[i];
|
||||
bool f_selected = false;
|
||||
|
||||
if (i == Blocked.num_selected) {
|
||||
@ -859,19 +871,15 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
uint64_t cur_time = get_unix_time();
|
||||
struct tm cur_loc_tm = *localtime((const time_t *) &cur_time);
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
int nf = tox_get_num_online_friends(m);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
wattron(self->window, A_BOLD);
|
||||
wprintw(self->window, " Online: ");
|
||||
wattroff(self->window, A_BOLD);
|
||||
wprintw(self->window, "%d/%d \n\n", nf, Friends.num_friends);
|
||||
wprintw(self->window, "%d/%d \n\n", Friends.num_online, Friends.num_friends);
|
||||
|
||||
if ((y2 - FLIST_OFST) <= 0)
|
||||
return;
|
||||
|
||||
int selected_num = 0;
|
||||
uint32_t selected_num = 0;
|
||||
|
||||
/* Determine which portion of friendlist to draw based on current position */
|
||||
int page = Friends.num_selected / (y2 - FLIST_OFST);
|
||||
@ -881,7 +889,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
int i;
|
||||
|
||||
for (i = start; i < Friends.num_friends && i < end; ++i) {
|
||||
int f = Friends.index[i];
|
||||
uint32_t f = Friends.index[i];
|
||||
bool f_selected = false;
|
||||
|
||||
if (Friends.list[f].active) {
|
||||
@ -895,26 +903,20 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
wprintw(self->window, " ");
|
||||
}
|
||||
|
||||
if (Friends.list[f].online) {
|
||||
uint8_t status = Friends.list[f].status;
|
||||
int colour = WHITE;
|
||||
if (Friends.list[f].connection_status != TOX_CONNECTION_NONE) {
|
||||
TOX_USER_STATUS status = Friends.list[f].status;
|
||||
int colour = MAGENTA;
|
||||
|
||||
switch (status) {
|
||||
case TOX_USERSTATUS_NONE:
|
||||
case TOX_USER_STATUS_NONE:
|
||||
colour = GREEN;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_AWAY:
|
||||
case TOX_USER_STATUS_AWAY:
|
||||
colour = YELLOW;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_BUSY:
|
||||
case TOX_USER_STATUS_BUSY:
|
||||
colour = RED;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_INVALID:
|
||||
colour = MAGENTA;
|
||||
break;
|
||||
}
|
||||
|
||||
wattron(self->window, COLOR_PAIR(colour) | A_BOLD);
|
||||
@ -933,11 +935,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
/* Reset Friends.list[f].statusmsg on window resize */
|
||||
if (fix_statuses) {
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
int s_len = tox_get_status_message(m, Friends.list[f].num, (uint8_t *) statusmsg,
|
||||
TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
size_t s_len = tox_friend_get_status_message(m, Friends.list[f].num, (uint8_t *) statusmsg,
|
||||
sizeof(statusmsg));
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
@ -946,7 +948,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
}
|
||||
|
||||
/* Truncate note if it doesn't fit on one line */
|
||||
uint16_t maxlen = x2 - getcurx(self->window) - 2;
|
||||
size_t maxlen = x2 - getcurx(self->window) - 2;
|
||||
|
||||
if (Friends.list[f].statusmsg_len > maxlen) {
|
||||
Friends.list[f].statusmsg[maxlen - 3] = '\0';
|
||||
@ -1023,7 +1025,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
help_onDraw(self);
|
||||
}
|
||||
|
||||
void disable_chatwin(int32_t f_num)
|
||||
void disable_chatwin(uint32_t f_num)
|
||||
{
|
||||
Friends.list[f_num].chatwin = -1;
|
||||
}
|
||||
@ -1051,7 +1053,7 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
|
||||
const char *errmsg = "* Warning: Too many windows are open.";
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
|
||||
|
||||
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
|
||||
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1070,11 +1072,10 @@ ToxWindow new_friendlist(void)
|
||||
ret.onFriendAdded = &friendlist_onFriendAdded;
|
||||
ret.onMessage = &friendlist_onMessage;
|
||||
ret.onConnectionChange = &friendlist_onConnectionChange;
|
||||
ret.onAction = &friendlist_onMessage; /* Action has identical behaviour to message */
|
||||
ret.onNickChange = &friendlist_onNickChange;
|
||||
ret.onStatusChange = &friendlist_onStatusChange;
|
||||
ret.onStatusMessageChange = &friendlist_onStatusMessageChange;
|
||||
ret.onFileSendRequest = &friendlist_onFileSendRequest;
|
||||
ret.onFileChunkRequest = &friendlist_onFileChunkRequest;
|
||||
ret.onGroupInvite = &friendlist_onGroupInvite;
|
||||
|
||||
#ifdef AUDIO
|
||||
|
@ -35,8 +35,8 @@ struct FileReceiver {
|
||||
FILE *file;
|
||||
bool pending;
|
||||
bool active;
|
||||
uint64_t size;
|
||||
uint64_t bytes_recv;
|
||||
size_t size;
|
||||
size_t bytes_recv;
|
||||
double bps;
|
||||
uint64_t last_progress; /* unix-time when we last updated progress */
|
||||
uint32_t line_id;
|
||||
@ -58,14 +58,14 @@ struct GroupChatInvite {
|
||||
typedef struct {
|
||||
char name[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
int namelength;
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH + 1];
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH + 1];
|
||||
uint16_t statusmsg_len;
|
||||
char pub_key[TOX_PUBLIC_KEY_SIZE];
|
||||
int32_t num;
|
||||
uint32_t num;
|
||||
int chatwin;
|
||||
bool active;
|
||||
bool online;
|
||||
uint8_t is_typing;
|
||||
TOX_CONNECTION connection_status;
|
||||
bool is_typing;
|
||||
bool logging_on; /* saves preference for friend irrespective of global settings */
|
||||
uint8_t status;
|
||||
struct LastOnline last_online;
|
||||
@ -78,25 +78,26 @@ typedef struct {
|
||||
char name[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
int namelength;
|
||||
char pub_key[TOX_PUBLIC_KEY_SIZE];
|
||||
int32_t num;
|
||||
uint32_t num;
|
||||
bool active;
|
||||
uint64_t last_on;
|
||||
} BlockedFriend;
|
||||
|
||||
typedef struct {
|
||||
int num_selected;
|
||||
int max_idx; /* 1 + the index of the last friend in list */
|
||||
int num_friends;
|
||||
int *index;
|
||||
size_t num_friends;
|
||||
size_t num_online;
|
||||
size_t max_idx; /* 1 + the index of the last friend in list */
|
||||
uint32_t *index;
|
||||
ToxicFriend *list;
|
||||
} FriendsList;
|
||||
|
||||
ToxWindow new_friendlist(void);
|
||||
void disable_chatwin(int32_t f_num);
|
||||
void disable_chatwin(uint32_t f_num);
|
||||
int get_friendnum(uint8_t *name);
|
||||
int load_blocklist(char *data);
|
||||
void kill_friendlist(void);
|
||||
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort);
|
||||
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort);
|
||||
|
||||
/* sorts friendlist_index first by connection status then alphabetically */
|
||||
void sort_friendlist_index(void);
|
||||
|
@ -61,13 +61,14 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
return;
|
||||
}
|
||||
|
||||
const char *msg;
|
||||
int32_t friendnum = tox_add_friend_norequest(m, FrndRequests.request[req].key);
|
||||
TOX_ERR_FRIEND_ADD err;
|
||||
uint32_t friendnum = tox_friend_add_norequest(m, FrndRequests.request[req].key, &err);
|
||||
|
||||
if (friendnum == -1)
|
||||
msg = "Failed to add friend.";
|
||||
else {
|
||||
msg = "Friend request accepted.";
|
||||
if (err != TOX_ERR_FRIEND_ADD_OK) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to add friend (error %d\n)", err);
|
||||
return;
|
||||
} else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Friend request accepted.");
|
||||
on_friendadded(m, friendnum, true);
|
||||
}
|
||||
|
||||
@ -82,48 +83,55 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
|
||||
FrndRequests.max_idx = i;
|
||||
--FrndRequests.num_requests;
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||
|
||||
}
|
||||
|
||||
void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
|
||||
void cmd_add_helper(ToxWindow *self, Tox *m, const char *id_bin, const char *msg)
|
||||
{
|
||||
const 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:
|
||||
TOX_ERR_FRIEND_ADD err;
|
||||
uint32_t f_num = tox_friend_add(m, (uint8_t *) id_bin, (uint8_t *) msg, strlen(msg), &err);
|
||||
|
||||
switch (err) {
|
||||
case TOX_ERR_FRIEND_ADD_TOO_LONG:
|
||||
errmsg = "Message is too long.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_NOMESSAGE:
|
||||
case TOX_ERR_FRIEND_ADD_NO_MESSAGE:
|
||||
errmsg = "Please add a message to your request.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_OWNKEY:
|
||||
case TOX_ERR_FRIEND_ADD_OWN_KEY:
|
||||
errmsg = "That appears to be your own ID.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_ALREADYSENT:
|
||||
case TOX_ERR_FRIEND_ADD_ALREADY_SENT:
|
||||
errmsg = "Friend request has already been sent.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_UNKNOWN:
|
||||
errmsg = "Undefined error when adding friend.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_BADCHECKSUM:
|
||||
case TOX_ERR_FRIEND_ADD_BAD_CHECKSUM:
|
||||
errmsg = "Bad checksum in address.";
|
||||
break;
|
||||
|
||||
case TOX_FAERR_SETNEWNOSPAM:
|
||||
case TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM:
|
||||
errmsg = "Nospam was different.";
|
||||
break;
|
||||
|
||||
default:
|
||||
case TOX_ERR_FRIEND_ADD_MALLOC:
|
||||
errmsg = "Core memory allocation failed.";
|
||||
break;
|
||||
|
||||
case TOX_ERR_FRIEND_ADD_OK:
|
||||
errmsg = "Friend request sent.";
|
||||
on_friendadded(m, f_num, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case TOX_ERR_FRIEND_ADD_NULL:
|
||||
/* fallthrough */
|
||||
default:
|
||||
errmsg = "Faile to add friend: Unknown error.";
|
||||
} break;
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
||||
}
|
||||
@ -152,21 +160,23 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
snprintf(msg, sizeof(msg), "%s", tmp);
|
||||
} else {
|
||||
char selfname[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfname);
|
||||
tox_self_get_name(m, (uint8_t *) selfname);
|
||||
|
||||
size_t n_len = tox_self_get_name_size(m);
|
||||
selfname[n_len] = '\0';
|
||||
snprintf(msg, sizeof(msg), "Hello, my name is %s. Care to Tox?", selfname);
|
||||
}
|
||||
|
||||
char id_bin[TOX_FRIEND_ADDRESS_SIZE] = {0};
|
||||
char id_bin[TOX_ADDRESS_SIZE] = {0};
|
||||
uint16_t id_len = (uint16_t) strlen(id);
|
||||
|
||||
/* try to add tox ID */
|
||||
if (id_len == 2 * TOX_FRIEND_ADDRESS_SIZE) {
|
||||
if (id_len == 2 * TOX_ADDRESS_SIZE) {
|
||||
size_t i;
|
||||
char xx[3];
|
||||
uint32_t x;
|
||||
|
||||
for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
|
||||
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
|
||||
xx[0] = id[2 * i];
|
||||
xx[1] = id[2 * i + 1];
|
||||
xx[2] = '\0';
|
||||
@ -187,77 +197,72 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
|
||||
void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc < 2) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: No file path supplied.");
|
||||
return;
|
||||
}
|
||||
// if (argc < 2) {
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: No file path supplied.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
/* turns the avatar off */
|
||||
if (strlen(argv[1]) < 3) {
|
||||
tox_unset_avatar(m);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No avatar set.");
|
||||
return;
|
||||
}
|
||||
// /* turns the avatar off */
|
||||
// if (strlen(argv[1]) < 3) {
|
||||
// tox_unset_avatar(m);
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No avatar set.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (argv[1][0] != '\"') {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Path must be enclosed in quotes.");
|
||||
return;
|
||||
}
|
||||
// if (argv[1][0] != '\"') {
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Path must be enclosed in quotes.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
/* remove opening and closing quotes */
|
||||
char path[MAX_STR_SIZE];
|
||||
snprintf(path, sizeof(path), "%s", &argv[1][1]);
|
||||
int len = strlen(path) - 1;
|
||||
path[len] = '\0';
|
||||
// /* remove opening and closing quotes */
|
||||
// char path[MAX_STR_SIZE];
|
||||
// snprintf(path, sizeof(path), "%s", &argv[1][1]);
|
||||
// int len = strlen(path) - 1;
|
||||
// path[len] = '\0';
|
||||
|
||||
off_t sz = file_size(path);
|
||||
// off_t sz = file_size(path);
|
||||
|
||||
if (sz <= 8) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Invalid file.");
|
||||
return;
|
||||
}
|
||||
// if (sz <= 8) {
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Invalid file.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (sz > TOX_AVATAR_MAX_DATA_LENGTH) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: File is too large.");
|
||||
return;
|
||||
}
|
||||
// FILE *fp = fopen(path, "rb");
|
||||
|
||||
FILE *fp = fopen(path, "rb");
|
||||
// if (fp == NULL) {
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Could not open file.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (fp == NULL) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Could not open file.");
|
||||
return;
|
||||
}
|
||||
// char PNG_signature[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
|
||||
char PNG_signature[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
// if (check_file_signature(PNG_signature, sizeof(PNG_signature), fp) != 0) {
|
||||
// fclose(fp);
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: File type not supported.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (check_file_signature(PNG_signature, sizeof(PNG_signature), fp) != 0) {
|
||||
fclose(fp);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: File type not supported.");
|
||||
return;
|
||||
}
|
||||
// char *avatar = malloc(sz);
|
||||
|
||||
char *avatar = malloc(sz);
|
||||
// if (avatar == NULL)
|
||||
// exit_toxic_err("Failed in cmd_avatar", FATALERR_MEMORY);
|
||||
|
||||
if (avatar == NULL)
|
||||
exit_toxic_err("Failed in set_avatar", FATALERR_MEMORY);
|
||||
// if (fread(avatar, sz, 1, fp) != 1) {
|
||||
// fclose(fp);
|
||||
// free(avatar);
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Read fail.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (fread(avatar, sz, 1, fp) != 1) {
|
||||
fclose(fp);
|
||||
free(avatar);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Read fail.");
|
||||
return;
|
||||
}
|
||||
// if (tox_set_avatar(m, TOX_AVATAR_FORMAT_PNG, (const uint8_t *) avatar, (uint32_t) sz) == -1)
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar");
|
||||
|
||||
if (tox_set_avatar(m, TOX_AVATAR_FORMAT_PNG, (const uint8_t *) avatar, (uint32_t) sz) == -1)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Core error.");
|
||||
// char filename[MAX_STR_SIZE];
|
||||
// get_file_name(filename, sizeof(filename), path);
|
||||
// line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Avatar set to '%s'", filename);
|
||||
|
||||
char filename[MAX_STR_SIZE];
|
||||
get_file_name(filename, sizeof(filename), path);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Avatar set to '%s'", filename);
|
||||
|
||||
fclose(fp);
|
||||
free(avatar);
|
||||
// fclose(fp);
|
||||
// free(avatar);
|
||||
}
|
||||
|
||||
void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
@ -383,8 +388,8 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
const char *swch = argv[1];
|
||||
|
||||
if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
|
||||
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, (uint8_t *) myid);
|
||||
char myid[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(m, (uint8_t *) myid);
|
||||
|
||||
if (self->is_chat) {
|
||||
Friends.list[self->num].logging_on = true;
|
||||
@ -415,13 +420,13 @@ 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};
|
||||
char address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, (uint8_t *) address);
|
||||
char id[TOX_ADDRESS_SIZE * 2 + 1] = {0};
|
||||
char address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(m, (uint8_t *) address);
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
|
||||
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
|
||||
char xx[3];
|
||||
snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff);
|
||||
strcat(id, xx);
|
||||
@ -438,7 +443,7 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
}
|
||||
|
||||
char nick[MAX_STR_SIZE];
|
||||
int len = 0;
|
||||
size_t len = 0;
|
||||
|
||||
if (argv[1][0] == '\"') { /* remove opening and closing quotes */
|
||||
snprintf(nick, sizeof(nick), "%s", &argv[1][1]);
|
||||
@ -457,7 +462,7 @@ 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';
|
||||
|
||||
tox_set_name(m, (uint8_t *) nick, (uint16_t) len);
|
||||
tox_self_set_name(m, (uint8_t *) nick, len, NULL);
|
||||
prompt_update_nick(prompt, nick);
|
||||
|
||||
store_data(m, DATA_FILE);
|
||||
@ -539,26 +544,23 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
goto finish;
|
||||
}
|
||||
|
||||
char status[MAX_STR_SIZE];
|
||||
snprintf(status, sizeof(status), "%s", argv[1]);
|
||||
str_to_lower(status);
|
||||
const char *status_str = argv[1]);
|
||||
TOX_USER_STATUS status;
|
||||
|
||||
TOX_USERSTATUS status_kind;
|
||||
|
||||
if (!strcmp(status, "online"))
|
||||
status_kind = TOX_USERSTATUS_NONE;
|
||||
else if (!strcmp(status, "away"))
|
||||
status_kind = TOX_USERSTATUS_AWAY;
|
||||
else if (!strcmp(status, "busy"))
|
||||
status_kind = TOX_USERSTATUS_BUSY;
|
||||
if (!strcasecmp(status_str, "online"))
|
||||
status = TOX_USER_STATUS_NONE;
|
||||
else if (!strcasecmp(status_str, "away"))
|
||||
status = TOX_USER_STATUS_AWAY;
|
||||
else if (!strcasecmp(status_str, "busy"))
|
||||
status = TOX_USER_STATUS_BUSY;
|
||||
else {
|
||||
errmsg = "Invalid status. Valid statuses are: online, busy and away.";
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
tox_set_user_status(m, status_kind);
|
||||
prompt_update_status(prompt, status_kind);
|
||||
tox_self_set_status(m, status);
|
||||
prompt_update_status(prompt, status);
|
||||
|
||||
if (have_note) {
|
||||
if (argv[2][0] != '\"') {
|
||||
|
@ -42,7 +42,7 @@ void cmd_quit(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]
|
||||
void cmd_requests(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, char *id_bin, char *msg);
|
||||
void cmd_add_helper(ToxWindow *self, Tox *m, const char *id_bin, const char *msg);
|
||||
|
||||
#ifdef AUDIO
|
||||
void cmd_list_devices(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -66,7 +66,9 @@ void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
||||
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick);
|
||||
|
||||
tox_self_get_name(m, (uint8_t *) selfnick);
|
||||
size_t sn_len = tox_self_get_name_size(m);
|
||||
selfnick[sn_len] = '\0';
|
||||
|
||||
line_info_add(self, timefrmt, selfnick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title);
|
||||
|
@ -244,7 +244,9 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
get_group_nick_truncate(m, nick, peernum, groupnum);
|
||||
|
||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick);
|
||||
tox_self_get_name(m, (uint8_t *) selfnick);
|
||||
|
||||
size_t sn_len = tox_self_get_name_size(m);
|
||||
selfnick[sn_len] = '\0';
|
||||
|
||||
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
|
||||
@ -252,7 +254,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
/* Only play sound if mentioned by someone else */
|
||||
if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) {
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
|
||||
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "%s %s", nick, msg);
|
||||
else
|
||||
@ -283,12 +285,14 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
get_group_nick_truncate(m, nick, peernum, groupnum);
|
||||
|
||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick);
|
||||
tox_self_get_name(m, (uint8_t *) selfnick);
|
||||
|
||||
size_t n_len = tox_self_get_name_size(m);
|
||||
selfnick[n_len] = '\0';
|
||||
|
||||
if (strcasestr(action, selfnick)) {
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
|
||||
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
||||
else
|
||||
@ -366,7 +370,7 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
|
||||
groupchats[gnum].peer_names[i * N + n_len] = '\0';
|
||||
groupchats[gnum].peer_name_lengths[i] = n_len;
|
||||
filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(groupchats[gnum].oldpeer_names, groupchats[gnum].peer_names, N * npeers);
|
||||
@ -579,7 +583,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
|
||||
/* TODO: make this not suck */
|
||||
if (ctx->line[0] != L'/' || wcscmp(ctx->line, L"/me") == 0) {
|
||||
diff = complete_line(self, groupchats[self->num].peer_names, groupchats[self->num].num_peers,
|
||||
diff = complete_line(self, groupchats[self->num].peer_names, groupchats[self->num].num_peers,
|
||||
TOX_MAX_NAME_LENGTH);
|
||||
} else if (wcsncmp(ctx->line, L"/avatar \"", wcslen(L"/avatar \"")) == 0) {
|
||||
diff = dir_match(self, m, ctx->line, L"/avatar");
|
||||
@ -593,10 +597,10 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
||||
}
|
||||
} else {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
} else {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
} else if (key == user_settings->key_peer_list_down) { /* Scroll peerlist up and down one position */
|
||||
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
|
||||
@ -720,8 +724,8 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
||||
line_info_init(ctx->hst);
|
||||
|
||||
if (user_settings->autolog == AUTOLOG_ON) {
|
||||
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, (uint8_t *) myid);
|
||||
char myid[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(m, (uint8_t *) myid);
|
||||
log_enable(self->name, myid, NULL, ctx->log, LOG_GROUP);
|
||||
}
|
||||
|
||||
@ -733,7 +737,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
||||
|
||||
|
||||
#ifdef AUDIO
|
||||
static int group_audio_open_out_device(int groupnum)
|
||||
static int group_audio_open_out_device(int groupnum)
|
||||
{
|
||||
char dname[MAX_STR_SIZE];
|
||||
get_primary_device_name(output, dname, sizeof(dname));
|
||||
@ -821,13 +825,13 @@ static int group_audio_write(int peernum, int groupnum, const int16_t *pcm, unsi
|
||||
ALint state;
|
||||
alGetSourcei(groupchats[groupnum].audio.source, AL_SOURCE_STATE, &state);
|
||||
|
||||
if (state != AL_PLAYING)
|
||||
if (state != AL_PLAYING)
|
||||
alSourcePlay(groupchats[groupnum].audio.source);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int peernum, const int16_t *pcm,
|
||||
static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int peernum, const int16_t *pcm,
|
||||
unsigned int samples, uint8_t channels, unsigned int sample_rate)
|
||||
{
|
||||
return;
|
||||
|
18
src/input.c
18
src/input.c
@ -46,12 +46,12 @@ void input_new_char(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_
|
||||
|
||||
/* this is the only place we need to do this check */
|
||||
if (cur_len == -1) {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (add_char_to_buf(ctx, key) == -1) {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ static void input_backspace(ToxWindow *self, int x, int mx_x)
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (del_char_buf_bck(ctx) == -1) {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ static void input_backspace(ToxWindow *self, int x, int mx_x)
|
||||
static void input_delete(ToxWindow *self)
|
||||
{
|
||||
if (del_char_buf_frnt(self->chatwin) == -1)
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
|
||||
/* delete last typed word */
|
||||
@ -93,7 +93,7 @@ static void input_del_word(ToxWindow *self, int x, int mx_x)
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (del_word_buf(ctx) == -1) {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -102,14 +102,14 @@ static void input_del_word(ToxWindow *self, int x, int mx_x)
|
||||
static void input_discard(ToxWindow *self)
|
||||
{
|
||||
if (discard_buf(self->chatwin) == -1)
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
|
||||
/* deletes entire line after cursor from input field and buffer */
|
||||
static void input_kill(ChatContext *ctx)
|
||||
{
|
||||
if (kill_buf(ctx) == -1)
|
||||
sound_notify(NULL, error, NT_ALWAYS, NULL);
|
||||
sound_notify(NULL, notif_error, NT_ALWAYS, NULL);
|
||||
}
|
||||
|
||||
static void input_yank(ToxWindow *self, int x, int mx_x)
|
||||
@ -117,7 +117,7 @@ static void input_yank(ToxWindow *self, int x, int mx_x)
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (yank_buf(ctx) == -1) {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ bool input_handle(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_y)
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: this special case is ugly.
|
||||
/* TODO: this special case is ugly.
|
||||
maybe convert entire function to if/else and make them all customizable keys? */
|
||||
if (!match && key == user_settings->key_toggle_peerlist) {
|
||||
if (self->is_groupchat) {
|
||||
|
@ -226,7 +226,7 @@ void line_info_add(ToxWindow *self, const char *timestr, const char *name1, cons
|
||||
}
|
||||
|
||||
/* adds a single queue item to hst if possible. only called once per call to line_info_print() */
|
||||
static void line_info_check_queue(ToxWindow *self)
|
||||
static void line_info_check_queue(ToxWindow *self)
|
||||
{
|
||||
struct history *hst = self->chatwin->hst;
|
||||
struct line_info *line = line_info_ret_queue(hst);
|
||||
@ -484,14 +484,14 @@ static void line_info_scroll_up(struct history *hst)
|
||||
{
|
||||
if (hst->line_start->prev)
|
||||
hst->line_start = hst->line_start->prev;
|
||||
else sound_notify(NULL, error, NT_ALWAYS, NULL);
|
||||
else sound_notify(NULL, notif_error, NT_ALWAYS, NULL);
|
||||
}
|
||||
|
||||
static void line_info_scroll_down(struct history *hst)
|
||||
{
|
||||
if (hst->line_start->next)
|
||||
hst->line_start = hst->line_start->next;
|
||||
else sound_notify(NULL, error, NT_ALWAYS, NULL);
|
||||
else sound_notify(NULL, notif_error, NT_ALWAYS, NULL);
|
||||
}
|
||||
|
||||
static void line_info_page_up(ToxWindow *self, struct history *hst)
|
||||
|
@ -103,7 +103,9 @@ void cqueue_remove(ToxWindow *self, Tox *m, uint32_t receipt)
|
||||
}
|
||||
|
||||
char selfname[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
|
||||
tox_self_get_name(m, (uint8_t *) selfname);
|
||||
|
||||
size_t len = tox_self_get_name_size(m);
|
||||
selfname[len] = '\0';
|
||||
|
||||
write_to_log(msg->message, selfname, self->chatwin->log, msg->type == OUT_ACTION);
|
||||
|
@ -199,9 +199,9 @@ int valid_nick(const char *nick)
|
||||
|
||||
for (i = 0; nick[i]; ++i) {
|
||||
if ((nick[i] == ' ' && nick[i + 1] == ' ')
|
||||
|| nick[i] == '/'
|
||||
|| nick[i] == '\n'
|
||||
|| nick[i] == '\t'
|
||||
|| nick[i] == '/'
|
||||
|| nick[i] == '\n'
|
||||
|| nick[i] == '\t'
|
||||
|| nick[i] == '\v'
|
||||
|| nick[i] == '\r')
|
||||
|
||||
@ -212,9 +212,9 @@ int valid_nick(const char *nick)
|
||||
}
|
||||
|
||||
/* Converts all newline/tab chars to spaces (use for strings that should be contained to a single line) */
|
||||
void filter_str(char *str, int len)
|
||||
void filter_str(char *str, size_t len)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (str[i] == '\n' || str[i] == '\r' || str[i] == '\t' || str[i] == '\v')
|
||||
@ -263,13 +263,15 @@ void str_to_lower(char *str)
|
||||
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
|
||||
if toxcore API call fails, put UNKNOWN_NAME in buf
|
||||
Returns nick len */
|
||||
int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
||||
size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum)
|
||||
{
|
||||
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
|
||||
size_t len = tox_self_get_name_size(m);
|
||||
|
||||
if (len == -1) {
|
||||
if (len == 0) {
|
||||
strcpy(buf, UNKNOWN_NAME);
|
||||
len = strlen(UNKNOWN_NAME);
|
||||
} else {
|
||||
tox_self_get_name(m, (uint8_t *) buf);
|
||||
}
|
||||
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||
@ -296,9 +298,9 @@ int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum)
|
||||
|
||||
/* copies data to msg buffer.
|
||||
returns length of msg, which will be no larger than size-1 */
|
||||
uint16_t copy_tox_str(char *msg, size_t size, const char *data, uint16_t length)
|
||||
size_t copy_tox_str(char *msg, size_t size, const char *data, size_t length)
|
||||
{
|
||||
int len = MIN(length, size - 1);
|
||||
size_t len = MIN(length, size - 1);
|
||||
memcpy(msg, data, len);
|
||||
msg[len] = '\0';
|
||||
return len;
|
||||
@ -372,7 +374,7 @@ off_t file_size(const char *path)
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
/* compares the first size bytes of fp to signature.
|
||||
/* compares the first size bytes of fp to signature.
|
||||
Returns 0 if they are the same, 1 if they differ, and -1 on error.
|
||||
|
||||
On success this function will seek back to the beginning of fp */
|
||||
|
134
src/notify.c
134
src/notify.c
@ -1,5 +1,5 @@
|
||||
/* notify.c
|
||||
*
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2014 Toxic All Rights Reserved.
|
||||
*
|
||||
@ -67,12 +67,12 @@ extern struct user_settings *user_settings;
|
||||
struct Control {
|
||||
time_t cooldown;
|
||||
time_t notif_timeout;
|
||||
|
||||
|
||||
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
||||
pthread_mutex_t poll_mutex[1];
|
||||
bool poll_active;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SOUND_NOTIFY
|
||||
uint32_t device_idx; /* index of output device */
|
||||
char* sounds[SOUNDS_SIZE];
|
||||
@ -107,11 +107,11 @@ static void tab_notify(ToxWindow *self, uint64_t flags)
|
||||
if (self == NULL)
|
||||
return;
|
||||
|
||||
if (flags & NT_WNDALERT_0)
|
||||
if (flags & NT_WNDALERT_0)
|
||||
self->alert = WINDOW_ALERT_0;
|
||||
else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) )
|
||||
else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) )
|
||||
self->alert = WINDOW_ALERT_1;
|
||||
else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) )
|
||||
else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) )
|
||||
self->alert = WINDOW_ALERT_2;
|
||||
}
|
||||
|
||||
@ -154,14 +154,14 @@ static bool device_opened = false;
|
||||
time_t last_opened_update = 0;
|
||||
|
||||
bool m_open_device()
|
||||
{
|
||||
{
|
||||
last_opened_update = get_unix_time();
|
||||
|
||||
|
||||
if (device_opened) return true;
|
||||
|
||||
|
||||
/* Blah error check */
|
||||
open_primary_device(output, &Control.device_idx, 48000, 20, 1);
|
||||
|
||||
|
||||
return (device_opened = true);
|
||||
}
|
||||
|
||||
@ -194,9 +194,9 @@ void graceful_clear()
|
||||
*actives[i].id_indicator = -1; /* reset indicator value */
|
||||
|
||||
if ( actives[i].looping ) {
|
||||
stop_sound(i);
|
||||
stop_sound(i);
|
||||
} else {
|
||||
if (!is_playing(actives[i].source))
|
||||
if (!is_playing(actives[i].source))
|
||||
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
|
||||
else break;
|
||||
}
|
||||
@ -217,17 +217,17 @@ void* do_playing(void* _p)
|
||||
{
|
||||
(void)_p;
|
||||
int i;
|
||||
|
||||
|
||||
bool has_looping = false;
|
||||
|
||||
|
||||
while(Control.poll_active) {
|
||||
control_lock();
|
||||
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
|
||||
|
||||
|
||||
if (actives[i].looping) has_looping = true;
|
||||
|
||||
|
||||
if (actives[i].active && !actives[i].looping
|
||||
#ifdef BOX_NOTIFY
|
||||
&& !actives[i].box
|
||||
@ -237,7 +237,7 @@ void* do_playing(void* _p)
|
||||
*actives[i].id_indicator = -1; /* reset indicator value */
|
||||
|
||||
if (!is_playing(actives[i].source)) {
|
||||
/* Close */
|
||||
/* Close */
|
||||
alSourceStop(actives[i].source);
|
||||
alDeleteSources(1, &actives[i].source);
|
||||
alDeleteBuffers(1, &actives[i].buffer);
|
||||
@ -263,14 +263,14 @@ void* do_playing(void* _p)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* device is opened and no activity in under DEVICE_COOLDOWN time, close device*/
|
||||
if (device_opened && !has_looping &&
|
||||
if (device_opened && !has_looping &&
|
||||
(get_unix_time() - last_opened_update) > DEVICE_COOLDOWN) {
|
||||
m_close_device();
|
||||
}
|
||||
has_looping = false;
|
||||
|
||||
|
||||
control_unlock();
|
||||
usleep(10000);
|
||||
}
|
||||
@ -278,20 +278,20 @@ void* do_playing(void* _p)
|
||||
}
|
||||
|
||||
int play_source(uint32_t source, uint32_t buffer, bool looping)
|
||||
{
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < ACTIVE_NOTIFS_MAX && actives[i].active; i ++);
|
||||
if ( i == ACTIVE_NOTIFS_MAX ) {
|
||||
return -1; /* Full */
|
||||
}
|
||||
|
||||
|
||||
alSourcePlay(source);
|
||||
|
||||
|
||||
actives[i].active = 1;
|
||||
actives[i].source = source;
|
||||
actives[i].buffer = buffer;
|
||||
actives[i].looping = looping;
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -324,20 +324,20 @@ void graceful_clear()
|
||||
{
|
||||
int i;
|
||||
control_lock();
|
||||
|
||||
|
||||
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
|
||||
if (actives[i].box) {
|
||||
GError* ignore;
|
||||
notify_notification_close(actives[i].box, &ignore);
|
||||
actives[i].box = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (actives[i].id_indicator)
|
||||
*actives[i].id_indicator = -1; /* reset indicator value */
|
||||
|
||||
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
control_unlock();
|
||||
}
|
||||
#endif
|
||||
@ -356,7 +356,7 @@ int init_notify(int login_cooldown, int notification_timeout)
|
||||
#ifdef SOUND_NOTIFY
|
||||
alutInitWithoutContext(NULL, NULL);
|
||||
#endif /* SOUND_NOTIFY */
|
||||
|
||||
|
||||
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
||||
if (pthread_mutex_init(Control.poll_mutex, NULL) != 0)
|
||||
return -1;
|
||||
@ -371,8 +371,8 @@ int init_notify(int login_cooldown, int notification_timeout)
|
||||
Control.poll_active = 1;
|
||||
#endif
|
||||
Control.cooldown = get_unix_time() + login_cooldown;
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef BOX_NOTIFY
|
||||
notify_init("Toxic");
|
||||
#endif
|
||||
@ -381,11 +381,11 @@ int init_notify(int login_cooldown, int notification_timeout)
|
||||
}
|
||||
|
||||
void terminate_notify()
|
||||
{
|
||||
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
||||
if ( !Control.poll_active ) return;
|
||||
{
|
||||
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
||||
if ( !Control.poll_active ) return;
|
||||
Control.poll_active = 0;
|
||||
|
||||
|
||||
graceful_clear();
|
||||
#endif
|
||||
|
||||
@ -394,7 +394,7 @@ void terminate_notify()
|
||||
for (; i < SOUNDS_SIZE; i ++) free(Control.sounds[i]);
|
||||
alutExit();
|
||||
#endif /* SOUND_NOTIFY */
|
||||
|
||||
|
||||
#ifdef BOX_NOTIFY
|
||||
notify_uninit();
|
||||
#endif
|
||||
@ -404,7 +404,7 @@ void terminate_notify()
|
||||
int set_sound(Notification sound, const char* value)
|
||||
{
|
||||
if (sound == silent) return 0;
|
||||
|
||||
|
||||
free(Control.sounds[sound]);
|
||||
|
||||
size_t len = strlen(value) + 1;
|
||||
@ -416,18 +416,18 @@ int set_sound(Notification sound, const char* value)
|
||||
}
|
||||
|
||||
int play_sound_internal(Notification what, bool loop)
|
||||
{
|
||||
{
|
||||
uint32_t source;
|
||||
uint32_t buffer;
|
||||
|
||||
|
||||
m_open_device();
|
||||
|
||||
|
||||
alGenSources(1, &source);
|
||||
alGenBuffers(1, &buffer);
|
||||
buffer = alutCreateBufferFromFile(Control.sounds[what]);
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
alSourcei(source, AL_LOOPING, loop);
|
||||
|
||||
|
||||
int rc = play_source(source, buffer, loop);
|
||||
if (rc < 0) {
|
||||
alSourceStop(source);
|
||||
@ -435,7 +435,7 @@ int play_sound_internal(Notification what, bool loop)
|
||||
alDeleteBuffers(1,&buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -464,7 +464,7 @@ void stop_sound(int id)
|
||||
notify_notification_close(actives[id].box, &ignore);
|
||||
}
|
||||
#endif
|
||||
if (actives[id].id_indicator)
|
||||
if (actives[id].id_indicator)
|
||||
*actives[id].id_indicator = -1;
|
||||
// alSourcei(actives[id].source, AL_LOOPING, false);
|
||||
alSourceStop(actives[id].source);
|
||||
@ -484,11 +484,11 @@ static int m_play_sound(Notification notif, uint64_t flags)
|
||||
beep();
|
||||
|
||||
return -1;
|
||||
#endif /* SOUND_NOTIFY */
|
||||
#endif /* SOUND_NOTIFY */
|
||||
}
|
||||
|
||||
#ifdef BOX_NOTIFY
|
||||
void m_notify_action(NotifyNotification *box, char *action, void* data)
|
||||
void m_notify_action(NotifyNotification *box, char *action, void* data)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
@ -503,7 +503,7 @@ int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_in
|
||||
int id = -1;
|
||||
control_lock();
|
||||
|
||||
if (self && (!self->stb || self->stb->status != TOX_USERSTATUS_BUSY) && user_settings->alerts == ALERTS_ENABLED)
|
||||
if (self && (!self->stb || self->stb->status != TOX_USER_STATUS_BUSY) && user_settings->alerts == ALERTS_ENABLED)
|
||||
id = m_play_sound(notif, flags);
|
||||
else if (flags & NT_ALWAYS)
|
||||
id = m_play_sound(notif, flags);
|
||||
@ -520,7 +520,7 @@ int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_in
|
||||
|
||||
#endif
|
||||
|
||||
if ( id_indicator && id != -1 ) {
|
||||
if ( id_indicator && id != -1 ) {
|
||||
actives[id].id_indicator = id_indicator;
|
||||
*id_indicator = id;
|
||||
}
|
||||
@ -533,46 +533,46 @@ int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_in
|
||||
int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id)
|
||||
{
|
||||
tab_notify(self, flags);
|
||||
|
||||
|
||||
if (notifications_are_disabled(flags))
|
||||
return -1;
|
||||
|
||||
|
||||
if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1;
|
||||
#ifdef SOUND_NOTIFY
|
||||
#ifdef SOUND_NOTIFY
|
||||
control_lock();
|
||||
|
||||
|
||||
if (!actives[id].active || !Control.sounds[notif]) {
|
||||
control_unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
m_open_device();
|
||||
|
||||
|
||||
alSourceStop(actives[id].source);
|
||||
alDeleteSources(1, &actives[id].source);
|
||||
alDeleteBuffers(1,&actives[id].buffer);
|
||||
|
||||
|
||||
|
||||
|
||||
alGenSources(1, &actives[id].source);
|
||||
alGenBuffers(1, &actives[id].buffer);
|
||||
actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]);
|
||||
alSourcei(actives[id].source, AL_BUFFER, actives[id].buffer);
|
||||
alSourcei(actives[id].source, AL_LOOPING, flags & NT_LOOP);
|
||||
|
||||
|
||||
alSourcePlay(actives[id].source);
|
||||
|
||||
|
||||
control_unlock();
|
||||
|
||||
|
||||
return id;
|
||||
#else
|
||||
if (notif != silent)
|
||||
beep();
|
||||
|
||||
|
||||
return 0;
|
||||
#endif /* SOUND_NOTIFY */
|
||||
}
|
||||
|
||||
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...)
|
||||
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, const char* title, const char* format, ...)
|
||||
{
|
||||
if (notifications_are_disabled(flags)) {
|
||||
tab_notify(self, flags);
|
||||
@ -594,7 +594,7 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indi
|
||||
return -1; /* Full */
|
||||
}
|
||||
|
||||
actives[id].active = 1;
|
||||
actives[id].active = 1;
|
||||
actives[id].id_indicator = id_indicator;
|
||||
if (id_indicator) *id_indicator = id;
|
||||
}
|
||||
@ -607,13 +607,13 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indi
|
||||
vsnprintf (actives[id].messages[0], MAX_BOX_MSG_LEN, format, __ARGS__);
|
||||
va_end (__ARGS__);
|
||||
|
||||
if (strlen(actives[id].messages[0]) > MAX_BOX_MSG_LEN - 3)
|
||||
if (strlen(actives[id].messages[0]) > MAX_BOX_MSG_LEN - 3)
|
||||
strcpy(actives[id].messages[0] + MAX_BOX_MSG_LEN - 3, "...");
|
||||
|
||||
actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL);
|
||||
actives[id].size++;
|
||||
actives[id].n_timeout = get_unix_time() + Control.notif_timeout / 1000;
|
||||
|
||||
|
||||
notify_notification_set_timeout(actives[id].box, Control.notif_timeout);
|
||||
notify_notification_set_app_name(actives[id].box, "toxic");
|
||||
/*notify_notification_add_action(actives[id].box, "lel", "default", m_notify_action, self, NULL);*/
|
||||
@ -687,7 +687,7 @@ int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const
|
||||
|
||||
control_lock();
|
||||
|
||||
int id;
|
||||
int id;
|
||||
for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++);
|
||||
if ( id == ACTIVE_NOTIFS_MAX ) {
|
||||
control_unlock();
|
||||
@ -706,7 +706,7 @@ int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const
|
||||
vsnprintf (actives[id].messages[0], MAX_BOX_MSG_LEN, format, __ARGS__);
|
||||
va_end (__ARGS__);
|
||||
|
||||
if (strlen(actives[id].messages[0]) > MAX_BOX_MSG_LEN - 3)
|
||||
if (strlen(actives[id].messages[0]) > MAX_BOX_MSG_LEN - 3)
|
||||
strcpy(actives[id].messages[0] + MAX_BOX_MSG_LEN - 3, "...");
|
||||
|
||||
actives[id].active = 1;
|
||||
|
10
src/notify.h
10
src/notify.h
@ -1,5 +1,5 @@
|
||||
/* notify.h
|
||||
*
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2014 Toxic All Rights Reserved.
|
||||
*
|
||||
@ -29,7 +29,7 @@
|
||||
typedef enum _Notification
|
||||
{
|
||||
silent = -1,
|
||||
error,
|
||||
notif_error,
|
||||
self_log_in,
|
||||
self_log_out,
|
||||
user_log_in,
|
||||
@ -49,14 +49,14 @@ typedef enum _Flags {
|
||||
NT_LOOP = 1 << 2, /* Loop sound. If this setting active, notify() will return id of the sound
|
||||
* so it could be stopped. It will return 0 if error or NT_NATIVE flag is set and play \a instead
|
||||
*/
|
||||
NT_RESTOL = 1 << 3, /* Respect tolerance. Usually used to stop flood at toxic startup
|
||||
NT_RESTOL = 1 << 3, /* Respect tolerance. Usually used to stop flood at toxic startup
|
||||
* Only works if login_cooldown is true when calling init_notify()
|
||||
*/
|
||||
NT_NOTIFWND = 1 << 4, /* Pop notify window. NOTE: only works(/WILL WORK) if libnotify is present */
|
||||
NT_WNDALERT_0 = 1 << 5, /* Alert toxic */
|
||||
NT_WNDALERT_1 = 1 << 6, /* Alert toxic */
|
||||
NT_WNDALERT_2 = 1 << 7, /* Alert toxic */
|
||||
|
||||
|
||||
NT_ALWAYS = 1 << 8, /* Force sound to play */
|
||||
} Flags;
|
||||
|
||||
@ -68,7 +68,7 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id);
|
||||
|
||||
void stop_sound(int id);
|
||||
|
||||
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...);
|
||||
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, const char* title, const char* format, ...);
|
||||
int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...);
|
||||
int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const char* title, const char* format, ...);
|
||||
int box_silent_notify2(ToxWindow* self, uint64_t flags, int id, const char* format, ...);
|
||||
|
60
src/prompt.c
60
src/prompt.c
@ -114,13 +114,18 @@ void prompt_update_statusmessage(ToxWindow *prompt, Tox *m, const char *statusms
|
||||
{
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
int len = strlen(statusbar->statusmsg);
|
||||
size_t len = strlen(statusbar->statusmsg);
|
||||
statusbar->statusmsg_len = len;
|
||||
tox_set_status_message(m, (uint8_t *) statusmsg, (uint64_t) len);
|
||||
|
||||
TOX_ERR_SET_INFO err;
|
||||
tox_self_set_status_message(m, (uint8_t *) statusmsg, len, &err);
|
||||
|
||||
if (err != TOX_ERR_SET_INFO_OK)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set note (error %d)\n", err);
|
||||
}
|
||||
|
||||
/* Updates own status in prompt statusbar */
|
||||
void prompt_update_status(ToxWindow *prompt, uint8_t status)
|
||||
void prompt_update_status(ToxWindow *prompt, TOX_USER_STATUS status)
|
||||
{
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
statusbar->status = status;
|
||||
@ -209,10 +214,10 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
||||
}
|
||||
} else {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
} else {
|
||||
sound_notify(self, error, 0, NULL);
|
||||
sound_notify(self, notif_error, 0, NULL);
|
||||
}
|
||||
} else if (key == '\n') {
|
||||
rm_trailing_spaces_buf(ctx);
|
||||
@ -254,29 +259,22 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
wmove(statusbar->topline, 0, 0);
|
||||
|
||||
if (statusbar->is_online) {
|
||||
int colour = WHITE;
|
||||
const char *status_text = "Unknown";
|
||||
int colour = MAGENTA;
|
||||
const char *status_text = "ERROR";
|
||||
|
||||
switch (statusbar->status) {
|
||||
case TOX_USERSTATUS_NONE:
|
||||
case TOX_USER_STATUS_NONE:
|
||||
status_text = "Online";
|
||||
colour = GREEN;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_AWAY:
|
||||
case TOX_USER_STATUS_AWAY:
|
||||
status_text = "Away";
|
||||
colour = YELLOW;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_BUSY:
|
||||
case TOX_USER_STATUS_BUSY:
|
||||
status_text = "Busy";
|
||||
colour = RED;
|
||||
break;
|
||||
|
||||
case TOX_USERSTATUS_INVALID:
|
||||
status_text = "ERROR";
|
||||
colour = MAGENTA;
|
||||
break;
|
||||
}
|
||||
|
||||
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
||||
@ -295,10 +293,10 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
/* Reset statusbar->statusmsg on window resize */
|
||||
if (x2 != self->x) {
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {0};
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_self_status_message(m, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
@ -334,7 +332,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
help_onDraw(self);
|
||||
}
|
||||
|
||||
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
|
||||
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, uint32_t friendnum , TOX_CONNECTION connection_status)
|
||||
{
|
||||
if (friendnum < 0)
|
||||
return;
|
||||
@ -351,7 +349,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
const char *msg;
|
||||
|
||||
if (status == 1) {
|
||||
if (connection_status != TOX_CONNECTION_NONE) {
|
||||
msg = "has come online";
|
||||
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
|
||||
write_to_log(msg, nick, ctx->log, true);
|
||||
@ -376,7 +374,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
|
||||
}
|
||||
}
|
||||
|
||||
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, const char *data, uint16_t length)
|
||||
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, const char *data, size_t length)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
@ -406,15 +404,19 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
||||
|
||||
/* Init statusbar info */
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->status = TOX_USERSTATUS_NONE;
|
||||
statusbar->status = TOX_USER_STATUS_NONE;
|
||||
statusbar->is_online = false;
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH];
|
||||
char statusmsg[MAX_STR_SIZE];
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_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);
|
||||
size_t n_len = tox_self_get_name_size(m);
|
||||
tox_self_get_name(m, (uint8_t *) nick);
|
||||
|
||||
size_t s_len = tox_self_get_status_message_size(m);
|
||||
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
||||
|
||||
TOX_USER_STATUS status = tox_self_get_status(m);
|
||||
|
||||
nick[n_len] = '\0';
|
||||
statusmsg[s_len] = '\0';
|
||||
@ -468,8 +470,8 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
|
||||
line_info_init(ctx->hst);
|
||||
|
||||
if (user_settings->autolog == AUTOLOG_ON) {
|
||||
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, (uint8_t *) myid);
|
||||
char myid[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(m, (uint8_t *) myid);
|
||||
log_enable(self->name, myid, NULL, ctx->log, LOG_PROMPT);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ void prep_prompt_win(void);
|
||||
void prompt_init_statusbar(ToxWindow *self, Tox *m);
|
||||
void prompt_update_nick(ToxWindow *prompt, const char *nick);
|
||||
void prompt_update_statusmessage(ToxWindow *prompt, Tox *m, const char *statusmsg);
|
||||
void prompt_update_status(ToxWindow *prompt, uint8_t status);
|
||||
void prompt_update_status(ToxWindow *prompt, TOX_USER_STATUS status);
|
||||
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected);
|
||||
void kill_prompt_window(ToxWindow *self);
|
||||
|
||||
|
@ -66,7 +66,7 @@ struct user_settings {
|
||||
int key_toggle_peerlist;
|
||||
|
||||
int mplex_away; /* boolean (1 for reaction to terminal attach/detach) */
|
||||
char mplex_away_note [TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
char mplex_away_note [TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
|
||||
#ifdef AUDIO
|
||||
int audio_in_dev;
|
||||
|
@ -70,8 +70,8 @@ static char buffer [BUFFER_SIZE];
|
||||
static bool auto_away_active = false;
|
||||
|
||||
static mplex_status mplex = MPLEX_NONE;
|
||||
static TOX_USERSTATUS prev_status = TOX_USERSTATUS_NONE;
|
||||
static char prev_note [TOX_MAX_STATUSMESSAGE_LENGTH] = "";
|
||||
static TOX_USER_STATUS prev_status = TOX_USER_STATUS_NONE;
|
||||
static char prev_note [TOX_MAX_STATUS_MESSAGE_LENGTH] = "";
|
||||
|
||||
/* mutex for access to status data, for sync between:
|
||||
- user command /status from ncurses thread
|
||||
@ -314,7 +314,7 @@ static int mplex_is_detached ()
|
||||
|
||||
static void mplex_timer_handler (Tox *m)
|
||||
{
|
||||
TOX_USERSTATUS current_status, new_status;
|
||||
TOX_USER_STATUS current_status, new_status;
|
||||
const char *new_note;
|
||||
|
||||
if (mplex == MPLEX_NONE)
|
||||
@ -323,23 +323,23 @@ static void mplex_timer_handler (Tox *m)
|
||||
int detached = mplex_is_detached ();
|
||||
|
||||
pthread_mutex_lock (&Winthread.lock);
|
||||
current_status = tox_get_self_user_status (m);
|
||||
current_status = tox_self_get_status (m);
|
||||
pthread_mutex_unlock (&Winthread.lock);
|
||||
|
||||
if (auto_away_active && current_status == TOX_USERSTATUS_AWAY && !detached)
|
||||
if (auto_away_active && current_status == TOX_USER_STATUS_AWAY && !detached)
|
||||
{
|
||||
auto_away_active = false;
|
||||
new_status = prev_status;
|
||||
new_note = prev_note;
|
||||
}
|
||||
else
|
||||
if (current_status == TOX_USERSTATUS_NONE && detached)
|
||||
if (current_status == TOX_USER_STATUS_NONE && detached)
|
||||
{
|
||||
auto_away_active = true;
|
||||
prev_status = current_status;
|
||||
new_status = TOX_USERSTATUS_AWAY;
|
||||
new_status = TOX_USER_STATUS_AWAY;
|
||||
pthread_mutex_lock (&Winthread.lock);
|
||||
tox_get_self_status_message (m, (uint8_t*) prev_note, sizeof (prev_note));
|
||||
tox_self_get_status_message (m, (uint8_t*) prev_note);
|
||||
pthread_mutex_unlock (&Winthread.lock);
|
||||
new_note = user_settings->mplex_away_note;
|
||||
}
|
||||
@ -348,8 +348,8 @@ static void mplex_timer_handler (Tox *m)
|
||||
|
||||
char argv[3][MAX_STR_SIZE];
|
||||
strcpy (argv[0], "/status");
|
||||
strcpy (argv[1], (new_status == TOX_USERSTATUS_AWAY ? "away" :
|
||||
new_status == TOX_USERSTATUS_BUSY ? "busy" : "online"));
|
||||
strcpy (argv[1], (new_status == TOX_USER_STATUS_AWAY ? "away" :
|
||||
new_status == TOX_USER_STATUS_BUSY ? "busy" : "online"));
|
||||
argv[2][0] = '\"';
|
||||
strcpy (argv[2] + 1, new_note);
|
||||
strcat (argv[2], "\"");
|
||||
|
299
src/toxic.c
299
src/toxic.c
@ -85,9 +85,6 @@ struct audio_thread audio_thread;
|
||||
struct arg_opts arg_opts;
|
||||
struct user_settings *user_settings = NULL;
|
||||
|
||||
#define MIN_PASSWORD_LEN 6
|
||||
#define MAX_PASSWORD_LEN 64
|
||||
|
||||
static struct user_password {
|
||||
bool data_is_encrypted;
|
||||
char pass[MAX_PASSWORD_LEN + 1];
|
||||
@ -101,7 +98,7 @@ static void catch_SIGINT(int sig)
|
||||
|
||||
static void catch_SIGSEGV(int sig)
|
||||
{
|
||||
freopen("/dev/tty", "w", stderr);
|
||||
freopen("/dev/tty", "w", stderr); // make sure stderr is enabled since we may have disabled it
|
||||
endwin();
|
||||
fprintf(stderr, "Caught SIGSEGV: Aborting toxic session.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -150,9 +147,6 @@ void exit_toxic_success(Tox *m)
|
||||
|
||||
void exit_toxic_err(const char *errmsg, int errcode)
|
||||
{
|
||||
if (errmsg == NULL)
|
||||
errmsg = "No error message";
|
||||
|
||||
freopen("/dev/tty", "w", stderr);
|
||||
endwin();
|
||||
fprintf(stderr, "Toxic session aborted with error code %d (%s)\n", errcode, errmsg);
|
||||
@ -166,7 +160,7 @@ static void init_term(void)
|
||||
if (!arg_opts.default_locale) {
|
||||
if (setlocale(LC_ALL, "") == NULL)
|
||||
exit_toxic_err("Could not set your locale, please check your locale settings or "
|
||||
"disable unicode support with the -d flag.", FATALERR_LOCALE_SET);
|
||||
"disable unicode support with the -d flag.", FATALERR_LOCALE_NOT_SET);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -254,74 +248,6 @@ static void print_init_messages(ToxWindow *toxwin)
|
||||
line_info_add(toxwin, NULL, NULL, NULL, SYS_MSG, 0, 0, init_messages.msgs[i]);
|
||||
}
|
||||
|
||||
static Tox *init_tox(void)
|
||||
{
|
||||
Tox_Options tox_opts;
|
||||
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
||||
tox_opts.udp_disabled = arg_opts.force_tcp;
|
||||
tox_opts.proxy_type = arg_opts.proxy_type;
|
||||
|
||||
if (tox_opts.proxy_type != TOX_PROXY_NONE) {
|
||||
tox_opts.proxy_port = arg_opts.proxy_port;
|
||||
snprintf(tox_opts.proxy_address, sizeof(tox_opts.proxy_address), "%s", arg_opts.proxy_address);
|
||||
const char *ps = tox_opts.proxy_type == TOX_PROXY_SOCKS5 ? "SOCKS5" : "HTTP";
|
||||
|
||||
char tmp[48];
|
||||
snprintf(tmp, sizeof(tmp), "Using %s proxy %s : %d", ps, arg_opts.proxy_address, arg_opts.proxy_port);
|
||||
queue_init_message("%s", tmp);
|
||||
}
|
||||
|
||||
if (tox_opts.udp_disabled) {
|
||||
queue_init_message("UDP disabled");
|
||||
} else if (tox_opts.proxy_type != TOX_PROXY_NONE) {
|
||||
const char *msg = "WARNING: Using a proxy without disabling UDP may leak your real IP address.";
|
||||
queue_init_message("%s", msg);
|
||||
msg = "Use the -t option to disable UDP.";
|
||||
queue_init_message("%s", msg);
|
||||
}
|
||||
|
||||
/* Init core */
|
||||
Tox *m = tox_new(&tox_opts);
|
||||
|
||||
if (tox_opts.ipv6enabled && m == NULL) {
|
||||
queue_init_message("IPv6 failed to initialize");
|
||||
tox_opts.ipv6enabled = 0;
|
||||
m = tox_new(&tox_opts);
|
||||
}
|
||||
|
||||
if (!tox_opts.ipv6enabled)
|
||||
queue_init_message("Forcing IPv4 connection");
|
||||
|
||||
if (tox_opts.proxy_type != TOX_PROXY_NONE && m == NULL)
|
||||
exit_toxic_err("Proxy error", FATALERR_PROXY);
|
||||
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Callbacks */
|
||||
tox_callback_connection_status(m, on_connectionchange, NULL);
|
||||
tox_callback_typing_change(m, on_typing_change, NULL);
|
||||
tox_callback_friend_request(m, on_request, NULL);
|
||||
tox_callback_friend_message(m, on_message, NULL);
|
||||
tox_callback_name_change(m, on_nickchange, NULL);
|
||||
tox_callback_user_status(m, on_statuschange, NULL);
|
||||
tox_callback_status_message(m, on_statusmessagechange, NULL);
|
||||
tox_callback_friend_action(m, on_action, NULL);
|
||||
tox_callback_group_invite(m, on_groupinvite, NULL);
|
||||
tox_callback_group_message(m, on_groupmessage, NULL);
|
||||
tox_callback_group_action(m, on_groupaction, NULL);
|
||||
tox_callback_group_namelist_change(m, on_group_namelistchange, NULL);
|
||||
tox_callback_group_title(m, on_group_titlechange, NULL);
|
||||
tox_callback_file_send_request(m, on_file_sendrequest, NULL);
|
||||
tox_callback_file_control(m, on_file_control, NULL);
|
||||
tox_callback_file_data(m, on_file_data, NULL);
|
||||
tox_callback_read_receipt(m, on_read_receipt, NULL);
|
||||
|
||||
tox_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User"));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
#define MIN_NODE_LINE 50 /* IP: 7 + port: 5 + key: 38 + spaces: 2 = 70. ! (& e.g. tox.im = 6) */
|
||||
#define MAX_NODE_LINE 256 /* Approx max number of chars in a sever line (name + port + key) */
|
||||
#define MAXNODES 50
|
||||
@ -378,7 +304,7 @@ static int load_nodelist(const char *filename)
|
||||
|
||||
int init_connection_helper(Tox *m, int line)
|
||||
{
|
||||
return tox_bootstrap_from_address(m, toxNodes.nodes[line], toxNodes.ports[line], (uint8_t *) toxNodes.keys[line]);
|
||||
return tox_bootstrap(m, toxNodes.nodes[line], toxNodes.ports[line], (uint8_t *) toxNodes.keys[line], NULL);
|
||||
}
|
||||
|
||||
/* Connects to a random DHT node listed in the DHTnodes file
|
||||
@ -474,6 +400,10 @@ static void load_friendlist(Tox *m)
|
||||
sort_friendlist_index();
|
||||
}
|
||||
|
||||
|
||||
#define MIN_PASSWORD_LEN 6
|
||||
#define MAX_PASSWORD_LEN 64
|
||||
|
||||
/* return length of password on success, 0 on failure */
|
||||
static int password_prompt(char *buf, int size)
|
||||
{
|
||||
@ -534,6 +464,7 @@ static void first_time_encrypt(const char *msg)
|
||||
int len = 0;
|
||||
bool valid_password = false;
|
||||
char passconfirm[MAX_PASSWORD_LEN + 1] = {0};
|
||||
|
||||
printf("Enter a new password (must be at least %d characters) ", MIN_PASSWORD_LEN);
|
||||
|
||||
while (valid_password == false) {
|
||||
@ -564,7 +495,7 @@ static void first_time_encrypt(const char *msg)
|
||||
valid_password = true;
|
||||
}
|
||||
|
||||
queue_init_message("Data file '%s' has been encrypted", DATA_FILE);
|
||||
queue_init_message("Data file '%s' will be encrypted", DATA_FILE);
|
||||
memset(passconfirm, 0, sizeof(passconfirm));
|
||||
user_password.data_is_encrypted = true;
|
||||
}
|
||||
@ -578,13 +509,10 @@ static void first_time_encrypt(const char *msg)
|
||||
*/
|
||||
int store_data(Tox *m, const char *path)
|
||||
{
|
||||
if (arg_opts.ignore_data_file)
|
||||
return 0;
|
||||
|
||||
if (path == NULL)
|
||||
return -1;
|
||||
|
||||
int len = user_password.data_is_encrypted ? tox_encrypted_size(m) : tox_size(m);
|
||||
size_t len = user_password.data_is_encrypted ? tox_encrypted_size(m) : tox_get_savedata_size(m);
|
||||
char *buf = malloc(len);
|
||||
|
||||
if (buf == NULL)
|
||||
@ -596,72 +524,118 @@ int store_data(Tox *m, const char *path)
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
tox_save(m, (uint8_t *) buf);
|
||||
tox_get_savedata(m, (uint8_t *) buf);
|
||||
}
|
||||
|
||||
FILE *fd = fopen(path, "wb");
|
||||
FILE *fp = fopen(path, "wb");
|
||||
|
||||
if (fd == NULL) {
|
||||
if (fp == NULL) {
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fwrite(buf, len, 1, fd) != 1) {
|
||||
if (fwrite(buf, len, 1, fp) != 1) {
|
||||
free(buf);
|
||||
fclose(fd);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
fclose(fd);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void load_data(Tox *m, char *path)
|
||||
static void init_tox_callbacks(Tox *m)
|
||||
{
|
||||
if (arg_opts.ignore_data_file)
|
||||
return;
|
||||
tox_callback_friend_connection_status(m, on_connectionchange, NULL);
|
||||
tox_callback_friend_typing(m, on_typing_change, NULL);
|
||||
tox_callback_friend_request(m, on_request, NULL);
|
||||
tox_callback_friend_message(m, on_message, NULL);
|
||||
tox_callback_friend_name(m, on_nickchange, NULL);
|
||||
tox_callback_friend_status(m, on_statuschange, NULL);
|
||||
tox_callback_friend_status_message(m, on_statusmessagechange, NULL);
|
||||
tox_callback_friend_read_receipt(m, on_read_receipt, NULL);
|
||||
tox_callback_group_invite(m, on_groupinvite, NULL);
|
||||
tox_callback_group_message(m, on_groupmessage, NULL);
|
||||
tox_callback_group_action(m, on_groupaction, NULL);
|
||||
tox_callback_group_namelist_change(m, on_group_namelistchange, NULL);
|
||||
tox_callback_group_title(m, on_group_titlechange, NULL);
|
||||
tox_callback_file_chunk_request(m, on_file_sendrequest, NULL);
|
||||
tox_callback_file_recv_control(m, on_file_control, NULL);
|
||||
tox_callback_file_recv_chunk(m, on_file_data, NULL);
|
||||
}
|
||||
|
||||
FILE *fd = fopen(path, "rb");
|
||||
static void init_tox_options(Tox_Options *tox_opts)
|
||||
{
|
||||
tox_opts->ipv6_enabled = !arg_opts.use_ipv4;
|
||||
tox_opts->udp_enabled = !arg_opts.force_tcp;
|
||||
tox_opts->proxy_type = arg_opts.proxy_type;
|
||||
|
||||
if (fd != NULL) {
|
||||
off_t len = file_size(path);
|
||||
if (!tox_opts.ipv6_enabled)
|
||||
queue_init_message("Forcing IPv4 connection");
|
||||
|
||||
if (tox_opts->proxy_type != TOX_PROXY_TYPE_NONE) {
|
||||
tox_opts->proxy_port = arg_opts.proxy_port;
|
||||
snprintf(tox_opts->proxy_address, sizeof(tox_opts->proxy_address), "%s", arg_opts.proxy_address);
|
||||
const char *ps = tox_opts.proxy_type == TOX_PROXY_TYPE_SOCKS5 ? "SOCKS5" : "HTTP";
|
||||
|
||||
char tmp[48];
|
||||
snprintf(tmp, sizeof(tmp), "Using %s proxy %s : %d", ps, arg_opts.proxy_address, arg_opts.proxy_port);
|
||||
queue_init_message("%s", tmp);
|
||||
}
|
||||
|
||||
if (!tox_opts->udp_enabled) {
|
||||
queue_init_message("UDP disabled");
|
||||
} else if (tox_opts->proxy_type != TOX_PROXY_TYPE_NONE) {
|
||||
const char *msg = "WARNING: Using a proxy without disabling UDP may leak your real IP address.";
|
||||
queue_init_message("%s", msg);
|
||||
msg = "Use the -t option to disable UDP.";
|
||||
queue_init_message("%s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
static Tox *load_tox(char *data_path, Tox_Options *tox_opts, TOX_ERR_NEW *err)
|
||||
{
|
||||
FILE *fp = fopen(data_path, "rb");
|
||||
|
||||
if (fp != NULL) {
|
||||
off_t len = file_size(data_path);
|
||||
|
||||
if (len == -1) {
|
||||
fclose(fd);
|
||||
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
|
||||
fclose(fp);
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_FILEOP);
|
||||
}
|
||||
|
||||
char *buf = malloc(len);
|
||||
|
||||
if (buf == NULL) {
|
||||
fclose(fd);
|
||||
exit_toxic_err("failed in load_data", FATALERR_MEMORY);
|
||||
fclose(fp);
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_MEMORY);
|
||||
}
|
||||
|
||||
if (fread(buf, len, 1, fd) != 1) {
|
||||
if (fread(buf, len, 1, fp) != 1) {
|
||||
free(buf);
|
||||
fclose(fd);
|
||||
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
|
||||
fclose(fp);
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_FILEOP);
|
||||
}
|
||||
|
||||
bool is_encrypted = tox_is_save_encrypted((uint8_t *) buf);
|
||||
bool is_encrypted = tox_is_data_encrypted((uint8_t *) buf);
|
||||
|
||||
/* attempt to encrypt an already encrypted data file */
|
||||
if (arg_opts.encrypt_data && is_encrypted)
|
||||
exit_toxic_err("failed in load_data", FATALERR_ENCRYPT);
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_ENCRYPT);
|
||||
|
||||
if (arg_opts.unencrypt_data && is_encrypted)
|
||||
queue_init_message("Data file '%s' has been unencrypted", path);
|
||||
queue_init_message("Data file '%s' has been unencrypted", data_path);
|
||||
else if (arg_opts.unencrypt_data)
|
||||
queue_init_message("Warning: passed --unencrypt-data option with unencrypted data file '%s'", path);
|
||||
queue_init_message("Warning: passed --unencrypt-data option with unencrypted data file '%s'", data_path);
|
||||
|
||||
if (is_encrypted) {
|
||||
if (!arg_opts.unencrypt_data)
|
||||
user_password.data_is_encrypted = true;
|
||||
|
||||
int pwlen = 0;
|
||||
system("clear");
|
||||
system("clear"); // TODO: is this portable?
|
||||
printf("Enter password (q to quit) ");
|
||||
|
||||
while (true) {
|
||||
@ -678,43 +652,72 @@ static void load_data(Tox *m, char *path)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tox_encrypted_load(m, (uint8_t *) buf, len, (uint8_t *) user_password.pass, pwlen) == 0) {
|
||||
m = tox_encrypted_new(tox_opts, (uint8_t *) buf, len, user_password.pass, pwlen, err);
|
||||
|
||||
if (err == TOX_ERR_NEW_OK) {
|
||||
break;
|
||||
} else {
|
||||
} else if (err == TOX_ERR_NEW_LOAD_DECRYPTION_FAILED) {
|
||||
system("clear");
|
||||
sleep(1);
|
||||
printf("Invalid password. Try again. ");
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* tox_load errors are to be ignored until toxcore is fixed */
|
||||
tox_load(m, (uint8_t *) buf, len);
|
||||
m = tox_new(tox_opts, (uint8_t *) buf, len, err);
|
||||
|
||||
if (err != TOX_ERR_NEW_OK)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
load_friendlist(m);
|
||||
load_blocklist(BLOCK_FILE);
|
||||
|
||||
free(buf);
|
||||
fclose(fd);
|
||||
fclose(fp);
|
||||
} else {
|
||||
/* if file exists then open() failing is fatal */
|
||||
if (file_exists(path))
|
||||
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
|
||||
if (file_exists(data_path))
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_FILEOP);
|
||||
|
||||
if (store_data(m, path) != 0)
|
||||
exit_toxic_err("failed in load_data", FATALERR_STORE_DATA);
|
||||
m = tox_new(tox_opts, NULL, 0, err);
|
||||
|
||||
if (err != TOX_ERR_NEW_OK)
|
||||
return NULL;
|
||||
|
||||
if (store_data(m, data_path) == -1)
|
||||
exit_toxic_err("failed in load_toxic", FATALERR_FILEOP);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static Tox *load_toxic(char *data_path, TOX_ERR_NEW *err)
|
||||
{
|
||||
Tox_Options tox_opts;
|
||||
init_tox_options(&tox_opts);
|
||||
|
||||
Tox *m = load_tox(data_path, &tox_opts, err);
|
||||
|
||||
if (err != TOX_ERR_NEW_OK)
|
||||
return NULL;
|
||||
|
||||
init_tox_callbacks(m);
|
||||
tox_self_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User"), NULL);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static void do_toxic(Tox *m, ToxWindow *prompt)
|
||||
{
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
|
||||
do_connection(m, prompt);
|
||||
do_file_senders(m);
|
||||
|
||||
if (arg_opts.no_connect == 0) {
|
||||
tox_do(m); /* main tox-core loop */
|
||||
}
|
||||
if (arg_opts.no_connect == 0)
|
||||
tox_iterate(m); /* main toxcore loop */
|
||||
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
}
|
||||
@ -752,16 +755,19 @@ void *thread_cqueue(void *data)
|
||||
|
||||
while (true) {
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
int i;
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 2; i < MAX_WINDOWS_NUM; ++i) {
|
||||
ToxWindow *toxwin = get_window_ptr(i);
|
||||
|
||||
if (toxwin != NULL && toxwin->is_chat && tox_get_friend_connection_status(m, toxwin->num) == 1)
|
||||
if (toxwin != NULL && toxwin->is_chat
|
||||
&& tox_friend_get_connection_status(m, toxwin->num, NULL) != TOX_CONNECTION_NONE)
|
||||
cqueue_try_send(toxwin, m);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
usleep(4000);
|
||||
}
|
||||
}
|
||||
@ -775,6 +781,7 @@ void *thread_audio(void *data)
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
toxav_do(av);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
usleep(toxav_do_interval(av) * 1000);
|
||||
}
|
||||
}
|
||||
@ -797,7 +804,6 @@ static void print_usage(void)
|
||||
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
|
||||
fprintf(stderr, " -t, --force-tcp Force TCP connection (use this with proxies)\n");
|
||||
fprintf(stderr, " -u, --unencrypt-data Unencrypt an encrypted data file\n");
|
||||
fprintf(stderr, " -x, --nodata Ignore data file\n");
|
||||
}
|
||||
|
||||
static void set_default_opts(void)
|
||||
@ -805,7 +811,7 @@ static void set_default_opts(void)
|
||||
memset(&arg_opts, 0, sizeof(struct arg_opts));
|
||||
|
||||
/* set any non-zero defaults here*/
|
||||
arg_opts.proxy_type = TOX_PROXY_NONE;
|
||||
arg_opts.proxy_type = TOX_PROXY_TYPE_NONE;
|
||||
}
|
||||
|
||||
static void parse_args(int argc, char *argv[])
|
||||
@ -814,7 +820,6 @@ static void parse_args(int argc, char *argv[])
|
||||
|
||||
static struct option long_opts[] = {
|
||||
{"file", required_argument, 0, 'f'},
|
||||
{"nodata", no_argument, 0, 'x'},
|
||||
{"ipv4", no_argument, 0, '4'},
|
||||
{"debug", no_argument, 0, 'b'},
|
||||
{"default-locale", no_argument, 0, 'd'},
|
||||
@ -891,7 +896,7 @@ static void parse_args(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
arg_opts.proxy_type = TOX_PROXY_SOCKS5;
|
||||
arg_opts.proxy_type = TOX_PROXY_TYPE_SOCKS5;
|
||||
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
||||
|
||||
if (++optind > argc || argv[optind-1][0] == '-')
|
||||
@ -901,7 +906,7 @@ static void parse_args(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
arg_opts.proxy_type = TOX_PROXY_HTTP;
|
||||
arg_opts.proxy_type = TOX_PROXY_TYPE_HTTP;
|
||||
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
||||
|
||||
if (++optind > argc || argv[optind-1][0] == '-')
|
||||
@ -926,11 +931,6 @@ static void parse_args(int argc, char *argv[])
|
||||
arg_opts.unencrypt_data = 1;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
arg_opts.ignore_data_file = 1;
|
||||
queue_init_message("Ignoring data file");
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
print_usage();
|
||||
@ -995,6 +995,7 @@ static useconds_t optimal_msleepval(uint64_t *looptimer, uint64_t *loopcount, ui
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
// FIXME
|
||||
void DnD_callback(const char* asdv, DropType dt)
|
||||
{
|
||||
if (dt != DT_plain)
|
||||
@ -1006,31 +1007,29 @@ void DnD_callback(const char* asdv, DropType dt)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
parse_args(argc, argv);
|
||||
|
||||
/* Use the -b flag to enable stderr */
|
||||
if (!arg_opts.debug)
|
||||
freopen("/dev/null", "w", stderr);
|
||||
|
||||
if (arg_opts.encrypt_data && arg_opts.unencrypt_data) {
|
||||
arg_opts.encrypt_data = 0;
|
||||
arg_opts.unencrypt_data = 0;
|
||||
queue_init_message("Warning: Using --unencrypt-data and --encrypt-data simultaneously has no effect");
|
||||
}
|
||||
|
||||
/* Use the -b flag to enable stderr */
|
||||
if (!arg_opts.debug)
|
||||
freopen("/dev/null", "w", stderr);
|
||||
|
||||
/* Make sure all written files are read/writeable only by the current user. */
|
||||
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
|
||||
int config_err = init_default_data_files();
|
||||
bool datafile_exists = file_exists(DATA_FILE);
|
||||
|
||||
if (!arg_opts.ignore_data_file) {
|
||||
if (!datafile_exists && !arg_opts.unencrypt_data)
|
||||
first_time_encrypt("Creating new data file. Would you like to encrypt it? Y/n (q to quit)");
|
||||
else if (arg_opts.encrypt_data)
|
||||
first_time_encrypt("Encrypt existing data file? Y/n (q to quit)");
|
||||
}
|
||||
if (!datafile_exists && !arg_opts.unencrypt_data)
|
||||
first_time_encrypt("Creating new data file. Would you like to encrypt it? Y/n (q to quit)");
|
||||
else if (arg_opts.encrypt_data)
|
||||
first_time_encrypt("Encrypt existing data file? Y/n (q to quit)");
|
||||
|
||||
|
||||
/* init user_settings struct and load settings from conf file */
|
||||
user_settings = calloc(1, sizeof(struct user_settings));
|
||||
@ -1046,20 +1045,18 @@ int main(int argc, char *argv[])
|
||||
queue_init_message("X failed to initialize");
|
||||
#endif
|
||||
|
||||
Tox *m = init_tox();
|
||||
TOX_ERR_NEW err;
|
||||
Tox *m = load_toxic(DATA_FILE, &err);
|
||||
|
||||
if (m == NULL)
|
||||
exit_toxic_err("failed in main", FATALERR_NETWORKINIT);
|
||||
if (m == NULL || err != TOX_ERR_NEW_OK)
|
||||
exit_toxic_err("Tox instance failed to initialize", err);
|
||||
|
||||
if (!arg_opts.ignore_data_file) {
|
||||
if (arg_opts.encrypt_data && !datafile_exists)
|
||||
arg_opts.encrypt_data = 0;
|
||||
if (arg_opts.encrypt_data && !datafile_exists)
|
||||
arg_opts.encrypt_data = 0;
|
||||
|
||||
load_data(m, DATA_FILE);
|
||||
|
||||
}
|
||||
|
||||
init_term();
|
||||
|
||||
prompt = init_windows(m);
|
||||
prompt_init_statusbar(prompt, m);
|
||||
|
||||
@ -1104,7 +1101,7 @@ int main(int argc, char *argv[])
|
||||
queue_init_message("Failed to load user settings");
|
||||
|
||||
/* screen/tmux auto-away timer */
|
||||
if (init_mplex_away_timer (m) == -1)
|
||||
if (init_mplex_away_timer(m) == -1)
|
||||
queue_init_message("Failed to init mplex auto-away.");
|
||||
|
||||
print_init_messages(prompt);
|
||||
|
47
src/toxic.h
47
src/toxic.h
@ -77,13 +77,12 @@ typedef enum _FATAL_ERRS {
|
||||
FATALERR_THREAD_CREATE = -3, /* thread creation failed for critical thread */
|
||||
FATALERR_MUTEX_INIT = -4, /* mutex init for critical thread failed */
|
||||
FATALERR_THREAD_ATTR = -5, /* thread attr object init failed */
|
||||
FATALERR_LOCALE_SET = -6, /* system locale not set */
|
||||
FATALERR_LOCALE_NOT_SET = -6, /* system locale not set */
|
||||
FATALERR_STORE_DATA = -7, /* store_data failed in critical section */
|
||||
FATALERR_NETWORKINIT = -8, /* Tox network failed to init */
|
||||
FATALERR_INFLOOP = -9, /* infinite loop detected */
|
||||
FATALERR_WININIT = -10, /* window init failed */
|
||||
FATALERR_PROXY = -11, /* Tox network failed to init using a proxy */
|
||||
FATALERR_ENCRYPT = -12, /* Data file encryption failure */
|
||||
FATALERR_INFLOOP = -8, /* infinite loop detected */
|
||||
FATALERR_WININIT = -9, /* window init failed */
|
||||
FATALERR_PROXY = -10, /* Tox network failed to init using a proxy */
|
||||
FATALERR_ENCRYPT = -11, /* Data file encryption failure */
|
||||
} FATAL_ERRS;
|
||||
|
||||
/* Fixes text color problem on some terminals.
|
||||
@ -98,26 +97,26 @@ void exit_toxic_err(const char *errmsg, int errcode);
|
||||
|
||||
int store_data(Tox *m, const char *path);
|
||||
|
||||
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata);
|
||||
void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata);
|
||||
void on_message(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
|
||||
void on_action(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
|
||||
void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
|
||||
void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata);
|
||||
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
|
||||
void on_friendadded(Tox *m, int32_t friendnumber, bool sort);
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, void *userdata);
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void *userdata);
|
||||
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, uint16_t length, void *userdata);
|
||||
/* callbacks */
|
||||
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata);
|
||||
void on_connectionchange(Tox *m, uint32_t friendnumber, uint8_t status, void *userdata);
|
||||
void on_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, void *userdata);
|
||||
void on_action(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata);
|
||||
void on_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata);
|
||||
void on_statuschange(Tox *m, uint32_t friendnumber, TOX_USER_STATUS status, void *userdata);
|
||||
void on_statusmessagechange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata);
|
||||
void on_friendadded(Tox *m, uint32_t friendnumber, bool sort);
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, size_t length, void *userdata);
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, size_t length, void *userdata);
|
||||
void on_groupinvite(Tox *m, uint32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, size_t length, void *userdata);
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
|
||||
void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t *title, uint8_t length, void *userdata);
|
||||
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *pathname,
|
||||
uint16_t pathname_length, void *userdata);
|
||||
void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
|
||||
const uint8_t *data, uint16_t length, void *userdata);
|
||||
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata);
|
||||
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);
|
||||
void on_read_receipt(Tox *m, int32_t, uint32_t, void *userdata);
|
||||
void on_file_chunk_request(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata);
|
||||
void on_file_control (Tox *m, uint32_t friendnumber, uint32_t filenumber, TOX_FILE_CONTROL control, void *userdata);
|
||||
void on_file_recv(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint32_t kind, uint64_t file_size,
|
||||
const uint8_t *filename, size_t filename_length, void *userdata);
|
||||
void on_typing_change(Tox *m, uint32_t friendnumber, uint8_t is_typing, void *userdata);
|
||||
void on_read_receipt(Tox *m, uint32_t friendnumber, uint32_t receipt, void *userdata);
|
||||
|
||||
#ifdef AUDIO
|
||||
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
||||
|
@ -125,7 +125,7 @@ int yank_buf(ChatContext *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Deletes all characters from line starting at pos and going backwards
|
||||
/* Deletes all characters from line starting at pos and going backwards
|
||||
until we find a space or run out of characters.
|
||||
Return 0 on success, -1 if nothing to delete */
|
||||
int del_word_buf(ChatContext *ctx)
|
||||
@ -225,7 +225,7 @@ void fetch_hist_item(ChatContext *ctx, int key_dir)
|
||||
if (key_dir == KEY_UP) {
|
||||
if (--ctx->hst_pos < 0) {
|
||||
ctx->hst_pos = 0;
|
||||
sound_notify(NULL, error, NT_ALWAYS, NULL);
|
||||
sound_notify(NULL, notif_error, NT_ALWAYS, NULL);
|
||||
}
|
||||
} else {
|
||||
if (++ctx->hst_pos >= ctx->hst_tot) {
|
||||
|
126
src/windows.c
126
src/windows.c
@ -46,12 +46,12 @@ extern struct user_settings *user_settings;
|
||||
static int num_active_windows;
|
||||
|
||||
/* CALLBACKS START */
|
||||
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
char msg[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) data, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onFriendRequest != NULL) {
|
||||
@ -60,22 +60,22 @@ void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t
|
||||
}
|
||||
}
|
||||
|
||||
void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata)
|
||||
void on_connectionchange(Tox *m, uint32_t friendnumber, TOX_CONNECTION connection_status, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onConnectionChange != NULL)
|
||||
windows[i].onConnectionChange(&windows[i], m, friendnumber, status);
|
||||
windows[i].onConnectionChange(&windows[i], m, friendnumber, connection_status);
|
||||
}
|
||||
}
|
||||
|
||||
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata)
|
||||
void on_typing_change(Tox *m, uint32_t friendnumber, uint8_t is_typing, void *userdata)
|
||||
{
|
||||
if (user_settings->show_typing_other == SHOW_TYPING_OFF)
|
||||
return;
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onTypingChange != NULL)
|
||||
@ -83,39 +83,27 @@ void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *use
|
||||
}
|
||||
}
|
||||
|
||||
void on_message(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
void on_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
char msg[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) string, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onMessage != NULL)
|
||||
windows[i].onMessage(&windows[i], m, friendnumber, msg, length);
|
||||
windows[i].onMessage(&windows[i], m, friendnumber, type, msg, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_action(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
{
|
||||
char msg[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) string, length);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onAction != NULL)
|
||||
windows[i].onAction(&windows[i], m, friendnumber, msg, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
void on_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
|
||||
{
|
||||
char nick[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
length = copy_tox_str(nick, sizeof(nick), (const char *) string, length);
|
||||
filter_str(nick, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onNickChange != NULL)
|
||||
@ -125,13 +113,13 @@ void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
|
||||
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
void on_statusmessagechange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
|
||||
{
|
||||
char msg[TOX_MAX_STATUSMESSAGE_LENGTH + 1];
|
||||
char msg[TOX_MAX_STATUS_MESSAGE_LENGTH + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) string, length);
|
||||
filter_str(msg, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onStatusMessageChange != NULL)
|
||||
@ -139,9 +127,9 @@ void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string,
|
||||
}
|
||||
}
|
||||
|
||||
void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata)
|
||||
void on_statuschange(Tox *m, uint32_t friendnumber, TOX_USER_STATUS status, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onStatusChange != NULL)
|
||||
@ -149,9 +137,9 @@ void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdat
|
||||
}
|
||||
}
|
||||
|
||||
void on_friendadded(Tox *m, int32_t friendnumber, bool sort)
|
||||
void on_friendadded(Tox *m, uint32_t friendnumber, bool sort)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onFriendAdded != NULL)
|
||||
@ -161,13 +149,13 @@ void on_friendadded(Tox *m, int32_t friendnumber, bool sort)
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length,
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
char msg[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) message, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupMessage != NULL)
|
||||
@ -175,13 +163,13 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *mes
|
||||
}
|
||||
}
|
||||
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length,
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
char msg[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) action, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupAction != NULL)
|
||||
@ -189,10 +177,10 @@ void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *acti
|
||||
}
|
||||
}
|
||||
|
||||
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, uint16_t length,
|
||||
void on_groupinvite(Tox *m, uint32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupInvite != NULL)
|
||||
@ -202,7 +190,7 @@ void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *g
|
||||
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupNamelistChange != NULL)
|
||||
@ -216,7 +204,7 @@ void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t
|
||||
char data[MAX_STR_SIZE + 1];
|
||||
length = copy_tox_str(data, sizeof(data), (const char *) title, length);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupTitleChange != NULL)
|
||||
@ -224,44 +212,54 @@ void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
|
||||
const uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||
void on_file_chunk_request(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position,
|
||||
size_t length, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onFileSendRequest != NULL)
|
||||
windows[i].onFileSendRequest(&windows[i], m, friendnumber, filenumber, filesize,
|
||||
(const char *) filename, filename_length);
|
||||
if (windows[i].onFileChunkRequest != NULL)
|
||||
windows[i].onFileChunkRequest(&windows[i], m, friendnumber, filenumber, position, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_file_control (Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void on_file_recv_chunk(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position,
|
||||
const uint8_t *data, size_t length, void *user_data)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onFileRecvChunk != NULL)
|
||||
windows[i].onFileRecvChunk(&windows[i], m, friendnumber, filenumber, position, data, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_file_control(Tox *m, uint32_t friendnumber, uint32_t filenumber, TOX_FILE_CONTROL control,
|
||||
void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
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, (const char *) data, length);
|
||||
windows[i].onFileControl(&windows[i], m, friendnumber, filenumber, control);
|
||||
}
|
||||
}
|
||||
|
||||
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length,
|
||||
void *userdata)
|
||||
void on_file_recv(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint32_t kind, uint64_t file_size,
|
||||
const uint8_t *filename, size_t filename_length, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onFileData != NULL)
|
||||
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, (const char *) data, length);
|
||||
windows[i].onFileRecv(&windows[i], m, friendnumber, filenumber, kind, file_size, filename,
|
||||
filename_length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_read_receipt(Tox *m, int32_t friendnumber, uint32_t receipt, void *userdata)
|
||||
void on_read_receipt(Tox *m, uint32_t friendnumber, uint32_t receipt, void *userdata)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onReadReceipt != NULL)
|
||||
@ -273,7 +271,7 @@ void on_read_receipt(Tox *m, int32_t friendnumber, uint32_t receipt, void *userd
|
||||
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
||||
uint8_t channels, unsigned int sample_rate, void *arg)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onWriteDevice != NULL)
|
||||
@ -289,7 +287,7 @@ int add_window(Tox *m, ToxWindow w)
|
||||
if (LINES < 2)
|
||||
return -1;
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; i++) {
|
||||
if (windows[i].active)
|
||||
@ -383,7 +381,7 @@ void on_window_resize(void)
|
||||
getmaxyx(stdscr, y2, x2);
|
||||
y2 -= 2;
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (!windows[i].active)
|
||||
@ -455,7 +453,7 @@ static void draw_bar(void)
|
||||
printw(" TOXIC " TOXICVER " |");
|
||||
attroff(COLOR_PAIR(BLUE) | A_BOLD);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (!windows[i].active)
|
||||
@ -529,11 +527,11 @@ void draw_active_window(Tox *m)
|
||||
}
|
||||
}
|
||||
|
||||
/* refresh inactive windows to prevent scrolling bugs.
|
||||
/* refresh inactive windows to prevent scrolling bugs.
|
||||
call at least once per second */
|
||||
void refresh_inactive_windows(void)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
ToxWindow *a = &windows[i];
|
||||
@ -569,7 +567,7 @@ int get_num_active_windows(void)
|
||||
/* destroys all chat and groupchat windows (should only be called on shutdown) */
|
||||
void kill_all_windows(Tox *m)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].is_chat)
|
||||
|
@ -81,21 +81,21 @@ struct audio_thread {
|
||||
};
|
||||
|
||||
struct arg_opts {
|
||||
int ignore_data_file;
|
||||
int use_ipv4;
|
||||
int force_tcp;
|
||||
int debug;
|
||||
int default_locale;
|
||||
int use_custom_data;
|
||||
int no_connect;
|
||||
int encrypt_data;
|
||||
int unencrypt_data;
|
||||
bool use_ipv4;
|
||||
bool force_tcp;
|
||||
bool debug;
|
||||
bool default_locale;
|
||||
bool use_custom_data;
|
||||
bool no_connect;
|
||||
bool encrypt_data;
|
||||
bool unencrypt_data;
|
||||
|
||||
char dns_path[MAX_STR_SIZE];
|
||||
char config_path[MAX_STR_SIZE];
|
||||
char nodes_path[MAX_STR_SIZE];
|
||||
|
||||
uint8_t proxy_type;
|
||||
char proxy_address[256];
|
||||
uint8_t proxy_type;
|
||||
uint16_t proxy_port;
|
||||
};
|
||||
|
||||
@ -106,27 +106,30 @@ typedef struct ChatContext ChatContext;
|
||||
typedef struct Help Help;
|
||||
|
||||
struct ToxWindow {
|
||||
/* ncurses */
|
||||
void(*onKey)(ToxWindow *, Tox *, wint_t, bool);
|
||||
void(*onDraw)(ToxWindow *, Tox *);
|
||||
void(*onInit)(ToxWindow *, Tox *);
|
||||
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 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 char *, uint16_t);
|
||||
void(*onAction)(ToxWindow *, Tox *, int32_t, const char *, uint16_t);
|
||||
|
||||
/* toxcore */
|
||||
void(*onFriendRequest)(ToxWindow *, Tox *, const char *, const char *, size_t);
|
||||
void(*onFriendAdded)(ToxWindow *, Tox *, uint32_t, bool);
|
||||
void(*onConnectionChange)(ToxWindow *, Tox *, uint32_t, TOX_CONNECTION);
|
||||
void(*onMessage)(ToxWindow *, Tox *, uint32_t, TOX_MESSAGE_TYPE, const char *, size_t);
|
||||
void(*onNickChange)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
||||
void(*onStatusChange)(ToxWindow *, Tox *, uint32_t, TOX_USER_STATUS);
|
||||
void(*onStatusMessageChange)(ToxWindow *, uint32_t, const char *, size_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, uint8_t, const char *, uint16_t);
|
||||
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int, int, uint8_t);
|
||||
void(*onGroupTitleChange)(ToxWindow *, Tox *, int, int, const char *, uint8_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);
|
||||
void(*onReadReceipt)(ToxWindow *, Tox *, int32_t, uint32_t);
|
||||
void(*onFileChunkRequest)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, size_t);
|
||||
void(*onFileRecvChunk)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
||||
void(*onFileControl)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_FILE_CONTROL);
|
||||
void(*onFileRecv)(ToxWindow *, Tox *, uint32_t, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
||||
void(*onTypingChange)(ToxWindow *, Tox *, uint32_t, bool);
|
||||
void(*onReadReceipt)(ToxWindow *, Tox *, uint32_t, uint32_t);
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
@ -143,7 +146,7 @@ struct ToxWindow {
|
||||
void(*onPeerTimeout)(ToxWindow *, ToxAv *, int);
|
||||
void(*onWriteDevice)(ToxWindow *, Tox *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int);
|
||||
|
||||
int call_idx; /* If in a call will have this index set, otherwise it's -1.
|
||||
int call_idx; /* If in a call will have this index set, otherwise it's -1.
|
||||
* Don't modify outside av callbacks. */
|
||||
int device_selection[2]; /* -1 if not set, if set uses these selections instead of primary device */
|
||||
|
||||
@ -151,9 +154,9 @@ struct ToxWindow {
|
||||
#endif /* AUDIO */
|
||||
|
||||
int active_box; /* For box notify */
|
||||
|
||||
|
||||
char name[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
int32_t num; /* corresponds to friendnumber in chat windows */
|
||||
uint32_t num; /* corresponds to friendnumber in chat windows */
|
||||
bool active;
|
||||
int x;
|
||||
|
||||
@ -175,19 +178,19 @@ struct ToxWindow {
|
||||
/* statusbar info holder */
|
||||
struct StatusBar {
|
||||
WINDOW *topline;
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH + 1];
|
||||
uint16_t statusmsg_len;
|
||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH + 1];
|
||||
size_t statusmsg_len;
|
||||
char nick[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
int nick_len;
|
||||
uint8_t status;
|
||||
bool is_online;
|
||||
size_t nick_len;
|
||||
TOX_USER_STATUS status;
|
||||
TOX_CONNECTION connection;
|
||||
};
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
|
||||
#define INFOBOX_HEIGHT 7
|
||||
#define INFOBOX_WIDTH 21
|
||||
|
||||
/* holds display info for audio calls */
|
||||
struct infobox {
|
||||
float vad_lvl;
|
||||
@ -252,7 +255,7 @@ void on_window_resize(void);
|
||||
void force_refresh(WINDOW *w);
|
||||
ToxWindow *get_window_ptr(int i);
|
||||
|
||||
/* refresh inactive windows to prevent scrolling bugs.
|
||||
/* refresh inactive windows to prevent scrolling bugs.
|
||||
call at least once per second */
|
||||
void refresh_inactive_windows(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user