Merge pull request #117 from KostyaKow/master

created new files misc_tools.(c|h) and moved hex_string_to_bin() there.
This commit is contained in:
irungentoo 2013-07-27 09:32:43 -07:00
commit 8eb76e46a8
13 changed files with 86 additions and 84 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ cmake_install.cmake
install_manifest.txt install_manifest.txt
testing/data testing/data
*~

View File

@ -29,6 +29,7 @@
#include "../core/DHT.h" #include "../core/DHT.h"
#include "../core/friend_requests.h" #include "../core/friend_requests.h"
#include "../testing/misc_tools.h"
//Sleep function (x = milliseconds) //Sleep function (x = milliseconds)
#ifdef WIN32 #ifdef WIN32
@ -41,21 +42,7 @@
#define PORT 33445 #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() void manage_keys()
{ {

View File

@ -4,6 +4,6 @@ project(DHT_bootstrap C)
set(exe_name DHT_bootstrap) set(exe_name DHT_bootstrap)
add_executable(${exe_name} add_executable(${exe_name}
DHT_bootstrap.c) DHT_bootstrap.c ../testing/misc_tools.c)
linkCoreLibraries(${exe_name}) linkCoreLibraries(${exe_name})

View File

@ -38,6 +38,7 @@
#include "../core/network.h" #include "../core/network.h"
#include "../core/DHT.h" #include "../core/DHT.h"
#include "../core/net_crypto.h" #include "../core/net_crypto.h"
#include "misc_tools.h"
#include <string.h> #include <string.h>
@ -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)); 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]; uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -30,6 +30,7 @@
//#include "../core/network.h" //#include "../core/network.h"
#include "../core/DHT.c" #include "../core/DHT.c"
#include "../core/friend_requests.c" #include "../core/friend_requests.c"
#include "misc_tools.h"
#include <string.h> #include <string.h>
@ -114,22 +115,6 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
printf("\n--------------------END-----------------------------\n\n\n"); 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[]) int main(int argc, char *argv[])
{ {
//memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);

View File

@ -38,6 +38,7 @@
*/ */
#include "../core/Messenger.h" #include "../core/Messenger.h"
#include "misc_tools.h"
#ifdef WIN32 #ifdef WIN32
@ -50,22 +51,6 @@
#endif #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) void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
{ {
printf("Friend request recieved from: \n"); printf("Friend request recieved from: \n");

View File

@ -4,6 +4,6 @@ project(DHT_cryptosendfiletest C)
set(exe_name DHT_cryptosendfiletest) set(exe_name DHT_cryptosendfiletest)
add_executable(${exe_name} add_executable(${exe_name}
DHT_cryptosendfiletest.c) DHT_cryptosendfiletest.c misc_tools.c)
linkCoreLibraries(${exe_name}) linkCoreLibraries(${exe_name})

View File

@ -4,6 +4,6 @@ project(DHT_test C)
set(exe_name DHT_test) set(exe_name DHT_test)
add_executable(${exe_name} add_executable(${exe_name}
DHT_test.c) DHT_test.c misc_tools.c)
linkCoreLibraries(${exe_name}) linkCoreLibraries(${exe_name})

View File

@ -4,6 +4,6 @@ project(Messenger_test C)
set(exe_name Messenger_test) set(exe_name Messenger_test)
add_executable(${exe_name} add_executable(${exe_name}
Messenger_test.c) Messenger_test.c misc_tools.c)
linkCoreLibraries(${exe_name}) linkCoreLibraries(${exe_name})

View File

@ -4,7 +4,7 @@ project(nTox C)
set(exe_name nTox) set(exe_name nTox)
add_executable(${exe_name} add_executable(${exe_name}
nTox.c) nTox.c misc_tools.c)
target_link_libraries(${exe_name} ncurses) target_link_libraries(${exe_name} ncurses)

43
testing/misc_tools.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#include "misc_tools.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h> //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;
}

29
testing/misc_tools.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef MISC_TOOLS_H
#define MISC_TOOLS_H
unsigned char * hex_string_to_bin(char hex_string[]);
#endif // MISC_TOOLS_H

View File

@ -22,6 +22,8 @@
*/ */
#include "nTox.h" #include "nTox.h"
#include "misc_tools.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
@ -46,21 +48,6 @@ void new_lines(char *line)
do_refresh(); 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) void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
{ {
if (line[0] == '/') { if (line[0] == '/') {