/util.c (4b7aa265a4a8cd5fbfd719861f0c93261128e7a8) (3159 bytes) (mode 100644) (type blob)
#include "log.h"
#include "util.h"
#include <string.h>
#include <tox/tox.h>
#include <stdio.h>
#include <stdlib.h>
void writechecksum(uint8_t *address)
{
uint8_t *checksum = address + 36;
uint32_t i;
for (i = 0; i < 36; ++i)
checksum[i % 2] ^= address[i];
}
/* From utox/util.c */
void to_hex(char_t *a, const char_t *p, int size)
{
char_t b, c;
const char_t *end = p + size;
while(p != end) {
b = *p++;
c = (b & 0xF);
b = (b >> 4);
if(b < 10) {
*a++ = b + '0';
} else {
*a++ = b - 10 + 'A';
}
if(c < 10) {
*a++ = c + '0';
} else {
*a++ = c - 10 + 'A';
}
}
a = '\0';
}
/* From utox/util.c */
void id_to_string(char_t *dest, const char_t *src)
{
to_hex(dest, src, TOX_FRIEND_ADDRESS_SIZE);
}
/* From utox/util.c */
int string_to_id(char_t *w, char_t *a)
{
char_t *end = w + TOX_FRIEND_ADDRESS_SIZE;
while(w != end) {
char_t c, v;
c = *a++;
if(c >= '0' && c <= '9') {
v = (c - '0') << 4;
} else if(c >= 'A' && c <= 'F') {
v = (c - 'A' + 10) << 4;
} else if(c >= 'a' && c <= 'f') {
v = (c - 'a' + 10) << 4;
} else {
return 0;
}
c = *a++;
if(c >= '0' && c <= '9') {
v |= (c - '0');
} else if(c >= 'A' && c <= 'F') {
v |= (c - 'A' + 10);
} else if(c >= 'a' && c <= 'f') {
v |= (c - 'a' + 10);
} else {
return 0;
}
*w++ = v;
}
return 1;
}
/* Parse the -L parameter */
/* 0 = success */
int parse_local_port_forward(char *string, int *local_port, char **hostname, int *remote_port)
{
char *lport;
char *host;
char *rport;
lport = strtok(string, ":");
host = strtok(NULL, ":");
rport = strtok(NULL, ":");
if(!lport || !host || !rport)
{
return -1;
}
*local_port = atoi(lport);
*hostname = host;
*remote_port = atoi(rport);
return 0;
}
/* Parse the -P parameter */
/* 0 = success */
int parse_pipe_port_forward(char *string, char **hostname, int *remote_port)
{
char *host;
char *rport;
host = strtok(string, ":");
rport = strtok(NULL, ":");
if(!host || !rport)
{
return -1;
}
*hostname = host;
*remote_port = atoi(rport);
return 0;
}
void* file_raw(char *path, uint32_t *size)
{
FILE *file;
char *data;
int len;
file = fopen(path, "rb");
if(!file) {
log_printf(L_WARNING, "File not found (%s)\n", path);
return NULL;
}
fseek(file, 0, SEEK_END);
len = ftell(file);
data = malloc(len);
if(!data) {
fclose(file);
return NULL;
}
fseek(file, 0, SEEK_SET);
if(fread(data, len, 1, file) != 1) {
log_printf(L_WARNING, "Read error (%s)\n", path);
fclose(file);
free(data);
return NULL;
}
fclose(file);
log_printf(L_DEBUG, "Read %u bytes (%s)\n", len, path);
if(size) {
*size = len;
}
return data;
}
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
223 |
edf6645defd9952878f1f84d5d994b7965041a77 |
.gitignore |
100644 |
blob |
631 |
c0d340c3c80824fc29c870f595ba899d22b6ad2e |
BUILD.md |
100644 |
blob |
35058 |
2061be2b732ea86101a7c0d5f4df0bbbfb830a30 |
LICENSE.md |
100644 |
blob |
625 |
09a266ab0e335693d1c6190031a0ea57b78e4ec0 |
Makefile |
100644 |
blob |
4746 |
5fb29214099ee1d4c2643e0f9ece65b6dfc0c502 |
README.md |
100644 |
blob |
14347 |
58b31ab2400da8f31012d114a7f06856d39abea7 |
client.c |
100644 |
blob |
742 |
1ac50085e349329987ff615195ecfde70ab35088 |
client.h |
100644 |
blob |
1484 |
c7627d9efe446dec9006ca1be763d7b0e93e304d |
log.c |
100644 |
blob |
620 |
25b19f7a9e487e8ef743253f15cf92963c310e54 |
log.h |
100644 |
blob |
26054 |
f57603edf39362a353a4a9059ad89008fa989f4f |
main.c |
100644 |
blob |
2358 |
a3890ca5ffc06b7d7494512905e14bc11c0ceac7 |
main.h |
040000 |
tree |
- |
4a59483ee964610826460af90011bc8dfbf344db |
scripts |
100644 |
blob |
3878 |
2511c521a73cc63e177c67a4693a2b4aca612c9c |
tox_bootstrap.h |
100644 |
blob |
12536 |
75e9dc5ed9399120416e8da5f24d1ccde41cf901 |
utarray.h |
100644 |
blob |
61492 |
7205c67efa27c66884c8d4d1c8a105d4854a0548 |
uthash.h |
100644 |
blob |
3159 |
4b7aa265a4a8cd5fbfd719861f0c93261128e7a8 |
util.c |
100644 |
blob |
380 |
30d24a59885fa184228e8fd29c87efee48fd5ac8 |
util.h |
100644 |
blob |
55882 |
b5f3f04c104785a57d8280c37c1b19b36068e56e |
utlist.h |
100644 |
blob |
11555 |
867442c843dbe6bf096a488e3ce9ec6323809f7f |
utstring.h |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/gdr/tuntox
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/gdr/tuntox
Clone this repository using git:
git clone git://git.rocketgit.com/user/gdr/tuntox
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main