mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-03 20:46:28 +00:00
Fix GruuAddress and use it in ParticipantDevice.
This commit is contained in:
parent
2ad1f46105
commit
8458585266
11 changed files with 103 additions and 30 deletions
|
|
@ -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() + "@";
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ public:
|
|||
|
||||
bool isValid () const;
|
||||
|
||||
std::string getUrn () const;
|
||||
void setUrn (const std::string &urn);
|
||||
|
||||
std::string asString () const override;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<Participant> 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);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ using namespace std;
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
ParticipantDevice::ParticipantDevice (const Address &gruu) {
|
||||
ParticipantDevice::ParticipantDevice () {}
|
||||
|
||||
ParticipantDevice::ParticipantDevice (const GruuAddress &gruu) {
|
||||
mGruu = gruu;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,27 +20,34 @@
|
|||
#ifndef _PARTICIPANT_DEVICE_H_
|
||||
#define _PARTICIPANT_DEVICE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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<CallSession> getSession () const { return mSession; }
|
||||
inline void setSession (std::shared_ptr<CallSession> session) { mSession = session; }
|
||||
|
||||
bool isValid () const { return mGruu.isValid(); }
|
||||
|
||||
private:
|
||||
Address mGruu;
|
||||
GruuAddress mGruu;
|
||||
std::shared_ptr<CallSession> mSession;
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -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<ParticipantDevice>::const_iterator findDevice (const Address &gruu) const;
|
||||
const std::list<ParticipantDevice> &getDevices () const;
|
||||
void addDevice (const Address &gruu);
|
||||
void removeDevice (const Address &gruu);
|
||||
std::shared_ptr<ParticipantDevice> findDevice (const GruuAddress &gruu) const;
|
||||
std::shared_ptr<ParticipantDevice> findDevice (const std::shared_ptr<const CallSession> &session);
|
||||
const std::list<std::shared_ptr<ParticipantDevice>> &getDevices () const;
|
||||
std::shared_ptr<ParticipantDevice> 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<CallSession> session;
|
||||
std::list<ParticipantDevice> devices;
|
||||
std::list<std::shared_ptr<ParticipantDevice>> devices;
|
||||
|
||||
L_DECLARE_PUBLIC(Participant);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,25 +62,42 @@ void ParticipantPrivate::setConferenceSubscribeEvent (LinphoneEvent *ev) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const list<ParticipantDevice>::const_iterator ParticipantPrivate::findDevice (const Address &gruu) const {
|
||||
ParticipantDevice device(gruu);
|
||||
return find(devices.cbegin(), devices.cend(), device);
|
||||
shared_ptr<ParticipantDevice> ParticipantPrivate::findDevice (const GruuAddress &gruu) const {
|
||||
for (const auto &device : devices) {
|
||||
if (device->getGruu() == gruu)
|
||||
return device;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const list<ParticipantDevice> &ParticipantPrivate::getDevices () const {
|
||||
shared_ptr<ParticipantDevice> ParticipantPrivate::findDevice (const shared_ptr<const CallSession> &session) {
|
||||
for (const auto &device : devices) {
|
||||
if (device->getSession() == session)
|
||||
return device;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const list<shared_ptr<ParticipantDevice>> &ParticipantPrivate::getDevices () const {
|
||||
return devices;
|
||||
}
|
||||
|
||||
void ParticipantPrivate::addDevice (const Address &gruu) {
|
||||
ParticipantDevice device(gruu);
|
||||
if(findDevice(gruu) == devices.cend())
|
||||
shared_ptr<ParticipantDevice> ParticipantPrivate::addDevice (const GruuAddress &gruu) {
|
||||
if (!findDevice(gruu)) {
|
||||
shared_ptr<ParticipantDevice> device = make_shared<ParticipantDevice>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue