Commit c0a6e18e authored by Erwan Croze's avatar Erwan Croze 👋🏻 Committed by Simon Morlat

Use sip_t instead of multiple argument to bind contact

parent 8590b49e
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2018 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -60,7 +60,6 @@ void ConferenceAddressGenerator::onRecordFound (Record *r) {
mConferenceAddr->asStringUriOnly(),
config->get<ConfigString>("transport")->read(),
mUuid,
mPath,
shared_from_this()
);
}
......
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2017 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -187,7 +187,7 @@ void flexisip::ConferenceServer::bindAddresses () {
// Binding loaded chat room
for (const auto &chatRoom : mCore->getChatRooms()) {
bindChatRoom(chatRoom->getPeerAddress()->asStringUriOnly(), mTransport, chatRoom->getPeerAddress()->getUriParam("gr"), mPath, nullptr);
bindChatRoom(chatRoom->getPeerAddress()->asStringUriOnly(), mTransport, chatRoom->getPeerAddress()->getUriParam("gr"), nullptr);
}
mAddressesBound = true;
......@@ -205,21 +205,22 @@ void flexisip::ConferenceServer::bindConference() {
shared_ptr<FakeListener> listener = make_shared<FakeListener>();
auto config = GenericManager::get()->getRoot()->get<GenericStruct>("conference-server");
if (config && config->get<ConfigBoolean>("enabled")->read()) {
sip_contact_t *sipContact = sip_contact_make(mHome.home(), mTransport.c_str());
url_t *url = url_make(mHome.home(), config->get<ConfigString>("conference-factory-uri")->read().c_str());
sip_path_t *bindingPath = sip_path_format(mHome.home(), "<%s>", mPath.c_str());
SofiaAutoHome home;
BindingParameters parameter;
sip_contact_t* sipContact = sip_contact_create(home.home(), reinterpret_cast<url_string_t*>(url_make(home.home(), mTransport.c_str())), nullptr);
url_t *from = url_make(home.home(), config->get<ConfigString>("conference-factory-uri")->read().c_str());
parameter.callId = "CONFERENCE";
parameter.path = mPath;
parameter.globalExpire = numeric_limits<int>::max();
parameter.alias = false;
parameter.version = 0;
RegistrarDb::get()->bind(
url,
from,
sipContact,
"CONFERENCE",
0,
bindingPath,
nullptr,
nullptr,
true,
numeric_limits<int>::max(),
false,
0,
parameter,
listener
);
}
......@@ -229,27 +230,26 @@ void ConferenceServer::bindChatRoom (
const string &bindingUrl,
const string &contact,
const string &gruu,
const string &path,
const shared_ptr<ContactUpdateListener> &listener
) {
url_t *url = url_make(mHome.home(), bindingUrl.c_str());
sip_contact_t *sipContact = sip_contact_make(mHome.home(), contact.c_str());
sip_contact_add_param(mHome.home(), sipContact, su_strdup(mHome.home(), ("+sip.instance=\"<" + gruu + ">\"").c_str()));
url_param_add(mHome.home(), sipContact->m_url, ("gr=" + gruu).c_str());
sip_supported_t *sipSupported = reinterpret_cast<sip_supported_t *>(sip_header_format(mHome.home(), sip_supported_class, "gruu"));
sip_path_t *bindingPath = sip_path_format(mHome.home(), "<%s>", mPath.c_str());
SofiaAutoHome home;
BindingParameters parameter;
sip_contact_t* sipContact = sip_contact_create(home.home(), reinterpret_cast<url_string_t*>(url_make(home.home(), contact.c_str())), ("+sip.instance=\"<" + gruu + ">\"").c_str());
url_t *from = url_make(home.home(), bindingUrl.c_str());
url_param_add(home.home(), from, ("gr=" + gruu).c_str());
parameter.callId = gruu;
parameter.path = mPath;
parameter.globalExpire = numeric_limits<int>::max();
parameter.alias = false;
parameter.version = 0;
parameter.withGruu = true;
RegistrarDb::get()->bind(
url,
from,
sipContact,
gruu.c_str(),
0,
bindingPath,
sipSupported,
nullptr,
true,
numeric_limits<int>::max(),
false,
0,
parameter,
listener
);
}
......@@ -276,7 +276,7 @@ ConferenceServer::Init::Init() {
},
{
Boolean,
"enable-one-to-one-chat-room",
"enable-one-to-one-chat-room",
"Whether one-to-one chat room creation is allowed or not",
"true"
},
......
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2017 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -49,7 +49,6 @@ namespace flexisip {
const std::string &bindingUrl,
const std::string &contact,
const std::string &gruu,
const std::string &path,
const std::shared_ptr<ContactUpdateListener> &listener
);
......
This diff is collapsed.
......@@ -33,16 +33,13 @@ RegistrarDbInternal::RegistrarDbInternal(Agent *ag) : RegistrarDb(ag) {
mWritable = true;
}
void RegistrarDbInternal::doBind(const url_t *ifrom, sip_contact_t *icontact, const char *iid, uint32_t iseq,
const sip_path_t *ipath, list<string> acceptHeaders, bool usedAsRoute, int expire, int alias, int version,
const shared_ptr<ContactUpdateListener> &listener) {
string key = Record::defineKeyFromUrl(ifrom);
time_t now = getCurrentTime();
void RegistrarDbInternal::doBind(const sip_t *sip, int globalExpire, bool alias, int version, const shared_ptr<ContactUpdateListener> &listener) {
string key = Record::defineKeyFromUrl(sip->sip_from->a_url);
map<string, Record *>::iterator it = mRecords.find(key);
Record *r;
if (it == mRecords.end()) {
r = new Record(ifrom);
if (sip->sip_from && it == mRecords.end()) {
r = new Record(sip->sip_from->a_url);
mRecords.insert(make_pair(key, r));
LOGD("Creating AOR %s association", key.c_str());
} else {
......@@ -50,13 +47,13 @@ void RegistrarDbInternal::doBind(const url_t *ifrom, sip_contact_t *icontact, co
r = (*it).second;
}
if (r->isInvalidRegister(iid, iseq)) {
if (sip->sip_call_id && sip->sip_cseq && r->isInvalidRegister(sip->sip_call_id->i_id, sip->sip_cseq->cs_seq)) {
LOGD("Invalid register");
if (listener) listener->onInvalid();
return;
}
r->update(icontact, ipath, expire, iid, iseq, now, alias, acceptHeaders, usedAsRoute, listener);
r->update(sip, globalExpire, alias, version, listener);
mLocalRegExpire->update(*r);
if (listener) listener->onRecordFound(r);
......
......@@ -29,8 +29,7 @@ class RegistrarDbInternal : public RegistrarDb {
void clearAll();
private:
virtual void doBind(const url_t *ifrom, sip_contact_t *icontact, const char *iid, uint32_t iseq, const sip_path_t *ipath,
std::list<std::string> acceptHeaders, bool usedAsRoute, int expire, int alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doBind(const sip_t *sip, int globalExpire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doClear(const sip_t *sip, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doFetch(const url_t *url, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doFetchForGruu(const url_t *url, const std::string &gruu, const std::shared_ptr<ContactUpdateListener> &listener);
......
This diff is collapsed.
......@@ -104,9 +104,7 @@ class RegistrarDbRedisAsync : public RegistrarDb {
bool disconnect();
protected:
virtual void doBind(const url_t *ifrom, sip_contact_t *icontact, const char *iid, uint32_t iseq,
const sip_path_t *ipath, std::list<std::string> acceptHeaders, bool usedAsRoute, int expire, int alias, int version,
const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doBind(const sip_t *sip, int globalExpire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doClear(const sip_t *sip, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doFetch(const url_t *url, const std::shared_ptr<ContactUpdateListener> &listener);
virtual void doFetchForGruu(const url_t *url, const std::string &gruu, const std::shared_ptr<ContactUpdateListener> &listener);
......
This diff is collapsed.
......@@ -49,11 +49,9 @@ struct ExtendedContactCommon {
ExtendedContactCommon(const char *contactId, const std::list<std::string> &path, const std::string &callId,
const char *lineValue) {
if (!callId.empty())
mCallId = callId;
if (!callId.empty()) mCallId = callId;
mPath = path;
if (lineValue)
mUniqueId = lineValue;
if (lineValue) mUniqueId = lineValue;
mContactId = contactId;
}
ExtendedContactCommon(const std::string &route) : mContactId(), mCallId(), mUniqueId(), mPath({route}) {
......@@ -68,6 +66,7 @@ struct ExtendedContact {
std::string mCallId;
std::string mUniqueId;
std::list<std::string> mPath; //list of urls as string (not enclosed with brakets)
std::string mUserAgent;
sip_contact_t *mSipContact; // Full contact
float mQ;
time_t mExpireAt;
......@@ -91,7 +90,10 @@ struct ExtendedContact {
return mContactId.c_str();
}
inline const char *route() {
return (mPath.empty() ? NULL : mPath.cbegin()->c_str());
return (mPath.empty() ? nullptr : mPath.cbegin()->c_str());
}
inline const char *userAgent() {
return mUserAgent.c_str();
}
static int resolveExpire(const char *contact_expire, int global_expire) {
......@@ -123,7 +125,7 @@ struct ExtendedContact {
const std::string &getUniqueId() {
return (mUniqueId.empty() ? mCallId : mUniqueId);
}
time_t getExpireNotAtMessage() {
return mExpireNotAtMessage;
}
......@@ -136,14 +138,14 @@ struct ExtendedContact {
void transferRegId(const std::shared_ptr<ExtendedContact> &oldEc);
const std::string getMessageExpires(const msg_param_t *m_params);
ExtendedContact(const ExtendedContactCommon &common, sip_contact_t *sip_contact, int global_expire, uint32_t cseq,
time_t updateTime, bool alias, const std::list<std::string> &acceptHeaders)
ExtendedContact(const ExtendedContactCommon &common, const sip_contact_t *sip_contact, int global_expire, uint32_t cseq,
time_t updateTime, bool alias, const std::list<std::string> &acceptHeaders, const std::string &userAgent)
: mContactId(common.mContactId), mCallId(common.mCallId), mUniqueId(common.mUniqueId), mPath(common.mPath),
mSipContact(NULL), mQ(1.0), mUpdatedTime(updateTime), mCSeq(cseq), mAlias(alias), mAcceptHeader(acceptHeaders),
mUsedAsRoute(false), mRegId(0), mHome() {
mUserAgent(userAgent), mSipContact(nullptr), mQ(1.0), mUpdatedTime(updateTime), mCSeq(cseq), mAlias(alias),
mAcceptHeader(acceptHeaders), mUsedAsRoute(false), mRegId(0), mHome() {
mSipContact = sip_contact_dup(mHome.home(), sip_contact);
mSipContact->m_next = NULL;
mSipContact->m_next = nullptr;
if (mSipContact->m_q) {
mQ = atof(mSipContact->m_q);
......@@ -161,18 +163,18 @@ struct ExtendedContact {
}
ExtendedContact(const url_t *url, const std::string &route, const float q = 1.0)
: mContactId(), mCallId(), mUniqueId(), mPath({route}), mSipContact(NULL), mQ(q), mExpireAt(LONG_MAX),
: mContactId(), mCallId(), mUniqueId(), mPath({route}), mUserAgent(), mSipContact(nullptr), mQ(q), mExpireAt(LONG_MAX),
mExpireNotAtMessage(LONG_MAX), mUpdatedTime(0), mCSeq(0), mAlias(false), mAcceptHeader({}), mUsedAsRoute(false),
mRegId(0), mHome() {
mSipContact = sip_contact_create(mHome.home(), (url_string_t*)url, NULL);
mSipContact = sip_contact_create(mHome.home(), (url_string_t*)url, nullptr);
}
ExtendedContact(const ExtendedContact &ec)
: mContactId(ec.mContactId), mCallId(ec.mCallId), mUniqueId(ec.mUniqueId), mPath(ec.mPath), mSipContact(NULL), mQ(ec.mQ),
mExpireAt(ec.mExpireAt), mExpireNotAtMessage(ec.mExpireNotAtMessage), mUpdatedTime(ec.mUpdatedTime), mCSeq(ec.mCSeq),
mAlias(ec.mAlias), mAcceptHeader(ec.mAcceptHeader), mUsedAsRoute(ec.mUsedAsRoute), mRegId(ec.mRegId), mHome() {
: mContactId(ec.mContactId), mCallId(ec.mCallId), mUniqueId(ec.mUniqueId), mPath(ec.mPath), mUserAgent(ec.mUserAgent),
mSipContact(nullptr), mQ(ec.mQ), mExpireAt(ec.mExpireAt), mExpireNotAtMessage(ec.mExpireNotAtMessage), mUpdatedTime(ec.mUpdatedTime),
mCSeq(ec.mCSeq), mAlias(ec.mAlias), mAcceptHeader(ec.mAcceptHeader), mUsedAsRoute(ec.mUsedAsRoute), mRegId(ec.mRegId), mHome() {
mSipContact = sip_contact_dup(mHome.home(), ec.mSipContact);
mSipContact->m_next = NULL;
mSipContact->m_next = nullptr;
}
std::ostream &print(std::ostream &stream, time_t _now = getCurrentTime(), time_t offset = 0) const;
......@@ -195,6 +197,7 @@ class Record {
private:
static void init();
void insertOrUpdateBinding(const std::shared_ptr<ExtendedContact> &ec, const std::shared_ptr<ContactUpdateListener> &listener);
std::shared_ptr< std::multimap<std::string, std::string> > extractInfoFromHeader(const char *url_headers, const std::list<std::string> paramName);
std::list<std::shared_ptr<ExtendedContact>> mContacts;
std::list<std::shared_ptr<ExtendedContact>> mContactsToRemove;
std::string mKey;
......@@ -217,9 +220,7 @@ class Record {
}
bool isInvalidRegister(const std::string &call_id, uint32_t cseq);
void clean(time_t time, const std::shared_ptr<ContactUpdateListener> &listener);
void update(sip_contact_t *contacts, const sip_path_t *path, int globalExpire, const std::string &call_id,
uint32_t cseq, time_t now, bool alias, const std::list<std::string> accept, bool usedAsRoute,
const std::shared_ptr<ContactUpdateListener> &listener);
void update(const sip_t *sip, int globalExpire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
//Deprecated: this one is used by protobuf serializer
void update(const ExtendedContactCommon &ecc, const char *sipuri, long int expireAt, float q, uint32_t cseq,
time_t updated_time, bool alias, const std::list<std::string> accept, bool usedAsRoute,
......@@ -306,6 +307,24 @@ public:
virtual void onLocalRegExpireUpdated(unsigned int count) = 0;
};
struct BindingParameters {
bool alias;
bool withGruu;
int globalExpire;
int version;
std::string callId;
std::string path;
BindingParameters() {
alias = false;
withGruu = false;
globalExpire = 0;
version = 0;
callId = "";
path = "";
}
};
/**
* A singleton class which holds records contact addresses associated with a from.
* Both local and remote storage implementations exist.
......@@ -317,9 +336,8 @@ class RegistrarDb {
public:
static RegistrarDb *initialize(Agent *ag);
static RegistrarDb *get();
void bind(const url_t *ifrom, sip_contact_t *icontact, const char *iid, uint32_t iseq,
const sip_path_t *ipath, const sip_supported_t *isupported, const sip_accept_t *iaccept, bool usedAsRoute, int expire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
void bind(const sip_t *sip, int globalExpire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener);
void bind(const sip_t *sip, const BindingParameters &parameter, const std::shared_ptr<ContactUpdateListener> &listener);
void bind(const url_t *from, const sip_contact_t *contact, const BindingParameters &parameter, const std::shared_ptr<ContactUpdateListener> &listener);
void clear(const sip_t *sip, const std::shared_ptr<ContactUpdateListener> &listener);
void fetch(const url_t *url, const std::shared_ptr<ContactUpdateListener> &listener, bool recursive = false);
void fetch(const url_t *url, const std::shared_ptr<ContactUpdateListener> &listener, bool includingDomains, bool recursive);
......@@ -375,8 +393,7 @@ class RegistrarDb {
void unsubscribe(LocalRegExpireListener *listener);
void notifyLocalRegExpireListener(unsigned int count);
};
virtual void doBind(const url_t *ifrom, sip_contact_t *icontact, const char *iid, uint32_t iseq,
const sip_path_t *ipath, std::list<std::string> acceptHeaders, bool usedAsRoute, int expire, int alias, int version, const std::shared_ptr<ContactUpdateListener> &listener) = 0;
virtual void doBind(const sip_t *sip, int globalExpire, bool alias, int version, const std::shared_ptr<ContactUpdateListener> &listener) = 0;
virtual void doClear(const sip_t *sip, const std::shared_ptr<ContactUpdateListener> &listener) = 0;
virtual void doFetch(const url_t *url, const std::shared_ptr<ContactUpdateListener> &listener) = 0;
virtual void doFetchForGruu(const url_t *url, const std::string &gruu, const std::shared_ptr<ContactUpdateListener> &listener) = 0;
......
......@@ -62,13 +62,23 @@ int test_bind_without_ecc(ExtendedContactCommon &ecc, const unique_ptr<RecordSer
sip_accept_t *accept) {
Record initial(NULL);
list<string> acceptHeaders;
while (accept != NULL) {
acceptHeaders.push_back(accept->ac_type);
accept = accept->ac_next;
}
msg_t *msg = msg_create(sip_default_mclass(), 0);
su_home_t *homeSip = msg_home(msg);
sip_t *sip = sip_object(msg);
sip->sip_contact = sip_contact_dup(homeSip, contacts);
sip->sip_contact->m_next = nullptr;
sip->sip_accept = sip_accept_dup(homeSip, accept);
sip->sip_from = sip_from_create(homeSip, reinterpret_cast<url_string_t*>(contacts->m_url));
sip->sip_path = sip_path_dup(homeSip, path);
sip->sip_call_id = sip_call_id_make(homeSip, callid);
sip->sip_expires = sip_expires_create(homeSip, now);
sip->sip_cseq = sip_cseq_create(homeSip, cseq, sip_method_unknown, nullptr);
initial.update(sip, globalexpire, alias, 0, nullptr);
msg_unref(msg);
initial.update(contacts, path, globalexpire, callid, cseq, now, alias, acceptHeaders, false, NULL);
if (!compare(firstContact(initial), alias, ecc, cseq, expireat, quality, contact, now)) {
cerr << "Initial and parameters differ" << endl;
return -1;
......
......@@ -54,8 +54,7 @@ std::ostream &operator<<(std::ostream &stream, const std::list<std::string> &str
}
template <typename CompT> inline void check(const std::string &name, const CompT &v1, const CompT &v2) {
if (v1 != v2)
BAD(name << " X" << v1 << "X / X" << v2 << "X");
if (v1 != v2) std::cout << name << " X" << v1 << "X / X" << v2 << "X" << std::endl;
}
bool compare(const ExtendedContact &ec1, bool alias, const ExtendedContactCommon &common, uint32_t cseq,
......@@ -83,8 +82,7 @@ bool compare(const ExtendedContact &ec1, const ExtendedContact &ec2) {
bool compare(const Record &r1, const Record &r2) {
auto ec1 = r1.getExtendedContacts();
auto ec2 = r2.getExtendedContacts();
if (ec1.size() != ec2.size())
BAD("ecc size :" << ec1.size() << " / " << ec2.size());
if (ec1.size() != ec2.size()) BAD("ecc size :" << ec1.size() << " / " << ec2.size());
return compare(firstContact(r1), firstContact(r2));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment