From 0492c91ba14fe6435e267df2db18e7335a554767 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 25 Jul 2016 17:35:04 +0200 Subject: [PATCH] No longer rely on the uri field of LinphoneFriend being set (use linphone_friend_get_address() instead). --- console/commands.c | 24 +++-- console/linphonec.c | 10 ++- coreapi/carddav.c | 12 +-- coreapi/friend.c | 126 +++++++++++++++++--------- coreapi/friendlist.c | 172 +++++++++++++++++++++++------------- coreapi/friendlist.h | 2 +- coreapi/help/buddy_status.c | 6 +- coreapi/linphonefriend.h | 2 +- coreapi/presence.c | 9 +- coreapi/vcard_stubs.c | 8 +- gtk/calllogs.c | 4 +- gtk/friendlist.c | 64 ++++++++------ gtk/main.c | 3 +- tester/presence_tester.c | 9 +- tester/vcard_tester.c | 14 ++- 15 files changed, 300 insertions(+), 165 deletions(-) diff --git a/console/commands.c b/console/commands.c index 81e4d5121..61ea2ec11 100644 --- a/console/commands.c +++ b/console/commands.c @@ -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; } } diff --git a/console/linphonec.c b/console/linphonec.c index 8b8f87f26..0de61a36b 100644 --- a/console/linphonec.c +++ b/console/linphonec.c @@ -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) } diff --git a/coreapi/carddav.c b/coreapi/carddav.c index 39c4574cc..b07bb60ba 100644 --- a/coreapi/carddav.c +++ b/coreapi/carddav.c @@ -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; } diff --git a/coreapi/friend.c b/coreapi/friend.c index 86dfd9279..fb0b6588c 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -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); } } diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index e9e99c9d9..7baf0fe81 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -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"); + 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) { - err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri); + 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 (err >= 0) { - /* Close the "entry" element. */ - err = xmlTextWriterEndElement(writer); - } - 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; + lf = (LinphoneFriend *)bctbx_list_get_data(elem); + iterator = addresses = linphone_friend_get_addresses(lf); + while (iterator && (result == NULL)) { + LinphoneAddress *lfaddr = (LinphoneAddress *)bctbx_list_get_data(iterator); + if (linphone_address_weak_equal(lfaddr, address)) + result = lf; + iterator = bctbx_list_next(iterator); + } } - return NULL; + return result; } LinphoneFriend * linphone_friend_list_find_friend_by_uri(const LinphoneFriendList *list, const char *uri) { @@ -587,8 +634,8 @@ LinphoneFriend * linphone_friend_list_find_friend_by_uri(const LinphoneFriendLis LinphoneFriend * linphone_friend_list_find_friend_by_ref_key(const LinphoneFriendList *list, const char *ref_key) { const bctbx_list_t *elem; if (ref_key == NULL) return NULL; - for (elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); if ((lf->refkey != NULL) && (strcmp(lf->refkey, ref_key) == 0)) return lf; } return NULL; @@ -596,8 +643,8 @@ LinphoneFriend * linphone_friend_list_find_friend_by_ref_key(const LinphoneFrien LinphoneFriend * linphone_friend_list_find_friend_by_inc_subscribe(const LinphoneFriendList *list, SalOp *op) { const bctbx_list_t *elem; - for (elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); if (bctbx_list_find(lf->insubs, op)) return lf; } return NULL; @@ -605,8 +652,8 @@ LinphoneFriend * linphone_friend_list_find_friend_by_inc_subscribe(const Linphon LinphoneFriend * linphone_friend_list_find_friend_by_out_subscribe(const LinphoneFriendList *list, SalOp *op) { const bctbx_list_t *elem; - for (elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); if (lf->outsub && ((lf->outsub == op) || sal_op_is_forked_of(lf->outsub, op))) return lf; } return NULL; @@ -671,8 +718,8 @@ void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, Linphon ms_message("Friends list [%p] subscription update skipped since subscriptions not enabled yet", list); } } else if (list->enable_subscriptions) { - for (elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); linphone_friend_update_subscribes(lf, cfg, only_when_registered); } } @@ -680,16 +727,16 @@ void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, Linphon void linphone_friend_list_invalidate_subscriptions(LinphoneFriendList *list) { const bctbx_list_t *elem; - for (elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); linphone_friend_invalidate_subscription(lf); } } void linphone_friend_list_notify_presence(LinphoneFriendList *list, LinphonePresenceModel *presence) { const bctbx_list_t *elem; - for(elem = list->friends; elem != NULL; elem = elem->next) { - LinphoneFriend *lf = (LinphoneFriend *)elem->data; + for(elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); linphone_friend_notify(lf, presence); } } @@ -763,7 +810,7 @@ void linphone_friend_list_subscription_state_changed(LinphoneCore *lc, LinphoneE } } -LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list) { +LinphoneCore* linphone_friend_list_get_core(const LinphoneFriendList *list) { return list->lc; } @@ -772,10 +819,10 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis bctbx_list_t *vcards_iterator = NULL; int count = 0; -#ifndef VCARD_ENABLED - ms_error("vCard support wasn't enabled at compilation time"); - return -1; -#endif + if (!linphone_core_vcard_supported()) { + ms_error("vCard support wasn't enabled at compilation time"); + return -1; + } if (!list) { ms_error("Can't import into a NULL list"); return -1; @@ -788,8 +835,8 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis return -1; } - while (vcards_iterator != NULL && vcards_iterator->data != NULL) { - LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data; + while (vcards_iterator != NULL && bctbx_list_get_data(vcards_iterator) != NULL) { + LinphoneVcard *vcard = (LinphoneVcard *)bctbx_list_get_data(vcards_iterator); LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { @@ -811,10 +858,10 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l bctbx_list_t *vcards_iterator = NULL; int count = 0; -#ifndef VCARD_ENABLED - ms_error("vCard support wasn't enabled at compilation time"); - return -1; -#endif + if (!linphone_core_vcard_supported()) { + ms_error("vCard support wasn't enabled at compilation time"); + return -1; + } if (!list) { ms_error("Can't import into a NULL list"); return -1; @@ -827,8 +874,8 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l return -1; } - while (vcards_iterator != NULL && vcards_iterator->data != NULL) { - LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data; + while (vcards_iterator != NULL && bctbx_list_get_data(vcards_iterator) != NULL) { + LinphoneVcard *vcard = (LinphoneVcard *)bctbx_list_get_data(vcards_iterator); LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { @@ -847,7 +894,12 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file) { FILE *file = NULL; - const bctbx_list_t *friends = linphone_friend_list_get_friends(list); + const bctbx_list_t *friends; + + if (!linphone_core_vcard_supported()) { + ms_error("vCard support wasn't enabled at compilation time"); + return; + } file = fopen(vcard_file, "wb"); if (file == NULL) { @@ -855,11 +907,9 @@ void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list return; } -#ifndef VCARD_ENABLED - ms_error("vCard support wasn't enabled at compilation time"); -#endif - while (friends != NULL && friends->data != NULL) { - LinphoneFriend *lf = (LinphoneFriend *)friends->data; + friends = linphone_friend_list_get_friends(list); + while (friends != NULL && bctbx_list_get_data(friends) != NULL) { + LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(friends); LinphoneVcard *vcard = linphone_friend_get_vcard(lf); if (vcard) { const char *vcard_text = linphone_vcard_as_vcard4_string(vcard); diff --git a/coreapi/friendlist.h b/coreapi/friendlist.h index 3dbe44805..a798928c2 100644 --- a/coreapi/friendlist.h +++ b/coreapi/friendlist.h @@ -381,7 +381,7 @@ void linphone_friend_list_update_dirty_friends(LinphoneFriendList *list); * @param[in] list LinphoneFriendList object. * @return a LinphoneCore object */ -LINPHONE_PUBLIC LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list); +LINPHONE_PUBLIC LinphoneCore* linphone_friend_list_get_core(const LinphoneFriendList *list); /** * Creates and adds LinphoneFriend objects to LinphoneFriendList from a file that contains the vCard(s) to parse diff --git a/coreapi/help/buddy_status.c b/coreapi/help/buddy_status.c index 58f75bd1a..03e44e728 100644 --- a/coreapi/help/buddy_status.c +++ b/coreapi/help/buddy_status.c @@ -52,17 +52,19 @@ static void stop(int signum){ */ static void notify_presence_recv_updated (LinphoneCore *lc, LinphoneFriend *friend) { const LinphonePresenceModel* model = linphone_friend_get_presence_model(friend); - const LinphoneAddress* friend_address = linphone_friend_get_address(friend); + LinphoneAddress* friend_address = linphone_friend_get_address(friend); LinphonePresenceActivity *activity = linphone_presence_model_get_activity(model); char *activity_str = linphone_presence_activity_to_string(activity); printf("New state state [%s] for user id [%s] \n" ,activity_str ,linphone_address_as_string (friend_address)); + linphone_address_unref(friend_address); } static void new_subscription_requested (LinphoneCore *lc, LinphoneFriend *friend, const char* url) { - const LinphoneAddress* friend_address = linphone_friend_get_address(friend); + LinphoneAddress* friend_address = linphone_friend_get_address(friend); printf(" [%s] wants to see your status, accepting\n" ,linphone_address_as_string (friend_address)); + linphone_address_unref(friend_address); linphone_friend_edit(friend); /* start editing friend */ linphone_friend_set_inc_subscribe_policy(friend,LinphoneSPAccept); /* Accept incoming subscription request for this friend*/ linphone_friend_done(friend); /*commit change*/ diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index f4e8618d8..3c3483c71 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -162,7 +162,7 @@ LINPHONE_PUBLIC int linphone_friend_set_address(LinphoneFriend *fr, const Linpho * @param lf #LinphoneFriend object * @return #LinphoneAddress */ -LINPHONE_PUBLIC const LinphoneAddress *linphone_friend_get_address(const LinphoneFriend *lf); +LINPHONE_PUBLIC LinphoneAddress * linphone_friend_get_address(const LinphoneFriend *lf); /** * Adds an address in this friend diff --git a/coreapi/presence.c b/coreapi/presence.c index f2083e2c6..a92ff06cc 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -1471,6 +1471,7 @@ static LinphonePresenceModel * process_pidf_xml_presence_notification(xmlparsing void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalOp *op){ LinphoneFriend *fl=linphone_core_create_friend_with_address(lc,subscriber); + LinphoneAddress *addr; char *tmp; if (fl==NULL) return ; @@ -1481,10 +1482,11 @@ void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalO /* the newly created "not yet" friend ownership is transfered to the lc->subscribers list*/ lc->subscribers=bctbx_list_append(lc->subscribers,fl); - tmp = linphone_address_as_string(fl->uri); + addr = linphone_friend_get_address(fl); + tmp = linphone_address_as_string(addr); linphone_core_notify_new_subscription_requested(lc,fl,tmp); ms_free(tmp); - + linphone_address_unref(addr); } void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf){ @@ -1905,7 +1907,7 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa if (lf!=NULL){ LinphonePresenceActivity *activity = NULL; char *activity_str; - friend=lf->uri; + friend=linphone_friend_get_address(lf); tmp=linphone_address_as_string(friend); activity = linphone_presence_model_get_activity(presence); activity_str = linphone_presence_activity_to_string(activity); @@ -1916,6 +1918,7 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa lf->presence_received = TRUE; lf->out_sub_state = linphone_subscription_state_from_sal(ss); linphone_core_notify_notify_presence_received(lc,(LinphoneFriend*)lf); + linphone_address_unref(friend); ms_free(tmp); if (op != lf->outsub){ /*case of a NOTIFY received out of any dialog*/ diff --git a/coreapi/vcard_stubs.c b/coreapi/vcard_stubs.c index 255deae8f..3d20ca2d6 100644 --- a/coreapi/vcard_stubs.c +++ b/coreapi/vcard_stubs.c @@ -54,11 +54,11 @@ LinphoneVcard* linphone_vcard_new(void) { void linphone_vcard_free(LinphoneVcard *vCard) { } -MSList* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *filename) { +bctbx_list_t* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *filename) { return NULL; } -MSList* linphone_vcard_context_get_vcard_list_from_buffer(LinphoneVcardContext *context, const char *buffer) { +bctbx_list_t* linphone_vcard_context_get_vcard_list_from_buffer(LinphoneVcardContext *context, const char *buffer) { return NULL; } @@ -100,7 +100,7 @@ void linphone_vcard_remove_sip_address(LinphoneVcard *vCard, const char *sip_add void linphone_vcard_edit_main_sip_address(LinphoneVcard *vCard, const char *sip_address) { } -MSList* linphone_vcard_get_sip_addresses(const LinphoneVcard *vCard) { +bctbx_list_t* linphone_vcard_get_sip_addresses(const LinphoneVcard *vCard) { return NULL; } @@ -110,7 +110,7 @@ void linphone_vcard_add_phone_number(LinphoneVcard *vCard, const char *phone) { void linphone_vcard_remove_phone_number(LinphoneVcard *vCard, const char *phone) { } -MSList* linphone_vcard_get_phone_numbers(const LinphoneVcard *vCard) { +bctbx_list_t* linphone_vcard_get_phone_numbers(const LinphoneVcard *vCard) { return NULL; } diff --git a/gtk/calllogs.c b/gtk/calllogs.c index 9f81ac875..53b752cac 100644 --- a/gtk/calllogs.c +++ b/gtk/calllogs.c @@ -316,10 +316,12 @@ void linphone_gtk_call_log_update(GtkWidget *w){ #endif lf=linphone_core_get_friend_by_address(linphone_gtk_get_core(),addr); if(lf != NULL){ - if ((display=linphone_address_get_display_name(linphone_friend_get_address(lf)))) { + LinphoneAddress *address = linphone_friend_get_address(lf); + if ((display=linphone_address_get_display_name(address))) { /*update display name from friend*/ linphone_address_set_display_name(la,display); } + linphone_address_unref(address); } else { display=linphone_address_get_display_name(la); } diff --git a/gtk/friendlist.c b/gtk/friendlist.c index d4a06f79b..64eef2536 100644 --- a/gtk/friendlist.c +++ b/gtk/friendlist.c @@ -89,11 +89,13 @@ static void linphone_gtk_set_selection_to_uri_bar(GtkTreeView *treeview){ LinphoneFriend *lf=NULL; gchar* friend; select = gtk_tree_view_get_selection (treeview); - if (gtk_tree_selection_get_selected (select, &model, &iter)) - { + if (gtk_tree_selection_get_selected (select, &model, &iter)) { + LinphoneAddress *addr; gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1); - friend=linphone_address_as_string(linphone_friend_get_address(lf)); + addr = linphone_friend_get_address(lf); + friend=linphone_address_as_string(addr); gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),friend); + linphone_address_unref(addr); ms_free(friend); } } @@ -175,11 +177,12 @@ gboolean linphone_gtk_on_key_press(GtkWidget *widget, GdkEvent *event, gpointer LinphoneChatRoom *cr; do{ if (index == key) { - const LinphoneAddress *uri; + LinphoneAddress *addr; gtk_tree_model_get (model, &iter,FRIEND_CHATROOM , &cr, -1); gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1); - uri = linphone_friend_get_address(lf); - if (lf != NULL) linphone_gtk_friend_list_set_chat_conversation(uri); + addr = linphone_friend_get_address(lf); + if (lf != NULL) linphone_gtk_friend_list_set_chat_conversation(addr); + linphone_address_unref(addr); if (cr != NULL){ linphone_gtk_mark_chat_read(cr); linphone_gtk_friend_list_update_button_display(GTK_TREE_VIEW(friendlist)); @@ -214,7 +217,7 @@ void linphone_gtk_delete_history(GtkWidget *button){ linphone_chat_room_delete_history(cr); if(chat_view!=NULL){ const LinphoneAddress *from=linphone_gtk_friend_list_get_active_address(); - const LinphoneAddress *addr=linphone_friend_get_address(lf); + LinphoneAddress *addr=linphone_friend_get_address(lf); if(linphone_address_weak_equal(from,addr)){ GtkTextView *text_view=GTK_TEXT_VIEW(linphone_gtk_get_widget(chat_view,"textview")); GtkTextIter start; @@ -226,6 +229,7 @@ void linphone_gtk_delete_history(GtkWidget *button){ gtk_text_buffer_delete (text_buffer, &start, &end); g_object_set_data(G_OBJECT(chat_view),"from_message",NULL); } + linphone_address_unref(addr); } linphone_gtk_show_friends(); } @@ -327,19 +331,20 @@ void linphone_gtk_friend_list_set_chat_conversation(const LinphoneAddress *la){ store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist))); if (gtk_tree_model_get_iter_first(model,&iter)) { do{ - const LinphoneAddress *uri; + LinphoneAddress *addr; gtk_tree_model_get(model, &iter,FRIEND_ID , &lf, -1); - uri=linphone_friend_get_address(lf); - if (linphone_address_weak_equal(uri,la)){ + addr=linphone_friend_get_address(lf); + if (linphone_address_weak_equal(addr,la)){ gtk_tree_model_get (model, &iter,FRIEND_CHATROOM , &cr, -1); if(cr==NULL){ - cr=linphone_gtk_create_chatroom(uri); + cr=linphone_gtk_create_chatroom(addr); gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1); } - linphone_gtk_friend_list_set_active_address(uri); + linphone_gtk_friend_list_set_active_address(addr); gtk_tree_selection_select_iter(selection, &iter); break; } + linphone_address_unref(addr); }while(gtk_tree_model_iter_next(model,&iter)); } } @@ -388,22 +393,23 @@ void linphone_gtk_chat_selected(GtkWidget *item){ store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(item))); if (gtk_tree_selection_get_selected (select, &model, &iter)){ GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(w,"viewswitch"); - const LinphoneAddress *uri; + LinphoneAddress *addr; gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1); gtk_tree_model_get (model, &iter,FRIEND_CHATROOM , &cr, -1); - uri=linphone_friend_get_address(lf); + addr=linphone_friend_get_address(lf); if(cr==NULL){ - cr=linphone_gtk_create_chatroom(uri); + cr=linphone_gtk_create_chatroom(addr); gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1); } page=GTK_WIDGET(g_object_get_data(G_OBJECT(friendlist),"chatview")); - linphone_gtk_friend_list_set_active_address(uri); + linphone_gtk_friend_list_set_active_address(addr); if(page==NULL){ - page=linphone_gtk_init_chatroom(cr,uri); + page=linphone_gtk_init_chatroom(cr,addr); g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)page); } else { - linphone_gtk_load_chatroom(cr,uri,page); + linphone_gtk_load_chatroom(cr,addr,page); } + linphone_address_unref(addr); linphone_gtk_mark_chat_read(cr); gtk_notebook_set_current_page(notebook,gtk_notebook_page_num(notebook,page)); g_idle_add((GSourceFunc)grab_focus,linphone_gtk_get_widget(page,"text_entry")); @@ -589,8 +595,10 @@ void linphone_gtk_friend_list_on_name_column_clicked(GtkTreeModel *model){ static int get_friend_weight(const LinphoneFriend *lf){ int w=0; LinphoneCore *lc=linphone_gtk_get_core(); - LinphoneChatRoom *cr=linphone_core_get_chat_room(lc,linphone_friend_get_address(lf)); + LinphoneAddress *addr = linphone_friend_get_address(lf); + LinphoneChatRoom *cr=linphone_core_get_chat_room(lc, addr); + linphone_address_unref(addr); if (cr && linphone_chat_room_get_unread_messages_count(cr)>0){ w+=2000; } @@ -616,7 +624,7 @@ static int friend_compare_func(const LinphoneFriend *lf1, const LinphoneFriend * w2=get_friend_weight(lf2); if (w1==w2){ const char *u1,*u2; - const LinphoneAddress *addr1,*addr2; + LinphoneAddress *addr1,*addr2; addr1=linphone_friend_get_address(lf1); addr2=linphone_friend_get_address(lf2); u1=linphone_address_get_display_name(addr1) ? linphone_address_get_display_name(addr1) : linphone_address_get_username(addr1); @@ -628,6 +636,8 @@ static int friend_compare_func(const LinphoneFriend *lf1, const LinphoneFriend * } else { ret = -1; } + linphone_address_unref(addr1); + linphone_address_unref(addr2); } else { ret = w2-w1; } @@ -749,8 +759,8 @@ void linphone_gtk_show_friends(void){ for(itf=sorted;itf!=NULL;itf=bctbx_list_next(itf)){ LinphoneFriend *lf=(LinphoneFriend*)itf->data; - const LinphoneAddress *f_uri=linphone_friend_get_address(lf); - char *uri=linphone_address_as_string(f_uri); + LinphoneAddress *f_addr=linphone_friend_get_address(lf); + char *uri=linphone_address_as_string(f_addr); const char *name=linphone_friend_get_name(lf); const char *display=name; char *escaped=NULL; @@ -759,14 +769,14 @@ void linphone_gtk_show_friends(void){ //BuddyInfo *bi; gboolean send_subscribe=linphone_friend_get_send_subscribe(lf); if (display==NULL || display[0]=='\0') { - display=linphone_address_get_username(f_uri); + display=linphone_address_get_username(f_addr); } gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter,FRIEND_NAME, display,FRIEND_ID,lf, FRIEND_PRESENCE_IMG, send_subscribe ? status_to_icon_name(linphone_friend_get_status(lf)) : NULL, FRIEND_CHAT,"linphone-chat-nothing", -1); - cr=linphone_gtk_create_chatroom(f_uri); + cr=linphone_gtk_create_chatroom(f_addr); gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1); nbmsg=linphone_chat_room_get_unread_messages_count(cr); if(nbmsg != 0){ @@ -776,6 +786,7 @@ void linphone_gtk_show_friends(void){ escaped=g_markup_escape_text(uri,-1); gtk_list_store_set(store,&iter,FRIEND_SIP_ADDRESS,escaped,-1); g_free(escaped); + linphone_address_unref(f_addr); ms_free(uri); } bctbx_list_free(sorted); @@ -785,13 +796,14 @@ void linphone_gtk_show_contact(LinphoneFriend *lf, GtkWidget *parent){ GtkWidget *w = linphone_gtk_create_window("contact", parent); char *uri; const char *name = linphone_friend_get_name(lf); - const LinphoneAddress *f_uri = linphone_friend_get_address(lf); + LinphoneAddress *f_addr = linphone_friend_get_address(lf); - uri=linphone_address_as_string_uri_only(f_uri); + uri=linphone_address_as_string_uri_only(f_addr); if (uri) { gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"sip_address")),uri); ms_free(uri); } + linphone_address_unref(f_addr); if (name){ gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"name")),name); diff --git a/gtk/main.c b/gtk/main.c index 581314e5b..9503b68a0 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -677,7 +677,7 @@ void on_contact_provider_search_results( LinphoneContactSearch* req, bctbx_list_ while( friends ){ LinphoneFriend* lf = friends->data; if( lf ) { - const LinphoneAddress* la = linphone_friend_get_address(lf); + LinphoneAddress* la = linphone_friend_get_address(lf); if( la ){ char *addr = linphone_address_as_string(la); @@ -688,6 +688,7 @@ void on_contact_provider_search_results( LinphoneContactSearch* req, bctbx_list_ 1, COMPLETION_LDAP, -1); ms_free(addr); } + linphone_address_unref(la); } } friends = friends->next; diff --git a/tester/presence_tester.c b/tester/presence_tester.c index 042dff08f..edcd2c39f 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -37,9 +37,11 @@ static LinphoneCoreManager* presence_linphone_core_manager_new(char* username) { void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url){ - char* from=linphone_address_as_string(linphone_friend_get_address(lf)); + LinphoneAddress *addr = linphone_friend_get_address(lf); + char* from=linphone_address_as_string(addr); stats* counters; ms_message("New subscription request from [%s] url [%s]",from,url); + linphone_address_unref(addr); ms_free(from); counters = get_stats(lc); counters->number_of_NewSubscriptionRequest++; @@ -48,10 +50,11 @@ void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { stats* counters; - unsigned int i; - char* from=linphone_address_as_string(linphone_friend_get_address(lf)); + LinphoneAddress *addr = linphone_friend_get_address(lf); + char* from=linphone_address_as_string(addr); ms_message("New Notify request from [%s] ",from); + linphone_address_unref(addr); ms_free(from); counters = get_stats(lc); counters->number_of_NotifyPresenceReceived++; diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 790244f19..4c1dac4c5 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -276,6 +276,7 @@ static void friends_sqlite_storage(void) { bctbx_list_t *friends_lists_from_db = NULL; char *friends_db = bc_tester_file("friends.db"); LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); + LinphoneAddress *laddress = NULL, *laddress2 = NULL; char *address = NULL, *address2 = NULL; v_table->friend_list_created = friend_list_created_cb; @@ -329,9 +330,13 @@ static void friends_sqlite_storage(void) { BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, unsigned int, "%u"); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf))); - address = linphone_address_as_string(linphone_friend_get_address(lf)); - address2 = linphone_address_as_string(linphone_friend_get_address(lf2)); + laddress = linphone_friend_get_address(lf); + address = linphone_address_as_string(laddress); + laddress2 = linphone_friend_get_address(lf2); + address2 = linphone_address_as_string(laddress2); BC_ASSERT_STRING_EQUAL(address2, address); + linphone_address_unref(laddress); + linphone_address_unref(laddress2); ms_free(address); ms_free(address2); @@ -583,6 +588,7 @@ static void carddav_integration(void) { LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); const char *refkey = "toto"; char *address = NULL; + LinphoneAddress *addr; linphone_friend_list_set_uri(lfl, CARDDAV_SERVER); cbs = linphone_friend_list_get_callbacks(lfl); @@ -636,9 +642,11 @@ static void carddav_integration(void) { BC_ASSERT_STRING_EQUAL(lf->refkey, refkey); BC_ASSERT_EQUAL(lf->storage_id, lf2->storage_id, unsigned int, "%u"); linphone_friend_unref(lf2); - address = linphone_address_as_string_uri_only(lf->uri); + addr = linphone_friend_get_address(lf); + address = linphone_address_as_string_uri_only(addr); BC_ASSERT_STRING_EQUAL(address, "sip:sylvain@sip.linphone.org"); ms_free(address); + linphone_address_unref(addr); linphone_friend_edit(lf); linphone_friend_done(lf);