From 8f653ab4bf7444c25ec270525b3432a936f791e0 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 15 Mar 2018 15:48:59 +0100 Subject: [PATCH] now it compiles --- src/CMakeLists.txt | 6 ++ .../local-conference-list-event-handler.cpp | 3 +- .../local-conference-list-event-handler.h | 5 +- .../remote-conference-list-event-handler.cpp | 78 +++++++++++++------ .../remote-conference-list-event-handler.h | 21 ++++- src/content/content-p.h | 2 + src/content/content.cpp | 20 +++-- src/content/content.h | 2 +- 8 files changed, 100 insertions(+), 37 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fbca16af0..1408baddb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,8 +73,10 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES conference/conference.h conference/handlers/local-conference-event-handler-p.h conference/handlers/local-conference-event-handler.h + conference/handlers/local-conference-list-event-handler.h conference/handlers/remote-conference-event-handler-p.h conference/handlers/remote-conference-event-handler.h + conference/handlers/remote-conference-list-event-handler.h conference/local-conference-p.h conference/local-conference.h conference/params/call-session-params-p.h @@ -156,6 +158,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES variant/variant.h xml/conference-info.h xml/resource-lists.h + xml/rlmi.h xml/xml.h ) @@ -206,7 +209,9 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES chat/notification/is-composing.cpp conference/conference.cpp conference/handlers/local-conference-event-handler.cpp + conference/handlers/local-conference-list-event-handler.cpp conference/handlers/remote-conference-event-handler.cpp + conference/handlers/remote-conference-list-event-handler.cpp conference/local-conference.cpp conference/params/call-session-params.cpp conference/params/media-session-params.cpp @@ -269,6 +274,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES variant/variant.cpp xml/conference-info.cpp xml/resource-lists.cpp + xml/rlmi.cpp xml/xml.cpp ) diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index 0e4a08a22..37869db0f 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +/* #include "local-conference-list-event-handler.h" // ============================================================================= @@ -28,3 +28,4 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- LINPHONE_END_NAMESPACE +*/ diff --git a/src/conference/handlers/local-conference-list-event-handler.h b/src/conference/handlers/local-conference-list-event-handler.h index 3339433c8..1da508dd7 100644 --- a/src/conference/handlers/local-conference-list-event-handler.h +++ b/src/conference/handlers/local-conference-list-event-handler.h @@ -16,10 +16,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +/* #ifndef _L_LOCAL_CONFERENCE_LIST_EVENT_HANDLER_H_ #define _L_LOCAL_CONFERENCE_LIST_EVENT_HANDLER_H_ +#include "linphone/utils/general.h" + // ============================================================================= LINPHONE_BEGIN_NAMESPACE @@ -41,3 +43,4 @@ private: LINPHONE_END_NAMESPACE #endif // ifndef _L_LOCAL_CONFERENCE_LIST_EVENT_HANDLER_H_ +*/ diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index 21e3183d5..aef6184da 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -17,15 +17,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "linphone/api/c-api.h" +#include "linphone/core.h" +#include "linphone/event.h" +#include "linphone/proxy_config.h" +#include "linphone/utils/utils.h" + #include "address/address.h" -#include "content/content.h" +#include "c-wrapper/c-wrapper.h" #include "content/content-manager.h" #include "content/content-type.h" +#include "core/core-p.h" #include "remote-conference-event-handler.h" #include "remote-conference-list-event-handler.h" #include "xml/resource-lists.h" #include "xml/rlmi.h" +// TODO: Remove me later. +#include "private.h" + // ============================================================================= using namespace std; @@ -38,14 +48,14 @@ void RemoteConferenceListEventHandler::subscribe () { if (lev) return; - Content *content; + Content content; content.setContentType(ContentType::ResourceLists); Xsd::ResourceLists::ResourceLists rl = Xsd::ResourceLists::ResourceLists(); Xsd::ResourceLists::ListType l = Xsd::ResourceLists::ListType(); for (const auto &handler : handlers) { - const Address &addr = handler->getChatRoomId()->getPeerAddress(); - addr.setUriParam("Last-Notify", handler->getLastNotify()); + Address addr = handler->getChatRoomId().getPeerAddress(); + addr.setUriParam("Last-Notify", Utils::toString(handler->getLastNotify())); Xsd::ResourceLists::EntryType entry = Xsd::ResourceLists::EntryType(addr.asString()); l.getEntry().push_back(entry); } @@ -56,18 +66,18 @@ void RemoteConferenceListEventHandler::subscribe () { serializeResourceLists(xmlBody, rl, map); content.setBody(xmlBody.str()); - LinphoneAddress *rlsAddr = linphone_address_new(); LinphoneCore *lc = getCore()->getCCore(); - LinphoneProxyConfig *cfg = linphone_core_lookup_known_proxy(lc, rlsAddr); - if (!cfg || (linphone_proxy_config_get_state(cfg) != LinphoneRegistrationOk)) { - linphone_address_unref(rlsAddr); + LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(lc); + if (!cfg || (linphone_proxy_config_get_state(cfg) != LinphoneRegistrationOk)) return; - } + + LinphoneAddress *rlsAddr = linphone_address_new(linphone_proxy_config_get_conference_factory_uri(cfg)); lev = linphone_event_ref(linphone_core_create_subscribe(lc, rlsAddr, "conference", 600)); - lev->op->set_from(); + char *from = linphone_address_as_string(linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(getCore()->getCCore()))); + lev->op->set_from(from); + bctbx_free(from); linphone_address_unref(rlsAddr); - linphone_event_set_content linphone_event_set_internal(lev, TRUE); linphone_event_set_user_data(lev, this); linphone_event_send_subscribe(lev, content.toLinphoneContent()); @@ -82,57 +92,75 @@ void RemoteConferenceListEventHandler::unsubscribe () { } void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { - list contents = ContentManager::multipartToContentList(multipart); + list contents = ContentManager::multipartToContentList(*multipart); char *from = linphone_address_as_string(linphone_event_get_from(lev)); const Address local(from); bctbx_free(from); map addresses; for (const auto &content : contents) { const string &body = content.getBodyAsString(); - if (content.getContentType == ContentType::Rlmi) { + const ContentType &contentType = content.getContentType(); + if (contentType == ContentType::Rlmi) { addresses = parseRlmi(body); continue; } + const string &value = content.getHeaderValue("Content-Id"); + if (value.empty()) + continue; + + Address cid(value); + Address peer = addresses[cid]; ChatRoomId id(local, peer); shared_ptr handler = findHandler(id); if (!handler) continue; - if (content.getContentType == ContentType::Multipart) + if (contentType == ContentType::Multipart) handler->multipartNotifyReceived(body); - else if (content.getContentType == ContentType::Conference) + else if (contentType == ContentType::ConferenceInfo) handler->notifyReceived(body); } } map RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { - istringstream data(content.getBodyAsString()); - unique_ptr rl(Xsd::ResourceLists::parseResourceLists( + istringstream data(xmlBody); + unique_ptr rlmi(Xsd::Rlmi::parseList( data, Xsd::XmlSchema::Flags::dont_validate )); map addresses; - for (const auto &l : rl->getList()) { - for (const auto &entry : l.getEntry()) { - if (entry) - Address addr(entry.getUri()); - addresses.push_back(move(addr)); + for (const auto &resource : rlmi->getResource()) { + if (resource.getInstance().empty()) + continue; + + Address peer(resource.getUri()); + for (const auto &instance : resource.getInstance()) { + if (!instance.getCid().present()) + continue; + + Address cid(instance.getCid().get()); + addresses[cid] = peer; } } return addresses; } void RemoteConferenceListEventHandler::addHandler (std::shared_ptr handler) { - + handlers.push_back(handler); } -shared_ptr RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) { +shared_ptr RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { + for (const auto &handler : handlers) { + if (handler->getChatRoomId() == chatRoomId) + return handler; + } + return nullptr; } const list> &RemoteConferenceListEventHandler::getHandlers () const { - + return handlers; } LINPHONE_END_NAMESPACE diff --git a/src/conference/handlers/remote-conference-list-event-handler.h b/src/conference/handlers/remote-conference-list-event-handler.h index d3a12ee31..43a25e6a1 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.h +++ b/src/conference/handlers/remote-conference-list-event-handler.h @@ -20,25 +20,38 @@ #ifndef _L_REMOTE_CONFERENCE_LIST_EVENT_HANDLER_H_ #define _L_REMOTE_CONFERENCE_LIST_EVENT_HANDLER_H_ +#include +#include +#include + +#include "linphone/types.h" +#include "linphone/utils/general.h" + +#include "chat/chat-room/chat-room-id.h" +#include "content/content.h" +#include "core/core-accessor.h" + // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class LinphoneEvent; +class Address; class RemoteConferenceEventHandler; -class RemoteConferenceListEventHandler : public Object { +class RemoteConferenceListEventHandler : public Object, public CoreAccessor { public: void subscribe (); void unsubscribe (); - void notifyReceived (); + void notifyReceived (Content *multipart); void addHandler (std::shared_ptr handler); std::shared_ptr findHandler (const ChatRoomId &chatRoomId) const; const std::list> &getHandlers () const; private: std::list> handlers; - LinphoneEvent *lev; + LinphoneEvent *lev = nullptr; + + std::map parseRlmi (const std::string &xmlBody) const; }; LINPHONE_END_NAMESPACE diff --git a/src/content/content-p.h b/src/content/content-p.h index d0b8738c6..8693432ff 100644 --- a/src/content/content-p.h +++ b/src/content/content-p.h @@ -36,6 +36,8 @@ private: std::string contentEncoding; std::list> headers; + const std::list>::const_iterator findHeader (const std::string &headerName) const; + L_DECLARE_PUBLIC(Content); }; diff --git a/src/content/content.cpp b/src/content/content.cpp index c538141cf..78aabcf4b 100644 --- a/src/content/content.cpp +++ b/src/content/content.cpp @@ -34,6 +34,14 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- +const list>::const_iterator ContentPrivate::findHeader (const string &headerName) const { + return findIf(headers, [&headerName](const pair &pair) { + return pair.first == headerName; + }); +} + +// ============================================================================= + Content::Content () : ClonableObject(*new ContentPrivate) {} Content::Content (const Content &other) : ClonableObject(*new ContentPrivate), AppDataContainer(other) { @@ -208,16 +216,18 @@ const list> &Content::getHeaders () const { void Content::removeHeader (const string &headerName) { L_D(); - auto it = findHeader(headerName); + auto it = d->findHeader(headerName); if (it != d->headers.cend()) d->headers.remove(*it); } -list>::const_iterator Content::findHeader (const string &headerName) const { +const string &Content::getHeaderValue (const string &headerName) const { L_D(); - return findIf(d->headers, [&headerName](const pair &pair) { - return pair.first == headerName; - }); + auto it = d->findHeader(headerName); + if (it != d->headers.cend()) + return (*it).second; + + return Utils::getEmptyConstRefObject(); } LinphoneContent *Content::toLinphoneContent () const { diff --git a/src/content/content.h b/src/content/content.h index d3be11f51..923f75ee5 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -78,7 +78,7 @@ public: const std::list> &getHeaders () const; void addHeader (const std::string &headerName, const std::string &headerValue); void removeHeader (const std::string &headerName); - std::list>::const_iterator findHeader (const std::string &headerName) const; + const std::string &getHeaderValue (const std::string &headerName) const; // TODO: Remove me later. virtual LinphoneContent *toLinphoneContent () const;