diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f90b0134d..2ad611b2e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES address/address-p.h address/address.h + address/gruu-address-p.h + address/gruu-address.h address/simple-address-p.h address/simple-address.h c-wrapper/c-wrapper.h @@ -143,6 +145,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES set(LINPHONE_CXX_OBJECTS_SOURCE_FILES address/address.cpp + address/gruu-address.cpp address/simple-address.cpp c-wrapper/api/c-address.cpp c-wrapper/api/c-call-cbs.cpp diff --git a/src/address/gruu-address-p.h b/src/address/gruu-address-p.h new file mode 100644 index 000000000..116707db5 --- /dev/null +++ b/src/address/gruu-address-p.h @@ -0,0 +1,40 @@ +/* + * gruu-address-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _GRUU_ADDRESS_P_H_ +#define _GRUU_ADDRESS_P_H_ + +#include "gruu-address.h" +#include "address/simple-address-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class GruuAddressPrivate : public SimpleAddressPrivate { +private: + std::string urn; + bool valid = false; + + L_DECLARE_PUBLIC(GruuAddress); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _GRUU_ADDRESS_P_H_ diff --git a/src/address/gruu-address.cpp b/src/address/gruu-address.cpp new file mode 100644 index 000000000..da125764d --- /dev/null +++ b/src/address/gruu-address.cpp @@ -0,0 +1,93 @@ +/* + * gruu-address.cpp + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "linphone/utils/utils.h" + +#include "gruu-address-p.h" +#include "c-wrapper/c-wrapper.h" +#include "logger/logger.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +// ----------------------------------------------------------------------------- + +GruuAddress::GruuAddress (const string &address) : SimpleAddress(address) { + L_D(); + Address tmpAddress(address); + if (tmpAddress.isValid()) { + if (!tmpAddress.hasUriParam("gr")) + return; + d->urn = tmpAddress.getUriParamValue("gr"); + d->valid = true; + } +} + +GruuAddress::GruuAddress (const GruuAddress &src) : SimpleAddress(src) { + L_D(); + d->urn = src.getPrivate()->urn; + d->valid = src.getPrivate()->valid; +} + +GruuAddress::GruuAddress (const Address &src) : SimpleAddress(src) { + L_D(); + if (src.isValid()) { + if (!src.hasUriParam("gr")) + return; + d->urn = src.getUriParamValue("gr"); + d->valid = true; + } +} + +GruuAddress &GruuAddress::operator= (const GruuAddress &src) { + L_D(); + if (this != &src) { + SimpleAddress::operator=(src); + d->urn = src.getPrivate()->urn; + d->valid = src.getPrivate()->valid; + } + return *this; +} + +bool GruuAddress::operator== (const GruuAddress &address) const { + return asString() == address.asString(); +} + +bool GruuAddress::operator!= (const GruuAddress &address) const { + return !(*this == address); +} + +bool GruuAddress::operator< (const GruuAddress &address) const { + return asString() < address.asString(); +} + +bool GruuAddress::isValid () const { + L_D(); + return d->valid; +} + +string GruuAddress::asString () const { + Address tmpAddress(*this); + return tmpAddress.asString(); +} + +LINPHONE_END_NAMESPACE diff --git a/src/address/gruu-address.h b/src/address/gruu-address.h new file mode 100644 index 000000000..8de6a8edf --- /dev/null +++ b/src/address/gruu-address.h @@ -0,0 +1,56 @@ +/* + * gruu-address.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _GRUU_ADDRESS_H_ +#define _GRUU_ADDRESS_H_ + +#include "address/simple-address.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class Address; +class GruuAddressPrivate; + +class LINPHONE_PUBLIC GruuAddress : public SimpleAddress { +public: + explicit GruuAddress (const std::string &address = ""); + GruuAddress (const GruuAddress &src); + GruuAddress (const Address &src); + ~GruuAddress () = default; + + GruuAddress &operator= (const GruuAddress &src); + + bool operator== (const GruuAddress &address) const; + bool operator!= (const GruuAddress &address) const; + + bool operator< (const GruuAddress &address) const; + + bool isValid () const; + + std::string asString () const override; + +private: + L_DECLARE_PRIVATE(GruuAddress); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _GRUU_ADDRESS_H_ diff --git a/src/address/simple-address.cpp b/src/address/simple-address.cpp index 19a1da395..cf7112390 100644 --- a/src/address/simple-address.cpp +++ b/src/address/simple-address.cpp @@ -109,9 +109,4 @@ string SimpleAddress::asString () const { return tmpAddress.asString(); } -string SimpleAddress::asStringUriOnly () const { - Address tmpAddress(*this); - return tmpAddress.asStringUriOnly(); -} - LINPHONE_END_NAMESPACE diff --git a/src/address/simple-address.h b/src/address/simple-address.h index 4a76a83ee..991bacd01 100644 --- a/src/address/simple-address.h +++ b/src/address/simple-address.h @@ -53,8 +53,7 @@ public: bool isSip () const; - std::string asString () const; - std::string asStringUriOnly () const; + virtual std::string asString () const; private: L_DECLARE_PRIVATE(SimpleAddress); diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index 93e970114..97bd83af2 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -97,7 +97,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyFullState (int notifyId) UserType::EndpointSequence endpoints; user.setRoles(roles); user.setEndpoint(endpoints); - user.setEntity(participant->getAddress().asStringUriOnly()); + user.setEntity(participant->getAddress().asString()); user.getRoles()->getEntry().push_back(participant->isAdmin() ? "admin" : "participant"); user.setState(StateType::full); diff --git a/src/conference/session/media-session.cpp b/src/conference/session/media-session.cpp index e51fc7069..9a8f6ae56 100644 --- a/src/conference/session/media-session.cpp +++ b/src/conference/session/media-session.cpp @@ -1263,7 +1263,7 @@ void MediaSessionPrivate::makeLocalMediaDescription () { md->streams[mainAudioStreamIndex].payloads = l; if (audioStream && audioStream->ms.sessions.rtp_session) { md->streams[mainAudioStreamIndex].rtp_ssrc = rtp_session_get_send_ssrc(audioStream->ms.sessions.rtp_session); - strncpy(md->streams[mainAudioStreamIndex].rtcp_cname, conference.getMe()->getAddress().asStringUriOnly().c_str(), sizeof(md->streams[mainAudioStreamIndex].rtcp_cname)); + strncpy(md->streams[mainAudioStreamIndex].rtcp_cname, conference.getMe()->getAddress().asString().c_str(), sizeof(md->streams[mainAudioStreamIndex].rtcp_cname)); } else lWarning() << "Cannot get audio local ssrc for CallSession [" << q << "]"; @@ -1295,7 +1295,7 @@ void MediaSessionPrivate::makeLocalMediaDescription () { md->streams[mainVideoStreamIndex].payloads = l; if (videoStream && videoStream->ms.sessions.rtp_session) { md->streams[mainVideoStreamIndex].rtp_ssrc = rtp_session_get_send_ssrc(videoStream->ms.sessions.rtp_session); - strncpy(md->streams[mainVideoStreamIndex].rtcp_cname, conference.getMe()->getAddress().asStringUriOnly().c_str(), sizeof(md->streams[mainVideoStreamIndex].rtcp_cname)); + strncpy(md->streams[mainVideoStreamIndex].rtcp_cname, conference.getMe()->getAddress().asString().c_str(), sizeof(md->streams[mainVideoStreamIndex].rtcp_cname)); } else lWarning() << "Cannot get video local ssrc for CallSession [" << q << "]"; if (mainVideoStreamIndex > maxIndex) @@ -1327,7 +1327,7 @@ void MediaSessionPrivate::makeLocalMediaDescription () { md->streams[mainTextStreamIndex].payloads = l; if (textStream && textStream->ms.sessions.rtp_session) { md->streams[mainTextStreamIndex].rtp_ssrc = rtp_session_get_send_ssrc(textStream->ms.sessions.rtp_session); - strncpy(md->streams[mainTextStreamIndex].rtcp_cname, conference.getMe()->getAddress().asStringUriOnly().c_str(), sizeof(md->streams[mainTextStreamIndex].rtcp_cname)); + strncpy(md->streams[mainTextStreamIndex].rtcp_cname, conference.getMe()->getAddress().asString().c_str(), sizeof(md->streams[mainTextStreamIndex].rtcp_cname)); } else lWarning() << "Cannot get text local ssrc for CallSession [" << q << "]"; if (mainTextStreamIndex > maxIndex) @@ -2201,7 +2201,7 @@ void MediaSessionPrivate::initializeAudioStream () { rtp_session_enable_network_simulation(audioStream->ms.sessions.rtp_session, &core->net_conf.netsim_params); applyJitterBufferParams(audioStream->ms.sessions.rtp_session, LinphoneStreamTypeAudio); string userAgent = linphone_core_get_user_agent(core); - audio_stream_set_rtcp_information(audioStream, conference.getMe()->getAddress().asStringUriOnly().c_str(), userAgent.c_str()); + audio_stream_set_rtcp_information(audioStream, conference.getMe()->getAddress().asString().c_str(), userAgent.c_str()); rtp_session_set_symmetric_rtp(audioStream->ms.sessions.rtp_session, linphone_core_symmetric_rtp_enabled(core)); setupDtlsParams(&audioStream->ms); @@ -2354,7 +2354,7 @@ void MediaSessionPrivate::initializeVideoStream () { rtp_session_enable_network_simulation(videoStream->ms.sessions.rtp_session, &core->net_conf.netsim_params); applyJitterBufferParams(videoStream->ms.sessions.rtp_session, LinphoneStreamTypeVideo); string userAgent = linphone_core_get_user_agent(core); - video_stream_set_rtcp_information(videoStream, conference.getMe()->getAddress().asStringUriOnly().c_str(), userAgent.c_str()); + video_stream_set_rtcp_information(videoStream, conference.getMe()->getAddress().asString().c_str(), userAgent.c_str()); rtp_session_set_symmetric_rtp(videoStream->ms.sessions.rtp_session, linphone_core_symmetric_rtp_enabled(core)); setupDtlsParams(&videoStream->ms); /* Initialize zrtp even if we didn't explicitely set it, just in case peer offers it */