diff --git a/CMakeLists.txt b/CMakeLists.txt index 85c4138a2e2a090247ca7e8dbd57a71b1d2d1e27..84d9be922f9afd885fc85f27b64e8ffbf33b14e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ find_package(Iconv REQUIRED) include(FindEXPAT) find_package(EXPAT REQUIRED) find_package(Libidn) +find_package(SystemdDaemon) # To be able to include the config.h file generated by cmake include_directories("src/") @@ -31,6 +32,12 @@ else() message("Building without stringprep support.") endif() +if(SYSTEMDDAEMON_FOUND) + include_directories(${SYSTEMDDAEMON_INCLUDE_DIRS}) +else() + message("Building without systemd daemon support.") +endif() + set(POLLER "POLL" CACHE STRING "Choose the poller between POLL and EPOLL (Linux-only)") if((NOT ${POLLER} MATCHES "POLL") AND @@ -124,6 +131,9 @@ target_link_libraries(${PROJECT_NAME} bridge utils config) +if(SYSTEMDDAEMON_FOUND) + target_link_libraries(xmpp ${SYSTEMDDAEMON_LIBRARIES}) +endif() if(WITH_DOC) add_dependencies(${PROJECT_NAME} doc) endif() diff --git a/cmake/Modules/FindSystemdDaemon.cmake b/cmake/Modules/FindSystemdDaemon.cmake new file mode 100644 index 0000000000000000000000000000000000000000..b653889e27a5b36ed96c544b7aa80a7e19db22b8 --- /dev/null +++ b/cmake/Modules/FindSystemdDaemon.cmake @@ -0,0 +1,34 @@ +# - Find SystemdDaemon +# Find the systemd daemon library +# +# This module defines the following variables: +# SYSTEMDDAEMON_FOUND - True if library and include directory are found +# If set to TRUE, the following are also defined: +# SYSTEMDDAEMON_INCLUDE_DIRS - The directory where to find the header file +# SYSTEMDDAEMON_LIBRARIES - Where to find the library file +# +# For conveniance, these variables are also set. They have the same values +# than the variables above. The user can thus choose his/her prefered way +# to write them. +# SYSTEMDDAEMON_LIBRARY +# SYSTEMDDAEMON_INCLUDE_DIR +# +# This file is in the public domain + +find_path(SYSTEMDDAEMON_INCLUDE_DIRS NAMES systemd/sd-daemon.h + DOC "The Systemd Daemon include directory") + +find_library(SYSTEMDDAEMON_LIBRARIES NAMES systemd-daemon + DOC "The Systemd Daemon library") + +# Use some standard module to handle the QUIETLY and REQUIRED arguments, and +# set SYSTEMDDAEMON_FOUND to TRUE if these two variables are set. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SystemdDaemon REQUIRED_VARS SYSTEMDDAEMON_LIBRARIES SYSTEMDDAEMON_INCLUDE_DIRS) + +if(SYSTEMDDAEMON_FOUND) + set(SYSTEMDDAEMON_LIBRARY ${SYSTEMDDAEMON_LIBRARIES}) + set(SYSTEMDDAEMON_INCLUDE_DIR ${SYSTEMDDAEMON_INCLUDE_DIRS}) +endif() + +mark_as_advanced(SYSTEMDDAEMON_INCLUDE_DIRS SYSTEMDDAEMON_LIBRARIES) \ No newline at end of file diff --git a/src/config.h.cmake b/src/config.h.cmake index 8ee0fd3021fac9cd33676874974ee6d4fbec1c0a..62186cc352fd0da10a39d1cb09702761845a9d78 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -1,3 +1,4 @@ #cmakedefine ICONV_SECOND_ARGUMENT_IS_CONST #cmakedefine LIBIDN_FOUND +#cmakedefine SYSTEMDDAEMON_FOUND #cmakedefine POLLER ${POLLER} diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index a5e9842d3940503e3400995384957ed8eb73370a..17afd63f7be439c9785b69c0a2427ea2e32f8259 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -12,6 +12,12 @@ #include +#include + +#ifdef SYSTEMDDAEMON_FOUND +# include +#endif + #define STREAM_NS "http://etherx.jabber.org/streams" #define COMPONENT_NS "jabber:component:accept" #define MUC_NS "http://jabber.org/protocol/muc" @@ -74,6 +80,9 @@ void XmppComponent::send_stanza(const Stanza& stanza) void XmppComponent::on_connection_failed(const std::string& reason) { log_error("Failed to connect to the XMPP server: " << reason); +#ifdef SYSTEMDDAEMON_FOUND + sd_notifyf(0, "STATUS=Failed to connect to the XMPP server: %s", reason.data()); +#endif } void XmppComponent::on_connected() @@ -248,6 +257,9 @@ void XmppComponent::handle_handshake(const Stanza& stanza) this->ever_auth = true; this->last_auth = true; log_info("Authenticated with the XMPP server"); +#ifdef SYSTEMDDAEMON_FOUND + sd_notify(0, "READY=1"); +#endif } void XmppComponent::handle_presence(const Stanza& stanza) @@ -420,6 +432,11 @@ void XmppComponent::handle_error(const Stanza& stanza) if (text) error_message = text->get_inner(); log_error("Stream error received from the XMPP server: " << error_message); +#ifdef SYSTEMDDAEMON_FOUND + if (!this->ever_auth) + sd_notifyf(0, "STATUS=Failed to authenticate to the XMPP server: %s", error_message.data()); +#endif + } Bridge* XmppComponent::get_user_bridge(const std::string& user_jid)