Add date code
This commit is contained in:
66
include/TessesFramework/Date/Date.hpp
Normal file
66
include/TessesFramework/Date/Date.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Tesses::Framework::Date
|
||||
{
|
||||
int GetTimeZone();
|
||||
bool TimeZoneSupportDST();
|
||||
|
||||
class DateTime {
|
||||
int year=1970;
|
||||
int month=1;
|
||||
int day=1;
|
||||
int hour=0;
|
||||
int minute=0;
|
||||
int second=0;
|
||||
bool isLocal=false;
|
||||
int64_t ToEpochNoConvert();
|
||||
void FromEpochNoConvert(int64_t gmt);
|
||||
public:
|
||||
DateTime();
|
||||
DateTime(int year, int month, int day, int hour, int minute, int seconds, bool isLocal=true);
|
||||
DateTime(int64_t epoch);
|
||||
int Year();
|
||||
int Month();
|
||||
int Day();
|
||||
int Hour();
|
||||
int Minute();
|
||||
int Second();
|
||||
int DayOfWeek();
|
||||
bool IsLocal();
|
||||
int64_t ToEpoch();
|
||||
DateTime ToLocal();
|
||||
DateTime ToUTC();
|
||||
void SetToLocal();
|
||||
void SetToUTC();
|
||||
void SetYear(int y);
|
||||
void SetMonth(int m);
|
||||
void SetDay(int d);
|
||||
void SetHour(int h);
|
||||
void SetMinute(int m);
|
||||
void SetSecond(int s);
|
||||
void SetLocal(bool local);
|
||||
void Set(int64_t epoch);
|
||||
void Set(int year, int month, int day, int hour, int minute, int seconds, bool isLocal=true);
|
||||
|
||||
|
||||
|
||||
void SetToNow();
|
||||
void SetToNowUTC();
|
||||
static DateTime Now();
|
||||
static DateTime NowUTC();
|
||||
|
||||
std::string ToString();
|
||||
std::string ToString(std::string fmt);
|
||||
|
||||
|
||||
std::string ToHttpDate();
|
||||
static bool TryParseHttpDate(std::string txt, DateTime& dt);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
@ -31,8 +31,10 @@ namespace Tesses::Framework::Filesystem
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
};
|
||||
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
};
|
||||
extern LocalFilesystem LocalFS;
|
||||
}
|
||||
@ -13,7 +13,7 @@ namespace Tesses::Framework::Filesystem
|
||||
class MemoryFileData {
|
||||
public:
|
||||
MemoryFileData();
|
||||
time_t lastWrite;
|
||||
Date::DateTime lastWrite;
|
||||
|
||||
bool canAccess;
|
||||
size_t readers;
|
||||
@ -31,7 +31,7 @@ namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
public:
|
||||
MemoryDirectory();
|
||||
time_t lastWrite;
|
||||
Date::DateTime lastWrite;
|
||||
std::vector<MemoryEntry*> entries;
|
||||
~MemoryDirectory();
|
||||
};
|
||||
@ -39,7 +39,7 @@ namespace Tesses::Framework::Filesystem
|
||||
class MemorySymlink : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
time_t lastWrite;
|
||||
Date::DateTime lastWrite;
|
||||
VFSPath linkedTo;
|
||||
};
|
||||
|
||||
@ -92,8 +92,8 @@ namespace Tesses::Framework::Filesystem
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
~MemoryFilesystem();
|
||||
};
|
||||
};
|
||||
@ -51,7 +51,7 @@ namespace Tesses::Framework::Filesystem
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~MountableFilesystem();
|
||||
void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
};
|
||||
}
|
||||
@ -36,8 +36,8 @@ namespace Tesses::Framework::Filesystem
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~SubdirFilesystem();
|
||||
void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
};
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
#include "../Streams/Stream.hpp"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "../Date/Date.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
@ -130,8 +131,8 @@ namespace Tesses::Framework::Filesystem
|
||||
virtual VFSPath SystemToVFSPath(std::string path)=0;
|
||||
|
||||
|
||||
virtual void GetDate(VFSPath path, time_t& lastWrite, time_t& lastAccess);
|
||||
virtual void SetDate(VFSPath path, time_t lastWrite, time_t lastAccess);
|
||||
virtual void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
virtual void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
virtual ~VFS();
|
||||
};
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "HttpUtils.hpp"
|
||||
#include "../Threading/Thread.hpp"
|
||||
#include "../Date/Date.hpp"
|
||||
#include <unordered_map>
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
@ -79,6 +80,7 @@ namespace Tesses::Framework::Http
|
||||
void SendException(std::exception& ex);
|
||||
Tesses::Framework::Streams::Stream* OpenResponseStream();
|
||||
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);
|
||||
ServerContext& WithMimeType(std::string mime);
|
||||
@ -110,11 +112,19 @@ namespace Tesses::Framework::Http
|
||||
Tesses::Framework::Streams::TcpServer* server;
|
||||
IHttpServer* http;
|
||||
Tesses::Framework::Threading::Thread* thrd;
|
||||
bool owns;
|
||||
uint16_t port;
|
||||
|
||||
bool ownsTCP;
|
||||
bool ownsHttp;
|
||||
bool showIPs;
|
||||
|
||||
public:
|
||||
HttpServer(uint16_t port, IHttpServer& http);
|
||||
HttpServer(uint16_t port, IHttpServer* http, bool owns);
|
||||
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);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void Process(Tesses::Framework::Streams::Stream& strm, IHttpServer& server, std::string ip, uint16_t port, bool encrypted);
|
||||
~HttpServer();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Date/Date.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
@ -78,6 +79,9 @@ struct CaseInsensitiveLess {
|
||||
void Clear();
|
||||
void Clear(std::string key, bool kvpExistsAfter);
|
||||
void SetValue(std::string key, std::string value);
|
||||
void SetValue(std::string key, int64_t v);
|
||||
void SetValue(std::string key, double v);
|
||||
void SetValue(std::string key, Date::DateTime v);
|
||||
void SetValue(std::string key, std::vector<std::string> value);
|
||||
template<typename Itterator>
|
||||
void SetValue(std::string key, Itterator begin, Itterator end)
|
||||
@ -86,6 +90,9 @@ struct CaseInsensitiveLess {
|
||||
AddValue(key, begin, end);
|
||||
}
|
||||
void AddValue(std::string key, std::string value);
|
||||
void AddValue(std::string key, int64_t v);
|
||||
void AddValue(std::string key, double v);
|
||||
void AddValue(std::string key, Date::DateTime v);
|
||||
void AddValue(std::string key, std::vector<std::string> value);
|
||||
|
||||
template<typename Itterator>
|
||||
@ -100,6 +107,7 @@ struct CaseInsensitiveLess {
|
||||
bool TryGetFirstInt(std::string key, int64_t& value);
|
||||
|
||||
bool TryGetFirstDouble(std::string key, double& value);
|
||||
bool TryGetFirstDate(std::string key, Date::DateTime& value);
|
||||
|
||||
bool GetFirstBoolean(std::string key);
|
||||
|
||||
@ -140,10 +148,11 @@ struct CaseInsensitiveLess {
|
||||
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
|
||||
static std::string HtmlEncode(std::string v);
|
||||
static std::vector<std::string> SplitString(std::string text, std::string delimiter,std::size_t maxCnt = std::string::npos);
|
||||
static std::string Replace(std::string str, std::string find, std::string replace);
|
||||
static std::string StatusCodeString(StatusCode code);
|
||||
static std::string ToLower(std::string str);
|
||||
static std::string ToUpper(std::string str);
|
||||
|
||||
static std::string LeftPad(std::string text, int count, char c);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -10,10 +10,12 @@ namespace Tesses::Framework::Streams
|
||||
bool owns;
|
||||
bool valid;
|
||||
public:
|
||||
TcpServer(int32_t backlog);
|
||||
TcpServer(int32_t sock,bool owns);
|
||||
TcpServer(uint16_t port, int32_t backlog);
|
||||
TcpServer(std::string ip, uint16_t port, int32_t backlog);
|
||||
NetworkStream* GetStream(std::string& ip, uint16_t& port);
|
||||
uint16_t GetPort();
|
||||
~TcpServer();
|
||||
bool IsValid();
|
||||
void Close();
|
||||
@ -30,6 +32,7 @@ namespace Tesses::Framework::Streams
|
||||
NetworkStream(bool ipV6,bool datagram);
|
||||
NetworkStream(std::string ipOrFqdn, uint16_t port, bool datagram,bool broadcast,bool supportIPv6);
|
||||
NetworkStream(int32_t sock, bool owns);
|
||||
uint16_t GetPort();
|
||||
void Listen(int32_t backlog);
|
||||
void Bind(std::string ip, uint16_t port);
|
||||
void SetBroadcast(bool bC);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "Date/Date.hpp"
|
||||
#include "Http/HttpServer.hpp"
|
||||
#include "Http/HttpClient.hpp"
|
||||
#include "Http/FileServer.hpp"
|
||||
|
||||
Reference in New Issue
Block a user