From 01ed39c1b0534661f9cc4020a4e8b01ddf5d9679 Mon Sep 17 00:00:00 2001 From: Patch Bot Date: Thu, 4 Jun 2026 18:47:56 +0000 Subject: [PATCH] Add nwcore and nwssl root libraries --- CMakeLists.txt | 8 +++++ include/core/core.h | 14 +++++++++ include/nwssl/nwssl.h | 15 ++++++++++ src/core/CMakeLists.txt | 66 +++++++++++++++++++++++++++++++++++++++++ src/core/core.c | 10 +++++++ src/ssl/CMakeLists.txt | 51 +++++++++++++++++++++++++++++++ src/ssl/nwssl.c | 16 ++++++++++ 7 files changed, 180 insertions(+) create mode 100644 include/core/core.h create mode 100644 include/nwssl/nwssl.h create mode 100644 src/core/CMakeLists.txt create mode 100644 src/core/core.c create mode 100644 src/ssl/CMakeLists.txt create mode 100644 src/ssl/nwssl.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 94c10a2..5c3a7e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,6 +274,12 @@ add_subdirectory(third_party/libsodium) set(BUILD_SHARED_LIBS ${_MARS_NWE_SAVED_BUILD_SHARED_LIBS}) add_subdirectory(third_party/matrixssl) +# mars-nwe base libraries. nwcore owns common project infrastructure such as +# logging; nwssl is the temporary SSL/Crypto abstraction on top of MatrixSSL +# OpenSSL-compat until the native API is complete. +add_subdirectory(src/core) +add_subdirectory(src/ssl) + if(ENABLE_DIRECTORY) set(TINYLDAP_OUTPUT_NAME nwdirectory CACHE STRING "" FORCE) set(TINYLDAP_BUILD_SHARED ON CACHE BOOL "" FORCE) @@ -310,6 +316,8 @@ message(STATUS "Install new DOS utilities: ${MARS_NWE_INSTALL_NEW_DOSUTILS}") message(STATUS "Build DOS utilities: ${MAINTAINER_BUILD} (maintainer build)") message(STATUS "Build nwdirectory: ${ENABLE_DIRECTORY}") message(STATUS "Build MatrixSSL programs: ${MARS_NWE_BUILD_MATRIXSSL_PROGRAMS}") +message(STATUS "Build nwcore: ON") +message(STATUS "Build nwssl: ON") message(STATUS "Maintainer build: ${MAINTAINER_BUILD}") message(STATUS "Packet Burst support: ${ENABLE_BURSTMODE}") diff --git a/include/core/core.h b/include/core/core.h new file mode 100644 index 0000000..762e3f4 --- /dev/null +++ b/include/core/core.h @@ -0,0 +1,14 @@ +#ifndef MARS_NWE_CORE_H +#define MARS_NWE_CORE_H + +#ifdef __cplusplus +extern "C" { +#endif + +const char *nwcore_version(void); + +#ifdef __cplusplus +} +#endif + +#endif /* MARS_NWE_CORE_H */ diff --git a/include/nwssl/nwssl.h b/include/nwssl/nwssl.h new file mode 100644 index 0000000..8c37e93 --- /dev/null +++ b/include/nwssl/nwssl.h @@ -0,0 +1,15 @@ +#ifndef MARS_NWE_NWSSL_H +#define MARS_NWE_NWSSL_H + +#ifdef __cplusplus +extern "C" { +#endif + +const char *nwssl_version(void); +int nwssl_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* MARS_NWE_NWSSL_H */ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 0000000..e283f28 --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,66 @@ +find_package(Threads REQUIRED) + +set(NWCORE_ZLOG_DIR + "${CMAKE_SOURCE_DIR}/third_party/zlog" + CACHE PATH "Path to bundled zlog source tree") + +if(NOT EXISTS "${NWCORE_ZLOG_DIR}/src/zlog.h") + message(FATAL_ERROR "Bundled zlog is required. Run: git submodule update --init --recursive third_party/zlog") +endif() + +file(GLOB NWCORE_ZLOG_SOURCES CONFIGURE_DEPENDS + "${NWCORE_ZLOG_DIR}/src/*.c") + +list(REMOVE_ITEM NWCORE_ZLOG_SOURCES + "${NWCORE_ZLOG_DIR}/src/zlog_win.c" + "${NWCORE_ZLOG_DIR}/src/zlog-chk-conf.c") + +set(NWCORE_BUILD_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/nwcore") +file(MAKE_DIRECTORY "${NWCORE_BUILD_INCLUDE_DIR}") + +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/core.h" + "${NWCORE_BUILD_INCLUDE_DIR}/core.h" + COPYONLY) +configure_file( + "${NWCORE_ZLOG_DIR}/src/zlog.h" + "${NWCORE_BUILD_INCLUDE_DIR}/zlog.h" + COPYONLY) + +add_library(nwcore SHARED + core.c + ${NWCORE_ZLOG_SOURCES}) +add_library(mars_nwe::core ALIAS nwcore) + +set_target_properties(nwcore PROPERTIES + OUTPUT_NAME nwcore + VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" + SOVERSION "${VERSION_MAJOR}") + +target_compile_features(nwcore PRIVATE c_std_99) +target_compile_definitions(nwcore PRIVATE + _GNU_SOURCE + MARS_NWE_VERSION_STRING="${MARS_NWE_VERSION}") + +target_include_directories(nwcore + PUBLIC + "$" + "$" + "$" + PRIVATE + "${NWCORE_ZLOG_DIR}/src") + +target_link_libraries(nwcore PUBLIC Threads::Threads) + +install(TARGETS nwcore + EXPORT mars-nwe-core-targets + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + +install(DIRECTORY "${NWCORE_BUILD_INCLUDE_DIR}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nwcore") + +install(EXPORT mars-nwe-core-targets + NAMESPACE mars_nwe:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mars-nwe") diff --git a/src/core/core.c b/src/core/core.c new file mode 100644 index 0000000..5044092 --- /dev/null +++ b/src/core/core.c @@ -0,0 +1,10 @@ +#include + +#ifndef MARS_NWE_VERSION_STRING +#define MARS_NWE_VERSION_STRING "unknown" +#endif + +const char *nwcore_version(void) +{ + return MARS_NWE_VERSION_STRING; +} diff --git a/src/ssl/CMakeLists.txt b/src/ssl/CMakeLists.txt new file mode 100644 index 0000000..8c5da8b --- /dev/null +++ b/src/ssl/CMakeLists.txt @@ -0,0 +1,51 @@ +set(NWSSL_BUILD_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/nwssl") +set(NWSSL_OPENSSL_COMPAT_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include") +file(MAKE_DIRECTORY "${NWSSL_BUILD_INCLUDE_DIR}" "${NWSSL_OPENSSL_COMPAT_INCLUDE_DIR}/openssl") + +configure_file( + "${CMAKE_SOURCE_DIR}/include/nwssl/nwssl.h" + "${NWSSL_BUILD_INCLUDE_DIR}/nwssl.h" + COPYONLY) + +# Temporary OpenSSL compatibility surface for legacy mars-nwe code. MatrixSSL's +# reduced OpenSSL layer intentionally does not provide md5.h, so expose a small +# MD5 wrapper here until callers move to the real nwssl API. +file(WRITE "${NWSSL_OPENSSL_COMPAT_INCLUDE_DIR}/openssl/md5.h" "#pragma once\n#include \n#include \n#include \ntypedef psMd5_t MD5_CTX;\nstatic inline int MD5_Init(MD5_CTX *c) { return psMd5Init(c) >= 0 ? 1 : 0; }\nstatic inline int MD5_Update(MD5_CTX *c, const void *data, size_t len) { psMd5Update(c, (const unsigned char *)data, (uint32_t)len); return 1; }\nstatic inline int MD5_Final(unsigned char *md, MD5_CTX *c) { psMd5Final(c, md); return 1; }\n") + +add_library(nwssl SHARED nwssl.c) +add_library(mars_nwe::ssl ALIAS nwssl) + +set_target_properties(nwssl PROPERTIES + OUTPUT_NAME nwssl + VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" + SOVERSION "${VERSION_MAJOR}") + +target_compile_features(nwssl PRIVATE c_std_99) +target_compile_definitions(nwssl PRIVATE + _GNU_SOURCE + MARS_NWE_VERSION_STRING="${MARS_NWE_VERSION}") + +target_include_directories(nwssl + PUBLIC + "$" + "$" + PRIVATE + "${CMAKE_SOURCE_DIR}/include") + +target_link_libraries(nwssl + PUBLIC + OpenSSL::SSL + OpenSSL::Crypto) + +install(TARGETS nwssl + EXPORT mars-nwe-ssl-targets + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + +install(DIRECTORY "${NWSSL_BUILD_INCLUDE_DIR}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nwssl") + +install(EXPORT mars-nwe-ssl-targets + NAMESPACE mars_nwe:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mars-nwe") diff --git a/src/ssl/nwssl.c b/src/ssl/nwssl.c new file mode 100644 index 0000000..370b26b --- /dev/null +++ b/src/ssl/nwssl.c @@ -0,0 +1,16 @@ +#include +#include + +#ifndef MARS_NWE_VERSION_STRING +#define MARS_NWE_VERSION_STRING "unknown" +#endif + +const char *nwssl_version(void) +{ + return MARS_NWE_VERSION_STRING; +} + +int nwssl_init(void) +{ + return SSL_library_init(); +}