From 207c067cf22d65cdfc08e8659fb8dd575e248053 Mon Sep 17 00:00:00 2001 From: Stuart Banks Date: Wed, 31 Jul 2013 02:15:01 -0400 Subject: Clean up/format code --- testing/nTox_win32.c | 85 ++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 49 deletions(-) (limited to 'testing/nTox_win32.c') diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 3a9caaf5..3286bb3a 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -88,14 +88,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { void load_key() { FILE *data_file = NULL; - - if ((data_file = fopen("data", "r"))) { + data_file = fopen("data","r"); + if (data_file) { fseek(data_file, 0, SEEK_END); int size = ftell(data_file); fseek(data_file, 0, SEEK_SET); uint8_t data[size]; - - if(fread(data, sizeof(uint8_t), size, data_file) != size) { + if (fread(data, sizeof(uint8_t), size, data_file) != size) { printf("\n[i] Could not read the data file. Exiting."); exit(1); } @@ -107,23 +106,23 @@ void load_key() Messenger_save(data); data_file = fopen("data", "w"); - if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { + if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { printf("\n[i] Could not write data to file. Exiting."); exit(1); } } - fclose(data_file); } void line_eval(char* line) { if(line[0] == '/') { + char inpt_command = line[1]; /* Add friend */ - if(line[1] == 'f') { + if(inpt_command == 'f') { int i; char temp_id[128]; - for (i=0; i<128; i++) + for (i = 0; i < 128; i++) temp_id[i] = line[i+3]; int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); char numstring[100]; @@ -131,28 +130,27 @@ void line_eval(char* line) printf(numstring); } - else if (line[1] == 'r') { + else if (inpt_command == 'r') { do_header(); printf("\n\n"); } - else if (line[1] == 'l') { + else if (inpt_command == 'l') { printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); int i; - - for (i=0; i < getnumfriends(); i++) { + for (i = 0; i < getnumfriends(); i++) { char name[MAX_NAME_LENGTH]; getname(i, (uint8_t*)name); printf("[%d] %s\n\n", i, (uint8_t*)name); } } - else if (line[1] == 'd') { + else if (inpt_command == 'd') { size_t len = strlen(line); char numstring[len-3]; int i; - for (i=0; i\n", argv[0]); exit(0); } - if (initMessenger() == -1) { printf("initMessenger failed"); exit(0); } - if (argc > 4) { if(strncmp(argv[4], "nokey", 6) < 0) { } @@ -267,26 +261,25 @@ int main(int argc, char *argv[]) m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); - - char idstring1[32][5]; - char idstring2[32][5]; - uint32_t i; - for(i = 0; i < 32; i++) + char idstring1[PUB_KEY_BYTES][5]; + char idstring2[PUB_KEY_BYTES][5]; + int i; + for(i = 0; i < PUB_KEY_BYTES; i++) { - if(self_public_key[i] < 16) + if(self_public_key[i] < (PUB_KEY_BYTES/2)) strcpy(idstring1[i],"0"); else strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } strcpy(users_id,"[i] your ID: "); - for (i=0; i<32; i++) { - strcat(users_id,idstring1[i]); - strcat(users_id,idstring2[i]); + int j; + for (j = 0; j < PUB_KEY_BYTES; j++) { + strcat(users_id,idstring1[j]); + strcat(users_id,idstring2[j]); } do_header(); - IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); @@ -296,12 +289,9 @@ int main(int argc, char *argv[]) exit(1); DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); - int c; int on = 0; - _beginthread(get_input, 0, NULL); - while(1) { if (on == 1 && DHT_isconnected() == -1) { printf("\n---------------------------------"); @@ -309,15 +299,12 @@ int main(int argc, char *argv[]) printf("\n---------------------------------\n\n"); on = 0; } - if (on == 0 && DHT_isconnected()) { printf("\n[i] Connected to DHT"); printf("\n---------------------------------\n\n"); on = 1; } - doMessenger(); } - return 0; } \ No newline at end of file -- cgit v1.2.3 From 17e64b3ee50605cbc15f195f770dacf31039e121 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 31 Jul 2013 05:52:08 -0400 Subject: initialize num_requests --- testing/nTox.c | 3 ++- testing/nTox_win32.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'testing/nTox_win32.c') diff --git a/testing/nTox.c b/testing/nTox.c index 5f184407..54f973d0 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -38,7 +38,7 @@ char line[STRING_LENGTH]; int x, y; uint8_t pending_requests[256][CLIENT_ID_SIZE]; -uint8_t num_requests; +uint8_t num_requests = 0; void new_lines(char *line) { @@ -57,6 +57,7 @@ void print_friendlist() new_lines("[i] Friend List:"); uint32_t i; for (i = 0; i <= num_requests; i++) { + printf ("num_resusts: %d\n", num_requests); char fstring[128]; getname(i, (uint8_t*)name); diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 3286bb3a..27ab6a77 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -27,7 +27,7 @@ #include uint8_t pending_requests[256][CLIENT_ID_SIZE]; -uint8_t num_requests; +uint8_t num_requests = 0; char line[STRING_LENGTH]; char users_id[200]; -- cgit v1.2.3