Adding C API + first test

This commit is contained in:
Erwan Croze 2018-02-14 17:12:50 +01:00
parent ace638771e
commit 38fed6a292
18 changed files with 882 additions and 2 deletions

View file

@ -86,7 +86,9 @@ set(C_API_HEADER_FILES
c-chat-room.h
c-dial-plan.h
c-event-log.h
c-magic-search.h
c-participant.h
c-search-result.h
c-types.h
)

View file

@ -34,6 +34,8 @@
#include "linphone/api/c-dial-plan.h"
#include "linphone/api/c-event-log.h"
#include "linphone/api/c-participant.h"
#include "linphone/api/c-magic-search.h"
#include "linphone/api/c-search-result.h"
#include "linphone/api/c-types.h"
#endif // ifndef _L_C_API_H_

View file

@ -0,0 +1,121 @@
/*
* c-magic-search.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_C_MAGIC_SEARCH_H_
#define _L_C_MAGIC_SEARCH_H_
#include "linphone/api/c-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup misc
* @{
*/
/**
* Constructs a LinphoneMagicSearch object
**/
LINPHONE_PUBLIC LinphoneMagicSearch *linphone_magic_search_new(LinphoneCore *lc);
/**
* Increment reference count of LinphoneMagicSearch object.
**/
LINPHONE_PUBLIC LinphoneMagicSearch *linphone_magic_search_ref(LinphoneMagicSearch *magicSearch);
/**
* Decrement reference count of LinphoneMagicSearch object. When dropped to zero, memory is freed.
**/
LINPHONE_PUBLIC void linphone_magic_search_unref(LinphoneMagicSearch *magicSearch);
/**
* Set the minimum value used to calculate the weight in search
* @param[in] weight minimum weight
**/
LINPHONE_PUBLIC void linphone_magic_search_set_min_weight(LinphoneMagicSearch *magicSearch, const unsigned int weight);
/**
* @return the minimum value used to calculate the weight in search
**/
LINPHONE_PUBLIC unsigned int linphone_magic_search_get_min_weight(const LinphoneMagicSearch *magicSearch);
/**
* Set the maximum value used to calculate the weight in search
* @param[in] weight maximum weight
**/
LINPHONE_PUBLIC void linphone_magic_search_set_max_weight(LinphoneMagicSearch *magicSearch, const unsigned int weight);
/**
* @return the maximum value used to calculate the weight in search
**/
LINPHONE_PUBLIC unsigned int linphone_magic_search_get_max_weight(const LinphoneMagicSearch *magicSearch);
/**
* @return the delimiter used to find matched filter word
**/
LINPHONE_PUBLIC const char *linphone_magic_search_get_delimiter(const LinphoneMagicSearch *magicSearch);
/**
* Set the delimiter used to find matched filter word
* @param[in] delimiter delimiter (example "-_.,")
**/
LINPHONE_PUBLIC void linphone_magic_search_set_delimiter(LinphoneMagicSearch *magicSearch, const char *delimiter);
/**
* @return the number of the maximum SearchResult which will be return
**/
LINPHONE_PUBLIC unsigned int linphone_magic_search_get_search_limit(const LinphoneMagicSearch *magicSearch);
/**
* Set the number of the maximum SearchResult which will be return
* @param[in] limit
**/
LINPHONE_PUBLIC void linphone_magic_search_set_search_limit(LinphoneMagicSearch *magicSearch, const unsigned int limit);
/**
* @return if the search is limited
**/
LINPHONE_PUBLIC bool_t linphone_magic_search_get_limited_search(const LinphoneMagicSearch *magicSearch);
/**
* Enable or disable the limited search
* @param[in] limited
**/
LINPHONE_PUBLIC void linphone_magic_search_set_limited_search(LinphoneMagicSearch *magicSearch, const bool_t limited);
/**
* Create a sorted list of SearchResult from SipUri, Contact name,
* Contact displayname, Contact phone number, which match with a filter word
* @param[in] filter word we search
* @param[in] withDomain domain which we want to search only
* @return sorted list of \bctbx_list{LinphoneSearchResult}
**/
LINPHONE_PUBLIC bctbx_list_t* linphone_magic_search_get_contact_list_from_filter(const LinphoneMagicSearch *magicSearch, const char *filter, const char *withDomain);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // _L_C_MAGIC_SEARCH_H_

View file

@ -0,0 +1,67 @@
/*
* c-search-result.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_C_SEARCH_RESULT_H_
#define _L_C_SEARCH_RESULT_H_
#include "linphone/api/c-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup misc
* @{
*/
/**
* Increment reference count of LinphoneSearchResult object.
**/
LINPHONE_PUBLIC LinphoneSearchResult *linphone_search_result_ref(LinphoneSearchResult *searchResult);
/**
* Decrement reference count of LinphoneSearchResult object. When dropped to zero, memory is freed.
**/
LINPHONE_PUBLIC void linphone_search_result_unref(LinphoneSearchResult *searchResult);
/**
* @return LinphoneFriend associed
**/
LINPHONE_PUBLIC const LinphoneFriend* linphone_search_result_get_friend(LinphoneSearchResult *searchResult);
/**
* @return LinphoneAddress associed
**/
LINPHONE_PUBLIC const LinphoneAddress* linphone_search_result_get_address(LinphoneSearchResult *searchResult);
/**
* @return the result weight
**/
LINPHONE_PUBLIC unsigned int linphone_search_result_get_weight(LinphoneSearchResult *searchResult);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // _L_C_SEARCH_RESULT_H_

View file

@ -150,12 +150,24 @@ typedef struct _LinphoneEventLog LinphoneEventLog;
**/
typedef struct _LinphoneDialPlan LinphoneDialPlan;
/**
* A LinphoneMagicSearch is used to do specifics searchs
* @ingroup misc
**/
typedef struct _LinphoneMagicSearch LinphoneMagicSearch;
/**
* The LinphoneParticipant object represents a participant of a conference.
* @ingroup misc
**/
typedef struct _LinphoneParticipant LinphoneParticipant;
/**
* The LinphoneSearchResult object represents a result of a search
* @ingroup misc
**/
typedef struct _LinphoneSearchResult LinphoneSearchResult;
// =============================================================================
// C Enums.
// =============================================================================

View file

@ -21,7 +21,9 @@
#define _L_UTILS_H_
#include <ctime>
#include <list>
#include <string>
#include <utility>
#include <vector>
#include "linphone/utils/enum-generator.h"

View file

@ -144,6 +144,10 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
object/property-container.h
object/singleton.h
sal/sal.h
search/magic-search.h
search/magic-search-p.h
search/search-result.h
search/search-result-p.h
utils/background-task.h
utils/payload-type-handler.h
variant/variant.h
@ -167,7 +171,9 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
c-wrapper/api/c-core.cpp
c-wrapper/api/c-dial-plan.cpp
c-wrapper/api/c-event-log.cpp
c-wrapper/api/c-magic-search.cpp
c-wrapper/api/c-participant.cpp
c-wrapper/api/c-search-result.cpp
c-wrapper/internal/c-sal.cpp
c-wrapper/internal/c-tools.cpp
call/call.cpp
@ -249,6 +255,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
sal/refer-op.cpp
sal/register-op.cpp
sal/sal.cpp
search/magic-search.cpp
search/search-result.cpp
utils/background-task.cpp
utils/fs.cpp
utils/general.cpp

View file

@ -0,0 +1,86 @@
/*
* c-magic-search.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "search/magic-search.h"
#include "c-wrapper/c-wrapper.h"
using namespace std;
L_DECLARE_C_OBJECT_IMPL(MagicSearch);
LinphoneMagicSearch *linphone_magic_search_new(LinphoneCore *lc) {
shared_ptr<LinphonePrivate::MagicSearch> cppPtr = make_shared<LinphonePrivate::MagicSearch>(L_GET_CPP_PTR_FROM_C_OBJECT(lc));
LinphoneMagicSearch *object = L_INIT(MagicSearch);
L_SET_CPP_PTR_FROM_C_OBJECT(object, cppPtr);
return object;
}
LinphoneMagicSearch *linphone_magic_search_ref(LinphoneMagicSearch *magicSearch) {
belle_sip_object_ref(magicSearch);
return magicSearch;
}
void linphone_magic_search_unref(LinphoneMagicSearch *magicSearch) {
belle_sip_object_unref(magicSearch);
}
void linphone_magic_search_set_min_weight(LinphoneMagicSearch *magicSearch, const unsigned int weight) {
L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->setMinWeight(weight);
}
unsigned int linphone_magic_search_get_min_weight(const LinphoneMagicSearch *magicSearch) {
return L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getMinWeight();
}
void linphone_magic_search_set_max_weight(LinphoneMagicSearch *magicSearch, const unsigned int weight) {
L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->setMaxWeight(weight);
}
unsigned int linphone_magic_search_get_max_weight(const LinphoneMagicSearch *magicSearch) {
return L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getMaxWeight();
}
const char *linphone_magic_search_get_delimiter(const LinphoneMagicSearch *magicSearch) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getDelimiter());
}
void linphone_magic_search_set_delimiter(LinphoneMagicSearch *magicSearch, const char *delimiter) {
L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->setDelimiter(L_C_TO_STRING(delimiter));
}
unsigned int linphone_magic_search_get_search_limit(const LinphoneMagicSearch *magicSearch) {
return L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getSearchLimit();
}
void linphone_magic_search_set_search_limit(LinphoneMagicSearch *magicSearch, const unsigned int limit) {
L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->setSearchLimit(limit);
}
bool_t linphone_magic_search_get_limited_search(const LinphoneMagicSearch *magicSearch) {
return L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getLimitedSearch();
}
void linphone_magic_search_set_limited_search(LinphoneMagicSearch *magicSearch, const bool_t limited) {
L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->setLimitedSearch(limited);
}
bctbx_list_t* linphone_magic_search_get_contact_list_from_filter(const LinphoneMagicSearch *magicSearch, const char *filter, const char *withDomain) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(magicSearch)->getContactListFromFilter(L_C_TO_STRING(filter), L_C_TO_STRING(withDomain)));
}

View file

@ -0,0 +1,44 @@
/*
* c-search-result.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "search/search-result.h"
#include "c-wrapper/c-wrapper.h"
L_DECLARE_C_CLONABLE_OBJECT_IMPL(SearchResult);
LinphoneSearchResult *linphone_search_result_ref(LinphoneSearchResult *searchResult) {
belle_sip_object_ref(searchResult);
return searchResult;
}
void linphone_search_result_unref(LinphoneSearchResult *searchResult) {
belle_sip_object_unref(searchResult);
}
const LinphoneFriend* linphone_search_result_get_friend(LinphoneSearchResult *searchResult) {
return L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getFriend();
}
const LinphoneAddress* linphone_search_result_get_address(LinphoneSearchResult *searchResult) {
return L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getAddress();
}
unsigned int linphone_search_result_get_weight(LinphoneSearchResult *searchResult) {
return L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getWeight();
}

View file

@ -39,8 +39,10 @@
F(Core, Core) \
F(DialPlan, DialPlan) \
F(EventLog, EventLog) \
F(MagicSearch, MagicSearch) \
F(MediaSessionParams, CallParams) \
F(Participant, Participant)
F(Participant, Participant) \
F(SearchResult, SearchResult)
#define L_REGISTER_SUBTYPES(F) \
F(AbstractChatRoom, BasicChatRoom) \

View file

@ -0,0 +1,42 @@
/*
* magic-search-p.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_MAGIC_SEARCH_P_H_
#define _L_MAGIC_SEARCH_P_H_
#include "magic-search.h"
#include "object/object-p.h"
LINPHONE_BEGIN_NAMESPACE
class MagicSearchPrivate : public ObjectPrivate{
private:
unsigned int mMaxWeight;
unsigned int mMinWeight;
unsigned int mSearchLimit; // Number of ResultSearch maximum when the search is limited
bool mLimitedSearch; // Limit the search
std::string mDelimiter; // Delimiter use for the search
L_DECLARE_PUBLIC(MagicSearch);
};
LINPHONE_END_NAMESPACE
#endif //_L_MAGIC_SEARCH_P_H_

174
src/search/magic-search.cpp Normal file
View file

@ -0,0 +1,174 @@
/*
* magic-search.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "magic-search-p.h"
#include <bctoolbox/list.h>
#include "c-wrapper/internal/c-tools.h"
#include "linphone/utils/utils.h"
#include "linphone/core.h"
#include "linphone/types.h"
#include "private.h"
using namespace std;
LINPHONE_BEGIN_NAMESPACE
MagicSearch::MagicSearch(const std::shared_ptr<Core> &core) : CoreAccessor(core), Object(*new MagicSearchPrivate){
L_D();
d->mMinWeight = 0;
d->mMaxWeight = 1000;
d->mSearchLimit = 10;
d->mLimitedSearch = true;
d->mDelimiter = "+_-";
}
void MagicSearch::setMinWeight(const unsigned int weight) {
L_D();
d->mMinWeight = weight;
}
unsigned int MagicSearch::getMinWeight() const {
L_D();
return d->mMinWeight;
}
void MagicSearch::setMaxWeight(const unsigned int weight) {
L_D();
d->mMaxWeight = weight;
}
unsigned int MagicSearch::getMaxWeight() const {
L_D();
return d->mMaxWeight;
}
const string &MagicSearch::getDelimiter() const {
L_D();
return d->mDelimiter;
}
void MagicSearch::setDelimiter(const string &delimiter) {
L_D();
d->mDelimiter = delimiter;
}
unsigned int MagicSearch::getSearchLimit() const {
L_D();
return d->mSearchLimit;
}
void MagicSearch::setSearchLimit(const unsigned int limit) {
L_D();
d->mSearchLimit = limit;
}
bool MagicSearch::getLimitedSearch() const {
L_D();
return d->mLimitedSearch;
}
void MagicSearch::setLimitedSearch(const bool limited) {
L_D();
d->mLimitedSearch = limited;
}
list<SearchResult> MagicSearch::getContactListFromFilter(const string &filter, const string &withDomain) const {
list<SearchResult> resultList = list<SearchResult>();
LinphoneFriendList* list = linphone_core_get_default_friend_list(this->getCore()->getCCore());
// For all friends or when we reach the search limit
for (bctbx_list_t *f = list->friends ;
f != nullptr && (!getLimitedSearch() || resultList.size() < getSearchLimit());
f = bctbx_list_next(f)
) {
unsigned int weight = getMinWeight();
LinphoneFriend* lFriend = reinterpret_cast<LinphoneFriend*>(f->data);
const LinphoneAddress* lAddress = linphone_friend_get_address(lFriend);
if (lAddress == nullptr) break;
// Check domain
if (!withDomain.empty() &&
withDomain.compare(linphone_address_get_domain(lAddress)) != 0
) break;
// NAME
if (linphone_friend_get_name(lFriend) != nullptr) {
weight += getWeight(linphone_friend_get_name(lFriend), filter);
}
// PHONE NUMBER
bctbx_list_t *phoneNumbers = linphone_friend_get_phone_numbers(lFriend);
while (phoneNumbers != nullptr && phoneNumbers->data != nullptr) {
string number = static_cast<const char*>(phoneNumbers->data);
weight += getWeight(number, filter);
phoneNumbers = phoneNumbers->next;
}
// SIPURI
if (linphone_address_get_username(lAddress) != nullptr) {
weight += getWeight(linphone_address_get_username(lAddress), filter);
}
// DISPLAYNAME
if (linphone_address_get_display_name(lAddress) != nullptr) {
weight += getWeight(linphone_address_get_display_name(lAddress), filter);
}
resultList.push_back(SearchResult(weight, lAddress, lFriend));
}
resultList.sort();
return resultList;
}
unsigned int MagicSearch::getWeight(const string &stringWords, const string &filter) const {
size_t weight = string::npos;
// Finding all occurrences of "filter" in "stringWords"
for (size_t w = stringWords.find(filter) ; w != string::npos ; w = stringWords.find(filter, w)) {
// weight max if occurence find at beginning
if (w == 0) {
weight = getMaxWeight();
} else {
bool isDelimiter = false;
// get the char before the matched filter
const char l = stringWords.at(w - 1);
// Check if it's a delimiter
for (const char d : getDelimiter()) {
if (l == d) {
isDelimiter = true;
break;
}
}
unsigned int newWeight = getMaxWeight() - (unsigned int)((isDelimiter) ? 1 : w + 1);
weight = (weight != string::npos) ? weight + newWeight : newWeight;
}
}
return (weight != string::npos) ? (unsigned int)(weight) : getMinWeight();
}
MagicSearch::~MagicSearch() {}
LINPHONE_END_NAMESPACE

119
src/search/magic-search.h Normal file
View file

@ -0,0 +1,119 @@
/*
* magic-search.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_MAGIC_SEARCH_H_
#define _L_MAGIC_SEARCH_H_
#include <string>
#include <list>
#include <memory>
#include "core/core.h"
#include "core/core-accessor.h"
#include "search-result.h"
LINPHONE_BEGIN_NAMESPACE
class MagicSearchPrivate;
class LINPHONE_PUBLIC MagicSearch : public CoreAccessor, public Object{
public:
MagicSearch(const std::shared_ptr<Core> &core);
~MagicSearch();
/**
* Set the minimum value used to calculate the weight in search
* @param[in] weight minimum weight
**/
void setMinWeight(const unsigned int weight);
/**
* @return the minimum value used to calculate the weight in search
**/
unsigned int getMinWeight() const;
/**
* Set the maximum value used to calculate the weight in search
* @param[in] weight maximum weight
**/
void setMaxWeight(const unsigned int weight);
/**
* @return the maximum value used to calculate the weight in search
**/
unsigned int getMaxWeight() const;
/**
* @return the delimiter used to find matched filter word
**/
const std::string& getDelimiter() const;
/**
* Set the delimiter used to find matched filter word
* @param[in] delimiter delimiter (example "-_.,")
**/
void setDelimiter(const std::string &delimiter);
/**
* @return the number of the maximum SearchResult which will be return
**/
unsigned int getSearchLimit() const;
/**
* Set the number of the maximum SearchResult which will be return
* @param[in] limit
**/
void setSearchLimit(const unsigned int limit);
/**
* @return if the search is limited
**/
bool getLimitedSearch() const;
/**
* Enable or disable the limited search
* @param[in] limited
**/
void setLimitedSearch(const bool limited);
/**
* Create a sorted list of SearchResult from SipUri, Contact name,
* Contact displayname, Contact phone number, which match with a filter word
* @param[in] filter word we search
* @param[in] withDomain domain which we want to search only
* @return sorted list of SearchResult with "filter"
**/
std::list<SearchResult> getContactListFromFilter(const std::string &filter, const std::string &withDomain = "") const;
private:
/**
* Return a weight for a searched in with a filter
* @param[in] stringWords which where we are searching
* @param[in] filter what we are searching
* @return calculate weight
**/
unsigned int getWeight(const std::string &stringWords, const std::string &filter) const;
L_DECLARE_PRIVATE(MagicSearch);
};
LINPHONE_END_NAMESPACE
#endif //_L_MAGIC_SEARCH_H_

View file

@ -0,0 +1,42 @@
/*
* search-result-p.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_SEARCH_RESULT_P_H_
#define _L_SEARCH_RESULT_P_H_
#include "search-result.h"
#include "object/clonable-object-p.h"
#include "linphone/types.h"
LINPHONE_BEGIN_NAMESPACE
class SearchResultPrivate : public ClonableObjectPrivate {
private:
const LinphoneFriend *mFriend;
const LinphoneAddress *mAddress;
unsigned int mWeight;
L_DECLARE_PUBLIC(SearchResult);
};
LINPHONE_END_NAMESPACE
#endif //_L_SEARCH_RESULT_P_H_

View file

@ -0,0 +1,66 @@
/*
* search-result.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "search-result-p.h"
#include "linphone/utils/utils.h"
using namespace LinphonePrivate;
LINPHONE_BEGIN_NAMESPACE
SearchResult::SearchResult(const unsigned int weight, const LinphoneAddress *a, const LinphoneFriend *f) : ClonableObject(*new SearchResultPrivate) {
L_D();
d->mWeight = weight;
d->mAddress = a;
d->mFriend = f;
}
SearchResult::SearchResult(const SearchResult &sr) : ClonableObject(*new SearchResultPrivate) {
L_D();
d->mWeight = sr.getWeight();
d->mAddress = sr.getAddress();
d->mFriend = sr.getFriend();
}
SearchResult::~SearchResult() {};
bool SearchResult::operator<(const SearchResult& rsr) {
return this->getWeight() < rsr.getWeight();
}
bool SearchResult::operator=(const SearchResult& rsr) {
return this->getWeight() == rsr.getWeight();
}
const LinphoneFriend* SearchResult::getFriend() const {
L_D();
return d->mFriend;
}
const LinphoneAddress *SearchResult::getAddress() const {
L_D();
return d->mAddress;
}
unsigned int SearchResult::getWeight() const {
L_D();
return d->mWeight;
}
LINPHONE_END_NAMESPACE

View file

@ -0,0 +1,63 @@
/*
* search-result.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_SEARCH_RESULT_H_
#define _L_SEARCH_RESULT_H_
#include "object/clonable-object.h"
#include "linphone/utils/general.h"
#include "linphone/types.h"
#include "private.h"
LINPHONE_BEGIN_NAMESPACE
class SearchResultPrivate;
class LINPHONE_PUBLIC SearchResult : public ClonableObject {
public:
SearchResult() = delete;
SearchResult(const unsigned int weight, const LinphoneAddress *a, const LinphoneFriend *f = nullptr);
SearchResult(const SearchResult &sr);
~SearchResult();
bool operator<(const SearchResult& rsr);
bool operator=(const SearchResult& rsr);
/**
* @return LinphoneFriend associed
**/
const LinphoneFriend* getFriend() const;
/**
* @return LinphoneAddress associed
**/
const LinphoneAddress* getAddress() const;
/**
* @return the result weight
**/
unsigned int getWeight() const;
private:
L_DECLARE_PRIVATE(SearchResult);
};
LINPHONE_END_NAMESPACE
#endif //_L_SEARCH_RESULT_H_

View file

@ -19,6 +19,7 @@
#include <algorithm>
#include <cstdlib>
#include <list>
#include <sstream>
#include <bctoolbox/port.h>

View file

@ -23,6 +23,21 @@
#include "linphone/lpconfig.h"
#include "tester_utils.h"
static const char *sFriends[5] = {
"sip:test@sip.example.org",
"sip:test2@sip.example.org",
"sip:allo@sip.example.org",
"sip:hello@sip.example.org",
"sip:hello@sip.test.org"
};
static void _create_friend_from_tab(LinphoneCore *lc, LinphoneFriendList *list, const char *friends[], const unsigned int size) {
for (unsigned int i = 0 ; i <= size ; i++) {
LinphoneFriend *fr = linphone_core_create_friend_with_address(lc, friends[i]);
linphone_friend_list_add_friend(list, fr);
}
}
static void linphone_version_test(void){
const char *version=linphone_core_get_version();
/*make sure the git version is always included in the version number*/
@ -393,6 +408,17 @@ static void custom_tones_setup(void){
linphone_core_manager_destroy(mgr);
}
static void search_friend_all_domains(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "sip:toto@sip.linphone.org");
_create_friend_from_tab(manager->lc, lfl, sFriends, 5);
linphone_friend_unref(lf);
linphone_core_manager_destroy(manager);
}
test_t setup_tests[] = {
TEST_NO_TAG("Version check", linphone_version_test),
TEST_NO_TAG("Linphone Address", linphone_address_test),
@ -409,7 +435,8 @@ test_t setup_tests[] = {
TEST_NO_TAG("Devices reload", devices_reload_test),
TEST_NO_TAG("Codec usability", codec_usability_test),
TEST_NO_TAG("Codec setup", codec_setup),
TEST_NO_TAG("Custom tones setup", custom_tones_setup)
TEST_NO_TAG("Custom tones setup", custom_tones_setup),
TEST_NO_TAG("Search friend from all domains", search_friend_all_domains)
};
test_suite_t setup_test_suite = {"Setup", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,