summaryrefslogtreecommitdiff
path: root/testing/toxic/prompt.c
diff options
context:
space:
mode:
authorSimon Levermann <simon@levermaenner.de>2013-08-08 18:05:41 +0200
committerSimon Levermann <simon@levermaenner.de>2013-08-08 18:05:41 +0200
commitcaedd4489ef34e4afffbde9c4917439f3187f6ab (patch)
tree18719c3be8f9c0e21a6ae37a880f4351510ebc4b /testing/toxic/prompt.c
parentd7e2cca854cbc3d0f2418fd95f7033d6b352b587 (diff)
parentcd22973d48102a6b90dbcb46e58616f7decc1d59 (diff)
Merge branch 'master' of https://github.com/irungentoo/ProjectTox-Core into upstream
Diffstat (limited to 'testing/toxic/prompt.c')
-rw-r--r--testing/toxic/prompt.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 661d881f..eaa8d7bc 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -12,12 +12,12 @@
12 12
13#include "windows.h" 13#include "windows.h"
14 14
15uint8_t pending_requests[256][CLIENT_ID_SIZE]; // XXX 15uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
16uint8_t num_requests=0; // XXX 16uint8_t num_requests=0; // XXX
17 17
18extern void on_friendadded(int friendnumber); 18extern void on_friendadded(int friendnumber);
19static void print_usage(ToxWindow *self); 19static void print_usage(ToxWindow *self);
20static char prompt_buf[256] = {0}; 20static char prompt_buf[MAX_STR_SIZE] = {0};
21static int prompt_buf_pos = 0; 21static int prompt_buf_pos = 0;
22 22
23// XXX: 23// XXX:
@@ -43,7 +43,7 @@ unsigned char *hex_string_to_bin(char hex_string[])
43static void execute(ToxWindow *self, char *u_cmd) 43static void execute(ToxWindow *self, char *u_cmd)
44{ 44{
45 int newlines = 0; 45 int newlines = 0;
46 char cmd[256] = {0}; 46 char cmd[MAX_STR_SIZE] = {0};
47 int i; 47 int i;
48 for (i = 0; i < strlen(prompt_buf); ++i) { 48 for (i = 0; i < strlen(prompt_buf); ++i) {
49 if (u_cmd[i] == '\n') 49 if (u_cmd[i] == '\n')
@@ -53,9 +53,9 @@ static void execute(ToxWindow *self, char *u_cmd)
53 } 53 }
54 54
55 int leading_spc = 0; 55 int leading_spc = 0;
56 for (i = 0; i < 256 && isspace(cmd[i]); ++i) 56 for (i = 0; i < MAX_STR_SIZE && isspace(cmd[i]); ++i)
57 leading_spc++; 57 leading_spc++;
58 memmove(cmd, cmd + leading_spc, 256 - leading_spc); 58 memmove(cmd, cmd + leading_spc, MAX_STR_SIZE - leading_spc);
59 59
60 int cmd_end = strlen(cmd); 60 int cmd_end = strlen(cmd);
61 while (cmd_end > 0 && cmd_end--) 61 while (cmd_end > 0 && cmd_end--)
@@ -121,7 +121,7 @@ static void execute(ToxWindow *self, char *u_cmd)
121 } 121 }
122 122
123 else if (!strncmp(cmd, "add ", strlen("add "))) { 123 else if (!strncmp(cmd, "add ", strlen("add "))) {
124 uint8_t id_bin[32]; 124 uint8_t id_bin[KEY_SIZE_BYTES];
125 char xx[3]; 125 char xx[3];
126 uint32_t x; 126 uint32_t x;
127 char *id = strchr(cmd, ' '); 127 char *id = strchr(cmd, ' ');
@@ -136,12 +136,12 @@ static void execute(ToxWindow *self, char *u_cmd)
136 msg++; 136 msg++;
137 } 137 }
138 else msg = ""; 138 else msg = "";
139 if (strlen(id) != 2*32) { 139 if (strlen(id) != 2*KEY_SIZE_BYTES) {
140 wprintw(self->window, "Invalid ID length.\n"); 140 wprintw(self->window, "Invalid ID length.\n");
141 return; 141 return;
142 } 142 }
143 int i; 143 int i;
144 for (i = 0; i < 32; ++i) { 144 for (i = 0; i < KEY_SIZE_BYTES; ++i) {
145 xx[0] = id[2*i]; 145 xx[0] = id[2*i];
146 xx[1] = id[2*i+1]; 146 xx[1] = id[2*i+1];
147 xx[2] = '\0'; 147 xx[2] = '\0';
@@ -228,17 +228,6 @@ static void execute(ToxWindow *self, char *u_cmd)
228 } 228 }
229 } 229 }
230 230
231 else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) {
232 char *msg = strchr(cmd, ' ');
233 if (msg == NULL) {
234 wprintw(self->window, "Invalid syntax.\n");
235 return;
236 }
237 msg++;
238 m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
239 wprintw(self->window, "Status set to: %s\n", msg);
240 }
241
242 else if (!strncmp(cmd, "nick ", strlen("nick "))) { 231 else if (!strncmp(cmd, "nick ", strlen("nick "))) {
243 char *nick = strchr(cmd, ' '); 232 char *nick = strchr(cmd, ' ');
244 if (nick == NULL) { 233 if (nick == NULL) {
@@ -251,9 +240,9 @@ static void execute(ToxWindow *self, char *u_cmd)
251 } 240 }
252 241
253 else if (!strcmp(cmd, "myid")) { 242 else if (!strcmp(cmd, "myid")) {
254 char id[32*2 + 1] = {0}; 243 char id[KEY_SIZE_BYTES*2 + 1] = {0};
255 size_t i; 244 size_t i;
256 for (i = 0; i < 32; ++i) { 245 for (i = 0; i < KEY_SIZE_BYTES; ++i) {
257 char xx[3]; 246 char xx[3];
258 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 247 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
259 strcat(id, xx); 248 strcat(id, xx);
@@ -372,7 +361,6 @@ static void print_usage(ToxWindow *self)
372 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); 361 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
373 wprintw(self->window, " add <id> <message> : Add friend\n"); 362 wprintw(self->window, " add <id> <message> : Add friend\n");
374 wprintw(self->window, " status <type> <message> : Set your status\n"); 363 wprintw(self->window, " status <type> <message> : Set your status\n");
375 wprintw(self->window, " statusmsg <message> : Set your status\n");
376 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 364 wprintw(self->window, " nick <nickname> : Set your nickname\n");
377 wprintw(self->window, " accept <number> : Accept friend request\n"); 365 wprintw(self->window, " accept <number> : Accept friend request\n");
378 wprintw(self->window, " myid : Print your ID\n"); 366 wprintw(self->window, " myid : Print your ID\n");