summaryrefslogtreecommitdiff
path: root/testing/nTox_win32.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-31 10:25:29 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-31 10:25:29 -0400
commitbdd13d1954e0befb1682cf1f6727e9b382450ed8 (patch)
tree61ab2649c5515c1f0bd8b3506fb7fd7be7d15737 /testing/nTox_win32.c
parent55a2e59a64d879440667b9d672a3878fa7fe5d2e (diff)
parent17e64b3ee50605cbc15f195f770dacf31039e121 (diff)
Merge branch 'master' of https://github.com/JFreegman/ProjectTox-Core into JFreegman-master
Conflicts: testing/nTox.c
Diffstat (limited to 'testing/nTox_win32.c')
-rw-r--r--testing/nTox_win32.c87
1 files changed, 37 insertions, 50 deletions
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
29uint8_t pending_requests[256][CLIENT_ID_SIZE]; 29uint8_t pending_requests[256][CLIENT_ID_SIZE];
30uint8_t num_requests; 30uint8_t num_requests = 0;
31 31
32char line[STRING_LENGTH]; 32char line[STRING_LENGTH];
33char users_id[200]; 33char users_id[200];
@@ -88,14 +88,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
88void load_key() 88void 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
119void line_eval(char* line) 117void 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