summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Kowalski <kostyakow42@gmail.com>2013-07-27 12:10:41 -0400
committerKonstantin Kowalski <kostyakow42@gmail.com>2013-07-27 12:10:41 -0400
commitb3fa1fc8f48aea08da1552d76397e959cd0aa690 (patch)
tree53511a8fffa0c019b7bb6d92815cca2cd5969a6b
parent4edf2207fe1fe41e5ad6a17067eb91bd9fdbaef9 (diff)
[fixed]created new files misc_tools.(c|h) and moved hex_string_to_bin() there.
-rw-r--r--.gitignore1
-rw-r--r--other/DHT_bootstrap.c17
-rw-r--r--other/cmake/DHT_bootstrap.cmake2
-rw-r--r--testing/DHT_cryptosendfiletest.c17
-rw-r--r--testing/DHT_test.c17
-rw-r--r--testing/Messenger_test.c17
-rw-r--r--testing/cmake/DHT_cryptosendfiletest.cmake4
-rw-r--r--testing/cmake/DHT_test.cmake2
-rw-r--r--testing/cmake/Messenger_test.cmake2
-rw-r--r--testing/cmake/nTox.cmake2
-rw-r--r--testing/misc_tools.c43
-rw-r--r--testing/misc_tools.h29
-rw-r--r--testing/nTox.c16
13 files changed, 85 insertions, 84 deletions
diff --git a/.gitignore b/.gitignore
index 73c7919e..010561a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ cmake_install.cmake
11install_manifest.txt 11install_manifest.txt
12 12
13testing/data 13testing/data
14*~
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 8942c237..19714e70 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -29,6 +29,7 @@
29 29
30#include "../core/DHT.h" 30#include "../core/DHT.h"
31#include "../core/friend_requests.h" 31#include "../core/friend_requests.h"
32#include "../testing/misc_tools.h"
32 33
33//Sleep function (x = milliseconds) 34//Sleep function (x = milliseconds)
34#ifdef WIN32 35#ifdef WIN32
@@ -41,21 +42,7 @@
41 42
42#define PORT 33445 43#define PORT 33445
43 44
44//TODO: rewrite 45
45unsigned char * hex_string_to_bin(char hex_string[])
46{
47 size_t len = strlen(hex_string);
48 unsigned char * val = malloc(len);
49 char * pos = hex_string;
50 int i=0;
51 while(i < len)
52 {
53 sscanf(pos,"%2hhx",&val[i]);
54 pos+=2;
55 i++;
56 }
57 return val;
58}
59 46
60void manage_keys() 47void manage_keys()
61{ 48{
diff --git a/other/cmake/DHT_bootstrap.cmake b/other/cmake/DHT_bootstrap.cmake
index c3c313ae..e2b164ba 100644
--- a/other/cmake/DHT_bootstrap.cmake
+++ b/other/cmake/DHT_bootstrap.cmake
@@ -4,6 +4,6 @@ project(DHT_bootstrap C)
4set(exe_name DHT_bootstrap) 4set(exe_name DHT_bootstrap)
5 5
6add_executable(${exe_name} 6add_executable(${exe_name}
7 DHT_bootstrap.c) 7 DHT_bootstrap.c ../testing/misc_tools.c)
8 8
9linkCoreLibraries(${exe_name}) 9linkCoreLibraries(${exe_name})
diff --git a/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c
index 5c3a0256..c7c33531 100644
--- a/testing/DHT_cryptosendfiletest.c
+++ b/testing/DHT_cryptosendfiletest.c
@@ -38,6 +38,7 @@
38#include "../core/network.h" 38#include "../core/network.h"
39#include "../core/DHT.h" 39#include "../core/DHT.h"
40#include "../core/net_crypto.h" 40#include "../core/net_crypto.h"
41#include "misc_tools.h"
41 42
42#include <string.h> 43#include <string.h>
43 44
@@ -60,22 +61,6 @@ void printip(IP_Port ip_port)
60 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)); 61 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));
61} 62}
62 63
63//TODO: rewrite
64unsigned char * hex_string_to_bin(char hex_string[])
65{
66 size_t len = strlen(hex_string);
67 unsigned char * val = malloc(len);
68 char * pos = hex_string;
69 int i=0;
70 while(i < len)
71 {
72 sscanf(pos,"%2hhx",&val[i]);
73 pos+=2;
74 i++;
75 }
76 return val;
77}
78
79uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; 64uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
80 65
81int main(int argc, char *argv[]) 66int main(int argc, char *argv[])
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index d14e1577..2e9c2ac2 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -30,6 +30,7 @@
30//#include "../core/network.h" 30//#include "../core/network.h"
31#include "../core/DHT.c" 31#include "../core/DHT.c"
32#include "../core/friend_requests.c" 32#include "../core/friend_requests.c"
33#include "misc_tools.h"
33 34
34#include <string.h> 35#include <string.h>
35 36
@@ -114,22 +115,6 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
114 printf("\n--------------------END-----------------------------\n\n\n"); 115 printf("\n--------------------END-----------------------------\n\n\n");
115} 116}
116 117
117//TODO: rewrite
118unsigned char * hex_string_to_bin(char hex_string[])
119{
120 size_t len = strlen(hex_string);
121 unsigned char * val = malloc(len);
122 char * pos = hex_string;
123 int i=0;
124 while(i < len)
125 {
126 sscanf(pos,"%2hhx",&val[i]);
127 pos+=2;
128 i++;
129 }
130 return val;
131}
132
133int main(int argc, char *argv[]) 118int main(int argc, char *argv[])
134{ 119{
135 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); 120 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index f38eb962..0518d284 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -38,6 +38,7 @@
38 */ 38 */
39 39
40#include "../core/Messenger.h" 40#include "../core/Messenger.h"
41#include "misc_tools.h"
41 42
42#ifdef WIN32 43#ifdef WIN32
43 44
@@ -50,22 +51,6 @@
50 51
51#endif 52#endif
52 53
53//TODO: rewrite
54unsigned char * hex_string_to_bin(char hex_string[])
55{
56 size_t len = strlen(hex_string);
57 unsigned char * val = malloc(len);
58 char * pos = hex_string;
59 int i=0;
60 while(i < len)
61 {
62 sscanf(pos,"%2hhx",&val[i]);
63 pos+=2;
64 i++;
65 }
66 return val;
67}
68
69void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) 54void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
70{ 55{
71 printf("Friend request recieved from: \n"); 56 printf("Friend request recieved from: \n");
diff --git a/testing/cmake/DHT_cryptosendfiletest.cmake b/testing/cmake/DHT_cryptosendfiletest.cmake
index 8d6079f8..c98a2bcd 100644
--- a/testing/cmake/DHT_cryptosendfiletest.cmake
+++ b/testing/cmake/DHT_cryptosendfiletest.cmake
@@ -4,6 +4,6 @@ project(DHT_cryptosendfiletest C)
4set(exe_name DHT_cryptosendfiletest) 4set(exe_name DHT_cryptosendfiletest)
5 5
6add_executable(${exe_name} 6add_executable(${exe_name}
7 DHT_cryptosendfiletest.c) 7 DHT_cryptosendfiletest.c misc_tools.c)
8 8
9linkCoreLibraries(${exe_name}) \ No newline at end of file 9linkCoreLibraries(${exe_name})
diff --git a/testing/cmake/DHT_test.cmake b/testing/cmake/DHT_test.cmake
index bcde4370..74fdf35d 100644
--- a/testing/cmake/DHT_test.cmake
+++ b/testing/cmake/DHT_test.cmake
@@ -4,6 +4,6 @@ project(DHT_test C)
4set(exe_name DHT_test) 4set(exe_name DHT_test)
5 5
6add_executable(${exe_name} 6add_executable(${exe_name}
7 DHT_test.c) 7 DHT_test.c misc_tools.c)
8 8
9linkCoreLibraries(${exe_name}) 9linkCoreLibraries(${exe_name})
diff --git a/testing/cmake/Messenger_test.cmake b/testing/cmake/Messenger_test.cmake
index a85e043d..b2f54d0a 100644
--- a/testing/cmake/Messenger_test.cmake
+++ b/testing/cmake/Messenger_test.cmake
@@ -4,6 +4,6 @@ project(Messenger_test C)
4set(exe_name Messenger_test) 4set(exe_name Messenger_test)
5 5
6add_executable(${exe_name} 6add_executable(${exe_name}
7 Messenger_test.c) 7 Messenger_test.c misc_tools.c)
8 8
9linkCoreLibraries(${exe_name}) 9linkCoreLibraries(${exe_name})
diff --git a/testing/cmake/nTox.cmake b/testing/cmake/nTox.cmake
index 1656bc80..4c6905e5 100644
--- a/testing/cmake/nTox.cmake
+++ b/testing/cmake/nTox.cmake
@@ -4,7 +4,7 @@ project(nTox C)
4set(exe_name nTox) 4set(exe_name nTox)
5 5
6add_executable(${exe_name} 6add_executable(${exe_name}
7 nTox.c) 7 nTox.c misc_tools.c)
8 8
9target_link_libraries(${exe_name} ncurses) 9target_link_libraries(${exe_name} ncurses)
10 10
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
new file mode 100644
index 00000000..34d64bf4
--- /dev/null
+++ b/testing/misc_tools.c
@@ -0,0 +1,43 @@
1/* misc_tools.c
2 *
3 * Miscellaneous functions and data structures for doing random things.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include "misc_tools.h"
25
26#include <string.h>
27#include <stdlib.h>
28#include <stdio.h> //for sscanf
29
30//TODO: rewrite
31unsigned char * hex_string_to_bin(char hex_string[])
32{
33 size_t len = strlen(hex_string);
34 unsigned char *val = malloc(len);
35 char *pos = hex_string;
36 int i=0;
37 while(i < len) {
38 sscanf(pos,"%2hhx",&val[i]);
39 pos+=2;
40 i++;
41 }
42 return val;
43} \ No newline at end of file
diff --git a/testing/misc_tools.h b/testing/misc_tools.h
new file mode 100644
index 00000000..29b37ce5
--- /dev/null
+++ b/testing/misc_tools.h
@@ -0,0 +1,29 @@
1/* misc_tools.h
2 *
3 * Miscellaneous functions and data structures for doing random things.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#ifndef MISC_TOOLS_H
25#define MISC_TOOLS_H
26
27unsigned char * hex_string_to_bin(char hex_string[]);
28
29#endif // MISC_TOOLS_H \ No newline at end of file
diff --git a/testing/nTox.c b/testing/nTox.c
index 27654191..cb38bb9f 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "nTox.h" 24#include "nTox.h"
25#include "misc_tools.h"
25#include <stdio.h> 26#include <stdio.h>
26#include <time.h> 27#include <time.h>
27#ifdef WIN32 28#ifdef WIN32
@@ -46,21 +47,6 @@ void new_lines(char *line)
46 do_refresh(); 47 do_refresh();
47} 48}
48 49
49//TODO: rewrite
50unsigned char * hex_string_to_bin(char hex_string[])
51{
52 size_t len = strlen(hex_string);
53 unsigned char * val = malloc(len);
54 char * pos = hex_string;
55 int i=0;
56 while(i < len) {
57 sscanf(pos,"%2hhx",&val[i]);
58 pos+=2;
59 i++;
60 }
61 return val;
62}
63
64void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) 50void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
65{ 51{
66 if (line[0] == '/') { 52 if (line[0] == '/') {