summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL.md3
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/DHT.c2
-rw-r--r--core/DHT.h2
-rw-r--r--core/Lossless_UDP.c4
-rw-r--r--core/Lossless_UDP.h2
-rw-r--r--core/net_crypto.c2
-rw-r--r--testing/misc_tools.c1
-rw-r--r--testing/nTox.c8
-rw-r--r--testing/toxic/chat.c115
-rw-r--r--testing/toxic/main.c8
-rw-r--r--testing/toxic/prompt.c19
12 files changed, 130 insertions, 37 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 625a9c6d..483928b0 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -101,6 +101,7 @@ Grab the following packages:
101 * http://www.gnu.org/software/automake/ 101 * http://www.gnu.org/software/automake/
102 * http://www.cmake.org/ 102 * http://www.cmake.org/
103 * https://github.com/jedisct1/libsodium 103 * https://github.com/jedisct1/libsodium
104 * http://www.hyperrealm.com/libconfig/
104 105
105Uncompress and install them all. Make sure to follow the README as the instructions change, but they all follow the same pattern below: 106Uncompress and install them all. Make sure to follow the README as the instructions change, but they all follow the same pattern below:
106 107
@@ -118,7 +119,7 @@ make
118``` 119```
119 120
120Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory 121Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory
121and make your life more annoying. 122(or the wrong version gets installed) and make your life more annoying.
122 123
123Another thing you may want to install is the latest gcc, this caused me a few problems as XCode from 4.3 124Another thing you may want to install is the latest gcc, this caused me a few problems as XCode from 4.3
124no longer includes gcc and instead uses LLVM-GCC, a nice install guide can be found at 125no longer includes gcc and instead uses LLVM-GCC, a nice install guide can be found at
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 36acb6cf..5bd496cb 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -17,3 +17,4 @@ set(core_sources
17 Messenger.c) 17 Messenger.c)
18 18
19add_library(toxcore SHARED ${core_sources}) 19add_library(toxcore SHARED ${core_sources})
20target_link_libraries(toxcore ${SODIUM_LIBRARY})
diff --git a/core/DHT.c b/core/DHT.c
index 5d5910e0..08b4710e 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -1,6 +1,6 @@
1/* DHT.c 1/* DHT.c
2 * 2 *
3 * An implementation of the DHT as seen in docs/DHT.txt 3 * An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 * 6 *
diff --git a/core/DHT.h b/core/DHT.h
index ffa02087..36670ed5 100644
--- a/core/DHT.h
+++ b/core/DHT.h
@@ -1,6 +1,6 @@
1/* DHT.h 1/* DHT.h
2 * 2 *
3 * An implementation of the DHT as seen in docs/DHT.txt 3 * An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 * 6 *
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c
index 33b8eb19..a753e5ff 100644
--- a/core/Lossless_UDP.c
+++ b/core/Lossless_UDP.c
@@ -1,6 +1,6 @@
1/* Lossless_UDP.c 1/* Lossless_UDP.c
2 * 2 *
3 * An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt 3 * An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 * 6 *
@@ -467,7 +467,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
467/* 467/*
468 * BEGIN Packet sending functions 468 * BEGIN Packet sending functions
469 * One per packet type. 469 * One per packet type.
470 * see docs/Lossless_UDP.txt for more information. 470 * see http://wiki.tox.im/index.php/Lossless_UDP for more information.
471 */ 471 */
472 472
473int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) 473int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2)
diff --git a/core/Lossless_UDP.h b/core/Lossless_UDP.h
index 573e1ab9..75ef273e 100644
--- a/core/Lossless_UDP.h
+++ b/core/Lossless_UDP.h
@@ -1,6 +1,6 @@
1/* Lossless_UDP.h 1/* Lossless_UDP.h
2 * 2 *
3 * An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt 3 * An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 * 6 *
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 3b5b67f4..561ba866 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -1,7 +1,7 @@
1/* net_crypto.c 1/* net_crypto.c
2 * 2 *
3 * Functions for the core network crypto. 3 * Functions for the core network crypto.
4 * See also: docs/Crypto.txt 4 * See also: http://wiki.tox.im/index.php/DHT
5 * 5 *
6 * NOTE: This code has to be perfect. We don't mess around with encryption. 6 * NOTE: This code has to be perfect. We don't mess around with encryption.
7 * 7 *
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index dbaa8b3b..aa546a88 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -36,5 +36,6 @@ unsigned char * hex_string_to_bin(char hex_string[])
36 int i; 36 int i;
37 for(i = 0; i < len; ++i, pos+=2) 37 for(i = 0; i < len; ++i, pos+=2)
38 sscanf(pos,"%2hhx",&val[i]); 38 sscanf(pos,"%2hhx",&val[i]);
39
39 return val; 40 return val;
40} 41}
diff --git a/testing/nTox.c b/testing/nTox.c
index 4be69ac4..072c17e3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -142,7 +142,9 @@ void line_eval(char *line)
142 for (i = 0; i < 128; i++) 142 for (i = 0; i < 128; i++)
143 temp_id[i] = line[i+prompt_offset]; 143 temp_id[i] = line[i+prompt_offset];
144 144
145 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 145 unsigned char *bin_string = hex_string_to_bin(temp_id);
146 int num = m_addfriend(bin_string, (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
147 free(bin_string);
146 char numstring[100]; 148 char numstring[100];
147 switch (num) { 149 switch (num) {
148 case FAERR_TOOLONG: 150 case FAERR_TOOLONG:
@@ -466,7 +468,9 @@ int main(int argc, char *argv[])
466 else 468 else
467 exit(1); 469 exit(1);
468 470
469 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 471 unsigned char *binary_string = hex_string_to_bin(argv[3]);
472 DHT_bootstrap(bootstrap_ip_port, binary_string);
473 free(binary_string);
470 nodelay(stdscr, TRUE); 474 nodelay(stdscr, TRUE);
471 while(true) { 475 while(true) {
472 if (on == 0 && DHT_isconnected()) { 476 if (on == 0 && DHT_isconnected()) {
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 7cae1c0a..936eb868 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -26,6 +26,8 @@ typedef struct {
26} ChatContext; 26} ChatContext;
27 27
28extern void fix_name(uint8_t* name); 28extern void fix_name(uint8_t* name);
29void print_help(ChatContext* self);
30void execute(ToxWindow* self, ChatContext* ctx, char* cmd);
29 31
30static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { 32static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) {
31 ChatContext* ctx = (ChatContext*) self->x; 33 ChatContext* ctx = (ChatContext*) self->x;
@@ -49,6 +51,7 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
49 51
50 wattron(ctx->history, COLOR_PAIR(2)); 52 wattron(ctx->history, COLOR_PAIR(2));
51 wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); 53 wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
54 wattroff(ctx->history, COLOR_PAIR(2));
52 wattron(ctx->history, COLOR_PAIR(4)); 55 wattron(ctx->history, COLOR_PAIR(4));
53 wprintw(ctx->history, "%s: ", nick); 56 wprintw(ctx->history, "%s: ", nick);
54 wattroff(ctx->history, COLOR_PAIR(4)); 57 wattroff(ctx->history, COLOR_PAIR(4));
@@ -77,6 +80,18 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1
77 80
78} 81}
79 82
83/* check that the string has one non-space character */
84int string_is_empty(char *string)
85{
86 int rc = 0;
87 char *copy = strdup(string);
88
89 rc = ((strtok(copy, " ") == NULL) ? 1:0);
90 free(copy);
91
92 return rc;
93}
94
80static void chat_onKey(ToxWindow* self, int key) { 95static void chat_onKey(ToxWindow* self, int key) {
81 ChatContext* ctx = (ChatContext*) self->x; 96 ChatContext* ctx = (ChatContext*) self->x;
82 97
@@ -85,36 +100,93 @@ static void chat_onKey(ToxWindow* self, int key) {
85 struct tm * timeinfo; 100 struct tm * timeinfo;
86 timeinfo = localtime(&now); 101 timeinfo = localtime(&now);
87 102
103 /* PRINTABLE characters: Add to line */
88 if(isprint(key)) { 104 if(isprint(key)) {
89
90 if(ctx->pos != sizeof(ctx->line)-1) { 105 if(ctx->pos != sizeof(ctx->line)-1) {
91 ctx->line[ctx->pos++] = key; 106 ctx->line[ctx->pos++] = key;
92 ctx->line[ctx->pos] = '\0'; 107 ctx->line[ctx->pos] = '\0';
93 } 108 }
94 } 109 }
110
111 /* RETURN key: Execute command or print line */
95 else if(key == '\n') { 112 else if(key == '\n') {
96 wattron(ctx->history, COLOR_PAIR(2)); 113 if (ctx->line[0] == '/')
97 wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); 114 execute(self, ctx, ctx->line);
98 wattron(ctx->history, COLOR_PAIR(1)); 115 else {
99 wprintw(ctx->history, "you: ", ctx->line); 116 if(!string_is_empty(ctx->line)) {
100 wattroff(ctx->history, COLOR_PAIR(1)); 117 /* make sure the string has at least non-space character */
101 wprintw(ctx->history, "%s\n", ctx->line); 118 wattron(ctx->history, COLOR_PAIR(2));
102 119 wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
103 if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { 120 wattroff(ctx->history, COLOR_PAIR(2));
104 wattron(ctx->history, COLOR_PAIR(3)); 121 wattron(ctx->history, COLOR_PAIR(1));
105 wprintw(ctx->history, " * Failed to send message.\n"); 122 wprintw(ctx->history, "you: ", ctx->line);
106 wattroff(ctx->history, COLOR_PAIR(3)); 123 wattroff(ctx->history, COLOR_PAIR(1));
124 wprintw(ctx->history, "%s\n", ctx->line);
125 }
126 if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
127 wattron(ctx->history, COLOR_PAIR(3));
128 wprintw(ctx->history, " * Failed to send message.\n");
129 wattroff(ctx->history, COLOR_PAIR(3));
130 }
107 } 131 }
108
109 ctx->line[0] = '\0'; 132 ctx->line[0] = '\0';
110 ctx->pos = 0; 133 ctx->pos = 0;
111 } 134 }
135
136 /* BACKSPACE key: Remove one character from line */
112 else if(key == 0x107 || key == 0x8 || key == 0x7f) { 137 else if(key == 0x107 || key == 0x8 || key == 0x7f) {
113 if(ctx->pos != 0) { 138 if(ctx->pos != 0) {
114 ctx->line[--ctx->pos] = '\0'; 139 ctx->line[--ctx->pos] = '\0';
115 } 140 }
116 } 141 }
142}
117 143
144void execute(ToxWindow* self, ChatContext* ctx, char* cmd)
145{
146 if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
147 wclear(self->window);
148 wclear(ctx->history);
149 }
150 else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h"))
151 print_help(ctx);
152 else if (!strcmp(cmd, "/quit") || !strcmp(cmd, "/exit") || !strcmp(cmd, "/q")) {
153 endwin();
154 exit(0);
155 }
156 else if (!strncmp(cmd, "/status ", strlen("/status "))) {
157 char* msg;
158 msg = strchr(cmd, ' ');
159 if(msg == NULL) {
160 wprintw(ctx->history, "Invalid syntax.\n");
161 return;
162 }
163 msg++;
164 m_set_userstatus((uint8_t*) msg, strlen(msg)+1);
165 wprintw(ctx->history, "Status set to: %s\n", msg);
166 }
167 else if (!strncmp(cmd, "/nick ", strlen("/nick "))) {
168 char* nick;
169 nick = strchr(cmd, ' ');
170 if(nick == NULL) {
171 wprintw(ctx->history, "Invalid syntax.\n");
172 return;
173 }
174 nick++;
175 setname((uint8_t*) nick, strlen(nick)+1);
176 wprintw(ctx->history, "Nickname set to: %s\n", nick);
177 }
178 else if(!strcmp(cmd, "/myid")) {
179 char id[32*2 + 1] = {0};
180 int i;
181 for (i = 0; i < 32; i++) {
182 char xx[3];
183 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
184 strcat(id, xx);
185 }
186 wprintw(ctx->history, "Your ID: %s\n", id);
187 }
188 else
189 wprintw(ctx->history, "Invalid command.\n");
118} 190}
119 191
120static void chat_onDraw(ToxWindow* self) { 192static void chat_onDraw(ToxWindow* self) {
@@ -147,6 +219,21 @@ static void chat_onInit(ToxWindow* self) {
147 ctx->linewin = subwin(self->window, 2, x, y - 3, 0); 219 ctx->linewin = subwin(self->window, 2, x, y - 3, 0);
148} 220}
149 221
222void print_help(ChatContext* self) {
223 wattron(self->history, COLOR_PAIR(2) | A_BOLD);
224 wprintw(self->history, "\nCommands:\n");
225 wattroff(self->history, A_BOLD);
226
227 wprintw(self->history, " /status <message> : Set your status\n");
228 wprintw(self->history, " /nick <nickname> : Set your nickname\n");
229 wprintw(self->history, " /myid : Print your ID\n");
230 wprintw(self->history, " /clear : Clear the screen\n");
231 wprintw(self->history, " /quit or /exit : Exit program\n");
232 wprintw(self->history, " /help : Print this message again\n\n");
233
234 wattroff(self->history, COLOR_PAIR(2));
235}
236
150ToxWindow new_chat(int friendnum) { 237ToxWindow new_chat(int friendnum) {
151 ToxWindow ret; 238 ToxWindow ret;
152 239
@@ -169,6 +256,6 @@ ToxWindow new_chat(int friendnum) {
169 x->friendnum = friendnum; 256 x->friendnum = friendnum;
170 257
171 ret.x = (void*) x; 258 ret.x = (void*) x;
172 259 free(x);
173 return ret; 260 return ret;
174} 261}
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 3b45a89f..e0e23708 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -91,7 +91,7 @@ static void init_term() {
91 cbreak(); 91 cbreak();
92 keypad(stdscr, 1); 92 keypad(stdscr, 1);
93 noecho(); 93 noecho();
94 timeout(2000); 94 timeout(100);
95 95
96 if(has_colors()) { 96 if(has_colors()) {
97 start_color(); 97 start_color();
@@ -255,15 +255,15 @@ static void draw_bar() {
255 attron(A_BOLD); 255 attron(A_BOLD);
256 } 256 }
257 257
258 odd = (odd+1) % 2; 258 odd = (odd+1) % 10;
259 259
260 if(windows[i].blink && odd) { 260 if(windows[i].blink && (odd < 5)) {
261 attron(COLOR_PAIR(3)); 261 attron(COLOR_PAIR(3));
262 } 262 }
263 263
264 printw(" %s", windows[i].title); 264 printw(" %s", windows[i].title);
265 265
266 if(windows[i].blink && odd) { 266 if(windows[i].blink && (odd < 5)) {
267 attron(COLOR_PAIR(3)); 267 attron(COLOR_PAIR(3));
268 } 268 }
269 269
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 1db60883..463b9352 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -89,7 +89,9 @@ static void execute(ToxWindow* self, char* cmd) {
89 } 89 }
90 90
91 dht.ip.i = resolved_address; 91 dht.ip.i = resolved_address;
92 DHT_bootstrap(dht, hex_string_to_bin(key)); 92 unsigned char *binary_string = hex_string_to_bin(key);
93 DHT_bootstrap(dht, binary_string);
94 free(binary_string);
93 } 95 }
94 else if(!strncmp(cmd, "add ", strlen("add "))) { 96 else if(!strncmp(cmd, "add ", strlen("add "))) {
95 uint8_t id_bin[32]; 97 uint8_t id_bin[32];
@@ -148,7 +150,7 @@ static void execute(ToxWindow* self, char* cmd) {
148 wprintw(self->window, "Friend request already sent.\n"); 150 wprintw(self->window, "Friend request already sent.\n");
149 break; 151 break;
150 case -5: 152 case -5:
151 wprintw(self->window, "[i] Undefined error when adding friend.\n"); 153 wprintw(self->window, "Undefined error when adding friend.\n");
152 break; 154 break;
153 default: 155 default:
154 wprintw(self->window, "Friend added as %d.\n", num); 156 wprintw(self->window, "Friend added as %d.\n", num);
@@ -178,12 +180,13 @@ static void execute(ToxWindow* self, char* cmd) {
178 180
179 nick = strchr(cmd, ' '); 181 nick = strchr(cmd, ' ');
180 if(nick == NULL) { 182 if(nick == NULL) {
183 wprintw(self->window, "Invalid syntax.\n");
181 return; 184 return;
182 } 185 }
183 nick++; 186 nick++;
184 187
185 setname((uint8_t*) nick, strlen(nick)+1); 188 setname((uint8_t*) nick, strlen(nick)+1);
186 wprintw(self->window, "Nickname set to: %s.\n", nick); 189 wprintw(self->window, "Nickname set to: %s\n", nick);
187 } 190 }
188 else if(!strcmp(cmd, "myid")) { 191 else if(!strcmp(cmd, "myid")) {
189 char id[32*2 + 1] = {0}; 192 char id[32*2 + 1] = {0};
@@ -195,7 +198,7 @@ static void execute(ToxWindow* self, char* cmd) {
195 strcat(id, xx); 198 strcat(id, xx);
196 } 199 }
197 200
198 wprintw(self->window, "%s\n", id); 201 wprintw(self->window, "Your ID: %s\n", id);
199 } 202 }
200 else if(!strncmp(cmd, "accept ", strlen("accept "))) { 203 else if(!strncmp(cmd, "accept ", strlen("accept "))) {
201 char* id; 204 char* id;
@@ -251,20 +254,18 @@ static void execute(ToxWindow* self, char* cmd) {
251 wprintw(self->window, "Message successfully sent.\n"); 254 wprintw(self->window, "Message successfully sent.\n");
252 } 255 }
253 } 256 }
257
254 else { 258 else {
255 wprintw(self->window, "Invalid syntax.\n"); 259 wprintw(self->window, "Invalid command.\n");
256 } 260 }
257} 261}
258 262
259static void prompt_onKey(ToxWindow* self, int key) { 263static void prompt_onKey(ToxWindow* self, int key) {
260
261 // PRINTABLE characters: Add to line. 264 // PRINTABLE characters: Add to line.
262 if(isprint(key)) { 265 if(isprint(key)) {
263
264 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { 266 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) {
265 return; 267 return;
266 } 268 }
267
268 prompt_buf[prompt_buf_pos++] = key; 269 prompt_buf[prompt_buf_pos++] = key;
269 prompt_buf[prompt_buf_pos] = 0; 270 prompt_buf[prompt_buf_pos] = 0;
270 } 271 }
@@ -273,14 +274,12 @@ static void prompt_onKey(ToxWindow* self, int key) {
273 else if(key == '\n') { 274 else if(key == '\n') {
274 wprintw(self->window, "\n"); 275 wprintw(self->window, "\n");
275 execute(self, prompt_buf); 276 execute(self, prompt_buf);
276
277 prompt_buf_pos = 0; 277 prompt_buf_pos = 0;
278 prompt_buf[0] = 0; 278 prompt_buf[0] = 0;
279 } 279 }
280 280
281 // BACKSPACE key: Remove one character from line. 281 // BACKSPACE key: Remove one character from line.
282 else if(key == 0x107 || key == 0x8 || key == 0x7f) { 282 else if(key == 0x107 || key == 0x8 || key == 0x7f) {
283
284 if(prompt_buf_pos != 0) { 283 if(prompt_buf_pos != 0) {
285 prompt_buf[--prompt_buf_pos] = 0; 284 prompt_buf[--prompt_buf_pos] = 0;
286 } 285 }