diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-31 10:25:29 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-31 10:25:29 -0400 |
commit | bdd13d1954e0befb1682cf1f6727e9b382450ed8 (patch) | |
tree | 61ab2649c5515c1f0bd8b3506fb7fd7be7d15737 /testing | |
parent | 55a2e59a64d879440667b9d672a3878fa7fe5d2e (diff) | |
parent | 17e64b3ee50605cbc15f195f770dacf31039e121 (diff) |
Merge branch 'master' of https://github.com/JFreegman/ProjectTox-Core into JFreegman-master
Conflicts:
testing/nTox.c
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 164 | ||||
-rw-r--r-- | testing/nTox.h | 1 | ||||
-rw-r--r-- | testing/nTox_win32.c | 87 | ||||
-rw-r--r-- | testing/nTox_win32.h | 1 |
4 files changed, 125 insertions, 128 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 6aef1d7b..29726a3a 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -23,9 +23,9 @@ | |||
23 | #include "nTox.h" | 23 | #include "nTox.h" |
24 | #include "misc_tools.h" | 24 | #include "misc_tools.h" |
25 | 25 | ||
26 | |||
27 | #include <stdio.h> | 26 | #include <stdio.h> |
28 | #include <time.h> | 27 | #include <time.h> |
28 | |||
29 | #ifdef WIN32 | 29 | #ifdef WIN32 |
30 | #define c_sleep(x) Sleep(1*x) | 30 | #define c_sleep(x) Sleep(1*x) |
31 | #else | 31 | #else |
@@ -35,20 +35,22 @@ | |||
35 | 35 | ||
36 | char lines[HISTORY][STRING_LENGTH]; | 36 | char lines[HISTORY][STRING_LENGTH]; |
37 | char line[STRING_LENGTH]; | 37 | char line[STRING_LENGTH]; |
38 | |||
38 | char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n" | 39 | char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n" |
39 | "[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"; | 40 | "[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"; |
40 | int x,y; | 41 | int x, y; |
42 | |||
41 | 43 | ||
42 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 44 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; |
43 | uint8_t num_requests; | 45 | uint8_t num_requests = 0; |
44 | 46 | ||
45 | void new_lines(char *line) | 47 | void new_lines(char *line) |
46 | { | 48 | { |
47 | int i; | 49 | int i; |
48 | for (i = HISTORY-1; i > 0; i--) | 50 | for (i = HISTORY-1; i > 0; i--) |
49 | strcpy(lines[i],lines[i-1]); | 51 | strcpy(lines[i], lines[i-1]); |
50 | 52 | ||
51 | strcpy(lines[0],line); | 53 | strcpy(lines[0], line); |
52 | do_refresh(); | 54 | do_refresh(); |
53 | } | 55 | } |
54 | 56 | ||
@@ -56,10 +58,10 @@ void new_lines(char *line) | |||
56 | void print_friendlist() | 58 | void print_friendlist() |
57 | { | 59 | { |
58 | char name[MAX_NAME_LENGTH]; | 60 | char name[MAX_NAME_LENGTH]; |
59 | uint32_t i; | ||
60 | |||
61 | new_lines("[i] Friend List:"); | 61 | new_lines("[i] Friend List:"); |
62 | for (i=0; i <= num_requests; i++) { | 62 | uint32_t i; |
63 | for (i = 0; i <= num_requests; i++) { | ||
64 | printf ("num_resusts: %d\n", num_requests); | ||
63 | char fstring[128]; | 65 | char fstring[128]; |
64 | 66 | ||
65 | getname(i, (uint8_t*)name); | 67 | getname(i, (uint8_t*)name); |
@@ -75,19 +77,20 @@ void print_friendlist() | |||
75 | char *format_message(char *message, int friendnum) | 77 | char *format_message(char *message, int friendnum) |
76 | { | 78 | { |
77 | char name[MAX_NAME_LENGTH]; | 79 | char name[MAX_NAME_LENGTH]; |
78 | if(friendnum != -1) { | 80 | if (friendnum != -1) { |
79 | getname(friendnum, (uint8_t*)name); | 81 | getname(friendnum, (uint8_t*)name); |
80 | } else { | 82 | } else { |
81 | getself_name((uint8_t*)name); | 83 | getself_name((uint8_t*)name); |
82 | } | 84 | } |
83 | char *msg = malloc(100+strlen(message)+strlen(name)+1); | 85 | char *msg = malloc(100+strlen(message)+strlen(name)+1); |
86 | |||
84 | time_t rawtime; | 87 | time_t rawtime; |
85 | struct tm * timeinfo; | 88 | struct tm * timeinfo; |
86 | time ( &rawtime ); | 89 | time ( &rawtime ); |
87 | timeinfo = localtime ( &rawtime ); | 90 | timeinfo = localtime ( &rawtime ); |
88 | char* time = asctime(timeinfo); | 91 | char* time = asctime(timeinfo); |
89 | size_t len = strlen(time); | 92 | size_t len = strlen(time); |
90 | time[len-1]='\0'; | 93 | time[len-1] = '\0'; |
91 | sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp | 94 | sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp |
92 | return msg; | 95 | return msg; |
93 | } | 96 | } |
@@ -95,13 +98,14 @@ char *format_message(char *message, int friendnum) | |||
95 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | 98 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) |
96 | { | 99 | { |
97 | if (line[0] == '/') { | 100 | if (line[0] == '/') { |
98 | char command[STRING_LENGTH + 2] = "> "; | 101 | char inpt_command = line[1]; |
99 | strcat(command, line); | 102 | char prompt[STRING_LENGTH + 2] = "> "; |
100 | new_lines(command); | 103 | strcat(prompt, line); |
101 | if (line[1] == 'f') { // add friend command: /f ID | 104 | new_lines(prompt); |
105 | if (inpt_command == 'f') { // add friend command: /f ID | ||
102 | int i; | 106 | int i; |
103 | char temp_id[128]; | 107 | char temp_id[128]; |
104 | for (i=0; i<128; i++) | 108 | for (i = 0; i < 128; i++) |
105 | temp_id[i] = line[i+3]; | 109 | temp_id[i] = line[i+3]; |
106 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 110 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
107 | char numstring[100]; | 111 | char numstring[100]; |
@@ -109,63 +113,63 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
109 | new_lines(numstring); | 113 | new_lines(numstring); |
110 | do_refresh(); | 114 | do_refresh(); |
111 | } | 115 | } |
112 | else if (line[1] == 'd') { | 116 | else if (inpt_command == 'd') { |
113 | doMessenger(); | 117 | doMessenger(); |
114 | } | 118 | } |
115 | else if (line[1] == 'm') { //message command: /m friendnumber messsage | 119 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage |
116 | int i; | ||
117 | size_t len = strlen(line); | 120 | size_t len = strlen(line); |
118 | char numstring[len-3]; | 121 | char numstring[len-3]; |
119 | char message[len-3]; | 122 | char message[len-3]; |
120 | for (i=0; i<len; i++) { | 123 | int i; |
124 | for (i = 0; i < len; i++) { | ||
121 | if (line[i+3] != ' ') { | 125 | if (line[i+3] != ' ') { |
122 | numstring[i] = line[i+3]; | 126 | numstring[i] = line[i+3]; |
123 | } else { | 127 | } else { |
124 | int j; | 128 | int j; |
125 | for (j=i+1; j<len; j++) | 129 | for (j = (i+1); j < len; j++) |
126 | message[j-i-1] = line[j+3]; | 130 | message[j-i-1] = line[j+3]; |
127 | break; | 131 | break; |
128 | } | 132 | } |
129 | } | 133 | } |
130 | int num = atoi(numstring); | 134 | int num = atoi(numstring); |
131 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | 135 | if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { |
132 | new_lines("[i] could not send message"); | 136 | new_lines("[i] could not send message"); |
133 | } else { | 137 | } else { |
134 | new_lines(format_message(message, -1)); | 138 | new_lines(format_message(message, -1)); |
135 | } | 139 | } |
136 | } | 140 | } |
137 | else if (line[1] == 'n') { | 141 | else if (inpt_command == 'n') { |
138 | uint8_t name[MAX_NAME_LENGTH]; | 142 | uint8_t name[MAX_NAME_LENGTH]; |
139 | int i = 0; | 143 | int i = 0; |
140 | size_t len = strlen(line); | 144 | size_t len = strlen(line); |
141 | for (i=3; i<len; i++) { | 145 | for (i = 3; i < len; i++) { |
142 | if (line[i] == 0 || line[i] == '\n') break; | 146 | if (line[i] == 0 || line[i] == '\n') break; |
143 | name[i - 3] = line[i]; | 147 | name[i-3] = line[i]; |
144 | } | 148 | } |
145 | name[i - 3] = 0; | 149 | name[i-3] = 0; |
146 | setname(name, i); | 150 | setname(name, i); |
147 | char numstring[100]; | 151 | char numstring[100]; |
148 | sprintf(numstring, "[i] changed nick to %s", (char*)name); | 152 | sprintf(numstring, "[i] changed nick to %s", (char*)name); |
149 | new_lines(numstring); | 153 | new_lines(numstring); |
150 | } | 154 | } |
151 | else if (line[1] == 'l') { | 155 | else if (inpt_command == 'l') { |
152 | print_friendlist(); | 156 | print_friendlist(); |
153 | } | 157 | } |
154 | else if (line[1] == 's') { | 158 | else if (inpt_command == 's') { |
155 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 159 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
156 | int i = 0; | 160 | int i = 0; |
157 | size_t len = strlen(line); | 161 | size_t len = strlen(line); |
158 | for (i=3; i<len; i++) { | 162 | for (i = 3; i < len; i++) { |
159 | if (line[i] == 0 || line[i] == '\n') break; | 163 | if (line[i] == 0 || line[i] == '\n') break; |
160 | status[i - 3] = line[i]; | 164 | status[i-3] = line[i]; |
161 | } | 165 | } |
162 | status[i - 3] = 0; | 166 | status[i-3] = 0; |
163 | m_set_userstatus(status, strlen((char*)status)); | 167 | m_set_userstatus(status, strlen((char*)status)); |
164 | char numstring[100]; | 168 | char numstring[100]; |
165 | sprintf(numstring, "[i] changed status to %s", (char*)status); | 169 | sprintf(numstring, "[i] changed status to %s", (char*)status); |
166 | new_lines(numstring); | 170 | new_lines(numstring); |
167 | } | 171 | } |
168 | else if (line[1] == 'a') { | 172 | else if (inpt_command == 'a') { |
169 | uint8_t numf = atoi(line + 3); | 173 | uint8_t numf = atoi(line + 3); |
170 | char numchar[100]; | 174 | char numchar[100]; |
171 | sprintf(numchar, "[i] friend request %u accepted", numf); | 175 | sprintf(numchar, "[i] friend request %u accepted", numf); |
@@ -176,34 +180,34 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
176 | do_refresh(); | 180 | do_refresh(); |
177 | 181 | ||
178 | } | 182 | } |
179 | 183 | else if (inpt_command == 'h') { //help | |
180 | else if (line[1] == 'h') { //help | 184 | new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); |
181 | new_lines(help); | 185 | new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"); |
182 | } | 186 | } |
183 | 187 | else if (inpt_command == 'i') { //info | |
184 | else if (line[1] == 'i') { //info | ||
185 | char idstring0[200]; | 188 | char idstring0[200]; |
186 | char idstring1[32][5]; | 189 | char idstring1[PUB_KEY_BYTES][5]; |
187 | char idstring2[32][5]; | 190 | char idstring2[PUB_KEY_BYTES][5]; |
188 | uint32_t i; | 191 | int i; |
189 | for(i = 0; i < 32; i++) | 192 | for (i = 0; i < PUB_KEY_BYTES; i++) |
190 | { | 193 | { |
191 | if(self_public_key[i] < 16) | 194 | if (self_public_key[i] < (PUB_KEY_BYTES/2)) |
192 | strcpy(idstring1[i],"0"); | 195 | strcpy(idstring1[i],"0"); |
193 | else | 196 | else |
194 | strcpy(idstring1[i], ""); | 197 | strcpy(idstring1[i], ""); |
195 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 198 | sprintf(idstring2[i], "%hhX", self_public_key[i]); |
196 | } | 199 | } |
197 | // | 200 | // |
198 | strcpy(idstring0,"[i] ID: "); | 201 | strcpy(idstring0,"[i] ID: "); |
199 | for (i=0; i<32; i++) { | 202 | int j; |
200 | strcat(idstring0,idstring1[i]); | 203 | for (j = 0; j < PUB_KEY_BYTES; j++) { |
201 | strcat(idstring0,idstring2[i]); | 204 | strcat(idstring0,idstring1[j]); |
205 | strcat(idstring0,idstring2[j]); | ||
202 | } | 206 | } |
203 | new_lines(idstring0); | 207 | new_lines(idstring0); |
204 | } | 208 | } |
205 | 209 | ||
206 | else if (line[1] == 'q') { //exit | 210 | else if (inpt_command == 'q') { //exit |
207 | endwin(); | 211 | endwin(); |
208 | exit(EXIT_SUCCESS); | 212 | exit(EXIT_SUCCESS); |
209 | } else { | 213 | } else { |
@@ -217,9 +221,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
217 | 221 | ||
218 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | 222 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) |
219 | { | 223 | { |
220 | int i = 0; | ||
221 | strcpy(output,input); | 224 | strcpy(output,input); |
222 | size_t len = strlen(output); | 225 | size_t len = strlen(output); |
226 | int i = 0; | ||
223 | for (i = line_width; i < len; i = i + line_width) { | 227 | for (i = line_width; i < len; i = i + line_width) { |
224 | while (output[i] != ' ' && i != 0) { | 228 | while (output[i] != ' ' && i != 0) { |
225 | i--; | 229 | i--; |
@@ -233,9 +237,9 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | |||
233 | int count_lines(char *string) | 237 | int count_lines(char *string) |
234 | { | 238 | { |
235 | size_t len = strlen(string); | 239 | size_t len = strlen(string); |
236 | int i; | ||
237 | int count = 1; | 240 | int count = 1; |
238 | for (i=0; i < len; i++) { | 241 | int i; |
242 | for (i = 0; i < len; i++) { | ||
239 | if (string[i] == '\n') | 243 | if (string[i] == '\n') |
240 | count++; | 244 | count++; |
241 | } | 245 | } |
@@ -246,7 +250,7 @@ char *appender(char *str, const char c) | |||
246 | { | 250 | { |
247 | size_t len = strlen(str); | 251 | size_t len = strlen(str); |
248 | if (len < STRING_LENGTH) { | 252 | if (len < STRING_LENGTH) { |
249 | str[len + 1] = str[len]; | 253 | str[len+1] = str[len]; |
250 | str[len] = c; | 254 | str[len] = c; |
251 | } | 255 | } |
252 | return str; | 256 | return str; |
@@ -254,21 +258,21 @@ char *appender(char *str, const char c) | |||
254 | 258 | ||
255 | void do_refresh() | 259 | void do_refresh() |
256 | { | 260 | { |
257 | int i; | ||
258 | int count=0; | 261 | int count=0; |
259 | int l; | ||
260 | char wrap_output[STRING_LENGTH]; | 262 | char wrap_output[STRING_LENGTH]; |
261 | for (i=0; i<HISTORY; i++) { | 263 | int L; |
264 | int i; | ||
265 | for (i = 0; i < HISTORY; i++) { | ||
262 | wrap(wrap_output, lines[i], x); | 266 | wrap(wrap_output, lines[i], x); |
263 | l = count_lines(wrap_output); | 267 | L = count_lines(wrap_output); |
264 | count = count + l; | 268 | count = count + L; |
265 | if (count < y) { | 269 | if (count < y) { |
266 | move(y-1-count,0); | 270 | move(y-1-count, 0); |
267 | printw(wrap_output); | 271 | printw(wrap_output); |
268 | clrtoeol(); | 272 | clrtoeol(); |
269 | } | 273 | } |
270 | } | 274 | } |
271 | move(y-1,0); | 275 | move(y-1, 0); |
272 | clrtoeol(); | 276 | clrtoeol(); |
273 | printw(">> "); | 277 | printw(">> "); |
274 | printw(line); | 278 | printw(line); |
@@ -299,12 +303,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
299 | timeinfo = localtime ( &rawtime ); | 303 | timeinfo = localtime ( &rawtime ); |
300 | char* temp = asctime(timeinfo); | 304 | char* temp = asctime(timeinfo); |
301 | size_t len = strlen(temp); | 305 | size_t len = strlen(temp); |
302 | temp[len-1]='\0'; | 306 | temp[len-1] = '\0'; |
303 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp | 307 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp |
304 | new_lines(format_message((char*)string, friendnumber)); | 308 | new_lines(format_message((char*)string, friendnumber)); |
305 | } | 309 | } |
306 | 310 | ||
307 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { | 311 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) |
312 | { | ||
308 | char name[MAX_NAME_LENGTH]; | 313 | char name[MAX_NAME_LENGTH]; |
309 | getname(friendnumber, (uint8_t*)name); | 314 | getname(friendnumber, (uint8_t*)name); |
310 | char msg[100+length]; | 315 | char msg[100+length]; |
@@ -312,7 +317,8 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { | |||
312 | new_lines(msg); | 317 | new_lines(msg); |
313 | } | 318 | } |
314 | 319 | ||
315 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | 320 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
321 | { | ||
316 | char name[MAX_NAME_LENGTH]; | 322 | char name[MAX_NAME_LENGTH]; |
317 | getname(friendnumber, (uint8_t*)name); | 323 | getname(friendnumber, (uint8_t*)name); |
318 | char msg[100+length+strlen(name)+1]; | 324 | char msg[100+length+strlen(name)+1]; |
@@ -320,15 +326,17 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | |||
320 | new_lines(msg); | 326 | new_lines(msg); |
321 | } | 327 | } |
322 | 328 | ||
323 | void load_key(){ | 329 | void load_key() |
330 | { | ||
324 | FILE *data_file = NULL; | 331 | FILE *data_file = NULL; |
325 | if ((data_file = fopen("data","r"))) { | 332 | data_file = fopen("data","r"); |
333 | if (data_file) { | ||
326 | //load keys | 334 | //load keys |
327 | fseek(data_file, 0, SEEK_END); | 335 | fseek(data_file, 0, SEEK_END); |
328 | int size = ftell(data_file); | 336 | int size = ftell(data_file); |
329 | fseek(data_file, 0, SEEK_SET); | 337 | fseek(data_file, 0, SEEK_SET); |
330 | uint8_t data[size]; | 338 | uint8_t data[size]; |
331 | if(fread(data, sizeof(uint8_t), size, data_file) != size){ | 339 | if (fread(data, sizeof(uint8_t), size, data_file) != size){ |
332 | printf("[i] could not read data file\n[i] exiting\n"); | 340 | printf("[i] could not read data file\n[i] exiting\n"); |
333 | exit(1); | 341 | exit(1); |
334 | } | 342 | } |
@@ -339,7 +347,7 @@ void load_key(){ | |||
339 | uint8_t data[size]; | 347 | uint8_t data[size]; |
340 | Messenger_save(data); | 348 | Messenger_save(data); |
341 | data_file = fopen("data","w"); | 349 | data_file = fopen("data","w"); |
342 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ | 350 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ |
343 | printf("[i] could not write data file\n[i] exiting\n"); | 351 | printf("[i] could not write data file\n[i] exiting\n"); |
344 | exit(1); | 352 | exit(1); |
345 | } | 353 | } |
@@ -369,26 +377,27 @@ int main(int argc, char *argv[]) | |||
369 | m_callback_namechange(print_nickchange); | 377 | m_callback_namechange(print_nickchange); |
370 | m_callback_userstatus(print_statuschange); | 378 | m_callback_userstatus(print_statuschange); |
371 | char idstring0[200]; | 379 | char idstring0[200]; |
372 | char idstring1[32][5]; | 380 | char idstring1[PUB_KEY_BYTES][5]; |
373 | char idstring2[32][5]; | 381 | char idstring2[PUB_KEY_BYTES][5]; |
374 | uint32_t i; | 382 | int i; |
375 | for(i = 0; i < 32; i++) | 383 | for(i = 0; i < PUB_KEY_BYTES; i++) |
376 | { | 384 | { |
377 | if(self_public_key[i] < 16) | 385 | if (self_public_key[i] < (PUB_KEY_BYTES / 2)) |
378 | strcpy(idstring1[i],"0"); | 386 | strcpy(idstring1[i],"0"); |
379 | else | 387 | else |
380 | strcpy(idstring1[i], ""); | 388 | strcpy(idstring1[i], ""); |
381 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 389 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
382 | } | 390 | } |
383 | strcpy(idstring0,"[i] your ID: "); | 391 | strcpy(idstring0,"[i] your ID: "); |
384 | for (i=0; i<32; i++) { | 392 | int j; |
385 | strcat(idstring0,idstring1[i]); | 393 | for (j = 0; j < PUB_KEY_BYTES; j++) { |
386 | strcat(idstring0,idstring2[i]); | 394 | strcat(idstring0,idstring1[j]); |
395 | strcat(idstring0,idstring2[j]); | ||
387 | } | 396 | } |
388 | initscr(); | 397 | initscr(); |
389 | noecho(); | 398 | noecho(); |
390 | raw(); | 399 | raw(); |
391 | getmaxyx(stdscr,y,x); | 400 | getmaxyx(stdscr, y, x); |
392 | new_lines(idstring0); | 401 | new_lines(idstring0); |
393 | new_lines(help); | 402 | new_lines(help); |
394 | strcpy(line, ""); | 403 | strcpy(line, ""); |
@@ -413,7 +422,6 @@ int main(int argc, char *argv[]) | |||
413 | do_refresh(); | 422 | do_refresh(); |
414 | 423 | ||
415 | c = getch(); | 424 | c = getch(); |
416 | |||
417 | if (c == ERR || c == 27) | 425 | if (c == ERR || c == 27) |
418 | continue; | 426 | continue; |
419 | 427 | ||
@@ -422,7 +430,7 @@ int main(int argc, char *argv[]) | |||
422 | line_eval(lines, line); | 430 | line_eval(lines, line); |
423 | strcpy(line, ""); | 431 | strcpy(line, ""); |
424 | } else if (c == 127) { | 432 | } else if (c == 127) { |
425 | line[strlen(line) - 1] = '\0'; | 433 | line[strlen(line)-1] = '\0'; |
426 | } else if (isalnum(c) || ispunct(c) || c == ' ') { | 434 | } else if (isalnum(c) || ispunct(c) || c == ' ') { |
427 | strcpy(line, appender(line, (char) c)); | 435 | strcpy(line, appender(line, (char) c)); |
428 | } | 436 | } |
diff --git a/testing/nTox.h b/testing/nTox.h index 9b69d959..9d82556c 100644 --- a/testing/nTox.h +++ b/testing/nTox.h | |||
@@ -39,6 +39,7 @@ | |||
39 | #include "../core/network.h" | 39 | #include "../core/network.h" |
40 | #define STRING_LENGTH 256 | 40 | #define STRING_LENGTH 256 |
41 | #define HISTORY 50 | 41 | #define HISTORY 50 |
42 | #define PUB_KEY_BYTES 32 | ||
42 | 43 | ||
43 | void new_lines(char *line); | 44 | void new_lines(char *line); |
44 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line); | 45 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line); |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index a870c210..b7b6a70d 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <process.h> | 27 | #include <process.h> |
28 | 28 | ||
29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; |
30 | uint8_t num_requests; | 30 | uint8_t num_requests = 0; |
31 | 31 | ||
32 | char line[STRING_LENGTH]; | 32 | char line[STRING_LENGTH]; |
33 | char users_id[200]; | 33 | char users_id[200]; |
@@ -88,14 +88,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | |||
88 | void load_key() | 88 | void load_key() |
89 | { | 89 | { |
90 | FILE *data_file = NULL; | 90 | FILE *data_file = NULL; |
91 | 91 | data_file = fopen("data","r"); | |
92 | if ((data_file = fopen("data", "r"))) { | 92 | if (data_file) { |
93 | fseek(data_file, 0, SEEK_END); | 93 | fseek(data_file, 0, SEEK_END); |
94 | int size = ftell(data_file); | 94 | int size = ftell(data_file); |
95 | fseek(data_file, 0, SEEK_SET); | 95 | fseek(data_file, 0, SEEK_SET); |
96 | uint8_t data[size]; | 96 | uint8_t data[size]; |
97 | 97 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { | |
98 | if(fread(data, sizeof(uint8_t), size, data_file) != size) { | ||
99 | printf("\n[i] Could not read the data file. Exiting."); | 98 | printf("\n[i] Could not read the data file. Exiting."); |
100 | exit(1); | 99 | exit(1); |
101 | } | 100 | } |
@@ -107,23 +106,23 @@ void load_key() | |||
107 | Messenger_save(data); | 106 | Messenger_save(data); |
108 | data_file = fopen("data", "w"); | 107 | data_file = fopen("data", "w"); |
109 | 108 | ||
110 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { | 109 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { |
111 | printf("\n[i] Could not write data to file. Exiting."); | 110 | printf("\n[i] Could not write data to file. Exiting."); |
112 | exit(1); | 111 | exit(1); |
113 | } | 112 | } |
114 | } | 113 | } |
115 | |||
116 | fclose(data_file); | 114 | fclose(data_file); |
117 | } | 115 | } |
118 | 116 | ||
119 | void line_eval(char* line) | 117 | void line_eval(char* line) |
120 | { | 118 | { |
121 | if(line[0] == '/') { | 119 | if(line[0] == '/') { |
120 | char inpt_command = line[1]; | ||
122 | /* Add friend */ | 121 | /* Add friend */ |
123 | if(line[1] == 'f') { | 122 | if(inpt_command == 'f') { |
124 | int i; | 123 | int i; |
125 | char temp_id[128]; | 124 | char temp_id[128]; |
126 | for (i=0; i<128; i++) | 125 | for (i = 0; i < 128; i++) |
127 | temp_id[i] = line[i+3]; | 126 | temp_id[i] = line[i+3]; |
128 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 127 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
129 | char numstring[100]; | 128 | char numstring[100]; |
@@ -131,28 +130,27 @@ void line_eval(char* line) | |||
131 | printf(numstring); | 130 | printf(numstring); |
132 | } | 131 | } |
133 | 132 | ||
134 | else if (line[1] == 'r') { | 133 | else if (inpt_command == 'r') { |
135 | do_header(); | 134 | do_header(); |
136 | printf("\n\n"); | 135 | printf("\n\n"); |
137 | } | 136 | } |
138 | 137 | ||
139 | else if (line[1] == 'l') { | 138 | else if (inpt_command == 'l') { |
140 | printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); | 139 | printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); |
141 | 140 | ||
142 | int i; | 141 | int i; |
143 | 142 | for (i = 0; i < getnumfriends(); i++) { | |
144 | for (i=0; i < getnumfriends(); i++) { | ||
145 | char name[MAX_NAME_LENGTH]; | 143 | char name[MAX_NAME_LENGTH]; |
146 | getname(i, (uint8_t*)name); | 144 | getname(i, (uint8_t*)name); |
147 | printf("[%d] %s\n\n", i, (uint8_t*)name); | 145 | printf("[%d] %s\n\n", i, (uint8_t*)name); |
148 | } | 146 | } |
149 | } | 147 | } |
150 | 148 | ||
151 | else if (line[1] == 'd') { | 149 | else if (inpt_command == 'd') { |
152 | size_t len = strlen(line); | 150 | size_t len = strlen(line); |
153 | char numstring[len-3]; | 151 | char numstring[len-3]; |
154 | int i; | 152 | int i; |
155 | for (i=0; i<len; i++) { | 153 | for (i = 0; i < len; i++) { |
156 | if (line[i+3] != ' ') { | 154 | if (line[i+3] != ' ') { |
157 | numstring[i] = line[i+3]; | 155 | numstring[i] = line[i+3]; |
158 | } | 156 | } |
@@ -161,17 +159,17 @@ void line_eval(char* line) | |||
161 | m_delfriend(num); | 159 | m_delfriend(num); |
162 | } | 160 | } |
163 | /* Send message to friend */ | 161 | /* Send message to friend */ |
164 | else if (line[1] == 'm') { | 162 | else if (inpt_command == 'm') { |
165 | int i; | ||
166 | size_t len = strlen(line); | 163 | size_t len = strlen(line); |
167 | char numstring[len-3]; | 164 | char numstring[len-3]; |
168 | char message[len-3]; | 165 | char message[len-3]; |
169 | for (i=0; i<len; i++) { | 166 | int i; |
167 | for (i = 0; i < len; i++) { | ||
170 | if (line[i+3] != ' ') { | 168 | if (line[i+3] != ' ') { |
171 | numstring[i] = line[i+3]; | 169 | numstring[i] = line[i+3]; |
172 | } else { | 170 | } else { |
173 | int j; | 171 | int j; |
174 | for (j=i+1; j<len; j++) | 172 | for (j = (i+1); j < len; j++) |
175 | message[j-i-1] = line[j+3]; | 173 | message[j-i-1] = line[j+3]; |
176 | break; | 174 | break; |
177 | } | 175 | } |
@@ -185,37 +183,37 @@ void line_eval(char* line) | |||
185 | } | 183 | } |
186 | } | 184 | } |
187 | 185 | ||
188 | else if (line[1] == 'n') { | 186 | else if (inpt_command == 'n') { |
189 | uint8_t name[MAX_NAME_LENGTH]; | 187 | uint8_t name[MAX_NAME_LENGTH]; |
190 | int i = 0; | 188 | int i = 0; |
191 | size_t len = strlen(line); | 189 | size_t len = strlen(line); |
192 | for (i=3; i<len; i++) { | 190 | for (i = 3; i < len; i++) { |
193 | if (line[i] == 0 || line[i] == '\n') break; | 191 | if (line[i] == 0 || line[i] == '\n') break; |
194 | name[i - 3] = line[i]; | 192 | name[i-3] = line[i]; |
195 | } | 193 | } |
196 | name[i - 3] = 0; | 194 | name[i-3] = 0; |
197 | setname(name, i); | 195 | setname(name, i); |
198 | char numstring[100]; | 196 | char numstring[100]; |
199 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | 197 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); |
200 | printf(numstring); | 198 | printf(numstring); |
201 | } | 199 | } |
202 | 200 | ||
203 | else if (line[1] == 's') { | 201 | else if (inpt_command == 's') { |
204 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 202 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
205 | int i = 0; | 203 | int i = 0; |
206 | size_t len = strlen(line); | 204 | size_t len = strlen(line); |
207 | for (i=3; i<len; i++) { | 205 | for (i = 3; i < len; i++) { |
208 | if (line[i] == 0 || line[i] == '\n') break; | 206 | if (line[i] == 0 || line[i] == '\n') break; |
209 | status[i - 3] = line[i]; | 207 | status[i-3] = line[i]; |
210 | } | 208 | } |
211 | status[i - 3] = 0; | 209 | status[i-3] = 0; |
212 | m_set_userstatus(status, strlen((char*)status)); | 210 | m_set_userstatus(status, strlen((char*)status)); |
213 | char numstring[100]; | 211 | char numstring[100]; |
214 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 212 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
215 | printf(numstring); | 213 | printf(numstring); |
216 | } | 214 | } |
217 | 215 | ||
218 | else if (line[1] == 'a') { | 216 | else if (inpt_command == 'a') { |
219 | uint8_t numf = atoi(line + 3); | 217 | uint8_t numf = atoi(line + 3); |
220 | char numchar[100]; | 218 | char numchar[100]; |
221 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); | 219 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); |
@@ -225,12 +223,10 @@ void line_eval(char* line) | |||
225 | printf(numchar); | 223 | printf(numchar); |
226 | } | 224 | } |
227 | /* EXIT */ | 225 | /* EXIT */ |
228 | else if (line[1] == 'q') { | 226 | else if (inpt_command == 'q') { |
229 | exit(EXIT_SUCCESS); | 227 | exit(EXIT_SUCCESS); |
230 | } | 228 | } |
231 | } | 229 | } else { |
232 | |||
233 | else { | ||
234 | //nothing atm | 230 | //nothing atm |
235 | } | 231 | } |
236 | } | 232 | } |
@@ -250,12 +246,10 @@ int main(int argc, char *argv[]) | |||
250 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); | 246 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); |
251 | exit(0); | 247 | exit(0); |
252 | } | 248 | } |
253 | |||
254 | if (initMessenger() == -1) { | 249 | if (initMessenger() == -1) { |
255 | printf("initMessenger failed"); | 250 | printf("initMessenger failed"); |
256 | exit(0); | 251 | exit(0); |
257 | } | 252 | } |
258 | |||
259 | if (argc > 4) { | 253 | if (argc > 4) { |
260 | if(strncmp(argv[4], "nokey", 6) < 0) { | 254 | if(strncmp(argv[4], "nokey", 6) < 0) { |
261 | } | 255 | } |
@@ -267,26 +261,25 @@ int main(int argc, char *argv[]) | |||
267 | m_callback_friendmessage(print_message); | 261 | m_callback_friendmessage(print_message); |
268 | m_callback_namechange(print_nickchange); | 262 | m_callback_namechange(print_nickchange); |
269 | m_callback_userstatus(print_statuschange); | 263 | m_callback_userstatus(print_statuschange); |
270 | 264 | char idstring1[PUB_KEY_BYTES][5]; | |
271 | char idstring1[32][5]; | 265 | char idstring2[PUB_KEY_BYTES][5]; |
272 | char idstring2[32][5]; | 266 | int i; |
273 | uint32_t i; | 267 | for(i = 0; i < PUB_KEY_BYTES; i++) |
274 | for(i = 0; i < 32; i++) | ||
275 | { | 268 | { |
276 | if(self_public_key[i] < 16) | 269 | if(self_public_key[i] < (PUB_KEY_BYTES/2)) |
277 | strcpy(idstring1[i],"0"); | 270 | strcpy(idstring1[i],"0"); |
278 | else | 271 | else |
279 | strcpy(idstring1[i], ""); | 272 | strcpy(idstring1[i], ""); |
280 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 273 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
281 | } | 274 | } |
282 | strcpy(users_id,"[i] your ID: "); | 275 | strcpy(users_id,"[i] your ID: "); |
283 | for (i=0; i<32; i++) { | 276 | int j; |
284 | strcat(users_id,idstring1[i]); | 277 | for (j = 0; j < PUB_KEY_BYTES; j++) { |
285 | strcat(users_id,idstring2[i]); | 278 | strcat(users_id,idstring1[j]); |
279 | strcat(users_id,idstring2[j]); | ||
286 | } | 280 | } |
287 | 281 | ||
288 | do_header(); | 282 | do_header(); |
289 | |||
290 | IP_Port bootstrap_ip_port; | 283 | IP_Port bootstrap_ip_port; |
291 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 284 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
292 | int resolved_address = resolve_addr(argv[1]); | 285 | int resolved_address = resolve_addr(argv[1]); |
@@ -296,12 +289,9 @@ int main(int argc, char *argv[]) | |||
296 | exit(1); | 289 | exit(1); |
297 | 290 | ||
298 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 291 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
299 | |||
300 | int c; | 292 | int c; |
301 | int on = 0; | 293 | int on = 0; |
302 | |||
303 | _beginthread(get_input, 0, NULL); | 294 | _beginthread(get_input, 0, NULL); |
304 | |||
305 | while(1) { | 295 | while(1) { |
306 | if (on == 1 && DHT_isconnected() == -1) { | 296 | if (on == 1 && DHT_isconnected() == -1) { |
307 | printf("\n---------------------------------"); | 297 | printf("\n---------------------------------"); |
@@ -309,16 +299,13 @@ int main(int argc, char *argv[]) | |||
309 | printf("\n---------------------------------\n\n"); | 299 | printf("\n---------------------------------\n\n"); |
310 | on = 0; | 300 | on = 0; |
311 | } | 301 | } |
312 | |||
313 | if (on == 0 && DHT_isconnected()) { | 302 | if (on == 0 && DHT_isconnected()) { |
314 | printf("\n[i] Connected to DHT"); | 303 | printf("\n[i] Connected to DHT"); |
315 | printf("\n---------------------------------\n\n"); | 304 | printf("\n---------------------------------\n\n"); |
316 | on = 1; | 305 | on = 1; |
317 | } | 306 | } |
318 | |||
319 | doMessenger(); | 307 | doMessenger(); |
320 | Sleep(1); | 308 | Sleep(1); |
321 | } | 309 | } |
322 | |||
323 | return 0; | 310 | return 0; |
324 | } \ No newline at end of file | 311 | } \ No newline at end of file |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 7861be1c..84d4a778 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -27,5 +27,6 @@ | |||
27 | #include "../core/network.h" | 27 | #include "../core/network.h" |
28 | 28 | ||
29 | #define STRING_LENGTH 256 | 29 | #define STRING_LENGTH 256 |
30 | #define PUB_KEY_BYTES 32 | ||
30 | 31 | ||
31 | #endif \ No newline at end of file | 32 | #endif \ No newline at end of file |