mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-06-01 18:15:31 +00:00
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
This commit is contained in:
@@ -1,59 +1,83 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
#include <string>
|
||||
#include "../Streams/Stream.hpp"
|
||||
#include "../TextStreams/TextWriter.hpp"
|
||||
#include "Json.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
namespace Tesses::Framework::Serialization::Bencode {
|
||||
class BeArray;
|
||||
class BeDictionary;
|
||||
class BeString;
|
||||
using BeUndefined = std::monostate;
|
||||
class BeArray;
|
||||
class BeDictionary;
|
||||
class BeString;
|
||||
using BeUndefined = std::monostate;
|
||||
|
||||
using BeToken = std::variant<BeUndefined,BeArray,BeDictionary,BeString,int64_t>;
|
||||
using BeToken =
|
||||
std::variant<BeUndefined, BeArray, BeDictionary, BeString, int64_t>;
|
||||
|
||||
class BeArray {
|
||||
public:
|
||||
std::vector<BeToken> tokens;
|
||||
};
|
||||
class BeArray {
|
||||
public:
|
||||
std::vector<BeToken> tokens;
|
||||
};
|
||||
|
||||
class BeDictionary {
|
||||
public:
|
||||
std::vector<std::pair<BeString,BeToken>> tokens;
|
||||
BeToken GetValue(BeString key) const;
|
||||
void SetValue(BeString key, BeToken value);
|
||||
};
|
||||
class BeString {
|
||||
public:
|
||||
BeString();
|
||||
BeString(const std::string& text);
|
||||
BeString(const char* text);
|
||||
BeString(const std::vector<uint8_t>& data);
|
||||
std::vector<uint8_t> data;
|
||||
class BeDictionary {
|
||||
public:
|
||||
std::vector<std::pair<BeString, BeToken>> tokens;
|
||||
BeToken GetValue(BeString key) const;
|
||||
void SetValue(BeString key, BeToken value);
|
||||
};
|
||||
class BeString {
|
||||
public:
|
||||
BeString();
|
||||
BeString(const std::string &text);
|
||||
BeString(const char *text);
|
||||
BeString(const std::vector<uint8_t> &data);
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
operator std::string() const;
|
||||
};
|
||||
bool operator==(const BeString& lStr, const BeString& rStr);
|
||||
bool operator==(const BeString& lStr, const std::string& rStr);
|
||||
bool operator==(const std::string& lStr, const BeString& rStr);
|
||||
bool operator==(const BeString& lStr, const char* rStr);
|
||||
bool operator==(const char* lStr, const BeString& rStr);
|
||||
|
||||
bool operator!=(const BeString& lStr, const BeString& rStr);
|
||||
bool operator!=(const BeString& lStr, const std::string& rStr);
|
||||
bool operator!=(const std::string& lStr, const BeString& rStr);
|
||||
bool operator!=(const BeString& lStr, const char* rStr);
|
||||
bool operator!=(const char* lStr, const BeString& rStr);
|
||||
|
||||
class Bencode {
|
||||
public:
|
||||
static void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,const BeToken& value);
|
||||
static BeToken Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
//This cannot be converted back to torrent, this may (probably will) be out of order
|
||||
static Json::JToken ToJson(const BeToken& tkn);
|
||||
//This may (probably will) be out of order
|
||||
static void Print(std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> writer, BeToken tkn);
|
||||
};
|
||||
}
|
||||
operator std::string() const;
|
||||
};
|
||||
bool operator==(const BeString &lStr, const BeString &rStr);
|
||||
bool operator==(const BeString &lStr, const std::string &rStr);
|
||||
bool operator==(const std::string &lStr, const BeString &rStr);
|
||||
bool operator==(const BeString &lStr, const char *rStr);
|
||||
bool operator==(const char *lStr, const BeString &rStr);
|
||||
|
||||
bool operator!=(const BeString &lStr, const BeString &rStr);
|
||||
bool operator!=(const BeString &lStr, const std::string &rStr);
|
||||
bool operator!=(const std::string &lStr, const BeString &rStr);
|
||||
bool operator!=(const BeString &lStr, const char *rStr);
|
||||
bool operator!=(const char *lStr, const BeString &rStr);
|
||||
|
||||
class Bencode {
|
||||
public:
|
||||
static void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
const BeToken &value);
|
||||
static BeToken
|
||||
Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
// This cannot be converted back to torrent, this may (probably will) be out
|
||||
// of order
|
||||
static Json::JToken ToJson(const BeToken &tkn);
|
||||
// This may (probably will) be out of order
|
||||
static void
|
||||
Print(std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> writer,
|
||||
BeToken tkn);
|
||||
};
|
||||
} // namespace Tesses::Framework::Serialization::Bencode
|
||||
@@ -1,82 +1,93 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Uuid.hpp"
|
||||
namespace Tesses::Framework::Serialization
|
||||
{
|
||||
|
||||
namespace Tesses::Framework::Serialization {
|
||||
|
||||
/**
|
||||
* @brief A bit converter
|
||||
*
|
||||
*
|
||||
*/
|
||||
class BitConverter {
|
||||
public:
|
||||
|
||||
static double ToDoubleBits(uint64_t v);
|
||||
|
||||
static uint64_t ToUintBits(double v);
|
||||
static float ToFloatBits(uint32_t v);
|
||||
|
||||
static uint32_t ToUint32Bits(float v);
|
||||
|
||||
static double ToDoubleBE(uint8_t& b);
|
||||
static float ToFloatBE(uint8_t& b);
|
||||
|
||||
static uint64_t ToUint64BE(uint8_t& b);
|
||||
static uint32_t ToUint32BE(uint8_t& b);
|
||||
static uint16_t ToUint16BE(uint8_t& b);
|
||||
public:
|
||||
static double ToDoubleBits(uint64_t v);
|
||||
|
||||
static double ToDoubleLE(uint8_t& b);
|
||||
static float ToFloatLE(uint8_t& b);
|
||||
static uint64_t ToUint64LE(uint8_t& b);
|
||||
static uint32_t ToUint32LE(uint8_t& b);
|
||||
static uint16_t ToUint16LE(uint8_t& b);
|
||||
static uint64_t ToUintBits(double v);
|
||||
static float ToFloatBits(uint32_t v);
|
||||
|
||||
static int64_t ToSint64BE(uint8_t& b);
|
||||
static int32_t ToSint32BE(uint8_t& b);
|
||||
static int16_t ToSint16BE(uint8_t& b);
|
||||
static int64_t ToSint64LE(uint8_t& b);
|
||||
static int32_t ToSint32LE(uint8_t& b);
|
||||
static int16_t ToSint16LE(uint8_t& b);
|
||||
static uint32_t ToUint32Bits(float v);
|
||||
|
||||
static Uuid ToUuid(uint8_t& b);
|
||||
static double ToDoubleBE(uint8_t &b);
|
||||
static float ToFloatBE(uint8_t &b);
|
||||
|
||||
static uint64_t ToUint64BE(uint8_t &b);
|
||||
static uint32_t ToUint32BE(uint8_t &b);
|
||||
static uint16_t ToUint16BE(uint8_t &b);
|
||||
|
||||
static void ToUuid(uint8_t& b, Uuid& uuid);
|
||||
static double ToDoubleLE(uint8_t &b);
|
||||
static float ToFloatLE(uint8_t &b);
|
||||
static uint64_t ToUint64LE(uint8_t &b);
|
||||
static uint32_t ToUint32LE(uint8_t &b);
|
||||
static uint16_t ToUint16LE(uint8_t &b);
|
||||
|
||||
static int64_t ToSint64BE(uint8_t &b);
|
||||
static int32_t ToSint32BE(uint8_t &b);
|
||||
static int16_t ToSint16BE(uint8_t &b);
|
||||
static int64_t ToSint64LE(uint8_t &b);
|
||||
static int32_t ToSint32LE(uint8_t &b);
|
||||
static int16_t ToSint16LE(uint8_t &b);
|
||||
|
||||
static void FromDoubleBE(uint8_t& b, double v);
|
||||
static void FromFloatBE(uint8_t& b, float v);
|
||||
static void FromUint64BE(uint8_t& b, uint64_t v);
|
||||
static void FromUint32BE(uint8_t& b, uint32_t v);
|
||||
static void FromUint16BE(uint8_t& b, uint16_t v);
|
||||
static Uuid ToUuid(uint8_t &b);
|
||||
|
||||
static void FromDoubleLE(uint8_t& b, double v);
|
||||
static void FromFloatLE(uint8_t& b, float v);
|
||||
static void FromUint64LE(uint8_t& b, uint64_t v);
|
||||
static void FromUint32LE(uint8_t& b, uint32_t v);
|
||||
static void FromUint16LE(uint8_t& b, uint16_t v);
|
||||
|
||||
static void FromSint64BE(uint8_t& b, int64_t v);
|
||||
static void FromSint32BE(uint8_t& b, int32_t v);
|
||||
static void FromSint16BE(uint8_t& b, int16_t v);
|
||||
|
||||
static void FromSint64LE(uint8_t& b, int64_t v);
|
||||
static void FromSint32LE(uint8_t& b, int32_t v);
|
||||
static void FromSint16LE(uint8_t& b, int16_t v);
|
||||
|
||||
static void FromUuid(uint8_t& b, const Uuid& uuid);
|
||||
static void ToUuid(uint8_t &b, Uuid &uuid);
|
||||
|
||||
static void FromDoubleBE(uint8_t &b, double v);
|
||||
static void FromFloatBE(uint8_t &b, float v);
|
||||
static void FromUint64BE(uint8_t &b, uint64_t v);
|
||||
static void FromUint32BE(uint8_t &b, uint32_t v);
|
||||
static void FromUint16BE(uint8_t &b, uint16_t v);
|
||||
|
||||
static void FromDoubleLE(uint8_t &b, double v);
|
||||
static void FromFloatLE(uint8_t &b, float v);
|
||||
static void FromUint64LE(uint8_t &b, uint64_t v);
|
||||
static void FromUint32LE(uint8_t &b, uint32_t v);
|
||||
static void FromUint16LE(uint8_t &b, uint16_t v);
|
||||
|
||||
static inline bool IsLittleEndian()
|
||||
{
|
||||
uint8_t a[2];
|
||||
a[0] = 0x01;
|
||||
a[1] = 0xA4;
|
||||
uint16_t num=0;
|
||||
memcpy(&num,&a, 2);
|
||||
return num != 420;
|
||||
}
|
||||
static void FromSint64BE(uint8_t &b, int64_t v);
|
||||
static void FromSint32BE(uint8_t &b, int32_t v);
|
||||
static void FromSint16BE(uint8_t &b, int16_t v);
|
||||
|
||||
static void FromSint64LE(uint8_t &b, int64_t v);
|
||||
static void FromSint32LE(uint8_t &b, int32_t v);
|
||||
static void FromSint16LE(uint8_t &b, int16_t v);
|
||||
|
||||
static void FromUuid(uint8_t &b, const Uuid &uuid);
|
||||
|
||||
static inline bool IsLittleEndian() {
|
||||
uint8_t a[2];
|
||||
a[0] = 0x01;
|
||||
a[1] = 0xA4;
|
||||
uint16_t num = 0;
|
||||
memcpy(&num, &a, 2);
|
||||
return num != 420;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Tesses::Framework::Serialization
|
||||
@@ -1,94 +1,101 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
namespace Tesses::Framework::Serialization::Json
|
||||
{
|
||||
class JArray;
|
||||
class JObject;
|
||||
using JUndefined = std::monostate;
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
namespace Tesses::Framework::Serialization::Json {
|
||||
class JArray;
|
||||
class JObject;
|
||||
using JUndefined = std::monostate;
|
||||
|
||||
using JToken = std::variant<JUndefined,std::nullptr_t,bool,int64_t,double,std::string, JArray, JObject>;
|
||||
using JToken = std::variant<JUndefined, std::nullptr_t, bool, int64_t, double,
|
||||
std::string, JArray, JObject>;
|
||||
|
||||
class JOItem;
|
||||
class JOItem;
|
||||
|
||||
class JArray
|
||||
{
|
||||
std::vector<JToken> items;
|
||||
public:
|
||||
JArray();
|
||||
JArray(std::initializer_list<JToken> items);
|
||||
std::vector<JToken>& GetVector();
|
||||
void Add(JToken item);
|
||||
void RemoveAt(size_t index);
|
||||
size_t Count();
|
||||
void SetAt(size_t index, JToken item);
|
||||
JToken GetAt(size_t index);
|
||||
void Clear();
|
||||
class JArray {
|
||||
std::vector<JToken> items;
|
||||
|
||||
std::vector<JToken>::iterator begin();
|
||||
std::vector<JToken>::iterator end();
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
JArray();
|
||||
JArray(std::initializer_list<JToken> items);
|
||||
std::vector<JToken> &GetVector();
|
||||
void Add(JToken item);
|
||||
void RemoveAt(size_t index);
|
||||
size_t Count();
|
||||
void SetAt(size_t index, JToken item);
|
||||
JToken GetAt(size_t index);
|
||||
void Clear();
|
||||
|
||||
|
||||
std::vector<JToken>::iterator begin();
|
||||
std::vector<JToken>::iterator end();
|
||||
};
|
||||
|
||||
class JObject {
|
||||
std::map<std::string,JToken> map;
|
||||
public:
|
||||
JObject();
|
||||
JObject(std::initializer_list<JOItem> items);
|
||||
void SetValue(std::string key, JToken item);
|
||||
template<typename T>
|
||||
bool TryGetValueAsType(std::string key, T& value)
|
||||
{
|
||||
auto obj = GetValue(key);
|
||||
if(std::holds_alternative<T>(obj))
|
||||
{
|
||||
value = std::get<T>(obj);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class JObject {
|
||||
std::map<std::string, JToken> map;
|
||||
|
||||
JToken GetValue(std::string key);
|
||||
void Remove(std::string key);
|
||||
std::map<std::string,JToken>& GetMap();
|
||||
std::map<std::string,JToken>::iterator begin();
|
||||
std::map<std::string,JToken>::iterator end();
|
||||
};
|
||||
template<typename T>
|
||||
bool TryGetJToken(JToken json, T& item)
|
||||
{
|
||||
if(std::holds_alternative<T>(json))
|
||||
{
|
||||
item = std::get<T>(json);
|
||||
public:
|
||||
JObject();
|
||||
JObject(std::initializer_list<JOItem> items);
|
||||
void SetValue(std::string key, JToken item);
|
||||
template <typename T> bool TryGetValueAsType(std::string key, T &value) {
|
||||
auto obj = GetValue(key);
|
||||
if (std::holds_alternative<T>(obj)) {
|
||||
value = std::get<T>(obj);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class JOItem {
|
||||
public:
|
||||
JOItem();
|
||||
JOItem(std::string key, JToken value);
|
||||
|
||||
std::string key;
|
||||
JToken value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Json
|
||||
{
|
||||
static std::string tab(std::string str);
|
||||
public:
|
||||
static JToken Decode(std::string str);
|
||||
static std::string Encode(JToken tkn, bool indent=true);
|
||||
static JArray DocDecode(std::string str);
|
||||
static std::string DocEncode(JArray array,bool indent=true);
|
||||
};
|
||||
JToken GetValue(std::string key);
|
||||
void Remove(std::string key);
|
||||
std::map<std::string, JToken> &GetMap();
|
||||
std::map<std::string, JToken>::iterator begin();
|
||||
std::map<std::string, JToken>::iterator end();
|
||||
};
|
||||
template <typename T> bool TryGetJToken(JToken json, T &item) {
|
||||
if (std::holds_alternative<T>(json)) {
|
||||
item = std::get<T>(json);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class JOItem {
|
||||
public:
|
||||
JOItem();
|
||||
JOItem(std::string key, JToken value);
|
||||
|
||||
std::string key;
|
||||
JToken value;
|
||||
};
|
||||
|
||||
class Json {
|
||||
static std::string tab(std::string str);
|
||||
|
||||
public:
|
||||
static JToken Decode(std::string str);
|
||||
static std::string Encode(JToken tkn, bool indent = true);
|
||||
static JArray DocDecode(std::string str);
|
||||
static std::string DocEncode(JArray array, bool indent = true);
|
||||
};
|
||||
} // namespace Tesses::Framework::Serialization::Json
|
||||
|
||||
@@ -1,18 +1,42 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||
#include "TessesFramework/Filesystem/VFS.hpp"
|
||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||
#include <optional>
|
||||
namespace Tesses::Framework::Serialization {
|
||||
class SQLiteDatabase {
|
||||
private:
|
||||
void* data;
|
||||
static int collector(void* user, int count,char** vals, char** keys);
|
||||
public:
|
||||
SQLiteDatabase(Tesses::Framework::Filesystem::VFSPath path);
|
||||
static std::string Escape(std::string text);
|
||||
static bool IsEnabled();
|
||||
void Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& results);
|
||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> Exec(std::string statement);
|
||||
~SQLiteDatabase();
|
||||
};
|
||||
}
|
||||
class SQLiteDatabase {
|
||||
private:
|
||||
void *data;
|
||||
static int collector(void *user, int count, char **vals, char **keys);
|
||||
|
||||
public:
|
||||
SQLiteDatabase(Tesses::Framework::Filesystem::VFSPath path);
|
||||
static std::string Escape(std::string text);
|
||||
static bool IsEnabled();
|
||||
void
|
||||
Exec(std::string statement,
|
||||
std::vector<
|
||||
std::vector<std::pair<std::string, std::optional<std::string>>>>
|
||||
&results);
|
||||
std::vector<std::vector<std::pair<std::string, std::optional<std::string>>>>
|
||||
Exec(std::string statement);
|
||||
~SQLiteDatabase();
|
||||
};
|
||||
} // namespace Tesses::Framework::Serialization
|
||||
Reference in New Issue
Block a user