diff --git a/.cmake-format b/.cmake-format index 814ae81..757f231 100644 --- a/.cmake-format +++ b/.cmake-format @@ -1,6 +1,6 @@ format: tab_size: 4 - line_width: 80 + line_width: 97 dangle_parens: true markup: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0bdbfe6..24522e0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,6 @@ default: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - stages: # List of stages for jobs, and their order of execution - build - test diff --git a/CMakeLists.txt b/CMakeLists.txt index 515e153..4f20c26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ -cmake_minimum_required(VERSION 3.21...3.27) +cmake_minimum_required(VERSION 3.21...3.28) # Not ideal to use this global variable, but necessary to make sure that tooling and projects use # the same version -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) # strongly encouraged to enable this globally to avoid conflicts between -Wpedantic being enabled # and -std=c++20 and -std=gnu++20 for example when compiling with PCH enabled @@ -26,28 +26,30 @@ include(GNUInstallDirs) # search required packages and libs #--------------------------------------------------------------------------------------- -find_package( - Boost 1.71 CONFIG - COMPONENTS filesystem - REQUIRED -) - -find_package(Threads REQUIRED) +# find_package( +# Boost 1.81 CONFIG +# COMPONENTS filesystem asio headers +# REQUIRED +# ) # ---- Add other dependencies via CPM ---- # see https://github.com/cpm-cmake/CPM.cmake for more info include(cmake/CPM.cmake) +option(BUILD_SHARED_LIBS "Build shared libraries" YES) +set(BOOST_INCLUDE_LIBRARIES filesystem asio headers) +CPMAddPackage("gh:ClausKlein/boost-cmake@1.81.0-rc3") + # PackageProject.cmake will be used to make our target installable -CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.11.0") +# XXX done with boost-cmake! CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.11.0") # see https://github.com/aminya/project_options for more info CPMAddPackage("gh:aminya/project_options@0.32.1") # XXX list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR}) add_library( - tftpd STATIC + tftpd # FIXME(CK) STATIC async_tftpd_server.cpp async_tftpd_server.hpp tftpd.hpp @@ -56,9 +58,8 @@ add_library( tftp_subs.cpp tftp/tftpsubs.h ) -target_link_libraries( - ${PROJECT_NAME} PUBLIC Boost::filesystem Boost::headers Threads::Threads -) +list(TRANSFORM BOOST_INCLUDE_LIBRARIES PREPEND Boost:: OUTPUT_VARIABLE BOOST_TARGETS) +target_link_libraries(${PROJECT_NAME} PUBLIC ${BOOST_TARGETS}) target_compile_definitions(${PROJECT_NAME} PUBLIC BOOST_ASIO_NO_DEPRECATED) target_include_directories( ${PROJECT_NAME} PUBLIC $ @@ -81,11 +82,9 @@ if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Debug") # ENABLE_INCLUDE_WHAT_YOU_USE ) - # FIXME: should be PRIVATE! CK target_link_libraries( - ${PROJECT_NAME} - PUBLIC $ - $ + ${PROJECT_NAME} PUBLIC $ + $ ) else() include(cmake/WarningsAsErrors.cmake) @@ -106,12 +105,25 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) # EXPORT_HEADER ${EXPORT_HEADER_LOCATION} COMPATIBILITY SameMajorVersion DISABLE_VERSION_SUFFIX YES - DEPENDENCIES "boost 1.71" + DEPENDENCIES "Boost 1.81" ) # NOTE: implicit done! add_library(tftpd::tftpd ALIAS tftpd) - install(FILES async_tftpd_server.hpp - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) + install(FILES async_tftpd_server.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + if(BUILD_SHARED_LIBS) + install(IMPORTED_RUNTIME_ARTIFACTS ${PROJECT_NAME} RUNTIME_DEPENDENCY_SET + _dependency_set + ) + install( + RUNTIME_DEPENDENCY_SET + _dependency_set + POST_EXCLUDE_REGEXES + "${CMAKE_INSTALL_PREFIX}/lib" + RUNTIME + DESTINATION + lib + ) + endif() include(CPack) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 43509bc..6f09c59 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,9 +19,9 @@ "value": "${sourceDir}/stagedir" }, "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_BUILD_TYPE": "Release", "CMAKE_DEBUG_POSTFIX": "D", - "BUILD_SHARED_LIBS": "NO" + "BUILD_SHARED_LIBS": true }, "environment": { "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index ff9d31c..0abb277 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -1,17 +1,11 @@ -set(CPM_DOWNLOAD_VERSION 0.37.0) +set(CPM_DOWNLOAD_VERSION 0.38.7) if(CPM_SOURCE_CACHE) - set(_CPM_DOWNLOAD_LOCATION - "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake" - ) + set(_CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") elseif(DEFINED ENV{CPM_SOURCE_CACHE}) - set(_CPM_DOWNLOAD_LOCATION - "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake" - ) + set(_CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") else() - set(_CPM_DOWNLOAD_LOCATION - "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake" - ) + set(_CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() set(CPM_DOWNLOAD_LOCATION diff --git a/cmake/WarningsAsErrors.cmake b/cmake/WarningsAsErrors.cmake index 3776fd5..b3881b4 100644 --- a/cmake/WarningsAsErrors.cmake +++ b/cmake/WarningsAsErrors.cmake @@ -1,18 +1,10 @@ -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES - "MSVC" -) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options( - ${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow - ) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION - GREATER_EQUAL 10.0 - ) - target_compile_options( - ${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof - ) + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 10.0) + target_compile_options(${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") diff --git a/option_test.cpp b/option_test.cpp index c82bd59..aa68000 100644 --- a/option_test.cpp +++ b/option_test.cpp @@ -41,7 +41,7 @@ int main() "tsize\0"s "12345678910\0"s}; std::vector msg(test1.begin(), test1.end()); - msg.resize(PKTSIZE); + // TODO(CK): why? msg.resize(PKTSIZE); err = tftpd::tftp(msg, fp, path, ackbuf); std::cout << path << " segsize:" << tftpd::g_segsize << " tsize:" << tftpd::g_tsize << " timeout: " << tftpd::g_timeout << std::endl; diff --git a/test.sh b/test.sh index c5c6f18..e387d25 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -uex -# NOTE: not loger used: tftp-hpa 5.2 +# NOTE: not longer used: tftp-hpa 5.2 # Usage: tftp [-4][-6][-v][-V][-l][-m mode][-w size][-B blocksize] [-R port:port] [host [port]] [-c command] #XXX TFTP="/usr/bin/tftp -v -4 127.0.0.1 1234 -m binary" @@ -148,7 +148,7 @@ fi ############################################## # NOTE we start our an own client ############################################## -# normal binary upload with dublicate ack's +# normal binary upload with duplicate ack's # TODO: should not fail ## bin/tftpd_test 1234 & ## sleep 1 @@ -168,7 +168,7 @@ if test "${UNAME}" == "Linux"; then wait fi ############################################## -echo "NOTE: absolut path upload must fail!" +echo "NOTE: absolute path upload must fail!" dd if=bin/tftpd_test of=test32k.dat bs=1024 count=32 bin/tftpd_test 1234 & sleep 1 @@ -194,7 +194,7 @@ sleep 1 ${TFTP} --input=build.ninja --upload=./../build.ninja && exit 1 wait -# invalid absolut path upload must fail +# invalid absolute path upload must fail bin/tftpd_test 1234 & sleep 1 ${TFTP} --input=build.ninja --upload=//srv///tftp/build.ninja && exit 1 diff --git a/tftp/tftp.1 b/tftp/tftp.1 index 951f24b..170cd60 100644 --- a/tftp/tftp.1 +++ b/tftp/tftp.1 @@ -83,7 +83,7 @@ Note that the protocol, unlike the .Tn FTP protocol, -does not maintain connections betwen transfers; thus, the +does not maintain connections between transfers; thus, the .Cm connect command does not actually create a connection, but merely remembers what host is to be used for transfers. diff --git a/tftpd.hpp b/tftpd.hpp index c42c7eb..aad0ac7 100644 --- a/tftpd.hpp +++ b/tftpd.hpp @@ -358,7 +358,7 @@ class receiver : public server } while (false); // =============================== - // write the current data segement + // write the current data segment // =============================== size_t const seg_length = rxlen - TFTP_HEADER; ssize_t written = writeit(file_guard_.get(), &dp_, seg_length, false); diff --git a/tftpd_options.cpp b/tftpd_options.cpp index a8bf3af..4d155e5 100644 --- a/tftpd_options.cpp +++ b/tftpd_options.cpp @@ -171,7 +171,7 @@ static bool set_tsize(uintmax_t *vp) } if (sz == 0) { - sz = g_tsize; // only usefull for RRQ + sz = g_tsize; // only useful for RRQ } else { g_tsize = sz; // in case of WRQ } diff --git a/tftpd_utils.cpp b/tftpd_utils.cpp index 78b66dc..db06802 100644 --- a/tftpd_utils.cpp +++ b/tftpd_utils.cpp @@ -49,6 +49,7 @@ char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of Califor #include #include #include +#include #include #include @@ -57,9 +58,17 @@ char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of Califor #include #include #include -#include #include +#ifdef __APPLE__ +# define syslog fprintf +# define LOG_NOTICE stdout +# define LOG_WARNING stdout +# define LOG_ERR stderr +#else +# include +#endif + namespace tftpd { extern const char *g_rootdir; // the only tftp root dir used! @@ -80,7 +89,7 @@ constexpr bool suppress_error{false}; // Change root directory on startup. This means the remote host does not need to pass along the directory as part of the // transfer, and may add security. constexpr bool secure_tftp{true}; -// Allow new files to be created. Normaly, tftpd will only allow upload of files that already exist. +// Allow new files to be created. Normally, tftpd will only allow upload of files that already exist. constexpr bool allow_create{true}; struct formats @@ -100,8 +109,17 @@ static struct formats formats[] = { // XXX {"netascii", /* validate_access, send */ int tftp(const std::vector &rxbuffer, FILE *&file, std::string &file_path, std::vector &optack) { + // see too async_tftpd_server.cpp + boost::filesystem::path const dir(*dirs); + (void)boost::filesystem::create_directory(dir); + +#ifndef __APPLE__ + openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP); +#endif + syslog(LOG_NOTICE, "%s(%lu)\n", BOOST_CURRENT_FUNCTION, rxbuffer.size()); init_opt(); + file = nullptr; assert(rxbuffer.size() >= TFTP_HEADER);