summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt10
-rw-r--r--cmake/Modules/FindSystemdDaemon.cmake34
-rw-r--r--src/config.h.cmake1
-rw-r--r--src/xmpp/xmpp_component.cpp17
4 files changed, 62 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85c4138..84d9be9 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 0000000..b653889
--- /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 8ee0fd3..62186cc 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 a5e9842..17afd63 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -12,6 +12,12 @@
#include <stdio.h>
+#include <config.h>
+
+#ifdef SYSTEMDDAEMON_FOUND
+# include <systemd/sd-daemon.h>
+#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)