handle simple notify when subcribe was made for list

This commit is contained in:
Benjamin Reis 2018-03-20 16:39:47 +01:00
parent 177dd8778c
commit 0bc8499bbb
4 changed files with 65 additions and 35 deletions

View file

@ -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<AbstractChatRoom> 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<ClientGroupChatRoom> cgcr;
if (chatRoom->getCapabilities() & ChatRoom::Capabilities::Proxy)
cgcr = static_pointer_cast<ClientGroupChatRoom>(
static_pointer_cast<ClientGroupToBasicChatRoom>(chatRoom)->getProxiedChatRoom());
else
cgcr = static_pointer_cast<ClientGroupChatRoom>(chatRoom);
shared_ptr<ClientGroupChatRoom> cgcr;
if (chatRoom->getCapabilities() & ChatRoom::Capabilities::Proxy)
cgcr = static_pointer_cast<ClientGroupChatRoom>(
static_pointer_cast<ClientGroupToBasicChatRoom>(chatRoom)->getProxiedChatRoom());
else
cgcr = static_pointer_cast<ClientGroupChatRoom>(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));
}
}

View file

@ -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);
}
// -----------------------------------------------------------------------------

View file

@ -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<Content> 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<Xsd::ConferenceInfo::ConferenceType> 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<Content> contents = ContentManager::multipartToContentList(*notifyContent);
bctbx_free(from);
map<Address, Address> addresses;
map<IdentityAddress, IdentityAddress> 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<Address, Address> RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const {
map<IdentityAddress, IdentityAddress> RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const {
istringstream data(xmlBody);
unique_ptr<Xsd::Rlmi::List> rlmi(Xsd::Rlmi::parseList(
data,
Xsd::XmlSchema::Flags::dont_validate
));
map<Address, Address> addresses;
map<IdentityAddress, IdentityAddress> 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;
}
}

View file

@ -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<RemoteConferenceEventHandler *> handlers;
LinphoneEvent *lev = nullptr;
std::map<Address, Address> parseRlmi (const std::string &xmlBody) const;
std::map<IdentityAddress, IdentityAddress> parseRlmi (const std::string &xmlBody) const;
// CoreListener
void onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) override;