From b47a179309e59b95ac62c5f21fa080d29a024998 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Thu, 31 Oct 2013 17:34:58 +0100 Subject: [PATCH] add linphone_core_find_friend() --- coreapi/friend.c | 42 ++++++++++++---------------------------- coreapi/linphonefriend.h | 9 +++++++++ 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index 22a2a24c2..c8417e22c 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -516,40 +516,22 @@ const char *linphone_friend_get_ref_key(const LinphoneFriend *lf){ return lf->refkey; } -static bool_t username_match(const char *u1, const char *u2){ - if (u1==NULL && u2==NULL) return TRUE; - if (u1 && u2 && strcasecmp(u1,u2)==0) return TRUE; - return FALSE; +LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc, const LinphoneAddress *addr){ + LinphoneFriend *lf=NULL; + MSList *elem; + for(elem=lc->friends;elem!=NULL;elem=ms_list_next(elem)){ + lf=(LinphoneFriend*)elem->data; + if (linphone_address_weak_equal(lf->uri,addr)) + break; + lf=NULL; + } + return lf; } LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri){ LinphoneAddress *puri=linphone_address_new(uri); - const MSList *elem; - const char *username; - const char *domain; - const char *it_username; - const char *it_host; - LinphoneFriend *lf=NULL; - - if (puri==NULL){ - return NULL; - } - username=linphone_address_get_username(puri); - domain=linphone_address_get_domain(puri); - if (domain==NULL) { - linphone_address_destroy(puri); - return NULL; - } - for(elem=lc->friends;elem!=NULL;elem=ms_list_next(elem)){ - lf=(LinphoneFriend*)elem->data; - it_username=linphone_address_get_username(lf->uri); - it_host=linphone_address_get_domain(lf->uri);; - if (strcasecmp(domain,it_host)==0 && username_match(username,it_username)){ - break; - } - lf=NULL; - } - linphone_address_destroy(puri); + LinphoneFriend *lf=puri ? linphone_core_find_friend(lc,puri) : NULL; + if (puri) linphone_address_unref(puri); return lf; } diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index 101c9f62f..66fbcea8e 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -372,9 +372,18 @@ LINPHONE_PUBLIC void linphone_core_notify_all_friends(LinphoneCore *lc, Linphone * @param[in] lc #LinphoneCore object. * @param[in] addr The address to use to search the friend. * @returns The #LinphoneFriend object corresponding to the given address. + * @deprecated use linphone_core_find_friend() instead. */ LINPHONE_PUBLIC LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *addr); +/** + * Search a LinphoneFriend by its address. + * @param[in] lc #LinphoneCore object. + * @param[in] addr The address to use to search the friend. + * @returns The #LinphoneFriend object corresponding to the given address. + */ +LINPHONE_PUBLIC LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc, const LinphoneAddress *addr); + /** * Search a LinphoneFriend by its reference key. * @param[in] lc #LinphoneCore object.