From c115a448ddadb2639e2ae76a65ef2959127ba777 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 24 Nov 2017 15:26:35 +0100 Subject: [PATCH] Fix chat messages routing issues because of gruu addresses. --- coreapi/linphonecore.c | 24 ++++++++++++------- coreapi/private.h | 1 - include/linphone/core.h | 2 ++ src/c-wrapper/api/c-chat-room.cpp | 12 ++++++++-- src/chat/chat-message/chat-message.cpp | 3 ++- src/chat/chat-room/client-group-chat-room.cpp | 4 +++- src/conference/conference.cpp | 7 ++++-- .../remote-conference-event-handler.cpp | 1 + src/sal/op.h | 4 ---- 9 files changed, 39 insertions(+), 19 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 88c8b1bc9..728f94bfd 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3368,6 +3368,21 @@ const char * linphone_core_get_identity(LinphoneCore *lc){ return from; } +char * linphone_core_get_device_identity(LinphoneCore *lc) { + char *identity = NULL; + LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(lc); + if (proxy) { + const LinphoneAddress *contactAddr = linphone_proxy_config_get_contact(proxy); + if (contactAddr) + identity = linphone_address_as_string(contactAddr); + else + identity = bctbx_strdup(linphone_proxy_config_get_identity(proxy)); + } else { + identity = bctbx_strdup(linphone_core_get_primary_contact(lc)); + } + return identity; +} + const char * linphone_core_get_route(LinphoneCore *lc){ LinphoneProxyConfig *proxy=linphone_core_get_default_proxy_config(lc); const char *route=NULL; @@ -3548,11 +3563,9 @@ static void linphone_transfer_routes_to_op(bctbx_list_t *routes, SalOp *op){ void linphone_configure_op_with_proxy(LinphoneCore *lc, SalOp *op, const LinphoneAddress *dest, SalCustomHeader *headers, bool_t with_contact, LinphoneProxyConfig *proxy){ bctbx_list_t *routes=NULL; - const LinphoneAddress *contactAddr = nullptr; const char *identity; if (proxy){ - contactAddr = linphone_proxy_config_get_contact(proxy); identity=linphone_proxy_config_get_identity(proxy); if (linphone_proxy_config_get_privacy(proxy)!=LinphonePrivacyDefault) { op->set_privacy(linphone_proxy_config_get_privacy(proxy)); @@ -3565,12 +3578,7 @@ void linphone_configure_op_with_proxy(LinphoneCore *lc, SalOp *op, const Linphon } op->set_to_address(L_GET_PRIVATE_FROM_C_OBJECT(dest)->getInternalAddress()); - if (op->getUseGruuInFrom() && contactAddr && linphone_address_has_uri_param(contactAddr, "gr")) { - char *contactAddrStr = linphone_address_as_string_uri_only(contactAddr); - op->set_from(contactAddrStr); - bctbx_free(contactAddrStr); - } else - op->set_from(identity); + op->set_from(identity); op->set_sent_custom_header(headers); op->set_realm(linphone_proxy_config_get_realm(proxy)); diff --git a/coreapi/private.h b/coreapi/private.h index fc2bc54e3..da493d8f5 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -452,7 +452,6 @@ void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call); void linphone_call_stop_media_streams(LinphoneCall *call); void linphone_call_delete_upnp_session(LinphoneCall *call); int _linphone_core_apply_transports(LinphoneCore *lc); -const char * linphone_core_get_identity(LinphoneCore *lc); void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose); void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progresses); diff --git a/include/linphone/core.h b/include/linphone/core.h index 166430666..55e8cbe5f 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -1403,6 +1403,8 @@ LINPHONE_PUBLIC const char *linphone_core_get_primary_contact(LinphoneCore *lc); **/ LINPHONE_PUBLIC const char * linphone_core_get_identity(LinphoneCore *lc); +LINPHONE_PUBLIC char * linphone_core_get_device_identity(LinphoneCore *lc); + /** * Tells LinphoneCore to guess local hostname automatically in primary contact. * @ingroup proxies diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 3291afc31..76aca9c08 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -351,8 +351,16 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(core, addr); linphone_address_unref(addr); string from; - if (proxy) - from = L_GET_CPP_PTR_FROM_C_OBJECT(linphone_proxy_config_get_identity_address(proxy))->asString(); + if (proxy) { + const LinphoneAddress *contactAddr = linphone_proxy_config_get_contact(proxy); + if (contactAddr) { + char *cFrom = linphone_address_as_string(contactAddr); + from = string(cFrom); + bctbx_free(cFrom); + } else { + from = L_GET_CPP_PTR_FROM_C_OBJECT(linphone_proxy_config_get_identity_address(proxy))->asString(); + } + } if (from.empty()) from = linphone_core_get_primary_contact(core); LinphonePrivate::IdentityAddress me(from); diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 903797412..99589a6bf 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -478,7 +478,6 @@ void ChatMessagePrivate::send () { LinphoneAddress *peer = linphone_address_new(q->getToAddress().asString().c_str()); /* Sending out of call */ salOp = op = new SalMessageOp(core->getCCore()->sal); - op->setUseGruuInFrom(true); linphone_configure_op( core->getCCore(), op, peer, getSalCustomHeaders(), !!lp_config_get_int(core->getCCore()->config, "sip", "chat_msg_with_contact", 0) @@ -486,6 +485,8 @@ void ChatMessagePrivate::send () { op->set_user_pointer(L_GET_C_BACK_PTR(q)); /* If out of call, directly store msg */ linphone_address_unref(peer); } + op->set_from(q->getFromAddress().asString().c_str()); + op->set_to(q->getToAddress().asString().c_str()); // --------------------------------------- // Start of message modification diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index a30efac9c..3643d5240 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -64,7 +64,9 @@ shared_ptr ClientGroupChatRoomPrivate::createSession () { shared_ptr focus = qConference->getPrivate()->focus; shared_ptr session = focus->getPrivate()->createSession(*q, &csp, false, q); const Address &myAddress = q->getMe()->getAddress(); - session->configure(LinphoneCallOutgoing, nullptr, nullptr, myAddress, focus->getAddress()); + Address myCleanedAddress(myAddress); + myCleanedAddress.setUriParam("gr"); // Remove gr parameter for INVITE + session->configure(LinphoneCallOutgoing, nullptr, nullptr, myCleanedAddress, focus->getAddress()); session->initiateOutgoing(); return session; } diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 8ea32bedc..52991d8b8 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -234,8 +234,11 @@ shared_ptr Conference::findParticipant (const shared_ptrme->getAddress() == simpleAddr; + IdentityAddress cleanedAddr(addr); + cleanedAddr.setGruu(""); + IdentityAddress cleanedMeAddr(d->me->getAddress()); + cleanedMeAddr.setGruu(""); + return cleanedMeAddr == cleanedAddr; } LINPHONE_END_NAMESPACE diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index 6bf3718ce..c6be552f1 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -184,6 +184,7 @@ void RemoteConferenceEventHandler::subscribe (const ChatRoomId &chatRoomId) { d->chatRoomId = chatRoomId; LinphoneAddress *lAddr = linphone_address_new(d->chatRoomId.getPeerAddress().asString().c_str()); d->lev = linphone_core_create_subscribe(d->conf->getCore()->getCCore(), lAddr, "conference", 600); + d->lev->op->set_from(d->chatRoomId.getLocalAddress().asString().c_str()); linphone_event_add_custom_header(d->lev, "Last-Notify-Version", Utils::toString(d->lastNotify).c_str()); linphone_address_unref(lAddr); linphone_event_set_internal(d->lev, TRUE); diff --git a/src/sal/op.h b/src/sal/op.h index d461cf7fb..06c009909 100644 --- a/src/sal/op.h +++ b/src/sal/op.h @@ -84,9 +84,6 @@ public: void set_sent_custom_header(SalCustomHeader* ch); - bool getUseGruuInFrom () { return useGruuInFrom; } - void setUseGruuInFrom (bool value) { useGruuInFrom = value; } - void enable_cnx_ip_to_0000_if_sendonly(bool_t yesno) {this->_cnx_ip_to_0000_if_sendonly_enabled = yesno;} bool_t cnx_ip_to_0000_if_sendonly_enabled() const {return this->_cnx_ip_to_0000_if_sendonly_enabled;} @@ -256,7 +253,6 @@ protected: bool_t has_auth_pending = FALSE; bool_t supports_session_timers = FALSE; bool_t op_released = FALSE; - bool useGruuInFrom = false; friend class Sal; };