Skip to content

[http] let use external civetweb #14194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmake/modules/RootBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ROOT_BUILD_OPTION(builtin_cfitsio OFF "Build CFITSIO internally (requires networ
ROOT_BUILD_OPTION(builtin_clang ON "Build bundled copy of Clang")
ROOT_BUILD_OPTION(builtin_cling ON "Build bundled copy of Cling. Only build with an external cling if you know what you are doing: associating ROOT commits with cling commits is tricky.")
MARK_AS_ADVANCED(builtin_cling)
ROOT_BUILD_OPTION(builtin_civetweb ON "Use civetweb distributed with ROOT")
ROOT_BUILD_OPTION(builtin_cppzmq OFF "Use ZeroMQ C++ bindings installed by ROOT (requires network)")
ROOT_BUILD_OPTION(builtin_davix OFF "Build Davix internally (requires network)")
ROOT_BUILD_OPTION(builtin_fftw3 OFF "Build FFTW3 internally (requires network)")
Expand Down Expand Up @@ -278,6 +279,7 @@ endif()
if(builtin_all)
set(builtin_afterimage_defvalue ON)
set(builtin_cfitsio_defvalue ON)
set(builtin_civetweb_defvalue ON)
set(builtin_clang_defvalue ON)
set(builtin_cling_defvalue ON)
set(builtin_cppzmq_defvalue ON)
Expand Down
21 changes: 21 additions & 0 deletions cmake/modules/SearchInstalledSoftware.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ if(builtin_nlohmannjson)
add_subdirectory(builtins/nlohmann)
endif()

#--- Check for civetweb ---------------------------------------------------------
if(NOT builtin_civetweb)
message(STATUS "Looking for civetweb")
if(NOT "$ENV{CIVETWEB_BUILD}" STREQUAL "" AND NOT "$ENV{CIVETWEB_SRC}" STREQUAL "")
set(civetweb_LIBRARIES $ENV{CIVETWEB_BUILD}/src/libcivetweb.so)
set(civetweb_INCLUDE_DIR $ENV{CIVETWEB_SRC}/include)
message(STATUS "Use civetweb ${civetweb_LIBRARIES} and ${civetweb_INCLUDE_DIR}")
else()
if(fail-on-missing)
find_package(civetweb 1.15 REQUIRED)
else()
find_package(civetweb 1.15 QUIET)
if(civetweb_FOUND)
message(STATUS "Found civetweb version ${civetweb_VERSION}")
else()
message(STATUS "civetweb not found. Switching on builtin_civetweb option")
set(builtin_civetweb ON CACHE BOOL "Enabled because civetweb not found" FORCE)
endif()
endif()
endif()
endif()

#---Check for Unuran ------------------------------------------------------------------
if(unuran AND NOT builtin_unuran)
Expand Down
91 changes: 53 additions & 38 deletions net/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if(RT_LIBRARY)
set(RT_LIBRARIES ${RT_LIBRARY})
endif()

if(builtin_civetweb)
set(_civetweb_src civetweb/civetweb.c)
set(_civetweb_libs ${RT_LIBRARIES} )
endif()

ROOT_STANDARD_LIBRARY_PACKAGE(RHTTP
HEADERS
THttpCallArg.h
Expand All @@ -42,62 +47,72 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RHTTP
src/THttpWSHandler.cxx
src/TRootSniffer.cxx
src/TRootSnifferStore.cxx
civetweb/civetweb.c
${_civetweb_src}
LIBRARIES
ZLIB::ZLIB
${RT_LIBRARIES}
${_civetweb_libs}
${FASTCGI_LIBRARY}
${CMAKE_DL_LIBS}
DEPENDENCIES
RIO
Thread
)

if(ssl)
target_include_directories(RHTTP SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR})
endif()
if(builtin_civetweb)
target_include_directories(RHTTP PRIVATE civetweb)

if(FASTCGI_FOUND)
target_include_directories(RHTTP PRIVATE ${FASTCGI_INCLUDE_DIR})
endif()
if(ssl)
target_include_directories(RHTTP SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR})
endif()

target_compile_definitions(RHTTP PRIVATE -DUSE_WEBSOCKET)
target_compile_definitions(RHTTP PRIVATE -DUSE_WEBSOCKET)

if(NOT MSVC)
target_compile_definitions(RHTTP PRIVATE -DUSE_X_DOM_SOCKET)
endif()
if(NOT MSVC)
target_compile_definitions(RHTTP PRIVATE -DUSE_X_DOM_SOCKET)
endif()

if(ssl)
if(OPENSSL_VERSION)
string(REPLACE "." ";" lst ${OPENSSL_VERSION})
list(GET lst 0 ssl_major)
list(GET lst 1 ssl_minor)
endif()
if(ssl)
if(OPENSSL_VERSION)
string(REPLACE "." ";" lst ${OPENSSL_VERSION})
list(GET lst 0 ssl_major)
list(GET lst 1 ssl_minor)
endif()

if((${ssl_major} EQUAL "1") AND (${ssl_minor} EQUAL "1"))
MESSAGE(STATUS "Use SSL API VERSION 1.1 for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_1_1)
set(link_ssl ON)
elseif((${ssl_major} EQUAL "3") AND ((${ssl_minor} EQUAL "0") OR (${ssl_minor} EQUAL "1")))
MESSAGE(STATUS "Use SSL API VERSION 3.${ssl_minor} for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_3_0)
set(link_ssl ON)
elseif((${ssl_major} EQUAL "1") AND (${ssl_minor} EQUAL "0"))
MESSAGE(STATUS "Use SSL API VERSION 1.0 for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_1_0)
set(link_ssl ON)
if((${ssl_major} EQUAL "1") AND (${ssl_minor} EQUAL "1"))
MESSAGE(STATUS "Use SSL API VERSION 1.1 for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_1_1)
set(link_ssl ON)
elseif((${ssl_major} EQUAL "3") AND ((${ssl_minor} EQUAL "0") OR (${ssl_minor} EQUAL "1")))
MESSAGE(STATUS "Use SSL API VERSION 3.${ssl_minor} for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_3_0)
set(link_ssl ON)
elseif((${ssl_major} EQUAL "1") AND (${ssl_minor} EQUAL "0"))
MESSAGE(STATUS "Use SSL API VERSION 1.0 for civetweb")
target_compile_definitions(RHTTP PUBLIC -DOPENSSL_API_1_0)
set(link_ssl ON)
else()
MESSAGE(WARNING "Not able to recognize SSL version ${OPENSSL_VERSION}, disable SSL")
target_compile_definitions(RHTTP PUBLIC -DNO_SSL)
endif()
if(link_ssl)
target_compile_definitions(RHTTP PUBLIC -DNO_SSL_DL)
target_link_libraries(RHTTP PRIVATE ${OPENSSL_LIBRARIES})
endif()
else()
MESSAGE(WARNING "Not able to recognize SSL version ${OPENSSL_VERSION}, disable SSL")
target_compile_definitions(RHTTP PUBLIC -DNO_SSL)
endif()
if(link_ssl)
target_compile_definitions(RHTTP PUBLIC -DNO_SSL_DL)
target_link_libraries(RHTTP PRIVATE ${OPENSSL_LIBRARIES})
endif()

else()
target_compile_definitions(RHTTP PUBLIC -DNO_SSL)
endif()

if(NOT FASTCGI_FOUND)
target_include_directories(RHTTP SYSTEM PRIVATE ${civetweb_INCLUDE_DIR})
target_link_libraries(RHTTP PRIVATE ${civetweb_LIBRARIES})
# workaround for R__memcompress failure with external civetweb
target_compile_definitions(RHTTP PRIVATE -D_EXTERNAL_CIVETWEB)

endif(builtin_civetweb)

if(FASTCGI_FOUND)
target_include_directories(RHTTP PRIVATE ${FASTCGI_INCLUDE_DIR})
else()
target_compile_definitions(RHTTP PUBLIC -DHTTP_WITHOUT_FASTCGI)
endif()
34 changes: 33 additions & 1 deletion net/http/src/TCivetweb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,15 @@ static int begin_request_handler(struct mg_connection *conn, void *)
case THttpCallArg::kZipAlways: dozip = kTRUE; break;
}

#ifdef _EXTERNAL_CIVETWEB
// with external civeweb one gets failure R__memcompress
// while it is not critical, try to avoid for now
// to be tested later
(void) dozip;
#else
if (dozip)
arg->CompressWithGzip();
#endif

std::string hdr = arg->FillHttpHeader("HTTP/1.1");
mg_printf(conn, "%s", hdr.c_str());
Expand Down Expand Up @@ -524,14 +531,16 @@ TCivetweb::~TCivetweb()
{
if (fCtx && !fTerminating)
mg_stop(fCtx);

mg_exit_library();
}

////////////////////////////////////////////////////////////////////////////////
/// process civetweb log message, can be used to detect critical errors

Int_t TCivetweb::ProcessLog(const char *message)
{
if ((gDebug > 0) || (strstr(message, "cannot bind to") != 0))
if ((gDebug > 0) || strstr(message, "cannot bind to"))
Error("Log", "%s", message);

return 0;
Expand Down Expand Up @@ -775,6 +784,29 @@ Bool_t TCivetweb::Create(const char *args)

options[op++] = nullptr;

if (is_socket && !mg_check_feature(MG_FEATURES_X_DOMAIN_SOCKET)) {
Error("Create", "civetweb compiled without sockets binding support");
return kFALSE;
}

if (IsSecured() && !mg_check_feature(MG_FEATURES_SSL)) {
Error("Create", "civetweb compiled without SSL support");
return kFALSE;
}

if (!mg_check_feature(MG_FEATURES_WEBSOCKET)) {
Error("Create", "civetweb compiled without websockets support");
return kFALSE;
}

if (IsSecured()) {
/* Initialize with SSL support */
mg_init_library(MG_FEATURES_TLS);
} else {
/* Initialize without SSL support */
mg_init_library(MG_FEATURES_DEFAULT);
}

// try to remove socket file - if any
if (is_socket && !sport.Contains(","))
gSystem->Unlink(sport.Data()+1);
Expand Down
2 changes: 1 addition & 1 deletion net/http/src/TCivetweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <mutex>

#include "../civetweb/civetweb.h"
#include "civetweb.h"

class TCivetweb : public THttpEngine {
protected:
Expand Down