From 1c1ad846381e149bbe290aab9c73242e60bc3ceb Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 7 May 2018 10:33:27 +0200 Subject: [PATCH] fix testers --- coreapi/linphonecore.c | 5 ++--- coreapi/private_functions.h | 2 +- src/c-wrapper/api/c-content.cpp | 8 ++++---- src/chat/chat-room/client-group-chat-room.cpp | 11 ++++++----- src/chat/chat-room/client-group-chat-room.h | 3 ++- .../handlers/local-conference-event-handler.cpp | 7 +++++-- .../local-conference-list-event-handler.cpp | 15 ++++++++------- .../handlers/remote-conference-event-handler-p.h | 1 + .../handlers/remote-conference-event-handler.h | 1 + .../remote-conference-list-event-handler.cpp | 10 +++++++++- src/content/content-manager.cpp | 3 ++- src/db/main-db.cpp | 3 ++- tester/group_chat_tester.c | 2 +- tester/local_tester_hosts | 2 +- 14 files changed, 45 insertions(+), 28 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index df41cd954..fda0b9c59 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2178,10 +2178,9 @@ static void _linphone_core_conference_subscribe_received(LinphoneCore *lc, Linph IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)) )); - if (chatRoom) { - linphone_event_accept_subscription(lev); + if (chatRoom) L_GET_PRIVATE(static_pointer_cast(chatRoom))->subscribeReceived(lev); - } else + else linphone_event_deny_subscription(lev, LinphoneReasonDeclined); } diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index a539a5cae..a4cc829c4 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -384,7 +384,7 @@ void linphone_configure_op(LinphoneCore *lc, LinphonePrivate::SalOp *op, const L void linphone_configure_op_with_proxy(LinphoneCore *lc, LinphonePrivate::SalOp *op, const LinphoneAddress *dest, SalCustomHeader *headers, bool_t with_contact, LinphoneProxyConfig *proxy); LinphoneContent * linphone_content_new(void); LinphoneContent * linphone_content_copy(const LinphoneContent *ref); -SalBodyHandler *sal_body_handler_from_content(const LinphoneContent *content); +SalBodyHandler *sal_body_handler_from_content(const LinphoneContent *content, bool parseMultipart = true); SalReason linphone_reason_to_sal(LinphoneReason reason); LinphoneReason linphone_reason_from_sal(SalReason reason); void linphone_error_info_to_sal(const LinphoneErrorInfo* ei, SalErrorInfo* sei); diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index 580c78ca3..ebf18d7c6 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -211,7 +211,7 @@ const char *linphone_content_get_key(const LinphoneContent *content) { const LinphonePrivate::FileTransferContent *ftc = static_cast(c); content->key = ms_strdup(ftc->getFileKeyAsString()); } - + return content->key; } @@ -259,7 +259,7 @@ static LinphoneContent * linphone_content_new_with_body_handler(SalBodyHandler * linphone_content_set_string_buffer(content, body); belle_sip_free(body); } - + belle_sip_list_t *headers = (belle_sip_list_t *)sal_body_handler_get_headers(body_handler); while (headers) { belle_sip_header_t *cHeader = BELLE_SIP_HEADER(headers->data); @@ -297,13 +297,13 @@ LinphoneContent * linphone_content_from_sal_body_handler(SalBodyHandler *body_ha return NULL; } -SalBodyHandler * sal_body_handler_from_content(const LinphoneContent *content) { +SalBodyHandler * sal_body_handler_from_content(const LinphoneContent *content, bool parseMultipart) { if (content == NULL) return NULL; SalBodyHandler *body_handler; LinphonePrivate::ContentType contentType = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); - if (contentType.isMultipart()) { + if (contentType.isMultipart() && parseMultipart) { size_t size = linphone_content_get_size(content); char *buffer = ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getBodyAsUtf8String().c_str()); const char *boundary = L_STRING_TO_C(contentType.getParameter("boundary").getValue()); diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index d9dbe0039..9ba60c83f 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -258,7 +258,8 @@ ClientGroupChatRoom::ClientGroupChatRoom ( AbstractChatRoom::CapabilitiesMask capabilities, const string &subject, list> &&participants, - unsigned int lastNotifyId + unsigned int lastNotifyId, + bool hasBeenLeft ) : ChatRoom(*new ClientGroupChatRoomPrivate, core, chatRoomId), RemoteConference(core, me->getAddress(), nullptr) { L_D(); @@ -276,7 +277,8 @@ RemoteConference(core, me->getAddress(), nullptr) { dConference->eventHandler->setChatRoomId(chatRoomId); dConference->eventHandler->setLastNotify(lastNotifyId); - getCore()->getPrivate()->remoteListEventHandler->addHandler(dConference->eventHandler.get()); + if (!hasBeenLeft) + getCore()->getPrivate()->remoteListEventHandler->addHandler(dConference->eventHandler.get()); } ClientGroupChatRoom::~ClientGroupChatRoom () { @@ -498,8 +500,7 @@ void ClientGroupChatRoom::leave () { L_D(); L_D_T(RemoteConference, dConference); - dConference->eventHandler->unsubscribe(); - + dConference->eventHandler->getPrivate()->lev = nullptr; shared_ptr session = dConference->focus->getPrivate()->getSession(); if (session) session->terminate(); @@ -534,7 +535,7 @@ void ClientGroupChatRoom::onConferenceTerminated (const IdentityAddress &addr) { L_D(); L_D_T(RemoteConference, dConference); - dConference->eventHandler->unsubscribe(); + dConference->eventHandler->getPrivate()->lev = nullptr; dConference->eventHandler->resetLastNotify(); d->setState(ChatRoom::State::Terminated); d->addEvent(make_shared( diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index 5d28a2ce9..cc3205a67 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -54,7 +54,8 @@ public: AbstractChatRoom::CapabilitiesMask capabilities, const std::string &subject, std::list> &&participants, - unsigned int lastNotifyId + unsigned int lastNotifyId, + bool hasBeenLeft = false ); ~ClientGroupChatRoom (); diff --git a/src/conference/handlers/local-conference-event-handler.cpp b/src/conference/handlers/local-conference-event-handler.cpp index ea8cc1f85..b9da2b703 100644 --- a/src/conference/handlers/local-conference-event-handler.cpp +++ b/src/conference/handlers/local-conference-event-handler.cpp @@ -410,6 +410,7 @@ void LocalConferenceEventHandler::subscribeReceived (LinphoneEvent *lev, bool on bctbx_free(addrStr); if (!participant) { lError() << "received SUBSCRIBE corresponds to no participant of the conference; " << d->conf->getConferenceAddress().asString() << ", no NOTIFY sent."; + linphone_event_deny_subscription(lev, LinphoneReasonDeclined); return; } @@ -418,16 +419,18 @@ void LocalConferenceEventHandler::subscribeReceived (LinphoneEvent *lev, bool on IdentityAddress contactAddr(contactAddrStr); bctbx_free(contactAddrStr); shared_ptr device = participant->getPrivate()->findDevice(contactAddr); - if (!device) { + if (!device || (device->getState() != ParticipantDevice::State::Present && device->getState() != ParticipantDevice::State::Joining)) { lError() << "received SUBSCRIBE for conference: " << d->conf->getConferenceAddress().asString() << "device sending subscribe: " << contactAddr.asString() << " is not known, no NOTIFY sent."; + linphone_event_deny_subscription(lev, LinphoneReasonDeclined); return; } + linphone_event_accept_subscription(lev); if (linphone_event_get_subscription_state(lev) == LinphoneSubscriptionActive) { unsigned int lastNotify = static_cast(Utils::stoi(linphone_event_get_custom_header(lev, "Last-Notify-Version"))); device->setConferenceSubscribeEvent(lev); - if (lastNotify == 0) { + if (lastNotify == 0 || (device->getState() == ParticipantDevice::State::Joining)) { lInfo() << "Sending initial notify of conference:" << d->conf->getConferenceAddress().asString() << " to: " << device->getAddress().asString(); d->notifyFullState(d->createNotifyFullState(static_cast(d->lastNotify), oneToOne), device); } else if (lastNotify < d->lastNotify) { diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index 3d3ac4f1f..c25dc0194 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -54,8 +54,6 @@ namespace { void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, const LinphoneContent *body) { LinphoneSubscriptionState subscriptionState = linphone_event_get_subscription_state(lev); - if (subscriptionState != LinphoneSubscriptionIncomingReceived && subscriptionState != LinphoneSubscriptionTerminated) - return; const string &xmlBody = string(linphone_content_get_string_buffer(body)); if (xmlBody.empty()) { @@ -63,6 +61,11 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con return; } + linphone_event_accept_subscription(lev); + + if (subscriptionState != LinphoneSubscriptionIncomingReceived && subscriptionState != LinphoneSubscriptionTerminated) + return; + const LinphoneAddress *lAddr = linphone_event_get_from(lev); char *addrStr = linphone_address_as_string(lAddr); IdentityAddress participantAddr(addrStr); @@ -110,7 +113,7 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con continue; } shared_ptr device = participant->getPrivate()->findDevice(deviceAddr); - if (!device) { + if (!device || (device->getState() != ParticipantDevice::State::Present && device->getState() != ParticipantDevice::State::Joining)) { lError() << "Received subscribe for unknown device: " << deviceAddr << " for participant: " << participantAddr << " for chat room: " << chatRoomId; continue; @@ -134,6 +137,7 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con char token[17]; belle_sip_random_token(token, sizeof(token)); content->addHeader("Content-Id", token); + content->addHeader("Content-Length", Utils::toString(notifyBody.size())); contents.push_back(content); // Add entry into the Rlmi content of the notify body @@ -146,11 +150,8 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con } } - if (noContent) { - linphone_event_deny_subscription(lev, LinphoneReasonDeclined); + if (noContent) return; - } - linphone_event_accept_subscription(lev); Xsd::Rlmi::List list("", 0, TRUE); list.setResource(resources); diff --git a/src/conference/handlers/remote-conference-event-handler-p.h b/src/conference/handlers/remote-conference-event-handler-p.h index 8d4a06836..54eaf2280 100644 --- a/src/conference/handlers/remote-conference-event-handler-p.h +++ b/src/conference/handlers/remote-conference-event-handler-p.h @@ -32,6 +32,7 @@ LINPHONE_BEGIN_NAMESPACE class RemoteConferenceEventHandlerPrivate : public ObjectPrivate, public CoreListener { + friend class ClientGroupChatRoom; private: void simpleNotifyReceived (const std::string &xmlBody); void subscribe (); diff --git a/src/conference/handlers/remote-conference-event-handler.h b/src/conference/handlers/remote-conference-event-handler.h index e5e1cfbff..550ffeff1 100644 --- a/src/conference/handlers/remote-conference-event-handler.h +++ b/src/conference/handlers/remote-conference-event-handler.h @@ -31,6 +31,7 @@ class RemoteConference; class RemoteConferenceEventHandlerPrivate; class RemoteConferenceEventHandler : public Object { + friend class ClientGroupChatRoom; public: RemoteConferenceEventHandler (RemoteConference *remoteConference); ~RemoteConferenceEventHandler (); diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index 0fad80d66..37271b545 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -76,7 +76,15 @@ void RemoteConferenceListEventHandler::subscribe () { Xsd::ResourceLists::ResourceLists rl = Xsd::ResourceLists::ResourceLists(); Xsd::ResourceLists::ListType l = Xsd::ResourceLists::ListType(); for (const auto &handler : handlers) { - Address addr = handler->getChatRoomId().getPeerAddress(); + const ChatRoomId &chatRoomId = handler->getChatRoomId(); + shared_ptr cr = getCore()->findChatRoom(chatRoomId); + if (!cr) + continue; + + if (cr->hasBeenLeft()) + continue; + + Address addr = chatRoomId.getPeerAddress(); addr.setUriParam("Last-Notify", Utils::toString(handler->getLastNotify())); Xsd::ResourceLists::EntryType entry = Xsd::ResourceLists::EntryType(addr.asStringUriOnly()); l.getEntry().push_back(entry); diff --git a/src/content/content-manager.cpp b/src/content/content-manager.cpp index 40f842f5d..d3ae1c0ee 100644 --- a/src/content/content-manager.cpp +++ b/src/content/content-manager.cpp @@ -62,8 +62,9 @@ Content ContentManager::contentListToMultipart (const list &contents, for (Content *content : contents) { LinphoneContent *cContent = L_GET_C_BACK_PTR(content); - SalBodyHandler *sbh = sal_body_handler_from_content(cContent); + SalBodyHandler *sbh = sal_body_handler_ref(sal_body_handler_from_content(cContent, false)); belle_sip_multipart_body_handler_add_part(mpbh, BELLE_SIP_BODY_HANDLER(sbh)); + sal_body_handler_unref(sbh); linphone_content_unref(cContent); } diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 655b56cee..73017d184 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -2399,7 +2399,8 @@ list> MainDb::getChatRooms () const { capabilities, subject, move(participants), - lastNotifyId + lastNotifyId, + hasBeenLeft ); AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); dChatRoom->setState(ChatRoom::State::Instantiated); diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 8291a6f9b..101aeab4a 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -1543,7 +1543,7 @@ static void group_chat_room_reinvited_after_removed_base (bool_t offline_when_re coresManagerList = bctbx_list_append(coresManagerList, laure); } if (!offline_when_reinvited) - BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateTerminated, initialLaureStats.number_of_LinphoneChatRoomStateTerminated + 1, 3000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateTerminated, initialLaureStats.number_of_LinphoneChatRoomStateTerminated + 1, 5000)); wait_for_list(coresList,0, 1, 2000); initialLaureStats = laure->stat; diff --git a/tester/local_tester_hosts b/tester/local_tester_hosts index 453c74f53..94fbdce4d 100644 --- a/tester/local_tester_hosts +++ b/tester/local_tester_hosts @@ -1,4 +1,4 @@ 127.0.0.1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org sipv4.example.org conf.example.org ::1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org 188.165.46.90 tunnel.wildcard2.linphone.org -64:ff9b::94.23.19.176 sipv4-nat64.example.org +64:ff9b::94.23.19.176 sipv4-nat64.example.org