mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 15:55:46 +00:00
Make streams and vfs and http shared_ptr
This commit is contained in:
@@ -11,8 +11,8 @@ namespace Tesses::Framework::Crypto
|
||||
public:
|
||||
static std::string GetCertChain();
|
||||
|
||||
ClientTLSStream(Tesses::Framework::Streams::Stream* innerStream, bool owns, bool verify, std::string domain);
|
||||
ClientTLSStream(Tesses::Framework::Streams::Stream* innerStream, bool owns, bool verify, std::string domain, std::string cert);
|
||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain);
|
||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain, std::string cert);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool CanRead();
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace Tesses::Framework::Crypto
|
||||
Sha1();
|
||||
bool Start();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(Tesses::Framework::Streams::Stream* strm);
|
||||
bool Update(Tesses::Framework::Streams::Stream& strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha1();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream* strm);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream& strm);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
class Sha256 {
|
||||
void* inner;
|
||||
@@ -27,13 +25,11 @@ namespace Tesses::Framework::Crypto
|
||||
bool Start(bool is224=false);
|
||||
bool Is224();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(Tesses::Framework::Streams::Stream* strm);
|
||||
bool Update(Tesses::Framework::Streams::Stream& strm);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha256();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len,bool is224=false);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream* strm,bool is224=false);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream& strm,bool is224=false);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,bool is224=false);
|
||||
|
||||
};
|
||||
class Sha512 {
|
||||
@@ -44,14 +40,12 @@ namespace Tesses::Framework::Crypto
|
||||
bool Start(bool is384=false);
|
||||
bool Is384();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(Tesses::Framework::Streams::Stream* strm);
|
||||
bool Update(Tesses::Framework::Streams::Stream& strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha512();
|
||||
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len,bool is384=false);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream* strm,bool is384=false);
|
||||
static std::vector<uint8_t> ComputeHash(Tesses::Framework::Streams::Stream& strm,bool is384=false);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,bool is384=false);
|
||||
};
|
||||
typedef enum {
|
||||
VERSION_SHA1=1,
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
public:
|
||||
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
@@ -35,6 +35,11 @@ namespace Tesses::Framework::Filesystem
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
|
||||
};
|
||||
extern LocalFilesystem LocalFS;
|
||||
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace Tesses::Framework::Filesystem
|
||||
MemoryEntry* GetEntry(VFSPath path,bool followSymlink);
|
||||
public:
|
||||
MemoryFilesystem();
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
|
||||
@@ -7,29 +7,28 @@ namespace Tesses::Framework::Filesystem
|
||||
class MountableDirectory {
|
||||
public:
|
||||
std::string name;
|
||||
VFS* vfs;
|
||||
std::shared_ptr<VFS> vfs;
|
||||
bool owns;
|
||||
std::vector<MountableDirectory*> dirs;
|
||||
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, VFS*& vfs);
|
||||
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
||||
~MountableDirectory();
|
||||
};
|
||||
|
||||
class MountableFilesystem : public VFS
|
||||
{
|
||||
bool owns;
|
||||
VFS* root;
|
||||
std::shared_ptr<VFS> root;
|
||||
|
||||
std::vector<MountableDirectory*> directories;
|
||||
|
||||
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, VFS*& vfs);
|
||||
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
||||
|
||||
|
||||
public:
|
||||
MountableFilesystem();
|
||||
MountableFilesystem(VFS* root, bool owns);
|
||||
void Mount(VFSPath path, VFS* fs, bool owns);
|
||||
MountableFilesystem(std::shared_ptr<VFS> root);
|
||||
void Mount(VFSPath path, std::shared_ptr<VFS> vfs);
|
||||
void Unmount(VFSPath path);
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
@@ -53,5 +52,10 @@ namespace Tesses::Framework::Filesystem
|
||||
~MountableFilesystem();
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Tesses::Framework::Filesystem
|
||||
class NullFilesystem : public VFS
|
||||
{
|
||||
public:
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
|
||||
@@ -6,14 +6,13 @@ namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class SubdirFilesystem : public VFS
|
||||
{
|
||||
bool owns;
|
||||
VFS* parent;
|
||||
std::shared_ptr<VFS> parent;
|
||||
VFSPath path;
|
||||
VFSPath ToParent(VFSPath path);
|
||||
VFSPath FromParent(VFSPath path);
|
||||
public:
|
||||
SubdirFilesystem(VFS* parent, VFSPath path, bool owns);
|
||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
@@ -38,6 +37,9 @@ namespace Tesses::Framework::Filesystem
|
||||
~SubdirFilesystem();
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,20 @@
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class StatVFSData {
|
||||
public:
|
||||
uint64_t BlockSize;
|
||||
uint64_t FragmentSize;
|
||||
uint64_t Blocks;
|
||||
uint64_t BlocksFree;
|
||||
uint64_t BlocksAvailable;
|
||||
uint64_t TotalInodes;
|
||||
uint64_t FreeInodes;
|
||||
uint64_t AvailableInodes;
|
||||
uint64_t Id;
|
||||
uint64_t Flags;
|
||||
uint64_t MaxNameLength;
|
||||
};
|
||||
class VFSPath {
|
||||
public:
|
||||
static VFSPath CurrentDirectoryAsRelative();
|
||||
@@ -107,7 +121,7 @@ namespace Tesses::Framework::Filesystem
|
||||
class VFS {
|
||||
public:
|
||||
|
||||
virtual Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode)=0;
|
||||
virtual std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode)=0;
|
||||
virtual void CreateDirectory(VFSPath path)=0;
|
||||
virtual void DeleteDirectory(VFSPath path)=0;
|
||||
virtual bool RegularFileExists(VFSPath path)=0;
|
||||
@@ -134,6 +148,10 @@ namespace Tesses::Framework::Filesystem
|
||||
virtual void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
virtual void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
virtual bool StatVFS(VFSPath path, StatVFSData& data);
|
||||
|
||||
virtual void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
virtual ~VFS();
|
||||
};
|
||||
}
|
||||
@@ -6,8 +6,8 @@ namespace Tesses::Framework::Http
|
||||
{
|
||||
class FileServer : public IHttpServer
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFS* vfs;
|
||||
bool ownsVFS;
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
|
||||
|
||||
|
||||
bool SendFile(ServerContext& ctx,Tesses::Framework::Filesystem::VFSPath path);
|
||||
@@ -17,8 +17,8 @@ namespace Tesses::Framework::Http
|
||||
std::vector<std::string> defaultNames;
|
||||
FileServer(std::filesystem::path path,bool allowListing,bool spa);
|
||||
FileServer(std::filesystem::path path,bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
||||
FileServer(Tesses::Framework::Filesystem::VFS* fs, bool owns, bool allowListing, bool spa);
|
||||
FileServer(Tesses::Framework::Filesystem::VFS* fs, bool owns, bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
||||
bool Handle(ServerContext& ctx);
|
||||
~FileServer();
|
||||
};
|
||||
|
||||
@@ -10,18 +10,18 @@ namespace Tesses::Framework::Http
|
||||
class HttpRequestBody {
|
||||
public:
|
||||
virtual void HandleHeaders(HttpDictionary& dict);
|
||||
virtual void Write(Tesses::Framework::Streams::Stream* strm)=0;
|
||||
virtual void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)=0;
|
||||
virtual ~HttpRequestBody();
|
||||
};
|
||||
|
||||
class StreamHttpRequestBody : public HttpRequestBody {
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
std::string mimeType;
|
||||
public:
|
||||
StreamHttpRequestBody(Tesses::Framework::Streams::Stream* strm, bool owns, std::string mimeType);
|
||||
StreamHttpRequestBody(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary& dict);
|
||||
void Write(Tesses::Framework::Streams::Stream* strm);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~StreamHttpRequestBody();
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Tesses::Framework::Http
|
||||
public:
|
||||
TextHttpRequestBody(std::string text, std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary& dict);
|
||||
void Write(Tesses::Framework::Streams::Stream* strm);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~TextHttpRequestBody();
|
||||
};
|
||||
|
||||
@@ -49,52 +49,47 @@ namespace Tesses::Framework::Http
|
||||
HttpDictionary requestHeaders;
|
||||
HttpRequestBody* body;
|
||||
|
||||
static Tesses::Framework::Streams::Stream* EstablishConnection(Uri uri,bool ignoreSSLErrors,std::string trusted_root_cert_bundle);
|
||||
static Tesses::Framework::Streams::Stream* EstablishUnixPathConnection(std::string unixPath, Uri uri, bool ignoreSSLErrors, std::string trusted_root_cert_bundle);
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishConnection(Uri uri,bool ignoreSSLErrors,std::string trusted_root_cert_bundle);
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishUnixPathConnection(std::string unixPath, Uri uri, bool ignoreSSLErrors, std::string trusted_root_cert_bundle);
|
||||
|
||||
void SendRequest(Tesses::Framework::Streams::Stream* strm);
|
||||
void SendRequest(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
|
||||
class HttpResponse {
|
||||
private:
|
||||
bool owns;
|
||||
Tesses::Framework::Streams::Stream* handleStrm;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> handleStrm;
|
||||
public:
|
||||
HttpResponse(Tesses::Framework::Streams::Stream* strm, bool owns);
|
||||
HttpResponse(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
HttpResponse(HttpRequest& request);
|
||||
std::string version;
|
||||
StatusCode statusCode;
|
||||
HttpDictionary responseHeaders;
|
||||
std::string ReadAsString();
|
||||
Tesses::Framework::Streams::Stream* ReadAsStream();
|
||||
void CopyToStream(Tesses::Framework::Streams::Stream* strm);
|
||||
Tesses::Framework::Streams::Stream* GetInternalStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> ReadAsStream();
|
||||
void CopyToStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetInternalStream();
|
||||
~HttpResponse();
|
||||
};
|
||||
|
||||
void DownloadToStreamSimple(std::string url, Tesses::Framework::Streams::Stream* strm);
|
||||
void DownloadToStreamSimple(std::string url, Tesses::Framework::Streams::Stream& strm);
|
||||
void DownloadToStreamSimple(std::string url, std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
|
||||
void DownloadToFileSimple(std::string url, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DownloadToFileSimple(std::string url, Tesses::Framework::Filesystem::VFS* vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DownloadToFileSimple(std::string url, Tesses::Framework::Filesystem::VFS& vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DownloadToFileSimple(std::string url, Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadToStringSimple(std::string url);
|
||||
|
||||
bool WebSocketClientSuccessDefault(HttpDictionary& dict,bool v);
|
||||
void WebSocketClient(std::string url, HttpDictionary& requestHeaders, WebSocketConnection& wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
void WebSocketClient(std::string url, HttpDictionary& requestHeaders, WebSocketConnection* wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
void WebSocketClient(std::string url, HttpDictionary& requestHeaders, std::shared_ptr<WebSocketConnection> wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
|
||||
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream* strm);
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream& strm);
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS* vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS& vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadUnixSocketToStringSimple(std::string unixSocket,std::string url);
|
||||
|
||||
|
||||
void WebSocketUnixSocketClient(std::string unixSocket,std::string url, HttpDictionary& requestHeaders, WebSocketConnection& wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
void WebSocketUnixSocketClient(std::string unixSocket,std::string url,HttpDictionary& requestHeaders, WebSocketConnection* wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
void WebSocketUnixSocketClient(std::string unixSocket,std::string url, HttpDictionary& requestHeaders, std::shared_ptr<WebSocketConnection> wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace Tesses::Framework::Http
|
||||
|
||||
class ServerContext {
|
||||
bool sent;
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::map<std::string,ServerContextData*> data;
|
||||
public:
|
||||
HttpDictionary requestHeaders;
|
||||
@@ -31,27 +31,25 @@ namespace Tesses::Framework::Http
|
||||
uint16_t port;
|
||||
std::string version;
|
||||
bool encrypted;
|
||||
ServerContext(Tesses::Framework::Streams::Stream* strm);
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~ServerContext();
|
||||
Tesses::Framework::Streams::Stream& GetStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
std::string GetOriginalPathWithQuery();
|
||||
std::string GetUrlWithQuery();
|
||||
bool Sent();
|
||||
bool NeedToParseFormData();
|
||||
void ParseFormData(std::function<Tesses::Framework::Streams::Stream*(std::string mime, std::string filename, std::string name)> cb);
|
||||
void ReadStream(Tesses::Framework::Streams::Stream& strm);
|
||||
void ReadStream(Tesses::Framework::Streams::Stream* strm);
|
||||
void ParseFormData(std::function<std::shared_ptr<Tesses::Framework::Streams::Stream>(std::string mime, std::string filename, std::string name)> cb);
|
||||
void ReadStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::string ReadString();
|
||||
void SendBytes(std::vector<uint8_t> buffer);
|
||||
void SendText(std::string text);
|
||||
void SendStream(Tesses::Framework::Streams::Stream& strm);
|
||||
void SendStream(Tesses::Framework::Streams::Stream* strm);
|
||||
void SendStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
void SendErrorPage(bool showPath);
|
||||
void SendNotFound();
|
||||
void SendBadRequest();
|
||||
void SendException(std::exception& ex);
|
||||
Tesses::Framework::Streams::Stream* OpenResponseStream();
|
||||
Tesses::Framework::Streams::Stream* OpenRequestStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenResponseStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenRequestStream();
|
||||
ServerContext& WithLastModified(Date::DateTime time);
|
||||
ServerContext& WithHeader(std::string key, std::string value);
|
||||
ServerContext& WithSingleHeader(std::string key, std::string value);
|
||||
@@ -59,7 +57,7 @@ namespace Tesses::Framework::Http
|
||||
ServerContext& WithContentDisposition(std::string filename, bool isInline);
|
||||
ServerContext& WriteHeaders();
|
||||
void StartWebSocketSession(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
||||
void StartWebSocketSession(WebSocketConnection& connection);
|
||||
void StartWebSocketSession(std::shared_ptr<WebSocketConnection> connection);
|
||||
|
||||
template<class T>
|
||||
T* GetServerContentData(std::string tag)
|
||||
@@ -81,27 +79,20 @@ namespace Tesses::Framework::Http
|
||||
};
|
||||
|
||||
class HttpServer {
|
||||
Tesses::Framework::Streams::TcpServer* server;
|
||||
IHttpServer* http;
|
||||
std::shared_ptr<Tesses::Framework::Streams::TcpServer> server;
|
||||
std::shared_ptr<IHttpServer> http;
|
||||
Tesses::Framework::Threading::Thread* thrd;
|
||||
|
||||
bool ownsTCP;
|
||||
bool ownsHttp;
|
||||
bool showIPs;
|
||||
bool showARTL;
|
||||
|
||||
public:
|
||||
HttpServer(Tesses::Framework::Streams::TcpServer& tcpServer, IHttpServer& http, bool showIPs=true);
|
||||
HttpServer(Tesses::Framework::Streams::TcpServer* tcpServer, bool ownsTCP, IHttpServer& http, bool showIPs=true);
|
||||
HttpServer(Tesses::Framework::Streams::TcpServer& tcpServer, IHttpServer* http, bool ownsHttpServer, bool showIPs=true);
|
||||
HttpServer(Tesses::Framework::Streams::TcpServer* tcpServer, bool ownsTCP, IHttpServer* http, bool ownsHttpServer, bool showIPs=true);
|
||||
HttpServer(uint16_t port, IHttpServer& http, bool showIPs=true);
|
||||
HttpServer(uint16_t port, IHttpServer* http, bool owns, bool showIPs=true);
|
||||
HttpServer(std::string unixPath, IHttpServer& http);
|
||||
HttpServer(std::string unixPath, IHttpServer* http, bool owns);
|
||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void Process(Tesses::Framework::Streams::Stream& strm, IHttpServer& server, std::string ip, uint16_t port, bool encrypted);
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port, bool encrypted);
|
||||
~HttpServer();
|
||||
};
|
||||
}
|
||||
@@ -4,22 +4,20 @@
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class HttpStream : public Tesses::Framework::Streams::Stream {
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
size_t offset;
|
||||
size_t read;
|
||||
int64_t length;
|
||||
int64_t position;
|
||||
|
||||
bool owns;
|
||||
bool recv;
|
||||
bool http1_1;
|
||||
|
||||
bool done;
|
||||
|
||||
public:
|
||||
HttpStream(Tesses::Framework::Streams::Stream* strm, bool owns, int64_t length, bool recv, bool http1_1);
|
||||
HttpStream(Tesses::Framework::Streams::Stream& strm, int64_t length, bool recv,bool http1_1);
|
||||
HttpStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, int64_t length, bool recv, bool http1_1);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool EndOfStream();
|
||||
|
||||
@@ -7,17 +7,14 @@ namespace Tesses::Framework::Http
|
||||
{
|
||||
class MountableServer : public IHttpServer
|
||||
{
|
||||
IHttpServer* root;
|
||||
bool owns;
|
||||
std::vector<std::pair<std::string,std::pair<bool,IHttpServer*>>> servers;
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
std::vector<std::pair<std::string,std::shared_ptr<IHttpServer>>> servers;
|
||||
std::string Subpath(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
||||
bool StartsWith(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
||||
public:
|
||||
MountableServer();
|
||||
MountableServer(IHttpServer* root, bool owns);
|
||||
MountableServer(IHttpServer& root);
|
||||
void Mount(std::string path, IHttpServer* server, bool owns);
|
||||
void Mount(std::string path, IHttpServer& server);
|
||||
MountableServer(std::shared_ptr<IHttpServer> root);
|
||||
void Mount(std::string path, std::shared_ptr<IHttpServer> server);
|
||||
void Unmount(std::string path);
|
||||
bool Handle(ServerContext& ctx);
|
||||
~MountableServer();
|
||||
|
||||
@@ -6,7 +6,7 @@ class SMTPBody
|
||||
{
|
||||
public:
|
||||
std::string mimeType;
|
||||
virtual void Write(Tesses::Framework::Streams::Stream* strm)=0;
|
||||
virtual void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)=0;
|
||||
virtual ~SMTPBody();
|
||||
};
|
||||
|
||||
@@ -16,27 +16,25 @@ class SMTPStringBody : public SMTPBody
|
||||
SMTPStringBody();
|
||||
SMTPStringBody(std::string text, std::string mimeType);
|
||||
std::string text;
|
||||
void Write(Tesses::Framework::Streams::Stream* strm);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
|
||||
class SMTPStreamBody : public SMTPBody
|
||||
{
|
||||
Tesses::Framework::Streams::Stream* stream;
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> stream;
|
||||
|
||||
public:
|
||||
SMTPStreamBody(std::string mimeType,Tesses::Framework::Streams::Stream& stream);
|
||||
SMTPStreamBody(std::string mimeType,Tesses::Framework::Streams::Stream* stream, bool owns);
|
||||
void Write(Tesses::Framework::Streams::Stream* strm);
|
||||
SMTPStreamBody(std::string mimeType,std::shared_ptr<Tesses::Framework::Streams::Stream> stream);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~SMTPStreamBody();
|
||||
};
|
||||
|
||||
|
||||
class SMTPClient {
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
public:
|
||||
SMTPClient(Tesses::Framework::Streams::Stream* stream,bool owns=true);
|
||||
SMTPClient(Tesses::Framework::Streams::Stream& strm);
|
||||
SMTPClient(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::string domain;
|
||||
std::string username;
|
||||
std::string password;
|
||||
@@ -44,8 +42,8 @@ class SMTPClient {
|
||||
std::string from_name;
|
||||
std::string to;
|
||||
std::string subject;
|
||||
SMTPBody* body;
|
||||
std::vector<std::pair<std::string,SMTPBody*>> attachments;
|
||||
std::shared_ptr<SMTPBody> body;
|
||||
std::vector<std::pair<std::string,std::shared_ptr<SMTPBody>>> attachments;
|
||||
void Send();
|
||||
~SMTPClient();
|
||||
};
|
||||
|
||||
@@ -27,14 +27,11 @@ class Process {
|
||||
|
||||
|
||||
void CloseStdInNow();
|
||||
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM OBJECT
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdinStream();
|
||||
|
||||
Tesses::Framework::Streams::Stream* GetStdinStream();
|
||||
|
||||
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM OBJECT
|
||||
Tesses::Framework::Streams::Stream* GetStdoutStream();
|
||||
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM OBJECT
|
||||
Tesses::Framework::Streams::Stream* GetStderrStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdoutStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStderrStream();
|
||||
|
||||
Process();
|
||||
Process(std::string name, std::vector<std::string> args,bool includeThisEnv=true);
|
||||
|
||||
@@ -6,15 +6,13 @@ namespace Tesses::Framework::Streams
|
||||
class BufferedStream : public Stream
|
||||
{
|
||||
private:
|
||||
Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Stream> strm;
|
||||
uint8_t* buffer;
|
||||
size_t bufferSize;
|
||||
size_t offset;
|
||||
size_t read;
|
||||
public:
|
||||
BufferedStream(Stream* strm, bool owns, size_t bufferSize=1024);
|
||||
BufferedStream(Stream& strm, size_t bufferSize=1024);
|
||||
BufferedStream(std::shared_ptr<Stream> strm, size_t bufferSize=1024);
|
||||
bool EndOfStream();
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
namespace Tesses::Framework::Streams
|
||||
{
|
||||
class ByteReader {
|
||||
Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Stream> strm;
|
||||
public:
|
||||
Stream* GetStream();
|
||||
ByteReader(Stream* strm, bool owns);
|
||||
ByteReader(Stream& strm);
|
||||
std::shared_ptr<Stream> GetStream();
|
||||
ByteReader(std::shared_ptr<Stream> strm);
|
||||
uint8_t ReadU8();
|
||||
uint16_t ReadU16BE();
|
||||
uint16_t ReadU16LE();
|
||||
@@ -28,6 +26,5 @@ namespace Tesses::Framework::Streams
|
||||
float ReadF32LE();
|
||||
double ReadF64BE();
|
||||
double ReadF64LE();
|
||||
~ByteReader();
|
||||
};
|
||||
}
|
||||
@@ -4,12 +4,11 @@
|
||||
namespace Tesses::Framework::Streams
|
||||
{
|
||||
class ByteWriter {
|
||||
Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Stream> strm;
|
||||
|
||||
public:
|
||||
Stream* GetStream();
|
||||
ByteWriter(Stream* strm, bool owns);
|
||||
ByteWriter(Stream& strm);
|
||||
std::shared_ptr<Stream> GetStream();
|
||||
ByteWriter(std::shared_ptr<Stream> strm);
|
||||
void WriteU8(uint8_t v);
|
||||
void WriteU16BE(uint16_t v);
|
||||
void WriteU16LE(uint16_t v);
|
||||
@@ -28,6 +27,5 @@ namespace Tesses::Framework::Streams
|
||||
void WriteF32LE(float v);
|
||||
void WriteF64BE(double v);
|
||||
void WriteF64LE(double v);
|
||||
~ByteWriter();
|
||||
};
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Tesses::Framework::Streams
|
||||
TcpServer(uint16_t port, int32_t backlog);
|
||||
TcpServer(std::string ip, uint16_t port, int32_t backlog);
|
||||
TcpServer(std::string unixPath,int32_t backlog);
|
||||
NetworkStream* GetStream(std::string& ip, uint16_t& port);
|
||||
std::shared_ptr<NetworkStream> GetStream(std::string& ip, uint16_t& port);
|
||||
uint16_t GetPort();
|
||||
~TcpServer();
|
||||
bool IsValid();
|
||||
@@ -45,7 +45,7 @@ namespace Tesses::Framework::Streams
|
||||
void Listen(int32_t backlog);
|
||||
void Bind(std::string ip, uint16_t port);
|
||||
void SetBroadcast(bool bC);
|
||||
NetworkStream* Accept(std::string& ip, uint16_t& port);
|
||||
std::shared_ptr<NetworkStream> Accept(std::string& ip, uint16_t& port);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
size_t ReadFrom(uint8_t* buff, size_t sz, std::string& ip, uint16_t& port);
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace Tesses::Framework::Streams
|
||||
virtual int64_t GetLength();
|
||||
virtual void Flush();
|
||||
virtual void Seek(int64_t pos, SeekOrigin whence);
|
||||
void CopyTo(Stream* strm, size_t buffSize=1024);
|
||||
void CopyTo(Stream& strm, size_t buffSize=1024);
|
||||
void CopyTo(std::shared_ptr<Stream> strm, size_t buffSize=1024);
|
||||
virtual ~Stream();
|
||||
};
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void string_t;
|
||||
typedef void tf_vfs_t;
|
||||
typedef void tf_stream_t;
|
||||
typedef void tf_thread_t;
|
||||
typedef void tf_mutex_t;
|
||||
typedef void tf_vfs_dir_t;
|
||||
|
||||
typedef void (*tf_action_user_data_t)(void* ptr);
|
||||
|
||||
|
||||
typedef enum {
|
||||
TF_SEEK_BEGIN,
|
||||
TF_SEEK_CURRENT,
|
||||
TF_SEEK_END
|
||||
} TF_WHENCE;
|
||||
|
||||
string_t* string_create();
|
||||
string_t* string_create_from_buff(const void* text, size_t len);
|
||||
string_t* string_create_from_charpointer(const char* text);
|
||||
string_t* string_resize(string_t* str, size_t len);
|
||||
string_t* string_set_char(string_t* str, size_t index, char c);
|
||||
char string_get_char(string_t* str,size_t index);
|
||||
string_t* string_append_char(string_t* str, char c);
|
||||
string_t* string_append_from_buff(string_t* str,const void* text, size_t len);
|
||||
string_t* string_append_from_charpointer(string_t* str,const char* text);
|
||||
string_t* string_append(string_t* str, string_t* toAppend);
|
||||
string_t* string_append_signed(string_t* str, int64_t num);
|
||||
string_t* string_append_unsigned(string_t* str, uint64_t num);
|
||||
string_t* string_append_double(string_t* str, double num);
|
||||
void string_print(string_t* str);
|
||||
void string_println(string_t* str);
|
||||
size_t string_size(string_t* str);
|
||||
const char* string_c_str(string_t* str);
|
||||
void string_free(string_t* str);
|
||||
|
||||
void tf_init();
|
||||
tf_thread_t* tf_create_thread(void* userData, tf_action_user_data_t cb);
|
||||
void tf_join_thread(tf_thread_t* thrd);
|
||||
void tf_detach_thread(tf_thread_t* thrd);
|
||||
|
||||
tf_mutex_t* tf_mutex_create();
|
||||
void tf_mutex_lock(tf_mutex_t* mtx);
|
||||
bool tf_mutex_trylock(tf_mutex_t* mtx);
|
||||
void tf_mutex_unlock(tf_mutex_t* mtx);
|
||||
void tf_mutex_free(tf_mutex_t* mtx);
|
||||
|
||||
bool tf_stream_canread(tf_stream_t* strm);
|
||||
bool tf_stream_canwrite(tf_stream_t* strm);
|
||||
bool tf_stream_canseek(tf_stream_t* strm);
|
||||
bool tf_stream_eof(tf_stream_t* strm);
|
||||
int64_t tf_stream_getlen(tf_stream_t* strm);
|
||||
int64_t tf_stream_getpos(tf_stream_t* strm);
|
||||
void tf_stream_seek(tf_stream_t* strm, int64_t pos, TF_WHENCE whence);
|
||||
size_t tf_stream_read(tf_stream_t* strm, uint8_t* buffer, size_t length);
|
||||
size_t tf_stream_write(tf_stream_t* strm, const uint8_t* buffer, size_t length);
|
||||
size_t tf_stream_readblock(tf_stream_t* strm, uint8_t* buffer, size_t length);
|
||||
void tf_stream_writeblock(tf_stream_t* strm, const uint8_t* buffer, size_t length);
|
||||
void tf_stream_copyto(tf_stream_t* src, tf_stream_t* dest, size_t blockSize);
|
||||
void tf_stream_close(tf_stream_t* strm);
|
||||
void tf_stream_flush(tf_stream_t* strm);
|
||||
int32_t tf_stream_readbyte(tf_stream_t* strm);
|
||||
void tf_stream_writebyte(tf_stream_t* strm, uint8_t val);
|
||||
|
||||
tf_stream_t* tf_stream_fopen(const char* file, const char* mode);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "../TextStreams/StringWriter.hpp"
|
||||
|
||||
namespace Tesses::Framework::Text {
|
||||
void GenerateCHeaderFile(Streams::Stream* strm,std::string name, TextStreams::TextWriter* writer);
|
||||
void GenerateCHeaderFile(std::shared_ptr<Streams::Stream> strm,std::string name, std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
|
||||
std::string GenerateCHeaderFile(Streams::Stream* strm,std::string name);
|
||||
void GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name, TextStreams::TextWriter* writer);
|
||||
std::string GenerateCHeaderFile(std::shared_ptr<Streams::Stream> strm,std::string name);
|
||||
void GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name, std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
std::string GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name);
|
||||
}
|
||||
@@ -6,12 +6,11 @@ namespace Tesses::Framework::TextStreams
|
||||
class StreamReader : public TextReader
|
||||
{
|
||||
private:
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
bool owns;
|
||||
public:
|
||||
Tesses::Framework::Streams::Stream& GetStream();
|
||||
StreamReader(Tesses::Framework::Streams::Stream& strm);
|
||||
StreamReader(Tesses::Framework::Streams::Stream* strm, bool owns);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
StreamReader(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
StreamReader(std::filesystem::path filename);
|
||||
bool ReadBlock(std::string& str,size_t sz);
|
||||
bool Rewind();
|
||||
|
||||
@@ -6,12 +6,10 @@ namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
class StreamWriter : public TextWriter {
|
||||
private:
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
public:
|
||||
Tesses::Framework::Streams::Stream& GetStream();
|
||||
StreamWriter(Tesses::Framework::Streams::Stream& strm);
|
||||
StreamWriter(Tesses::Framework::Streams::Stream* strm, bool owns);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
StreamWriter(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
StreamWriter(std::filesystem::path filename, bool append=false);
|
||||
void WriteData(const char* text, size_t len);
|
||||
~StreamWriter();
|
||||
|
||||
Reference in New Issue
Block a user