Commit 82b3ab30 authored by Ronan's avatar Ronan

feat(Event): init

parent 12ad3540
......@@ -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_VCARD "Turn on compilation of vcard4 support." YES)
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)
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)
set(CMAKE_CXX_STANDARD 11)
if(ENABLE_STATIC)
set(LINPHONE_LIBS_FOR_TOOLS linphone-static)
else()
......
......@@ -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)
......
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _ABSTRACT_DB_P_H_
#define _ABSTRACT_DB_P_H_
#include <soci/soci.h>
#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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 &parameters) {
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
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _ABSTRACT_DB_H_
#define _ABSTRACT_DB_H_
#include <string>
#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 &parameters);
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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "call-event.h"
// =============================================================================
// TODO.
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "message-event.h"
// =============================================================================
// TODO.
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _MESSAGE_EVENT_H_
#define _MESSAGE_EVENT_H_
#include <list>
#include <string>
#include "event.h"
#include "utils/linphone.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ErrorInfo;
class Message;
class MessageEventPrivate;
class MessageEvent : public Event {
public:
typedef std::pair<std::string, std::string> 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<CustomHeader> getCustomHeaders () const;
private:
L_DECLARE_PRIVATE(MessageEvent);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _MESSAGE_EVENT_H_
......@@ -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
......@@ -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
......
......@@ -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 }