From 84585852660bbdb719914ba5eea7c1f93ac67697 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 13 Nov 2017 11:23:12 +0100 Subject: [PATCH] Fix GruuAddress and use it in ParticipantDevice. --- src/address/address.cpp | 14 +++++++ src/address/address.h | 2 + src/address/gruu-address.cpp | 22 +++++++++-- src/address/gruu-address.h | 3 ++ src/address/simple-address.cpp | 11 +++++- src/address/simple-address.h | 4 ++ .../local-conference-event-handler.cpp | 4 +- src/conference/participant-device.cpp | 4 +- src/conference/participant-device.h | 19 ++++++--- src/conference/participant-p.h | 11 +++--- src/conference/participant.cpp | 39 +++++++++++++------ 11 files changed, 103 insertions(+), 30 deletions(-) diff --git a/src/address/address.cpp b/src/address/address.cpp index 551975285..924eb9ad0 100644 --- a/src/address/address.cpp +++ b/src/address/address.cpp @@ -22,6 +22,7 @@ #include "address-p.h" #include "c-wrapper/c-wrapper.h" #include "logger/logger.h" +#include "address/gruu-address.h" #include "address/simple-address.h" // ============================================================================= @@ -46,6 +47,19 @@ Address::Address (const Address &src) : ClonableObject(*new AddressPrivate) { d->internalAddress = sal_address_clone(salAddress); } +Address::Address (const GruuAddress &src) : ClonableObject(*new AddressPrivate) { + L_D(); + string uri = src.getScheme() + ":" + src.getUsername() + "@"; + if (src.getDomain().find(':') != string::npos) + uri += "[" + src.getDomain() + "]"; + else + uri += src.getDomain(); + uri += "?gr=" + src.getUrn(); + if (!(d->internalAddress = sal_address_new(L_STRING_TO_C(uri)))) { + lWarning() << "Cannot create Address, bad GruuAddress source"; + } +} + Address::Address (const SimpleAddress &src) : ClonableObject(*new AddressPrivate) { L_D(); string uri = src.getScheme() + ":" + src.getUsername() + "@"; diff --git a/src/address/address.h b/src/address/address.h index 540bf7be4..e3c5f7ef4 100644 --- a/src/address/address.h +++ b/src/address/address.h @@ -28,6 +28,7 @@ LINPHONE_BEGIN_NAMESPACE class AddressPrivate; +class GruuAddress; class SimpleAddress; class LINPHONE_PUBLIC Address : public ClonableObject { @@ -42,6 +43,7 @@ class LINPHONE_PUBLIC Address : public ClonableObject { public: explicit Address (const std::string &address = ""); Address (const Address &src); + Address (const GruuAddress &src); Address (const SimpleAddress &src); ~Address (); diff --git a/src/address/gruu-address.cpp b/src/address/gruu-address.cpp index da125764d..636e8d929 100644 --- a/src/address/gruu-address.cpp +++ b/src/address/gruu-address.cpp @@ -31,28 +31,32 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- -GruuAddress::GruuAddress (const string &address) : SimpleAddress(address) { +GruuAddress::GruuAddress (const string &address) : SimpleAddress(*new GruuAddressPrivate) { L_D(); Address tmpAddress(address); if (tmpAddress.isValid()) { if (!tmpAddress.hasUriParam("gr")) return; + SimpleAddress base(address); + SimpleAddress::clone(base); d->urn = tmpAddress.getUriParamValue("gr"); d->valid = true; } } -GruuAddress::GruuAddress (const GruuAddress &src) : SimpleAddress(src) { +GruuAddress::GruuAddress (const GruuAddress &src) : SimpleAddress(*new GruuAddressPrivate) { L_D(); + SimpleAddress::clone(src); d->urn = src.getPrivate()->urn; d->valid = src.getPrivate()->valid; } -GruuAddress::GruuAddress (const Address &src) : SimpleAddress(src) { +GruuAddress::GruuAddress (const Address &src) : SimpleAddress(*new GruuAddressPrivate) { L_D(); if (src.isValid()) { if (!src.hasUriParam("gr")) return; + SimpleAddress::clone(SimpleAddress(src)); d->urn = src.getUriParamValue("gr"); d->valid = true; } @@ -85,9 +89,19 @@ bool GruuAddress::isValid () const { return d->valid; } +string GruuAddress::getUrn () const { + L_D(); + return d->urn; +} + +void GruuAddress::setUrn (const string &urn) { + L_D(); + d->urn = urn; +} + string GruuAddress::asString () const { Address tmpAddress(*this); - return tmpAddress.asString(); + return tmpAddress.asStringUriOnly(); } LINPHONE_END_NAMESPACE diff --git a/src/address/gruu-address.h b/src/address/gruu-address.h index 8de6a8edf..d9c5d269d 100644 --- a/src/address/gruu-address.h +++ b/src/address/gruu-address.h @@ -45,6 +45,9 @@ public: bool isValid () const; + std::string getUrn () const; + void setUrn (const std::string &urn); + std::string asString () const override; private: diff --git a/src/address/simple-address.cpp b/src/address/simple-address.cpp index cf7112390..09d539a42 100644 --- a/src/address/simple-address.cpp +++ b/src/address/simple-address.cpp @@ -55,6 +55,8 @@ SimpleAddress::SimpleAddress (const Address &src) : ClonableObject(*new SimpleAd d->domain = src.getDomain(); } +SimpleAddress::SimpleAddress (SimpleAddressPrivate &p) : ClonableObject(p) {} + SimpleAddress &SimpleAddress::operator= (const SimpleAddress &src) { L_D(); if (this != &src) { @@ -106,7 +108,14 @@ bool SimpleAddress::setDomain (const string &domain) { string SimpleAddress::asString () const { Address tmpAddress(*this); - return tmpAddress.asString(); + return tmpAddress.asStringUriOnly(); +} + +void SimpleAddress::clone (const SimpleAddress &src) { + L_D(); + d->scheme = src.getPrivate()->scheme; + d->username = src.getPrivate()->username; + d->domain = src.getPrivate()->domain; } LINPHONE_END_NAMESPACE diff --git a/src/address/simple-address.h b/src/address/simple-address.h index 991bacd01..fe01071b8 100644 --- a/src/address/simple-address.h +++ b/src/address/simple-address.h @@ -55,6 +55,10 @@ public: virtual std::string asString () const; +protected: + explicit SimpleAddress (SimpleAddressPrivate &p); + void clone (const SimpleAddress &src); + private: L_DECLARE_PRIVATE(SimpleAddress); }; diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index 97bd83af2..f5d07ec37 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -102,7 +102,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyFullState (int notifyId) user.setState(StateType::full); for (const auto &device : participant->getPrivate()->getDevices()) { - const string &gruu = device.getGruu().asStringUriOnly(); + const string &gruu = device->getGruu().asString(); EndpointType endpoint = EndpointType(); endpoint.setEntity(gruu); endpoint.setState(StateType::full); @@ -127,7 +127,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const A shared_ptr p = conf->findParticipant(addr); if (p) { for (const auto &device : p->getPrivate()->getDevices()) { - const string &gruu = device.getGruu().asStringUriOnly(); + const string &gruu = device->getGruu().asString(); EndpointType endpoint = EndpointType(); endpoint.setEntity(gruu); endpoint.setState(StateType::full); diff --git a/src/conference/participant-device.cpp b/src/conference/participant-device.cpp index 16a2130c3..e7d60f385 100644 --- a/src/conference/participant-device.cpp +++ b/src/conference/participant-device.cpp @@ -25,7 +25,9 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -ParticipantDevice::ParticipantDevice (const Address &gruu) { +ParticipantDevice::ParticipantDevice () {} + +ParticipantDevice::ParticipantDevice (const GruuAddress &gruu) { mGruu = gruu; } diff --git a/src/conference/participant-device.h b/src/conference/participant-device.h index 38f495b21..d889d9e22 100644 --- a/src/conference/participant-device.h +++ b/src/conference/participant-device.h @@ -20,27 +20,34 @@ #ifndef _PARTICIPANT_DEVICE_H_ #define _PARTICIPANT_DEVICE_H_ +#include #include -#include "address/address.h" +#include "address/gruu-address.h" #include "linphone/utils/general.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class CallSession; + class ParticipantDevice { public: - explicit ParticipantDevice (const Address &gruu); + ParticipantDevice (); + explicit ParticipantDevice (const GruuAddress &gruu); bool operator== (const ParticipantDevice &device) const; - inline const Address &getGruu () const { - return mGruu; - }; + inline const GruuAddress &getGruu () const { return mGruu; } + inline std::shared_ptr getSession () const { return mSession; } + inline void setSession (std::shared_ptr session) { mSession = session; } + + bool isValid () const { return mGruu.isValid(); } private: - Address mGruu; + GruuAddress mGruu; + std::shared_ptr mSession; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/participant-p.h b/src/conference/participant-p.h index a412d4cb7..7327ee9d2 100644 --- a/src/conference/participant-p.h +++ b/src/conference/participant-p.h @@ -48,10 +48,11 @@ public: inline void setAddress (const SimpleAddress &newAddr) { addr = newAddr; } inline void setAdmin (bool isAdmin) { this->isAdmin = isAdmin; } inline void setContactAddress (const Address &contactAddr) { this->contactAddr = contactAddr; } - const std::list::const_iterator findDevice (const Address &gruu) const; - const std::list &getDevices () const; - void addDevice (const Address &gruu); - void removeDevice (const Address &gruu); + std::shared_ptr findDevice (const GruuAddress &gruu) const; + std::shared_ptr findDevice (const std::shared_ptr &session); + const std::list> &getDevices () const; + std::shared_ptr addDevice (const GruuAddress &gruu); + void removeDevice (const GruuAddress &gruu); private: SimpleAddress addr; @@ -59,7 +60,7 @@ private: bool isAdmin = false; LinphoneEvent *conferenceSubscribeEvent = nullptr; std::shared_ptr session; - std::list devices; + std::list> devices; L_DECLARE_PUBLIC(Participant); }; diff --git a/src/conference/participant.cpp b/src/conference/participant.cpp index 289b483d0..d8d1b89be 100644 --- a/src/conference/participant.cpp +++ b/src/conference/participant.cpp @@ -62,25 +62,42 @@ void ParticipantPrivate::setConferenceSubscribeEvent (LinphoneEvent *ev) { // ----------------------------------------------------------------------------- -const list::const_iterator ParticipantPrivate::findDevice (const Address &gruu) const { - ParticipantDevice device(gruu); - return find(devices.cbegin(), devices.cend(), device); +shared_ptr ParticipantPrivate::findDevice (const GruuAddress &gruu) const { + for (const auto &device : devices) { + if (device->getGruu() == gruu) + return device; + } + return nullptr; } -const list &ParticipantPrivate::getDevices () const { +shared_ptr ParticipantPrivate::findDevice (const shared_ptr &session) { + for (const auto &device : devices) { + if (device->getSession() == session) + return device; + } + return nullptr; +} + +const list> &ParticipantPrivate::getDevices () const { return devices; } -void ParticipantPrivate::addDevice (const Address &gruu) { - ParticipantDevice device(gruu); - if(findDevice(gruu) == devices.cend()) +shared_ptr ParticipantPrivate::addDevice (const GruuAddress &gruu) { + if (!findDevice(gruu)) { + shared_ptr device = make_shared(gruu); devices.push_back(device); + return device; + } + return nullptr; } -void ParticipantPrivate::removeDevice (const Address &gruu) { - ParticipantDevice device(gruu); - if(findDevice(gruu) != devices.cend()) - devices.remove(device); +void ParticipantPrivate::removeDevice (const GruuAddress &gruu) { + for (auto it = devices.begin(); it != devices.end(); it++) { + if ((*it)->getGruu() == gruu) { + devices.erase(it); + return; + } + } } // =============================================================================