Commit d600a284 authored by louiz’'s avatar louiz’

Remove all the libs that are now in louloulibs

parent 1028d4d5
......@@ -15,35 +15,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE
#
## Look for external libraries
#
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
include(FindEXPAT)
find_package(EXPAT REQUIRED)
find_package(ICONV REQUIRED)
find_package(LIBUUID REQUIRED)
if(WITH_LIBIDN)
find_package(LIBIDN REQUIRED)
elseif(NOT WITHOUT_LIBIDN)
find_package(LIBIDN)
endif()
if(WITH_SYSTEMD)
find_package(SYSTEMD REQUIRED)
elseif(NOT WITHOUT_SYSTEMD)
find_package(SYSTEMD)
endif()
if(WITH_BOTAN)
find_package(BOTAN REQUIRED)
elseif(NOT WITHOUT_BOTAN)
find_package(BOTAN)
endif()
if(WITH_CARES)
find_package(CARES REQUIRED)
elseif(NOT WITHOUT_CARES)
find_package(CARES)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
#
## Get the software version
......@@ -68,42 +40,12 @@ if(${PROJECT_NAME}_VERSION_SUFFIX MATCHES "^~dev$")
endif()
endif()
set(BIBOUMI_VERSION
set(SOFTWARE_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}${${PROJECT_NAME}_VERSION_SUFFIX})
# To be able to include the config.h file generated by cmake
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/")
include_directories(${EXPAT_INCLUDE_DIRS})
include_directories(${ICONV_INCLUDE_DIRS})
include_directories(${LIBUUID_INCLUDE_DIRS})
if(LIBIDN_FOUND)
include_directories(${LIBIDN_INCLUDE_DIRS})
endif()
if(SYSTEMD_FOUND)
include_directories(${SYSTEMD_INCLUDE_DIRS})
endif()
if(BOTAN_FOUND)
include_directories(SYSTEM ${BOTAN_INCLUDE_DIRS})
endif()
if(CARES_FOUND)
include_directories(${CARES_INCLUDE_DIRS})
endif()
set(POLLER_DOCSTRING "Choose the poller between POLL and EPOLL (Linux-only)")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(POLLER "EPOLL" CACHE STRING ${POLLER_DOCSTRING})
else()
set(POLLER "POLL" CACHE STRING ${POLLER_DOCSTRING})
endif()
if((NOT ${POLLER} MATCHES "POLL") AND
(NOT ${POLLER} MATCHES "EPOLL"))
message(FATAL_ERROR "POLLER must be either POLL or EPOLL")
endif()
#
## Documentation
......@@ -121,43 +63,21 @@ if(RONN_EXECUTABLE)
add_custom_target(doc DEPENDS ${MAN_PAGE})
endif()
#
## utils
#
file(GLOB source_utils
src/utils/*.[hc]pp)
add_library(utils STATIC ${source_utils})
target_link_libraries(utils ${ICONV_LIBRARIES})
#
## config
#
file(GLOB source_config
src/config/*.[hc]pp)
add_library(config STATIC ${source_config})
target_link_libraries(config utils)
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/louloulibs")
message(FATAL_ERROR "louloulibs/ directory not found. Make sure you fetched the submodules with 'git submodule init && git submodule update'")
endif()
add_subdirectory("louloulibs")
include_directories("louloulibs")
#
## logger
#
file(GLOB source_logger
src/logger/*.[hc]pp)
add_library(logger STATIC ${source_logger})
target_link_libraries(logger config)
include_directories(${EXPAT_INCLUDE_DIRS})
include_directories(${ICONV_INCLUDE_DIRS})
include_directories(${LIBUUID_INCLUDE_DIRS})
#
## network
#
file(GLOB source_network
src/network/*.[hc]pp)
add_library(network STATIC ${source_network})
target_link_libraries(network logger)
if(BOTAN_FOUND)
target_link_libraries(network ${BOTAN_LIBRARIES})
endif()
if(CARES_FOUND)
target_link_libraries(network ${CARES_LIBRARIES})
endif()
# If they are found in louloulibs CMakeLists.txt, we inherite these values
include_directories(${LIBIDN_INCLUDE_DIRS})
include_directories(${SYSTEMD_INCLUDE_DIRS})
include_directories(SYSTEM ${BOTAN_INCLUDE_DIRS})
include_directories(${CARES_INCLUDE_DIRS})
#
## irclib
......@@ -168,17 +88,12 @@ add_library(irc STATIC ${source_irc})
target_link_libraries(irc network utils logger)
#
## xmpplib
## xmpp
#
file(GLOB source_xmpp
src/xmpp/*.[hc]pp)
add_library(xmpp STATIC ${source_xmpp})
target_link_libraries(xmpp bridge network utils logger
${EXPAT_LIBRARIES}
${LIBUUID_LIBRARIES})
if(LIBIDN_FOUND)
target_link_libraries(xmpp ${LIBIDN_LIBRARIES})
endif()
target_link_libraries(xmpp xmpplib bridge network utils logger)
#
## bridge
......@@ -209,6 +124,7 @@ endif()
add_executable(test_suite EXCLUDE_FROM_ALL
src/test.cpp)
target_link_libraries(test_suite
xmpplib
xmpp
irc
bridge
......@@ -216,9 +132,6 @@ target_link_libraries(test_suite
config
logger)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
#
## Install target
#
......
# - Find botan
# Find the botan cryptographic library
#
# This module defines the following variables:
# BOTAN_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# BOTAN_INCLUDE_DIRS - The directory where to find the header file
# BOTAN_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.
# BOTAN_LIBRARY
# BOTAN_INCLUDE_DIR
#
# This file is in the public domain
find_path(BOTAN_INCLUDE_DIRS NAMES botan/botan.h
PATH_SUFFIXES botan-1.11
DOC "The botan include directory")
find_library(BOTAN_LIBRARIES NAMES botan botan-1.11
DOC "The botan library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set BOTAN_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BOTAN REQUIRED_VARS BOTAN_LIBRARIES BOTAN_INCLUDE_DIRS)
if(BOTAN_FOUND)
set(BOTAN_LIBRARY ${BOTAN_LIBRARIES})
set(BOTAN_INCLUDE_DIR ${BOTAN_INCLUDE_DIRS})
endif()
mark_as_advanced(BOTAN_INCLUDE_DIRS BOTAN_LIBRARIES)
# - Find c-ares
# Find the c-ares library, and more particularly the stringprep header.
#
# This module defines the following variables:
# CARES_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# CARES_INCLUDE_DIRS - The directory where to find the header file
# CARES_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.
# CARES_INCLUDE_DIR
# CARES_LIBRARY
#
# This file is in the public domain
if(NOT CARES_FOUND)
find_path(CARES_INCLUDE_DIRS NAMES ares.h
DOC "The c-ares include directory")
find_library(CARES_LIBRARIES NAMES cares
DOC "The c-ares library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set CARES_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CARES REQUIRED_VARS CARES_LIBRARIES CARES_INCLUDE_DIRS)
# Compatibility for all the ways of writing these variables
if(CARES_FOUND)
set(CARES_INCLUDE_DIR ${CARES_INCLUDE_DIRS})
set(CARES_LIBRARY ${CARES_LIBRARIES})
endif()
endif()
mark_as_advanced(CARES_INCLUDE_DIRS CARES_LIBRARIES)
# - Find iconv
# Find the iconv (character set conversion) library
#
# This module defines the following variables:
# ICONV_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# ICONV_INCLUDE_DIRS - The directory where to find the header file
# ICONV_LIBRARIES - Where to find the library file
# ICONV_SECOND_ARGUMENT_IS_CONST - The second argument for iconv() is const
#
# 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.
# ICONV_LIBRARY
# ICONV_INCLUDE_DIR
#
# This file is in the public domain
find_path(ICONV_INCLUDE_DIRS NAMES iconv.h
DOC "The iconv include directory")
find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c
DOC "The iconv library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set ICONV_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Iconv REQUIRED_VARS ICONV_LIBRARIES ICONV_INCLUDE_DIRS)
# Check if the prototype is
# size_t iconv(iconv_t cd, char** inbuf, size_t* inbytesleft,
# char** outbuf, size_t* outbytesleft);
# or
# size_t iconv (iconv_t cd, const char** inbuf, size_t* inbytesleft,
# char** outbuf, size_t* outbytesleft);
if(ICONV_FOUND)
include(CheckCXXSourceCompiles)
# Set the parameters needed to compile the following code.
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
check_cxx_source_compiles("
#include <iconv.h>
int main(){
iconv_t conv = 0;
const char* in = 0;
size_t ilen = 0;
char* out = 0;
size_t olen = 0;
iconv(conv, &in, &ilen, &out, &olen);
return 0;}"
ICONV_SECOND_ARGUMENT_IS_CONST)
# Compatibility for all the ways of writing these variables
set(ICONV_LIBRARY ${ICONV_LIBRARIES})
set(ICONV_INCLUDE_DIR ${ICONV_INCLUDE_DIRS})
endif()
mark_as_advanced(ICONV_INCLUDE_DIRS ICONV_LIBRARIES ICONV_SECOND_ARGUMENT_IS_CONST)
\ No newline at end of file
# - Find libidn
# Find the libidn library, and more particularly the stringprep header.
#
# This module defines the following variables:
# LIBIDN_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# LIBIDN_INCLUDE_DIRS - The directory where to find the header file
# LIBIDN_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.
# LIBIDN_INCLUDE_DIR
# LIBIDN_LIBRARY
#
# This file is in the public domain
include(FindPkgConfig)
pkg_check_modules(LIBIDN libidn)
if(NOT LIBIDN_FOUND)
find_path(LIBIDN_INCLUDE_DIRS NAMES stringprep.h
DOC "The libidn include directory")
# The library containing the stringprep module is libidn
find_library(LIBIDN_LIBRARIES NAMES idn
DOC "The libidn library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set LIBIDN_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBIDN REQUIRED_VARS LIBIDN_LIBRARIES LIBIDN_INCLUDE_DIRS)
# Compatibility for all the ways of writing these variables
if(LIBIDN_FOUND)
set(LIBIDN_INCLUDE_DIR ${LIBIDN_INCLUDE_DIRS})
set(LIBIDN_LIBRARY ${LIBIDN_LIBRARIES})
endif()
endif()
mark_as_advanced(LIBIDN_INCLUDE_DIRS LIBIDN_LIBRARIES)
\ No newline at end of file
# - Find libuuid
# Find the libuuid library
#
# This module defines the following variables:
# LIBUUID_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# LIBUUID_INCLUDE_DIRS - The directory where to find the header file
# LIBUUID_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.
# LIBUUID_INCLUDE_DIR
# LIBUUID_LIBRARY
#
# This file is in the public domain
include(FindPkgConfig)
pkg_check_modules(LIBUUID uuid)
if(NOT LIBUUID_FOUND)
find_path(LIBUUID_INCLUDE_DIRS NAMES uuid.h
PATH_SUFFIXES uuid
DOC "The libuuid include directory")
find_library(LIBUUID_LIBRARIES NAMES uuid
DOC "The libuuid library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set LIBUUID_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBUUID REQUIRED_VARS LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
# Compatibility for all the ways of writing these variables
if(LIBUUID_FOUND)
set(LIBUUID_INCLUDE_DIR ${LIBUUID_INCLUDE_DIRS})
set(LIBUUID_LIBRARY ${LIBUUID_LIBRARIES})
endif()
endif()
mark_as_advanced(LIBUUID_INCLUDE_DIRS LIBUUID_LIBRARIES)
# - Find SystemdDaemon
# Find the systemd daemon library
#
# This module defines the following variables:
# SYSTEMD_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# SYSTEMD_INCLUDE_DIRS - The directory where to find the header file
# SYSTEMD_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.
# SYSTEMD_LIBRARY
# SYSTEMD_INCLUDE_DIR
#
# This file is in the public domain
include(FindPkgConfig)
pkg_check_modules(SYSTEMD libsystemd)
if(NOT SYSTEMD_FOUND)
find_path(SYSTEMD_INCLUDE_DIRS NAMES systemd/sd-daemon.h
DOC "The Systemd include directory")
find_library(SYSTEMD_LIBRARIES NAMES systemd
DOC "The Systemd library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set SYSTEMD_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SYSTEMD REQUIRED_VARS SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS)
if(SYSTEMD_FOUND)
set(SYSTEMD_LIBRARY ${SYSTEMD_LIBRARIES})
set(SYSTEMD_INCLUDE_DIR ${SYSTEMD_INCLUDE_DIRS})
endif()
endif()
mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
\ No newline at end of file
#include <bridge/bridge.hpp>
#include <bridge/colors.hpp>
#include <bridge/list_element.hpp>
#include <xmpp/xmpp_component.hpp>
#include <xmpp/biboumi_component.hpp>
#include <xmpp/xmpp_stanza.hpp>
#include <irc/irc_message.hpp>
#include <network/poller.hpp>
......@@ -20,7 +20,7 @@ using namespace std::string_literals;
static const char* action_prefix = "\01ACTION ";
Bridge::Bridge(const std::string& user_jid, XmppComponent* xmpp, std::shared_ptr<Poller> poller):
Bridge::Bridge(const std::string& user_jid, BiboumiComponent* xmpp, std::shared_ptr<Poller> poller):
user_jid(user_jid),
xmpp(xmpp),
poller(poller)
......
......@@ -12,7 +12,7 @@
#include <string>
#include <memory>
class XmppComponent;
class BiboumiComponent;
class Poller;
/**
......@@ -32,7 +32,7 @@ using irc_responder_callback_t = std::function<bool(const std::string& irc_hostn
class Bridge
{
public:
explicit Bridge(const std::string& user_jid, XmppComponent* xmpp, std::shared_ptr<Poller> poller);
explicit Bridge(const std::string& user_jid, BiboumiComponent* xmpp, std::shared_ptr<Poller> poller);
~Bridge();
/**
* QUIT all connected IRC servers.
......@@ -211,7 +211,7 @@ private:
* but we still need to communicate with it, when sending messages from
* IRC to XMPP.
*/
XmppComponent* xmpp;
BiboumiComponent* xmpp;
/**
* Poller, to give it the IrcClients that we spawn, to make it manage
* their sockets.
......
#define SYSTEM_NAME "${CMAKE_SYSTEM}"
#cmakedefine ICONV_SECOND_ARGUMENT_IS_CONST
#cmakedefine LIBIDN_FOUND
#cmakedefine SYSTEMD_FOUND
#cmakedefine POLLER ${POLLER}
#cmakedefine BOTAN_FOUND
#cmakedefine CARES_FOUND
#cmakedefine BIBOUMI_VERSION "${BIBOUMI_VERSION}"
#include <config/config.hpp>
#include <iostream>
#include <sstream>
#include <stdlib.h>
std::string Config::filename = "./biboumi.cfg";
bool Config::file_must_exist = false;
std::string Config::get(const std::string& option, const std::string& def)
{
Config* self = Config::instance().get();
auto it = self->values.find(option);
if (it == self->values.end())
return def;
return it->second;
}
int Config::get_int(const std::string& option, const int& def)
{
Config* self = Config::instance().get();
std::string res = self->get(option, "");
if (!res.empty())
return atoi(res.c_str());
else
return def;
}
void Config::set(const std::string& option, const std::string& value, bool save)
{
Config* self = Config::instance().get();
self->values[option] = value;
if (save)
{
self->save_to_file();
self->trigger_configuration_change();
}
}
void Config::connect(t_config_changed_callback callback)
{
Config* self = Config::instance().get();
self->callbacks.push_back(callback);
}
void Config::close()
{
Config* self = Config::instance().get();
self->values.clear();
Config::instance().reset();
}
/**
* Private methods
*/
void Config::trigger_configuration_change()
{
std::vector<t_config_changed_callback>::iterator it;
for (it = this->callbacks.begin(); it < this->callbacks.end(); ++it)
(*it)();
}
std::unique_ptr<Config>& Config::instance()
{
static std::unique_ptr<Config> instance;
if (!instance)
{
instance = std::make_unique<Config>();
instance->read_conf();
}
return instance;
}
bool Config::read_conf()
{
std::ifstream file;
file.open(filename.data());
if (!file.is_open())
{
if (Config::file_must_exist)
{
perror(("Error while opening file " + filename + " for reading.").c_str());
file.exceptions(std::ifstream::failbit);
}
return false;
}
std::string line;
size_t pos;
std::string option;
std::string value;
while (file.good())
{
std::getline(file, line);
if (line == "" || line[0] == '#')
continue ;
pos = line.find('=');
if (pos == std::string::npos)
continue ;
option = line.substr(0, pos);
value = line.substr(pos+1);
this->values[option] = value;
}
return true;
}
void Config::save_to_file() const
{
std::ofstream file(this->filename.data());
if (file.fail())
{
std::cerr << "Could not save config file." << std::endl;
return ;
}
for (auto& it: this->values)
file << it.first << "=" << it.second << std::endl;
file.close();
}
/**
* Read the config file and save all the values in a map.
* Also, a singleton.
*
* Use Config::filename = "bla" to set the filename you want to use.
*
* If you want to exit if the file does not exist when it is open for
* reading, set Config::file_must_exist = true.
*
* Config::get() can the be used to access the values in the conf.
*
* Use Config::close() when you're done getting/setting value. This will
* save the config into the file.
*/
#ifndef CONFIG_INCLUDED
# define CONFIG_INCLUDED
#include <functional>
#include <fstream>
#include <memory>
#include <vector>
#include <string>
#include <map>
typedef std::function<void()> t_config_changed_callback;
class Config
{
public:
Config(){};
~Config(){};
/**
* returns a value from the config. If it doesn’t exist, use
* the second argument as the default.
* @param option The option we want
* @param def The default value in case the option does not exist
*/
static std::string get(const std::string&, const std::string&);
/**
* returns a value from the config. If it doesn’t exist, use
* the second argument as the default.
* @param option The option we want
* @param def The default value in case the option does not exist
*/
static int get_int(const std::string&, const int&);
/**
* Set a value for the given option. And write all the config
* in the file from which it was read if boolean is set.
* @param option The option to set
* @param value The value to use
* @param save if true, save the config file
*/
static void set(const std::string&, const std::string&, bool save = false);
/**
* Adds a function to a list. This function will be called whenever a
* configuration change occurs.
*/
static void connect(t_config_changed_callback);
/**
* Close the config file, saving it to the file is save == true.
*/
static void close();
/**
* Set the value of the filename to use, before calling any method.
*/
static std::string filename;
/**
* Set to true if you want an exception to be raised if the file does not
* exist when reading it.
*/
static bool file_must_exist;
private:
/**
* Get the singleton instance
*/
static std::unique_ptr<Config>& instance();
/**
* Read the configuration file at the given path.
*/
bool read_conf();
/**
* Write all the config values into the configuration file
*/
void save_to_file() const;
/**
* Call all the callbacks previously registered using connect().
* This is used to notify any class that a configuration change occured.
*/
void trigger_configuration_change();
std::map<std::string, std::string> values;
std::vector<t_config_changed_callback> callbacks;
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
Config(Config&&) = delete;
Config& operator=(Config&&) = delete;
};
#endif // CONFIG_INCLUDED
......@@ -14,7 +14,7 @@
#include <chrono>
#include <string>
#include "config.h"
#include "louloulibs.h"
using namespace std::