Use the CallSessionParams to add parameters to the contact address.

This fixes the GRUU address in the contact of an INVITE.
This commit is contained in:
Ghislain MARY 2017-11-09 16:00:50 +01:00
parent 9f2db02565
commit 88c9e1e593
5 changed files with 41 additions and 6 deletions

View file

@ -59,16 +59,13 @@ shared_ptr<CallSession> ClientGroupChatRoomPrivate::createSession () {
CallSessionParams csp;
csp.addCustomHeader("Require", "recipient-list-invite");
csp.addCustomContactParameter("text");
shared_ptr<Participant> focus = qConference->getPrivate()->focus;
shared_ptr<CallSession> session = focus->getPrivate()->createSession(*q, &csp, false, q);
const Address &myAddress = q->getMe()->getAddress();
session->configure(LinphoneCallOutgoing, nullptr, nullptr, myAddress, focus->getContactAddress());
session->initiateOutgoing();
Address addr = myAddress;
addr.setParam("text");
session->getPrivate()->getOp()->set_contact_address(addr.getPrivate()->getInternalAddress());
return session;
}

View file

@ -20,6 +20,8 @@
#ifndef _CALL_SESSION_PARAMS_P_H_
#define _CALL_SESSION_PARAMS_P_H_
#include <unordered_map>
#include "object/clonable-object-p.h"
#include "call-session-params.h"
@ -48,6 +50,8 @@ public:
SalCustomHeader * getCustomHeaders () const;
void setCustomHeaders (const SalCustomHeader *ch);
const std::unordered_map<std::string, std::string> &getCustomContactParameters () const { return customContactParameters; }
LinphoneCall *getReferer () const { return referer; }
void setReferer (LinphoneCall *call) { referer = call; }
@ -61,6 +65,7 @@ private:
bool internalCallUpdate = false;
bool noUserConsent = false; /* When set to true an UPDATE request will be used instead of reINVITE */
SalCustomHeader *customHeaders = nullptr;
std::unordered_map<std::string, std::string> customContactParameters;
LinphoneCall *referer = nullptr; /* In case call creation is consecutive to an incoming transfer, this points to the original call */
L_DECLARE_PUBLIC(CallSessionParams);

View file

@ -54,6 +54,7 @@ void CallSessionParamsPrivate::clone (const CallSessionParamsPrivate &src, CallS
/* The management of the custom headers is not optimal. We copy everything while ref counting would be more efficient. */
if (src.customHeaders)
dst.customHeaders = sal_custom_header_clone(src.customHeaders);
dst.customContactParameters = src.customContactParameters;
dst.referer = src.referer;
}
@ -137,4 +138,28 @@ const char * CallSessionParams::getCustomHeader (const string &headerName) const
return sal_custom_header_find(d->customHeaders, headerName.c_str());
}
// -----------------------------------------------------------------------------
void CallSessionParams::addCustomContactParameter (const std::string &paramName, const std::string &paramValue) {
L_D();
auto it = d->customContactParameters.find(paramName);
if (it != d->customContactParameters.end())
d->customContactParameters.erase(it);
pair<string, string> param(paramName, paramValue);
d->customContactParameters.insert(param);
}
void CallSessionParams::clearCustomContactParameters () {
L_D();
d->customContactParameters.clear();
}
std::string CallSessionParams::getCustomContactParameter (const std::string &paramName) const {
L_D();
auto it = d->customContactParameters.find(paramName);
if (it == d->customContactParameters.end())
return "";
return it->second;
}
LINPHONE_END_NAMESPACE

View file

@ -56,6 +56,10 @@ public:
void clearCustomHeaders ();
const char * getCustomHeader (const std::string &headerName) const;
void addCustomContactParameter (const std::string &paramName, const std::string &paramValue = "");
void clearCustomContactParameters ();
std::string getCustomContactParameter (const std::string &paramName) const;
protected:
explicit CallSessionParams (CallSessionParamsPrivate &p);

View file

@ -600,9 +600,13 @@ void CallSessionPrivate::updateCurrentParams () const {}
// -----------------------------------------------------------------------------
void CallSessionPrivate::setContactOp () {
L_Q();
SalAddress *salAddress = nullptr;
LinphoneAddress *contact = getFixedContact();
if (contact) {
auto contactParams = q->getParams()->getPrivate()->getCustomContactParameters();
for (auto it = contactParams.begin(); it != contactParams.end(); it++)
linphone_address_set_param(contact, it->first.c_str(), it->second.empty() ? nullptr : it->second.c_str());
salAddress = const_cast<SalAddress *>(L_GET_PRIVATE_FROM_C_OBJECT(contact)->getInternalAddress());
op->set_contact_address(salAddress);
linphone_address_unref(contact);
@ -652,10 +656,10 @@ LinphoneAddress * CallSessionPrivate::getFixedContact () const {
char *addr = sal_address_as_string(pingOp->get_contact_address());
result = linphone_address_new(addr);
ms_free(addr);
} else if (destProxy && destProxy->op && _linphone_proxy_config_get_contact_without_params(destProxy)) {
} else if (destProxy && destProxy->op && linphone_proxy_config_get_contact(destProxy)) {
/* If using a proxy, use the contact address as guessed with the REGISTERs */
lInfo() << "Contact has been fixed using proxy";
result = linphone_address_clone(_linphone_proxy_config_get_contact_without_params(destProxy));
result = linphone_address_clone(linphone_proxy_config_get_contact(destProxy));
} else {
result = linphone_core_get_primary_contact_parsed(core);
if (result) {