Commit 8626d874 authored by Matthieu Tanon's avatar Matthieu Tanon
Browse files

Upgrade main-db event module version to 1.0.5

Improve conference security events to use enum of security alert types
Usual event filters now take security events in account
parent daa4b687
......@@ -230,7 +230,7 @@ typedef void (*LinphoneChatRoomCbsStateChangedCb) (LinphoneChatRoom *cr, Linphon
/**
* Callback used to notify a security alert in the chat room.
* @param[in] cr #LinphoneChatRoom object
* @param[in] securityAlert the security alert
* @param[in] securityAlertType the security alert type
*/
typedef void (*LinphoneChatRoomCbsSecurityAlertCb) (LinphoneChatRoom *cr, const LinphoneEventLog *event_log);
......
......@@ -35,7 +35,7 @@
F(ConferenceParticipantUnsetAdmin /**< Conference participant (unset admin) event */) \
F(ConferenceParticipantDeviceAdded /**< Conference participant device (added) event */) \
F(ConferenceParticipantDeviceRemoved /**< Conference participant device (removed) event */) \
F(ConferenceSecurityAlert /**< Conference security alert event*/) \
F(ConferenceSubjectChanged /**< Conference subject event */) \
F(ConferenceSecurityAlert /**< Conference security alert event*/) \
#endif // ifndef _L_EVENT_LOG_ENUMS_H_
......@@ -721,7 +721,7 @@ void ClientGroupChatRoom::onSecurityAlert (const shared_ptr<ConferenceSecurityEv
cout << "onSecurityAlert() securityAlert = " << event->getSecurityAlert() << endl;
d->addEvent(event);
// TODO notify the application for UI alert
// notify the application for UI alert
LinphoneChatRoom *cr = d->getCChatRoom();
_linphone_chat_room_notify_security_alert(cr, L_GET_C_BACK_PTR(event));
}
......
......@@ -166,10 +166,12 @@ ChatMessageModifier::Result LimeV2::processOutgoingMessage (const shared_ptr<Cha
// TODO if multidevice is forbidden send a ConferenceSecurityEvent
time_t securityAlertTime = time(nullptr);
const string &securityAlert = "Sending encrypted message to multidevice participant";
shared_ptr<ConferenceSecurityEvent> securityEvent = make_shared<ConferenceSecurityEvent>(securityAlertTime, chatRoom->getConferenceId(), securityAlert);
ConferenceSecurityEvent::SecurityAlertType securityAlertType = ConferenceSecurityEvent::SecurityAlertType::MultideviceParticipant;
shared_ptr<ConferenceSecurityEvent> securityEvent = make_shared<ConferenceSecurityEvent>(securityAlertTime, chatRoom->getConferenceId(), securityAlertType);
shared_ptr<ClientGroupChatRoom> confListener = static_pointer_cast<ClientGroupChatRoom>(chatRoom);
confListener->onSecurityAlert(securityEvent);
// TODO add policies to adapt behaviour when multiple devices
lError() << "Sending encrypted message to multidevice participant";
cout << "[ALERT] Sending encrypted message to multidevice participant (message rejected)" << endl;
return ChatMessageModifier::Result::Error;
......
......@@ -94,7 +94,7 @@ namespace Statements {
)",
/* SelectConferenceEvents */ R"(
SELECT conference_event_view.id AS event_id, type, creation_time, from_sip_address.value, to_sip_address.value, time, imdn_message_id, state, direction, is_secured, notify_id, device_sip_address.value, participant_sip_address.value, subject, delivery_notification_required, display_notification_required
SELECT conference_event_view.id AS event_id, type, creation_time, from_sip_address.value, to_sip_address.value, time, imdn_message_id, state, direction, is_secured, notify_id, device_sip_address.value, participant_sip_address.value, subject, delivery_notification_required, display_notification_required, security_alert
FROM conference_event_view
LEFT JOIN sip_address AS from_sip_address ON from_sip_address.id = from_sip_address_id
LEFT JOIN sip_address AS to_sip_address ON to_sip_address.id = to_sip_address_id
......
......@@ -48,7 +48,7 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
namespace {
constexpr unsigned int ModuleVersionEvents = makeVersion(1, 0, 4);
constexpr unsigned int ModuleVersionEvents = makeVersion(1, 0, 5);
constexpr unsigned int ModuleVersionFriends = makeVersion(1, 0, 0);
constexpr unsigned int ModuleVersionLegacyFriendsImport = makeVersion(1, 0, 0);
constexpr unsigned int ModuleVersionLegacyHistoryImport = makeVersion(1, 0, 0);
......@@ -157,7 +157,7 @@ namespace {
// TODO: Find a workaround to deal with StaticString concatenation!!!
constexpr char ConferenceCallFilter[] = "3,4";
constexpr char ConferenceChatMessageFilter[] = "5";
constexpr char ConferenceInfoNoDeviceFilter[] = "1,2,6,7,8,9,12";
constexpr char ConferenceInfoNoDeviceFilter[] = "1,2,6,7,8,9,12,13";
constexpr char ConferenceInfoFilter[] = "1,2,6,7,8,9,10,11,12";
#else
constexpr auto ConferenceCallFilter = SqlEventFilterBuilder<
......@@ -174,7 +174,8 @@ namespace {
EventLog::Type::ConferenceParticipantRemoved,
EventLog::Type::ConferenceParticipantSetAdmin,
EventLog::Type::ConferenceParticipantUnsetAdmin,
EventLog::Type::ConferenceSubjectChanged
EventLog::Type::ConferenceSubjectChanged,
EventLog::Type::ConferenceSecurityAlert
>::get();
constexpr auto ConferenceInfoFilter = ConferenceInfoNoDeviceFilter + "," + SqlEventFilterBuilder<
......@@ -698,7 +699,7 @@ shared_ptr<EventLog> MainDbPrivate::selectConferenceSecurityEvent (
return make_shared<ConferenceSecurityEvent>(
getConferenceEventCreationTimeFromRow(row),
conferenceId,
row.get<string>(13)
static_cast<ConferenceSecurityEvent::SecurityAlertType>(row.get<int>(16))
);
}
......@@ -941,13 +942,12 @@ long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLo
if (eventId < 0)
return -1;
const string &securityAlert = static_pointer_cast<ConferenceSecurityEvent>(eventLog)->getSecurityAlert();
const int &securityAlertType = int(static_pointer_cast<ConferenceSecurityEvent>(eventLog)->getSecurityAlertType());
// insert security event into new table "conference_security_event"
soci::session *session = dbSession.getBackendSession();
*session << "INSERT INTO conference_security_event (event_id, security_alert)"
" VALUES (:eventId, :securityAlert)", soci::use(eventId), soci::use(securityAlert);
" VALUES (:eventId, :securityAlertType)", soci::use(eventId), soci::use(securityAlertType);
return eventId;
}
......@@ -1100,23 +1100,25 @@ void MainDbPrivate::updateSchema () {
if (version < makeVersion(1, 0, 4)) {
*session << "ALTER TABLE conference_chat_message_event ADD COLUMN delivery_notification_required BOOLEAN NOT NULL DEFAULT 0";
*session << "ALTER TABLE conference_chat_message_event ADD COLUMN display_notification_required BOOLEAN NOT NULL DEFAULT 0";
}
if (version < makeVersion(1, 0, 5)) {
*session << "DROP VIEW IF EXISTS conference_event_view";
string query;
if (q->getBackend() == AbstractDb::Backend::Mysql)
query = "CREATE OR REPLACE VIEW conference_event_view AS";
query = "CREATE VIEW conference_event_view AS";
else
query = "CREATE VIEW IF NOT EXISTS conference_event_view AS";
query = "CREATE VIEW conference_event_view AS";
*session << query +
" SELECT id, type, creation_time, chat_room_id, from_sip_address_id, to_sip_address_id, time, imdn_message_id, state, direction, is_secured, notify_id, device_sip_address_id, participant_sip_address_id, subject, delivery_notification_required, display_notification_required"
" SELECT id, type, creation_time, chat_room_id, from_sip_address_id, to_sip_address_id, time, imdn_message_id, state, direction, is_secured, notify_id, device_sip_address_id, participant_sip_address_id, subject, delivery_notification_required, display_notification_required, security_alert" // TEST
" FROM event"
" LEFT JOIN conference_event ON conference_event.event_id = event.id"
" LEFT JOIN conference_chat_message_event ON conference_chat_message_event.event_id = event.id"
" LEFT JOIN conference_notified_event ON conference_notified_event.event_id = event.id"
" LEFT JOIN conference_participant_device_event ON conference_participant_device_event.event_id = event.id"
" LEFT JOIN conference_participant_event ON conference_participant_event.event_id = event.id"
" LEFT JOIN conference_subject_event ON conference_subject_event.event_id = event.id";
" LEFT JOIN conference_subject_event ON conference_subject_event.event_id = event.id"
" LEFT JOIN conference_security_event ON conference_security_event.event_id = event.id"; // TEST
}
}
......@@ -1555,7 +1557,7 @@ void MainDb::init () {
"CREATE TABLE IF NOT EXISTS conference_security_event ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
" security_alert VARCHAR(255) NOT NULL,"
" security_alert TINYINT UNSIGNED NOT NULL,"
" FOREIGN KEY (event_id)"
" REFERENCES conference_event(event_id)"
......
......@@ -30,7 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
class ConferenceSecurityEventPrivate : public ConferenceEventPrivate {
public:
string securityAlert;
ConferenceSecurityEvent::SecurityAlertType securityAlertType;
};
// -----------------------------------------------------------------------------
......@@ -38,7 +38,7 @@ public:
ConferenceSecurityEvent::ConferenceSecurityEvent (
time_t creationTime,
const ConferenceId &conferenceId,
const string &securityAlert
SecurityAlertType securityAlertType
) : ConferenceEvent(
*new ConferenceSecurityEventPrivate,
Type::ConferenceSecurityAlert,
......@@ -46,12 +46,12 @@ ConferenceSecurityEvent::ConferenceSecurityEvent (
conferenceId
) {
L_D();
d->securityAlert = securityAlert;
d->securityAlertType = securityAlertType;
}
const string &ConferenceSecurityEvent::getSecurityAlert () const {
ConferenceSecurityEvent::SecurityAlertType ConferenceSecurityEvent::getSecurityAlertType () const {
L_D();
return d->securityAlert;
return d->securityAlertType;
}
LINPHONE_END_NAMESPACE
......@@ -31,14 +31,26 @@ LINPHONE_BEGIN_NAMESPACE
class ConferenceSecurityEventPrivate;
class LINPHONE_PUBLIC ConferenceSecurityEvent : public ConferenceEvent {
public:
enum SecurityAlertType {
/**
* Encrypting message to forbidden multidevice participant.
*/
MultideviceParticipant,
/**
* Trying to set lime PeerDeviceStatus using a new identity key.
*/
LimeIdentityKeyChanged
};
ConferenceSecurityEvent (
time_t creationTime,
const ConferenceId &conferenceId,
const std::string &securityAlert
SecurityAlertType securityAlertType
);
const std::string &getSecurityAlert () const;
SecurityAlertType getSecurityAlertType () const;
private:
L_DECLARE_PRIVATE(ConferenceSecurityEvent);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment