created new files misc_tools.(c|h) and moved hex_string_to_bin() there.

This commit is contained in:
Konstantin Kowalski 2013-07-27 10:53:01 -04:00
parent 4edf2207fe
commit 77ebbed91b
8 changed files with 80 additions and 79 deletions

View File

@ -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})

43
core/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
core/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

@ -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()
{

View File

@ -38,6 +38,7 @@
#include "../core/network.h"
#include "../core/DHT.h"
#include "../core/net_crypto.h"
#include "../core/misc_tools.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));
}
//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[])

View File

@ -30,6 +30,7 @@
//#include "../core/network.h"
#include "../core/DHT.c"
#include "../core/friend_requests.c"
#include "../core/misc_tools.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");
}
//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);

View File

@ -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");

View File

@ -22,6 +22,7 @@
*/
#include "nTox.h"
#include "../core/misc_tools.h"
#include <stdio.h>
#include <time.h>
#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] == '/') {