Commit 8a28ba7e authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Feature/plugin replace module

parent e7bfe1c0
Pipeline #2054 passed with stages
in 37 minutes and 53 seconds
......@@ -65,7 +65,6 @@ src/flexisip_binder
src/flexisip_ctdumper
src/flexisip_pusher
src/flexisip_serializer
flexisip
flexisip-config.h.in
OUTPUT/
test/massregister/users.csv
......
......@@ -232,6 +232,7 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}/src/
${ORTP_INCLUDE_DIRS}
${SOFIASIPUA_INCLUDE_DIRS}
include/
src/
src/plugin
)
......@@ -244,6 +245,7 @@ add_definitions("-DHAVE_CONFIG_H")
bc_init_compilation_flags(CPP_BUILD_FLAGS C_BUILD_FLAGS CXX_BUILD_FLAGS ENABLE_STRICT)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(scripts)
add_subdirectory(share)
......
......@@ -219,6 +219,8 @@ fi
%{_bindir}/*
%{_libdir}/*.so
%{_datarootdir}/*
%dir %{_includedir}/flexisip
%{_includedir}/flexisip/*.hh
%if @ENABLE_PRESENCE@
%{_sysconfdir}/init.d/flexisip-presence
......@@ -256,6 +258,9 @@ fi
%changelog
* Wed Jan 16 2019 Sylvain Berfini <sylvain.berfini@belledonne-communications.com>
- Added include directory with flexisip header files
* Tue Nov 27 2018 ronan.abhamon <ronan.abhamon@belledonne-communications.com>
- Do not set CMAKE_INSTALL_LIBDIR and never with _libdir!
......
############################################################################
# CMakeLists.txt
# Copyright (C) 2019 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
set(HEADER_FILES
agent.hh
common.hh
configmanager.hh
event.hh
eventlogs.hh
forkbasiccontext.hh
forkcallcontext.hh
forkmessagecontext.hh
global.hh
logmanager.hh
module-auth.hh
module-registrar.hh
module-router.hh
module.hh
plugin.hh
registrardb.hh
transaction.hh
)
set(FLEXISIP_HEADER_FILES )
foreach(HEADER_FILE ${HEADER_FILES})
list(APPEND FLEXISIP_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/flexisip/${HEADER_FILE}")
endforeach()
set(FLEXISIP_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/flexisip" PARENT_SCOPE)
set(FLEXISIP_HEADER_FILES ${FLEXISIP_HEADER_FILES} PARENT_SCOPE)
install(FILES ${FLEXISIP_HEADER_FILES}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/flexisip
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
......@@ -16,17 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef agent_hh
#define agent_hh
#pragma once
#if defined(HAVE_CONFIG_H) && !defined(FLEXISIP_INCLUDED)
#include "flexisip-config.h"
#define FLEXISIP_INCLUDED
#endif
#include <string>
#include <sstream>
#include <memory>
#include "common.hh"
#include "configmanager.hh"
#include "event.hh"
#include "transaction.hh"
#include "eventlogs.hh"
#include <sofia-sip/sip.h>
#include <sofia-sip/sip_protos.h>
......@@ -37,16 +38,17 @@
#include <sofia-sip/nta_stateless.h>
#include <sofia-sip/nth.h>
#include "common.hh"
#include "configmanager.hh"
#include "event.hh"
#include "transaction.hh"
#include "eventlogs/eventlogs.hh"
#include <string>
#include <sstream>
#include <memory>
#include <ifaddrs.h>
#if ENABLE_MDNS
#include "belle-sip/belle-sip.h"
#endif
namespace flexisip {
class Module;
class DomainRegistrationManager;
......@@ -247,4 +249,4 @@ private:
#endif
};
#endif
}
\ No newline at end of file
......@@ -17,8 +17,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROXY_COMMON_H
#define PROXY_COMMON_H
#pragma once
#include "logmanager.hh"
#include <cstdlib>
#include <cstdarg>
......@@ -27,12 +28,15 @@
#include <vector>
#include <sys/timeb.h>
#include "log/logmanager.hh"
#ifndef MAX
#define MAX(a, b) (a) > (b) ? (a) : (b)
#endif
time_t getCurrentTime();
time_t getTimeOffset(time_t current_time);
namespace flexisip {
class Mutex {
public:
Mutex(bool reentrant = false);
......@@ -64,9 +68,6 @@ template <typename _first, typename _last> class map_delete_functor {
#define RESTART_EXIT_CODE 5
time_t getCurrentTime();
time_t getTimeOffset(time_t current_time);
// Helper to get ip from host in a portable binary format.
class BinaryIp {
public:
......@@ -88,4 +89,4 @@ inline std::vector<std::string> split (const std::string &str, char delimiter) {
return split(str, std::string(1, delimiter));
}
#endif
}
\ No newline at end of file
......@@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef configmanager_hh
#define configmanager_hh
#pragma once
#if defined(HAVE_CONFIG_H) && !defined(FLEXISIP_INCLUDED)
......@@ -31,6 +30,8 @@
#endif
#include "common.hh"
#include <string>
#include <sstream>
#include <iostream>
......@@ -45,8 +46,6 @@
#include <cxxabi.h>
#include <memory>
#include "common.hh"
#ifdef ENABLE_SNMP
#include <net-snmp/net-snmp-config.h>
......@@ -61,14 +60,15 @@ typedef unsigned long oid;
#endif /* ENABLE_SNMP */
extern oid company_id;
namespace flexisip {
struct LpConfig;
};
#include "expressionparser.hh"
#include "global.hh"
#include "utils/flexisip-exception.hh"
namespace flexisip {
struct LpConfig;
enum class ConfigState { Check, Changed, Reset, Commited };
class ConfigValue;
......@@ -687,4 +687,4 @@ class GenericManager : protected ConfigValueListener {
NotificationEntry *mNotifier;
};
#endif
}
\ No newline at end of file
......@@ -15,21 +15,23 @@
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 event_hh
#define event_hh
#include <memory>
#include <list>
#include <string>
#include <ostream>
#include <functional>
#pragma once
#include <sofia-sip/tport.h>
#include <sofia-sip/msg.h>
#include <sofia-sip/sip.h>
#include <sofia-sip/nta.h>
#include <memory>
#include <list>
#include <string>
#include <ostream>
#include <functional>
#include <regex.h>
namespace flexisip {
class Agent;
class Module;
class IncomingAgent;
......@@ -258,4 +260,4 @@ private:
su_home_t mHome;
};
#endif // event_hh
}
\ No newline at end of file
......@@ -16,18 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef eventlogs_hh
#define eventlogs_hh
#pragma once
#include "common.hh"
#include <sofia-sip/sip.h>
#include <sofia-sip/sip_protos.h>
#include "../common.hh"
#include <string>
#include <memory>
#include <queue>
#include <mutex>
namespace flexisip {
class EventLog {
friend class FilesystemEventLogWriter;
friend class DataBaseEventLogWriter;
......@@ -179,6 +181,8 @@ private:
bool mIsReady;
};
}
#if ENABLE_SOCI
#ifdef __GNUG__
......@@ -192,6 +196,8 @@ private:
#include "utils/threadpool.hh"
namespace flexisip {
class DataBaseEventLogWriter: public EventLogWriter {
public:
enum class Backend {
......@@ -234,6 +240,6 @@ private:
std::string mInsertReq[5];
};
#endif
}
#endif
#endif
\ No newline at end of file
......@@ -16,16 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef forkbasiccontext_hh
#define forkbasiccontext_hh
#pragma once
#include "agent.hh"
#include "event.hh"
#include "transaction.hh"
#include "forkcontext.hh"
#include <list>
#include <map>
namespace flexisip {
class ForkBasicContext : public ForkContext {
private:
su_timer_t
......@@ -46,4 +48,4 @@ class ForkBasicContext : public ForkContext {
void onDecisionTimer();
};
#endif /* forkbasiccontext_hh */
}
\ No newline at end of file
......@@ -16,15 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef forkcallcontext_hh
#define forkcallcontext_hh
#pragma once
#include "agent.hh"
#include "event.hh"
#include "transaction.hh"
#include "forkcontext.hh"
#include <list>
namespace flexisip {
enum FlexisipForkStatus {FlexisipForkAcceptedElsewhere, FlexisipForkDeclineElsewhere, FlexisipForkStandard};
class ForkCallContext : public ForkContext {
......@@ -63,4 +65,4 @@ class ForkCallContext : public ForkContext {
static const int sUrgentCodesWithout603[];
};
#endif // forkcallcontext_hh
}
\ No newline at end of file
......@@ -16,14 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef forkcontext_hh
#define forkcontext_hh
#pragma once
#include "agent.hh"
#include "event.hh"
#include "transaction.hh"
#include "registrardb.hh"
namespace flexisip {
class OnContactRegisteredListener;
class ForkContextConfig {
......@@ -168,4 +169,4 @@ class ForkContext : public std::enable_shared_from_this<ForkContext> {
static const int sAllCodesUrgent[];
};
#endif /* forkcontext_hh */
}
\ No newline at end of file
......@@ -16,16 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef forkmessagecontext_hh
#define forkmessagecontext_hh
#pragma once
#include "agent.hh"
#include "event.hh"
#include "transaction.hh"
#include "forkcontext.hh"
#include <list>
#include <map>
namespace flexisip {
class ForkMessageContext : public ForkContext {
private:
su_timer_t
......@@ -55,4 +57,4 @@ class ForkMessageContext : public ForkContext {
void logDeliveredToUserEvent(const std::shared_ptr<BranchInfo> &br, const std::shared_ptr<ResponseSipEvent> &event);
};
#endif /* forkmessagecontext_hh */
}
\ No newline at end of file
......@@ -16,13 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef global_hh
#define global_hh
#pragma once
// =============================================================================
#define FLEXISIP_DISABLE_COPY(CLASS) \
CLASS(const CLASS &) = delete; \
CLASS &operator=(const CLASS &) = delete
#endif // ifndef global_hh
......@@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOGMANAGER_HH
#define LOGMANAGER_HH
#pragma once
#include <string>
#include <iostream>
......@@ -164,6 +163,4 @@ do {
void disableGlobally();
} // end log
} // end flexisip
#endif // LOGMANAGER_HH
} // end flexisip
\ No newline at end of file
......@@ -21,6 +21,8 @@
#include "auth/flexisip-auth-module.hh"
#include "module.hh"
namespace flexisip {
class Authentication : public Module {
public:
StatCounter64 *mCountAsyncRetrieve = nullptr;
......@@ -38,7 +40,7 @@ public:
bool handleTestAccountCreationRequests(std::shared_ptr<RequestSipEvent> &ev);
bool isTrustedPeer(std::shared_ptr<RequestSipEvent> &ev);
bool tlsClientCertificatePostCheck(const std::shared_ptr<RequestSipEvent> &ev);
bool handleTlsClientAuthentication(std::shared_ptr<RequestSipEvent> &ev);
virtual bool handleTlsClientAuthentication(std::shared_ptr<RequestSipEvent> &ev);
void onRequest(std::shared_ptr<RequestSipEvent> &ev) override;
void onResponse(std::shared_ptr<ResponseSipEvent> &ev) override;
void onIdle() override;
......@@ -78,3 +80,5 @@ private:
bool mRejectWrongClientCertificates = false;
bool mTrustDomainCertificates = false;
};
}
\ No newline at end of file
......@@ -16,16 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODULE_REGISTRAR_HH_
#define MODULE_REGISTRAR_HH_
#pragma once
#include "module.hh"
#include "agent.hh"
#include "registrardb.hh"
#include <sofia-sip/sip_status.h>
#include <sofia-sip/su_random.h>
#include <signal.h>
#include "module.hh"
#include "agent.hh"
#include "registrardb.hh"
namespace flexisip {
struct RegistrarStats {
std::unique_ptr<StatPair> mCountBind;
......@@ -179,4 +181,5 @@ class RegistrarMgt {
virtual unsigned long long int getTotalNumberOfAddedRecords() = 0;
virtual unsigned long long int getTotalNumberOfExpiredRecords() = 0;
};
#endif /* MODULE_REGISTRAR_HH_ */
}
\ No newline at end of file
......@@ -25,6 +25,8 @@
#include "forkmessagecontext.hh"
#include "forkbasiccontext.hh"
namespace flexisip {
struct RouterStats {
std::unique_ptr<StatPair> mCountForks;
std::unique_ptr<StatPair> mCountForkTransactions;
......@@ -80,7 +82,10 @@ class ModuleRouter : public Module, public ModuleToolbox, public ForkContextList
std::list<std::shared_ptr<ExtendedContact>> &ec_list);
virtual bool dispatch(const std::shared_ptr<RequestSipEvent> &ev, const std::shared_ptr<ExtendedContact> &contact,
std::shared_ptr<ForkContext> context, const std::string &targetUris);
virtual bool lateDispatch(const std::shared_ptr<RequestSipEvent> &ev, const std::shared_ptr<ExtendedContact> &contact,
std::shared_ptr<ForkContext> context, const std::string &targetUris);
std::string routingKey(const url_t *sipUri);
std::vector<std::string> split(const char *data, const char *delim);
std::list<std::string> mDomains;
bool mFork = false;
......@@ -104,4 +109,52 @@ class ModuleRouter : public Module, public ModuleToolbox, public ForkContextList
private:
static ModuleInfo<ModuleRouter> sInfo;
};
\ No newline at end of file
};
class OnContactRegisteredListener : public ContactRegisteredListener, public ContactUpdateListener, public std::enable_shared_from_this<OnContactRegisteredListener> {
friend class ModuleRouter;
ModuleRouter *mModule;
url_t *mSipUri;
std::string mUid;
su_home_t mHome;
public:
OnContactRegisteredListener(ModuleRouter *module, const url_t *sipUri)
: mModule(module), mUid("") {
su_home_init(&mHome);
mSipUri = url_hdup(&mHome, sipUri);
if (url_has_param(mSipUri, "gr")) {
LOGD("Trying to create a ContactRegistered listener using a SIP URI with a gruu, removing let's remove it");
mSipUri->url_params = url_strip_param_string((char*)mSipUri->url_params, "gr");
}
LOGD("Listener created for sipUri = %s", url_as_string(&mHome, mSipUri));
}
~OnContactRegisteredListener() {
su_home_deinit(&mHome);
}
void onContactRegistered(Record *r, const std::string &uid) {
LOGD("Listener found for topic = %s, uid = %s, sipUri = %s", r->getKey().c_str(), uid.c_str(), url_as_string(&mHome, mSipUri));
mUid = uid;
onRecordFound(r);
}
void onRecordFound(Record *r) {
if (r) {
LOGD("Record found for uid = %s", mUid.c_str());
mModule->onContactRegistered(mUid, r, mSipUri);
} else {
LOGW("No record found for uid = %s", mUid.c_str());
}
}
void onError() {
}
void onInvalid() {
}
void onContactUpdated(const std::shared_ptr<ExtendedContact> &ec) {
}
};
}
\ No newline at end of file
......@@ -16,16 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef module_hh
#define module_hh
#include "sofia-sip/nta_tport.h"
#include "sofia-sip/tport.h"
#include "sofia-sip/msg_header.h"
#pragma once
#include "configmanager.hh"
#include "event.hh"
#include <sofia-sip/nta_tport.h>
#include <sofia-sip/tport.h>
#include <sofia-sip/msg_header.h>
namespace flexisip {
// =============================================================================
// -----------------------------------------------------------------------------
......@@ -67,6 +68,7 @@ public:
Agent *getAgent() const;
nta_agent_t *getSofiaAgent() const;
const std::string &getModuleName() const;
const std::string &getModuleConfigName() const;
void declare(GenericStruct *root);
void checkConfig();
void load();
......@@ -86,6 +88,7 @@ public:
inline void process(std::shared_ptr<ResponseSipEvent> &ev) {
processResponse(ev);
}
void setInfo(ModuleInfoBase *moduleInfo);
protected:
virtual void onDeclare(GenericStruct *root) {}
......@@ -117,8 +120,6 @@ protected:
Agent *mAgent;
private:
void setInfo(ModuleInfoBase *moduleInfo);
ModuleInfoBase *mInfo;
GenericStruct *mModuleConfig;
EntryFilter *mFilter;
......@@ -205,11 +206,15 @@ public:
return mClass;
}
const std::string &getReplace() const {
return mReplace;
}
protected:
ModuleInfoBase(
const std::string &moduleName, const std::string &help, const std::vector<std::string> &after,
ModuleOid oid, ModuleClass moduleClass
) : mName(moduleName), mHelp(help), mAfter(after), mOidIndex(oid), mClass(moduleClass) {
ModuleOid oid, ModuleClass moduleClass, const std::string &replace
) : mName(moduleName), mHelp(help), mAfter(after), mOidIndex(oid), mClass(moduleClass), mReplace(replace) {
ModuleInfoManager::get()->registerModuleInfo(this);
}
......@@ -221,6 +226,7 @@ private:
const std::vector<std::string> mAfter;
const oid mOidIndex;
ModuleClass mClass;
const std::string mReplace;
};
template<typename T>
......@@ -230,8 +236,8 @@ public:
ModuleInfo(
const std::string &moduleName, const std::string &help, const std::vector<std::string> &after,
ModuleOid oid, ModuleClass moduleClass = ModuleClass::Production
) : ModuleInfoBase(moduleName, help, after, oid, moduleClass) {}
ModuleOid oid, ModuleClass moduleClass = ModuleClass::Production, const std::string &replace = ""
) : ModuleInfoBase(moduleName, help, after, oid, moduleClass, replace) {}
private:
Module *create(Agent *agent) override {
......@@ -311,4 +317,4 @@ public:
static sip_via_t *getLastVia(sip_t *sip);
};