Commit b47a1793 authored by Simon Morlat's avatar Simon Morlat

add linphone_core_find_friend()

parent 23bca78e
......@@ -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_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 *linphone_core_find_friend(const LinphoneCore *lc, const LinphoneAddress *addr){
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;
}
MSList *elem;
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)){
if (linphone_address_weak_equal(lf->uri,addr))
break;
}
lf=NULL;
}
linphone_address_destroy(puri);
return lf;
}
LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri){
LinphoneAddress *puri=linphone_address_new(uri);
LinphoneFriend *lf=puri ? linphone_core_find_friend(lc,puri) : NULL;
if (puri) linphone_address_unref(puri);
return lf;
}
......
......@@ -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.
......
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