diff --git a/CMakeLists.txt b/CMakeLists.txt index ff3cce46..9eda3e0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ set( IXWEBSOCKET_SOURCES ixwebsocket/IXStrCaseCompare.cpp ixwebsocket/IXUdpSocket.cpp ixwebsocket/IXUrlParser.cpp + ixwebsocket/IXUUid.cpp ixwebsocket/IXUserAgent.cpp ixwebsocket/IXWebSocket.cpp ixwebsocket/IXWebSocketCloseConstants.cpp @@ -86,6 +87,7 @@ set( IXWEBSOCKET_HEADERS ixwebsocket/IXStrCaseCompare.h ixwebsocket/IXUdpSocket.h ixwebsocket/IXUrlParser.h + ixwebsocket/IXUUid.h ixwebsocket/IXUtf8Validator.h ixwebsocket/IXUserAgent.h ixwebsocket/IXWebSocket.h @@ -256,7 +258,6 @@ install(EXPORT ixwebsocket if (USE_WS OR USE_TEST) add_subdirectory(ixcore) - add_subdirectory(ixcrypto) include(FetchContent) FetchContent_Declare(spdlog diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8a52d0e7..d4f66b5b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [11.0.8] - 2020-12-25 + +(ws) trim ws dependencies no more ixcrypto and ixcore deps + ## [11.0.7] - 2020-12-25 (ws) trim ws dependencies, only depends on ixcrypto and ixcore diff --git a/ixcore/CMakeLists.txt b/ixcore/CMakeLists.txt deleted file mode 100644 index 54babb44..00000000 --- a/ixcore/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# -# Author: Benjamin Sergeant -# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. -# - -set (IXCORE_SOURCES - ixcore/utils/IXCoreLogger.cpp -) - -set (IXCORE_HEADERS - ixcore/utils/IXCoreLogger.h -) - -add_library(ixcore STATIC - ${IXCORE_SOURCES} - ${IXCORE_HEADERS} -) - -target_include_directories( ixcore PUBLIC . ) diff --git a/ixcore/ixcore/utils/IXCoreLogger.cpp b/ixcore/ixcore/utils/IXCoreLogger.cpp deleted file mode 100644 index 89159d54..00000000 --- a/ixcore/ixcore/utils/IXCoreLogger.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * IXCoreLogger.cpp - * Author: Thomas Wells, Benjamin Sergeant - * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. - */ - -#include "ixcore/utils/IXCoreLogger.h" - -namespace ix -{ - // Default do a no-op logger - CoreLogger::LogFunc CoreLogger::_currentLogger = [](const char*, LogLevel) {}; - - void CoreLogger::log(const char* msg, LogLevel level) - { - _currentLogger(msg, level); - } - - void CoreLogger::debug(const std::string& msg) - { - _currentLogger(msg.c_str(), LogLevel::Debug); - } - - void CoreLogger::info(const std::string& msg) - { - _currentLogger(msg.c_str(), LogLevel::Info); - } - - void CoreLogger::warn(const std::string& msg) - { - _currentLogger(msg.c_str(), LogLevel::Warning); - } - - void CoreLogger::error(const std::string& msg) - { - _currentLogger(msg.c_str(), LogLevel::Error); - } - - void CoreLogger::critical(const std::string& msg) - { - _currentLogger(msg.c_str(), LogLevel::Critical); - } - -} // namespace ix diff --git a/ixcore/ixcore/utils/IXCoreLogger.h b/ixcore/ixcore/utils/IXCoreLogger.h deleted file mode 100644 index 18a23883..00000000 --- a/ixcore/ixcore/utils/IXCoreLogger.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * IXCoreLogger.h - * Author: Thomas Wells, Benjamin Sergeant - * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. - */ - -#pragma once -#include -#include - -namespace ix -{ - enum class LogLevel - { - Debug = 0, - Info = 1, - Warning = 2, - Error = 3, - Critical = 4 - }; - - class CoreLogger - { - public: - using LogFunc = std::function; - - static void log(const char* msg, LogLevel level = LogLevel::Debug); - - static void debug(const std::string& msg); - static void info(const std::string& msg); - static void warn(const std::string& msg); - static void error(const std::string& msg); - static void critical(const std::string& msg); - - static void setLogFunction(LogFunc& func) - { - _currentLogger = func; - } - - private: - static LogFunc _currentLogger; - }; - -} // namespace ix diff --git a/ixcrypto/CMakeLists.txt b/ixcrypto/CMakeLists.txt deleted file mode 100644 index 000f8a6b..00000000 --- a/ixcrypto/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# -# Author: Benjamin Sergeant -# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. -# -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../CMake;${CMAKE_MODULE_PATH}") - -set (IXCRYPTO_SOURCES - ixcrypto/IXHMac.cpp - ixcrypto/IXBase64.cpp - ixcrypto/IXUuid.cpp - ixcrypto/IXHash.cpp -) - -set (IXCRYPTO_HEADERS - ixcrypto/IXHMac.h - ixcrypto/IXBase64.h - ixcrypto/IXUuid.h - ixcrypto/IXHash.h -) - -add_library(ixcrypto STATIC - ${IXCRYPTO_SOURCES} - ${IXCRYPTO_HEADERS} -) - -set(IXCRYPTO_INCLUDE_DIRS - . - ../ixcore) - -target_include_directories( ixcrypto PUBLIC ${IXCRYPTO_INCLUDE_DIRS} ) - -# hmac computation needs a crypto library - -target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_TLS) -if (USE_MBED_TLS) - find_package(MbedTLS REQUIRED) - target_include_directories(ixcrypto PUBLIC ${MBEDTLS_INCLUDE_DIRS}) - target_link_libraries(ixcrypto ${MBEDTLS_LIBRARIES}) - target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_MBED_TLS) -elseif (USE_OPEN_SSL) - find_package(OpenSSL REQUIRED) - add_definitions(${OPENSSL_DEFINITIONS}) - message(STATUS "OpenSSL: " ${OPENSSL_VERSION}) - include_directories(${OPENSSL_INCLUDE_DIR}) - target_link_libraries(ixcrypto ${OPENSSL_LIBRARIES}) - target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_OPEN_SSL) -endif() diff --git a/ixcrypto/ixcrypto/IXBase64.cpp b/ixcrypto/ixcrypto/IXBase64.cpp deleted file mode 100644 index 3248f497..00000000 --- a/ixcrypto/ixcrypto/IXBase64.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - base64.cpp and base64.h - - Copyright (C) 2004-2008 René Nyffenegger - - This source code is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this source code must not be misrepresented; you must not - claim that you wrote the original source code. If you use this source code - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original source code. - - 3. This notice may not be removed or altered from any source distribution. - - René Nyffenegger rene.nyffenegger@adp-gmbh.ch - - */ - -#include "IXBase64.h" - -namespace ix -{ - static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - std::string base64_encode(const std::string& data, size_t len) - { - const char* bytes_to_encode = data.c_str(); - return base64_encode(bytes_to_encode, len); - } - - std::string base64_encode(const char* bytes_to_encode, size_t len) - { - std::string ret; - ret.reserve(((len + 2) / 3) * 4); - - int i = 0; - int j = 0; - unsigned char char_array_3[3]; - unsigned char char_array_4[4]; - - while (len--) - { - char_array_3[i++] = *(bytes_to_encode++); - if (i == 3) - { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (i = 0; (i < 4); i++) - ret += base64_chars[char_array_4[i]]; - - i = 0; - } - } - - if (i) - { - for (j = i; j < 3; j++) - char_array_3[j] = '\0'; - - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (j = 0; (j < i + 1); j++) - ret += base64_chars[char_array_4[j]]; - - while ((i++ < 3)) - ret += '='; - } - - return ret; - } - - static inline bool is_base64(unsigned char c) - { - return (isalnum(c) || (c == '+') || (c == '/')); - } - - std::string base64_decode(const std::string& encoded_string) - { - int in_len = (int) encoded_string.size(); - int i = 0; - int j = 0; - int in_ = 0; - unsigned char char_array_4[4], char_array_3[3]; - std::string ret; - ret.reserve(((in_len + 3) / 4) * 3); - - while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) - { - char_array_4[i++] = encoded_string[in_]; - in_++; - if (i == 4) - { - for (i = 0; i < 4; i++) - char_array_4[i] = base64_chars.find(char_array_4[i]); - - 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); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (i = 0; (i < 3); i++) - ret += char_array_3[i]; - - i = 0; - } - } - - if (i) - { - for (j = i; j < 4; j++) - char_array_4[j] = 0; - - for (j = 0; j < 4; j++) - char_array_4[j] = base64_chars.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); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (j = 0; (j < i - 1); j++) - ret += char_array_3[j]; - } - - return ret; - } -} // namespace ix diff --git a/ixcrypto/ixcrypto/IXBase64.h b/ixcrypto/ixcrypto/IXBase64.h deleted file mode 100644 index 07bad77b..00000000 --- a/ixcrypto/ixcrypto/IXBase64.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * base64.h - * Author: Benjamin Sergeant - * Copyright (c) 2018 Machine Zone. All rights reserved. - */ - -#pragma once - -#include - -namespace ix -{ - std::string base64_encode(const std::string& data, size_t len); - std::string base64_encode(const char* data, size_t len); - std::string base64_decode(const std::string& encoded_string); -} // namespace ix diff --git a/ixcrypto/ixcrypto/IXHMac.cpp b/ixcrypto/ixcrypto/IXHMac.cpp deleted file mode 100644 index d798f80d..00000000 --- a/ixcrypto/ixcrypto/IXHMac.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * IXHMac.h - * Author: Benjamin Sergeant - * Copyright (c) 2018 Machine Zone. All rights reserved. - */ - -#include "IXHMac.h" - -#include "IXBase64.h" - -#if defined(IXCRYPTO_USE_MBED_TLS) -#include -#elif defined(__APPLE__) -#include -#elif defined(IXCRYPTO_USE_OPEN_SSL) -#include -#else -#include -#endif - -namespace ix -{ - std::string hmac(const std::string& data, const std::string& key) - { - constexpr size_t hashSize = 16; - unsigned char hash[hashSize]; - -#if defined(IXCRYPTO_USE_MBED_TLS) - mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_MD5), - (unsigned char*) key.c_str(), - key.size(), - (unsigned char*) data.c_str(), - data.size(), - (unsigned char*) &hash); -#elif defined(__APPLE__) - CCHmac(kCCHmacAlgMD5, key.c_str(), key.size(), data.c_str(), data.size(), &hash); -#elif defined(IXCRYPTO_USE_OPEN_SSL) - HMAC(EVP_md5(), - key.c_str(), - (int) key.size(), - (unsigned char*) data.c_str(), - (int) data.size(), - (unsigned char*) hash, - nullptr); -#else - assert(false && "hmac not implemented on this platform"); -#endif - - std::string hashString(reinterpret_cast(hash), hashSize); - - return base64_encode(hashString, (uint32_t) hashString.size()); - } -} // namespace ix diff --git a/ixcrypto/ixcrypto/IXHMac.h b/ixcrypto/ixcrypto/IXHMac.h deleted file mode 100644 index a0f93eae..00000000 --- a/ixcrypto/ixcrypto/IXHMac.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * IXHMac.h - * Author: Benjamin Sergeant - * Copyright (c) 2018 Machine Zone. All rights reserved. - */ - -#pragma once - -#include - -namespace ix -{ - std::string hmac(const std::string& data, const std::string& key); -} diff --git a/ixcrypto/ixcrypto/IXHash.cpp b/ixcrypto/ixcrypto/IXHash.cpp deleted file mode 100644 index 99bfb264..00000000 --- a/ixcrypto/ixcrypto/IXHash.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * IXHash.h - * Author: Benjamin Sergeant - * Copyright (c) 2018 Machine Zone. All rights reserved. - */ - -#include "IXHash.h" - -namespace ix -{ - uint64_t djb2Hash(const std::vector& data) - { - uint64_t hashAddress = 5381; - - for (auto&& c : data) - { - hashAddress = ((hashAddress << 5) + hashAddress) + c; - } - - return hashAddress; - } - - uint64_t djb2HashStr(const std::string& data) - { - uint64_t hashAddress = 5381; - - for (size_t i = 0; i < data.size(); ++i) - { - hashAddress = ((hashAddress << 5) + hashAddress) + data[i]; - } - - return hashAddress; - } -} // namespace ix diff --git a/ixcrypto/ixcrypto/IXHash.h b/ixcrypto/ixcrypto/IXHash.h deleted file mode 100644 index 85ed97f7..00000000 --- a/ixcrypto/ixcrypto/IXHash.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * IXHash.h - * Author: Benjamin Sergeant - * Copyright (c) 2018 Machine Zone. All rights reserved. - */ - -#pragma once - -#include -#include -#include - -namespace ix -{ - uint64_t djb2Hash(const std::vector& data); - uint64_t djb2HashStr(const std::string& data); -} diff --git a/ixcrypto/ixcrypto/IXUuid.cpp b/ixwebsocket/IXUuid.cpp similarity index 100% rename from ixcrypto/ixcrypto/IXUuid.cpp rename to ixwebsocket/IXUuid.cpp diff --git a/ixcrypto/ixcrypto/IXUuid.h b/ixwebsocket/IXUuid.h similarity index 100% rename from ixcrypto/ixcrypto/IXUuid.h rename to ixwebsocket/IXUuid.h diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 1e3b4517..d7e88dbd 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.0.7" +#define IX_WEBSOCKET_VERSION "11.0.8" diff --git a/makefile.dev b/makefile.dev index 32fff680..75cc7049 100644 --- a/makefile.dev +++ b/makefile.dev @@ -28,25 +28,25 @@ brew: # server side ?) and I can't work-around it easily, so we're using mbedtls on # Linux for the SSL backend, which works great. ws_mbedtls_install: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_ZLIB=OFF -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; ninja install) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_ZLIB=OFF -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; ninja install) ws: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) ws_unity: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) ws_install: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. -DUSE_TEST=0 && ninja install) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_TLS=1 -DUSE_WS=1 .. -DUSE_TEST=0 && ninja install) ws_install_release: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. -DUSE_TEST=0 && ninja install) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_TLS=1 -DUSE_WS=1 .. -DUSE_TEST=0 && ninja install) ws_openssl_install: mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_OPEN_SSL=1 .. ; ninja install) ws_mbedtls: - mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j 4) + mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j 4) ws_no_ssl: mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_WS=1 .. ; make -j 4) @@ -111,27 +111,27 @@ test_server: (cd test && npm i ws && node broadcast-server.js) test: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_TEST=1 ..) + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_TEST=1 ..) (cd build ; ninja) (cd build ; ninja test) test_asan: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer") + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer") (cd build ; ninja) (cd build ; ctest -V .) test_tsan_mbedtls: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_MBED_TLS=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_MBED_TLS=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") (cd build ; ninja) (cd build ; ninja test) test_tsan_openssl: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_OPENS_SSL=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_OPENS_SSL=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") (cd build ; ninja) (cd build ; ninja test) test_tsan_sectransport: - mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_OPENS_SSL=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_OPENS_SSL=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer") (cd build ; ninja) (cd build ; ninja test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a4729a5e..932fdbd2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,7 +58,6 @@ target_include_directories(ixwebsocket_test PRIVATE ../third_party ) target_link_libraries(ixwebsocket_test ixwebsocket) -target_link_libraries(ixwebsocket_test ixcrypto) target_link_libraries(ixwebsocket_test spdlog) foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES}) @@ -81,7 +80,6 @@ foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES}) # library with the most dependencies come first target_link_libraries(${TEST_TARGET_NAME} ixwebsocket_test) target_link_libraries(${TEST_TARGET_NAME} ixwebsocket) - target_link_libraries(${TEST_TARGET_NAME} ixcrypto) target_link_libraries(${TEST_TARGET_NAME} ixcore) target_link_libraries(${TEST_TARGET_NAME} spdlog) diff --git a/test/IXTest.cpp b/test/IXTest.cpp index 85a73498..d9c67599 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/test/test_runner.cpp b/test/test_runner.cpp index 4410d841..5c000e1e 100644 --- a/test/test_runner.cpp +++ b/test/test_runner.cpp @@ -6,7 +6,6 @@ #define CATCH_CONFIG_RUNNER #include "catch.hpp" -#include #include #include @@ -21,42 +20,6 @@ int main(int argc, char* argv[]) #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif - - ix::CoreLogger::LogFunc logFunc = [](const char* msg, ix::LogLevel level) { - switch (level) - { - case ix::LogLevel::Debug: - { - spdlog::debug(msg); - } - break; - - case ix::LogLevel::Info: - { - spdlog::info(msg); - } - break; - - case ix::LogLevel::Warning: - { - spdlog::warn(msg); - } - break; - - case ix::LogLevel::Error: - { - spdlog::error(msg); - } - break; - - case ix::LogLevel::Critical: - { - spdlog::critical(msg); - } - break; - } - }; - ix::CoreLogger::setLogFunction(logFunc); spdlog::set_level(spdlog::level::debug); int result = Catch::Session().run(argc, argv); diff --git a/ws/CMakeLists.txt b/ws/CMakeLists.txt index 0fa8760c..3351dca3 100644 --- a/ws/CMakeLists.txt +++ b/ws/CMakeLists.txt @@ -30,7 +30,6 @@ add_executable(ws # library with the most dependencies come first target_link_libraries(ws ixwebsocket) -target_link_libraries(ws ixcrypto) target_link_libraries(ws ixcore) target_link_libraries(ws spdlog) diff --git a/ws/docker_build.sh b/ws/docker_build.sh deleted file mode 100644 index 049ad66e..00000000 --- a/ws/docker_build.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# -# Author: Benjamin Sergeant -# Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved. -# - -# 'manual' way of building. I cannot get CMake to work to build in a container. - -g++ --std=c++14 \ - -DIXWEBSOCKET_USE_TLS \ - -g \ - ../ixwebsocket/IXEventFd.cpp \ - ../ixwebsocket/IXSocket.cpp \ - ../ixwebsocket/IXSocketServer.cpp \ - ../ixwebsocket/IXSocketConnect.cpp \ - ../ixwebsocket/IXSocketFactory.cpp \ - ../ixwebsocket/IXDNSLookup.cpp \ - ../ixwebsocket/IXCancellationRequest.cpp \ - ../ixwebsocket/IXWebSocket.cpp \ - ../ixwebsocket/IXWebSocketServer.cpp \ - ../ixwebsocket/IXWebSocketTransport.cpp \ - ../ixwebsocket/IXWebSocketHandshake.cpp \ - ../ixwebsocket/IXWebSocketPerMessageDeflate.cpp \ - ../ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp \ - ../ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp \ - ../ixwebsocket/IXWebSocketHttpHeaders.cpp \ - ../ixwebsocket/IXHttpClient.cpp \ - ../ixwebsocket/IXUrlParser.cpp \ - ../ixwebsocket/IXSocketOpenSSL.cpp \ - ../ixwebsocket/linux/IXSetThreadName_linux.cpp \ - ../third_party/msgpack11/msgpack11.cpp \ - ixcrypto/IXBase64.cpp \ - ixcrypto/IXHash.cpp \ - ixcrypto/IXUuid.cpp \ - ws_http_client.cpp \ - ws_ping_pong.cpp \ - ws_broadcast_server.cpp \ - ws_echo_server.cpp \ - ws_chat.cpp \ - ws_connect.cpp \ - ws_transfer.cpp \ - ws_send.cpp \ - ws_receive.cpp \ - ws.cpp \ - -I . \ - -I .. \ - -I ../third_party \ - -o ws \ - -lcrypto -lssl -lz -lpthread diff --git a/ws/ws.cpp b/ws/ws.cpp index 357868a1..8df93d6c 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -15,10 +15,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include @@ -29,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +143,30 @@ namespace return path; } } + + uint64_t djb2Hash(const std::vector& data) + { + uint64_t hashAddress = 5381; + + for (auto&& c : data) + { + hashAddress = ((hashAddress << 5) + hashAddress) + c; + } + + return hashAddress; + } + + uint64_t djb2HashStr(const std::string& data) + { + uint64_t hashAddress = 5381; + + for (size_t i = 0; i < data.size(); ++i) + { + hashAddress = ((hashAddress << 5) + hashAddress) + data[i]; + } + + return hashAddress; + } } // namespace namespace ix @@ -988,7 +1009,7 @@ namespace ix spdlog::info("gzip input: {} size {} cksum {}", filename, res.second.size(), - ix::djb2HashStr(res.second)); + djb2HashStr(res.second)); std::string compressedBytes; @@ -1022,7 +1043,7 @@ namespace ix spdlog::info("gzip output: {} size {} cksum {}", outputFilename, compressedBytes.size(), - ix::djb2HashStr(compressedBytes)); + djb2HashStr(compressedBytes)); return 0; } @@ -1042,7 +1063,7 @@ namespace ix spdlog::info("gunzip input: {} size {} cksum {}", filename, res.second.size(), - ix::djb2HashStr(res.second)); + djb2HashStr(res.second)); std::string decompressedBytes; @@ -1070,7 +1091,7 @@ namespace ix spdlog::info("gunzip output: {} size {} cksum {}", outputFilename, decompressedBytes.size(), - ix::djb2HashStr(decompressedBytes)); + djb2HashStr(decompressedBytes)); return 0; } @@ -1175,7 +1196,7 @@ namespace ix std::stringstream ss; ss << "messages received per second: " << receivedCountPerSecs; - CoreLogger::info(ss.str()); + spdlog::info(ss.str()); receivedCountPerSecs = 0; @@ -1928,7 +1949,7 @@ namespace ix spdlog::info("ws_receive: Content size: {}", content.size()); // Validate checksum - uint64_t cksum = ix::djb2Hash(content); + uint64_t cksum = djb2Hash(content); auto cksumRef = data["djb2_hash"].string_value(); spdlog::info("ws_receive: Computed hash: {}", cksum); @@ -2481,41 +2502,6 @@ int main(int argc, char** argv) ix::setThreadName("ws main thread"); ix::initNetSystem(); - ix::CoreLogger::LogFunc logFunc = [](const char* msg, ix::LogLevel level) { - switch (level) - { - case ix::LogLevel::Debug: - { - spdlog::debug(msg); - } - break; - - case ix::LogLevel::Info: - { - spdlog::info(msg); - } - break; - - case ix::LogLevel::Warning: - { - spdlog::warn(msg); - } - break; - - case ix::LogLevel::Error: - { - spdlog::error(msg); - } - break; - - case ix::LogLevel::Critical: - { - spdlog::critical(msg); - } - break; - } - }; - ix::CoreLogger::setLogFunction(logFunc); spdlog::set_level(spdlog::level::debug); #ifndef _WIN32