Compare commits
21 Commits
v1.4.0-rc.
...
v1.4.0-rc.
Author | SHA1 | Date | |
---|---|---|---|
5e4f4e27f6 | |||
7db8486f1e | |||
a6eb7f6e97 | |||
46184df89c | |||
73f7ec1a8d | |||
135f855309 | |||
159428ea76 | |||
c23cbc275f | |||
fbd8464043 | |||
f52afe9c92 | |||
61fb586f86 | |||
c19c6269aa | |||
0b1a0c9689 | |||
83bb62456a | |||
f1d1a1cbb1 | |||
8bf4f6336f | |||
25e40560b7 | |||
fd452f6643 | |||
389fa61fba | |||
a67197766e | |||
ae414c5c99 |
@@ -67,7 +67,7 @@ jobs:
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: |
|
||||
sudo pacman -S --noconfirm doxygen zip alsa-lib libxcb xcb-util-cursor pipewire
|
||||
sudo pacman -S --noconfirm doxygen ninja zip libxcb xcb-util-cursor pipewire
|
||||
|
||||
- name: Generating Documentation
|
||||
run: |
|
||||
@@ -76,7 +76,7 @@ jobs:
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake --build . --config Release
|
||||
cmake --install .
|
||||
|
||||
@@ -112,7 +112,7 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: sudo apt install -y doxygen zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev libpipewire-0.3-dev
|
||||
run: sudo apt install -y doxygen ninja-build zip libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev libpipewire-0.3-dev
|
||||
|
||||
- name: Generating Documentation
|
||||
run: |
|
||||
@@ -121,7 +121,7 @@ jobs:
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake --build . --config Release
|
||||
cmake --install .
|
||||
|
||||
|
26
Assembly.def
Normal file
26
Assembly.def
Normal file
@@ -0,0 +1,26 @@
|
||||
LIBRARY EHS_Dyn
|
||||
EXPORTS
|
||||
?GenerateSeed_u64@HRNG@ehs@@SA_KXZ
|
||||
?Generate_u64@HRNG@ehs@@SA_K_K0@Z
|
||||
?Generate_u64@HRNG@ehs@@SA_KXZ
|
||||
?GenerateSeed_s64@HRNG@ehs@@SA_JXZ
|
||||
?Generate_s64@HRNG@ehs@@SA_J_J0@Z
|
||||
?Generate_s64@HRNG@ehs@@SA_JXZ
|
||||
?GenerateSeed_u32@HRNG@ehs@@SAIXZ
|
||||
?Generate_u32@HRNG@ehs@@SAIII@Z
|
||||
?Generate_u32@HRNG@ehs@@SAIXZ
|
||||
?GenerateSeed_s32@HRNG@ehs@@SAHXZ
|
||||
?Generate_s32@HRNG@ehs@@SAHHH@Z
|
||||
?Generate_s32@HRNG@ehs@@SAHXZ
|
||||
?GenerateSeed_u16@HRNG@ehs@@SAIXZ
|
||||
?Generate_u16@HRNG@ehs@@SAGGG@Z
|
||||
?Generate_u16@HRNG@ehs@@SAGXZ
|
||||
?GenerateSeed_s16@HRNG@ehs@@SAFXZ
|
||||
?Generate_s16@HRNG@ehs@@SAFFF@Z
|
||||
?Generate_s16@HRNG@ehs@@SAFXZ
|
||||
?GenerateSeed_u8@HRNG@ehs@@SAEXZ
|
||||
?Generate_u8@HRNG@ehs@@SAEEE@Z
|
||||
?Generate_u8@HRNG@ehs@@SAEXZ
|
||||
?GenerateSeed_s8@HRNG@ehs@@SACXZ
|
||||
?Generate_s8@HRNG@ehs@@SACCC@Z
|
||||
?Generate_s8@HRNG@ehs@@SACXZ
|
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.25.1)
|
||||
cmake_minimum_required(VERSION 3.30.4)
|
||||
|
||||
set(IS_OS_WINDOWS FALSE)
|
||||
set(IS_OS_LINUX FALSE)
|
||||
@@ -11,6 +11,8 @@ set(IS_ARCH_ARM FALSE)
|
||||
|
||||
project(EHS CXX C)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(IS_OS_WINDOWS TRUE)
|
||||
set(USER_HOME_DIRECTORY "$ENV{USERPROFILE}")
|
||||
@@ -199,6 +201,8 @@ set(EHS_SOURCES
|
||||
src/io/socket/ehc/NetUtils.cpp
|
||||
include/ehs/io/socket/BaseICMP.h src/io/socket/BaseICMP.cpp
|
||||
include/ehs/io/socket/ICMP.h
|
||||
src/io/socket/QueryVar.cpp include/ehs/io/socket/QueryVar.h
|
||||
src/io/socket/HeaderVar.cpp include/ehs/io/socket/HeaderVar.h
|
||||
)
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
@@ -240,7 +244,7 @@ elseif (IS_OS_LINUX)
|
||||
include/ehs/io/socket/ICMP_LNX.h src/io/socket/ICMP_LNX.cpp
|
||||
)
|
||||
|
||||
#set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
|
||||
set(LINUX_WINDOW_SYSTEM "XCB" CACHE STRING "Linux Window System")
|
||||
|
||||
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
|
||||
add_compile_definitions(EHS_WS_WAYLAND)
|
||||
@@ -258,15 +262,12 @@ elseif (IS_OS_LINUX)
|
||||
if (IS_ARCH_AMD64)
|
||||
list(APPEND EHS_SOURCES src/system/CPU_GCC_AMD64.asm src/HRNG_GCC.asm src/Math_GCC_AMD64.asm src/system/AVX2_GCC_AMD64.asm src/system/AVX512_GCC_AMD64.asm)
|
||||
elseif (IS_ARCH_ARM64)
|
||||
list(APPEND EHS_SOURCES src/system/CPU_ARM64.cpp src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s src/system/AVX2_AARCH64.cpp src/system/AVX512_AARCH64.cpp)
|
||||
list(APPEND EHS_SOURCES src/system/CPU_ARM64.cpp src/system/CPU_GCC_AARCH64.s src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s src/system/AVX2_AARCH64.cpp src/system/AVX512_AARCH64.cpp)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
#message("${CMAKE_CXX_FLAGS}")
|
||||
|
||||
add_library(EHS_Stc STATIC ${EHS_SOURCES})
|
||||
add_library(EHS_Dyn SHARED ${EHS_SOURCES})
|
||||
add_library(EHS_Dyn SHARED ${EHS_SOURCES} Assembly.def)
|
||||
add_executable(StrToHash src/StrToHash.cpp)
|
||||
|
||||
target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT)
|
||||
@@ -327,6 +328,6 @@ elseif (IS_OS_LINUX)
|
||||
target_link_libraries(StrToHash xcb xcb-cursor xcb-xfixes xcb-xinput)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(EHS_Dyn z asound pipewire-0.3)
|
||||
target_link_libraries(StrToHash z asound EHS_Stc)
|
||||
target_link_libraries(EHS_Dyn z pipewire-0.3)
|
||||
target_link_libraries(StrToHash z EHS_Stc)
|
||||
endif ()
|
@@ -38,6 +38,8 @@ This project does not fully follow the C++ standard.
|
||||
- Asynchronous Task System
|
||||
- URI Parsing
|
||||
- USB (WIP)
|
||||
- Base64
|
||||
- SHA256
|
||||
|
||||
### Supported Architectures
|
||||
- AMD64
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class EHS_LIB_IO HRNG
|
||||
class HRNG
|
||||
{
|
||||
public:
|
||||
static UInt_64 GenerateSeed_u64();
|
||||
|
@@ -63,7 +63,7 @@ namespace ehs
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
/// @param [in] code The unique code to use.
|
||||
/// @param [in] msg Detailed information about what happened.
|
||||
Log(LogType type, const std::initializer_list<Str_8> &tags, UInt_64 code, Str_8 msg);
|
||||
Log(LogType type, const Str_8 &tags, UInt_64 code, Str_8 msg);
|
||||
|
||||
/// Initializes members with the given information.
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
@@ -134,20 +134,20 @@ namespace ehs
|
||||
|
||||
#ifndef EHS_LOG_INT
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg))
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAcronym_8()) + ", " + EHS_FILE + ", " + EHS_FUNC + ", " + ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE), code, msg))
|
||||
#else
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg))
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAcronym_8()) + ", " + EHS_FUNC, code, msg))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EHS_LOG
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg))
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAppName_8()) + ", " + EHS_FILE + ", " + EHS_FUNC + ", " + ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE), code, msg))
|
||||
#else
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg))
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAppName_8()) + ", " + EHS_FUNC, code, msg))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EHS_LOG_SUCCESS
|
||||
#define EHS_LOG_SUCCESS() ehs::Log::Raise({})
|
||||
#define EHS_LOG_SUCCESS() ehs::Log::Raise({})
|
||||
#endif
|
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class SHA256
|
||||
class EHS_LIB_IO SHA256
|
||||
{
|
||||
private:
|
||||
static UInt_32 ROTR(UInt_32 x, UInt_32 n);
|
||||
|
@@ -25,6 +25,7 @@ namespace ehs
|
||||
pw_core *core;
|
||||
pw_stream *input;
|
||||
pw_stream *output;
|
||||
spa_hook paramsHook;
|
||||
|
||||
static void RegistryEventGlobal(void *data, UInt_32 id, UInt_32 permissions, const char *type, UInt_32 version, const spa_dict *props);
|
||||
|
||||
|
@@ -21,6 +21,8 @@ namespace ehs
|
||||
bool active;
|
||||
|
||||
public:
|
||||
virtual ~HID() = default;
|
||||
|
||||
HID();
|
||||
|
||||
HID(UInt_8 type, Str_8 name, UInt_64 id);
|
||||
|
@@ -27,92 +27,92 @@ namespace ehs
|
||||
|
||||
Keyboard* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button Escape;
|
||||
static const Button Backspace;
|
||||
static const Button Enter;
|
||||
static const Button LShift;
|
||||
static const Button RShift;
|
||||
static const Button LAlt;
|
||||
static const Button RAlt;
|
||||
static const Button LCtrl;
|
||||
static const Button RCtrl;
|
||||
static const Button Space;
|
||||
static const Button A;
|
||||
static const Button B;
|
||||
static const Button C;
|
||||
static const Button D;
|
||||
static const Button E;
|
||||
static const Button F;
|
||||
static const Button G;
|
||||
static const Button H;
|
||||
static const Button I;
|
||||
static const Button J;
|
||||
static const Button K;
|
||||
static const Button L;
|
||||
static const Button M;
|
||||
static const Button N;
|
||||
static const Button O;
|
||||
static const Button P;
|
||||
static const Button Q;
|
||||
static const Button R;
|
||||
static const Button S;
|
||||
static const Button T;
|
||||
static const Button U;
|
||||
static const Button V;
|
||||
static const Button W;
|
||||
static const Button X;
|
||||
static const Button Y;
|
||||
static const Button Z;
|
||||
static const Button One;
|
||||
static const Button Two;
|
||||
static const Button Three;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button Six;
|
||||
static const Button Seven;
|
||||
static const Button Eight;
|
||||
static const Button Nine;
|
||||
static const Button Zero;
|
||||
static const Button Minus;
|
||||
static const Button Equals;
|
||||
static const Button Tilde;
|
||||
static const Button BackSlash;
|
||||
static const Button LeftSquareBracket;
|
||||
static const Button RightSquareBracket;
|
||||
static const Button SemiColon;
|
||||
static const Button Apostrophe;
|
||||
static const Button Comma;
|
||||
static const Button Period;
|
||||
static const Button ForwardSlash;
|
||||
static const Button F1;
|
||||
static const Button F2;
|
||||
static const Button F3;
|
||||
static const Button F4;
|
||||
static const Button F5;
|
||||
static const Button F6;
|
||||
static const Button F7;
|
||||
static const Button F8;
|
||||
static const Button F9;
|
||||
static const Button F10;
|
||||
static const Button F11;
|
||||
static const Button F12;
|
||||
static const Button F13;
|
||||
static const Button F14;
|
||||
static const Button F15;
|
||||
static const Button F16;
|
||||
static const Button F17;
|
||||
static const Button F18;
|
||||
static const Button F19;
|
||||
static const Button F20;
|
||||
static const Button F21;
|
||||
static const Button F22;
|
||||
static const Button F23;
|
||||
static const Button F24;
|
||||
static const Button Left;
|
||||
static const Button Right;
|
||||
static const Button Up;
|
||||
static const Button Down;
|
||||
static inline const Button Unknown = Button("Unknown");
|
||||
static inline const Button Escape = Button("Escape Button");
|
||||
static inline const Button Backspace = Button("Backspace Button");
|
||||
static inline const Button Enter = Button("Enter Button");
|
||||
static inline const Button LShift = Button("Left Shift Button");
|
||||
static inline const Button RShift = Button("Right Shift Button");
|
||||
static inline const Button LAlt = Button("Left Alt Button");
|
||||
static inline const Button RAlt = Button("Right Alt Button");
|
||||
static inline const Button LCtrl = Button("Left Control Button");
|
||||
static inline const Button RCtrl = Button("Right Button");
|
||||
static inline const Button Space = Button("Space Button");
|
||||
static inline const Button A = Button("A Button");
|
||||
static inline const Button B = Button("B Button");
|
||||
static inline const Button C = Button("C Button");
|
||||
static inline const Button D = Button("D Button");
|
||||
static inline const Button E = Button("E Button");
|
||||
static inline const Button F = Button("F Button");
|
||||
static inline const Button G = Button("G Button");
|
||||
static inline const Button H = Button("H Button");
|
||||
static inline const Button I = Button("I Button");
|
||||
static inline const Button J = Button("J Button");
|
||||
static inline const Button K = Button("K Button");
|
||||
static inline const Button L = Button("L Button");
|
||||
static inline const Button M = Button("M Button");
|
||||
static inline const Button N = Button("N Button");
|
||||
static inline const Button O = Button("O Button");
|
||||
static inline const Button P = Button("P Button");
|
||||
static inline const Button Q = Button("Q Button");
|
||||
static inline const Button R = Button("R Button");
|
||||
static inline const Button S = Button("S Button");
|
||||
static inline const Button T = Button("T Button");
|
||||
static inline const Button U = Button("U Button");
|
||||
static inline const Button V = Button("V Button");
|
||||
static inline const Button W = Button("W Button");
|
||||
static inline const Button X = Button("X Button");
|
||||
static inline const Button Y = Button("Y Button");
|
||||
static inline const Button Z = Button("Z Button");
|
||||
static inline const Button One = Button("One Button");
|
||||
static inline const Button Two = Button("Two Button");
|
||||
static inline const Button Three = Button("Three Button");
|
||||
static inline const Button Four = Button("Four Button");
|
||||
static inline const Button Five = Button("Five Button");
|
||||
static inline const Button Six = Button("Six Button");
|
||||
static inline const Button Seven = Button("Seven Button");
|
||||
static inline const Button Eight = Button("Eight Button");
|
||||
static inline const Button Nine = Button("Nine Button");
|
||||
static inline const Button Zero = Button("Zero Button");
|
||||
static inline const Button Minus = Button("Minus Button");
|
||||
static inline const Button Equals = Button("Equals Button");
|
||||
static inline const Button Tilde = Button("Tilde Button");
|
||||
static inline const Button BackSlash = Button("Back Slash Button");
|
||||
static inline const Button LeftSquareBracket = Button("Left Square Bracket Button");
|
||||
static inline const Button RightSquareBracket = Button("Right Square Bracket Button");
|
||||
static inline const Button SemiColon = Button("Semi Colon Button");
|
||||
static inline const Button Apostrophe = Button("Apostrophe Button");
|
||||
static inline const Button Comma = Button("Comma Button");
|
||||
static inline const Button Period = Button("Period Button");
|
||||
static inline const Button ForwardSlash = Button("Forward Slash Button");
|
||||
static inline const Button F1 = Button("Function One Button");
|
||||
static inline const Button F2 = Button("Function Two Button");
|
||||
static inline const Button F3 = Button("Function Three Button");
|
||||
static inline const Button F4 = Button("Function Four Button");
|
||||
static inline const Button F5 = Button("Function Five Button");
|
||||
static inline const Button F6 = Button("Function Six Button");
|
||||
static inline const Button F7 = Button("Function Seven Button");
|
||||
static inline const Button F8 = Button("Function Eight Button");
|
||||
static inline const Button F9 = Button("Function Nine Button");
|
||||
static inline const Button F10 = Button("Function Ten Button");
|
||||
static inline const Button F11 = Button("Function Eleven Button");
|
||||
static inline const Button F12 = Button("Function Twelve Button");
|
||||
static inline const Button F13 = Button("Function Thirteen Button");
|
||||
static inline const Button F14 = Button("Function Fourteen Button");
|
||||
static inline const Button F15 = Button("Function Fifteen Button");
|
||||
static inline const Button F16 = Button("Function Sixteen Button");
|
||||
static inline const Button F17 = Button("Function Seventeen Button");
|
||||
static inline const Button F18 = Button("Function Eighteen Button");
|
||||
static inline const Button F19 = Button("Function Nineteen Button");
|
||||
static inline const Button F20 = Button("Function Twenty Button");
|
||||
static inline const Button F21 = Button("Function Twenty One Button");
|
||||
static inline const Button F22 = Button("Function Twenty Two Button");
|
||||
static inline const Button F23 = Button("Function Twenty Three Button");
|
||||
static inline const Button F24 = Button("Function Twenty Four Button");
|
||||
static inline const Button Left = Button("Left Button");
|
||||
static inline const Button Right = Button("Right Button");
|
||||
static inline const Button Up = Button("Up Button");
|
||||
static inline const Button Down = Button("Down Button");
|
||||
|
||||
static Button TranslateScanCode(UInt_32 code);
|
||||
|
||||
|
@@ -37,18 +37,18 @@ namespace ehs
|
||||
|
||||
Mouse* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button LMB;
|
||||
static const Button MMB;
|
||||
static const Button RMB;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button ScrollUp;
|
||||
static const Button ScrollDown;
|
||||
static const Button ScrollLeft;
|
||||
static const Button ScrollRight;
|
||||
static const Button Back;
|
||||
static const Button Forward;
|
||||
static inline const Button Unknown = Button("Unknown Button");
|
||||
static inline const Button LMB = Button("Left Mouse Button");
|
||||
static inline const Button MMB = Button("Middle Mouse Button");
|
||||
static inline const Button RMB = Button("Right Mouse Button");
|
||||
static inline const Button Four = Button("Four Button");
|
||||
static inline const Button Five = Button("Five Button");
|
||||
static inline const Button ScrollUp = Button("Scroll Up Button");
|
||||
static inline const Button ScrollDown = Button("Scroll Down Button");
|
||||
static inline const Button ScrollLeft = Button("Scroll Left Button");
|
||||
static inline const Button ScrollRight = Button("Scroll Right Button");
|
||||
static inline const Button Back = Button("Back Button");
|
||||
static inline const Button Forward = Button("Forward Button");
|
||||
|
||||
static Button TranslateXCB(const UInt_32 code);
|
||||
};
|
||||
|
@@ -24,9 +24,9 @@ namespace ehs
|
||||
bool connected;
|
||||
|
||||
public:
|
||||
static const UInt_16 HTTPS_Port = 443;
|
||||
static const UInt_16 HTTP_Port = 80;
|
||||
static const UInt_16 MaxHeaderSize = 8192;
|
||||
static constexpr UInt_16 HTTPS_Port = 443;
|
||||
static constexpr UInt_16 HTTP_Port = 80;
|
||||
static constexpr UInt_16 MaxHeaderSize = 8192;
|
||||
|
||||
virtual ~BaseTCP() = default;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace ehs
|
||||
/// @param [in] address The ip address to bind to.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Used for servers.
|
||||
virtual void Bind(const Str_8& address, UInt_16 port) = 0;
|
||||
virtual void Bind(Str_8 address, const UInt_16 &port) = 0;
|
||||
|
||||
/// Listens for new incoming connections.
|
||||
/// @note Used for servers.
|
||||
@@ -63,13 +63,13 @@ namespace ehs
|
||||
|
||||
/// Accepts the new incoming connection.
|
||||
/// @note Used for servers.
|
||||
virtual BaseTCP* Accept() = 0;
|
||||
virtual BaseTCP *Accept() = 0;
|
||||
|
||||
/// Connects to a server at the specified address and port.
|
||||
/// @param [in] address The ip address to connect to.
|
||||
/// @param [in] port The port to connect to.
|
||||
/// @note Used for clients.
|
||||
virtual void Connect(const Str_8& address, UInt_16 port) = 0;
|
||||
virtual void Connect(Str_8 address, const UInt_16 &port) = 0;
|
||||
|
||||
/// Sends data to the connected endpoint.
|
||||
/// @param [in] buffer The data to send to the endpoint.
|
||||
@@ -150,6 +150,8 @@ namespace ehs
|
||||
|
||||
virtual bool IsIPv6Only() const = 0;
|
||||
|
||||
virtual void SetReuse(const bool &enabled) = 0;
|
||||
|
||||
/// Retrieves whether or not this socket was initialized.
|
||||
/// @returns The result.
|
||||
virtual bool IsValid() const = 0;
|
||||
|
45
include/ehs/io/socket/HeaderVar.h
Normal file
45
include/ehs/io/socket/HeaderVar.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class HeaderVar
|
||||
{
|
||||
private:
|
||||
UInt_64 id;
|
||||
Str_8 name;
|
||||
Str_8 value;
|
||||
|
||||
public:
|
||||
HeaderVar();
|
||||
|
||||
HeaderVar(Str_8 name, Str_8 value);
|
||||
|
||||
HeaderVar(HeaderVar &&other) noexcept;
|
||||
|
||||
HeaderVar(const HeaderVar &other);
|
||||
|
||||
HeaderVar &operator=(HeaderVar &&other) noexcept;
|
||||
|
||||
HeaderVar &operator=(const HeaderVar &other);
|
||||
|
||||
bool operator==(const HeaderVar &other) const;
|
||||
|
||||
bool operator!=(const HeaderVar &other) const;
|
||||
|
||||
bool operator==(const UInt_64 &otherId) const;
|
||||
|
||||
bool operator!=(const UInt_64 &otherId) const;
|
||||
|
||||
UInt_64 GetId() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
Str_8 GetValue() const;
|
||||
|
||||
void SetValue(Str_8 value);
|
||||
|
||||
Str_8 ToStr() const;
|
||||
};
|
||||
}
|
45
include/ehs/io/socket/QueryVar.h
Normal file
45
include/ehs/io/socket/QueryVar.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class QueryVar
|
||||
{
|
||||
private:
|
||||
UInt_64 id;
|
||||
Str_8 name;
|
||||
Str_8 value;
|
||||
|
||||
public:
|
||||
QueryVar();
|
||||
|
||||
QueryVar(Str_8 name, Str_8 value);
|
||||
|
||||
QueryVar(QueryVar &&other) noexcept;
|
||||
|
||||
QueryVar(const QueryVar &other);
|
||||
|
||||
QueryVar &operator=(QueryVar &&other) noexcept;
|
||||
|
||||
QueryVar &operator=(const QueryVar &other);
|
||||
|
||||
bool operator==(const QueryVar &other) const;
|
||||
|
||||
bool operator!=(const QueryVar &other) const;
|
||||
|
||||
bool operator==(const UInt_64 &otherId) const;
|
||||
|
||||
bool operator!=(const UInt_64 &otherId) const;
|
||||
|
||||
UInt_64 GetId() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
Str_8 GetValue() const;
|
||||
|
||||
void SetValue(Str_8 value);
|
||||
|
||||
Str_8 ToStr() const;
|
||||
};
|
||||
}
|
@@ -5,6 +5,8 @@
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/json/Json.h"
|
||||
#include "Socket.h"
|
||||
#include "QueryVar.h"
|
||||
#include "HeaderVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -21,8 +23,8 @@ namespace ehs
|
||||
private:
|
||||
Verb verb;
|
||||
Str_8 rsrc;
|
||||
Vector<Str_8> queries;
|
||||
Vector<Str_8> header;
|
||||
Vector<QueryVar> queries;
|
||||
Vector<HeaderVar> header;
|
||||
ContentType cType;
|
||||
Str_8 body;
|
||||
|
||||
@@ -33,25 +35,34 @@ namespace ehs
|
||||
/// Initializes this request with a given verb and URI resource.
|
||||
/// @param [in] verb The type of request to make.
|
||||
/// @param [in] rsrc The URI endpoint to make the request at.
|
||||
Request(const Verb verb, const Str_8& rsrc);
|
||||
Request(const Verb &verb, Str_8 rsrc);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The C-style string of the request.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Request(const char* data, const UInt_64 size);
|
||||
Request(const char *data, const UInt_64 &size);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The string of the request.
|
||||
Request(const Str_8& data);
|
||||
Request(const Str_8 &data);
|
||||
|
||||
/// Moves members from another object of the same type.
|
||||
/// @param [in] other The object to move from.
|
||||
Request(Request &&other) noexcept;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
Request(const Request& req) = default;
|
||||
/// @param [in] other The object to copy from.
|
||||
Request(const Request &other);
|
||||
|
||||
/// Moves members from another object of the same type.
|
||||
/// @param [in] other The object to move from.
|
||||
/// @returns The request that has been assigned to.
|
||||
Request& operator=(Request &&other) noexcept;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
/// @param [in] other The object to copy from.
|
||||
/// @returns The request that has been assigned to.
|
||||
Request& operator=(const Request& req);
|
||||
Request& operator=(const Request &other);
|
||||
|
||||
/// Retrieves the verb for the request.
|
||||
/// @returns The result.
|
||||
@@ -59,7 +70,7 @@ namespace ehs
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
void SetContentType(const ContentType &cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
@@ -67,75 +78,145 @@ namespace ehs
|
||||
|
||||
/// Sets the URI resource.
|
||||
/// @param [in] rsrc The resource.
|
||||
void SetResource(const Str_8& rsrc);
|
||||
void SetResource(Str_8 rsrc);
|
||||
|
||||
/// Retrieves the URI resource.
|
||||
/// @returns The result.
|
||||
Str_8 GetResource() const;
|
||||
|
||||
/// Adds a query variable to the URI.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddQuery(const Str_8& var, const Str_8& value);
|
||||
/// Checks whether a header variable exists using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasQueryVar(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a query variable from the URI.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the query variable. Empty if it was not found.
|
||||
Str_8 GetQuery(const Str_8& var);
|
||||
/// Checks whether a header variable exists using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasQueryVar(const Str_8 &name) const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable to add to the header.
|
||||
/// @returns False if the given variable name already exists. True otherwise.
|
||||
bool AddQueryVar(QueryVar var);
|
||||
|
||||
/// Removes a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveQueryVar(const UInt_64 &id);
|
||||
|
||||
/// Removes a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveQueryVar(const Str_8 &name);
|
||||
|
||||
/// Retrieves a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
QueryVar *GetQueryVar(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
QueryVar *GetQueryVar(const Str_8& name) const;
|
||||
|
||||
/// Retrieves a header variable value using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetQueryValue(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable value using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetQueryValue(const Str_8& name) const;
|
||||
|
||||
/// Retrieves all the query variables from the URI in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetQueries() const;
|
||||
Vector<QueryVar> GetQueries() const;
|
||||
|
||||
/// A helper method to automatically add the required header variables for basic authentication.
|
||||
/// @param [in] id The username or id.
|
||||
/// @param [in] secret The secret given by an API.
|
||||
void BasicAuth(const Str_8& id, const Str_8& secret);
|
||||
void BasicAuth(const Str_8 &id, const Str_8 &secret);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BearerAuth(const Str_8& token);
|
||||
void BearerAuth(const Str_8 &token);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
/// @param [in] clientId The client id given by an API.
|
||||
void BearerAuth(const Str_8& token, const Str_8& clientId);
|
||||
void BearerAuth(const Str_8 &token, const Str_8 &clientId);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bot authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BotAuth(const Str_8& token);
|
||||
void BotAuth(const Str_8 &token);
|
||||
|
||||
/// Checks whether a header variable exists using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasHeaderVar(const UInt_64 &id) const;
|
||||
|
||||
/// Checks whether a header variable exists using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasHeaderVar(const Str_8 &name) const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
/// @param [in] var The variable to add to the header.
|
||||
/// @returns False if the given variable name already exists. True otherwise.
|
||||
bool AddHeaderVar(HeaderVar var);
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
/// Removes a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveHeaderVar(const UInt_64 &id);
|
||||
|
||||
/// Removes a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveHeaderVar(const Str_8 &name);
|
||||
|
||||
/// Retrieves a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
HeaderVar *GetHeaderVar(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
HeaderVar *GetHeaderVar(const Str_8& name) const;
|
||||
|
||||
/// Retrieves a header variable value using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetHeaderValue(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable value using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetHeaderValue(const Str_8& name) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
Vector<HeaderVar> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToBody(const Str_8& var, const Str_8& value);
|
||||
void AddToBody(const Str_8 &var, const Str_8 &value);
|
||||
|
||||
/// Adds a value to the body.
|
||||
/// @param [in] data The value to add.
|
||||
void AddToBody(const Str_8& data);
|
||||
void AddToBody(const Str_8 &data);
|
||||
|
||||
/// Sets the entire body.
|
||||
/// @param [in] body The body to use.
|
||||
void SetBody(const Str_8& body);
|
||||
void SetBody(const Str_8 &body);
|
||||
|
||||
/// Retrieves a body variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the body variable. Empty if it was not found.
|
||||
Str_8 GetVar(const Str_8& var) const;
|
||||
Str_8 GetVar(const Str_8 &var) const;
|
||||
|
||||
/// Retrieves the entire body.
|
||||
/// @returns The result.
|
||||
@@ -152,13 +233,13 @@ namespace ehs
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 VerbToStr(const Verb verb);
|
||||
static Str_8 VerbToStr(const Verb &verb);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
static Str_8 ContentTypeToStr(const ContentType &cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
static ContentType StrToContentType(const Str_8 &value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
void ReadData(const Str_8 &data);
|
||||
|
||||
};
|
||||
}
|
@@ -5,6 +5,7 @@
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/json/Json.h"
|
||||
#include "Socket.h"
|
||||
#include "HeaderVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace ehs
|
||||
UInt_32 code;
|
||||
Str_8 server;
|
||||
ContentType cType;
|
||||
Vector<Str_8> header;
|
||||
Vector<HeaderVar> header;
|
||||
Str_8 body;
|
||||
|
||||
public:
|
||||
@@ -24,29 +25,38 @@ namespace ehs
|
||||
/// Initializes this response with a given code and server identifier.
|
||||
/// @param [in] code The code to give.
|
||||
/// @param [in] server The server identifier.
|
||||
Response(const UInt_32 code, const Str_8& server);
|
||||
Response(const UInt_32 &code, Str_8 server);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The C-style string of the response.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Response(const char* data, const UInt_64 size);
|
||||
Response(const char *data, const UInt_64 &size);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The string of the response.
|
||||
Response(const Str_8& data);
|
||||
Response(const Str_8 &data);
|
||||
|
||||
/// Moves members from another object of the same type.
|
||||
/// @param [in] other The object to move from.
|
||||
Response(Response &&other) noexcept;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
Response(const Response& res) = default;
|
||||
/// @param [in] other The object to copy from.
|
||||
Response(const Response &other);
|
||||
|
||||
/// Moves members from another object of the same type.
|
||||
/// @param [in] other The object to move from.
|
||||
/// @returns The response that has been assigned to.
|
||||
Response &operator=(Response &&other) noexcept;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
/// @returns The response that has been assigned to.
|
||||
Response& operator=(const Response& res);
|
||||
Response& operator=(const Response &other);
|
||||
|
||||
/// Sets the response code to send to the endpoint.
|
||||
/// @param [in] code The code for success, error or info.
|
||||
void SetCode(const UInt_32 code);
|
||||
void SetCode(const UInt_32 &code);
|
||||
|
||||
/// Retrieves the response code.
|
||||
/// @returns The result.
|
||||
@@ -54,7 +64,7 @@ namespace ehs
|
||||
|
||||
/// Sets the server identifier.
|
||||
/// @param [in] server The server identifier to use.
|
||||
void SetServer(const Str_8& server);
|
||||
void SetServer(Str_8 server);
|
||||
|
||||
/// Retrieves the server identifier.
|
||||
/// @returns The result.
|
||||
@@ -62,25 +72,60 @@ namespace ehs
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
void SetContentType(const ContentType &cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
ContentType GetContentType() const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
/// Checks whether a header variable exists using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasHeaderVar(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
/// Checks whether a header variable exists using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable exists. False otherwise.
|
||||
bool HasHeaderVar(const Str_8 &name) const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable to add to the header.
|
||||
/// @returns False if the given variable name already exists. True otherwise.
|
||||
bool AddHeaderVar(HeaderVar var);
|
||||
|
||||
/// Removes a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveHeaderVar(const UInt_64 &id);
|
||||
|
||||
/// Removes a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns True if the variable was found. False otherwise.
|
||||
bool RemoveHeaderVar(const Str_8 &name);
|
||||
|
||||
/// Retrieves a header variable using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
HeaderVar *GetHeaderVar(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable object if found. Nullptr otherwise.
|
||||
HeaderVar *GetHeaderVar(const Str_8& name) const;
|
||||
|
||||
/// Retrieves a header variable value using the id.
|
||||
/// @param [in] id The variable id to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetHeaderValue(const UInt_64 &id) const;
|
||||
|
||||
/// Retrieves a header variable value using the name.
|
||||
/// @param [in] name The variable name to look for.
|
||||
/// @returns The variable's value if found. Empty otherwise.
|
||||
Str_8 GetHeaderValue(const Str_8& name) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
Vector<HeaderVar> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
@@ -115,13 +160,13 @@ namespace ehs
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 CodeToStr(const UInt_32 code);
|
||||
static Str_8 CodeToStr(const UInt_32 &code);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
static Str_8 ContentTypeToStr(const ContentType &cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
static ContentType StrToContentType(const Str_8 &value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
void ReadData(const Str_8 &data);
|
||||
|
||||
};
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <openssl/types.h>
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "TCP.h"
|
||||
@@ -15,15 +17,18 @@ namespace ehs
|
||||
class EHS_LIB_IO SSL : public TCP
|
||||
{
|
||||
private:
|
||||
bool server;
|
||||
SSL_CTX* ctx;
|
||||
::SSL* sslHdl;
|
||||
X509 *cert;
|
||||
EVP_PKEY* pkey;
|
||||
|
||||
public:
|
||||
~SSL() override;
|
||||
|
||||
SSL();
|
||||
|
||||
SSL(const IP type);
|
||||
SSL(const IP &type, const bool &server);
|
||||
|
||||
SSL(TCP&& tcp) noexcept;
|
||||
|
||||
@@ -37,19 +42,19 @@ namespace ehs
|
||||
|
||||
void Release() override;
|
||||
|
||||
void Bind(const Str_8& address, unsigned short port) override;
|
||||
void Listen() override;
|
||||
|
||||
SSL* Accept() override;
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port) override;
|
||||
void Connect(Str_8 address, const UInt_16 &port) override;
|
||||
|
||||
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
|
||||
UInt_64 Send(const Byte* buffer, const UInt_32 size) override;
|
||||
|
||||
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
|
||||
UInt_64 Receive(Byte* buffer, const UInt_32 size) override;
|
||||
|
||||
void UseCertificate(const Byte* data, const UInt_64 size);
|
||||
void UseCertificate(const Char_8* data, const UInt_32 &size);
|
||||
|
||||
void UsePrivateKey(const Byte* data, const UInt_64 size);
|
||||
void UsePrivateKey(const Char_8* data, const UInt_32 &size);
|
||||
|
||||
bool IsValid();
|
||||
};
|
||||
|
@@ -40,7 +40,9 @@ namespace ehs
|
||||
APP_XML,
|
||||
TEXT_PLAIN,
|
||||
TEXT_HTML,
|
||||
TEXT_CSS,
|
||||
TEXT_XML,
|
||||
IMG_X_ICON,
|
||||
NONE
|
||||
};
|
||||
|
||||
|
@@ -46,7 +46,7 @@ namespace ehs
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, UInt_16 port) override;
|
||||
void Bind(Str_8 address, const UInt_16 &port) override;
|
||||
|
||||
/// Listens for incoming connections. Used for servers or PtP.
|
||||
void Listen() override;
|
||||
@@ -58,7 +58,7 @@ namespace ehs
|
||||
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
|
||||
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param port The port of the listening TCP socket.
|
||||
void Connect(const Str_8& address, UInt_16 port) override;
|
||||
void Connect(Str_8 address, const UInt_16 &port) override;
|
||||
|
||||
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [in] buffer The C-style array to send.
|
||||
@@ -84,15 +84,17 @@ namespace ehs
|
||||
|
||||
bool IsIPv6Only() const override;
|
||||
|
||||
void SetReuse(const bool &value) override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, UInt_16 port);
|
||||
void Bind_v6(const Str_8 &address, const UInt_16 &port) const;
|
||||
|
||||
void Bind_v4(const Str_8& address, UInt_16 port);
|
||||
void Bind_v4(const Str_8 &address, const UInt_16 &port) const;
|
||||
|
||||
void Connect_v6(const Str_8& address, UInt_16 port);
|
||||
void Connect_v6(const Str_8 &address, const UInt_16 &port);
|
||||
|
||||
void Connect_v4(const Str_8& address, UInt_16 port);
|
||||
void Connect_v4(const Str_8 &address, const UInt_16 &port);
|
||||
};
|
||||
}
|
@@ -46,7 +46,7 @@ namespace ehs
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, UInt_16 port) override;
|
||||
void Bind(Str_8 address, const UInt_16 &port) override;
|
||||
|
||||
/// Listens for incoming connections. Used for servers or PtP.
|
||||
void Listen() override;
|
||||
@@ -58,7 +58,7 @@ namespace ehs
|
||||
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
|
||||
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param port The port of the listening TCP socket.
|
||||
void Connect(const Str_8& address, UInt_16 port) override;
|
||||
void Connect(Str_8 address, const UInt_16 &port) override;
|
||||
|
||||
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [in] buffer The C-style array to send.
|
||||
@@ -84,12 +84,14 @@ namespace ehs
|
||||
|
||||
bool IsIPv6Only() const override;
|
||||
|
||||
void SetReuse(const bool &value) override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, UInt_16 port);
|
||||
void Bind_v6(const Str_8& address, const UInt_16 &port);
|
||||
|
||||
void Bind_v4(const Str_8& address, UInt_16 port);
|
||||
void Bind_v4(const Str_8& address, const UInt_16 &port);
|
||||
|
||||
void Connect_v6(const Str_8& address, UInt_16 port);
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class AVX2
|
||||
class EHS_LIB_IO AVX2
|
||||
{
|
||||
public:
|
||||
/// Compares two unaligned 4 element vectors using 64-bit integers.
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class AVX512
|
||||
class EHS_LIB_IO AVX512
|
||||
{
|
||||
public:
|
||||
/// Compares two unaligned 8 element vectors using 64-bit integers.
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#define EHS_64_BIT
|
||||
#elif defined(_M_ARM64) || defined(__aarch64__)
|
||||
#define EHS_LITTLE_ENDIAN
|
||||
#define EHS_ARCH_ARM64
|
||||
#define EHS_ARCH_AARCH64
|
||||
#define EHS_64_BIT
|
||||
#else
|
||||
#error Unsupported architecture.
|
||||
|
@@ -281,6 +281,8 @@ namespace ehs
|
||||
|
||||
//static Str_8 ToStr();
|
||||
|
||||
static UInt_64 RetrieveFreq_AARCH64();
|
||||
|
||||
static UInt_64 RetrieveTSC_Freq();
|
||||
|
||||
static UInt_64 CalculateTSC_Freq();
|
||||
|
10
src/Log.cpp
10
src/Log.cpp
@@ -75,12 +75,12 @@ namespace ehs
|
||||
{
|
||||
}
|
||||
|
||||
Log::Log(LogType type, const std::initializer_list<Str_8> &tags, const UInt_64 code, Str_8 msg)
|
||||
: type(type), tags(tags.size()), code(code), msg((Str_8&&)msg)
|
||||
Log::Log(LogType type, const Str_8 &tags, const UInt_64 code, Str_8 msg)
|
||||
: type(type), code(code), msg((Str_8&&)msg)
|
||||
{
|
||||
UInt_64 i = 0;
|
||||
for (auto v = tags.begin(); v != tags.end(); ++v)
|
||||
this->tags[i++] = *v;
|
||||
const Vector<Str_8> tmpTags = tags.Split(", ");
|
||||
|
||||
this->tags = Array<Str_8>(&tmpTags[0], tmpTags.Size());
|
||||
}
|
||||
|
||||
Log::Log(LogType type, Array<Str_8> tags, const UInt_64 code, Str_8 msg)
|
||||
|
@@ -51,7 +51,7 @@ namespace ehs
|
||||
}
|
||||
|
||||
return result;
|
||||
#elif defined(EHS_ARCH_ARM64)
|
||||
#elif defined(EHS_ARCH_AARCH64)
|
||||
return Sqrt_VFP4(from);
|
||||
#endif
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace ehs
|
||||
}
|
||||
|
||||
return result;
|
||||
#elif defined(EHS_ARCH_ARM64)
|
||||
#elif defined(EHS_ARCH_AARCH64)
|
||||
return Sqrt_VFP4(from);
|
||||
#endif
|
||||
}
|
||||
|
@@ -93,13 +93,13 @@ namespace ehs
|
||||
}
|
||||
|
||||
AudioDevice::AudioDevice()
|
||||
: id(0), loop(nullptr), context(nullptr), core(nullptr), input(nullptr), output(nullptr)
|
||||
: id(0), loop(nullptr), context(nullptr), core(nullptr), input(nullptr), output(nullptr), paramsHook{}
|
||||
{
|
||||
}
|
||||
|
||||
AudioDevice::AudioDevice(AudioDevice&& device) noexcept
|
||||
: BaseAudioDevice(device), id(device.id), name((Str_8 &&)device.name), loop(device.loop),
|
||||
context(device.context), core(device.core), input(device.input), output(device.output)
|
||||
context(device.context), core(device.core), input(device.input), output(device.output), paramsHook(device.paramsHook)
|
||||
{
|
||||
device.id = 0;
|
||||
device.loop = nullptr;
|
||||
@@ -107,11 +107,12 @@ namespace ehs
|
||||
device.core = nullptr;
|
||||
device.input = nullptr;
|
||||
device.output = nullptr;
|
||||
device.paramsHook = {};
|
||||
}
|
||||
|
||||
AudioDevice::AudioDevice(const AudioDevice& device)
|
||||
: BaseAudioDevice(device), id(device.id), name(device.name), loop(nullptr), context(nullptr), core(nullptr),
|
||||
input(nullptr), output(nullptr)
|
||||
input(nullptr), output(nullptr), paramsHook{}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -129,6 +130,7 @@ namespace ehs
|
||||
core = device.core;
|
||||
input = device.input;
|
||||
output = device.output;
|
||||
paramsHook = device.paramsHook;
|
||||
|
||||
device.id = 0;
|
||||
device.loop = nullptr;
|
||||
@@ -136,6 +138,7 @@ namespace ehs
|
||||
device.core = nullptr;
|
||||
device.input = nullptr;
|
||||
device.output = nullptr;
|
||||
device.paramsHook = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -154,6 +157,7 @@ namespace ehs
|
||||
core = nullptr;
|
||||
input = nullptr;
|
||||
output = nullptr;
|
||||
paramsHook = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -206,14 +210,18 @@ namespace ehs
|
||||
return;
|
||||
}
|
||||
|
||||
pw_stream_connect(
|
||||
output,
|
||||
SInt_32 err = pw_stream_connect(
|
||||
input,
|
||||
PW_DIRECTION_INPUT,
|
||||
id,
|
||||
(pw_stream_flags)(PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS),
|
||||
pod,
|
||||
1
|
||||
);
|
||||
if (err)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to connect input stream for audio device.");
|
||||
}
|
||||
}
|
||||
|
||||
if (GetType() == AudioDeviceType::OUTPUT || GetType() == AudioDeviceType::ALL)
|
||||
@@ -225,7 +233,7 @@ namespace ehs
|
||||
return;
|
||||
}
|
||||
|
||||
pw_stream_connect(
|
||||
SInt_32 err = pw_stream_connect(
|
||||
output,
|
||||
PW_DIRECTION_OUTPUT,
|
||||
id,
|
||||
@@ -233,6 +241,10 @@ namespace ehs
|
||||
pod,
|
||||
1
|
||||
);
|
||||
if (err)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to connect output stream for audio device.");
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr pw_stream_events streamEvents = {
|
||||
@@ -240,8 +252,17 @@ namespace ehs
|
||||
.param_changed = OnParamChanged
|
||||
};
|
||||
|
||||
spa_hook streamListener = {};
|
||||
pw_stream_add_listener(output, &streamListener, &streamEvents, this);
|
||||
pw_stream_add_listener(output, ¶msHook, &streamEvents, this);
|
||||
|
||||
while (pw_stream_get_state(output, nullptr) == PW_STREAM_STATE_CONNECTING)
|
||||
{
|
||||
SInt_32 err = pw_loop_iterate(loop, 0);
|
||||
if (err < 0)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 3, "Failed to update audio with error #" + Str_8::FromNum(err) + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
@@ -283,7 +304,15 @@ namespace ehs
|
||||
return 0;
|
||||
}
|
||||
|
||||
pw_loop_iterate(loop, 0);
|
||||
if (!data || !size)
|
||||
return 0;
|
||||
|
||||
SInt_32 err = pw_loop_iterate(loop, 0);
|
||||
if (err < 0)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to update audio with error #" + Str_8::FromNum(err) + ".");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pw_stream_get_state(output, nullptr) != PW_STREAM_STATE_STREAMING)
|
||||
return 0;
|
||||
|
@@ -36,93 +36,6 @@ namespace ehs
|
||||
return new Keyboard(*this);
|
||||
}
|
||||
|
||||
const Button Keyboard::Unknown("Unknown");
|
||||
const Button Keyboard::Escape("Escape Button");
|
||||
const Button Keyboard::Backspace("Backspace Button");
|
||||
const Button Keyboard::Enter("Enter Button");
|
||||
const Button Keyboard::LShift("Left Shift Button");
|
||||
const Button Keyboard::RShift("Right Shift Button");
|
||||
const Button Keyboard::LAlt("Left Alt Button");
|
||||
const Button Keyboard::RAlt("Right Alt Button");
|
||||
const Button Keyboard::LCtrl("Left Control Button");
|
||||
const Button Keyboard::RCtrl("Right Control Button");
|
||||
const Button Keyboard::Space("Space Button");
|
||||
const Button Keyboard::A("A Button");
|
||||
const Button Keyboard::B("B Button");
|
||||
const Button Keyboard::C("C Button");
|
||||
const Button Keyboard::D("D Button");
|
||||
const Button Keyboard::E("E Button");
|
||||
const Button Keyboard::F("F Button");
|
||||
const Button Keyboard::G("G Button");
|
||||
const Button Keyboard::H("H Button");
|
||||
const Button Keyboard::I("I Button");
|
||||
const Button Keyboard::J("J Button");
|
||||
const Button Keyboard::K("K Button");
|
||||
const Button Keyboard::L("L Button");
|
||||
const Button Keyboard::M("M Button");
|
||||
const Button Keyboard::N("N Button");
|
||||
const Button Keyboard::O("O Button");
|
||||
const Button Keyboard::P("P Button");
|
||||
const Button Keyboard::Q("Q Button");
|
||||
const Button Keyboard::R("R Button");
|
||||
const Button Keyboard::S("S Button");
|
||||
const Button Keyboard::T("T Button");
|
||||
const Button Keyboard::U("U Button");
|
||||
const Button Keyboard::V("V Button");
|
||||
const Button Keyboard::W("W Button");
|
||||
const Button Keyboard::X("X Button");
|
||||
const Button Keyboard::Y("Y Button");
|
||||
const Button Keyboard::Z("Z Button");
|
||||
const Button Keyboard::One("One Button");
|
||||
const Button Keyboard::Two("Two Button");
|
||||
const Button Keyboard::Three("Three Button");
|
||||
const Button Keyboard::Four("Four Button");
|
||||
const Button Keyboard::Five("Five Button");
|
||||
const Button Keyboard::Six("Six Button");
|
||||
const Button Keyboard::Seven("Seven Button");
|
||||
const Button Keyboard::Eight("Eight Button");
|
||||
const Button Keyboard::Nine("Nine Button");
|
||||
const Button Keyboard::Zero("Zero Button");
|
||||
const Button Keyboard::Equals("Equals Button");
|
||||
const Button Keyboard::Minus("Minus Button");
|
||||
const Button Keyboard::Tilde("Tilde Button");
|
||||
const Button Keyboard::BackSlash("Back Slash Button");
|
||||
const Button Keyboard::LeftSquareBracket("Left Square Bracket Button");
|
||||
const Button Keyboard::RightSquareBracket("Right Square Bracket Button");
|
||||
const Button Keyboard::SemiColon("Semi-Colon Button");
|
||||
const Button Keyboard::Apostrophe("Apostrophe Button");
|
||||
const Button Keyboard::Comma("Comma Button");
|
||||
const Button Keyboard::Period("Period Button");
|
||||
const Button Keyboard::ForwardSlash("Forward Slash Button");
|
||||
const Button Keyboard::F1("Function 1 Button");
|
||||
const Button Keyboard::F2("Function 2 Button");
|
||||
const Button Keyboard::F3("Function 3 Button");
|
||||
const Button Keyboard::F4("Function 4 Button");
|
||||
const Button Keyboard::F5("Function 5 Button");
|
||||
const Button Keyboard::F6("Function 6 Button");
|
||||
const Button Keyboard::F7("Function 7 Button");
|
||||
const Button Keyboard::F8("Function 8 Button");
|
||||
const Button Keyboard::F9("Function 9 Button");
|
||||
const Button Keyboard::F10("Function 10 Button");
|
||||
const Button Keyboard::F11("Function 11 Button");
|
||||
const Button Keyboard::F12("Function 12 Button");
|
||||
const Button Keyboard::F13("Function 13 Button");
|
||||
const Button Keyboard::F14("Function 14 Button");
|
||||
const Button Keyboard::F15("Function 15 Button");
|
||||
const Button Keyboard::F16("Function 16 Button");
|
||||
const Button Keyboard::F17("Function 17 Button");
|
||||
const Button Keyboard::F18("Function 18 Button");
|
||||
const Button Keyboard::F19("Function 19 Button");
|
||||
const Button Keyboard::F20("Function 20 Button");
|
||||
const Button Keyboard::F21("Function 21 Button");
|
||||
const Button Keyboard::F22("Function 22 Button");
|
||||
const Button Keyboard::F23("Function 23 Button");
|
||||
const Button Keyboard::F24("Function 24 Button");
|
||||
const Button Keyboard::Left("Left Arrow Button");
|
||||
const Button Keyboard::Right("Right Arrow Button");
|
||||
const Button Keyboard::Up("Up Arrow Button");
|
||||
const Button Keyboard::Down("Down Arrow Button");
|
||||
|
||||
Button Keyboard::TranslateScanCode(const UInt_32 code)
|
||||
{
|
||||
switch (code)
|
||||
|
@@ -50,19 +50,6 @@ namespace ehs
|
||||
return new Mouse(*this);
|
||||
}
|
||||
|
||||
const Button Mouse::Unknown("Unknown");
|
||||
const Button Mouse::LMB("Left Mouse Button");
|
||||
const Button Mouse::MMB("Middle Mouse Button");
|
||||
const Button Mouse::RMB("Right Mouse Button");
|
||||
const Button Mouse::Four("Mouse Button Four");
|
||||
const Button Mouse::Five("Mouse Button Five");
|
||||
const Button Mouse::ScrollUp("Scroll Up");
|
||||
const Button Mouse::ScrollDown("Scroll Down");
|
||||
const Button Mouse::ScrollLeft("Scroll Left");
|
||||
const Button Mouse::ScrollRight("Scroll Right");
|
||||
const Button Mouse::Back("Back Mouse Button");
|
||||
const Button Mouse::Forward("Forward Mouse Button");
|
||||
|
||||
Button Mouse::TranslateXCB(const UInt_32 code)
|
||||
{
|
||||
switch (code)
|
||||
|
@@ -108,7 +108,7 @@ namespace ehs
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
req.AddToHeader("Host", remoteHostName);
|
||||
req.AddHeaderVar({"Host", remoteHostName});
|
||||
|
||||
SendStr(req.FormResult());
|
||||
}
|
||||
@@ -124,10 +124,10 @@ namespace ehs
|
||||
|
||||
Response response(header);
|
||||
|
||||
Str_8 encoding = response.GetHeader("Transfer-Encoding");
|
||||
Str_8 encoding = response.GetHeaderValue("Transfer-Encoding");
|
||||
if (!encoding.Size())
|
||||
{
|
||||
int bodySize = response.GetHeader("content-length").ToDecimal<int>();
|
||||
int bodySize = response.GetHeaderValue("content-length").ToDecimal<int>();
|
||||
if (!bodySize)
|
||||
return response;
|
||||
|
||||
@@ -163,10 +163,10 @@ namespace ehs
|
||||
if (request.GetVerb() == Verb::GET)
|
||||
return request;
|
||||
|
||||
Str_8 encoding = request.GetHeader("Transfer-Encoding");
|
||||
Str_8 encoding = request.GetHeaderValue("Transfer-Encoding");
|
||||
if (!encoding.Size())
|
||||
{
|
||||
int bodySize = request.GetHeader("Content-Length").ToDecimal<int>();
|
||||
int bodySize = request.GetHeaderValue("Content-Length").ToDecimal<int>();
|
||||
if (!bodySize)
|
||||
return request;
|
||||
|
||||
|
96
src/io/socket/HeaderVar.cpp
Normal file
96
src/io/socket/HeaderVar.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "ehs/io/socket/HeaderVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
HeaderVar::HeaderVar()
|
||||
: id(0)
|
||||
{
|
||||
}
|
||||
|
||||
HeaderVar::HeaderVar(Str_8 name, Str_8 value)
|
||||
: id(name.Hash_64()), name((Str_8 &&)name), value((Str_8 &&)value)
|
||||
{
|
||||
}
|
||||
|
||||
HeaderVar::HeaderVar(HeaderVar&& other) noexcept
|
||||
: id(other.id), name((Str_8 &&)other.name), value((Str_8 &&)other.value)
|
||||
{
|
||||
other.id = 0;
|
||||
}
|
||||
|
||||
HeaderVar::HeaderVar(const HeaderVar& other)
|
||||
: id(other.id), name(other.name), value(other.value)
|
||||
{
|
||||
}
|
||||
|
||||
HeaderVar& HeaderVar::operator=(HeaderVar&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
id = other.id;
|
||||
name = (Str_8 &&)other.name;
|
||||
value = (Str_8 &&)other.value;
|
||||
|
||||
other.id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
HeaderVar& HeaderVar::operator=(const HeaderVar& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
id = other.id;
|
||||
name = other.name;
|
||||
value = other.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool HeaderVar::operator==(const HeaderVar& other) const
|
||||
{
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
bool HeaderVar::operator!=(const HeaderVar& other) const
|
||||
{
|
||||
return id != other.id;
|
||||
}
|
||||
|
||||
bool HeaderVar::operator==(const UInt_64& otherId) const
|
||||
{
|
||||
return id == otherId;
|
||||
}
|
||||
|
||||
bool HeaderVar::operator!=(const UInt_64& otherId) const
|
||||
{
|
||||
return id != otherId;
|
||||
}
|
||||
|
||||
UInt_64 HeaderVar::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
Str_8 HeaderVar::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
Str_8 HeaderVar::GetValue() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void HeaderVar::SetValue(Str_8 value)
|
||||
{
|
||||
this->value = (Str_8 &&)value;
|
||||
}
|
||||
|
||||
Str_8 HeaderVar::ToStr() const
|
||||
{
|
||||
return name + ": " + value;
|
||||
}
|
||||
}
|
96
src/io/socket/QueryVar.cpp
Normal file
96
src/io/socket/QueryVar.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "ehs/io/socket/QueryVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
QueryVar::QueryVar()
|
||||
: id(0)
|
||||
{
|
||||
}
|
||||
|
||||
QueryVar::QueryVar(Str_8 name, Str_8 value)
|
||||
: id(name.Hash_64()), name((Str_8 &&)name), value((Str_8 &&)value)
|
||||
{
|
||||
}
|
||||
|
||||
QueryVar::QueryVar(QueryVar&& other) noexcept
|
||||
: id(other.id), name((Str_8 &&)other.name), value((Str_8 &&)other.value)
|
||||
{
|
||||
other.id = 0;
|
||||
}
|
||||
|
||||
QueryVar::QueryVar(const QueryVar& other)
|
||||
: id(other.id), name(other.name), value(other.value)
|
||||
{
|
||||
}
|
||||
|
||||
QueryVar& QueryVar::operator=(QueryVar&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
id = other.id;
|
||||
name = (Str_8 &&)other.name;
|
||||
value = (Str_8 &&)other.value;
|
||||
|
||||
other.id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QueryVar& QueryVar::operator=(const QueryVar& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
id = other.id;
|
||||
name = other.name;
|
||||
value = other.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool QueryVar::operator==(const QueryVar& other) const
|
||||
{
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
bool QueryVar::operator!=(const QueryVar& other) const
|
||||
{
|
||||
return id != other.id;
|
||||
}
|
||||
|
||||
bool QueryVar::operator==(const UInt_64& otherId) const
|
||||
{
|
||||
return id == otherId;
|
||||
}
|
||||
|
||||
bool QueryVar::operator!=(const UInt_64& otherId) const
|
||||
{
|
||||
return id != otherId;
|
||||
}
|
||||
|
||||
UInt_64 QueryVar::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
Str_8 QueryVar::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
Str_8 QueryVar::GetValue() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void QueryVar::SetValue(Str_8 value)
|
||||
{
|
||||
this->value = (Str_8 &&)value;
|
||||
}
|
||||
|
||||
Str_8 QueryVar::ToStr() const
|
||||
{
|
||||
return name + "=" + value;
|
||||
}
|
||||
}
|
@@ -4,38 +4,70 @@
|
||||
namespace ehs
|
||||
{
|
||||
Request::Request()
|
||||
: verb(Verb::GET), cType(ContentType::NONE)
|
||||
: verb(Verb::POST), cType(ContentType::NONE)
|
||||
{
|
||||
}
|
||||
|
||||
Request::Request(const Verb verb, const Str_8& rsrc)
|
||||
: verb(verb), rsrc(rsrc), cType(ContentType::NONE)
|
||||
Request::Request(const Verb &verb, Str_8 rsrc)
|
||||
: verb(verb), rsrc((Str_8 &&)rsrc), cType(ContentType::NONE)
|
||||
{
|
||||
}
|
||||
|
||||
Request::Request(const char* data, const UInt_64 size)
|
||||
Request::Request(const char *data, const UInt_64 &size)
|
||||
: verb(Verb::POST), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(Str_8(data, size));
|
||||
}
|
||||
|
||||
Request::Request(const Str_8& data)
|
||||
Request::Request(const Str_8 &data)
|
||||
: verb(Verb::POST), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(data);
|
||||
}
|
||||
|
||||
Request& Request::operator=(const Request &req)
|
||||
|
||||
Request::Request(Request&& other) noexcept
|
||||
: verb(other.verb), rsrc((Str_8 &&)other.rsrc), queries((Vector<QueryVar> &&)other.queries),
|
||||
header((Vector<HeaderVar> &&)other.header), cType(other.cType), body((Str_8 &&)other.body)
|
||||
{
|
||||
if (this == &req)
|
||||
other.verb = Verb::POST;
|
||||
other.cType = ContentType::NONE;
|
||||
}
|
||||
|
||||
Request::Request(const Request& other)
|
||||
: verb(other.verb), rsrc(other.rsrc), queries(other.queries), header(other.header), cType(other.cType),
|
||||
body(other.body)
|
||||
{
|
||||
}
|
||||
|
||||
Request& Request::operator=(Request&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
verb = other.verb;
|
||||
rsrc = (Str_8 &&)other.rsrc;
|
||||
queries = (Vector<QueryVar> &&)other.queries;
|
||||
header = (Vector<HeaderVar> &&)other.header;
|
||||
cType = other.cType;
|
||||
body = (Str_8 &&)other.body;
|
||||
|
||||
other.verb = Verb::POST;
|
||||
other.cType = ContentType::NONE;
|
||||
|
||||
return* this;
|
||||
}
|
||||
|
||||
Request& Request::operator=(const Request &other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
verb = req.verb;
|
||||
rsrc = req.rsrc;
|
||||
queries = req.queries;
|
||||
header = req.header;
|
||||
cType = req.cType;
|
||||
body = req.body;
|
||||
verb = other.verb;
|
||||
rsrc = other.rsrc;
|
||||
queries = other.queries;
|
||||
header = other.header;
|
||||
cType = other.cType;
|
||||
body = other.body;
|
||||
|
||||
return* this;
|
||||
}
|
||||
@@ -45,7 +77,7 @@ namespace ehs
|
||||
return verb;
|
||||
}
|
||||
|
||||
void Request::SetContentType(const ContentType cType)
|
||||
void Request::SetContentType(const ContentType &cType)
|
||||
{
|
||||
if (body.Size())
|
||||
body.Resize(0);
|
||||
@@ -58,9 +90,9 @@ namespace ehs
|
||||
return cType;
|
||||
}
|
||||
|
||||
void Request::SetResource(const Str_8& rsrc)
|
||||
void Request::SetResource(Str_8 rsrc)
|
||||
{
|
||||
this->rsrc = rsrc;
|
||||
this->rsrc = (Str_8 &&)rsrc;
|
||||
}
|
||||
|
||||
Str_8 Request::GetResource() const
|
||||
@@ -68,69 +100,179 @@ namespace ehs
|
||||
return rsrc;
|
||||
}
|
||||
|
||||
void Request::AddQuery(const Str_8& var, const Str_8& value)
|
||||
bool Request::HasQueryVar(const UInt_64& id) const
|
||||
{
|
||||
queries.Push(var + "=" + value);
|
||||
for (UInt_64 i = 0; i < queries.Size(); ++i)
|
||||
if (queries[i] == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Str_8 Request::GetQuery(const Str_8& var)
|
||||
bool Request::HasQueryVar(const Str_8& name) const
|
||||
{
|
||||
return HasQueryVar(name.Hash_64());
|
||||
}
|
||||
|
||||
bool Request::AddQueryVar(QueryVar var)
|
||||
{
|
||||
if (HasQueryVar(var.GetId()))
|
||||
return false;
|
||||
|
||||
queries.Push((QueryVar &&)var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Request::RemoveQueryVar(const UInt_64& id)
|
||||
{
|
||||
for (UInt_64 i = 0; i < queries.Size(); ++i)
|
||||
{
|
||||
Vector<Str_8> data = queries[i].Split("=");
|
||||
if (queries[i] != id)
|
||||
continue;
|
||||
|
||||
if (data[0] == var)
|
||||
return data[1];
|
||||
queries.Swap(i, queries.End());
|
||||
queries.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return "";
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Str_8> Request::GetQueries() const
|
||||
bool Request::RemoveQueryVar(const Str_8& name)
|
||||
{
|
||||
return RemoveQueryVar(name.Hash_64());
|
||||
}
|
||||
|
||||
QueryVar *Request::GetQueryVar(const UInt_64& id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < queries.Size(); ++i)
|
||||
if (queries[i] == id)
|
||||
return &queries[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QueryVar *Request::GetQueryVar(const Str_8& name) const
|
||||
{
|
||||
return GetQueryVar(name.Hash_64());
|
||||
}
|
||||
|
||||
Str_8 Request::GetQueryValue(const UInt_64& id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < queries.Size(); ++i)
|
||||
if (queries[i] == id)
|
||||
return queries[i].GetValue();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Str_8 Request::GetQueryValue(const Str_8& name) const
|
||||
{
|
||||
return GetQueryValue(name.Hash_64());
|
||||
}
|
||||
|
||||
Vector<QueryVar> Request::GetQueries() const
|
||||
{
|
||||
return queries;
|
||||
}
|
||||
|
||||
void Request::BasicAuth(const Str_8& id, const Str_8& secret)
|
||||
{
|
||||
AddToHeader("Authorization", Str_8("Basic ") + Base64::Encode(id + ":" + secret));
|
||||
AddHeaderVar({"Authorization", Str_8("Basic ") + Base64::Encode(id + ":" + secret)});
|
||||
}
|
||||
|
||||
void Request::BearerAuth(const Str_8& token)
|
||||
{
|
||||
AddToHeader("Authorization", "Bearer " + token);
|
||||
AddHeaderVar({"Authorization", "Bearer " + token});
|
||||
}
|
||||
|
||||
void Request::BearerAuth(const Str_8& token, const Str_8& clientId)
|
||||
{
|
||||
AddToHeader("Authorization", "Bearer " + token);
|
||||
AddToHeader("Client-Id", clientId);
|
||||
AddHeaderVar({"Authorization", "Bearer " + token});
|
||||
AddHeaderVar({"Client-Id", clientId});
|
||||
}
|
||||
|
||||
void Request::BotAuth(const Str_8& token)
|
||||
{
|
||||
AddToHeader("Authorization", "Bot " + token);
|
||||
}
|
||||
|
||||
void Request::AddToHeader(const Str_8& var, const Str_8& value)
|
||||
{
|
||||
header.Push(var + ": " + value);
|
||||
AddHeaderVar({"Authorization", "Bot " + token});
|
||||
}
|
||||
|
||||
Str_8 Request::GetHeader(const Str_8& var) const
|
||||
bool Request::HasHeaderVar(const UInt_64& id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Request::HasHeaderVar(const Str_8& name) const
|
||||
{
|
||||
return HasHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
bool Request::AddHeaderVar(HeaderVar var)
|
||||
{
|
||||
if (HasHeaderVar(var.GetId()))
|
||||
return false;
|
||||
|
||||
header.Push((HeaderVar &&)var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Request::RemoveHeaderVar(const UInt_64 &id)
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
{
|
||||
Vector<Str_8> data = header[i].Split(": ");
|
||||
if (header[i] != id)
|
||||
continue;
|
||||
|
||||
if (data[0] == var)
|
||||
return data[1];
|
||||
header.Swap(i, header.End());
|
||||
header.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return "";
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Str_8> Request::GetHeader() const
|
||||
|
||||
bool Request::RemoveHeaderVar(const Str_8 &name)
|
||||
{
|
||||
return RemoveHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
HeaderVar *Request::GetHeaderVar(const UInt_64 &id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return &header[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HeaderVar *Request::GetHeaderVar(const Str_8 &name) const
|
||||
{
|
||||
return GetHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
Str_8 Request::GetHeaderValue(const UInt_64 &id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return header[i].GetValue();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Str_8 Request::GetHeaderValue(const Str_8 &name) const
|
||||
{
|
||||
return GetHeaderValue(name.Hash_64());
|
||||
}
|
||||
|
||||
Vector<HeaderVar> Request::GetHeader() const
|
||||
{
|
||||
return header;
|
||||
}
|
||||
@@ -200,16 +342,20 @@ namespace ehs
|
||||
Str_8 result = VerbToStr(verb) + " " + rsrc;
|
||||
|
||||
if (queries.Size())
|
||||
result += "?" + queries[0];
|
||||
result += "?" + queries[0].ToStr();
|
||||
|
||||
for (UInt_64 i = 1; i < queries.Size(); ++i)
|
||||
result += "&" + queries[i];
|
||||
result += "&" + queries[i].ToStr();
|
||||
|
||||
result += " HTTP/1.1\r\n";
|
||||
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
{
|
||||
result += header[i] + "\r\n";
|
||||
if (header[i] == 11245195881701120957ull || header[i] == 6556302699635904946ull ||
|
||||
header[i] == 13347276190653935221ull) // Content-Length, Server, and Content-Type in order from left to right.
|
||||
continue;
|
||||
|
||||
result += header[i].ToStr() + "\r\n";
|
||||
}
|
||||
|
||||
result += "Content-Type: " + ContentTypeToStr(cType) + "\r\n";
|
||||
@@ -227,7 +373,7 @@ namespace ehs
|
||||
return rsrc.Size() || queries.Size() || header.Size() || body.Size();
|
||||
}
|
||||
|
||||
Str_8 Request::VerbToStr(const Verb verb)
|
||||
Str_8 Request::VerbToStr(const Verb &verb)
|
||||
{
|
||||
switch (verb)
|
||||
{
|
||||
@@ -244,7 +390,7 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
Str_8 Request::ContentTypeToStr(const ContentType cType)
|
||||
Str_8 Request::ContentTypeToStr(const ContentType &cType)
|
||||
{
|
||||
switch (cType)
|
||||
{
|
||||
@@ -262,14 +408,18 @@ namespace ehs
|
||||
return "text/plain";
|
||||
case ContentType::TEXT_HTML:
|
||||
return "text/html";
|
||||
case ContentType::TEXT_CSS:
|
||||
return "text/css";
|
||||
case ContentType::TEXT_XML:
|
||||
return "text/xml";
|
||||
case ContentType::IMG_X_ICON:
|
||||
return "image/x-icon";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
ContentType Request::StrToContentType(const Str_8& value)
|
||||
ContentType Request::StrToContentType(const Str_8 &value)
|
||||
{
|
||||
if (value == "multipart/form-data")
|
||||
return ContentType::APP_MULTIPART_FORMDATA;
|
||||
@@ -285,13 +435,17 @@ namespace ehs
|
||||
return ContentType::TEXT_PLAIN;
|
||||
else if (value == "text/html")
|
||||
return ContentType::TEXT_HTML;
|
||||
else if (value == "text/css")
|
||||
return ContentType::TEXT_CSS;
|
||||
else if (value == "text/xml")
|
||||
return ContentType::TEXT_XML;
|
||||
else if (value == "image/x-icon")
|
||||
return ContentType::IMG_X_ICON;
|
||||
else
|
||||
return ContentType::NONE;
|
||||
}
|
||||
|
||||
void Request::ReadData(const Str_8& data)
|
||||
void Request::ReadData(const Str_8 &data)
|
||||
{
|
||||
Vector<Str_8> lines = data.Split("\r\n");
|
||||
Vector<Str_8> meta = lines[0].Split(" ");
|
||||
@@ -308,7 +462,14 @@ namespace ehs
|
||||
{
|
||||
rsrc = meta[1].Sub(0, queryIndex);
|
||||
cType = ContentType::APP_FORMURLENCODED;
|
||||
queries = meta[1].Sub(queryIndex + 1).Split("&");
|
||||
|
||||
Vector<Str_8> strQueries = meta[1].Sub(queryIndex + 1).Split("&");
|
||||
for (UInt_64 i = 0; i < strQueries.Size(); ++i)
|
||||
{
|
||||
const Vector<Str_8> queryVar = strQueries[i].Split("=");
|
||||
|
||||
queries.Push({queryVar[0], queryVar[1]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -331,7 +492,9 @@ namespace ehs
|
||||
if (var[0] == "Content-Length")
|
||||
continue;
|
||||
|
||||
header.Push(lines[i]);
|
||||
Vector<Str_8> headerVar = lines[i].Split(": ");
|
||||
|
||||
header.Push({headerVar[0], headerVar[1]});
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,43 +2,73 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Response::Response(const UInt_32 code, const Str_8& server)
|
||||
: code(code), server(server), cType(ContentType::NONE)
|
||||
{
|
||||
}
|
||||
|
||||
Response::Response(const char* data, const UInt_64 size)
|
||||
: code(0), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(Str_8(data, size));
|
||||
}
|
||||
|
||||
Response::Response(const Str_8& data)
|
||||
: code(0), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(data);
|
||||
}
|
||||
|
||||
Response::Response()
|
||||
: code(0), cType(ContentType::NONE)
|
||||
{
|
||||
}
|
||||
|
||||
Response& Response::operator=(const Response& res)
|
||||
Response::Response(const UInt_32 &code, Str_8 server)
|
||||
: code(code), server((Str_8 &&)server), cType(ContentType::NONE)
|
||||
{
|
||||
if (this == &res)
|
||||
return *this;
|
||||
}
|
||||
|
||||
code = res.code;
|
||||
server = res.server;
|
||||
cType = res.cType;
|
||||
header = res.header;
|
||||
body = res.body;
|
||||
Response::Response(const char *data, const UInt_64 &size)
|
||||
: code(0), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(Str_8(data, size));
|
||||
}
|
||||
|
||||
Response::Response(const Str_8 &data)
|
||||
: code(0), cType(ContentType::NONE)
|
||||
{
|
||||
ReadData(data);
|
||||
}
|
||||
|
||||
Response::Response(Response&& other) noexcept
|
||||
: code(other.code), server((Str_8 &&)other.server), cType(other.cType), header((Vector<HeaderVar> &&)other.header),
|
||||
body((Str_8 &&)other.body)
|
||||
{
|
||||
other.code = 0;
|
||||
other.cType = ContentType::NONE;
|
||||
}
|
||||
|
||||
Response::Response(const Response &other)
|
||||
: code(other.code), server(other.server), cType(other.cType), header(other.header), body(other.body)
|
||||
{
|
||||
}
|
||||
|
||||
Response& Response::operator=(Response&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
code = other.code;
|
||||
server = (Str_8 &&)other.server;
|
||||
cType = other.cType;
|
||||
header = (Vector<HeaderVar> &&)other.header;
|
||||
body = (Str_8 &&)other.body;
|
||||
|
||||
other.code = 0;
|
||||
other.cType = ContentType::NONE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Response::SetCode(const UInt_32 code)
|
||||
Response& Response::operator=(const Response& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
code = other.code;
|
||||
server = other.server;
|
||||
cType = other.cType;
|
||||
header = other.header;
|
||||
body = other.body;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Response::SetCode(const UInt_32 &code)
|
||||
{
|
||||
this->code = code;
|
||||
}
|
||||
@@ -48,9 +78,9 @@ namespace ehs
|
||||
return code;
|
||||
}
|
||||
|
||||
void Response::SetServer(const Str_8& server)
|
||||
void Response::SetServer(Str_8 server)
|
||||
{
|
||||
this->server = server;
|
||||
this->server = (Str_8 &&)server;
|
||||
}
|
||||
|
||||
Str_8 Response::GetServer() const
|
||||
@@ -58,7 +88,7 @@ namespace ehs
|
||||
return server;
|
||||
}
|
||||
|
||||
void Response::SetContentType(const ContentType cType)
|
||||
void Response::SetContentType(const ContentType &cType)
|
||||
{
|
||||
this->cType = cType;
|
||||
}
|
||||
@@ -68,27 +98,80 @@ namespace ehs
|
||||
return cType;
|
||||
}
|
||||
|
||||
void Response::AddToHeader(const Str_8& var, const Str_8& value)
|
||||
bool Response::HasHeaderVar(const UInt_64& id) const
|
||||
{
|
||||
header.Push(var + ": " + value);
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Str_8 Response::GetHeader(const Str_8& var) const
|
||||
bool Response::HasHeaderVar(const Str_8& name) const
|
||||
{
|
||||
Str_8 lIdentity = var.GetLower();
|
||||
return HasHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
bool Response::AddHeaderVar(HeaderVar var)
|
||||
{
|
||||
if (HasHeaderVar(var.GetId()))
|
||||
return false;
|
||||
|
||||
header.Push((HeaderVar &&)var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Response::RemoveHeaderVar(const UInt_64& id)
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
{
|
||||
Vector<Str_8> data = header[i].Split(": ");
|
||||
if (header[i] != id)
|
||||
continue;
|
||||
|
||||
if (data[0].GetLower() == lIdentity)
|
||||
return data[1];
|
||||
header.Swap(i, header.End());
|
||||
header.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return "";
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Str_8> Response::GetHeader() const
|
||||
bool Response::RemoveHeaderVar(const Str_8& name)
|
||||
{
|
||||
return RemoveHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
HeaderVar* Response::GetHeaderVar(const UInt_64 &id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return &header[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HeaderVar *Response::GetHeaderVar(const Str_8 &name) const
|
||||
{
|
||||
return GetHeaderVar(name.Hash_64());
|
||||
}
|
||||
|
||||
Str_8 Response::GetHeaderValue(const UInt_64& id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
if (header[i] == id)
|
||||
return header[i].GetValue();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Str_8 Response::GetHeaderValue(const Str_8& name) const
|
||||
{
|
||||
return GetHeaderValue(name.Hash_64());
|
||||
}
|
||||
|
||||
Vector<HeaderVar> Response::GetHeader() const
|
||||
{
|
||||
return header;
|
||||
}
|
||||
@@ -159,14 +242,11 @@ namespace ehs
|
||||
|
||||
for (UInt_64 i = 0; i < header.Size(); ++i)
|
||||
{
|
||||
if (header[i].Find("Content-Length", nullptr, SearchPattern::LEFT_RIGHT, IndexResult::ENDING))
|
||||
continue;
|
||||
else if (header[i].Find("Server", nullptr, SearchPattern::LEFT_RIGHT, IndexResult::ENDING))
|
||||
continue;
|
||||
else if (header[i].Find("Content-Type", nullptr, SearchPattern::LEFT_RIGHT, IndexResult::ENDING))
|
||||
if (header[i] == 11245195881701120957ull || header[i] == 6556302699635904946ull ||
|
||||
header[i] == 13347276190653935221ull) // Content-Length, Server, and Content-Type in order from left to right.
|
||||
continue;
|
||||
|
||||
result += header[i] + "\r\n";
|
||||
result += header[i].ToStr() + "\r\n";
|
||||
}
|
||||
|
||||
result += "Content-Type: " + ContentTypeToStr(cType) + "\r\nContent-Length: " + Str_8::FromNum(body.Size()) + "\r\n\r\n" + body;
|
||||
@@ -179,7 +259,7 @@ namespace ehs
|
||||
return server.Size() || header.Size() || body.Size();
|
||||
}
|
||||
|
||||
Str_8 Response::CodeToStr(const UInt_32 code)
|
||||
Str_8 Response::CodeToStr(const UInt_32 &code)
|
||||
{
|
||||
if (code == 100)
|
||||
return "Continue";
|
||||
@@ -323,7 +403,7 @@ namespace ehs
|
||||
return "Unused Status Code";
|
||||
}
|
||||
|
||||
Str_8 Response::ContentTypeToStr(const ContentType cType)
|
||||
Str_8 Response::ContentTypeToStr(const ContentType &cType)
|
||||
{
|
||||
switch (cType)
|
||||
{
|
||||
@@ -341,14 +421,18 @@ namespace ehs
|
||||
return "text/plain";
|
||||
case ContentType::TEXT_HTML:
|
||||
return "text/html";
|
||||
case ContentType::TEXT_CSS:
|
||||
return "text/css";
|
||||
case ContentType::TEXT_XML:
|
||||
return "text/xml";
|
||||
case ContentType::IMG_X_ICON:
|
||||
return "image/x-icon";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
ContentType Response::StrToContentType(const Str_8& value)
|
||||
ContentType Response::StrToContentType(const Str_8 &value)
|
||||
{
|
||||
if (value == "multipart/form-data")
|
||||
return ContentType::APP_MULTIPART_FORMDATA;
|
||||
@@ -364,13 +448,17 @@ namespace ehs
|
||||
return ContentType::TEXT_PLAIN;
|
||||
else if (value == "text/html")
|
||||
return ContentType::TEXT_HTML;
|
||||
else if (value == "text/css")
|
||||
return ContentType::TEXT_CSS;
|
||||
else if (value == "text/xml")
|
||||
return ContentType::TEXT_XML;
|
||||
else if (value == "image/x-icon")
|
||||
return ContentType::IMG_X_ICON;
|
||||
else
|
||||
return ContentType::NONE;
|
||||
}
|
||||
|
||||
void Response::ReadData(const Str_8& data)
|
||||
void Response::ReadData(const Str_8 &data)
|
||||
{
|
||||
Vector<Str_8> lines = data.Split("\r\n");
|
||||
Vector<Str_8> meta = lines[0].Split(" ");
|
||||
@@ -384,12 +472,12 @@ namespace ehs
|
||||
|
||||
Vector<Str_8> var = lines[i].Split(": ");
|
||||
|
||||
if (var[0].GetLower() == "server")
|
||||
if (var[0] == "Server")
|
||||
{
|
||||
server = var[1];
|
||||
continue;
|
||||
}
|
||||
else if (var[0].GetLower() == "content-type")
|
||||
else if (var[0] == "Content-Type")
|
||||
{
|
||||
Vector<Str_8> ctData = var[1].Split(";");
|
||||
|
||||
@@ -397,7 +485,9 @@ namespace ehs
|
||||
continue;
|
||||
}
|
||||
|
||||
header.Push(lines[i]);
|
||||
Vector<Str_8> headerVar = lines[i].Split(": ");
|
||||
|
||||
header.Push({headerVar[0], headerVar[1]});
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/provider.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -12,6 +14,11 @@ namespace ehs
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
X509_free(cert);
|
||||
|
||||
|
||||
if (sslHdl)
|
||||
{
|
||||
if (connection)
|
||||
@@ -25,28 +32,28 @@ namespace ehs
|
||||
}
|
||||
|
||||
SSL::SSL()
|
||||
: ctx(nullptr), sslHdl(nullptr)
|
||||
: server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
SSL::SSL(const IP type)
|
||||
: TCP(type), ctx(nullptr), sslHdl(nullptr)
|
||||
SSL::SSL(const IP &type, const bool &server)
|
||||
: TCP(type), server(server), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr)
|
||||
{
|
||||
SSL::Initialize();
|
||||
}
|
||||
|
||||
SSL::SSL(TCP&& tcp) noexcept
|
||||
: TCP(std::move(tcp)), ctx(nullptr), sslHdl(nullptr)
|
||||
: TCP(std::move(tcp)), server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
SSL::SSL(const TCP& tcp)
|
||||
: TCP(tcp), ctx(nullptr), sslHdl(nullptr)
|
||||
: TCP(tcp), server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
SSL::SSL(const SSL& ssl)
|
||||
: TCP(ssl), ctx(nullptr), sslHdl(nullptr)
|
||||
: TCP(ssl), server(ssl.server), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,8 +64,11 @@ namespace ehs
|
||||
|
||||
TCP::operator=(ssl);
|
||||
|
||||
server = ssl.server;
|
||||
ctx = nullptr;
|
||||
sslHdl = nullptr;
|
||||
cert = nullptr;
|
||||
pkey = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -71,6 +81,40 @@ namespace ehs
|
||||
return;
|
||||
|
||||
SSL_library_init();
|
||||
OpenSSL_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, nullptr);
|
||||
OSSL_PROVIDER_load(nullptr, "default");
|
||||
|
||||
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
|
||||
|
||||
if (server)
|
||||
{
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
if (!ctx)
|
||||
{
|
||||
UInt_32 code = ERR_get_error();
|
||||
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
|
||||
}
|
||||
|
||||
SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!MD5");
|
||||
SSL_CTX_set_ciphersuites(ctx,
|
||||
"TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:"
|
||||
"TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx = SSL_CTX_new(TLS_client_method());
|
||||
if (!ctx)
|
||||
{
|
||||
UInt_32 code = ERR_get_error();
|
||||
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
|
||||
}
|
||||
|
||||
SSL_CTX_set_default_verify_paths(ctx);
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SSL::Release()
|
||||
@@ -80,6 +124,12 @@ namespace ehs
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = nullptr;
|
||||
|
||||
X509_free(cert);
|
||||
cert = nullptr;
|
||||
|
||||
if (sslHdl)
|
||||
{
|
||||
if (connection)
|
||||
@@ -97,46 +147,37 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void SSL::Bind(const Str_8& address, unsigned short port)
|
||||
void SSL::Listen()
|
||||
{
|
||||
if (bound)
|
||||
return;
|
||||
sslHdl = SSL_new(ctx);
|
||||
SSL_set_fd(sslHdl, hdl);
|
||||
|
||||
OpenSSL_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
TCP::Listen();
|
||||
|
||||
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
|
||||
|
||||
SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!MD5");
|
||||
SSL_CTX_set_ciphersuites(ctx,
|
||||
"TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:"
|
||||
"TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256"
|
||||
);
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10101000L
|
||||
SSL_CTX_set_ecdh_auto(ctx, 1);
|
||||
#endif
|
||||
|
||||
sslHdl = SSL_new(ctx);
|
||||
SSL_set_fd(sslHdl, hdl);
|
||||
|
||||
TCP::Bind(address, port);
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
SSL* SSL::Accept()
|
||||
SSL* SSL::Accept()
|
||||
{
|
||||
if (!bound)
|
||||
return nullptr;
|
||||
|
||||
TCP* tcp = TCP::Accept();
|
||||
if (!tcp)
|
||||
return nullptr;
|
||||
|
||||
SSL* client = new SSL(std::move(*tcp));
|
||||
|
||||
delete tcp;
|
||||
|
||||
client->ctx = nullptr;
|
||||
client->sslHdl = SSL_new(ctx);
|
||||
client->sslHdl = SSL_new(this->ctx);
|
||||
if (!client->sslHdl)
|
||||
{
|
||||
UInt_32 code = ERR_get_error();
|
||||
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SSL_set_fd(client->sslHdl, client->hdl);
|
||||
|
||||
int err = SSL_accept(client->sslHdl);
|
||||
@@ -146,30 +187,15 @@ namespace ehs
|
||||
return {};
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
void SSL::Connect(const Str_8& address, const UInt_16 port)
|
||||
void SSL::Connect(Str_8 address, const UInt_16 &port)
|
||||
{
|
||||
if (bound)
|
||||
return;
|
||||
|
||||
TCP::Connect(address, port);
|
||||
|
||||
OpenSSL_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
|
||||
ctx = SSL_CTX_new(TLS_client_method());
|
||||
if (!ctx)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to creat SSL context.");
|
||||
return;
|
||||
}
|
||||
|
||||
SSL_CTX_set_default_verify_paths(ctx);
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, nullptr);
|
||||
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
|
||||
|
||||
sslHdl = SSL_new(ctx);
|
||||
SSL_set_fd(sslHdl, hdl);
|
||||
|
||||
@@ -192,8 +218,12 @@ namespace ehs
|
||||
if (written <= 0)
|
||||
{
|
||||
int code = SSL_get_error(sslHdl, written);
|
||||
ERR_print_errors_fp(stderr);
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to send data with error #" + Str_8::FromNum(code) + ".");
|
||||
if (code != SSL_ERROR_WANT_WRITE)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to send data with error #" + Str_8::FromNum(code) + ".");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -206,48 +236,46 @@ namespace ehs
|
||||
if (received <= 0)
|
||||
{
|
||||
int code = SSL_get_error(sslHdl, received);
|
||||
ERR_print_errors_fp(stderr);
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data with error #" + Str_8::FromNum(code) + ".");
|
||||
if (code != SSL_ERROR_WANT_READ)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data with error #" + Str_8::FromNum(code) + ".");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return received;
|
||||
}
|
||||
|
||||
void SSL::UseCertificate(const Byte* data, const UInt_64 size)
|
||||
void SSL::UseCertificate(const Char_8* data, const UInt_32 &size)
|
||||
{
|
||||
X509 *cert = d2i_X509(nullptr, &data, (long)size);
|
||||
if (!cert)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Invalid certificate.");
|
||||
return;
|
||||
}
|
||||
BIO* certBio = BIO_new_mem_buf(data, (int)size);
|
||||
X509 *cert = PEM_read_bio_X509(certBio, nullptr, nullptr, nullptr);
|
||||
|
||||
if (SSL_CTX_use_certificate(ctx, cert) != 1)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to use certificate.");
|
||||
return;
|
||||
}
|
||||
if (!SSL_CTX_use_certificate(ctx, cert))
|
||||
{
|
||||
UInt_32 code = ERR_get_error();
|
||||
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
|
||||
return;
|
||||
}
|
||||
|
||||
X509_free(cert);
|
||||
BIO_free(certBio);
|
||||
}
|
||||
|
||||
void SSL::UsePrivateKey(const Byte* data, const UInt_64 size)
|
||||
void SSL::UsePrivateKey(const Char_8* data, const UInt_32 &size)
|
||||
{
|
||||
EVP_PKEY *key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &data, (long)size);
|
||||
if (!key)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Invalid private key.");
|
||||
return;
|
||||
}
|
||||
BIO* keyBio = BIO_new_mem_buf(data, (int)size);
|
||||
EVP_PKEY* pkey = PEM_read_bio_PrivateKey(keyBio, nullptr, nullptr, nullptr);
|
||||
|
||||
if (SSL_CTX_use_PrivateKey(ctx, key) != 1)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to use private key.");
|
||||
return;
|
||||
}
|
||||
if (!SSL_CTX_use_PrivateKey(ctx, pkey))
|
||||
{
|
||||
UInt_32 code = ERR_get_error();
|
||||
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
|
||||
return;
|
||||
}
|
||||
|
||||
EVP_PKEY_free(key);
|
||||
BIO_free(keyBio);
|
||||
}
|
||||
|
||||
bool SSL::IsValid()
|
||||
|
@@ -114,7 +114,7 @@ namespace ehs
|
||||
hdl = EHS_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void TCP::Bind(const Str_8& address, UInt_16 port)
|
||||
void TCP::Bind(Str_8 address, const UInt_16 &port)
|
||||
{
|
||||
if (!IsValid() || bound || connection)
|
||||
return;
|
||||
@@ -124,7 +124,7 @@ namespace ehs
|
||||
else if (ip == IP::V4)
|
||||
Bind_v4(address, port);
|
||||
|
||||
this->localAddr = address;
|
||||
this->localAddr = (Str_8 &&)address;
|
||||
this->localPort = port;
|
||||
|
||||
bound = true;
|
||||
@@ -207,26 +207,26 @@ namespace ehs
|
||||
return client;
|
||||
}
|
||||
|
||||
void TCP::Connect(const Str_8& address, const UInt_16 port)
|
||||
void TCP::Connect(Str_8 address, const UInt_16 &port)
|
||||
{
|
||||
if (connection || !IsValid() || listening)
|
||||
return;
|
||||
|
||||
remoteHostName = address;
|
||||
remoteHostName = (Str_8 &&)address;
|
||||
remotePort = port;
|
||||
|
||||
if (ip == IP::V6)
|
||||
{
|
||||
if (IsIPv6Only())
|
||||
remoteAddr = DNS::Resolve(IP::V6, address);
|
||||
remoteAddr = DNS::Resolve(IP::V6, remoteHostName);
|
||||
else
|
||||
remoteAddr = DNS::Resolve(address);
|
||||
remoteAddr = DNS::Resolve(remoteHostName);
|
||||
|
||||
Connect_v6(remoteAddr, port);
|
||||
}
|
||||
else if (ip == IP::V4)
|
||||
{
|
||||
remoteAddr = DNS::Resolve(IP::V4, address);
|
||||
remoteAddr = DNS::Resolve(IP::V4, remoteHostName);
|
||||
|
||||
Connect_v4(remoteAddr, port);
|
||||
}
|
||||
@@ -385,12 +385,30 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
void TCP::SetReuse(const bool &value)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set address and port reuse while socket is not initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
const int result = (int)value;
|
||||
if (setsockopt(hdl, SOL_SOCKET, SO_REUSEPORT, &result, sizeof(int)) == -1)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to set address and port reuse with error #" + Str_8::FromNum(errno) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
bool TCP::IsValid() const
|
||||
{
|
||||
return hdl != EHS_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void TCP::Bind_v6(const Str_8& address, UInt_16 port)
|
||||
void TCP::Bind_v6(const Str_8& address, const UInt_16 &port) const
|
||||
{
|
||||
sockaddr_in6 result = {};
|
||||
result.sin6_family = AF_INET6;
|
||||
@@ -426,7 +444,7 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void TCP::Bind_v4(const Str_8& address, UInt_16 port)
|
||||
void TCP::Bind_v4(const Str_8& address, const UInt_16 &port) const
|
||||
{
|
||||
sockaddr_in result = {};
|
||||
result.sin_family = AF_INET;
|
||||
@@ -461,7 +479,7 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void TCP::Connect_v6(const Str_8& address, UInt_16 port)
|
||||
void TCP::Connect_v6(const Str_8 &address, const UInt_16 &port)
|
||||
{
|
||||
sockaddr_in6 result = {};
|
||||
result.sin6_family = AF_INET6;
|
||||
@@ -498,7 +516,7 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void TCP::Connect_v4(const Str_8& address, UInt_16 port)
|
||||
void TCP::Connect_v4(const Str_8 &address, const UInt_16 &port)
|
||||
{
|
||||
sockaddr_in result = {};
|
||||
result.sin_family = AF_INET;
|
||||
|
@@ -137,7 +137,7 @@ namespace ehs
|
||||
connected = false;
|
||||
}
|
||||
|
||||
void TCP::Bind(const Str_8& address, UInt_16 port)
|
||||
void TCP::Bind(Str_8 address, const UInt_16 &port)
|
||||
{
|
||||
if (!IsValid() || bound || connection)
|
||||
return;
|
||||
@@ -147,7 +147,7 @@ namespace ehs
|
||||
else if (ip == IP::V4)
|
||||
Bind_v4(address, port);
|
||||
|
||||
this->localAddr = address;
|
||||
this->localAddr = (Str_8 &&)address;
|
||||
this->localPort = port;
|
||||
|
||||
bound = true;
|
||||
@@ -236,26 +236,26 @@ namespace ehs
|
||||
return client;
|
||||
}
|
||||
|
||||
void TCP::Connect(const Str_8& address, const UInt_16 port)
|
||||
void TCP::Connect(Str_8 address, const UInt_16 &port)
|
||||
{
|
||||
if (connection || !IsValid() || listening)
|
||||
return;
|
||||
|
||||
remoteHostName = address;
|
||||
remoteHostName = (Str_8 &&)address;
|
||||
remotePort = port;
|
||||
|
||||
if (ip == IP::V6)
|
||||
{
|
||||
if (IsIPv6Only())
|
||||
remoteAddr = DNS::Resolve(IP::V6, address);
|
||||
remoteAddr = DNS::Resolve(IP::V6, remoteHostName);
|
||||
else
|
||||
remoteAddr = DNS::Resolve(address);
|
||||
remoteAddr = DNS::Resolve(remoteHostName);
|
||||
|
||||
Connect_v6(remoteAddr, port);
|
||||
}
|
||||
else if (ip == IP::V4)
|
||||
{
|
||||
remoteAddr = DNS::Resolve(IP::V4, address);
|
||||
remoteAddr = DNS::Resolve(IP::V4, remoteHostName);
|
||||
|
||||
Connect_v4(remoteAddr, port);
|
||||
}
|
||||
@@ -406,6 +406,10 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
void TCP::SetReuse(const bool &value)
|
||||
{
|
||||
}
|
||||
|
||||
bool TCP::IsValid() const
|
||||
{
|
||||
return hdl != EHS_INVALID_SOCKET;
|
||||
|
@@ -81,7 +81,7 @@ namespace ehs
|
||||
authReq.SetContentType(ContentType::APP_FORMURLENCODED);
|
||||
authReq.BasicAuth(clientId, secret);
|
||||
authReq.AddToBody("grant_type", "authorization_code");
|
||||
authReq.AddToBody("code", cbReq.GetQuery("code"));
|
||||
authReq.AddToBody("code", cbReq.GetQueryValue("code"));
|
||||
authReq.AddToBody("redirect_uri", rURI);
|
||||
|
||||
accounts.SendReq(authReq);
|
||||
@@ -134,7 +134,7 @@ namespace ehs
|
||||
StartConnection();
|
||||
|
||||
Request req(Verb::PUT, "/v1/me/player/volume");
|
||||
req.AddQuery("volume_percent", Str_8::FromNum(level));
|
||||
req.AddQueryVar({"volume_percent", Str_8::FromNum(level)});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -206,7 +206,7 @@ namespace ehs
|
||||
}
|
||||
|
||||
Request req(Verb::PUT, "/v1/me/player/repeat");
|
||||
req.AddQuery("state", result);
|
||||
req.AddQueryVar({"state", result});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -226,7 +226,7 @@ namespace ehs
|
||||
StartConnection();
|
||||
|
||||
Request req(Verb::PUT, "/v1/me/player/repeat");
|
||||
req.AddQuery("state", state ? "true" : "false");
|
||||
req.AddQueryVar({"state", state ? "true" : "false"});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -258,10 +258,10 @@ namespace ehs
|
||||
|
||||
q += "+track%3A" + name.ReplaceAll(" ", "+");
|
||||
|
||||
req.AddQuery("q", q);
|
||||
req.AddQuery("type", "track");
|
||||
req.AddQuery("limit", "1");
|
||||
req.AddQuery("offset", "0");
|
||||
req.AddQueryVar({"q", q});
|
||||
req.AddQueryVar({"type", "track"});
|
||||
req.AddQueryVar({"limit", "1"});
|
||||
req.AddQueryVar({"offset", "0"});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -454,7 +454,7 @@ namespace ehs
|
||||
StartConnection();
|
||||
|
||||
Request req(Verb::POST, "/v1/me/player/queue");
|
||||
req.AddQuery("uri", "spotify:track:" + id);
|
||||
req.AddQueryVar({"uri", "spotify:track:" + id});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -505,8 +505,8 @@ namespace ehs
|
||||
StartConnection();
|
||||
|
||||
Request req(Verb::POST, "/v1/playlists/" + playlistId + "/tracks");
|
||||
req.AddQuery("position", Str_8::FromNum(pos));
|
||||
req.AddQuery("uris", "spotify:track:" + trackId);
|
||||
req.AddQueryVar({"position", Str_8::FromNum(pos)});
|
||||
req.AddQueryVar({"uris", "spotify:track:" + trackId});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
@@ -564,7 +564,7 @@ namespace ehs
|
||||
StartConnection();
|
||||
|
||||
Request req(Verb::PUT, "/v1/me/player/seek");
|
||||
req.AddQuery("position_ms", Str_8::FromNum(pos));
|
||||
req.AddQueryVar({"position_ms", Str_8::FromNum(pos)});
|
||||
req.BearerAuth(token);
|
||||
|
||||
client.SendReq(req);
|
||||
|
@@ -78,7 +78,7 @@ namespace ehs
|
||||
authReq.SetContentType(ContentType::APP_FORMURLENCODED);
|
||||
authReq.AddToBody("client_id", clientId);
|
||||
authReq.AddToBody("client_secret", secret);
|
||||
authReq.AddToBody("code", cbReq.GetQuery("code"));
|
||||
authReq.AddToBody("code", cbReq.GetQueryValue("code"));
|
||||
authReq.AddToBody("grant_type", "authorization_code");
|
||||
authReq.AddToBody("redirect_uri", redURI);
|
||||
|
||||
|
@@ -78,7 +78,7 @@ namespace ehs
|
||||
{
|
||||
#if defined(EHS_ARCH_X64)
|
||||
return Architecture::X64;
|
||||
#elif defined(EHS_ARCH_ARM64)
|
||||
#elif defined(EHS_ARCH_AARCH64)
|
||||
return Architecture::ARM64;
|
||||
#else
|
||||
return Architecture::UNKNOWN;
|
||||
@@ -113,13 +113,19 @@ namespace ehs
|
||||
|
||||
return frequency.QuadPart;
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
if (!TSC_Freq)
|
||||
TSC_Freq = RetrieveTSC_Freq();
|
||||
#if defined(EHS_ARCH_X64)
|
||||
if (!TSC_Freq)
|
||||
TSC_Freq = RetrieveTSC_Freq();
|
||||
|
||||
return TSC_Freq;
|
||||
return TSC_Freq;
|
||||
#elif defined(EHS_ARCH_AARCH64)
|
||||
return RetrieveFreq_AARCH64();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt_64 CPU::GetTSC()
|
||||
@@ -133,7 +139,7 @@ namespace ehs
|
||||
TSC tsc;
|
||||
RDTSCP(&tsc);
|
||||
|
||||
#if defined(EHS_ARCH_X64)
|
||||
#if defined(EHS_ARCH_X64) || defined(EHS_ARCH_AARCH64)
|
||||
UInt_64 result = 0;
|
||||
|
||||
#if defined(EHS_LITTLE_ENDIAN)
|
||||
|
@@ -2,10 +2,6 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
void CPU::RDTSCP(TSC* tsc)
|
||||
{
|
||||
}
|
||||
|
||||
void CPU::GetManufacturer(Char_8* input)
|
||||
{
|
||||
}
|
||||
|
14
src/system/CPU_GCC_AARCH64.s
Normal file
14
src/system/CPU_GCC_AARCH64.s
Normal file
@@ -0,0 +1,14 @@
|
||||
.global _ZN3ehs3CPU6RDTSCPEPNS_3TSCE
|
||||
.global _ZN3ehs3CPU20RetrieveFreq_AARCH64Ev
|
||||
|
||||
.section .text
|
||||
_ZN3ehs3CPU6RDTSCPEPNS_3TSCE:
|
||||
MRS X2, CNTVCT_EL0
|
||||
EOR W1, W1, W1
|
||||
STR W1, [X0]
|
||||
STR X2, [X0, #4]
|
||||
RET
|
||||
|
||||
_ZN3ehs3CPU20RetrieveFreq_AARCH64Ev:
|
||||
MRS X0, CNTFRQ_EL0
|
||||
RET
|
Reference in New Issue
Block a user