From bf5715d5fcd791e0f1a04d91a3ef024b9f0f7d1a Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 17 Aug 2017 10:08:08 +0200 Subject: [PATCH 01/49] add findSoci.cmake --- cmake/FindSoci.cmake | 98 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 cmake/FindSoci.cmake diff --git a/cmake/FindSoci.cmake b/cmake/FindSoci.cmake new file mode 100644 index 000000000..b723b44af --- /dev/null +++ b/cmake/FindSoci.cmake @@ -0,0 +1,98 @@ +############################################################################### +# CMake module to search for SOCI library +# +# WARNING: This module is experimental work in progress. +# +# This module defines: +# SOCI_INCLUDE_DIRS = include dirs to be used when using the soci library +# SOCI_LIBRARY = full path to the soci library +# SOCI_VERSION = the soci version found (not yet. soci does not provide that info.) +# SOCI_FOUND = true if soci was found +# +# This module respects: +# LIB_SUFFIX = (64|32|"") Specifies the suffix for the lib directory +# +# For each component you specify in find_package(), the following variables are set. +# +# SOCI_${COMPONENT}_PLUGIN = full path to the soci plugin +# SOCI_${COMPONENT}_FOUND +# +# Copyright (c) 2011 Michael Jansen +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +############################################################################### +# +### Global Configuration Section +# +SET(_SOCI_ALL_PLUGINS mysql odbc postgresql sqlite3) +SET(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIR SOCI_LIBRARY) + +# +### FIRST STEP: Find the soci headers. +# +FIND_PATH( + SOCI_INCLUDE_DIR soci.h + PATH "/usr/local" + PATH_SUFFIXES "" "soci" + DOC "Soci (http://soci.sourceforge.net) include directory") +MARK_AS_ADVANCED(SOCI_INCLUDE_DIR) + +SET(SOCI_INCLUDE_DIRS ${SOCI_INCLUDE_DIR}) + +# +### SECOND STEP: Find the soci core library. Respect LIB_SUFFIX +# +FIND_LIBRARY( + SOCI_LIBRARY + NAMES soci_core + HINTS ${SOCI_INCLUDE_DIR}/.. + PATH_SUFFIXES lib${LIB_SUFFIX}) +MARK_AS_ADVANCED(SOCI_LIBRARY) + +GET_FILENAME_COMPONENT(SOCI_LIBRARY_DIR ${SOCI_LIBRARY} PATH) +MARK_AS_ADVANCED(SOCI_LIBRARY_DIR) + +# +### THIRD STEP: Find all installed plugins if the library was found +# +IF(SOCI_INCLUDE_DIR AND SOCI_LIBRARY) + + MESSAGE(STATUS "Soci found: Looking for plugins") + FOREACH(plugin IN LISTS _SOCI_ALL_PLUGINS) + + FIND_LIBRARY( + SOCI_${plugin}_PLUGIN + NAMES soci_${plugin} + HINTS ${SOCI_INCLUDE_DIR}/.. + PATH_SUFFIXES lib${LIB_SUFFIX}) + MARK_AS_ADVANCED(SOCI_${plugin}_PLUGIN) + + IF(SOCI_${plugin}_PLUGIN) + MESSAGE(STATUS " * Plugin ${plugin} found ${SOCI_${plugin}_PLUGIN}.") + SET(SOCI_${plugin}_FOUND True) + ELSE() + MESSAGE(STATUS " * Plugin ${plugin} not found.") + SET(SOCI_${plugin}_FOUND False) + ENDIF() + + ENDFOREACH() + + # + ### FOURTH CHECK: Check if the required components were all found + # + FOREACH(component ${Soci_FIND_COMPONENTS}) + IF(NOT SOCI_${component}_FOUND) + MESSAGE(SEND_ERROR "Required component ${component} not found. It seems that Soci was built without support of ${component}, consider rebuilding it.") + ENDIF() + ENDFOREACH() + +ENDIF() + +# +### ADHERE TO STANDARDS +# +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Soci DEFAULT_MSG ${_SOCI_REQUIRED_VARS}) + From e8534f0c60fb2e17a4936ecf064cf94368e187bf Mon Sep 17 00:00:00 2001 From: nicolas Date: Thu, 17 Aug 2017 10:48:48 +0200 Subject: [PATCH 02/49] enhance findSoci.cmake + respect cmake variables naming convention --- cmake/FindSoci.cmake | 34 ++++++++++++---------------------- coreapi/CMakeLists.txt | 2 +- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/cmake/FindSoci.cmake b/cmake/FindSoci.cmake index b723b44af..35846f5d0 100644 --- a/cmake/FindSoci.cmake +++ b/cmake/FindSoci.cmake @@ -5,13 +5,10 @@ # # This module defines: # SOCI_INCLUDE_DIRS = include dirs to be used when using the soci library -# SOCI_LIBRARY = full path to the soci library +# SOCI_LIBRARIES = full path to the soci library # SOCI_VERSION = the soci version found (not yet. soci does not provide that info.) # SOCI_FOUND = true if soci was found # -# This module respects: -# LIB_SUFFIX = (64|32|"") Specifies the suffix for the lib directory -# # For each component you specify in find_package(), the following variables are set. # # SOCI_${COMPONENT}_PLUGIN = full path to the soci plugin @@ -26,38 +23,32 @@ # ### Global Configuration Section # -SET(_SOCI_ALL_PLUGINS mysql odbc postgresql sqlite3) -SET(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIR SOCI_LIBRARY) +SET(_SOCI_ALL_PLUGINS mysql sqlite3) +SET(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIRS SOCI_LIBRARIES) # ### FIRST STEP: Find the soci headers. # -FIND_PATH( - SOCI_INCLUDE_DIR soci.h - PATH "/usr/local" - PATH_SUFFIXES "" "soci" +FIND_PATH(SOCI_INCLUDE_DIRS soci.h + PATH_SUFFIXES "soci" DOC "Soci (http://soci.sourceforge.net) include directory") -MARK_AS_ADVANCED(SOCI_INCLUDE_DIR) - -SET(SOCI_INCLUDE_DIRS ${SOCI_INCLUDE_DIR}) +MARK_AS_ADVANCED(SOCI_INCLUDE_DIRS) # ### SECOND STEP: Find the soci core library. Respect LIB_SUFFIX # -FIND_LIBRARY( - SOCI_LIBRARY +FIND_LIBRARY(SOCI_LIBRARIES NAMES soci_core - HINTS ${SOCI_INCLUDE_DIR}/.. - PATH_SUFFIXES lib${LIB_SUFFIX}) -MARK_AS_ADVANCED(SOCI_LIBRARY) + PATH_SUFFIXES lib lib64) +MARK_AS_ADVANCED(SOCI_LIBRARIES) -GET_FILENAME_COMPONENT(SOCI_LIBRARY_DIR ${SOCI_LIBRARY} PATH) +GET_FILENAME_COMPONENT(SOCI_LIBRARY_DIR ${SOCI_LIBRARIES} PATH) MARK_AS_ADVANCED(SOCI_LIBRARY_DIR) # ### THIRD STEP: Find all installed plugins if the library was found # -IF(SOCI_INCLUDE_DIR AND SOCI_LIBRARY) +IF(SOCI_INCLUDE_DIRS AND SOCI_LIBRARIES) MESSAGE(STATUS "Soci found: Looking for plugins") FOREACH(plugin IN LISTS _SOCI_ALL_PLUGINS) @@ -65,8 +56,7 @@ IF(SOCI_INCLUDE_DIR AND SOCI_LIBRARY) FIND_LIBRARY( SOCI_${plugin}_PLUGIN NAMES soci_${plugin} - HINTS ${SOCI_INCLUDE_DIR}/.. - PATH_SUFFIXES lib${LIB_SUFFIX}) + PATH_SUFFIXES lib lib64) MARK_AS_ADVANCED(SOCI_${plugin}_PLUGIN) IF(SOCI_${plugin}_PLUGIN) diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index c2d02a538..70f361c00 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -158,7 +158,7 @@ set(LIBS ${ORTP_LIBRARIES} ${XML2_LIBRARIES} ${BELR_LIBRARIES} - ${SOCI_LIBRARY} + ${SOCI_LIBRARIES} ) if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") list(APPEND LIBS "Ws2_32") From f36c4a221b38ba514b0e8b26795633c3b3dc8a67 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 17 Aug 2017 11:48:58 +0200 Subject: [PATCH 03/49] Soci dependency optional --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 681df3806..b53a54f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,7 @@ else() find_package(Belr REQUIRED) endif() find_package(XML2 REQUIRED) -find_package(Soci REQUIRED) +find_package(Soci OPTIONAL) find_package(Zlib) if(ENABLE_TUNNEL) if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) From af8cbd6957b7cbc188c2286caea553af894009fa Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 17 Aug 2017 11:51:17 +0200 Subject: [PATCH 04/49] fix previsous commit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b53a54f7f..1eec8481e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,7 @@ else() find_package(Belr REQUIRED) endif() find_package(XML2 REQUIRED) -find_package(Soci OPTIONAL) +find_package(Soci) find_package(Zlib) if(ENABLE_TUNNEL) if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) From 12ad35401c228f65035afe297c6847d13a2e4fbf Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 17 Aug 2017 11:57:40 +0200 Subject: [PATCH 05/49] link to soci libs only if found --- coreapi/CMakeLists.txt | 4 +++- src/CMakeLists.txt | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 70f361c00..3eddeb895 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -158,7 +158,6 @@ set(LIBS ${ORTP_LIBRARIES} ${XML2_LIBRARIES} ${BELR_LIBRARIES} - ${SOCI_LIBRARIES} ) if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") list(APPEND LIBS "Ws2_32") @@ -169,6 +168,9 @@ endif() if(ZLIB_FOUND) list(APPEND LIBS ${ZLIB_LIBRARIES}) endif() +if(SOCI_FOUND) + list(APPEND LIBS ${SOCI_LIBRARIES}) +endif() if(SQLITE3_FOUND) list(APPEND LIBS ${SQLITE3_LIBRARIES}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c3ec397f..6615525fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,7 +53,11 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES ) set(LINPHONE_CXX_OBJECTS_DEFINITIONS "-DLIBLINPHONE_EXPORTS") -set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_MYSQL_INCLUDES}) +set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS}) + +if(SOCI_FOUND) + list(APPEND LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${SOCI_INCLUDE_DIRS} ${SOCI_MYSQL_INCLUDES}) +endif() set(LINPHONE_PRIVATE_HEADER_FILES) foreach(header ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES}) From 82b3ab304f2b36dd779dd2a532ae13dd3d026e8f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Aug 2017 13:46:27 +0200 Subject: [PATCH 06/49] feat(Event): init --- CMakeLists.txt | 28 ++++----- src/CMakeLists.txt | 15 ++++- src/db/abstract/abstract-db-p.h | 46 +++++++++++++++ src/db/abstract/abstract-db.cpp | 90 ++++++++++++++++++++++++++++ src/db/abstract/abstract-db.h | 62 ++++++++++++++++++++ src/db/events-db.cpp | 100 ++++++++++++++++++++++++++++++++ src/db/events-db.h | 47 +++++++++++++++ src/event/call-event.cpp | 23 ++++++++ src/event/call-event.h | 42 ++++++++++++++ src/event/event-p.h | 38 ++++++++++++ src/event/event.cpp | 40 +++++++++++++ src/event/event.h | 54 +++++++++++++++++ src/event/message-event.cpp | 23 ++++++++ src/event/message-event.h | 57 ++++++++++++++++++ src/object/clonable-object.cpp | 8 +-- src/object/clonable-object.h | 4 ++ src/utils/general.h | 16 +++-- src/utils/linphone.h | 46 +++++++++++++++ src/utils/utils.h | 12 ++-- 19 files changed, 721 insertions(+), 30 deletions(-) create mode 100644 src/db/abstract/abstract-db-p.h create mode 100644 src/db/abstract/abstract-db.cpp create mode 100644 src/db/abstract/abstract-db.h create mode 100644 src/db/events-db.cpp create mode 100644 src/db/events-db.h create mode 100644 src/event/call-event.cpp create mode 100644 src/event/call-event.h create mode 100644 src/event/event-p.h create mode 100644 src/event/event.cpp create mode 100644 src/event/event.h create mode 100644 src/event/message-event.cpp create mode 100644 src/event/message-event.h create mode 100644 src/utils/linphone.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eec8481e..1283185a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,35 +38,37 @@ include(CMakeDependentOption) option(ENABLE_SHARED "Build shared library." YES) option(ENABLE_STATIC "Build static library." YES) + option(ENABLE_CONSOLE_UI "Turn on or off compilation of console interface." YES) -option(ENABLE_DATE "Use build date in internal version number." NO) +option(ENABLE_CSHARP_WRAPPER "Build the C# wrapper for Liblinphone." OFF) +option(ENABLE_CXX_WRAPPER "Build the C++ wrapper for Liblinphone." YES) option(ENABLE_DAEMON "Enable the linphone daemon interface." YES) +option(ENABLE_DATE "Use build date in internal version number." NO) +option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO) option(ENABLE_DOC "Enable documentation generation with Doxygen." YES) -option(ENABLE_JAVADOC "Add a target to generate documentation for Java API" NO) option(ENABLE_GTK_UI "Turn on or off compilation of gtk interface." NO) +option(ENABLE_JAVADOC "Add a target to generate documentation for Java API" NO) option(ENABLE_LDAP "Enable LDAP support." NO) -option(ENABLE_SQLITE_STORAGE "Turn on compilation sqlite storage, for messages, contacts, history" YES) -cmake_dependent_option(ENABLE_LIME "Enable Instant Messaging Encryption." YES "ENABLE_SQLITE_STORAGE" NO) -cmake_dependent_option(ENABLE_NOTIFY "Enable libnotify support." YES "ENABLE_GTK_UI;NOT APPLE" NO) +option(ENABLE_NLS "Build with internationalisation support" YES) option(ENABLE_RELATIVE_PREFIX "Find resources relatively to the installation directory." NO) +option(ENABLE_ROOTCA_DOWNLOAD "Download rootca.pem at build time." YES) +option(ENABLE_SOCI_STORAGE "Turn on compilation soci storage, for messages, contacts, history" YES) +option(ENABLE_SQLITE_STORAGE "Turn on compilation sqlite storage, for messages, contacts, history" YES) option(ENABLE_STRICT "Build with strict compile options." YES) option(ENABLE_TOOLS "Turn on or off compilation of tools." YES) option(ENABLE_TUNNEL "Turn on compilation of tunnel support." NO) option(ENABLE_TUTORIALS "Enable compilation of tutorials." YES) option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES) option(ENABLE_UPDATE_CHECK "Enable update check." NO) -option(ENABLE_VIDEO "Build with video support." YES) -cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENABLE_GTK_UI" NO) -option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO) -option(ENABLE_NLS "Build with internationalisation support" YES) option(ENABLE_VCARD "Turn on compilation of vcard4 support." YES) -option(ENABLE_ROOTCA_DOWNLOAD "Download rootca.pem at build time." YES) -option(ENABLE_CXX_WRAPPER "Build the C++ wrapper for Liblinphone." YES) -option(ENABLE_CSHARP_WRAPPER "Build the C# wrapper for Liblinphone." OFF) +option(ENABLE_VIDEO "Build with video support." YES) + +cmake_dependent_option(ENABLE_LIME "Enable Instant Messaging Encryption." YES "ENABLE_SQLITE_STORAGE" NO) +cmake_dependent_option(ENABLE_NOTIFY "Enable libnotify support." YES "ENABLE_GTK_UI;NOT APPLE" NO) +cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENABLE_GTK_UI" NO) set(CMAKE_CXX_STANDARD 11) - if(ENABLE_STATIC) set(LINPHONE_LIBS_FOR_TOOLS linphone-static) else() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6615525fe..65bd7f49c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,13 +29,20 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES cpim/message/cpim-message.h cpim/parser/cpim-grammar.h cpim/parser/cpim-parser.h + db/abstract/abstract-db-p.h + db/abstract/abstract-db.h + db/events-db.h + event/call-event.h + event/event.h + event/message-event.h logger/logger.h - object/clonable-object.h object/clonable-object-p.h + object/clonable-object.h object/object-p.h object/object.h object/singleton.h utils/general.h + utils/linphone.h utils/utils.h ) @@ -46,6 +53,11 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES cpim/message/cpim-message.cpp cpim/parser/cpim-grammar.cpp cpim/parser/cpim-parser.cpp + db/abstract/abstract-db.cpp + db/events-db.cpp + event/call-event.cpp + event/event.cpp + event/message-event.cpp logger/logger.cpp object/clonable-object.cpp object/object.cpp @@ -57,6 +69,7 @@ set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS}) if(SOCI_FOUND) list(APPEND LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${SOCI_INCLUDE_DIRS} ${SOCI_MYSQL_INCLUDES}) + add_definitions(-DSOCI_ENABLED) endif() set(LINPHONE_PRIVATE_HEADER_FILES) diff --git a/src/db/abstract/abstract-db-p.h b/src/db/abstract/abstract-db-p.h new file mode 100644 index 000000000..c04110813 --- /dev/null +++ b/src/db/abstract/abstract-db-p.h @@ -0,0 +1,46 @@ +/* + * abstract-db-p.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _ABSTRACT_DB_P_H_ +#define _ABSTRACT_DB_P_H_ + +#include + +#include "abstract-db.h" +#include "object/object-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class AbstractDbPrivate : public ObjectPrivate { +public: + #ifdef SOCI_ENABLED + soci::session session; + #endif // ifndef SOCI_ENABLED + +private: + AbstractDb::Backend backend; + bool isConnected = false; + + L_DECLARE_PUBLIC(AbstractDb); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _ABSTRACT_DB_P_H_ diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp new file mode 100644 index 000000000..158f76628 --- /dev/null +++ b/src/db/abstract/abstract-db.cpp @@ -0,0 +1,90 @@ +/* + * abstract-db.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "abstract-db-p.h" +#include "logger/logger.h" + +#include "abstract-db.h" + +using namespace std; + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +AbstractDb::AbstractDb (AbstractDbPrivate &p) : Object(*new AbstractDbPrivate) {} + +bool AbstractDb::connect (Backend backend, const std::string ¶meters) { + L_D(AbstractDb); + + #ifdef SOCI_ENABLED + + try { + if (d->isConnected) { + d->session.close(); + d->isConnected = false; + } + + d->session.open(backend == Mysql ? "mysql" : "sqlite3", parameters); + init(); + } catch (const exception &e) { + return false; + } + + return true; + + #else + + lWarning() << "Cannot use AbstractDb. Soci is not enabled."; + return false; + + #endif // ifndef SOCI_ENABLED +} + +bool AbstractDb::isConnected () const { + L_D(const AbstractDb); + return d->isConnected; +} + +AbstractDb::Backend AbstractDb::getBackend () const { + L_D(const AbstractDb); + return d->backend; +} + +// ----------------------------------------------------------------------------- + +void AbstractDb::init () { + // Nothing. +} + +// ----------------------------------------------------------------------------- + +string AbstractDb::primaryKeyAutoIncrementStr () const { + L_D(const AbstractDb); + + switch (d->backend) { + case Mysql: + return " BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT"; + case Sqlite3: + return " INTEGER PRIMARY KEY AUTOINCREMENT"; + } + + return ""; +} + +LINPHONE_END_NAMESPACE diff --git a/src/db/abstract/abstract-db.h b/src/db/abstract/abstract-db.h new file mode 100644 index 000000000..1e54943b2 --- /dev/null +++ b/src/db/abstract/abstract-db.h @@ -0,0 +1,62 @@ +/* + * abstract-db.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _ABSTRACT_DB_H_ +#define _ABSTRACT_DB_H_ + +#include + +#include "object/object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class AbstractDbPrivate; + +class LINPHONE_PUBLIC AbstractDb : public Object { +public: + enum Backend { + Mysql, + Sqlite3 + }; + + virtual ~AbstractDb () = default; + + bool connect (Backend backend, const std::string ¶meters); + bool disconnect (); + + bool isConnected () const; + + Backend getBackend () const; + +protected: + explicit AbstractDb (AbstractDbPrivate &p); + + virtual void init (); + + std::string primaryKeyAutoIncrementStr () const; + +private: + L_DECLARE_PRIVATE(AbstractDb); + L_DISABLE_COPY(AbstractDb); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _ABSTRACT_DB_H_ diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp new file mode 100644 index 000000000..226866121 --- /dev/null +++ b/src/db/events-db.cpp @@ -0,0 +1,100 @@ +/* + * events-db.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "abstract/abstract-db-p.h" + +#include "events-db.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class EventsDbPrivate : public AbstractDbPrivate {}; + +// ----------------------------------------------------------------------------- + +EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} + +void EventsDb::init () { + #ifdef SOCI_ENABLED + + L_D(EventsDb); + + d->session << + "CREATE TABLE IF NOT EXISTS sip_address (" + " id" + primaryKeyAutoIncrementStr() + "," + " value VARCHAR(255) NOT NULL" + ")"; + + d->session << + "CREATE TABLE IF NOT EXISTS event (" + " id" + primaryKeyAutoIncrementStr() + "," + " timestamp TIMESTAMP NOT NULL" + ")"; + + d->session << + "CREATE TABLE IF NOT EXISTS message_status (" + " id" + primaryKeyAutoIncrementStr() + "," + " status VARCHAR(255) NOT NULL" + ")"; + + d->session << + "CREATE TABLE IF NOT EXISTS message_direction (" + " id" + primaryKeyAutoIncrementStr() + "," + " direction VARCHAR(255) NOT NULL" + ")"; + + d->session << + "CREATE TABLE IF NOT EXISTS dialog (" + " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. + " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. + " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. + " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). + " FOREIGN KEY (local_sip_address_id)" + " REFERENCES sip_address(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (remote_sip_address_id)" + " REFERENCES sip_address(id)" + " ON DELETE CASCADE" + ")"; + + d->session << + "CREATE TABLE IF NOT EXISTS message_event (" + " id" + primaryKeyAutoIncrementStr() + "," + " dialog_id BIGINT UNSIGNED NOT NULL," + " status_id TINYINT UNSIGNED NOT NULL," + " direction_id TINYINT UNSIGNED NOT NULL," + " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 + " content_type VARCHAR(255) NOT NULL," + " is_secured BOOLEAN NOT NULL," + " app_data VARCHAR(2048)," + " FOREIGN KEY (dialog_id)" + " REFERENCES dialog(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (status_id)" + " REFERENCES message_status(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (direction_id)" + " REFERENCES message_direction(id)" + " ON DELETE CASCADE" + ")"; + + #endif // ifndef SOCI_ENABLED +} + +LINPHONE_END_NAMESPACE diff --git a/src/db/events-db.h b/src/db/events-db.h new file mode 100644 index 000000000..3cd201a25 --- /dev/null +++ b/src/db/events-db.h @@ -0,0 +1,47 @@ +/* + * events-db.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _EVENTS_DB_H_ +#define _EVENTS_DB_H_ + +#include "abstract/abstract-db.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class Event; +class EventsDbPrivate; + +class LINPHONE_PUBLIC EventsDb : public AbstractDb { +public: + EventsDb (); + + bool writeEvent (const Event &event); + +protected: + void init () override; + +private: + L_DECLARE_PRIVATE(EventsDb); + L_DISABLE_COPY(EventsDb); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _EVENTS_DB_H_ diff --git a/src/event/call-event.cpp b/src/event/call-event.cpp new file mode 100644 index 000000000..5620cb303 --- /dev/null +++ b/src/event/call-event.cpp @@ -0,0 +1,23 @@ +/* + * call-event.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "call-event.h" + +// ============================================================================= + +// TODO. diff --git a/src/event/call-event.h b/src/event/call-event.h new file mode 100644 index 000000000..0cbdb7f0f --- /dev/null +++ b/src/event/call-event.h @@ -0,0 +1,42 @@ +/* + * call-event.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CALL_EVENT_H_ +#define _CALL_EVENT_H_ + +#include "event.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class Call; +class CallEventPrivate; + +class CallEvent : public Event { +public: + CallEvent (const Call &message); + CallEvent (const CallEvent &src); + +private: + L_DECLARE_PRIVATE(CallEvent); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CALL_EVENT_H_ diff --git a/src/event/event-p.h b/src/event/event-p.h new file mode 100644 index 000000000..0499716fd --- /dev/null +++ b/src/event/event-p.h @@ -0,0 +1,38 @@ +/* + * event-p.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _EVENT_P_H_ +#define _EVENT_P_H_ + +#include "event.h" +#include "object/clonable-object-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class EventPrivate : public ClonableObjectPrivate { +private: + Event::Type type = Event::None; + + L_DECLARE_PUBLIC(Event); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _EVENT_P_H_ diff --git a/src/event/event.cpp b/src/event/event.cpp new file mode 100644 index 000000000..03d887f3a --- /dev/null +++ b/src/event/event.cpp @@ -0,0 +1,40 @@ +/* + * event.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "event-p.h" + +#include "event.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +Event::Event () : ClonableObject(*new EventPrivate) {} + +Event::Event (const Event &) : ClonableObject(*new EventPrivate) { + // `src` parameter is useless. +} + +Event::Event (EventPrivate &p) : ClonableObject(p) {} + +Event::Type Event::getType () const { + L_D(const Event); + return d->type; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/event.h b/src/event/event.h new file mode 100644 index 000000000..e4724112c --- /dev/null +++ b/src/event/event.h @@ -0,0 +1,54 @@ +/* + * event.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _EVENT_H_ +#define _EVENT_H_ + +#include "object/clonable-object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class EventPrivate; + +class Event : public ClonableObject { +public: + enum Type { + None, + MessageEvent, + FileMessageEvent, + CallEvent + }; + + Event (); + Event (const Event &src); + virtual ~Event () = default; + + Type getType () const; + +protected: + Event (EventPrivate &p); + +private: + L_DECLARE_PRIVATE(Event); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _EVENT_H_ diff --git a/src/event/message-event.cpp b/src/event/message-event.cpp new file mode 100644 index 000000000..4791ed3b7 --- /dev/null +++ b/src/event/message-event.cpp @@ -0,0 +1,23 @@ +/* + * message-event.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "message-event.h" + +// ============================================================================= + +// TODO. diff --git a/src/event/message-event.h b/src/event/message-event.h new file mode 100644 index 000000000..e3a3ac725 --- /dev/null +++ b/src/event/message-event.h @@ -0,0 +1,57 @@ +/* + * message-event.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MESSAGE_EVENT_H_ +#define _MESSAGE_EVENT_H_ + +#include +#include + +#include "event.h" +#include "utils/linphone.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ErrorInfo; +class Message; +class MessageEventPrivate; + +class MessageEvent : public Event { +public: + typedef std::pair CustomHeader; + + MessageEvent (const Message &message); + MessageEvent (const MessageEvent &src); + + std::string getText () const; + MessageState getState () const; + + MessageDirection getDirection () const; + ErrorInfo getErrorInfo () const; + std::string getImdnMessageId () const; + std::list getCustomHeaders () const; + +private: + L_DECLARE_PRIVATE(MessageEvent); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _MESSAGE_EVENT_H_ diff --git a/src/object/clonable-object.cpp b/src/object/clonable-object.cpp index 5b21b09b3..2b50da650 100644 --- a/src/object/clonable-object.cpp +++ b/src/object/clonable-object.cpp @@ -24,12 +24,12 @@ LINPHONE_BEGIN_NAMESPACE // ============================================================================= -ClonableObject::~ClonableObject () { - delete mPrivate; -} - ClonableObject::ClonableObject (ClonableObjectPrivate &p) : mPrivate(&p) { mPrivate->mPublic = this; } +ClonableObject::~ClonableObject () { + delete mPrivate; +} + LINPHONE_END_NAMESPACE diff --git a/src/object/clonable-object.h b/src/object/clonable-object.h index bda4392e1..fdca68b99 100644 --- a/src/object/clonable-object.h +++ b/src/object/clonable-object.h @@ -38,6 +38,10 @@ protected: private: L_DECLARE_PRIVATE(ClonableObject); + + // Yeah, it's a `ClonableObject` that cannot be copied. + // Only inherited classes must implement copy. + L_DISABLE_COPY(ClonableObject); }; LINPHONE_END_NAMESPACE diff --git a/src/utils/general.h b/src/utils/general.h index 17a911eb6..41eac6087 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -21,6 +21,14 @@ #ifndef _GENERAL_H_ #define _GENERAL_H_ +#define LINPHONE_NAMESPACE LinphonePrivate +#define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { +#define LINPHONE_END_NAMESPACE } + +// ----------------------------------------------------------------------------- + +LINPHONE_BEGIN_NAMESPACE + #ifndef LINPHONE_PUBLIC #if defined(_MSC_VER) #ifdef LINPHONE_STATIC @@ -39,12 +47,6 @@ // ----------------------------------------------------------------------------- -#define LINPHONE_NAMESPACE LinphonePrivate -#define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { -#define LINPHONE_END_NAMESPACE } - -// ----------------------------------------------------------------------------- - #define L_DECLARE_PRIVATE(CLASS) \ inline CLASS ## Private * getPrivate() { \ return reinterpret_cast(mPrivate); \ @@ -70,4 +72,6 @@ #define L_D(CLASS) CLASS ## Private * const d = getPrivate(); #define L_Q(CLASS) CLASS * const q = getPublic(); +LINPHONE_END_NAMESPACE + #endif // ifndef _GENERAL_H_ diff --git a/src/utils/linphone.h b/src/utils/linphone.h new file mode 100644 index 000000000..7c81b5512 --- /dev/null +++ b/src/utils/linphone.h @@ -0,0 +1,46 @@ +/* + * linphone.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _LINPHONE_H_ +#define _LINPHONE_H_ + +#include "general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +enum MessageDirection { + IncomingMessage, + OutgoingMessage +}; + +enum MessageState { + IdleMessageState, + InProgressMessageState, + DeliveredMessageState, + NotDeliveredMessageState, + FileTransferErrorMessageState, + FileTransferDoneMessageState, + DeliveredToUserMessageState, + DisplayedMessageState +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _LINPHONE_H_ diff --git a/src/utils/utils.h b/src/utils/utils.h index 3e5ca768d..799de2287 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -29,15 +29,15 @@ LINPHONE_BEGIN_NAMESPACE namespace Utils { - bool iequals (const std::string &a, const std::string &b); + bool iequals (const std::string &a, const std::string &b); - std::vector split (const std::string &str, const std::string &delimiter); + std::vector split (const std::string &str, const std::string &delimiter); - inline std::vector split (const std::string &str, char delimiter) { - return split(str, std::string(1, delimiter)); - } + inline std::vector split (const std::string &str, char delimiter) { + return split(str, std::string(1, delimiter)); + } - int stoi (const std::string &str, size_t *idx = 0, int base = 10); + int stoi (const std::string &str, size_t *idx = 0, int base = 10); } LINPHONE_END_NAMESPACE From bbd87a51d2f691289e65b5bba9bd79bcc1ab7e5b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Aug 2017 13:51:35 +0200 Subject: [PATCH 07/49] feat(core): add missing LINPHONE_PUBLIC --- src/event/call-event.h | 2 +- src/event/event.h | 2 +- src/event/message-event.h | 2 +- src/utils/utils.h | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/event/call-event.h b/src/event/call-event.h index 0cbdb7f0f..044946fce 100644 --- a/src/event/call-event.h +++ b/src/event/call-event.h @@ -28,7 +28,7 @@ LINPHONE_BEGIN_NAMESPACE class Call; class CallEventPrivate; -class CallEvent : public Event { +class LINPHONE_PUBLIC CallEvent : public Event { public: CallEvent (const Call &message); CallEvent (const CallEvent &src); diff --git a/src/event/event.h b/src/event/event.h index e4724112c..31b019cab 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -27,7 +27,7 @@ LINPHONE_BEGIN_NAMESPACE class EventPrivate; -class Event : public ClonableObject { +class LINPHONE_PUBLIC Event : public ClonableObject { public: enum Type { None, diff --git a/src/event/message-event.h b/src/event/message-event.h index e3a3ac725..2c9d5174d 100644 --- a/src/event/message-event.h +++ b/src/event/message-event.h @@ -33,7 +33,7 @@ class ErrorInfo; class Message; class MessageEventPrivate; -class MessageEvent : public Event { +class LINPHONE_PUBLIC MessageEvent : public Event { public: typedef std::pair CustomHeader; diff --git a/src/utils/utils.h b/src/utils/utils.h index 799de2287..ceede0cda 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -29,15 +29,15 @@ LINPHONE_BEGIN_NAMESPACE namespace Utils { - bool iequals (const std::string &a, const std::string &b); + LINPHONE_PUBLIC bool iequals (const std::string &a, const std::string &b); - std::vector split (const std::string &str, const std::string &delimiter); + LINPHONE_PUBLIC std::vector split (const std::string &str, const std::string &delimiter); - inline std::vector split (const std::string &str, char delimiter) { + LINPHONE_PUBLIC inline std::vector split (const std::string &str, char delimiter) { return split(str, std::string(1, delimiter)); } - int stoi (const std::string &str, size_t *idx = 0, int base = 10); + LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10); } LINPHONE_END_NAMESPACE From d986f2e447a58cc4550dd8c957dafb050b569ceb Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Aug 2017 13:56:45 +0200 Subject: [PATCH 08/49] chore(src/CMakeLists.txt): use SYSTEM flag on external include dirs --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 65bd7f49c..314043650 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,12 +83,12 @@ bc_apply_compile_flags(LINPHONE_CXX_OBJECTS_SOURCE_FILES STRICT_OPTIONS_CPP STRI if(ENABLE_STATIC) add_library(linphone-cxx-objects-static OBJECT ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES}) target_compile_definitions(linphone-cxx-objects-static PRIVATE ${LINPHONE_CXX_OBJECTS_DEFINITIONS}) - target_include_directories(linphone-cxx-objects-static PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS}) + target_include_directories(linphone-cxx-objects-static SYSTEM PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS}) endif() if(ENABLE_SHARED) add_library(linphone-cxx-objects OBJECT ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES}) target_compile_definitions(linphone-cxx-objects PRIVATE ${LINPHONE_CXX_OBJECTS_DEFINITIONS}) - target_include_directories(linphone-cxx-objects PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS}) + target_include_directories(linphone-cxx-objects SYSTEM PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS}) target_compile_options(linphone-cxx-objects PRIVATE "-fPIC") endif() From bbc0835236b16de1c331be08cb362044c609f1cc Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Aug 2017 14:34:06 +0200 Subject: [PATCH 09/49] feat(core): rename linphone.h to enums.h --- src/CMakeLists.txt | 2 +- src/{utils/linphone.h => enums.h} | 10 +++++----- src/event/message-event.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/{utils/linphone.h => enums.h} (91%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 314043650..79ddcb9b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES db/abstract/abstract-db-p.h db/abstract/abstract-db.h db/events-db.h + enums.h event/call-event.h event/event.h event/message-event.h @@ -42,7 +43,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES object/object.h object/singleton.h utils/general.h - utils/linphone.h utils/utils.h ) diff --git a/src/utils/linphone.h b/src/enums.h similarity index 91% rename from src/utils/linphone.h rename to src/enums.h index 7c81b5512..1a4a2487c 100644 --- a/src/utils/linphone.h +++ b/src/enums.h @@ -1,5 +1,5 @@ /* - * linphone.h + * enums.h * Copyright (C) 2017 Belledonne Communications SARL * * This program is free software: you can redistribute it and/or modify @@ -16,10 +16,10 @@ * along with this program. If not, see . */ -#ifndef _LINPHONE_H_ -#define _LINPHONE_H_ +#ifndef _ENUMS_H_ +#define _ENUMS_H_ -#include "general.h" +#include "utils/general.h" // ============================================================================= @@ -43,4 +43,4 @@ enum MessageState { LINPHONE_END_NAMESPACE -#endif // ifndef _LINPHONE_H_ +#endif // ifndef _ENUMS_H_ diff --git a/src/event/message-event.h b/src/event/message-event.h index 2c9d5174d..b0d03f619 100644 --- a/src/event/message-event.h +++ b/src/event/message-event.h @@ -22,8 +22,8 @@ #include #include +#include "enums.h" #include "event.h" -#include "utils/linphone.h" // ============================================================================= From 6e7ae964d8d5ac1d215cf8a9d7e978a92c01a8ea Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Aug 2017 14:35:50 +0200 Subject: [PATCH 10/49] feat(enums): use `enum class` instead of `enum` --- src/enums.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/enums.h b/src/enums.h index 1a4a2487c..ba228481f 100644 --- a/src/enums.h +++ b/src/enums.h @@ -25,20 +25,20 @@ LINPHONE_BEGIN_NAMESPACE -enum MessageDirection { - IncomingMessage, - OutgoingMessage +enum class MessageDirection { + Incoming, + Outgoing }; -enum MessageState { - IdleMessageState, - InProgressMessageState, - DeliveredMessageState, - NotDeliveredMessageState, - FileTransferErrorMessageState, - FileTransferDoneMessageState, - DeliveredToUserMessageState, - DisplayedMessageState +enum class MessageState { + Idle, + InProgress, + Delivered, + NotDelivered, + FileTransferError, + FileTransferDone, + DeliveredToUser, + Displayed }; LINPHONE_END_NAMESPACE From 1f3bcb463c027aaf4761c179b6444b4216c4f0c0 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 18 Aug 2017 09:26:48 +0200 Subject: [PATCH 11/49] feat(event): provide a working message event --- src/CMakeLists.txt | 2 + src/db/abstract/abstract-db-p.h | 4 +- src/db/events-db.cpp | 110 ++++++++++++++++---------------- src/event/event.cpp | 5 +- src/event/event.h | 6 +- src/event/message-event.cpp | 28 +++++++- src/event/message-event.h | 17 +---- src/message/message.cpp | 17 +++++ src/message/message.h | 98 ++++++++++++++++++++++++++++ 9 files changed, 212 insertions(+), 75 deletions(-) create mode 100644 src/message/message.cpp create mode 100644 src/message/message.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79ddcb9b0..523a270f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES event/event.h event/message-event.h logger/logger.h + message/message.h object/clonable-object-p.h object/clonable-object.h object/object-p.h @@ -59,6 +60,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES event/event.cpp event/message-event.cpp logger/logger.cpp + message/message.cpp object/clonable-object.cpp object/object.cpp utils/utils.cpp diff --git a/src/db/abstract/abstract-db-p.h b/src/db/abstract/abstract-db-p.h index c04110813..a3ef0e11d 100644 --- a/src/db/abstract/abstract-db-p.h +++ b/src/db/abstract/abstract-db-p.h @@ -19,7 +19,9 @@ #ifndef _ABSTRACT_DB_P_H_ #define _ABSTRACT_DB_P_H_ -#include +#ifdef SOCI_ENABLED + #include +#endif // ifdef SOCI_ENABLED #include "abstract-db.h" #include "object/object-p.h" diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 226866121..bf207d85a 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -33,68 +33,68 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} void EventsDb::init () { #ifdef SOCI_ENABLED - L_D(EventsDb); + L_D(EventsDb); - d->session << - "CREATE TABLE IF NOT EXISTS sip_address (" - " id" + primaryKeyAutoIncrementStr() + "," - " value VARCHAR(255) NOT NULL" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS sip_address (" + " id" + primaryKeyAutoIncrementStr() + "," + " value VARCHAR(255) NOT NULL" + ")"; - d->session << - "CREATE TABLE IF NOT EXISTS event (" - " id" + primaryKeyAutoIncrementStr() + "," - " timestamp TIMESTAMP NOT NULL" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS event (" + " id" + primaryKeyAutoIncrementStr() + "," + " timestamp TIMESTAMP NOT NULL" + ")"; - d->session << - "CREATE TABLE IF NOT EXISTS message_status (" - " id" + primaryKeyAutoIncrementStr() + "," - " status VARCHAR(255) NOT NULL" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS message_status (" + " id" + primaryKeyAutoIncrementStr() + "," + " status VARCHAR(255) NOT NULL" + ")"; - d->session << - "CREATE TABLE IF NOT EXISTS message_direction (" - " id" + primaryKeyAutoIncrementStr() + "," - " direction VARCHAR(255) NOT NULL" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS message_direction (" + " id" + primaryKeyAutoIncrementStr() + "," + " direction VARCHAR(255) NOT NULL" + ")"; - d->session << - "CREATE TABLE IF NOT EXISTS dialog (" - " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. - " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. - " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. - " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). - " FOREIGN KEY (local_sip_address_id)" - " REFERENCES sip_address(id)" - " ON DELETE CASCADE," - " FOREIGN KEY (remote_sip_address_id)" - " REFERENCES sip_address(id)" - " ON DELETE CASCADE" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS dialog (" + " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. + " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. + " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. + " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). + " FOREIGN KEY (local_sip_address_id)" + " REFERENCES sip_address(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (remote_sip_address_id)" + " REFERENCES sip_address(id)" + " ON DELETE CASCADE" + ")"; - d->session << - "CREATE TABLE IF NOT EXISTS message_event (" - " id" + primaryKeyAutoIncrementStr() + "," - " dialog_id BIGINT UNSIGNED NOT NULL," - " status_id TINYINT UNSIGNED NOT NULL," - " direction_id TINYINT UNSIGNED NOT NULL," - " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 - " content_type VARCHAR(255) NOT NULL," - " is_secured BOOLEAN NOT NULL," - " app_data VARCHAR(2048)," - " FOREIGN KEY (dialog_id)" - " REFERENCES dialog(id)" - " ON DELETE CASCADE," - " FOREIGN KEY (status_id)" - " REFERENCES message_status(id)" - " ON DELETE CASCADE," - " FOREIGN KEY (direction_id)" - " REFERENCES message_direction(id)" - " ON DELETE CASCADE" - ")"; + d->session << + "CREATE TABLE IF NOT EXISTS message_event (" + " id" + primaryKeyAutoIncrementStr() + "," + " dialog_id BIGINT UNSIGNED NOT NULL," + " status_id TINYINT UNSIGNED NOT NULL," + " direction_id TINYINT UNSIGNED NOT NULL," + " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 + " content_type VARCHAR(255) NOT NULL," + " is_secured BOOLEAN NOT NULL," + " app_data VARCHAR(2048)," + " FOREIGN KEY (dialog_id)" + " REFERENCES dialog(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (status_id)" + " REFERENCES message_status(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (direction_id)" + " REFERENCES message_direction(id)" + " ON DELETE CASCADE" + ")"; - #endif // ifndef SOCI_ENABLED + #endif // ifndef SOCI_ENABLED } LINPHONE_END_NAMESPACE diff --git a/src/event/event.cpp b/src/event/event.cpp index 03d887f3a..6a059950f 100644 --- a/src/event/event.cpp +++ b/src/event/event.cpp @@ -30,7 +30,10 @@ Event::Event (const Event &) : ClonableObject(*new EventPrivate) { // `src` parameter is useless. } -Event::Event (EventPrivate &p) : ClonableObject(p) {} +Event::Event (EventPrivate &p, Type type) : ClonableObject(p) { + L_D(Event); + d->type = type; +} Event::Type Event::getType () const { L_D(const Event); diff --git a/src/event/event.h b/src/event/event.h index 31b019cab..f0aa80010 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -32,8 +32,8 @@ public: enum Type { None, MessageEvent, - FileMessageEvent, - CallEvent + CallStartEvent, + CallEndEvent }; Event (); @@ -43,7 +43,7 @@ public: Type getType () const; protected: - Event (EventPrivate &p); + Event (EventPrivate &p, Type type); private: L_DECLARE_PRIVATE(Event); diff --git a/src/event/message-event.cpp b/src/event/message-event.cpp index 4791ed3b7..f9ca6fa62 100644 --- a/src/event/message-event.cpp +++ b/src/event/message-event.cpp @@ -16,8 +16,34 @@ * along with this program. If not, see . */ +#include "event-p.h" +#include "message/message.h" + #include "message-event.h" // ============================================================================= -// TODO. +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class MessageEventPrivate : public EventPrivate { +public: + shared_ptr message; +}; + +// ----------------------------------------------------------------------------- + +MessageEvent::MessageEvent (const shared_ptr &message) : Event(*new MessageEventPrivate, Event::MessageEvent) { + L_D(MessageEvent); + d->message = message; +} + +MessageEvent::MessageEvent (const MessageEvent &src) : MessageEvent(src.getMessage()) {} + +shared_ptr MessageEvent::getMessage () const { + L_D(const MessageEvent); + return d->message; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/message-event.h b/src/event/message-event.h index b0d03f619..5d46cb604 100644 --- a/src/event/message-event.h +++ b/src/event/message-event.h @@ -19,34 +19,23 @@ #ifndef _MESSAGE_EVENT_H_ #define _MESSAGE_EVENT_H_ -#include -#include +#include -#include "enums.h" #include "event.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class ErrorInfo; class Message; class MessageEventPrivate; class LINPHONE_PUBLIC MessageEvent : public Event { public: - typedef std::pair CustomHeader; - - MessageEvent (const Message &message); + MessageEvent (const std::shared_ptr &message); MessageEvent (const MessageEvent &src); - std::string getText () const; - MessageState getState () const; - - MessageDirection getDirection () const; - ErrorInfo getErrorInfo () const; - std::string getImdnMessageId () const; - std::list getCustomHeaders () const; + std::shared_ptr getMessage () const; private: L_DECLARE_PRIVATE(MessageEvent); diff --git a/src/message/message.cpp b/src/message/message.cpp new file mode 100644 index 000000000..b74ec5376 --- /dev/null +++ b/src/message/message.cpp @@ -0,0 +1,17 @@ +/* + * message.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ diff --git a/src/message/message.h b/src/message/message.h new file mode 100644 index 000000000..2d35abcd9 --- /dev/null +++ b/src/message/message.h @@ -0,0 +1,98 @@ +/* + * message.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MESSAGE_H_ +#define _MESSAGE_H_ + +#include +#include +#include + +#include "enums.h" +#include "object/object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class Address; +class ChatRoom; +class ErrorInfo; +class MessagePrivate; + +class LINPHONE_PUBLIC Message : public Object { + friend class ChatRoom; + +public: + std::string getText () const; + + /** + * @brief Set a chat message text to be sent by linphone_chat_room_send_message. + */ + int setText (const std::string &text); + + /** + * @brief Get the state of the message. + */ + // ChatMessageState getState () const; + + /** + * @brief Get if the message was encrypted when transfered. + */ + bool isSecured (); + + /** + * @brief Get the time the message was sent. + */ + time_t getTime () const; + + std::shared_ptr getChatRoom (); + + std::string getMessageId () const; + + std::string getAppdata () const; + void setAppdata (const std::string &data); + + std::shared_ptr getPeerAddress () const; + + std::shared_ptr getFromAddress () const; + void setFromAddress (const std::shared_ptr &address); + + std::shared_ptr getToAddress () const; + void setToAddress (const std::shared_ptr &addr); + + std::shared_ptr getLocalAddress () const; + + std::string getCustomHeaderValue (const std::string &headerName); + + void addCustomHeader (const std::string &headerName, const std::string &headerValue); + void removeCustomHeader (const std::string &headerName); + + std::shared_ptr getErrorInfo () const; + +protected: + Message (); + +private: + L_DECLARE_PRIVATE(Message); + L_DISABLE_COPY(Message); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _MESSAGE_H_ From f9a078befa2a8a4a74c2581428a3d534db51dedd Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 18 Aug 2017 13:13:11 +0200 Subject: [PATCH 12/49] feat(Event): provide a working call event --- CMakeLists.txt | 9 +++++- coreapi/help/examples/C/buddy_status.c | 4 +-- coreapi/help/examples/C/chatroom.c | 4 +-- coreapi/help/examples/C/filetransfer.c | 4 +-- coreapi/help/examples/C/helloworld.c | 2 +- coreapi/help/examples/C/notify.c | 4 +-- .../help/examples/C/realtimetext_receiver.c | 2 +- coreapi/help/examples/C/realtimetext_sender.c | 2 +- coreapi/help/examples/C/registration.c | 2 +- src/CMakeLists.txt | 1 + src/event/call-event.cpp | 28 ++++++++++++++++- src/event/call-event.h | 6 +++- src/event/event.cpp | 4 +-- src/event/message-event.cpp | 2 +- src/logger/logger.cpp | 4 ++- src/utils/general.cpp | 31 +++++++++++++++++++ src/utils/general.h | 12 +++++-- 17 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 src/utils/general.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1283185a3..83c390b2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,13 @@ cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENAB set(CMAKE_CXX_STANDARD 11) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG") + if(ENABLE_STATIC) set(LINPHONE_LIBS_FOR_TOOLS linphone-static) else() @@ -259,7 +266,7 @@ if(LINPHONE_CPPFLAGS) endif() if(ENABLE_DEBUG_LOGS) - add_definitions("-DDEBUG") + add_definitions("-DDEBUG_LOGS") endif() set(STRICT_OPTIONS_CPP ) diff --git a/coreapi/help/examples/C/buddy_status.c b/coreapi/help/examples/C/buddy_status.c index 905162214..98149b951 100644 --- a/coreapi/help/examples/C/buddy_status.c +++ b/coreapi/help/examples/C/buddy_status.c @@ -107,8 +107,8 @@ int main(int argc, char *argv[]){ password=argv[3]; } signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/chatroom.c b/coreapi/help/examples/C/chatroom.c index 52a71faab..ad21d3399 100644 --- a/coreapi/help/examples/C/chatroom.c +++ b/coreapi/help/examples/C/chatroom.c @@ -59,8 +59,8 @@ int main(int argc, char *argv[]){ } signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/filetransfer.c b/coreapi/help/examples/C/filetransfer.c index e461aafa2..485c0a662 100644 --- a/coreapi/help/examples/C/filetransfer.c +++ b/coreapi/help/examples/C/filetransfer.c @@ -133,8 +133,8 @@ int main(int argc, char *argv[]){ big_file[sizeof(big_file)-1]=*"E"; signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif vtable.message_received=message_received; diff --git a/coreapi/help/examples/C/helloworld.c b/coreapi/help/examples/C/helloworld.c index 19f433eab..8da3b227f 100644 --- a/coreapi/help/examples/C/helloworld.c +++ b/coreapi/help/examples/C/helloworld.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/notify.c b/coreapi/help/examples/C/notify.c index 8ebbc3e82..9f20cdb1c 100644 --- a/coreapi/help/examples/C/notify.c +++ b/coreapi/help/examples/C/notify.c @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#define DEBUG 1 +#define DEBUG_LOGS 1 #include "linphone/core.h" @@ -102,7 +102,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/realtimetext_receiver.c b/coreapi/help/examples/C/realtimetext_receiver.c index 9d8acf5dc..3915749a8 100644 --- a/coreapi/help/examples/C/realtimetext_receiver.c +++ b/coreapi/help/examples/C/realtimetext_receiver.c @@ -82,7 +82,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/realtimetext_sender.c b/coreapi/help/examples/C/realtimetext_sender.c index d765a6768..340ad7de2 100644 --- a/coreapi/help/examples/C/realtimetext_sender.c +++ b/coreapi/help/examples/C/realtimetext_sender.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif diff --git a/coreapi/help/examples/C/registration.c b/coreapi/help/examples/C/registration.c index 318723323..66667bc05 100644 --- a/coreapi/help/examples/C/registration.c +++ b/coreapi/help/examples/C/registration.c @@ -76,7 +76,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 523a270f4..422c8b1f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES message/message.cpp object/clonable-object.cpp object/object.cpp + utils/general.cpp utils/utils.cpp ) diff --git a/src/event/call-event.cpp b/src/event/call-event.cpp index 5620cb303..3837e9f9f 100644 --- a/src/event/call-event.cpp +++ b/src/event/call-event.cpp @@ -16,8 +16,34 @@ * along with this program. If not, see . */ +#include "event-p.h" + #include "call-event.h" // ============================================================================= -// TODO. +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class CallEventPrivate : public EventPrivate { +public: + shared_ptr call; +}; + +// ----------------------------------------------------------------------------- + +CallEvent::CallEvent (Type type, const shared_ptr &call) : Event(*new CallEventPrivate, type) { + L_D(CallEvent); + L_ASSERT(call); + d->call = call; +} + +CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getCall()) {} + +shared_ptr CallEvent::getCall () const { + L_D(const CallEvent); + return d->call; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/call-event.h b/src/event/call-event.h index 044946fce..fa2577aea 100644 --- a/src/event/call-event.h +++ b/src/event/call-event.h @@ -19,6 +19,8 @@ #ifndef _CALL_EVENT_H_ #define _CALL_EVENT_H_ +#include + #include "event.h" // ============================================================================= @@ -30,9 +32,11 @@ class CallEventPrivate; class LINPHONE_PUBLIC CallEvent : public Event { public: - CallEvent (const Call &message); + CallEvent (Type type, const std::shared_ptr &message); CallEvent (const CallEvent &src); + std::shared_ptr getCall () const; + private: L_DECLARE_PRIVATE(CallEvent); }; diff --git a/src/event/event.cpp b/src/event/event.cpp index 6a059950f..af505a417 100644 --- a/src/event/event.cpp +++ b/src/event/event.cpp @@ -26,9 +26,7 @@ LINPHONE_BEGIN_NAMESPACE Event::Event () : ClonableObject(*new EventPrivate) {} -Event::Event (const Event &) : ClonableObject(*new EventPrivate) { - // `src` parameter is useless. -} +Event::Event (const Event &) : ClonableObject(*new EventPrivate) {} Event::Event (EventPrivate &p, Type type) : ClonableObject(p) { L_D(Event); diff --git a/src/event/message-event.cpp b/src/event/message-event.cpp index f9ca6fa62..84c140526 100644 --- a/src/event/message-event.cpp +++ b/src/event/message-event.cpp @@ -17,7 +17,6 @@ */ #include "event-p.h" -#include "message/message.h" #include "message-event.h" @@ -36,6 +35,7 @@ public: MessageEvent::MessageEvent (const shared_ptr &message) : Event(*new MessageEventPrivate, Event::MessageEvent) { L_D(MessageEvent); + L_ASSERT(message); d->message = message; } diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index 340cf4a4f..7ca01589d 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -49,7 +49,9 @@ Logger::~Logger () { switch (d->level) { case Debug: - ms_debug("%s", str.c_str()); + #if DEBUG_LOGS + ms_debug("%s", str.c_str()); + #endif // if DEBUG_LOGS break; case Info: ms_message("%s", str.c_str()); diff --git a/src/utils/general.cpp b/src/utils/general.cpp new file mode 100644 index 000000000..9ed357c03 --- /dev/null +++ b/src/utils/general.cpp @@ -0,0 +1,31 @@ +/* + * general.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "logger/logger.h" + +#include "general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +void l_assert (const char *condition, const char *file, int line) { + lFatal() << "ASSERT: " << condition << " in " << file << " line " << line << "."; +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/general.h b/src/utils/general.h index 41eac6087..b91bf5af0 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -// ============================================================================= - #ifndef _GENERAL_H_ #define _GENERAL_H_ +// ============================================================================= + #define LINPHONE_NAMESPACE LinphonePrivate #define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { #define LINPHONE_END_NAMESPACE } @@ -72,6 +72,14 @@ LINPHONE_BEGIN_NAMESPACE #define L_D(CLASS) CLASS ## Private * const d = getPrivate(); #define L_Q(CLASS) CLASS * const q = getPublic(); +void l_assert (const char *condition, const char *file, int line); + +#ifdef DEBUG + #define L_ASSERT(CONDITION) static_cast(false && (CONDITION)) +#else + #define L_ASSERT(CONDITION) ((CONDITION) ? static_cast(0) : l_assert(#CONDITION, __FILE__, __LINE__)) +#endif + LINPHONE_END_NAMESPACE #endif // ifndef _GENERAL_H_ From 01999cbad14488eb7f34a46d1f34570558c31a90 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 18 Aug 2017 14:55:47 +0200 Subject: [PATCH 13/49] feat(Message): add interface --- src/message/message.h | 52 ++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/message/message.h b/src/message/message.h index 2d35abcd9..2ed93b803 100644 --- a/src/message/message.h +++ b/src/message/message.h @@ -32,6 +32,7 @@ LINPHONE_BEGIN_NAMESPACE class Address; class ChatRoom; +class Content; class ErrorInfo; class MessagePrivate; @@ -39,52 +40,43 @@ class LINPHONE_PUBLIC Message : public Object { friend class ChatRoom; public: + MessageDirection getDirection () const; + + std::shared_ptr getFromAddress () const; + std::shared_ptr getToAddress () const; + std::shared_ptr getLocalAddress () const; + std::shared_ptr getRemoteAddress () const; + + std::shared_ptr getChatRoom () const; + + std::shared_ptr getErrorInfo () const; + + std::string getContentType () const; + std::string getText () const; + void setText (const std::string &text); - /** - * @brief Set a chat message text to be sent by linphone_chat_room_send_message. - */ - int setText (const std::string &text); + void send () const; - /** - * @brief Get the state of the message. - */ - // ChatMessageState getState () const; + bool containsReadableText () const; - /** - * @brief Get if the message was encrypted when transfered. - */ - bool isSecured (); + bool isSecured () const; - /** - * @brief Get the time the message was sent. - */ time_t getTime () const; - std::shared_ptr getChatRoom (); - - std::string getMessageId () const; + std::string getId () const; std::string getAppdata () const; void setAppdata (const std::string &data); - std::shared_ptr getPeerAddress () const; - - std::shared_ptr getFromAddress () const; - void setFromAddress (const std::shared_ptr &address); - - std::shared_ptr getToAddress () const; - void setToAddress (const std::shared_ptr &addr); - - std::shared_ptr getLocalAddress () const; + std::list > getContents () const; + void addContent (std::shared_ptr &content); + void removeContent (std::shared_ptr &content); std::string getCustomHeaderValue (const std::string &headerName); - void addCustomHeader (const std::string &headerName, const std::string &headerValue); void removeCustomHeader (const std::string &headerName); - std::shared_ptr getErrorInfo () const; - protected: Message (); From 78824b02a97188f012aaab41267551043766f58b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 21 Aug 2017 09:29:05 +0200 Subject: [PATCH 14/49] fix(AbstractDb): unused variable when soci is not available --- src/db/abstract/abstract-db.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index 158f76628..3235f0ec3 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -30,30 +30,25 @@ LINPHONE_BEGIN_NAMESPACE AbstractDb::AbstractDb (AbstractDbPrivate &p) : Object(*new AbstractDbPrivate) {} bool AbstractDb::connect (Backend backend, const std::string ¶meters) { - L_D(AbstractDb); - #ifdef SOCI_ENABLED + L_D(AbstractDb); + try { + if (d->isConnected) { + d->session.close(); + d->isConnected = false; + } - try { - if (d->isConnected) { - d->session.close(); - d->isConnected = false; + d->session.open(backend == Mysql ? "mysql" : "sqlite3", parameters); + init(); + } catch (const exception &e) { + return false; } - d->session.open(backend == Mysql ? "mysql" : "sqlite3", parameters); - init(); - } catch (const exception &e) { - return false; - } - - return true; - + return true; #else - - lWarning() << "Cannot use AbstractDb. Soci is not enabled."; - return false; - - #endif // ifndef SOCI_ENABLED + lWarning() << "Cannot use AbstractDb. Soci is not enabled."; + return false; + #endif // ifndef SOCI_ENABLED } bool AbstractDb::isConnected () const { From 1b78b453c1fc7d4403f2d534feb5698b10d7f118 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 21 Aug 2017 13:42:50 +0200 Subject: [PATCH 15/49] Added LinphoneCall's setVideoWindowId method in JNI wrapper --- coreapi/linphonecore_jni.cc | 15 +++++++++++++++ java/common/org/linphone/core/LinphoneCall.java | 9 +++++++++ java/impl/org/linphone/core/LinphoneCallImpl.java | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 5f730ca0c..2a684c8b7 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -7846,6 +7846,21 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCallImpl_setListener(JNIEn linphone_call_set_next_video_frame_decoded_callback(call, _next_video_frame_decoded_callback, listener); } +extern "C" void Java_org_linphone_core_LinphoneCallImpl_setVideoWindowId(JNIEnv* env + ,jobject thiz + ,jlong lc + ,jobject obj) { + jobject oldWindow = (jobject) linphone_call_get_native_video_window_id((LinphoneCall*)lc); + if (obj != NULL) { + obj = env->NewGlobalRef(obj); + ms_message("Java_org_linphone_core_LinphoneCallImpl_setVideoWindowId(): NewGlobalRef(%p)",obj); + }else ms_message("Java_org_linphone_core_LinphoneCallImpl_setVideoWindowId(): setting to NULL"); + linphone_call_set_native_video_window_id((LinphoneCall*)lc,(void *)obj); + if (oldWindow != NULL) { + ms_message("Java_org_linphone_core_LinphoneCallImpl_setVideoWindowId(): DeleteGlobalRef(%p)",oldWindow); + env->DeleteGlobalRef(oldWindow); + } +} /* * returns the java TunnelConfig associated with a C LinphoneTunnelConfig. diff --git a/java/common/org/linphone/core/LinphoneCall.java b/java/common/org/linphone/core/LinphoneCall.java index 8cb43e796..332a76b57 100644 --- a/java/common/org/linphone/core/LinphoneCall.java +++ b/java/common/org/linphone/core/LinphoneCall.java @@ -20,6 +20,8 @@ package org.linphone.core; import java.util.Vector; +import org.linphone.mediastream.video.AndroidVideoWindowImpl; + /** * Object representing a call. Calls are created using {@link LinphoneCore#invite(LinphoneAddress)} or passed to the application by listener {@link LinphoneCoreListener#callState} * @@ -404,6 +406,13 @@ public interface LinphoneCall { */ void setListener(LinphoneCall.LinphoneCallListener listener); + /** + * Set the native video window id where the video is to be displayed. + * On Android, it must be of type {@link AndroidVideoWindowImpl} + * @param w window of type {@link AndroidVideoWindowImpl} + */ + void setVideoWindow(Object w); + /** * Indicates if remote party requested automatic answering to be performed. * This is an indication - the application remains responsible for answering the call. diff --git a/java/impl/org/linphone/core/LinphoneCallImpl.java b/java/impl/org/linphone/core/LinphoneCallImpl.java index f1338c423..70c0b01dc 100644 --- a/java/impl/org/linphone/core/LinphoneCallImpl.java +++ b/java/impl/org/linphone/core/LinphoneCallImpl.java @@ -45,6 +45,7 @@ class LinphoneCallImpl implements LinphoneCall { private native float getAverageQuality(long nativePtr); private native boolean mediaInProgress(long nativePtr); private native void setListener(long ptr, LinphoneCallListener listener); + private native void setVideoWindowId(long nativePtr, Object wid); native private long getDiversionAddress(long nativePtr); native private Object getStats(long nativePtr, int stream_type); native private LinphoneCore getCore(long nativePtr); @@ -295,6 +296,11 @@ class LinphoneCallImpl implements LinphoneCall { setListener(nativePtr, listener); } } + + @Override + public synchronized void setVideoWindow(Object w) { + setVideoWindowId(nativePtr, w); + } public LinphoneAddress getDiversionAddress() { long lNativePtr = getDiversionAddress(nativePtr); From 1610aa411e6a6d01aaa81d078906b00611893b4d Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 21 Aug 2017 13:59:09 +0200 Subject: [PATCH 16/49] feat(Message): add a basic impl --- src/message/message.cpp | 171 ++++++++++++++++++++++++++++++++++++++++ src/message/message.h | 19 ++--- 2 files changed, 181 insertions(+), 9 deletions(-) diff --git a/src/message/message.cpp b/src/message/message.cpp index b74ec5376..c3eaff907 100644 --- a/src/message/message.cpp +++ b/src/message/message.cpp @@ -15,3 +15,174 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include + +#include "db/events-db.h" +#include "object/object-p.h" + +#include "message.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +using namespace std; + +class MessagePrivate : public ObjectPrivate { +private: + weak_ptr chatRoom; + MessageDirection direction = MessageDirection::Incoming; + // LinphoneAddress *from; + // LinphoneAddress *to; + shared_ptr errorInfo; + string contentType; + string text; + bool isSecured = false; + time_t time = 0; + string id; + string appData; + list > contents; + unordered_map customHeaders; + MessageState state = MessageState::Idle; + shared_ptr eventsDb; + + L_DECLARE_PUBLIC(Message); +}; + +// ----------------------------------------------------------------------------- + +Message::Message (MessagePrivate &p) : Object(p) {} + +shared_ptr Message::getChatRoom () const { + L_D(const Message); + shared_ptr chatRoom = d->chatRoom.lock(); + if (!chatRoom) { + // TODO. + } + return chatRoom; +} + +MessageDirection Message::getDirection () const { + L_D(const Message); + return d->direction; +} + +shared_ptr Message::getFromAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getToAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getLocalAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getRemoteAddress () const { + // TODO. + return nullptr; +} + +MessageState Message::getState () const { + L_D(const Message); + return d->state; +} + +shared_ptr Message::getErrorInfo () const { + L_D(const Message); + return d->errorInfo; +} + +string Message::getContentType () const { + L_D(const Message); + return d->contentType; +} + +string Message::getText () const { + L_D(const Message); + return d->text; +} + +void Message::setText (const string &text) { + L_D(Message); + d->text = text; +} + +void Message::send () const { + // TODO. +} + +bool Message::containsReadableText () const { + // TODO: Check content type. + return true; +} + +bool Message::isSecured () const { + L_D(const Message); + return d->isSecured; +} + +time_t Message::getTime () const { + L_D(const Message); + return d->time; +} + +string Message::getId () const { + L_D(const Message); + return d->id; +} + +string Message::getAppdata () const { + L_D(const Message); + return d->appData; +} + +void Message::setAppdata (const string &appData) { + L_D(Message); + d->appData = appData; +} + +list > Message::getContents () const { + L_D(const Message); + list > contents; + for (const auto &content : d->contents) + contents.push_back(content); + return contents; +} + +void Message::addContent (const shared_ptr &content) { + L_D(Message); + d->contents.push_back(content); +} + +void Message::removeContent (const shared_ptr &content) { + L_D(Message); + d->contents.remove(const_pointer_cast(content)); +} + +string Message::getCustomHeaderValue (const string &headerName) const { + L_D(const Message); + try { + return d->customHeaders.at(headerName); + } catch (const exception &) { + // Key doesn't exist. + } + return ""; +} + +void Message::addCustomHeader (const string &headerName, const string &headerValue) { + L_D(Message); + d->customHeaders[headerName] = headerValue; +} + +void Message::removeCustomHeader (const string &headerName) { + L_D(Message); + d->customHeaders.erase(headerName); +} + +LINPHONE_END_NAMESPACE diff --git a/src/message/message.h b/src/message/message.h index 2ed93b803..e317269c4 100644 --- a/src/message/message.h +++ b/src/message/message.h @@ -40,6 +40,8 @@ class LINPHONE_PUBLIC Message : public Object { friend class ChatRoom; public: + std::shared_ptr getChatRoom () const; + MessageDirection getDirection () const; std::shared_ptr getFromAddress () const; @@ -47,7 +49,7 @@ public: std::shared_ptr getLocalAddress () const; std::shared_ptr getRemoteAddress () const; - std::shared_ptr getChatRoom () const; + MessageState getState () const; std::shared_ptr getErrorInfo () const; @@ -67,20 +69,19 @@ public: std::string getId () const; std::string getAppdata () const; - void setAppdata (const std::string &data); + void setAppdata (const std::string &appData); - std::list > getContents () const; - void addContent (std::shared_ptr &content); - void removeContent (std::shared_ptr &content); + std::list > getContents () const; + void addContent (const std::shared_ptr &content); + void removeContent (const std::shared_ptr &content); - std::string getCustomHeaderValue (const std::string &headerName); + std::string getCustomHeaderValue (const std::string &headerName) const; void addCustomHeader (const std::string &headerName, const std::string &headerValue); void removeCustomHeader (const std::string &headerName); -protected: - Message (); - private: + Message (MessagePrivate &p); + L_DECLARE_PRIVATE(Message); L_DISABLE_COPY(Message); }; From d0048a553deb61ff0f61be0d035337ac7395e744 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 22 Aug 2017 17:15:43 +0200 Subject: [PATCH 17/49] feat(core): provide a shareable data in ClonableObject, assignment operator is supported by events, ... --- src/CMakeLists.txt | 5 ++ src/db/abstract/abstract-db-p.h | 10 +-- src/db/abstract/abstract-db.cpp | 33 ++++------ src/db/events-db.cpp | 15 +++-- src/db/provider/db-session-p.h | 54 ++++++++++++++++ src/db/provider/db-session-provider.cpp | 83 +++++++++++++++++++++++++ src/db/provider/db-session-provider.h | 48 ++++++++++++++ src/db/provider/db-session.cpp | 36 +++++++++++ src/db/provider/db-session.h | 49 +++++++++++++++ src/event/call-event.cpp | 10 +++ src/event/call-event.h | 2 + src/event/event.cpp | 11 +++- src/event/event.h | 2 + src/event/message-event.cpp | 10 +++ src/event/message-event.h | 2 + src/object/clonable-object-p.h | 11 +++- src/object/clonable-object.cpp | 59 ++++++++++++++++-- src/object/clonable-object.h | 9 ++- src/object/object-p.h | 2 - src/object/object.h | 2 - src/utils/general.h | 60 ++++++++++++++---- src/utils/utils.h | 12 ++-- 22 files changed, 460 insertions(+), 65 deletions(-) create mode 100644 src/db/provider/db-session-p.h create mode 100644 src/db/provider/db-session-provider.cpp create mode 100644 src/db/provider/db-session-provider.h create mode 100644 src/db/provider/db-session.cpp create mode 100644 src/db/provider/db-session.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 422c8b1f3..29d437147 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES db/abstract/abstract-db-p.h db/abstract/abstract-db.h db/events-db.h + db/provider/db-session-p.h + db/provider/db-session-provider.h + db/provider/db-session.h enums.h event/call-event.h event/event.h @@ -56,6 +59,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES cpim/parser/cpim-parser.cpp db/abstract/abstract-db.cpp db/events-db.cpp + db/provider/db-session-provider.cpp + db/provider/db-session.cpp event/call-event.cpp event/event.cpp event/message-event.cpp diff --git a/src/db/abstract/abstract-db-p.h b/src/db/abstract/abstract-db-p.h index a3ef0e11d..51dbd2ffe 100644 --- a/src/db/abstract/abstract-db-p.h +++ b/src/db/abstract/abstract-db-p.h @@ -19,11 +19,8 @@ #ifndef _ABSTRACT_DB_P_H_ #define _ABSTRACT_DB_P_H_ -#ifdef SOCI_ENABLED - #include -#endif // ifdef SOCI_ENABLED - #include "abstract-db.h" +#include "db/provider/db-session.h" #include "object/object-p.h" // ============================================================================= @@ -32,13 +29,10 @@ LINPHONE_BEGIN_NAMESPACE class AbstractDbPrivate : public ObjectPrivate { public: - #ifdef SOCI_ENABLED - soci::session session; - #endif // ifndef SOCI_ENABLED + DbSession dbSession; private: AbstractDb::Backend backend; - bool isConnected = false; L_DECLARE_PUBLIC(AbstractDb); }; diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index 3235f0ec3..63e2fcef4 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -17,43 +17,34 @@ */ #include "abstract-db-p.h" +#include "db/provider/db-session-provider.h" #include "logger/logger.h" #include "abstract-db.h" -using namespace std; - // ============================================================================= +using namespace std; + LINPHONE_BEGIN_NAMESPACE AbstractDb::AbstractDb (AbstractDbPrivate &p) : Object(*new AbstractDbPrivate) {} -bool AbstractDb::connect (Backend backend, const std::string ¶meters) { - #ifdef SOCI_ENABLED - L_D(AbstractDb); - try { - if (d->isConnected) { - d->session.close(); - d->isConnected = false; - } +bool AbstractDb::connect (Backend backend, const string ¶meters) { + L_D(AbstractDb); - d->session.open(backend == Mysql ? "mysql" : "sqlite3", parameters); - init(); - } catch (const exception &e) { - return false; - } + d->dbSession = DbSessionProvider::getInstance()->getSession( + (backend == Mysql ? "mysql://" : "sqlite3://") + parameters + ); - return true; - #else - lWarning() << "Cannot use AbstractDb. Soci is not enabled."; - return false; - #endif // ifndef SOCI_ENABLED + if (d->dbSession) + init(); + return d->dbSession; } bool AbstractDb::isConnected () const { L_D(const AbstractDb); - return d->isConnected; + return d->dbSession; } AbstractDb::Backend AbstractDb::getBackend () const { diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index bf207d85a..8a949c0e8 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -20,6 +20,11 @@ #include "events-db.h" +// TODO: Remove me. +#ifdef SOCI_ENABLED + #undef SOCI_ENABLED +#endif + // ============================================================================= LINPHONE_BEGIN_NAMESPACE @@ -61,10 +66,10 @@ void EventsDb::init () { d->session << "CREATE TABLE IF NOT EXISTS dialog (" - " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. - " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. - " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. - " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). + " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. + " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. + " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. + " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). " FOREIGN KEY (local_sip_address_id)" " REFERENCES sip_address(id)" " ON DELETE CASCADE," @@ -79,7 +84,7 @@ void EventsDb::init () { " dialog_id BIGINT UNSIGNED NOT NULL," " status_id TINYINT UNSIGNED NOT NULL," " direction_id TINYINT UNSIGNED NOT NULL," - " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 + " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 " content_type VARCHAR(255) NOT NULL," " is_secured BOOLEAN NOT NULL," " app_data VARCHAR(2048)," diff --git a/src/db/provider/db-session-p.h b/src/db/provider/db-session-p.h new file mode 100644 index 000000000..597ceaa44 --- /dev/null +++ b/src/db/provider/db-session-p.h @@ -0,0 +1,54 @@ +/* + * db-session-p.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DB_SESSION_P_H_ +#define _DB_SESSION_P_H_ + +#ifdef SOCI_ENABLED + #include +#endif // ifdef SOCI_ENABLED + +#include "db-session.h" +#include "object/clonable-object-p.h" + +// ============================================================================= + +#ifdef SOCI_ENABLED + namespace soci { + class session; + } +#endif // ifdef SOCI_ENABLED + +LINPHONE_BEGIN_NAMESPACE + +class DbSessionPrivate : public ClonableObjectPrivate { + friend class DbSessionProvider; + +private: + bool isValid = false; + + #ifdef SOCI_ENABLED + std::shared_ptr session; + #endif // ifndef SOCI_ENABLED + + L_DECLARE_PUBLIC(DbSession); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _DB_SESSION_P_H_ diff --git a/src/db/provider/db-session-provider.cpp b/src/db/provider/db-session-provider.cpp new file mode 100644 index 000000000..04c8bb98e --- /dev/null +++ b/src/db/provider/db-session-provider.cpp @@ -0,0 +1,83 @@ +/* + * db-session-provider.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef SOCI_ENABLED + #include + + #include +#endif // ifdef SOCI_ENABLED + +#include "db-session-p.h" +#include "object/object-p.h" + +#include "db-session-provider.h" + +#define CLEAN_COUNTER_MAX 1000 + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class DbSessionProviderPrivate : public ObjectPrivate { +public: + #ifdef SOCI_ENABLED + typedef pair, DbSessionPrivate *> InternalSession; + unordered_map sessions; + #endif // ifdef SOCI_ENABLED + + int cleanCounter = 0; +}; + +DbSessionProvider::DbSessionProvider () : Singleton(*new DbSessionProviderPrivate) {} + +DbSession DbSessionProvider::getSession (const string &uri) { + DbSession session; + + #ifdef SOCI_ENABLED + L_D(DbSessionProvider); + try { + shared_ptr sociSession = d->sessions[uri].first.lock(); + if (!sociSession) { // Create new session. + sociSession = make_shared(uri); + DbSessionPrivate *p = session.getPrivate(); + p->session = sociSession; + p->isValid = true; + d->sessions[uri] = make_pair(sociSession, p); + } else // Share session. + session.setRef(*d->sessions[uri].second); + } catch (const exception &) {} + + // Remove invalid weak ptrs. + if (++d->cleanCounter >= CLEAN_COUNTER_MAX) { + d->cleanCounter = 0; + + for (auto it = d->sessions.begin(), itEnd = d->sessions.end(); it != itEnd;) { + if (it->second.first.expired()) + it = d->sessions.erase(it); + else + ++it; + } + } + #endif // ifndef SOCI_ENABLED + + return session; +} + +LINPHONE_END_NAMESPACE diff --git a/src/db/provider/db-session-provider.h b/src/db/provider/db-session-provider.h new file mode 100644 index 000000000..50542d5eb --- /dev/null +++ b/src/db/provider/db-session-provider.h @@ -0,0 +1,48 @@ +/* + * db-session-provider.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DB_SESSION_PROVIDER_H_ +#define _DB_SESSION_PROVIDER_H_ + +#include + +#include "db-session.h" +#include "object/singleton.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class DbSessionProviderPrivate; + +class DbSessionProvider : public Singleton { + friend class Singleton; + +public: + DbSession getSession (const std::string &uri); + +private: + DbSessionProvider (); + + L_DECLARE_PRIVATE(DbSessionProvider); + L_DISABLE_COPY(DbSessionProvider); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _DB_SESSION_PROVIDER_H_ diff --git a/src/db/provider/db-session.cpp b/src/db/provider/db-session.cpp new file mode 100644 index 000000000..ac1f85d52 --- /dev/null +++ b/src/db/provider/db-session.cpp @@ -0,0 +1,36 @@ +/* + * db-session.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "db-session-p.h" + +#include "db-session.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +L_USE_DEFAULT_SHARE_IMPL(DbSession, ClonableObject); + +DbSession::operator bool () const { + L_D(const DbSession); + return d->isValid; +} + +LINPHONE_END_NAMESPACE diff --git a/src/db/provider/db-session.h b/src/db/provider/db-session.h new file mode 100644 index 000000000..35eb6fe59 --- /dev/null +++ b/src/db/provider/db-session.h @@ -0,0 +1,49 @@ +/* + * db-session.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DB_SESSION_H_ +#define _DB_SESSION_H_ + +#include + +#include "object/clonable-object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class DbSessionPrivate; + +class DbSession : public ClonableObject { + friend class DbSessionProvider; + +public: + DbSession (); + DbSession (const DbSession &src); + + DbSession &operator= (const DbSession &src); + + operator bool () const; + +private: + L_DECLARE_PRIVATE(DbSession); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _DB_SESSION_H_ diff --git a/src/event/call-event.cpp b/src/event/call-event.cpp index 3837e9f9f..bc17b4e2c 100644 --- a/src/event/call-event.cpp +++ b/src/event/call-event.cpp @@ -41,6 +41,16 @@ CallEvent::CallEvent (Type type, const shared_ptr &call) : Event(*new Call CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getCall()) {} +CallEvent &CallEvent::operator= (const CallEvent &src) { + L_D(CallEvent); + if (this != &src) { + Event::operator=(src); + d->call = src.getPrivate()->call; + } + + return *this; +} + shared_ptr CallEvent::getCall () const { L_D(const CallEvent); return d->call; diff --git a/src/event/call-event.h b/src/event/call-event.h index fa2577aea..e56d25dfc 100644 --- a/src/event/call-event.h +++ b/src/event/call-event.h @@ -35,6 +35,8 @@ public: CallEvent (Type type, const std::shared_ptr &message); CallEvent (const CallEvent &src); + CallEvent &operator= (const CallEvent &src); + std::shared_ptr getCall () const; private: diff --git a/src/event/event.cpp b/src/event/event.cpp index af505a417..824240425 100644 --- a/src/event/event.cpp +++ b/src/event/event.cpp @@ -24,15 +24,24 @@ LINPHONE_BEGIN_NAMESPACE +// ----------------------------------------------------------------------------- + Event::Event () : ClonableObject(*new EventPrivate) {} Event::Event (const Event &) : ClonableObject(*new EventPrivate) {} -Event::Event (EventPrivate &p, Type type) : ClonableObject(p) { +Event::Event (EventPrivate &p, Type type) : ClonableObject(*new EventPrivate) { L_D(Event); d->type = type; } +Event &Event::operator= (const Event &src) { + L_D(Event); + if (this != &src) + d->type = src.getPrivate()->type; + return *this; +} + Event::Type Event::getType () const { L_D(const Event); return d->type; diff --git a/src/event/event.h b/src/event/event.h index f0aa80010..17deb379f 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -40,6 +40,8 @@ public: Event (const Event &src); virtual ~Event () = default; + Event &operator= (const Event &src); + Type getType () const; protected: diff --git a/src/event/message-event.cpp b/src/event/message-event.cpp index 84c140526..49e74f3b7 100644 --- a/src/event/message-event.cpp +++ b/src/event/message-event.cpp @@ -41,6 +41,16 @@ MessageEvent::MessageEvent (const shared_ptr &message) : Event(*new Mes MessageEvent::MessageEvent (const MessageEvent &src) : MessageEvent(src.getMessage()) {} +MessageEvent &MessageEvent::operator= (const MessageEvent &src) { + L_D(MessageEvent); + if (this != &src) { + Event::operator=(src); + d->message = src.getPrivate()->message; + } + + return *this; +} + shared_ptr MessageEvent::getMessage () const { L_D(const MessageEvent); return d->message; diff --git a/src/event/message-event.h b/src/event/message-event.h index 5d46cb604..9edff75a9 100644 --- a/src/event/message-event.h +++ b/src/event/message-event.h @@ -35,6 +35,8 @@ public: MessageEvent (const std::shared_ptr &message); MessageEvent (const MessageEvent &src); + MessageEvent &operator= (const MessageEvent &src); + std::shared_ptr getMessage () const; private: diff --git a/src/object/clonable-object-p.h b/src/object/clonable-object-p.h index 94c3b4491..8c099be7b 100644 --- a/src/object/clonable-object-p.h +++ b/src/object/clonable-object-p.h @@ -19,22 +19,27 @@ #ifndef _CLONABLE_OBJECT_P_H_ #define _CLONABLE_OBJECT_P_H_ +#include + #include "utils/general.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class ClonableObject; - class ClonableObjectPrivate { public: virtual ~ClonableObjectPrivate () = default; protected: - ClonableObject *mPublic = nullptr; + std::unordered_map *mPublic = nullptr; private: + void ref (); + void unref (); + + int nRefs = 0; + L_DECLARE_PUBLIC(ClonableObject); }; diff --git a/src/object/clonable-object.cpp b/src/object/clonable-object.cpp index 2b50da650..32c36a2ae 100644 --- a/src/object/clonable-object.cpp +++ b/src/object/clonable-object.cpp @@ -20,16 +20,67 @@ #include "clonable-object.h" -LINPHONE_BEGIN_NAMESPACE - // ============================================================================= +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +// TODO: Use atomic counter? + +void ClonableObjectPrivate::ref () { + ++nRefs; +} + +void ClonableObjectPrivate::unref () { + if (--nRefs == 0) { + delete mPublic; + delete this; + } +} + +// ----------------------------------------------------------------------------- + ClonableObject::ClonableObject (ClonableObjectPrivate &p) : mPrivate(&p) { - mPrivate->mPublic = this; + // Q-pointer must be empty. It's a constructor that takes a new private data. + L_ASSERT(!mPrivate->mPublic); + + mPrivate->mPublic = new remove_pointermPublic)>::type; + (*mPrivate->mPublic)[mPrivate] = this; + mPrivate->ref(); +} + +ClonableObject::ClonableObject (const ClonableObjectPrivate &p) { + // Cannot access to Q-pointer. It's a copy constructor from private data. + L_ASSERT(!mPrivate); + + setRef(p); } ClonableObject::~ClonableObject () { - delete mPrivate; + mPrivate->mPublic->erase(mPrivate); + mPrivate->unref(); +} + +void ClonableObject::setRef (const ClonableObjectPrivate &p) { + // Q-pointer must exist. + L_ASSERT(mPrivate); + L_ASSERT(mPrivate->mPublic); + + // Nothing, same reference. + if (&p == mPrivate) + return; + + // Unref previous private data. + if (mPrivate) { + mPrivate->mPublic->erase(mPrivate); + mPrivate->unref(); + } + + // Add and reference new private data. + mPrivate = const_cast(&p); + (*mPrivate->mPublic)[mPrivate] = this; + mPrivate->ref(); } LINPHONE_END_NAMESPACE diff --git a/src/object/clonable-object.h b/src/object/clonable-object.h index fdca68b99..490c5bc71 100644 --- a/src/object/clonable-object.h +++ b/src/object/clonable-object.h @@ -25,15 +25,20 @@ LINPHONE_BEGIN_NAMESPACE -class ClonableObjectPrivate; - class LINPHONE_PUBLIC ClonableObject { public: virtual ~ClonableObject (); protected: + // Use a new ClonableObjectPrivate without owner. explicit ClonableObject (ClonableObjectPrivate &p); + // If you want share an existing ClonableObjectPrivate, call this function. + explicit ClonableObject (const ClonableObjectPrivate &p); + + // Change the ClonableObjectPrivate, it can be shared. + void setRef (const ClonableObjectPrivate &p); + ClonableObjectPrivate *mPrivate = nullptr; private: diff --git a/src/object/object-p.h b/src/object/object-p.h index 83d7612fc..ca9111eac 100644 --- a/src/object/object-p.h +++ b/src/object/object-p.h @@ -25,8 +25,6 @@ LINPHONE_BEGIN_NAMESPACE -class Object; - class ObjectPrivate { public: virtual ~ObjectPrivate () = default; diff --git a/src/object/object.h b/src/object/object.h index 54ed08d28..d3cc22808 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -25,8 +25,6 @@ LINPHONE_BEGIN_NAMESPACE -class ObjectPrivate; - class LINPHONE_PUBLIC Object { public: virtual ~Object (); diff --git a/src/utils/general.h b/src/utils/general.h index b91bf5af0..7f46799b8 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -47,6 +47,14 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- +void l_assert (const char *condition, const char *file, int line); + +#ifdef DEBUG + #define L_ASSERT(CONDITION) static_cast(false && (CONDITION)) +#else + #define L_ASSERT(CONDITION) ((CONDITION) ? static_cast(0) : l_assert(#CONDITION, __FILE__, __LINE__)) +#endif + #define L_DECLARE_PRIVATE(CLASS) \ inline CLASS ## Private * getPrivate() { \ return reinterpret_cast(mPrivate); \ @@ -56,12 +64,41 @@ LINPHONE_BEGIN_NAMESPACE } \ friend class CLASS ## Private; +class ClonableObject; +class ClonableObjectPrivate; +class Object; +class ObjectPrivate; + +template +inline ClonableObject *getPublicHelper (T *object, ClonableObjectPrivate *context) { + auto it = object->find(context); + L_ASSERT(it != object->end()); + return it->second; +} + +template +inline const ClonableObject *getPublicHelper (const T *object, const ClonableObjectPrivate *context) { + auto it = object->find(context); + L_ASSERT(it != object->cend()); + return it->second; +} + +template +inline Object *getPublicHelper (T *object, ObjectPrivate *) { + return object; +} + +template +inline const Object *getPublicHelper (const T *object, const ObjectPrivate *) { + return object; +} + #define L_DECLARE_PUBLIC(CLASS) \ - inline CLASS * getPublic() { \ - return static_cast(mPublic); \ + inline CLASS * getPublic () { \ + return static_cast(getPublicHelper(mPublic, this)); \ } \ - inline const CLASS *getPublic() const { \ - return static_cast(mPublic); \ + inline const CLASS *getPublic () const { \ + return static_cast(getPublicHelper(mPublic, this)); \ } \ friend class CLASS; @@ -72,13 +109,14 @@ LINPHONE_BEGIN_NAMESPACE #define L_D(CLASS) CLASS ## Private * const d = getPrivate(); #define L_Q(CLASS) CLASS * const q = getPublic(); -void l_assert (const char *condition, const char *file, int line); - -#ifdef DEBUG - #define L_ASSERT(CONDITION) static_cast(false && (CONDITION)) -#else - #define L_ASSERT(CONDITION) ((CONDITION) ? static_cast(0) : l_assert(#CONDITION, __FILE__, __LINE__)) -#endif +#define L_USE_DEFAULT_SHARE_IMPL(CLASS, PARENT_CLASS) \ + CLASS::CLASS () : PARENT_CLASS(*new CLASS ## Private) {} \ + CLASS::CLASS (const CLASS &src) : ClonableObject(*src.getPrivate()) {} \ + CLASS &CLASS::operator= (const CLASS &src) { \ + if (this != &src) \ + setRef(*src.getPrivate()); \ + return *this; \ + } LINPHONE_END_NAMESPACE diff --git a/src/utils/utils.h b/src/utils/utils.h index ceede0cda..e64dc4e7e 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -29,15 +29,15 @@ LINPHONE_BEGIN_NAMESPACE namespace Utils { - LINPHONE_PUBLIC bool iequals (const std::string &a, const std::string &b); + LINPHONE_PUBLIC bool iequals (const std::string &a, const std::string &b); - LINPHONE_PUBLIC std::vector split (const std::string &str, const std::string &delimiter); + LINPHONE_PUBLIC std::vector split (const std::string &str, const std::string &delimiter); - LINPHONE_PUBLIC inline std::vector split (const std::string &str, char delimiter) { - return split(str, std::string(1, delimiter)); - } + LINPHONE_PUBLIC inline std::vector split (const std::string &str, char delimiter) { + return split(str, std::string(1, delimiter)); + } - LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10); + LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10); } LINPHONE_END_NAMESPACE From 8c98297aa4101d83a61ad6e0b530e7dbfafacd0b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 22 Aug 2017 17:17:56 +0200 Subject: [PATCH 18/49] fix(ClonableObject): use correct assert on setRef --- src/object/clonable-object.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/object/clonable-object.cpp b/src/object/clonable-object.cpp index 32c36a2ae..1eb46a512 100644 --- a/src/object/clonable-object.cpp +++ b/src/object/clonable-object.cpp @@ -63,9 +63,8 @@ ClonableObject::~ClonableObject () { } void ClonableObject::setRef (const ClonableObjectPrivate &p) { - // Q-pointer must exist. - L_ASSERT(mPrivate); - L_ASSERT(mPrivate->mPublic); + // Q-pointer must exist if private data is defined. + L_ASSERT(!mPrivate || mPrivate->mPublic); // Nothing, same reference. if (&p == mPrivate) From 552be2a6394ee6c13ca31954f65f11c38b1dad6d Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 23 Aug 2017 09:21:14 +0200 Subject: [PATCH 19/49] small rework of trace level management. --- coreapi/bellesip_sal/sal_impl.c | 52 +++++++++----------------- coreapi/help/examples/C/CMakeLists.txt | 2 +- coreapi/linphonecore.c | 18 ++++----- daemon/CMakeLists.txt | 2 +- include/linphone/core.h | 8 ++++ include/sal/sal.h | 2 + tester/accountmanager.c | 2 +- tester/liblinphone_tester.c | 3 +- tester/register_tester.c | 5 +++ tester/tester.c | 2 +- tools/CMakeLists.txt | 4 +- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index c6803481b..4aa2c1fb8 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -59,31 +59,6 @@ void sal_op_set_privacy_from_message(SalOp* op,belle_sip_message_t* msg) { } static void set_tls_properties(Sal *ctx); -void _belle_sip_log(const char *domain, belle_sip_log_level lev, const char *fmt, va_list args) { - OrtpLogLevel ortp_level; - switch(lev) { - case BELLE_SIP_LOG_FATAL: - ortp_level=ORTP_FATAL; - break; - case BELLE_SIP_LOG_ERROR: - ortp_level=ORTP_ERROR; - break; - case BELLE_SIP_LOG_WARNING: - ortp_level=ORTP_WARNING; - break; - case BELLE_SIP_LOG_MESSAGE: - ortp_level=ORTP_MESSAGE; - break; - case BELLE_SIP_LOG_DEBUG: - default: - ortp_level=ORTP_DEBUG; - break; - } - if (ortp_log_level_enabled("belle-sip", ortp_level)){ - ortp_logv("belle-sip", ortp_level,fmt,args); - } -} - void sal_enable_log(){ sal_set_log_level(ORTP_MESSAGE); } @@ -93,24 +68,31 @@ void sal_disable_log() { } void sal_set_log_level(OrtpLogLevel level) { - belle_sip_log_level belle_sip_level; + belle_sip_log_level belle_sip_level = BELLE_SIP_LOG_MESSAGE; if ((level&ORTP_FATAL) != 0) { belle_sip_level = BELLE_SIP_LOG_FATAL; - } else if ((level&ORTP_ERROR) != 0) { + } + if ((level&ORTP_ERROR) != 0) { belle_sip_level = BELLE_SIP_LOG_ERROR; - } else if ((level&ORTP_WARNING) != 0) { + } + if ((level&ORTP_WARNING) != 0) { belle_sip_level = BELLE_SIP_LOG_WARNING; - } else if ((level&ORTP_MESSAGE) != 0) { - belle_sip_level = BELLE_SIP_LOG_MESSAGE; - } else if (((level&ORTP_DEBUG) != 0) || ((level&ORTP_TRACE) != 0)) { - belle_sip_level = BELLE_SIP_LOG_DEBUG; - } else { - //well, this should never occurs but... + } + if ((level&ORTP_MESSAGE) != 0) { belle_sip_level = BELLE_SIP_LOG_MESSAGE; } + if (((level&ORTP_DEBUG) != 0) || ((level&ORTP_TRACE) != 0)) { + belle_sip_level = BELLE_SIP_LOG_DEBUG; + } + belle_sip_set_log_level(belle_sip_level); } +static BctbxLogFunc _belle_sip_log_handler = bctbx_logv_out; +void sal_set_log_handler(BctbxLogFunc log_handler) { + _belle_sip_log_handler = log_handler; + belle_sip_set_log_handler(log_handler); +} void sal_add_pending_auth(Sal *sal, SalOp *op){ if (bctbx_list_find(sal->pending_auths,op)==NULL){ sal->pending_auths=bctbx_list_append(sal->pending_auths,op); @@ -505,7 +487,7 @@ Sal * sal_init(MSFactory *factory){ sal->auto_contacts=TRUE; sal->factory = factory; /*first create the stack, which initializes the belle-sip object's pool for this thread*/ - belle_sip_set_log_handler(_belle_sip_log); + belle_sip_set_log_handler(_belle_sip_log_handler); //printf by default sal->stack = belle_sip_stack_new(NULL); sal->user_agent=belle_sip_header_user_agent_new(); diff --git a/coreapi/help/examples/C/CMakeLists.txt b/coreapi/help/examples/C/CMakeLists.txt index af59a648a..84a5b38d5 100644 --- a/coreapi/help/examples/C/CMakeLists.txt +++ b/coreapi/help/examples/C/CMakeLists.txt @@ -29,7 +29,7 @@ if (ENABLE_TOOLS) string(REPLACE ".c" "" EXECUTABLE_NAME ${EXECUTABLE}) bc_apply_compile_flags(${EXECUTABLE} STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(${EXECUTABLE_NAME} ${USE_BUNDLE} ${EXECUTABLE}) - target_link_libraries(${EXECUTABLE_NAME} ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES}) + target_link_libraries(${EXECUTABLE_NAME} ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") if (NOT IOS) install(TARGETS ${EXECUTABLE_NAME} diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 28972673c..bf99af464 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -468,7 +468,9 @@ void linphone_core_set_log_handler(OrtpLogFunc logfunc) { void linphone_core_set_log_file(FILE *file) { if (file == NULL) file = stdout; - ortp_set_log_file(file); + bctbx_set_log_file(file); /*gather everythings*/ + sal_set_log_handler(NULL); /*disable default log handler*/ + ortp_set_log_handler(NULL); /*disable default log handler*/ } void linphone_core_set_log_level(OrtpLogLevel loglevel) { @@ -497,15 +499,13 @@ void linphone_core_set_log_level(OrtpLogLevel loglevel) { } void linphone_core_set_log_level_mask(unsigned int loglevel) { - ortp_set_log_level_mask(NULL, loglevel); - bctbx_set_log_level_mask(NULL, loglevel); - if (loglevel == 0) { - sal_disable_log(); - } else { - sal_enable_log(); - } + //we only have 2 domain for now ortp and belle-sip + bctbx_set_log_level_mask(ORTP_LOG_DOMAIN, loglevel); + sal_set_log_level((OrtpLogLevel)loglevel); +} +unsigned int linphone_core_get_log_level_mask(void) { + return bctbx_get_log_level_mask(ORTP_LOG_DOMAIN); } - static int _open_log_collection_file_with_idx(int idx) { struct stat statbuf; char *log_filename; diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 1975363c2..61178d119 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -119,7 +119,7 @@ target_link_libraries(linphone-daemon ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER set_target_properties(linphone-daemon PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") add_executable(linphone-daemon-pipetest ${DAEMON_PIPETEST_SOURCE_FILES}) -target_link_libraries(linphone-daemon-pipetest ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES}) +target_link_libraries(linphone-daemon-pipetest ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(linphone-daemon-pipetest PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(INSTALL_TARGETS linphone-daemon linphone-daemon-pipetest) diff --git a/include/linphone/core.h b/include/linphone/core.h index 6fc0bb029..01483b3c9 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -803,6 +803,14 @@ LINPHONE_PUBLIC void linphone_core_set_log_level(OrtpLogLevel loglevel); */ LINPHONE_PUBLIC void linphone_core_set_log_level_mask(unsigned int loglevel); +/** + * Get defined log level mask. + * + * @return The loglevel parameter is a bitmask parameter. Therefore to enable only warning and error + * messages, use ORTP_WARNING | ORTP_ERROR. To disable logs, simply set loglevel to 0. + */ +LINPHONE_PUBLIC unsigned int linphone_core_get_log_level_mask(void); + /** * Enable logs in supplied FILE*. * @param file a C FILE* where to fprintf logs. If null stdout is used. diff --git a/include/sal/sal.h b/include/sal/sal.h index f41c09336..1cabcb5fa 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -148,6 +148,8 @@ const char *sal_address_get_header(const SalAddress *addr, const char *name); LINPHONE_PUBLIC Sal * sal_init(MSFactory *factory); LINPHONE_PUBLIC void sal_uninit(Sal* sal); + +void sal_set_log_handler(BctbxLogFunc log_handler); void sal_set_user_pointer(Sal *sal, void *user_data); void *sal_get_user_pointer(const Sal *sal); diff --git a/tester/accountmanager.c b/tester/accountmanager.c index 385717ed2..26ebd3f75 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -259,7 +259,7 @@ static LinphoneAddress *account_manager_check_account(AccountManager *m, Linphon void linphone_core_manager_check_accounts(LinphoneCoreManager *m){ const bctbx_list_t *it; AccountManager *am=account_manager_get(); - int logmask = ortp_get_log_level_mask(NULL); + int logmask = linphone_core_get_log_level_mask(); if (!liblinphonetester_show_account_manager_logs) linphone_core_set_log_level_mask(ORTP_ERROR|ORTP_FATAL); for(it=linphone_core_get_proxy_config_list(m->lc);it!=NULL;it=it->next){ diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 3626150a4..4857b5855 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -195,8 +195,7 @@ int liblinphone_tester_set_log_file(const char *filename) { return -1; } ms_message("Redirecting traces to file [%s]", filename); - bctbx_set_log_file(log_file); - ortp_set_log_file(log_file); + linphone_core_set_log_file(log_file); return 0; } diff --git a/tester/register_tester.c b/tester/register_tester.c index 6989c8b1c..c8f899b2e 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -684,6 +684,11 @@ static void proxy_transport_change(void){ linphone_core_manager_destroy(lcm); } +/* + * On ios, some firewal require to disable flow label (livebox with default firewall level). + * sudo sysctl net.inet6.ip6.auto_flowlabel=0 + * It might be possible to found a sockopt for such purpose. + */ static void proxy_transport_change_with_wrong_port(void) { LinphoneCoreManager* lcm = create_lcm(); stats* counters = &lcm->stat; diff --git a/tester/tester.c b/tester/tester.c index 9e4f2c10e..996c99f81 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -461,7 +461,7 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){ } void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { - int old_log_level = ortp_get_log_level_mask(NULL); + int old_log_level = linphone_core_get_log_level_mask(); linphone_core_set_log_level(ORTP_ERROR); if (mgr->phone_alias) { ms_free(mgr->phone_alias); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f26b5491f..fdc797c02 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -33,7 +33,7 @@ endif() set(LP_AUTO_ANSWER_SOURCE_FILES auto_answer.c) bc_apply_compile_flags(LP_AUTO_ANSWER_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(lp-auto-answer ${USE_BUNDLE} ${LP_AUTO_ANSWER_SOURCE_FILES}) -target_link_libraries(lp-auto-answer ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_LIBRARIES}) +target_link_libraries(lp-auto-answer ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(lp-auto-answer PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(LP_SENDMSG_SOURCE_FILES lpsendmsg.c) @@ -57,7 +57,7 @@ set_target_properties(xml2lpc_test PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(LP_TEST_ECC_SOURCE_FILES test_ecc.c) bc_apply_compile_flags(LP_TEST_ECC_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(lp-test-ecc ${USE_BUNDLE} ${LP_TEST_ECC_SOURCE_FILES}) -target_link_libraries(lp-test-ecc ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${MEDIASTREAMER2_LIBRARIES}) +target_link_libraries(lp-test-ecc ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${MEDIASTREAMER2_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(lp-test-ecc PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") if (NOT IOS) From 5f9b2481d6d1e6e820b19f215ca1acf66e335d1b Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 23 Aug 2017 09:59:19 +0200 Subject: [PATCH 20/49] Fixed Myanmar dialplan --- coreapi/dial_plan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreapi/dial_plan.c b/coreapi/dial_plan.c index 85c652fe8..31f60bbc0 100644 --- a/coreapi/dial_plan.c +++ b/coreapi/dial_plan.c @@ -168,7 +168,7 @@ static LinphoneDialPlan const dial_plans[]={ {"Montserrat" ,"MS" , "664" , 10 , "011" }, {"Morocco" ,"MA" , "212" , 9 , "00" }, {"Mozambique" ,"MZ" , "258" , 9 , "00" }, - {"Myanmar" ,"MM" , "95" , 8 , "00" }, + {"Myanmar" ,"MM" , "95" , 10 , "00" }, {"Namibia" ,"NA" , "264" , 9 , "00" }, {"Nauru" ,"NR" , "674" , 7 , "00" }, {"Nepal" ,"NP" , "43" , 10 , "00" }, From e25d0c3efaa0c5fa365044421cb5571f1b3a1b16 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 23 Aug 2017 11:56:46 +0200 Subject: [PATCH 21/49] fix FindSoci.cmake --- cmake/FindSoci.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/FindSoci.cmake b/cmake/FindSoci.cmake index 35846f5d0..91c4e376d 100644 --- a/cmake/FindSoci.cmake +++ b/cmake/FindSoci.cmake @@ -29,8 +29,7 @@ SET(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIRS SOCI_LIBRARIES) # ### FIRST STEP: Find the soci headers. # -FIND_PATH(SOCI_INCLUDE_DIRS soci.h - PATH_SUFFIXES "soci" +FIND_PATH(SOCI_INCLUDE_DIRS soci/soci.h DOC "Soci (http://soci.sourceforge.net) include directory") MARK_AS_ADVANCED(SOCI_INCLUDE_DIRS) From 0399162c4c6e778c73e549e49aba7e364234d148 Mon Sep 17 00:00:00 2001 From: Brieuc Viel Date: Wed, 23 Aug 2017 12:01:01 +0200 Subject: [PATCH 22/49] [FriendsImpl] update java wrapper to add function getVcardToString from friend --- coreapi/linphonecore_jni.cc | 9 +++++++++ java/common/org/linphone/core/LinphoneFriend.java | 6 ++++++ java/impl/org/linphone/core/LinphoneCoreImpl.java | 2 +- java/impl/org/linphone/core/LinphoneFriendImpl.java | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 2a684c8b7..c6f063c54 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -4284,6 +4284,15 @@ extern "C" jobject Java_org_linphone_core_LinphoneFriendImpl_getCore(JNIEnv* en return NULL; } +extern "C" jstring Java_org_linphone_core_LinphoneFriendImpl_getVcardToString(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + LinphoneFriend *lf = (LinphoneFriend*)ptr; + LinphoneVcard *lvc = linphone_friend_get_vcard(lf); + const char* vcard = linphone_vcard_as_vcard4_string(lvc); + return vcard ? env->NewStringUTF(vcard) : NULL; +} + extern "C" jobject Java_org_linphone_core_LinphoneFriendListImpl_getCore(JNIEnv* env ,jobject thiz ,jlong ptr) { diff --git a/java/common/org/linphone/core/LinphoneFriend.java b/java/common/org/linphone/core/LinphoneFriend.java index a9c2d9979..07b582979 100644 --- a/java/common/org/linphone/core/LinphoneFriend.java +++ b/java/common/org/linphone/core/LinphoneFriend.java @@ -165,6 +165,12 @@ public interface LinphoneFriend { * @return The reference key of the friend. **/ String getRefKey(); + +/** + * return a the string value of the vcard corresponding to the given friend + */ + String getVcardToString(); + /** * Set a name for this friend * @param name diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 2d5ed151c..671fb1fcc 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -195,7 +195,7 @@ class LinphoneCoreImpl implements LinphoneCore { private native Object createFriend(long nativePtr); private native Object createFriendWithAddress(long nativePtr, String address); private native int getIncomingTimeout(long nativePtr); - + LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig, File factoryConfig, Object userdata) throws IOException { mListener = listener; String user = userConfig == null ? null : userConfig.getCanonicalPath(); diff --git a/java/impl/org/linphone/core/LinphoneFriendImpl.java b/java/impl/org/linphone/core/LinphoneFriendImpl.java index 6aa92bda6..1aa3c4f26 100644 --- a/java/impl/org/linphone/core/LinphoneFriendImpl.java +++ b/java/impl/org/linphone/core/LinphoneFriendImpl.java @@ -40,6 +40,7 @@ public class LinphoneFriendImpl implements LinphoneFriend, Serializable { private native Object getCore(long ptr); private native void setRefKey(long nativePtr, String key); private native String getRefKey(long nativePtr); + private native String getVcardToString(long nativePtr); private Object userdData; public Object getUserData() { @@ -141,6 +142,12 @@ public class LinphoneFriendImpl implements LinphoneFriend, Serializable { public String getRefKey(){ return getRefKey(nativePtr); } + + + public synchronized String getVcardToString() { + return getVcardToString(nativePtr); + } + private native void setName(long nativePtr, String name); @Override From 6df37d30f90a4a768acb3c45f4172f8eb0a61e9f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 23 Aug 2017 15:53:50 +0200 Subject: [PATCH 23/49] feat(EventsDb): provide interface --- src/db/abstract/abstract-db.cpp | 4 +- src/db/events-db.cpp | 97 +++++++++++++++++++++---- src/db/events-db.h | 24 +++++- src/db/provider/db-session-p.h | 17 ++--- src/db/provider/db-session-provider.cpp | 48 ++++++------ src/db/provider/db-session.cpp | 15 ++++ src/db/provider/db-session.h | 45 +++++++++++- src/utils/general.h | 3 +- 8 files changed, 198 insertions(+), 55 deletions(-) diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index 63e2fcef4..39101ff00 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -34,8 +34,8 @@ bool AbstractDb::connect (Backend backend, const string ¶meters) { L_D(AbstractDb); d->dbSession = DbSessionProvider::getInstance()->getSession( - (backend == Mysql ? "mysql://" : "sqlite3://") + parameters - ); + (backend == Mysql ? "mysql://" : "sqlite3://") + parameters + ); if (d->dbSession) init(); diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 8a949c0e8..82431fa0a 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -16,17 +16,21 @@ * along with this program. If not, see . */ +#ifdef SOCI_ENABLED + #include +#endif // ifdef SOCI_ENABLED + #include "abstract/abstract-db-p.h" +#include "event/call-event.h" +#include "event/event.h" +#include "event/message-event.h" #include "events-db.h" -// TODO: Remove me. -#ifdef SOCI_ENABLED - #undef SOCI_ENABLED -#endif - // ============================================================================= +using namespace std; + LINPHONE_BEGIN_NAMESPACE class EventsDbPrivate : public AbstractDbPrivate {}; @@ -37,34 +41,34 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} void EventsDb::init () { #ifdef SOCI_ENABLED - L_D(EventsDb); + soci::session *session = d->dbSession.getBackendSession(); - d->session << + *session << "CREATE TABLE IF NOT EXISTS sip_address (" " id" + primaryKeyAutoIncrementStr() + "," " value VARCHAR(255) NOT NULL" ")"; - d->session << + *session << "CREATE TABLE IF NOT EXISTS event (" " id" + primaryKeyAutoIncrementStr() + "," " timestamp TIMESTAMP NOT NULL" ")"; - d->session << + *session << "CREATE TABLE IF NOT EXISTS message_status (" " id" + primaryKeyAutoIncrementStr() + "," " status VARCHAR(255) NOT NULL" ")"; - d->session << + *session << "CREATE TABLE IF NOT EXISTS message_direction (" " id" + primaryKeyAutoIncrementStr() + "," " direction VARCHAR(255) NOT NULL" ")"; - d->session << + *session << "CREATE TABLE IF NOT EXISTS dialog (" " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. @@ -78,7 +82,7 @@ void EventsDb::init () { " ON DELETE CASCADE" ")"; - d->session << + *session << "CREATE TABLE IF NOT EXISTS message_event (" " id" + primaryKeyAutoIncrementStr() + "," " dialog_id BIGINT UNSIGNED NOT NULL," @@ -99,7 +103,74 @@ void EventsDb::init () { " ON DELETE CASCADE" ")"; - #endif // ifndef SOCI_ENABLED + #endif // ifdef SOCI_ENABLED +} + +// ----------------------------------------------------------------------------- + +bool EventsDb::addEvent (const Event &event) { + // TODO. + switch (event.getType()) { + case Event::None: + return false; + case Event::MessageEvent: + case Event::CallStartEvent: + case Event::CallEndEvent: + break; + } + + return true; +} + +bool EventsDb::deleteEvent (const Event &event) { + // TODO. + (void)event; + return true; +} + +void EventsDb::cleanEvents (FilterMask mask) { + // TODO. + (void)mask; +} + +int EventsDb::getEventsCount (FilterMask mask) { + // TODO. + (void)mask; + return 0; +} + +int EventsDb::getMessagesCount (const string &remoteAddress) { + // TODO. + (void)remoteAddress; + return 0; +} + +int EventsDb::getUnreadMessagesCount (const string &remoteAddress) { + // TODO. + (void)remoteAddress; + return 0; +} + +list EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) { + // TODO. + (void)remoteAddress; + (void)nLast; + (void)mask; + return list(); +} + +list EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) { + // TODO. + (void)remoteAddress; + (void)begin; + (void)end; + (void)mask; + return list(); +} + +void EventsDb::cleanHistory (const string &remoteAddress) { + // TODO. + (void)remoteAddress; } LINPHONE_END_NAMESPACE diff --git a/src/db/events-db.h b/src/db/events-db.h index 3cd201a25..1c77af3a9 100644 --- a/src/db/events-db.h +++ b/src/db/events-db.h @@ -19,6 +19,8 @@ #ifndef _EVENTS_DB_H_ #define _EVENTS_DB_H_ +#include + #include "abstract/abstract-db.h" // ============================================================================= @@ -30,9 +32,29 @@ class EventsDbPrivate; class LINPHONE_PUBLIC EventsDb : public AbstractDb { public: + enum Filter { + NoFilter = 0x0, + MessageFilter = 0x1, + CallFilter = 0x2, + ConferenceFilter = 0x4 + }; + + typedef int FilterMask; + EventsDb (); - bool writeEvent (const Event &event); + // Generic. + bool addEvent (const Event &event); + bool deleteEvent (const Event &event); + void cleanEvents (FilterMask mask = NoFilter); + int getEventsCount (FilterMask mask = NoFilter); + + // Messages, calls and conferences. + int getMessagesCount (const std::string &remoteAddress); + int getUnreadMessagesCount (const std::string &remoteAddress); + std::list getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter); + std::list getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter); + void cleanHistory (const std::string &remoteAddress); protected: void init () override; diff --git a/src/db/provider/db-session-p.h b/src/db/provider/db-session-p.h index 597ceaa44..de9e9b5da 100644 --- a/src/db/provider/db-session-p.h +++ b/src/db/provider/db-session-p.h @@ -19,32 +19,25 @@ #ifndef _DB_SESSION_P_H_ #define _DB_SESSION_P_H_ -#ifdef SOCI_ENABLED - #include -#endif // ifdef SOCI_ENABLED +#include #include "db-session.h" #include "object/clonable-object-p.h" // ============================================================================= -#ifdef SOCI_ENABLED - namespace soci { - class session; - } -#endif // ifdef SOCI_ENABLED - LINPHONE_BEGIN_NAMESPACE +// ----------------------------------------------------------------------------- + class DbSessionPrivate : public ClonableObjectPrivate { friend class DbSessionProvider; private: bool isValid = false; - #ifdef SOCI_ENABLED - std::shared_ptr session; - #endif // ifndef SOCI_ENABLED + DbSession::Type type = DbSession::None; + std::shared_ptr backendSession; L_DECLARE_PUBLIC(DbSession); }; diff --git a/src/db/provider/db-session-provider.cpp b/src/db/provider/db-session-provider.cpp index 04c8bb98e..35dc9c82c 100644 --- a/src/db/provider/db-session-provider.cpp +++ b/src/db/provider/db-session-provider.cpp @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -#ifdef SOCI_ENABLED - #include +#include +#ifdef SOCI_ENABLED #include #endif // ifdef SOCI_ENABLED @@ -37,45 +37,45 @@ LINPHONE_BEGIN_NAMESPACE class DbSessionProviderPrivate : public ObjectPrivate { public: - #ifdef SOCI_ENABLED - typedef pair, DbSessionPrivate *> InternalSession; - unordered_map sessions; - #endif // ifdef SOCI_ENABLED - + typedef pair, DbSessionPrivate *> InternalSession; + unordered_map sessions; int cleanCounter = 0; }; DbSessionProvider::DbSessionProvider () : Singleton(*new DbSessionProviderPrivate) {} DbSession DbSessionProvider::getSession (const string &uri) { - DbSession session; + L_D(DbSessionProvider); #ifdef SOCI_ENABLED - L_D(DbSessionProvider); + DbSession session(DbSession::Soci); try { - shared_ptr sociSession = d->sessions[uri].first.lock(); - if (!sociSession) { // Create new session. - sociSession = make_shared(uri); + shared_ptr backendSession = d->sessions[uri].first.lock(); + ++d->cleanCounter; + if (!backendSession) { // Create new session. + backendSession = make_shared(uri); DbSessionPrivate *p = session.getPrivate(); - p->session = sociSession; + p->backendSession = backendSession; p->isValid = true; - d->sessions[uri] = make_pair(sociSession, p); + d->sessions[uri] = make_pair(backendSession, p); } else // Share session. session.setRef(*d->sessions[uri].second); } catch (const exception &) {} + #else + DbSession session(DbSession::None); + #endif // ifdef SOCI_ENABLED - // Remove invalid weak ptrs. - if (++d->cleanCounter >= CLEAN_COUNTER_MAX) { - d->cleanCounter = 0; + // Remove invalid weak ptrs. + if (d->cleanCounter >= CLEAN_COUNTER_MAX) { + d->cleanCounter = 0; - for (auto it = d->sessions.begin(), itEnd = d->sessions.end(); it != itEnd;) { - if (it->second.first.expired()) - it = d->sessions.erase(it); - else - ++it; - } + for (auto it = d->sessions.begin(), itEnd = d->sessions.end(); it != itEnd;) { + if (it->second.first.expired()) + it = d->sessions.erase(it); + else + ++it; } - #endif // ifndef SOCI_ENABLED + } return session; } diff --git a/src/db/provider/db-session.cpp b/src/db/provider/db-session.cpp index ac1f85d52..f074804b3 100644 --- a/src/db/provider/db-session.cpp +++ b/src/db/provider/db-session.cpp @@ -26,6 +26,11 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE +DbSession::DbSession (Type type) : ClonableObject(*new DbSessionPrivate) { + L_D(DbSession); + d->type = type; +} + L_USE_DEFAULT_SHARE_IMPL(DbSession, ClonableObject); DbSession::operator bool () const { @@ -33,4 +38,14 @@ DbSession::operator bool () const { return d->isValid; } +DbSession::Type DbSession::getBackendType () const { + L_D(const DbSession); + return d->type; +} + +void *DbSession::getBackendSession () const { + L_D(const DbSession); + return d->backendSession.get(); +} + LINPHONE_END_NAMESPACE diff --git a/src/db/provider/db-session.h b/src/db/provider/db-session.h index 35eb6fe59..ac8a0582e 100644 --- a/src/db/provider/db-session.h +++ b/src/db/provider/db-session.h @@ -25,6 +25,12 @@ // ============================================================================= +#ifdef SOCI_ENABLED + namespace soci { + class session; + } +#endif // ifdef SOCI_ENABLED + LINPHONE_BEGIN_NAMESPACE class DbSessionPrivate; @@ -33,17 +39,54 @@ class DbSession : public ClonableObject { friend class DbSessionProvider; public: - DbSession (); + enum Type { + None, + Soci + }; + + DbSession (Type type = None); DbSession (const DbSession &src); DbSession &operator= (const DbSession &src); operator bool () const; + Type getBackendType () const; + + template + T *getBackendSession () const; + private: + void *getBackendSession () const; + L_DECLARE_PRIVATE(DbSession); }; +// ----------------------------------------------------------------------------- + +template +struct TypeOfDbSession { + static const DbSession::Type type = DbSession::None; +}; + +#ifdef SOCI_ENABLED + + template<> + struct TypeOfDbSession<::soci::session> { + static const DbSession::Type type = DbSession::Soci; + }; + +#endif // ifdef SOCI_ENABLED + +template +T *DbSession::getBackendSession () const { + typedef TypeOfDbSession Type; + static_assert(Type::type != DbSession::None, "Unable to get backend session, invalid type."); + if (getBackendType() != Type::type) + return nullptr; + return static_cast(getBackendSession()); +} + LINPHONE_END_NAMESPACE #endif // ifndef _DB_SESSION_H_ diff --git a/src/utils/general.h b/src/utils/general.h index 7f46799b8..243c7a7ca 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -110,8 +110,7 @@ inline const Object *getPublicHelper (const T *object, const ObjectPrivate *) { #define L_Q(CLASS) CLASS * const q = getPublic(); #define L_USE_DEFAULT_SHARE_IMPL(CLASS, PARENT_CLASS) \ - CLASS::CLASS () : PARENT_CLASS(*new CLASS ## Private) {} \ - CLASS::CLASS (const CLASS &src) : ClonableObject(*src.getPrivate()) {} \ + CLASS::CLASS (const CLASS &src) : PARENT_CLASS(*src.getPrivate()) {} \ CLASS &CLASS::operator= (const CLASS &src) { \ if (this != &src) \ setRef(*src.getPrivate()); \ From a399cb0579127f55293f9b15572e42054d37e769 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Wed, 23 Aug 2017 17:07:54 +0200 Subject: [PATCH 24/49] Fix C# wrapper for UWP --- wrappers/csharp/genwrapper.py | 58 ++++++++++++++++----------- wrappers/csharp/wrapper_impl.mustache | 58 ++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 25 deletions(-) diff --git a/wrappers/csharp/genwrapper.py b/wrappers/csharp/genwrapper.py index 84dd66dd9..2bf303cf6 100644 --- a/wrappers/csharp/genwrapper.py +++ b/wrappers/csharp/genwrapper.py @@ -1,17 +1,17 @@ #!/usr/bin/python # 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 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. @@ -58,7 +58,7 @@ class CsharpTranslator(object): def translate_method_name(self, name, recursive=False, topAncestor=None): translatedName = name.to_camel_case(lower=True) - + if name.prev is None or not recursive or name.prev is topAncestor: return translatedName @@ -129,7 +129,7 @@ class CsharpTranslator(object): return False if dllImport else True elif type(_type) is AbsApi.EnumType: return False if dllImport else True - + def translate_type(self, _type, isArg, dllImport=True): if type(_type) is AbsApi.EnumType: if dllImport and isArg: @@ -156,10 +156,10 @@ class CsharpTranslator(object): raise AbsApi.Error('translation of bctbx_list_t of enums') else: raise AbsApi.Error('translation of bctbx_list_t of unknow type !') - + def translate_argument(self, arg, dllImport=True): return '{0} {1}'.format(self.translate_type(arg.type, True, dllImport), self.translate_argument_name(arg.name)) - + def throws_exception(self, return_type): if type(return_type) is AbsApi.BaseType: if return_type.name == 'status': @@ -178,7 +178,7 @@ class CsharpTranslator(object): if arg is not method.args[0] or not static: methodElems['params'] += ', ' methodElems['params'] += self.translate_argument(arg) - + methodDict = {} methodDict['prototype'] = "static extern {return} {name}({params});".format(**methodElems) @@ -235,7 +235,7 @@ class CsharpTranslator(object): methodDict['impl']['args'] += self.translate_argument(arg, False) return methodDict - + ########################################################################################################################################### def translate_property_getter(self, prop, name, static=False): @@ -311,7 +311,7 @@ class CsharpTranslator(object): methodDict['setter_c_name'] = methodDictSet['setter_c_name'] return methodDict - + def translate_property(self, prop): res = [] name = prop.name.to_camel_case() @@ -323,7 +323,7 @@ class CsharpTranslator(object): elif prop.setter is not None: res.append(self.translate_property_setter(prop.setter, name)) return res - + ########################################################################################################################################### def translate_listener(self, _class, method): @@ -350,7 +350,7 @@ class CsharpTranslator(object): listenerDict['delegate']['interfaceClassName'] = listenedClass.name.to_camel_case() listenerDict['delegate']['isSimpleListener'] = not listenedClass.multilistener listenerDict['delegate']['isMultiListener'] = listenedClass.multilistener - + listenerDict['delegate']['params_public'] = "" listenerDict['delegate']['params_private'] = "" listenerDict['delegate']['params'] = "" @@ -378,7 +378,7 @@ class CsharpTranslator(object): else: listenerDict['delegate']['first_param'] = argName listenerDict['delegate']['params'] = 'thiz' - + listenerDict['delegate']['params_public'] += normalType + " " + argName listenerDict['delegate']['params_private'] += dllImportType + " " + argName @@ -434,7 +434,7 @@ class CsharpTranslator(object): methodDict['is_generic'] = True return methodDict - + ########################################################################################################################################### def translate_enum(self, enum): @@ -470,6 +470,8 @@ class CsharpTranslator(object): classDict = {} classDict['className'] = _class.name.to_camel_case() classDict['isLinphoneFactory'] = _class.name.to_camel_case() == "Factory" + classDict['isLinphoneCall'] = _class.name.to_camel_case() == "Call" + classDict['isLinphoneCore'] = _class.name.to_camel_case() == "Core" classDict['doc'] = self.docTranslator.translate(_class.briefDescription) classDict['dllImports'] = [] @@ -482,12 +484,12 @@ class CsharpTranslator(object): else: classDict['dllImports'].append(self.generate_add_for_listener_callbacks(_class, listenerName)) classDict['dllImports'].append(self.generate_remove_for_listener_callbacks(_class, listenerName)) - + for method in _class.classMethods: try: if 'get' in method.name.to_word_list(): methodDict = self.translate_property_getter(method, method.name.to_camel_case(), True) - #The following doesn't work because there a at least one method that has both getter and setter, + #The following doesn't work because there a at least one method that has both getter and setter, #and because it doesn't do both of them at once, property is declared twice #elif 'set' in method.name.to_word_list(): # methodDict = self.translate_property_setter(method, method.name.to_camel_case(), True) @@ -521,7 +523,7 @@ class CsharpTranslator(object): interfaceDict['methods'] = [] for method in interface.methods: interfaceDict['methods'].append(self.translate_listener(interface, method)) - + return interfaceDict ########################################################################################################################################### @@ -549,7 +551,7 @@ class WrapperImpl(object): self.enums = enums self.interfaces = interfaces self.classes = classes - + ########################################################################################################################################### def render(renderer, item, path): @@ -569,21 +571,29 @@ def main(): argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.') argparser.add_argument('-n --name', type=str, help='the name of the genarated source file', dest='outputfile', default='LinphoneWrapper.cs') args = argparser.parse_args() - + entries = os.listdir(args.outputdir) - + project = CApi.Project() project.initFromDir(args.xmldir) project.check() - + parser = AbsApi.CParser(project) - parser.functionBl = ['linphone_vcard_get_belcard', 'linphone_core_get_current_vtable'] + parser.functionBl = \ + ['linphone_vcard_get_belcard',\ + 'linphone_core_get_current_vtable',\ + 'linphone_call_set_native_video_window_id',\ + 'linphone_call_get_native_video_window_id',\ + 'linphone_core_get_native_preview_window_id',\ + 'linphone_core_set_native_preview_window_id',\ + 'linphone_core_set_native_video_window_id',\ + 'linphone_core_get_native_video_window_id'] parser.classBl += 'LinphoneCoreVTable' parser.methodBl.remove('getCurrentCallbacks') parser.parse_all() translator = CsharpTranslator() renderer = pystache.Renderer() - + enums = [] for item in parser.enumsIndex.items(): if item[1] is not None: @@ -610,4 +620,4 @@ def main(): render(renderer, wrapper, args.outputdir + "/" + args.outputfile) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/wrappers/csharp/wrapper_impl.mustache b/wrappers/csharp/wrapper_impl.mustache index f99438889..b281a5f80 100644 --- a/wrappers/csharp/wrapper_impl.mustache +++ b/wrappers/csharp/wrapper_impl.mustache @@ -376,6 +376,62 @@ namespace Linphone return fromNativePtr(coreCbsPtr, false); } {{/isLinphoneFactory}} + {{#isLinphoneCall}} + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern IntPtr linphone_call_get_native_video_window_id(IntPtr thiz); + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern void linphone_call_set_native_video_window_id(IntPtr thiz, IntPtr id); + + /// Get the native window handle of the video window, casted as an unsigned long. + public string NativeVideoWindowId + { + get + { + return Marshal.PtrToStringUni(linphone_call_get_native_video_window_id(nativePtr)); + } + set + { + linphone_call_set_native_video_window_id(nativePtr, Marshal.StringToHGlobalUni(value)); + } + } + {{/isLinphoneCall}} + {{#isLinphoneCore}} + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern IntPtr linphone_core_get_native_video_window_id(IntPtr thiz); + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern void linphone_core_set_native_video_window_id(IntPtr thiz, IntPtr id); + + /// Get the native window handle of the video window. + public string NativeVideoWindowId + { + get + { + return Marshal.PtrToStringUni(linphone_core_get_native_video_window_id(nativePtr)); + } + set + { + linphone_core_set_native_video_window_id(nativePtr, Marshal.StringToHGlobalUni(value)); + } + } + + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern IntPtr linphone_core_get_native_preview_window_id(IntPtr thiz); + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern void linphone_core_set_native_preview_window_id(IntPtr thiz, IntPtr id); + + /// Get the native window handle of the video preview window. + public string NativePreviewWindowId + { + get + { + return Marshal.PtrToStringUni(linphone_core_get_native_preview_window_id(nativePtr)); + } + set + { + linphone_core_set_native_preview_window_id(nativePtr, Marshal.StringToHGlobalUni(value)); + } + } + {{/isLinphoneCore}} {{#dllImports}} [DllImport(LinphoneWrapper.LIB_NAME)] {{{prototype}}} @@ -400,7 +456,7 @@ namespace Linphone return Marshal.PtrToStringAnsi(stringPtr); {{/is_string}} {{#is_bool}} - return {{getter_c_name}}({{getter_nativePtr}}) == 1; + return {{getter_c_name}}({{getter_nativePtr}}) != 0; {{/is_bool}} {{#is_class}} IntPtr ptr = {{getter_c_name}}({{getter_nativePtr}}); From abf91b0648be40fb2bcb407fe75a28619f0527bc Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Wed, 23 Aug 2017 17:08:37 +0200 Subject: [PATCH 25/49] Fix function linphone_video_definition_equals --- coreapi/video_definition.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/coreapi/video_definition.c b/coreapi/video_definition.c index 57329d154..d193d0363 100644 --- a/coreapi/video_definition.c +++ b/coreapi/video_definition.c @@ -101,8 +101,9 @@ void linphone_video_definition_set_name(LinphoneVideoDefinition *vdef, const cha } bool_t linphone_video_definition_equals(const LinphoneVideoDefinition *vdef1, const LinphoneVideoDefinition *vdef2) { - return (((vdef1->width == vdef2->width) && (vdef1->height == vdef2->height)) - || ((vdef1->width == vdef2->height) && (vdef1->height == vdef2->width))); + return ((vdef1 != NULL && vdef2 != NULL) + && (((vdef1->width == vdef2->width) && (vdef1->height == vdef2->height)) + || ((vdef1->width == vdef2->height) && (vdef1->height == vdef2->width)))); } bool_t linphone_video_definition_strict_equals(const LinphoneVideoDefinition *vdef1, const LinphoneVideoDefinition *vdef2) { From a322fb9a4273aa1ae2f9a4afff70adcc13b6bbf6 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 23 Aug 2017 18:06:07 +0200 Subject: [PATCH 26/49] feat(EventsDb): impl `getEventsCount` --- src/db/events-db.cpp | 216 ++++++++++++++++++++++++++++++------------- src/db/events-db.h | 10 +- src/logger/logger.h | 6 ++ 3 files changed, 165 insertions(+), 67 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 82431fa0a..e8d0fa857 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -24,6 +24,7 @@ #include "event/call-event.h" #include "event/event.h" #include "event/message-event.h" +#include "logger/logger.h" #include "events-db.h" @@ -39,8 +40,50 @@ class EventsDbPrivate : public AbstractDbPrivate {}; EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} -void EventsDb::init () { - #ifdef SOCI_ENABLED +// ----------------------------------------------------------------------------- +// Helpers. +// ----------------------------------------------------------------------------- + +inline string mapFilterToSqlEvent (EventsDb::Filter filter) { + switch (filter) { + case EventsDb::NoFilter: + break; + case EventsDb::MessageFilter: + return "0"; + case EventsDb::CallFilter: + return "1"; + case EventsDb::ConferenceFilter: + return "2"; + } + + return ""; +} + +static string buildSqlEventFilter (const list &filters, EventsDb::FilterMask mask) { + bool isStart = true; + string sql; + for (const auto &filter : filters) { + if (!(mask & filter)) + continue; + + if (isStart) { + isStart = false; + sql += " WHERE "; + } else + sql += " OR "; + sql += " type = " + mapFilterToSqlEvent(filter); + } + + return sql; +} + +// ----------------------------------------------------------------------------- +// Soci backend. +// ----------------------------------------------------------------------------- + +#ifdef SOCI_ENABLED + + void EventsDb::init () { L_D(EventsDb); soci::session *session = d->dbSession.getBackendSession(); @@ -102,75 +145,124 @@ void EventsDb::init () { " REFERENCES message_direction(id)" " ON DELETE CASCADE" ")"; - - #endif // ifdef SOCI_ENABLED -} - -// ----------------------------------------------------------------------------- - -bool EventsDb::addEvent (const Event &event) { - // TODO. - switch (event.getType()) { - case Event::None: - return false; - case Event::MessageEvent: - case Event::CallStartEvent: - case Event::CallEndEvent: - break; } - return true; -} + bool EventsDb::addEvent (const Event &event) { + // TODO. + switch (event.getType()) { + case Event::None: + return false; + case Event::MessageEvent: + case Event::CallStartEvent: + case Event::CallEndEvent: + break; + } -bool EventsDb::deleteEvent (const Event &event) { - // TODO. - (void)event; - return true; -} + return true; + } -void EventsDb::cleanEvents (FilterMask mask) { - // TODO. - (void)mask; -} + bool EventsDb::deleteEvent (const Event &event) { + // TODO. + (void)event; + return true; + } -int EventsDb::getEventsCount (FilterMask mask) { - // TODO. - (void)mask; - return 0; -} + void EventsDb::cleanEvents (FilterMask mask) { + // TODO. + (void)mask; + } -int EventsDb::getMessagesCount (const string &remoteAddress) { - // TODO. - (void)remoteAddress; - return 0; -} + int EventsDb::getEventsCount (FilterMask mask) const { + L_D(const EventsDb); -int EventsDb::getUnreadMessagesCount (const string &remoteAddress) { - // TODO. - (void)remoteAddress; - return 0; -} + string query = "SELECT COUNT(*) FROM event" + + buildSqlEventFilter({ MessageFilter, CallFilter, ConferenceFilter }, mask); + int count = 0; -list EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) { - // TODO. - (void)remoteAddress; - (void)nLast; - (void)mask; - return list(); -} + L_BEGIN_LOG_EXCEPTION -list EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) { - // TODO. - (void)remoteAddress; - (void)begin; - (void)end; - (void)mask; - return list(); -} + soci::session *session = d->dbSession.getBackendSession(); + *session << query, soci::into(count); -void EventsDb::cleanHistory (const string &remoteAddress) { - // TODO. - (void)remoteAddress; -} + L_END_LOG_EXCEPTION + + return count; + } + + int EventsDb::getMessagesCount (const string &remoteAddress) const { + // TODO. + (void)remoteAddress; + return 0; + } + + int EventsDb::getUnreadMessagesCount (const string &remoteAddress) const { + // TODO. + (void)remoteAddress; + return 0; + } + + list EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) const { + // TODO. + (void)remoteAddress; + (void)nLast; + (void)mask; + return list(); + } + + list EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) const { + // TODO. + (void)remoteAddress; + (void)begin; + (void)end; + (void)mask; + return list(); + } + + void EventsDb::cleanHistory (const string &remoteAddress) { + // TODO. + (void)remoteAddress; + } + +// ----------------------------------------------------------------------------- +// No backend. +// ----------------------------------------------------------------------------- + +#else + + void EventsDb::init () {} + + bool EventsDb::addEvent (const Event &) { + return false; + } + + bool EventsDb::deleteEvent (const Event &) { + return false; + } + + void EventsDb::cleanEvents (FilterMask) {} + + int EventsDb::getEventsCount (FilterMask) const { + return 0; + } + + int EventsDb::getMessagesCount (const string &) const { + return 0; + } + + int EventsDb::getUnreadMessagesCount (const string &) const { + return 0; + } + + list EventsDb::getHistory (const string &, int, FilterMask) const { + return list(); + } + + list EventsDb::getHistory (const string &, int, int, FilterMask) const { + return list(); + } + + void EventsDb::cleanHistory (const string &) {} + +#endif // ifdef SOCI_ENABLED LINPHONE_END_NAMESPACE diff --git a/src/db/events-db.h b/src/db/events-db.h index 1c77af3a9..5a1b1bfb3 100644 --- a/src/db/events-db.h +++ b/src/db/events-db.h @@ -47,13 +47,13 @@ public: bool addEvent (const Event &event); bool deleteEvent (const Event &event); void cleanEvents (FilterMask mask = NoFilter); - int getEventsCount (FilterMask mask = NoFilter); + int getEventsCount (FilterMask mask = NoFilter) const; // Messages, calls and conferences. - int getMessagesCount (const std::string &remoteAddress); - int getUnreadMessagesCount (const std::string &remoteAddress); - std::list getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter); - std::list getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter); + int getMessagesCount (const std::string &remoteAddress) const; + int getUnreadMessagesCount (const std::string &remoteAddress) const; + std::list getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter) const; + std::list getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter) const; void cleanHistory (const std::string &remoteAddress); protected: diff --git a/src/logger/logger.h b/src/logger/logger.h index c3c209c1e..2314a9ea9 100644 --- a/src/logger/logger.h +++ b/src/logger/logger.h @@ -57,4 +57,10 @@ LINPHONE_END_NAMESPACE #define lError() LINPHONE_NAMESPACE::Logger(Logger::Error).getOutput() #define lFatal() LINPHONE_NAMESPACE::Logger(Logger::Fatal).getOutput() +#define L_BEGIN_LOG_EXCEPTION try { + #define L_END_LOG_EXCEPTION \ +} catch (const exception &e) { \ + lWarning() << "Error: " << e.what(); \ +} + #endif // ifndef _LOGGER_H_ From 8d7b79f3bb8ba6428e2c4174bb19033ccf32fd1f Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Thu, 24 Aug 2017 09:26:42 +0200 Subject: [PATCH 27/49] fix output of traces comming from bctbx tester framework --- tester/liblinphone_tester.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 4857b5855..7421a20d0 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -167,9 +167,7 @@ static void log_handler(int lev, const char *fmt, va_list args) { #endif va_end(cap); #endif - if (log_file){ - ortp_logv_out(ORTP_LOG_DOMAIN, lev, fmt, args); - } + bctbx_logv(ORTP_LOG_DOMAIN, lev, fmt, args); } void liblinphone_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) { From 4e7726e9ee6ab4105423e821b08ef82fcc7bc93a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 10:12:12 +0200 Subject: [PATCH 28/49] fix(Message): const in container doesn't work on windows --- src/message/message.cpp | 4 ++-- src/message/message.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/message/message.cpp b/src/message/message.cpp index c3eaff907..c562c2d86 100644 --- a/src/message/message.cpp +++ b/src/message/message.cpp @@ -147,9 +147,9 @@ void Message::setAppdata (const string &appData) { d->appData = appData; } -list > Message::getContents () const { +list > Message::getContents () const { L_D(const Message); - list > contents; + list > contents; for (const auto &content : d->contents) contents.push_back(content); return contents; diff --git a/src/message/message.h b/src/message/message.h index e317269c4..287b6aa81 100644 --- a/src/message/message.h +++ b/src/message/message.h @@ -71,7 +71,7 @@ public: std::string getAppdata () const; void setAppdata (const std::string &appData); - std::list > getContents () const; + std::list > getContents () const; void addContent (const std::shared_ptr &content); void removeContent (const std::shared_ptr &content); From 6162b8a9e718ad6e0d98c1cf215690f6e26cd01f Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 24 Aug 2017 10:46:45 +0200 Subject: [PATCH 29/49] Fixed Cameroon dialplan --- coreapi/dial_plan.c | 2 +- tester/proxy_config_tester.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/coreapi/dial_plan.c b/coreapi/dial_plan.c index 31f60bbc0..327521377 100644 --- a/coreapi/dial_plan.c +++ b/coreapi/dial_plan.c @@ -60,7 +60,7 @@ static LinphoneDialPlan const dial_plans[]={ {"Burkina Faso" ,"BF" , "226" , 8 , "00" }, {"Burundi" ,"BI" , "257" , 8 , "011" }, {"Cambodia" ,"KH" , "855" , 9 , "00" }, - {"Cameroon" ,"CM" , "237" , 8 , "00" }, + {"Cameroon" ,"CM" , "237" , 9 , "00" }, {"Canada" ,"CA" , "1" , 10 , "011" }, {"Cape Verde" ,"CV" , "238" , 7 , "00" }, {"Cayman Islands" ,"KY" , "1" , 10 , "011" }, diff --git a/tester/proxy_config_tester.c b/tester/proxy_config_tester.c index 27c4063f0..c11f352db 100644 --- a/tester/proxy_config_tester.c +++ b/tester/proxy_config_tester.c @@ -132,6 +132,14 @@ static void phone_normalization_with_proxy(void) { BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+5217227718184"), "+5217227718184"); /*this is a mobile phone number */ BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+528127718184"), "+528127718184"); /*this is a landline phone number from Monterrey*/ + // Phone normalization for myanmar dial plans + linphone_proxy_config_set_dial_prefix(proxy, "95"); + BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "9965066691"), "+959965066691"); + + // Phone normalization for cameroon dial plans + linphone_proxy_config_set_dial_prefix(proxy, "237"); + BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "674788175"), "+237674788175"); + linphone_proxy_config_unref(proxy); } From 637be81450ee8d60a2924b47c238aae9814039ec Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Thu, 24 Aug 2017 11:22:34 +0200 Subject: [PATCH 30/49] Fix typo error for CPP compile flags --- tester/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tester/CMakeLists.txt b/tester/CMakeLists.txt index 099c37c2b..60b1ab5e2 100644 --- a/tester/CMakeLists.txt +++ b/tester/CMakeLists.txt @@ -204,7 +204,7 @@ if(APPLE) endif() bc_apply_compile_flags(SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C) -bc_apply_compile_flags(SOURCE_FILES_C_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX) +bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX) bc_apply_compile_flags(SOURCE_FILES_OBJC STRICT_OPTIONS_CPP STRICT_OPTIONS_OBJC) if(MSVC) From 3c70511b7d04c134bb49059c42f6777fc820f9f0 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 12:05:40 +0200 Subject: [PATCH 31/49] feat(EventsDb): impl `getMessagesCount` --- src/db/abstract/abstract-db.cpp | 5 +- src/db/abstract/abstract-db.h | 2 +- src/db/events-db.cpp | 82 ++++++++++++++++++++++++--------- src/db/events-db.h | 6 +-- 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index 39101ff00..81df3a33f 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -18,7 +18,6 @@ #include "abstract-db-p.h" #include "db/provider/db-session-provider.h" -#include "logger/logger.h" #include "abstract-db.h" @@ -60,12 +59,12 @@ void AbstractDb::init () { // ----------------------------------------------------------------------------- -string AbstractDb::primaryKeyAutoIncrementStr () const { +string AbstractDb::primaryKeyAutoIncrementStr (const string &type) const { L_D(const AbstractDb); switch (d->backend) { case Mysql: - return " BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT"; + return type + "UNSIGNED PRIMARY KEY AUTO_INCREMENT"; case Sqlite3: return " INTEGER PRIMARY KEY AUTOINCREMENT"; } diff --git a/src/db/abstract/abstract-db.h b/src/db/abstract/abstract-db.h index 1e54943b2..3eac6971f 100644 --- a/src/db/abstract/abstract-db.h +++ b/src/db/abstract/abstract-db.h @@ -50,7 +50,7 @@ protected: virtual void init (); - std::string primaryKeyAutoIncrementStr () const; + std::string primaryKeyAutoIncrementStr (const std::string &type = "INT") const; private: L_DECLARE_PRIVATE(AbstractDb); diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index e8d0fa857..f9aaf4685 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +#include + #ifdef SOCI_ENABLED #include #endif // ifdef SOCI_ENABLED @@ -44,22 +46,29 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- -inline string mapFilterToSqlEvent (EventsDb::Filter filter) { - switch (filter) { - case EventsDb::NoFilter: - break; - case EventsDb::MessageFilter: - return "0"; - case EventsDb::CallFilter: - return "1"; - case EventsDb::ConferenceFilter: - return "2"; - } - - return ""; +inline constexpr const char *mapFilterToSqlEvent (EventsDb::Filter filter) { + // Ugly. Yes. But constexpr... + return filter == EventsDb::MessageFilter + ? "0" + : (filter == EventsDb::CallFilter + ? "1" + : (filter == EventsDb::ConferenceFilter + ? "2" + : "" + ) + ); } static string buildSqlEventFilter (const list &filters, EventsDb::FilterMask mask) { + L_ASSERT( + find_if(filters.cbegin(), filters.cend(), [](const EventsDb::Filter &filter) { + return filter == EventsDb::NoFilter; + }) == filters.cend() + ); + + if (mask == EventsDb::NoFilter) + return ""; + bool isStart = true; string sql; for (const auto &filter : filters) { @@ -71,7 +80,8 @@ static string buildSqlEventFilter (const list &filters, Events sql += " WHERE "; } else sql += " OR "; - sql += " type = " + mapFilterToSqlEvent(filter); + sql += " event_type_id = "; + sql += mapFilterToSqlEvent(filter); } return sql; @@ -93,28 +103,39 @@ static string buildSqlEventFilter (const list &filters, Events " value VARCHAR(255) NOT NULL" ")"; + *session << + "CREATE TABLE IF NOT EXISTS event_type (" + " id" + primaryKeyAutoIncrementStr("TINYINT") + "," + " value VARCHAR(255) NOT NULL" + ")"; + *session << "CREATE TABLE IF NOT EXISTS event (" " id" + primaryKeyAutoIncrementStr() + "," - " timestamp TIMESTAMP NOT NULL" + " event_type_id TINYINT UNSIGNED NOT NULL," + " timestamp TIMESTAMP NOT NULL," + " FOREIGN KEY (event_type_id)" + " REFERENCES event_type(id)" + " ON DELETE CASCADE" ")"; *session << "CREATE TABLE IF NOT EXISTS message_status (" - " id" + primaryKeyAutoIncrementStr() + "," + " id" + primaryKeyAutoIncrementStr("TINYINT") + "," " status VARCHAR(255) NOT NULL" ")"; *session << "CREATE TABLE IF NOT EXISTS message_direction (" - " id" + primaryKeyAutoIncrementStr() + "," + " id" + primaryKeyAutoIncrementStr("TINYINT") + "," " direction VARCHAR(255) NOT NULL" ")"; *session << "CREATE TABLE IF NOT EXISTS dialog (" - " local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate. - " remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address. + " id" + primaryKeyAutoIncrementStr() + "," + " local_sip_address_id INT UNSIGNED NOT NULL," // Sip address used to communicate. + " remote_sip_address_id INT UNSIGNED NOT NULL," // Server (for conference) or user sip address. " creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date. " last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...). " FOREIGN KEY (local_sip_address_id)" @@ -128,7 +149,7 @@ static string buildSqlEventFilter (const list &filters, Events *session << "CREATE TABLE IF NOT EXISTS message_event (" " id" + primaryKeyAutoIncrementStr() + "," - " dialog_id BIGINT UNSIGNED NOT NULL," + " dialog_id INT UNSIGNED NOT NULL," " status_id TINYINT UNSIGNED NOT NULL," " direction_id TINYINT UNSIGNED NOT NULL," " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 @@ -190,9 +211,24 @@ static string buildSqlEventFilter (const list &filters, Events } int EventsDb::getMessagesCount (const string &remoteAddress) const { - // TODO. - (void)remoteAddress; - return 0; + L_D(const EventsDb); + + string query = "SELECT COUNT(*) FROM message_event" + " WHERE dialog_id = (" + " SELECT id FROM dialog WHERE remote_sip_address_id =(" + " SELECT id FROM sip_address WHERE value = :remote_address" + " )" + " )", use(remoteAddress); + int count = 0; + + L_BEGIN_LOG_EXCEPTION + + soci::session *session = d->dbSession.getBackendSession(); + *session << query, soci::into(count); + + L_END_LOG_EXCEPTION + + return count; } int EventsDb::getUnreadMessagesCount (const string &remoteAddress) const { diff --git a/src/db/events-db.h b/src/db/events-db.h index 5a1b1bfb3..d6013ed2e 100644 --- a/src/db/events-db.h +++ b/src/db/events-db.h @@ -50,11 +50,11 @@ public: int getEventsCount (FilterMask mask = NoFilter) const; // Messages, calls and conferences. - int getMessagesCount (const std::string &remoteAddress) const; - int getUnreadMessagesCount (const std::string &remoteAddress) const; + int getMessagesCount (const std::string &remoteAddress = "") const; + int getUnreadMessagesCount (const std::string &remoteAddress = "") const; std::list getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter) const; std::list getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter) const; - void cleanHistory (const std::string &remoteAddress); + void cleanHistory (const std::string &remoteAddress = ""); protected: void init () override; From 0684ac464971c90c0597a57c72c27130111d354b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 12:12:35 +0200 Subject: [PATCH 32/49] little fixes --- src/db/events-db.cpp | 13 +++++++------ src/enums.h | 16 +--------------- src/message/message.cpp | 8 ++++---- src/message/message.h | 20 ++++++++++++++++++-- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index f9aaf4685..4673554c5 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -213,12 +213,13 @@ static string buildSqlEventFilter (const list &filters, Events int EventsDb::getMessagesCount (const string &remoteAddress) const { L_D(const EventsDb); - string query = "SELECT COUNT(*) FROM message_event" - " WHERE dialog_id = (" - " SELECT id FROM dialog WHERE remote_sip_address_id =(" - " SELECT id FROM sip_address WHERE value = :remote_address" - " )" - " )", use(remoteAddress); + string query = "SELECT COUNT(*) FROM message_event"; + if (!remoteAddress.empty()) + query += " WHERE dialog_id = (" + " SELECT id FROM dialog WHERE remote_sip_address_id =(" + " SELECT id FROM sip_address WHERE value = :remote_address" + " )" + " )", soci::use(remoteAddress); int count = 0; L_BEGIN_LOG_EXCEPTION diff --git a/src/enums.h b/src/enums.h index ba228481f..78f0d1ed5 100644 --- a/src/enums.h +++ b/src/enums.h @@ -25,21 +25,7 @@ LINPHONE_BEGIN_NAMESPACE -enum class MessageDirection { - Incoming, - Outgoing -}; - -enum class MessageState { - Idle, - InProgress, - Delivered, - NotDelivered, - FileTransferError, - FileTransferDone, - DeliveredToUser, - Displayed -}; +// Nothing. for the moment. LINPHONE_END_NAMESPACE diff --git a/src/message/message.cpp b/src/message/message.cpp index c562c2d86..a4e907426 100644 --- a/src/message/message.cpp +++ b/src/message/message.cpp @@ -32,7 +32,7 @@ using namespace std; class MessagePrivate : public ObjectPrivate { private: weak_ptr chatRoom; - MessageDirection direction = MessageDirection::Incoming; + Message::Direction direction = Message::Incoming; // LinphoneAddress *from; // LinphoneAddress *to; shared_ptr errorInfo; @@ -44,7 +44,7 @@ private: string appData; list > contents; unordered_map customHeaders; - MessageState state = MessageState::Idle; + Message::State state = Message::Idle; shared_ptr eventsDb; L_DECLARE_PUBLIC(Message); @@ -63,7 +63,7 @@ shared_ptr Message::getChatRoom () const { return chatRoom; } -MessageDirection Message::getDirection () const { +Message::Direction Message::getDirection () const { L_D(const Message); return d->direction; } @@ -88,7 +88,7 @@ shared_ptr Message::getRemoteAddress () const { return nullptr; } -MessageState Message::getState () const { +Message::State Message::getState () const { L_D(const Message); return d->state; } diff --git a/src/message/message.h b/src/message/message.h index 287b6aa81..61754010b 100644 --- a/src/message/message.h +++ b/src/message/message.h @@ -40,16 +40,32 @@ class LINPHONE_PUBLIC Message : public Object { friend class ChatRoom; public: + enum Direction { + Incoming, + Outgoing + }; + + enum State { + Idle, + InProgress, + Delivered, + NotDelivered, + FileTransferError, + FileTransferDone, + DeliveredToUser, + Displayed + }; + std::shared_ptr getChatRoom () const; - MessageDirection getDirection () const; + Direction getDirection () const; std::shared_ptr getFromAddress () const; std::shared_ptr getToAddress () const; std::shared_ptr getLocalAddress () const; std::shared_ptr getRemoteAddress () const; - MessageState getState () const; + State getState () const; std::shared_ptr getErrorInfo () const; From 1fe9f6d4c65eef9db2d8378a58b029c0c27c71ae Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Thu, 24 Aug 2017 12:12:43 +0200 Subject: [PATCH 33/49] Fix C# wrapper --- wrappers/csharp/wrapper_impl.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/csharp/wrapper_impl.mustache b/wrappers/csharp/wrapper_impl.mustache index b281a5f80..f66c504fe 100644 --- a/wrappers/csharp/wrapper_impl.mustache +++ b/wrappers/csharp/wrapper_impl.mustache @@ -532,12 +532,12 @@ namespace Linphone return fromNativePtr<{{type}}>(ptr, {{takeRef}}); {{/is_class}} {{#is_enum}} - {{#exception}}int exception_result = {{/exception}}{{return}}{{c_name}}({{nativePtr}}{{c_args}}); + {{#exception}}int exception_result = {{/exception}}{{return}}{{c_name}}({{nativePtr}}{{{c_args}}}); {{#exception}}if (exception_result != 0) throw new LinphoneException("{{name}} returned value " + exception_result);{{/exception}} {{/is_enum}} {{#is_generic}} - {{#exception}}int exception_result = {{/exception}}{{return}}{{c_name}}({{nativePtr}}{{c_args}}); - {{#exception}}if (exception_result != 0) throw new LinphoneException("{{name}} returned value " + exception_result);{{/exception}} + {{#exception}}int exception_result = {{/exception}}{{return}}{{c_name}}({{nativePtr}}{{{c_args}}}); + {{#exception}}if (exception_result != 0) throw new LinphoneException("{{name}} returned value" + exception_result);{{/exception}} {{/is_generic}} {{#is_string_list}} return MarshalStringArray({{c_name}}({{nativePtr}}{{c_args}})); From c9dac359b4f83d1ce98dde42ec584d68aa4f2978 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 14:28:19 +0200 Subject: [PATCH 34/49] feat(EventsDb): impl `getUnreadMessagesCount` --- src/db/events-db.cpp | 71 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 4673554c5..bddacaf82 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -17,6 +17,7 @@ */ #include +#include #ifdef SOCI_ENABLED #include @@ -27,6 +28,7 @@ #include "event/event.h" #include "event/message-event.h" #include "logger/logger.h" +#include "message/message.h" #include "events-db.h" @@ -46,19 +48,40 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- -inline constexpr const char *mapFilterToSqlEvent (EventsDb::Filter filter) { +inline constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { // Ugly. Yes. But constexpr... return filter == EventsDb::MessageFilter - ? "0" + ? "1" : (filter == EventsDb::CallFilter - ? "1" + ? "2" : (filter == EventsDb::ConferenceFilter - ? "2" + ? "3" : "" ) ); } +inline constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { + return direction == Message::Direction::Incoming ? "1" : "2"; +} + +static constexpr pair messageStateToSql[] = { + { Message::Idle, "1" }, + { Message::InProgress, "2" }, + { Message::Delivered, "3" }, + { Message::NotDelivered, "4" }, + { Message::FileTransferError, "5" }, + { Message::FileTransferDone, "6" }, + { Message::DeliveredToUser, "7" }, + { Message::Displayed, "8" } +}; + +inline constexpr const char *mapMessageStateToSql (Message::State state) { + return mapMessageStateToSql(state); +} + +// ----------------------------------------------------------------------------- + static string buildSqlEventFilter (const list &filters, EventsDb::FilterMask mask) { L_ASSERT( find_if(filters.cbegin(), filters.cend(), [](const EventsDb::Filter &filter) { @@ -81,7 +104,7 @@ static string buildSqlEventFilter (const list &filters, Events } else sql += " OR "; sql += " event_type_id = "; - sql += mapFilterToSqlEvent(filter); + sql += mapEventFilterToSql(filter); } return sql; @@ -120,9 +143,9 @@ static string buildSqlEventFilter (const list &filters, Events ")"; *session << - "CREATE TABLE IF NOT EXISTS message_status (" + "CREATE TABLE IF NOT EXISTS message_state (" " id" + primaryKeyAutoIncrementStr("TINYINT") + "," - " status VARCHAR(255) NOT NULL" + " state VARCHAR(255) NOT NULL" ")"; *session << @@ -150,7 +173,7 @@ static string buildSqlEventFilter (const list &filters, Events "CREATE TABLE IF NOT EXISTS message_event (" " id" + primaryKeyAutoIncrementStr() + "," " dialog_id INT UNSIGNED NOT NULL," - " status_id TINYINT UNSIGNED NOT NULL," + " state_id TINYINT UNSIGNED NOT NULL," " direction_id TINYINT UNSIGNED NOT NULL," " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 " content_type VARCHAR(255) NOT NULL," @@ -159,8 +182,8 @@ static string buildSqlEventFilter (const list &filters, Events " FOREIGN KEY (dialog_id)" " REFERENCES dialog(id)" " ON DELETE CASCADE," - " FOREIGN KEY (status_id)" - " REFERENCES message_status(id)" + " FOREIGN KEY (state_id)" + " REFERENCES message_state(id)" " ON DELETE CASCADE," " FOREIGN KEY (direction_id)" " REFERENCES message_direction(id)" @@ -219,13 +242,13 @@ static string buildSqlEventFilter (const list &filters, Events " SELECT id FROM dialog WHERE remote_sip_address_id =(" " SELECT id FROM sip_address WHERE value = :remote_address" " )" - " )", soci::use(remoteAddress); + " )"; int count = 0; L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); - *session << query, soci::into(count); + *session << query, soci::use(remoteAddress), soci::into(count); L_END_LOG_EXCEPTION @@ -233,9 +256,27 @@ static string buildSqlEventFilter (const list &filters, Events } int EventsDb::getUnreadMessagesCount (const string &remoteAddress) const { - // TODO. - (void)remoteAddress; - return 0; + L_D(const EventsDb); + + string query = "SELECT COUNT(*) FROM message_event"; + if (!remoteAddress.empty()) + query += " WHERE dialog_id = (" + " SELECT id FROM dialog WHERE remote_sip_address_id = (" + " SELECT id FROM sip_address WHERE value = :remote_address" + " )" + " )" + " AND direction_id = " + string(mapMessageDirectionToSql(Message::Incoming)) + + " AND state_id = " + string(mapMessageStateToSql(Message::Displayed)); + int count = 0; + + L_BEGIN_LOG_EXCEPTION + + soci::session *session = d->dbSession.getBackendSession(); + *session << query, soci::use(remoteAddress), soci::into(count); + + L_END_LOG_EXCEPTION + + return count; } list EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) const { From 8af55bcf34e600387dddf39444111231b60106bc Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 24 Aug 2017 15:10:46 +0200 Subject: [PATCH 35/49] Fixed flexisip crash when using the userdb.conf file --- tester/flexisip/userdb.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tester/flexisip/userdb.conf b/tester/flexisip/userdb.conf index 6ac364764..c990afc35 100644 --- a/tester/flexisip/userdb.conf +++ b/tester/flexisip/userdb.conf @@ -1,8 +1,7 @@ -liblinphone_tester@sip.example.org secret liblinphone_tester +33123456789 +liblinphone_tester@sip.example.org secret liblinphone_tester@auth.example.org secret liblinphone_tester@auth1.example.org secret tester@sip.example.org secret - pauline@sip.example.org secret marie@sip.example.org secret laure@sip.example.org secret From 79d716d9d7f7c8c99edb61d06d4a92d20d7a9dff Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 15:14:31 +0200 Subject: [PATCH 36/49] feat(EventsDb): insert data for message_state, message_direction and event_type tables --- src/db/events-db.cpp | 65 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index bddacaf82..dcbcc3241 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -48,17 +48,14 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- +static constexpr pair eventFilterToSql[] = { + { EventsDb::MessageFilter, "1" }, + { EventsDb::CallFilter, "2" }, + { EventsDb::ConferenceFilter, "3" } +}; + inline constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { - // Ugly. Yes. But constexpr... - return filter == EventsDb::MessageFilter - ? "1" - : (filter == EventsDb::CallFilter - ? "2" - : (filter == EventsDb::ConferenceFilter - ? "3" - : "" - ) - ); + return eventFilterToSql[filter].second; } inline constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { @@ -77,7 +74,7 @@ static constexpr pair messageStateToSql[] = { }; inline constexpr const char *mapMessageStateToSql (Message::State state) { - return mapMessageStateToSql(state); + return messageStateToSql[state].second; } // ----------------------------------------------------------------------------- @@ -189,6 +186,52 @@ static string buildSqlEventFilter (const list &filters, Events " REFERENCES message_direction(id)" " ON DELETE CASCADE" ")"; + + { + string query = getBackend() == Mysql + ? "INSERT INTO event_type (id, value)" + : "INSERT OR IGNORE INTO event_type (id, value)"; + query += "VALUES" + "(1, \"Message\")," + "(2, \"Call\")," + "(3, \"Conference\")"; + if (getBackend() == Mysql) + query += "ON DUPLICATE KEY UPDATE value = VALUES(value)"; + + *session << query; + } + + { + string query = getBackend() == Mysql + ? "INSERT INTO message_direction (id, value)" + : "INSERT OR IGNORE INTO message_direction (id, value)"; + query += "VALUES" + "(1, \"Incoming\")," + "(2, \"Outgoing\")"; + if (getBackend() == Mysql) + query += "ON DUPLICATE KEY UPDATE value = VALUES(value)"; + + *session << query; + } + + { + string query = getBackend() == Mysql + ? "INSERT INTO message_state (id, value)" + : "INSERT OR IGNORE INTO message_state (id, value)"; + query += "VALUES" + "(1, \"Idle\")," + "(2, \"InProgress\")," + "(3, \"Delivered\")," + "(4, \"NotDelivered\")," + "(5, \"FileTransferError\")," + "(6, \"FileTransferDone\")," + "(7, \"DeliveredToUser\")," + "(8, \"Displayed\")"; + if (getBackend() == Mysql) + query += "ON DUPLICATE KEY UPDATE value = VALUES(value)"; + + *session << query; + } } bool EventsDb::addEvent (const Event &event) { From 3e9b07432dd6d99cccdd0839a5b33d5e6b8ab4d2 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 15:55:57 +0200 Subject: [PATCH 37/49] feat(core): add empty `Content` class --- src/CMakeLists.txt | 2 ++ src/content/content.cpp | 37 +++++++++++++++++++++++++++++++++ src/content/content.h | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/content/content.cpp create mode 100644 src/content/content.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29d437147..336ed8de9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ ############################################################################ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES + content/content.h cpim/cpim.h cpim/header/cpim-core-headers.h cpim/header/cpim-generic-header.h @@ -51,6 +52,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES ) set(LINPHONE_CXX_OBJECTS_SOURCE_FILES + content/content.cpp cpim/header/cpim-core-headers.cpp cpim/header/cpim-generic-header.cpp cpim/header/cpim-header.cpp diff --git a/src/content/content.cpp b/src/content/content.cpp new file mode 100644 index 000000000..2003b1613 --- /dev/null +++ b/src/content/content.cpp @@ -0,0 +1,37 @@ +/* + * content.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "object/object-p.h" + +#include "content.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ContentPrivate : public ObjectPrivate { +private: + + L_DECLARE_PUBLIC(Content); +}; + +// ----------------------------------------------------------------------------- + +Content::Content (ContentPrivate &p) : Object(p) {} + +LINPHONE_END_NAMESPACE diff --git a/src/content/content.h b/src/content/content.h new file mode 100644 index 000000000..fa59de1e7 --- /dev/null +++ b/src/content/content.h @@ -0,0 +1,45 @@ +/* + * content.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONTENT_H_ +#define _CONTENT_H_ + +#include "object/object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ContentPrivate; + +class LINPHONE_PUBLIC Content : public Object { + friend class Core; + +public: + // Nothing for the moment. + +private: + Content (ContentPrivate &p); + + L_DECLARE_PRIVATE(Content); + L_DISABLE_COPY(Content); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONTENT_H_ From 98a370e79fa8143fcd9dc807964f870c0eb65db4 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 16:01:39 +0200 Subject: [PATCH 38/49] feat(core): add empty `Core` class --- src/CMakeLists.txt | 2 ++ src/core/core.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/core/core.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/core/core.cpp create mode 100644 src/core/core.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 336ed8de9..82a01ba77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES content/content.h + core/core.h cpim/cpim.h cpim/header/cpim-core-headers.h cpim/header/cpim-generic-header.h @@ -53,6 +54,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES set(LINPHONE_CXX_OBJECTS_SOURCE_FILES content/content.cpp + core/core.cpp cpim/header/cpim-core-headers.cpp cpim/header/cpim-generic-header.cpp cpim/header/cpim-header.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp new file mode 100644 index 000000000..2d4e9696e --- /dev/null +++ b/src/core/core.cpp @@ -0,0 +1,36 @@ +/* + * core.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "object/object-p.h" + +#include "core.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class CorePrivate : public ObjectPrivate { +public: + // TODO. +}; + +// ----------------------------------------------------------------------------- + +Core::Core (CorePrivate &p) : Object(p) {} + +LINPHONE_END_NAMESPACE diff --git a/src/core/core.h b/src/core/core.h new file mode 100644 index 000000000..1d4874c31 --- /dev/null +++ b/src/core/core.h @@ -0,0 +1,43 @@ +/* + * core.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CORE_H_ +#define _CORE_H_ + +#include "object/object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class CorePrivate; + +class LINPHONE_PUBLIC Core : public Object { +public: + // Nothing for the moment. + +private: + Core (CorePrivate &p); + + L_DECLARE_PRIVATE(Core); + L_DISABLE_COPY(Core); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CORE_H_ From 3c51f52fa6e2ceeb04563b76790357f5846f5133 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 17:17:09 +0200 Subject: [PATCH 39/49] feat(Event): add new conference event type --- src/db/events-db.cpp | 6 ++++++ src/event/event.h | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index dcbcc3241..11b7e6e28 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -242,6 +242,12 @@ static string buildSqlEventFilter (const list &filters, Events case Event::MessageEvent: case Event::CallStartEvent: case Event::CallEndEvent: + case Event::ConferenceCreatedEvent: + case Event::ConferenceDestroyedEvent: + case Event::ConferenceParticipantAddedEvent: + case Event::ConferenceParticipantRemovedEvent: + case Event::ConferenceParticipantSetAdminEvent: + case Event::ConferenceParticipantUnsetAdminEvent: break; } diff --git a/src/event/event.h b/src/event/event.h index 17deb379f..ebd530a4b 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -31,9 +31,19 @@ class LINPHONE_PUBLIC Event : public ClonableObject { public: enum Type { None, + // MessageEvent. MessageEvent, + // CallEvent. CallStartEvent, - CallEndEvent + CallEndEvent, + // ConferenceEvent. + ConferenceCreatedEvent, + ConferenceDestroyedEvent, + // ConferenceParticipantEvent. + ConferenceParticipantAddedEvent, + ConferenceParticipantRemovedEvent, + ConferenceParticipantSetAdminEvent, + ConferenceParticipantUnsetAdminEvent }; Event (); From 0e37546ef374ece527952b418591f9cefb0ccb21 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 17:22:49 +0200 Subject: [PATCH 40/49] feat(Event): add conference event --- src/CMakeLists.txt | 2 ++ src/event/conference-event.cpp | 54 ++++++++++++++++++++++++++++++++++ src/event/conference-event.h | 49 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/event/conference-event.cpp create mode 100644 src/event/conference-event.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82a01ba77..aa481ec68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES db/provider/db-session.h enums.h event/call-event.h + event/conference-event.h event/event.h event/message-event.h logger/logger.h @@ -66,6 +67,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES db/provider/db-session-provider.cpp db/provider/db-session.cpp event/call-event.cpp + event/conference-event.cpp event/event.cpp event/message-event.cpp logger/logger.cpp diff --git a/src/event/conference-event.cpp b/src/event/conference-event.cpp new file mode 100644 index 000000000..9cd2e9d11 --- /dev/null +++ b/src/event/conference-event.cpp @@ -0,0 +1,54 @@ +/* + * conference-event.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "event-p.h" + +#include "conference-event.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class ConferenceEventPrivate : public EventPrivate { +public: + shared_ptr
address; +}; + +// ----------------------------------------------------------------------------- + +ConferenceEvent::ConferenceEvent (Type type, const shared_ptr
&address) : Event(*new ConferenceEventPrivate, type) { + L_D(ConferenceEvent); + L_ASSERT(address); + d->address = address; +} + +ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : ConferenceEvent(src.getType(), src.getAddress()) {} + +ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { + L_D(ConferenceEvent); + if (this != &src) { + Event::operator=(src); + d->address = src.getPrivate()->address; + } + + return *this; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/conference-event.h b/src/event/conference-event.h new file mode 100644 index 000000000..c7e0d7803 --- /dev/null +++ b/src/event/conference-event.h @@ -0,0 +1,49 @@ +/* + * conference-event.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONFERENCE_EVENT_H_ +#define _CONFERENCE_EVENT_H_ + +#include + +#include "event.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class Address; +class Conference; +class ConferenceEventPrivate; + +class LINPHONE_PUBLIC ConferenceEvent : public Event { +public: + ConferenceEvent (Type type, const std::shared_ptr
&address); + ConferenceEvent (const ConferenceEvent &src); + + ConferenceEvent &operator= (const ConferenceEvent &src); + + std::shared_ptr
getAddress () const; + +private: + L_DECLARE_PRIVATE(ConferenceEvent); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONFERENCE_EVENT_H_ From 1d968f7ddde9f8f4bcb5ff3291f28e15d47a0ccf Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Aug 2017 17:25:40 +0200 Subject: [PATCH 41/49] feat(Event): add assert on type when Call or Conference event are created --- src/event/call-event.cpp | 1 + src/event/conference-event.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/event/call-event.cpp b/src/event/call-event.cpp index bc17b4e2c..f6eee2b1e 100644 --- a/src/event/call-event.cpp +++ b/src/event/call-event.cpp @@ -36,6 +36,7 @@ public: CallEvent::CallEvent (Type type, const shared_ptr &call) : Event(*new CallEventPrivate, type) { L_D(CallEvent); L_ASSERT(call); + L_ASSERT(type == CallStartEvent || type == CallEndEvent); d->call = call; } diff --git a/src/event/conference-event.cpp b/src/event/conference-event.cpp index 9cd2e9d11..9fb000415 100644 --- a/src/event/conference-event.cpp +++ b/src/event/conference-event.cpp @@ -35,6 +35,7 @@ public: ConferenceEvent::ConferenceEvent (Type type, const shared_ptr
&address) : Event(*new ConferenceEventPrivate, type) { L_D(ConferenceEvent); + L_ASSERT(type == ConferenceCreatedEvent || type == ConferenceDestroyedEvent); L_ASSERT(address); d->address = address; } From 89745baaca29f3354f04bca3774dcd9510073883 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 10:16:44 +0200 Subject: [PATCH 42/49] fix(EventsDb): remove useless inline keywork in constexpr --- src/db/events-db.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 11b7e6e28..e6f7ef56e 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -48,21 +48,21 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- -static constexpr pair eventFilterToSql[] = { +constexpr pair eventFilterToSql[]{ { EventsDb::MessageFilter, "1" }, { EventsDb::CallFilter, "2" }, { EventsDb::ConferenceFilter, "3" } }; -inline constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { +constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { return eventFilterToSql[filter].second; } -inline constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { +constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { return direction == Message::Direction::Incoming ? "1" : "2"; } -static constexpr pair messageStateToSql[] = { +constexpr pair messageStateToSql[]{ { Message::Idle, "1" }, { Message::InProgress, "2" }, { Message::Delivered, "3" }, @@ -73,7 +73,7 @@ static constexpr pair messageStateToSql[] = { { Message::Displayed, "8" } }; -inline constexpr const char *mapMessageStateToSql (Message::State state) { +constexpr const char *mapMessageStateToSql (Message::State state) { return messageStateToSql[state].second; } From 02e1935c4f05cc33754588cb05468c8ff74c6e56 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 10:42:27 +0200 Subject: [PATCH 43/49] feat(core): use static on inline funcs --- src/cpim/parser/cpim-parser.cpp | 4 ++-- src/db/events-db.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cpim/parser/cpim-parser.cpp b/src/cpim/parser/cpim-parser.cpp index c57a15ab2..724f4bf68 100644 --- a/src/cpim/parser/cpim-parser.cpp +++ b/src/cpim/parser/cpim-parser.cpp @@ -279,7 +279,7 @@ shared_ptr Cpim::Parser::cloneHeader (const Header &header) { class EmptyObject {}; -inline bool headerIsValid (const shared_ptr &grammar, const string &input) { +static bool headerIsValid (const shared_ptr &grammar, const string &input) { belr::Parser > parser(grammar); parser.setHandler( "Header", belr::make_fn(make_shared ) @@ -307,7 +307,7 @@ bool Cpim::Parser::headerParameterIsValid (const string &headerParameter) const // ----------------------------------------------------------------------------- -inline bool coreHeaderIsValid ( +static bool coreHeaderIsValid ( const shared_ptr &grammar, const string &headerName, const string &headerValue, diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index e6f7ef56e..2b04961c2 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -48,21 +48,21 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- -constexpr pair eventFilterToSql[]{ +static constexpr pair eventFilterToSql[] = { { EventsDb::MessageFilter, "1" }, { EventsDb::CallFilter, "2" }, { EventsDb::ConferenceFilter, "3" } }; -constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { +static constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { return eventFilterToSql[filter].second; } -constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { +static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { return direction == Message::Direction::Incoming ? "1" : "2"; } -constexpr pair messageStateToSql[]{ +static constexpr pair messageStateToSql[] = { { Message::Idle, "1" }, { Message::InProgress, "2" }, { Message::Delivered, "3" }, @@ -73,7 +73,7 @@ constexpr pair messageStateToSql[]{ { Message::Displayed, "8" } }; -constexpr const char *mapMessageStateToSql (Message::State state) { +static constexpr const char *mapMessageStateToSql (Message::State state) { return messageStateToSql[state].second; } From 9cc9d23a5d2505f1c859e936130fc686fe258c9b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 11:00:52 +0200 Subject: [PATCH 44/49] fix(EventsDb): try to fix mac compilation --- src/db/events-db.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 2b04961c2..d468ff5d2 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -17,7 +17,6 @@ */ #include -#include #ifdef SOCI_ENABLED #include @@ -48,7 +47,13 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Helpers. // ----------------------------------------------------------------------------- -static constexpr pair eventFilterToSql[] = { +template +struct ToSqlPair { + T first; + const char *second; +}; + +static constexpr ToSqlPair eventFilterToSql[] = { { EventsDb::MessageFilter, "1" }, { EventsDb::CallFilter, "2" }, { EventsDb::ConferenceFilter, "3" } @@ -62,7 +67,7 @@ static constexpr const char *mapMessageDirectionToSql (Message::Direction direct return direction == Message::Direction::Incoming ? "1" : "2"; } -static constexpr pair messageStateToSql[] = { +static constexpr ToSqlPair messageStateToSql[] = { { Message::Idle, "1" }, { Message::InProgress, "2" }, { Message::Delivered, "3" }, From ab41ae3c45c2f8a729d0cb4d3fde6b6477db1706 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Fri, 25 Aug 2017 11:39:37 +0200 Subject: [PATCH 45/49] add gruu support --- coreapi/bellesip_sal/sal_op_registration.c | 11 ++- coreapi/linphonecall.c | 8 +- coreapi/linphonecore.c | 13 +-- coreapi/sal.c | 14 +++ include/sal/sal.h | 1 + tester/call_single_tester.c | 99 +++++++++++++++++++++- tester/register_tester.c | 11 +++ 7 files changed, 139 insertions(+), 18 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index 1d0ccbb3e..3526152e0 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -48,8 +48,17 @@ static void register_refresher_listener (belle_sip_refresher_t* refresher if (service_route_address) belle_sip_object_unref(service_route_address); sal_remove_pending_auth(op->base.root,op); /*just in case*/ + if (contact) { - sal_op_set_contact_address(op,(SalAddress*)(BELLE_SIP_HEADER_ADDRESS(contact))); /*update contact with real value*/ + const char *gruu; + belle_sip_parameters_t* p = (BELLE_SIP_PARAMETERS(contact)); + if((gruu = belle_sip_parameters_get_parameter(p, "pub-gruu"))) { + char *unquoted = belle_sip_unquote_strdup(gruu); + sal_op_set_contact_address(op, (SalAddress*)belle_sip_header_address_parse(unquoted)); + belle_sip_parameters_remove_parameter(p, "pub-gruu"); + } else { + sal_op_set_contact_address(op, (SalAddress*)(BELLE_SIP_HEADER_ADDRESS(contact))); /*update contact with real value*/ + } } op->base.root->callbacks.register_success(op,belle_sip_refresher_get_expires(op->refresher)>0); } else if (status_code>=400) { diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 4471af2f1..c455c68e2 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -4983,13 +4983,7 @@ static LinphoneAddress *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , void linphone_call_set_contact_op(LinphoneCall* call) { LinphoneAddress *contact; contact=get_fixed_contact(call->core,call,call->dest_proxy); - if (contact){ - SalTransport tport=sal_address_get_transport((SalAddress*)contact); - sal_address_clean((SalAddress*)contact); /* clean out contact_params that come from proxy config*/ - sal_address_set_transport((SalAddress*)contact,tport); - sal_op_set_contact_address(call->op, contact); - linphone_address_unref(contact); - } + sal_op_set_and_clean_contact_address(call->op, (SalAddress *)contact); } LinphonePlayer *linphone_call_get_player(LinphoneCall *call){ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index bf99af464..262082c31 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1387,7 +1387,7 @@ static void sip_config_read(LinphoneCore *lc) { sal_enable_sip_update_method(lc->sal,lp_config_get_int(lc->config,"sip","sip_update",1)); lc->sip_conf.vfu_with_info=lp_config_get_int(lc->config,"sip","vfu_with_info",1); linphone_core_set_sip_transport_timeout(lc, lp_config_get_int(lc->config, "sip", "transport_timeout", 63000)); - sal_set_supported_tags(lc->sal,lp_config_get_string(lc->config,"sip","supported","replaces, outbound")); + sal_set_supported_tags(lc->sal,lp_config_get_string(lc->config,"sip","supported","replaces, outbound, gruu")); lc->sip_conf.save_auth_info = lp_config_get_int(lc->config, "sip", "save_auth_info", 1); linphone_core_create_im_notif_policy(lc); } @@ -3503,14 +3503,9 @@ void linphone_configure_op_with_proxy(LinphoneCore *lc, SalOp *op, const Linphon sal_op_set_realm(op,linphone_proxy_config_get_realm(proxy)); if (with_contact && proxy && proxy->op){ const SalAddress *contact; - if ((contact=sal_op_get_contact_address(proxy->op))){ - SalTransport tport=sal_address_get_transport((SalAddress*)contact); - SalAddress *new_contact=sal_address_clone(contact); - sal_address_clean(new_contact); /* clean out contact_params that come from proxy config*/ - sal_address_set_transport(new_contact,tport); - sal_op_set_contact_address(op,new_contact); - sal_address_destroy(new_contact); - } + contact=sal_op_get_contact_address(proxy->op); + SalAddress *new_contact = contact ? sal_address_clone(contact) : NULL; + sal_op_set_and_clean_contact_address(proxy->op, new_contact); } sal_op_cnx_ip_to_0000_if_sendonly_enable(op,lp_config_get_default_int(lc->config,"sip","cnx_ip_to_0000_if_sendonly_enabled",0)); /*also set in linphone_call_new_incoming*/ } diff --git a/coreapi/sal.c b/coreapi/sal.c index b52557aad..3870e59e3 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -517,6 +517,20 @@ void sal_op_set_contact_address(SalOp *op, const SalAddress *address){ if (((SalOpBase*)op)->contact_address) sal_address_destroy(((SalOpBase*)op)->contact_address); ((SalOpBase*)op)->contact_address=address?sal_address_clone(address):NULL; } + +void sal_op_set_and_clean_contact_address(SalOp *op, SalAddress *contact) { + if (contact){ + SalTransport tport = sal_address_get_transport((SalAddress*)contact); + const char* gruu = bctbx_strdup(sal_address_get_uri_param(contact, "gr")); + sal_address_clean((SalAddress*)contact); /* clean out contact_params that come from proxy config*/ + sal_address_set_transport((SalAddress*)contact,tport); + if(gruu) + sal_address_set_uri_param(contact, "gr", gruu); + sal_op_set_contact_address(op, contact); + sal_address_unref(contact); + } +} + const SalAddress* sal_op_get_contact_address(const SalOp *op) { return ((SalOpBase*)op)->contact_address; } diff --git a/include/sal/sal.h b/include/sal/sal.h index 1cabcb5fa..0aa5073ae 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -674,6 +674,7 @@ SalOp * sal_op_new(Sal *sal); /*generic SalOp API, working for all operations */ Sal *sal_op_get_sal(const SalOp *op); void sal_op_set_contact_address(SalOp *op, const SalAddress* address); +void sal_op_set_and_clean_contact_address(SalOp *op, SalAddress* address); void sal_op_set_route(SalOp *op, const char *route); void sal_op_set_route_address(SalOp *op, const SalAddress* address); void sal_op_add_route_address(SalOp *op, const SalAddress* address); diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index 383722743..089ac77d6 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -6158,6 +6158,101 @@ static void recreate_zrtpdb_when_corrupted(void) { #endif /* SQLITE_STORAGE_ENABLED */ } +static void simple_call_with_gruu(void) { + LinphoneCoreManager* marie; + LinphoneCoreManager* pauline; + const LinphoneAddress *addr; + LinphoneCall *marie_call = NULL; + LinphoneCall *pauline_call = NULL; + LinphoneProxyConfig* pauline_cfg; + + marie = linphone_core_manager_new( "marie_rc"); + pauline = linphone_core_manager_new("pauline_tcp_rc"); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneRegistrationOk, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneRegistrationOk, 1)); + + pauline_cfg = linphone_core_get_default_proxy_config(pauline->lc); + addr = linphone_proxy_config_get_contact(pauline_cfg); + BC_ASSERT_PTR_NOT_NULL(addr); + BC_ASSERT_PTR_NOT_NULL(strstr(linphone_address_as_string_uri_only(addr), "gr")); + + marie_call = linphone_core_invite_address(marie->lc, addr); + BC_ASSERT_PTR_NOT_NULL(marie_call); + if(!marie_call) goto end; + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallIncomingReceived, 1)); + pauline_call = linphone_core_get_current_call(pauline->lc); + BC_ASSERT_PTR_NOT_NULL(pauline_call); + if(!pauline_call) goto end; + linphone_call_accept(pauline_call); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1)); + + linphone_call_terminate(pauline_call); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); + +end: + linphone_core_manager_destroy(pauline); + linphone_core_manager_destroy(marie); +} + +static void simple_call_with_gruu_only_one_device_ring(void) { + LinphoneCoreManager* marie; + LinphoneCoreManager* pauline; + LinphoneCoreManager* pauline2; + const LinphoneAddress *pauline_addr; + const LinphoneAddress *pauline_addr2; + LinphoneCall *marie_call = NULL; + LinphoneCall *pauline_call = NULL; + LinphoneProxyConfig* pauline_cfg; + LinphoneProxyConfig* pauline_cfg2; + + marie = linphone_core_manager_new( "marie_rc"); + pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); + pauline2 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneRegistrationOk, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneRegistrationOk, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline2->stat.number_of_LinphoneRegistrationOk, 1)); + + pauline_cfg = linphone_core_get_default_proxy_config(pauline->lc); + pauline_addr = linphone_proxy_config_get_contact(pauline_cfg); + BC_ASSERT_PTR_NOT_NULL(pauline_addr); + BC_ASSERT_PTR_NOT_NULL(strstr(linphone_address_as_string_uri_only(pauline_addr), "gr")); + pauline_cfg2 = linphone_core_get_default_proxy_config(pauline2->lc); + pauline_addr2 = linphone_proxy_config_get_contact(pauline_cfg2); + BC_ASSERT_PTR_NOT_NULL(pauline_addr2); + BC_ASSERT_PTR_NOT_NULL(strstr(linphone_address_as_string_uri_only(pauline_addr2), "gr")); + BC_ASSERT_NOT_EQUAL(linphone_address_as_string_uri_only(pauline_addr), linphone_address_as_string_uri_only(pauline_addr2), char*, "%s"); // Not same GRUU + + marie_call = linphone_core_invite_address(marie->lc, pauline_addr); + BC_ASSERT_PTR_NOT_NULL(marie_call); + if(!marie_call) goto end; + BC_ASSERT_FALSE(wait_for(marie->lc, pauline2->lc, &pauline2->stat.number_of_LinphoneCallIncomingReceived, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallIncomingReceived, 1)); + pauline_call = linphone_core_get_current_call(pauline->lc); + BC_ASSERT_PTR_NOT_NULL(pauline_call); + if(!pauline_call) goto end; + + linphone_call_accept(pauline_call); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1)); + + linphone_call_terminate(pauline_call); + + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1)); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); + +end: + linphone_core_manager_destroy(pauline); + linphone_core_manager_destroy(pauline2); + linphone_core_manager_destroy(marie); +} + test_t call_tests[] = { TEST_NO_TAG("Early declined call", early_declined_call), TEST_NO_TAG("Call declined", call_declined), @@ -6309,7 +6404,9 @@ test_t call_tests[] = { TEST_NO_TAG("Call cancelled with reason", cancel_call_with_error), TEST_NO_TAG("Call accepted, other ringing device receive CANCEL with reason", cancel_other_device_after_accept), TEST_NO_TAG("Call declined, other ringing device receive CANCEL with reason", cancel_other_device_after_decline), - TEST_NO_TAG("Recreate ZRTP db file when corrupted", recreate_zrtpdb_when_corrupted) + TEST_NO_TAG("Recreate ZRTP db file when corrupted", recreate_zrtpdb_when_corrupted), + TEST_NO_TAG("Simple call with GRUU", simple_call_with_gruu), + TEST_NO_TAG("Simple call with GRUU only one device ring", simple_call_with_gruu_only_one_device_ring) }; test_suite_t call_test_suite = {"Single Call", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each, diff --git a/tester/register_tester.c b/tester/register_tester.c index c8f899b2e..c994e8931 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -1185,6 +1185,16 @@ static void tls_auth_info_client_cert_cb_2(void) { } } +static void register_get_gruu(void) { + LinphoneCoreManager *marie=linphone_core_manager_new("marie_rc"); + LinphoneProxyConfig *cfg=linphone_core_get_default_proxy_config(marie->lc); + if(cfg) { + const LinphoneAddress *addr = linphone_proxy_config_get_contact(cfg); + BC_ASSERT_PTR_NOT_NULL(addr); + BC_ASSERT_PTR_NOT_NULL(strstr(linphone_address_as_string_uri_only(addr), "gr")); + } + linphone_core_manager_destroy(marie); +} test_t register_tests[] = { TEST_NO_TAG("Simple register", simple_register), @@ -1231,6 +1241,7 @@ test_t register_tests[] = { TEST_NO_TAG("AuthInfo TLS client certificate authentication using API 2", tls_auth_info_client_cert_api_path), TEST_NO_TAG("AuthInfo TLS client certificate authentication in callback", tls_auth_info_client_cert_cb), TEST_NO_TAG("AuthInfo TLS client certificate authentication in callback 2", tls_auth_info_client_cert_cb_2), + TEST_NO_TAG("Register get GRUU", register_get_gruu) }; test_suite_t register_test_suite = {"Register", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each, From 133d58d618d75f70e0dcec121788349e0c59e15b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 12:06:20 +0200 Subject: [PATCH 46/49] fix(ConferenceEvent): add getAddress impl --- src/event/conference-event.cpp | 5 +++++ src/event/conference-event.h | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/event/conference-event.cpp b/src/event/conference-event.cpp index 9fb000415..e2ae54200 100644 --- a/src/event/conference-event.cpp +++ b/src/event/conference-event.cpp @@ -52,4 +52,9 @@ ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { return *this; } +shared_ptr
ConferenceEvent::getAddress () const { + // TODO. + return nullptr; +} + LINPHONE_END_NAMESPACE diff --git a/src/event/conference-event.h b/src/event/conference-event.h index c7e0d7803..c063f7ac3 100644 --- a/src/event/conference-event.h +++ b/src/event/conference-event.h @@ -28,18 +28,21 @@ LINPHONE_BEGIN_NAMESPACE class Address; -class Conference; class ConferenceEventPrivate; class LINPHONE_PUBLIC ConferenceEvent : public Event { public: ConferenceEvent (Type type, const std::shared_ptr
&address); ConferenceEvent (const ConferenceEvent &src); + virtual ~ConferenceEvent () = default; ConferenceEvent &operator= (const ConferenceEvent &src); std::shared_ptr
getAddress () const; +protected: + ConferenceEvent (ConferenceEventPrivate &p, Type type); + private: L_DECLARE_PRIVATE(ConferenceEvent); }; From a17289a013ca1e30d5f33115891ead8922a3290d Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 14:50:21 +0200 Subject: [PATCH 47/49] feat(Event): add `ConferenceParticipantEvent` --- src/CMakeLists.txt | 3 + src/event/conference-event-p.h | 39 ++++++++++++ src/event/conference-event.cpp | 19 +++--- src/event/conference-event.h | 2 +- src/event/conference-participant-event.cpp | 70 ++++++++++++++++++++++ src/event/conference-participant-event.h | 49 +++++++++++++++ 6 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 src/event/conference-event-p.h create mode 100644 src/event/conference-participant-event.cpp create mode 100644 src/event/conference-participant-event.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa481ec68..128049d35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES db/provider/db-session.h enums.h event/call-event.h + event/conference-event-p.h event/conference-event.h + event/conference-participant-event.h event/event.h event/message-event.h logger/logger.h @@ -68,6 +70,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES db/provider/db-session.cpp event/call-event.cpp event/conference-event.cpp + event/conference-participant-event.cpp event/event.cpp event/message-event.cpp logger/logger.cpp diff --git a/src/event/conference-event-p.h b/src/event/conference-event-p.h new file mode 100644 index 000000000..d4fcd9b65 --- /dev/null +++ b/src/event/conference-event-p.h @@ -0,0 +1,39 @@ +/* + * conference-event-p.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONFERENCE_EVENT_P_H_ +#define _CONFERENCE_EVENT_P_H_ + +#include "conference-event.h" + +#include "event-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ConferenceEventPrivate : public EventPrivate { +private: + std::shared_ptr
address; + + L_DECLARE_PUBLIC(ConferenceEvent); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONFERENCE_EVENT_P_H_ diff --git a/src/event/conference-event.cpp b/src/event/conference-event.cpp index e2ae54200..a75d22657 100644 --- a/src/event/conference-event.cpp +++ b/src/event/conference-event.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "event-p.h" +#include "conference-event-p.h" #include "conference-event.h" @@ -26,14 +26,8 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -class ConferenceEventPrivate : public EventPrivate { -public: - shared_ptr
address; -}; - -// ----------------------------------------------------------------------------- - -ConferenceEvent::ConferenceEvent (Type type, const shared_ptr
&address) : Event(*new ConferenceEventPrivate, type) { +ConferenceEvent::ConferenceEvent (Type type, const shared_ptr
&address) : + Event(*new ConferenceEventPrivate, type) { L_D(ConferenceEvent); L_ASSERT(type == ConferenceCreatedEvent || type == ConferenceDestroyedEvent); L_ASSERT(address); @@ -42,6 +36,13 @@ ConferenceEvent::ConferenceEvent (Type type, const shared_ptr
&address) ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : ConferenceEvent(src.getType(), src.getAddress()) {} +ConferenceEvent::ConferenceEvent (ConferenceEventPrivate &p, Type type, const shared_ptr
&address) : + Event(p, type) { + L_D(ConferenceEvent); + L_ASSERT(address); + d->address = address; +} + ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { L_D(ConferenceEvent); if (this != &src) { diff --git a/src/event/conference-event.h b/src/event/conference-event.h index c063f7ac3..5a499b215 100644 --- a/src/event/conference-event.h +++ b/src/event/conference-event.h @@ -41,7 +41,7 @@ public: std::shared_ptr
getAddress () const; protected: - ConferenceEvent (ConferenceEventPrivate &p, Type type); + ConferenceEvent (ConferenceEventPrivate &p, Type type, const std::shared_ptr
&address); private: L_DECLARE_PRIVATE(ConferenceEvent); diff --git a/src/event/conference-participant-event.cpp b/src/event/conference-participant-event.cpp new file mode 100644 index 000000000..5cb0a1ce7 --- /dev/null +++ b/src/event/conference-participant-event.cpp @@ -0,0 +1,70 @@ +/* + * conference-participant-event.cpp + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "conference-event-p.h" + +#include "conference-participant-event.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class ConferenceParticipantEventPrivate : public ConferenceEventPrivate { +public: + shared_ptr
participantAddress; +}; + +// ----------------------------------------------------------------------------- + +ConferenceParticipantEvent::ConferenceParticipantEvent ( + Type type, + const shared_ptr
&conferenceAddress, + const shared_ptr
&participantAddress +) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, conferenceAddress) { + L_D(ConferenceParticipantEvent); + L_ASSERT( + type == ConferenceParticipantAddedEvent || + type == ConferenceParticipantRemovedEvent || + type == ConferenceParticipantSetAdminEvent || + type == ConferenceParticipantUnsetAdminEvent + ); + L_ASSERT(participantAddress); + d->participantAddress = participantAddress; +} + +ConferenceParticipantEvent::ConferenceParticipantEvent (const ConferenceParticipantEvent &src) : + ConferenceParticipantEvent(src.getType(), src.getAddress(), src.getParticipantAddress()) {} + +ConferenceParticipantEvent &ConferenceParticipantEvent::operator= (const ConferenceParticipantEvent &src) { + L_D(ConferenceParticipantEvent); + if (this != &src) { + ConferenceEvent::operator=(src); + d->participantAddress = src.getPrivate()->participantAddress; + } + + return *this; +} + +shared_ptr
ConferenceParticipantEvent::getParticipantAddress () const { + // TODO. + return nullptr; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/conference-participant-event.h b/src/event/conference-participant-event.h new file mode 100644 index 000000000..9b65f1002 --- /dev/null +++ b/src/event/conference-participant-event.h @@ -0,0 +1,49 @@ +/* + * conference-participant-event.h + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONFERENCE_PARTICIPANT_EVENT_H_ +#define _CONFERENCE_PARTICIPANT_EVENT_H_ + +#include "conference-event.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ConferenceParticipantEventPrivate; + +class LINPHONE_PUBLIC ConferenceParticipantEvent : public ConferenceEvent { +public: + ConferenceParticipantEvent ( + Type type, + const std::shared_ptr
&conferenceAddress, + const std::shared_ptr
&participantAddress + ); + ConferenceParticipantEvent (const ConferenceParticipantEvent &src); + + ConferenceParticipantEvent &operator= (const ConferenceParticipantEvent &src); + + std::shared_ptr
getParticipantAddress () const; + +private: + L_DECLARE_PRIVATE(ConferenceParticipantEvent); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONFERENCE_PARTICIPANT_EVENT_H_ From a96d04c7b4c112e3084a0ad1bd3bda7a11ff4ca4 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 15:36:38 +0200 Subject: [PATCH 48/49] fix(EventsDb): avoid unused functions if soci is not available --- src/db/events-db.cpp | 136 +++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index d468ff5d2..b8fe9ac89 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -43,81 +43,79 @@ class EventsDbPrivate : public AbstractDbPrivate {}; EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} -// ----------------------------------------------------------------------------- -// Helpers. -// ----------------------------------------------------------------------------- - -template -struct ToSqlPair { - T first; - const char *second; -}; - -static constexpr ToSqlPair eventFilterToSql[] = { - { EventsDb::MessageFilter, "1" }, - { EventsDb::CallFilter, "2" }, - { EventsDb::ConferenceFilter, "3" } -}; - -static constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { - return eventFilterToSql[filter].second; -} - -static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { - return direction == Message::Direction::Incoming ? "1" : "2"; -} - -static constexpr ToSqlPair messageStateToSql[] = { - { Message::Idle, "1" }, - { Message::InProgress, "2" }, - { Message::Delivered, "3" }, - { Message::NotDelivered, "4" }, - { Message::FileTransferError, "5" }, - { Message::FileTransferDone, "6" }, - { Message::DeliveredToUser, "7" }, - { Message::Displayed, "8" } -}; - -static constexpr const char *mapMessageStateToSql (Message::State state) { - return messageStateToSql[state].second; -} - -// ----------------------------------------------------------------------------- - -static string buildSqlEventFilter (const list &filters, EventsDb::FilterMask mask) { - L_ASSERT( - find_if(filters.cbegin(), filters.cend(), [](const EventsDb::Filter &filter) { - return filter == EventsDb::NoFilter; - }) == filters.cend() - ); - - if (mask == EventsDb::NoFilter) - return ""; - - bool isStart = true; - string sql; - for (const auto &filter : filters) { - if (!(mask & filter)) - continue; - - if (isStart) { - isStart = false; - sql += " WHERE "; - } else - sql += " OR "; - sql += " event_type_id = "; - sql += mapEventFilterToSql(filter); - } - - return sql; -} - // ----------------------------------------------------------------------------- // Soci backend. // ----------------------------------------------------------------------------- #ifdef SOCI_ENABLED + template + struct EnumToSql { + T first; + const char *second; + }; + + static constexpr EnumToSql eventFilterToSql[] = { + { EventsDb::MessageFilter, "1" }, + { EventsDb::CallFilter, "2" }, + { EventsDb::ConferenceFilter, "3" } + }; + + static constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { + return eventFilterToSql[filter].second; + } + + static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { + return direction == Message::Direction::Incoming ? "1" : "2"; + } + + static constexpr EnumToSql messageStateToSql[] = { + { Message::Idle, "1" }, + { Message::InProgress, "2" }, + { Message::Delivered, "3" }, + { Message::NotDelivered, "4" }, + { Message::FileTransferError, "5" }, + { Message::FileTransferDone, "6" }, + { Message::DeliveredToUser, "7" }, + { Message::Displayed, "8" } + }; + + static constexpr const char *mapMessageStateToSql (Message::State state) { + return messageStateToSql[state].second; + } + +// ----------------------------------------------------------------------------- + + static string buildSqlEventFilter (const list &filters, EventsDb::FilterMask mask) { + L_ASSERT( + find_if(filters.cbegin(), filters.cend(), [](const EventsDb::Filter &filter) { + return filter == EventsDb::NoFilter; + }) == filters.cend() + ); + + if (mask == EventsDb::NoFilter) + return ""; + + bool isStart = true; + string sql; + for (const auto &filter : filters) { + if (!(mask & filter)) + continue; + + if (isStart) { + isStart = false; + sql += " WHERE "; + } else + sql += " OR "; + sql += " event_type_id = "; + sql += mapEventFilterToSql(filter); + } + + return sql; + } + +// ----------------------------------------------------------------------------- + void EventsDb::init () { L_D(EventsDb); soci::session *session = d->dbSession.getBackendSession(); From b6952c1dbac68328d67f7215febf0a268ee746bd Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 25 Aug 2017 15:55:00 +0200 Subject: [PATCH 49/49] fix(EventsDb): search correctly enum value --- src/db/events-db.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index b8fe9ac89..d6c90fb29 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -55,6 +55,15 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} const char *second; }; + template + static constexpr const char *mapEnumToSql (const EnumToSql enumToSql[], size_t n, T key) { + return n == 0 ? "" : ( + enumToSql[n - 1].first == key ? enumToSql[n - 1].second : mapEnumToSql(enumToSql, n - 1, key) + ); + } + +// ----------------------------------------------------------------------------- + static constexpr EnumToSql eventFilterToSql[] = { { EventsDb::MessageFilter, "1" }, { EventsDb::CallFilter, "2" }, @@ -62,11 +71,9 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} }; static constexpr const char *mapEventFilterToSql (EventsDb::Filter filter) { - return eventFilterToSql[filter].second; - } - - static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { - return direction == Message::Direction::Incoming ? "1" : "2"; + return mapEnumToSql( + eventFilterToSql, sizeof eventFilterToSql / sizeof eventFilterToSql[0], filter + ); } static constexpr EnumToSql messageStateToSql[] = { @@ -81,7 +88,13 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} }; static constexpr const char *mapMessageStateToSql (Message::State state) { - return messageStateToSql[state].second; + return mapEnumToSql( + messageStateToSql, sizeof messageStateToSql / sizeof messageStateToSql[0], state + ); + } + + static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { + return direction == Message::Direction::Incoming ? "1" : "2"; } // -----------------------------------------------------------------------------