From 94dab852758a9d5a85e8c3d9e0a89f2aa26fa1b7 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Wed, 7 Aug 2013 18:52:11 -0700 Subject: [PATCH 1/7] Adds full -D support to toxics versioning, includes the commit number --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f30d8e9..38f02dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 2.6.0) project(toxic C) +execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE COMMIT) +SET(GCC_COVERAGE_COMPILE_FLAGS '-DTOXICVER="0.1.1_r${COMMIT}"') +add_definitions(${GCC_COVERAGE_COMPILE_FLAGS}) set(exe_name toxic) add_executable(${exe_name} From 297ee1ecaaea0731d5954624aed4b4663f8934f6 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 8 Aug 2013 04:51:58 -0400 Subject: [PATCH 2/7] fix magic numbers --- chat.c | 6 +++--- main.c | 2 +- prompt.c | 24 ++++++++++++------------ windows.h | 4 +++- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/chat.c b/chat.c index 28c5de6..56dfb05 100644 --- a/chat.c +++ b/chat.c @@ -16,7 +16,7 @@ typedef struct { int friendnum; - char line[256]; + char line[MAX_STR_SIZE]; size_t pos; WINDOW* history; WINDOW* linewin; @@ -178,9 +178,9 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd) } else if (!strcmp(cmd, "/myid")) { - char id[32*2 + 1] = {0}; + char id[KEY_SIZE_BYTES*2+1] = {0}; int i; - for (i = 0; i < 32; i++) { + for (i = 0; i < KEY_SIZE_BYTES; i++) { char xx[3]; snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); strcat(id, xx); diff --git a/main.c b/main.c index b2310c8..d151955 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length) wprintw(prompt->window, "\nFriend request from:\n"); int i; - for (i = 0; i < 32; ++i) { + for (i = 0; i < KEY_SIZE_BYTES; ++i) { wprintw(prompt->window, "%02x", public_key[i] & 0xff); } diff --git a/prompt.c b/prompt.c index 661d881..08874a9 100644 --- a/prompt.c +++ b/prompt.c @@ -12,12 +12,12 @@ #include "windows.h" -uint8_t pending_requests[256][CLIENT_ID_SIZE]; // XXX +uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX uint8_t num_requests=0; // XXX extern void on_friendadded(int friendnumber); static void print_usage(ToxWindow *self); -static char prompt_buf[256] = {0}; +static char prompt_buf[MAX_STR_SIZE] = {0}; static int prompt_buf_pos = 0; // XXX: @@ -43,7 +43,7 @@ unsigned char *hex_string_to_bin(char hex_string[]) static void execute(ToxWindow *self, char *u_cmd) { int newlines = 0; - char cmd[256] = {0}; + char cmd[MAX_STR_SIZE] = {0}; int i; for (i = 0; i < strlen(prompt_buf); ++i) { if (u_cmd[i] == '\n') @@ -53,9 +53,9 @@ static void execute(ToxWindow *self, char *u_cmd) } int leading_spc = 0; - for (i = 0; i < 256 && isspace(cmd[i]); ++i) + for (i = 0; i < MAX_STR_SIZE && isspace(cmd[i]); ++i) leading_spc++; - memmove(cmd, cmd + leading_spc, 256 - leading_spc); + memmove(cmd, cmd + leading_spc, MAX_STR_SIZE - leading_spc); int cmd_end = strlen(cmd); while (cmd_end > 0 && cmd_end--) @@ -109,7 +109,7 @@ static void execute(ToxWindow *self, char *u_cmd) } dht.port = htons(atoi(port)); - uint32_t resolved_address = resolve_addr(ip); + uintKEY_SIZE_BYTES_t resolved_address = resolve_addr(ip); if (resolved_address == 0) { return; } @@ -121,9 +121,9 @@ static void execute(ToxWindow *self, char *u_cmd) } else if (!strncmp(cmd, "add ", strlen("add "))) { - uint8_t id_bin[32]; + uint8_t id_bin[KEY_SIZE_BYTES]; char xx[3]; - uint32_t x; + uintKEY_SIZE_BYTES_t x; char *id = strchr(cmd, ' '); if (id == NULL) { wprintw(self->window, "Invalid syntax.\n"); @@ -136,12 +136,12 @@ static void execute(ToxWindow *self, char *u_cmd) msg++; } else msg = ""; - if (strlen(id) != 2*32) { + if (strlen(id) != 2*KEY_SIZE_BYTES) { wprintw(self->window, "Invalid ID length.\n"); return; } int i; - for (i = 0; i < 32; ++i) { + for (i = 0; i < KEY_SIZE_BYTES; ++i) { xx[0] = id[2*i]; xx[1] = id[2*i+1]; xx[2] = '\0'; @@ -251,9 +251,9 @@ static void execute(ToxWindow *self, char *u_cmd) } else if (!strcmp(cmd, "myid")) { - char id[32*2 + 1] = {0}; + char id[KEY_SIZE_BYTES*2 + 1] = {0}; size_t i; - for (i = 0; i < 32; ++i) { + for (i = 0; i < KEY_SIZE_BYTES; ++i) { char xx[3]; snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); strcat(id, xx); diff --git a/windows.h b/windows.h index cb45614..287e534 100644 --- a/windows.h +++ b/windows.h @@ -5,7 +5,9 @@ #include #define TOXWINDOWS_MAX_NUM 32 #define MAX_FRIENDS_NUM 100 - +#define MAX_STR_SIZE 256 +#define KEY_SIZE_BYTES 32 + /* number of permanent default windows */ #define N_DEFAULT_WINS 2 From 757073a461d6a5a749a4c0194234152d592d627b Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 8 Aug 2013 04:55:22 -0400 Subject: [PATCH 3/7] oops --- prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prompt.c b/prompt.c index 08874a9..b50792f 100644 --- a/prompt.c +++ b/prompt.c @@ -109,7 +109,7 @@ static void execute(ToxWindow *self, char *u_cmd) } dht.port = htons(atoi(port)); - uintKEY_SIZE_BYTES_t resolved_address = resolve_addr(ip); + uint32_t resolved_address = resolve_addr(ip); if (resolved_address == 0) { return; } @@ -123,7 +123,7 @@ static void execute(ToxWindow *self, char *u_cmd) else if (!strncmp(cmd, "add ", strlen("add "))) { uint8_t id_bin[KEY_SIZE_BYTES]; char xx[3]; - uintKEY_SIZE_BYTES_t x; + uint32_t x; char *id = strchr(cmd, ' '); if (id == NULL) { wprintw(self->window, "Invalid syntax.\n"); From 4cf43ae0974e5fcc18447d936f5e02dd97977e05 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Thu, 8 Aug 2013 03:04:36 -0700 Subject: [PATCH 4/7] Merged upstream main.c changes --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 27e3d85..777ed80 100644 --- a/main.c +++ b/main.c @@ -22,7 +22,7 @@ extern int add_req(uint8_t *public_key); // XXX /* Holds status of chat windows */ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; -#define TOXICVER "0.1.0" //Will be moved to a -D flag later +//#define TOXICVER "0.1.0" //Will be moved to a -D flag later static ToxWindow windows[MAX_WINDOW_SLOTS]; static ToxWindow* prompt; @@ -69,7 +69,7 @@ void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) } } -void on_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length) +void on_statuschange(int friendnumber, uint8_t *string, uint16_t length) { wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); int i; @@ -113,7 +113,7 @@ static void init_tox() m_callback_friendrequest(on_request); m_callback_friendmessage(on_message); m_callback_namechange(on_nickchange); - m_callback_userstatus(on_statuschange); + m_callback_statusmessage(on_statuschange); } void init_window_status() From 6a37d6e9f1e7bf40a3309a20b209d0629bb58db5 Mon Sep 17 00:00:00 2001 From: Nominate Date: Thu, 8 Aug 2013 11:09:46 +0100 Subject: [PATCH 5/7] Removed superfluous statusmsg Users can just respecify their status with a message. This will also encourage users to think about which status is actually appropriate instead of just leaving the status alone. --- prompt.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/prompt.c b/prompt.c index 661d881..b3d6d22 100644 --- a/prompt.c +++ b/prompt.c @@ -228,17 +228,6 @@ static void execute(ToxWindow *self, char *u_cmd) } } - else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) { - char *msg = strchr(cmd, ' '); - if (msg == NULL) { - wprintw(self->window, "Invalid syntax.\n"); - return; - } - msg++; - m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); - wprintw(self->window, "Status set to: %s\n", msg); - } - else if (!strncmp(cmd, "nick ", strlen("nick "))) { char *nick = strchr(cmd, ' '); if (nick == NULL) { @@ -372,7 +361,6 @@ 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, " 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 d6468d7d0cc9b4c3cb424e3986cc9275e7d007ff Mon Sep 17 00:00:00 2001 From: Nominate Date: Thu, 8 Aug 2013 11:22:48 +0100 Subject: [PATCH 6/7] Updated chat.c to bring /status inline with prompt.c status command --- chat.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/chat.c b/chat.c index 28c5de6..669fd14 100644 --- a/chat.c +++ b/chat.c @@ -154,15 +154,47 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd) } else if (!strncmp(cmd, "/status ", strlen("/status "))) { + char *status = strchr(cmd, ' '); char *msg; - msg = strchr(cmd, ' '); - if (msg == NULL) { + char *status_text; + if (status == NULL) { wprintw(ctx->history, "Invalid syntax.\n"); return; } - msg++; - m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); - wprintw(ctx->history, "Status set to: %s\n", msg); + status++; + USERSTATUS status_kind; + if (!strncmp(status, "online", strlen("online"))) { + status_kind = USERSTATUS_NONE; + status_text = "ONLINE"; + } + + else if (!strncmp(status, "away", strlen("away"))) { + status_kind = USERSTATUS_AWAY; + status_text = "AWAY"; + } + + else if (!strncmp(status, "busy", strlen("busy"))) { + status_kind = USERSTATUS_BUSY; + status_text = "BUSY"; + } + + else + { + wprintw(ctx->history, "Invalid status.\n"); + return; + } + + msg = strchr(status, ' '); + if (msg == NULL) { + m_set_userstatus(status_kind); + wprintw(ctx->history, "Status set to: %s\n", status_text); + } + else { + msg++; + m_set_userstatus(status_kind); + m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); + wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); + } } else if (!strncmp(cmd, "/nick ", strlen("/nick "))) { @@ -231,7 +263,7 @@ void print_help(ChatContext *self) wprintw(self->history, "Commands:\n"); wattroff(self->history, A_BOLD); - wprintw(self->history, " /status : Set your status\n"); + wprintw(self->history, " /status : Set your status\n"); wprintw(self->history, " /nick : Set your nickname\n"); wprintw(self->history, " /myid : Print your ID\n"); wprintw(self->history, " /clear : Clear the screen\n"); From 0eff37e3d7cbfd5e8a55b5c0fbcebe6923283de3 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 8 Aug 2013 10:59:22 -0400 Subject: [PATCH 7/7] Moved a define and fixed another. --- main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index d457957..7fa9e96 100644 --- a/main.c +++ b/main.c @@ -22,7 +22,10 @@ extern int add_req(uint8_t *public_key); // XXX /* Holds status of chat windows */ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; -//#define TOXICVER "0.1.0" //Will be moved to a -D flag later + +#ifndef TOXICVER +#define TOXICVER "NOVER" //Use the -D flag to set this +#endif static ToxWindow windows[MAX_WINDOW_SLOTS]; static ToxWindow* prompt;