diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 6ddd5b9b..7e5c119a 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -12,6 +12,7 @@ set(core_sources
net_crypto.c
friend_requests.c
LAN_discovery.c
- Messenger.c)
+ Messenger.c
+ misc_tools.c)
add_library(core ${core_sources})
diff --git a/core/misc_tools.c b/core/misc_tools.c
new file mode 100644
index 00000000..34d64bf4
--- /dev/null
+++ b/core/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/core/misc_tools.h b/core/misc_tools.h
new file mode 100644
index 00000000..29b37ce5
--- /dev/null
+++ b/core/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/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 8942c237..61901a15 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 "../core/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/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c
index 5c3a0256..23423497 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 "../core/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 d14e1577..92845b7e 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 "../core/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 f38eb962..6ad5c7dd 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -38,6 +38,7 @@
*/
#include "../core/Messenger.h"
+#include "../core/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/nTox.c b/testing/nTox.c
index 27654191..e202a697 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -22,6 +22,7 @@
*/
#include "nTox.h"
+#include "../core/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] == '/') {