diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index c33e60c03..2a826f0e3 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -57,6 +57,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "chat/chat-room/server-group-chat-room-p.h" #include "conference/handlers/local-conference-list-event-handler.h" #include "conference/handlers/remote-conference-event-handler.h" +#include "conference/handlers/remote-conference-list-event-handler.h" #include "content/content-manager.h" #include "content/content-type.h" #include "core/core-p.h" @@ -2134,33 +2135,38 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve } } else if (strcmp(notified_event, "conference") == 0) { const LinphoneAddress *resource = linphone_event_get_resource(lev); + if (strcmp(linphone_address_as_string_uri_only(resource), linphone_proxy_config_get_conference_factory_uri(linphone_core_get_default_proxy_config(lc))) == 0) { + L_GET_PRIVATE_FROM_C_OBJECT(lc)->remoteListEventHandler->notifyReceived(L_GET_CPP_PTR_FROM_C_OBJECT(body)); + return; + } + const LinphoneAddress *from = linphone_event_get_from(lev); shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) )); + if (!chatRoom) + return; - if (chatRoom) { - shared_ptr cgcr; - if (chatRoom->getCapabilities() & ChatRoom::Capabilities::Proxy) - cgcr = static_pointer_cast( - static_pointer_cast(chatRoom)->getProxiedChatRoom()); - else - cgcr = static_pointer_cast(chatRoom); + shared_ptr cgcr; + if (chatRoom->getCapabilities() & ChatRoom::Capabilities::Proxy) + cgcr = static_pointer_cast( + static_pointer_cast(chatRoom)->getProxiedChatRoom()); + else + cgcr = static_pointer_cast(chatRoom); - if (linphone_content_is_multipart(body)) { - // TODO : migrate to c++ 'Content'. - int i = 0; - LinphoneContent *part = NULL; - while ((part = linphone_content_get_part(body, i))) { - i++; - L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(part)); - linphone_content_unref(part); - } - } else - L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(body)); - } + if (linphone_content_is_multipart(body)) { + // TODO : migrate to c++ 'Content'. + int i = 0; + LinphoneContent *part = NULL; + while ((part = linphone_content_get_part(body, i))) { + i++; + L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(part)); + linphone_content_unref(part); + } + } else + L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(body)); } } diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index 98cdeb92f..4b768d2de 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -163,7 +163,9 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con contents.push_front(rlmiContent); Content multipart = ContentManager::contentListToMultipart(contents, MultipartBoundaryListEventHandler); - linphone_event_notify(lev, multipart.toLinphoneContent()); + LinphoneContent *cContent = L_GET_C_BACK_PTR(&multipart); + linphone_event_notify(lev, cContent); + linphone_content_unref(cContent); } // ----------------------------------------------------------------------------- diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index ea619757a..f8ed05304 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -28,8 +28,10 @@ #include "content/content-manager.h" #include "content/content-type.h" #include "core/core-p.h" +#include "logger/logger.h" #include "remote-conference-event-handler.h" #include "remote-conference-list-event-handler.h" +#include "xml/conference-info.h" #include "xml/resource-lists.h" #include "xml/rlmi.h" @@ -109,7 +111,9 @@ void RemoteConferenceListEventHandler::subscribe () { } */ linphone_event_set_user_data(lev, this); - linphone_event_send_subscribe(lev, content.toLinphoneContent()); + LinphoneContent *cContent = L_GET_C_BACK_PTR(&content); + linphone_event_send_subscribe(lev, cContent); + linphone_content_unref(cContent); } void RemoteConferenceListEventHandler::unsubscribe () { @@ -121,12 +125,30 @@ void RemoteConferenceListEventHandler::unsubscribe () { lev = nullptr; } -void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { - list contents = ContentManager::multipartToContentList(*multipart); +void RemoteConferenceListEventHandler::notifyReceived (const Content *notifyContent) { char *from = linphone_address_as_string(linphone_event_get_from(lev)); - const Address local(from); + const IdentityAddress local(from); + + if (notifyContent->getContentType() != ContentType::Multipart) { + // Simple notify received directly from a chat-room + const string &xmlBody = notifyContent->getBodyAsString(); + istringstream data(xmlBody); + unique_ptr confInfo = Xsd::ConferenceInfo::parseConferenceInfo(data, Xsd::XmlSchema::Flags::dont_validate); + + IdentityAddress entityAddress(confInfo->getEntity().c_str()); + lError() << entityAddress; + ChatRoomId id(entityAddress, local); + lError() << id; + RemoteConferenceEventHandler *handler = findHandler(id); + if (!handler) + return; + + handler->notifyReceived(xmlBody); + } + + list contents = ContentManager::multipartToContentList(*notifyContent); bctbx_free(from); - map addresses; + map addresses; for (const auto &content : contents) { const string &body = content.getBodyAsString(); const ContentType &contentType = content.getContentType(); @@ -139,9 +161,9 @@ void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { if (value.empty()) continue; - Address cid(value); - Address peer = addresses[cid]; - ChatRoomId id(local, peer); + IdentityAddress cid(value); + IdentityAddress peer = addresses[cid]; + ChatRoomId id(peer, local); RemoteConferenceEventHandler *handler = findHandler(id); if (!handler) continue; @@ -178,23 +200,23 @@ void RemoteConferenceListEventHandler::removeHandler (RemoteConferenceEventHandl handlers.remove(handler); } -map RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { +map RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { istringstream data(xmlBody); unique_ptr rlmi(Xsd::Rlmi::parseList( data, Xsd::XmlSchema::Flags::dont_validate )); - map addresses; + map addresses; for (const auto &resource : rlmi->getResource()) { if (resource.getInstance().empty()) continue; - Address peer(resource.getUri()); + IdentityAddress peer(resource.getUri()); for (const auto &instance : resource.getInstance()) { if (!instance.getCid().present()) continue; - Address cid(instance.getCid().get()); + IdentityAddress cid(instance.getCid().get()); addresses[cid] = peer; } } diff --git a/src/conference/handlers/remote-conference-list-event-handler.h b/src/conference/handlers/remote-conference-list-event-handler.h index 53bf78e60..81abb2cf6 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.h +++ b/src/conference/handlers/remote-conference-list-event-handler.h @@ -28,7 +28,6 @@ #include "linphone/utils/general.h" #include "chat/chat-room/chat-room-id.h" -#include "content/content.h" #include "core/core-accessor.h" #include "core/core-listener.h" @@ -37,6 +36,7 @@ LINPHONE_BEGIN_NAMESPACE class Address; +class Content; class RemoteConferenceEventHandler; class RemoteConferenceListEventHandler : public CoreAccessor , public CoreListener { @@ -46,7 +46,7 @@ public: void subscribe (); void unsubscribe (); - void notifyReceived (Content *multipart); + void notifyReceived (const Content *notifyContent); void addHandler (RemoteConferenceEventHandler *handler); void removeHandler (RemoteConferenceEventHandler *handler); RemoteConferenceEventHandler *findHandler (const ChatRoomId &chatRoomId) const; @@ -56,7 +56,7 @@ private: std::list handlers; LinphoneEvent *lev = nullptr; - std::map parseRlmi (const std::string &xmlBody) const; + std::map parseRlmi (const std::string &xmlBody) const; // CoreListener void onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) override;