diff --git a/coreapi/friend.c b/coreapi/friend.c index c71b729d7..16bf62912 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -88,10 +88,10 @@ const char *linphone_online_status_to_string(LinphoneOnlineStatus ss){ 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; + const bctbx_list_t *addressesa = linphone_friend_get_addresses(lfa); + const bctbx_list_t *addressesb = linphone_friend_get_addresses(lfb); + bctbx_list_t *iteratora = (bctbx_list_t *)addressesa; + bctbx_list_t *iteratorb = (bctbx_list_t *)addressesb; int ret = 1; while (iteratora && (ret == 1)) { @@ -104,13 +104,6 @@ static int friend_compare(const void * a, const void * b) { 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; } @@ -319,21 +312,15 @@ void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr } } -bctbx_list_t* linphone_friend_get_addresses(const LinphoneFriend *lf) { +const bctbx_list_t* linphone_friend_get_addresses(const LinphoneFriend *lf) { if (!lf) return NULL; if (linphone_core_vcard_supported()) { - bctbx_list_t *result = NULL; const bctbx_list_t * addresses = linphone_vcard_get_sip_addresses(lf->vcard); - while (addresses) { - LinphoneAddress *addr = (LinphoneAddress *)addresses->data; - result = bctbx_list_append(result, linphone_address_clone(addr)); - addresses = bctbx_list_next(addresses); - } - return result; + return addresses; } else { bctbx_list_t *addresses = NULL; - return lf->uri ? bctbx_list_append(addresses, linphone_address_clone(lf->uri)) : NULL; + return lf->uri ? bctbx_list_append(addresses, lf->uri) : NULL; } } @@ -608,18 +595,17 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){ const LinphonePresenceModel * linphone_friend_get_presence_model(const LinphoneFriend *lf) { const LinphonePresenceModel *presence = NULL; LinphoneFriend* fuckconst = (LinphoneFriend*)lf; - bctbx_list_t* addrs = linphone_friend_get_addresses(fuckconst); + const bctbx_list_t* addrs = linphone_friend_get_addresses(fuckconst); bctbx_list_t* phones = NULL; bctbx_list_t *it; - for (it = addrs; it!= NULL; it = it->next) { + for (it = (bctbx_list_t *)addrs; it!= NULL; it = it->next) { LinphoneAddress *addr = (LinphoneAddress*)it->data; char *uri = linphone_address_as_string_uri_only(addr); presence = linphone_friend_get_presence_model_for_uri_or_tel(fuckconst, uri); ms_free(uri); if (presence) break; } - bctbx_list_free_with_data(addrs, (bctbx_list_free_func) linphone_address_unref); if (presence) return presence; phones = linphone_friend_get_phone_numbers(fuckconst); diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index d0542dd13..9db5c74e0 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -108,9 +108,9 @@ static bctbx_list_t * uri_list(const LinphoneFriendList *list) { 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); + const bctbx_list_t *addresses = linphone_friend_get_addresses(lf); bctbx_list_t *numbers = linphone_friend_get_phone_numbers(lf); - iterator = addresses; + iterator = (bctbx_list_t *)addresses; while (iterator) { LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(iterator); if (addr) { @@ -134,7 +134,6 @@ static bctbx_list_t * uri_list(const LinphoneFriendList *list) { } iterator = bctbx_list_next(iterator); } - if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref); } return uri_list; } @@ -307,7 +306,7 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList if (resource_object != NULL) xmlXPathFreeObject(resource_object); if (full_state == TRUE) { - bctbx_list_t *addresses; + const bctbx_list_t *addresses; bctbx_list_t *numbers; bctbx_list_t *iterator; bctbx_list_t *l = list->friends; @@ -315,7 +314,7 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList lf = (LinphoneFriend *)bctbx_list_get_data(l); addresses = linphone_friend_get_addresses(lf); numbers = linphone_friend_get_phone_numbers(lf); - iterator = addresses; + iterator = (bctbx_list_t *)addresses; while (iterator) { LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(iterator); char *uri = linphone_address_as_string_uri_only(addr); @@ -324,7 +323,6 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList ms_free(uri); iterator = bctbx_list_next(iterator); } - if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref); iterator = numbers; while (iterator) { const char *number = (const char *)bctbx_list_get_data(iterator); @@ -687,14 +685,13 @@ LinphoneFriend * linphone_friend_list_find_friend_by_address(const LinphoneFrien iterator = bctbx_list_next(iterator); } } else { - bctbx_list_t *addresses = linphone_friend_get_addresses(lf); - iterator = addresses; + const bctbx_list_t *addresses = linphone_friend_get_addresses(lf); + iterator = (bctbx_list_t *)addresses; 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); } - bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref); } } return result; diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index 1ea323ea9..af6f995d8 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -177,7 +177,7 @@ LINPHONE_PUBLIC void linphone_friend_add_address(LinphoneFriend *lf, const Linph * @param lf #LinphoneFriend object * @return \mslist{LinphoneAddress} */ -LINPHONE_PUBLIC bctbx_list_t* linphone_friend_get_addresses(const LinphoneFriend *lf); +LINPHONE_PUBLIC const bctbx_list_t* linphone_friend_get_addresses(const LinphoneFriend *lf); /** * Removes an address in this friend diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index ef37989bd..fdd7b6c19 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -145,13 +145,12 @@ static void linphone_vcard_phone_numbers_and_sip_addresses(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nIMPP;TYPE=home:sip:sylvain@sip.linphone.org\r\nTEL;TYPE=work:0952636505\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); - bctbx_list_t *sip_addresses = linphone_friend_get_addresses(lf); + const bctbx_list_t *sip_addresses = linphone_friend_get_addresses(lf); bctbx_list_t *phone_numbers = linphone_friend_get_phone_numbers(lf); LinphoneAddress *addr = NULL; BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 2, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 1, unsigned int, "%u"); - if (sip_addresses) bctbx_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref); if (phone_numbers) bctbx_list_free(phone_numbers); linphone_friend_unref(lf); @@ -163,14 +162,12 @@ static void linphone_vcard_phone_numbers_and_sip_addresses(void) { BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 0, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 2, unsigned int, "%u"); - if (sip_addresses) bctbx_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref); if (phone_numbers) bctbx_list_free(phone_numbers); addr = linphone_address_new("sip:sylvain@sip.linphone.org"); linphone_friend_add_address(lf, addr); sip_addresses = linphone_friend_get_addresses(lf); BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 1, unsigned int, "%u"); - if (sip_addresses) bctbx_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref); linphone_friend_remove_phone_number(lf, "0952636505"); phone_numbers = linphone_friend_get_phone_numbers(lf); @@ -187,7 +184,6 @@ static void linphone_vcard_phone_numbers_and_sip_addresses(void) { linphone_friend_done(lf); sip_addresses = linphone_friend_get_addresses(lf); BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 0, unsigned int, "%u"); - if (sip_addresses) bctbx_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref); linphone_friend_add_phone_number(lf, "+33952636505"); phone_numbers = linphone_friend_get_phone_numbers(lf);