summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/nTox.c6
-rw-r--r--testing/nTox_win32.c26
-rw-r--r--testing/toxic/chat.c6
-rw-r--r--testing/toxic/friendlist.c2
-rw-r--r--testing/toxic/main.c8
-rw-r--r--testing/toxic/prompt.c94
6 files changed, 82 insertions, 60 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index fe91b1fa..63d0c32e 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -228,7 +228,7 @@ void line_eval(char *line)
228 status[i-3] = line[i]; 228 status[i-3] = line[i];
229 } 229 }
230 status[i-3] = 0; 230 status[i-3] = 0;
231 m_set_userstatus(status, strlen((char*)status) + 1); 231 m_set_userstatus(USERSTATUS_KIND_ONLINE, status, strlen((char*)status) + 1);
232 char numstring[100]; 232 char numstring[100];
233 sprintf(numstring, "[i] changed status to %s", (char*)status); 233 sprintf(numstring, "[i] changed status to %s", (char*)status);
234 new_lines(numstring); 234 new_lines(numstring);
@@ -364,7 +364,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
364 } 364 }
365} 365}
366 366
367void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) 367void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length)
368{ 368{
369 char name[MAX_NAME_LENGTH]; 369 char name[MAX_NAME_LENGTH];
370 if(getname(friendnumber, (uint8_t*)name) != -1) { 370 if(getname(friendnumber, (uint8_t*)name) != -1) {
@@ -392,7 +392,7 @@ void load_key(char *path)
392 } 392 }
393 Messenger_load(data, size); 393 Messenger_load(data, size);
394 394
395 } else { 395 } else {
396 //else save new keys 396 //else save new keys
397 int size = Messenger_size(); 397 int size = Messenger_size();
398 uint8_t data[size]; 398 uint8_t data[size];
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index f3c7a188..dbbd0f6e 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -18,7 +18,7 @@
18 * 18 *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 * 21 *
22 */ 22 */
23 23
24#include "nTox_win32.h" 24#include "nTox_win32.h"
@@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
86 printf(msg); 86 printf(msg);
87} 87}
88 88
89void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) 89void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length)
90{ 90{
91 char name[MAX_NAME_LENGTH]; 91 char name[MAX_NAME_LENGTH];
92 getname(friendnumber, (uint8_t*)name); 92 getname(friendnumber, (uint8_t*)name);
@@ -95,7 +95,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
95 printf(msg); 95 printf(msg);
96} 96}
97 97
98void load_key() 98void load_key()
99{ 99{
100 FILE *data_file = NULL; 100 FILE *data_file = NULL;
101 data_file = fopen("data","r"); 101 data_file = fopen("data","r");
@@ -130,7 +130,7 @@ void add_friend()
130 int i; 130 int i;
131 char temp_id[128]; 131 char temp_id[128];
132 132
133 for (i = 0; i < 128; i++) 133 for (i = 0; i < 128; i++)
134 temp_id[i] = line[i+3]; 134 temp_id[i] = line[i+3];
135 135
136 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 136 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
@@ -141,7 +141,7 @@ void add_friend()
141 printf(numstring); 141 printf(numstring);
142 ++maxnumfriends; 142 ++maxnumfriends;
143 } 143 }
144 else if (num == -1) 144 else if (num == -1)
145 printf("\n[i] Message is too long.\n\n"); 145 printf("\n[i] Message is too long.\n\n");
146 146
147 else if (num == -2) 147 else if (num == -2)
@@ -180,7 +180,7 @@ void list_friends()
180 char name[MAX_NAME_LENGTH]; 180 char name[MAX_NAME_LENGTH];
181 getname(i, (uint8_t*)name); 181 getname(i, (uint8_t*)name);
182 182
183 if (m_friendstatus(i) == 4) 183 if (m_friendstatus(i) == 4)
184 printf("[%d] %s\n", i, (uint8_t*)name); 184 printf("[%d] %s\n", i, (uint8_t*)name);
185 } 185 }
186 186
@@ -213,7 +213,7 @@ void message_friend()
213 213
214 for (i = 0; i < len; i++) { 214 for (i = 0; i < len; i++) {
215 215
216 if (line[i+3] != ' ') 216 if (line[i+3] != ' ')
217 numstring[i] = line[i+3]; 217 numstring[i] = line[i+3];
218 218
219 else { 219 else {
@@ -243,7 +243,7 @@ void change_nickname()
243 243
244 for (i = 3; i < len; i++) { 244 for (i = 3; i < len; i++) {
245 245
246 if (line[i] == 0 || line[i] == '\n') 246 if (line[i] == 0 || line[i] == '\n')
247 break; 247 break;
248 248
249 name[i-3] = line[i]; 249 name[i-3] = line[i];
@@ -268,7 +268,7 @@ void change_status(int savetofile)
268 size_t len = strlen(line); 268 size_t len = strlen(line);
269 269
270 for (i = 3; i < len; i++) { 270 for (i = 3; i < len; i++) {
271 if (line[i] == 0 || line[i] == '\n') 271 if (line[i] == 0 || line[i] == '\n')
272 break; 272 break;
273 273
274 status[i-3] = line[i]; 274 status[i-3] = line[i];
@@ -350,7 +350,7 @@ void line_eval(char* line)
350 accept_friend_request(line); 350 accept_friend_request(line);
351 } 351 }
352 /* EXIT */ 352 /* EXIT */
353 else if (inpt_command == 'q') { 353 else if (inpt_command == 'q') {
354 strcpy(line, "---Offline"); 354 strcpy(line, "---Offline");
355 change_status(0); 355 change_status(0);
356 exit(EXIT_SUCCESS); 356 exit(EXIT_SUCCESS);
@@ -398,7 +398,7 @@ int main(int argc, char *argv[])
398 nameloaded = 1; 398 nameloaded = 1;
399 printf("%s\n", name); 399 printf("%s\n", name);
400 fclose(name_file); 400 fclose(name_file);
401 } 401 }
402 402
403 FILE* status_file = NULL; 403 FILE* status_file = NULL;
404 status_file = fopen("statusfile.txt", "r"); 404 status_file = fopen("statusfile.txt", "r");
@@ -424,7 +424,7 @@ int main(int argc, char *argv[])
424 { 424 {
425 if(self_public_key[i] < (PUB_KEY_BYTES/2)) 425 if(self_public_key[i] < (PUB_KEY_BYTES/2))
426 strcpy(idstring1[i],"0"); 426 strcpy(idstring1[i],"0");
427 else 427 else
428 strcpy(idstring1[i], ""); 428 strcpy(idstring1[i], "");
429 sprintf(idstring2[i], "%hhX",self_public_key[i]); 429 sprintf(idstring2[i], "%hhX",self_public_key[i]);
430 } 430 }
@@ -442,7 +442,7 @@ int main(int argc, char *argv[])
442 int resolved_address = resolve_addr(argv[1]); 442 int resolved_address = resolve_addr(argv[1]);
443 if (resolved_address != 0) 443 if (resolved_address != 0)
444 bootstrap_ip_port.ip.i = resolved_address; 444 bootstrap_ip_port.ip.i = resolved_address;
445 else 445 else
446 exit(1); 446 exit(1);
447 447
448 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 448 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 15d124bc..7262e722 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -34,7 +34,7 @@ void execute(ToxWindow* self, ChatContext* ctx, char* cmd);
34static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { 34static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) {
35 ChatContext* ctx = (ChatContext*) self->x; 35 ChatContext* ctx = (ChatContext*) self->x;
36 uint8_t nick[MAX_NAME_LENGTH] = {0}; 36 uint8_t nick[MAX_NAME_LENGTH] = {0};
37 37
38 time_t now; 38 time_t now;
39 time(&now); 39 time(&now);
40 struct tm * timeinfo; 40 struct tm * timeinfo;
@@ -60,6 +60,8 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
60 wprintw(ctx->history, "%s\n", msg); 60 wprintw(ctx->history, "%s\n", msg);
61 61
62 self->blink = true; 62 self->blink = true;
63 beep();
64 flash();
63} 65}
64 66
65static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t len) { 67static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t len) {
@@ -163,7 +165,7 @@ void execute(ToxWindow* self, ChatContext* ctx, char* cmd)
163 return; 165 return;
164 } 166 }
165 msg++; 167 msg++;
166 m_set_userstatus((uint8_t*) msg, strlen(msg)+1); 168 m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1);
167 wprintw(ctx->history, "Status set to: %s\n", msg); 169 wprintw(ctx->history, "Status set to: %s\n", msg);
168 } 170 }
169 else if (!strncmp(cmd, "/nick ", strlen("/nick "))) { 171 else if (!strncmp(cmd, "/nick ", strlen("/nick "))) {
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c
index a1f9851e..94e8fb47 100644
--- a/testing/toxic/friendlist.c
+++ b/testing/toxic/friendlist.c
@@ -138,7 +138,7 @@ static void friendlist_onDraw(ToxWindow* self) {
138 curs_set(0); 138 curs_set(0);
139 size_t i; 139 size_t i;
140 140
141 wclear(self->window); 141 werase(self->window);
142 142
143 if(num_friends == 0) { 143 if(num_friends == 0) {
144 wprintw(self->window, "Empty. Add some friends! :-)\n"); 144 wprintw(self->window, "Empty. Add some friends! :-)\n");
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 892f812a..19a0b959 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -68,10 +68,10 @@ void on_nickchange(int friendnumber, uint8_t* string, uint16_t length) {
68 } 68 }
69} 69}
70 70
71void on_statuschange(int friendnumber, uint8_t* string, uint16_t length) { 71void on_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t* string, uint16_t length) {
72 size_t i; 72 size_t i;
73 73
74 wprintw(prompt->window, "\n(statuschange) %d: %s!\n", friendnumber, string); 74 wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string);
75 75
76 for(i=0; i<MAX_WINDOW_SLOTS; i++) { 76 for(i=0; i<MAX_WINDOW_SLOTS; i++) {
77 if(windows[i].onStatusChange != NULL) 77 if(windows[i].onStatusChange != NULL)
@@ -216,7 +216,7 @@ static void load_data(char *path) {
216 216
217 Messenger_load(buf, len); 217 Messenger_load(buf, len);
218 } 218 }
219 else { 219 else {
220 len = Messenger_size(); 220 len = Messenger_size();
221 buf = malloc(len); 221 buf = malloc(len);
222 222
@@ -337,7 +337,7 @@ int main(int argc, char* argv[]) {
337 337
338 for(i = 0; i < argc; i++) { 338 for(i = 0; i < argc; i++) {
339 if (argv[i] == NULL){ 339 if (argv[i] == NULL){
340 break; 340 break;
341 } else if(argv[i][0] == '-') { 341 } else if(argv[i][0] == '-') {
342 if(argv[i][1] == 'f') { 342 if(argv[i][1] == 'f') {
343 if(argv[i + 1] != NULL) 343 if(argv[i + 1] != NULL)
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index f973afd7..20f6b480 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Toxic -- Tox Curses Client 2* Toxic -- Tox Curses Client
3 */ 3*/
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
@@ -41,7 +41,17 @@ unsigned char * hex_string_to_bin(char hex_string[])
41static char prompt_buf[256] = {0}; 41static char prompt_buf[256] = {0};
42static int prompt_buf_pos=0; 42static int prompt_buf_pos=0;
43 43
44static void execute(ToxWindow* self, char* cmd) { 44static void execute(ToxWindow* self, char* u_cmd) {
45 int i;
46 int newlines = 0;
47 char cmd[256] = {0};
48 for(i = 0; i < strlen(prompt_buf); i++)
49 {
50 if (u_cmd[i] == '\n')
51 ++newlines;
52 else
53 cmd[i - newlines] = u_cmd[i];
54 }
45 55
46 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { 56 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
47 endwin(); 57 endwin();
@@ -91,7 +101,7 @@ static void execute(ToxWindow* self, char* cmd) {
91 dht.ip.i = resolved_address; 101 dht.ip.i = resolved_address;
92 unsigned char *binary_string = hex_string_to_bin(key); 102 unsigned char *binary_string = hex_string_to_bin(key);
93 DHT_bootstrap(dht, binary_string); 103 DHT_bootstrap(dht, binary_string);
94 free(binary_string); 104 free(binary_string);
95 } 105 }
96 else if(!strncmp(cmd, "add ", strlen("add "))) { 106 else if(!strncmp(cmd, "add ", strlen("add "))) {
97 uint8_t id_bin[32]; 107 uint8_t id_bin[32];
@@ -137,7 +147,7 @@ static void execute(ToxWindow* self, char* cmd) {
137 147
138 num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1); 148 num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1);
139 switch (num) { 149 switch (num) {
140 case -1: 150 case -1:
141 wprintw(self->window, "Message is too long.\n"); 151 wprintw(self->window, "Message is too long.\n");
142 break; 152 break;
143 case -2: 153 case -2:
@@ -151,18 +161,19 @@ static void execute(ToxWindow* self, char* cmd) {
151 break; 161 break;
152 case -5: 162 case -5:
153 wprintw(self->window, "Undefined error when adding friend.\n"); 163 wprintw(self->window, "Undefined error when adding friend.\n");
154 break; 164 break;
155 default: 165 default:
156 wprintw(self->window, "Friend added as %d.\n", num); 166 wprintw(self->window, "Friend added as %d.\n", num);
157 on_friendadded(num); 167 on_friendadded(num);
158 break; 168 break;
159 } 169 }
160 } 170 }
161 else if (!strcmp(cmd, "clear")) { 171 else if(!strcmp(cmd, "clear")) {
162 wclear(self->window); 172 wclear(self->window);
163 } 173 }
164 else if(!strcmp(cmd, "help")) { 174 else if(!strcmp(cmd, "help")) {
165 print_usage(self); 175 wclear(self->window);
176 print_usage(self);
166 } 177 }
167 else if(!strncmp(cmd, "status ", strlen("status "))) { 178 else if(!strncmp(cmd, "status ", strlen("status "))) {
168 char* msg; 179 char* msg;
@@ -174,7 +185,7 @@ static void execute(ToxWindow* self, char* cmd) {
174 } 185 }
175 msg++; 186 msg++;
176 187
177 m_set_userstatus((uint8_t*) msg, strlen(msg)+1); 188 m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1);
178 wprintw(self->window, "Status set to: %s\n", msg); 189 wprintw(self->window, "Status set to: %s\n", msg);
179 } 190 }
180 else if(!strncmp(cmd, "nick ", strlen("nick "))) { 191 else if(!strncmp(cmd, "nick ", strlen("nick "))) {
@@ -196,7 +207,7 @@ static void execute(ToxWindow* self, char* cmd) {
196 207
197 for(i=0; i<32; i++) { 208 for(i=0; i<32; i++) {
198 char xx[3]; 209 char xx[3];
199 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 210 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
200 strcat(id, xx); 211 strcat(id, xx);
201 } 212 }
202 213
@@ -264,8 +275,16 @@ static void execute(ToxWindow* self, char* cmd) {
264static void prompt_onKey(ToxWindow* self, int key) { 275static void prompt_onKey(ToxWindow* self, int key) {
265 // PRINTABLE characters: Add to line. 276 // PRINTABLE characters: Add to line.
266 if(isprint(key)) { 277 if(isprint(key)) {
267 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { 278 if (prompt_buf_pos == (sizeof(prompt_buf) - 1)){
268 return; 279 wprintw(self->window, "\nToo Long.\n");
280 prompt_buf_pos = 0;
281 prompt_buf[0] = 0;
282 }
283 else if(!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS) && (prompt_buf_pos % (COLS - 3) == 0)) {
284 prompt_buf[prompt_buf_pos++] = '\n';
285 }
286 else if(!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS) && ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) {
287 prompt_buf[prompt_buf_pos++] = '\n';
269 } 288 }
270 prompt_buf[prompt_buf_pos++] = key; 289 prompt_buf[prompt_buf_pos++] = key;
271 prompt_buf[prompt_buf_pos] = 0; 290 prompt_buf[prompt_buf_pos] = 0;
@@ -288,20 +307,22 @@ static void prompt_onKey(ToxWindow* self, int key) {
288} 307}
289 308
290static void prompt_onDraw(ToxWindow* self) { 309static void prompt_onDraw(ToxWindow* self) {
291 curs_set(1); 310 curs_set(1);
292 int x, y; 311 int x, y;
293 312 getyx(self->window, y, x);
294 getyx(self->window, y, x); 313 (void) x;
295 (void) x; 314 int i;
296 315 for (i = 0; i < (strlen(prompt_buf)); i++)
297 wattron(self->window, COLOR_PAIR(1)); 316 {
298 mvwprintw(self->window, y, 0, "# "); 317 if ((prompt_buf[i] == '\n') && (y != 0))
299 wattroff(self->window, COLOR_PAIR(1)); 318 --y;
300 319 }
301 mvwprintw(self->window, y, 2, "%s", prompt_buf); 320 wattron(self->window, COLOR_PAIR(1));
302 wclrtoeol(self->window); 321 mvwprintw(self->window, y, 0, "# ");
303 322 wattroff(self->window, COLOR_PAIR(1));
304 wrefresh(self->window); 323 mvwprintw(self->window, y, 2, "%s", prompt_buf);
324 wclrtoeol(self->window);
325 wrefresh(self->window);
305} 326}
306 327
307static void print_usage(ToxWindow* self) { 328static void print_usage(ToxWindow* self) {
@@ -309,16 +330,15 @@ static void print_usage(ToxWindow* self) {
309 wprintw(self->window, "Commands:\n"); 330 wprintw(self->window, "Commands:\n");
310 wattroff(self->window, A_BOLD); 331 wattroff(self->window, A_BOLD);
311 332
312 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); 333 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
313 wprintw(self->window, " add <id> <message> : Add friend\n"); 334 wprintw(self->window, " add <id> <message> : Add friend\n");
314 wprintw(self->window, " status <message> : Set your status\n"); 335 wprintw(self->window, " status <message> : Set your status\n");
315 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 336 wprintw(self->window, " nick <nickname> : Set your nickname\n");
316 wprintw(self->window, " accept <number> : Accept friend request\n"); 337 wprintw(self->window, " accept <number> : Accept friend request\n");
317 wprintw(self->window, " myid : Print your ID\n"); 338 wprintw(self->window, " myid : Print your ID\n");
318 wprintw(self->window, " clear : Clear this window\n"); 339 wprintw(self->window, " quit/exit : Exit program\n");
319 wprintw(self->window, " quit/exit : Exit program\n"); 340 wprintw(self->window, " help : Print this message again\n");
320 wprintw(self->window, " help : Print this message again\n"); 341 wprintw(self->window, " clear : Clear this window\n");
321
322 342
323 wattron(self->window, A_BOLD); 343 wattron(self->window, A_BOLD);
324 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); 344 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");