Add support for systemd-daemon
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
@@ -1,3 +1,4 @@
|
||||
#cmakedefine ICONV_SECOND_ARGUMENT_IS_CONST
|
||||
#cmakedefine LIBIDN_FOUND
|
||||
#cmakedefine SYSTEMDDAEMON_FOUND
|
||||
#cmakedefine POLLER ${POLLER}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user