From 6f98fc47b02d70c2e2eb50d4bdc942286950cda5 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 8 Aug 2013 04:51:58 -0400 Subject: fix magic numbers --- testing/toxic/prompt.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'testing/toxic/prompt.c') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 661d881f..08874a9a 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/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); -- cgit v1.2.3 From 0f2b4e5c7790f5f35a7ddefc532551c928bd3f2f Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 8 Aug 2013 04:55:22 -0400 Subject: oops --- testing/toxic/prompt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testing/toxic/prompt.c') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 08874a9a..b50792fe 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/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"); -- cgit v1.2.3 From d9750569ac1ff49442ea5158b99e78fd24ec9715 Mon Sep 17 00:00:00 2001 From: Nominate Date: Thu, 8 Aug 2013 11:09:46 +0100 Subject: 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. --- testing/toxic/prompt.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'testing/toxic/prompt.c') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 661d881f..b3d6d229 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/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"); -- cgit v1.2.3