Commit e3cda96b authored by Ronan's avatar Ronan
Browse files

fix(MagicSearch): mark many methods as const + avoid memory leak in wrapper

parent f808bb70
......@@ -130,10 +130,10 @@ LINPHONE_PUBLIC void linphone_magic_search_reset_search_cache (LinphoneMagicSear
* - "" for searching in all contact
* - "*" for searching in contact with sip SipUri
* - "yourdomain" for searching in contact from "yourdomain" domain
* @return sorted list of \bctbx_list{LinphoneSearchResult}
* @return sorted list of \bctbx_list{LinphoneSearchResult} \onTheFlyList
**/
LINPHONE_PUBLIC bctbx_list_t* linphone_magic_search_get_contact_list_from_filter (
LinphoneMagicSearch *magic_search,
LINPHONE_PUBLIC bctbx_list_t *linphone_magic_search_get_contact_list_from_filter (
const LinphoneMagicSearch *magic_search,
const char *filter,
const char *domain
);
......
......@@ -101,8 +101,8 @@ void linphone_magic_search_reset_search_cache (LinphoneMagicSearch *magic_search
L_GET_CPP_PTR_FROM_C_OBJECT(magic_search)->resetSearchCache();
}
bctbx_list_t* linphone_magic_search_get_contact_list_from_filter (
LinphoneMagicSearch *magic_search,
bctbx_list_t *linphone_magic_search_get_contact_list_from_filter (
const LinphoneMagicSearch *magic_search,
const char *filter,
const char *domain
) {
......
......@@ -33,7 +33,8 @@ private:
bool mLimitedSearch; // Limit the search
std::string mDelimiter; // Delimiter use for the search
bool mUseDelimiter;
std::list<SearchResult> *mCacheResult;
mutable std::list<SearchResult> *mCacheResult;
L_DECLARE_PUBLIC(MagicSearch);
};
......@@ -41,4 +42,3 @@ private:
LINPHONE_END_NAMESPACE
#endif //_L_MAGIC_SEARCH_P_H_
......@@ -33,7 +33,7 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
MagicSearch::MagicSearch(const std::shared_ptr<Core> &core) : CoreAccessor(core), Object(*new MagicSearchPrivate){
MagicSearch::MagicSearch (const std::shared_ptr<Core> &core) : CoreAccessor(core), Object(*new MagicSearchPrivate){
L_D();
d->mMinWeight = 0;
d->mMaxWeight = 1000;
......@@ -44,71 +44,71 @@ MagicSearch::MagicSearch(const std::shared_ptr<Core> &core) : CoreAccessor(core)
d->mCacheResult = nullptr;
}
MagicSearch::~MagicSearch() {
MagicSearch::~MagicSearch () {
resetSearchCache();
}
void MagicSearch::setMinWeight(const unsigned int weight) {
void MagicSearch::setMinWeight (const unsigned int weight) {
L_D();
d->mMinWeight = weight;
}
unsigned int MagicSearch::getMinWeight() const {
unsigned int MagicSearch::getMinWeight () const {
L_D();
return d->mMinWeight;
}
void MagicSearch::setMaxWeight(const unsigned int weight) {
void MagicSearch::setMaxWeight (const unsigned int weight) {
L_D();
d->mMaxWeight = weight;
}
unsigned int MagicSearch::getMaxWeight() const {
unsigned int MagicSearch::getMaxWeight () const {
L_D();
return d->mMaxWeight;
}
const string &MagicSearch::getDelimiter() const {
const string &MagicSearch::getDelimiter () const {
L_D();
return d->mDelimiter;
}
void MagicSearch::setDelimiter(const string &delimiter) {
void MagicSearch::setDelimiter (const string &delimiter) {
L_D();
d->mDelimiter = delimiter;
}
bool MagicSearch::getUseDelimiter() const {
bool MagicSearch::getUseDelimiter () const {
L_D();
return d->mUseDelimiter;
}
void MagicSearch::setUseDelimiter(bool enable) {
void MagicSearch::setUseDelimiter (bool enable) {
L_D();
d->mUseDelimiter = enable;
}
unsigned int MagicSearch::getSearchLimit() const {
unsigned int MagicSearch::getSearchLimit () const {
L_D();
return d->mSearchLimit;
}
void MagicSearch::setSearchLimit(const unsigned int limit) {
void MagicSearch::setSearchLimit (const unsigned int limit) {
L_D();
d->mSearchLimit = limit;
}
bool MagicSearch::getLimitedSearch() const {
bool MagicSearch::getLimitedSearch () const {
L_D();
return d->mLimitedSearch;
}
void MagicSearch::setLimitedSearch(const bool limited) {
void MagicSearch::setLimitedSearch (const bool limited) {
L_D();
d->mLimitedSearch = limited;
}
void MagicSearch::resetSearchCache() {
void MagicSearch::resetSearchCache () const {
L_D();
if (d->mCacheResult) {
delete d->mCacheResult;
......@@ -116,7 +116,7 @@ void MagicSearch::resetSearchCache() {
}
}
list<SearchResult> MagicSearch::getContactListFromFilter(const string &filter, const string &withDomain) {
list<SearchResult> MagicSearch::getContactListFromFilter (const string &filter, const string &withDomain) const {
list<SearchResult> *resultList;
list<SearchResult> returnList;
LinphoneProxyConfig *proxy = nullptr;
......@@ -166,18 +166,18 @@ list<SearchResult> MagicSearch::getContactListFromFilter(const string &filter, c
// Private Methods //
/////////////////////
list<SearchResult> *MagicSearch::getSearchCache() const {
list<SearchResult> *MagicSearch::getSearchCache () const {
L_D();
return d->mCacheResult;
}
void MagicSearch::setSearchCache(list<SearchResult> *cache) {
void MagicSearch::setSearchCache (list<SearchResult> *cache) const {
L_D();
if (d->mCacheResult != cache) resetSearchCache();
d->mCacheResult = cache;
}
static bool findAddress(const list<SearchResult> &list, const LinphoneAddress *addr) {
static bool findAddress (const list<SearchResult> &list, const LinphoneAddress *addr) {
bool returnValue = false;
char *charAddr = linphone_address_as_string_uri_only(addr);
string sAddr = charAddr;
......@@ -197,7 +197,11 @@ static bool findAddress(const list<SearchResult> &list, const LinphoneAddress *a
return returnValue;
}
list<SearchResult> MagicSearch::getAddressFromCallLog(const string &filter, const string &withDomain, const list<SearchResult> &currentList) {
list<SearchResult> MagicSearch::getAddressFromCallLog (
const string &filter,
const string &withDomain,
const list<SearchResult> &currentList
) const {
list<SearchResult> resultList;
const bctbx_list_t *callLog = linphone_core_get_call_logs(this->getCore()->getCCore());
......@@ -223,7 +227,7 @@ list<SearchResult> MagicSearch::getAddressFromCallLog(const string &filter, cons
return resultList;
}
list<SearchResult> MagicSearch::getFriends(const string &withDomain) {
list<SearchResult> MagicSearch::getFriends (const string &withDomain) const {
list<SearchResult> returnList;
list<SearchResult> clResults;
LinphoneFriendList *list = linphone_core_get_default_friend_list(this->getCore()->getCCore());
......@@ -296,7 +300,7 @@ list<SearchResult> MagicSearch::getFriends(const string &withDomain) {
return *uniqueItemsList(returnList);
}
list<SearchResult> *MagicSearch::beginNewSearch(const string &filter, const string &withDomain) {
list<SearchResult> *MagicSearch::beginNewSearch (const string &filter, const string &withDomain) const {
list<SearchResult> clResults;
list<SearchResult> *resultList = new list<SearchResult>();
LinphoneFriendList *fList = linphone_core_get_default_friend_list(this->getCore()->getCCore());
......@@ -313,7 +317,7 @@ list<SearchResult> *MagicSearch::beginNewSearch(const string &filter, const stri
return uniqueItemsList(*resultList);
}
list<SearchResult> *MagicSearch::continueSearch(const string &filter, const string &withDomain) {
list<SearchResult> *MagicSearch::continueSearch (const string &filter, const string &withDomain) const {
list<SearchResult> *resultList = new list<SearchResult>();
const list <SearchResult> *cacheList = getSearchCache();
......@@ -334,7 +338,7 @@ list<SearchResult> *MagicSearch::continueSearch(const string &filter, const stri
return uniqueItemsList(*resultList);
}
list<SearchResult> MagicSearch::searchInFriend(const LinphoneFriend *lFriend, const string &filter, const string &withDomain) {
list<SearchResult> MagicSearch::searchInFriend (const LinphoneFriend *lFriend, const string &filter, const string &withDomain) const {
list<SearchResult> friendResult;
string phoneNumber = "";
unsigned int weight = getMinWeight();
......@@ -411,7 +415,7 @@ list<SearchResult> MagicSearch::searchInFriend(const LinphoneFriend *lFriend, co
return friendResult;
}
unsigned int MagicSearch::searchInAddress(const LinphoneAddress *lAddress, const string &filter, const string &withDomain) {
unsigned int MagicSearch::searchInAddress (const LinphoneAddress *lAddress, const string &filter, const string &withDomain) const {
unsigned int weight = getMinWeight();
if (lAddress != nullptr && checkDomain(nullptr, lAddress, withDomain)) {
// SIPURI
......@@ -426,7 +430,7 @@ unsigned int MagicSearch::searchInAddress(const LinphoneAddress *lAddress, const
return weight;
}
unsigned int MagicSearch::getWeight(const string &stringWords, const string &filter) const {
unsigned int MagicSearch::getWeight (const string &stringWords, const string &filter) const {
locale loc;
string filterLC = filter;
string stringWordsLC = stringWords;
......@@ -467,7 +471,7 @@ unsigned int MagicSearch::getWeight(const string &stringWords, const string &fil
return (weight != string::npos) ? (unsigned int)(weight) : getMinWeight();
}
bool MagicSearch::checkDomain(const LinphoneFriend *lFriend, const LinphoneAddress *lAddress, const string &withDomain) const {
bool MagicSearch::checkDomain (const LinphoneFriend *lFriend, const LinphoneAddress *lAddress, const string &withDomain) const {
bool onlyOneDomain = !withDomain.empty() && withDomain != "*";
const LinphonePresenceModel *presenceModel = lFriend ? linphone_friend_get_presence_model(lFriend) : nullptr;
char *contactPresence = presenceModel ? linphone_presence_model_get_contact(presenceModel) : nullptr;
......@@ -492,13 +496,13 @@ bool MagicSearch::checkDomain(const LinphoneFriend *lFriend, const LinphoneAddre
return soFarSoGood;
}
void MagicSearch::addResultsToResultsList(std::list<SearchResult> &results, std::list<SearchResult> &srL) {
void MagicSearch::addResultsToResultsList (std::list<SearchResult> &results, std::list<SearchResult> &srL) const {
if (results.size() > 0) {
srL.merge(results);
}
}
static string getAddressFromSearchResult(const SearchResult &sr, const shared_ptr<Core> lc) {
static string getAddressFromSearchResult (const SearchResult &sr, const shared_ptr<Core> lc) {
string sAddress = "";
if (!sr.getAddress() && sr.getFriend()) {
const LinphonePresenceModel *presenceModel = linphone_friend_get_presence_model(sr.getFriend());
......@@ -524,7 +528,7 @@ static string getAddressFromSearchResult(const SearchResult &sr, const shared_pt
return sAddress;
}
list<SearchResult> *MagicSearch::uniqueItemsList(list<SearchResult> &list) {
list<SearchResult> *MagicSearch::uniqueItemsList (list<SearchResult> &list) const {
auto lc = this->getCore();
list.unique([lc](const SearchResult& lsr, const SearchResult& rsr){
string left = getAddressFromSearchResult(lsr, lc);
......
......@@ -35,80 +35,80 @@ class MagicSearchPrivate;
class LINPHONE_PUBLIC MagicSearch : public CoreAccessor, public Object{
public:
MagicSearch(const std::shared_ptr<Core> &core);
MagicSearch(const MagicSearch &ms) = delete;
~MagicSearch();
MagicSearch (const std::shared_ptr<Core> &core);
MagicSearch (const MagicSearch &ms) = delete;
~MagicSearch ();
/**
* Set the minimum value used to calculate the weight in search
* @param[in] weight minimum weight
**/
void setMinWeight(const unsigned int weight);
void setMinWeight (const unsigned int weight);
/**
* @return the minimum value used to calculate the weight in search
**/
unsigned int getMinWeight() const;
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);
void setMaxWeight (const unsigned int weight);
/**
* @return the maximum value used to calculate the weight in search
**/
unsigned int getMaxWeight() const;
unsigned int getMaxWeight () const;
/**
* @return the delimiter used to find matched filter word
**/
const std::string& getDelimiter() const;
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);
void setDelimiter (const std::string &delimiter);
/**
* @return if the delimiter search is used
**/
bool getUseDelimiter() const;
bool getUseDelimiter () const;
/**
* Enable or disable the delimiter in search
* @param[in] enable
**/
void setUseDelimiter(bool enable);
void setUseDelimiter (bool enable);
/**
* @return the number of the maximum SearchResult which will be return
**/
unsigned int getSearchLimit() const;
unsigned int getSearchLimit () const;
/**
* Set the number of the maximum SearchResult which will be return
* @param[in] limit
**/
void setSearchLimit(const unsigned int limit);
void setSearchLimit (const unsigned int limit);
/**
* @return if the search is limited
**/
bool getLimitedSearch() const;
bool getLimitedSearch () const;
/**
* Enable or disable the limited search
* @param[in] limited
**/
void setLimitedSearch(const bool limited);
void setLimitedSearch (const bool limited);
/**
* Reset the cache to begin a new search
**/
void resetSearchCache();
void resetSearchCache () const;
/**
* Create a sorted list of SearchResult from SipUri, Contact name,
......@@ -123,7 +123,7 @@ public:
* - "yourdomain" for searching in contact from "yourdomain" domain
* @return sorted list of SearchResult with "filter" or an empty list if "filter" is empty
**/
std::list<SearchResult> getContactListFromFilter(const std::string &filter, const std::string &withDomain = "");
std::list<SearchResult> getContactListFromFilter (const std::string &filter, const std::string &withDomain = "") const;
private:
......@@ -131,14 +131,14 @@ private:
* @return the cache of precedent result
* @private
**/
std::list<SearchResult> *getSearchCache() const;
std::list<SearchResult> *getSearchCache () const;
/**
* Save a result for future search
* @param[in] cache result we want to save
* @private
**/
void setSearchCache(std::list<SearchResult> *cache);
void setSearchCache (std::list<SearchResult> *cache) const;
/**
* Get all address from call log
......@@ -148,7 +148,11 @@ private:
* @return all address from call log which match in a SearchResult list
* @private
**/
std::list<SearchResult> getAddressFromCallLog(const std::string &filter, const std::string &withDomain, const std::list<SearchResult> &currentList);
std::list<SearchResult> getAddressFromCallLog (
const std::string &filter,
const std::string &withDomain,
const std::list<SearchResult> &currentList
) const;
/**
* Get all friends as SearchResult
......@@ -156,7 +160,7 @@ private:
* @return all friends in a SearchResult list
* @private
**/
std::list<SearchResult> getFriends(const std::string &withDomain);
std::list<SearchResult> getFriends (const std::string &withDomain) const;
/**
* Begin the search from friend list
......@@ -164,7 +168,7 @@ private:
* @param[in] withDomain domain which we want to search only
* @private
**/
std::list<SearchResult> *beginNewSearch(const std::string &filter, const std::string &withDomain);
std::list<SearchResult> *beginNewSearch (const std::string &filter, const std::string &withDomain) const;
/**
* Continue the search from the cache of precedent search
......@@ -172,7 +176,7 @@ private:
* @param[in] withDomain domain which we want to search only
* @private
**/
std::list<SearchResult> *continueSearch(const std::string &filter, const std::string &withDomain);
std::list<SearchResult> *continueSearch (const std::string &filter, const std::string &withDomain) const;
/**
* Search informations in friend given
......@@ -182,7 +186,7 @@ private:
* @return list of result from friend
* @private
**/
std::list<SearchResult> searchInFriend(const LinphoneFriend* lFriend, const std::string &filter, const std::string &withDomain);
std::list<SearchResult> searchInFriend (const LinphoneFriend* lFriend, const std::string &filter, const std::string &withDomain) const;
/**
* Search informations in address given
......@@ -191,7 +195,7 @@ private:
* @param[in] withDomain domain which we want to search only
* @private
**/
unsigned int searchInAddress(const LinphoneAddress *lAddress, const std::string &filter, const std::string &withDomain);
unsigned int searchInAddress (const LinphoneAddress *lAddress, const std::string &filter, const std::string &withDomain) const;
/**
* Return a weight for a searched in with a filter
......@@ -200,7 +204,7 @@ private:
* @return calculate weight
* @private
**/
unsigned int getWeight(const std::string &stringWords, const std::string &filter) const;
unsigned int getWeight (const std::string &stringWords, const std::string &filter) const;
/**
* Return if the given address match domain policy
......@@ -209,11 +213,11 @@ private:
* @param[in] withDomain domain policy
* @private
**/
bool checkDomain(const LinphoneFriend* lFriend, const LinphoneAddress *lAddress, const std::string &withDomain) const;
bool checkDomain (const LinphoneFriend* lFriend, const LinphoneAddress *lAddress, const std::string &withDomain) const;
void addResultsToResultsList(std::list<SearchResult> &results, std::list<SearchResult> &srL);
void addResultsToResultsList (std::list<SearchResult> &results, std::list<SearchResult> &srL) const;
std::list<SearchResult> *uniqueItemsList(std::list<SearchResult> &list);
std::list<SearchResult> *uniqueItemsList (std::list<SearchResult> &list) const;
L_DECLARE_PRIVATE(MagicSearch);
};
......
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