From 0590d8325c4ae729fe3f1f96a4d4632ac9eefff4 Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Wed, 14 Aug 2013 17:27:10 +1200 Subject: [PATCH 01/27] removing unnecessary function pointer _isset variables --- core/Messenger.c | 34 +++++++++++++--------------------- core/Messenger.h | 12 ++---------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index 2721f8f6..45e8e3f9 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -75,9 +75,9 @@ int getclient_id(Messenger *m, int friend_id, uint8_t *client_id) return -1; } -/* +/* * returns a uint16_t that represents the checksum of address of length len - * + * * TODO: Another checksum algorithm might be better. */ static uint16_t address_checksum(uint8_t *address, uint32_t len) @@ -94,7 +94,7 @@ static uint16_t address_checksum(uint8_t *address, uint32_t len) /* * returns a FRIEND_ADDRESS_SIZE byte address to give to others. * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] - * + * */ void getaddress(Messenger *m, uint8_t *address) { @@ -118,7 +118,7 @@ void getaddress(Messenger *m, uint8_t *address) * return FAERR_ALREADYSENT if friend request already sent or already a friend * return FAERR_UNKNOWN for unknown error * return FAERR_BADCHECKSUM if bad checksum in address - * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different + * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different * (the nospam for that friend was set to the new one) */ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) @@ -449,8 +449,7 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno) m->friendlist[friendnumber].receives_read_receipts = yesno; } -/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); -static uint8_t friend_request_isset = 0; */ +/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */ /* set the function that will be executed when a friend request is received. */ void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata) { @@ -461,55 +460,48 @@ void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) { m->friend_message = function; - m->friend_message_isset = 1; m->friend_message_userdata = userdata; } void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) { m->friend_action = function; - m->friend_action_isset = 1; m->friend_action_userdata = userdata; } void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) { m->friend_namechange = function; - m->friend_namechange_isset = 1; m->friend_namechange_userdata = userdata; } void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) { m->friend_statusmessagechange = function; - m->friend_statusmessagechange_isset = 1; m->friend_statuschange_userdata = userdata; } void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void*), void* userdata) { m->friend_userstatuschange = function; - m->friend_userstatuschange_isset = 1; m->friend_userstatuschange_userdata = userdata; } void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void*), void* userdata) { m->read_receipt = function; - m->read_receipt_isset = 1; m->read_receipt_userdata = userdata; } void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void*), void* userdata) { m->friend_connectionstatuschange = function; - m->friend_connectionstatuschange_isset = 1; m->friend_connectionstatuschange_userdata = userdata; } static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status) { - if (!m->friend_connectionstatuschange_isset) + if (!m->friend_connectionstatuschange) return; if (status == NOFRIEND) return; @@ -648,7 +640,7 @@ void doFriends(Messenger *m) case PACKET_ID_NICKNAME: { if (data_length >= MAX_NAME_LENGTH || data_length == 0) break; - if(m->friend_namechange_isset) + if(m->friend_namechange) m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata); memcpy(m->friendlist[i].name, data, data_length); m->friendlist[i].name[data_length - 1] = 0; /* make sure the NULL terminator is present. */ @@ -659,7 +651,7 @@ void doFriends(Messenger *m) break; uint8_t *status = calloc(MIN(data_length, MAX_STATUSMESSAGE_LENGTH), 1); memcpy(status, data, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); - if (m->friend_statusmessagechange_isset) + if (m->friend_statusmessagechange) m->friend_statusmessagechange(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH), m->friend_statuschange_userdata); set_friend_statusmessage(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); @@ -670,7 +662,7 @@ void doFriends(Messenger *m) if (data_length != 1) break; USERSTATUS status = data[0]; - if (m->friend_userstatuschange_isset) + if (m->friend_userstatuschange) m->friend_userstatuschange(m, i, status, m->friend_userstatuschange_userdata); set_friend_userstatus(m, i, status); break; @@ -683,12 +675,12 @@ void doFriends(Messenger *m) if (m->friendlist[i].receives_read_receipts) { write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); } - if (m->friend_message_isset) + if (m->friend_message) (*m->friend_message)(m, i, message, message_length, m->friend_message_userdata); break; } case PACKET_ID_ACTION: { - if (m->friend_action_isset) + if (m->friend_action) (*m->friend_action)(m, i, data, data_length, m->friend_action_userdata); break; } @@ -698,7 +690,7 @@ void doFriends(Messenger *m) break; memcpy(&msgid, data, sizeof(msgid)); msgid = ntohl(msgid); - if (m->read_receipt_isset) + if (m->read_receipt) (*m->read_receipt)(m, i, msgid, m->read_receipt_userdata); break; } @@ -744,7 +736,7 @@ void doMessenger(Messenger *m) doNetCrypto(); doInbound(m); doFriends(m); - + timer_poll(); } diff --git a/core/Messenger.h b/core/Messenger.h index 9621176f..a2add19d 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -111,28 +111,20 @@ typedef struct Messenger { uint32_t numfriends; void (*friend_message)(struct Messenger *m, int, uint8_t *, uint16_t, void*); - uint8_t friend_message_isset; void* friend_message_userdata; void (*friend_action)(struct Messenger *m, int, uint8_t *, uint16_t, void*); - uint8_t friend_action_isset; void* friend_action_userdata; void (*friend_namechange)(struct Messenger *m, int, uint8_t *, uint16_t, void*); - uint8_t friend_namechange_isset; void* friend_namechange_userdata; void (*friend_statusmessagechange)(struct Messenger *m, int, uint8_t *, uint16_t, void*); - uint8_t friend_statusmessagechange_isset; void* friend_statusmessagechange_userdata; void (*friend_userstatuschange)(struct Messenger *m, int, USERSTATUS, void*); - uint8_t friend_userstatuschange_isset; void* friend_userstatuschange_userdata; void (*read_receipt)(struct Messenger *m, int, uint32_t, void*); - uint8_t read_receipt_isset; void* read_receipt_userdata; void (*friend_statuschange)(struct Messenger *m, int, uint8_t, void*); - uint8_t friend_statuschange_isset; void* friend_statuschange_userdata; void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void*); - uint8_t friend_connectionstatuschange_isset; void* friend_connectionstatuschange_userdata; @@ -141,7 +133,7 @@ typedef struct Messenger { /* * returns a FRIEND_ADDRESS_SIZE byte address to give to others. * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] - * + * */ void getaddress(Messenger *m, uint8_t *address); @@ -157,7 +149,7 @@ void getaddress(Messenger *m, uint8_t *address); * return -4 if friend request already sent or already a friend * return -5 for unknown error * return -6 if bad checksum in address - * return -7 if the friend was already there but the nospam was different + * return -7 if the friend was already there but the nospam was different * (the nospam for that friend was set to the new one) */ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length); From cf5ad56a4a26afc93da63a6064d49f6203c42d03 Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Wed, 14 Aug 2013 17:35:15 +1200 Subject: [PATCH 02/27] fixing minor memory leak of friendlist --- core/Messenger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/Messenger.c b/core/Messenger.c index 45e8e3f9..e2d83ada 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -572,7 +572,10 @@ Messenger * initMessenger(void) /* run this before closing shop */ void cleanupMessenger(Messenger *m){ - /* FIXME TODO it seems no one frees friendlist or all the elements status */ + /* FIXME TODO ideally cleanupMessenger will mirror initMessenger + * this requires the other modules to expose cleanup functions + */ + free(m->friendlist); free(m); } From 72ee99e84838e3b0c74e3d66defdcc3ab7f4f6f9 Mon Sep 17 00:00:00 2001 From: naxuroqa Date: Wed, 14 Aug 2013 10:44:25 +0200 Subject: [PATCH 03/27] rewrite of get_id function --- testing/nTox.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index cab2d158..ead4fd21 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -52,28 +52,15 @@ uint8_t num_requests = 0; void get_id(Messenger *m, char *data) { - char idstring0[200]; - char idstring1[FRIEND_ADDRESS_SIZE][5]; - char idstring2[FRIEND_ADDRESS_SIZE][5]; + sprintf(data, "[i] ID: "); + int offset = strlen(data); int i = 0; uint8_t address[FRIEND_ADDRESS_SIZE]; getaddress(m, address); - for(i = 0; i < FRIEND_ADDRESS_SIZE; i++) + for(; i < FRIEND_ADDRESS_SIZE; i++) { - if (address[i] < (FRIEND_ADDRESS_SIZE / 2)) - strcpy(idstring1[i],"0"); - else - strcpy(idstring1[i], ""); - sprintf(idstring2[i], "%hhX",address[i]); + sprintf(data + 2*i + offset, "%02X ", address[i]); } - strcpy(idstring0,"[i] ID: "); - int j = 0; - for (j = 0; j < FRIEND_ADDRESS_SIZE; j++) { - strcat(idstring0,idstring1[j]); - strcat(idstring0,idstring2[j]); - } - - memcpy(data, idstring0, strlen(idstring0)); } void new_lines(char *line) From 3b42f489e495748b729958b3be18954eb27e75f7 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Wed, 14 Aug 2013 21:16:02 +1200 Subject: [PATCH 04/27] Have toxic handle new no-spam values from friend request --- testing/toxic/prompt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index e1a7d75c..b1d6693f 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -138,6 +138,12 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) case FAERR_UNKNOWN: wprintw(self->window, "Undefined error when adding friend.\n"); break; + case FAERR_BADCHECKSUM: + wprintw(self->window, "Bad checksum in address.\n"); + break; + case FAERR_SETNEWNOSPAM: + wprintw(self->window, "Nospam was different.\n"); + break; default: wprintw(self->window, "Friend added as %d.\n", num); on_friendadded(num); From 1260aee9e1b61841459f83397f84b089d360819b Mon Sep 17 00:00:00 2001 From: Astonex Date: Wed, 14 Aug 2013 11:23:38 +0100 Subject: [PATCH 05/27] Update prompt.c Make id uppercase. --- testing/toxic/prompt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index e1a7d75c..c0169c62 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -121,6 +121,11 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) } id_bin[i] = x; } + + for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { + id[i] = toupper(id[i]); + } + int num = m_addfriend(m, id_bin, (uint8_t*) msg, strlen(msg)+1); switch (num) { case FAERR_TOOLONG: From 4e21ac0d57df8d20dcdc4dd318d1e63166017e30 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 13 Aug 2013 09:34:46 +1200 Subject: [PATCH 06/27] prefer param over static Conflicts: testing/toxic/main.c --- testing/toxic/friendlist.c | 6 +++--- testing/toxic/main.c | 29 ++++++++++++++--------------- testing/toxic/prompt.c | 6 +++--- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index 56061cf9..1a77440e 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c @@ -13,7 +13,7 @@ #include "windows.h" extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; -extern int add_window(ToxWindow w, int n); +extern int add_window(Messenger *m, ToxWindow w, int n); extern ToxWindow new_chat(Messenger *m, int friendnum); extern int active_window; @@ -54,7 +54,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num; - add_window(new_chat(m, num), i); + add_window(m, new_chat(m, num), i); active_window = i; break; } @@ -121,7 +121,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num_selected; friends[num_selected].chatwin = num_selected; - add_window(new_chat(m, num_selected), i); + add_window(m, new_chat(m, num_selected), i); active_window = i; break; } diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 40ff5d09..8ab2d393 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -40,8 +40,6 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; static ToxWindow windows[MAX_WINDOW_SLOTS]; static ToxWindow* prompt; -static Messenger *m; - int w_num; int active_window; @@ -103,7 +101,7 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l } } -void on_friendadded(int friendnumber) +void on_friendadded(Messenger *m, int friendnumber) { friendlist_onFriendAdded(m, friendnumber); } @@ -129,10 +127,10 @@ static void init_term() refresh(); } -static void init_tox() +static Messenger * init_tox() { /* Init core */ - m = initMessenger(); + Messenger *m = initMessenger(); /* Callbacks */ m_callback_friendrequest(m, on_request, NULL); @@ -147,6 +145,7 @@ static void init_tox() #else setname(m, (uint8_t*) "Hipster", sizeof("Hipster")); #endif + return m; } #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ @@ -207,7 +206,7 @@ void init_window_status() WINDOW_STATUS[j] = -1; } -int add_window(ToxWindow w, int n) +int add_window(Messenger *m, ToxWindow w, int n) { if (w_num >= TOXWINDOWS_MAX_NUM) return -1; @@ -241,13 +240,13 @@ void del_window(ToxWindow *w, int f_num) refresh(); } -static void init_windows() +static void init_windows(Messenger *m) { w_num = 0; int n_prompt = 0; int n_friendslist = 1; - if (add_window(new_prompt(), n_prompt) == -1 - || add_window(new_friendlist(), n_friendslist) == -1) { + if (add_window(m, new_prompt(), n_prompt) == -1 + || add_window(m, new_friendlist(), n_friendslist) == -1) { fprintf(stderr, "add_window() failed.\n"); endwin(); exit(1); @@ -255,7 +254,7 @@ static void init_windows() prompt = &windows[n_prompt]; } -static void do_tox() +static void do_tox(Messenger *m) { static int conn_try = 0; static int conn_err = 0; @@ -279,7 +278,7 @@ static void do_tox() doMessenger(m); } -static void load_data(char *path) +static void load_data(Messenger *m, char *path) { FILE *fd; size_t len; @@ -451,12 +450,12 @@ int main(int argc, char *argv[]) } init_term(); - init_tox(); - init_windows(); + Messenger *m = init_tox(); + init_windows(m); init_window_status(); if(f_loadfromfile) - load_data(DATA_FILE); + load_data(m, DATA_FILE); free(DATA_FILE); if (f_flag == -1) { @@ -474,7 +473,7 @@ int main(int argc, char *argv[]) } while(true) { /* Update tox */ - do_tox(); + do_tox(m); /* Draw */ a = &windows[active_window]; diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index b1d6693f..c01ed710 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -15,7 +15,7 @@ uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX uint8_t num_requests=0; // XXX -extern void on_friendadded(int friendnumber); +extern void on_friendadded(Messenger *m, int friendnumber); static char prompt_buf[MAX_STR_SIZE] = {0}; static int prompt_buf_pos = 0; @@ -87,7 +87,7 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args) wprintw(self->window, "Failed to add friend.\n"); else { wprintw(self->window, "Friend accepted as: %d.\n", num); - on_friendadded(num); + on_friendadded(m, num); } } @@ -146,7 +146,7 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) break; default: wprintw(self->window, "Friend added as %d.\n", num); - on_friendadded(num); + on_friendadded(m, num); break; } } From 3f37c5580dc6cfd0920095f6d3c99aba035724ee Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 12:58:15 +1200 Subject: [PATCH 07/27] add header guard and includes to windows.h --- testing/toxic/windows.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 648243d0..4eb55a99 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h @@ -1,8 +1,13 @@ /* * Toxic -- Tox Curses Client */ +#ifndef _windows_h +#define _windows_h +#include +#include #include +#include "../../core/Messenger.h" #define TOXWINDOWS_MAX_NUM 32 #define MAX_FRIENDS_NUM 100 #define MAX_STR_SIZE 256 @@ -32,3 +37,6 @@ struct ToxWindow_ { WINDOW* window; }; + +#endif + From 75ce48146a7764b67a19d41e4da5d279d59b6ea1 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 13 Aug 2013 10:50:43 +1200 Subject: [PATCH 08/27] remove externs in favor of includes --- testing/toxic/chat.c | 10 ++--- testing/toxic/chat.h | 7 ++++ testing/toxic/friendlist.c | 25 ++++++------ testing/toxic/friendlist.h | 14 +++++++ testing/toxic/main.c | 84 +++++++++++++++++++------------------- testing/toxic/prompt.c | 6 ++- testing/toxic/prompt.h | 14 +++++++ 7 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 testing/toxic/chat.h create mode 100644 testing/toxic/friendlist.h create mode 100644 testing/toxic/prompt.h diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 1b5e743d..6811569b 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -13,6 +13,8 @@ #include "../../core/network.h" #include "windows.h" +#include "friendlist.h" +#include "chat.h" #define CURS_Y_OFFSET 3 @@ -24,10 +26,8 @@ typedef struct { WINDOW* linewin; } ChatContext; -extern int active_window; +static delWindowFn *del_window; -extern void del_window(ToxWindow *w, int f_num); -extern void fix_name(uint8_t *name); void print_help(ChatContext *self); void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd); @@ -320,7 +320,6 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) } else if (strcmp(ctx->line, "/close") == 0) { - active_window = 0; // Go to prompt screen int f_num = ctx->friendnum; delwin(ctx->linewin); del_window(self, f_num); @@ -371,8 +370,9 @@ void print_help(ChatContext *self) wattroff(self->history, COLOR_PAIR(2)); } -ToxWindow new_chat(Messenger *m, int friendnum) +ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn *f) { + del_window = f; ToxWindow ret; memset(&ret, 0, sizeof(ret)); diff --git a/testing/toxic/chat.h b/testing/toxic/chat.h new file mode 100644 index 00000000..dcd5b3ba --- /dev/null +++ b/testing/toxic/chat.h @@ -0,0 +1,7 @@ +#ifndef CHAT_H_6489PZ13 +#define CHAT_H_6489PZ13 + +typedef void (delWindowFn)(ToxWindow *w, int f_num); +ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn f); + +#endif /* end of include guard: CHAT_H_6489PZ13 */ diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index 1a77440e..5b79fdef 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c @@ -10,13 +10,12 @@ #include "../../core/Messenger.h" #include "../../core/network.h" -#include "windows.h" +#include "friendlist.h" -extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; -extern int add_window(Messenger *m, ToxWindow w, int n); -extern ToxWindow new_chat(Messenger *m, int friendnum); - -extern int active_window; +static delWindowFn *del_window; +static setActiveWindowFn *set_active_window; +static addWindowFn *add_window; +static char * WINDOW_STATUS; typedef struct { uint8_t name[MAX_NAME_LENGTH]; @@ -54,8 +53,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num; - add_window(m, new_chat(m, num), i); - active_window = i; + add_window(m, new_chat(m, num, del_window), i); break; } } @@ -111,7 +109,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) int i; for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { if (WINDOW_STATUS[i] == num_selected) { - active_window = i; + set_active_window(i); break; } } @@ -121,8 +119,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num_selected; friends[num_selected].chatwin = num_selected; - add_window(m, new_chat(m, num_selected), i); - active_window = i; + add_window(m, new_chat(m, num_selected, del_window), i); break; } } @@ -169,7 +166,11 @@ static void friendlist_onInit(ToxWindow *self, Messenger *m) } -ToxWindow new_friendlist() { +ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws) { + del_window = dw; + set_active_window = saw; + add_window = aw; + WINDOW_STATUS = ws; ToxWindow ret; memset(&ret, 0, sizeof(ret)); diff --git a/testing/toxic/friendlist.h b/testing/toxic/friendlist.h new file mode 100644 index 00000000..e8b93aef --- /dev/null +++ b/testing/toxic/friendlist.h @@ -0,0 +1,14 @@ +#ifndef FRIENDLIST_H_53I41IM +#define FRIENDLIST_H_53I41IM + + +#include "windows.h" +#include "chat.h" +typedef void (setActiveWindowFn)(int ch); +typedef int (addWindowFn)(Messenger *m, ToxWindow w, int n); +ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws); +int friendlist_onFriendAdded(Messenger *m, int num); +void disable_chatwin(int f_num); +void fix_name(uint8_t *name); + +#endif /* end of include guard: FRIENDLIST_H_53I41IM */ diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 8ab2d393..a109311e 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -21,14 +21,9 @@ #include "configdir.h" #include "windows.h" +#include "prompt.h" +#include "friendlist.h" -extern ToxWindow new_prompt(); -extern ToxWindow new_friendlist(); - -extern int friendlist_onFriendAdded(Messenger *m, int num); -extern void disable_chatwin(int f_num); -extern int add_req(uint8_t *public_key); // XXX -extern unsigned char *hex_string_to_bin(char hex_string[]); /* Holds status of chat windows */ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; @@ -221,12 +216,14 @@ int add_window(Messenger *m, ToxWindow w, int n) windows[n] = w; w.onInit(&w, m); w_num++; + active_window = n; return n; } /* Deletes window w and cleans up */ void del_window(ToxWindow *w, int f_num) { + active_window = 0; // Go to prompt screen delwin(w->window); int i; for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { @@ -240,13 +237,48 @@ void del_window(ToxWindow *w, int f_num) refresh(); } +/* Shows next window when tab or back-tab is pressed */ +void set_active_window(int ch) +{ + int f_inf = 0; + int max = MAX_WINDOW_SLOTS-1; + if (ch == '\t') { + int i = (active_window + 1) % max; + while (true) { + if (WINDOW_STATUS[i] != -1) { + active_window = i; + return; + } + i = (i + 1) % max; + if (f_inf++ > max) { // infinite loop check + endwin(); + exit(2); + } + } + }else { + int i = active_window - 1; + if (i < 0) i = max; + while (true) { + if (WINDOW_STATUS[i] != -1) { + active_window = i; + return; + } + if (--i < 0) i = max; + if (f_inf++ > max) { + endwin(); + exit(2); + } + } + } +} + static void init_windows(Messenger *m) { w_num = 0; int n_prompt = 0; int n_friendslist = 1; - if (add_window(m, new_prompt(), n_prompt) == -1 - || add_window(m, new_friendlist(), n_friendslist) == -1) { + if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 + || add_window(m, new_friendlist(del_window, set_active_window, add_window, WINDOW_STATUS), n_friendslist) == -1) { fprintf(stderr, "add_window() failed.\n"); endwin(); exit(1); @@ -378,40 +410,6 @@ void prepare_window(WINDOW *w) wresize(w, LINES-2, COLS); } -/* Shows next window when tab or back-tab is pressed */ -void set_active_window(int ch) -{ - int f_inf = 0; - int max = MAX_WINDOW_SLOTS-1; - if (ch == '\t') { - int i = (active_window + 1) % max; - while (true) { - if (WINDOW_STATUS[i] != -1) { - active_window = i; - return; - } - i = (i + 1) % max; - if (f_inf++ > max) { // infinite loop check - endwin(); - exit(2); - } - } - }else { - int i = active_window - 1; - if (i < 0) i = max; - while (true) { - if (WINDOW_STATUS[i] != -1) { - active_window = i; - return; - } - if (--i < 0) i = max; - if (f_inf++ > max) { - endwin(); - exit(2); - } - } - } -} int main(int argc, char *argv[]) { diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index c01ed710..bc4b8545 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -11,11 +11,12 @@ #include "../../core/network.h" #include "windows.h" +#include "prompt.h" uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX uint8_t num_requests=0; // XXX -extern void on_friendadded(Messenger *m, int friendnumber); +static friendAddedFn *on_friendadded; static char prompt_buf[MAX_STR_SIZE] = {0}; static int prompt_buf_pos = 0; @@ -428,8 +429,9 @@ static void prompt_onInit(ToxWindow *self, Messenger *m) wclrtoeol(self->window); } -ToxWindow new_prompt() +ToxWindow new_prompt(friendAddedFn *f) { + on_friendadded = f; ToxWindow ret; memset(&ret, 0, sizeof(ret)); ret.onKey = &prompt_onKey; diff --git a/testing/toxic/prompt.h b/testing/toxic/prompt.h new file mode 100644 index 00000000..6c5320ab --- /dev/null +++ b/testing/toxic/prompt.h @@ -0,0 +1,14 @@ +#ifndef PROMPT_H_UZYGWFFL +#define PROMPT_H_UZYGWFFL + +#include "windows.h" + +typedef void (friendAddedFn)(Messenger *m, int friendnumber); + +ToxWindow new_prompt(friendAddedFn *f); +int add_req(uint8_t *public_key); +unsigned char *hex_string_to_bin(char hex_string[]); + +#endif /* end of include guard: PROMPT_H_UZYGWFFL */ + + From 1edb7c1660884face7f5d97b8d6df57da5e54a17 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 13 Aug 2013 12:21:03 +1200 Subject: [PATCH 09/27] move windows functions to its own file --- testing/toxic/CMakeLists.txt | 1 + testing/toxic/main.c | 236 +---------------------------------- testing/toxic/windows.c | 235 ++++++++++++++++++++++++++++++++++ testing/toxic/windows.h | 8 ++ 4 files changed, 248 insertions(+), 232 deletions(-) create mode 100644 testing/toxic/windows.c diff --git a/testing/toxic/CMakeLists.txt b/testing/toxic/CMakeLists.txt index 13b8692d..dd811b97 100644 --- a/testing/toxic/CMakeLists.txt +++ b/testing/toxic/CMakeLists.txt @@ -8,6 +8,7 @@ set(exe_name toxic) add_executable(${exe_name} main.c + windows.c prompt.c friendlist.c chat.c diff --git a/testing/toxic/main.c b/testing/toxic/main.c index a109311e..d7b251dc 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -24,84 +24,10 @@ #include "prompt.h" #include "friendlist.h" - -/* Holds status of chat windows */ -char WINDOW_STATUS[MAX_WINDOW_SLOTS]; - #ifndef TOXICVER #define TOXICVER "NOVER" //Use the -D flag to set this #endif -static ToxWindow windows[MAX_WINDOW_SLOTS]; -static ToxWindow* prompt; - -int w_num; -int active_window; - -/* CALLBACKS START */ -void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata) -{ - int n = add_req(public_key); - wprintw(prompt->window, "\nFriend request from:\n"); - - int i; - for (i = 0; i < KEY_SIZE_BYTES; ++i) { - wprintw(prompt->window, "%02x", public_key[i] & 0xff); - } - - wprintw(prompt->window, "\nWith the message: %s\n", data); - wprintw(prompt->window, "\nUse \"accept %d\" to accept it.\n", n); - - for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { - if (windows[i].onFriendRequest != NULL) - windows[i].onFriendRequest(&windows[i], public_key, data, length); - } -} - -void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) -{ - int i; - for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { - if (windows[i].onMessage != NULL) - windows[i].onMessage(&windows[i], m, friendnumber, string, length); - } -} - -void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) -{ - int i; - for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { - if (windows[i].onAction != NULL) - windows[i].onAction(&windows[i], m, friendnumber, string, length); - } -} - -void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) -{ - wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); - int i; - for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { - if (windows[i].onNickChange != NULL) - windows[i].onNickChange(&windows[i], friendnumber, string, length); - } -} - -void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) -{ - wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); - int i; - for (i=0; i= TOXWINDOWS_MAX_NUM) - return -1; - - if (LINES < 2) - return -1; - - w.window = newwin(LINES - 2, COLS, 0, 0); - if (w.window == NULL) - return -1; - - windows[n] = w; - w.onInit(&w, m); - w_num++; - active_window = n; - return n; -} - -/* Deletes window w and cleans up */ -void del_window(ToxWindow *w, int f_num) -{ - active_window = 0; // Go to prompt screen - delwin(w->window); - int i; - for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { - if (WINDOW_STATUS[i] == f_num) { - WINDOW_STATUS[i] = -1; - disable_chatwin(f_num); - break; - } - } - clear(); - refresh(); -} - -/* Shows next window when tab or back-tab is pressed */ -void set_active_window(int ch) -{ - int f_inf = 0; - int max = MAX_WINDOW_SLOTS-1; - if (ch == '\t') { - int i = (active_window + 1) % max; - while (true) { - if (WINDOW_STATUS[i] != -1) { - active_window = i; - return; - } - i = (i + 1) % max; - if (f_inf++ > max) { // infinite loop check - endwin(); - exit(2); - } - } - }else { - int i = active_window - 1; - if (i < 0) i = max; - while (true) { - if (WINDOW_STATUS[i] != -1) { - active_window = i; - return; - } - if (--i < 0) i = max; - if (f_inf++ > max) { - endwin(); - exit(2); - } - } - } -} - -static void init_windows(Messenger *m) -{ - w_num = 0; - int n_prompt = 0; - int n_friendslist = 1; - if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 - || add_window(m, new_friendlist(del_window, set_active_window, add_window, WINDOW_STATUS), n_friendslist) == -1) { - fprintf(stderr, "add_window() failed.\n"); - endwin(); - exit(1); - } - prompt = &windows[n_prompt]; -} - -static void do_tox(Messenger *m) +static void do_tox(Messenger *m, ToxWindow * prompt) { static int conn_try = 0; static int conn_err = 0; @@ -367,54 +196,8 @@ static void load_data(Messenger *m, char *path) fclose(fd); } -static void draw_bar() -{ - static int odd = 0; - int blinkrate = 30; - - attron(COLOR_PAIR(4)); - mvhline(LINES - 2, 0, '_', COLS); - attroff(COLOR_PAIR(4)); - - move(LINES - 1, 0); - - attron(COLOR_PAIR(4) | A_BOLD); - printw(" TOXIC " TOXICVER "|"); - attroff(COLOR_PAIR(4) | A_BOLD); - - int i; - for (i = 0; i < (MAX_WINDOW_SLOTS); ++i) { - if (WINDOW_STATUS[i] != -1) { - if (i == active_window) - attron(A_BOLD); - - odd = (odd+1) % blinkrate; - if (windows[i].blink && (odd < (blinkrate/2))) - attron(COLOR_PAIR(3)); - - printw(" %s", windows[i].title); - if (windows[i].blink && (odd < (blinkrate/2))) - attroff(COLOR_PAIR(3)); - - if (i == active_window) { - attroff(A_BOLD); - } - } - } - refresh(); -} - -void prepare_window(WINDOW *w) -{ - mvwin(w, 0, 0); - wresize(w, LINES-2, COLS); -} - - int main(int argc, char *argv[]) { - int ch; - ToxWindow* a; char *user_config_dir = get_user_config_dir(); char *DATA_FILE; int config_err = create_user_config_dir(user_config_dir); @@ -449,7 +232,7 @@ int main(int argc, char *argv[]) init_term(); Messenger *m = init_tox(); - init_windows(m); + ToxWindow * prompt = init_windows(m); init_window_status(); if(f_loadfromfile) @@ -471,21 +254,10 @@ int main(int argc, char *argv[]) } while(true) { /* Update tox */ - do_tox(m); + do_tox(m, prompt); /* Draw */ - a = &windows[active_window]; - prepare_window(a->window); - a->blink = false; - draw_bar(); - a->onDraw(a); - - /* Handle input */ - ch = getch(); - if (ch == '\t' || ch == KEY_BTAB) - set_active_window(ch); - else if (ch != ERR) - a->onKey(a, m, ch); + draw_active_window(m); } cleanupMessenger(m); return 0; diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c new file mode 100644 index 00000000..c3952432 --- /dev/null +++ b/testing/toxic/windows.c @@ -0,0 +1,235 @@ +#include "friendlist.h" +#include "prompt.h" +#include "windows.h" + +/* Holds status of chat windows */ +char WINDOW_STATUS[MAX_WINDOW_SLOTS]; + +static int w_num; +static ToxWindow windows[MAX_WINDOW_SLOTS]; +static Messenger *m; +int active_window; + +static ToxWindow* prompt; + +/* CALLBACKS START */ +void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata) +{ + int n = add_req(public_key); + wprintw(prompt->window, "\nFriend request from:\n"); + + int i; + for (i = 0; i < KEY_SIZE_BYTES; ++i) { + wprintw(prompt->window, "%02x", public_key[i] & 0xff); + } + + wprintw(prompt->window, "\nWith the message: %s\n", data); + wprintw(prompt->window, "\nUse \"accept %d\" to accept it.\n", n); + + for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { + if (windows[i].onFriendRequest != NULL) + windows[i].onFriendRequest(&windows[i], public_key, data, length); + } +} + +void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) +{ + int i; + for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { + if (windows[i].onMessage != NULL) + windows[i].onMessage(&windows[i], m, friendnumber, string, length); + } +} + +void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) +{ + int i; + for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { + if (windows[i].onAction != NULL) + windows[i].onAction(&windows[i], m, friendnumber, string, length); + } +} + +void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) +{ + wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); + int i; + for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { + if (windows[i].onNickChange != NULL) + windows[i].onNickChange(&windows[i], friendnumber, string, length); + } +} + +void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata) +{ + wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); + int i; + for (i=0; i= TOXWINDOWS_MAX_NUM) + return -1; + + if (LINES < 2) + return -1; + + w.window = newwin(LINES - 2, COLS, 0, 0); + if (w.window == NULL) + return -1; + + windows[n] = w; + w.onInit(&w, m); + w_num++; + active_window = n; + return n; +} + +/* Deletes window w and cleans up */ +void del_window(ToxWindow *w, int f_num) +{ + active_window = 0; // Go to prompt screen + delwin(w->window); + int i; + for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { + if (WINDOW_STATUS[i] == f_num) { + WINDOW_STATUS[i] = -1; + disable_chatwin(f_num); + break; + } + } + clear(); + refresh(); +} + +/* Shows next window when tab or back-tab is pressed */ +void set_active_window(int ch) +{ + int f_inf = 0; + int max = MAX_WINDOW_SLOTS-1; + if (ch == '\t') { + int i = (active_window + 1) % max; + while (true) { + if (WINDOW_STATUS[i] != -1) { + active_window = i; + return; + } + i = (i + 1) % max; + if (f_inf++ > max) { // infinite loop check + endwin(); + exit(2); + } + } + }else { + int i = active_window - 1; + if (i < 0) i = max; + while (true) { + if (WINDOW_STATUS[i] != -1) { + active_window = i; + return; + } + if (--i < 0) i = max; + if (f_inf++ > max) { + endwin(); + exit(2); + } + } + } +} + +void init_window_status() +{ + /* Default window values decrement from -2 */ + int i; + for (i = 0; i < N_DEFAULT_WINS; ++i) + WINDOW_STATUS[i] = -(i+2); + + int j; + for (j = N_DEFAULT_WINS; j < MAX_WINDOW_SLOTS; j++) + WINDOW_STATUS[j] = -1; +} + +ToxWindow * init_windows() +{ + w_num = 0; + int n_prompt = 0; + int n_friendslist = 1; + if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 + || add_window(m, new_friendlist(del_window, set_active_window, add_window, WINDOW_STATUS), n_friendslist) == -1) { + fprintf(stderr, "add_window() failed.\n"); + endwin(); + exit(1); + } + prompt = &windows[n_prompt]; + return prompt; +} + +static void draw_bar() +{ + static int odd = 0; + int blinkrate = 30; + + attron(COLOR_PAIR(4)); + mvhline(LINES - 2, 0, '_', COLS); + attroff(COLOR_PAIR(4)); + + move(LINES - 1, 0); + + attron(COLOR_PAIR(4) | A_BOLD); + printw(" TOXIC " TOXICVER "|"); + attroff(COLOR_PAIR(4) | A_BOLD); + + int i; + for (i = 0; i < (MAX_WINDOW_SLOTS); ++i) { + if (WINDOW_STATUS[i] != -1) { + if (i == active_window) + attron(A_BOLD); + + odd = (odd+1) % blinkrate; + if (windows[i].blink && (odd < (blinkrate/2))) + attron(COLOR_PAIR(3)); + + printw(" %s", windows[i].title); + if (windows[i].blink && (odd < (blinkrate/2))) + attroff(COLOR_PAIR(3)); + + if (i == active_window) { + attroff(A_BOLD); + } + } + } + refresh(); +} + +void prepare_window(WINDOW *w) +{ + mvwin(w, 0, 0); + wresize(w, LINES-2, COLS); +} + +void draw_active_window(Messenger * m) +{ + + ToxWindow *a = &windows[active_window]; + prepare_window(a->window); + a->blink = false; + draw_bar(); + a->onDraw(a); + + /* Handle input */ + int ch = getch(); + if (ch == '\t' || ch == KEY_BTAB) + set_active_window(ch); + else if (ch != ERR) + a->onKey(a, m, ch); +} diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 4eb55a99..613fa3b3 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h @@ -38,5 +38,13 @@ struct ToxWindow_ { WINDOW* window; }; +void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata); +void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata); +void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata); +void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata); +void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void* userdata); +void init_window_status(); +ToxWindow * init_windows(); +void draw_active_window(Messenger * m); #endif From 4946c809d75ebec360d3f34b7518fb5f0948c925 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 13 Aug 2013 12:32:09 +1200 Subject: [PATCH 10/27] remove temporary callbacks from refactoring --- testing/toxic/chat.c | 5 +---- testing/toxic/chat.h | 3 +-- testing/toxic/friendlist.c | 13 ++++--------- testing/toxic/friendlist.h | 6 ++---- testing/toxic/windows.c | 2 +- testing/toxic/windows.h | 3 +++ 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 6811569b..e4da9484 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -26,8 +26,6 @@ typedef struct { WINDOW* linewin; } ChatContext; -static delWindowFn *del_window; - void print_help(ChatContext *self); void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd); @@ -370,9 +368,8 @@ void print_help(ChatContext *self) wattroff(self->history, COLOR_PAIR(2)); } -ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn *f) +ToxWindow new_chat(Messenger *m, int friendnum) { - del_window = f; ToxWindow ret; memset(&ret, 0, sizeof(ret)); diff --git a/testing/toxic/chat.h b/testing/toxic/chat.h index dcd5b3ba..7599d462 100644 --- a/testing/toxic/chat.h +++ b/testing/toxic/chat.h @@ -1,7 +1,6 @@ #ifndef CHAT_H_6489PZ13 #define CHAT_H_6489PZ13 -typedef void (delWindowFn)(ToxWindow *w, int f_num); -ToxWindow new_chat(Messenger *m, int friendnum, delWindowFn f); +ToxWindow new_chat(Messenger *m, int friendnum); #endif /* end of include guard: CHAT_H_6489PZ13 */ diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index 5b79fdef..e7504fbf 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c @@ -10,11 +10,9 @@ #include "../../core/Messenger.h" #include "../../core/network.h" +#include "windows.h" #include "friendlist.h" -static delWindowFn *del_window; -static setActiveWindowFn *set_active_window; -static addWindowFn *add_window; static char * WINDOW_STATUS; typedef struct { @@ -53,7 +51,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num; - add_window(m, new_chat(m, num, del_window), i); + add_window(m, new_chat(m, num), i); break; } } @@ -119,7 +117,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) if (WINDOW_STATUS[i] == -1) { WINDOW_STATUS[i] = num_selected; friends[num_selected].chatwin = num_selected; - add_window(m, new_chat(m, num_selected, del_window), i); + add_window(m, new_chat(m, num_selected), i); break; } } @@ -166,10 +164,7 @@ static void friendlist_onInit(ToxWindow *self, Messenger *m) } -ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws) { - del_window = dw; - set_active_window = saw; - add_window = aw; +ToxWindow new_friendlist(char * ws) { WINDOW_STATUS = ws; ToxWindow ret; memset(&ret, 0, sizeof(ret)); diff --git a/testing/toxic/friendlist.h b/testing/toxic/friendlist.h index e8b93aef..c3d8dac7 100644 --- a/testing/toxic/friendlist.h +++ b/testing/toxic/friendlist.h @@ -1,12 +1,10 @@ #ifndef FRIENDLIST_H_53I41IM #define FRIENDLIST_H_53I41IM - #include "windows.h" #include "chat.h" -typedef void (setActiveWindowFn)(int ch); -typedef int (addWindowFn)(Messenger *m, ToxWindow w, int n); -ToxWindow new_friendlist(delWindowFn dw, setActiveWindowFn saw, addWindowFn aw, char * ws); + +ToxWindow new_friendlist(char * ws); int friendlist_onFriendAdded(Messenger *m, int num); void disable_chatwin(int f_num); void fix_name(uint8_t *name); diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index c3952432..d19392ac 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c @@ -165,7 +165,7 @@ ToxWindow * init_windows() int n_prompt = 0; int n_friendslist = 1; if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 - || add_window(m, new_friendlist(del_window, set_active_window, add_window, WINDOW_STATUS), n_friendslist) == -1) { + || add_window(m, new_friendlist(WINDOW_STATUS), n_friendslist) == -1) { fprintf(stderr, "add_window() failed.\n"); endwin(); exit(1); diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 613fa3b3..37f3e9da 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h @@ -46,5 +46,8 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l void init_window_status(); ToxWindow * init_windows(); void draw_active_window(Messenger * m); +int add_window(Messenger *m, ToxWindow w, int n); +void del_window(ToxWindow *w, int f_num); +void set_active_window(int ch); #endif From 4ddd91b580edc78755531b86955c8eb828ff2ad0 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 08:56:29 -0400 Subject: [PATCH 11/27] Fixed small compile error on my end. --- testing/toxic/main.c | 3 --- testing/toxic/windows.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index d7b251dc..063c1483 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -24,9 +24,6 @@ #include "prompt.h" #include "friendlist.h" -#ifndef TOXICVER -#define TOXICVER "NOVER" //Use the -D flag to set this -#endif static void init_term() { diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 37f3e9da..7d81e814 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h @@ -19,6 +19,10 @@ /* maximum window slots for WINDOW_STATUS array */ #define MAX_WINDOW_SLOTS N_DEFAULT_WINS+MAX_FRIENDS_NUM +#ifndef TOXICVER +#define TOXICVER "NOVER" //Use the -D flag to set this +#endif + typedef struct ToxWindow_ ToxWindow; struct ToxWindow_ { From 0b27a0cb355a15fddbce639e66d5af2c2106526a Mon Sep 17 00:00:00 2001 From: slvr Date: Wed, 14 Aug 2013 14:26:04 +0100 Subject: [PATCH 12/27] Incorrect constants: s/BOXZERO/ZERO/ --- core/net_crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/net_crypto.c b/core/net_crypto.c index 07c43c40..0d8ad4c7 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -81,7 +81,7 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, if (length + crypto_box_MACBYTES > MAX_DATA_SIZE || length == 0) return -1; - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0}; + uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES] = {0}; uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES]; memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); /* pad the message with 32 0 bytes. */ @@ -114,7 +114,7 @@ int encrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, if (length + crypto_box_MACBYTES > MAX_DATA_SIZE || length == 0) return -1; - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0}; + uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES] = {0}; uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES]; memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); /* pad the message with 32 0 bytes. */ From ee34b51c24acfcee7c155b3b056a16dded8a27bc Mon Sep 17 00:00:00 2001 From: slvr Date: Wed, 14 Aug 2013 14:29:39 +0100 Subject: [PATCH 13/27] s/BOXZERO/ZERO/ --- core/net_crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/net_crypto.c b/core/net_crypto.c index 0d8ad4c7..fd606335 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -139,7 +139,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, if (length > MAX_DATA_SIZE || length <= crypto_box_BOXZEROBYTES) return -1; - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES]; + uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES]; uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0}; memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); /* pad the message with 16 0 bytes. */ @@ -165,7 +165,7 @@ int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, if (length > MAX_DATA_SIZE || length <= crypto_box_BOXZEROBYTES) return -1; - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES]; + uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES]; uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0}; memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); /* pad the message with 16 0 bytes. */ From a854a730ecd3b92426914d9bc30713ade92d5727 Mon Sep 17 00:00:00 2001 From: slvr Date: Wed, 14 Aug 2013 14:46:29 +0100 Subject: [PATCH 14/27] Reduced redundant code, added new crypto test --- auto_tests/crypto_test.c | 38 +++++++++++++++++++++ core/net_crypto.c | 72 +++++++++------------------------------- 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 9ac81349..8b5397e4 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -197,6 +197,43 @@ START_TEST(test_endtoend) } END_TEST +START_TEST(test_large_data) +{ + unsigned char k[crypto_box_BEFORENMBYTES]; + + unsigned char n[crypto_box_NONCEBYTES]; + + unsigned char m1[MAX_DATA_SIZE - ENCRYPTION_PADDING]; + unsigned char c1[sizeof(m1) + ENCRYPTION_PADDING]; + unsigned char m1prime[sizeof(m1)]; + + unsigned char m2[MAX_DATA_SIZE]; + unsigned char c2[sizeof(m2) + ENCRYPTION_PADDING]; + + int c1len, c2len; + int m1plen; + + //Generate random messages + rand_bytes(m1, sizeof(m1)); + rand_bytes(m2, sizeof(m2)); + rand_bytes(n, crypto_box_NONCEBYTES); + + //Generate key + rand_bytes(k, crypto_box_BEFORENMBYTES); + + c1len = encrypt_data_fast(k, n, m1, sizeof(m1), c1); + c2len = encrypt_data_fast(k, n, m2, sizeof(m2), c2); + + ck_assert_msg(c1len == sizeof(m1) + ENCRYPTION_PADDING, "Could not encrypt max size"); + ck_assert_msg(c2len == -1, "incorrectly succeeded encrypting massive size"); + + m1plen = decrypt_data_fast(k, n, c1, c1len, m1prime); + + ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ"); + ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ"); +} +END_TEST + #define DEFTESTCASE(NAME) \ TCase *NAME = tcase_create(#NAME); \ tcase_add_test(NAME, test_##NAME); \ @@ -209,6 +246,7 @@ Suite* crypto_suite(void) DEFTESTCASE(known); DEFTESTCASE(fast_known); DEFTESTCASE(endtoend); + DEFTESTCASE(large_data); return s; } diff --git a/core/net_crypto.c b/core/net_crypto.c index fd606335..ab18dd63 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -71,33 +71,6 @@ uint8_t crypto_iszero(uint8_t *mem, uint32_t length) return check; // We return zero if mem is made out of zeroes. } -/* encrypts plain of length length to encrypted of length + 16 using the - public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce - return -1 if there was a problem. - return length of encrypted data if everything was fine. */ -int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, - uint8_t *plain, uint32_t length, uint8_t *encrypted) -{ - if (length + crypto_box_MACBYTES > MAX_DATA_SIZE || length == 0) - return -1; - - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES] = {0}; - uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES]; - - memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); /* pad the message with 32 0 bytes. */ - - crypto_box(temp_encrypted, temp_plain, length + crypto_box_ZEROBYTES, nonce, public_key, secret_key); - - /* if encryption is successful the first crypto_box_BOXZEROBYTES of the message will be zero - apparently memcmp should not be used so we do this instead:*/ - if(crypto_iszero(temp_encrypted, crypto_box_BOXZEROBYTES) != 0) - return -1; - - /* unpad the encrypted message */ - memcpy(encrypted, temp_encrypted + crypto_box_BOXZEROBYTES, length + crypto_box_MACBYTES); - return length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES; -} - /* Precomputes the shared key from their public_key and our secret_key. This way we can avoid an expensive elliptic curve scalar multiply for each encrypt/decrypt operation. @@ -129,35 +102,6 @@ int encrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, return length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES; } -/* decrypts encrypted of length length to plain of length length - 16 using the - public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce - return -1 if there was a problem(decryption failed) - return length of plain data if everything was fine. */ -int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, - uint8_t *encrypted, uint32_t length, uint8_t *plain) -{ - if (length > MAX_DATA_SIZE || length <= crypto_box_BOXZEROBYTES) - return -1; - - uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES]; - uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0}; - - memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); /* pad the message with 16 0 bytes. */ - - if (crypto_box_open(temp_plain, temp_encrypted, length + crypto_box_BOXZEROBYTES, - nonce, public_key, secret_key) == -1) - return -1; - - /* if decryption is successful the first crypto_box_ZEROBYTES of the message will be zero - apparently memcmp should not be used so we do this instead:*/ - if(crypto_iszero(temp_plain, crypto_box_ZEROBYTES) != 0) - return -1; - - /* unpad the plain message */ - memcpy(plain, temp_plain + crypto_box_ZEROBYTES, length - crypto_box_MACBYTES); - return length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES; -} - /* Fast decrypt. Depends on enc_ley from encrypt_precompute. */ int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, uint8_t *encrypted, uint32_t length, uint8_t *plain) @@ -184,6 +128,22 @@ int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, return length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES; } +int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, + uint8_t *plain, uint32_t length, uint8_t *encrypted) +{ + uint8_t k[crypto_box_BEFORENMBYTES]; + encrypt_precompute(public_key, secret_key, k); + return encrypt_data_fast(k, nonce, plain, length, encrypted); +} + +int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, + uint8_t *encrypted, uint32_t length, uint8_t *plain) +{ + uint8_t k[crypto_box_BEFORENMBYTES]; + encrypt_precompute(public_key, secret_key, k); + return decrypt_data_fast(k, nonce, encrypted, length, plain); +} + /* increment the given nonce by 1 */ static void increment_nonce(uint8_t *nonce) { From 8eb8fb2ab5f703388be8987fd6b2cdf9dbc567e9 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 09:52:03 -0400 Subject: [PATCH 15/27] Messenger fix from pr #461. --- core/Messenger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Messenger.c b/core/Messenger.c index e2d83ada..690a81b1 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -746,7 +746,7 @@ void doMessenger(Messenger *m) /* returns the size of the messenger data (for saving) */ uint32_t Messenger_size(Messenger *m) { - return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) + sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * m->numfriends; } From 5909a13ba417733d14c3f88b79f7ec60faa8cbbf Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 10:26:02 -0400 Subject: [PATCH 16/27] Add friend now fails if it already is in DHT. --- core/DHT.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/DHT.c b/core/DHT.c index d359076d..5eae147c 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -633,6 +633,8 @@ static int handle_sendnodes(IP_Port source, uint8_t * packet, uint32_t length) int DHT_addfriend(uint8_t * client_id) { + if(friend_number(client_id) != -1) /*Is friend already in DHT?*/ + return 1; Friend * temp; temp = realloc(friends_list, sizeof(Friend) * (num_friends + 1)); if (temp == NULL) From 2196fb8bc8117af1536db43cba5823f355077da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Arg=C3=BCelles?= Date: Wed, 14 Aug 2013 10:40:26 -0500 Subject: [PATCH 17/27] Fix segfault when using -f in toxic Call strdup() to the data file argument string to avoid segmentation fault when it is later freed. --- testing/toxic/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 063c1483..ec33c72f 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) else if (argv[i][0] == '-') { if (argv[i][1] == 'f') { if (argv[i + 1] != NULL) - DATA_FILE = argv[i + 1]; + DATA_FILE = strdup(argv[i + 1]); else f_flag = -1; } else if (argv[i][1] == 'n') { From 566295037f1b742c872d3750ee73a92504bdcb6b Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 12:35:55 -0400 Subject: [PATCH 18/27] Added logo in readme to repo. --- other/tox.png | Bin 0 -> 17922 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 other/tox.png diff --git a/other/tox.png b/other/tox.png new file mode 100644 index 0000000000000000000000000000000000000000..e3d6869614de9ba60eedf7009ef0e934342e41b8 GIT binary patch literal 17922 zcmajH2|Seh+Xp3WeIP zeg3Qg3bpYP3bmeR^Ln`AR;z9S|61o}prww=tlu*Z|FOwNN9!z#jr{L@X>vGR+2VTs ziW>^GRRH<_I#g85UvQDzU0YX^yN8=cV9(aZqo@uPY9C7b>=`5P&Z!=pktGc;5zsj@ z75?Jg^#DI%Bb-}(V0?RV*G4=0@DCb`!R+-Z-MbQ2$?R>Q)&E0T>0V{BeuNPigS%m<`;G*dY=M8PwQ$3qXYv27`hS06?dt#eg|)~0?>GF9$DGg0KeFz2p4rjgEiEyst4#6I`GiO;>(_&= zBC;%6$4a3GE6ClMj$sVQ!5xE8-%!LNhY+Hk>skJn2@l2ORmu$dBS7xlL@+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O^U75w&_6@|fo%bH#Ml_Y zxff(lM~mWeXc7dA_dvz&nwuHRQskvxn} ziQ7PEw2giH2AXxX@08MdJ2ci>I#_ulkPgHH*7)Yl^l2OaJMo>nS1}8N;_Or1zd*tR zOfns;#@g@8B$c)VHaYlAS>222M;0CUNL=|&I^lH<|2`@jvj9~{_Z#hM0~}bZ41gG7BZxZS0-PccY@BAkf?w6H`aW zm!&jR%d>MrL!pbYB*&VUyBAQP)M&I)Mk}LqdQH2)DeYq&cif$vII>Ry>)Q)gN^<*w z;29QmiedSsZRp$i#i`<$pcHo6pK}H9mrSUVwKZ}baL&ab)dkJB*Q17GKt*i>QQ%T{ zp?xeK3U1`!1Ly@;R@tkxdG?J&x)-Bd88}YlZ>320w9NIRDSJ^mBT9bH-Abjx`FPX& zu}N?gIdXCmfnM2&VoxipWMJc#EqOU**0jCL?5?c)a1s@@!R9Kv@i%|>fo=*aFrgKY zU!cYdxQ_Y&I1F_aQ9z*50aT&P0NtTJLhe8XB6t0NJ~shS`+tA_1<_)l{?E@j5BRn@6Z4Dp#I0_|9^uP7UEahPqs|AJ_;j3X=`3Oo2h>F-v0x>Hx%Ij literal 0 HcmV?d00001 From 95664357d42d4d71a093d011124b0b1be7c1e380 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 12:38:10 -0400 Subject: [PATCH 19/27] Logo is now hosted on the repo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81836b4f..d4106910 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Project Tox](https://rbt.asia/boards/g/img/0352/79/1373823047559.png "Project Tox") +![Project Tox](https://raw.github.com/irungentoo/ProjectTox-Core/master/other/tox.png "Project Tox") Project Tox, _also known as Tox_, is a FOSS (Free and Open Source Software) instant messaging application aimed to replace Skype.
With the rise of governmental monitoring programs, Tox aims to be an easy to use, all-in-one communication platform (including audio, and videochats in the future) that ensures their users full privacy and secure message delivery.

From 1b2ac061ec37504adbe29d3d9a7b6d7ef3dbab9e Mon Sep 17 00:00:00 2001 From: naxuroqa Date: Wed, 14 Aug 2013 19:21:36 +0200 Subject: [PATCH 20/27] Fix for another segfault/leak case when using -f arg --- testing/toxic/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index ec33c72f..53639eb2 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -196,17 +196,8 @@ static void load_data(Messenger *m, char *path) int main(int argc, char *argv[]) { char *user_config_dir = get_user_config_dir(); - char *DATA_FILE; - int config_err = create_user_config_dir(user_config_dir); - if(config_err) { - DATA_FILE = "data"; - } else { - DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); - strcpy(DATA_FILE, user_config_dir); - strcat(DATA_FILE, CONFIGDIR); - strcat(DATA_FILE, "data"); - } - free(user_config_dir); + char *DATA_FILE = NULL; + int config_err = 0; /* This is broken */ int f_loadfromfile = 1; @@ -227,6 +218,19 @@ int main(int argc, char *argv[]) } } + if (DATA_FILE == NULL ) { + config_err = create_user_config_dir(user_config_dir); + if (config_err) { + DATA_FILE = strdup("data"); + } else { + DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); + strcpy(DATA_FILE, user_config_dir); + strcat(DATA_FILE, CONFIGDIR); + strcat(DATA_FILE, "data"); + } + } + free(user_config_dir); + init_term(); Messenger *m = init_tox(); ToxWindow * prompt = init_windows(m); From aa114d2778f87180eaf946f2fd3113c53d2304bc Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 14 Aug 2013 16:02:21 -0400 Subject: [PATCH 21/27] small bug fixes --- testing/toxic/chat.c | 2 +- testing/toxic/main.c | 5 ++--- testing/toxic/prompt.c | 2 +- testing/toxic/windows.c | 5 +++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index e4da9484..d5edf956 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -314,7 +314,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); } - wprintw(ctx->history, "Your ID: %s\n", id); + wprintw(ctx->history, "%s\n", id); } else if (strcmp(ctx->line, "/close") == 0) { diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 53639eb2..d1a4be5d 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -45,7 +45,7 @@ static void init_term() refresh(); } -static Messenger * init_tox() +static Messenger *init_tox() { /* Init core */ Messenger *m = initMessenger(); @@ -199,7 +199,6 @@ int main(int argc, char *argv[]) char *DATA_FILE = NULL; int config_err = 0; - /* This is broken */ int f_loadfromfile = 1; int f_flag = 0; int i = 0; @@ -233,7 +232,7 @@ int main(int argc, char *argv[]) init_term(); Messenger *m = init_tox(); - ToxWindow * prompt = init_windows(m); + ToxWindow *prompt = init_windows(m); init_window_status(); if(f_loadfromfile) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index fb8a5090..b84773af 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -238,7 +238,7 @@ void cmd_myid(ToxWindow *self, Messenger *m, char **args) snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); } - wprintw(self->window, "Your ID: %s\n", id); + wprintw(self->window, "%s\n", id); } void cmd_nick(ToxWindow *self, Messenger *m, char **args) diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index d19392ac..aab46e99 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c @@ -159,7 +159,7 @@ void init_window_status() WINDOW_STATUS[j] = -1; } -ToxWindow * init_windows() +ToxWindow *init_windows() { w_num = 0; int n_prompt = 0; @@ -170,6 +170,7 @@ ToxWindow * init_windows() endwin(); exit(1); } + active_window = n_prompt; prompt = &windows[n_prompt]; return prompt; } @@ -217,7 +218,7 @@ void prepare_window(WINDOW *w) wresize(w, LINES-2, COLS); } -void draw_active_window(Messenger * m) +void draw_active_window(Messenger *m) { ToxWindow *a = &windows[active_window]; From 4330bfbf871e769cf1599825bfb09ba56293d6a0 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 14 Aug 2013 18:26:00 -0400 Subject: [PATCH 22/27] Metadata collection prevention part 1 of ???. Crypto requests packets are packets that can be routed by nodes in the DHT. In this pull request I have merged both Natping requests and friend requests into one common packet (Crypto request packets). Both these packets should now only be distinguishable by the size of the data in them to an outside observer for an example on how to send and recieve data with these packets see: friend_requests.c Note that these packets are prefixed with id 32 (friend request packets) which means this change is compatible with the currently running DHT bootstrap servers. Also changed small thing in DHT_test.c --- core/DHT.c | 55 ++++++++++++++---------------------------- core/friend_requests.c | 42 ++++++++++---------------------- core/net_crypto.c | 51 ++++++++++++++++++++++++++++++++++----- core/net_crypto.h | 10 ++++---- testing/DHT_test.c | 4 +-- 5 files changed, 83 insertions(+), 79 deletions(-) diff --git a/core/DHT.c b/core/DHT.c index 5eae147c..057ee9ce 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -932,49 +932,30 @@ static int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) } /* Handle a received ping request for */ -static int handle_NATping(IP_Port source, uint8_t * packet, uint32_t length) +static int handle_NATping(IP_Port source, uint8_t * source_pubkey, uint8_t * packet, uint32_t length) { - if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING - || length > MAX_DATA_SIZE + ENCRYPTION_PADDING) + uint64_t ping_id; + memcpy(&ping_id, packet + 1, sizeof(uint64_t)); + + int friendnumber = friend_number(source_pubkey); + if (friendnumber == -1) return 1; - /* check if request is for us. */ - if (id_equal(packet + 1, self_public_key)) { - uint8_t public_key[crypto_box_PUBLICKEYBYTES]; - uint8_t data[MAX_DATA_SIZE]; + Friend * friend = &friends_list[friendnumber]; - int len = handle_request(public_key, data, packet, length); - if (len != sizeof(uint64_t) + 1) - return 1; - - uint64_t ping_id; - memcpy(&ping_id, data + 1, sizeof(uint64_t)); - - int friendnumber = friend_number(public_key); - if (friendnumber == -1) - return 1; - - Friend * friend = &friends_list[friendnumber]; - - if (data[0] == 0) { - /* 1 is reply */ - send_NATping(public_key, ping_id, 1); - friend->recvNATping_timestamp = unix_time(); + if (packet[0] == 0) { + /* 1 is reply */ + send_NATping(source_pubkey, ping_id, 1); + friend->recvNATping_timestamp = unix_time(); + return 0; + } else if (packet[0] == 1) { + if (friend->NATping_id == ping_id) { + friend->NATping_id = ((uint64_t)random_int() << 32) + random_int(); + friend->hole_punching = 1; return 0; - } else if (data[0] == 1) { - if (friend->NATping_id == ping_id) { - friend->NATping_id = ((uint64_t)random_int() << 32) + random_int(); - friend->hole_punching = 1; - return 0; - } } - return 1; } - - /* if request is not for us, try routing it. */ - route_packet(packet + 1, packet, length); - - return 0; + return 1; } /* Get the most common ip in the ip_portlist @@ -1082,7 +1063,7 @@ void DHT_init(void) networking_registerhandler(1, &handle_ping_response); networking_registerhandler(2, &handle_getnodes); networking_registerhandler(3, &handle_sendnodes); - networking_registerhandler(254, &handle_NATping); + cryptopacket_registerhandler(254, &handle_NATping); } void doDHT(void) diff --git a/core/friend_requests.c b/core/friend_requests.c index 8276db29..ae19ebdd 100644 --- a/core/friend_requests.c +++ b/core/friend_requests.c @@ -123,39 +123,23 @@ static int request_received(uint8_t * client_id) } -static int friendreq_handlepacket(IP_Port source, uint8_t * packet, uint32_t length) +static int friendreq_handlepacket(IP_Port source, uint8_t * source_pubkey, uint8_t * packet, uint32_t length) { - if (packet[0] == 32) { - if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING || - length > MAX_DATA_SIZE + ENCRYPTION_PADDING) - return 1; - if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) {// check if request is for us. - if (handle_friendrequest_isset == 0) - return 1; + if (handle_friendrequest_isset == 0) + return 1; + if (length <= sizeof(nospam)) + return 1; + if (request_received(source_pubkey)) + return 1; + if (memcmp(packet, &nospam, sizeof(nospam)) != 0) + return 1; - uint8_t public_key[crypto_box_PUBLICKEYBYTES]; - uint8_t data[MAX_DATA_SIZE]; - int len = handle_request(public_key, data, packet, length); - if (len == -1) - return 1; - if (len <= sizeof(nospam)) - return 1; - if (request_received(public_key)) - return 1; - if (memcmp(data, &nospam, sizeof(nospam)) != 0) - return 1; - - addto_receivedlist(public_key); - (*handle_friendrequest)(public_key, data + 4, len - 4, handle_friendrequest_userdata); - } else { /* if request is not for us, try routing it. */ - if(route_packet(packet + 1, packet, length) == length) - return 0; - } - } - return 1; + addto_receivedlist(source_pubkey); + (*handle_friendrequest)(source_pubkey, packet + 4, length - 4, handle_friendrequest_userdata); + return 0; } void friendreq_init(void) { - networking_registerhandler(32, &friendreq_handlepacket); + cryptopacket_registerhandler(32, &friendreq_handlepacket); } diff --git a/core/net_crypto.c b/core/net_crypto.c index ab18dd63..376708ab 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -221,15 +221,18 @@ int write_cryptpacket(int crypt_connection_id, uint8_t *data, uint32_t length) returns the length of the created packet on success */ int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t length, uint8_t request_id) { - if (MAX_DATA_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING) + if (MAX_DATA_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING) return -1; uint8_t nonce[crypto_box_NONCEBYTES]; + uint8_t temp[MAX_DATA_SIZE]; + memcpy(temp + 1, data, length); + temp[0] = request_id; random_nonce(nonce); - int len = encrypt_data(public_key, self_secret_key, nonce, data, length, + int len = encrypt_data(public_key, self_secret_key, nonce, temp, length, 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet); if (len == -1) return -1; - packet[0] = request_id; + packet[0] = 32; memcpy(packet + 1, public_key, crypto_box_PUBLICKEYBYTES); memcpy(packet + 1 + crypto_box_PUBLICKEYBYTES, self_public_key, crypto_box_PUBLICKEYBYTES); memcpy(packet + 1 + crypto_box_PUBLICKEYBYTES * 2, nonce, crypto_box_NONCEBYTES); @@ -241,7 +244,7 @@ int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t in data if a friend or ping request was sent to us and returns the length of the data. packet is the request packet and length is its length return -1 if not valid request. */ -int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t length) +static int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *request_id, uint8_t *packet, uint16_t length) { if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING && @@ -249,16 +252,51 @@ int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); uint8_t nonce[crypto_box_NONCEBYTES]; + uint8_t temp[MAX_DATA_SIZE]; memcpy(nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2, crypto_box_NONCEBYTES); int len1 = decrypt_data(public_key, self_secret_key, nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, - length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), data); - if(len1 == -1) + length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp); + if(len1 == -1 || len1 == 0) return -1; + request_id[0] = temp[0]; + --len1; + memcpy(data, temp + 1, len1); return len1; } else return -1; } +static cryptopacket_handler_callback cryptopackethandlers[256] = {0}; + +void cryptopacket_registerhandler(uint8_t byte, cryptopacket_handler_callback cb) +{ + cryptopackethandlers[byte] = cb; +} + +static int cryptopacket_handle(IP_Port source, uint8_t * packet, uint32_t length) +{ + if (packet[0] == 32) { + if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING || + length > MAX_DATA_SIZE + ENCRYPTION_PADDING) + return 1; + if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) {// check if request is for us. + uint8_t public_key[crypto_box_PUBLICKEYBYTES]; + uint8_t data[MAX_DATA_SIZE]; + uint8_t number; + int len = handle_request(public_key, data, &number, packet, length); + if (len == -1 || len == 0) + return 1; + if (!cryptopackethandlers[number]) return 1; + cryptopackethandlers[number](source, public_key, data, len - 1); + + } else { /* if request is not for us, try routing it. */ + if(route_packet(packet + 1, packet, length) == length) + return 0; + } + } + return 1; +} + /* Send a crypto handshake packet containing an encrypted secret nonce and session public key to peer with connection_id and public_key the packet is encrypted with a random nonce which is sent in plain text with the packet */ @@ -579,6 +617,7 @@ void initNetCrypto(void) { memset(crypto_connections, 0 ,sizeof(crypto_connections)); memset(incoming_connections, -1 ,sizeof(incoming_connections)); + networking_registerhandler(32, &cryptopacket_handle); uint32_t i; for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) crypto_connections[i].number = ~0; diff --git a/core/net_crypto.h b/core/net_crypto.h index 135e099d..570b9373 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h @@ -25,6 +25,7 @@ #define NET_CRYPTO_H #include "Lossless_UDP.h" +#include "DHT.h" #ifdef __cplusplus extern "C" { @@ -88,11 +89,10 @@ int write_cryptpacket(int crypt_connection_id, uint8_t *data, uint32_t length); returns the length of the created packet on success */ int create_request(uint8_t *packet, uint8_t * public_key, uint8_t *data, uint32_t length, uint8_t request_id); -/* puts the senders public key in the request in public_key, the data from the request - in data if a friend or ping request was sent to us and returns the length of the data. - packet is the request packet and length is its length - return -1 if not valid request. */ -int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t length); + +typedef int (*cryptopacket_handler_callback)(IP_Port ip_port, uint8_t * source_pubkey, uint8_t *data, uint32_t len); +/* Function to call when request beginning with byte is received */ +void cryptopacket_registerhandler(uint8_t byte, cryptopacket_handler_callback cb); /* Start a secure connection with other peer who has public_key and ip_port returns -1 if failure diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 350093fd..c5b367cf 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -53,10 +53,10 @@ void print_clientlist() uint32_t i, j; IP_Port p_ip; printf("___________________CLOSE________________________________\n"); - for(i = 0; i < 4; i++) { + for(i = 0; i < 32; i++) { printf("ClientID: "); for(j = 0; j < 32; j++) { - printf("%hhX", close_clientlist[i].client_id[j]); + printf("%02hhX", close_clientlist[i].client_id[j]); } p_ip = close_clientlist[i].ip_port; printf("\nIP: %u.%u.%u.%u Port: %u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); From e9f15d3879724da62fb2cfb8d8dceb01f1286ff9 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 12:59:16 +1200 Subject: [PATCH 23/27] refresh windows after resize --- testing/toxic/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index d1a4be5d..aa025a1a 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #ifdef _win32 #include @@ -25,9 +26,17 @@ #include "friendlist.h" +void on_window_resize(int sig) +{ + endwin(); + refresh(); + clear(); +} + static void init_term() { /* Setup terminal */ + signal(SIGWINCH, on_window_resize); initscr(); cbreak(); keypad(stdscr, 1); From 93b34ef9e3b4ad44b9f387b112d168b2db55b8a3 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 14:55:57 +1200 Subject: [PATCH 24/27] move client data struct to header file --- core/DHT.c | 11 ----------- core/DHT.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/DHT.c b/core/DHT.c index 057ee9ce..cf0b396c 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -63,17 +63,6 @@ /*----------------------------------------------------------------------------------*/ -typedef struct { - uint8_t client_id[CLIENT_ID_SIZE]; - IP_Port ip_port; - uint64_t timestamp; - uint64_t last_pinged; - - /* Returned by this node. Either our friend or us */ - IP_Port ret_ip_port; - uint64_t ret_timestamp; -} Client_data; - typedef struct { uint8_t client_id[CLIENT_ID_SIZE]; Client_data client_list[MAX_FRIEND_CLIENTS]; diff --git a/core/DHT.h b/core/DHT.h index 0e05f132..bfbe8829 100644 --- a/core/DHT.h +++ b/core/DHT.h @@ -34,6 +34,17 @@ extern "C" { /* size of the client_id in bytes */ #define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES +typedef struct { + uint8_t client_id[CLIENT_ID_SIZE]; + IP_Port ip_port; + uint64_t timestamp; + uint64_t last_pinged; + + /* Returned by this node. Either our friend or us */ + IP_Port ret_ip_port; + uint64_t ret_timestamp; +} Client_data; + /* Add a new friend to the friends list client_id must be CLIENT_ID_SIZE bytes long. returns 0 if success From 6b38b704a4a36e183817323f61505130df6f1dea Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 14:45:56 +1200 Subject: [PATCH 25/27] provide access to the close client list --- core/DHT.c | 6 ++++++ core/DHT.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/core/DHT.c b/core/DHT.c index cf0b396c..1d13aa73 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -104,6 +104,12 @@ static Pinged send_nodes[LSEND_NODES_ARRAY]; /*----------------------------------------------------------------------------------*/ + +Client_data * DHT_get_close_list(void) +{ + return close_clientlist; +} + /* Compares client_id1 and client_id2 with client_id * return 0 if both are same distance * return 1 if client_id1 is closer diff --git a/core/DHT.h b/core/DHT.h index bfbe8829..00a43d76 100644 --- a/core/DHT.h +++ b/core/DHT.h @@ -45,6 +45,8 @@ typedef struct { uint64_t ret_timestamp; } Client_data; +Client_data * DHT_get_close_list(void); + /* Add a new friend to the friends list client_id must be CLIENT_ID_SIZE bytes long. returns 0 if success From 1e190c97b848ac14eeca26df114e26fd13fd5035 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 14:48:02 +1200 Subject: [PATCH 26/27] add dhtstatus file --- testing/toxic/CMakeLists.txt | 1 + testing/toxic/dhtstatus.c | 89 ++++++++++++++++++++++++++++++++++++ testing/toxic/dhtstatus.h | 8 ++++ 3 files changed, 98 insertions(+) create mode 100644 testing/toxic/dhtstatus.c create mode 100644 testing/toxic/dhtstatus.h diff --git a/testing/toxic/CMakeLists.txt b/testing/toxic/CMakeLists.txt index dd811b97..9ee7020e 100644 --- a/testing/toxic/CMakeLists.txt +++ b/testing/toxic/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(${exe_name} windows.c prompt.c friendlist.c + dhtstatus.c chat.c configdir.c) diff --git a/testing/toxic/dhtstatus.c b/testing/toxic/dhtstatus.c new file mode 100644 index 00000000..66268900 --- /dev/null +++ b/testing/toxic/dhtstatus.c @@ -0,0 +1,89 @@ +#include "dhtstatus.h" +#include "string.h" +#include "../../core/network.h" +#include "../../core/DHT.h" + +typedef uint8_t ipbuf[3*4+3+1]; +static int num_selected = 0; + +static void printip(ipbuf buf, IP ip) +{ + sprintf((char*)buf, "%u.%u.%u.%u", ip.c[0], ip.c[1], ip.c[2], ip.c[3]); +} + +static void dhtstatus_onKey(ToxWindow *self, Messenger *m, int key) +{ + switch(key) { + case KEY_UP: + case 'k': + if (--num_selected < 0) + num_selected = CLIENT_ID_SIZE-1; + break; + + case KEY_DOWN: + case 'j': + num_selected = (num_selected+1) % CLIENT_ID_SIZE; + break; + + case '\n': + break; + + default: + break; + } +} + +static void dhtstatus_onDraw(ToxWindow *self) +{ + Client_data * close_clientlist = DHT_get_close_list(); + curs_set(0); + werase(self->window); + + uint64_t now = unix_time(); + uint32_t i, j; + ipbuf ipbuf; + wprintw(self->window,"\n%llu ______________________ CLOSE LIST ________________________ ___ IP ADDR ___ _PRT_ LST PNG ____ SELF ____ _PRT_ LST\n\n", now); + for(i = 0; i < CLIENT_ID_SIZE; i++) { + Client_data * client = close_clientlist + i; + if (i == num_selected) wattron(self->window, COLOR_PAIR(3)); + wprintw(self->window,"[%02i] ", i); + uint16_t port = ntohs(client->ip_port.port); + if(port) { + for(j = 0; j < 32; j++) + wprintw(self->window, "%02hhx", client->client_id[j]); + + printip(ipbuf, client->ip_port.ip); + wprintw(self->window, " %15s %5u ", ipbuf, port); + wprintw(self->window, " %3llu ", now - client->timestamp); + wprintw(self->window, " %3llu ", now - client->last_pinged); + + port = ntohs(client->ret_ip_port.port); + if(port) { + printip(ipbuf, client->ret_ip_port.ip); + wprintw(self->window, " %15s %5u %3llu", ipbuf, port, now - close_clientlist[i].ret_timestamp); + } + } + wprintw(self->window, "\n"); + if (i == num_selected) wattroff(self->window, COLOR_PAIR(3)); + } + + wrefresh(self->window); +} + +static void dhtstatus_onInit(ToxWindow *self, Messenger *m) +{ + +} + +ToxWindow new_dhtstatus() +{ + ToxWindow ret; + memset(&ret, 0, sizeof(ret)); + + ret.onKey = &dhtstatus_onKey; + ret.onDraw = &dhtstatus_onDraw; + ret.onInit = &dhtstatus_onInit; + + strcpy(ret.title, "[dht status]"); + return ret; +} diff --git a/testing/toxic/dhtstatus.h b/testing/toxic/dhtstatus.h new file mode 100644 index 00000000..2b30e5a3 --- /dev/null +++ b/testing/toxic/dhtstatus.h @@ -0,0 +1,8 @@ +#ifndef _dhtstatus_h +#define _dhtstatus_h + +#include "windows.h" + +ToxWindow new_dhtstatus(); + +#endif From bf6c04b2cafe0a132aa54c6134217a0f4369a054 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 11 Aug 2013 14:49:41 +1200 Subject: [PATCH 27/27] add dhtstatus window --- testing/toxic/windows.c | 5 ++++- testing/toxic/windows.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index aab46e99..6de50741 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c @@ -1,5 +1,6 @@ #include "friendlist.h" #include "prompt.h" +#include "dhtstatus.h" #include "windows.h" /* Holds status of chat windows */ @@ -164,8 +165,10 @@ ToxWindow *init_windows() w_num = 0; int n_prompt = 0; int n_friendslist = 1; + int n_dhtstatus = 2; if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 - || add_window(m, new_friendlist(WINDOW_STATUS), n_friendslist) == -1) { + || add_window(m, new_friendlist(WINDOW_STATUS), n_friendslist) == -1 + || add_window(m, new_dhtstatus(), n_dhtstatus) == -1) { fprintf(stderr, "add_window() failed.\n"); endwin(); exit(1); diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 7d81e814..893ccf6f 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h @@ -14,7 +14,7 @@ #define KEY_SIZE_BYTES 32 /* number of permanent default windows */ -#define N_DEFAULT_WINS 2 +#define N_DEFAULT_WINS 3 /* maximum window slots for WINDOW_STATUS array */ #define MAX_WINDOW_SLOTS N_DEFAULT_WINS+MAX_FRIENDS_NUM