7 Commits

Author SHA1 Message Date
Philipp Swoboda
a01974171f Add runtime libraries during install steps 2025-03-03 09:34:22 +01:00
Philipp Swoboda
75dc1cc25d Add LabMCT install instructions 2025-02-28 15:13:21 +01:00
ef3942807f Add special install rules for LabMCT 2024-03-20 15:35:56 +01:00
a814dea032 Add HTTP PATCH request 2023-06-12 18:56:23 +02:00
4aba620039 Add remove user function in basicauthmiddleware 2023-06-09 12:51:42 +02:00
0960b2c7f7 Update 'CMakeLists.txt' 2023-06-08 12:37:05 +02:00
Philipp Swoboda
90fc0a01b0 Make qhttpengine compatible with Qt6 2023-06-07 22:31:55 +02:00
11 changed files with 73 additions and 36 deletions

View File

@@ -13,6 +13,10 @@ set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_
# Build a shared library by default # Build a shared library by default
option(BUILD_SHARED_LIBS "Build QHttpEngine as a shared library" ON) option(BUILD_SHARED_LIBS "Build QHttpEngine as a shared library" ON)
option(BUILD_AGAINST_QT6 "Build against Qt6" ON)
option(BUILD_FOR_LABMCT "Build for LabMCT" OFF)
set(BUILD_FOR_LABMCT ON)
set(BIN_INSTALL_DIR bin CACHE STRING "Binary runtime installation directory relative to the install prefix") set(BIN_INSTALL_DIR bin CACHE STRING "Binary runtime installation directory relative to the install prefix")
set(LIB_INSTALL_DIR lib CACHE STRING "Library installation directory relative to the install prefix") set(LIB_INSTALL_DIR lib CACHE STRING "Library installation directory relative to the install prefix")
@@ -21,8 +25,14 @@ set(INCLUDE_INSTALL_DIR include CACHE STRING "Header installation directory rela
set(DOC_INSTALL_DIR share/doc/qhttpengine CACHE STRING "Documentation installation directory relative to the install prefix") set(DOC_INSTALL_DIR share/doc/qhttpengine CACHE STRING "Documentation installation directory relative to the install prefix")
set(EXAMPLES_INSTALL_DIR "${LIB_INSTALL_DIR}/qhttpengine/examples" CACHE STRING "Examples installation directory relative to the install prefix") set(EXAMPLES_INSTALL_DIR "${LIB_INSTALL_DIR}/qhttpengine/examples" CACHE STRING "Examples installation directory relative to the install prefix")
find_package(Qt5Network 5.4 REQUIRED)
if(BUILD_AGAINST_QT6)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Core5Compat Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Core5Compat Network REQUIRED)
else()
find_package(QT NAMES Qt5 COMPONENTS Core Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network REQUIRED)
endif()
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
add_subdirectory(src) add_subdirectory(src)
@@ -38,22 +48,22 @@ if(BUILD_EXAMPLES)
add_subdirectory(examples) add_subdirectory(examples)
endif() endif()
option(BUILD_TESTS "Build the test suite" OFF) #option(BUILD_TESTS "Build the test suite" OFF)
if(BUILD_TESTS) #if(BUILD_TESTS)
find_package(Qt5Test 5.4 REQUIRED) # find_package(Qt${QT_VERSION_MAJOR}Test REQUIRED)
enable_testing() # enable_testing()
add_subdirectory(tests) # add_subdirectory(tests)
endif() #endif()
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}") #set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "${PROJECT_AUTHOR}") #set(CPACK_PACKAGE_VENDOR "${PROJECT_AUTHOR}")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) #set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) #set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) #set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "Documentation") #set(CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "Documentation")
set(CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION "Documentation generated for the library") #set(CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION "Documentation generated for the library")
set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Examples") #set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Examples")
set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION "Sample applications using the library") #set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION "Sample applications using the library")
include(CPack) #include(CPack)

View File

@@ -3,7 +3,7 @@ set(SRC
main.cpp main.cpp
) )
qt5_add_resources(QRC resources.qrc) qt_add_resources(QRC resources.qrc)
add_executable(chatserver ${SRC} ${QRC}) add_executable(chatserver ${SRC} ${QRC})
target_link_libraries(chatserver qhttpengine) target_link_libraries(chatserver qhttpengine)

View File

@@ -42,13 +42,13 @@ endif()
add_library(qhttpengine ${HEADERS} ${SRC}) add_library(qhttpengine ${HEADERS} ${SRC})
set_target_properties(qhttpengine PROPERTIES set_target_properties(qhttpengine PROPERTIES
CXX_STANDARD 11 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
DEFINE_SYMBOL QT_NO_SIGNALS_SLOTS_KEYWORDS DEFINE_SYMBOL QT_NO_SIGNALS_SLOTS_KEYWORDS
DEFINE_SYMBOL QHTTPENGINE_LIBRARY DEFINE_SYMBOL QHTTPENGINE_LIBRARY
PUBLIC_HEADER "${HEADERS}" PUBLIC_HEADER "${HEADERS}"
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR} #SOVERSION ${PROJECT_VERSION_MAJOR}
) )
target_include_directories(qhttpengine PUBLIC target_include_directories(qhttpengine PUBLIC
@@ -57,8 +57,20 @@ target_include_directories(qhttpengine PUBLIC
"$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>" "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>"
) )
target_link_libraries(qhttpengine Qt5::Network) if(BUILD_AGAINST_QT6)
target_link_libraries(qhttpengine Qt${QT_VERSION_MAJOR}::Network Qt6::Core5Compat)
else()
target_link_libraries(qhttpengine Qt${QT_VERSION_MAJOR}::Network)
endif()
if(BUILD_FOR_LABMCT)
set_target_properties(qhttpengine PROPERTIES
INSTALL_RPATH "${LABMCT_RPATH}")
install(FILES $<TARGET_RUNTIME_DLLS:qhttpengine> DESTINATION ./)
install(TARGETS qhttpengine
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
else()
install(TARGETS qhttpengine EXPORT qhttpengine-export install(TARGETS qhttpengine EXPORT qhttpengine-export
RUNTIME DESTINATION "${BIN_INSTALL_DIR}" RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
LIBRARY DESTINATION "${LIB_INSTALL_DIR}" LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
@@ -86,3 +98,4 @@ configure_file(qhttpengine.pc.in "${CMAKE_CURRENT_BINARY_DIR}/qhttpengine.pc" @O
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qhttpengine.pc" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qhttpengine.pc"
DESTINATION "${LIB_INSTALL_DIR}/pkgconfig" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig"
) )
endif()

View File

@@ -61,6 +61,7 @@ public:
* with the new one provided. * with the new one provided.
*/ */
void add(const QString &username, const QString &password); void add(const QString &username, const QString &password);
void remove(const QString &username);
/** /**
* @brief Process the request * @brief Process the request

View File

@@ -137,19 +137,19 @@ public:
} }
template <typename Func1> template <typename Func1>
inline typename QtPrivate::QEnableIf<!QtPrivate::AreArgumentsCompatible<Func1, QObject*>::value, void>::Type inline typename std::enable_if<!QtPrivate::AreArgumentsCompatible<Func1, QObject*>::value, void>::type
registerMethod(const QString &name, Func1 slot, bool readAll = true) { registerMethod(const QString &name, Func1 slot, bool readAll = true) {
registerMethod(name, Q_NULLPTR, slot, readAll); registerMethod(name, Q_NULLPTR, slot, readAll);
} }
template <typename Func1> template <typename Func1>
inline typename QtPrivate::QEnableIf<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction &&
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
!std::is_same<const char*, Func1>::value, !std::is_same<const char*, Func1>::value,
#else #else
!QtPrivate::is_same<const char*, Func1>::value, !QtPrivate::is_same<const char*, Func1>::value,
#endif #endif
void>::Type void>::type
registerMethod(const QString &name, QObject *context, Func1 slot, bool readAll = true) { registerMethod(const QString &name, QObject *context, Func1 slot, bool readAll = true) {
// There is an easier way to do this but then the header wouldn't // There is an easier way to do this but then the header wouldn't
@@ -158,6 +158,7 @@ public:
} }
#endif #endif
protected: protected:
/** /**

View File

@@ -135,7 +135,9 @@ public:
/// Diagnostic trace /// Diagnostic trace
TRACE = 1 << 6, TRACE = 1 << 6,
/// Proxy connection /// Proxy connection
CONNECT = 1 << 7 CONNECT = 1 << 7,
/// Store partial resource
PATCH = 1 << 8
}; };
/** /**

View File

@@ -46,6 +46,11 @@ void BasicAuthMiddleware::add(const QString &username, const QString &password)
d->map.insert(username, password); d->map.insert(username, password);
} }
void BasicAuthMiddleware::remove(const QString &username)
{
d->map.remove(username);
}
bool BasicAuthMiddleware::verify(const QString &username, const QString &password) bool BasicAuthMiddleware::verify(const QString &username, const QString &password)
{ {
return d->map.contains(username) && d->map.value(username) == password; return d->map.contains(username) && d->map.value(username) == password;

View File

@@ -125,6 +125,8 @@ bool Parser::parseRequestHeaders(const QByteArray &data, Socket::Method &method,
method = Socket::TRACE; method = Socket::TRACE;
} else if (parts[0] == "CONNECT") { } else if (parts[0] == "CONNECT") {
method = Socket::CONNECT; method = Socket::CONNECT;
} else if (parts[0] == "PATCH") {
method = Socket::PATCH;
} else { } else {
return false; return false;
} }

View File

@@ -38,13 +38,12 @@ ProxySocket::ProxySocket(Socket *socket, const QString &path, const QHostAddress
connect(&mUpstreamSocket, &QTcpSocket::connected, this, &ProxySocket::onUpstreamConnected); connect(&mUpstreamSocket, &QTcpSocket::connected, this, &ProxySocket::onUpstreamConnected);
connect(&mUpstreamSocket, &QTcpSocket::readyRead, this, &ProxySocket::onUpstreamReadyRead); connect(&mUpstreamSocket, &QTcpSocket::readyRead, this, &ProxySocket::onUpstreamReadyRead);
connect( #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
&mUpstreamSocket, connect(&mUpstreamSocket, &QAbstractSocket::error,this, &ProxySocket::onUpstreamError);
static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error), #else
this, connect(&mUpstreamSocket, static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error),
&ProxySocket::onUpstreamError this, &ProxySocket::onUpstreamError);
); #endif
mUpstreamSocket.connectToHost(address, port); mUpstreamSocket.connectToHost(address, port);
} }
@@ -135,7 +134,7 @@ void ProxySocket::onUpstreamReadyRead()
} }
} }
void ProxySocket::onUpstreamError(QAbstractSocket::SocketError socketError) void ProxySocket::onUpstreamError()
{ {
if (mHeadersParsed) { if (mHeadersParsed) {
mDownstreamSocket->close(); mDownstreamSocket->close();

View File

@@ -51,7 +51,7 @@ private Q_SLOTS:
void onUpstreamConnected(); void onUpstreamConnected();
void onUpstreamReadyRead(); void onUpstreamReadyRead();
void onUpstreamError(QTcpSocket::SocketError socketError); void onUpstreamError();
private: private:

View File

@@ -91,8 +91,12 @@ void Server::incomingConnection(qintptr socketDescriptor)
}); });
// If an error occurs, delete the socket // If an error occurs, delete the socket
connect(socket, static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error), #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
socket, &QSslSocket::deleteLater); connect(socket, &QAbstractSocket::error, socket, &QSslSocket::deleteLater);
#else
connect(socket, static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error),
socket, &QSslSocket::deleteLater);
#endif
socket->setSocketDescriptor(socketDescriptor); socket->setSocketDescriptor(socketDescriptor);
socket->setSslConfiguration(d->configuration); socket->setSslConfiguration(d->configuration);