From 0130de40cd60776531429f1b51f85c8ca9373f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Thu, 7 Sep 2017 14:45:47 +0200 Subject: [PATCH 1/7] Makes the CSharp wrapper generator to work with Python 3 --- wrappers/csharp/genwrapper.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/wrappers/csharp/genwrapper.py b/wrappers/csharp/genwrapper.py index 2bf303cf6..e5aad72a7 100644 --- a/wrappers/csharp/genwrapper.py +++ b/wrappers/csharp/genwrapper.py @@ -22,7 +22,7 @@ import sys import pystache sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'tools')) -print sys.path +print(sys.path) import genapixml as CApi import abstractapi as AbsApi import metadoc @@ -604,17 +604,18 @@ def main(): interfaces = [] classes = [] - for _class in parser.classesIndex.values() + parser.interfacesIndex.values(): - if _class is not None: - try: - if type(_class) is AbsApi.Class: - impl = ClassImpl(_class, translator) - classes.append(impl) - else: - impl = InterfaceImpl(_class, translator) - interfaces.append(impl) - except AbsApi.Error as e: - print('Could not translate {0}: {1}'.format(_class.name.to_camel_case(fullName=True), e.args[0])) + for index in [parser.classesIndex, parser.interfacesIndex]: + for _class in index.values(): + if _class is not None: + try: + if type(_class) is AbsApi.Class: + impl = ClassImpl(_class, translator) + classes.append(impl) + else: + impl = InterfaceImpl(_class, translator) + interfaces.append(impl) + except AbsApi.Error as e: + print('Could not translate {0}: {1}'.format(_class.name.to_camel_case(fullName=True), e.args[0])) wrapper = WrapperImpl(enums, interfaces, classes) render(renderer, wrapper, args.outputdir + "/" + args.outputfile) From f94f51521ce3e918ddca28455f4db99bab0d8091 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 7 Sep 2017 15:56:26 +0200 Subject: [PATCH 2/7] feat(core): rename message to chat-message --- src/CMakeLists.txt | 12 +-- src/address/address.cpp | 3 +- .../message.cpp => chat/chat-message.cpp} | 98 +++++++++--------- .../message.h => chat/chat-message.h} | 19 ++-- src/db/events-db.cpp | 34 +++--- tester/db/linphone.db | Bin 18432 -> 18432 bytes 6 files changed, 84 insertions(+), 82 deletions(-) rename src/{message/message.cpp => chat/chat-message.cpp} (53%) rename src/{message/message.h => chat/chat-message.h} (89%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94c5f0f96..c1143fb8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,12 +24,13 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES address/address-p.h address/address.h c-wrapper/c-tools.h + chat/chat-message.h chat/chat-room-p.h chat/chat-room.h - content/content.h - core/core.h chat/imdn.h chat/is-composing.h + content/content.h + core/core.h cpim/cpim.h cpim/header/cpim-core-headers.h cpim/header/cpim-generic-header.h @@ -53,7 +54,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES event-log/event-log.h event-log/message-event.h logger/logger.h - message/message.h object/clonable-object-p.h object/clonable-object.h object/object-p.h @@ -66,11 +66,12 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES address/address.cpp c-wrapper/api/c-address.cpp c-wrapper/api/c-event-log.cpp + chat/chat-message.cpp chat/chat-room.cpp - content/content.cpp - core/core.cpp chat/imdn.cpp chat/is-composing.cpp + content/content.cpp + core/core.cpp cpim/header/cpim-core-headers.cpp cpim/header/cpim-generic-header.cpp cpim/header/cpim-header.cpp @@ -87,7 +88,6 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES event-log/event-log.cpp event-log/message-event.cpp logger/logger.cpp - message/message.cpp object/clonable-object.cpp object/object.cpp utils/content-type.cpp diff --git a/src/address/address.cpp b/src/address/address.cpp index ebb88f4ab..7bac71911 100644 --- a/src/address/address.cpp +++ b/src/address/address.cpp @@ -16,9 +16,8 @@ * along with this program. If not, see . */ - #include "linphone/utils/utils.h" -#include +#include "sal/sal.h" #include "address-p.h" #include "c-wrapper/c-tools.h" diff --git a/src/message/message.cpp b/src/chat/chat-message.cpp similarity index 53% rename from src/message/message.cpp rename to src/chat/chat-message.cpp index a4e907426..1e6a987ad 100644 --- a/src/message/message.cpp +++ b/src/chat/chat-message.cpp @@ -1,5 +1,5 @@ /* - * message.cpp + * chat-message.cpp * Copyright (C) 2017 Belledonne Communications SARL * * This program is free software: you can redistribute it and/or modify @@ -21,7 +21,7 @@ #include "db/events-db.h" #include "object/object-p.h" -#include "message.h" +#include "chat-message.h" // ============================================================================= @@ -29,10 +29,10 @@ LINPHONE_BEGIN_NAMESPACE using namespace std; -class MessagePrivate : public ObjectPrivate { +class ChatMessagePrivate : public ObjectPrivate { private: weak_ptr chatRoom; - Message::Direction direction = Message::Incoming; + ChatMessage::Direction direction = ChatMessage::Incoming; // LinphoneAddress *from; // LinphoneAddress *to; shared_ptr errorInfo; @@ -44,18 +44,18 @@ private: string appData; list > contents; unordered_map customHeaders; - Message::State state = Message::Idle; + ChatMessage::State state = ChatMessage::Idle; shared_ptr eventsDb; - L_DECLARE_PUBLIC(Message); + L_DECLARE_PUBLIC(ChatMessage); }; // ----------------------------------------------------------------------------- -Message::Message (MessagePrivate &p) : Object(p) {} +ChatMessage::ChatMessage (ChatMessagePrivate &p) : Object(p) {} -shared_ptr Message::getChatRoom () const { - L_D(const Message); +shared_ptr ChatMessage::getChatRoom () const { + L_D(const ChatMessage); shared_ptr chatRoom = d->chatRoom.lock(); if (!chatRoom) { // TODO. @@ -63,110 +63,110 @@ shared_ptr Message::getChatRoom () const { return chatRoom; } -Message::Direction Message::getDirection () const { - L_D(const Message); +ChatMessage::Direction ChatMessage::getDirection () const { + L_D(const ChatMessage); return d->direction; } -shared_ptr Message::getFromAddress () const { +shared_ptr ChatMessage::getFromAddress () const { // TODO. return nullptr; } -shared_ptr Message::getToAddress () const { +shared_ptr ChatMessage::getToAddress () const { // TODO. return nullptr; } -shared_ptr Message::getLocalAddress () const { +shared_ptr ChatMessage::getLocalAddress () const { // TODO. return nullptr; } -shared_ptr Message::getRemoteAddress () const { +shared_ptr ChatMessage::getRemoteAddress () const { // TODO. return nullptr; } -Message::State Message::getState () const { - L_D(const Message); +ChatMessage::State ChatMessage::getState () const { + L_D(const ChatMessage); return d->state; } -shared_ptr Message::getErrorInfo () const { - L_D(const Message); +shared_ptr ChatMessage::getErrorInfo () const { + L_D(const ChatMessage); return d->errorInfo; } -string Message::getContentType () const { - L_D(const Message); +string ChatMessage::getContentType () const { + L_D(const ChatMessage); return d->contentType; } -string Message::getText () const { - L_D(const Message); +string ChatMessage::getText () const { + L_D(const ChatMessage); return d->text; } -void Message::setText (const string &text) { - L_D(Message); +void ChatMessage::setText (const string &text) { + L_D(ChatMessage); d->text = text; } -void Message::send () const { +void ChatMessage::send () const { // TODO. } -bool Message::containsReadableText () const { +bool ChatMessage::containsReadableText () const { // TODO: Check content type. return true; } -bool Message::isSecured () const { - L_D(const Message); +bool ChatMessage::isSecured () const { + L_D(const ChatMessage); return d->isSecured; } -time_t Message::getTime () const { - L_D(const Message); +time_t ChatMessage::getTime () const { + L_D(const ChatMessage); return d->time; } -string Message::getId () const { - L_D(const Message); +string ChatMessage::getId () const { + L_D(const ChatMessage); return d->id; } -string Message::getAppdata () const { - L_D(const Message); +string ChatMessage::getAppdata () const { + L_D(const ChatMessage); return d->appData; } -void Message::setAppdata (const string &appData) { - L_D(Message); +void ChatMessage::setAppdata (const string &appData) { + L_D(ChatMessage); d->appData = appData; } -list > Message::getContents () const { - L_D(const Message); +list > ChatMessage::getContents () const { + L_D(const ChatMessage); list > contents; for (const auto &content : d->contents) contents.push_back(content); return contents; } -void Message::addContent (const shared_ptr &content) { - L_D(Message); +void ChatMessage::addContent (const shared_ptr &content) { + L_D(ChatMessage); d->contents.push_back(content); } -void Message::removeContent (const shared_ptr &content) { - L_D(Message); +void ChatMessage::removeContent (const shared_ptr &content) { + L_D(ChatMessage); d->contents.remove(const_pointer_cast(content)); } -string Message::getCustomHeaderValue (const string &headerName) const { - L_D(const Message); +string ChatMessage::getCustomHeaderValue (const string &headerName) const { + L_D(const ChatMessage); try { return d->customHeaders.at(headerName); } catch (const exception &) { @@ -175,13 +175,13 @@ string Message::getCustomHeaderValue (const string &headerName) const { return ""; } -void Message::addCustomHeader (const string &headerName, const string &headerValue) { - L_D(Message); +void ChatMessage::addCustomHeader (const string &headerName, const string &headerValue) { + L_D(ChatMessage); d->customHeaders[headerName] = headerValue; } -void Message::removeCustomHeader (const string &headerName) { - L_D(Message); +void ChatMessage::removeCustomHeader (const string &headerName) { + L_D(ChatMessage); d->customHeaders.erase(headerName); } diff --git a/src/message/message.h b/src/chat/chat-message.h similarity index 89% rename from src/message/message.h rename to src/chat/chat-message.h index 3bb643315..830cf9991 100644 --- a/src/message/message.h +++ b/src/chat/chat-message.h @@ -1,5 +1,5 @@ /* - * message.h + * chat-message.h * Copyright (C) 2017 Belledonne Communications SARL * * This program is free software: you can redistribute it and/or modify @@ -16,12 +16,11 @@ * along with this program. If not, see . */ -#ifndef _MESSAGE_H_ -#define _MESSAGE_H_ +#ifndef _CHAT_MESSAGE_H_ +#define _CHAT_MESSAGE_H_ #include #include -#include #include "object/object.h" @@ -33,9 +32,9 @@ class Address; class ChatRoom; class Content; class ErrorInfo; -class MessagePrivate; +class ChatMessagePrivate; -class LINPHONE_PUBLIC Message : public Object { +class LINPHONE_PUBLIC ChatMessage : public Object { friend class ChatRoom; public: @@ -95,12 +94,12 @@ public: void removeCustomHeader (const std::string &headerName); private: - Message (MessagePrivate &p); + ChatMessage (ChatMessagePrivate &p); - L_DECLARE_PRIVATE(Message); - L_DISABLE_COPY(Message); + L_DECLARE_PRIVATE(ChatMessage); + L_DISABLE_COPY(ChatMessage); }; LINPHONE_END_NAMESPACE -#endif // ifndef _MESSAGE_H_ +#endif // ifndef _CHAT_MESSAGE_H_ diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index a9ce194f7..7fdc13037 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -23,10 +23,10 @@ #endif // ifdef SOCI_ENABLED #include "abstract/abstract-db-p.h" +#include "chat/chat-message.h" #include "event-log/call-event.h" #include "event-log/message-event.h" #include "logger/logger.h" -#include "message/message.h" #include "events-db.h" @@ -75,25 +75,25 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} ); } - 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 EnumToSql messageStateToSql[] = { + { ChatMessage::Idle, "1" }, + { ChatMessage::InProgress, "2" }, + { ChatMessage::Delivered, "3" }, + { ChatMessage::NotDelivered, "4" }, + { ChatMessage::FileTransferError, "5" }, + { ChatMessage::FileTransferDone, "6" }, + { ChatMessage::DeliveredToUser, "7" }, + { ChatMessage::Displayed, "8" } }; - static constexpr const char *mapMessageStateToSql (Message::State state) { + static constexpr const char *mapMessageStateToSql (ChatMessage::State state) { return mapEnumToSql( messageStateToSql, sizeof messageStateToSql / sizeof messageStateToSql[0], state ); } - static constexpr const char *mapMessageDirectionToSql (Message::Direction direction) { - return direction == Message::Direction::Incoming ? "1" : "2"; + static constexpr const char *mapMessageDirectionToSql (ChatMessage::Direction direction) { + return direction == ChatMessage::Direction::Incoming ? "1" : "2"; } // ----------------------------------------------------------------------------- @@ -188,6 +188,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} " dialog_id INT UNSIGNED NOT NULL," " state_id TINYINT UNSIGNED NOT NULL," " direction_id TINYINT UNSIGNED NOT NULL," + " sender_sip_address_id INT UNSIGNED NOT NULL," " imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3 " is_secured BOOLEAN NOT NULL," " content_type VARCHAR(255) NOT NULL," // Content type of text. (Html or text for example.) @@ -204,6 +205,9 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} " ON DELETE CASCADE," " FOREIGN KEY (direction_id)" " REFERENCES message_direction(id)" + " ON DELETE CASCADE," + " FOREIGN KEY (sender_sip_address_id)" + " REFERENCES sip_address(id)" " ON DELETE CASCADE" ")"; @@ -379,8 +383,8 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} " SELECT id FROM sip_address WHERE value = :remote_address" " )" " )" - " AND direction_id = " + string(mapMessageDirectionToSql(Message::Incoming)) + - " AND state_id = " + string(mapMessageStateToSql(Message::Displayed)); + " AND direction_id = " + string(mapMessageDirectionToSql(ChatMessage::Incoming)) + + " AND state_id = " + string(mapMessageStateToSql(ChatMessage::Displayed)); int count = 0; L_BEGIN_LOG_EXCEPTION diff --git a/tester/db/linphone.db b/tester/db/linphone.db index 46eb44d6482827ae237e76bb93c06a543a4ec378..948bb10a2d5072d623865650d9b3c5a006eefe49 100644 GIT binary patch delta 95 zcmZpez}PT>aRaLjJHt)}Alf=vkYx=wOPdQ1ySTbKV~_jfFxziz#i@BIsYR1z4HYN5 w+UZZ8X(up7B(aRaLjJEIQ+qYtCUW<{9 From 795b46413bcc6ae4e590831bd43f8c660adff3c9 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 7 Sep 2017 16:00:58 +0200 Subject: [PATCH 3/7] fix(core): sort include --- src/chat/chat-room.cpp | 4 ---- src/chat/imdn.cpp | 6 +++--- src/chat/is-composing.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp index 3aeac16d8..9ca62c0b3 100644 --- a/src/chat/chat-room.cpp +++ b/src/chat/chat-room.cpp @@ -21,8 +21,6 @@ #include "linphone/utils/utils.h" #include "chat-room-p.h" - -#include "chat-room.h" #include "imdn.h" #include "logger/logger.h" #include "utils/content-type.h" @@ -35,8 +33,6 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -// ============================================================================= - ChatRoomPrivate::ChatRoomPrivate (LinphoneCore *core) : core(core), isComposingHandler(core, this) {} diff --git a/src/chat/imdn.cpp b/src/chat/imdn.cpp index 79b953cbe..e0c0696ca 100644 --- a/src/chat/imdn.cpp +++ b/src/chat/imdn.cpp @@ -16,16 +16,16 @@ * along with this program. If not, see . */ +#include "logger/logger.h" + #include "imdn.h" -#include "logger/logger.h" +// ============================================================================= using namespace std; LINPHONE_BEGIN_NAMESPACE -// ============================================================================= - const string Imdn::imdnPrefix = "/imdn:imdn"; void Imdn::parse (ChatRoom &cr, const string &text) { diff --git a/src/chat/is-composing.cpp b/src/chat/is-composing.cpp index 4a6e9a98a..efc1c685d 100644 --- a/src/chat/is-composing.cpp +++ b/src/chat/is-composing.cpp @@ -16,19 +16,19 @@ * along with this program. If not, see . */ -#include "is-composing.h" +#include "linphone/utils/utils.h" #include "chat-room-p.h" - #include "logger/logger.h" -#include "linphone/utils/utils.h" + +#include "is-composing.h" + +// ============================================================================= using namespace std; LINPHONE_BEGIN_NAMESPACE -// ============================================================================= - const string IsComposing::isComposingPrefix = "/xsi:isComposing"; // ----------------------------------------------------------------------------- From a87e810a9b8024cf5ce67b076cc727f2a30152d9 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 7 Sep 2017 16:25:25 +0200 Subject: [PATCH 4/7] Flexisip's DOS test wasn't working --- tester/flexisip_tester.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tester/flexisip_tester.c b/tester/flexisip_tester.c index 1c987a249..324b82221 100644 --- a/tester/flexisip_tester.c +++ b/tester/flexisip_tester.c @@ -955,7 +955,7 @@ static void dos_module_trigger(void) { // At this point we should be banned for a minute wait_for_until(marie->lc, pauline->lc, &dummy, 1, 65000);; // Wait several seconds to ensure we are not banned anymore - BC_ASSERT_LOWER(marie->stat.number_of_LinphoneMessageReceived, number_of_messge_to_send, int, "%d"); + BC_ASSERT_LOWER_STRICT(marie->stat.number_of_LinphoneMessageReceived, number_of_messge_to_send, int, "%d"); reset_counters(&marie->stat); reset_counters(&pauline->stat); From 1ff50ec17953d722c9558d843acbe7220dd6fcd8 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 8 Sep 2017 09:23:57 +0200 Subject: [PATCH 5/7] feat(Events): finish impl --- src/c-wrapper/c-tools.h | 15 +++++++++++---- src/event-log/conference-event.cpp | 14 ++++++-------- src/event-log/conference-participant-event.cpp | 11 +++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/c-wrapper/c-tools.h b/src/c-wrapper/c-tools.h index 9d8975fb8..8f4b6d738 100644 --- a/src/c-wrapper/c-tools.h +++ b/src/c-wrapper/c-tools.h @@ -47,18 +47,22 @@ public: template static inline std::shared_ptr getCppPtrFromC (void *object) { - if (!object) - return std::shared_ptr(); + L_ASSERT(object); return static_cast *>(object)->cppPtr; } template static inline std::shared_ptr getCppPtrFromC (const void *object) { - if (!object) - return std::shared_ptr(); + L_ASSERT(object); return static_cast *>(object)->cppPtr; } + template + static inline void setCppPtrFromC (void *object, std::shared_ptr &cppPtr) { + L_ASSERT(object); + static_cast *>(object)->cppPtr = cppPtr; + } + private: Wrapper (); @@ -108,6 +112,9 @@ LINPHONE_END_NAMESPACE #define L_GET_CPP_PTR_FROM_C_STRUCT(OBJECT, TYPE) \ LINPHONE_NAMESPACE::Wrapper::getCppPtrFromC(OBJECT) +#define L_SET_CPP_PTR_FROM_C_STRUCT(OBJECT, CPP_PTR) \ + LINPHONE_NAMESPACE::Wrapper::setCppPtrFromC(OBJECT, CPP_PTR) + #define L_GET_PRIVATE(OBJECT) \ LINPHONE_NAMESPACE::Wrapper::getPrivate(OBJECT) diff --git a/src/event-log/conference-event.cpp b/src/event-log/conference-event.cpp index cfb4ca69c..16486a929 100644 --- a/src/event-log/conference-event.cpp +++ b/src/event-log/conference-event.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "address/address.h" #include "conference-event-p.h" #include "conference-event.h" @@ -31,8 +32,7 @@ ConferenceEvent::ConferenceEvent (Type type, const shared_ptr &ad L_D(ConferenceEvent); L_ASSERT(type == TypeConferenceCreated || type == TypeConferenceDestroyed); L_ASSERT(address); - // TODO: Duplicate address. - d->address = address; + d->address = make_shared
(*address); } ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : ConferenceEvent(src.getType(), src.getAddress()) {} @@ -41,24 +41,22 @@ ConferenceEvent::ConferenceEvent (ConferenceEventPrivate &p, Type type, const sh EventLog(p, type) { L_D(ConferenceEvent); L_ASSERT(address); - // TODO: Duplicate address. - d->address = address; + d->address = make_shared
(*address); } ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { L_D(ConferenceEvent); if (this != &src) { EventLog::operator=(src); - // TODO: Duplicate address. - d->address = src.getPrivate()->address; + d->address = make_shared
(*src.getPrivate()->address); } return *this; } shared_ptr ConferenceEvent::getAddress () const { - // TODO. - return nullptr; + L_D(const ConferenceEvent); + return d->address; } LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference-participant-event.cpp b/src/event-log/conference-participant-event.cpp index 0095da63a..d1d647f75 100644 --- a/src/event-log/conference-participant-event.cpp +++ b/src/event-log/conference-participant-event.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "address/address.h" #include "conference-event-p.h" #include "conference-participant-event.h" @@ -46,8 +47,7 @@ ConferenceParticipantEvent::ConferenceParticipantEvent ( type == TypeConferenceParticipantUnsetAdmin ); L_ASSERT(participantAddress); - // TODO: Duplicate address. - d->participantAddress = participantAddress; + d->participantAddress = make_shared
(*participantAddress); } ConferenceParticipantEvent::ConferenceParticipantEvent (const ConferenceParticipantEvent &src) : @@ -57,16 +57,15 @@ ConferenceParticipantEvent &ConferenceParticipantEvent::operator= (const Confere L_D(ConferenceParticipantEvent); if (this != &src) { ConferenceEvent::operator=(src); - // TODO: Duplicate address. - d->participantAddress = src.getPrivate()->participantAddress; + d->participantAddress = make_shared
(*src.getPrivate()->participantAddress); } return *this; } shared_ptr ConferenceParticipantEvent::getParticipantAddress () const { - // TODO. - return nullptr; + L_D(const ConferenceParticipantEvent); + return d->participantAddress; } LINPHONE_END_NAMESPACE From c0696f786d3b923e94f22ca2850024045277b6e3 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 8 Sep 2017 11:17:18 +0200 Subject: [PATCH 6/7] zrtp cache migration must only take uri from local identity instead of whole LinphoneAddress, including display name. --- coreapi/linphonecore.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 5c881db24..7e727b775 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6541,6 +6541,7 @@ void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook } void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){ + LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(lc); if (lc->zrtp_secrets_cache != NULL) { ms_free(lc->zrtp_secrets_cache); } @@ -6548,7 +6549,7 @@ void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){ lc->zrtp_secrets_cache=file ? ms_strdup(file) : NULL; /* shall we perform cache migration ? */ - if (!lp_config_get_int(lc->config,"sip","zrtp_cache_migration_done",FALSE)) { + if (proxy && !lp_config_get_int(lc->config,"sip","zrtp_cache_migration_done",FALSE)) { char *tmpFile = reinterpret_cast(bctbx_malloc(strlen(file)+6)); /* check we have a valid xml cache file given in path */ FILE *CACHEFD = NULL; @@ -6579,12 +6580,13 @@ void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){ /* migrate */ char *bkpFile = reinterpret_cast(bctbx_malloc(strlen(file)+6)); sprintf(bkpFile,"%s.bkp", file); - - if ((ret = ms_zrtp_cache_migration((void *)cacheXml, linphone_core_get_zrtp_cache_db(lc), linphone_core_get_identity(lc))) == 0) { + char *selfURI = linphone_address_as_string_uri_only(linphone_proxy_config_get_identity_address(proxy)); + if ((ret = ms_zrtp_cache_migration((void *)cacheXml, linphone_core_get_zrtp_cache_db(lc), selfURI)) == 0) { ms_message("LIME/ZRTP cache migration successfull, obsolete xml file kept as backup in %s", bkpFile); } else { ms_error("LIME/ZRTP cache migration failed(returned -%x), start with a fresh cache, old one kept as backup in %s", -ret, bkpFile); } + ms_free(selfURI); /* rename the newly created sqlite3 file in to the given file name */ rename(file, bkpFile); From 252925a3737f440b506d2c2681b3f18d7468b6d5 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 8 Sep 2017 13:58:19 +0200 Subject: [PATCH 7/7] improve logging to make sure all logger are handler by liblinphone, including, ortp, bzrtp and belle-sip --- coreapi/bellesip_sal/sal_impl.c | 1 - coreapi/linphonecore.c | 42 ++++++++++++++++----------------- tester/message_tester.c | 17 ++++++++++++- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 4aa2c1fb8..b2fe0d69a 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -487,7 +487,6 @@ 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_handler); //printf by default sal->stack = belle_sip_stack_new(NULL); sal->user_agent=belle_sip_header_user_agent_new(); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 7e727b775..d629a5d93 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -103,7 +103,8 @@ inline OrtpLogLevel operator|=(OrtpLogLevel a, OrtpLogLevel b) { return static_cast(ia |= ib); } -static OrtpLogFunc liblinphone_log_func = NULL; +static OrtpLogFunc liblinphone_user_log_func = bctbx_logv_out; /*by default, user log handler = stdout*/ +static OrtpLogFunc liblinphone_current_log_func = NULL; /*can be either logcolection or user_log*/ static LinphoneLogCollectionState liblinphone_log_collection_state = LinphoneLogCollectionDisabled; static char * liblinphone_log_collection_path = NULL; static char * liblinphone_log_collection_prefix = NULL; @@ -463,20 +464,18 @@ const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _Lin static void linphone_core_log_collection_handler(const char *domain, OrtpLogLevel level, const char *fmt, va_list args); void linphone_core_set_log_handler(OrtpLogFunc logfunc) { - if (ortp_get_log_handler() == linphone_core_log_collection_handler) { + liblinphone_user_log_func = logfunc; + if (liblinphone_current_log_func == linphone_core_log_collection_handler) { ms_message("There is already a log collection handler, keep it"); - liblinphone_log_func = logfunc; } else { - ortp_set_log_handler(logfunc); - sal_set_log_handler(logfunc); + bctbx_set_log_handler(liblinphone_current_log_func=liblinphone_user_log_func); } } void linphone_core_set_log_file(FILE *file) { if (file == NULL) file = stdout; + linphone_core_set_log_handler(NULL); 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) { @@ -507,6 +506,7 @@ void linphone_core_set_log_level(OrtpLogLevel loglevel) { void linphone_core_set_log_level_mask(unsigned int loglevel) { //we only have 2 domain for now ortp and belle-sip bctbx_set_log_level_mask(ORTP_LOG_DOMAIN, loglevel); + bctbx_set_log_level_mask("bzrtp", loglevel); /*need something to set log lvel for all domains*/ sal_set_log_level((OrtpLogLevel)loglevel); } unsigned int linphone_core_get_log_level_mask(void) { @@ -575,11 +575,11 @@ static void linphone_core_log_collection_handler(const char *domain, OrtpLogLeve time_t tt; int ret; - if (liblinphone_log_func != NULL && liblinphone_log_func != linphone_core_log_collection_handler) { + if (liblinphone_user_log_func != NULL && liblinphone_user_log_func != linphone_core_log_collection_handler) { #ifndef _WIN32 va_list args_copy; va_copy(args_copy, args); - liblinphone_log_func(domain, level, fmt, args_copy); + liblinphone_user_log_func(domain, level, fmt, args_copy); va_end(args_copy); #else /* This works on 32 bits, luckily. */ @@ -687,24 +687,15 @@ LinphoneLogCollectionState linphone_core_log_collection_enabled(void) { void linphone_core_enable_log_collection(LinphoneLogCollectionState state) { if (liblinphone_log_collection_state == state) return; - /* at first call of this function, set liblinphone_log_func to the current - * ortp log function */ - if( liblinphone_log_func == NULL ){ - liblinphone_log_func = ortp_get_log_handler(); - } liblinphone_log_collection_state = state; if (state != LinphoneLogCollectionDisabled) { ortp_mutex_init(&liblinphone_log_collection_mutex, NULL); if (state == LinphoneLogCollectionEnabledWithoutPreviousLogHandler) { - liblinphone_log_func = NULL; - } else { - liblinphone_log_func = ortp_get_log_handler(); + liblinphone_user_log_func = NULL; /*remove user log handler*/ } - ortp_set_log_handler(linphone_core_log_collection_handler); - sal_set_log_handler(linphone_core_log_collection_handler); + bctbx_set_log_handler(liblinphone_current_log_func = linphone_core_log_collection_handler); } else { - ortp_set_log_handler(liblinphone_log_func); - sal_set_log_handler(liblinphone_log_func); + bctbx_set_log_handler(liblinphone_user_log_func); /*restaure */ } } @@ -2170,7 +2161,11 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig LinphoneCoreCbs *internal_cbs = _linphone_core_cbs_new(); const char *msplugins_dir; const char *image_resources_dir; - + + bctbx_init_logger(FALSE); + if (liblinphone_user_log_func && liblinphone_current_log_func == NULL) + bctbx_set_log_handler(liblinphone_current_log_func=liblinphone_user_log_func); /*default value*/ + ms_message("Initializing LinphoneCore %s", linphone_core_get_version()); lc->config=lp_config_ref(config); @@ -2198,7 +2193,9 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up"); + ortp_set_log_handler(NULL); /*remove ortp default log handler*/ ortp_init(); + linphone_core_activate_log_serialization_if_needed(); msplugins_dir = linphone_factory_get_msplugins_dir(lfactory); @@ -6156,6 +6153,7 @@ static void linphone_core_uninit(LinphoneCore *lc) bctbx_list_free_with_data(lc->vtable_refs,(void (*)(void *))v_table_reference_destroy); ms_bandwidth_controller_destroy(lc->bw_controller); ms_factory_destroy(lc->factory); + bctbx_uninit_logger(); } static void stop_refreshing_proxy_config(bool_t is_sip_reachable, LinphoneProxyConfig* cfg) { diff --git a/tester/message_tester.c b/tester/message_tester.c index 2bd560c2b..ddbf20023 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -1462,6 +1462,13 @@ static void lime_cache_migration(void) { fclose(xmlCacheFD); LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); + LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(marie->lc); + LinphoneAddress *new_identity = linphone_address_clone(linphone_proxy_config_get_identity_address(cfg)); + linphone_proxy_config_edit(cfg); + linphone_address_set_display_name(new_identity,"what about if we have a display name ?"); + linphone_proxy_config_set_identity_address(cfg, new_identity); + + linphone_proxy_config_done(cfg); if (!linphone_core_lime_available(marie->lc)) { ms_warning("Lime not available, skiping"); @@ -1476,7 +1483,15 @@ static void lime_cache_migration(void) { /* set the cache path, it will trigger the migration function */ linphone_core_set_zrtp_secrets_file(marie->lc, xmlCache_filepath); - + /*short check*/ + limeKey_t associatedKey={0}; + + char * selfURI = linphone_address_as_string_uri_only(new_identity); + linphone_address_unref(new_identity); + bctbx_str_to_uint8(associatedKey.peerZID, (const uint8_t *)"0987654321fedcba5a5a5a5a", (uint16_t)strlen("0987654321fedcba5a5a5a5a")); + /* 0987654321fedcba5a5a5a5a is the only one with pvs=1*/ + BC_ASSERT_FALSE(lime_getCachedRcvKeyByZid(marie->lc->zrtp_cache_db, &associatedKey, selfURI, "sip:bob@sip.linphone.org")); + ms_free(selfURI); /* perform checks on the new cache, simple check is ok as deeper ones are performed in the bzrtp migration tester */ /* TODO */