From 14413c472460d6fadfeec98c00ca6d4c96817dc4 Mon Sep 17 00:00:00 2001 From: DarkSER Date: Tue, 6 Aug 2013 22:06:17 +0200 Subject: [PATCH 01/11] fixed print_statuschange & m_set_userstatus usage in nTox_win32.c --- testing/nTox_win32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index dbbd0f6e..2e6451f3 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) printf(msg); } -void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length) +void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); @@ -275,7 +275,7 @@ void change_status(int savetofile) } status[i-3] = 0; - m_set_userstatus(status, strlen((char*)status)); + m_set_userstatus(m_get_userstatus_kind(0), status, strlen((char*)status)); char numstring[100]; sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); printf(numstring); @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { sscanf(line, "%s", (char*)status); } - m_set_userstatus(status, strlen((char*)status)+1); + m_set_userstatus(m_get_userstatus_kind(0), status, strlen((char*)status)+1); statusloaded = 1; printf("%s\n", status); fclose(status_file); From b32a7b2294fff9f5ef0f5027e4e2ce1f01adc221 Mon Sep 17 00:00:00 2001 From: ptrasd Date: Wed, 7 Aug 2013 02:10:46 -0400 Subject: [PATCH 02/11] testing/toxic/prompt.c: changed execute() to skip whitespace at start of command --- testing/toxic/prompt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 89c87d8f..a96c07bb 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -52,6 +52,11 @@ static void execute(ToxWindow *self, char *u_cmd) cmd[i - newlines] = u_cmd[i]; } + int leading_spc = 0; + for (i = 0; i < 256 && isspace(cmd[i]); ++i) + leading_spc++; + memmove(cmd, cmd + leading_spc, 256 - leading_spc); + if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { endwin(); exit(0); From caa75b52c37b16aa00f1cb692cc533444c5d716d Mon Sep 17 00:00:00 2001 From: ptrasd Date: Wed, 7 Aug 2013 02:25:20 -0400 Subject: [PATCH 03/11] testing/toxic/prompt.c: changed execute() to ignore whitespace at end of commands --- testing/toxic/prompt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index a96c07bb..b0e21c64 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -57,6 +57,12 @@ static void execute(ToxWindow *self, char *u_cmd) leading_spc++; memmove(cmd, cmd + leading_spc, 256 - leading_spc); + int cmd_end = strlen(cmd); + while (cmd_end > 0 && cmd_end--) + if (!isspace(cmd[cmd_end])) + break; + cmd[cmd_end + 1] = '\0'; + if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { endwin(); exit(0); From 90524356a79d15353c91ad4125cd7f8d8e7a35d3 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 7 Aug 2013 02:34:55 -0400 Subject: [PATCH 04/11] Fixed two bugs --- core/Messenger.c | 6 +++--- testing/toxic/main.c | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index 5532c9cc..4e994a15 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -116,8 +116,8 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) return FAERR_ALREADYSENT; uint32_t i; - for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ - if(friendlist[i].status == NOFRIEND) { + for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ + if (friendlist[i].status == NOFRIEND) { DHT_addfriend(client_id); friendlist[i].status = FRIEND_ADDED; friendlist[i].crypt_connection_id = -1; @@ -141,7 +141,7 @@ int m_addfriend_norequest(uint8_t * client_id) if (getfriend_id(client_id) != -1) return -1; uint32_t i; - for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ + for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ if(friendlist[i].status == NOFRIEND) { DHT_addfriend(client_id); friendlist[i].status = FRIEND_REQUESTED; diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 1ba8b6c9..44430653 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -249,6 +249,7 @@ static void load_data(char *path) static void draw_bar() { static int odd = 0; + int blinkrate = 30; attron(COLOR_PAIR(4)); mvhline(LINES - 2, 0, '_', COLS); @@ -266,14 +267,13 @@ static void draw_bar() if (i == active_window) attron(A_BOLD); - odd = (odd+1) % 10; - if (windows[i].blink && (odd < 5)) { + 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 < 5)) { - attron(COLOR_PAIR(3)); + attroff(COLOR_PAIR(3)); } if (i == active_window) { attroff(A_BOLD); @@ -375,9 +375,8 @@ int main(int argc, char *argv[]) ch = getch(); if (ch == '\t' || ch == KEY_BTAB) set_active_window(ch); - else if (ch != ERR) { + else if (ch != ERR) a->onKey(a, ch); - } } return 0; } From 3f3be026b7b8cbf5eecaa7272c780c651698702e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 7 Aug 2013 02:52:56 -0400 Subject: [PATCH 05/11] forgot this --- 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 44430653..8de76244 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -272,7 +272,7 @@ static void draw_bar() attron(COLOR_PAIR(3)); } printw(" %s", windows[i].title); - if (windows[i].blink && (odd < 5)) { + if (windows[i].blink && (odd < (blinkrate/2))) { attroff(COLOR_PAIR(3)); } if (i == active_window) { From ba48234bfc864702b6464d3b148eafaf9ae32486 Mon Sep 17 00:00:00 2001 From: jin-eld Date: Wed, 7 Aug 2013 10:14:10 +0300 Subject: [PATCH 06/11] Allow to set a specific userstatus type in toxic Use: status , where type is one of online away busy offline The message parameter is optional. To set only the status message, as it was before, use: statusmsg --- testing/toxic/prompt.c | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 89c87d8f..6b110073 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -164,6 +164,54 @@ static void execute(ToxWindow *self, char *u_cmd) } else if (!strncmp(cmd, "status ", strlen("status "))) { + char *status = strchr(cmd, ' '); + char *msg; + char *status_text; + if (status == NULL) { + wprintw(self->window, "Invalid syntax.\n"); + return; + } + status++; + USERSTATUS_KIND status_kind; + if (!strncmp(status, "online", strlen("online"))) { + status_kind = USERSTATUS_KIND_ONLINE; + status_text = "ONLINE"; + } + + else if (!strncmp(status, "away", strlen("away"))) { + status_kind = USERSTATUS_KIND_AWAY; + status_text = "AWAY"; + } + + else if (!strncmp(status, "busy", strlen("busy"))) { + status_kind = USERSTATUS_KIND_BUSY; + status_text = "BUSY"; + } + + else if (!strncmp(status, "offline", strlen("offline"))) { + status_kind = USERSTATUS_KIND_OFFLINE; + status_text = "OFFLINE"; + } + + else + { + wprintw(self->window, "Invalid status.\n"); + return; + } + + msg = strchr(status, ' '); + if (msg == NULL) { + m_set_userstatus_kind(status_kind); + wprintw(self->window, "Status set to: %s\n", status_text); + } + else { + msg++; + m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1); + wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); + } + } + + else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) { char *msg = strchr(cmd, ' '); if (msg == NULL) { wprintw(self->window, "Invalid syntax.\n"); @@ -306,7 +354,8 @@ static void print_usage(ToxWindow *self) wprintw(self->window, " connect : Connect to DHT server\n"); wprintw(self->window, " add : Add friend\n"); - wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " statusmsg : Set your status\n"); wprintw(self->window, " nick : Set your nickname\n"); wprintw(self->window, " accept : Accept friend request\n"); wprintw(self->window, " myid : Print your ID\n"); From defabe8e0a7d501425149a8deca1ed95cf7ef032 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 7 Aug 2013 09:43:05 +0200 Subject: [PATCH 07/11] set USERSTATUS_KIND_RETAIN as default --- testing/nTox_win32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 2e6451f3..007305ad 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -275,7 +275,7 @@ void change_status(int savetofile) } status[i-3] = 0; - m_set_userstatus(m_get_userstatus_kind(0), status, strlen((char*)status)); + m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)); char numstring[100]; sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); printf(numstring); @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { sscanf(line, "%s", (char*)status); } - m_set_userstatus(m_get_userstatus_kind(0), status, strlen((char*)status)+1); + m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1); statusloaded = 1; printf("%s\n", status); fclose(status_file); From 6349ccc97b93abc1e0023c2af5b8f50c0491d7f9 Mon Sep 17 00:00:00 2001 From: Simon Levermann Date: Wed, 7 Aug 2013 13:13:04 +0200 Subject: [PATCH 08/11] Don't ignore the result of fwrite. Since we're building with -Wall and -Werror, this causes compile failures. --- testing/Messenger_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 0518d284..ad86184d 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) if ( file==NULL ){return 1;} uint8_t * buffer = malloc(Messenger_size()); Messenger_save(buffer); - fwrite(buffer, 1, Messenger_size(), file); + size_t write_result = fwrite(buffer, 1, Messenger_size(), file); free(buffer); fclose(file); } From 924219b1abf542eabc6740570436640382c82a39 Mon Sep 17 00:00:00 2001 From: Simon Levermann Date: Wed, 7 Aug 2013 13:23:12 +0200 Subject: [PATCH 09/11] Actually use write_result --- testing/Messenger_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index ad86184d..24a78abb 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -139,6 +139,7 @@ int main(int argc, char *argv[]) uint8_t * buffer = malloc(Messenger_size()); Messenger_save(buffer); size_t write_result = fwrite(buffer, 1, Messenger_size(), file); + if (write_result < Messenger_size()) {return 1;} free(buffer); fclose(file); } From a102fa7cb0cce2e29e428794cc2e9d8f8d1eb03b Mon Sep 17 00:00:00 2001 From: Robert Sutton Date: Wed, 7 Aug 2013 12:54:42 -0400 Subject: [PATCH 10/11] Add #undef before #define to fix redefinition warning --- testing/misc_tools.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/misc_tools.h b/testing/misc_tools.h index eb09693e..1abdb809 100644 --- a/testing/misc_tools.h +++ b/testing/misc_tools.h @@ -51,6 +51,7 @@ unsigned char * hex_string_to_bin(char hex_string[]); DEBUG_PRINT(__VA_ARGS__, ' '); \ } while (0) + #undef ERROR #define ERROR(exit_status, ...) do { \ fprintf(stderr, "error in "); \ DEBUG_PRINT(__VA_ARGS__, ' '); \ @@ -58,6 +59,7 @@ unsigned char * hex_string_to_bin(char hex_string[]); } while (0) #else #define WARNING(...) + #undef ERROR #define ERROR(...) #endif // DEBUG From 83112c588af46232af4be74ee69a133be199110b Mon Sep 17 00:00:00 2001 From: Robert Sutton Date: Wed, 7 Aug 2013 13:30:14 -0400 Subject: [PATCH 11/11] Fix incompatible pointer type warning by changing type of print_statuschange to match parameter of userstatus callback. --- testing/nTox_win32.c | 2 +- testing/nTox_win32.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 007305ad..e4489f13 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) printf(msg); } -void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) +void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 271403b8..36d5df1f 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h @@ -32,7 +32,7 @@ void do_header(); void print_message(int friendnumber, uint8_t * string, uint16_t length); void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); -void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); +void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length); void load_key(); void add_friend(); void list_friends(); @@ -44,4 +44,4 @@ void accept_friend_request(); void line_eval(char* line); void get_input(); -#endif \ No newline at end of file +#endif