Commit 70dc2392 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Adding file for conference

parent 5d837b14
......@@ -28,3 +28,6 @@
[submodule "submodules/bcunit"]
path = submodules/bcunit
url = git://git.linphone.org/bcunit.git
[submodule "submodules/linphone"]
path = submodules/linphone
url = git://git.linphone.org/linphone.git
......@@ -43,6 +43,7 @@ option(ENABLE_DOC "Build documentation" YES)
option(ENABLE_MONOTONIC_CLOCK_REGISTRATIONS "Enable monotonic clock for registrations" NO)
option(ENABLE_ODBC "Build ODBC support for database connection" NO)
option(ENABLE_PRESENCE "Build presence support" NO)
option(ENABLE_CONFERENCE "Build conference support" NO)
option(ENABLE_PROTOBUF "Build with protobuf support" NO)
option(ENABLE_PUSHNOTIFICATION "Build with remote push notification support" YES)
option(ENABLE_REDIS "Build with Redis support" NO)
......@@ -52,6 +53,8 @@ option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_TRANSCODER "Build transcoder support" YES)
cmake_dependent_option(ENABLE_SPECIFIC_FEATURES "Enable mediarelay specific features" OFF "ENABLE_TRANSCODER" OFF)
find_package(Threads)
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
......@@ -226,6 +229,16 @@ if(ENABLE_PRESENCE)
endif()
endif()
if(ENABLE_CONFERENCE)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake")
include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake")
else ()
#find_package(Linphone REQUIRED)
#find_package(LinphoneCxx REQUIRED)
endif()
endif()
if(ENABLE_SOCI)
find_package(Soci REQUIRED COMPONENTS mysql)
find_path(SOCI_MYSQL_INCLUDES NAMES mysql.h PATH_SUFFIXES mysql)
......
......@@ -7,6 +7,7 @@
#cmakedefine ENABLE_LIBODB_MYSQL 1
#cmakedefine ENABLE_TRANSCODER 1
#cmakedefine ENABLE_PRESENCE 1
#cmakedefine ENABLE_CONFERENCE 1
#cmakedefine ENABLE_PROTOBUF 1
#cmakedefine ENABLE_ODBC 1
#cmakedefine ENABLE_REDIS 1
......
......@@ -20,7 +20,7 @@
#
############################################################################
set(FLEXISIP_LIBS ${ORTP_LIBRARIES} ${SOFIASIPUA_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES})
set(FLEXISIP_LIBS ${ORTP_LIBRARIES} ${SOFIASIPUA_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(FLEXISIP_INCLUDES)
......@@ -79,6 +79,7 @@ set(FLEXISIP_SOURCES
module-redirect.cc module-presence.cc
domain-registrations.cc domain-registrations.hh
stats.cc stats.hh
service-server.hh
${FLEXISIP_UTILS_SRC}
)
......@@ -88,7 +89,6 @@ add_custom_target(flexisip-git-version
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/flexisip_gitversion.h"
)
function(ADD_XSD_WRAPPERS file _comment)
set(destinations ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.hxx ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.cxx)
set(source ${CMAKE_CURRENT_LIST_DIR}/xml/${file}.xsd)
......@@ -197,6 +197,13 @@ if(ENABLE_PRESENCE)
list(APPEND FLEXISIP_DEPENDENCIES xml pidf+xml rlmi+xml resource-lists rpid data-model)
endif()
if(ENABLE_CONFERENCE)
list(APPEND FLEXISIP_SOURCES
conference/conference-server.cc
conference/conference-server.hh
)
endif()
if(ENABLE_PUSHNOTIFICATION)
file(GLOB PUSHNOTIFICATION_SRCS pushnotification/*.cc pushnotification/*.hh)
list(APPEND FLEXISIP_SOURCES module-pushnotification.cc ${PUSHNOTIFICATION_SRCS})
......
......@@ -73,7 +73,8 @@ thesources= \
$(GITVERSION_FILE) \
module-redirect.cc module-presence.cc \
domain-registrations.cc domain-registrations.hh \
utils/threadpool.cc utils/threadpool.hh
utils/threadpool.cc utils/threadpool.hh \
service-server.hh
......
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2017 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "conference-server.hh"
using namespace flexisip;
ConferenceServer::ConferenceServer() : ServiceServer() {
}
ConferenceServer::~ConferenceServer() {
}
void ConferenceServer::_init() {
}
void ConferenceServer::_run() {
}
void ConferenceServer::_stop() {
}
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2017 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __flexisip__conference_server__
#define __flexisip__conference_server__
#include "../service-server.hh"
namespace flexisip {
class ConferenceServer : public ServiceServer {
public:
ConferenceServer();
~ConferenceServer();
void _init();
void _run();
void _stop();
};
} // namespace flexisip
#endif //__flexisip__conference_server__
......@@ -77,6 +77,10 @@
#include "presence/presence-longterm.hh"
#endif // ENABLE_PRESENCE
#ifdef ENABLE_CONFERENCE
#include "conference/conference-server.hh"
#endif // ENABLE_CONFERENCE
#include "monitor.hh"
#include <openssl/opensslconf.h>
......@@ -98,7 +102,10 @@ static su_root_t *root = NULL;
#if ENABLE_PRESENCE
static std::shared_ptr<flexisip::PresenceServer> presenceServer;
#endif
#endif // ENABLE_PRESENCE
#if ENABLE_CONFERENCE
static std::shared_ptr<flexisip::ConferenceServer> conferenceServer;
#endif // ENABLE_CONFERENCE
using namespace std;
......@@ -136,9 +143,14 @@ static void flexisip_stop(int signum) {
su_root_break(root);
}
#if ENABLE_PRESENCE
if (presenceServer){
if (presenceServer) {
presenceServer->stop();
}
#endif
#if ENABLE_CONFERENCE
if (conferenceServer) {
conferenceServer->stop();
}
#endif
} //else nop
}
......@@ -533,15 +545,13 @@ static void list_modules() {
}
}
static const char* getFunctionName(bool startProxy, bool startPresence){
if (startProxy && startPresence){
return "proxy+presence";
}else if (startProxy){
return "proxy";
}else if (startPresence){
return "presence";
}
return "none";
static const string getFunctionName(bool startProxy, bool startPresence, bool startConference){
string functions;
if(startProxy) functions = "proxy";
if(startPresence) functions += ((functions.empty()) ? "" : "+") + string("presence");
if(startConference) functions += ((functions.empty()) ? "" : "+") + string("conference");
return (functions.empty()) ? "none" : functions;
}
static void notifyWatchDog(){
......@@ -585,6 +595,9 @@ static string version() {
#if ENABLE_PRESENCE
version << "- Presence\n";
#endif
#if ENABLE_CONFERENCE
version << "- Conference\n";
#endif
return version.str();
}
......@@ -597,6 +610,9 @@ int main(int argc, char *argv[]) {
Stats *proxy_stats = NULL;
#ifdef ENABLE_PRESENCE
Stats *presence_stats = NULL;
#endif
#ifdef ENABLE_CONFERENCE
Stats *conference_stats = NULL;
#endif
bool debug;
map<string, string> oset;
......@@ -604,7 +620,7 @@ int main(int argc, char *argv[]) {
string versionString = version();
// clang-format off
TCLAP::CmdLine cmd("", ' ', versionString);
TCLAP::ValueArg<string> functionName("", "server", "Specify the server function to operate: 'proxy', 'presence', or 'all'.", TCLAP::ValueArgOptional, "", "server function", cmd);
TCLAP::ValueArg<string> functionName("", "server", "Specify the server function to operate: 'proxy', 'presence', 'conference', or 'all'.", TCLAP::ValueArgOptional, "", "server function", cmd);
TCLAP::ValueArg<string> configFile("c", "config", "Specify the location of the configuration file.", TCLAP::ValueArgOptional, CONFIG_DIR "/flexisip.conf", "file", cmd);
TCLAP::ValueArg<string> pkcsFile("", "p12-passphrase-file", "Specify the location of the pkcs12 passphrase file.", TCLAP::ValueArgOptional,"", "file", cmd);
TCLAP::SwitchArg daemonMode("", "daemon", "Launch in daemon mode.", cmd);
......@@ -741,17 +757,24 @@ int main(int argc, char *argv[]) {
bool startProxy = false;
bool startPresence = false;
bool startConference = false;
if (functionName.getValue() == "proxy"){
startProxy = true;
}else if (functionName.getValue() == "presence"){
startPresence = true;
#ifndef ENABLE_PRESENCE
LOGF("Flexisip was compiled without presence server extension.");
#endif
}else if (functionName.getValue() == "conference"){
startConference = true;
#ifndef ENABLE_CONFERENCE
LOGF("Flexisip was compiled without conference server extension.");
#endif
}else if (functionName.getValue() == "all"){
startPresence = true;
startProxy = true;
startConference = true;
}else if (functionName.getValue().empty()){
auto default_servers = cfg->getGlobal()->get<ConfigStringList>("default-servers");
if (default_servers->contains("proxy")){
......@@ -760,13 +783,16 @@ int main(int argc, char *argv[]) {
if (default_servers->contains("presence")){
startPresence = true;
}
if (!startPresence && !startProxy){
if (default_servers->contains("conference")){
startConference = true;
}
if (!startPresence && !startProxy && !startConference){
LOGF("Bad default-servers definition '%s'.", default_servers->get().c_str());
}
}else{
LOGF("There is no server function '%s'.", functionName.getValue().c_str());
}
string fName = getFunctionName(startProxy, startPresence);
string fName = getFunctionName(startProxy, startPresence, startConference);
// Initialize
std::string log_level = cfg->getGlobal()->get<ConfigString>("log-level")->read();
std::string syslog_level = cfg->getGlobal()->get<ConfigString>("syslog-level")->read();
......@@ -909,12 +935,9 @@ int main(int argc, char *argv[]) {
notifyWatchDog();
}
try{
if (startProxy){
//start as a thread
presenceServer->start();
}else{
presenceServer->run();
}
presenceServer->setWithThread(startProxy);
presenceServer->init();
presenceServer->run();
}catch(FlexisipException &e){
/* Catch the presence server exception, which is generally caused by a failure while binding the SIP listening points.
* Since it prevents from starting and it is not a crash, it shall be notified to the user with LOGF*/
......@@ -925,7 +948,25 @@ int main(int argc, char *argv[]) {
presence_stats->start();
#endif
}
if (startConference){
#ifdef ENABLE_CONFERENCE
conferenceServer = make_shared<flexisip::ConferenceServer>();
try{
conferenceServer->setWithThread(startProxy);
conferenceServer->init();
conferenceServer->run();
}catch(FlexisipException &e){
/* Catch the conference server exception, which is generally caused by a failure while binding the SIP listening points.
* Since it prevents from starting and it is not a crash, it shall be notified to the user with LOGF*/
LOGF("Fail to start flexisip conference server");
}
conference_stats = new Stats("conference");
conference_stats->start();
#endif // ENABLE_CONFERENCE
}
if (startProxy){
su_timer_t *timer = su_timer_create(su_root_task(root), 5000);
su_timer_set_for_ever(timer, (su_timer_f)timerfunc, a.get());
......@@ -941,7 +982,16 @@ int main(int argc, char *argv[]) {
delete presence_stats;
}
presenceServer.reset();
#endif
#endif // ENABLE_PRESENCE
#ifdef ENABLE_CONFERENCE
if (conference_stats) {
conference_stats->stop();
delete conference_stats;
}
//conferenceServer.reset();
#endif // ENABLE_CONFERENCE
if (stun) {
stun->stop();
delete stun;
......
......@@ -75,10 +75,8 @@ PresenceServer::Init::Init() {
s->addChildrenValues(items);
}
PresenceServer::PresenceServer() throw(FlexisipException)
: mStarted(true)
, mIterateThread(nullptr) {
PresenceServer::PresenceServer() : ServiceServer() {
auto config = GenericManager::get()->getRoot()->get<GenericStruct>("presence-server");
/*Enabling leak detector should be done asap.*/
belle_sip_object_enable_leak_detector(GenericManager::get()->getRoot()->get<GenericStruct>("presence-server")->get<ConfigBoolean>("leak-detector")->read());
......@@ -120,7 +118,7 @@ static void remove_listening_point(belle_sip_listening_point_t* lp,belle_sip_pro
belle_sip_provider_remove_listening_point(prov,lp);
}
PresenceServer::~PresenceServer() {
PresenceServer::~PresenceServer(){
belle_sip_provider_clean_channels(mProvider);
const belle_sip_list_t * lps = belle_sip_provider_get_listening_points(mProvider);
belle_sip_list_t * tmp_list = belle_sip_list_copy(lps);
......@@ -142,20 +140,20 @@ PresenceServer::~PresenceServer() {
SLOGD << "Presence server destroyed";
}
void PresenceServer::_start(bool withThread) throw(FlexisipException) {
void PresenceServer::_init() {
if (!mEnabled) return;
GenericStruct *cr = GenericManager::get()->getRoot();
std::string get_users_with_phones_request = cr->get<GenericStruct>("module::Authentication")
->get<ConfigString>("soci-users-with-phones-request")
->read();
->get<ConfigString>("soci-users-with-phones-request")
->read();
if(get_users_with_phones_request == "") {
LOGF("Unable to start presence server : soci-users-with-phones-request is not precised in flexisip.conf, please fix it.");
}
list<string> transports = cr->get<GenericStruct>("presence-server")
->get<ConfigStringList>("transports")
->read();
->get<ConfigStringList>("transports")
->read();
for (auto it = transports.begin(); it != transports.end(); ++it) {
string transport = *it;
if(transport.find("sips") != string::npos || transport.find("transport=tls") != string::npos) {
......@@ -171,33 +169,14 @@ void PresenceServer::_start(bool withThread) throw(FlexisipException) {
throw FLEXISIP_EXCEPTION << "Cannot add lp for [" << *it << "]";
}
}
if (withThread){
mIterateThread.reset (new thread([this]() {
while (mStarted)
belle_sip_main_loop_run(belle_sip_stack_get_main_loop(this->mStack)); // is not interrupted by add source
}));
}
}
void PresenceServer::start() throw(FlexisipException) {
_start(true);
void PresenceServer::_run() {
belle_sip_main_loop_run(belle_sip_stack_get_main_loop(mStack));
}
void PresenceServer::run() throw(FlexisipException){
_start(false);
while (mStarted){
belle_sip_main_loop_run(belle_sip_stack_get_main_loop(mStack));
}
}
void PresenceServer::stop() {
mStarted = false;
void PresenceServer::_stop() {
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(mStack));
if (mIterateThread) {
pthread_kill(mIterateThread->native_handle(), SIGINT);//because main loop is not interruptible
mIterateThread->join();
mIterateThread.reset();
}
}
......
......@@ -20,7 +20,6 @@
#define __flexisip__presence_server__
#include <iostream>
#include <thread>
#include <map>
#include <unordered_map>
#include <vector>
......@@ -30,6 +29,7 @@
//#include "presence-configmanager.hh"
//#include "presentity-presenceinformation.hh"
#include "presentity-manager.hh"
#include "../service-server.hh"
#include "belle-sip/sip-uri.h"
typedef struct belle_sip_main_loop belle_sip_main_loop_t;
......@@ -67,15 +67,13 @@ public:
virtual void onListenerEvents(std::list<std::shared_ptr<PresentityPresenceInformation>>& infos) const = 0;
};
class PresenceServer : public PresentityManager {
class PresenceServer : public PresentityManager, public ServiceServer {
public:
PresenceServer() throw (FlexisipException);
PresenceServer();
~PresenceServer();
//Starts presence server as a thread
void start() throw (FlexisipException);
//Directly run the presence server (in current thread).
void run() throw (FlexisipException);
void stop();
void _init();
void _run();
void _stop();
belle_sip_main_loop_t* getBelleSipMainLoop();
void addPresenceInfoObserver(const std::shared_ptr<PresenceInfoObserver> &observer);
void removePresenceInfoObserver(const std::shared_ptr<PresenceInfoObserver> &observer);
......@@ -85,15 +83,13 @@ private:
Init();
};
static Init sStaticInit;
bool mStarted;
bool mEnabled;
//PresenceConfigManager mConfigManager;
belle_sip_stack_t *mStack;
belle_sip_provider_t *mProvider;
belle_sip_listener_t *mListener;
std::unique_ptr<std::thread> mIterateThread;
int mDefaultExpires;
std::string mBypass;
bool mEnabled;
// belle sip cbs
static void processDialogTerminated(PresenceServer * thiz, const belle_sip_dialog_terminated_event_t *event);
......@@ -102,7 +98,6 @@ private:
static void processResponseEvent(PresenceServer * thiz, const belle_sip_response_event_t *event);
static void processTimeout(PresenceServer * thiz, const belle_sip_timeout_event_t *event) ;
static void processTransactionTerminated(PresenceServer * thiz, const belle_sip_transaction_terminated_event_t *event);
void _start(bool withThread) throw (FlexisipException);
void processPublishRequestEvent(const belle_sip_request_event_t *event) throw (BelleSipSignalingException,FlexisipException);
void processSubscribeRequestEvent(const belle_sip_request_event_t *event) throw (BelleSipSignalingException,FlexisipException);
......
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2017 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __flexisip__service_server__
#define __flexisip__service_server__
#include <iostream>
#include <functional>
#include <thread>
#include <csignal>
namespace flexisip {
class ServiceServer {
public:
ServiceServer() : ServiceServer(false) {};
ServiceServer(bool withThread) :
mStarted(true),
mWithThread(withThread),
mIterateThread(nullptr)
{};
virtual ~ServiceServer() {};
void init() {
this->_init();
};
//Run service server
void run() {
if (mWithThread) {
mIterateThread.reset (new std::thread([this]() {
this->__run();
}));
} else {
this->__run();
}
};
void stop() {
mStarted = false;
this->_stop();
if (mIterateThread) {
pthread_kill(mIterateThread->native_handle(), SIGINT);//because main loop is not interruptible
mIterateThread->join();
mIterateThread.reset();
}
};
void setWithThread(bool withThread) { this->mWithThread = withThread;};
virtual void _init() = 0;
virtual void _run() = 0;
virtual void _stop() = 0;
protected:
bool mStarted;
bool mWithThread;
std::unique_ptr<std::thread> mIterateThread;
private:
void __run() {
while (mStarted)
this->_run();
}
};
} //namespace flexisip
#endif //__flexisip__service_server__
cmake-builder @ 0433ac7b
Subproject commit 22dc65169c4083248cd3f6ac849c059767ae6f17
Subproject commit 0433ac7b7a0681a08bda65133584eeda6137f1b5
linphone @ 18952e8e
Subproject commit 18952e8eb77d51a5a582b2b3a0ba5fa3adf5f7ce
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment