3 Commits

Author SHA1 Message Date
389fa61fba Merge pull request 'Fixed gitea workflow.' (#18) from NetChannels into main
Some checks failed
Build & Release / Windows-AMD64-Build (push) Failing after 21s
Build & Release / Linux-AARCH64-Build (push) Successful in 43m31s
Build & Release / Linux-AMD64-Build (push) Successful in 15m15s
Reviewed-on: #18
2025-03-25 18:43:47 -07:00
a67197766e Merge pull request 'Fixed gitea workflow.' (#17) from NetChannels into main
Some checks failed
Build & Release / Windows-AMD64-Build (push) Failing after 25s
Build & Release / Linux-AMD64-Build (push) Failing after 11m42s
Build & Release / Linux-AARCH64-Build (push) Successful in 43m39s
Reviewed-on: #17
2025-03-25 18:37:27 -07:00
ae414c5c99 Merge pull request 'Added CPU::GetCacheLineSize() definition for Windows.' (#16) from NetChannels into main
Reviewed-on: #16
2025-03-25 16:50:40 -07:00
71 changed files with 963 additions and 3616 deletions

View File

@@ -22,9 +22,10 @@ jobs:
- name: Building/Compiling/Installing Project - name: Building/Compiling/Installing Project
run: | run: |
cd ${{ gitea.workspace }} cd ${{ gitea.workspace }}
vcpkg install
mkdir build mkdir build
cd build cd build
cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" .. cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake ..
cmake --build . --config Release cmake --build . --config Release
cmake --install . cmake --install .
@@ -35,8 +36,6 @@ jobs:
mv build/Release/EHS_Dyn.dll bin mv build/Release/EHS_Dyn.dll bin
mv build/Release/StrToHash.exe bin mv build/Release/StrToHash.exe bin
mv build/Release/zlib1.dll bin mv build/Release/zlib1.dll bin
mv build/Release/libcrypto-3-x64.dll bin
mv build/Release/libssl-3-x64.dll bin
mkdir lib mkdir lib
mv build/Release/EHS_Stc.lib lib mv build/Release/EHS_Stc.lib lib
mv build/Release/EHS_Dyn.lib lib mv build/Release/EHS_Dyn.lib lib
@@ -57,7 +56,6 @@ jobs:
files: |- files: |-
ehs-windows-amd64.zip ehs-windows-amd64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false
Linux-AMD64-Build: Linux-AMD64-Build:
runs-on: linux-x86_64 runs-on: linux-x86_64
@@ -67,7 +65,7 @@ jobs:
- name: Installing Dependencies - name: Installing Dependencies
run: | run: |
sudo pacman -S --noconfirm doxygen ninja zip libxcb xcb-util-cursor pipewire sudo pacman -S --noconfirm doxygen zip alsa-lib libxcb xcb-util-cursor pipewire
- name: Generating Documentation - name: Generating Documentation
run: | run: |
@@ -76,7 +74,7 @@ jobs:
- name: Building/Compiling/Installing Project - name: Building/Compiling/Installing Project
run: | run: |
cd ${{ gitea.workspace }} cd ${{ gitea.workspace }}
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
cmake --build . --config Release cmake --build . --config Release
cmake --install . cmake --install .
@@ -103,7 +101,6 @@ jobs:
files: |- files: |-
ehs-linux-amd64.zip ehs-linux-amd64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false
Linux-AARCH64-Build: Linux-AARCH64-Build:
runs-on: linux-aarch64 runs-on: linux-aarch64
@@ -112,7 +109,7 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Installing Dependencies - name: Installing Dependencies
run: sudo apt install -y doxygen ninja-build zip libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev libpipewire-0.3-dev run: sudo apt install -y doxygen zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev libpipewire-0.3-dev
- name: Generating Documentation - name: Generating Documentation
run: | run: |
@@ -121,7 +118,7 @@ jobs:
- name: Building/Compiling/Installing Project - name: Building/Compiling/Installing Project
run: | run: |
cd ${{ gitea.workspace }} cd ${{ gitea.workspace }}
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
cmake --build . --config Release cmake --build . --config Release
cmake --install . cmake --install .
@@ -148,4 +145,3 @@ jobs:
files: |- files: |-
ehs-linux-aarch64.zip ehs-linux-aarch64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false

View File

@@ -1,26 +0,0 @@
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

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.30.4) cmake_minimum_required(VERSION 3.25.1)
set(IS_OS_WINDOWS FALSE) set(IS_OS_WINDOWS FALSE)
set(IS_OS_LINUX FALSE) set(IS_OS_LINUX FALSE)
@@ -11,8 +11,6 @@ set(IS_ARCH_ARM FALSE)
project(EHS CXX C) project(EHS CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON)
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(IS_OS_WINDOWS TRUE) set(IS_OS_WINDOWS TRUE)
set(USER_HOME_DIRECTORY "$ENV{USERPROFILE}") set(USER_HOME_DIRECTORY "$ENV{USERPROFILE}")
@@ -53,7 +51,6 @@ set(EHS_SOURCES
src/Color3.cpp include/ehs/Color3.h src/Color3.cpp include/ehs/Color3.h
src/Version.cpp include/ehs/Version.h src/Version.cpp include/ehs/Version.h
src/Base64.cpp include/ehs/Base64.h src/Base64.cpp include/ehs/Base64.h
src/SHA256.cpp include/ehs/SHA256.h
src/Data.cpp include/ehs/Data.h src/Data.cpp include/ehs/Data.h
src/Range.cpp include/ehs/Range.h src/Range.cpp include/ehs/Range.h
src/Util.cpp include/ehs/Util.h src/Util.cpp include/ehs/Util.h
@@ -100,8 +97,6 @@ set(EHS_SOURCES
include/ehs/system/OS.h include/ehs/system/OS.h
include/ehs/system/Semaphore.h include/ehs/system/Semaphore.h
include/ehs/system/System.h include/ehs/system/System.h
include/ehs/system/AVX2.h
include/ehs/system/AVX512.h
src/json/Json.cpp include/ehs/json/Json.h src/json/Json.cpp include/ehs/json/Json.h
src/json/JsonBase.cpp include/ehs/json/JsonBase.h src/json/JsonBase.cpp include/ehs/json/JsonBase.h
@@ -199,10 +194,11 @@ set(EHS_SOURCES
src/io/socket/ehc/NetClientCh.cpp src/io/socket/ehc/NetClientCh.cpp
src/io/socket/ehc/NetServerCh.cpp src/io/socket/ehc/NetServerCh.cpp
src/io/socket/ehc/NetUtils.cpp src/io/socket/ehc/NetUtils.cpp
include/ehs/io/socket/BaseICMP.h src/io/socket/BaseICMP.cpp src/io/socket/BaseICMP.cpp
include/ehs/io/socket/ICMP_LNX.h
src/io/socket/ICMP_LNX.cpp
include/ehs/io/socket/ICMP.h include/ehs/io/socket/ICMP.h
src/io/socket/QueryVar.cpp include/ehs/io/socket/QueryVar.h src/io/socket/ICMP_LNX.cpp
src/io/socket/HeaderVar.cpp include/ehs/io/socket/HeaderVar.h
) )
if (IS_OS_WINDOWS) if (IS_OS_WINDOWS)
@@ -221,10 +217,7 @@ if (IS_OS_WINDOWS)
src/io/COM.cpp include/ehs/io/COM.h src/io/COM.cpp include/ehs/io/COM.h
src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm
src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h
include/ehs/io/socket/ICMP_W32.h src/io/socket/ICMP_W32.cpp
src/system/AVX2_MSVC_AMD64.asm src/system/AVX512_MSVC_AMD64.asm
) )
elseif (IS_OS_LINUX) elseif (IS_OS_LINUX)
list(APPEND EHS_SOURCES list(APPEND EHS_SOURCES
src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h
@@ -241,10 +234,9 @@ elseif (IS_OS_LINUX)
src/system/User.cpp include/ehs/system/User.h src/system/User.cpp include/ehs/system/User.h
src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h
src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h
include/ehs/io/socket/ICMP_LNX.h src/io/socket/ICMP_LNX.cpp
) )
set(LINUX_WINDOW_SYSTEM "XCB" CACHE STRING "Linux Window System") #set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland") if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
add_compile_definitions(EHS_WS_WAYLAND) add_compile_definitions(EHS_WS_WAYLAND)
@@ -260,14 +252,18 @@ elseif (IS_OS_LINUX)
endif () endif ()
if (IS_ARCH_AMD64) 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) list(APPEND EHS_SOURCES src/system/CPU_GCC_AMD64.asm src/HRNG_GCC.asm src/Math_GCC_AMD64.asm)
elseif (IS_ARCH_ARM64) elseif (IS_ARCH_ARM64)
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) list(APPEND EHS_SOURCES src/system/CPU_ARM64.cpp src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s)
endif () endif ()
endif() endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
#message("${CMAKE_CXX_FLAGS}")
add_library(EHS_Stc STATIC ${EHS_SOURCES}) add_library(EHS_Stc STATIC ${EHS_SOURCES})
add_library(EHS_Dyn SHARED ${EHS_SOURCES} Assembly.def) add_library(EHS_Dyn SHARED ${EHS_SOURCES}
include/ehs/io/socket/BaseICMP.h)
add_executable(StrToHash src/StrToHash.cpp) add_executable(StrToHash src/StrToHash.cpp)
target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT) target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT)
@@ -317,7 +313,7 @@ target_link_libraries(EHS_Dyn OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
target_link_libraries(StrToHash OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB) target_link_libraries(StrToHash OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
if (IS_OS_WINDOWS) if (IS_OS_WINDOWS)
target_link_libraries(EHS_Dyn avrt ws2_32 IPHLPAPI) target_link_libraries(EHS_Dyn avrt ws2_32)
target_link_libraries(StrToHash ws2_32 avrt EHS_Stc) target_link_libraries(StrToHash ws2_32 avrt EHS_Stc)
elseif (IS_OS_LINUX) elseif (IS_OS_LINUX)
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland") if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
@@ -328,6 +324,6 @@ elseif (IS_OS_LINUX)
target_link_libraries(StrToHash xcb xcb-cursor xcb-xfixes xcb-xinput) target_link_libraries(StrToHash xcb xcb-cursor xcb-xfixes xcb-xinput)
endif () endif ()
target_link_libraries(EHS_Dyn z pipewire-0.3) target_link_libraries(EHS_Dyn z asound pipewire-0.3)
target_link_libraries(StrToHash z EHS_Stc) target_link_libraries(StrToHash z asound EHS_Stc)
endif () endif ()

View File

@@ -22,7 +22,6 @@ This project does not fully follow the C++ standard.
- Semaphores - Semaphores
- CPU information and features at runtime - CPU information and features at runtime
- HTTP(S) Socket Layer - HTTP(S) Socket Layer
- ICMP & ICMPv6 Socket
- TCP Socket - TCP Socket
- UDP Socket - UDP Socket
- COM (Serial) IO - COM (Serial) IO
@@ -38,8 +37,6 @@ This project does not fully follow the C++ standard.
- Asynchronous Task System - Asynchronous Task System
- URI Parsing - URI Parsing
- USB (WIP) - USB (WIP)
- Base64
- SHA256
### Supported Architectures ### Supported Architectures
- AMD64 - AMD64

View File

@@ -8,26 +8,17 @@ namespace ehs
class EHS_LIB_IO Base64 class EHS_LIB_IO Base64
{ {
private: private:
static constexpr UInt_8 asciiUrl[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; static const char ascii[];
static constexpr UInt_8 ascii[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
public: public:
static Str_8 EncodeURL(const Str_8 &input);
static Str_8 Encode(const Str_8 &input); static Str_8 Encode(const Str_8 &input);
static Str_8 DecodeURL(const Str_8 &input);
static Str_8 Decode(const Str_8 &input); static Str_8 Decode(const Str_8 &input);
private: private:
static UInt_8 FindURL(const UInt_8 &c); static char Find(char c);
static UInt_8 Find(const UInt_8 &c); static bool IsBase64(char c);
static bool IsBase64URL(const UInt_8 &c);
static bool IsBase64(const UInt_8 &c);
}; };
} }

View File

@@ -5,7 +5,7 @@
namespace ehs namespace ehs
{ {
class HRNG class EHS_LIB_IO HRNG
{ {
public: public:
static UInt_64 GenerateSeed_u64(); static UInt_64 GenerateSeed_u64();

View File

@@ -63,7 +63,7 @@ namespace ehs
/// @param [in] tags The tags to associate this log with. /// @param [in] tags The tags to associate this log with.
/// @param [in] code The unique code to use. /// @param [in] code The unique code to use.
/// @param [in] msg Detailed information about what happened. /// @param [in] msg Detailed information about what happened.
Log(LogType type, const Str_8 &tags, UInt_64 code, Str_8 msg); Log(LogType type, const std::initializer_list<Str_8> &tags, UInt_64 code, Str_8 msg);
/// Initializes members with the given information. /// Initializes members with the given information.
/// @param [in] tags The tags to associate this log with. /// @param [in] tags The tags to associate this log with.
@@ -134,17 +134,17 @@ namespace ehs
#ifndef EHS_LOG_INT #ifndef EHS_LOG_INT
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#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)) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAcronym_8()) + ", " + EHS_FUNC, code, msg)) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif
#ifndef EHS_LOG #ifndef EHS_LOG
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#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)) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, ehs::Str_8(ehs::GetAppName_8()) + ", " + EHS_FUNC, code, msg)) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif

View File

@@ -1,59 +0,0 @@
#pragma once
#include "Types.h"
namespace ehs
{
class EHS_LIB_IO SHA256
{
private:
static UInt_32 ROTR(UInt_32 x, UInt_32 n);
static UInt_32 CH(UInt_32 x, UInt_32 y, UInt_32 z);
static UInt_32 MAJ(UInt_32 x, UInt_32 y, UInt_32 z);
static UInt_32 EP0(UInt_32 x);
static UInt_32 EP1(UInt_32 x);
static UInt_32 SIG0(UInt_32 x);
static UInt_32 SIG1(UInt_32 x);
static constexpr UInt_32 k[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
UInt_32 state[8];
UInt_64 bitLen;
Byte data[64];
UInt_64 dataLen;
public:
SHA256();
SHA256(SHA256 &&other) noexcept;
SHA256(const SHA256 &other);
SHA256 &operator=(SHA256 &&other) noexcept;
SHA256 &operator=(const SHA256 &other);
void Update(const Byte *data, UInt_64 len);
void Final(Byte hash[32]);
void Hash(const Byte *data, UInt_64 len, Byte hash[32]);
private:
void Transform(const Byte data[64]);
};
}

View File

@@ -48,11 +48,8 @@ namespace ehs
/// @param [in] str The C-style string. /// @param [in] str The C-style string.
/// @param [in] size The size of the given C-style string. /// @param [in] size The size of the given C-style string.
Str(const T* const str, const N size) Str(const T* const str, const N size)
: size(size), data(nullptr) : size((size) ? size : Len(str)), data(nullptr)
{ {
if (!size)
return;
data = new T[this->size + 1]; data = new T[this->size + 1];
Util::Copy(data, str, Size(true)); Util::Copy(data, str, Size(true));
@@ -917,10 +914,10 @@ namespace ehs
} }
/// Splits a string into a Vector with the given separator. /// Splits a string into a Vector with the given separator.
/// @param [in] delimeter The given string as the separator. /// @param [in] ide The given string as the separator.
/// @param [in] max The max amount of times to split the string. /// @param [in] max The max amount of times to split the string.
/// @returns The resulting string object. /// @returns The resulting string object.
Vector<Str<T, N>, N> Split(const Str<T, N>& delimeter, const N max = 0) const Vector<Str<T, N>, N> Split(const Str<T, N>& ide, const N max = 0) const
{ {
Vector<Str<T, N>, N> result(0, 5); Vector<Str<T, N>, N> result(0, 5);
@@ -928,9 +925,9 @@ namespace ehs
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
N r = i - (c - 1) - b; N r = i - (c - 1) - b;
if (!r) if (!r)
@@ -958,17 +955,17 @@ namespace ehs
} }
/// Removes all instances of the ide. /// Removes all instances of the ide.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @returns The resulting string object. /// @returns The resulting string object.
Str<T, N> RemoveAll(const Str<T, N>& delimeter) const Str<T, N> RemoveAll(const Str<T, N>& ide) const
{ {
Str<T, N> result(size); Str<T, N> result(size);
for (N i = 0, b = 0, c = 0; i < size; ++i) for (N i = 0, b = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
c = 0; c = 0;
} }
else else
@@ -987,18 +984,18 @@ namespace ehs
} }
/// Replaces all instances of ide with the replacer. /// Replaces all instances of ide with the replacer.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @param [in] replacer The string placed. /// @param [in] replacer The string placed.
/// @returns The resulting string object. /// @returns The resulting string object.
Str ReplaceAll(const Str& delimeter, const Str& replacer) const Str ReplaceAll(const Str& ide, const Str& replacer) const
{ {
Str<T, N> result; Str<T, N> result;
for (N i = 0, b = 0; i < size; ++i) for (N i = 0, b = 0; i < size; ++i)
{ {
if (data[i] == delimeter[b]) if (data[i] == ide[b])
{ {
if (++b == delimeter.Size()) if (++b == ide.Size())
{ {
result.Push(replacer); result.Push(replacer);
b = 0; b = 0;
@@ -1014,20 +1011,20 @@ namespace ehs
} }
/// Finds the first instance of the given string object. /// Finds the first instance of the given string object.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @param [out] index The index of the string found. Can be a nullptr. /// @param [out] index The index of the string found. Can be a nullptr.
/// @param [in] pattern The search pattern for optimization. /// @param [in] pattern The search pattern for optimization.
/// @param [in] result What index to return where the first instance is found. /// @param [in] result What index to return where the first instance is found.
/// @returns The index where the instance was found with the result varying from the result parameter. /// @returns The index where the instance was found with the result varying from the result parameter.
bool Find(const Str<T, N> &delimeter, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const bool Find(const Str<T, N> &ide, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const
{ {
if (pattern == SearchPattern::LEFT_RIGHT) if (pattern == SearchPattern::LEFT_RIGHT)
{ {
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
if (result == IndexResult::BEGINNING) if (result == IndexResult::BEGINNING)
{ {
@@ -1049,16 +1046,16 @@ namespace ehs
} }
else if (pattern == SearchPattern::RIGHT_LEFT) else if (pattern == SearchPattern::RIGHT_LEFT)
{ {
for (N i = size, c = delimeter.Size(); i > 0; --i) for (N i = size, c = ide.Size(); i > 0; --i)
{ {
if (data[i - 1] == delimeter[c - 1]) if (data[i - 1] == ide[c - 1])
{ {
if (--c == 0) if (--c == 0)
{ {
if (result == IndexResult::BEGINNING) if (result == IndexResult::BEGINNING)
{ {
if (index) if (index)
*index = i - (delimeter.Size() - 1); *index = i - (ide.Size() - 1);
return true; return true;
} }
@@ -1078,18 +1075,18 @@ namespace ehs
} }
/// Checks if the current string contains the given ide. /// Checks if the current string contains the given ide.
/// @param [in] delimeter The given ide to check for. /// @param [in] ide The given ide to check for.
/// @param [in] pattern The search pattern to use. /// @param [in] pattern The search pattern to use.
/// @returns True if the current string does contain the ide. /// @returns True if the current string does contain the ide.
bool Contains(const Str<T, N>& delimeter, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const bool Contains(const Str<T, N>& ide, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const
{ {
if (pattern == SearchPattern::LEFT_RIGHT) if (pattern == SearchPattern::LEFT_RIGHT)
{ {
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
return true; return true;
} }
@@ -1098,9 +1095,9 @@ namespace ehs
} }
else if (pattern == SearchPattern::RIGHT_LEFT) else if (pattern == SearchPattern::RIGHT_LEFT)
{ {
for (N i = size, c = delimeter.Size(); i > 0; --i) for (N i = size, c = ide.Size(); i > 0; --i)
{ {
if (data[i - 1] == delimeter[c - 1]) if (data[i - 1] == ide[c - 1])
{ {
if (--c == 0) if (--c == 0)
{ {
@@ -1113,54 +1110,6 @@ namespace ehs
return false; return false;
} }
Vector<Str> ParseArgs() const
{
Vector<Str> args;
T *quoteStart = nullptr;
T *spaceStart = nullptr;
for (T *i = data; i <= data + size; ++i)
{
if (*i == '\"' && !spaceStart)
{
if (quoteStart)
{
args.Push(Str(quoteStart, i - quoteStart));
quoteStart = nullptr;
}
else
{
if (i + 1 < &data[size - 1])
quoteStart = i + 1;
else
args.Push({});
}
}
else if (*i == ' ' && !quoteStart)
{
if (spaceStart)
{
args.Push(Str(spaceStart, i - spaceStart));
spaceStart = i + 1;
}
else
{
if (i + 1 < &data[size - 1])
spaceStart = i + 1;
else
args.Push({});
}
}
}
if (quoteStart)
args.Push(Str(quoteStart, &data[size - 1] - (quoteStart - 1)));
else if (spaceStart)
args.Push(Str(spaceStart, &data[size - 1] - (spaceStart - 1)));
return args;
}
/// Checks if the string represents a number. Must not have any alphabetical characters. /// Checks if the string represents a number. Must not have any alphabetical characters.
/// @returns The result. /// @returns The result.
bool IsNum() const bool IsNum() const

View File

@@ -392,7 +392,7 @@ namespace ehs
{ {
if (stride) if (stride)
{ {
rawSize = (this->size + size) / stride * stride; rawSize = (this->size + size()) / stride * stride;
if ((this->size + size) % stride) if ((this->size + size) % stride)
rawSize += stride; rawSize += stride;
} }
@@ -403,7 +403,7 @@ namespace ehs
T* result = new T[rawSize]; T* result = new T[rawSize];
for (N i = 0; i < this->size; ++i) for (N i = 0; i < size; ++i)
result[i] = std::move(data[i]); result[i] = std::move(data[i]);
delete[] data; delete[] data;

View File

@@ -25,7 +25,6 @@ namespace ehs
pw_core *core; pw_core *core;
pw_stream *input; pw_stream *input;
pw_stream *output; 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); static void RegistryEventGlobal(void *data, UInt_32 id, UInt_32 permissions, const char *type, UInt_32 version, const spa_dict *props);

View File

@@ -21,8 +21,6 @@ namespace ehs
bool active; bool active;
public: public:
virtual ~HID() = default;
HID(); HID();
HID(UInt_8 type, Str_8 name, UInt_64 id); HID(UInt_8 type, Str_8 name, UInt_64 id);

View File

@@ -10,7 +10,7 @@ namespace ehs
{ {
private: private:
Array<InputHandler*> handlers; Array<InputHandler*> handlers;
bool initialized; bool initalized;
public: public:
~Input(); ~Input();
@@ -31,13 +31,13 @@ namespace ehs
void Poll(); void Poll();
bool HasHandler(UInt_64 hashId) const; bool HasHandler(const UInt_64 hashId) const;
bool HasHandler(const Str_8& id) const; bool HasHandler(const Str_8& id) const;
bool AddHandler(InputHandler* handler); bool AddHandler(InputHandler* handler);
const InputHandler* GetHandler(UInt_64 hashId) const; const InputHandler* GetHandler(const UInt_64 hashId) const;
const InputHandler* GetHandler(const Str_8& id) const; const InputHandler* GetHandler(const Str_8& id) const;

View File

@@ -31,9 +31,9 @@ namespace ehs
InputHandler& operator=(const InputHandler& ih); InputHandler& operator=(const InputHandler& ih);
bool operator==(UInt_64 otherHashId) const; bool operator==(const UInt_64 otherHashId) const;
bool operator!=(UInt_64 otherHashId) const; bool operator!=(const UInt_64 otherHashId) const;
virtual bool Initialize(); virtual bool Initialize();
@@ -47,13 +47,13 @@ namespace ehs
void ResetAllStates(); void ResetAllStates();
bool HasDevice(UInt_64 id) const; bool HasDevice(const UInt_64 id) const;
bool AddDevice(HID* device); bool AddDevice(HID* device);
HID* GetDevice(UInt_64 id) const; HID* GetDevice(const UInt_64 id) const;
HID* GetDeviceByType(UInt_8 type) const; HID* GetDeviceByType(const UInt_8 type) const;
virtual bool IsInitialized() const; virtual bool IsInitialized() const;
}; };

View File

@@ -27,92 +27,92 @@ namespace ehs
Keyboard* Clone() const override; Keyboard* Clone() const override;
static inline const Button Unknown = Button("Unknown"); static const Button Unknown;
static inline const Button Escape = Button("Escape Button"); static const Button Escape;
static inline const Button Backspace = Button("Backspace Button"); static const Button Backspace;
static inline const Button Enter = Button("Enter Button"); static const Button Enter;
static inline const Button LShift = Button("Left Shift Button"); static const Button LShift;
static inline const Button RShift = Button("Right Shift Button"); static const Button RShift;
static inline const Button LAlt = Button("Left Alt Button"); static const Button LAlt;
static inline const Button RAlt = Button("Right Alt Button"); static const Button RAlt;
static inline const Button LCtrl = Button("Left Control Button"); static const Button LCtrl;
static inline const Button RCtrl = Button("Right Button"); static const Button RCtrl;
static inline const Button Space = Button("Space Button"); static const Button Space;
static inline const Button A = Button("A Button"); static const Button A;
static inline const Button B = Button("B Button"); static const Button B;
static inline const Button C = Button("C Button"); static const Button C;
static inline const Button D = Button("D Button"); static const Button D;
static inline const Button E = Button("E Button"); static const Button E;
static inline const Button F = Button("F Button"); static const Button F;
static inline const Button G = Button("G Button"); static const Button G;
static inline const Button H = Button("H Button"); static const Button H;
static inline const Button I = Button("I Button"); static const Button I;
static inline const Button J = Button("J Button"); static const Button J;
static inline const Button K = Button("K Button"); static const Button K;
static inline const Button L = Button("L Button"); static const Button L;
static inline const Button M = Button("M Button"); static const Button M;
static inline const Button N = Button("N Button"); static const Button N;
static inline const Button O = Button("O Button"); static const Button O;
static inline const Button P = Button("P Button"); static const Button P;
static inline const Button Q = Button("Q Button"); static const Button Q;
static inline const Button R = Button("R Button"); static const Button R;
static inline const Button S = Button("S Button"); static const Button S;
static inline const Button T = Button("T Button"); static const Button T;
static inline const Button U = Button("U Button"); static const Button U;
static inline const Button V = Button("V Button"); static const Button V;
static inline const Button W = Button("W Button"); static const Button W;
static inline const Button X = Button("X Button"); static const Button X;
static inline const Button Y = Button("Y Button"); static const Button Y;
static inline const Button Z = Button("Z Button"); static const Button Z;
static inline const Button One = Button("One Button"); static const Button One;
static inline const Button Two = Button("Two Button"); static const Button Two;
static inline const Button Three = Button("Three Button"); static const Button Three;
static inline const Button Four = Button("Four Button"); static const Button Four;
static inline const Button Five = Button("Five Button"); static const Button Five;
static inline const Button Six = Button("Six Button"); static const Button Six;
static inline const Button Seven = Button("Seven Button"); static const Button Seven;
static inline const Button Eight = Button("Eight Button"); static const Button Eight;
static inline const Button Nine = Button("Nine Button"); static const Button Nine;
static inline const Button Zero = Button("Zero Button"); static const Button Zero;
static inline const Button Minus = Button("Minus Button"); static const Button Minus;
static inline const Button Equals = Button("Equals Button"); static const Button Equals;
static inline const Button Tilde = Button("Tilde Button"); static const Button Tilde;
static inline const Button BackSlash = Button("Back Slash Button"); static const Button BackSlash;
static inline const Button LeftSquareBracket = Button("Left Square Bracket Button"); static const Button LeftSquareBracket;
static inline const Button RightSquareBracket = Button("Right Square Bracket Button"); static const Button RightSquareBracket;
static inline const Button SemiColon = Button("Semi Colon Button"); static const Button SemiColon;
static inline const Button Apostrophe = Button("Apostrophe Button"); static const Button Apostrophe;
static inline const Button Comma = Button("Comma Button"); static const Button Comma;
static inline const Button Period = Button("Period Button"); static const Button Period;
static inline const Button ForwardSlash = Button("Forward Slash Button"); static const Button ForwardSlash;
static inline const Button F1 = Button("Function One Button"); static const Button F1;
static inline const Button F2 = Button("Function Two Button"); static const Button F2;
static inline const Button F3 = Button("Function Three Button"); static const Button F3;
static inline const Button F4 = Button("Function Four Button"); static const Button F4;
static inline const Button F5 = Button("Function Five Button"); static const Button F5;
static inline const Button F6 = Button("Function Six Button"); static const Button F6;
static inline const Button F7 = Button("Function Seven Button"); static const Button F7;
static inline const Button F8 = Button("Function Eight Button"); static const Button F8;
static inline const Button F9 = Button("Function Nine Button"); static const Button F9;
static inline const Button F10 = Button("Function Ten Button"); static const Button F10;
static inline const Button F11 = Button("Function Eleven Button"); static const Button F11;
static inline const Button F12 = Button("Function Twelve Button"); static const Button F12;
static inline const Button F13 = Button("Function Thirteen Button"); static const Button F13;
static inline const Button F14 = Button("Function Fourteen Button"); static const Button F14;
static inline const Button F15 = Button("Function Fifteen Button"); static const Button F15;
static inline const Button F16 = Button("Function Sixteen Button"); static const Button F16;
static inline const Button F17 = Button("Function Seventeen Button"); static const Button F17;
static inline const Button F18 = Button("Function Eighteen Button"); static const Button F18;
static inline const Button F19 = Button("Function Nineteen Button"); static const Button F19;
static inline const Button F20 = Button("Function Twenty Button"); static const Button F20;
static inline const Button F21 = Button("Function Twenty One Button"); static const Button F21;
static inline const Button F22 = Button("Function Twenty Two Button"); static const Button F22;
static inline const Button F23 = Button("Function Twenty Three Button"); static const Button F23;
static inline const Button F24 = Button("Function Twenty Four Button"); static const Button F24;
static inline const Button Left = Button("Left Button"); static const Button Left;
static inline const Button Right = Button("Right Button"); static const Button Right;
static inline const Button Up = Button("Up Button"); static const Button Up;
static inline const Button Down = Button("Down Button"); static const Button Down;
static Button TranslateScanCode(UInt_32 code); static Button TranslateScanCode(UInt_32 code);

View File

@@ -37,18 +37,18 @@ namespace ehs
Mouse* Clone() const override; Mouse* Clone() const override;
static inline const Button Unknown = Button("Unknown Button"); static const Button Unknown;
static inline const Button LMB = Button("Left Mouse Button"); static const Button LMB;
static inline const Button MMB = Button("Middle Mouse Button"); static const Button MMB;
static inline const Button RMB = Button("Right Mouse Button"); static const Button RMB;
static inline const Button Four = Button("Four Button"); static const Button Four;
static inline const Button Five = Button("Five Button"); static const Button Five;
static inline const Button ScrollUp = Button("Scroll Up Button"); static const Button ScrollUp;
static inline const Button ScrollDown = Button("Scroll Down Button"); static const Button ScrollDown;
static inline const Button ScrollLeft = Button("Scroll Left Button"); static const Button ScrollLeft;
static inline const Button ScrollRight = Button("Scroll Right Button"); static const Button ScrollRight;
static inline const Button Back = Button("Back Button"); static const Button Back;
static inline const Button Forward = Button("Forward Button"); static const Button Forward;
static Button TranslateXCB(const UInt_32 code); static Button TranslateXCB(const UInt_32 code);
}; };

View File

@@ -25,8 +25,6 @@ namespace ehs
IP version; IP version;
public: public:
virtual ~BaseICMP() = default;
BaseICMP(); BaseICMP();
BaseICMP(IP version); BaseICMP(IP version);
@@ -39,30 +37,17 @@ namespace ehs
BaseICMP &operator=(const BaseICMP &icmp); BaseICMP &operator=(const BaseICMP &icmp);
virtual void Release(); virtual UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size); virtual UInt_64 Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data);
UInt_64 Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data);
void SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size); void SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size);
virtual void SetReceiveTimeout(UInt_64 timeout); virtual void SetReceiveTimeout(UInt_64 timeout);
IP GetVersion() const;
virtual bool IsValid() const; virtual bool IsValid() const;
protected: protected:
static UInt_16 ComputeChecksumV4(UInt_16 *buffer, Size length); static UInt_16 ComputeChecksum(UInt_16 *buffer, Size length);
private:
virtual UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
virtual UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
virtual UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
virtual UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
}; };
} }

View File

@@ -24,9 +24,9 @@ namespace ehs
bool connected; bool connected;
public: public:
static constexpr UInt_16 HTTPS_Port = 443; static const UInt_16 HTTPS_Port = 443;
static constexpr UInt_16 HTTP_Port = 80; static const UInt_16 HTTP_Port = 80;
static constexpr UInt_16 MaxHeaderSize = 8192; static const UInt_16 MaxHeaderSize = 8192;
virtual ~BaseTCP() = default; virtual ~BaseTCP() = default;
@@ -55,7 +55,7 @@ namespace ehs
/// @param [in] address The ip address to bind to. /// @param [in] address The ip address to bind to.
/// @param [in] port The port to bind to. /// @param [in] port The port to bind to.
/// @note Used for servers. /// @note Used for servers.
virtual void Bind(Str_8 address, const UInt_16 &port) = 0; virtual void Bind(const Str_8& address, UInt_16 port) = 0;
/// Listens for new incoming connections. /// Listens for new incoming connections.
/// @note Used for servers. /// @note Used for servers.
@@ -69,7 +69,7 @@ namespace ehs
/// @param [in] address The ip address to connect to. /// @param [in] address The ip address to connect to.
/// @param [in] port The port to connect to. /// @param [in] port The port to connect to.
/// @note Used for clients. /// @note Used for clients.
virtual void Connect(Str_8 address, const UInt_16 &port) = 0; virtual void Connect(const Str_8& address, UInt_16 port) = 0;
/// Sends data to the connected endpoint. /// Sends data to the connected endpoint.
/// @param [in] buffer The data to send to the endpoint. /// @param [in] buffer The data to send to the endpoint.
@@ -150,8 +150,6 @@ namespace ehs
virtual bool IsIPv6Only() const = 0; virtual bool IsIPv6Only() const = 0;
virtual void SetReuse(const bool &enabled) = 0;
/// Retrieves whether or not this socket was initialized. /// Retrieves whether or not this socket was initialized.
/// @returns The result. /// @returns The result.
virtual bool IsValid() const = 0; virtual bool IsValid() const = 0;

View File

@@ -1,45 +0,0 @@
#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;
};
}

View File

@@ -1,9 +1,7 @@
#pragma once #pragma once
#include "ehs/system/OS.h"
#ifdef EHS_OS_WINDOWS #ifdef EHS_OS_WINDOWS
#include "ICMP_W32.h" #include "BaseICMP.h"
#else #else
#include "ICMP_LNX.h" #include "ICMP_LNX.h"
#endif #endif

View File

@@ -2,26 +2,14 @@
#include "BaseICMP.h" #include "BaseICMP.h"
#include <netinet/in.h>
namespace ehs namespace ehs
{ {
struct PseudoICMPv6_Header class ICMP : public BaseICMP
{
sockaddr_in6 src;
sockaddr_in6 dst;
UInt_32 length;
};
class ICMP final : public BaseICMP
{ {
private: private:
Int_32 hdl; Int_32 hdl;
sockaddr_in6 src;
public: public:
~ICMP() override;
ICMP(); ICMP();
ICMP(IP version); ICMP(IP version);
@@ -34,27 +22,12 @@ namespace ehs
ICMP &operator=(const ICMP &icmp); ICMP &operator=(const ICMP &icmp);
void Release() override; UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data) override;
void SetReceiveTimeout(UInt_64 timeout) override; void SetReceiveTimeout(UInt_64 timeout) override;
bool IsValid() const override; bool IsValid() const override;
private:
static bool IsLinkLocal(const in6_addr &addr);
static sockaddr_in6 RetrieveSrcAddress();
static UInt_32 CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header);
UInt_16 ComputeChecksumV6(UInt_16* buffer, Size length, const sockaddr_in6& dst);
UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
}; };
} }

View File

@@ -1,63 +0,0 @@
#pragma once
#include "BaseICMP.h"
#include "ehs/System/OS.h"
#include <winsock2.h>
#include <WS2tcpip.h>
#include <iphlpapi.h>
namespace ehs
{
struct PseudoICMPv6_Header
{
sockaddr_in6 src;
sockaddr_in6 dst;
UInt_32 length;
};
class ICMP : public BaseICMP
{
private:
Socket hdl;
sockaddr_in6 src;
public:
~ICMP() override;
ICMP();
ICMP(IP version);
ICMP(ICMP &&icmp) noexcept;
ICMP(const ICMP &icmp);
ICMP &operator=(ICMP &&icmp) noexcept;
ICMP &operator=(const ICMP &icmp);
void Release() override;
void SetReceiveTimeout(UInt_64 timeout) override;
bool IsValid() const override;
private:
static bool IsLinkLocal(const in6_addr &addr);
static sockaddr_in6 RetrieveSrcAddress();
static UInt_32 CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header);
UInt_16 ComputeChecksumV6(UInt_16* buffer, Size length, const sockaddr_in6& dst);
UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
};
}

View File

@@ -1,45 +0,0 @@
#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;
};
}

View File

@@ -5,8 +5,6 @@
#include "ehs/Str.h" #include "ehs/Str.h"
#include "ehs/json/Json.h" #include "ehs/json/Json.h"
#include "Socket.h" #include "Socket.h"
#include "QueryVar.h"
#include "HeaderVar.h"
namespace ehs namespace ehs
{ {
@@ -23,8 +21,8 @@ namespace ehs
private: private:
Verb verb; Verb verb;
Str_8 rsrc; Str_8 rsrc;
Vector<QueryVar> queries; Vector<Str_8> queries;
Vector<HeaderVar> header; Vector<Str_8> header;
ContentType cType; ContentType cType;
Str_8 body; Str_8 body;
@@ -35,34 +33,25 @@ namespace ehs
/// Initializes this request with a given verb and URI resource. /// Initializes this request with a given verb and URI resource.
/// @param [in] verb The type of request to make. /// @param [in] verb The type of request to make.
/// @param [in] rsrc The URI endpoint to make the request at. /// @param [in] rsrc The URI endpoint to make the request at.
Request(const Verb &verb, Str_8 rsrc); Request(const Verb verb, const Str_8& rsrc);
/// Initializes this request with the raw request data. /// Initializes this request with the raw request data.
/// @param [in] data The C-style string of the request. /// @param [in] data The C-style string of the request.
/// @param [in] size The size of the given C-style string. /// @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. /// Initializes this request with the raw request data.
/// @param [in] data The string of the request. /// @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. /// Copies members from another object of the same type.
/// @param [in] other The object to move from. /// @param [in] req The object to copy from.
Request(Request &&other) noexcept; Request(const Request& req) = default;
/// Copies members from another object of the same type. /// Copies members from another object of the same type.
/// @param [in] other The object to copy from. /// @param [in] req 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. /// @returns The request that has been assigned to.
Request& operator=(Request &&other) noexcept; Request& operator=(const Request& req);
/// Copies members from another object of the same type.
/// @param [in] other The object to copy from.
/// @returns The request that has been assigned to.
Request& operator=(const Request &other);
/// Retrieves the verb for the request. /// Retrieves the verb for the request.
/// @returns The result. /// @returns The result.
@@ -70,7 +59,7 @@ namespace ehs
/// Sets the content type for the body. /// Sets the content type for the body.
/// @param [in] cType The content type to use. /// @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. /// Retrieves the content type for the body.
/// @returns The result. /// @returns The result.
@@ -78,60 +67,25 @@ namespace ehs
/// Sets the URI resource. /// Sets the URI resource.
/// @param [in] rsrc The resource. /// @param [in] rsrc The resource.
void SetResource(Str_8 rsrc); void SetResource(const Str_8& rsrc);
/// Retrieves the URI resource. /// Retrieves the URI resource.
/// @returns The result. /// @returns The result.
Str_8 GetResource() const; Str_8 GetResource() const;
/// Checks whether a header variable exists using the id. /// Adds a query variable to the URI.
/// @param [in] id The variable id to look for. /// @param [in] var The variable identifier.
/// @returns True if the variable exists. False otherwise. /// @param [in] value The value of the variable.
bool HasQueryVar(const UInt_64 &id) const; void AddQuery(const Str_8& var, const Str_8& value);
/// Checks whether a header variable exists using the name. /// Retrieves a query variable from the URI.
/// @param [in] name The variable name to look for. /// @param [in] var The variable identifier to look for.
/// @returns True if the variable exists. False otherwise. /// @returns The value of the query variable. Empty if it was not found.
bool HasQueryVar(const Str_8 &name) const; Str_8 GetQuery(const Str_8& var);
/// 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. /// Retrieves all the query variables from the URI in a vector object.
/// @returns The result. /// @returns The result.
Vector<QueryVar> GetQueries() const; Vector<Str_8> GetQueries() const;
/// A helper method to automatically add the required header variables for basic authentication. /// A helper method to automatically add the required header variables for basic authentication.
/// @param [in] id The username or id. /// @param [in] id The username or id.
@@ -151,54 +105,19 @@ namespace ehs
/// @param [in] token The token given by an API. /// @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. /// Adds a header variable.
/// @param [in] var The variable to add to the header. /// @param [in] var The variable identifier.
/// @returns False if the given variable name already exists. True otherwise. /// @param [in] value The value of the variable.
bool AddHeaderVar(HeaderVar var); void AddToHeader(const Str_8& var, const Str_8& value);
/// Removes a header variable using the id. /// Retrieves a header variable.
/// @param [in] id The variable id to look for. /// @param [in] var The variable identifier to look for.
/// @returns True if the variable was found. False otherwise. /// @returns The value of the header variable. Empty if it was not found.
bool RemoveHeaderVar(const UInt_64 &id); Str_8 GetHeader(const Str_8& var) const;
/// 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. /// Retrieves all the header variables in a vector object.
/// @returns The result. /// @returns The result.
Vector<HeaderVar> GetHeader() const; Vector<Str_8> GetHeader() const;
/// Adds a body variable. /// Adds a body variable.
/// @param [in] var The variable identifier. /// @param [in] var The variable identifier.
@@ -233,9 +152,9 @@ namespace ehs
bool IsValid() const; bool IsValid() const;
private: 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);

View File

@@ -5,7 +5,6 @@
#include "ehs/Str.h" #include "ehs/Str.h"
#include "ehs/json/Json.h" #include "ehs/json/Json.h"
#include "Socket.h" #include "Socket.h"
#include "HeaderVar.h"
namespace ehs namespace ehs
{ {
@@ -15,7 +14,7 @@ namespace ehs
UInt_32 code; UInt_32 code;
Str_8 server; Str_8 server;
ContentType cType; ContentType cType;
Vector<HeaderVar> header; Vector<Str_8> header;
Str_8 body; Str_8 body;
public: public:
@@ -25,38 +24,29 @@ namespace ehs
/// Initializes this response with a given code and server identifier. /// Initializes this response with a given code and server identifier.
/// @param [in] code The code to give. /// @param [in] code The code to give.
/// @param [in] server The server identifier. /// @param [in] server The server identifier.
Response(const UInt_32 &code, Str_8 server); Response(const UInt_32 code, const Str_8& server);
/// Initializes this response with the raw response data. /// Initializes this response with the raw response data.
/// @param [in] data The C-style string of the response. /// @param [in] data The C-style string of the response.
/// @param [in] size The size of the given C-style string. /// @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. /// Initializes this response with the raw response data.
/// @param [in] data The string of the response. /// @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. /// Copies members from another object of the same type.
/// @param [in] other The object to copy from. /// @param [in] res The object to copy from.
Response(const Response &other); Response(const Response& res) = default;
/// 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. /// Copies members from another object of the same type.
/// @param [in] res The object to copy from. /// @param [in] res The object to copy from.
/// @returns The response that has been assigned to. /// @returns The response that has been assigned to.
Response& operator=(const Response &other); Response& operator=(const Response& res);
/// Sets the response code to send to the endpoint. /// Sets the response code to send to the endpoint.
/// @param [in] code The code for success, error or info. /// @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. /// Retrieves the response code.
/// @returns The result. /// @returns The result.
@@ -64,7 +54,7 @@ namespace ehs
/// Sets the server identifier. /// Sets the server identifier.
/// @param [in] server The server identifier to use. /// @param [in] server The server identifier to use.
void SetServer(Str_8 server); void SetServer(const Str_8& server);
/// Retrieves the server identifier. /// Retrieves the server identifier.
/// @returns The result. /// @returns The result.
@@ -72,60 +62,25 @@ namespace ehs
/// Sets the content type for the body. /// Sets the content type for the body.
/// @param [in] cType The content type to use. /// @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. /// Retrieves the content type for the body.
/// @returns The result. /// @returns The result.
ContentType GetContentType() const; ContentType GetContentType() const;
/// 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. /// Adds a header variable.
/// @param [in] var The variable to add to the header. /// @param [in] var The variable identifier.
/// @returns False if the given variable name already exists. True otherwise. /// @param [in] value The value of the variable.
bool AddHeaderVar(HeaderVar var); void AddToHeader(const Str_8& var, const Str_8& value);
/// Removes a header variable using the id. /// Retrieves a header variable.
/// @param [in] id The variable id to look for. /// @param [in] var The variable identifier to look for.
/// @returns True if the variable was found. False otherwise. /// @returns The value of the header variable. Empty if it was not found.
bool RemoveHeaderVar(const UInt_64 &id); Str_8 GetHeader(const Str_8& var) const;
/// 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. /// Retrieves all the header variables in a vector object.
/// @returns The result. /// @returns The result.
Vector<HeaderVar> GetHeader() const; Vector<Str_8> GetHeader() const;
/// Adds a body variable. /// Adds a body variable.
/// @param [in] var The variable identifier. /// @param [in] var The variable identifier.
@@ -160,9 +115,9 @@ namespace ehs
bool IsValid() const; bool IsValid() const;
private: 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);

View File

@@ -1,7 +1,5 @@
#pragma once #pragma once
#include <openssl/types.h>
#include "ehs/EHS.h" #include "ehs/EHS.h"
#include "ehs/Str.h" #include "ehs/Str.h"
#include "TCP.h" #include "TCP.h"
@@ -17,18 +15,15 @@ namespace ehs
class EHS_LIB_IO SSL : public TCP class EHS_LIB_IO SSL : public TCP
{ {
private: private:
bool server;
SSL_CTX* ctx; SSL_CTX* ctx;
::SSL* sslHdl; ::SSL* sslHdl;
X509 *cert;
EVP_PKEY* pkey;
public: public:
~SSL() override; ~SSL() override;
SSL(); SSL();
SSL(const IP &type, const bool &server); SSL(const IP type);
SSL(TCP&& tcp) noexcept; SSL(TCP&& tcp) noexcept;
@@ -42,19 +37,19 @@ namespace ehs
void Release() override; void Release() override;
void Listen() override; void Bind(const Str_8& address, unsigned short port) override;
SSL* Accept() override; SSL* Accept() override;
void Connect(Str_8 address, const UInt_16 &port) override; void Connect(const Str_8& address, const UInt_16 port) override;
UInt_64 Send(const Byte* buffer, const UInt_32 size) override; UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
UInt_64 Receive(Byte* buffer, const UInt_32 size) override; UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
void UseCertificate(const Char_8* data, const UInt_32 &size); void UseCertificate(const Byte* data, const UInt_64 size);
void UsePrivateKey(const Char_8* data, const UInt_32 &size); void UsePrivateKey(const Byte* data, const UInt_64 size);
bool IsValid(); bool IsValid();
}; };

View File

@@ -40,9 +40,7 @@ namespace ehs
APP_XML, APP_XML,
TEXT_PLAIN, TEXT_PLAIN,
TEXT_HTML, TEXT_HTML,
TEXT_CSS,
TEXT_XML, TEXT_XML,
IMG_X_ICON,
NONE NONE
}; };

View File

@@ -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] 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. /// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called. /// @note Requires the port given to be forwarded if this is called.
void Bind(Str_8 address, const UInt_16 &port) override; void Bind(const Str_8& address, UInt_16 port) override;
/// Listens for incoming connections. Used for servers or PtP. /// Listens for incoming connections. Used for servers or PtP.
void Listen() override; void Listen() override;
@@ -58,7 +58,7 @@ namespace ehs
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP. /// 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 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. /// @param port The port of the listening TCP socket.
void Connect(Str_8 address, const UInt_16 &port) override; void Connect(const Str_8& address, 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. /// 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. /// @param [in] buffer The C-style array to send.
@@ -84,17 +84,15 @@ namespace ehs
bool IsIPv6Only() const override; bool IsIPv6Only() const override;
void SetReuse(const bool &value) override;
bool IsValid() const override; bool IsValid() const override;
private: private:
void Bind_v6(const Str_8 &address, const UInt_16 &port) const; void Bind_v6(const Str_8& address, UInt_16 port);
void Bind_v4(const Str_8 &address, const UInt_16 &port) const; void Bind_v4(const Str_8& address, UInt_16 port);
void Connect_v6(const Str_8 &address, const UInt_16 &port); void Connect_v6(const Str_8& address, UInt_16 port);
void Connect_v4(const Str_8 &address, const UInt_16 &port); void Connect_v4(const Str_8& address, UInt_16 port);
}; };
} }

View File

@@ -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] 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. /// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called. /// @note Requires the port given to be forwarded if this is called.
void Bind(Str_8 address, const UInt_16 &port) override; void Bind(const Str_8& address, UInt_16 port) override;
/// Listens for incoming connections. Used for servers or PtP. /// Listens for incoming connections. Used for servers or PtP.
void Listen() override; void Listen() override;
@@ -58,7 +58,7 @@ namespace ehs
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP. /// 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 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. /// @param port The port of the listening TCP socket.
void Connect(Str_8 address, const UInt_16 &port) override; void Connect(const Str_8& address, 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. /// 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. /// @param [in] buffer The C-style array to send.
@@ -84,14 +84,12 @@ namespace ehs
bool IsIPv6Only() const override; bool IsIPv6Only() const override;
void SetReuse(const bool &value) override;
bool IsValid() const override; bool IsValid() const override;
private: private:
void Bind_v6(const Str_8& address, const UInt_16 &port); void Bind_v6(const Str_8& address, UInt_16 port);
void Bind_v4(const Str_8& address, const UInt_16 &port); void Bind_v4(const Str_8& address, UInt_16 port);
void Connect_v6(const Str_8& address, UInt_16 port); void Connect_v6(const Str_8& address, UInt_16 port);

View File

@@ -1,36 +0,0 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
class EHS_LIB_IO AVX2
{
public:
/// Compares two unaligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
static bool CompareUnaligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two unaligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
static bool CompareUnaligned(const SInt_64 *a, const SInt_64 *b);
/// Compares two aligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two aligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const SInt_64 *a, const SInt_64 *b);
};
}

View File

@@ -1,36 +0,0 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
class EHS_LIB_IO AVX512
{
public:
/// Compares two unaligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
static bool CompareUnaligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two unaligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
static bool CompareUnaligned(const SInt_64 *a, const SInt_64 *b);
/// Compares two aligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two aligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const SInt_64 *a, const SInt_64 *b);
};
}

View File

@@ -6,7 +6,7 @@
#define EHS_64_BIT #define EHS_64_BIT
#elif defined(_M_ARM64) || defined(__aarch64__) #elif defined(_M_ARM64) || defined(__aarch64__)
#define EHS_LITTLE_ENDIAN #define EHS_LITTLE_ENDIAN
#define EHS_ARCH_AARCH64 #define EHS_ARCH_ARM64
#define EHS_64_BIT #define EHS_64_BIT
#else #else
#error Unsupported architecture. #error Unsupported architecture.

View File

@@ -8,7 +8,7 @@ namespace ehs
class EHS_LIB_IO BaseSystem class EHS_LIB_IO BaseSystem
{ {
public: public:
static void OpenURI(Str_8 uri); static void OpenURI(const Str_8& uri);
static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters); static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters);

View File

@@ -38,70 +38,6 @@ namespace ehs
#endif #endif
public: public:
static const bool hasFPU;
static const bool hasVME;
static const bool hasDE;
static const bool hasPSE;
static const bool hasTSC;
static const bool hasMSR;
static const bool hasPAE;
static const bool hasMCE;
static const bool hasCX8;
static const bool hasAPIC;
static const bool hasSEP;
static const bool hasMTRR;
static const bool hasPGE;
static const bool hasMCA;
static const bool hasCMOV;
static const bool hasPSE_36;
static const bool hasPSN;
static const bool hasCLFSH;
static const bool hasDS;
static const bool hasACPI;
static const bool hasMMX;
static const bool hasFXSR;
static const bool hasSSE;
static const bool hasSSE2;
static const bool hasSS;
static const bool hasHTT;
static const bool hasTM;
static const bool hasIA64;
static const bool hasPBE;
static const bool hasSSE3;
static const bool hasPCLMULQDQ;
static const bool hasDTES64;
static const bool hasMONITOR;
static const bool hasVMX;
static const bool hasSMX;
static const bool hasEST;
static const bool hasTM2;
static const bool hasSSSE3;
static const bool hasCNXT_ID;
static const bool hasSDBG;
static const bool hasFMA;
static const bool hasCX16;
static const bool hasXTPR;
static const bool hasPDCM;
static const bool hasPCID;
static const bool hasDCA;
static const bool hasSSE4_1;
static const bool hasSSE4_2;
static const bool hasX2APIC;
static const bool hasMOVBE;
static const bool hasPOPCNT;
static const bool hasTSC_DEADLINE;
static const bool hasAES;
static const bool hasXSAVE;
static const bool hasOSXSAVE;
static const bool hasAVX;
static const bool hasF16C;
static const bool hasRDRND;
static const bool hasHYPERVISOR;
static const bool hasAVX2;
static const bool hasAVX512F;
static const bool hasRDSEED;
static const bool hasADX;
static Architecture GetArchitecture(); static Architecture GetArchitecture();
static UInt_8 PointerSize(); static UInt_8 PointerSize();
@@ -132,157 +68,153 @@ namespace ehs
static UInt_8 GetExtFamilyId(); static UInt_8 GetExtFamilyId();
static UInt_32 GetFeatureBits_1();
static bool HasFPU();
static bool HasVME();
static bool HasDE();
static bool HasPSE();
static bool HasTSC();
static bool HasMSR();
static bool HasPAE();
static bool HasMCE();
static bool HasCX8();
static bool HasAPIC();
static bool HasSEP();
static bool HasMTRR();
static bool HasPGE();
static bool HasMCA();
static bool HasCMOV();
static bool HasPAT();
static bool HasPSE_36();
static bool HasPSN();
static bool HasCLFSH();
static bool HasDS();
static bool HasACPI();
static bool HasMMX();
static bool HasFXSR();
static bool HasSSE();
static bool HasSSE2();
static bool HasSS();
static bool HasHTT();
static bool HasTM();
static bool HasIA64();
static bool HasPBE();
static UInt_32 GetFeatureBits_2();
static bool HasSSE3();
static bool HasPCLMULQDQ();
static bool HasDTES64();
static bool HasMONITOR();
static bool HasDS_CPL();
static bool HasVMX();
static bool HasSMX();
static bool HasEST();
static bool HasTM2();
static bool HasSSSE3();
static bool HasCNXT_ID();
static bool HasSDBG();
static bool HasFMA();
static bool HasCX16();
static bool HasXTPR();
static bool HasPDCM();
static bool HasPCID();
static bool HasDCA();
static bool HasSSE4_1();
static bool HasSSE4_2();
static bool HasX2APIC();
static bool HasMOVBE();
static bool HasPOPCNT();
static bool HasTSC_DEADLINE();
static bool HasAES();
static bool HasXSAVE();
static bool HasOSXSAVE();
static bool HasAVX();
static bool HasF16C();
static bool HasRDRND();
static bool HasHYPERVISOR();
static UInt_32 GetExtFeatureBits_1();
static bool HasAVX2();
static bool HasRDSEED();
static bool HasADX();
static UInt_32 GetExtFeatureBits_2();
static UInt_32 GetExtFeatureBits_3();
/// Retrieves the CPU brand as a null-terminated ASCII string. /// Retrieves the CPU brand as a null-terminated ASCII string.
/// @param[out] input A 48 byte character array representing the brand. /// @param[out] input A 48 byte character array representing the brand.
static void GetBrand(Char_8* input); static void GetBrand(Char_8* input);
static UInt_8 GetCacheLineSize(); static UInt_8 GetCacheLineSize();
static UInt_32 GetFeatureBits_1();
static UInt_32 GetFeatureBits_2();
static UInt_32 GetExtFeatureBits_1();
static UInt_32 GetExtFeatureBits_2();
static UInt_32 GetExtFeatureBits_3();
private:
static bool RetrieveFPU();
static bool RetrieveVME();
static bool RetrieveDE();
static bool RetrievePSE();
static bool RetrieveTSC();
static bool RetrieveMSR();
static bool RetrievePAE();
static bool RetrieveMCE();
static bool RetrieveCX8();
static bool RetrieveAPIC();
static bool RetrieveSEP();
static bool RetrieveMTRR();
static bool RetrievePGE();
static bool RetrieveMCA();
static bool RetrieveCMOV();
static bool RetrievePAT();
static bool RetrievePSE_36();
static bool RetrievePSN();
static bool RetrieveCLFSH();
static bool RetrieveDS();
static bool RetrieveACPI();
static bool RetrieveMMX();
static bool RetrieveFXSR();
static bool RetrieveSSE();
static bool RetrieveSSE2();
static bool RetrieveSS();
static bool RetrieveHTT();
static bool RetrieveTM();
static bool RetrieveIA64();
static bool RetrievePBE();
static bool RetrieveSSE3();
static bool RetrievePCLMULQDQ();
static bool RetrieveDTES64();
static bool RetrieveMONITOR();
static bool RetrieveDS_CPL();
static bool RetrieveVMX();
static bool RetrieveSMX();
static bool RetrieveEST();
static bool RetrieveTM2();
static bool RetrieveSSSE3();
static bool RetrieveCNXT_ID();
static bool RetrieveSDBG();
static bool RetrieveFMA();
static bool RetrieveCX16();
static bool RetrieveXTPR();
static bool RetrievePDCM();
static bool RetrievePCID();
static bool RetrieveDCA();
static bool RetrieveSSE4_1();
static bool RetrieveSSE4_2();
static bool RetrieveX2APIC();
static bool RetrieveMOVBE();
static bool RetrievePOPCNT();
static bool RetrieveTSC_DEADLINE();
static bool RetrieveAES();
static bool RetrieveXSAVE();
static bool RetrieveOSXSAVE();
static bool RetrieveAVX();
static bool RetrieveF16C();
static bool RetrieveRDRND();
static bool RetrieveHYPERVISOR();
static bool RetrieveAVX2();
static bool RetrieveAVX512F();
static bool RetrieveRDSEED();
static bool RetrieveADX();
//static Str_8 ToStr(); //static Str_8 ToStr();
static UInt_64 RetrieveFreq_AARCH64(); private:
static UInt_64 RetrieveTSC_Freq(); static UInt_64 RetrieveTSC_Freq();
static UInt_64 CalculateTSC_Freq(); static UInt_64 CalculateTSC_Freq();

View File

@@ -8,7 +8,7 @@ namespace ehs
class EHS_LIB_IO System : public BaseSystem class EHS_LIB_IO System : public BaseSystem
{ {
public: public:
static void OpenURI(Str_8 uri); static void OpenURI(const Str_8& uri);
static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters); static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters);

View File

@@ -7,6 +7,6 @@ namespace ehs
class EHS_LIB_IO System : public BaseSystem class EHS_LIB_IO System : public BaseSystem
{ {
public: public:
static void OpenURI(Str_8 uri); static void OpenURI(const Str_8& uri);
}; };
} }

View File

@@ -2,35 +2,7 @@
namespace ehs namespace ehs
{ {
Str_8 Base64::EncodeURL(const Str_8 &input) const char Base64::ascii[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
{
UInt_64 input_length = input.Size();
// Calculate the output length
UInt_64 output_length = (input_length * 4 + 2) / 3;
// Allocate memory for the output
Str_8 result(output_length);
// Loop through the input and fill the output
for (int i = 0, j = 0; i < input_length;) {
// Take first byte and shift right by 2 bits
UInt_32 octet_a = (UInt_8)input[i++];
UInt_32 octet_b = i < input_length ? (UInt_8)input[i++] : 0;
UInt_32 octet_c = i < input_length ? (UInt_8)input[i++] : 0;
UInt_32 triple = (octet_a << 16) + (octet_b << 8) + octet_c;
// Encode the 24-bits into four 6-bits integers
result[j++] = asciiUrl[(triple >> 3 * 6) & 0x3F];
result[j++] = asciiUrl[(triple >> 2 * 6) & 0x3F];
result[j++] = asciiUrl[(triple >> 1 * 6) & 0x3F];
result[j++] = asciiUrl[(triple >> 0 * 6) & 0x3F];
}
return result;
}
Str_8 Base64::Encode(const Str_8 &input) Str_8 Base64::Encode(const Str_8 &input)
{ {
@@ -46,9 +18,9 @@ namespace ehs
for (int i = 0, j = 0; i < input_length;) { for (int i = 0, j = 0; i < input_length;) {
// Take first byte and shift right by 2 bits // Take first byte and shift right by 2 bits
UInt_32 octet_a = i < input_length ? (UInt_8)input[i++] : 0; UInt_32 octet_a = i < input_length ? input[i++] : 0;
UInt_32 octet_b = i < input_length ? (UInt_8)input[i++] : 0; UInt_32 octet_b = i < input_length ? input[i++] : 0;
UInt_32 octet_c = i < input_length ? (UInt_8)input[i++] : 0; UInt_32 octet_c = i < input_length ? input[i++] : 0;
UInt_32 triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; UInt_32 triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
@@ -70,151 +42,63 @@ namespace ehs
return result; return result;
} }
Str_8 Base64::DecodeURL(const Str_8 &input)
{
Str_8 result(input.Size() * 3 / 4);
UInt_64 remaining = input.Size();
UInt_64 offsetIn = 0;
UInt_64 offsetOut = 0;
UInt_8 quartet[4];
while (remaining)
{
if (remaining >= 4)
{
for (UInt_8 i = 0; i < 4; ++i)
{
if (!IsBase64URL(input[offsetIn + i]))
return {};
quartet[i] = FindURL(input[offsetIn + i]);
if (quartet[i] == EHS_UINT_8_MAX)
return {};
}
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[0] << 2) | (((UInt_8*)&quartet)[1] >> 4));
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[1] << 4) | (((UInt_8*)&quartet)[2] >> 2));
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[2] << 6) | ((UInt_8*)&quartet)[3]);
offsetIn += 4;
remaining -= 4;
}
else
{
for (UInt_8 i = 0; i < 4; ++i)
{
if (i < remaining)
{
if (!IsBase64URL(input[offsetIn + i]))
return {};
quartet[i] = FindURL(input[offsetIn + i]);
if (quartet[i] == EHS_UINT_8_MAX)
return {};
}
else
quartet[i] = 0;
}
result[offsetOut++] = (Char_8)((quartet[0] << 2) | (quartet[1] >> 4));
if (remaining == 3)
result[offsetOut++] = (Char_8)((quartet[1] << 4) | (quartet[2] >> 2));
offsetIn += remaining;
remaining = 0;
}
}
return result;
}
Str_8 Base64::Decode(const Str_8 &input) Str_8 Base64::Decode(const Str_8 &input)
{ {
Str_8 result(input.Size() * 3 / 4); UInt_64 in_len = input.Size();
int i = 0;
int j = 0;
int in_ = 0;
char char_array_4[4], char_array_3[3];
Str_8 ret;
UInt_64 remaining = input.Size(); while (in_len-- && ( input[in_] != '=') && IsBase64(input[in_]))
UInt_64 offsetIn = 0;
UInt_64 offsetOut = 0;
UInt_8 quartet[4];
while (remaining)
{ {
if (remaining >= 4) char_array_4[i++] = input[in_]; in_++;
if (i ==4)
{ {
for (UInt_8 i = 0; i < 4; ++i) for (i = 0; i <4; i++)
{ char_array_4[i] = Find(char_array_4[i]);
if (!IsBase64(input[offsetIn + i]))
return {};
quartet[i] = Find(input[offsetIn + i]); char_array_3[0] = ( char_array_4[0] << 2 ) + ((char_array_4[1] & 0x30) >> 4);
if (quartet[i] == EHS_UINT_8_MAX) char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
return {}; char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
}
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[0] << 2) | (((UInt_8*)&quartet)[1] >> 4)); for (i = 0; (i < 3); i++)
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[1] << 4) | (((UInt_8*)&quartet)[2] >> 2)); ret += char_array_3[i];
result[offsetOut++] = (Char_8)((((UInt_8*)&quartet)[2] << 6) | ((UInt_8*)&quartet)[3]);
offsetIn += 4; i = 0;
remaining -= 4;
}
else
{
for (UInt_8 i = 0; i < 4; ++i)
{
if (i < remaining)
{
if (!IsBase64(input[offsetIn + i]))
return {};
quartet[i] = Find(input[offsetIn + i]);
if (quartet[i] == EHS_UINT_8_MAX)
return {};
}
else
quartet[i] = 0;
}
result[offsetOut++] = (Char_8)((quartet[0] << 2) | (quartet[1] >> 4));
if (remaining == 3)
result[offsetOut++] = (Char_8)((quartet[1] << 4) | (quartet[2] >> 2));
offsetIn += remaining;
remaining = 0;
} }
} }
return result; if (i)
{
for (j = 0; j < i; j++)
char_array_4[j] = Find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
for (j = 0; (j < i - 1); j++)
ret += char_array_3[j];
} }
UInt_8 Base64::FindURL(const UInt_8 &c) return ret;
{
for (UInt_8 i = 0; i < (UInt_8)sizeof(asciiUrl) - 1; ++i)
if (asciiUrl[i] == c)
return i;
return EHS_UINT_8_MAX;;
} }
UInt_8 Base64::Find(const UInt_8 &c) char Base64::Find(const char c)
{
for (char i = 0; i < (char)sizeof(ascii); ++i)
{ {
for (UInt_8 i = 0; i < (UInt_8)sizeof(ascii) - 1; ++i)
if (ascii[i] == c) if (ascii[i] == c)
return i; return i;
}
return EHS_SINT_8_MAX; return EHS_SINT_8_MAX;
} }
bool Base64::IsBase64URL(const UInt_8 &c) bool Base64::IsBase64(const char c)
{ {
return (c > 47 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 123) || c == '-' || c == '_'; return (c > 47 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 123) || (c == '+') || (c == '/');
}
bool Base64::IsBase64(const UInt_8 &c)
{
return (c > 47 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 123) || c == '+' || c == '/';
} }
} }

View File

@@ -75,12 +75,12 @@ namespace ehs
{ {
} }
Log::Log(LogType type, const Str_8 &tags, const UInt_64 code, Str_8 msg) Log::Log(LogType type, const std::initializer_list<Str_8> &tags, const UInt_64 code, Str_8 msg)
: type(type), code(code), msg((Str_8&&)msg) : type(type), tags(tags.size()), code(code), msg((Str_8&&)msg)
{ {
const Vector<Str_8> tmpTags = tags.Split(", "); UInt_64 i = 0;
for (auto v = tags.begin(); v != tags.end(); ++v)
this->tags = Array<Str_8>(&tmpTags[0], tmpTags.Size()); this->tags[i++] = *v;
} }
Log::Log(LogType type, Array<Str_8> tags, const UInt_64 code, Str_8 msg) Log::Log(LogType type, Array<Str_8> tags, const UInt_64 code, Str_8 msg)

View File

@@ -36,9 +36,9 @@ namespace ehs
double Math::Sqrt(const double from) double Math::Sqrt(const double from)
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
if (CPU::hasAVX) if (CPU::HasAVX())
return Sqrt_AVX(from); return Sqrt_AVX(from);
else if (CPU::hasSSE) else if (CPU::HasSSE())
return Sqrt_SSE2(from); return Sqrt_SSE2(from);
double temp = 0.0; double temp = 0.0;
@@ -51,7 +51,7 @@ namespace ehs
} }
return result; return result;
#elif defined(EHS_ARCH_AARCH64) #elif defined(EHS_ARCH_ARM64)
return Sqrt_VFP4(from); return Sqrt_VFP4(from);
#endif #endif
} }
@@ -59,9 +59,9 @@ namespace ehs
float Math::Sqrt(const float from) float Math::Sqrt(const float from)
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
if (CPU::hasAVX) if (CPU::HasAVX())
return Sqrt_AVX(from); return Sqrt_AVX(from);
else if (CPU::hasSSE) else if (CPU::HasSSE())
return Sqrt_SSE(from); return Sqrt_SSE(from);
float temp = 0.0f; float temp = 0.0f;
@@ -74,7 +74,7 @@ namespace ehs
} }
return result; return result;
#elif defined(EHS_ARCH_AARCH64) #elif defined(EHS_ARCH_ARM64)
return Sqrt_VFP4(from); return Sqrt_VFP4(from);
#endif #endif
} }

View File

@@ -1,209 +0,0 @@
#include "ehs/SHA256.h"
#include "ehs/Util.h"
namespace ehs
{
UInt_32 SHA256::ROTR(const UInt_32 x, const UInt_32 n)
{
return (x >> n) | (x << (32 - n));
}
UInt_32 SHA256::CH(const UInt_32 x, const UInt_32 y, const UInt_32 z)
{
return (x & y) ^ (~x & z);
}
UInt_32 SHA256::MAJ(const UInt_32 x, const UInt_32 y, const UInt_32 z)
{
return (x & y) ^ (x & z) ^ (y & z);
}
UInt_32 SHA256::EP0(const UInt_32 x)
{
return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22);
}
UInt_32 SHA256::EP1(const UInt_32 x)
{
return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25);
}
UInt_32 SHA256::SIG0(const UInt_32 x)
{
return ROTR(x, 7) ^ ROTR(x, 18) ^ (x >> 3);
}
UInt_32 SHA256::SIG1(const UInt_32 x)
{
return ROTR(x,17) ^ ROTR(x, 19) ^ (x >> 10);
}
SHA256::SHA256()
: state{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19},
bitLen(0), data{}, dataLen(0)
{
}
SHA256::SHA256(SHA256&& other) noexcept
: state{}, bitLen(0), data{}, dataLen(0)
{
Util::Copy(state, other.state, sizeof(state) / sizeof(UInt_32));
bitLen = other.bitLen;
Util::Copy(data, other.data, sizeof(data));
dataLen = other.dataLen;
Util::Zero(other.state, sizeof(state) / sizeof(UInt_32));
other.bitLen = 0;
Util::Zero(other.data, sizeof(data));
other.dataLen = 0;
}
SHA256::SHA256(const SHA256& other)
: state{}, bitLen(0), data{}, dataLen(0)
{
Util::Copy(state, other.state, sizeof(state) / sizeof(UInt_32));
bitLen = other.bitLen;
Util::Copy(data, other.data, sizeof(data));
dataLen = other.dataLen;
}
SHA256& SHA256::operator=(SHA256&& other) noexcept
{
if (this == &other)
return *this;
Util::Copy(state, other.state, sizeof(state) / sizeof(UInt_32));
bitLen = other.bitLen;
Util::Copy(data, other.data, sizeof(data));
dataLen = other.dataLen;
Util::Zero(other.state, sizeof(state) / sizeof(UInt_32));
other.bitLen = 0;
Util::Zero(other.data, sizeof(data));
other.dataLen = 0;
return *this;
}
SHA256& SHA256::operator=(const SHA256& other)
{
if (this == &other)
return *this;
Util::Copy(state, other.state, sizeof(state) / sizeof(UInt_32));
bitLen = other.bitLen;
Util::Copy(data, other.data, sizeof(data));
dataLen = other.dataLen;
return *this;
}
void SHA256::Update(const Byte* data, const UInt_64 len)
{
for(UInt_64 i = 0; i < len; ++i)
{
this->data[dataLen++] = data[i];
if(dataLen == 64)
{
Transform(this->data);
bitLen += 512;
dataLen = 0;
}
}
}
void SHA256::Final(Byte hash[32])
{
UInt_32 i = dataLen;
/* Pad */
data[i++] = 0x80;
if(i > 56)
{
while(i < 64)
data[i++] = 0x00;
Transform(data);
i = 0;
}
while(i < 56)
data[i++] = 0x00;
/* Length in bits */
bitLen += dataLen * 8ULL;
data[63] = bitLen;
data[62] = bitLen >> 8;
data[61] = bitLen >> 16;
data[60] = bitLen >> 24;
data[59] = bitLen >> 32;
data[58] = bitLen >> 40;
data[57] = bitLen >> 48;
data[56] = bitLen >> 56;
Transform(data);
/* bigendian output */
for(i = 0; i < 4; ++i) {
hash[i] = (state[0] >> (24 - i * 8)) & 0xff;
hash[i + 4] = (state[1] >> (24 - i * 8)) & 0xff;
hash[i + 8] = (state[2] >> (24 - i * 8)) & 0xff;
hash[i + 12] = (state[3] >> (24 - i * 8)) & 0xff;
hash[i + 16] = (state[4] >> (24 - i * 8)) & 0xff;
hash[i + 20] = (state[5] >> (24 - i * 8)) & 0xff;
hash[i + 24] = (state[6] >> (24 - i * 8)) & 0xff;
hash[i + 28] = (state[7] >> (24 - i * 8)) & 0xff;
}
}
void SHA256::Hash(const Byte* data, const UInt_64 len, Byte hash[32])
{
Update(data, len);
Final(hash);
}
void SHA256::Transform(const Byte data[64])
{
UInt_32 m[64];
UInt_32 a = state[0];
UInt_32 b = state[1];
UInt_32 c = state[2];
UInt_32 d = state[3];
UInt_32 e = state[4];
UInt_32 f = state[5];
UInt_32 g = state[6];
UInt_32 h = state[7];
UInt_32 i, t1, t2;
for (i = 0; i < 16; ++i)
m[i] = (UInt_32)data[i * 4] << 24 | (UInt_32)data[i * 4 + 1] << 16 | (UInt_32)data[i * 4 + 2] << 8 | (UInt_32)data[i * 4 + 3];
for (; i < 64; ++i)
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
for(i = 0; i < 64; ++i)
{
t1 = h + EP1(e) + CH(e,f,g) + k[i] + m[i];
t2 = EP0(a) + MAJ(a,b,c);
h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
}
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
state[5] += f;
state[6] += g;
state[7] += h;
}
}

View File

@@ -1,9 +1,5 @@
#include "ehs/Util.h" #include "ehs/Util.h"
#include "ehs/system/CPU.h"
#include "ehs/system/AVX2.h"
#include "ehs/system/AVX512.h"
namespace ehs namespace ehs
{ {
bool Util::Compare(const void* const a, const void* const b, const UInt_64 size) bool Util::Compare(const void* const a, const void* const b, const UInt_64 size)

View File

@@ -693,7 +693,7 @@ namespace ehs
Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize) Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return UTF::To_32(GetCommandLineW()).ParseArgs(); return UTF::To_32(GetCommandLineW()).Split(U" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);
@@ -725,7 +725,7 @@ namespace ehs
Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize) Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return Str_16(GetCommandLineW()).ParseArgs(); return Str_16(GetCommandLineW()).Split(L" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);
@@ -755,7 +755,7 @@ namespace ehs
Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize) Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return UTF::To_8(GetCommandLineW()).ParseArgs(); return UTF::To_8(GetCommandLineW()).Split(" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);

View File

@@ -93,13 +93,13 @@ namespace ehs
} }
AudioDevice::AudioDevice() AudioDevice::AudioDevice()
: id(0), loop(nullptr), context(nullptr), core(nullptr), input(nullptr), output(nullptr), paramsHook{} : id(0), loop(nullptr), context(nullptr), core(nullptr), input(nullptr), output(nullptr)
{ {
} }
AudioDevice::AudioDevice(AudioDevice&& device) noexcept AudioDevice::AudioDevice(AudioDevice&& device) noexcept
: BaseAudioDevice(device), id(device.id), name((Str_8 &&)device.name), loop(device.loop), : 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), paramsHook(device.paramsHook) context(device.context), core(device.core), input(device.input), output(device.output)
{ {
device.id = 0; device.id = 0;
device.loop = nullptr; device.loop = nullptr;
@@ -107,12 +107,11 @@ namespace ehs
device.core = nullptr; device.core = nullptr;
device.input = nullptr; device.input = nullptr;
device.output = nullptr; device.output = nullptr;
device.paramsHook = {};
} }
AudioDevice::AudioDevice(const AudioDevice& device) AudioDevice::AudioDevice(const AudioDevice& device)
: BaseAudioDevice(device), id(device.id), name(device.name), loop(nullptr), context(nullptr), core(nullptr), : BaseAudioDevice(device), id(device.id), name(device.name), loop(nullptr), context(nullptr), core(nullptr),
input(nullptr), output(nullptr), paramsHook{} input(nullptr), output(nullptr)
{ {
} }
@@ -130,7 +129,6 @@ namespace ehs
core = device.core; core = device.core;
input = device.input; input = device.input;
output = device.output; output = device.output;
paramsHook = device.paramsHook;
device.id = 0; device.id = 0;
device.loop = nullptr; device.loop = nullptr;
@@ -138,7 +136,6 @@ namespace ehs
device.core = nullptr; device.core = nullptr;
device.input = nullptr; device.input = nullptr;
device.output = nullptr; device.output = nullptr;
device.paramsHook = {};
return *this; return *this;
} }
@@ -157,7 +154,6 @@ namespace ehs
core = nullptr; core = nullptr;
input = nullptr; input = nullptr;
output = nullptr; output = nullptr;
paramsHook = {};
return *this; return *this;
} }
@@ -210,18 +206,14 @@ namespace ehs
return; return;
} }
SInt_32 err = pw_stream_connect( pw_stream_connect(
input, output,
PW_DIRECTION_INPUT, PW_DIRECTION_INPUT,
id, id,
(pw_stream_flags)(PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS), (pw_stream_flags)(PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS),
pod, pod,
1 1
); );
if (err)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to connect input stream for audio device.");
}
} }
if (GetType() == AudioDeviceType::OUTPUT || GetType() == AudioDeviceType::ALL) if (GetType() == AudioDeviceType::OUTPUT || GetType() == AudioDeviceType::ALL)
@@ -233,7 +225,7 @@ namespace ehs
return; return;
} }
SInt_32 err = pw_stream_connect( pw_stream_connect(
output, output,
PW_DIRECTION_OUTPUT, PW_DIRECTION_OUTPUT,
id, id,
@@ -241,10 +233,6 @@ namespace ehs
pod, pod,
1 1
); );
if (err)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to connect output stream for audio device.");
}
} }
static constexpr pw_stream_events streamEvents = { static constexpr pw_stream_events streamEvents = {
@@ -252,17 +240,8 @@ namespace ehs
.param_changed = OnParamChanged .param_changed = OnParamChanged
}; };
pw_stream_add_listener(output, &paramsHook, &streamEvents, this); spa_hook streamListener = {};
pw_stream_add_listener(output, &streamListener, &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(); EHS_LOG_SUCCESS();
} }
@@ -304,15 +283,7 @@ namespace ehs
return 0; return 0;
} }
if (!data || !size) pw_loop_iterate(loop, 0);
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) if (pw_stream_get_state(output, nullptr) != PW_STREAM_STATE_STREAMING)
return 0; return 0;

View File

@@ -9,18 +9,18 @@ namespace ehs
} }
Input::Input() Input::Input()
: initialized(false) : initalized(false)
{ {
} }
Input::Input(Input&& input) noexcept Input::Input(Input&& input) noexcept
: handlers((Array<InputHandler*>&&)input.handlers), initialized(input.initialized) : handlers((Array<InputHandler*>&&)input.handlers), initalized(input.initalized)
{ {
input.initialized = false; input.initalized = false;
} }
Input::Input(const Input& input) Input::Input(const Input& input)
: initialized(false) : initalized(false)
{ {
} }
@@ -30,9 +30,9 @@ namespace ehs
return *this; return *this;
handlers = (Array<InputHandler*>&&)input.handlers; handlers = (Array<InputHandler*>&&)input.handlers;
initialized = input.initialized; initalized = input.initalized;
input.initialized = false; input.initalized = false;
return *this; return *this;
} }
@@ -46,14 +46,14 @@ namespace ehs
delete handlers; delete handlers;
handlers = Array<InputHandler*>(); handlers = Array<InputHandler*>();
initialized = false; initalized = false;
return *this; return *this;
} }
void Input::Initialize() void Input::Initialize()
{ {
if (initialized) if (initalized)
return; return;
UInt_64 i = 0; UInt_64 i = 0;
@@ -72,12 +72,12 @@ namespace ehs
i++; i++;
} }
initialized = true; initalized = true;
} }
void Input::Release() void Input::Release()
{ {
if (!initialized) if (!initalized)
return; return;
UInt_64 i = 0; UInt_64 i = 0;
@@ -96,7 +96,7 @@ namespace ehs
i++; i++;
} }
initialized = false; initalized = false;
} }
void Input::Poll() void Input::Poll()
@@ -124,7 +124,7 @@ namespace ehs
if (HasHandler(handler->GetHashId())) if (HasHandler(handler->GetHashId()))
return false; return false;
if (initialized) if (initalized)
{ {
bool hInitialized = handler->Initialize(); bool hInitialized = handler->Initialize();
if (!hInitialized) if (!hInitialized)
@@ -155,6 +155,6 @@ namespace ehs
bool Input::IsInitialized() const bool Input::IsInitialized() const
{ {
return initialized; return initalized;
} }
} }

View File

@@ -36,6 +36,93 @@ namespace ehs
return new Keyboard(*this); 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) Button Keyboard::TranslateScanCode(const UInt_32 code)
{ {
switch (code) switch (code)

View File

@@ -50,6 +50,19 @@ namespace ehs
return new Mouse(*this); 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) Button Mouse::TranslateXCB(const UInt_32 code)
{ {
switch (code) switch (code)

View File

@@ -1,6 +1,8 @@
#include "ehs/io/socket/BaseICMP.h" #include "ehs/io/socket/BaseICMP.h"
#include "ehs/Serializer.h" #include "ehs/Serializer.h"
#include <netinet/ip.h>
namespace ehs namespace ehs
{ {
@@ -45,24 +47,14 @@ namespace ehs
return *this; return *this;
} }
void BaseICMP::Release()
{
}
UInt_64 BaseICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) UInt_64 BaseICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{ {
if (GetVersion() == IP::V6) return 0;
return SendV6(address, header, data, size);
return SendV4(address, header, data, size);
} }
UInt_64 BaseICMP::Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) UInt_64 BaseICMP::Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data)
{ {
if (GetVersion() == IP::V6) return 0;
return ReceiveV6(address, header, data);
return ReceiveV4(address, header, data);
} }
void BaseICMP::SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size) void BaseICMP::SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size)
@@ -75,7 +67,7 @@ namespace ehs
} }
ICMP_Header header = { ICMP_Header header = {
version == IP::V6 ? (UInt_8)128 : (UInt_8)8, 8,
0, 0,
0 0
}; };
@@ -95,17 +87,12 @@ namespace ehs
{ {
} }
IP BaseICMP::GetVersion() const
{
return version;
}
bool BaseICMP::IsValid() const bool BaseICMP::IsValid() const
{ {
return false; return false;
} }
UInt_16 BaseICMP::ComputeChecksumV4(UInt_16 *buffer, Size length) UInt_16 BaseICMP::ComputeChecksum(UInt_16 *buffer, Size length)
{ {
Size sum = 0; Size sum = 0;
while (length > 1) while (length > 1)
@@ -122,24 +109,4 @@ namespace ehs
return (UInt_16)~sum; return (UInt_16)~sum;
} }
UInt_64 BaseICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
return 0;
}
UInt_64 BaseICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
return 0;
}
UInt_64 BaseICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
return 0;
}
UInt_64 BaseICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
return 0;
}
} }

View File

@@ -108,7 +108,7 @@ namespace ehs
if (!IsValid()) if (!IsValid())
return; return;
req.AddHeaderVar({"Host", remoteHostName}); req.AddToHeader("Host", remoteHostName);
SendStr(req.FormResult()); SendStr(req.FormResult());
} }
@@ -124,10 +124,10 @@ namespace ehs
Response response(header); Response response(header);
Str_8 encoding = response.GetHeaderValue("Transfer-Encoding"); Str_8 encoding = response.GetHeader("Transfer-Encoding");
if (!encoding.Size()) if (!encoding.Size())
{ {
int bodySize = response.GetHeaderValue("content-length").ToDecimal<int>(); int bodySize = response.GetHeader("content-length").ToDecimal<int>();
if (!bodySize) if (!bodySize)
return response; return response;
@@ -163,10 +163,10 @@ namespace ehs
if (request.GetVerb() == Verb::GET) if (request.GetVerb() == Verb::GET)
return request; return request;
Str_8 encoding = request.GetHeaderValue("Transfer-Encoding"); Str_8 encoding = request.GetHeader("Transfer-Encoding");
if (!encoding.Size()) if (!encoding.Size())
{ {
int bodySize = request.GetHeaderValue("Content-Length").ToDecimal<int>(); int bodySize = request.GetHeader("Content-Length").ToDecimal<int>();
if (!bodySize) if (!bodySize)
return request; return request;

View File

@@ -1,96 +0,0 @@
#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;
}
}

View File

@@ -5,30 +5,18 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h> #include <netinet/ip.h>
#include <ifaddrs.h>
#include <unistd.h>
namespace ehs namespace ehs
{ {
ICMP::~ICMP()
{
if (close(hdl) == -1)
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
}
ICMP::ICMP() ICMP::ICMP()
: hdl(EHS_INVALID_SOCKET), src{} : hdl(EHS_INVALID_SOCKET)
{ {
} }
ICMP::ICMP(const IP version) ICMP::ICMP(const IP version)
: BaseICMP(version), src{} : BaseICMP(version)
{ {
if (version == IP::V6)
hdl = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
else
hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (hdl < 0) if (hdl < 0)
{ {
EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + ".");
@@ -39,14 +27,13 @@ namespace ehs
} }
ICMP::ICMP(ICMP &&icmp) noexcept ICMP::ICMP(ICMP &&icmp) noexcept
: BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl), src(icmp.src) : BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl)
{ {
icmp.hdl = EHS_INVALID_SOCKET; icmp.hdl = EHS_INVALID_SOCKET;
icmp.src = {};
} }
ICMP::ICMP(const ICMP &icmp) ICMP::ICMP(const ICMP &icmp)
: BaseICMP(icmp), hdl(icmp.hdl), src{} : BaseICMP(icmp), hdl(icmp.hdl)
{ {
} }
@@ -58,10 +45,8 @@ namespace ehs
BaseICMP::operator=((BaseICMP &&)icmp); BaseICMP::operator=((BaseICMP &&)icmp);
hdl = icmp.hdl; hdl = icmp.hdl;
src = icmp.src;
icmp.hdl = EHS_INVALID_SOCKET; icmp.hdl = EHS_INVALID_SOCKET;
icmp.src = {};
return *this; return *this;
} }
@@ -74,136 +59,11 @@ namespace ehs
BaseICMP::operator=(icmp); BaseICMP::operator=(icmp);
hdl = icmp.hdl; hdl = icmp.hdl;
src = {};
return *this; return *this;
} }
void ICMP::Release() UInt_64 ICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, const UInt_64 size)
{
if (close(hdl) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
return;
}
hdl = EHS_INVALID_SOCKET;
EHS_LOG_SUCCESS();
}
void ICMP::SetReceiveTimeout(const UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, &result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
bool ICMP::IsLinkLocal(const in6_addr &addr)
{
return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0x80;
}
sockaddr_in6 ICMP::RetrieveSrcAddress()
{
ifaddrs *ifaddr;
sockaddr_in6 addr = {};
if (getifaddrs(&ifaddr) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve public address with error #" + Str_8::FromNum(errno) + ".");
return addr;
}
for (ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr == nullptr || ifa->ifa_addr->sa_family != AF_INET6)
continue;
addr = *(sockaddr_in6 *)ifa->ifa_addr;
if (!addr.sin6_addr.s6_addr32[0] || IsLinkLocal(addr.sin6_addr))
continue;
break;
}
freeifaddrs(ifaddr);
EHS_LOG_SUCCESS();
return addr;
}
UInt_32 ICMP::CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header)
{
UInt_32 checksum = 0;
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.src.sin6_addr.s6_addr[i];
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.dst.sin6_addr.s6_addr[i];
checksum += 58;
checksum += htons(header.length);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
return checksum;
}
UInt_16 ICMP::ComputeChecksumV6(UInt_16 *buffer, Size length, const sockaddr_in6 &dst)
{
UInt_32 checksum = 0;
if (!src.sin6_addr.s6_addr32[0])
{
src = RetrieveSrcAddress();
if (!src.sin6_addr.s6_addr32[0])
{
EHS_LOG_INT(LogType::ERR, 0, "Could not retrieve a suitable global address.");
return checksum;
}
}
checksum += CalculatePseudoHeaderChecksum({src, dst, (UInt_32)length});
while (length > 1)
{
checksum += *buffer++;
length -= sizeof(UInt_16);
}
if (length == 1)
checksum += *(UInt_8 *)buffer;
// Carry over any overflow from the 16-bit result
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
// Return the 16-bit complement
return ~checksum;
}
UInt_64 ICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{ {
if (!IsValid()) if (!IsValid())
{ {
@@ -222,17 +82,17 @@ namespace ehs
payload.SetOffset(payload.GetOffset() + size); payload.SetOffset(payload.GetOffset() + size);
sockaddr_in6 dst = {}; header.checksum = ComputeChecksum((UInt_16 *)&payload[0], payload.Size());
dst.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &(dst.sin6_addr));
header.checksum = ComputeChecksumV6((UInt_16 *)&payload[0], payload.Size(), dst);
payload.SetOffset(0); payload.SetOffset(0);
payload.Write(header); payload.Write(header);
payload.SetOffset(payload.Size()); payload.SetOffset(payload.Size());
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in6)); sockaddr_in dst_addr = {};
dst_addr.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst_addr.sin_addr));
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst_addr, sizeof(dst_addr));
if (sent < 0) if (sent < 0)
{ {
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
@@ -245,96 +105,7 @@ namespace ehs
return sent; return sent;
} }
UInt_64 ICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) UInt_64 ICMP::Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
header.checksum = ComputeChecksumV4((UInt_16 *)&payload[0], payload.Size());
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
sockaddr_in dst = {};
dst.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst.sin_addr));
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in6 remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, payload, 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET6_ADDRSTRLEN];
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
UInt_64 ICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{ {
if (!IsValid()) if (!IsValid())
{ {
@@ -381,4 +152,25 @@ namespace ehs
return recv; return recv;
} }
void ICMP::SetReceiveTimeout(UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, &result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
} }

View File

@@ -1,391 +0,0 @@
#include "ehs/io/socket/ICMP_W32.h"
struct iphdr
{
u_char ip_hl:4, ip_v:4;
u_char ip_tos;
u_short ip_len;
u_short ip_id;
u_short ip_off;
u_char ip_ttl;
u_char ip_p;
u_short ip_sum;
in_addr ip_src, ip_dst;
};
namespace ehs
{
ICMP::~ICMP()
{
if (closesocket(hdl) == -1)
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
}
ICMP::ICMP()
: hdl(EHS_INVALID_SOCKET)
{
}
ICMP::ICMP(const IP version)
: BaseICMP(version)
{
hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (hdl < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
ICMP::ICMP(ICMP &&icmp) noexcept
: BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl)
{
icmp.hdl = EHS_INVALID_SOCKET;
}
ICMP::ICMP(const ICMP &icmp)
: BaseICMP(icmp), hdl(icmp.hdl)
{
}
ICMP & ICMP::operator=(ICMP &&icmp) noexcept
{
if (this == &icmp)
return *this;
BaseICMP::operator=((BaseICMP &&)icmp);
hdl = icmp.hdl;
icmp.hdl = EHS_INVALID_SOCKET;
return *this;
}
ICMP & ICMP::operator=(const ICMP &icmp)
{
if (this == &icmp)
return *this;
BaseICMP::operator=(icmp);
hdl = icmp.hdl;
return *this;
}
void ICMP::Release()
{
if (closesocket(hdl) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
return;
}
hdl = EHS_INVALID_SOCKET;
EHS_LOG_SUCCESS();
}
void ICMP::SetReceiveTimeout(UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, (const char *)&result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
bool ICMP::IsLinkLocal(const in6_addr &addr)
{
return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0x80;
}
sockaddr_in6 ICMP::RetrieveSrcAddress()
{
sockaddr_in6 addr = {};
UInt_32 outBufLen = 15000;
Array<Byte> buffer(outBufLen);
PIP_ADAPTER_ADDRESSES pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)&buffer[0];
if (GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAdapterAddresses, (PULONG)&outBufLen) == ERROR_BUFFER_OVERFLOW)
{
buffer.Resize(outBufLen);
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)&buffer[0];
}
if (GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAdapterAddresses, (PULONG)&outBufLen) == NO_ERROR)
{
for (PIP_ADAPTER_ADDRESSES adapter = pAdapterAddresses; adapter != nullptr; adapter = adapter->Next)
{
for (PIP_ADAPTER_UNICAST_ADDRESS addrInfo = adapter->FirstUnicastAddress; addrInfo != nullptr; addrInfo = addrInfo->Next)
{
SOCKADDR *sa = addrInfo->Address.lpSockaddr;
if (sa->sa_family != AF_INET6)
continue;
sockaddr_in6 *ipv6Addr = (sockaddr_in6 *)sa;
// Skip link-local addresses
if (IN6_IS_ADDR_LINKLOCAL(&ipv6Addr->sin6_addr))
continue;
addr = *ipv6Addr;
return addr; // Return the first suitable address
}
}
}
EHS_LOG_SUCCESS();
return addr; // Return an empty sockaddr_in6 if no valid address was found
}
UInt_32 ICMP::CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header)
{
UInt_32 checksum = 0;
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.src.sin6_addr.s6_addr[i];
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.dst.sin6_addr.s6_addr[i];
checksum += 58;
checksum += htons(header.length);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
return checksum;
}
UInt_16 ICMP::ComputeChecksumV6(UInt_16 *buffer, Size length, const sockaddr_in6 &dst)
{
UInt_32 checksum = 0;
if (!src.sin6_addr.u.Word[0])
{
src = RetrieveSrcAddress();
if (!src.sin6_addr.u.Word[0])
{
EHS_LOG_INT(LogType::ERR, 0, "Could not retrieve a suitable global address.");
return checksum;
}
}
checksum += CalculatePseudoHeaderChecksum({src, dst, (UInt_32)length});
while (length > 1)
{
checksum += *buffer++;
length -= sizeof(UInt_16);
}
if (length == 1)
checksum += *(UInt_8 *)buffer;
// Carry over any overflow from the 16-bit result
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
// Return the 16-bit complement
return ~checksum;
}
UInt_64 ICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
sockaddr_in6 dst = {};
dst.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &(dst.sin6_addr));
header.checksum = ComputeChecksumV6((UInt_16 *)&payload[0], payload.Size(), dst);
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
SInt_64 sent = sendto(hdl, (const char *)&payload[0], payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in6));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
header.checksum = ComputeChecksumV4((UInt_16 *)&payload[0], payload.Size());
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
sockaddr_in dst_addr = {};
dst_addr.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst_addr.sin_addr));
SInt_64 sent = sendto(hdl, (const char *)&payload[0], payload.Size(), 0, (sockaddr *)&dst_addr, sizeof(dst_addr));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in6 remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, (char *)&payload[0], 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET6_ADDRSTRLEN];
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
UInt_64 ICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, (char *)&payload[0], 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET_ADDRSTRLEN];
if (!inet_ntop(remote.sin_family, &remote.sin_addr, tmpAddr, INET_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
iphdr ipHeader = payload.Read<iphdr>();
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
}

View File

@@ -1,96 +0,0 @@
#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;
}
}

View File

@@ -4,16 +4,16 @@
namespace ehs namespace ehs
{ {
Request::Request() Request::Request()
: verb(Verb::POST), cType(ContentType::NONE) : verb(Verb::GET), cType(ContentType::NONE)
{ {
} }
Request::Request(const Verb &verb, Str_8 rsrc) Request::Request(const Verb verb, const Str_8& rsrc)
: verb(verb), rsrc((Str_8 &&)rsrc), cType(ContentType::NONE) : verb(verb), rsrc(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) : verb(Verb::POST), cType(ContentType::NONE)
{ {
ReadData(Str_8(data, size)); ReadData(Str_8(data, size));
@@ -25,49 +25,17 @@ namespace ehs
ReadData(data); ReadData(data);
} }
Request::Request(Request&& other) noexcept Request& Request::operator=(const Request &req)
: 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; if (this == &req)
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; return *this;
verb = other.verb; verb = req.verb;
rsrc = (Str_8 &&)other.rsrc; rsrc = req.rsrc;
queries = (Vector<QueryVar> &&)other.queries; queries = req.queries;
header = (Vector<HeaderVar> &&)other.header; header = req.header;
cType = other.cType; cType = req.cType;
body = (Str_8 &&)other.body; body = req.body;
other.verb = Verb::POST;
other.cType = ContentType::NONE;
return* this;
}
Request& Request::operator=(const Request &other)
{
if (this == &other)
return *this;
verb = other.verb;
rsrc = other.rsrc;
queries = other.queries;
header = other.header;
cType = other.cType;
body = other.body;
return* this; return* this;
} }
@@ -77,7 +45,7 @@ namespace ehs
return verb; return verb;
} }
void Request::SetContentType(const ContentType &cType) void Request::SetContentType(const ContentType cType)
{ {
if (body.Size()) if (body.Size())
body.Resize(0); body.Resize(0);
@@ -90,9 +58,9 @@ namespace ehs
return cType; return cType;
} }
void Request::SetResource(Str_8 rsrc) void Request::SetResource(const Str_8& rsrc)
{ {
this->rsrc = (Str_8 &&)rsrc; this->rsrc = rsrc;
} }
Str_8 Request::GetResource() const Str_8 Request::GetResource() const
@@ -100,179 +68,69 @@ namespace ehs
return rsrc; return rsrc;
} }
bool Request::HasQueryVar(const UInt_64& id) const void Request::AddQuery(const Str_8& var, const Str_8& value)
{ {
for (UInt_64 i = 0; i < queries.Size(); ++i) queries.Push(var + "=" + value);
if (queries[i] == id)
return true;
return false;
} }
bool Request::HasQueryVar(const Str_8& name) const Str_8 Request::GetQuery(const Str_8& var)
{
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) for (UInt_64 i = 0; i < queries.Size(); ++i)
{ {
if (queries[i] != id) Vector<Str_8> data = queries[i].Split("=");
continue;
queries.Swap(i, queries.End()); if (data[0] == var)
queries.Pop(); return data[1];
return true;
} }
return false; return "";
} }
bool Request::RemoveQueryVar(const Str_8& name) Vector<Str_8> Request::GetQueries() const
{
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; return queries;
} }
void Request::BasicAuth(const Str_8& id, const Str_8& secret) void Request::BasicAuth(const Str_8& id, const Str_8& secret)
{ {
AddHeaderVar({"Authorization", Str_8("Basic ") + Base64::Encode(id + ":" + secret)}); AddToHeader("Authorization", Str_8("Basic ") + Base64::Encode(id + ":" + secret));
} }
void Request::BearerAuth(const Str_8& token) void Request::BearerAuth(const Str_8& token)
{ {
AddHeaderVar({"Authorization", "Bearer " + token}); AddToHeader("Authorization", "Bearer " + token);
} }
void Request::BearerAuth(const Str_8& token, const Str_8& clientId) void Request::BearerAuth(const Str_8& token, const Str_8& clientId)
{ {
AddHeaderVar({"Authorization", "Bearer " + token}); AddToHeader("Authorization", "Bearer " + token);
AddHeaderVar({"Client-Id", clientId}); AddToHeader("Client-Id", clientId);
} }
void Request::BotAuth(const Str_8& token) void Request::BotAuth(const Str_8& token)
{ {
AddHeaderVar({"Authorization", "Bot " + token}); AddToHeader("Authorization", "Bot " + token);
} }
bool Request::HasHeaderVar(const UInt_64& id) const void Request::AddToHeader(const Str_8& var, const Str_8& value)
{ {
for (UInt_64 i = 0; i < header.Size(); ++i) header.Push(var + ": " + value);
if (header[i] == id)
return true;
return false;
} }
bool Request::HasHeaderVar(const Str_8& name) const Str_8 Request::GetHeader(const Str_8& var) 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) for (UInt_64 i = 0; i < header.Size(); ++i)
{ {
if (header[i] != id) Vector<Str_8> data = header[i].Split(": ");
continue;
header.Swap(i, header.End()); if (data[0] == var)
header.Pop(); return data[1];
return true;
} }
return false; return "";
} }
bool Request::RemoveHeaderVar(const Str_8 &name) Vector<Str_8> Request::GetHeader() const
{
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; return header;
} }
@@ -342,20 +200,16 @@ namespace ehs
Str_8 result = VerbToStr(verb) + " " + rsrc; Str_8 result = VerbToStr(verb) + " " + rsrc;
if (queries.Size()) if (queries.Size())
result += "?" + queries[0].ToStr(); result += "?" + queries[0];
for (UInt_64 i = 1; i < queries.Size(); ++i) for (UInt_64 i = 1; i < queries.Size(); ++i)
result += "&" + queries[i].ToStr(); result += "&" + queries[i];
result += " HTTP/1.1\r\n"; result += " HTTP/1.1\r\n";
for (UInt_64 i = 0; i < header.Size(); ++i) for (UInt_64 i = 0; i < header.Size(); ++i)
{ {
if (header[i] == 11245195881701120957ull || header[i] == 6556302699635904946ull || result += header[i] + "\r\n";
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"; result += "Content-Type: " + ContentTypeToStr(cType) + "\r\n";
@@ -373,7 +227,7 @@ namespace ehs
return rsrc.Size() || queries.Size() || header.Size() || body.Size(); 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) switch (verb)
{ {
@@ -390,7 +244,7 @@ namespace ehs
} }
} }
Str_8 Request::ContentTypeToStr(const ContentType &cType) Str_8 Request::ContentTypeToStr(const ContentType cType)
{ {
switch (cType) switch (cType)
{ {
@@ -408,12 +262,8 @@ namespace ehs
return "text/plain"; return "text/plain";
case ContentType::TEXT_HTML: case ContentType::TEXT_HTML:
return "text/html"; return "text/html";
case ContentType::TEXT_CSS:
return "text/css";
case ContentType::TEXT_XML: case ContentType::TEXT_XML:
return "text/xml"; return "text/xml";
case ContentType::IMG_X_ICON:
return "image/x-icon";
default: default:
return ""; return "";
} }
@@ -435,12 +285,8 @@ namespace ehs
return ContentType::TEXT_PLAIN; return ContentType::TEXT_PLAIN;
else if (value == "text/html") else if (value == "text/html")
return ContentType::TEXT_HTML; return ContentType::TEXT_HTML;
else if (value == "text/css")
return ContentType::TEXT_CSS;
else if (value == "text/xml") else if (value == "text/xml")
return ContentType::TEXT_XML; return ContentType::TEXT_XML;
else if (value == "image/x-icon")
return ContentType::IMG_X_ICON;
else else
return ContentType::NONE; return ContentType::NONE;
} }
@@ -462,14 +308,7 @@ namespace ehs
{ {
rsrc = meta[1].Sub(0, queryIndex); rsrc = meta[1].Sub(0, queryIndex);
cType = ContentType::APP_FORMURLENCODED; 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 else
{ {
@@ -492,9 +331,7 @@ namespace ehs
if (var[0] == "Content-Length") if (var[0] == "Content-Length")
continue; continue;
Vector<Str_8> headerVar = lines[i].Split(": "); header.Push(lines[i]);
header.Push({headerVar[0], headerVar[1]});
} }
} }
} }

View File

@@ -2,17 +2,12 @@
namespace ehs namespace ehs
{ {
Response::Response() Response::Response(const UInt_32 code, const Str_8& server)
: code(0), cType(ContentType::NONE) : code(code), server(server), cType(ContentType::NONE)
{ {
} }
Response::Response(const UInt_32 &code, Str_8 server) Response::Response(const char* data, const UInt_64 size)
: code(code), server((Str_8 &&)server), cType(ContentType::NONE)
{
}
Response::Response(const char *data, const UInt_64 &size)
: code(0), cType(ContentType::NONE) : code(0), cType(ContentType::NONE)
{ {
ReadData(Str_8(data, size)); ReadData(Str_8(data, size));
@@ -24,51 +19,26 @@ namespace ehs
ReadData(data); ReadData(data);
} }
Response::Response(Response&& other) noexcept Response::Response()
: code(other.code), server((Str_8 &&)other.server), cType(other.cType), header((Vector<HeaderVar> &&)other.header), : code(0), cType(ContentType::NONE)
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 Response& Response::operator=(const Response& res)
{ {
if (this == &other) if (this == &res)
return *this; return *this;
code = other.code; code = res.code;
server = (Str_8 &&)other.server; server = res.server;
cType = other.cType; cType = res.cType;
header = (Vector<HeaderVar> &&)other.header; header = res.header;
body = (Str_8 &&)other.body; body = res.body;
other.code = 0;
other.cType = ContentType::NONE;
return *this; return *this;
} }
Response& Response::operator=(const Response& other) void Response::SetCode(const UInt_32 code)
{
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; this->code = code;
} }
@@ -78,9 +48,9 @@ namespace ehs
return code; return code;
} }
void Response::SetServer(Str_8 server) void Response::SetServer(const Str_8& server)
{ {
this->server = (Str_8 &&)server; this->server = server;
} }
Str_8 Response::GetServer() const Str_8 Response::GetServer() const
@@ -88,7 +58,7 @@ namespace ehs
return server; return server;
} }
void Response::SetContentType(const ContentType &cType) void Response::SetContentType(const ContentType cType)
{ {
this->cType = cType; this->cType = cType;
} }
@@ -98,80 +68,27 @@ namespace ehs
return cType; return cType;
} }
bool Response::HasHeaderVar(const UInt_64& id) const void Response::AddToHeader(const Str_8& var, const Str_8& value)
{ {
for (UInt_64 i = 0; i < header.Size(); ++i) header.Push(var + ": " + value);
if (header[i] == id)
return true;
return false;
} }
bool Response::HasHeaderVar(const Str_8& name) const Str_8 Response::GetHeader(const Str_8& var) const
{ {
return HasHeaderVar(name.Hash_64()); Str_8 lIdentity = var.GetLower();
}
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) for (UInt_64 i = 0; i < header.Size(); ++i)
{ {
if (header[i] != id) Vector<Str_8> data = header[i].Split(": ");
continue;
header.Swap(i, header.End()); if (data[0].GetLower() == lIdentity)
header.Pop(); return data[1];
return true;
} }
return false; return "";
} }
bool Response::RemoveHeaderVar(const Str_8& name) Vector<Str_8> Response::GetHeader() const
{
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; return header;
} }
@@ -242,11 +159,14 @@ namespace ehs
for (UInt_64 i = 0; i < header.Size(); ++i) for (UInt_64 i = 0; i < header.Size(); ++i)
{ {
if (header[i] == 11245195881701120957ull || header[i] == 6556302699635904946ull || if (header[i].Find("Content-Length", nullptr, SearchPattern::LEFT_RIGHT, IndexResult::ENDING))
header[i] == 13347276190653935221ull) // Content-Length, Server, and Content-Type in order from left to right. 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))
continue; continue;
result += header[i].ToStr() + "\r\n"; result += header[i] + "\r\n";
} }
result += "Content-Type: " + ContentTypeToStr(cType) + "\r\nContent-Length: " + Str_8::FromNum(body.Size()) + "\r\n\r\n" + body; result += "Content-Type: " + ContentTypeToStr(cType) + "\r\nContent-Length: " + Str_8::FromNum(body.Size()) + "\r\n\r\n" + body;
@@ -259,7 +179,7 @@ namespace ehs
return server.Size() || header.Size() || body.Size(); 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) if (code == 100)
return "Continue"; return "Continue";
@@ -403,7 +323,7 @@ namespace ehs
return "Unused Status Code"; return "Unused Status Code";
} }
Str_8 Response::ContentTypeToStr(const ContentType &cType) Str_8 Response::ContentTypeToStr(const ContentType cType)
{ {
switch (cType) switch (cType)
{ {
@@ -421,12 +341,8 @@ namespace ehs
return "text/plain"; return "text/plain";
case ContentType::TEXT_HTML: case ContentType::TEXT_HTML:
return "text/html"; return "text/html";
case ContentType::TEXT_CSS:
return "text/css";
case ContentType::TEXT_XML: case ContentType::TEXT_XML:
return "text/xml"; return "text/xml";
case ContentType::IMG_X_ICON:
return "image/x-icon";
default: default:
return ""; return "";
} }
@@ -448,12 +364,8 @@ namespace ehs
return ContentType::TEXT_PLAIN; return ContentType::TEXT_PLAIN;
else if (value == "text/html") else if (value == "text/html")
return ContentType::TEXT_HTML; return ContentType::TEXT_HTML;
else if (value == "text/css")
return ContentType::TEXT_CSS;
else if (value == "text/xml") else if (value == "text/xml")
return ContentType::TEXT_XML; return ContentType::TEXT_XML;
else if (value == "image/x-icon")
return ContentType::IMG_X_ICON;
else else
return ContentType::NONE; return ContentType::NONE;
} }
@@ -472,12 +384,12 @@ namespace ehs
Vector<Str_8> var = lines[i].Split(": "); Vector<Str_8> var = lines[i].Split(": ");
if (var[0] == "Server") if (var[0].GetLower() == "server")
{ {
server = var[1]; server = var[1];
continue; continue;
} }
else if (var[0] == "Content-Type") else if (var[0].GetLower() == "content-type")
{ {
Vector<Str_8> ctData = var[1].Split(";"); Vector<Str_8> ctData = var[1].Split(";");
@@ -485,9 +397,7 @@ namespace ehs
continue; continue;
} }
Vector<Str_8> headerVar = lines[i].Split(": "); header.Push(lines[i]);
header.Push({headerVar[0], headerVar[1]});
} }
} }
} }

View File

@@ -4,8 +4,6 @@
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/opensslv.h>
#include <openssl/provider.h>
namespace ehs namespace ehs
{ {
@@ -14,11 +12,6 @@ namespace ehs
if (!IsValid()) if (!IsValid())
return; return;
EVP_PKEY_free(pkey);
X509_free(cert);
if (sslHdl) if (sslHdl)
{ {
if (connection) if (connection)
@@ -32,28 +25,28 @@ namespace ehs
} }
SSL::SSL() SSL::SSL()
: server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr) : ctx(nullptr), sslHdl(nullptr)
{ {
} }
SSL::SSL(const IP &type, const bool &server) SSL::SSL(const IP type)
: TCP(type), server(server), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr) : TCP(type), ctx(nullptr), sslHdl(nullptr)
{ {
SSL::Initialize(); SSL::Initialize();
} }
SSL::SSL(TCP&& tcp) noexcept SSL::SSL(TCP&& tcp) noexcept
: TCP(std::move(tcp)), server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr) : TCP(std::move(tcp)), ctx(nullptr), sslHdl(nullptr)
{ {
} }
SSL::SSL(const TCP& tcp) SSL::SSL(const TCP& tcp)
: TCP(tcp), server(false), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr) : TCP(tcp), ctx(nullptr), sslHdl(nullptr)
{ {
} }
SSL::SSL(const SSL& ssl) SSL::SSL(const SSL& ssl)
: TCP(ssl), server(ssl.server), ctx(nullptr), sslHdl(nullptr), cert(nullptr), pkey(nullptr) : TCP(ssl), ctx(nullptr), sslHdl(nullptr)
{ {
} }
@@ -64,11 +57,8 @@ namespace ehs
TCP::operator=(ssl); TCP::operator=(ssl);
server = ssl.server;
ctx = nullptr; ctx = nullptr;
sslHdl = nullptr; sslHdl = nullptr;
cert = nullptr;
pkey = nullptr;
return *this; return *this;
} }
@@ -81,40 +71,6 @@ namespace ehs
return; return;
SSL_library_init(); 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() void SSL::Release()
@@ -124,12 +80,6 @@ namespace ehs
if (!IsValid()) if (!IsValid())
return; return;
EVP_PKEY_free(pkey);
pkey = nullptr;
X509_free(cert);
cert = nullptr;
if (sslHdl) if (sslHdl)
{ {
if (connection) if (connection)
@@ -147,14 +97,19 @@ namespace ehs
} }
} }
void SSL::Listen() void SSL::Bind(const Str_8& address, unsigned short port)
{ {
if (bound)
return;
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_server_method());
sslHdl = SSL_new(ctx); sslHdl = SSL_new(ctx);
SSL_set_fd(sslHdl, hdl); SSL_set_fd(sslHdl, hdl);
TCP::Listen(); TCP::Bind(address, port);
EHS_LOG_SUCCESS();
} }
SSL* SSL::Accept() SSL* SSL::Accept()
@@ -163,21 +118,13 @@ namespace ehs
return nullptr; return nullptr;
TCP* tcp = TCP::Accept(); TCP* tcp = TCP::Accept();
if (!tcp)
return nullptr;
SSL* client = new SSL(std::move(*tcp)); SSL* client = new SSL(std::move(*tcp));
delete tcp; delete tcp;
client->sslHdl = SSL_new(this->ctx); client->ctx = nullptr;
if (!client->sslHdl) client->sslHdl = SSL_new(ctx);
{
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); SSL_set_fd(client->sslHdl, client->hdl);
int err = SSL_accept(client->sslHdl); int err = SSL_accept(client->sslHdl);
@@ -187,29 +134,21 @@ namespace ehs
return {}; return {};
} }
EHS_LOG_SUCCESS();
return client; return client;
} }
void SSL::Connect(Str_8 address, const UInt_16 &port) void SSL::Connect(const Str_8& address, const UInt_16 port)
{ {
TCP::Connect(address, port); if (bound)
return;
TCP::Connect(address, port);
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_client_method());
sslHdl = SSL_new(ctx); sslHdl = SSL_new(ctx);
SSL_set_fd(sslHdl, hdl); SSL_set_fd(sslHdl, hdl);
SSL_connect(sslHdl);
SSL_set_tlsext_host_name(sslHdl, &address[0]);
SInt_32 rc = SSL_connect(sslHdl);
if (rc != 1)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to connect with error #" + Str_8::FromNum(SSL_get_error(sslHdl, rc)) + ".");
return;
}
EHS_LOG_SUCCESS();
} }
UInt_64 SSL::Send(const Byte* const buffer, const UInt_32 size) UInt_64 SSL::Send(const Byte* const buffer, const UInt_32 size)
@@ -218,12 +157,8 @@ namespace ehs
if (written <= 0) if (written <= 0)
{ {
int code = SSL_get_error(sslHdl, written); int code = SSL_get_error(sslHdl, written);
if (code != SSL_ERROR_WANT_WRITE)
{
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
EHS_LOG_INT(LogType::ERR, 0, "Failed to send data with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to send data with error #" + Str_8::FromNum(code) + ".");
}
return 0; return 0;
} }
@@ -236,46 +171,48 @@ namespace ehs
if (received <= 0) if (received <= 0)
{ {
int code = SSL_get_error(sslHdl, received); int code = SSL_get_error(sslHdl, received);
if (code != SSL_ERROR_WANT_READ)
{
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to receive data with error #" + Str_8::FromNum(code) + ".");
}
return 0; return 0;
} }
return received; return received;
} }
void SSL::UseCertificate(const Char_8* data, const UInt_32 &size) void SSL::UseCertificate(const Byte* data, const UInt_64 size)
{ {
BIO* certBio = BIO_new_mem_buf(data, (int)size); X509 *cert = d2i_X509(nullptr, &data, (long)size);
X509 *cert = PEM_read_bio_X509(certBio, nullptr, nullptr, nullptr); if (!cert)
if (!SSL_CTX_use_certificate(ctx, cert))
{ {
UInt_32 code = ERR_get_error(); EHS_LOG_INT(LogType::ERR, 0, "Invalid certificate.");
EHS_LOG_INT(LogType::ERR, 0, ERR_error_string(code, nullptr));
return; return;
} }
BIO_free(certBio); if (SSL_CTX_use_certificate(ctx, cert) != 1)
}
void SSL::UsePrivateKey(const Char_8* data, const UInt_32 &size)
{ {
BIO* keyBio = BIO_new_mem_buf(data, (int)size); EHS_LOG_INT(LogType::ERR, 1, "Failed to use certificate.");
EVP_PKEY* pkey = PEM_read_bio_PrivateKey(keyBio, nullptr, nullptr, nullptr);
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; return;
} }
BIO_free(keyBio); X509_free(cert);
}
void SSL::UsePrivateKey(const Byte* data, const UInt_64 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;
}
if (SSL_CTX_use_PrivateKey(ctx, key) != 1)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to use private key.");
return;
}
EVP_PKEY_free(key);
} }
bool SSL::IsValid() bool SSL::IsValid()

View File

@@ -114,7 +114,7 @@ namespace ehs
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
} }
void TCP::Bind(Str_8 address, const UInt_16 &port) void TCP::Bind(const Str_8& address, UInt_16 port)
{ {
if (!IsValid() || bound || connection) if (!IsValid() || bound || connection)
return; return;
@@ -124,7 +124,7 @@ namespace ehs
else if (ip == IP::V4) else if (ip == IP::V4)
Bind_v4(address, port); Bind_v4(address, port);
this->localAddr = (Str_8 &&)address; this->localAddr = address;
this->localPort = port; this->localPort = port;
bound = true; bound = true;
@@ -207,26 +207,26 @@ namespace ehs
return client; return client;
} }
void TCP::Connect(Str_8 address, const UInt_16 &port) void TCP::Connect(const Str_8& address, const UInt_16 port)
{ {
if (connection || !IsValid() || listening) if (connection || !IsValid() || listening)
return; return;
remoteHostName = (Str_8 &&)address; remoteHostName = address;
remotePort = port; remotePort = port;
if (ip == IP::V6) if (ip == IP::V6)
{ {
if (IsIPv6Only()) if (IsIPv6Only())
remoteAddr = DNS::Resolve(IP::V6, remoteHostName); remoteAddr = DNS::Resolve(IP::V6, address);
else else
remoteAddr = DNS::Resolve(remoteHostName); remoteAddr = DNS::Resolve(address);
Connect_v6(remoteAddr, port); Connect_v6(remoteAddr, port);
} }
else if (ip == IP::V4) else if (ip == IP::V4)
{ {
remoteAddr = DNS::Resolve(IP::V4, remoteHostName); remoteAddr = DNS::Resolve(IP::V4, address);
Connect_v4(remoteAddr, port); Connect_v4(remoteAddr, port);
} }
@@ -385,30 +385,12 @@ namespace ehs
return result; 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 bool TCP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;
} }
void TCP::Bind_v6(const Str_8& address, const UInt_16 &port) const void TCP::Bind_v6(const Str_8& address, UInt_16 port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@@ -444,7 +426,7 @@ namespace ehs
} }
} }
void TCP::Bind_v4(const Str_8& address, const UInt_16 &port) const void TCP::Bind_v4(const Str_8& address, UInt_16 port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;
@@ -479,7 +461,7 @@ namespace ehs
} }
} }
void TCP::Connect_v6(const Str_8 &address, const UInt_16 &port) void TCP::Connect_v6(const Str_8& address, UInt_16 port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@@ -516,7 +498,7 @@ namespace ehs
} }
} }
void TCP::Connect_v4(const Str_8 &address, const UInt_16 &port) void TCP::Connect_v4(const Str_8& address, UInt_16 port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;

View File

@@ -137,7 +137,7 @@ namespace ehs
connected = false; connected = false;
} }
void TCP::Bind(Str_8 address, const UInt_16 &port) void TCP::Bind(const Str_8& address, UInt_16 port)
{ {
if (!IsValid() || bound || connection) if (!IsValid() || bound || connection)
return; return;
@@ -147,7 +147,7 @@ namespace ehs
else if (ip == IP::V4) else if (ip == IP::V4)
Bind_v4(address, port); Bind_v4(address, port);
this->localAddr = (Str_8 &&)address; this->localAddr = address;
this->localPort = port; this->localPort = port;
bound = true; bound = true;
@@ -236,26 +236,26 @@ namespace ehs
return client; return client;
} }
void TCP::Connect(Str_8 address, const UInt_16 &port) void TCP::Connect(const Str_8& address, const UInt_16 port)
{ {
if (connection || !IsValid() || listening) if (connection || !IsValid() || listening)
return; return;
remoteHostName = (Str_8 &&)address; remoteHostName = address;
remotePort = port; remotePort = port;
if (ip == IP::V6) if (ip == IP::V6)
{ {
if (IsIPv6Only()) if (IsIPv6Only())
remoteAddr = DNS::Resolve(IP::V6, remoteHostName); remoteAddr = DNS::Resolve(IP::V6, address);
else else
remoteAddr = DNS::Resolve(remoteHostName); remoteAddr = DNS::Resolve(address);
Connect_v6(remoteAddr, port); Connect_v6(remoteAddr, port);
} }
else if (ip == IP::V4) else if (ip == IP::V4)
{ {
remoteAddr = DNS::Resolve(IP::V4, remoteHostName); remoteAddr = DNS::Resolve(IP::V4, address);
Connect_v4(remoteAddr, port); Connect_v4(remoteAddr, port);
} }
@@ -406,10 +406,6 @@ namespace ehs
return result; return result;
} }
void TCP::SetReuse(const bool &value)
{
}
bool TCP::IsValid() const bool TCP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;

View File

@@ -81,7 +81,7 @@ namespace ehs
authReq.SetContentType(ContentType::APP_FORMURLENCODED); authReq.SetContentType(ContentType::APP_FORMURLENCODED);
authReq.BasicAuth(clientId, secret); authReq.BasicAuth(clientId, secret);
authReq.AddToBody("grant_type", "authorization_code"); authReq.AddToBody("grant_type", "authorization_code");
authReq.AddToBody("code", cbReq.GetQueryValue("code")); authReq.AddToBody("code", cbReq.GetQuery("code"));
authReq.AddToBody("redirect_uri", rURI); authReq.AddToBody("redirect_uri", rURI);
accounts.SendReq(authReq); accounts.SendReq(authReq);
@@ -134,7 +134,7 @@ namespace ehs
StartConnection(); StartConnection();
Request req(Verb::PUT, "/v1/me/player/volume"); Request req(Verb::PUT, "/v1/me/player/volume");
req.AddQueryVar({"volume_percent", Str_8::FromNum(level)}); req.AddQuery("volume_percent", Str_8::FromNum(level));
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -206,7 +206,7 @@ namespace ehs
} }
Request req(Verb::PUT, "/v1/me/player/repeat"); Request req(Verb::PUT, "/v1/me/player/repeat");
req.AddQueryVar({"state", result}); req.AddQuery("state", result);
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -226,7 +226,7 @@ namespace ehs
StartConnection(); StartConnection();
Request req(Verb::PUT, "/v1/me/player/repeat"); Request req(Verb::PUT, "/v1/me/player/repeat");
req.AddQueryVar({"state", state ? "true" : "false"}); req.AddQuery("state", state ? "true" : "false");
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -258,10 +258,10 @@ namespace ehs
q += "+track%3A" + name.ReplaceAll(" ", "+"); q += "+track%3A" + name.ReplaceAll(" ", "+");
req.AddQueryVar({"q", q}); req.AddQuery("q", q);
req.AddQueryVar({"type", "track"}); req.AddQuery("type", "track");
req.AddQueryVar({"limit", "1"}); req.AddQuery("limit", "1");
req.AddQueryVar({"offset", "0"}); req.AddQuery("offset", "0");
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -454,7 +454,7 @@ namespace ehs
StartConnection(); StartConnection();
Request req(Verb::POST, "/v1/me/player/queue"); Request req(Verb::POST, "/v1/me/player/queue");
req.AddQueryVar({"uri", "spotify:track:" + id}); req.AddQuery("uri", "spotify:track:" + id);
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -505,8 +505,8 @@ namespace ehs
StartConnection(); StartConnection();
Request req(Verb::POST, "/v1/playlists/" + playlistId + "/tracks"); Request req(Verb::POST, "/v1/playlists/" + playlistId + "/tracks");
req.AddQueryVar({"position", Str_8::FromNum(pos)}); req.AddQuery("position", Str_8::FromNum(pos));
req.AddQueryVar({"uris", "spotify:track:" + trackId}); req.AddQuery("uris", "spotify:track:" + trackId);
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);
@@ -564,7 +564,7 @@ namespace ehs
StartConnection(); StartConnection();
Request req(Verb::PUT, "/v1/me/player/seek"); Request req(Verb::PUT, "/v1/me/player/seek");
req.AddQueryVar({"position_ms", Str_8::FromNum(pos)}); req.AddQuery("position_ms", Str_8::FromNum(pos));
req.BearerAuth(token); req.BearerAuth(token);
client.SendReq(req); client.SendReq(req);

View File

@@ -78,7 +78,7 @@ namespace ehs
authReq.SetContentType(ContentType::APP_FORMURLENCODED); authReq.SetContentType(ContentType::APP_FORMURLENCODED);
authReq.AddToBody("client_id", clientId); authReq.AddToBody("client_id", clientId);
authReq.AddToBody("client_secret", secret); authReq.AddToBody("client_secret", secret);
authReq.AddToBody("code", cbReq.GetQueryValue("code")); authReq.AddToBody("code", cbReq.GetQuery("code"));
authReq.AddToBody("grant_type", "authorization_code"); authReq.AddToBody("grant_type", "authorization_code");
authReq.AddToBody("redirect_uri", redURI); authReq.AddToBody("redirect_uri", redURI);

View File

@@ -1,24 +0,0 @@
#include "ehs/system/AVX2.h"
namespace ehs
{
bool AVX2::CompareUnaligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX2::CompareUnaligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
bool AVX2::CompareAligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX2::CompareAligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
}

View File

@@ -1,49 +0,0 @@
global _ZN3ehs4AVX216CompareUnalignedEPKmS2_
global _ZN3ehs4AVX216CompareUnalignedEPKlS2_
global _ZN3ehs4AVX214CompareAlignedEPKmS2_
global _ZN3ehs4AVX214CompareAlignedEPKlS2_
section .text
_ZN3ehs4AVX216CompareUnalignedEPKmS2_:
VMOVDQU YMM0, [RDI]
VMOVDQU YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX216CompareUnalignedEPKlS2_:
VMOVDQU YMM0, [RDI]
VMOVDQU YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX214CompareAlignedEPKmS2_:
VMOVDQA YMM0, [RDI]
VMOVDQA YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX214CompareAlignedEPKlS2_:
VMOVDQA YMM0, [RDI]
VMOVDQA YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET

View File

@@ -1,49 +0,0 @@
global ?CompareUnaligned@AVX2@ehs@@SA_NPEBK0@Z
global ?CompareUnaligned@AVX2@ehs@@SA_NPEBJ0@Z
global ?CompareAligned@AVX2@ehs@@SA_NPEBK0@Z
global ?CompareAligned@AVX2@ehs@@SA_NPEBJ0@Z
section .text
?CompareUnaligned@AVX2@ehs@@SA_NPEBK0@Z:
VMOVDQU YMM0, [RCX]
VMOVDQU YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareUnaligned@AVX2@ehs@@SA_NPEBJ0@Z:
VMOVDQU YMM0, [RCX]
VMOVDQU YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareAligned@AVX2@ehs@@SA_NPEBK0@Z:
VMOVDQA YMM0, [RCX]
VMOVDQA YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareAligned@AVX2@ehs@@SA_NPEBJ0@Z:
VMOVDQA YMM0, [RCX]
VMOVDQA YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET

View File

@@ -1,24 +0,0 @@
#include "ehs/system/AVX512.h"
namespace ehs
{
bool AVX512::CompareUnaligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX512::CompareUnaligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
bool AVX512::CompareAligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX512::CompareAligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
}

View File

@@ -1,49 +0,0 @@
global _ZN3ehs6AVX51216CompareUnalignedEPKmS2_
global _ZN3ehs6AVX51216CompareUnalignedEPKlS2_
global _ZN3ehs6AVX51214CompareAlignedEPKmS2_
global _ZN3ehs6AVX51214CompareAlignedEPKlS2_
section .text
_ZN3ehs6AVX51216CompareUnalignedEPKmS2_:
VMOVDQU64 ZMM0, [RDI]
VMOVDQU64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51216CompareUnalignedEPKlS2_:
VMOVDQU64 ZMM0, [RDI]
VMOVDQU64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51214CompareAlignedEPKmS2_:
VMOVDQA64 ZMM0, [RDI]
VMOVDQA64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51214CompareAlignedEPKlS2_:
VMOVDQA64 ZMM0, [RDI]
VMOVDQA64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET

View File

@@ -1,49 +0,0 @@
global ?CompareUnaligned@AVX512@ehs@@SA_NPEBK0@Z
global ?CompareUnaligned@AVX512@ehs@@SA_NPEBJ0@Z
global ?CompareAligned@AVX512@ehs@@SA_NPEBK0@Z
global ?CompareAligned@AVX512@ehs@@SA_NPEBJ0@Z
section .text
?CompareUnaligned@AVX512@ehs@@SA_NPEBK0@Z:
VMOVDQU64 ZMM0, [RCX]
VMOVDQU64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareUnaligned@AVX512@ehs@@SA_NPEBJ0@Z:
VMOVDQU64 ZMM0, [RCX]
VMOVDQU64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareAligned@AVX512@ehs@@SA_NPEBK0@Z:
VMOVDQA64 ZMM0, [RCX]
VMOVDQA64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareAligned@AVX512@ehs@@SA_NPEBJ0@Z:
VMOVDQA64 ZMM0, [RCX]
VMOVDQA64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET

View File

@@ -2,7 +2,7 @@
namespace ehs namespace ehs
{ {
void BaseSystem::OpenURI(Str_8 uri) void BaseSystem::OpenURI(const Str_8& uri)
{ {
} }

View File

@@ -10,75 +10,11 @@ namespace ehs
UInt_64 CPU::TSC_Freq = 0; UInt_64 CPU::TSC_Freq = 0;
#endif #endif
const bool CPU::hasFPU = RetrieveFPU();
const bool CPU::hasVME = RetrieveVME();
const bool CPU::hasDE = RetrieveDE();
const bool CPU::hasPSE = RetrievePSE();
const bool CPU::hasTSC = RetrieveTSC();
const bool CPU::hasMSR = RetrieveMSR();
const bool CPU::hasPAE = RetrievePAE();
const bool CPU::hasMCE = RetrieveMCE();
const bool CPU::hasCX8 = RetrieveCX8();
const bool CPU::hasAPIC = RetrieveAPIC();
const bool CPU::hasSEP = RetrieveSEP();
const bool CPU::hasMTRR = RetrieveMTRR();
const bool CPU::hasPGE = RetrievePGE();
const bool CPU::hasMCA = RetrieveMCA();
const bool CPU::hasCMOV = RetrieveCMOV();
const bool CPU::hasPSE_36 = RetrievePSE_36();
const bool CPU::hasPSN = RetrievePSN();
const bool CPU::hasCLFSH = RetrieveCLFSH();
const bool CPU::hasDS = RetrieveDS();
const bool CPU::hasACPI = RetrieveACPI();
const bool CPU::hasMMX = RetrieveMMX();
const bool CPU::hasFXSR = RetrieveFXSR();
const bool CPU::hasSSE = RetrieveSSE();
const bool CPU::hasSSE2 = RetrieveSSE2();
const bool CPU::hasSS = RetrieveSS();
const bool CPU::hasHTT = RetrieveHTT();
const bool CPU::hasTM = RetrieveTM();
const bool CPU::hasIA64 = RetrieveIA64();
const bool CPU::hasPBE = RetrievePBE();
const bool CPU::hasSSE3 = RetrieveSSE3();
const bool CPU::hasPCLMULQDQ = RetrievePCLMULQDQ();
const bool CPU::hasDTES64 = RetrieveDTES64();
const bool CPU::hasMONITOR = RetrieveMONITOR();
const bool CPU::hasVMX = RetrieveVMX();
const bool CPU::hasSMX = RetrieveSMX();
const bool CPU::hasEST = RetrieveEST();
const bool CPU::hasTM2 = RetrieveTM2();
const bool CPU::hasSSSE3 = RetrieveSSSE3();
const bool CPU::hasCNXT_ID = RetrieveCNXT_ID();
const bool CPU::hasSDBG = RetrieveSDBG();
const bool CPU::hasFMA = RetrieveFMA();
const bool CPU::hasCX16 = RetrieveCX16();
const bool CPU::hasXTPR = RetrieveXTPR();
const bool CPU::hasPDCM = RetrievePDCM();
const bool CPU::hasPCID = RetrievePCID();
const bool CPU::hasDCA = RetrieveDCA();
const bool CPU::hasSSE4_1 = RetrieveSSE4_1();
const bool CPU::hasSSE4_2 = RetrieveSSE4_2();
const bool CPU::hasX2APIC = RetrieveX2APIC();
const bool CPU::hasMOVBE = RetrieveMOVBE();
const bool CPU::hasPOPCNT = RetrievePOPCNT();
const bool CPU::hasTSC_DEADLINE = RetrieveTSC_DEADLINE();
const bool CPU::hasAES = RetrieveAES();
const bool CPU::hasXSAVE = RetrieveXSAVE();
const bool CPU::hasOSXSAVE = RetrieveOSXSAVE();
const bool CPU::hasAVX = RetrieveAVX();
const bool CPU::hasF16C = RetrieveF16C();
const bool CPU::hasRDRND = RetrieveRDRND();
const bool CPU::hasHYPERVISOR = RetrieveHYPERVISOR();
const bool CPU::hasAVX2 = RetrieveAVX2();
const bool CPU::hasAVX512F = RetrieveAVX512F();
const bool CPU::hasRDSEED = RetrieveRDSEED();
const bool CPU::hasADX = RetrieveADX();
Architecture CPU::GetArchitecture() Architecture CPU::GetArchitecture()
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
return Architecture::X64; return Architecture::X64;
#elif defined(EHS_ARCH_AARCH64) #elif defined(EHS_ARCH_ARM64)
return Architecture::ARM64; return Architecture::ARM64;
#else #else
return Architecture::UNKNOWN; return Architecture::UNKNOWN;
@@ -113,19 +49,13 @@ namespace ehs
return frequency.QuadPart; return frequency.QuadPart;
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
#if defined(EHS_ARCH_X64)
if (!TSC_Freq) if (!TSC_Freq)
TSC_Freq = RetrieveTSC_Freq(); TSC_Freq = RetrieveTSC_Freq();
return TSC_Freq; return TSC_Freq;
#elif defined(EHS_ARCH_AARCH64)
return RetrieveFreq_AARCH64();
#else
return 0;
#endif #endif
#else
return 0; return 0;
#endif
} }
UInt_64 CPU::GetTSC() UInt_64 CPU::GetTSC()
@@ -139,7 +69,7 @@ namespace ehs
TSC tsc; TSC tsc;
RDTSCP(&tsc); RDTSCP(&tsc);
#if defined(EHS_ARCH_X64) || defined(EHS_ARCH_AARCH64) #if defined(EHS_ARCH_X64)
UInt_64 result = 0; UInt_64 result = 0;
#if defined(EHS_LITTLE_ENDIAN) #if defined(EHS_LITTLE_ENDIAN)
@@ -189,589 +119,324 @@ namespace ehs
return (UInt_8)(GetInfoBits() >> 20); return (UInt_8)(GetInfoBits() >> 20);
} }
bool CPU::RetrieveFPU() bool CPU::HasFPU()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000001; return GetFeatureBits_1() & 0b00000000000000000000000000000001;
#else
return false;
#endif
} }
bool CPU::RetrieveVME() bool CPU::HasVME()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000010; return GetFeatureBits_1() & 0b00000000000000000000000000000010;
#else
return false;
#endif
} }
bool CPU::RetrieveDE() bool CPU::HasDE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000100; return GetFeatureBits_1() & 0b00000000000000000000000000000100;
#else
return false;
#endif
} }
bool CPU::RetrievePSE() bool CPU::HasPSE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000001000; return GetFeatureBits_1() & 0b00000000000000000000000000001000;
#else
return false;
#endif
} }
bool CPU::RetrieveTSC() bool CPU::HasTSC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000010000; return GetFeatureBits_1() & 0b00000000000000000000000000010000;
#else
return false;
#endif
} }
bool CPU::RetrieveMSR() bool CPU::HasMSR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000100000; return GetFeatureBits_1() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrievePAE() bool CPU::HasPAE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000001000000; return GetFeatureBits_1() & 0b00000000000000000000000001000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMCE() bool CPU::HasMCE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000010000000; return GetFeatureBits_1() & 0b00000000000000000000000010000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCX8() bool CPU::HasCX8()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000100000000; return GetFeatureBits_1() & 0b00000000000000000000000100000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAPIC() bool CPU::HasAPIC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000001000000000; return GetFeatureBits_1() & 0b00000000000000000000001000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSEP() bool CPU::HasSEP()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000100000000000; return GetFeatureBits_1() & 0b00000000000000000000100000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMTRR() bool CPU::HasMTRR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000001000000000000; return GetFeatureBits_1() & 0b00000000000000000001000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePGE() bool CPU::HasPGE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000010000000000000; return GetFeatureBits_1() & 0b00000000000000000010000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMCA() bool CPU::HasMCA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000100000000000000; return GetFeatureBits_1() & 0b00000000000000000100000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCMOV() bool CPU::HasCMOV()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000001000000000000000; return GetFeatureBits_1() & 0b00000000000000001000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePAT() bool CPU::HasPAT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000010000000000000000; return GetFeatureBits_1() & 0b00000000000000010000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePSE_36() bool CPU::HasPSE_36()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000100000000000000000; return GetFeatureBits_1() & 0b00000000000000100000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePSN() bool CPU::HasPSN()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000001000000000000000000; return GetFeatureBits_1() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCLFSH() bool CPU::HasCLFSH()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000010000000000000000000; return GetFeatureBits_1() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveDS() bool CPU::HasDS()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000001000000000000000000000; return GetFeatureBits_1() & 0b00000000001000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveACPI() bool CPU::HasACPI()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000010000000000000000000000; return GetFeatureBits_1() & 0b00000000010000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMMX() bool CPU::HasMMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000100000000000000000000000; return GetFeatureBits_1() & 0b00000000100000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveFXSR() bool CPU::HasFXSR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000001000000000000000000000000; return GetFeatureBits_1() & 0b00000001000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE() bool CPU::HasSSE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000010000000000000000000000000; return GetFeatureBits_1() & 0b00000010000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE2() bool CPU::HasSSE2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000100000000000000000000000000; return GetFeatureBits_1() & 0b00000100000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSS() bool CPU::HasSS()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00001000000000000000000000000000; return GetFeatureBits_1() & 0b00001000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveHTT() bool CPU::HasHTT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00010000000000000000000000000000; return GetFeatureBits_1() & 0b00010000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTM() bool CPU::HasTM()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00100000000000000000000000000000; return GetFeatureBits_1() & 0b00100000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveIA64() bool CPU::HasIA64()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b01000000000000000000000000000000; return GetFeatureBits_1() & 0b01000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePBE() bool CPU::HasPBE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b10000000000000000000000000000000; return GetFeatureBits_1() & 0b10000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE3() bool CPU::HasSSE3()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000001; return GetFeatureBits_2() & 0b00000000000000000000000000000001;
#else
return false;
#endif
} }
bool CPU::RetrievePCLMULQDQ() bool CPU::HasPCLMULQDQ()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000010; return GetFeatureBits_2() & 0b00000000000000000000000000000010;
#else
return false;
#endif
} }
bool CPU::RetrieveDTES64() bool CPU::HasDTES64()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000100; return GetFeatureBits_2() & 0b00000000000000000000000000000100;
#else
return false;
#endif
} }
bool CPU::RetrieveMONITOR() bool CPU::HasMONITOR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000001000; return GetFeatureBits_2() & 0b00000000000000000000000000001000;
#else
return false;
#endif
} }
bool CPU::RetrieveDS_CPL() bool CPU::HasDS_CPL()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000010000; return GetFeatureBits_2() & 0b00000000000000000000000000010000;
#else
return false;
#endif
} }
bool CPU::RetrieveVMX() bool CPU::HasVMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000100000; return GetFeatureBits_2() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrieveSMX() bool CPU::HasSMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000001000000; return GetFeatureBits_2() & 0b00000000000000000000000001000000;
#else
return false;
#endif
} }
bool CPU::RetrieveEST() bool CPU::HasEST()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000010000000; return GetFeatureBits_2() & 0b00000000000000000000000010000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTM2() bool CPU::HasTM2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000100000000; return GetFeatureBits_2() & 0b00000000000000000000000100000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSSE3() bool CPU::HasSSSE3()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000001000000000; return GetFeatureBits_2() & 0b00000000000000000000001000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCNXT_ID() bool CPU::HasCNXT_ID()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000010000000000; return GetFeatureBits_2() & 0b00000000000000000000010000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSDBG() bool CPU::HasSDBG()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000100000000000; return GetFeatureBits_2() & 0b00000000000000000000100000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveFMA() bool CPU::HasFMA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000001000000000000; return GetFeatureBits_2() & 0b00000000000000000001000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCX16() bool CPU::HasCX16()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000010000000000000; return GetFeatureBits_2() & 0b00000000000000000010000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveXTPR() bool CPU::HasXTPR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000100000000000000; return GetFeatureBits_2() & 0b00000000000000000100000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePDCM() bool CPU::HasPDCM()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000001000000000000000; return GetFeatureBits_2() & 0b00000000000000001000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePCID() bool CPU::HasPCID()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000100000000000000000; return GetFeatureBits_2() & 0b00000000000000100000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveDCA() bool CPU::HasDCA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000001000000000000000000; return GetFeatureBits_2() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE4_1() bool CPU::HasSSE4_1()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000010000000000000000000; return GetFeatureBits_2() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE4_2() bool CPU::HasSSE4_2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000100000000000000000000; return GetFeatureBits_2() & 0b00000000000100000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveX2APIC() bool CPU::HasX2APIC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000001000000000000000000000; return GetFeatureBits_2() & 0b00000000001000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMOVBE() bool CPU::HasMOVBE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000010000000000000000000000; return GetFeatureBits_2() & 0b00000000010000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePOPCNT() bool CPU::HasPOPCNT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000100000000000000000000000; return GetFeatureBits_2() & 0b00000000100000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTSC_DEADLINE() bool CPU::HasTSC_DEADLINE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000001000000000000000000000000; return GetFeatureBits_2() & 0b00000001000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAES() bool CPU::HasAES()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000010000000000000000000000000; return GetFeatureBits_2() & 0b00000010000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveXSAVE() bool CPU::HasXSAVE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000100000000000000000000000000; return GetFeatureBits_2() & 0b00000100000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveOSXSAVE() bool CPU::HasOSXSAVE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00001000000000000000000000000000; return GetFeatureBits_2() & 0b00001000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX() bool CPU::HasAVX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00010000000000000000000000000000; return GetFeatureBits_2() & 0b00010000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveF16C() bool CPU::HasF16C()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00100000000000000000000000000000; return GetFeatureBits_2() & 0b00100000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveRDRND() bool CPU::HasRDRND()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b01000000000000000000000000000000; return GetFeatureBits_2() & 0b01000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveHYPERVISOR() bool CPU::HasHYPERVISOR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b10000000000000000000000000000000; return GetFeatureBits_2() & 0b10000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX2() bool CPU::HasAVX2()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000000000000000000100000; return GetExtFeatureBits_1() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX512F() bool CPU::HasRDSEED()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000000010000000000000000;
#else
return false;
#endif
}
bool CPU::RetrieveRDSEED()
{
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000001000000000000000000; return GetExtFeatureBits_1() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveADX() bool CPU::HasADX()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000010000000000000000000; return GetExtFeatureBits_1() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
/* /*

View File

@@ -2,6 +2,10 @@
namespace ehs namespace ehs
{ {
void CPU::RDTSCP(TSC* tsc)
{
}
void CPU::GetManufacturer(Char_8* input) void CPU::GetManufacturer(Char_8* input)
{ {
} }
@@ -39,9 +43,4 @@ namespace ehs
void CPU::GetBrand(Char_8* input) void CPU::GetBrand(Char_8* input)
{ {
} }
UInt_8 CPU::GetCacheLineSize()
{
return 0;
}
} }

View File

@@ -1,14 +0,0 @@
.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

View File

@@ -13,17 +13,13 @@ namespace ehs
system("xdg-open \"" + *uri + "\""); system("xdg-open \"" + *uri + "\"");
delete uri;
return 0; return 0;
} }
void System::OpenURI(Str_8 uri) void System::OpenURI(const Str_8& uri)
{ {
Str_8 *arg = new Str_8((Str_8&&)uri);
Thread xdg; Thread xdg;
xdg.Start(XDG_Thread, arg); xdg.Start(XDG_Thread, (void*)&uri);
xdg.Detach(); xdg.Detach();
} }

View File

@@ -4,7 +4,7 @@
namespace ehs namespace ehs
{ {
void System::OpenURI(Str_8 uri) void System::OpenURI(const Str_8& uri)
{ {
ShellExecuteA(nullptr, "open", uri, nullptr, nullptr, SW_SHOW); ShellExecuteA(nullptr, "open", uri, nullptr, nullptr, SW_SHOW);
} }