mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:33:02 +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));
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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,7 +175,7 @@ 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)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||
@ -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,14 +206,18 @@ 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;
|
||||
@ -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) {
|
||||
|
@ -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 */
|
||||
|
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;
|
||||
@ -283,7 +285,9 @@ 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)) {
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
16
src/input.c
16
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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
@ -572,7 +572,7 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id)
|
||||
#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);
|
||||
|
@ -29,7 +29,7 @@
|
||||
typedef enum _Notification
|
||||
{
|
||||
silent = -1,
|
||||
error,
|
||||
notif_error,
|
||||
self_log_in,
|
||||
self_log_out,
|
||||
user_log_in,
|
||||
@ -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,
|
||||
|
@ -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) {
|
||||
|
124
src/windows.c
124
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)
|
||||
@ -533,7 +531,7 @@ void draw_active_window(Tox *m)
|
||||
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
|
||||
|
||||
@ -153,7 +156,7 @@ struct ToxWindow {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user