2018-08-08 06:12:38 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-1.0-only
|
|
|
|
// Copyright (C) 2018 Ludvig Strigeus <info@tunsafe.com>. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "tunsafe_types.h"
|
|
|
|
|
2018-09-15 11:22:05 -05:00
|
|
|
char *base64_encode(const uint8 *input, size_t length, char *output, size_t output_size, size_t *actual_size);
|
2018-12-10 16:13:54 -06:00
|
|
|
bool base64_decode(const uint8 *in, size_t inLen, uint8 *out, size_t *outLen);
|
2018-08-08 06:12:38 -05:00
|
|
|
bool IsOnlyZeros(const uint8 *data, size_t data_size);
|
|
|
|
|
|
|
|
int RunCommand(const char *fmt, ...);
|
2018-10-19 06:40:59 -05:00
|
|
|
typedef void Logger(int type, const char *msg);
|
2018-08-08 06:12:38 -05:00
|
|
|
extern Logger *g_logger;
|
|
|
|
|
|
|
|
|
2018-08-11 20:27:14 -05:00
|
|
|
void *memdup(const void *p, size_t size);
|
|
|
|
char *my_strndup(const char *p, size_t size);
|
|
|
|
|
|
|
|
size_t my_strlcpy(char *dst, size_t dstsize, const char *src);
|
|
|
|
|
|
|
|
template<typename T, typename U> static inline T postinc(T&x, U v) {
|
|
|
|
T t = x;
|
|
|
|
x += v;
|
|
|
|
return t;
|
|
|
|
}
|
2018-09-15 11:22:05 -05:00
|
|
|
|
|
|
|
template<typename T, typename U> static inline T exch(T&x, U v) {
|
|
|
|
T t = x;
|
|
|
|
x = v;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T> static inline T exch_null(T&x) {
|
|
|
|
T t = x;
|
|
|
|
x = NULL;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_space(uint8_t c);
|
|
|
|
void OsGetRandomBytes(uint8 *dst, size_t dst_size);
|
|
|
|
bool ParseConfigKeyValue(char *m, std::vector<std::pair<char *, char*>> *result);
|
|
|
|
bool ParseHexString(const char *text, void *data, size_t data_size);
|
|
|
|
void PrintHexString(const void *data, size_t data_size, char *result);
|
|
|
|
void SplitString(char *s, int separator, std::vector<char*> *components);
|
2018-10-07 12:38:58 -05:00
|
|
|
bool ParseBase64Key(const char *s, uint8 key[32]);
|
|
|
|
|
|
|
|
|
|
|
|
uint64 OsGetMilliseconds();
|
|
|
|
void InitOsxGetMilliseconds();
|
|
|
|
void OsInterruptibleSleep(int millis);
|
|
|
|
void OsGetTimestampTAI64N(uint8 dst[12]);
|
2018-10-07 12:41:58 -05:00
|
|
|
|
|
|
|
struct CommandLineOutput {
|
|
|
|
const char *filename_to_load;
|
|
|
|
const char *interface_name;
|
|
|
|
bool daemon;
|
|
|
|
};
|
|
|
|
int HandleCommandLine(int argc, char **argv, CommandLineOutput *output);
|