Commit 0492c91b authored by Ghislain MARY's avatar Ghislain MARY

No longer rely on the uri field of LinphoneFriend being set (use...

No longer rely on the uri field of LinphoneFriend being set (use linphone_friend_get_address() instead).
parent 8be730ac
......@@ -1829,7 +1829,7 @@ linphonec_proxy_use(LinphoneCore *lc, int index)
static void
linphonec_friend_display(LinphoneFriend *fr)
{
LinphoneAddress *uri=linphone_address_clone(linphone_friend_get_address(fr));
LinphoneAddress *uri=linphone_friend_get_address(fr);
char *str;
linphonec_out("name: %s\n", linphone_address_get_display_name(uri));
......@@ -1853,9 +1853,15 @@ linphonec_friend_list(LinphoneCore *lc, char *pat)
for(n=0; friend!=NULL; friend=bctbx_list_next(friend), ++n )
{
if ( pat ) {
const char *name = linphone_address_get_display_name(
linphone_friend_get_address((LinphoneFriend*)friend->data));
if (name && ! strstr(name, pat) ) continue;
LinphoneAddress *addr = linphone_friend_get_address((LinphoneFriend*)friend->data);
if (addr) {
const char *name = linphone_address_get_display_name(addr);
if (name && ! strstr(name, pat) ) {
linphone_address_unref(addr);
continue;
}
linphone_address_unref(addr);
}
}
linphonec_out("****** Friend %i *******\n",n);
linphonec_friend_display((LinphoneFriend*)friend->data);
......@@ -1869,16 +1875,18 @@ linphonec_friend_call(LinphoneCore *lc, unsigned int num)
{
const bctbx_list_t *friend = linphone_core_get_friend_list(lc);
unsigned int n;
char *addr;
char *addr_str;
for(n=0; friend!=NULL; friend=bctbx_list_next(friend), ++n )
{
if ( n == num )
{
int ret;
addr = linphone_address_as_string(linphone_friend_get_address((LinphoneFriend*)friend->data));
ret=lpc_cmd_call(lc, addr);
ms_free(addr);
LinphoneAddress *addr = linphone_friend_get_address((LinphoneFriend*)friend->data);
addr_str = linphone_address_as_string(addr);
ret=lpc_cmd_call(lc, addr_str);
ms_free(addr_str);
linphone_address_unref(addr);
return ret;
}
}
......
......@@ -291,9 +291,13 @@ linphonec_transfer_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneC
static void
linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid)
{
char *tmp=linphone_address_as_string(linphone_friend_get_address(fid));
printf("Friend %s is %s\n", tmp, linphone_online_status_to_string(linphone_friend_get_status(fid)));
ms_free(tmp);
LinphoneAddress *addr = linphone_friend_get_address(fid);
if (addr) {
char *tmp=linphone_address_as_string(addr);
printf("Friend %s is %s\n", tmp, linphone_online_status_to_string(linphone_friend_get_status(fid)));
ms_free(tmp);
linphone_address_unref(addr);
}
// todo: update Friend list state (unimplemented)
}
......
......@@ -22,17 +22,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
LinphoneCardDavContext* linphone_carddav_context_new(LinphoneFriendList *lfl) {
LinphoneCardDavContext *carddav_context = NULL;
if (!linphone_core_vcard_supported()) {
ms_error("[carddav] vCard isn't available (maybe it wasn't compiled), can't do CardDAV sync");
return NULL;
}
if (!lfl || !lfl->uri) {
return NULL;
}
#ifdef VCARD_ENABLED
carddav_context = (LinphoneCardDavContext *)ms_new0(LinphoneCardDavContext, 1);
carddav_context->friend_list = linphone_friend_list_ref(lfl);
#else
ms_error("[carddav] vCard isn't available (maybe it wasn't compiled), can't do CardDAV sync");
#endif
return carddav_context;
}
......
......@@ -85,11 +85,33 @@ const char *linphone_online_status_to_string(LinphoneOnlineStatus ss){
return str;
}
static int friend_compare(const void * a, const void * b){
LinphoneAddress *fa=((LinphoneFriend*)a)->uri;
LinphoneAddress *fb=((LinphoneFriend*)b)->uri;
if (linphone_address_weak_equal(fa,fb)) return 0;
return 1;
static int friend_compare(const void * a, const void * b) {
LinphoneFriend *lfa = (LinphoneFriend *)a;
LinphoneFriend *lfb = (LinphoneFriend *)b;
bctbx_list_t *addressesa = linphone_friend_get_addresses(lfa);
bctbx_list_t *addressesb = linphone_friend_get_addresses(lfb);
bctbx_list_t *iteratora = addressesa;
bctbx_list_t *iteratorb = addressesb;
int ret = 1;
while (iteratora && (ret == 1)) {
LinphoneAddress *fa = (LinphoneAddress *)bctbx_list_get_data(iteratora);
while (iteratorb && (ret == 1)) {
LinphoneAddress *fb = (LinphoneAddress *)bctbx_list_get_data(iteratorb);
if (linphone_address_weak_equal(fa, fb)) ret = 0;
iteratorb = bctbx_list_next(iteratorb);
}
iteratora = bctbx_list_next(iteratora);
}
if (addressesa) {
bctbx_list_free_with_data(addressesa, (bctbx_list_free_func)linphone_address_unref);
}
if (addressesb) {
bctbx_list_free_with_data(addressesb, (bctbx_list_free_func)linphone_address_unref);
}
return ret;
}
......@@ -97,14 +119,16 @@ bctbx_list_t *linphone_find_friend_by_address(bctbx_list_t *fl, const LinphoneAd
bctbx_list_t *res=NULL;
LinphoneFriend dummy;
if (lf!=NULL) *lf=NULL;
memset(&dummy, 0, sizeof(LinphoneFriend));
dummy.uri=(LinphoneAddress*)addr;
res=bctbx_list_find_custom(fl,friend_compare,&dummy);
if (lf!=NULL && res!=NULL) *lf=(LinphoneFriend*)res->data;
if (lf!=NULL && res!=NULL) *lf=(LinphoneFriend*)bctbx_list_get_data(res);
return res;
}
void __linphone_friend_do_subscribe(LinphoneFriend *fr){
LinphoneCore *lc=fr->lc;
LinphoneAddress *addr = linphone_friend_get_address(fr);
if (fr->outsub==NULL){
/* people for which we don't have yet an answer should appear as offline */
......@@ -118,9 +142,10 @@ void __linphone_friend_do_subscribe(LinphoneFriend *fr){
fr->outsub=NULL;
}
fr->outsub=sal_op_new(lc->sal);
linphone_configure_op(lc,fr->outsub,fr->uri,NULL,TRUE);
linphone_configure_op(lc,fr->outsub,addr,NULL,TRUE);
sal_subscribe_presence(fr->outsub,NULL,NULL,lp_config_get_int(lc->config,"sip","subscribe_expires",600));
fr->subscribe_active=TRUE;
linphone_address_unref(addr);
}
LinphoneFriend * linphone_friend_new(void){
......@@ -206,7 +231,7 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char
}
}
const LinphoneAddress *linphone_friend_get_address(const LinphoneFriend *lf) {
LinphoneAddress * linphone_friend_get_address(const LinphoneFriend *lf) {
if (linphone_core_vcard_supported()) {
if (lf->vcard) {
bctbx_list_t *sip_addresses = linphone_vcard_get_sip_addresses(lf->vcard);
......@@ -216,7 +241,9 @@ const LinphoneAddress *linphone_friend_get_address(const LinphoneFriend *lf) {
}
}
return NULL;
} else return lf->uri;
}
if (lf->uri) return linphone_address_clone(lf->uri);
return NULL;
}
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){
......@@ -273,7 +300,7 @@ bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) {
sip_addresses = linphone_vcard_get_sip_addresses(lf->vcard);
iterator = sip_addresses;
while (iterator) {
const char *sip_address = (const char *)iterator->data;
const char *sip_address = (const char *)bctbx_list_get_data(iterator);
LinphoneAddress *addr = linphone_address_new(sip_address);
if (addr) {
addresses = bctbx_list_append(addresses, addr);
......@@ -352,12 +379,16 @@ int linphone_friend_set_inc_subscribe_policy(LinphoneFriend *fr, LinphoneSubscri
void linphone_friend_notify(LinphoneFriend *lf, LinphonePresenceModel *presence){
bctbx_list_t *elem;
if (lf->insubs){
char *addr=linphone_address_as_string(linphone_friend_get_address(lf));
ms_message("Want to notify %s",addr);
ms_free(addr);
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) {
char *addr_str = linphone_address_as_string(addr);
ms_message("Want to notify %s", addr_str);
ms_free(addr_str);
linphone_address_unref(addr);
}
}
for(elem=lf->insubs; elem!=NULL; elem=elem->next){
SalOp *op = (SalOp*)elem->data;
for(elem=lf->insubs; elem!=NULL; elem=bctbx_list_next(elem)){
SalOp *op = (SalOp*)bctbx_list_get_data(elem);
sal_notify_presence(op,(SalPresenceModel *)presence);
}
}
......@@ -467,10 +498,13 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){
online_status = (basic_status == LinphonePresenceBasicStatusOpen) ? LinphoneStatusOnline : LinphoneStatusOffline;
if (nb_activities > 1) {
char *tmp = NULL;
const LinphoneAddress *addr = linphone_friend_get_address(lf);
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) tmp = linphone_address_as_string(addr);
ms_warning("Friend %s has several activities, get status from the first one", tmp ? tmp : "unknown");
if (tmp) ms_free(tmp);
if (tmp) {
ms_free(tmp);
linphone_address_unref(addr);
}
nb_activities = 1;
}
if (nb_activities == 1) {
......@@ -571,15 +605,17 @@ void linphone_friend_update_subscribes(LinphoneFriend *fr, LinphoneProxyConfig *
int can_subscribe=1;
if (only_when_registered && (fr->subscribe || fr->subscribe_active)){
LinphoneProxyConfig *cfg=linphone_core_lookup_known_proxy(fr->lc,fr->uri);
LinphoneAddress *addr = linphone_friend_get_address(fr);
LinphoneProxyConfig *cfg=linphone_core_lookup_known_proxy(fr->lc, addr);
if (proxy && proxy!=cfg) return;
if (cfg && cfg->state!=LinphoneRegistrationOk){
char *tmp=linphone_address_as_string(fr->uri);
char *tmp=linphone_address_as_string(addr);
ms_message("Friend [%s] belongs to proxy config with identity [%s], but this one isn't registered. Subscription is suspended.",
tmp,linphone_proxy_config_get_identity(cfg));
ms_free(tmp);
can_subscribe=0;
}
linphone_address_unref(addr);
}
if (can_subscribe && fr->subscribe && fr->subscribe_active==FALSE){
ms_message("Sending a new SUBSCRIBE");
......@@ -607,11 +643,13 @@ void linphone_friend_save(LinphoneFriend *fr, LinphoneCore *lc) {
void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc) {
LinphonePresenceModel *model;
LinphoneAddress *addr = linphone_friend_get_address(fr);
if (!fr->uri) {
if (!addr) {
ms_warning("No sip url defined.");
return;
}
linphone_address_unref(addr);
if (!linphone_core_ready(lc)) {
/* lc not ready, deffering subscription */
fr->commit=TRUE;
......@@ -707,7 +745,7 @@ void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend *lf) {
void linphone_core_update_friends_subscriptions(LinphoneCore *lc, LinphoneProxyConfig *cfg, bool_t only_when_registered) {
bctbx_list_t *lists = lc->friends_lists;
while (lists) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
linphone_friend_list_update_subscriptions(list, cfg, only_when_registered);
lists = bctbx_list_next(lists);
}
......@@ -726,14 +764,14 @@ void linphone_core_send_initial_subscribes(LinphoneCore *lc) {
if (lc->initial_subscribes_sent) return;
lc->initial_subscribes_sent=TRUE;
while (lists) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
if (list->rls_uri != NULL) {
rls_address = linphone_core_create_address(lc, list->rls_uri);
if (rls_address != NULL) {
const char *rls_domain = linphone_address_get_domain(rls_address);
if (rls_domain != NULL) {
for (elem = linphone_core_get_proxy_config_list(lc); elem != NULL; elem = elem->next) {
LinphoneProxyConfig *cfg = (LinphoneProxyConfig *)elem->data;
for (elem = linphone_core_get_proxy_config_list(lc); elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneProxyConfig *cfg = (LinphoneProxyConfig *)bctbx_list_get_data(elem);
const char *proxy_domain = linphone_proxy_config_get_domain(cfg);
if (strcmp(rls_domain, proxy_domain) == 0) {
proxy_config_for_rls_presence_uri_domain = TRUE;
......@@ -756,7 +794,7 @@ void linphone_core_send_initial_subscribes(LinphoneCore *lc) {
void linphone_core_invalidate_friend_subscriptions(LinphoneCore *lc) {
bctbx_list_t *lists = lc->friends_lists;
while (lists) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
linphone_friend_list_invalidate_subscriptions(list);
lists = bctbx_list_next(lists);
}
......@@ -784,7 +822,7 @@ LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc, const Linphone
bctbx_list_t *lists = lc->friends_lists;
LinphoneFriend *lf = NULL;
while (lists && !lf) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
lf = linphone_friend_list_find_friend_by_address(list, addr);
lists = bctbx_list_next(lists);
}
......@@ -795,7 +833,7 @@ LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, cons
bctbx_list_t *lists = lc->friends_lists;
LinphoneFriend *lf = NULL;
while (lists && !lf) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
lf = linphone_friend_list_find_friend_by_uri(list, uri);
lists = bctbx_list_next(lists);
}
......@@ -806,7 +844,7 @@ LinphoneFriend *linphone_core_get_friend_by_ref_key(const LinphoneCore *lc, cons
bctbx_list_t *lists = lc->friends_lists;
LinphoneFriend *lf = NULL;
while (lists && !lf) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
lf = linphone_friend_list_find_friend_by_ref_key(list, key);
lists = bctbx_list_next(lists);
}
......@@ -817,7 +855,7 @@ LinphoneFriend *linphone_core_find_friend_by_out_subscribe(const LinphoneCore *l
bctbx_list_t *lists = lc->friends_lists;
LinphoneFriend *lf = NULL;
while (lists && !lf) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
lf = linphone_friend_list_find_friend_by_out_subscribe(list, op);
lists = bctbx_list_next(lists);
}
......@@ -828,7 +866,7 @@ LinphoneFriend *linphone_core_find_friend_by_inc_subscribe(const LinphoneCore *l
bctbx_list_t *lists = lc->friends_lists;
LinphoneFriend *lf = NULL;
while (lists && !lf) {
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(lists);
lf = linphone_friend_list_find_friend_by_inc_subscribe(list, op);
lists = bctbx_list_next(lists);
}
......@@ -945,7 +983,7 @@ void linphone_core_write_friends_config(LinphoneCore* lc) {
store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1);
if (store_friends) {
for (elem=linphone_core_get_default_friend_list(lc)->friends,i=0; elem!=NULL; elem=bctbx_list_next(elem),i++){
linphone_friend_write_to_config_file(lc->config,(LinphoneFriend*)elem->data,i);
linphone_friend_write_to_config_file(lc->config,(LinphoneFriend*)bctbx_list_get_data(elem),i);
}
linphone_friend_write_to_config_file(lc->config,NULL,i); /* set the end */
}
......@@ -1123,7 +1161,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
lc->friends_lists = NULL;
while (friends_lists) {
LinphoneFriendList *list = (LinphoneFriendList *)friends_lists->data;
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(friends_lists);
linphone_core_add_friend_list(lc, list);
friends_lists = bctbx_list_next(friends_lists);
}
......@@ -1251,7 +1289,8 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
char *buf;
int store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1);
LinphoneVcard *vcard = NULL;
char *address = NULL;
LinphoneAddress *addr;
char *addr_str = NULL;
if (!store_friends) {
return;
......@@ -1268,11 +1307,12 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
}
if (linphone_core_vcard_supported()) vcard = linphone_friend_get_vcard(lf);
address = linphone_address_as_string(linphone_friend_get_address(lf));
addr = linphone_friend_get_address(lf);
addr_str = linphone_address_as_string(addr);
if (lf->storage_id > 0) {
buf = sqlite3_mprintf("UPDATE friends SET friend_list_id=%u,sip_uri=%Q,subscribe_policy=%i,send_subscribe=%i,ref_key=%Q,vCard=%Q,vCard_etag=%Q,vCard_url=%Q,presence_received=%i WHERE (id = %u);",
lf->friend_list->storage_id,
address,
addr_str,
lf->pol,
lf->subscribe,
lf->refkey,
......@@ -1285,7 +1325,7 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
} else {
buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%u,%Q,%i,%i,%Q,%Q,%Q,%Q,%i);",
lf->friend_list->storage_id,
address,
addr_str,
lf->pol,
lf->subscribe,
lf->refkey,
......@@ -1295,7 +1335,8 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
lf->presence_received
);
}
ms_free(address);
ms_free(addr_str);
linphone_address_unref(addr);
linphone_sql_request_generic(lc->friends_db, buf);
sqlite3_free(buf);
......@@ -1392,8 +1433,8 @@ bctbx_list_t* linphone_core_fetch_friends_from_db(LinphoneCore *lc, LinphoneFrie
ms_message("%s(): %u results fetched, completed in %i ms",__FUNCTION__, (unsigned int)bctbx_list_size(result), (int)(end-begin));
sqlite3_free(buf);
for(elem = result; elem != NULL; elem = elem->next) {
LinphoneFriend *lf = (LinphoneFriend *)elem->data;
for(elem = result; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem);
lf->lc = lc;
lf->friend_list = list;
}
......@@ -1421,8 +1462,8 @@ bctbx_list_t* linphone_core_fetch_friends_lists_from_db(LinphoneCore *lc) {
ms_message("%s(): %u results fetched, completed in %i ms",__FUNCTION__, (unsigned int)bctbx_list_size(result), (int)(end-begin));
sqlite3_free(buf);
for(elem = result; elem != NULL; elem = elem->next) {
LinphoneFriendList *lfl = (LinphoneFriendList *)elem->data;
for(elem = result; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriendList *lfl = (LinphoneFriendList *)bctbx_list_get_data(elem);
lfl->lc = lc;
lfl->friends = linphone_core_fetch_friends_from_db(lc, lfl);
}
......@@ -1506,7 +1547,7 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) {
for (i = 0; (lf = linphone_friend_new_from_config_file(lc, i)) != NULL; i++) {
char friend_section[32];
const LinphoneAddress *addr = linphone_friend_get_address(lf);
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) {
char *address = NULL;
const char *displayName = linphone_address_get_display_name(addr);
......@@ -1529,6 +1570,7 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) {
snprintf(friend_section, sizeof(friend_section), "friend_%i", i);
lp_config_clean_section(lpc, friend_section);
linphone_address_unref(addr);
}
}
......
......@@ -88,6 +88,20 @@ void linphone_friend_list_cbs_set_sync_status_changed(LinphoneFriendListCbs *cbs
cbs->sync_state_changed_cb = cb;
}
static int add_uri_entry(xmlTextWriterPtr writer, int err, const char *uri) {
if (err >= 0) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry");
}
if (err >= 0) {
err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri);
}
if (err >= 0) {
/* Close the "entry" element. */
err = xmlTextWriterEndElement(writer);
}
return err;
}
static char * create_resource_list_xml(const LinphoneFriendList *list) {
char *xml_content = NULL;
bctbx_list_t *elem;
......@@ -121,20 +135,38 @@ static char * create_resource_list_xml(const LinphoneFriendList *list) {
if (err>= 0) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"list");
}
for (elem = list->friends; elem != NULL; elem = elem->next) {
LinphoneFriend *lf = (LinphoneFriend *)elem->data;
char *uri = linphone_address_as_string_uri_only(lf->uri);
if (err >= 0) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry");
}
if (err >= 0) {
err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri);
for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem);
bctbx_list_t *iterator;
bctbx_list_t *addresses = linphone_friend_get_addresses(lf);
bctbx_list_t *numbers = linphone_friend_get_phone_numbers(lf);
LinphoneProxyConfig *proxy_config = linphone_core_get_default_proxy_config(linphone_friend_list_get_core(list));
iterator = addresses;
while (iterator) {
LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(iterator);
if (addr) {
char *uri = linphone_address_as_string_uri_only(addr);
if (uri) {
err = add_uri_entry(writer, err, uri);
ms_free(uri);
}
}
iterator = bctbx_list_next(iterator);
}
if (err >= 0) {
/* Close the "entry" element. */
err = xmlTextWriterEndElement(writer);
iterator = numbers;
while (iterator) {
const char *number = (const char *)bctbx_list_get_data(iterator);
char *normalized_number = linphone_proxy_config_normalize_phone_number(proxy_config, number);
if (normalized_number) {
char *uri = ms_strdup_printf("%s;user=phone", normalized_number);
err = add_uri_entry(writer, err, uri);
ms_free(uri);
ms_free(normalized_number);
}
iterator = bctbx_list_next(iterator);
}
if (uri) ms_free(uri);
if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
if (numbers) bctbx_list_free_with_data(numbers, (bctbx_list_free_func)ms_free);
}
if (err >= 0) {
/* Close the "list" element. */
......@@ -197,8 +229,8 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
}
if ((strcmp(full_state_str, "true") == 0) || (strcmp(full_state_str, "1") == 0)) {
bctbx_list_t *l = list->friends;
for (; l != NULL; l = l->next) {
lf = (LinphoneFriend *)l->data;
for (; l != NULL; l = bctbx_list_next(l)) {
lf = (LinphoneFriend *)bctbx_list_get_data(l);
linphone_friend_set_presence_model(lf, NULL);
}
full_state = TRUE;
......@@ -254,8 +286,8 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
if (full_state == TRUE) {
bctbx_list_t *l = list->friends;
for (; l != NULL; l = l->next) {
lf = (LinphoneFriend *)l->data;
for (; l != NULL; l = bctbx_list_next(l)) {
lf = (LinphoneFriend *)bctbx_list_get_data(l);
if (linphone_friend_is_presence_received(lf) == TRUE) {
linphone_core_notify_notify_presence_received(list->lc, lf);
}
......@@ -272,8 +304,8 @@ end:
static bool_t linphone_friend_list_has_subscribe_inactive(const LinphoneFriendList *list) {
bctbx_list_t *l = list->friends;
bool_t has_subscribe_inactive = FALSE;
for (; l != NULL; l = l->next) {
LinphoneFriend *lf = (LinphoneFriend *)l->data;
for (; l != NULL; l = bctbx_list_next(l)) {
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(l);
if (lf->subscribe_active != TRUE) {
has_subscribe_inactive = TRUE;
break;
......@@ -390,22 +422,27 @@ void linphone_friend_list_set_rls_uri(LinphoneFriendList *list, const char *rls_
static LinphoneFriendListStatus _linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *lf, bool_t synchronize) {
LinphoneFriendListStatus status = LinphoneFriendListInvalidFriend;
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (!list || !lf->uri || lf->friend_list) {
if (!list || !addr || lf->friend_list) {
if (!list)
ms_error("linphone_friend_list_add_friend(): invalid list, null");
if (!lf->uri)
if (!addr)
ms_error("linphone_friend_list_add_friend(): invalid friend, no sip uri");
if (lf->friend_list)
ms_error("linphone_friend_list_add_friend(): invalid friend, already in list");
if (addr) linphone_address_unref(addr);
return status;
}
if (bctbx_list_find(list->friends, lf) != NULL) {
char *tmp = NULL;
const LinphoneAddress *addr = linphone_friend_get_address(lf);
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) tmp = linphone_address_as_string(addr);
ms_warning("Friend %s already in list [%s], ignored.", tmp ? tmp : "unknown", list->display_name);
if (tmp) ms_free(tmp);
if (tmp) {
ms_free(tmp);
linphone_address_unref(addr);
}
} else {
status = linphone_friend_list_import_friend(list, lf, synchronize);
linphone_friend_save(lf, lf->lc);
......@@ -426,11 +463,13 @@ LinphoneFriendListStatus linphone_friend_list_add_local_friend(LinphoneFriendLis
}
LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList *list, LinphoneFriend *lf, bool_t synchronize) {
if (!lf->uri || lf->friend_list) {
if (!lf->uri)
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (!addr || lf->friend_list) {
if (!addr)
ms_error("linphone_friend_list_add_friend(): invalid friend, no sip uri");
if (lf->friend_list)
ms_error("linphone_friend_list_add_friend(): invalid friend, already in list");
if (addr) linphone_address_unref(addr);
return LinphoneFriendListInvalidFriend;
}
lf->friend_list = list;
......@@ -495,7 +534,7 @@ void linphone_friend_list_update_dirty_friends(LinphoneFriendList *list) {
while (dirty_friends) {
LinphoneCardDavContext *cdc = linphone_carddav_context_new(list);
if (cdc) {
LinphoneFriend *lf = (LinphoneFriend *)dirty_friends->data;
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(dirty_friends);
cdc->sync_done_cb = carddav_done;
if (lf) {
if (cdc->friend_list->cbs->sync_state_changed_cb) {
......@@ -568,13 +607,21 @@ void linphone_friend_list_synchronize_friends_from_server(LinphoneFriendList *li
LinphoneFriend * linphone_friend_list_find_friend_by_address(const LinphoneFriendList *list, const LinphoneAddress *address) {
LinphoneFriend *lf = NULL;
LinphoneFriend *result = NULL;
const bctbx_list_t *elem;
for (elem = list->friends; elem != NULL; elem = elem->next) {
lf = (LinphoneFriend *)elem->data;
if (linphone_address_weak_equal(lf->uri, address))
return lf;
for (elem = list->friends; (elem != NULL) && (result == NULL); elem = bctbx_list_next(elem)) {
bctbx_list_t *addresses;
bctbx_list_t *iterator;