From a604de901702eabcdc73507025e77e34db6a9266 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 31 Jul 2013 21:44:57 -0400 Subject: fixed friend add bugs --- testing/toxic/prompt.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'testing') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index e18bdff0..6970441f 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -133,10 +133,26 @@ static void execute(ToxWindow* self, char* cmd) { } num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1); - - wprintw(self->window, "Friend added as %d.\n", num); - on_friendadded(num); + switch (num) { + case -1: + wprintw(self->window, "Message is too long.\n"); + break; + case -2: + wprintw(self->window, "That appears to be your own ID.\n"); + break; + case -3: + wprintw(self->window, "Friend request already sent.\n"); + break; + case -4: + wprintw(self->window, "Invalid ID.\n"); + break; + default: + wprintw(self->window, "Friend added as %d.\n", num); + on_friendadded(num); + break; + } } + else if(!strcmp(cmd, "help")) { wattron(self->window, COLOR_PAIR(2) | A_BOLD); wprintw(self->window, "Commands:\n"); -- cgit v1.2.3 From 8abc0a346209512901254f981dab62c67a632f4a Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 1 Aug 2013 15:27:08 -0400 Subject: added error code for no message on friend add & updated nTox.c/nTox_win32.c --- core/Messenger.c | 30 ++++++++++++++++++------------ testing/nTox.c | 34 +++++++++++++++++++--------------- testing/nTox_win32.c | 10 ++++++---- testing/toxic/prompt.c | 8 +++++--- 4 files changed, 48 insertions(+), 34 deletions(-) (limited to 'testing') diff --git a/core/Messenger.c b/core/Messenger.c index 49f638df..f8a794ce 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -94,25 +94,31 @@ int getclient_id(int friend_id, uint8_t *client_id) return -1; } -/* add a friend - set the data that will be sent along with friend request - client_id is the client id of the friend - data is the data and length is the length - returns the friend number if success - return -1 if message length is too long - return -2 if user's own key - return -3 if already a friend - return -4 for other*/ +/* + * add a friend + * set the data that will be sent along with friend request + * client_id is the client id of the friend + * data is the data and length is the length + * returns the friend number if success + * return -1 if message length is too long + * return -2 if no message (message length must be >= 1 byte) + * return -3 if user's own key + * return -4 if friend request already sent or already a friend + * return -5 for unknown error + */ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) { if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES)) return -1; - if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) + if (length < 1) return -2; - if (getfriend_id(client_id) != -1) + if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) return -3; + if (getfriend_id(client_id) != -1) + return -4; + uint32_t i; for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ if(friendlist[i].status == 0) { @@ -130,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) return i; } } - return -4; + return -5; } int m_addfriend_norequest(uint8_t * client_id) diff --git a/testing/nTox.c b/testing/nTox.c index 17f4b0e7..f7d929f2 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -106,24 +106,28 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) char temp_id[128]; for (i = 0; i < 128; i++) temp_id[i] = line[i+prompt_offset]; + int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); char numstring[100]; switch (num) { - case -1: - sprintf(numstring, "[i] Incorrect key length"); - break; - case -2: - sprintf(numstring, "[i] That appears to be your own key"); - break; - case -3: - sprintf(numstring, "[i] Friend request already sent"); - break; - case -4: - sprintf(numstring, "[i] Could not add friend"); - break; - default: - sprintf(numstring, "[i] Added friend %d", num); - break; + case -1: + sprintf(numstring, "[i] Message is too long."); + break; + case -2: + sprintf(numstring, "[i] Please add a message to your request."); + break; + case -3: + sprintf(numstring, "[i] That appears to be your own ID."); + break; + case -4: + sprintf(numstring, "[i] Friend request already sent."); + break; + case -5: + sprintf(numstring, "[i] Undefined error when adding friend."); + break; + default: + sprintf(numstring, "[i] Added friend as %d.", num); + break; } new_lines(numstring); do_refresh(); diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index b9208d4f..8d9f3547 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -132,13 +132,15 @@ void line_eval(char* line) printf(numstring); } else if (num == -1) - printf("\nWrong key size\n\n"); + printf("\n[i] Message is too long.\n\n"); else if (num == -2) - printf("\nYou can't add yourself\n\n"); + printf("\n[i] Please add a message to your friend request.\n\n"); else if (num == -3) - printf("\nYou already have this person added\n\n"); + printf("\n[i] That appears to be your own ID.\n\n"); else if (num == -4) - printf("\nUndefined error when adding friend"); + printf("\n[i] Friend request already sent.\n\n"); + else if (num == -5) + printf("\n[i] Undefined error when adding friend\n\n"); } else if (inpt_command == 'r') { diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 6970441f..21c1f52a 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -138,13 +138,15 @@ static void execute(ToxWindow* self, char* cmd) { wprintw(self->window, "Message is too long.\n"); break; case -2: + wprintw(self->window, "Please add a message to your request.\n"); + case -3: wprintw(self->window, "That appears to be your own ID.\n"); break; - case -3: + case -4: wprintw(self->window, "Friend request already sent.\n"); break; - case -4: - wprintw(self->window, "Invalid ID.\n"); + case -5: + wprintw(self->window, "[i] Undefined error when adding friend.\n"); break; default: wprintw(self->window, "Friend added as %d.\n", num); -- cgit v1.2.3 From 9fbff0c7589166c185c6885b0d67b2402228e8b6 Mon Sep 17 00:00:00 2001 From: plutooo Date: Thu, 1 Aug 2013 13:15:55 -0700 Subject: nTox: fixed 2 possible crashes, 3 incorrect packet lengths --- testing/nTox.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'testing') diff --git a/testing/nTox.c b/testing/nTox.c index f87a2a25..de75d2ff 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -133,6 +133,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) } else if (inpt_command == 'm') { //message command: /m friendnumber messsage size_t len = strlen(line); + if(len < 3) + return; + char numstring[len-3]; char message[len-3]; int i; @@ -141,13 +144,13 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) numstring[i] = line[i+3]; } else { int j; - for (j = (i+1); j < len; j++) + for (j = (i+1); j < (len+1); j++) message[j-i-1] = line[j+3]; break; } } int num = atoi(numstring); - if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { + if (m_sendmessage(num, (uint8_t*) message, strlen(message) + 1) != 1) { new_lines("[i] could not send message"); } else { new_lines(format_message(message, -1)); @@ -162,7 +165,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) name[i-3] = line[i]; } name[i-3] = 0; - setname(name, i); + setname(name, i - 2); char numstring[100]; sprintf(numstring, "[i] changed nick to %s", (char*)name); new_lines(numstring); @@ -179,7 +182,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) status[i-3] = line[i]; } status[i-3] = 0; - m_set_userstatus(status, strlen((char*)status)); + m_set_userstatus(status, strlen((char*)status) + 1); char numstring[100]; sprintf(numstring, "[i] changed status to %s", (char*)status); new_lines(numstring); -- cgit v1.2.3 From ff2e04b107587e69096e1523bcf66b2f45cafd7a Mon Sep 17 00:00:00 2001 From: Nick ODell Date: Thu, 1 Aug 2013 16:15:25 -0600 Subject: Fix bug where messages from yourself were preceeded by [-1] --- testing/nTox.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'testing') diff --git a/testing/nTox.c b/testing/nTox.c index f87a2a25..a2d8ade5 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -89,7 +89,12 @@ char *format_message(char *message, int friendnum) char* time = asctime(timeinfo); size_t len = strlen(time); time[len-1] = '\0'; - sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp + if (friendnum != -1) { + sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); + } else { + // This message came from ourselves + sprintf(msg, "%s <%s> %s", time, name, message); + } return msg; } -- cgit v1.2.3 From 67b7523b1876481fe4213ea301a7896e5af9fcb0 Mon Sep 17 00:00:00 2001 From: Nick ODell Date: Thu, 1 Aug 2013 16:19:01 -0600 Subject: Remove code that did nothing. --- testing/nTox.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'testing') diff --git a/testing/nTox.c b/testing/nTox.c index a2d8ade5..0020e80e 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -318,17 +318,6 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) void print_message(int friendnumber, uint8_t * string, uint16_t length) { - char name[MAX_NAME_LENGTH]; - getname(friendnumber, (uint8_t*)name); - char msg[100+length+strlen(name)+1]; - time_t rawtime; - struct tm * timeinfo; - time ( &rawtime ); - timeinfo = localtime ( &rawtime ); - char* temp = asctime(timeinfo); - size_t len = strlen(temp); - temp[len-1] = '\0'; - sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp new_lines(format_message((char*)string, friendnumber)); } -- cgit v1.2.3 From 7189f4c7b2f7753f4b373af9f1a9f20eef5fba54 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 2 Aug 2013 03:36:31 -0400 Subject: fixed cursor --- testing/toxic/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'testing') diff --git a/testing/toxic/main.c b/testing/toxic/main.c index cdc6dc16..c596b708 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -280,6 +280,26 @@ void prepare_window(WINDOW* w) { wresize(w, LINES-2, COLS); } +/* + * Draws cursor relative to input on prompt window. + * Removes cursor on friends window and chat windows. + * + * TODO: Make it work for chat windows + */ +void position_cursor(WINDOW* w, char* title) +{ + curs_set(1); + if (strcmp(title, "[prompt]") == 0) { // main/prompt window + int x, y; + getyx(w, y, x); + move(y, x); + } + else if (strcmp(title, "[friends]") == 0) // friends window + curs_set(0); + else // any other window (i.e chat) + curs_set(0); +} + int main(int argc, char* argv[]) { int ch; ToxWindow* a; @@ -299,6 +319,7 @@ int main(int argc, char* argv[]) { a->blink = false; a->onDraw(a); draw_bar(); + position_cursor(a->window, a->title); // Handle input. ch = getch(); -- cgit v1.2.3