Merge 0815aea6fd78a84d2db9131ef6614fb467e83ba3 into 9b3f9f356db1ed29ca8a098cad3682d041b0c5fd

This commit is contained in:
Alex 2025-12-10 08:06:10 +00:00 committed by GitHub
commit bbc331485c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
508 changed files with 1774 additions and 46635 deletions

View File

@ -23,7 +23,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y build-essential ninja-build ccache libmariadb-dev libmariadb-dev-compat libboost-all-dev libperl-dev liblua5.1-0-dev libluajit-5.1-dev zlib1g-dev uuid-dev libssl-dev libsodium-dev libmbedtls-dev sudo apt-get install -y build-essential ninja-build ccache
- name: Configure - name: Configure
run: | run: |
@ -74,7 +74,7 @@ jobs:
- name: Build - name: Build
shell: pwsh shell: pwsh
run: cmake --build build --config RelWithDebInfo --target ALL_BUILD -- /m run: cmake --build build --parallel --config RelWithDebInfo --target ALL_BUILD -- /m
- name: Test - name: Test
working-directory: build working-directory: build

18
.gitmodules vendored
View File

@ -1,18 +1,6 @@
[submodule "submodules/glm"]
path = submodules/glm
url = https://github.com/g-truc/glm.git
[submodule "submodules/fmt"]
path = submodules/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "submodules/libuv"]
path = submodules/libuv
url = https://github.com/libuv/libuv.git
[submodule "submodules/cereal"]
path = submodules/cereal
url = https://github.com/USCiLab/cereal.git
[submodule "submodules/websocketpp"] [submodule "submodules/websocketpp"]
path = submodules/websocketpp path = submodules/websocketpp
url = https://github.com/zaphoyd/websocketpp.git url = https://github.com/zaphoyd/websocketpp.git
[submodule "submodules/recastnavigation"] [submodule "submodules/vcpkg"]
path = submodules/recastnavigation path = submodules/vcpkg
url = https://github.com/EQEmu/recastnavigation.git url = https://github.com/microsoft/vcpkg.git

View File

@ -1,490 +1,179 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20.0)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
IF(POLICY CMP0074) if(NOT CMAKE_TOOLCHAIN_FILE)
CMAKE_POLICY(SET CMP0074 NEW) if(DEFINED ENV{VCPKG_ROOT})
ENDIF() message(STATUS "Using vcpkg from VCPKG_ROOT")
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE FILEPATH "Vcpkg toolchain file"
)
else()
message(STATUS "Using vcpkg submodule")
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/submodules/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE FILEPATH "Vcpkg toolchain file"
)
endif()
endif()
PROJECT(EQEmu) project(EQEmu
VERSION 24.10.3
LANGUAGES CXX
)
IF(NOT CMAKE_BUILD_TYPE) #explicitly set CMP0167 for Find Boost
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) if(POLICY CMP0167)
ENDIF(NOT CMAKE_BUILD_TYPE) cmake_policy(SET CMP0167 NEW)
endif()
SET(CMAKE_CXX_STANDARD 20) if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type")
SET(CMAKE_CXX_EXTENSIONS OFF) endif()
OPTION(EQEMU_BUILD_STATIC "Build with static linking" OFF) set(CMAKE_CXX_STANDARD 20)
OPTION(EQEMU_BUILD_PCH "Build with precompiled headers (Windows)" ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
IF (EQEMU_BUILD_STATIC) option(EQEMU_BUILD_PCH "Build with precompiled headers (Windows)" ON)
SET(BUILD_SHARED_LIBS OFF)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".a")
MESSAGE(STATUS "Building with static linking")
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
IF (UNIX)
SET(PERL_LIBRARY "/opt/eqemu-perl/lib/5.32.1/x86_64-linux-thread-multi/CORE/libperl.so")
SET(PERL_INCLUDE_PATH "/opt/eqemu-perl/lib/5.32.1/x86_64-linux-thread-multi/CORE/")
SET(PERL_EXECUTABLE "/opt/eqemu-perl/bin/perl")
ENDIF ()
ENDIF (EQEMU_BUILD_STATIC)
if(MSVC)
# Requires libgoogle-perftools-dev google-perftools packages for linux (debian)
IF(EQEMU_ADD_PROFILER)
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed,-lprofiler,--as-needed")
ENDIF(EQEMU_ADD_PROFILER)
IF(USE_MAP_MMFS)
ADD_DEFINITIONS(-DUSE_MAP_MMFS)
ENDIF (USE_MAP_MMFS)
IF(MSVC)
add_compile_options(/bigobj) add_compile_options(/bigobj)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS NOMINMAX CRASH_LOGGING _HAS_AUTO_PTR_ETC)
ADD_DEFINITIONS(-DNOMINMAX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ADD_DEFINITIONS(-DCRASH_LOGGING)
ADD_DEFINITIONS(-D_HAS_AUTO_PTR_ETC) # for Luabind on C++17
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") option(EQEMU_DISABLE_MSVC_WARNINGS "Disable MSVC compile warnings." ON)
if(EQEMU_DISABLE_MSVC_WARNINGS)
OPTION(EQEMU_DISABLE_MSVC_WARNINGS "Disable MSVC compile warnings." ON) add_compile_options(/W0 /wd4005 /wd4996 /nologo /Os)
IF(EQEMU_DISABLE_MSVC_WARNINGS) endif()
ADD_DEFINITIONS( "/W0 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo /Os") else()
ENDIF(EQEMU_DISABLE_MSVC_WARNINGS) add_compile_definitions(HAS_UNION_SEMUN)
ELSE(MSVC) endif()
ADD_DEFINITIONS(-DHAS_UNION_SEMUN)
ENDIF(MSVC)
#FreeBSD support #FreeBSD support
IF(UNIX) if(UNIX)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
ADD_DEFINITIONS(-DFREEBSD) add_compile_definitions(FREEBSD)
ADD_DEFINITIONS(-D_GLIBCXX_USE_C99) add_compile_definitions(_GLIBCXX_USE_C99)
SET(FREEBSD TRUE) set(FREEBSD TRUE)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") endif()
IF(CMAKE_SYSTEM_NAME MATCHES "Darwin") if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
ADD_DEFINITIONS(-DDARWIN) add_compile_definitions(DARWIN)
SET(DARWIN TRUE) set(DARWIN TRUE)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") endif()
ENDIF(UNIX) endif()
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS) find_package(Boost REQUIRED COMPONENTS dynamic_bitset foreach tuple)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT) find_package(cereal CONFIG REQUIRED)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL) find_package(fmt CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(unofficial-libmariadb CONFIG REQUIRED)
find_package(libuv CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(recastnavigation CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LuaJit REQUIRED)
find_package(PerlLibs)
#MSVC can fetch dependencies automatically. message(STATUS "**************************************************")
IF(MSVC) message(STATUS "* Library Detection *")
INCLUDE("${CMAKE_SOURCE_DIR}/cmake/DependencyHelperMSVC.cmake") message(STATUS "**************************************************")
ENDIF()
#Find everything we need if(MARIADB_FOUND)
FIND_PACKAGE(Boost REQUIRED) message(STATUS "* MariaDB: FOUND *")
FIND_PACKAGE(MySQL) else()
FIND_PACKAGE(MariaDB) message(STATUS "* MariaDB: MISSING *")
FIND_PACKAGE(ZLIB) endif()
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(Lua51)
FIND_PACKAGE(LuaJit)
FIND_PACKAGE(PerlLibs)
FIND_PACKAGE(Sodium)
FIND_PACKAGE(mbedTLS)
MESSAGE(STATUS "**************************************************") if(ZLIB_FOUND)
MESSAGE(STATUS "* Library Detection *") message(STATUS "* ZLIB: FOUND *")
MESSAGE(STATUS "**************************************************") else()
message(STATUS "* ZLIB: MISSING *")
endif()
IF(MYSQL_FOUND) if(LuaJit_FOUND)
MESSAGE(STATUS "* MySQL: FOUND *") message(STATUS "* LuaJIT: FOUND *")
ELSE() else()
MESSAGE(STATUS "* MySQL: MISSING *") message(STATUS "* LuaJIT: MISSING *")
ENDIF() endif()
IF(MARIADB_FOUND) if(PerlLibs_FOUND)
MESSAGE(STATUS "* MariaDB: FOUND *") message(STATUS "* Perl: FOUND *")
ELSE() else()
MESSAGE(STATUS "* MariaDB: MISSING *") message(STATUS "* Perl: MISSING *")
ENDIF() endif()
IF(ZLIB_FOUND) if(OpenSSL_FOUND)
MESSAGE(STATUS "* ZLIB: FOUND *") message(STATUS "* OpenSSL: FOUND *")
ELSE() else()
MESSAGE(STATUS "* ZLIB: MISSING *") message(STATUS "* OpenSSL: MISSING *")
ENDIF() endif()
IF(Lua51_FOUND) message(STATUS "PERL_INCLUDE_PATH: ${PERL_INCLUDE_PATH}")
MESSAGE(STATUS "* Lua: FOUND *") message(STATUS "PERL_LIBRARY: ${PERL_LIBRARY}")
ELSE() message(STATUS "PERL_INCLUDE_DIR: ${PERL_INCLUDE_DIR}")
MESSAGE(STATUS "* Lua: MISSING *") message(STATUS "PERL_INCLUDE_DIRS: ${PERL_INCLUDE_DIRS}")
ENDIF() message(STATUS "PERL_LIBRARIES: ${PERL_LIBRARIES}")
message(STATUS "PERL_VERSION: ${PERL_VERSION}")
IF(LuaJit_FOUND) message(STATUS "**************************************************")
MESSAGE(STATUS "* LuaJIT: FOUND *")
ELSE()
MESSAGE(STATUS "* LuaJIT: MISSING *")
ENDIF()
IF(PerlLibs_FOUND)
MESSAGE(STATUS "* Perl: FOUND *")
ELSE()
MESSAGE(STATUS "* Perl: MISSING *")
ENDIF()
IF(SODIUM_FOUND)
MESSAGE(STATUS "* libsodium: FOUND *")
ELSE()
MESSAGE(STATUS "* libsodium: MISSING *")
ENDIF()
IF(OpenSSL_FOUND)
MESSAGE(STATUS "* OpenSSL: FOUND *")
ELSE()
MESSAGE(STATUS "* OpenSSL: MISSING *")
ENDIF()
IF(MBEDTLS_FOUND)
MESSAGE(STATUS "* mbedTLS: FOUND *")
ELSE()
MESSAGE(STATUS "* mbedTLS: MISSING *")
ENDIF()
MESSAGE(STATUS "PERL_INCLUDE_PATH: ${PERL_INCLUDE_PATH}")
MESSAGE(STATUS "PERL_LIBRARY: ${PERL_LIBRARY}")
MESSAGE(STATUS "PERL_INCLUDE_DIR: ${PERL_INCLUDE_DIR}")
MESSAGE(STATUS "PERL_INCLUDE_DIRS: ${PERL_INCLUDE_DIRS}")
MESSAGE(STATUS "PERL_LIBRARIES: ${PERL_LIBRARIES}")
MESSAGE(STATUS "PERL_VERSION: ${PERL_VERSION}")
MESSAGE(STATUS "**************************************************")
#options #options
OPTION(EQEMU_COMMANDS_LOGGING "Enable GM Command logs" ON) option(EQEMU_BUILD_SERVER "Build the game server." ON)
OPTION(EQEMU_BUILD_SERVER "Build the game server." ON) option(EQEMU_BUILD_LOGIN "Build the login server." ON)
OPTION(EQEMU_BUILD_LOGIN "Build the login server." ON) option(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_HC "Build the headless client." OFF) option(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
OPTION(EQEMU_PREFER_LUA "Build with normal Lua even if LuaJIT is found." OFF)
#PRNG options if(PerlLibs_FOUND)
OPTION(EQEMU_ADDITIVE_LFIB_PRNG "Use Additive LFib for PRNG." OFF) option(EQEMU_BUILD_PERL "Build Perl parser." ON)
MARK_AS_ADVANCED(EQEMU_ADDITIVE_LFIB_PRNG)
OPTION(EQEMU_BIASED_INT_DIST "Use biased int dist instead of uniform." OFF) if(EQEMU_BUILD_PERL)
MARK_AS_ADVANCED(EQEMU_BIASED_INT_DIST) set(PERL_LIBRARY_TYPE " Perl")
SET(EQEMU_CUSTOM_PRNG_ENGINE "" CACHE STRING "Custom random engine. (ex. std::default_random_engine)") else()
MARK_AS_ADVANCED(EQEMU_CUSTOM_PRNG_ENGINE) set(PERL_LIBRARY_TYPE " Missing")
endif()
else()
set(PERL_LIBRARY_TYPE "Disabled")
endif()
IF(CMAKE_COMPILER_IS_GNUCXX) message(STATUS "")
OPTION(EQEMU_SFMT19937 "Use GCC's extention for SIMD Fast MT19937." OFF) message(STATUS "**************************************************")
MARK_AS_ADVANCED(EQEMU_SFMT19937) message(STATUS "* Library Usage *")
ENDIF() message(STATUS "**************************************************")
message(STATUS "* Database: MariaDB *")
message(STATUS "* TLS: OpenSSL *")
message(STATUS "* Lua: LuaJIT *")
message(STATUS "* Perl: ${PERL_LIBRARY_TYPE} *")
message(STATUS "* zlib: ZLIB *")
message(STATUS "**************************************************")
IF(EQEMU_ADDITIVE_LFIB_PRNG)
ADD_DEFINITIONS(-DUSE_ADDITIVE_LFIB_PRNG)
IF(EQEMU_SFMT19937)
MESSAGE(STATUS "SFMT19937 and ADDITITVE_LFIB_PRNG both set, SFMT19937 ignored.")
SET(EQEMU_SFMT19937 OFF)
ENDIF()
IF(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "")
MESSAGE(STATUS "CUSTOM_PRNG_ENGINE and ADDITITVE_LFIB_PRNG both set, CUSTOM_PRNG_ENGINE ignored.")
SET(EQEMU_CUSTOM_PRNG_ENGINE "")
ENDIF()
ENDIF()
IF(EQEMU_SFMT19937) option(EQEMU_BUILD_LUA "Build Lua parser." ON)
ADD_DEFINITIONS(-DUSE_SFMT19937)
IF(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "")
MESSAGE(STATUS "CUSTOM_PRNG_ENGINE and SFMT19937 both set, CUSTOM_PRNG_ENGINE ignored.")
SET(EQEMU_CUSTOM_PRNG_ENGINE "")
ENDIF()
ENDIF()
IF(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "") if(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_CLIENT_FILES)
ADD_DEFINITIONS(-DUSE_CUSTOM_PRNG_ENGINE=${EQEMU_CUSTOM_PRNG_ENGINE}) add_subdirectory(common)
ENDIF() add_subdirectory(libs)
else()
message(FATAL_ERROR "No targets were selected to build, we must build at least one target.")
endif()
IF(EQEMU_BIASED_INT_DIST) if(EQEMU_BUILD_SERVER)
ADD_DEFINITIONS(-DBIASED_INT_DIST) add_subdirectory(shared_memory)
ENDIF() add_subdirectory(world)
add_subdirectory(zone)
add_subdirectory(ucs)
add_subdirectory(queryserv)
add_subdirectory(eqlaunch)
endif()
IF(EQEMU_COMMANDS_LOGGING) if(EQEMU_BUILD_LOGIN)
ADD_DEFINITIONS(-DCOMMANDS_LOGGING) add_subdirectory(loginserver)
ENDIF(EQEMU_COMMANDS_LOGGING) endif()
#database if(EQEMU_BUILD_TESTS)
IF(MySQL_FOUND AND MariaDB_FOUND) add_subdirectory(tests)
SET(DATABASE_LIBRARY_SELECTION MariaDB CACHE STRING "Database library to use: endif()
MySQL
MariaDB"
)
IF(DATABASE_LIBRARY_SELECTION STREQUAL "MySQL") if(EQEMU_BUILD_CLIENT_FILES)
SET(DATABASE_LIBRARY_TYPE " MySQL") add_subdirectory(client_files)
SET(DATABASE_LIBRARY_LIBS ${MySQL_LIBRARIES}) endif()
SET(DATABASE_LIBRARY_INCLUDE ${MySQL_INCLUDE_DIR})
ELSEIF(DATABASE_LIBRARY_SELECTION STREQUAL "MariaDB")
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "Unknown database library set, should be one of: MySQL, MariaDB")
ENDIF()
ELSEIF(MariaDB_FOUND)
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSEIF(MySQL_FOUND)
SET(DATABASE_LIBRARY_TYPE " MySQL")
SET(DATABASE_LIBRARY_LIBS ${MySQL_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MySQL_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "One of MySQL or MariaDB is a required dependency.")
ENDIF()
#security
#prefer openssl to mbedtls (arbitrary)
IF(OpenSSL_FOUND AND MBEDTLS_FOUND)
SET(TLS_LIBRARY_SELECTION OpenSSL CACHE STRING "TLS library to use:
OpenSSL
mbedTLS"
)
IF(TLS_LIBRARY_SELECTION STREQUAL "OpenSSL")
SET(TLS_LIBRARY_TYPE " OpenSSL")
SET(TLS_LIBRARY_ENABLED ON)
SET(TLS_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(TLS_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ADD_DEFINITIONS(-DEQEMU_USE_OPENSSL)
IF(${OPENSSL_VERSION} VERSION_GREATER_EQUAL "1.1.1")
ADD_DEFINITIONS(-DCPPHTTPLIB_OPENSSL_SUPPORT)
ENDIF()
ELSEIF(TLS_LIBRARY_SELECTION STREQUAL "mbedTLS")
SET(TLS_LIBRARY_TYPE " mbedTLS")
SET(TLS_LIBRARY_ENABLED ON)
SET(TLS_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
SET(TLS_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR})
ADD_DEFINITIONS(-DEQEMU_USE_MBEDTLS)
ELSE()
MESSAGE(FATAL_ERROR "Unknown TLS library set, should be one of: OpenSSL, mbedTLS")
ENDIF()
ELSEIF(OpenSSL_FOUND)
SET(TLS_LIBRARY_TYPE " OpenSSL")
SET(TLS_LIBRARY_ENABLED ON)
SET(TLS_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(TLS_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ADD_DEFINITIONS(-DEQEMU_USE_OPENSSL)
IF(${OPENSSL_VERSION} VERSION_GREATER_EQUAL "1.1.1")
ADD_DEFINITIONS(-DCPPHTTPLIB_OPENSSL_SUPPORT)
ENDIF()
ELSEIF(MBEDTLS_FOUND)
SET(TLS_LIBRARY_TYPE " mbedTLS")
SET(TLS_LIBRARY_ENABLED ON)
SET(TLS_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
SET(TLS_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR})
ADD_DEFINITIONS(-DEQEMU_USE_MBEDTLS)
ELSE()
SET(TLS_LIBRARY_TYPE "Disabled")
SET(TLS_LIBRARY_ENABLED OFF)
ENDIF()
IF(SODIUM_FOUND)
SET(SODIUM_LIBRARY_TYPE "Libsodium")
SET(SODIUM_LIBRARY_ENABLED ON)
SET(SODIUM_LIBRARY_LIBS ${SODIUM_LIBRARIES})
SET(SODIUM_LIBRARY_INCLUDE ${SODIUM_INCLUDE_DIRS})
ADD_DEFINITIONS(-DENABLE_SECURITY)
ELSE()
SET(SODIUM_LIBRARY_TYPE " Disabled")
SET(SODIUM_LIBRARY_ENABLED OFF)
ENDIF()
IF(LUAJIT_FOUND AND NOT (EQEMU_PREFER_LUA AND Lua51_FOUND))
SET(LUA_LIBRARY_TYPE " LuaJIT")
SET(LUA_LIBRARY_ENABLED ON)
SET(LUA_LIBRARY_LIBS ${LUAJIT_LIBRARY} luabind)
SET(LUA_LIBRARY_INCLUDE ${LUAJIT_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
ELSEIF(Lua51_FOUND )
SET(LUA_LIBRARY_TYPE " Lua 5.1")
SET(LUA_LIBRARY_ENABLED ON)
SET(LUA_LIBRARY_LIBS ${LUA_LIBRARY} luabind)
SET(LUA_LIBRARY_INCLUDE ${LUA_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
ELSE()
SET(LUA_LIBRARY_TYPE "Disabled")
SET(LUA_LIBRARY_ENABLED OFF)
ENDIF()
IF(PerlLibs_FOUND)
SET(PERL_LIBRARY_TYPE " Perl")
SET(PERL_LIBRARY_ENABLED ON)
SET(PERL_LIBRARY_LIBS ${PERL_LIBRARY})
SET(PERL_LIBRARY_INCLUDE ${PERL_INCLUDE_PATH})
ELSE()
SET(PERL_LIBRARY_TYPE "Disabled")
SET(PERL_LIBRARY_ENABLED OFF)
ENDIF()
#use zlib if exists
IF(ZLIB_FOUND)
OPTION(EQEMU_BUILD_ZLIB "Build internal version of zlib." ON)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_BINARY_DIR}/libs/zlibng")
ELSE()
SET(ZLIB_LIBRARY_TYPE " zlib")
SET(ZLIB_LIBRARY_LIBS ${ZLIB_LIBRARY})
SET(ZLIB_LIBRARY_INCLUDE ${ZLIB_INCLUDE_DIRS})
ENDIF()
ELSE()
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng")
ENDIF()
IF (EQEMU_BUILD_STATIC)
SET(ZLIB_LIBRARY_LIBS libz.a)
ENDIF(EQEMU_BUILD_STATIC)
MESSAGE(STATUS "")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Library Usage *")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Database: ${DATABASE_LIBRARY_TYPE} *")
MESSAGE(STATUS "* TLS: ${TLS_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Sodium: ${SODIUM_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Lua: ${LUA_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Perl: ${PERL_LIBRARY_TYPE} *")
MESSAGE(STATUS "* zlib: ${ZLIB_LIBRARY_TYPE} *")
MESSAGE(STATUS "**************************************************")
#setup server libs and headers
SET(SERVER_LIBS common ${DATABASE_LIBRARY_LIBS} ${ZLIB_LIBRARY_LIBS} ${Boost_LIBRARIES} uv_a fmt RecastNavigation::Detour)
set(FMT_HEADER_ONLY OFF)
INCLUDE_DIRECTORIES(SYSTEM "${DATABASE_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${Boost_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/glm")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cereal/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/fmt/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/libuv/include" )
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DebugUtils/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Detour/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourCrowd/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourTileCache/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Recast/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/websocketpp")
# silence obnoxious deprecation message
ADD_DEFINITIONS(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
IF(TLS_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${TLS_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${TLS_LIBRARY_INCLUDE}")
ENDIF()
IF(SODIUM_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_LIBRARY_INCLUDE}")
ENDIF()
IF(LUA_LIBRARY_ENABLED)
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
SET(ZONE_LIBS ${LUA_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${LUA_LIBRARY_INCLUDE}")
OPTION(EQEMU_SANITIZE_LUA_LIBS "Sanitize Lua Libraries (Remove OS and IO standard libraries from being able to run)." ON)
IF(EQEMU_SANITIZE_LUA_LIBS)
ADD_DEFINITIONS(-DSANITIZE_LUA_LIBS)
ENDIF()
ENDIF()
ENDIF()
IF(PERL_LIBRARY_ENABLED)
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
IF(EQEMU_BUILD_PERL)
SET(SERVER_LIBS ${SERVER_LIBS} ${PERL_LIBRARY_LIBS} perlbind)
INCLUDE_DIRECTORIES(SYSTEM "${PERL_LIBRARY_INCLUDE}")
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ADD_DEFINITIONS(-DPERLBIND_NO_STRICT_SCALAR_TYPES)
IF (UNIX AND EQEMU_BUILD_STATIC)
SET(SERVER_LIBS ${SERVER_LIBS} libcrypt.a)
ENDIF ()
ENDIF()
ENDIF()
IF(WIN32)
SET(SERVER_LIBS ${SERVER_LIBS} "ws2_32" "psapi" "iphlpapi" "userenv")
ENDIF()
IF(UNIX)
SET(SERVER_LIBS ${SERVER_LIBS} ${CMAKE_DL_LIBS} "z" "m" "pthread")
IF(NOT DARWIN)
SET(SERVER_LIBS ${SERVER_LIBS} "rt")
ENDIF()
# Freebsd provides uuids in the C library
IF(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
SET(SERVER_LIBS ${SERVER_LIBS} "uuid")
ENDIF()
ENDIF()
SET(ZONE_LIBS ${ZONE_LIBS} ${SERVER_LIBS})
IF(EQEMU_BUILD_LOGIN AND NOT TLS_LIBRARY_ENABLED)
MESSAGE(FATAL_ERROR "Login server requires a TLS Library to build.")
ENDIF()
IF(EQEMU_BUILD_HC AND NOT TLS_LIBRARY_ENABLED)
MESSAGE(FATAL_ERROR "Headless client requires a TLS Library to build.")
ENDIF()
IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(libs)
ADD_SUBDIRECTORY(submodules/fmt)
ADD_SUBDIRECTORY(submodules/libuv)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_COMPAT ON CACHE BOOL "Compile with zlib compatible API")
SET(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Build test binaries")
ADD_SUBDIRECTORY(libs/zlibng)
ENDIF()
SET(RECASTNAVIGATION_DEMO OFF CACHE BOOL "Build demo")
SET(RECASTNAVIGATION_TESTS OFF CACHE BOOL "Build tests")
SET(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "Build examples")
ADD_SUBDIRECTORY(submodules/recastnavigation)
ENDIF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
IF(EQEMU_BUILD_SERVER)
ADD_SUBDIRECTORY(shared_memory)
ADD_SUBDIRECTORY(world)
ADD_SUBDIRECTORY(zone)
ADD_SUBDIRECTORY(ucs)
ADD_SUBDIRECTORY(queryserv)
ADD_SUBDIRECTORY(eqlaunch)
ENDIF(EQEMU_BUILD_SERVER)
IF(EQEMU_BUILD_LOGIN)
ADD_SUBDIRECTORY(loginserver)
ENDIF(EQEMU_BUILD_LOGIN)
IF(EQEMU_BUILD_HC)
ADD_SUBDIRECTORY(hc)
ENDIF(EQEMU_BUILD_HC)
IF(EQEMU_BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF(EQEMU_BUILD_TESTS)
IF(EQEMU_BUILD_CLIENT_FILES)
ADD_SUBDIRECTORY(client_files)
ENDIF(EQEMU_BUILD_CLIENT_FILES)

View File

@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) cmake_minimum_required(VERSION 3.20)
add_subdirectory(import) add_subdirectory(import)
add_subdirectory(export) add_subdirectory(export)

View File

@ -1,16 +1,16 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20.0)
SET(export_sources set(export_sources
main.cpp main.cpp
) )
SET(export_headers set(export_headers
) )
ADD_EXECUTABLE(export_client_files ${export_sources} ${export_headers}) add_executable(export_client_files ${export_sources} ${export_headers})
INSTALL(TARGETS export_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS export_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
TARGET_LINK_LIBRARIES(export_client_files ${SERVER_LIBS}) target_link_libraries(export_client_files common)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -1,16 +1,16 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20.0)
SET(import_sources set(import_sources
main.cpp main.cpp
) )
SET(import_headers set(import_headers
) )
ADD_EXECUTABLE(import_client_files ${import_sources} ${import_headers}) add_executable(import_client_files ${import_sources} ${import_headers})
INSTALL(TARGETS import_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS import_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
TARGET_LINK_LIBRARIES(import_client_files ${SERVER_LIBS}) target_link_libraries(import_client_files common)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -1,89 +0,0 @@
OPTION(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG "Automatically fetch vcpkg dependencies for MSCV" ON)
OPTION(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL "Automatically fetch perl dependencies for MSCV" ON)
MARK_AS_ADVANCED(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG)
MARK_AS_ADVANCED(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL)
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86 "https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x86.zip")
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64 "https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x64.zip")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86 "http://strawberryperl.com/download/5.24.4.1/strawberry-perl-5.24.4.1-32bit-portable.zip")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64 "http://strawberryperl.com/download/5.24.4.1/strawberry-perl-5.24.4.1-64bit-portable.zip")
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_ZIP "vcpkg-export-x86.zip")
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_ZIP "vcpkg-export-x64.zip")
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_DIR "vcpkg-export-x86")
SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_DIR "vcpkg-export-x64")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86_ZIP "strawberry-perl-5.24.4.1-32bit-portable.zip")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64_ZIP "strawberry-perl-5.24.4.1-64bit-portable.zip")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86_DIR "x86")
SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64_DIR "x64")
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(EQEMU_VCPKG_URL ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64})
SET(EQEMU_PERL_URL ${EQEMU_MSVC_DEPENDENCIES_PERL_X64})
SET(EQEMU_VCPKG_ZIP ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_ZIP})
SET(EQEMU_VCPKG_DIR ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_DIR})
SET(EQEMU_PERL_ZIP ${EQEMU_MSVC_DEPENDENCIES_PERL_X64_ZIP})
SET(EQEMU_PERL_DIR ${EQEMU_MSVC_DEPENDENCIES_PERL_X64_DIR})
ELSE()
SET(EQEMU_VCPKG_URL ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86})
SET(EQEMU_PERL_URL ${EQEMU_MSVC_DEPENDENCIES_PERL_X86})
SET(EQEMU_VCPKG_ZIP ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_ZIP})
SET(EQEMU_VCPKG_DIR ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_DIR})
SET(EQEMU_PERL_ZIP ${EQEMU_MSVC_DEPENDENCIES_PERL_X86_ZIP})
SET(EQEMU_PERL_DIR ${EQEMU_MSVC_DEPENDENCIES_PERL_X86_DIR})
ENDIF()
IF(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG)
MESSAGE(STATUS "Resolving vcpkg dependencies...")
IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP})
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vcpkg)
MESSAGE(STATUS "Downloading existing vcpkg dependencies from releases...")
FILE(DOWNLOAD ${EQEMU_VCPKG_URL} ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS)
LIST(GET DOWNLOAD_STATUS 0 STATUS_CODE)
IF(NOT STATUS_CODE EQUAL 0)
MESSAGE(FATAL_ERROR "Was unable to download dependencies from ${EQEMU_VCPKG_URL}")
ENDIF()
MESSAGE(STATUS "Extracting files...")
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vcpkg
)
ENDIF()
INCLUDE(${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake)
ENDIF()
IF(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL)
MESSAGE(STATUS "Resolving perl dependencies...")
IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP})
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/perl)
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR})
MESSAGE(STATUS "Downloading portable perl...")
FILE(DOWNLOAD ${EQEMU_PERL_URL} ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS)
LIST(GET DOWNLOAD_STATUS 0 STATUS_CODE)
IF(NOT STATUS_CODE EQUAL 0)
MESSAGE(FATAL_ERROR "Was unable to download dependencies from ${EQEMU_PERL_URL}")
ENDIF()
MESSAGE(STATUS "Extracting files...")
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}
)
ENDIF()
SET(PERL_EXECUTABLE ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/bin/perl.exe CACHE FILEPATH "Path to perl program" FORCE)
SET(PERL_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/lib/CORE CACHE PATH "Path to perl include files" FORCE)
SET(PERL_LIBRARY ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/lib/CORE/libperl524.a CACHE FILEPATH "Path to perl library" FORCE)
ENDIF()

View File

@ -1,91 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# Modified from the FindLua51 that comes with CMake
#[=======================================================================[.rst:
FindLua51
---------
Locate Lua51 library This module defines
::
LUA51_FOUND, if false, do not try to link to Lua
LUA_LIBRARIES
LUA_INCLUDE_DIR, where to find lua.h
LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
Note that the expected include convention is
::
#include "lua.h"
and not
::
#include <lua/lua.h>
This is because, the lua location is not standardized and may exist in
locations other than lua/
#]=======================================================================]
find_path(LUA_INCLUDE_DIR lua.h
HINTS
ENV LUA_DIR
PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
)
if(LUA_LIBRARY)
# include the math library for Unix
if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
find_library(LUA_MATH_LIBRARY m)
set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
# For Windows and Mac, don't need to explicitly include the math library
else()
set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
endif()
endif()
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
unset(lua_version_str)
endif()
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
# handle the QUIETLY and REQUIRED arguments and set LUA51_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)

View File

@ -88,4 +88,3 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJit
VERSION_VAR LUAJIT_VERSION_STRING) VERSION_VAR LUAJIT_VERSION_STRING)
mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARIES LUAJIT_LIBRARY LUAJIT_MATH_LIBRARY) mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARIES LUAJIT_LIBRARY LUAJIT_MATH_LIBRARY)

View File

@ -1,87 +0,0 @@
# - Find mariadbclient
#
# -*- cmake -*-
#
# Find the native MariaDB includes and library
#
# MariaDB_INCLUDE_DIR - where to find mysql.h, etc.
# MariaDB_LIBRARIES - List of libraries when using MariaDB.
# MariaDB_FOUND - True if MariaDB found.
# The following can be used as a hint as to where to search:
# MARIADB_ROOT
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Already in cache, be silent
SET(MariaDB_FIND_QUIETLY TRUE)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Include dir
IF(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATHS ${MARIADB_ROOT}/include
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
# Library
SET(MariaDB_NAMES libmariadb)
IF(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATHS ${MARIADB_ROOT}/lib
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES} mariadbclient_r mariadbclient
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND TRUE)
SET(MariaDB_LIBRARIES ${MariaDB_LIBRARY})
ELSE (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND FALSE)
SET(MariaDB_LIBRARIES)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set MariaDB_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MariaDB DEFAULT_MSG MariaDB_LIBRARY MariaDB_INCLUDE_DIR)
IF(MariaDB_FOUND)
SET( MariaDB_LIBRARY_RELEASE ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARY_DEBUG ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARIES ${MariaDB_LIBRARY_RELEASE} ${MariaDB_LIBRARY_DEBUG} )
ELSE(MariaDB_FOUND)
SET( MariaDB_LIBRARIES )
ENDIF(MariaDB_FOUND)
MARK_AS_ADVANCED(
MariaDB_LIBRARY_DEBUG
MariaDB_LIBRARY_RELEASE
MariaDB_INCLUDE_DIR
)

View File

@ -1,87 +0,0 @@
# - Find mysqlclient
#
# -*- cmake -*-
#
# Find the native MySQL includes and library
#
# MySQL_INCLUDE_DIR - where to find mysql.h, etc.
# MySQL_LIBRARIES - List of libraries when using MySQL.
# MySQL_FOUND - True if MySQL found.
# The following can be used as a hint as to where to search:
# MYSQL_ROOT
IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARIES)
# Already in cache, be silent
SET(MySQL_FIND_QUIETLY TRUE)
ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARIES)
# Include dir
IF(MYSQL_ROOT)
FIND_PATH(MySQL_INCLUDE_DIR
NAMES mysql.h
PATHS ${MYSQL_ROOT}/include
PATH_SUFFIXES mysql
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_PATH(MySQL_INCLUDE_DIR
NAMES mysql.h
PATH_SUFFIXES mysql
)
ELSE(MYSQL_ROOT)
FIND_PATH(MySQL_INCLUDE_DIR
NAMES mysql.h
PATH_SUFFIXES mysql
)
ENDIF(MYSQL_ROOT)
# Library
SET(MySQL_NAMES libmysql)
IF(MYSQL_ROOT)
FIND_LIBRARY(MySQL_LIBRARY
NAMES ${MySQL_NAMES}
PATHS ${MYSQL_ROOT}/lib
PATH_SUFFIXES mysql
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_LIBRARY(MySQL_LIBRARY
NAMES ${MySQL_NAMES}
PATH_SUFFIXES mysql
)
ELSE(MYSQL_ROOT)
FIND_LIBRARY(MySQL_LIBRARY
NAMES ${MySQL_NAMES} mysqlclient_r mysqlclient
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64
PATH_SUFFIXES mysql
)
ENDIF(MYSQL_ROOT)
IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
SET(MySQL_FOUND TRUE)
SET( MySQL_LIBRARIES ${MySQL_LIBRARY} )
ELSE (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
SET(MySQL_FOUND FALSE)
SET( MySQL_LIBRARIES )
ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set MySQL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MySQL DEFAULT_MSG MySQL_LIBRARY MySQL_INCLUDE_DIR)
IF(MySQL_FOUND)
SET( MySQL_LIBRARY_RELEASE ${MySQL_LIBRARY} )
SET( MySQL_LIBRARY_DEBUG ${MySQL_LIBRARY} )
SET( MySQL_LIBRARIES ${MySQL_LIBRARY_RELEASE} ${MySQL_LIBRARY_DEBUG} )
ELSE(MySQL_FOUND)
SET( MySQL_LIBRARIES )
ENDIF(MySQL_FOUND)
MARK_AS_ADVANCED(
MySQL_LIBRARY_DEBUG
MySQL_LIBRARY_RELEASE
MySQL_INCLUDE_DIR
)

View File

@ -1,30 +0,0 @@
if (NOT MSVC)
include(FindPkgConfig)
pkg_check_modules(PC_SODIUM "libsodium")
if (NOT PC_SODIUM_FOUND)
pkg_check_modules(PC_SODIUM "sodium")
endif (NOT PC_SODIUM_FOUND)
if (PC_SODIUM_FOUND)
set(SODIUM_INCLUDE_HINTS ${PC_SODIUM_INCLUDE_DIRS} ${PC_SODIUM_INCLUDE_DIRS}/*)
set(SODIUM_LIBRARY_HINTS ${PC_SODIUM_LIBRARY_DIRS} ${PC_SODIUM_LIBRARY_DIRS}/*)
endif()
endif (NOT MSVC)
# some libraries install the headers is a subdirectory of the include dir
# returned by pkg-config, so use a wildcard match to improve chances of finding
# headers and libraries.
find_path(
SODIUM_INCLUDE_DIRS
NAMES sodium.h
HINTS ${SODIUM_INCLUDE_HINTS}
)
find_library(
SODIUM_LIBRARIES
NAMES libsodium sodium
HINTS ${SODIUM_LIBRARY_HINTS}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SODIUM DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
mark_as_advanced(SODIUM_FOUND SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)

View File

@ -1,93 +0,0 @@
# - Try to find mbedTLS
# Once done this will define
#
# Read-Only variables
# MBEDTLS_FOUND - system has mbedTLS
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory
# MBEDTLS_LIBRARIES - Link these to use mbedTLS
# MBEDTLS_LIBRARY - path to mbedTLS library
# MBEDX509_LIBRARY - path to mbedTLS X.509 library
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
#
# Hint
# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
SET(_MBEDTLS_ROOT_HINTS
${MBEDTLS_ROOT_DIR}
ENV MBEDTLS_ROOT_DIR
)
SET(_MBEDTLS_ROOT_HINTS_AND_PATHS
HINTS ${_MBEDTLS_ROOT_HINTS}
PATHS ${_MBEDTLS_ROOT_PATHS}
)
FIND_PATH(MBEDTLS_INCLUDE_DIR
NAMES mbedtls/version.h
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES include
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF()
FIND_LIBRARY(MBEDTLS_LIBRARY
NAMES mbedtls libmbedtls
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDX509_LIBRARY
NAMES mbedx509 libmbedx509
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY
NAMES mbedcrypto libmbedcrypto
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE)
ENDIF()
IF(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH)
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
ELSE(MBEDTLS_FOUND)
IF(MBEDTLS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
MARK_AS_ADVANCED(
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY
MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY
)

View File

@ -1,6 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20.0)
SET(common_sources set(common_sources
base_packet.cpp base_packet.cpp
bazaar.cpp bazaar.cpp
bodytypes.cpp bodytypes.cpp
@ -16,10 +16,8 @@ SET(common_sources
database/database_dump_service.cpp database/database_dump_service.cpp
database.cpp database.cpp
database_instances.cpp database_instances.cpp
database/database_update_manifest.cpp
database/database_update_manifest_custom.cpp
database/database_update_manifest_bots.cpp
database/database_update.cpp database/database_update.cpp
data_bucket.cpp
dbcore.cpp dbcore.cpp
deity.cpp deity.cpp
dynamic_zone_base.cpp dynamic_zone_base.cpp
@ -92,6 +90,8 @@ SET(common_sources
spdat.cpp spdat.cpp
spdat_bot.cpp spdat_bot.cpp
strings.cpp strings.cpp
strings_legacy.cpp
strings_misc.cpp
struct_strategy.cpp struct_strategy.cpp
textures.cpp textures.cpp
timer.cpp timer.cpp
@ -132,7 +132,7 @@ SET(common_sources
util/directory.cpp util/directory.cpp
util/uuid.cpp) util/uuid.cpp)
SET(repositories set(repositories
# Criteria # Criteria
repositories/criteria/content_filter_criteria.h repositories/criteria/content_filter_criteria.h
@ -531,10 +531,9 @@ SET(repositories
repositories/veteran_reward_templates_repository.h repositories/veteran_reward_templates_repository.h
repositories/zone_repository.h repositories/zone_repository.h
repositories/zone_points_repository.h repositories/zone_points_repository.h
) )
SET(common_headers set(common_headers
additive_lagged_fibonacci_engine.h additive_lagged_fibonacci_engine.h
bazaar.h bazaar.h
base_packet.h base_packet.h
@ -555,6 +554,10 @@ SET(common_headers
database.h database.h
database_schema.h database_schema.h
database/database_update.h database/database_update.h
database/database_update_manifest.h
database/database_update_manifest_custom.h
database/database_update_manifest_bots.h
data_bucket.cpp
dbcore.h dbcore.h
deity.h deity.h
discord/discord.h discord/discord.h
@ -723,19 +726,19 @@ SET(common_headers
util/uuid.h util/uuid.h
) )
SOURCE_GROUP(Event FILES source_group(Event FILES
event/event_loop.h event/event_loop.h
event/timer.h event/timer.h
event/task.h event/task.h
) )
SOURCE_GROUP(Json FILES source_group(Json FILES
json/json.h json/json.h
json/jsoncpp.cpp json/jsoncpp.cpp
json/json-forwards.h json/json-forwards.h
) )
SOURCE_GROUP(Net FILES source_group(Net FILES
net/console_server.cpp net/console_server.cpp
net/console_server.h net/console_server.h
net/console_server_connection.cpp net/console_server_connection.cpp
@ -774,7 +777,7 @@ SOURCE_GROUP(Net FILES
net/websocket_server_connection.h net/websocket_server_connection.h
) )
SOURCE_GROUP(Patches FILES source_group(Patches FILES
patches/patches.h patches/patches.h
patches/sod.h patches/sod.h
patches/sod_limits.h patches/sod_limits.h
@ -818,12 +821,413 @@ SOURCE_GROUP(Patches FILES
patches/uf_limits.cpp patches/uf_limits.cpp
) )
SOURCE_GROUP(StackWalker FILES source_group(Repositories FILES
# Criteria
repositories/criteria/content_filter_criteria.h
repositories/base/base_grid_repository.h
repositories/base/base_grid_entries_repository.h
# Base Repositories
repositories/base/base_aa_ability_repository.h
repositories/base/base_aa_ranks_repository.h
repositories/base/base_aa_rank_effects_repository.h
repositories/base/base_aa_rank_prereqs_repository.h
repositories/base/base_account_repository.h
repositories/base/base_account_flags_repository.h
repositories/base/base_account_ip_repository.h
repositories/base/base_account_rewards_repository.h
repositories/base/base_adventure_details_repository.h
repositories/base/base_adventure_members_repository.h
repositories/base/base_adventure_stats_repository.h
repositories/base/base_adventure_template_repository.h
repositories/base/base_adventure_template_entry_repository.h
repositories/base/base_adventure_template_entry_flavor_repository.h
repositories/base/base_alternate_currency_repository.h
repositories/base/base_auras_repository.h
repositories/base/base_base_data_repository.h
repositories/base/base_blocked_spells_repository.h
repositories/base/base_books_repository.h
repositories/base/base_bugs_repository.h
repositories/base/base_bug_reports_repository.h
repositories/base/base_buyer_repository.h
repositories/base/base_buyer_trade_items_repository.h
repositories/base/base_character_activities_repository.h
repositories/base/base_character_alternate_abilities_repository.h
repositories/base/base_character_alt_currency_repository.h
repositories/base/base_character_auras_repository.h
repositories/base/base_character_bandolier_repository.h
repositories/base/base_character_bind_repository.h
repositories/base/base_character_buffs_repository.h
repositories/base/base_character_corpses_repository.h
repositories/base/base_character_corpse_items_repository.h
repositories/base/base_character_currency_repository.h
repositories/base/base_character_data_repository.h
repositories/base/base_character_disciplines_repository.h
repositories/base/base_character_evolving_items_repository.h
repositories/base/base_character_expedition_lockouts_repository.h
repositories/base/base_character_exp_modifiers_repository.h
repositories/base/base_character_inspect_messages_repository.h
repositories/base/base_character_instance_safereturns_repository.h
repositories/base/base_character_item_recast_repository.h
repositories/base/base_character_languages_repository.h
repositories/base/base_character_leadership_abilities_repository.h
repositories/base/base_character_material_repository.h
repositories/base/base_character_memmed_spells_repository.h
repositories/base/base_character_parcels_repository.h
repositories/base/base_character_parcels_containers_repository.h
repositories/base/base_character_peqzone_flags_repository.h
repositories/base/base_character_pet_buffs_repository.h
repositories/base/base_character_pet_info_repository.h
repositories/base/base_character_pet_inventory_repository.h
repositories/base/base_character_potionbelt_repository.h
repositories/base/base_character_skills_repository.h
repositories/base/base_character_spells_repository.h
repositories/base/base_character_tasks_repository.h
repositories/base/base_character_task_timers_repository.h
repositories/base/base_char_create_combinations_repository.h
repositories/base/base_char_create_point_allocations_repository.h
repositories/base/base_char_recipe_list_repository.h
repositories/base/base_chatchannels_repository.h
repositories/base/base_chatchannel_reserved_names_repository.h
repositories/base/base_completed_shared_tasks_repository.h
repositories/base/base_completed_shared_task_activity_state_repository.h
repositories/base/base_completed_shared_task_members_repository.h
repositories/base/base_completed_tasks_repository.h
repositories/base/base_content_flags_repository.h
repositories/base/base_damageshieldtypes_repository.h
repositories/base/base_data_buckets_repository.h
repositories/base/base_db_str_repository.h
repositories/base/base_discord_webhooks_repository.h
repositories/base/base_discovered_items_repository.h
repositories/base/base_doors_repository.h
repositories/base/base_dynamic_zones_repository.h
repositories/base/base_dynamic_zone_lockouts_repository.h
repositories/base/base_dynamic_zone_members_repository.h
repositories/base/base_dynamic_zone_templates_repository.h
repositories/base/base_faction_association_repository.h
repositories/base/base_faction_base_data_repository.h
repositories/base/base_faction_list_repository.h
repositories/base/base_faction_list_mod_repository.h
repositories/base/base_faction_values_repository.h
repositories/base/base_fishing_repository.h
repositories/base/base_forage_repository.h
repositories/base/base_friends_repository.h
repositories/base/base_global_loot_repository.h
repositories/base/base_gm_ips_repository.h
repositories/base/base_graveyard_repository.h
repositories/base/base_ground_spawns_repository.h
repositories/base/base_group_id_repository.h
repositories/base/base_group_leaders_repository.h
repositories/base/base_guilds_repository.h
repositories/base/base_guild_ranks_repository.h
repositories/base/base_guild_permissions_repository.h
repositories/base/base_guild_members_repository.h
repositories/base/base_guild_bank_repository.h
repositories/base/base_guild_relations_repository.h
repositories/base/base_horses_repository.h
repositories/base/base_instance_list_repository.h
repositories/base/base_instance_list_player_repository.h
repositories/base/base_inventory_repository.h
repositories/base/base_inventory_snapshots_repository.h
repositories/base/base_ip_exemptions_repository.h
repositories/base/base_items_repository.h
repositories/base/base_items_evolving_details_repository.h
repositories/base/base_ldon_trap_entries_repository.h
repositories/base/base_ldon_trap_templates_repository.h
repositories/base/base_level_exp_mods_repository.h
repositories/base/base_lfguild_repository.h
repositories/base/base_login_accounts_repository.h
repositories/base/base_login_api_tokens_repository.h
repositories/base/base_login_server_admins_repository.h
repositories/base/base_login_server_list_types_repository.h
repositories/base/base_login_world_servers_repository.h
repositories/base/base_logsys_categories_repository.h
repositories/base/base_lootdrop_repository.h
repositories/base/base_lootdrop_entries_repository.h
repositories/base/base_loottable_repository.h
repositories/base/base_loottable_entries_repository.h
repositories/base/base_mail_repository.h
repositories/base/base_merchantlist_repository.h
repositories/base/base_merchantlist_temp_repository.h
repositories/base/base_name_filter_repository.h
repositories/base/base_npc_emotes_repository.h
repositories/base/base_npc_faction_repository.h
repositories/base/base_npc_faction_entries_repository.h
repositories/base/base_npc_scale_global_base_repository.h
repositories/base/base_npc_spells_repository.h
repositories/base/base_npc_spells_effects_repository.h
repositories/base/base_npc_spells_effects_entries_repository.h
repositories/base/base_npc_spells_entries_repository.h
repositories/base/base_npc_types_repository.h
repositories/base/base_npc_types_tint_repository.h
repositories/base/base_object_repository.h
repositories/base/base_object_contents_repository.h
repositories/base/base_perl_event_export_settings_repository.h
repositories/base/base_petitions_repository.h
repositories/base/base_pets_repository.h
repositories/base/base_pets_beastlord_data_repository.h
repositories/base/base_pets_equipmentset_repository.h
repositories/base/base_pets_equipmentset_entries_repository.h
repositories/base/base_player_titlesets_repository.h
repositories/base/base_player_event_aa_purchase_repository.h
repositories/base/base_player_event_killed_npc_repository.h
repositories/base/base_player_event_killed_named_npc_repository.h
repositories/base/base_player_event_killed_raid_npc_repository.h
repositories/base/base_player_event_log_settings_repository.h
repositories/base/base_player_event_logs_repository.h
repositories/base/base_player_event_loot_items_repository.h
repositories/base/base_player_event_merchant_purchase_repository.h
repositories/base/base_player_event_merchant_sell_repository.h
repositories/base/base_player_event_npc_handin_repository.h
repositories/base/base_player_event_npc_handin_entries_repository.h
repositories/base/base_player_event_speech_repository.h
repositories/base/base_player_event_trade_repository.h
repositories/base/base_player_event_trade_entries_repository.h
repositories/base/base_quest_globals_repository.h
repositories/base/base_raid_details_repository.h
repositories/base/base_raid_members_repository.h
repositories/base/base_reports_repository.h
repositories/base/base_respawn_times_repository.h
repositories/base/base_rule_sets_repository.h
repositories/base/base_rule_values_repository.h
repositories/base/base_saylink_repository.h
repositories/base/base_server_scheduled_events_repository.h
repositories/base/base_shared_tasks_repository.h
repositories/base/base_shared_task_activity_state_repository.h
repositories/base/base_shared_task_dynamic_zones_repository.h
repositories/base/base_shared_task_members_repository.h
repositories/base/base_skill_caps_repository.h
repositories/base/base_spawn2_repository.h
repositories/base/base_spawnentry_repository.h
repositories/base/base_spawngroup_repository.h
repositories/base/base_spawn_conditions_repository.h
repositories/base/base_spawn_condition_values_repository.h
repositories/base/base_spawn_events_repository.h
repositories/base/base_spells_new_repository.h
repositories/base/base_spell_buckets_repository.h
repositories/base/base_spell_globals_repository.h
repositories/base/base_starting_items_repository.h
repositories/base/base_start_zones_repository.h
repositories/base/base_tasks_repository.h
repositories/base/base_tasksets_repository.h
repositories/base/base_task_activities_repository.h
repositories/base/base_timers_repository.h
repositories/base/base_titles_repository.h
repositories/base/base_trader_repository.h
repositories/base/base_tradeskill_recipe_repository.h
repositories/base/base_tradeskill_recipe_entries_repository.h
repositories/base/base_traps_repository.h
repositories/base/base_tributes_repository.h
repositories/base/base_tribute_levels_repository.h
repositories/base/base_veteran_reward_templates_repository.h
repositories/base/base_zone_repository.h
repositories/base/base_zone_points_repository.h
# Extended Repositories
repositories/aa_ability_repository.h
repositories/aa_ranks_repository.h
repositories/aa_rank_effects_repository.h
repositories/aa_rank_prereqs_repository.h
repositories/account_repository.h
repositories/account_flags_repository.h
repositories/account_ip_repository.h
repositories/account_rewards_repository.h
repositories/adventure_details_repository.h
repositories/adventure_members_repository.h
repositories/adventure_stats_repository.h
repositories/adventure_template_repository.h
repositories/adventure_template_entry_repository.h
repositories/adventure_template_entry_flavor_repository.h
repositories/alternate_currency_repository.h
repositories/auras_repository.h
repositories/base_data_repository.h
repositories/blocked_spells_repository.h
repositories/books_repository.h
repositories/bugs_repository.h
repositories/bug_reports_repository.h
repositories/buyer_buy_lines_repository.h
repositories/buyer_trade_items_repository.h
repositories/character_activities_repository.h
repositories/character_alternate_abilities_repository.h
repositories/character_alt_currency_repository.h
repositories/character_auras_repository.h
repositories/character_bandolier_repository.h
repositories/character_bind_repository.h
repositories/character_buffs_repository.h
repositories/character_corpses_repository.h
repositories/character_corpse_items_repository.h
repositories/character_currency_repository.h
repositories/character_data_repository.h
repositories/character_disciplines_repository.h
repositories/character_evolving_items_repository.h
repositories/character_expedition_lockouts_repository.h
repositories/character_exp_modifiers_repository.h
repositories/character_inspect_messages_repository.h
repositories/character_instance_safereturns_repository.h
repositories/character_item_recast_repository.h
repositories/character_languages_repository.h
repositories/character_leadership_abilities_repository.h
repositories/character_material_repository.h
repositories/character_memmed_spells_repository.h
repositories/character_parcels_repository.h
repositories/character_parcels_containers_repository.h
repositories/character_peqzone_flags_repository.h
repositories/character_pet_buffs_repository.h
repositories/character_pet_info_repository.h
repositories/character_pet_inventory_repository.h
repositories/character_potionbelt_repository.h
repositories/character_skills_repository.h
repositories/character_spells_repository.h
repositories/character_tasks_repository.h
repositories/character_task_timers_repository.h
repositories/char_create_combinations_repository.h
repositories/char_create_point_allocations_repository.h
repositories/char_recipe_list_repository.h
repositories/chatchannels_repository.h
repositories/chatchannel_reserved_names_repository.h
repositories/completed_shared_tasks_repository.h
repositories/completed_shared_task_activity_state_repository.h
repositories/completed_shared_task_members_repository.h
repositories/completed_tasks_repository.h
repositories/content_flags_repository.h
repositories/damageshieldtypes_repository.h
repositories/data_buckets_repository.h
repositories/db_str_repository.h
repositories/discord_webhooks_repository.h
repositories/discovered_items_repository.h
repositories/doors_repository.h
repositories/dynamic_zones_repository.h
repositories/dynamic_zone_lockouts_repository.h
repositories/dynamic_zone_members_repository.h
repositories/dynamic_zone_templates_repository.h
repositories/faction_association_repository.h
repositories/faction_base_data_repository.h
repositories/faction_list_repository.h
repositories/faction_list_mod_repository.h
repositories/faction_values_repository.h
repositories/fishing_repository.h
repositories/forage_repository.h
repositories/friends_repository.h
repositories/global_loot_repository.h
repositories/gm_ips_repository.h
repositories/graveyard_repository.h
repositories/ground_spawns_repository.h
repositories/group_id_repository.h
repositories/group_leaders_repository.h
repositories/guilds_repository.h
repositories/guild_ranks_repository.h
repositories/guild_permissions_repository.h
repositories/guild_members_repository.h
repositories/guild_bank_repository.h
repositories/guild_relations_repository.h
repositories/horses_repository.h
repositories/instance_list_repository.h
repositories/instance_list_player_repository.h
repositories/inventory_repository.h
repositories/inventory_snapshots_repository.h
repositories/ip_exemptions_repository.h
repositories/items_repository.h
repositories/items_evolving_details_repository.h
repositories/ldon_trap_entries_repository.h
repositories/ldon_trap_templates_repository.h
repositories/level_exp_mods_repository.h
repositories/lfguild_repository.h
repositories/login_accounts_repository.h
repositories/login_api_tokens_repository.h
repositories/login_server_admins_repository.h
repositories/login_server_list_types_repository.h
repositories/login_world_servers_repository.h
repositories/logsys_categories_repository.h
repositories/lootdrop_repository.h
repositories/lootdrop_entries_repository.h
repositories/loottable_repository.h
repositories/loottable_entries_repository.h
repositories/mail_repository.h
repositories/merchantlist_repository.h
repositories/merchantlist_temp_repository.h
repositories/name_filter_repository.h
repositories/npc_emotes_repository.h
repositories/npc_faction_repository.h
repositories/npc_faction_entries_repository.h
repositories/npc_scale_global_base_repository.h
repositories/npc_spells_repository.h
repositories/npc_spells_effects_repository.h
repositories/npc_spells_effects_entries_repository.h
repositories/npc_spells_entries_repository.h
repositories/npc_types_repository.h
repositories/npc_types_tint_repository.h
repositories/object_repository.h
repositories/object_contents_repository.h
repositories/perl_event_export_settings_repository.h
repositories/petitions_repository.h
repositories/pets_repository.h
repositories/pets_beastlord_data_repository.h
repositories/pets_equipmentset_repository.h
repositories/pets_equipmentset_entries_repository.h
repositories/player_titlesets_repository.h
repositories/player_event_aa_purchase_repository.h
repositories/player_event_killed_npc_repository.h
repositories/player_event_killed_named_npc_repository.h
repositories/player_event_killed_raid_npc_repository.h
repositories/player_event_log_settings_repository.h
repositories/player_event_logs_repository.h
repositories/player_event_loot_items_repository.h
repositories/player_event_merchant_purchase_repository.h
repositories/player_event_merchant_sell_repository.h
repositories/player_event_npc_handin_repository.h
repositories/player_event_npc_handin_entries_repository.h
repositories/player_event_speech_repository.h
repositories/player_event_trade_repository.h
repositories/player_event_trade_entries_repository.h
repositories/quest_globals_repository.h
repositories/raid_details_repository.h
repositories/raid_members_repository.h
repositories/reports_repository.h
repositories/respawn_times_repository.h
repositories/rule_sets_repository.h
repositories/rule_values_repository.h
repositories/saylink_repository.h
repositories/server_scheduled_events_repository.h
repositories/shared_tasks_repository.h
repositories/shared_task_activity_state_repository.h
repositories/shared_task_dynamic_zones_repository.h
repositories/shared_task_members_repository.h
repositories/skill_caps_repository.h
repositories/spawn2_repository.h
repositories/spawnentry_repository.h
repositories/spawngroup_repository.h
repositories/spawn_conditions_repository.h
repositories/spawn_condition_values_repository.h
repositories/spawn_events_repository.h
repositories/spells_new_repository.h
repositories/spell_buckets_repository.h
repositories/spell_globals_repository.h
repositories/starting_items_repository.h
repositories/start_zones_repository.h
repositories/tasks_repository.h
repositories/tasksets_repository.h
repositories/task_activities_repository.h
repositories/timers_repository.h
repositories/titles_repository.h
repositories/trader_repository.h
repositories/tradeskill_recipe_repository.h
repositories/tradeskill_recipe_entries_repository.h
repositories/traps_repository.h
repositories/tributes_repository.h
repositories/tribute_levels_repository.h
repositories/veteran_reward_templates_repository.h
repositories/zone_repository.h
repositories/zone_points_repository.h
)
source_group(StackWalker FILES
StackWalker/StackWalker.h StackWalker/StackWalker.h
StackWalker/StackWalker.cpp StackWalker/StackWalker.cpp
) )
SOURCE_GROUP(Util FILES source_group(Util FILES
util/memory_stream.h util/memory_stream.h
util/directory.cpp util/directory.cpp
util/directory.h util/directory.h
@ -831,22 +1235,78 @@ SOURCE_GROUP(Util FILES
util/uuid.h util/uuid.h
) )
INCLUDE_DIRECTORIES(Patches SocketLib StackWalker) option(EQEMU_ADD_PROFILER "Link with Google perftools profiler" OFF)
#PRNG options
option(EQEMU_ADDITIVE_LFIB_PRNG "Use Additive LFib for PRNG." OFF)
mark_as_advanced(EQEMU_ADDITIVE_LFIB_PRNG)
option(EQEMU_BIASED_INT_DIST "Use biased int dist instead of uniform." OFF)
mark_as_advanced(EQEMU_BIASED_INT_DIST)
set(EQEMU_CUSTOM_PRNG_ENGINE "" CACHE STRING "Custom random engine. (ex. std::default_random_engine)")
mark_as_advanced(EQEMU_CUSTOM_PRNG_ENGINE)
ADD_LIBRARY(common ${common_sources} ${common_headers} ${repositories}) if(CMAKE_COMPILER_IS_GNUCXX)
option(EQEMU_SFMT19937 "Use GCC's extention for SIMD Fast MT19937." OFF)
mark_as_advanced(EQEMU_SFMT19937)
endif()
IF (UNIX) include_directories(Patches SocketLib StackWalker)
SET_SOURCE_FILES_PROPERTIES("SocketLib/Mime.cpp" PROPERTY COMPILE_FLAGS -Wno-unused-result)
SET_SOURCE_FILES_PROPERTIES("patches/sod.cpp" "patches/sof.cpp" "patches/rof.cpp" "patches/rof2.cpp" "patches/uf.cpp" PROPERTIES COMPILE_FLAGS -O0)
ENDIF (UNIX)
IF (EQEMU_BUILD_PCH) add_library(common ${common_sources} ${common_headers} ${repositories})
target_compile_definitions(common PUBLIC BOOST_BIND_GLOBAL_PLACEHOLDERS GLM_FORCE_RADIANS GLM_FORCE_CTOR_INIT GLM_ENABLE_EXPERIMENTAL)
target_include_directories(common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../submodules/websocketpp")
target_link_libraries(common PUBLIC cereal::cereal fmt::fmt unofficial::libmariadb $<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv> OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
# Requires libgoogle-perftools-dev google-perftools packages for linux (debian)
if(EQEMU_ADD_PROFILER)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed,-lprofiler,--as-needed")
endif()
if(EQEMU_ADDITIVE_LFIB_PRNG)
target_compile_definitions(common PUBLIC USE_ADDITIVE_LFIB_PRNG)
if(EQEMU_SFMT19937)
message(STATUS "SFMT19937 and ADDITITVE_LFIB_PRNG both set, SFMT19937 ignored.")
set(EQEMU_SFMT19937 OFF)
endif()
if(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "")
message(STATUS "CUSTOM_PRNG_ENGINE and ADDITITVE_LFIB_PRNG both set, CUSTOM_PRNG_ENGINE ignored.")
set(EQEMU_CUSTOM_PRNG_ENGINE "")
endif()
endif()
if(EQEMU_SFMT19937)
target_compile_definitions(common PUBLIC USE_SFMT19937)
if(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "")
message(STATUS "CUSTOM_PRNG_ENGINE and SFMT19937 both set, CUSTOM_PRNG_ENGINE ignored.")
set(EQEMU_CUSTOM_PRNG_ENGINE "")
endif()
endif()
if(NOT EQEMU_CUSTOM_PRNG_ENGINE STREQUAL "")
target_compile_definitions(common PUBLIC USE_CUSTOM_PRNG_ENGINE=${EQEMU_CUSTOM_PRNG_ENGINE})
endif()
if(EQEMU_BIASED_INT_DIST)
target_compile_definitions(common PUBLIC BIASED_INT_DIST)
endif()
if(${OPENSSL_VERSION} VERSION_GREATER_EQUAL "1.1.1")
target_compile_definitions(common PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT)
endif()
if(UNIX)
target_link_libraries(common PUBLIC uuid)
set_source_files_properties("SocketLib/Mime.cpp" PROPERTY COMPILE_FLAGS -Wno-unused-result)
set_source_files_properties("patches/sod.cpp" "patches/sof.cpp" "patches/rof.cpp" "patches/rof2.cpp" "patches/uf.cpp" PROPERTIES COMPILE_FLAGS -O0)
endif()
if(EQEMU_BUILD_PCH)
TARGET_PRECOMPILE_HEADERS(common PRIVATE pch/std-pch.h) TARGET_PRECOMPILE_HEADERS(common PRIVATE pch/std-pch.h)
# Avoid PCH/__OPTIMIZE__ mismatch when compiling certain patch sources with -O0 # Avoid PCH/__OPTIMIZE__ mismatch when compiling certain patch sources with -O0
# These files are compiled with -O0 on UNIX (see COMPILE_FLAGS above), which # These files are compiled with -O0 on UNIX (see COMPILE_FLAGS above), which
# disables the __OPTIMIZE__ predefined macro. Disabling PCH for them prevents # disables the __OPTIMIZE__ predefined macro. Disabling PCH for them prevents
# Clang from erroring due to macro state differences between the PCH and TU. # Clang from erroring due to macro state differences between the PCH and TU.
SET_SOURCE_FILES_PROPERTIES("patches/sod.cpp" "patches/sof.cpp" "patches/rof.cpp" "patches/rof2.cpp" "patches/uf.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS ON) set_source_files_properties("patches/sod.cpp" "patches/sof.cpp" "patches/rof.cpp" "patches/rof2.cpp" "patches/uf.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
ENDIF () endif()
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -16,6 +16,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include "../common/global_define.h" #include "../common/global_define.h"
#include "../common/classes.h" #include "../common/classes.h"
#include "data_verification.h" #include "data_verification.h"

View File

@ -19,6 +19,7 @@
*/ */
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include "eqemu_command_handler.h" #include "eqemu_command_handler.h"
#include "terminal_color.hpp" #include "terminal_color.hpp"
#include "../platform.h" #include "../platform.h"

View File

@ -9,17 +9,7 @@ using json = nlohmann::json;
const std::string NESTED_KEY_DELIMITER = "."; const std::string NESTED_KEY_DELIMITER = ".";
std::vector<DataBucketsRepository::DataBuckets> g_data_bucket_cache = {}; std::vector<DataBucketsRepository::DataBuckets> g_data_bucket_cache = {};
#if defined(ZONE) void DataBucket::SetData(SharedDatabase* database, const std::string &bucket_key, const std::string &bucket_value, std::string expires_time)
#include "../zone/zonedb.h"
extern ZoneDatabase database;
#elif defined(WORLD)
#include "../world/worlddb.h"
extern WorldDatabase database;
#else
#error "You must define either ZONE or WORLD"
#endif
void DataBucket::SetData(const std::string &bucket_key, const std::string &bucket_value, std::string expires_time)
{ {
auto k = DataBucketKey{ auto k = DataBucketKey{
.key = bucket_key, .key = bucket_key,
@ -27,10 +17,10 @@ void DataBucket::SetData(const std::string &bucket_key, const std::string &bucke
.expires = expires_time, .expires = expires_time,
}; };
DataBucket::SetData(k); DataBucket::SetData(database, k);
} }
void DataBucket::SetData(const DataBucketKey &k_) void DataBucket::SetData(SharedDatabase *database, const DataBucketKey &k_)
{ {
DataBucketKey k = k_; // copy the key so we can modify it DataBucketKey k = k_; // copy the key so we can modify it
bool is_nested = k.key.find(NESTED_KEY_DELIMITER) != std::string::npos; bool is_nested = k.key.find(NESTED_KEY_DELIMITER) != std::string::npos;
@ -39,7 +29,7 @@ void DataBucket::SetData(const DataBucketKey &k_)
} }
auto b = DataBucketsRepository::NewEntity(); auto b = DataBucketsRepository::NewEntity();
auto r = GetData(k, true); auto r = GetData(database, k, true);
// if we have an entry, use it // if we have an entry, use it
if (r.id > 0) { if (r.id > 0) {
b = r; b = r;
@ -149,10 +139,10 @@ void DataBucket::SetData(const DataBucketKey &k_)
} }
} }
DataBucketsRepository::UpdateOne(database, b); DataBucketsRepository::UpdateOne(*database, b);
} }
else { else {
b = DataBucketsRepository::InsertOne(database, b); b = DataBucketsRepository::InsertOne(*database, b);
// add to cache if it doesn't exist // add to cache if it doesn't exist
if (CanCache(k) && !ExistsInCache(b)) { if (CanCache(k) && !ExistsInCache(b)) {
@ -162,9 +152,9 @@ void DataBucket::SetData(const DataBucketKey &k_)
} }
} }
std::string DataBucket::GetData(const std::string &bucket_key) std::string DataBucket::GetData(SharedDatabase* database, const std::string &bucket_key)
{ {
return GetData(DataBucketKey{.key = bucket_key}).value; return GetData(database, DataBucketKey{.key = bucket_key}).value;
} }
DataBucketsRepository::DataBuckets DataBucket::ExtractNestedValue( DataBucketsRepository::DataBuckets DataBucket::ExtractNestedValue(
@ -214,7 +204,7 @@ DataBucketsRepository::DataBuckets DataBucket::ExtractNestedValue(
// if the bucket doesn't exist, it will be added to the cache as a miss // if the bucket doesn't exist, it will be added to the cache as a miss
// if ignore_misses_cache is true, the bucket will not be added to the cache as a miss // if ignore_misses_cache is true, the bucket will not be added to the cache as a miss
// the only place we should be ignoring the misses cache is on the initial read during SetData // the only place we should be ignoring the misses cache is on the initial read during SetData
DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_, bool ignore_misses_cache) DataBucketsRepository::DataBuckets DataBucket::GetData(SharedDatabase* database, const DataBucketKey &k_, bool ignore_misses_cache)
{ {
DataBucketKey k = k_; // Copy the key so we can modify it DataBucketKey k = k_; // Copy the key so we can modify it
@ -244,7 +234,7 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_,
if (CheckBucketMatch(e, k)) { if (CheckBucketMatch(e, k)) {
if (e.expires > 0 && e.expires < std::time(nullptr)) { if (e.expires > 0 && e.expires < std::time(nullptr)) {
LogDataBuckets("Attempted to read expired key [{}] removing from cache", e.key_); LogDataBuckets("Attempted to read expired key [{}] removing from cache", e.key_);
DeleteData(k); DeleteData(database, k);
return DataBucketsRepository::NewEntity(); return DataBucketsRepository::NewEntity();
} }
@ -261,7 +251,7 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_,
// Fetch the value from the database // Fetch the value from the database
auto r = DataBucketsRepository::GetWhere( auto r = DataBucketsRepository::GetWhere(
database, *database,
fmt::format( fmt::format(
" {} `key` = '{}' LIMIT 1", " {} `key` = '{}' LIMIT 1",
DataBucket::GetScopedDbFilters(k), DataBucket::GetScopedDbFilters(k),
@ -310,7 +300,7 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_,
// If the entry has expired, delete it // If the entry has expired, delete it
if (bucket.expires > 0 && bucket.expires < static_cast<long long>(std::time(nullptr))) { if (bucket.expires > 0 && bucket.expires < static_cast<long long>(std::time(nullptr))) {
DeleteData(k); DeleteData(database, k);
return DataBucketsRepository::NewEntity(); return DataBucketsRepository::NewEntity();
} }
@ -337,22 +327,22 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_,
return bucket; return bucket;
} }
std::string DataBucket::GetDataExpires(const std::string &bucket_key) std::string DataBucket::GetDataExpires(SharedDatabase* database, const std::string &bucket_key)
{ {
return GetDataExpires(DataBucketKey{.key = bucket_key}); return GetDataExpires(database, DataBucketKey{.key = bucket_key});
} }
std::string DataBucket::GetDataRemaining(const std::string &bucket_key) std::string DataBucket::GetDataRemaining(SharedDatabase* database, const std::string &bucket_key)
{ {
return GetDataRemaining(DataBucketKey{.key = bucket_key}); return GetDataRemaining(database, DataBucketKey{.key = bucket_key});
} }
bool DataBucket::DeleteData(const std::string &bucket_key) bool DataBucket::DeleteData(SharedDatabase* database, const std::string &bucket_key)
{ {
return DeleteData(DataBucketKey{.key = bucket_key}); return DeleteData(database, DataBucketKey{.key = bucket_key});
} }
bool DataBucket::DeleteData(const DataBucketKey &k) bool DataBucket::DeleteData(SharedDatabase* database, const DataBucketKey &k)
{ {
bool is_nested_key = k.key.find(NESTED_KEY_DELIMITER) != std::string::npos; bool is_nested_key = k.key.find(NESTED_KEY_DELIMITER) != std::string::npos;
@ -374,7 +364,7 @@ bool DataBucket::DeleteData(const DataBucketKey &k)
// Regular key deletion, no nesting involved // Regular key deletion, no nesting involved
return DataBucketsRepository::DeleteWhere( return DataBucketsRepository::DeleteWhere(
database, *database,
fmt::format("{} `key` = '{}'", DataBucket::GetScopedDbFilters(k), k.key) fmt::format("{} `key` = '{}'", DataBucket::GetScopedDbFilters(k), k.key)
); );
} }
@ -384,7 +374,7 @@ bool DataBucket::DeleteData(const DataBucketKey &k)
DataBucketKey top_level_k = k; DataBucketKey top_level_k = k;
top_level_k.key = top_level_key; top_level_k.key = top_level_key;
auto r = GetData(top_level_k); auto r = GetData(database, top_level_k);
if (r.id == 0 || r.value.empty() || !Strings::IsValidJson(r.value)) { if (r.id == 0 || r.value.empty() || !Strings::IsValidJson(r.value)) {
LogDataBuckets("Attempted to delete nested key [{}] but parent key [{}] does not exist or is invalid JSON", k.key, top_level_key); LogDataBuckets("Attempted to delete nested key [{}] but parent key [{}] does not exist or is invalid JSON", k.key, top_level_key);
return false; return false;
@ -444,14 +434,14 @@ bool DataBucket::DeleteData(const DataBucketKey &k)
} }
return DataBucketsRepository::DeleteWhere( return DataBucketsRepository::DeleteWhere(
database, *database,
fmt::format("{} `key` = '{}'", DataBucket::GetScopedDbFilters(k), top_level_key) fmt::format("{} `key` = '{}'", DataBucket::GetScopedDbFilters(k), top_level_key)
); );
} }
// Otherwise, update the existing JSON without the deleted key // Otherwise, update the existing JSON without the deleted key
r.value = json_value.dump(); r.value = json_value.dump();
DataBucketsRepository::UpdateOne(database, r); DataBucketsRepository::UpdateOne(*database, r);
// Update cache // Update cache
if (CanCache(k)) { if (CanCache(k)) {
@ -466,7 +456,7 @@ bool DataBucket::DeleteData(const DataBucketKey &k)
return true; return true;
} }
std::string DataBucket::GetDataExpires(const DataBucketKey &k) std::string DataBucket::GetDataExpires(SharedDatabase* database, const DataBucketKey &k)
{ {
LogDataBuckets( LogDataBuckets(
"Getting bucket expiration key [{}] bot_id [{}] account_id [{}] character_id [{}] npc_id [{}]", "Getting bucket expiration key [{}] bot_id [{}] account_id [{}] character_id [{}] npc_id [{}]",
@ -477,7 +467,7 @@ std::string DataBucket::GetDataExpires(const DataBucketKey &k)
k.npc_id k.npc_id
); );
auto r = GetData(k); auto r = GetData(database, k);
if (r.id == 0) { if (r.id == 0) {
return {}; return {};
} }
@ -485,7 +475,7 @@ std::string DataBucket::GetDataExpires(const DataBucketKey &k)
return std::to_string(r.expires); return std::to_string(r.expires);
} }
std::string DataBucket::GetDataRemaining(const DataBucketKey &k) std::string DataBucket::GetDataRemaining(SharedDatabase* database, const DataBucketKey &k)
{ {
LogDataBuckets( LogDataBuckets(
"Getting bucket remaining key [{}] bot_id [{}] account_id [{}] character_id [{}] npc_id [{}] bot_id [{}] zone_id [{}] instance_id [{}]", "Getting bucket remaining key [{}] bot_id [{}] account_id [{}] character_id [{}] npc_id [{}] bot_id [{}] zone_id [{}] instance_id [{}]",
@ -499,7 +489,7 @@ std::string DataBucket::GetDataRemaining(const DataBucketKey &k)
k.instance_id k.instance_id
); );
auto r = GetData(k); auto r = GetData(database, k);
if (r.id == 0) { if (r.id == 0) {
return "0"; return "0";
} }
@ -565,10 +555,10 @@ bool DataBucket::CheckBucketMatch(const DataBucketsRepository::DataBuckets &dbe,
); );
} }
void DataBucket::LoadZoneCache(uint16 zone_id, uint16 instance_id) void DataBucket::LoadZoneCache(SharedDatabase* database, uint16 zone_id, uint16 instance_id)
{ {
const auto &l = DataBucketsRepository::GetWhere( const auto &l = DataBucketsRepository::GetWhere(
database, *database,
fmt::format( fmt::format(
"zone_id = {} AND instance_id = {} AND (`expires` > {} OR `expires` = 0)", "zone_id = {} AND instance_id = {} AND (`expires` > {} OR `expires` = 0)",
zone_id, zone_id,
@ -608,7 +598,7 @@ void DataBucket::LoadZoneCache(uint16 zone_id, uint16 instance_id)
); );
} }
void DataBucket::BulkLoadEntitiesToCache(DataBucketLoadType::Type t, std::vector<uint32> ids) void DataBucket::BulkLoadEntitiesToCache(SharedDatabase* database, DataBucketLoadType::Type t, std::vector<uint32> ids)
{ {
if (ids.empty()) { if (ids.empty()) {
return; return;
@ -653,7 +643,7 @@ void DataBucket::BulkLoadEntitiesToCache(DataBucketLoadType::Type t, std::vector
} }
const auto &l = DataBucketsRepository::GetWhere( const auto &l = DataBucketsRepository::GetWhere(
database, *database,
fmt::format( fmt::format(
"{} IN ({}) AND (`expires` > {} OR `expires` = 0)", "{} IN ({}) AND (`expires` > {} OR `expires` = 0)",
column, column,
@ -843,4 +833,4 @@ bool DataBucket::CanCache(const DataBucketKey &key)
} }
return false; return false;
} }

View File

@ -5,6 +5,7 @@
#include "types.h" #include "types.h"
#include "repositories/data_buckets_repository.h" #include "repositories/data_buckets_repository.h"
#include "json/json_archive_single_line.h" #include "json/json_archive_single_line.h"
#include "shareddb.h"
struct DataBucketKey { struct DataBucketKey {
std::string key; std::string key;
@ -38,26 +39,26 @@ namespace DataBucketLoadType {
class DataBucket { class DataBucket {
public: public:
// non-scoped bucket methods (for global buckets) // non-scoped bucket methods (for global buckets)
static void SetData(const std::string &bucket_key, const std::string &bucket_value, std::string expires_time = ""); static void SetData(SharedDatabase *database, const std::string &bucket_key, const std::string &bucket_value, std::string expires_time = "");
static bool DeleteData(const std::string &bucket_key); static bool DeleteData(SharedDatabase *database, const std::string &bucket_key);
static std::string GetData(const std::string &bucket_key); static std::string GetData(SharedDatabase *database, const std::string &bucket_key);
static std::string GetDataExpires(const std::string &bucket_key); static std::string GetDataExpires(SharedDatabase *database, const std::string &bucket_key);
static std::string GetDataRemaining(const std::string &bucket_key); static std::string GetDataRemaining(SharedDatabase *database, const std::string &bucket_key);
// scoped bucket methods // scoped bucket methods
static void SetData(const DataBucketKey &k_); static void SetData(SharedDatabase *database, const DataBucketKey &k_);
static bool DeleteData(const DataBucketKey &k); static bool DeleteData(SharedDatabase *database, const DataBucketKey &k);
static DataBucketsRepository::DataBuckets GetData(const DataBucketKey &k_, bool ignore_misses_cache = false); static DataBucketsRepository::DataBuckets GetData(SharedDatabase *database, const DataBucketKey &k_, bool ignore_misses_cache = false);
static std::string GetDataExpires(const DataBucketKey &k); static std::string GetDataExpires(SharedDatabase *database, const DataBucketKey &k);
static std::string GetDataRemaining(const DataBucketKey &k); static std::string GetDataRemaining(SharedDatabase *database, const DataBucketKey &k);
static std::string GetScopedDbFilters(const DataBucketKey &k); static std::string GetScopedDbFilters(const DataBucketKey &k);
// bucket repository versus key matching // bucket repository versus key matching
static bool CheckBucketMatch(const DataBucketsRepository::DataBuckets &dbe, const DataBucketKey &k); static bool CheckBucketMatch(const DataBucketsRepository::DataBuckets &dbe, const DataBucketKey &k);
static bool ExistsInCache(const DataBucketsRepository::DataBuckets &entry); static bool ExistsInCache(const DataBucketsRepository::DataBuckets &entry);
static void LoadZoneCache(uint16 zone_id, uint16 instance_id); static void LoadZoneCache(SharedDatabase* database, uint16 zone_id, uint16 instance_id);
static void BulkLoadEntitiesToCache(DataBucketLoadType::Type t, std::vector<uint32> ids); static void BulkLoadEntitiesToCache(SharedDatabase* database, DataBucketLoadType::Type t, std::vector<uint32> ids);
static void DeleteCachedBuckets(DataBucketLoadType::Type type, uint32 id, uint32 secondary_id = 0); static void DeleteCachedBuckets(DataBucketLoadType::Type type, uint32 id, uint32 secondary_id = 0);
static void DeleteFromMissesCache(DataBucketsRepository::DataBuckets e); static void DeleteFromMissesCache(DataBucketsRepository::DataBuckets e);

View File

@ -5,11 +5,10 @@
#include "../strings.h" #include "../strings.h"
#include "../rulesys.h" #include "../rulesys.h"
#include "../http/httplib.h" #include "../http/httplib.h"
#include "database_update_manifest.cpp"
#include "database_update_manifest_custom.cpp"
#include "database_update_manifest_bots.cpp"
#include "database_dump_service.h" #include "database_dump_service.h"
#include "database_update_manifest.h"
#include "database_update_manifest_custom.h"
#include "database_update_manifest_bots.h"
constexpr int BREAK_LENGTH = 70; constexpr int BREAK_LENGTH = 70;

View File

@ -1,4 +1,4 @@
#include "database_update.h" #pragma once
std::vector<ManifestEntry> manifest_entries = { std::vector<ManifestEntry> manifest_entries = {
ManifestEntry{ ManifestEntry{

View File

@ -1,4 +1,4 @@
#include "database_update.h" #pragma once
std::vector<ManifestEntry> bot_manifest_entries = { std::vector<ManifestEntry> bot_manifest_entries = {
ManifestEntry{ ManifestEntry{

View File

@ -1,4 +1,4 @@
#include "database_update.h" #pragma once
std::vector<ManifestEntry> manifest_entries_custom = { std::vector<ManifestEntry> manifest_entries_custom = {
ManifestEntry{ ManifestEntry{

View File

@ -258,9 +258,17 @@ bool DBcore::Open(uint32 *errnum, char *errbuf)
if (pCompress) { if (pCompress) {
flags |= CLIENT_COMPRESS; flags |= CLIENT_COMPRESS;
} }
//todo: we need to revisit this ssl handling later
//the whole connect code is ancient and tls is starting to come as a default requirement for many db setups
if (pSSL) { if (pSSL) {
flags |= CLIENT_SSL; flags |= CLIENT_SSL;
} }
else {
int off = 0;
mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &off);
mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &off);
}
if (mysql_real_connect(mysql, pHost, pUser, pPassword, pDatabase, pPort, 0, flags)) { if (mysql_real_connect(mysql, pHost, pUser, pPassword, pDatabase, pPort, 0, flags)) {
pStatus = Connected; pStatus = Connected;

View File

@ -3,6 +3,7 @@
#include "rulesys.h" #include "rulesys.h"
#include "util/uuid.h" #include "util/uuid.h"
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <cereal/types/chrono.hpp> #include <cereal/types/chrono.hpp>
DzLockout::DzLockout(std::string uuid, std::string expedition, std::string event, uint64_t expire_time, uint32_t duration) DzLockout::DzLockout(std::string uuid, std::string expedition, std::string event, uint64_t expire_time, uint32_t duration)

View File

@ -23,9 +23,9 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <time.h> #include <time.h>
#include "../cereal/include/cereal/archives/binary.hpp" #include <cereal/archives/binary.hpp>
#include "../cereal/include/cereal/types/string.hpp" #include <cereal/types/string.hpp>
#include "../cereal/include/cereal/types/vector.hpp" #include <cereal/types/vector.hpp>
#include "../common/version.h" #include "../common/version.h"
#include "emu_constants.h" #include "emu_constants.h"
#include "textures.h" #include "textures.h"

View File

@ -23,6 +23,7 @@
#include "path_manager.h" #include "path_manager.h"
#include <fstream> #include <fstream>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
struct LoginConfig { struct LoginConfig {
std::string LoginHost; std::string LoginHost;

View File

@ -34,6 +34,7 @@
#endif #endif
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include "types.h" #include "types.h"
namespace Logs { namespace Logs {

View File

@ -3,6 +3,7 @@
#include "../json/json_archive_single_line.h" #include "../json/json_archive_single_line.h"
#include <vector> #include <vector>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <cereal/archives/json.hpp> #include <cereal/archives/json.hpp>
#include <cereal/types/vector.hpp> #include <cereal/types/vector.hpp>

View File

@ -36,6 +36,7 @@
#endif #endif
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <sys/stat.h> #include <sys/stat.h>

View File

@ -20,6 +20,7 @@
#include <cstring> #include <cstring>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <csignal> #include <csignal>
#include <vector> #include <vector>
#include "ip_util.h" #include "ip_util.h"

View File

@ -1,6 +1,7 @@
#include "console_server.h" #include "console_server.h"
#include "../strings.h" #include "../strings.h"
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
EQ::Net::ConsoleServer::ConsoleServer(const std::string &addr, int port) EQ::Net::ConsoleServer::ConsoleServer(const std::string &addr, int port)
{ {

View File

@ -5,6 +5,7 @@
#include "../servertalk.h" #include "../servertalk.h"
#include "../rulesys.h" #include "../rulesys.h"
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
EQ::Net::ConsoleServerConnection::ConsoleServerConnection(ConsoleServer *parent, std::shared_ptr<TCPConnection> connection) EQ::Net::ConsoleServerConnection::ConsoleServerConnection(ConsoleServer *parent, std::shared_ptr<TCPConnection> connection)
{ {

View File

@ -2,6 +2,7 @@
#include "endian.h" #include "endian.h"
#include <cctype> #include <cctype>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
void EQ::Net::Packet::PutInt8(size_t offset, int8_t value) void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
{ {

View File

@ -4,6 +4,7 @@
#include "crc32.h" #include "crc32.h"
#include <zlib.h> #include <zlib.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
// observed client receive window is 300 packets, 140KB // observed client receive window is 300 packets, 140KB
constexpr size_t MAX_CLIENT_RECV_PACKETS_PER_WINDOW = 300; constexpr size_t MAX_CLIENT_RECV_PACKETS_PER_WINDOW = 300;

View File

@ -2,6 +2,7 @@
#include "../event/event_loop.h" #include "../event/event_loop.h"
#include "../event/timer.h" #include "../event/timer.h"
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <map> #include <map>
#include <unordered_set> #include <unordered_set>
#include <array> #include <array>

View File

@ -4,6 +4,7 @@
#include "../util/uuid.h" #include "../util/uuid.h"
#include <sstream> #include <sstream>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
struct EQ::Net::WebsocketServerConnection::Impl { struct EQ::Net::WebsocketServerConnection::Impl {
WebsocketServer *parent; WebsocketServer *parent;

View File

@ -38,7 +38,7 @@
#include "../raid.h" #include "../raid.h"
#include "../guilds.h" #include "../guilds.h"
//#include "../repositories/trader_repository.h" //#include "../repositories/trader_repository.h"
#include "../cereal/include/cereal/types/vector.hpp" #include <cereal/types/vector.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>

View File

@ -2,6 +2,7 @@
#include <memory> #include <memory>
#include "process.h" #include "process.h"
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
std::string Process::execute(const std::string &cmd) std::string Process::execute(const std::string &cmd)
{ {

View File

@ -23,7 +23,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
class DBcore; class DBcore;

View File

@ -7,8 +7,8 @@
#include "items_repository.h" #include "items_repository.h"
#include "../../common/item_data.h" #include "../../common/item_data.h"
#include "../../common/races.h" #include "../../common/races.h"
#include "../cereal/include/cereal/archives/binary.hpp" #include <cereal/archives/binary.hpp>
#include "../cereal/include/cereal/types/string.hpp" #include <cereal/types/string.hpp>
class TraderRepository : public BaseTraderRepository { class TraderRepository : public BaseTraderRepository {
public: public:

View File

@ -23,6 +23,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include "../common/repositories/rule_sets_repository.h" #include "../common/repositories/rule_sets_repository.h"
#include "../common/repositories/rule_values_repository.h" #include "../common/repositories/rule_values_repository.h"

View File

@ -19,6 +19,7 @@
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#if defined(_MSC_VER) && _MSC_VER >= 1800 #if defined(_MSC_VER) && _MSC_VER >= 1800
#include <algorithm> #include <algorithm>

View File

@ -36,6 +36,7 @@
#include "strings.h" #include "strings.h"
#include <cereal/external/rapidjson/document.h> #include <cereal/external/rapidjson/document.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -47,14 +48,9 @@
#include <random> #include <random>
#include <string> #include <string>
//Const char based
#include "strings_legacy.cpp" // legacy c functions
#include "strings_misc.cpp" // anything non "Strings" scoped
#ifdef _WINDOWS #ifdef _WINDOWS
#include <ctype.h> #include <ctype.h>
#include <functional> #include <functional>
#include <algorithm>
#endif #endif
std::string Strings::Random(size_t length) std::string Strings::Random(size_t length)

View File

@ -2,6 +2,7 @@
#include <ios> #include <ios>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ranges.h>
#ifdef _WIN32 #ifdef _WIN32
#include <objbase.h> #include <objbase.h>

View File

@ -1,20 +1,20 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20)
SET(eqlaunch_sources set(eqlaunch_sources
eqlaunch.cpp eqlaunch.cpp
worldserver.cpp worldserver.cpp
zone_launch.cpp zone_launch.cpp
) )
SET(eqlaunch_headers set(eqlaunch_headers
worldserver.h worldserver.h
zone_launch.h zone_launch.h
) )
ADD_EXECUTABLE(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers}) add_executable(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers})
INSTALL(TARGETS eqlaunch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS eqlaunch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
TARGET_LINK_LIBRARIES(eqlaunch ${SERVER_LIBS}) target_link_libraries(eqlaunch common)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -1,22 +0,0 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
SET(hc_sources
eq.cpp
main.cpp
login.cpp
world.cpp
)
SET(hc_headers
eq.h
login.h
world.h
)
ADD_EXECUTABLE(hc ${hc_sources} ${hc_headers})
INSTALL(TARGETS hc RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
TARGET_LINK_LIBRARIES(hc ${SERVER_LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

350
hc/eq.cpp
View File

@ -1,350 +0,0 @@
#include "eq.h"
#include "../common/net/dns.h"
const char* eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char* buffer_out, bool enc) {
DES_key_schedule k;
DES_cblock v;
memset(&k, 0, sizeof(DES_key_schedule));
memset(&v, 0, sizeof(DES_cblock));
if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) {
return nullptr;
}
DES_ncbc_encrypt((const unsigned char*)buffer_in, (unsigned char*)buffer_out, (long)buffer_in_sz, &k, &v, enc);
return buffer_out;
}
EverQuest::EverQuest(const std::string &host, int port, const std::string &user, const std::string &pass, const std::string &server, const std::string &character)
{
m_host = host;
m_port = port;
m_user = user;
m_pass = pass;
m_server = server;
m_character = character;
m_dbid = 0;
EQ::Net::DNSLookup(m_host, port, false, [&](const std::string &addr) {
if (addr.empty()) {
Log.OutF(Logs::General, Logs::Headless_Client, "Could not resolve address: {0}", m_host);
return;
}
else {
m_host = addr;
m_login_connection_manager.reset(new EQ::Net::ReliableStreamConnectionManager());
m_login_connection_manager->OnNewConnection(std::bind(&EverQuest::LoginOnNewConnection, this, std::placeholders::_1));
m_login_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::LoginOnStatusChangeReconnectEnabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_login_connection_manager->OnPacketRecv(std::bind(&EverQuest::LoginOnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_login_connection_manager->Connect(m_host, m_port);
}
});
}
EverQuest::~EverQuest()
{
}
void EverQuest::LoginOnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection)
{
m_login_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting...");
}
void EverQuest::LoginOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connected.");
LoginSendSessionReady();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connection lost before we got to world, reconnecting.");
m_key.clear();
m_dbid = 0;
m_login_connection.reset();
m_login_connection_manager->Connect(m_host, m_port);
}
}
void EverQuest::LoginOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_login_connection.reset();
}
}
void EverQuest::LoginOnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet & p)
{
auto opcode = p.GetUInt16(0);
switch (opcode) {
case 0x0017: //OP_ChatMessage
LoginSendLogin();
break;
case 0x0018:
LoginProcessLoginResponse(p);
break;
case 0x0019:
LoginProcessServerPacketList(p);
break;
case 0x0022:
LoginProcessServerPlayResponse(p);
break;
}
}
void EverQuest::LoginSendSessionReady()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 1); //OP_SessionReady
p.PutUInt32(2, 2);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendLogin()
{
size_t buffer_len = m_user.length() + m_pass.length() + 2;
std::unique_ptr<char[]> buffer(new char[buffer_len]);
strcpy(&buffer[0], m_user.c_str());
strcpy(&buffer[m_user.length() + 1], m_pass.c_str());
size_t encrypted_len = buffer_len;
if (encrypted_len % 8 > 0) {
encrypted_len = ((encrypted_len / 8) + 1) * 8;
}
EQ::Net::DynamicPacket p;
p.Resize(12 + encrypted_len);
p.PutUInt16(0, 2); //OP_Login
p.PutUInt32(2, 3);
eqcrypt_block(&buffer[0], buffer_len, (char*)p.Data() + 12, true);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendServerRequest()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 4); //OP_ServerListRequest
p.PutUInt32(2, 4);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendPlayRequest(uint32_t id)
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 0x000d);
p.PutUInt16(2, 5);
p.PutUInt32(4, 0);
p.PutUInt32(8, 0);
p.PutUInt32(12, id);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginProcessLoginResponse(const EQ::Net::Packet & p)
{
auto encrypt_size = p.Length() - 12;
if (encrypt_size % 8 > 0) {
encrypt_size = (encrypt_size / 8) * 8;
}
std::unique_ptr<char[]> decrypted(new char[encrypt_size]);
eqcrypt_block((char*)p.Data() + 12, encrypt_size, &decrypted[0], false);
EQ::Net::StaticPacket sp(&decrypted[0], encrypt_size);
auto response_error = sp.GetUInt16(1);
if (response_error > 101) {
Log.OutF(Logs::General, Logs::Headless_Client, "Error logging in response code: {0}", response_error);
LoginDisableReconnect();
}
else {
m_key = sp.GetCString(12);
m_dbid = sp.GetUInt32(8);
Log.OutF(Logs::General, Logs::Headless_Client, "Logged in successfully with dbid {0} and key {1}", m_dbid, m_key);
LoginSendServerRequest();
}
}
void EverQuest::LoginProcessServerPacketList(const EQ::Net::Packet & p)
{
m_world_servers.clear();
auto number_of_servers = p.GetUInt32(18);
size_t idx = 22;
for (auto i = 0U; i < number_of_servers; ++i) {
WorldServer ws;
ws.address = p.GetCString(idx);
idx += (ws.address.length() + 1);
ws.type = p.GetInt32(idx);
idx += 4;
auto id = p.GetUInt32(idx);
idx += 4;
ws.long_name = p.GetCString(idx);
idx += (ws.long_name.length() + 1);
ws.lang = p.GetCString(idx);
idx += (ws.lang.length() + 1);
ws.region = p.GetCString(idx);
idx += (ws.region.length() + 1);
ws.status = p.GetInt32(idx);
idx += 4;
ws.players = p.GetInt32(idx);
idx += 4;
m_world_servers[id] = ws;
}
for (auto server : m_world_servers) {
if (server.second.long_name.compare(m_server) == 0) {
Log.OutF(Logs::General, Logs::Headless_Client, "Found world server {0}, attempting to login.", m_server);
LoginSendPlayRequest(server.first);
return;
}
}
Log.OutF(Logs::General, Logs::Headless_Client, "Got response from login server but could not find world server {0} disconnecting.", m_server);
LoginDisableReconnect();
}
void EverQuest::LoginProcessServerPlayResponse(const EQ::Net::Packet &p)
{
auto allowed = p.GetUInt8(12);
if (allowed) {
auto server = p.GetUInt32(18);
auto ws = m_world_servers.find(server);
if (ws != m_world_servers.end()) {
ConnectToWorld();
LoginDisableReconnect();
}
}
else {
auto message = p.GetUInt16(13);
Log.OutF(Logs::General, Logs::Headless_Client, "Failed to login to server with message {0}");
LoginDisableReconnect();
}
}
void EverQuest::LoginDisableReconnect()
{
m_login_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::LoginOnStatusChangeReconnectDisabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_login_connection->Close();
}
void EverQuest::ConnectToWorld()
{
m_world_connection_manager.reset(new EQ::Net::ReliableStreamConnectionManager());
m_world_connection_manager->OnNewConnection(std::bind(&EverQuest::WorldOnNewConnection, this, std::placeholders::_1));
m_world_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::WorldOnStatusChangeReconnectEnabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_world_connection_manager->OnPacketRecv(std::bind(&EverQuest::WorldOnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_world_connection_manager->Connect(m_host, 9000);
}
void EverQuest::WorldOnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection)
{
m_world_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting to world...");
}
void EverQuest::WorldOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connected.");
WorldSendClientAuth();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connection lost, reconnecting.");
m_world_connection.reset();
m_world_connection_manager->Connect(m_host, 9000);
}
}
void EverQuest::WorldOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_world_connection.reset();
}
}
void EverQuest::WorldOnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet & p)
{
auto opcode = p.GetUInt16(0);
switch (opcode) {
case 0x00d2:
WorldProcessCharacterSelect(p);
break;
default:
Log.OutF(Logs::General, Logs::Headless_Client, "Unhandled opcode: {0:#x}", opcode);
break;
}
}
void EverQuest::WorldSendClientAuth()
{
EQ::Net::DynamicPacket p;
p.Resize(2 + 464);
p.PutUInt16(0, 0x7a09U);
std::string dbid_str = std::to_string(m_dbid);
p.PutCString(2, dbid_str.c_str());
p.PutCString(2 + dbid_str.length() + 1, m_key.c_str());
m_world_connection->QueuePacket(p);
}
void EverQuest::WorldSendEnterWorld(const std::string &character)
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 0x578f);
p.PutString(2, character);
p.PutUInt32(66, 0);
p.PutUInt32(70, 0);
m_world_connection->QueuePacket(p);
}
void EverQuest::WorldProcessCharacterSelect(const EQ::Net::Packet &p)
{
auto char_count = p.GetUInt32(2);
size_t idx = 6;
//Log.OutF(Logs::General, Logs::Headless_Client, "{0} characters", char_count);
for (uint32_t i = 0; i < char_count; ++i) {
auto name = p.GetCString(idx);
idx += name.length() + 1;
auto pclass = p.GetUInt8(idx);
auto prace = p.GetUInt32(idx + 1);
auto plevel = p.GetUInt8(idx + 5);
idx += 274;
if (m_character.compare(name) == 0) {
Log.OutF(Logs::General, Logs::Headless_Client, "Found {0}, would attempt to login here.", m_character);
WorldSendEnterWorld(m_character);
return;
}
}
Log.OutF(Logs::General, Logs::Headless_Client, "Could not find {0}, cannot continue to login.", m_character);
}

74
hc/eq.h
View File

@ -1,74 +0,0 @@
#pragma once
#include "../common/eqemu_logsys.h"
#include "../common/net/reliable_stream_connection.h"
#include "../common/event/timer.h"
#include <openssl/des.h>
#include <string>
#include <map>
struct WorldServer
{
std::string long_name;
std::string address;
int type;
std::string lang;
std::string region;
int status;
int players;
};
class EverQuest
{
public:
EverQuest(const std::string &host, int port, const std::string &user, const std::string &pass, const std::string &server, const std::string &character);
~EverQuest();
private:
//Login
void LoginOnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection);
void LoginOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void LoginOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void LoginOnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p);
void LoginSendSessionReady();
void LoginSendLogin();
void LoginSendServerRequest();
void LoginSendPlayRequest(uint32_t id);
void LoginProcessLoginResponse(const EQ::Net::Packet &p);
void LoginProcessServerPacketList(const EQ::Net::Packet &p);
void LoginProcessServerPlayResponse(const EQ::Net::Packet &p);
void LoginDisableReconnect();
std::unique_ptr<EQ::Net::ReliableStreamConnectionManager> m_login_connection_manager;
std::shared_ptr<EQ::Net::ReliableStreamConnection> m_login_connection;
std::map<uint32_t, WorldServer> m_world_servers;
//World
void ConnectToWorld();
void WorldOnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection);
void WorldOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void WorldOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void WorldOnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p);
void WorldSendClientAuth();
void WorldSendEnterWorld(const std::string &character);
void WorldProcessCharacterSelect(const EQ::Net::Packet &p);
std::unique_ptr<EQ::Net::ReliableStreamConnectionManager> m_world_connection_manager;
std::shared_ptr<EQ::Net::ReliableStreamConnection> m_world_connection;
//Variables
std::string m_host;
int m_port;
std::string m_user;
std::string m_pass;
std::string m_server;
std::string m_character;
std::string m_key;
uint32_t m_dbid;
};

View File

@ -1,255 +0,0 @@
/*#include "login.h"
#include "../common/eqemu_logsys.h"
#include <openssl/des.h>
const char* eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char* buffer_out, bool enc) {
DES_key_schedule k;
DES_cblock v;
memset(&k, 0, sizeof(DES_key_schedule));
memset(&v, 0, sizeof(DES_cblock));
if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) {
return nullptr;
}
DES_ncbc_encrypt((const unsigned char*)buffer_in, (unsigned char*)buffer_out, (long)buffer_in_sz, &k, &v, enc);
return buffer_out;
}
LoginConnection::LoginConnection(const std::string &username, const std::string &password, const std::string &host, int host_port, const std::string &server)
{
m_connecting = false;
m_username = username;
m_password = password;
m_host = host;
m_host_port = host_port;
m_server = server;
m_connection_manager.reset(new EQ::Net::ReliableStreamConnectionManager());
m_connection_manager->OnNewConnection(std::bind(&LoginConnection::OnNewConnection, this, std::placeholders::_1));
m_connection_manager->OnConnectionStateChange(std::bind(&LoginConnection::OnStatusChangeActive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection_manager->OnPacketRecv(std::bind(&LoginConnection::OnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_connection_manager->Connect(host, host_port);
}
LoginConnection::~LoginConnection()
{
}
void LoginConnection::OnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection)
{
m_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting...");
}
void LoginConnection::OnStatusChangeActive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connected.");
SendSessionReady();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connection lost, reconnecting.");
m_key.clear();
m_dbid = 0;
m_connection.reset();
m_connection_manager->Connect(m_host, m_host_port);
}
}
void LoginConnection::OnStatusChangeInactive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_key.clear();
m_dbid = 0;
m_connection.reset();
}
}
void LoginConnection::OnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p)
{
auto opcode = p.GetUInt16(0);
switch (opcode) {
case 0x0017: //OP_ChatMessage
SendLogin();
break;
case 0x0018:
ProcessLoginResponse(p);
break;
case 0x0019:
ProcessServerPacketList(p);
break;
case 0x0022:
ProcessServerPlayResponse(p);
break;
}
}
void LoginConnection::Kill()
{
m_connection_manager->OnConnectionStateChange(std::bind(&LoginConnection::OnStatusChangeInactive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_key.clear();
m_dbid = 0;
m_connection->Close();
}
void LoginConnection::Start()
{
m_connection_manager->OnConnectionStateChange(std::bind(&LoginConnection::OnStatusChangeActive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection_manager->Connect(m_host, m_host_port);
}
void LoginConnection::SendSessionReady()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 1); //OP_SessionReady
p.PutUInt32(2, 2);
m_connection->QueuePacket(p);
}
void LoginConnection::SendLogin()
{
size_t buffer_len = m_username.length() + m_password.length() + 2;
std::unique_ptr<char[]> buffer(new char[buffer_len]);
strcpy(&buffer[0], m_username.c_str());
strcpy(&buffer[m_username.length() + 1], m_password.c_str());
size_t encrypted_len = buffer_len;
if (encrypted_len % 8 > 0) {
encrypted_len = ((encrypted_len / 8) + 1) * 8;
}
EQ::Net::DynamicPacket p;
p.Resize(12 + encrypted_len);
p.PutUInt16(0, 2); //OP_Login
p.PutUInt32(2, 3);
eqcrypt_block(&buffer[0], buffer_len, (char*)p.Data() + 12, true);
m_connection->QueuePacket(p);
}
void LoginConnection::SendServerRequest()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 4); //OP_ServerListRequest
p.PutUInt32(2, 4);
m_connection->QueuePacket(p);
}
void LoginConnection::SendPlayRequest(uint32_t id)
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 0x000d);
p.PutUInt16(2, 5);
p.PutUInt32(4, 0);
p.PutUInt32(8, 0);
p.PutUInt32(12, id);
m_connection->QueuePacket(p);
}
void LoginConnection::ProcessLoginResponse(const EQ::Net::Packet &p)
{
auto encrypt_size = p.Length() - 12;
if (encrypt_size % 8 > 0) {
encrypt_size = (encrypt_size / 8) * 8;
}
std::unique_ptr<char[]> decrypted(new char[encrypt_size]);
eqcrypt_block((char*)p.Data() + 12, encrypt_size, &decrypted[0], false);
EQ::Net::StaticPacket sp(&decrypted[0], encrypt_size);
auto response_error = sp.GetUInt16(1);
if (response_error > 101) {
Log.OutF(Logs::General, Logs::Headless_Client, "Error logging in response code: {0}", response_error);
Kill();
}
else {
m_key = sp.GetCString(12);
m_dbid = sp.GetUInt32(8);
Log.OutF(Logs::General, Logs::Headless_Client, "Logged in successfully with dbid {0} and key {1}", m_dbid, m_key);
SendServerRequest();
}
}
void LoginConnection::ProcessServerPacketList(const EQ::Net::Packet &p)
{
m_world_servers.clear();
auto number_of_servers = p.GetUInt32(18);
size_t idx = 22;
for (auto i = 0U; i < number_of_servers; ++i) {
WorldServer ws;
ws.address = p.GetCString(idx);
idx += (ws.address.length() + 1);
ws.type = p.GetInt32(idx);
idx += 4;
auto id = p.GetUInt32(idx);
idx += 4;
ws.long_name = p.GetCString(idx);
idx += (ws.long_name.length() + 1);
ws.lang = p.GetCString(idx);
idx += (ws.lang.length() + 1);
ws.region = p.GetCString(idx);
idx += (ws.region.length() + 1);
ws.status = p.GetInt32(idx);
idx += 4;
ws.players = p.GetInt32(idx);
idx += 4;
m_world_servers[id] = ws;
}
for (auto server : m_world_servers) {
if (server.second.long_name.compare(m_server) == 0) {
Log.OutF(Logs::General, Logs::Headless_Client, "Found world server {0}, attempting to login.", m_server);
SendPlayRequest(server.first);
return;
}
}
Log.OutF(Logs::General, Logs::Headless_Client, "Got response from login server but could not find world server {0} disconnecting.", m_server);
Kill();
}
void LoginConnection::ProcessServerPlayResponse(const EQ::Net::Packet &p)
{
auto allowed = p.GetUInt8(12);
if (allowed) {
auto server = p.GetUInt32(18);
auto ws = m_world_servers.find(server);
if (ws != m_world_servers.end()) {
if (m_on_can_login_world) {
m_on_can_login_world(ws->second, m_key, m_dbid);
}
Kill();
}
}
else {
auto message = p.GetUInt16(13);
Log.OutF(Logs::General, Logs::Headless_Client, "Failed to login to server with message {0}");
Kill();
}
}
*/

View File

@ -1,56 +0,0 @@
#pragma once
#include "../common/net/reliable_stream_connection.h"
#include "../common/event/timer.h"
#include <map>
struct WorldServer
{
std::string long_name;
std::string address;
int type;
std::string lang;
std::string region;
int status;
int players;
};
class LoginConnection
{
public:
LoginConnection(const std::string &username, const std::string &password, const std::string &host, int host_port, const std::string &server);
void OnCanLoginToWorld(std::function<void(const WorldServer&, const std::string&, uint32_t)> cb) { m_on_can_login_world = cb; }
~LoginConnection();
private:
void OnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection);
void OnStatusChangeActive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void OnStatusChangeInactive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void OnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p);
void Kill();
void Start();
void SendSessionReady();
void SendLogin();
void SendServerRequest();
void SendPlayRequest(uint32_t id);
void ProcessLoginResponse(const EQ::Net::Packet &p);
void ProcessServerPacketList(const EQ::Net::Packet &p);
void ProcessServerPlayResponse(const EQ::Net::Packet &p);
std::unique_ptr<EQ::Net::ReliableStreamConnectionManager> m_connection_manager;
std::shared_ptr<EQ::Net::ReliableStreamConnection> m_connection;
bool m_connecting;
std::unique_ptr<EQ::Timer> m_connect_timer;
std::string m_username;
std::string m_password;
std::string m_host;
int m_host_port;
std::string m_server;
std::string m_key;
uint32_t m_dbid;
std::map<uint32_t, WorldServer> m_world_servers;
std::function<void(const WorldServer&, const std::string&, uint32_t)> m_on_can_login_world;
};

View File

@ -1,51 +0,0 @@
#include "../common/event/event_loop.h"
#include "../common/eqemu_logsys.h"
#include "../common/crash.h"
#include "../common/platform.h"
#include "../common/json_config.h"
#include <thread>
#include "eq.h"
EQEmuLogSys Log;
int main() {
RegisterExecutablePlatform(ExePlatformHC);
Log.LoadLogSettingsDefaults();
set_exception_handler();
Log.OutF(Logs::General, Logs::Headless_Client, "Starting EQEmu Headless Client.");
auto config = EQ::JsonConfigFile::Load("hc.json");
auto config_handle = config.RawHandle();
std::vector<std::unique_ptr<EverQuest>> eq_list;
try {
for (int i = 0; i < config_handle.size(); ++i) {
auto c = config_handle[i];
auto host = c["host"].asString();
auto port = c["port"].asInt();
auto user = c["user"].asString();
auto pass = c["pass"].asString();
auto server = c["server"].asString();
auto character = c["character"].asString();
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting to {0}:{1} as Account '{2}' to Server '{3}' under Character '{4}'", host, port, user, server, character);
eq_list.push_back(std::unique_ptr<EverQuest>(new EverQuest(host, port, user, pass, server, character)));
}
}
catch (std::exception &ex) {
Log.OutF(Logs::General, Logs::Headless_Client, "Error parsing config file: {0}", ex.what());
return 0;
}
for (;;) {
EQ::EventLoop::Get().Process();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return 0;
}

View File

@ -1,78 +0,0 @@
#include "world.h"
#include "../common/eqemu_logsys.h"
WorldConnection::WorldConnection(const std::string &key, uint32_t dbid, const std::string &host)
{
m_connecting = false;
m_host = host;
m_key = key;
m_dbid = dbid;
m_connection_manager.reset(new EQ::Net::ReliableStreamConnectionManager());
m_connection_manager->OnNewConnection(std::bind(&WorldConnection::OnNewConnection, this, std::placeholders::_1));
m_connection_manager->OnConnectionStateChange(std::bind(&WorldConnection::OnStatusChangeActive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection_manager->OnPacketRecv(std::bind(&WorldConnection::OnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_connection_manager->Connect(host, 9000);
}
WorldConnection::~WorldConnection() {
}
void WorldConnection::OnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection)
{
m_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting to world...");
}
void WorldConnection::OnStatusChangeActive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connected.");
SendClientAuth();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connection lost, reconnecting.");
m_connection.reset();
m_connection_manager->Connect(m_host, 9000);
}
}
void WorldConnection::OnStatusChangeInactive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_connection.reset();
}
}
void WorldConnection::OnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p)
{
auto opcode = p.GetUInt16(0);
Log.OutF(Logs::General, Logs::Headless_Client, "Packet in:\n{0}", p.ToString());
}
void WorldConnection::Kill()
{
m_connection_manager->OnConnectionStateChange(std::bind(&WorldConnection::OnStatusChangeInactive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection->Close();
}
void WorldConnection::Start()
{
m_connection_manager->OnConnectionStateChange(std::bind(&WorldConnection::OnStatusChangeActive, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection_manager->Connect(m_host, 9000);
}
void WorldConnection::SendClientAuth()
{
EQ::Net::DynamicPacket p;
p.Resize(2 + 464);
p.PutUInt16(0, 0x7a09U);
std::string dbid_str = std::to_string(m_dbid);
p.PutCString(2, dbid_str.c_str());
p.PutCString(2 + dbid_str.length() + 1, m_key.c_str());
m_connection->QueuePacket(p);
}

View File

@ -1,31 +0,0 @@
#pragma once
#include "../common/net/reliable_stream_connection.h"
#include "../common/event/timer.h"
#include <map>
class WorldConnection
{
public:
WorldConnection(const std::string &key, uint32_t dbid, const std::string &host);
~WorldConnection();
private:
void OnNewConnection(std::shared_ptr<EQ::Net::ReliableStreamConnection> connection);
void OnStatusChangeActive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void OnStatusChangeInactive(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void OnPacketRecv(std::shared_ptr<EQ::Net::ReliableStreamConnection> conn, const EQ::Net::Packet &p);
void Kill();
void Start();
void SendClientAuth();
std::unique_ptr<EQ::Net::ReliableStreamConnectionManager> m_connection_manager;
std::shared_ptr<EQ::Net::ReliableStreamConnection> m_connection;
bool m_connecting;
std::unique_ptr<EQ::Timer> m_connect_timer;
std::string m_host;
std::string m_key;
uint32_t m_dbid;
};

View File

View File

View File

@ -1,7 +1,7 @@
IF(EQEMU_BUILD_LUA) if(EQEMU_BUILD_LUA)
ADD_SUBDIRECTORY(luabind) add_subdirectory(luabind)
ENDIF(EQEMU_BUILD_LUA) endif()
IF(EQEMU_BUILD_PERL) if(EQEMU_BUILD_PERL)
ADD_SUBDIRECTORY(perlbind) add_subdirectory(perlbind)
ENDIF(EQEMU_BUILD_PERL) endif()

View File

@ -1,6 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12) cmake_minimum_required(VERSION 3.20.0)
SET(lb_sources set(lb_sources
src/class.cpp src/class.cpp
src/class_info.cpp src/class_info.cpp
src/class_registry.cpp src/class_registry.cpp
@ -20,19 +20,16 @@ SET(lb_sources
src/wrapper_base.cpp src/wrapper_base.cpp
) )
SET(lb_headers add_library(luabind ${lb_sources})
target_include_directories(luabind PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${LUAJIT_INCLUDE_DIR})
target_link_libraries(luabind PUBLIC Boost::dynamic_bitset Boost::tuple Boost::foreach ${LUAJIT_LIBRARY})
) if(UNIX)
ADD_LIBRARY(luabind ${lb_sources} ${lb_headers})
IF(UNIX)
set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS -Wno-deprecated-declarations) set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS -Wno-deprecated-declarations)
ENDIF(UNIX) endif()
IF(MSVC) if(MSVC)
set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS " /W0 " ) set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS " /W0 " )
ENDIF(MSVC) endif()
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.20.0)
project(perlbind LANGUAGES CXX) project(perlbind LANGUAGES CXX)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".so" ".a")
find_package(PerlLibs)
set(PERLBIND_HEADERS set(PERLBIND_HEADERS
include/perlbind/array.h include/perlbind/array.h
include/perlbind/forward.h include/perlbind/forward.h
@ -45,6 +41,8 @@ target_include_directories(perlbind PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>) $<INSTALL_INTERFACE:include>)
target_compile_definitions(perlbind PUBLIC EMBPERL EMBPERL_PLUGIN PERLBIND_NO_STRICT_SCALAR_TYPES)
option(PERLBIND_BUILD_TESTS "Build tests" OFF) option(PERLBIND_BUILD_TESTS "Build tests" OFF)
option(PERLBIND_ENABLE_ASAN "Build with address sanitizer" OFF) option(PERLBIND_ENABLE_ASAN "Build with address sanitizer" OFF)

View File

@ -1,4 +0,0 @@
* text=auto
*.c text
*.h text
Makefile text

View File

@ -1,39 +0,0 @@
name: CI Static Analysis
on: [push, pull_request]
jobs:
GCC-10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install packages (Ubuntu)
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install -y gcc-10
- name: Generate project files
run: |
cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DWITH_FUZZERS=OFF -DWITH_CODE_COVERAGE=OFF -DWITH_MAINTAINER_WARNINGS=OFF
env:
CC: gcc-10
CFLAGS: "-fanalyzer -Werror -Wanalyzer-double-fclose -Wanalyzer-double-free -Wanalyzer-exposure-through-output-file -Wanalyzer-file-leak -Wanalyzer-free-of-non-heap -Wanalyzer-malloc-leak -Wanalyzer-null-argument -Wanalyzer-null-dereference -Wanalyzer-possible-null-argument -Wanalyzer-possible-null-dereference -Wanalyzer-stale-setjmp-buffer -Wanalyzer-tainted-array-index -Wanalyzer-unsafe-call-within-signal-handler -Wanalyzer-use-after-free -Wanalyzer-use-of-pointer-in-stale-stack-frame"
CI: true
- name: Compile source code
run: |
cmake --build . --config Release > /dev/null
Clang-12:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install packages (Ubuntu)
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" -y
sudo apt install clang-tools-12 -y
- name: Generate project files
run: |
scan-build-12 --status-bugs cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DWITH_FUZZERS=OFF -DWITH_CODE_COVERAGE=OFF -DWITH_MAINTAINER_WARNINGS=OFF
env:
CI: true
- name: Compile source code
run: |
scan-build-12 --status-bugs cmake --build . --config Release > /dev/null

View File

@ -1,381 +0,0 @@
name: CI CMake
on: [push, pull_request]
jobs:
ci-cmake:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Ubuntu GCC
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_SANITIZER=Address
codecov: ubuntu_gcc
- name: Ubuntu GCC OSB -O1 No Unaligned64
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_UNALIGNED=ON -DUNALIGNED64_OK=OFF -DWITH_SANITIZER=Undefined
build-dir: ../build
build-src-dir: ../zlib-ng
codecov: ubuntu_gcc_osb
cflags: -O1 -g3
- name: Ubuntu GCC -O3 No Unaligned
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_UNALIGNED=OFF
codecov: ubuntu_gcc_o3
cflags: -O3
- name: Ubuntu GCC Link Zlib
os: ubuntu-latest
compiler: gcc
cmake-args: -DZLIB_DUAL_LINK=ON
- name: Ubuntu GCC No AVX2
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_AVX2=OFF -DWITH_SANITIZER=Undefined
codecov: ubuntu_gcc_no_avx2
- name: Ubuntu GCC No SSE2
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_SSE2=OFF -DWITH_SANITIZER=Undefined
codecov: ubuntu_gcc_no_sse2
- name: Ubuntu GCC No SSE4
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_SSE4=OFF -DWITH_SANITIZER=Undefined
codecov: ubuntu_gcc_no_sse4
- name: Ubuntu GCC No PCLMULQDQ
os: ubuntu-latest
compiler: gcc
cmake-args: -DWITH_PCLMULQDQ=OFF -DWITH_SANITIZER=Undefined
codecov: ubuntu_gcc_no_pclmulqdq
- name: Ubuntu GCC Compat No Opt
os: ubuntu-latest
compiler: gcc
cmake-args: -DZLIB_COMPAT=ON -DWITH_NEW_STRATEGIES=OFF -DWITH_OPTIM=OFF -DWITH_SANITIZER=Address
codecov: ubuntu_gcc_compat_no_opt
cflags: -DNOT_TWEAK_COMPILER
- name: Ubuntu GCC ARM SF
os: ubuntu-latest
compiler: arm-linux-gnueabi-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabi -DWITH_SANITIZER=Address
packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross
codecov: ubuntu_gcc_armsf
- name: Ubuntu GCC ARM SF Compat No Opt
os: ubuntu-latest
compiler: arm-linux-gnueabi-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabi -DZLIB_COMPAT=ON -DWITH_NEW_STRATEGIES=OFF -DWITH_OPTIM=OFF -DWITH_SANITIZER=Undefined
packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross
codecov: ubuntu_gcc_armsf_compat_no_opt
- name: Ubuntu GCC ARM HF
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf -DWITH_SANITIZER=Address
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
codecov: ubuntu_gcc_armhf
- name: Ubuntu GCC ARM HF No ACLE
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf -DWITH_ACLE=OFF -DWITH_SANITIZER=Address
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
codecov: ubuntu_gcc_armhf_no_acle
- name: Ubuntu GCC ARM HF No NEON
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf -DWITH_NEON=OFF -DWITH_SANITIZER=Address
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
codecov: ubuntu_gcc_armhf_no_neon
- name: Ubuntu GCC ARM HF Compat No Opt
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf -DZLIB_COMPAT=ON -DWITH_NEW_STRATEGIES=OFF -DWITH_OPTIM=OFF -DWITH_SANITIZER=Undefined
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
codecov: ubuntu_gcc_armhf_compat_no_opt
- name: Ubuntu GCC AARCH64
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake -DWITH_SANITIZER=Address
asan-options: detect_leaks=0
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
codecov: ubuntu_gcc_aarch64
- name: Ubuntu GCC AARCH64 No ACLE
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake -DWITH_ACLE=OFF -DWITH_SANITIZER=Undefined
asan-options: detect_leaks=0
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
codecov: ubuntu_gcc_aarch64_no_acle
- name: Ubuntu GCC AARCH64 No NEON
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake -DWITH_NEON=OFF -DWITH_SANITIZER=Undefined
asan-options: detect_leaks=0
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
codecov: ubuntu_gcc_aarch64_no_neon
- name: Ubuntu GCC AARCH64 Compat No Opt
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake -DZLIB_COMPAT=ON -DWITH_NEW_STRATEGIES=OFF -DWITH_OPTIM=OFF -DWITH_SANITIZER=Undefined
asan-options: detect_leaks=0
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
codecov: ubuntu_gcc_aarch64_compat_no_opt
- name: Ubuntu GCC PPC
os: ubuntu-latest
compiler: powerpc-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc.cmake
packages: qemu gcc-powerpc-linux-gnu libc-dev-powerpc-cross
ldflags: -static
codecov: ubuntu_gcc_ppc
- name: Ubuntu GCC PPC64
os: ubuntu-latest
compiler: powerpc64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc64.cmake
packages: qemu gcc-powerpc64-linux-gnu libc-dev-ppc64-cross
ldflags: -static
codecov: ubuntu_gcc_ppc64
- name: Ubuntu GCC PPC64LE
os: ubuntu-latest
compiler: powerpc64le-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc64le.cmake
packages: qemu gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross
codecov: ubuntu_gcc_ppc64le
- name: Ubuntu GCC SPARC64
os: ubuntu-latest
compiler: sparc64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-sparc64.cmake
packages: qemu gcc-sparc64-linux-gnu libc-dev-sparc64-cross
ldflags: -static
codecov: ubuntu_gcc_sparc64
- name: Ubuntu GCC S390X
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-s390x.cmake -DWITH_SANITIZER=Address
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
ldflags: -static
codecov: ubuntu_gcc_s390x
- name: Ubuntu GCC S390X DFLTCC
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-s390x.cmake -DWITH_DFLTCC_DEFLATE=ON -DWITH_DFLTCC_INFLATE=ON -DWITH_SANITIZER=Address
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
ldflags: -static
codecov: ubuntu_gcc_s390x
- name: Ubuntu GCC S390X DFLTCC Compat
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-s390x.cmake -DZLIB_COMPAT=ON -DWITH_DFLTCC_DEFLATE=ON -DWITH_DFLTCC_INFLATE=ON -DWITH_SANITIZER=Undefined
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
ldflags: -static
codecov: ubuntu_gcc_s390x
- name: Ubuntu MinGW i686
os: ubuntu-latest
compiler: i686-w64-mingw32-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw-i686.cmake
packages: wine32 gcc-mingw-w64
# Codecov disabled due to gcov locking issue error
- name: Ubuntu MinGW x86_64
os: ubuntu-latest
compiler: x86_64-w64-mingw32-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw-x86_64.cmake
packages: wine-stable gcc-mingw-w64
codecov: ubuntu_gcc_mingw_x86_64
- name: Ubuntu Clang
os: ubuntu-latest
compiler: clang
packages: llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
codecov: ubuntu_clang
- name: Ubuntu Clang Inflate Strict
os: ubuntu-latest
compiler: clang
cmake-args: -DWITH_INFLATE_STRICT=ON
packages: llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
codecov: ubuntu_clang_inflate_strict
- name: Ubuntu Clang Inflate Allow Invalid Dist
os: ubuntu-latest
compiler: clang
cmake-args: -DWITH_INFLATE_ALLOW_INVALID_DIST=ON
packages: llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
codecov: ubuntu_clang_inflate_allow_invalid_dist
- name: Ubuntu Clang Memory Map
os: ubuntu-latest
compiler: clang
cflags: -DUSE_MMAP
packages: llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
codecov: ubuntu_clang_mmap
- name: Ubuntu Clang Debug
os: ubuntu-latest
compiler: clang
packages: llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
codecov: ubuntu_clang_debug
build-config: Debug
- name: Ubuntu Clang MSAN
os: ubuntu-latest
compiler: clang
cmake-args: -GNinja -DWITH_SANITIZER=Memory
packages: ninja-build llvm-6.0
gcov-exec: llvm-cov-6.0 gcov
cflags: -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins
codecov: ubuntu_clang_msan
- name: Windows MSVC Win32
os: windows-latest
compiler: cl
cmake-args: -A Win32
- name: Windows MSVC Win64
os: windows-latest
compiler: cl
cmake-args: -A x64
- name: Windows MSVC ARM No Test
os: windows-latest
compiler: cl
cmake-args: -A ARM
- name: Windows MSVC ARM64 No Test
os: windows-latest
compiler: cl
cmake-args: -A ARM64
- name: Windows GCC
os: windows-latest
compiler: gcc
cmake-args: -G Ninja
codecov: win64_gcc
- name: Windows GCC Compat No Opt
os: windows-latest
compiler: gcc
cmake-args: -G Ninja -DZLIB_COMPAT=ON -DWITH_NEW_STRATEGIES=OFF -DWITH_OPTIM=OFF
codecov: win64_gcc_compat_no_opt
- name: macOS Clang
os: macos-latest
compiler: clang
cmake-args: -DWITH_SANITIZER=Address
codecov: macos_clang
- name: macOS GCC
os: macos-latest
compiler: gcc-10
cmake-args: -DWITH_SANITIZER=Undefined
packages: gcc@10
gcov-exec: gcov-10
codecov: macos_gcc
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout test corpora
uses: actions/checkout@v2
with:
repository: nmoinvaz/corpora
path: test/data/corpora
- name: Install packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages
run: |
sudo dpkg --add-architecture i386 # Required for wine32
sudo apt-get update
sudo apt-get install -y ${{ matrix.packages }}
- name: Install packages (Windows)
if: runner.os == 'Windows'
run: |
choco install ninja ${{ matrix.packages }} --no-progress
- name: Install packages (macOS)
if: runner.os == 'macOS'
run: |
brew install ninja ${{ matrix.packages }}
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: Install codecov.io tools
if: matrix.codecov
run: |
python -u -m pip install codecov
- name: Generate project files
# Shared libaries turned off for qemu ppc* and sparc & reduce code coverage sources
run: |
mkdir ${{ matrix.build-dir || '.not-used' }}
cd ${{ matrix.build-dir || '.' }}
cmake ${{ matrix.build-src-dir || '.' }} ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }} -DBUILD_SHARED_LIBS=OFF -DWITH_FUZZERS=ON -DWITH_CODE_COVERAGE=ON -DWITH_MAINTAINER_WARNINGS=ON
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
LDFLAGS: ${{ matrix.ldflags }}
CI: true
- name: Compile source code
run: |
cd ${{ matrix.build-dir || '.' }}
cmake --build . --config ${{ matrix.build-config || 'Release' }}
- name: Run test cases
# Don't run tests on Windows ARM
if: runner.os != 'Windows' || contains(matrix.name, 'ARM') == false
run: |
cd ${{ matrix.build-dir || '.' }}
ctest --verbose -C Release --output-on-failure --max-width 120 -j 6
env:
ASAN_OPTIONS: ${{ matrix.asan-options || 'verbosity=0' }}:abort_on_error=1
MSAN_OPTIONS: ${{ matrix.msan-options || 'verbosity=0' }}:abort_on_error=1
TSAN_OPTIONS: ${{ matrix.tsan-options || 'verbosity=0' }}:abort_on_error=1
LSAN_OPTIONS: ${{ matrix.lsan-options || 'verbosity=0' }}:abort_on_error=1
- name: Upload coverage report
if: matrix.codecov && ( env.CODECOV_TOKEN_SECRET != '' || github.repository == 'zlib-ng/zlib-ng' )
shell: bash
run: |
bash tools/codecov-upload.sh
env:
# Codecov does not yet support GitHub Actions
CODECOV_TOKEN_SECRET: "${{secrets.CODECOV_TOKEN}}"
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN || 'e4fdf847-f541-4ab1-9d50-3d27e5913906' }}"
CODECOV_FLAGS: "${{ matrix.codecov }}"
CODECOV_NAME: "${{ matrix.name }}"
CODECOV_EXEC: "${{ matrix.gcov-exec || 'gcov' }}"
CODECOV_DIR: "${{ matrix.build-dir || '.' }}"

View File

@ -1,185 +0,0 @@
name: CI Configure
on: [push, pull_request]
jobs:
ci-configure:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Ubuntu GCC
os: ubuntu-latest
compiler: gcc
configure-args: --warn
- name: Ubuntu GCC OSB
os: ubuntu-latest
compiler: gcc
configure-args: --warn
build-dir: ../build
build-src-dir: ../zlib-ng
- name: Ubuntu GCC Compat No Opt
os: ubuntu-latest
compiler: gcc
configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
- name: Ubuntu GCC ARM SF
os: ubuntu-latest
compiler: arm-linux-gnueabi-gcc
configure-args: --warn
chost: arm-linux-gnueabi
packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross
- name: Ubuntu GCC ARM SF Compat No Opt
os: ubuntu-latest
compiler: arm-linux-gnueabi-gcc
configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
chost: arm-linux-gnueabi
packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross
- name: Ubuntu GCC ARM HF
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
configure-args: --warn
chost: arm-linux-gnueabihf
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
- name: Ubuntu GCC ARM HF No ACLE
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
configure-args: --warn --without-acle
chost: arm-linux-gnueabihf
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
- name: Ubuntu GCC ARM HF No NEON
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
configure-args: --warn --without-neon
chost: arm-linux-gnueabihf
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
- name: Ubuntu GCC ARM HF Compat No Opt
os: ubuntu-latest
compiler: arm-linux-gnueabihf-gcc
configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
chost: arm-linux-gnueabihf
packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross
- name: Ubuntu GCC AARCH64
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
configure-args: --warn
chost: aarch64-linux-gnu
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
- name: Ubuntu GCC AARCH64 No ACLE
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
configure-args: --warn --without-acle
chost: aarch64-linux-gnu
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
- name: Ubuntu GCC AARCH64 No NEON
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
configure-args: --warn --without-neon
chost: aarch64-linux-gnu
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
- name: Ubuntu GCC AARCH64 Compat No Opt
os: ubuntu-latest
compiler: aarch64-linux-gnu-gcc
configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
chost: aarch64-linux-gnu
packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross
- name: Ubuntu GCC PPC
os: ubuntu-latest
compiler: powerpc-linux-gnu-gcc
configure-args: --warn --static
chost: powerpc-linux-gnu
packages: qemu gcc-powerpc-linux-gnu libc-dev-powerpc-cross
cflags: -static
ldflags: -static
- name: Ubuntu GCC PPC64
os: ubuntu-latest
compiler: powerpc64-linux-gnu-gcc
configure-args: --warn --static
chost: powerpc-linux-gnu
packages: qemu gcc-powerpc64-linux-gnu libc-dev-ppc64-cross
cflags: -static
ldflags: -static
- name: Ubuntu GCC PPC64LE
os: ubuntu-latest
compiler: powerpc64le-linux-gnu-gcc
configure-args: --warn
chost: powerpc64le-linux-gnu
packages: qemu gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross
- name: Ubuntu GCC S390X
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
configure-args: --warn --static
chost: s390x-linux-gnu
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
cflags: -static
ldflags: -static
- name: Ubuntu GCC S390X DFLTCC
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
configure-args: --warn --static --with-dfltcc-deflate --with-dfltcc-inflate
chost: s390x-linux-gnu
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
cflags: -static
ldflags: -static
- name: Ubuntu GCC S390X DFLTCC Compat
os: ubuntu-latest
compiler: s390x-linux-gnu-gcc
configure-args: --warn --zlib-compat --static --with-dfltcc-deflate --with-dfltcc-inflate
chost: s390x-linux-gnu
packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
cflags: -static
ldflags: -static
- name: macOS GCC
os: macOS-latest
compiler: gcc
configure-args: --warn
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Install packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.packages }}
- name: Generate project files
run: |
mkdir ${{ matrix.build-dir || '.not-used' }}
cd ${{ matrix.build-dir || '.' }}
${{ matrix.build-src-dir || '.' }}/configure ${{ matrix.configure-args }}
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
LDFLAGS: ${{ matrix.ldflags }}
CHOST: ${{ matrix.chost }}
CI: true
- name: Compile source code
run: |
cd ${{ matrix.build-dir || '.' }}
make -j2
- name: Run test cases
run: |
cd ${{ matrix.build-dir || '.' }}
make test

View File

@ -1,23 +0,0 @@
name: CI Fuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'zlib-ng'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'zlib-ng'
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure()
with:
name: artifacts
path: ./out/artifacts

View File

@ -1,46 +0,0 @@
name: CI Libpng
on: [pull_request]
jobs:
pngtest:
name: Ubuntu Clang
runs-on: ubuntu-latest
steps:
- name: Checkout repository (zlib-ng)
uses: actions/checkout@v1
- name: Generate project files (zlib-ng)
run: |
cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DZLIB_COMPAT=ON -DZLIB_ENABLE_TESTS=OFF
env:
CC: clang
CFLAGS: -fPIC
CI: true
- name: Compile source code (zlib-ng)
run: |
cmake --build . --config Release
- name: Checkout repository (libpng)
uses: actions/checkout@v2
with:
repository: glennrp/libpng
path: libpng
- name: Generate project files (libpng)
run: |
cd libpng
cmake . -DCMAKE_BUILD_TYPE=Release -DPNG_TESTS=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR=.. -DZLIB_LIBRARY=$PWD/../libz.a
env:
CC: clang
CI: true
- name: Compile source code (libpng)
run: |
cd libpng
cmake --build . --config Release
- name: Run test cases (libpng)
run: |
cd libpng
ctest -C Release --output-on-failure --max-width 120

View File

@ -1,48 +0,0 @@
name: CI NMake
on: [push, pull_request]
jobs:
ci-cmake:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Windows NMake x86
os: windows-latest
makefile: win32/Makefile.msc
vc-vars: x86
- name: Windows NMake x64
os: windows-latest
makefile: win32/Makefile.msc
vc-vars: x86_amd64
- name: Windows NMake ARM No Test
os: windows-latest
makefile: win32/Makefile.arm
vc-vars: x86_arm
- name: Windows NMake ARM64 No Test
os: windows-latest
makefile: win32/Makefile.a64
vc-vars: x86_arm64
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Compile source code
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.vc-vars }}
nmake -f ${{ matrix.makefile }}
- name: Run test cases
shell: cmd
# Don't run tests on Windows ARM
if: contains(matrix.vc-vars, 'arm') == false
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.vc-vars }}
nmake -f ${{ matrix.makefile }} test
nmake -f ${{ matrix.makefile }} testdll

View File

@ -1,121 +0,0 @@
name: CI Pkgcheck
on: [push, pull_request]
jobs:
ci-pkgcheck:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Ubuntu GCC
os: ubuntu-latest
compiler: gcc
- name: Ubuntu GCC -m32
os: ubuntu-latest
compiler: gcc
packages: gcc-multilib
cmake-args: -DCMAKE_C_FLAGS=-m32
cflags: -m32
ldflags: -m32
- name: Ubuntu GCC ARM HF
os: ubuntu-latest
chost: arm-linux-gnueabihf
compiler: arm-linux-gnueabihf-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf
packages: qemu gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
- name: Ubuntu GCC AARCH64
os: ubuntu-latest
chost: aarch64-linux-gnu
compiler: aarch64-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake
packages: qemu gcc-aarch64-linux-gnu libc6-dev-arm64-cross
- name: Ubuntu GCC PPC
os: ubuntu-latest
chost: powerpc-linux-gnu
compiler: powerpc-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc.cmake
packages: qemu gcc-powerpc-linux-gnu libc6-dev-powerpc-cross
- name: Ubuntu GCC PPC64LE
os: ubuntu-latest
chost: powerpc64le-linux-gnu
compiler: powerpc64le-linux-gnu-gcc
cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc64le.cmake
packages: qemu gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross
- name: macOS Clang
os: macOS-latest
compiler: clang
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Install packages (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends abigail-tools ninja-build diffoscope ${{ matrix.packages }}
- name: Install packages (macOS)
if: runner.os == 'macOS'
run: |
brew install ninja diffoscope ${{ matrix.packages }}
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: Select Xcode version (macOS)
# Use a version of Xcode that supports ZERO_AR_DATE until CMake supports
# AppleClang linking with libtool using -D argument
# https://gitlab.kitware.com/cmake/cmake/-/issues/19852
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '12.1.1'
- name: Compare builds
run: |
sh test/pkgcheck.sh
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
CHOST: ${{ matrix.chost }}
CMAKE_ARGS: ${{ matrix.cmake-args }}
LDFLAGS: ${{ matrix.ldflags }}
- name: Compare builds (compat)
run: |
sh test/pkgcheck.sh --zlib-compat
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
CHOST: ${{ matrix.chost }}
CMAKE_ARGS: ${{ matrix.cmake-args }}
LDFLAGS: ${{ matrix.ldflags }}
- name: Check ABI
# macOS runner does not contain abigail
if: runner.os != 'macOS'
run: |
sh test/abicheck.sh --refresh_if
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
CHOST: ${{ matrix.chost }}
LDFLAGS: ${{ matrix.ldflags }}
- name: Check ABI (compat)
# macOS runner does not contain abigail
if: runner.os != 'macOS'
run: |
sh test/abicheck.sh --zlib-compat --refresh_if
env:
CC: ${{ matrix.compiler }}
CFLAGS: ${{ matrix.cflags }}
CHOST: ${{ matrix.chost }}
LDFLAGS: ${{ matrix.ldflags }}

View File

@ -1,73 +0,0 @@
name: CI Release
on:
push:
tags:
- '*'
jobs:
ci-cmake:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Windows MSVC Win32
os: windows-latest
compiler: cl
cmake-args: -A Win32
deploy-name: win32
- name: Windows MSVC Win32 Compat
os: windows-latest
compiler: cl
cmake-args: -A Win32 -DZLIB_COMPAT=ON
deploy-name: win32-compat
- name: Windows MSVC Win64
os: windows-latest
compiler: cl
cmake-args: -A x64
deploy-name: win64
- name: Windows MSVC Win64 Compat
os: windows-latest
compiler: cl
cmake-args: -A x64 -DZLIB_COMPAT=ON
deploy-name: win64-compat
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Set environment variables
shell: bash
run: echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Generate project files
run: |
cmake . ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Release -DZLIB_ENABLE_TESTS=ON -DCMAKE_INSTALL_PREFIX=out -DINSTALL_UTILS=ON
env:
CC: ${{ matrix.compiler }}
CI: true
- name: Compile source code
run: |
cmake --build . --config Release --target install
- name: Package release (Windows)
if: runner.os == 'Windows'
run: |
cd out
7z a -tzip ../zlib-ng-${{ matrix.deploy-name }}.zip bin include lib ../LICENSE.md ../README.md
- name: Upload release (Windows)
uses: svenstaro/upload-release-action@v1-release
if: runner.os == 'Windows'
with:
asset_name: zlib-ng-${{ matrix.deploy-name }}.zip
file: zlib-ng-${{ matrix.deploy-name }}.zip
tag: ${{env.tag}}
repo_token: ${{ secrets.GITHUB_TOKEN }}
overwrite: true
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

View File

@ -1,86 +0,0 @@
*.diff
*.patch
*.orig
*.rej
*~
*.a
*.lo
*.o
*.dylib
*.gcda
*.gcno
*.gcov
/adler32_test
/adler32_testsh
/example
/example64
/examplesh
/libz.so*
/libz-ng.so*
/makefixed
/minigzip
/minigzip64
/minigzipsh
/switchlevels
/zlib.pc
/zlib-ng.pc
/CVE-2003-0107
.DS_Store
*_fuzzer
*.obj
*.exe
*.pdb
*.exp
*.lib
*.dll
*.res
foo.gz
*.manifest
*.opensdf
*.sln
*.sdf
*.vcxproj
*.vcxproj.filters
.vs
CMakeCache.txt
CMakeFiles
Testing
/*.cmake
*.stackdump
*._h
zconf.h
zconf.h.cmakein
zconf.h.included
zconf-ng.h
zconf-ng.h.cmakein
ztest*
configure.log
a.out
/Makefile
/arch/arm/Makefile
/arch/generic/Makefile
/arch/power/Makefile
/arch/x86/Makefile
.kdev4
*.kdev4
/Debug
/example.dir
/minigzip.dir
/zlib.dir
/zlibstatic.dir
/win32/Debug
/build/
/build[.-]*/
/btmp[12]/
/pkgtmp[12]/
/.idea
/cmake-build-debug

View File

@ -1 +0,0 @@
disable=SC2140,SC2086,SC2046,SC2015,SC1097,SC1035,SC1036,SC1007,SC2154,SC2155,SC2000,SC2034,SC2016,SC1091,SC1090,SC2212,SC2143,SC2129,SC2102,SC2069,SC1041,SC1042,SC1044,SC1046,SC1119,SC1110,SC1111,SC1112,SC1102,SC1105,SC1101,SC1004,SC1003,SC1012,SC2068,SC2065,SC2064,SC2063,SC2059,SC2053,SC2048,SC2044,SC2032,SC2031,SC2030,SC2029,SC2025,SC2024,SC2022,SC2018,SC2019,SC2017,SC2014,SC2013,SC2012,SC2009,SC2001,SC2098,SC2096,SC2094,SC2091,SC2092,SC2088,SC2087,SC2076,SC2072,SC2071,SC2223,SC2221,SC2222,SC2217,SC2207,SC2206,SC2205,SC2190,SC2188,SC2187,SC2185,SC2179,SC2178,SC2174,SC2168,SC2167,SC2163,SC2161,SC2160,SC2153,SC2150,SC2148,SC2147,SC2146,SC2142,SC2139,SC2126,SC2123,SC2120,SC2119,SC2117,SC2114,SC1117,SC2164,SC1083,SC2004,SC2125,SC2128,SC2011,SC1008,SC1019,SC2093,SC1132,SC1129,SC2236,SC2237,SC2231,SC2230,SC2229,SC2106,SC2102,SC2243,SC2244,SC2245,SC2247,SC2248,SC2249,SC2250,SC2251,SC2252,SC2181

File diff suppressed because it is too large Load Diff

View File

@ -1,374 +0,0 @@
##
# THIS IS AN UNMAINTAINED COPY OF THE ORIGINAL FILE DISTRIBUTED WITH ZLIB 1.2.11
##
Frequently Asked Questions about zlib
If your question is not there, please check the zlib home page
http://zlib.net/ which may have more recent information.
The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
1. Is zlib Y2K-compliant?
Yes. zlib doesn't handle dates.
2. Where can I get a Windows DLL version?
The zlib sources can be compiled without change to produce a DLL. See the
file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the
precompiled DLL are found in the zlib web site at http://zlib.net/ .
3. Where can I get a Visual Basic interface to zlib?
See
* http://marknelson.us/1997/01/01/zlib-engine/
* win32/DLL_FAQ.txt in the zlib distribution
4. compress() returns Z_BUF_ERROR.
Make sure that before the call of compress(), the length of the compressed
buffer is equal to the available size of the compressed buffer and not
zero. For Visual Basic, check that this parameter is passed by reference
("as any"), not by value ("as long").
5. deflate() or inflate() returns Z_BUF_ERROR.
Before making the call, make sure that avail_in and avail_out are not zero.
When setting the parameter flush equal to Z_FINISH, also make sure that
avail_out is big enough to allow processing all pending input. Note that a
Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
made with more input or output space. A Z_BUF_ERROR may in fact be
unavoidable depending on how the functions are used, since it is not
possible to tell whether or not there is more output pending when
strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a
heavily annotated example.
6. Where's the zlib documentation (man pages, etc.)?
It's in zlib.h . Examples of zlib usage are in the files test/example.c
and test/minigzip.c, with more in examples/ .
7. Why don't you use GNU autoconf or libtool or ...?
Because we would like to keep zlib as a very small and simple package.
zlib is rather portable and doesn't need much configuration.
8. I found a bug in zlib.
Most of the time, such problems are due to an incorrect usage of zlib.
Please try to reproduce the problem with a small program and send the
corresponding source to us at zlib@gzip.org . Do not send multi-megabyte
data files without prior agreement.
9. Why do I get "undefined reference to gzputc"?
If "make test" produces something like
example.o(.text+0x154): undefined reference to `gzputc'
check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
/usr/X11R6/lib. Remove any old versions, then do "make install".
10. I need a Delphi interface to zlib.
See the contrib/delphi directory in the zlib distribution.
11. Can zlib handle .zip archives?
Not by itself, no. See the directory contrib/minizip in the zlib
distribution.
12. Can zlib handle .Z files?
No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
the code of uncompress on your own.
13. How can I make a Unix shared library?
By default a shared (and a static) library is built for Unix. So:
make distclean
./configure
make
14. How do I install a shared zlib library on Unix?
After the above, then:
make install
However, many flavors of Unix come with a shared zlib already installed.
Before going to the trouble of compiling a shared version of zlib and
trying to install it, you may want to check if it's already there! If you
can #include <zlib.h>, it's there. The -lz option will probably link to
it. You can check the version at the top of zlib.h or with the
ZLIB_VERSION symbol defined in zlib.h .
15. I have a question about OttoPDF.
We are not the authors of OttoPDF. The real author is on the OttoPDF web
site: Joel Hainley, jhainley@myndkryme.com.
16. Can zlib decode Flate data in an Adobe PDF file?
Yes. See http://www.pdflib.com/ . To modify PDF forms, see
http://sourceforge.net/projects/acroformtool/ .
17. Why am I getting this "register_frame_info not found" error on Solaris?
After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
generates an error such as:
ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
symbol __register_frame_info: referenced symbol not found
The symbol __register_frame_info is not part of zlib, it is generated by
the C compiler (cc or gcc). You must recompile applications using zlib
which have this problem. This problem is specific to Solaris. See
http://www.sunfreeware.com for Solaris versions of zlib and applications
using zlib.
18. Why does gzip give an error on a file I make with compress/deflate?
The compress and deflate functions produce data in the zlib format, which
is different and incompatible with the gzip format. The gz* functions in
zlib on the other hand use the gzip format. Both the zlib and gzip formats
use the same compressed data format internally, but have different headers
and trailers around the compressed data.
19. Ok, so why are there two different formats?
The gzip format was designed to retain the directory information about a
single file, such as the name and last modification date. The zlib format
on the other hand was designed for in-memory and communication channel
applications, and has a much more compact header and trailer and uses a
faster integrity check than gzip.
20. Well that's nice, but how do I make a gzip file in memory?
You can request that deflate write the gzip format instead of the zlib
format using deflateInit2(). You can also request that inflate decode the
gzip format using inflateInit2(). Read zlib.h for more details.
21. Is zlib thread-safe?
Yes. However any library routines that zlib uses and any application-
provided memory allocation routines must also be thread-safe. zlib's gz*
functions use stdio library routines, and most of zlib's functions use the
library memory allocation routines by default. zlib's *Init* functions
allow for the application to provide custom memory allocation routines.
Of course, you should only operate on any given zlib or gzip stream from a
single thread at a time.
22. Can I use zlib in my commercial application?
Yes. Please read the license in zlib.h.
23. Is zlib under the GNU license?
No. Please read the license in zlib.h.
24. The license says that altered source versions must be "plainly marked". So
what exactly do I need to do to meet that requirement?
You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In
particular, the final version number needs to be changed to "f", and an
identification string should be appended to ZLIB_VERSION. Version numbers
x.x.x.f are reserved for modifications to zlib by others than the zlib
maintainers. For example, if the version of the base zlib you are altering
is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also
update the version strings in deflate.c and inftrees.c.
For altered source distributions, you should also note the origin and
nature of the changes in zlib.h, as well as in ChangeLog and README, along
with the dates of the alterations. The origin should include at least your
name (or your company's name), and an email address to contact for help or
issues with the library.
Note that distributing a compiled zlib library along with zlib.h and
zconf.h is also a source distribution, and so you should change
ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
in zlib.h as you would for a full source distribution.
25. Will zlib work on a big-endian or little-endian architecture, and can I
exchange compressed data between them?
Yes and yes.
26. Will zlib work on a 64-bit machine?
Yes. It has been tested on 64-bit machines, and has no dependence on any
data types being limited to 32-bits in length. If you have any
difficulties, please provide a complete problem report to zlib@gzip.org
27. Will zlib decompress data from the PKWare Data Compression Library?
No. The PKWare DCL uses a completely different compressed data format than
does PKZIP and zlib. However, you can look in zlib's contrib/blast
directory for a possible solution to your problem.
28. Can I access data randomly in a compressed stream?
No, not without some preparation. If when compressing you periodically use
Z_FULL_FLUSH, carefully write all the pending data at those points, and
keep an index of those locations, then you can start decompression at those
points. You have to be careful to not use Z_FULL_FLUSH too often, since it
can significantly degrade compression. Alternatively, you can scan a
deflate stream once to generate an index, and then use that index for
random access. See examples/zran.c .
29. Does zlib work on MVS, OS/390, CICS, etc.?
It has in the past, but we have not heard of any recent evidence. There
were working ports of zlib 1.1.4 to MVS, but those links no longer work.
If you know of recent, successful applications of zlib on these operating
systems, please let us know. Thanks.
30. Is there some simpler, easier to read version of inflate I can look at to
understand the deflate format?
First off, you should read RFC 1951. Second, yes. Look in zlib's
contrib/puff directory.
31. Does zlib infringe on any patents?
As far as we know, no. In fact, that was originally the whole point behind
zlib. Look here for some more information:
http://www.gzip.org/#faq11
32. Can zlib work with greater than 4 GB of data?
Yes. inflate() and deflate() will process any amount of data correctly.
Each call of inflate() or deflate() is limited to input and output chunks
of the maximum value that can be stored in the compiler's "unsigned int"
type, but there is no limit to the number of chunks. Note however that the
strm.total_in and strm_total_out counters may be limited to 4 GB. These
counters are provided as a convenience and are not used internally by
inflate() or deflate(). The application can easily set up its own counters
updated after each call of inflate() or deflate() to count beyond 4 GB.
compress() and uncompress() may be limited to 4 GB, since they operate in a
single call. gzseek() and gztell() may be limited to 4 GB depending on how
zlib is compiled. See the zlibCompileFlags() function in zlib.h.
The word "may" appears several times above since there is a 4 GB limit only
if the compiler's "long" type is 32 bits. If the compiler's "long" type is
64 bits, then the limit is 16 exabytes.
33. Does zlib have any security vulnerabilities?
The only one that we are aware of is potentially in gzprintf(). If zlib is
compiled to use sprintf() or vsprintf(), then there is no protection
against a buffer overflow of an 8K string space (or other value as set by
gzbuffer()), other than the caller of gzprintf() assuring that the output
will not exceed 8K. On the other hand, if zlib is compiled to use
snprintf() or vsnprintf(), which should normally be the case, then there is
no vulnerability. The ./configure script will display warnings if an
insecure variation of sprintf() will be used by gzprintf(). Also the
zlibCompileFlags() function will return information on what variant of
sprintf() is used by gzprintf().
If you don't have snprintf() or vsnprintf() and would like one, you can
find a portable implementation here:
http://www.ijs.si/software/snprintf/
Note that you should be using the most recent version of zlib. Versions
1.1.3 and before were subject to a double-free vulnerability, and versions
1.2.1 and 1.2.2 were subject to an access exception when decompressing
invalid compressed data.
34. Is there a Java version of zlib?
Probably what you want is to use zlib in Java. zlib is already included
as part of the Java SDK in the java.util.zip package. If you really want
a version of zlib written in the Java language, look on the zlib home
page for links: http://zlib.net/ .
35. I get this or that compiler or source-code scanner warning when I crank it
up to maximally-pedantic. Can't you guys write proper code?
Many years ago, we gave up attempting to avoid warnings on every compiler
in the universe. It just got to be a waste of time, and some compilers
were downright silly as well as contradicted each other. So now, we simply
make sure that the code always works.
36. Valgrind (or some similar memory access checker) says that deflate is
performing a conditional jump that depends on an uninitialized value.
Isn't that a bug?
No. That is intentional for performance reasons, and the output of deflate
is not affected. This only started showing up recently since zlib 1.2.x
uses malloc() by default for allocations, whereas earlier versions used
calloc(), which zeros out the allocated memory. Even though the code was
correct, versions 1.2.4 and later was changed to not stimulate these
checkers.
37. Will zlib read the (insert any ancient or arcane format here) compressed
data format?
Probably not. Look in the comp.compression FAQ for pointers to various
formats and associated software.
38. How can I encrypt/decrypt zip files with zlib?
zlib doesn't support encryption. The original PKZIP encryption is very
weak and can be broken with freely available programs. To get strong
encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
compression. For PKZIP compatible "encryption", look at
http://www.info-zip.org/
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
"gzip" is the gzip format, and "deflate" is the zlib format. They should
probably have called the second one "zlib" instead to avoid confusion with
the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
correctly points to the zlib specification in RFC 1950 for the "deflate"
transfer encoding, there have been reports of servers and browsers that
incorrectly produce or expect raw deflate data per the deflate
specification in RFC 1951, most notably Microsoft. So even though the
"deflate" transfer encoding using the zlib format would be the more
efficient approach (and in fact exactly what the zlib format was designed
for), using the "gzip" transfer encoding is probably more reliable due to
an unfortunate choice of name on the part of the HTTP 1.1 authors.
Bottom line: use the gzip format for HTTP 1.1 encoding.
40. Does zlib support the new "Deflate64" format introduced by PKWare?
No. PKWare has apparently decided to keep that format proprietary, since
they have not documented it as they have previous compression formats. In
any case, the compression improvements are so modest compared to other more
modern approaches, that it's not worth the effort to implement.
41. I'm having a problem with the zip functions in zlib, can you help?
There are no zip functions in zlib. You are probably using minizip by
Giles Vollant, which is found in the contrib directory of zlib. It is not
part of zlib. In fact none of the stuff in contrib is part of zlib. The
files in there are not supported by the zlib authors. You need to contact
the authors of the respective contribution for help.
42. The match.asm code in contrib is under the GNU General Public License.
Since it's part of zlib, doesn't that mean that all of zlib falls under the
GNU GPL?
No. The files in contrib are not part of zlib. They were contributed by
other authors and are provided as a convenience to the user within the zlib
distribution. Each item in contrib has its own license.
43. Is zlib subject to export controls? What is its ECCN?
zlib is not subject to export controls, and so is classified as EAR99.
44. Can you please sign these lengthy legal documents and fax them back to us
so that we can use your software in our product?
No. Go away. Shoo.

View File

@ -1,37 +0,0 @@
Contents
--------
| Name | Description |
|:-----------------|:---------------------------------------------------------------|
| arch/ | Architecture-specific code |
| doc/ | Documentation for formats and algorithms |
| test/example.c | Zlib usages examples for build testing |
| test/minigzip.c | Minimal gzip-like functionality for build testing |
| test/infcover.c | Inflate code coverage for build testing |
| win32/ | Shared library version resources for Windows |
| CMakeLists.txt | Cmake build script |
| configure | Bash configure/build script |
| adler32.c | Compute the Adler-32 checksum of a data stream |
| chunkset.* | Inline functions to copy small data chunks |
| compress.c | Compress a memory buffer |
| deflate.* | Compress data using the deflate algorithm |
| deflate_fast.c | Compress data using the deflate algorithm with fast strategy |
| deflate_medium.c | Compress data using the deflate algorithm with medium strategy |
| deflate_slow.c | Compress data using the deflate algorithm with slow strategy |
| functable.* | Struct containing function pointers to optimized functions |
| gzguts.h | Internal definitions for gzip operations |
| gzlib.c | Functions common to reading and writing gzip files |
| gzread.c | Read gzip files |
| gzwrite.c | Write gzip files |
| infback.* | Inflate using a callback interface |
| inflate.* | Decompress data |
| inffast.* | Decompress data with speed optimizations |
| inffixed_tbl.h | Table for decoding fixed codes |
| inftrees.h | Generate Huffman trees for efficient decoding |
| trees.* | Output deflated data using Huffman coding |
| uncompr.c | Decompress a memory buffer |
| zconf.h.cmakein | zconf.h template for cmake |
| zendian.h | BYTE_ORDER for endian tests |
| zlib.3 | Man page for zlib |
| zlib.map | Linux symbol information |
| zlib.pc.in | Pkg-config template |

View File

@ -1,19 +0,0 @@
(C) 1995-2013 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors 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 software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
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 software.
3. This notice may not be removed or altered from any source distribution.

View File

@ -1,441 +0,0 @@
# Makefile for zlib
# Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
# For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type:
# ./configure; make test
# Normally configure builds both a static and a shared library.
# If you want to build just a static library, use: ./configure --static
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
# make install
# To install in $HOME instead of /usr/local, use:
# make install prefix=$HOME
CC=cc
CFLAGS=-O
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DZLIB_DEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
# -Wstrict-prototypes -Wmissing-prototypes
SFLAGS=-O
LDFLAGS=-L.
LIBNAME1=libz-ng
LIBNAME2=zlib-ng
SUFFIX=-ng
TEST_LIBS=$(LIBNAME1).a
LDSHARED=$(CC)
LDSHAREDFLAGS=-shared
VER=2.0.0-RC2
VER1=2
STATICLIB=$(LIBNAME1).a
SHAREDLIB=$(LIBNAME1).so
SHAREDLIBV=$(LIBNAME1).so.$(VER)
SHAREDLIBM=$(LIBNAME1).so.$(VER1)
IMPORTLIB=
SHAREDTARGET=$(LIBNAME1).so.$(VER)
PKGFILE=$(LIBNAME2).pc
LIBS=$(STATICLIB) $(SHAREDTARGET)
AR=ar
ARFLAGS=rc
DEFFILE=
RC=
RCFLAGS=
RCOBJS=
STRIP=
RANLIB=ranlib
LDCONFIG=ldconfig
LDSHAREDLIBC=
EXE=
SRCDIR=.
INCLUDES=-I$(SRCDIR)
ARCHDIR=arch/generic
ARCH_STATIC_OBJS=
ARCH_SHARED_OBJS=
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib
sharedlibdir = ${libdir}
includedir = ${prefix}/include
mandir = ${prefix}/share/man
man3dir = ${mandir}/man3
pkgconfigdir = ${libdir}/pkgconfig
OBJZ = \
adler32.o \
chunkset.o \
compare258.o \
compress.o \
crc32.o \
crc32_comb.o \
deflate.o \
deflate_fast.o \
deflate_medium.o \
deflate_quick.o \
deflate_slow.o \
functable.o \
infback.o \
inffast.o \
inflate.o \
inftrees.o \
insert_string.o \
trees.o \
uncompr.o \
zutil.o \
$(ARCH_STATIC_OBJS)
OBJG = \
gzlib.o \
gzread.o \
gzwrite.o
OBJC = $(OBJZ) $(OBJG)
PIC_OBJZ = \
adler32.lo \
chunkset.lo \
compare258.lo \
compress.lo \
crc32.lo \
crc32_comb.lo \
deflate.lo \
deflate_fast.lo \
deflate_medium.lo \
deflate_quick.lo \
deflate_slow.lo \
functable.lo \
infback.lo \
inffast.lo \
inflate.lo \
inftrees.lo \
insert_string.lo \
trees.lo \
uncompr.lo \
zutil.lo \
$(ARCH_SHARED_OBJS)
PIC_OBJG = \
gzlib.lo \
gzread.lo \
gzwrite.lo
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
OBJS = $(OBJC)
PIC_OBJS = $(PIC_OBJC)
all: static shared
static: adler32_test$(EXE) example$(EXE) minigzip$(EXE) fuzzers makefixed$(EXE) maketrees$(EXE) makecrct$(EXE)
shared: adler32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE)
check: test
.SECONDARY:
$(ARCHDIR)/%.o: $(SRCDIR)/$(ARCHDIR)/%.c
$(MAKE) -C $(ARCHDIR) $(notdir $@)
$(ARCHDIR)/%.lo: $(SRCDIR)/$(ARCHDIR)/%.c
$(MAKE) -C $(ARCHDIR) $(notdir $@)
%.o: $(ARCHDIR)/%.o
-cp $< $@
%.lo: $(ARCHDIR)/%.lo
-cp $< $@
test: all
$(MAKE) -C test
# This variable is set by configure.
WITH_FUZZERS=
# By default, use our own standalone_fuzz_target_runner.
# This runner does no fuzzing, but simply executes the inputs
# provided via parameters.
# Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
# to link the fuzzer(s) against a real fuzzing engine.
ifeq (,$(LIB_FUZZING_ENGINE))
LIB_FUZZING_ENGINE = standalone_fuzz_target_runner.o
else
# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
WITH_FUZZERS=1
endif
ifeq (1,$(WITH_FUZZERS))
fuzzers: checksum_fuzzer$(EXE) compress_fuzzer$(EXE) example_small_fuzzer$(EXE) example_large_fuzzer$(EXE) example_flush_fuzzer$(EXE) example_dict_fuzzer$(EXE) minigzip_fuzzer$(EXE)
else
fuzzers:
endif
# The standalone fuzz target runner.
standalone_fuzz_target_runner.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
checksum_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
compress_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
example_small_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
example_large_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
example_flush_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
example_dict_fuzzer.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
minigzip_fuzzer.o:
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
checksum_fuzzer$(EXE): checksum_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) checksum_fuzzer.o $(STATICLIB) -lpthread
compress_fuzzer$(EXE): compress_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) compress_fuzzer.o $(STATICLIB) -lpthread
example_small_fuzzer$(EXE): example_small_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_small_fuzzer.o $(STATICLIB) -lpthread
example_large_fuzzer$(EXE): example_large_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_large_fuzzer.o $(STATICLIB) -lpthread
example_flush_fuzzer$(EXE): example_flush_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_flush_fuzzer.o $(STATICLIB) -lpthread
example_dict_fuzzer$(EXE): example_dict_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_dict_fuzzer.o $(STATICLIB) -lpthread
minigzip_fuzzer$(EXE): minigzip_fuzzer.o standalone_fuzz_target_runner.o $(OBJG) $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) minigzip_fuzzer.o $(OBJG) $(STATICLIB) -lpthread
infcover.o: $(SRCDIR)/test/infcover.c $(SRCDIR)/zlib$(SUFFIX).h zconf$(SUFFIX).h
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/infcover.c
infcover$(EXE): infcover.o $(STATICLIB)
$(CC) $(LDFLAGS) -o $@ infcover.o $(STATICLIB)
ifneq ($(STRIP),)
$(STRIP) $@
endif
cover: infcover$(EXE)
rm -f *.gcda
./infcover
gcov inf*.c
$(STATICLIB): $(OBJS)
$(AR) $(ARFLAGS) $@ $(OBJS)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
adler32_test.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/adler32_test.c
example.o:
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
minigzip.o:
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
makefixed.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makefixed.c
maketrees.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/maketrees.c
makecrct.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makecrct.c
zlibrc.o: win32/zlib$(SUFFIX)1.rc
$(RC) $(RCFLAGS) -o $@ win32/zlib$(SUFFIX)1.rc
.SUFFIXES: .lo
%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
%.lo: $(SRCDIR)/%.c
$(CC) $(SFLAGS) -DPIC $(INCLUDES) -c -o $@ $<
$(OBJG): %.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
$(SHAREDTARGET): $(PIC_OBJS) $(DEFFILE) $(RCOBJS)
ifneq ($(SHAREDTARGET),)
$(LDSHARED) $(CFLAGS) $(LDSHAREDFLAGS) $(LDFLAGS) -o $@ $(DEFFILE) $(PIC_OBJS) $(RCOBJS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
ifneq ($(SHAREDLIB),$(SHAREDTARGET))
rm -f $(SHAREDLIB) $(SHAREDLIBM)
ln -s $@ $(SHAREDLIB)
ln -s $@ $(SHAREDLIBM)
endif
endif
adler32_test$(EXE): adler32_test.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ adler32_test.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
example$(EXE): example.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
minigzip$(EXE): minigzip.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
adler32_testsh$(EXE): adler32_test.o $(OBJG) $(SHAREDTARGET)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ adler32_test.o $(OBJG) $(SHAREDTARGET) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
examplesh$(EXE): example.o $(OBJG) $(SHAREDTARGET)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(OBJG) $(SHAREDTARGET) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
minigzipsh$(EXE): minigzip.o $(OBJG) $(SHAREDTARGET)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(OBJG) $(SHAREDTARGET) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
makefixed$(EXE): makefixed.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ makefixed.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
maketrees$(EXE): maketrees.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ maketrees.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
makecrct$(EXE): makecrct.o $(OBJG) $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ makecrct.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
ifneq ($(STRIP),)
$(STRIP) $@
endif
install-shared: $(SHAREDTARGET)
ifneq ($(SHAREDTARGET),)
-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDTARGET)
cp $(SHAREDTARGET) $(DESTDIR)$(sharedlibdir)
chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDTARGET)
ifneq ($(SHAREDLIB),$(SHAREDTARGET))
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM)
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB)
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM)
($(LDCONFIG) || true) >/dev/null 2>&1
# ldconfig is for Linux
endif
ifneq ($(IMPORTLIB),)
cp $(IMPORTLIB) $(DESTDIR)$(sharedlibdir)
chmod 644 $(DESTDIR)$(sharedlibdir)/$(IMPORTLIB)
endif
endif
install-static: $(STATICLIB)
-@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
rm -f $(DESTDIR)$(libdir)/$(STATICLIB)
cp $(STATICLIB) $(DESTDIR)$(libdir)
chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
-@($(RANLIB) $(DESTDIR)$(libdir)/$(STATICLIB) || true) >/dev/null 2>&1
# The ranlib in install-static is needed on NeXTSTEP which checks file times
install-libs: install-shared install-static
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
rm -f $(DESTDIR)$(man3dir)/zlib$(SUFFIX).3
cp $(SRCDIR)/zlib.3 $(DESTDIR)$(man3dir)/zlib$(SUFFIX).3
chmod 644 $(DESTDIR)$(man3dir)/zlib$(SUFFIX).3
rm -f $(DESTDIR)$(pkgconfigdir)/$(PKGFILE)
cp $(PKGFILE) $(DESTDIR)$(pkgconfigdir)
chmod 644 $(DESTDIR)$(pkgconfigdir)/$(PKGFILE)
install: install-libs
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
rm -f $(DESTDIR)$(includedir)/zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h
cp $(SRCDIR)/zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zlib$(SUFFIX).h
cp zconf$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h
chmod 644 $(DESTDIR)$(includedir)/zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h
uninstall-static:
cd $(DESTDIR)$(libdir) && rm -f $(STATICLIB)
uninstall-shared:
ifneq ($(SHAREDLIB),)
cd $(DESTDIR)$(sharedlibdir) && rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM)
endif
ifneq ($(IMPORTLIB),)
cd $(DESTDIR)$(sharedlibdir) && rm -f $(IMPORTLIB)
endif
uninstall: uninstall-static uninstall-shared
cd $(DESTDIR)$(includedir) && rm -f zlib$(SUFFIX).h zconf$(SUFFIX).h
cd $(DESTDIR)$(man3dir) && rm -f zlib$(SUFFIX).3
cd $(DESTDIR)$(pkgconfigdir) && rm -f $(PKGFILE)
docs: zlib.3.pdf
zlib.3.pdf: $(SRCDIR)/zlib.3
groff -mandoc -f H -T ps $(SRCDIR)/zlib.3 | ps2pdf - zlib.3.pdf
mostlyclean: clean
clean:
@if [ -f $(ARCHDIR)/Makefile ]; then $(MAKE) -C $(ARCHDIR) clean; fi
@if [ -f test/Makefile ]; then $(MAKE) -C test clean; fi
rm -f *.o *.lo *~ \
adler32_test$(EXE) example$(EXE) minigzip$(EXE) \
adler32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
checksum_fuzzer$(EXE) compress_fuzzer$(EXE) example_small_fuzzer$(EXE) example_large_fuzzer$(EXE) \
example_flush_fuzzer$(EXE) example_dict_fuzzer$(EXE) minigzip_fuzzer$(EXE) \
infcover makefixed$(EXE) maketrees$(EXE) makecrct$(EXE) \
$(STATICLIB) $(IMPORTLIB) $(SHAREDLIB) $(SHAREDLIBV) $(SHAREDLIBM) \
foo.gz so_locations \
_match.s maketree
rm -rf objs
rm -f *.gcda *.gcno *.gcov
rm -f a.out a.exe
rm -f *.pc
rm -f *._h
rm -rf btmp1 btmp2 pkgtmp1 pkgtmp2
maintainer-clean: distclean
distclean: clean
@if [ -f $(ARCHDIR)/Makefile ]; then $(MAKE) -C $(ARCHDIR) distclean; fi
@if [ -f test/Makefile ]; then $(MAKE) -C test distclean; fi
rm -f $(PKGFILE) configure.log zconf.h zconf.h.cmakein
-@rm -f .DS_Store
# Reset Makefile if building inside source tree
@if [ -f Makefile.in ]; then \
printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile ; \
printf '\ndistclean:\n\t$(MAKE) -f Makefile.in distclean\n' >> Makefile ; \
touch -r $(SRCDIR)/Makefile.in Makefile ; fi
# Reset zconf.h and zconf.h.cmakein if building inside source tree
@if [ -f zconf.h.in ]; then \
cp -p $(SRCDIR)/zconf.h.in zconf.h ; \
grep -v '^#cmakedefine' $(SRCDIR)/zconf.h.in > zconf.h.cmakein &&\
touch -r $(SRCDIR)/zconf.h.in zconf.h.cmakein ; fi
# Cleanup these files if building outside source tree
@if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf Makefile; fi
# Remove arch and test directory if building outside source tree
@if [ ! -f $(ARCHDIR)/Makefile.in ]; then rm -rf arch; fi
@if [ ! -f test/Makefile.in ]; then rm -rf test; fi
tags:
etags $(SRCDIR)/*.[ch]

View File

@ -1,206 +0,0 @@
## zlib-ng
*zlib data compression library for the next generation systems*
Maintained by Hans Kristian Rosbach
aka Dead2 (zlib-ng àt circlestorm dót org)
|CI|Status|
|:-|-|
|GitHub Actions|[![Master Branch Status](https://github.com/zlib-ng/zlib-ng/workflows/CI%20CMake/badge.svg)](https://github.com/zlib-ng/zlib-ng/actions) [![Master Branch Status](https://github.com/zlib-ng/zlib-ng/workflows/CI%20Configure/badge.svg)](https://github.com/zlib-ng/zlib-ng/actions) [![Master Branch Status](https://github.com/zlib-ng/zlib-ng/workflows/CI%20NMake/badge.svg)](https://github.com/zlib-ng/zlib-ng/actions)|
|Buildkite|[![Build status](https://badge.buildkite.com/7bb1ef84356d3baee26202706cc053ee1de871c0c712b65d26.svg?branch=develop)](https://buildkite.com/circlestorm-productions/zlib-ng)|
|CodeFactor|[![CodeFactor](https://www.codefactor.io/repository/github/zlib-ng/zlib-ng/badge)](https://www.codefactor.io/repository/github/zlib-ng/zlib-ng)|
|OSS-Fuzz|[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/zlib-ng.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:zlib-ng)
|Codecov|[![codecov.io](https://codecov.io/github/zlib-ng/zlib-ng/coverage.svg?branch=develop)](https://codecov.io/github/zlib-ng/zlib-ng/)|
Features
--------
* Zlib compatible API with support for dual-linking
* Modernized native API based on zlib API for ease of porting
* Modern C99 syntax and a clean code layout
* Deflate medium and quick algorithms based on Intels zlib fork
* Support for CPU intrinsics when available
* Adler32 implementation using SSSE3, AVX2, Neon & VSX
* CRC32-B implementation using PCLMULQDQ & ACLE
* Hash table implementation using CRC32-C intrinsics on x86 and ARM
* Slide hash implementations using SSE2, AVX2, Neon & VSX
* Compare256/258 implementations using SSE4.2 & AVX2
* Inflate chunk copying using SSE2, AVX2 & Neon
* Support for hardware-accelerated deflate using IBM Z DFLTCC
* Unaligned memory read/writes and large bit buffer improvements
* Includes improvements from Cloudflare and Intel forks
* Configure, CMake, and NMake build system support
* Comprehensive set of CMake unit tests
* Code sanitizers, fuzzing, and coverage
* GitHub Actions continuous integration on Windows, macOS, and Linux
* Emulated CI for ARM, AARCH64, PPC, PPC64, SPARC64, S390x using qemu
Fork Motivation
---------------------------
The motivation for this fork was due to seeing several 3rd party
contributions containing new optimizations not getting implemented
into the official zlib repository.
Mark Adler has been maintaining zlib for a very long time, and he has
done a great job and hopefully he will continue for a long time yet.
The idea of zlib-ng is not to replace zlib, but to co-exist as a
drop-in replacement with a lower threshold for code change.
zlib has a long history and is incredibly portable, even supporting
lots of systems that predate the Internet. This is great, but it does
complicate further development and maintainability.
The zlib code has numerous workarounds for old compilers that do not
understand ANSI-C or to accommodate systems with limitations such as
operating in a 16-bit environment.
Many of these workarounds are only maintenance burdens, some of them
are pretty huge code-wise. For example, the [v]s[n]printf workaround
code has a whopping 8 different implementations just to cater to
various old compilers. With this many workarounds cluttered throughout
the code, new programmers with an idea/interest for zlib will need
to take some time to figure out why all of these seemingly strange
things are used, and how to work within those confines.
So I decided to make a fork, merge all the Intel optimizations, merge
the Cloudflare optimizations that did not conflict, plus a couple
of other smaller patches. Then I started cleaning out workarounds,
various dead code, all contrib and example code as there is little
point in having those in this fork for various reasons.
A lot of improvements have gone into zlib-ng since its start, and
numerous people and companies have contributed both small and big
improvements, or valuable testing.
Please read LICENSE.md, it is very simple and very liberal.
Build
-----
There are two ways to build zlib-ng:
### Cmake
To build zlib-ng using the cross-platform makefile generator cmake.
```
cmake .
cmake --build . --config Release
ctest --verbose -C Release
```
Alternatively, you can use the cmake configuration GUI tool ccmake:
```
ccmake .
```
### Configure
To build zlib-ng using the bash configure script:
```
./configure
make
make test
```
Build Options
-------------
| CMake | configure | Description | Default |
|:-------------------------|:-------------------------|:--------------------------------------------------------------------------------------|---------|
| ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF |
| ZLIB_ENABLE_TESTS | | Build test binaries | ON |
| WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON |
| WITH_OPTIM | --without-optimizations | Build with optimisations | ON |
| WITH_NEW_STRATEGIES | --without-new-strategies | Use new strategies | ON |
| WITH_NATIVE_INSTRUCTIONS | --native | Compiles with full instruction set supported on this host (gcc/clang -march=native) | OFF |
| WITH_SANITIZER | --with-sanitizer | Build with sanitizer (memory, address, undefined) | OFF |
| WITH_FUZZERS | --with-fuzzers | Build test/fuzz | OFF |
| WITH_MAINTAINER_WARNINGS | | Build with project maintainer warnings | OFF |
| WITH_CODE_COVERAGE | | Enable code coverage reporting | OFF |
Install
-------
WARNING: We do not recommend manually installing unless you really
know what you are doing, because this can potentially override the system
default zlib library, and any incompatibility or wrong configuration of
zlib-ng can make the whole system unusable, requiring recovery or reinstall.
If you still want a manual install, we recommend using the /opt/ path prefix.
For Linux distros, an alternative way to use zlib-ng (if compiled in
zlib-compat mode) instead of zlib, is through the use of the
_LD_PRELOAD_ environment variable. If the program is dynamically linked
with zlib, then zlib-ng will temporarily be used instead by the program,
without risking system-wide instability.
```
LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.11.zlib-ng /usr/bin/program
```
### Cmake
To install zlib-ng system-wide using cmake:
```
cmake --build . --target install
```
### Configure
To install zlib-ng system-wide using the configure script:
```
make install
```
Contributing
------------
Zlib-ng is a aiming to be open to contributions, and we would be
delighted to receive pull requests on github.
Just remember that any code you submit must be your own and it must
be zlib licensed.
Help with testing and reviewing of pull requests etc is also very
much appreciated.
If you are interested in contributing, please consider joining our
IRC channel #zlib-ng on the Freenode IRC network.
Acknowledgments
----------------
Thanks to Servebolt.com for sponsoring my maintainership of zlib-ng.
Thanks go out to all the people and companies who have taken the time
to contribute code reviews, testing and/or patches. Zlib-ng would not
have been nearly as good without you.
The deflate format used by zlib was defined by Phil Katz.
The deflate and zlib specifications were written by L. Peter Deutsch.
zlib was originally created by Jean-loup Gailly (compression)
and Mark Adler (decompression).
Advanced Build Options
----------------------
| CMake | configure | Description | Default |
|:--------------------------------|:----------------------|:--------------------------------------------------------------------|------------------------|
| ZLIB_DUAL_LINK | | Dual link tests with system zlib | OFF |
| | --force-sse2 | Assume SSE2 instructions are always available | ON (x86), OFF (x86_64) |
| WITH_AVX2 | | Build with AVX2 intrinsics | ON |
| WITH_SSE2 | | Build with SSE2 intrinsics | ON |
| WITH_SSE4 | | Build with SSE4 intrinsics | ON |
| WITH_PCLMULQDQ | | Build with PCLMULQDQ intrinsics | ON |
| WITH_ACLE | --without-acle | Build with ACLE intrinsics | ON |
| WITH_NEON | --without-neon | Build with NEON intrinsics | ON |
| WITH_POWER8 | | Build with POWER8 optimisations | ON |
| WITH_DFLTCC_DEFLATE | --with-dfltcc-deflate | Use DEFLATE COMPRESSION CALL instruction for compression on IBM Z | OFF |
| WITH_DFLTCC_INFLATE | --with-dfltcc-inflate | Use DEFLATE COMPRESSION CALL instruction for decompression on IBM Z | OFF |
| WITH_UNALIGNED | | Allow optimizations that use unaligned reads if safe on current arch| ON |
| WITH_INFLATE_STRICT | | Build with strict inflate distance checking | OFF |
| WITH_INFLATE_ALLOW_INVALID_DIST | | Build with zero fill for inflate invalid distances | OFF |
| INSTALL_UTILS | | Copy minigzip and minideflate during install | OFF |

View File

@ -1,139 +0,0 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zbuild.h"
#include "zutil.h"
#include "functable.h"
#include "adler32_p.h"
/* ========================================================================= */
Z_INTERNAL uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len) {
uint32_t sum2;
unsigned n;
/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (UNLIKELY(len == 1))
return adler32_len_1(adler, buf, sum2);
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (UNLIKELY(buf == NULL))
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_len_16(adler, buf, len, sum2);
/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
#ifdef UNROLL_MORE
n = NMAX / 16; /* NMAX is divisible by 16 */
#else
n = NMAX / 8; /* NMAX is divisible by 8 */
#endif
do {
#ifdef UNROLL_MORE
DO16(adler, sum2, buf); /* 16 sums unrolled */
buf += 16;
#else
DO8(adler, sum2, buf, 0); /* 8 sums unrolled */
buf += 8;
#endif
} while (--n);
adler %= BASE;
sum2 %= BASE;
}
/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
#ifdef UNROLL_MORE
while (len >= 16) {
len -= 16;
DO16(adler, sum2, buf);
buf += 16;
#else
while (len >= 8) {
len -= 8;
DO8(adler, sum2, buf, 0);
buf += 8;
#endif
}
while (len) {
--len;
adler += *buf++;
sum2 += adler;
}
adler %= BASE;
sum2 %= BASE;
}
/* return recombined sums */
return adler | (sum2 << 16);
}
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) {
return (unsigned long)functable.adler32((uint32_t)adler, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) {
return functable.adler32(adler, buf, len);
}
#endif
/* ========================================================================= */
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) {
return (unsigned long)functable.adler32((uint32_t)adler, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) {
return functable.adler32(adler, buf, len);
}
#endif
/* ========================================================================= */
static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
uint32_t sum1;
uint32_t sum2;
unsigned rem;
/* for negative len, return invalid adler32 as a clue for debugging */
if (len2 < 0)
return 0xffffffff;
/* the derivation of this formula is left as an exercise for the reader */
len2 %= BASE; /* assumes len2 >= 0 */
rem = (unsigned)len2;
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
sum2 %= BASE;
sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE;
if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}
/* ========================================================================= */
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32_combine)(unsigned long adler1, unsigned long adler2, z_off_t len2) {
return (unsigned long)adler32_combine_((uint32_t)adler1, (uint32_t)adler2, len2);
}
unsigned long Z_EXPORT PREFIX4(adler32_combine)(unsigned long adler1, unsigned long adler2, z_off64_t len2) {
return (unsigned long)adler32_combine_((uint32_t)adler1, (uint32_t)adler2, len2);
}
#else
uint32_t Z_EXPORT PREFIX4(adler32_combine)(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
return adler32_combine_(adler1, adler2, len2);
}
#endif

View File

@ -1,53 +0,0 @@
/* adler32_p.h -- Private inline functions and macros shared with
* different computation of the Adler-32 checksum
* of a data stream.
* Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef ADLER32_P_H
#define ADLER32_P_H
#define BASE 65521U /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(sum1, sum2, buf, i) {(sum1) += buf[(i)]; (sum2) += (sum1);}
#define DO2(sum1, sum2, buf, i) {DO1(sum1, sum2, buf, i); DO1(sum1, sum2, buf, i+1);}
#define DO4(sum1, sum2, buf, i) {DO2(sum1, sum2, buf, i); DO2(sum1, sum2, buf, i+2);}
#define DO8(sum1, sum2, buf, i) {DO4(sum1, sum2, buf, i); DO4(sum1, sum2, buf, i+4);}
#define DO16(sum1, sum2, buf) {DO8(sum1, sum2, buf, 0); DO8(sum1, sum2, buf, 8);}
static inline uint32_t adler32_len_1(uint32_t adler, const unsigned char *buf, uint32_t sum2) {
adler += buf[0];
if (adler >= BASE)
adler -= BASE;
sum2 += adler;
if (sum2 >= BASE)
sum2 -= BASE;
return adler | (sum2 << 16);
}
static inline uint32_t adler32_len_16(uint32_t adler, const unsigned char *buf, size_t len, uint32_t sum2) {
while (len) {
--len;
adler += *buf++;
sum2 += adler;
}
if (adler >= BASE)
adler -= BASE;
sum2 %= BASE; /* only added so many BASE's */
return adler | (sum2 << 16);
}
static inline uint32_t adler32_len_64(uint32_t adler, const unsigned char *buf, size_t len, uint32_t sum2) {
while (len >= 16) {
len -= 16;
DO16(adler, sum2, buf);
buf += 16;
}
/* Process tail (len < 16). */
return adler32_len_16(adler, buf, len, sum2);
}
#endif /* ADLER32_P_H */

View File

@ -1,2 +0,0 @@
# ignore Makefiles; they're all automatically generated
Makefile

View File

@ -1,68 +0,0 @@
# Makefile for zlib
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
# For conditions of distribution and use, see copyright notice in zlib.h
CC=
CFLAGS=
SFLAGS=
INCLUDES=
ACLEFLAG=
NEONFLAG=
SUFFIX=
SRCDIR=.
SRCTOP=../..
TOPDIR=$(SRCTOP)
all: \
adler32_neon.o adler32_neon.lo \
armfeature.o armfeature.lo \
chunkset_neon.o chunkset_neon.lo \
crc32_acle.o crc32_acle.lo \
slide_neon.o slide_neon.lo \
insert_string_acle.o insert_string_acle.lo
adler32_neon.o:
$(CC) $(CFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_neon.c
adler32_neon.lo:
$(CC) $(SFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_neon.c
armfeature.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/armfeature.c
armfeature.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/armfeature.c
chunkset_neon.o:
$(CC) $(CFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_neon.c
chunkset_neon.lo:
$(CC) $(SFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_neon.c
crc32_acle.o:
$(CC) $(CFLAGS) $(ACLEFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/crc32_acle.c
crc32_acle.lo:
$(CC) $(SFLAGS) $(ACLEFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/crc32_acle.c
slide_neon.o:
$(CC) $(CFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_neon.c
slide_neon.lo:
$(CC) $(SFLAGS) $(NEONFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_neon.c
insert_string_acle.o:
$(CC) $(CFLAGS) $(ACLEFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/insert_string_acle.c
insert_string_acle.lo:
$(CC) $(SFLAGS) $(ACLEFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/insert_string_acle.c
mostlyclean: clean
clean:
rm -f *.o *.lo *~
rm -rf objs
rm -f *.gcda *.gcno *.gcov
distclean:
rm -f Makefile

View File

@ -1,126 +0,0 @@
/* Copyright (C) 1995-2011, 2016 Mark Adler
* Copyright (C) 2017 ARM Holdings Inc.
* Author: Adenilson Cavalcanti <adenilson.cavalcanti@arm.com>
*
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifdef ARM_NEON_ADLER32
#ifdef _M_ARM64
# include <arm64_neon.h>
#else
# include <arm_neon.h>
#endif
#include "../../zutil.h"
#include "../../adler32_p.h"
static void NEON_accum32(uint32_t *s, const unsigned char *buf, size_t len) {
static const uint8_t taps[32] = {
32, 31, 30, 29, 28, 27, 26, 25,
24, 23, 22, 21, 20, 19, 18, 17,
16, 15, 14, 13, 12, 11, 10, 9,
8, 7, 6, 5, 4, 3, 2, 1 };
uint32x2_t adacc2, s2acc2, as;
uint8x16_t t0 = vld1q_u8(taps), t1 = vld1q_u8(taps + 16);
uint32x4_t adacc = vdupq_n_u32(0), s2acc = vdupq_n_u32(0);
adacc = vsetq_lane_u32(s[0], adacc, 0);
s2acc = vsetq_lane_u32(s[1], s2acc, 0);
while (len >= 2) {
uint8x16_t d0 = vld1q_u8(buf), d1 = vld1q_u8(buf + 16);
uint16x8_t adler, sum2;
s2acc = vaddq_u32(s2acc, vshlq_n_u32(adacc, 5));
adler = vpaddlq_u8( d0);
adler = vpadalq_u8(adler, d1);
sum2 = vmull_u8( vget_low_u8(t0), vget_low_u8(d0));
sum2 = vmlal_u8(sum2, vget_high_u8(t0), vget_high_u8(d0));
sum2 = vmlal_u8(sum2, vget_low_u8(t1), vget_low_u8(d1));
sum2 = vmlal_u8(sum2, vget_high_u8(t1), vget_high_u8(d1));
adacc = vpadalq_u16(adacc, adler);
s2acc = vpadalq_u16(s2acc, sum2);
len -= 2;
buf += 32;
}
while (len > 0) {
uint8x16_t d0 = vld1q_u8(buf);
uint16x8_t adler, sum2;
s2acc = vaddq_u32(s2acc, vshlq_n_u32(adacc, 4));
adler = vpaddlq_u8(d0);
sum2 = vmull_u8( vget_low_u8(t1), vget_low_u8(d0));
sum2 = vmlal_u8(sum2, vget_high_u8(t1), vget_high_u8(d0));
adacc = vpadalq_u16(adacc, adler);
s2acc = vpadalq_u16(s2acc, sum2);
buf += 16;
len--;
}
adacc2 = vpadd_u32(vget_low_u32(adacc), vget_high_u32(adacc));
s2acc2 = vpadd_u32(vget_low_u32(s2acc), vget_high_u32(s2acc));
as = vpadd_u32(adacc2, s2acc2);
s[0] = vget_lane_u32(as, 0);
s[1] = vget_lane_u32(as, 1);
}
static void NEON_handle_tail(uint32_t *pair, const unsigned char *buf, size_t len) {
unsigned int i;
for (i = 0; i < len; ++i) {
pair[0] += buf[i];
pair[1] += pair[0];
}
}
uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len) {
/* split Adler-32 into component sums */
uint32_t sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1)
return adler32_len_1(adler, buf, sum2);
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == NULL)
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16)
return adler32_len_16(adler, buf, len, sum2);
uint32_t pair[2];
int n = NMAX;
unsigned int done = 0;
unsigned int i;
/* Split Adler-32 into component sums, it can be supplied by
* the caller sites (e.g. in a PNG file).
*/
pair[0] = adler;
pair[1] = sum2;
for (i = 0; i < len; i += n) {
if ((i + n) > len)
n = (int)(len - i);
if (n < 16)
break;
NEON_accum32(pair, buf + i, n / 16);
pair[0] %= BASE;
pair[1] %= BASE;
done += (n / 16) * 16;
}
/* Handle the tail elements. */
if (done < len) {
NEON_handle_tail(pair, (buf + done), len - done);
pair[0] %= BASE;
pair[1] %= BASE;
}
/* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */
return (pair[1] << 16) | pair[0];
}
#endif

View File

@ -1,13 +0,0 @@
/* arm.h -- check for ARM features.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef ARM_H_
#define ARM_H_
extern int arm_cpu_has_neon;
extern int arm_cpu_has_crc32;
void Z_INTERNAL arm_check_features(void);
#endif /* ARM_H_ */

View File

@ -1,69 +0,0 @@
#include "../../zutil.h"
#if defined(__linux__)
# include <sys/auxv.h>
# include <asm/hwcap.h>
#elif defined(__FreeBSD__) && defined(__aarch64__)
# include <machine/armreg.h>
# ifndef ID_AA64ISAR0_CRC32_VAL
# define ID_AA64ISAR0_CRC32_VAL ID_AA64ISAR0_CRC32
# endif
#elif defined(__APPLE__)
# include <sys/sysctl.h>
#elif defined(_WIN32)
# include <winapifamily.h>
#endif
static int arm_has_crc32() {
#if defined(__linux__) && defined(HWCAP2_CRC32)
return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0;
#elif defined(__FreeBSD__) && defined(__aarch64__)
return getenv("QEMU_EMULATING") == NULL
&& ID_AA64ISAR0_CRC32_VAL(READ_SPECIALREG(id_aa64isar0_el1)) >= ID_AA64ISAR0_CRC32_BASE;
#elif defined(__APPLE__)
int hascrc32;
size_t size = sizeof(hascrc32);
return sysctlbyname("hw.optional.armv8_crc32", &hascrc32, &size, NULL, 0) == 0
&& hascrc32 == 1;
#elif defined(ARM_NOCHECK_ACLE)
return 1;
#else
return 0;
#endif
}
/* AArch64 has neon. */
#if !defined(__aarch64__) && !defined(_M_ARM64)
static inline int arm_has_neon() {
#if defined(__linux__) && defined(HWCAP_NEON)
return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0 ? 1 : 0;
#elif defined(__APPLE__)
int hasneon;
size_t size = sizeof(hasneon);
return sysctlbyname("hw.optional.neon", &hasneon, &size, NULL, 0) == 0
&& hasneon == 1;
#elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION)
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
return 1; /* Always supported */
# endif
#endif
#if defined(ARM_NOCHECK_NEON)
return 1;
#else
return 0;
#endif
}
#endif
Z_INTERNAL int arm_cpu_has_neon;
Z_INTERNAL int arm_cpu_has_crc32;
void Z_INTERNAL arm_check_features(void) {
#if defined(__aarch64__) || defined(_M_ARM64)
arm_cpu_has_neon = 1; /* always available */
#else
arm_cpu_has_neon = arm_has_neon();
#endif
arm_cpu_has_crc32 = arm_has_crc32();
}

View File

@ -1,54 +0,0 @@
/* chunkset_neon.c -- NEON inline functions to copy small data chunks.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifdef ARM_NEON_CHUNKSET
#ifdef _M_ARM64
# include <arm64_neon.h>
#else
# include <arm_neon.h>
#endif
#include "../../zbuild.h"
#include "../../zutil.h"
typedef uint8x16_t chunk_t;
#define HAVE_CHUNKMEMSET_1
#define HAVE_CHUNKMEMSET_2
#define HAVE_CHUNKMEMSET_4
#define HAVE_CHUNKMEMSET_8
static inline void chunkmemset_1(uint8_t *from, chunk_t *chunk) {
*chunk = vld1q_dup_u8(from);
}
static inline void chunkmemset_2(uint8_t *from, chunk_t *chunk) {
*chunk = vreinterpretq_u8_s16(vdupq_n_s16(*(int16_t *)from));
}
static inline void chunkmemset_4(uint8_t *from, chunk_t *chunk) {
*chunk = vreinterpretq_u8_s32(vdupq_n_s32(*(int32_t *)from));
}
static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
*chunk = vcombine_u8(vld1_u8(from), vld1_u8(from));
}
#define CHUNKSIZE chunksize_neon
#define CHUNKCOPY chunkcopy_neon
#define CHUNKCOPY_SAFE chunkcopy_safe_neon
#define CHUNKUNROLL chunkunroll_neon
#define CHUNKMEMSET chunkmemset_neon
#define CHUNKMEMSET_SAFE chunkmemset_safe_neon
static inline void loadchunk(uint8_t const *s, chunk_t *chunk) {
*chunk = vld1q_u8(s);
}
static inline void storechunk(uint8_t *out, chunk_t *chunk) {
vst1q_u8(out, *chunk);
}
#include "chunkset_tpl.h"
#endif

View File

@ -1,110 +0,0 @@
/* crc32_acle.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
* Copyright (C) 2016 Yang Zhang
* For conditions of distribution and use, see copyright notice in zlib.h
*
*/
#ifdef ARM_ACLE_CRC_HASH
#ifndef _MSC_VER
# include <arm_acle.h>
#endif
#include "../../zutil.h"
uint32_t crc32_acle(uint32_t crc, const unsigned char *buf, uint64_t len) {
Z_REGISTER uint32_t c;
Z_REGISTER const uint16_t *buf2;
Z_REGISTER const uint32_t *buf4;
c = ~crc;
if (len && ((ptrdiff_t)buf & 1)) {
c = __crc32b(c, *buf++);
len--;
}
if ((len > sizeof(uint16_t)) && ((ptrdiff_t)buf & sizeof(uint16_t))) {
buf2 = (const uint16_t *) buf;
c = __crc32h(c, *buf2++);
len -= sizeof(uint16_t);
buf4 = (const uint32_t *) buf2;
} else {
buf4 = (const uint32_t *) buf;
}
#if defined(__aarch64__)
if ((len > sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) {
c = __crc32w(c, *buf4++);
len -= sizeof(uint32_t);
}
const uint64_t *buf8 = (const uint64_t *) buf4;
#ifdef UNROLL_MORE
while (len >= 4 * sizeof(uint64_t)) {
c = __crc32d(c, *buf8++);
c = __crc32d(c, *buf8++);
c = __crc32d(c, *buf8++);
c = __crc32d(c, *buf8++);
len -= 4 * sizeof(uint64_t);
}
#endif
while (len >= sizeof(uint64_t)) {
c = __crc32d(c, *buf8++);
len -= sizeof(uint64_t);
}
if (len >= sizeof(uint32_t)) {
buf4 = (const uint32_t *) buf8;
c = __crc32w(c, *buf4++);
len -= sizeof(uint32_t);
buf2 = (const uint16_t *) buf4;
} else {
buf2 = (const uint16_t *) buf8;
}
if (len >= sizeof(uint16_t)) {
c = __crc32h(c, *buf2++);
len -= sizeof(uint16_t);
}
buf = (const unsigned char *) buf2;
#else /* __aarch64__ */
# ifdef UNROLL_MORE
while (len >= 8 * sizeof(uint32_t)) {
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
c = __crc32w(c, *buf4++);
len -= 8 * sizeof(uint32_t);
}
# endif
while (len >= sizeof(uint32_t)) {
c = __crc32w(c, *buf4++);
len -= sizeof(uint32_t);
}
if (len >= sizeof(uint16_t)) {
buf2 = (const uint16_t *) buf4;
c = __crc32h(c, *buf2++);
len -= sizeof(uint16_t);
buf = (const unsigned char *) buf2;
} else {
buf = (const unsigned char *) buf4;
}
#endif /* __aarch64__ */
if (len) {
c = __crc32b(c, *buf);
}
c = ~c;
return c;
}
#endif

View File

@ -1,12 +0,0 @@
#ifndef ARM_CTZL_H
#define ARM_CTZL_H
#include <armintr.h>
#if defined(_MSC_VER) && !defined(__clang__)
static __forceinline unsigned long __builtin_ctzl(unsigned long value) {
return _arm_clz(_arm_rbit(value));
}
#endif
#endif

View File

@ -1,22 +0,0 @@
/* insert_string_acle.c -- insert_string variant using ACLE's CRC instructions
*
* Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
*/
#ifdef ARM_ACLE_CRC_HASH
#ifndef _MSC_VER
# include <arm_acle.h>
#endif
#include "../../zbuild.h"
#include "../../deflate.h"
#define UPDATE_HASH(s, h, val) \
h = __crc32w(0, val)
#define INSERT_STRING insert_string_acle
#define QUICK_INSERT_STRING quick_insert_string_acle
#include "../../insert_string_tpl.h"
#endif

View File

@ -1,52 +0,0 @@
/* slide_neon.c -- Optimized hash table shifting for ARM with support for NEON instructions
* Copyright (C) 2017-2020 Mika T. Lindqvist
*
* Authors:
* Mika T. Lindqvist <postmaster@raasu.org>
* Jun He <jun.he@arm.com>
*
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#if defined(ARM_NEON_SLIDEHASH)
#ifdef _M_ARM64
# include <arm64_neon.h>
#else
# include <arm_neon.h>
#endif
#include "../../zbuild.h"
#include "../../deflate.h"
/* SIMD version of hash_chain rebase */
static inline void slide_hash_chain(Pos *table, unsigned int entries, uint16_t window_size) {
Z_REGISTER uint16x8_t v, *p;
Z_REGISTER size_t n;
size_t size = entries*sizeof(table[0]);
Assert((size % sizeof(uint16x8_t) * 8 == 0), "hash table size err");
Assert(sizeof(Pos) == 2, "Wrong Pos size");
v = vdupq_n_u16(window_size);
p = (uint16x8_t *)table;
n = size / (sizeof(uint16x8_t) * 8);
do {
p[0] = vqsubq_u16(p[0], v);
p[1] = vqsubq_u16(p[1], v);
p[2] = vqsubq_u16(p[2], v);
p[3] = vqsubq_u16(p[3], v);
p[4] = vqsubq_u16(p[4], v);
p[5] = vqsubq_u16(p[5], v);
p[6] = vqsubq_u16(p[6], v);
p[7] = vqsubq_u16(p[7], v);
p += 8;
} while (--n);
}
Z_INTERNAL void slide_hash_neon(deflate_state *s) {
unsigned int wsize = s->w_size;
slide_hash_chain(s->head, HASH_SIZE, wsize);
slide_hash_chain(s->prev, wsize, wsize);
}
#endif

View File

@ -1,21 +0,0 @@
# Makefile for zlib
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
# For conditions of distribution and use, see copyright notice in zlib.h
CC=
CFLAGS=
SFLAGS=
INCLUDES=
SRCDIR=.
SRCTOP=../..
TOPDIR=$(SRCTOP)
all:
mostlyclean: clean
clean:
rm -f *.o *.lo *~ \
rm -rf objs
rm -f *.gcda *.gcno *.gcov

View File

@ -1,49 +0,0 @@
# Makefile for POWER-specific files
# Copyright (C) 2020 Matheus Castanho <msc@linux.ibm.com>, IBM
# For conditions of distribution and use, see copyright notice in zlib.h
CC=
CFLAGS=
SFLAGS=
INCLUDES=
SUFFIX=
SRCDIR=.
SRCTOP=../..
TOPDIR=$(SRCTOP)
P8FLAGS=-mcpu=power8
all: power.o \
power.lo \
adler32_power8.o \
adler32_power8.lo \
slide_hash_power8.o \
slide_hash_power8.lo
power.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/power.c
power.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/power.c
adler32_power8.o:
$(CC) $(CFLAGS) $(P8FLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_power8.c
adler32_power8.lo:
$(CC) $(SFLAGS) $(P8FLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_power8.c
slide_hash_power8.o:
$(CC) $(CFLAGS) $(P8FLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_power8.c
slide_hash_power8.lo:
$(CC) $(SFLAGS) $(P8FLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_power8.c
mostlyclean: clean
clean:
rm -f *.o *.lo *~
rm -rf objs
rm -f *.gcda *.gcno *.gcov
distclean:
rm -f Makefile

View File

@ -1,154 +0,0 @@
/* Adler32 for POWER8 using VSX instructions.
* Copyright (C) 2020 IBM Corporation
* Author: Rogerio Alves <rcardoso@linux.ibm.com>
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Calculate adler32 checksum for 16 bytes at once using POWER8+ VSX (vector)
* instructions.
*
* If adler32 do 1 byte at time on the first iteration s1 is s1_0 (_n means
* iteration n) is the initial value of adler - at start _0 is 1 unless
* adler initial value is different than 1. So s1_1 = s1_0 + c[0] after
* the first calculation. For the iteration s1_2 = s1_1 + c[1] and so on.
* Hence, for iteration N, s1_N = s1_(N-1) + c[N] is the value of s1 on
* after iteration N.
*
* Therefore, for s2 and iteration N, s2_N = s2_0 + N*s1_N + N*c[0] +
* N-1*c[1] + ... + c[N]
*
* In a more general way:
*
* s1_N = s1_0 + sum(i=1 to N)c[i]
* s2_N = s2_0 + N*s1 + sum (i=1 to N)(N-i+1)*c[i]
*
* Where s1_N, s2_N are the values for s1, s2 after N iterations. So if we
* can process N-bit at time we can do this at once.
*
* Since VSX can support 16-bit vector instructions, we can process
* 16-bit at time using N = 16 we have:
*
* s1 = s1_16 = s1_(16-1) + c[16] = s1_0 + sum(i=1 to 16)c[i]
* s2 = s2_16 = s2_0 + 16*s1 + sum(i=1 to 16)(16-i+1)*c[i]
*
* After the first iteration we calculate the adler32 checksum for 16 bytes.
*
* For more background about adler32 please check the RFC:
* https://www.ietf.org/rfc/rfc1950.txt
*/
#ifdef POWER8_VSX_ADLER32
#include <altivec.h>
#include "zbuild.h"
#include "zutil.h"
#include "adler32_p.h"
/* Vector across sum unsigned int (saturate). */
inline vector unsigned int vec_sumsu(vector unsigned int __a, vector unsigned int __b) {
__b = vec_sld(__a, __a, 8);
__b = vec_add(__b, __a);
__a = vec_sld(__b, __b, 4);
__a = vec_add(__a, __b);
return __a;
}
uint32_t adler32_power8(uint32_t adler, const unsigned char* buf, size_t len) {
uint32_t s1 = adler & 0xffff;
uint32_t s2 = (adler >> 16) & 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (UNLIKELY(len == 1))
return adler32_len_1(s1, buf, s2);
/* If buffer is empty or len=0 we need to return adler initial value. */
if (UNLIKELY(buf == NULL))
return 1;
/* This is faster than VSX code for len < 64. */
if (len < 64)
return adler32_len_64(s1, buf, len, s2);
/* Use POWER VSX instructions for len >= 64. */
const vector unsigned int v_zeros = { 0 };
const vector unsigned char v_mul = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1};
const vector unsigned char vsh = vec_splat_u8(4);
const vector unsigned int vmask = {0xffffffff, 0x0, 0x0, 0x0};
vector unsigned int vs1 = { 0 };
vector unsigned int vs2 = { 0 };
vector unsigned int vs1_save = { 0 };
vector unsigned int vsum1, vsum2;
vector unsigned char vbuf;
int n;
vs1[0] = s1;
vs2[0] = s2;
/* Do length bigger than NMAX in blocks of NMAX size. */
while (len >= NMAX) {
len -= NMAX;
n = NMAX / 16;
do {
vbuf = vec_xl(0, (unsigned char *) buf);
vsum1 = vec_sum4s(vbuf, v_zeros); /* sum(i=1 to 16) buf[i]. */
/* sum(i=1 to 16) buf[i]*(16-i+1). */
vsum2 = vec_msum(vbuf, v_mul, v_zeros);
/* Save vs1. */
vs1_save = vec_add(vs1_save, vs1);
/* Accumulate the sums. */
vs1 = vec_add(vsum1, vs1);
vs2 = vec_add(vsum2, vs2);
buf += 16;
} while (--n);
/* Once each block of NMAX size. */
vs1 = vec_sumsu(vs1, vsum1);
vs1_save = vec_sll(vs1_save, vsh); /* 16*vs1_save. */
vs2 = vec_add(vs1_save, vs2);
vs2 = vec_sumsu(vs2, vsum2);
/* vs1[0] = (s1_i + sum(i=1 to 16)buf[i]) mod 65521. */
vs1[0] = vs1[0] % BASE;
/* vs2[0] = s2_i + 16*s1_save +
sum(i=1 to 16)(16-i+1)*buf[i] mod 65521. */
vs2[0] = vs2[0] % BASE;
vs1 = vec_and(vs1, vmask);
vs2 = vec_and(vs2, vmask);
vs1_save = v_zeros;
}
/* len is less than NMAX one modulo is needed. */
if (len >= 16) {
while (len >= 16) {
len -= 16;
vbuf = vec_xl(0, (unsigned char *) buf);
vsum1 = vec_sum4s(vbuf, v_zeros); /* sum(i=1 to 16) buf[i]. */
/* sum(i=1 to 16) buf[i]*(16-i+1). */
vsum2 = vec_msum(vbuf, v_mul, v_zeros);
/* Save vs1. */
vs1_save = vec_add(vs1_save, vs1);
/* Accumulate the sums. */
vs1 = vec_add(vsum1, vs1);
vs2 = vec_add(vsum2, vs2);
buf += 16;
}
/* Since the size will be always less than NMAX we do this once. */
vs1 = vec_sumsu(vs1, vsum1);
vs1_save = vec_sll(vs1_save, vsh); /* 16*vs1_save. */
vs2 = vec_add(vs1_save, vs2);
vs2 = vec_sumsu(vs2, vsum2);
}
/* Copy result back to s1, s2 (mod 65521). */
s1 = vs1[0] % BASE;
s2 = vs2[0] % BASE;
/* Process tail (len < 16).and return */
return adler32_len_16(s1, buf, len, s2);
}
#endif /* POWER8_VSX_ADLER32 */

View File

@ -1,19 +0,0 @@
/* POWER feature check
* Copyright (C) 2020 Matheus Castanho <msc@linux.ibm.com>, IBM
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <sys/auxv.h>
#include "../../zutil.h"
Z_INTERNAL int power_cpu_has_arch_2_07;
void Z_INTERNAL power_check_features(void) {
unsigned long hwcap2;
hwcap2 = getauxval(AT_HWCAP2);
#ifdef POWER8
if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
power_cpu_has_arch_2_07 = 1;
#endif
}

View File

@ -1,13 +0,0 @@
/* power.h -- check for POWER CPU features
* Copyright (C) 2020 Matheus Castanho <msc@linux.ibm.com>, IBM
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef POWER_H_
#define POWER_H_
extern int power_cpu_has_arch_2_07;
void Z_INTERNAL power_check_features(void);
#endif /* POWER_H_ */

View File

@ -1,60 +0,0 @@
/* Optimized slide_hash for POWER processors
* Copyright (C) 2019-2020 IBM Corporation
* Author: Matheus Castanho <msc@linux.ibm.com>
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifdef POWER8_VSX_SLIDEHASH
#include <altivec.h>
#include "zbuild.h"
#include "deflate.h"
static inline void slide_hash_power8_loop(deflate_state *s, unsigned n_elems, Pos *table_end) {
vector unsigned short vw, vm, *vp;
unsigned chunks;
/* Each vector register (chunk) corresponds to 128 bits == 8 Posf,
* so instead of processing each of the n_elems in the hash table
* individually, we can do it in chunks of 8 with vector instructions.
*
* This function is only called from slide_hash_power8(), and both calls
* pass n_elems as a power of 2 higher than 2^7, as defined by
* deflateInit2_(), so n_elems will always be a multiple of 8. */
chunks = n_elems >> 3;
Assert(n_elems % 8 == 0, "Weird hash table size!");
/* This type casting is safe since s->w_size is always <= 64KB
* as defined by deflateInit2_() and Posf == unsigned short */
vw[0] = (Pos) s->w_size;
vw = vec_splat(vw,0);
vp = (vector unsigned short *) table_end;
do {
/* Processing 8 elements at a time */
vp--;
vm = *vp;
/* This is equivalent to: m >= w_size ? m - w_size : 0
* Since we are using a saturated unsigned subtraction, any
* values that are > w_size will be set to 0, while the others
* will be subtracted by w_size. */
*vp = vec_subs(vm,vw);
} while (--chunks);
}
void Z_INTERNAL slide_hash_power8(deflate_state *s) {
unsigned int n;
Pos *p;
n = HASH_SIZE;
p = &s->head[n];
slide_hash_power8_loop(s,n,p);
n = s->w_size;
p = &s->prev[n];
slide_hash_power8_loop(s,n,p);
}
#endif /* POWER8_VSX_SLIDEHASH */

View File

@ -1,40 +0,0 @@
# Makefile for zlib-ng
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
# For conditions of distribution and use, see copyright notice in zlib.h
CC=
CFLAGS=
SFLAGS=
INCLUDES=
SUFFIX=
SRCDIR=.
SRCTOP=../..
TOPDIR=$(SRCTOP)
dfltcc_common.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c
dfltcc_common.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c
dfltcc_deflate.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_deflate.c
dfltcc_deflate.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_deflate.c
dfltcc_inflate.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_inflate.c
dfltcc_inflate.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_inflate.c
mostlyclean: clean
clean:
rm -f *.o *.lo *~
rm -rf objs
rm -f *.gcda *.gcno *.gcov
distclean:
rm -f Makefile

View File

@ -1,216 +0,0 @@
# Introduction
This directory contains SystemZ deflate hardware acceleration support.
It can be enabled using the following build commands:
$ ./configure --with-dfltcc-deflate --with-dfltcc-inflate
$ make
or
$ cmake -DWITH_DFLTCC_DEFLATE=1 -DWITH_DFLTCC_INFLATE=1 .
$ make
When built like this, zlib-ng would compress using hardware on level 1,
and using software on all other levels. Decompression will always happen
in hardware. In order to enable hardware compression for levels 1-6
(i.e. to make it used by default) one could add
`-DDFLTCC_LEVEL_MASK=0x7e` to CFLAGS when building zlib-ng.
SystemZ deflate hardware acceleration is available on [IBM z15](
https://www.ibm.com/products/z15) and newer machines under the name [
"Integrated Accelerator for zEnterprise Data Compression"](
https://www.ibm.com/support/z-content-solutions/compression/). The
programming interface to it is a machine instruction called DEFLATE
CONVERSION CALL (DFLTCC). It is documented in Chapter 26 of [Principles
of Operation](http://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf). Both
the code and the rest of this document refer to this feature simply as
"DFLTCC".
# Performance
Performance figures are published [here](
https://github.com/iii-i/zlib-ng/wiki/Performance-with-dfltcc-patch-applied-and-dfltcc-support-built-on-dfltcc-enabled-machine
). The compression speed-up can be as high as 110x and the decompression
speed-up can be as high as 15x.
# Limitations
Two DFLTCC compression calls with identical inputs are not guaranteed to
produce identical outputs. Therefore care should be taken when using
hardware compression when reproducible results are desired. In
particular, zlib-ng-specific `zng_deflateSetParams` call allows setting
`Z_DEFLATE_REPRODUCIBLE` parameter, which disables DFLTCC support for a
particular stream.
DFLTCC does not support every single zlib-ng feature, in particular:
* `inflate(Z_BLOCK)` and `inflate(Z_TREES)`
* `inflateMark()`
* `inflatePrime()`
* `inflateSyncPoint()`
When used, these functions will either switch to software, or, in case
this is not possible, gracefully fail.
# Code structure
All SystemZ-specific code lives in `arch/s390` directory and is
integrated with the rest of zlib-ng using hook macros.
## Hook macros
DFLTCC takes as arguments a parameter block, an input buffer, an output
buffer and a window. `ZALLOC_STATE()`, `ZFREE_STATE()`, `ZCOPY_STATE()`,
`ZALLOC_WINDOW()` and `TRY_FREE_WINDOW()` macros encapsulate allocation
details for the parameter block (which is allocated alongside zlib-ng
state) and the window (which must be page-aligned).
While inflate software and hardware window formats match, this is not
the case for deflate. Therefore, `deflateSetDictionary()` and
`deflateGetDictionary()` need special handling, which is triggered using
`DEFLATE_SET_DICTIONARY_HOOK()` and `DEFLATE_GET_DICTIONARY_HOOK()`
macros.
`deflateResetKeep()` and `inflateResetKeep()` update the DFLTCC
parameter block using `DEFLATE_RESET_KEEP_HOOK()` and
`INFLATE_RESET_KEEP_HOOK()` macros.
`INFLATE_PRIME_HOOK()`, `INFLATE_MARK_HOOK()` and
`INFLATE_SYNC_POINT_HOOK()` macros make the respective unsupported
calls gracefully fail.
`DEFLATE_PARAMS_HOOK()` implements switching between hardware and
software compression mid-stream using `deflateParams()`. Switching
normally entails flushing the current block, which might not be possible
in low memory situations. `deflateParams()` uses `DEFLATE_DONE()` hook
in order to detect and gracefully handle such situations.
The algorithm implemented in hardware has different compression ratio
than the one implemented in software. `DEFLATE_BOUND_ADJUST_COMPLEN()`
and `DEFLATE_NEED_CONSERVATIVE_BOUND()` macros make `deflateBound()`
return the correct results for the hardware implementation.
Actual compression and decompression are handled by `DEFLATE_HOOK()` and
`INFLATE_TYPEDO_HOOK()` macros. Since inflation with DFLTCC manages the
window on its own, calling `updatewindow()` is suppressed using
`INFLATE_NEED_UPDATEWINDOW()` macro.
In addition to compression, DFLTCC computes CRC-32 and Adler-32
checksums, therefore, whenever it's used, software checksumming is
suppressed using `DEFLATE_NEED_CHECKSUM()` and `INFLATE_NEED_CHECKSUM()`
macros.
While software always produces reproducible compression results, this
is not the case for DFLTCC. Therefore, zlib-ng users are given the
ability to specify whether or not reproducible compression results
are required. While it is always possible to specify this setting
before the compression begins, it is not always possible to do so in
the middle of a deflate stream - the exact conditions for that are
determined by `DEFLATE_CAN_SET_REPRODUCIBLE()` macro.
## SystemZ-specific code
When zlib-ng is built with DFLTCC, the hooks described above are
converted to calls to functions, which are implemented in
`arch/s390/dfltcc_*` files. The functions can be grouped in three broad
categories:
* Base DFLTCC support, e.g. wrapping the machine instruction -
`dfltcc()` and allocating aligned memory - `dfltcc_alloc_state()`.
* Translating between software and hardware data formats, e.g.
`dfltcc_deflate_set_dictionary()`.
* Translating between software and hardware state machines, e.g.
`dfltcc_deflate()` and `dfltcc_inflate()`.
The functions from the first two categories are fairly simple, however,
various quirks in both software and hardware state machines make the
functions from the third category quite complicated.
### `dfltcc_deflate()` function
This function is called by `deflate()` and has the following
responsibilities:
* Checking whether DFLTCC can be used with the current stream. If this
is not the case, then it returns `0`, making `deflate()` use some
other function in order to compress in software. Otherwise it returns
`1`.
* Block management and Huffman table generation. DFLTCC ends blocks only
when explicitly instructed to do so by the software. Furthermore,
whether to use fixed or dynamic Huffman tables must also be determined
by the software. Since looking at data in order to gather statistics
would negate performance benefits, the following approach is used: the
first `DFLTCC_FIRST_FHT_BLOCK_SIZE` bytes are placed into a fixed
block, and every next `DFLTCC_BLOCK_SIZE` bytes are placed into
dynamic blocks.
* Writing EOBS. Block Closing Control bit in the parameter block
instructs DFLTCC to write EOBS, however, certain conditions need to be
met: input data length must be non-zero or Continuation Flag must be
set. To put this in simpler terms, DFLTCC will silently refuse to
write EOBS if this is the only thing that it is asked to do. Since the
code has to be able to emit EOBS in software anyway, in order to avoid
tricky corner cases Block Closing Control is never used. Whether to
write EOBS is instead controlled by `soft_bcc` variable.
* Triggering block post-processing. Depending on flush mode, `deflate()`
must perform various additional actions when a block or a stream ends.
`dfltcc_deflate()` informs `deflate()` about this using
`block_state *result` parameter.
* Converting software state fields into hardware parameter block fields,
and vice versa. For example, `wrap` and Check Value Type or `bi_valid`
and Sub-Byte Boundary. Certain fields cannot be translated and must
persist untouched in the parameter block between calls, for example,
Continuation Flag or Continuation State Buffer.
* Handling flush modes and low-memory situations. These aspects are
quite intertwined and pervasive. The general idea here is that the
code must not do anything in software - whether explicitly by e.g.
calling `send_eobs()`, or implicitly - by returning to `deflate()`
with certain return and `*result` values, when Continuation Flag is
set.
* Ending streams. When a new block is started and flush mode is
`Z_FINISH`, Block Header Final parameter block bit is used to mark
this block as final. However, sometimes an empty final block is
needed, and, unfortunately, just like with EOBS, DFLTCC will silently
refuse to do this. The general idea of DFLTCC implementation is to
rely as much as possible on the existing code. Here in order to do
this, the code pretends that it does not support DFLTCC, which makes
`deflate()` call a software compression function, which writes an
empty final block. Whether this is required is controlled by
`need_empty_block` variable.
* Error handling. This is simply converting
Operation-Ending-Supplemental Code to string. Errors can only happen
due to things like memory corruption, and therefore they don't affect
the `deflate()` return code.
### `dfltcc_inflate()` function
This function is called by `inflate()` from the `TYPEDO` state (that is,
when all the metadata is parsed and the stream is positioned at the type
bits of deflate block header) and it's responsible for the following:
* Falling back to software when flush mode is `Z_BLOCK` or `Z_TREES`.
Unfortunately, there is no way to ask DFLTCC to stop decompressing on
block or tree boundary.
* `inflate()` decompression loop management. This is controlled using
the return value, which can be either `DFLTCC_INFLATE_BREAK` or
`DFLTCC_INFLATE_CONTINUE`.
* Converting software state fields into hardware parameter block fields,
and vice versa. For example, `whave` and History Length or `wnext` and
History Offset.
* Ending streams. This instructs `inflate()` to return `Z_STREAM_END`
and is controlled by `last` state field.
* Error handling. Like deflate, error handling comprises
Operation-Ending-Supplemental Code to string conversion. Unlike
deflate, errors may happen due to bad inputs, therefore they are
propagated to `inflate()` by setting `mode` field to `MEM` or `BAD`.
# Testing
Given complexity of DFLTCC machine instruction, it is not clear whether
QEMU TCG will ever support it. At the time of writing, one has to have
access to an IBM z15+ VM or LPAR in order to test DFLTCC support. Since
DFLTCC is a non-privileged instruction, neither special VM/LPAR
configuration nor root are required.
Still, zlib-ng CI has a few QEMU TCG-based configurations that check
whether fallback to software is working.

View File

@ -1,89 +0,0 @@
/* dfltcc_deflate.c - IBM Z DEFLATE CONVERSION CALL general support. */
#include "../../zbuild.h"
#include "dfltcc_common.h"
#include "dfltcc_detail.h"
/*
Memory management.
DFLTCC requires parameter blocks and window to be aligned. zlib-ng allows
users to specify their own allocation functions, so using e.g.
`posix_memalign' is not an option. Thus, we overallocate and take the
aligned portion of the buffer.
*/
static inline int is_dfltcc_enabled(void) {
uint64_t facilities[(DFLTCC_FACILITY / 64) + 1];
Z_REGISTER uint8_t r0 __asm__("r0");
memset(facilities, 0, sizeof(facilities));
r0 = sizeof(facilities) / sizeof(facilities[0]) - 1;
/* STFLE is supported since z9-109 and only in z/Architecture mode. When
* compiling with -m31, gcc defaults to ESA mode, however, since the kernel
* is 64-bit, it's always z/Architecture mode at runtime.
*/
__asm__ volatile(
#ifndef __clang__
".machinemode push\n"
".machinemode zarch\n"
#endif
"stfle %[facilities]\n"
#ifndef __clang__
".machinemode pop\n"
#endif
: [facilities] "=Q" (facilities), [r0] "+r" (r0) :: "cc");
return is_bit_set((const char *)facilities, DFLTCC_FACILITY);
}
void Z_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size) {
struct dfltcc_state *dfltcc_state = (struct dfltcc_state *)((char *)strm->state + ALIGN_UP(size, 8));
struct dfltcc_qaf_param *param = (struct dfltcc_qaf_param *)&dfltcc_state->param;
/* Initialize available functions */
if (is_dfltcc_enabled()) {
dfltcc(DFLTCC_QAF, param, NULL, NULL, NULL, NULL, NULL);
memmove(&dfltcc_state->af, param, sizeof(dfltcc_state->af));
} else
memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
/* Initialize parameter block */
memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param));
dfltcc_state->param.nt = 1;
/* Initialize tuning parameters */
dfltcc_state->level_mask = DFLTCC_LEVEL_MASK;
dfltcc_state->block_size = DFLTCC_BLOCK_SIZE;
dfltcc_state->block_threshold = DFLTCC_FIRST_FHT_BLOCK_SIZE;
dfltcc_state->dht_threshold = DFLTCC_DHT_MIN_SAMPLE_SIZE;
dfltcc_state->param.ribm = DFLTCC_RIBM;
}
void Z_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size) {
return ZALLOC(strm, ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), sizeof(unsigned char));
}
void Z_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size) {
memcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state));
}
static const int PAGE_ALIGN = 0x1000;
void Z_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size) {
void *p;
void *w;
/* To simplify freeing, we store the pointer to the allocated buffer right
* before the window.
*/
p = ZALLOC(strm, sizeof(void *) + items * size + PAGE_ALIGN, sizeof(unsigned char));
if (p == NULL)
return NULL;
w = ALIGN_UP((char *)p + sizeof(void *), PAGE_ALIGN);
*(void **)((char *)w - sizeof(void *)) = p;
return w;
}
void Z_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w) {
if (w)
ZFREE(strm, *(void **)((unsigned char *)w - sizeof(void *)));
}

View File

@ -1,29 +0,0 @@
#ifndef DFLTCC_COMMON_H
#define DFLTCC_COMMON_H
#ifdef ZLIB_COMPAT
#include "../../zlib.h"
#else
#include "../../zlib-ng.h"
#endif
#include "../../zutil.h"
void Z_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size);
void Z_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size);
void Z_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size);
void Z_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size);
void Z_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w);
#define ZALLOC_STATE dfltcc_alloc_state
#define ZFREE_STATE ZFREE
#define ZCOPY_STATE dfltcc_copy_state
#define ZALLOC_WINDOW dfltcc_alloc_window
#define ZFREE_WINDOW dfltcc_free_window
#define TRY_FREE_WINDOW dfltcc_free_window
#endif

View File

@ -1,406 +0,0 @@
/* dfltcc_deflate.c - IBM Z DEFLATE CONVERSION CALL compression support. */
/*
Use the following commands to build zlib-ng with DFLTCC compression support:
$ ./configure --with-dfltcc-deflate
or
$ cmake -DWITH_DFLTCC_DEFLATE=1 .
and then
$ make
*/
#include "../../zbuild.h"
#include "../../zutil.h"
#include "../../deflate.h"
#include "../../trees_emit.h"
#include "dfltcc_deflate.h"
#include "dfltcc_detail.h"
static inline int dfltcc_can_deflate_with_params(PREFIX3(streamp) strm, int level, uInt window_bits, int strategy,
int reproducible) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
/* Unsupported compression settings */
if ((dfltcc_state->level_mask & (1 << level)) == 0)
return 0;
if (window_bits != HB_BITS)
return 0;
if (strategy != Z_FIXED && strategy != Z_DEFAULT_STRATEGY)
return 0;
if (reproducible)
return 0;
/* Unsupported hardware */
if (!is_bit_set(dfltcc_state->af.fns, DFLTCC_GDHT) ||
!is_bit_set(dfltcc_state->af.fns, DFLTCC_CMPR) ||
!is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0))
return 0;
return 1;
}
int Z_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
return dfltcc_can_deflate_with_params(strm, state->level, state->w_bits, state->strategy, state->reproducible);
}
static inline void dfltcc_gdht(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
size_t avail_in = strm->avail_in;
dfltcc(DFLTCC_GDHT, param, NULL, NULL, &strm->next_in, &avail_in, NULL);
}
static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
size_t avail_in = strm->avail_in;
size_t avail_out = strm->avail_out;
dfltcc_cc cc;
cc = dfltcc(DFLTCC_CMPR | HBT_CIRCULAR,
param, &strm->next_out, &avail_out,
&strm->next_in, &avail_in, state->window);
strm->total_in += (strm->avail_in - avail_in);
strm->total_out += (strm->avail_out - avail_out);
strm->avail_in = avail_in;
strm->avail_out = avail_out;
return cc;
}
static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param) {
deflate_state *state = (deflate_state *)strm->state;
send_bits(state, bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid);
flush_pending(strm);
if (state->pending != 0) {
/* The remaining data is located in pending_out[0:pending]. If someone
* calls put_byte() - this might happen in deflate() - the byte will be
* placed into pending_buf[pending], which is incorrect. Move the
* remaining data to the beginning of pending_buf so that put_byte() is
* usable again.
*/
memmove(state->pending_buf, state->pending_out, state->pending);
state->pending_out = state->pending_buf;
}
#ifdef ZLIB_DEBUG
state->compressed_len += param->eobl;
#endif
}
int Z_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
uInt masked_avail_in;
dfltcc_cc cc;
int need_empty_block;
int soft_bcc;
int no_flush;
if (!dfltcc_can_deflate(strm)) {
/* Clear history. */
if (flush == Z_FULL_FLUSH)
param->hl = 0;
return 0;
}
again:
masked_avail_in = 0;
soft_bcc = 0;
no_flush = flush == Z_NO_FLUSH;
/* No input data. Return, except when Continuation Flag is set, which means
* that DFLTCC has buffered some output in the parameter block and needs to
* be called again in order to flush it.
*/
if (strm->avail_in == 0 && !param->cf) {
/* A block is still open, and the hardware does not support closing
* blocks without adding data. Thus, close it manually.
*/
if (!no_flush && param->bcf) {
send_eobs(strm, param);
param->bcf = 0;
}
/* Let one of deflate_* functions write a trailing empty block. */
if (flush == Z_FINISH)
return 0;
/* Clear history. */
if (flush == Z_FULL_FLUSH)
param->hl = 0;
/* Trigger block post-processing if necessary. */
*result = no_flush ? need_more : block_done;
return 1;
}
/* There is an open non-BFINAL block, we are not going to close it just
* yet, we have compressed more than DFLTCC_BLOCK_SIZE bytes and we see
* more than DFLTCC_DHT_MIN_SAMPLE_SIZE bytes. Open a new block with a new
* DHT in order to adapt to a possibly changed input data distribution.
*/
if (param->bcf && no_flush &&
strm->total_in > dfltcc_state->block_threshold &&
strm->avail_in >= dfltcc_state->dht_threshold) {
if (param->cf) {
/* We need to flush the DFLTCC buffer before writing the
* End-of-block Symbol. Mask the input data and proceed as usual.
*/
masked_avail_in += strm->avail_in;
strm->avail_in = 0;
no_flush = 0;
} else {
/* DFLTCC buffer is empty, so we can manually write the
* End-of-block Symbol right away.
*/
send_eobs(strm, param);
param->bcf = 0;
dfltcc_state->block_threshold = strm->total_in + dfltcc_state->block_size;
}
}
/* No space for compressed data. If we proceed, dfltcc_cmpr() will return
* DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still
* set BCF=1, which is wrong. Avoid complications and return early.
*/
if (strm->avail_out == 0) {
*result = need_more;
return 1;
}
/* The caller gave us too much data. Pass only one block worth of
* uncompressed data to DFLTCC and mask the rest, so that on the next
* iteration we start a new block.
*/
if (no_flush && strm->avail_in > dfltcc_state->block_size) {
masked_avail_in += (strm->avail_in - dfltcc_state->block_size);
strm->avail_in = dfltcc_state->block_size;
}
/* When we have an open non-BFINAL deflate block and caller indicates that
* the stream is ending, we need to close an open deflate block and open a
* BFINAL one.
*/
need_empty_block = flush == Z_FINISH && param->bcf && !param->bhf;
/* Translate stream to parameter block */
param->cvt = state->wrap == 2 ? CVT_CRC32 : CVT_ADLER32;
if (!no_flush)
/* We need to close a block. Always do this in software - when there is
* no input data, the hardware will not honor BCC. */
soft_bcc = 1;
if (flush == Z_FINISH && !param->bcf)
/* We are about to open a BFINAL block, set Block Header Final bit
* until the stream ends.
*/
param->bhf = 1;
/* DFLTCC-CMPR will write to next_out, so make sure that buffers with
* higher precedence are empty.
*/
Assert(state->pending == 0, "There must be no pending bytes");
Assert(state->bi_valid < 8, "There must be less than 8 pending bits");
param->sbb = (unsigned int)state->bi_valid;
if (param->sbb > 0)
*strm->next_out = (unsigned char)state->bi_buf;
/* Honor history and check value */
param->nt = 0;
param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
/* When opening a block, choose a Huffman-Table Type */
if (!param->bcf) {
if (state->strategy == Z_FIXED || (strm->total_in == 0 && dfltcc_state->block_threshold > 0))
param->htt = HTT_FIXED;
else {
param->htt = HTT_DYNAMIC;
dfltcc_gdht(strm);
}
}
/* Deflate */
do {
cc = dfltcc_cmpr(strm);
if (strm->avail_in < 4096 && masked_avail_in > 0)
/* We are about to call DFLTCC with a small input buffer, which is
* inefficient. Since there is masked data, there will be at least
* one more DFLTCC call, so skip the current one and make the next
* one handle more data.
*/
break;
} while (cc == DFLTCC_CC_AGAIN);
/* Translate parameter block to stream */
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
state->bi_valid = param->sbb;
if (state->bi_valid == 0)
state->bi_buf = 0; /* Avoid accessing next_out */
else
state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1);
strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv;
/* Unmask the input data */
strm->avail_in += masked_avail_in;
masked_avail_in = 0;
/* If we encounter an error, it means there is a bug in DFLTCC call */
Assert(cc != DFLTCC_CC_OP2_CORRUPT || param->oesc == 0, "BUG");
/* Update Block-Continuation Flag. It will be used to check whether to call
* GDHT the next time.
*/
if (cc == DFLTCC_CC_OK) {
if (soft_bcc) {
send_eobs(strm, param);
param->bcf = 0;
dfltcc_state->block_threshold = strm->total_in + dfltcc_state->block_size;
} else
param->bcf = 1;
if (flush == Z_FINISH) {
if (need_empty_block)
/* Make the current deflate() call also close the stream */
return 0;
else {
bi_windup(state);
*result = finish_done;
}
} else {
if (flush == Z_FULL_FLUSH)
param->hl = 0; /* Clear history */
*result = flush == Z_NO_FLUSH ? need_more : block_done;
}
} else {
param->bcf = 1;
*result = need_more;
}
if (strm->avail_in != 0 && strm->avail_out != 0)
goto again; /* deflate() must use all input or all output */
return 1;
}
/*
Switching between hardware and software compression.
DFLTCC does not support all zlib settings, e.g. generation of non-compressed
blocks or alternative window sizes. When such settings are applied on the
fly with deflateParams, we need to convert between hardware and software
window formats.
*/
static int dfltcc_was_deflate_used(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
return strm->total_in > 0 || param->nt == 0 || param->hl > 0;
}
int Z_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy, int *flush) {
deflate_state *state = (deflate_state *)strm->state;
int could_deflate = dfltcc_can_deflate(strm);
int can_deflate = dfltcc_can_deflate_with_params(strm, level, state->w_bits, strategy, state->reproducible);
if (can_deflate == could_deflate)
/* We continue to work in the same mode - no changes needed */
return Z_OK;
if (!dfltcc_was_deflate_used(strm))
/* DFLTCC was not used yet - no changes needed */
return Z_OK;
/* For now, do not convert between window formats - simply get rid of the old data instead */
*flush = Z_FULL_FLUSH;
return Z_OK;
}
int Z_INTERNAL dfltcc_deflate_done(PREFIX3(streamp) strm, int flush) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
/* When deflate(Z_FULL_FLUSH) is called with small avail_out, it might
* close the block without resetting the compression state. Detect this
* situation and return that deflation is not done.
*/
if (flush == Z_FULL_FLUSH && strm->avail_out == 0)
return 0;
/* Return that deflation is not done if DFLTCC is used and either it
* buffered some data (Continuation Flag is set), or has not written EOBS
* yet (Block-Continuation Flag is set).
*/
return !dfltcc_can_deflate(strm) || (!param->cf && !param->bcf);
}
int Z_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible) {
deflate_state *state = (deflate_state *)strm->state;
return reproducible != state->reproducible && !dfltcc_was_deflate_used(strm);
}
/*
Preloading history.
*/
static void append_history(struct dfltcc_param_v0 *param, unsigned char *history, const unsigned char *buf, uInt count) {
size_t offset;
size_t n;
/* Do not use more than 32K */
if (count > HB_SIZE) {
buf += count - HB_SIZE;
count = HB_SIZE;
}
offset = (param->ho + param->hl) % HB_SIZE;
if (offset + count <= HB_SIZE)
/* Circular history buffer does not wrap - copy one chunk */
memcpy(history + offset, buf, count);
else {
/* Circular history buffer wraps - copy two chunks */
n = HB_SIZE - offset;
memcpy(history + offset, buf, n);
memcpy(history, buf + n, count - n);
}
n = param->hl + count;
if (n <= HB_SIZE)
/* All history fits into buffer - no need to discard anything */
param->hl = n;
else {
/* History does not fit into buffer - discard extra bytes */
param->ho = (param->ho + (n - HB_SIZE)) % HB_SIZE;
param->hl = HB_SIZE;
}
}
int Z_INTERNAL dfltcc_deflate_set_dictionary(PREFIX3(streamp) strm,
const unsigned char *dictionary, uInt dict_length) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
append_history(param, state->window, dictionary, dict_length);
state->strstart = 1; /* Add FDICT to zlib header */
state->block_start = state->strstart; /* Make deflate_stored happy */
return Z_OK;
}
int Z_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt *dict_length) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
if (dictionary) {
if (param->ho + param->hl <= HB_SIZE)
/* Circular history buffer does not wrap - copy one chunk */
memcpy(dictionary, state->window + param->ho, param->hl);
else {
/* Circular history buffer wraps - copy two chunks */
memcpy(dictionary, state->window + param->ho, HB_SIZE - param->ho);
memcpy(dictionary + HB_SIZE - param->ho, state->window, param->ho + param->hl - HB_SIZE);
}
}
if (dict_length)
*dict_length = param->hl;
return Z_OK;
}

View File

@ -1,56 +0,0 @@
#ifndef DFLTCC_DEFLATE_H
#define DFLTCC_DEFLATE_H
#include "dfltcc_common.h"
int Z_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm);
int Z_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result);
int Z_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy, int *flush);
int Z_INTERNAL dfltcc_deflate_done(PREFIX3(streamp) strm, int flush);
int Z_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible);
int Z_INTERNAL dfltcc_deflate_set_dictionary(PREFIX3(streamp) strm,
const unsigned char *dictionary, uInt dict_length);
int Z_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt* dict_length);
#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \
do { \
if (dfltcc_can_deflate((strm))) \
return dfltcc_deflate_set_dictionary((strm), (dict), (dict_len)); \
} while (0)
#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \
do { \
if (dfltcc_can_deflate((strm))) \
return dfltcc_deflate_get_dictionary((strm), (dict), (dict_len)); \
} while (0)
#define DEFLATE_RESET_KEEP_HOOK(strm) \
dfltcc_reset((strm), sizeof(deflate_state))
#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) \
do { \
int err; \
\
err = dfltcc_deflate_params((strm), (level), (strategy), (hook_flush)); \
if (err == Z_STREAM_ERROR) \
return err; \
} while (0)
#define DEFLATE_DONE dfltcc_deflate_done
#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
do { \
if (dfltcc_can_deflate((strm))) \
(complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
(source_len) * 16 + 15 + 7) >> 3; \
} while (0)
#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
#define DEFLATE_HOOK dfltcc_deflate
#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
#define DEFLATE_CAN_SET_REPRODUCIBLE dfltcc_can_set_reproducible
#endif

View File

@ -1,199 +0,0 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#ifdef HAVE_SYS_SDT_H
#include <sys/sdt.h>
#endif
/*
Tuning parameters.
*/
#ifndef DFLTCC_LEVEL_MASK
#define DFLTCC_LEVEL_MASK 0x2
#endif
#ifndef DFLTCC_BLOCK_SIZE
#define DFLTCC_BLOCK_SIZE 1048576
#endif
#ifndef DFLTCC_FIRST_FHT_BLOCK_SIZE
#define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096
#endif
#ifndef DFLTCC_DHT_MIN_SAMPLE_SIZE
#define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096
#endif
#ifndef DFLTCC_RIBM
#define DFLTCC_RIBM 0
#endif
/*
C wrapper for the DEFLATE CONVERSION CALL instruction.
*/
typedef enum {
DFLTCC_CC_OK = 0,
DFLTCC_CC_OP1_TOO_SHORT = 1,
DFLTCC_CC_OP2_TOO_SHORT = 2,
DFLTCC_CC_OP2_CORRUPT = 2,
DFLTCC_CC_AGAIN = 3,
} dfltcc_cc;
#define DFLTCC_QAF 0
#define DFLTCC_GDHT 1
#define DFLTCC_CMPR 2
#define DFLTCC_XPND 4
#define HBT_CIRCULAR (1 << 7)
#define HB_BITS 15
#define HB_SIZE (1 << HB_BITS)
#define DFLTCC_FACILITY 151
static inline dfltcc_cc dfltcc(int fn, void *param,
unsigned char **op1, size_t *len1, z_const unsigned char **op2, size_t *len2, void *hist) {
unsigned char *t2 = op1 ? *op1 : NULL;
size_t t3 = len1 ? *len1 : 0;
z_const unsigned char *t4 = op2 ? *op2 : NULL;
size_t t5 = len2 ? *len2 : 0;
Z_REGISTER int r0 __asm__("r0") = fn;
Z_REGISTER void *r1 __asm__("r1") = param;
Z_REGISTER unsigned char *r2 __asm__("r2") = t2;
Z_REGISTER size_t r3 __asm__("r3") = t3;
Z_REGISTER z_const unsigned char *r4 __asm__("r4") = t4;
Z_REGISTER size_t r5 __asm__("r5") = t5;
int cc;
__asm__ volatile(
#ifdef HAVE_SYS_SDT_H
STAP_PROBE_ASM(zlib, dfltcc_entry, STAP_PROBE_ASM_TEMPLATE(5))
#endif
".insn rrf,0xb9390000,%[r2],%[r4],%[hist],0\n"
#ifdef HAVE_SYS_SDT_H
STAP_PROBE_ASM(zlib, dfltcc_exit, STAP_PROBE_ASM_TEMPLATE(5))
#endif
"ipm %[cc]\n"
: [r2] "+r" (r2)
, [r3] "+r" (r3)
, [r4] "+r" (r4)
, [r5] "+r" (r5)
, [cc] "=r" (cc)
: [r0] "r" (r0)
, [r1] "r" (r1)
, [hist] "r" (hist)
#ifdef HAVE_SYS_SDT_H
, STAP_PROBE_ASM_OPERANDS(5, r2, r3, r4, r5, hist)
#endif
: "cc", "memory");
t2 = r2; t3 = r3; t4 = r4; t5 = r5;
if (op1)
*op1 = t2;
if (len1)
*len1 = t3;
if (op2)
*op2 = t4;
if (len2)
*len2 = t5;
return (cc >> 28) & 3;
}
/*
Parameter Block for Query Available Functions.
*/
#define static_assert(c, msg) __attribute__((unused)) static char static_assert_failed_ ## msg[c ? 1 : -1]
struct dfltcc_qaf_param {
char fns[16];
char reserved1[8];
char fmts[2];
char reserved2[6];
};
static_assert(sizeof(struct dfltcc_qaf_param) == 32, sizeof_struct_dfltcc_qaf_param_is_32);
static inline int is_bit_set(const char *bits, int n) {
return bits[n / 8] & (1 << (7 - (n % 8)));
}
static inline void clear_bit(char *bits, int n) {
bits[n / 8] &= ~(1 << (7 - (n % 8)));
}
#define DFLTCC_FMT0 0
/*
Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand.
*/
#define CVT_CRC32 0
#define CVT_ADLER32 1
#define HTT_FIXED 0
#define HTT_DYNAMIC 1
struct dfltcc_param_v0 {
uint16_t pbvn; /* Parameter-Block-Version Number */
uint8_t mvn; /* Model-Version Number */
uint8_t ribm; /* Reserved for IBM use */
uint32_t reserved32 : 31;
uint32_t cf : 1; /* Continuation Flag */
uint8_t reserved64[8];
uint32_t nt : 1; /* New Task */
uint32_t reserved129 : 1;
uint32_t cvt : 1; /* Check Value Type */
uint32_t reserved131 : 1;
uint32_t htt : 1; /* Huffman-Table Type */
uint32_t bcf : 1; /* Block-Continuation Flag */
uint32_t bcc : 1; /* Block Closing Control */
uint32_t bhf : 1; /* Block Header Final */
uint32_t reserved136 : 1;
uint32_t reserved137 : 1;
uint32_t dhtgc : 1; /* DHT Generation Control */
uint32_t reserved139 : 5;
uint32_t reserved144 : 5;
uint32_t sbb : 3; /* Sub-Byte Boundary */
uint8_t oesc; /* Operation-Ending-Supplemental Code */
uint32_t reserved160 : 12;
uint32_t ifs : 4; /* Incomplete-Function Status */
uint16_t ifl; /* Incomplete-Function Length */
uint8_t reserved192[8];
uint8_t reserved256[8];
uint8_t reserved320[4];
uint16_t hl; /* History Length */
uint32_t reserved368 : 1;
uint16_t ho : 15; /* History Offset */
uint32_t cv; /* Check Value */
uint32_t eobs : 15; /* End-of-block Symbol */
uint32_t reserved431: 1;
uint8_t eobl : 4; /* End-of-block Length */
uint32_t reserved436 : 12;
uint32_t reserved448 : 4;
uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table
Length */
uint8_t reserved464[6];
uint8_t cdht[288];
uint8_t reserved[32];
uint8_t csb[1152];
};
static_assert(sizeof(struct dfltcc_param_v0) == 1536, sizeof_struct_dfltcc_param_v0_is_1536);
static inline z_const char *oesc_msg(char *buf, int oesc) {
if (oesc == 0x00)
return NULL; /* Successful completion */
else {
sprintf(buf, "Operation-Ending-Supplemental Code is 0x%.2X", oesc);
return buf;
}
}
/*
Extension of inflate_state and deflate_state. Must be doubleword-aligned.
*/
struct dfltcc_state {
struct dfltcc_param_v0 param; /* Parameter block. */
struct dfltcc_qaf_param af; /* Available functions. */
uint16_t level_mask; /* Levels on which to use DFLTCC */
uint32_t block_size; /* New block each X bytes */
size_t block_threshold; /* New block after total_in > X */
uint32_t dht_threshold; /* New block only if avail_in >= X */
char msg[64]; /* Buffer for strm->msg */
};
#define ALIGN_UP(p, size) (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1))
#define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((char *)(state) + ALIGN_UP(sizeof(*state), 8)))

Some files were not shown because too many files have changed in this diff Show More