diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a055b3b..94412b5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,13 @@ if (COMPILE_WIN32) # No TUI for this set(ENABLE_TUI_SUPPORT OFF) message(CHECK_START "Enable TUI support - no; for simplicity WIN32 does not support TUI.") + + # Automatically use vcpkg if VCPKG_ROOT is set in the environment + if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT Z_VCPKG_TOOLCHAIN_LOADED) + if(DEFINED ENV{VCPKG_ROOT}) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "vcpkg toolchain file") + endif() + endif() else() set(CMAKE_C_COMPILER /usr/bin/gcc CACHE STRING "C compiler") set(CMAKE_CXX_COMPILER /usr/bin/g++ CACHE STRING "C++ compiler") @@ -158,12 +165,14 @@ if (COMPILE_WIN32) set(CMAKE_CXX_FLAGS "/EHsc /D_WIN32 /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR") set(CMAKE_C_FLAGS_RELEASE "/EHsc /D_WIN32 /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR") set(CMAKE_CXX_FLAGS_RELEASE "/EHsc /D_WIN32 /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR") +else() + message(STATUS "GCC version ${CMAKE_CXX_COMPILER_VERSION}") endif (COMPILE_WIN32) -message(STATUS "GCC version ${CMAKE_CXX_COMPILER_VERSION}") - set(CMAKE_INSTALL_PREFIX "/usr/local") +project(dvm) + # # Library Inclusions # @@ -258,7 +267,6 @@ execute_process(COMMAND git describe --abbrev=8 --always WORKING_DIRECTORY ${CMA add_definitions(-D__GIT_VER__="${GIT_VER}") add_definitions(-D__GIT_VER_HASH__="${GIT_VER_HASH}") -project(dvm) include(src/CMakeLists.txt) include(tools/CMakeLists.txt) diff --git a/src/CompilerOptions.cmake b/src/CompilerOptions.cmake index 20f9b60e..156f3721 100644 --- a/src/CompilerOptions.cmake +++ b/src/CompilerOptions.cmake @@ -183,20 +183,18 @@ if (HAVE_SENDMMSG) endif (HAVE_SENDMMSG) # are we enabling SSL support? -if (NOT COMPILE_WIN32) +find_package(OpenSSL QUIET) +if (OpenSSL_FOUND) message(STATUS "OpenSSL root dir: ${OPENSSL_ROOT_DIR}") - find_package(OpenSSL REQUIRED) - if (OpenSSL_FOUND) - message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") - message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}") - message(CHECK_START "Enable SSL support") - message(CHECK_PASS "yes") + message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") + message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}") + message(CHECK_START "Enable SSL support") + message(CHECK_PASS "yes") - add_definitions(-DENABLE_SSL) - include_directories("${OPENSSL_INCLUDE_DIR}") - else (OpenSSL_FOUND) - message(STATUS "OpenSSL not found, SSL support disabled") - message(CHECK_START "Enable SSL support") - message(CHECK_PASS "no") - endif (OpenSSL_FOUND) -endif (NOT COMPILE_WIN32) + add_definitions(-DENABLE_SSL) + include_directories("${OPENSSL_INCLUDE_DIR}") +else (OpenSSL_FOUND) + message(STATUS "OpenSSL not found, SSL support disabled") + message(CHECK_START "Enable SSL support") + message(CHECK_PASS "no") +endif (OpenSSL_FOUND) diff --git a/src/common/network/tcp/SecureTcpClient.h b/src/common/network/tcp/SecureTcpClient.h index 6d5728a0..33b2a0df 100644 --- a/src/common/network/tcp/SecureTcpClient.h +++ b/src/common/network/tcp/SecureTcpClient.h @@ -25,7 +25,11 @@ #include #include +#if !defined(_WIN32) #include +#else +#include +#endif // !defined(_WIN32) #include #include @@ -67,6 +71,7 @@ namespace network initSsl(sslCtx); +#if !defined(_WIN32) // setup socket for non-blocking operations int flags = fcntl(fd, F_GETFL, 0); if (flags < 0) { @@ -78,6 +83,15 @@ namespace network LogError(LOG_NET, "failed fcntl(F_SETFL), err: %d (%s)", errno, strerror(errno)); throw std::runtime_error("Cannot accept SSL client"); } +#else + // setup socket for non-blocking operations + u_long mode = 1; + if (ioctlsocket(fd, FIONBIO, &mode) != NO_ERROR) { + int err = WSAGetLastError(); + LogError(LOG_NET, "failed ioctlsocket(FIONBIO), err: %d", err); + throw std::runtime_error("Cannot accept SSL client"); + } +#endif // !defined(_WIN32) int status = -1; struct timeval tv, tvRestore; @@ -135,6 +149,7 @@ namespace network } } while (status == 1 && !SSL_is_init_finished(m_pSSL)); +#if !defined(_WIN32) // reset socket blocking operations if (!nonBlocking) { flags = fcntl(fd, F_GETFL, 0); @@ -148,6 +163,17 @@ namespace network throw std::runtime_error("Cannot accept SSL client"); } } +#else + // reset socket blocking operations + if (!nonBlocking) { + u_long mode = 0; // 0 = blocking, 1 = non-blocking + if (ioctlsocket(fd, FIONBIO, &mode) != NO_ERROR) { + int err = WSAGetLastError(); + LogError(LOG_NET, "failed ioctlsocket(FIONBIO), err: %d", err); + throw std::runtime_error("Cannot accept SSL client"); + } + } +#endif // !defined(_WIN32) } /** * @brief Initializes a new instance of the SecureTcpClient class. @@ -184,7 +210,8 @@ namespace network LogError(LOG_NET, "Failed to connect to server, %s err: %d", ERR_error_string(ERR_get_error(), NULL), errno); throw std::runtime_error("Failed to SSL connect to server"); } - + +#if !defined(_WIN32) // setup socket for non-blocking operations if (nonBlocking) { int flags = fcntl(m_fd, F_GETFL, 0); @@ -198,6 +225,17 @@ namespace network throw std::runtime_error("Failed to set SSL server connection to non-blocking"); } } +#else + // setup socket for non-blocking operations + if (nonBlocking) { + u_long mode = 1; + if (ioctlsocket(m_fd, FIONBIO, &mode) != NO_ERROR) { + int err = WSAGetLastError(); + LogError(LOG_NET, "failed ioctlsocket(FIONBIO), err: %d", err); + throw std::runtime_error("Cannot accept SSL client"); + } + } +#endif // !defined(_WIN32) } /** * @brief Finalizes a instance of the SecureTcpClient class. diff --git a/src/fne/CryptoContainer.cpp b/src/fne/CryptoContainer.cpp index 09298120..4eaa0d9e 100644 --- a/src/fne/CryptoContainer.cpp +++ b/src/fne/CryptoContainer.cpp @@ -72,10 +72,16 @@ int base64Decode(char* b64message, uint8_t** buffer) int decodeLen = calcDecodeLength(b64message), len = 0; *buffer = (uint8_t*)malloc(decodeLen + 1); + +#if defined(_WIN32) + BIO* b64 = BIO_new(BIO_f_base64()); + BIO* bio = BIO_new_mem_buf(b64message, (int)::strlen(b64message)); +#else FILE* stream = ::fmemopen(b64message, ::strlen(b64message), "r"); - + BIO* b64 = BIO_new(BIO_f_base64()); BIO* bio = BIO_new_fp(stream, BIO_NOCLOSE); +#endif // defined(_WIN32) bio = BIO_push(b64, bio); BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); // do not use newlines to flush buffer len = BIO_read(bio, *buffer, ::strlen(b64message)); @@ -84,7 +90,9 @@ int base64Decode(char* b64message, uint8_t** buffer) (*buffer)[len] = '\0'; BIO_free_all(bio); +#if !defined(_WIN32) ::fclose(stream); +#endif // !defined(_WIN32) return decodeLen; } diff --git a/src/fne/xml/rapidxml.h b/src/fne/xml/rapidxml.h index 77c09ac9..9a50fa5b 100644 --- a/src/fne/xml/rapidxml.h +++ b/src/fne/xml/rapidxml.h @@ -401,8 +401,13 @@ namespace rapidxml public: //! \cond internal +#if defined(_WIN32) + typedef void *alloc_func(std::size_t); // Type of user-defined function used to allocate memory + typedef void free_func(void *); // Type of user-defined function used to free memory +#else typedef void *(alloc_func)(std::size_t); // Type of user-defined function used to allocate memory typedef void (free_func)(void *); // Type of user-defined function used to free memory +#endif // defined(_WIN32) //! \endcond //! Constructs empty pool with default allocator functions. diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..c9027861 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "dvmhost", + "version-string": "6.0.0", + "builtin-baseline": "3d22b64585ca026e881728fd87e541c23a611a43", + "dependencies": [ + "openssl" + ] +}