diff --git a/.gitignore b/.gitignore index 73c7919ee..010561a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ cmake_install.cmake install_manifest.txt testing/data +*~ diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 8942c237c..19714e70b 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -29,6 +29,7 @@ #include "../core/DHT.h" #include "../core/friend_requests.h" +#include "../testing/misc_tools.h" //Sleep function (x = milliseconds) #ifdef WIN32 @@ -41,21 +42,7 @@ #define PORT 33445 -//TODO: rewrite -unsigned char * hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char * val = malloc(len); - char * pos = hex_string; - int i=0; - while(i < len) - { - sscanf(pos,"%2hhx",&val[i]); - pos+=2; - i++; - } - return val; -} + void manage_keys() { diff --git a/other/cmake/DHT_bootstrap.cmake b/other/cmake/DHT_bootstrap.cmake index c3c313ae6..e2b164bab 100644 --- a/other/cmake/DHT_bootstrap.cmake +++ b/other/cmake/DHT_bootstrap.cmake @@ -4,6 +4,6 @@ project(DHT_bootstrap C) set(exe_name DHT_bootstrap) add_executable(${exe_name} - DHT_bootstrap.c) + DHT_bootstrap.c ../testing/misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c index 5c3a02568..c7c335317 100644 --- a/testing/DHT_cryptosendfiletest.c +++ b/testing/DHT_cryptosendfiletest.c @@ -38,6 +38,7 @@ #include "../core/network.h" #include "../core/DHT.h" #include "../core/net_crypto.h" +#include "misc_tools.h" #include @@ -60,22 +61,6 @@ void printip(IP_Port ip_port) printf("\nIP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); } -//TODO: rewrite -unsigned char * hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char * val = malloc(len); - char * pos = hex_string; - int i=0; - while(i < len) - { - sscanf(pos,"%2hhx",&val[i]); - pos+=2; - i++; - } - return val; -} - uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; int main(int argc, char *argv[]) diff --git a/testing/DHT_test.c b/testing/DHT_test.c index d14e1577a..2e9c2ac27 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -30,6 +30,7 @@ //#include "../core/network.h" #include "../core/DHT.c" #include "../core/friend_requests.c" +#include "misc_tools.h" #include @@ -114,22 +115,6 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) printf("\n--------------------END-----------------------------\n\n\n"); } -//TODO: rewrite -unsigned char * hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char * val = malloc(len); - char * pos = hex_string; - int i=0; - while(i < len) - { - sscanf(pos,"%2hhx",&val[i]); - pos+=2; - i++; - } - return val; -} - int main(int argc, char *argv[]) { //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index f38eb9622..0518d2848 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -38,6 +38,7 @@ */ #include "../core/Messenger.h" +#include "misc_tools.h" #ifdef WIN32 @@ -50,22 +51,6 @@ #endif -//TODO: rewrite -unsigned char * hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char * val = malloc(len); - char * pos = hex_string; - int i=0; - while(i < len) - { - sscanf(pos,"%2hhx",&val[i]); - pos+=2; - i++; - } - return val; -} - void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) { printf("Friend request recieved from: \n"); diff --git a/testing/cmake/DHT_cryptosendfiletest.cmake b/testing/cmake/DHT_cryptosendfiletest.cmake index 8d6079f86..c98a2bcd4 100644 --- a/testing/cmake/DHT_cryptosendfiletest.cmake +++ b/testing/cmake/DHT_cryptosendfiletest.cmake @@ -4,6 +4,6 @@ project(DHT_cryptosendfiletest C) set(exe_name DHT_cryptosendfiletest) add_executable(${exe_name} - DHT_cryptosendfiletest.c) + DHT_cryptosendfiletest.c misc_tools.c) -linkCoreLibraries(${exe_name}) \ No newline at end of file +linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/DHT_test.cmake b/testing/cmake/DHT_test.cmake index bcde4370f..74fdf35d2 100644 --- a/testing/cmake/DHT_test.cmake +++ b/testing/cmake/DHT_test.cmake @@ -4,6 +4,6 @@ project(DHT_test C) set(exe_name DHT_test) add_executable(${exe_name} - DHT_test.c) + DHT_test.c misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/Messenger_test.cmake b/testing/cmake/Messenger_test.cmake index a85e043d3..b2f54d0a9 100644 --- a/testing/cmake/Messenger_test.cmake +++ b/testing/cmake/Messenger_test.cmake @@ -4,6 +4,6 @@ project(Messenger_test C) set(exe_name Messenger_test) add_executable(${exe_name} - Messenger_test.c) + Messenger_test.c misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/nTox.cmake b/testing/cmake/nTox.cmake index 1656bc80e..4c6905e5b 100644 --- a/testing/cmake/nTox.cmake +++ b/testing/cmake/nTox.cmake @@ -4,7 +4,7 @@ project(nTox C) set(exe_name nTox) add_executable(${exe_name} - nTox.c) + nTox.c misc_tools.c) target_link_libraries(${exe_name} ncurses) diff --git a/testing/misc_tools.c b/testing/misc_tools.c new file mode 100644 index 000000000..34d64bf49 --- /dev/null +++ b/testing/misc_tools.c @@ -0,0 +1,43 @@ +/* misc_tools.c + * + * Miscellaneous functions and data structures for doing random things. + * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#include "misc_tools.h" + +#include +#include +#include //for sscanf + +//TODO: rewrite +unsigned char * hex_string_to_bin(char hex_string[]) +{ + size_t len = strlen(hex_string); + unsigned char *val = malloc(len); + char *pos = hex_string; + int i=0; + while(i < len) { + sscanf(pos,"%2hhx",&val[i]); + pos+=2; + i++; + } + return val; +} \ No newline at end of file diff --git a/testing/misc_tools.h b/testing/misc_tools.h new file mode 100644 index 000000000..29b37ce5f --- /dev/null +++ b/testing/misc_tools.h @@ -0,0 +1,29 @@ +/* misc_tools.h + * + * Miscellaneous functions and data structures for doing random things. + * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#ifndef MISC_TOOLS_H +#define MISC_TOOLS_H + +unsigned char * hex_string_to_bin(char hex_string[]); + +#endif // MISC_TOOLS_H \ No newline at end of file diff --git a/testing/nTox.c b/testing/nTox.c index 276541919..cb38bb9fc 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -22,6 +22,7 @@ */ #include "nTox.h" +#include "misc_tools.h" #include #include #ifdef WIN32 @@ -46,21 +47,6 @@ void new_lines(char *line) do_refresh(); } -//TODO: rewrite -unsigned char * hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char * val = malloc(len); - char * pos = hex_string; - int i=0; - while(i < len) { - sscanf(pos,"%2hhx",&val[i]); - pos+=2; - i++; - } - return val; -} - void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') {