Commit 93114a59 authored by Julien Wadel's avatar Julien Wadel
Browse files

Fix setup tester if LDAP has not been activated

Update copyrights dates

Fix tester : _check_friend_result_list is used to compare minimal URI (no display name).

Use of std::mutex

Use createTimer instead of old linphone_core_add_iterate_hook, change ldap callback anme

Fix deadlock on Sal request pending
Fix ldap tester by enabling server configuration on Marie and reorder results by display name

Fix filter search on domain by taking account minimum weight
parent 853ef9ac
......@@ -486,7 +486,7 @@ typedef void (*LinphoneConferenceCbsParticipantDeviceRemovedCb) (LinphoneConfere
*/
/**
* Call back used to notify message delivery status
* Callback used to notify message delivery status
* @param magic_search #LinphoneChatMessage object @notnil
*/
typedef void (*LinphoneMagicSearchCbsSearchResultsReceivedCb)(LinphoneMagicSearch* magic_search);
......
/*
* Copyright (c) 21021 Belledonne Communications SARL.
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......@@ -54,9 +54,9 @@ public:
* - "password" : "".
* Password to pass to server when binding.
* - "filter" : "(sn=*%s*)".
* The search is base on this filter to search friends.
* The search is based on this filter to search friends.
* - "name_attribute" : "sn".
* Check these attributes To build Name Friend, separated by a comma and the first is the highest priority.
* Check these attributes to build Name Friend, separated by a comma and the first is the highest priority.
* - "sip_attribute" : "mobile,telephoneNumber,homePhone,sn".
* Check these attributes to build the SIP username in address of Friend. Attributes are separated by a comma and the first is the highest priority.
* - "sip_scheme" : "sip".
......
......@@ -47,10 +47,9 @@ LdapContactProvider::LdapContactProvider(const std::shared_ptr<Core> &core, cons
mLd = nullptr;
mSalContext = NULL;
mServerUri = NULL;
ortp_mutex_init(&mLock, NULL);
// register our hook into iterate so that LDAP can do its magic asynchronously.
linphone_core_add_iterate_hook(core->getCCore(), iterate, this);
mIteration = mCore->createTimer(std::bind(&LdapContactProvider::iterate, this), 50, "LdapContactProvider");
if( !LdapConfigKeys::validConfig(config) ) {
ms_error( "[LDAP] Invalid configuration for LDAP, aborting creation");
mCurrentAction = ACTION_ERROR;
......@@ -61,9 +60,17 @@ LdapContactProvider::LdapContactProvider(const std::shared_ptr<Core> &core, cons
}
LdapContactProvider::~LdapContactProvider(){
linphone_core_remove_iterate_hook(mCore->getCCore(), iterate, this);
if(mIteration){
mCore->destroyTimer(mIteration);
mIteration = nullptr;
}
// Wait for bind thread to end
ortp_mutex_lock(&mLock);
mLock.lock();
if (mSalContext) {
belle_sip_resolver_context_cancel(mSalContext);
belle_sip_object_unref(mSalContext);
mSalContext = NULL;
}
if(mConnected==1)// We have been bind. Clean the exit
ldap_unbind_ext_s(mLd, NULL, NULL);
if(mAwaitingMessageId > 0){//There is currently a request that has not been processed. Abandon it.
......@@ -74,8 +81,7 @@ LdapContactProvider::~LdapContactProvider(){
belle_sip_object_unref(mServerUri);
mServerUri = NULL;
}
ortp_mutex_unlock(&mLock);
ortp_mutex_destroy(&mLock);
mLock.unlock();
}
std::vector<std::shared_ptr<LdapContactProvider> > LdapContactProvider::create(const std::shared_ptr<Core> &core){
......@@ -188,11 +194,11 @@ int LdapContactProvider::getCurrentAction()const{
// Create a search object and store the request to be used when the provider is ready
void LdapContactProvider::search(const std::string& predicate, ContactSearchCallback cb, void* cbData){
std::shared_ptr<LdapContactSearch> request = std::make_shared<LdapContactSearch>(this, predicate, cb, cbData );
ortp_mutex_lock(&mLock);
mLock.lock();
if( request != NULL ) {
mRequests.push_back(request);
}
ortp_mutex_unlock(&mLock);
mLock.unlock();
}
// Start the search
......@@ -288,7 +294,7 @@ int LdapContactProvider::completeContact( LdapContactFields* contact, const char
//******************************************* ASYNC PROCESSING
// ACTION_NONE => ACTION_INIT => (ACTION_WAIT_DNS) => ACTION_INITIALIZE => ACTION_BIND => ACTION_WAIT_BIND => ACTION_WAIT_REQUEST
bool_t LdapContactProvider::iterate(void *data) {
bool LdapContactProvider::iterate(void *data) {
struct timeval pollTimeout = {0,0};
LDAPMessage* results = NULL;
LdapContactProvider* provider = (LdapContactProvider*)data;
......@@ -299,7 +305,7 @@ bool_t LdapContactProvider::iterate(void *data) {
// not using switch is wanted : we can do severals steps in one iteration if wanted.
if(provider->mCurrentAction == ACTION_NONE){
ms_debug("[LDAP] ACTION_NONE");
ortp_mutex_lock(&provider->mLock);
provider->mLock.lock();
if( provider->mRequests.size() > 0){
if( provider->mCurrentAction != ACTION_ERROR){
if( provider->mConnected != 1)
......@@ -308,7 +314,7 @@ bool_t LdapContactProvider::iterate(void *data) {
provider->mCurrentAction = ACTION_BIND;
}
}
ortp_mutex_unlock(&provider->mLock);
provider->mLock.unlock();
}
if(provider->mCurrentAction == ACTION_INIT){
......@@ -329,7 +335,7 @@ bool_t LdapContactProvider::iterate(void *data) {
port = 636;
belle_generic_uri_set_port(provider->mServerUri, port);
}
provider->mSalContext = provider->mCore->getCCore()->sal->resolveA(domain.c_str(), port, AF_INET, stun_server_resolved, provider);
provider->mSalContext = provider->mCore->getCCore()->sal->resolveA(domain.c_str(), port, AF_INET, ldapServerResolved, provider);
if (provider->mSalContext){
belle_sip_object_ref(provider->mSalContext);
provider->mCurrentAction = ACTION_WAIT_DNS;
......@@ -406,7 +412,7 @@ bool_t LdapContactProvider::iterate(void *data) {
size_t requestSize = 0;
if( provider->mLd && provider->mConnected ){
// check for pending searches
ortp_mutex_lock(&provider->mLock);
provider->mLock.lock();
for(auto it = provider->mRequests.begin() ; it != provider->mRequests.end() ; ){
if(!(*it))
it = provider->mRequests.erase(it);
......@@ -422,7 +428,7 @@ bool_t LdapContactProvider::iterate(void *data) {
++it;
}
requestSize = provider->mRequests.size();
ortp_mutex_unlock(&provider->mLock);
provider->mLock.unlock();
}
if( requestSize > 0 ){// No need to check connectivity as it is checked before
// never block
......@@ -464,11 +470,11 @@ bool_t LdapContactProvider::iterate(void *data) {
}
}
}
return TRUE;
return true;
}
void LdapContactProvider::stun_server_resolved(void *data, belle_sip_resolver_results_t *results) {
void LdapContactProvider::ldapServerResolved(void *data, belle_sip_resolver_results_t *results) {
LdapContactProvider * provider = (LdapContactProvider*)(data);
const struct addrinfo * addr = belle_sip_resolver_results_get_addrinfos(results);
if (addr) {
......@@ -488,19 +494,19 @@ void LdapContactProvider::stun_server_resolved(void *data, belle_sip_resolver_re
}else{
provider->mServerUrl = provider->mConfig["server"];
}
ortp_mutex_lock(&provider->mLock);
provider->mLock.lock();
provider->mCurrentAction = ACTION_INITIALIZE;
ortp_mutex_unlock(&provider->mLock);
provider->mLock.unlock();
} else {
ms_error("[LDAP] Server resolution failed, no address can be found.");
ortp_mutex_lock(&provider->mLock);
provider->mLock.lock();
provider->mCurrentAction = ACTION_ERROR;
ortp_mutex_unlock(&provider->mLock);
provider->mLock.unlock();
}
}
void LdapContactProvider::handleSearchResult( LDAPMessage* message ) {
ortp_mutex_lock(&mLock);
mLock.lock();
if(message){
int msgtype = ldap_msgtype(message);
LdapContactSearch* req = requestSearch(ldap_msgid(message));
......@@ -555,7 +561,7 @@ void LdapContactProvider::handleSearchResult( LDAPMessage* message ) {
}
mRequests.clear();
}
ortp_mutex_unlock(&mLock);
mLock.unlock();
}
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......@@ -30,6 +30,7 @@
#include <vector>
#include <string>
#include <list>
#include <mutex>
#include <ldap.h>
......@@ -147,13 +148,13 @@ public:
* @param data A pointer to #LdapContactProvider
* @return
*/
static bool_t iterate(void *data);
static bool iterate(void *data);
/**
* @brief stun_server_resolved Callback for DNS resolution with Sal. It retrieve the Sal's result and replace the server domain to the IP.
* @param data #LdapContactProvider
* @param results The address from Sal
*/
static void stun_server_resolved(void *data, belle_sip_resolver_results_t *results);
static void ldapServerResolved(void *data, belle_sip_resolver_results_t *results);
private:
/**
* @brief handleSearchResult Parse the LDAPMessage to get contacts and fill Search entries.
......@@ -167,12 +168,13 @@ private:
std::vector<std::string> mNameAttributes;// Optimization to avoid split each times
std::vector<std::string> mSipAttributes;// Optimization to avoid split each times
LDAP *mLd;
ortp_mutex_t mLock;
std::mutex mLock;
std::list<std::shared_ptr<LdapContactSearch> > mRequests;
int mAwaitingMessageId; // Waiting Message for ldap_abandon_ext on bind
bool_t mConnected; // If we are connected to server (bind)
int mCurrentAction; // Iteration action
belle_sip_source_t * mIteration; // Iteration loop
belle_sip_resolver_context_t * mSalContext; // Sal Context for DNS
belle_generic_uri_t *mServerUri;//Used to optimized query on SAL
std::string mServerUrl; // URL to use for connection. It can be different from configuration
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2010-2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2010-2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......@@ -39,7 +39,8 @@ void SearchAsyncData::CbData::resultsCb( LinphoneContactSearch* id, bctbx_list_t
cbData->mResult->push_back(SearchResult(0, addr, "", nullptr));
} else {// We have constraints : add result with weight
unsigned int weight = cbData->mParent->searchInAddress(addr, cbData->mFilter, cbData->mWithDomain);
cbData->mResult->push_back(SearchResult(weight, addr, "", nullptr));
if( weight > cbData->mParent->getMinWeight())
cbData->mResult->push_back(SearchResult(weight, addr, "", nullptr));
}
}
}
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
* Copyright (c) 2021 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
......
......@@ -85,3 +85,4 @@ sip_scheme=sip
sip_domain=ldap.example.org
use_sal=1
verify_server_certificates=0
enable=1
......@@ -1249,10 +1249,16 @@ static void search_friend_with_presence(void) {
resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "chloe", "");
if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
#ifdef LDAP_ENABLED
BC_ASSERT_EQUAL(bctbx_list_size(resultList), 3, int, "%d");
_check_friend_result_list(manager->lc, resultList, 0, "sip:Chloe@ldap.example.org", NULL);// From LDAP
_check_friend_result_list(manager->lc, resultList, 1, chloeSipUri, chloePhoneNumber);//"sip:ch@sip.example.org"
_check_friend_result_list(manager->lc, resultList, 2, "sip:chloe@sip.example.org", NULL);//"sip:chloe@sip.example.org"
#else
BC_ASSERT_EQUAL((int)bctbx_list_size(resultList), 2, int, "%d");
_check_friend_result_list(manager->lc, resultList, 0, chloeSipUri, chloePhoneNumber);//"sip:ch@sip.example.org"
_check_friend_result_list(manager->lc, resultList, 1, "sip:chloe@sip.example.org", NULL);//"sip:chloe@sip.example.org"
#endif
bctbx_list_free_with_data(resultList, (bctbx_list_free_func)linphone_magic_search_unref);
}
......@@ -1847,13 +1853,20 @@ static void search_friend_chat_room_remote(void) {
magicSearch = linphone_magic_search_new(marie->lc);
resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "", "");
if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
BC_ASSERT_EQUAL(bctbx_list_size(resultList), 6, int, "%d");
_check_friend_result_list(marie->lc, resultList, 0, "sip:+33655667788@ldap.example.org", NULL);
_check_friend_result_list(marie->lc, resultList, 1, "sip:0601234567@ldap.example.org", NULL);
_check_friend_result_list(marie->lc, resultList, 2, "sip:Chloe@ldap.example.org", NULL);
_check_friend_result_list(marie->lc, resultList, 3, "sip:Pauline@ldap.example.org", NULL);
_check_friend_result_list(marie->lc, resultList, 4, addr, NULL);
_check_friend_result_list(marie->lc, resultList, 5, "sip:pauline@sip.example.org", NULL); // marie_rc has an hardcoded friend for pauline
#ifdef LDAP_ENABLED
BC_ASSERT_EQUAL(bctbx_list_size(resultList), 6, int, "%d");// Sorted by display names
_check_friend_result_list(marie->lc, resultList, 0, "sip:Chloe@ldap.example.org", NULL); // "Chloe"
_check_friend_result_list(marie->lc, resultList, 1, "sip:+33655667788@ldap.example.org", NULL); // "Laure"
_check_friend_result_list(marie->lc, resultList, 2, "sip:0601234567@ldap.example.org", NULL); // "Marie"
_check_friend_result_list(marie->lc, resultList, 3, "sip:Pauline@ldap.example.org", NULL); //"Pauline"
_check_friend_result_list(marie->lc, resultList, 4, addr, NULL); // "pauline_***" *** is dynamic
_check_friend_result_list(marie->lc, resultList, 5, "sip:pauline@sip.example.org", NULL); // "Paupoche"
// marie_rc has an hardcoded friend for pauline
#else
BC_ASSERT_EQUAL((int)bctbx_list_size(resultList), 2, int, "%d");
_check_friend_result_list(marie->lc, resultList, 0, addr, NULL);
_check_friend_result_list(marie->lc, resultList, 1, "sip:pauline@sip.example.org", NULL); // marie_rc has an hardcoded friend for pauline
#endif
bctbx_list_free_with_data(resultList, (bctbx_list_free_func)linphone_magic_search_unref);
}
ms_free(addr);
......
......@@ -2273,7 +2273,7 @@ void _check_friend_result_list(LinphoneCore *lc, const bctbx_list_t *resultList,
const LinphoneAddress *la = (linphone_search_result_get_address(sr)) ?
linphone_search_result_get_address(sr) : linphone_friend_get_address(lf);
if (la) {
char* fa = linphone_address_as_string(la);
char* fa = linphone_address_as_string_uri_only(la);
BC_ASSERT_STRING_EQUAL(fa , uri);
free(fa);
return;
......
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