Commit e2ead014 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added method to remove friend from rc file

parent 1a87b91e
......@@ -214,6 +214,7 @@ LinphoneFriend * linphone_friend_new(void){
obj->subscribe = TRUE;
obj->vcard = NULL;
obj->storage_id = 0;
obj->rc_index = -1;
return obj;
}
......@@ -1072,11 +1073,6 @@ LinphoneSubscribePolicy __policy_str_to_enum(const char* pol){
return LinphoneSPWait;
}
LinphoneProxyConfig *__index_to_proxy(LinphoneCore *lc, int index){
if (index>=0) return (LinphoneProxyConfig*)bctbx_list_nth_data(lc->sip_conf.proxies,index);
else return NULL;
}
LinphoneFriend * linphone_friend_new_from_config_file(LinphoneCore *lc, int index){
const char *tmp;
char item[50];
......@@ -1107,25 +1103,36 @@ LinphoneFriend * linphone_friend_new_from_config_file(LinphoneCore *lc, int inde
linphone_friend_send_subscribe(lf,!!a);
a = lp_config_get_int(config, item, "presence_received", 0);
lf->presence_received = (bool_t)a;
lf->rc_index = index;
linphone_friend_set_ref_key(lf,lp_config_get_string(config,item,"refkey",NULL));
return lf;
}
const char *__policy_enum_to_str(LinphoneSubscribePolicy pol){
switch(pol){
case LinphoneSPAccept:
return "accept";
break;
case LinphoneSPDeny:
return "deny";
break;
case LinphoneSPWait:
return "wait";
break;
int linphone_friend_get_rc_index(const LinphoneFriend *lf) {
return lf->rc_index;
}
void linphone_friend_remove(LinphoneFriend *lf) {
if (!lf) return;
if (lf->friend_list) {
linphone_friend_list_remove_friend(lf->friend_list, lf);
}
if (lf->rc_index >= 0) {
LinphoneCore *lc = lf->lc;
if (lc) {
LinphoneConfig *config = linphone_core_get_config(lc);
if (config) {
char section[50];
sprintf(section, "friend_%i", lf->rc_index);
linphone_config_clean_section(config, section);
linphone_config_sync(config);
lf->rc_index = -1;
}
}
}
ms_warning("Invalid policy enum value.");
return "wait";
}
LinphoneCore *linphone_friend_get_core(const LinphoneFriend *fr){
......
......@@ -32,7 +32,21 @@
using namespace LinphonePrivate;
extern const char *__policy_enum_to_str(LinphoneSubscribePolicy pol);
const char *__policy_enum_to_str(LinphoneSubscribePolicy pol){
switch(pol){
case LinphoneSPAccept:
return "accept";
break;
case LinphoneSPDeny:
return "deny";
break;
case LinphoneSPWait:
return "wait";
break;
}
ms_warning("Invalid policy enum value.");
return "wait";
}
struct _LinphonePresenceNote {
belle_sip_object_t base;
......
......@@ -263,7 +263,6 @@ LINPHONE_PUBLIC bool_t _linphone_call_stats_rtcp_received_via_mux (const Linphon
bool_t linphone_core_media_description_contains_video_stream(const SalMediaDescription *md);
void linphone_core_send_initial_subscribes(LinphoneCore *lc);
LinphoneFriend * linphone_friend_new_from_config_file(struct _LinphoneCore *lc, int index);
void linphone_proxy_config_update(LinphoneProxyConfig *cfg);
LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri);
......@@ -455,6 +454,8 @@ void linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy);
void linphone_core_create_im_notif_policy(LinphoneCore *lc);
LINPHONE_PUBLIC LinphoneFriend * linphone_friend_new_from_config_file(LinphoneCore *lc, int index);
LINPHONE_PUBLIC int linphone_friend_get_rc_index(const LinphoneFriend *lf);
/*****************************************************************************
* REMOTE PROVISIONING FUNCTIONS *
......
......@@ -179,6 +179,7 @@ struct _LinphoneFriend{
LinphoneFriendList *friend_list;
LinphoneSubscriptionState out_sub_state;
int capabilities;
int rc_index;
};
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneFriend);
......
......@@ -379,6 +379,12 @@ LINPHONE_PUBLIC bool_t linphone_friend_has_capability_with_version_or_more(const
*/
LINPHONE_PUBLIC float linphone_friend_get_capability_version(const LinphoneFriend *lf, const LinphoneFriendCapability capability);
/**
* Removes a friend from it's friend list and from the rc if exists
* @param[in] lf #LinphoneFriend object to delete
*/
LINPHONE_PUBLIC void linphone_friend_remove(LinphoneFriend *lf);
/**
* @}
*/
......
......@@ -23,6 +23,7 @@
#include "linphone/friend.h"
#include "linphone/friendlist.h"
#include "linphone/lpconfig.h"
#include "linphone/friend.h"
#include "linphone/api/c-magic-search.h"
#include "tester_utils.h"
......@@ -1537,6 +1538,56 @@ static void echo_canceller_check(void){
linphone_core_manager_destroy(manager);
}
extern LinphoneFriend * linphone_friend_new_from_config_file(LinphoneCore *lc, int index);
extern int linphone_friend_get_rc_index(const LinphoneFriend *lf);
static void delete_friend_from_rc(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE);
LinphoneCore *core = manager->lc;
LinphoneConfig *config = linphone_core_get_config(core);
LinphoneFriendList *friend_list = linphone_core_get_default_friend_list(core);
const bctbx_list_t *friends = linphone_friend_list_get_friends(friend_list);
LinphoneFriend *francois = NULL;
BC_ASSERT_PTR_NOT_NULL(friends);
if (friends) {
BC_ASSERT_EQUAL(bctbx_list_size(friends), 3, int, "%i");
bctbx_list_t *it = NULL;
int index = 2;
for (it = (bctbx_list_t *)friends; it != NULL; it = bctbx_list_next(it)) {
LinphoneFriend *friend = (LinphoneFriend *) bctbx_list_get_data(it);
BC_ASSERT_EQUAL(linphone_friend_get_rc_index(friend), index, int, "%i");
if (index == 1) {
francois = linphone_friend_ref(friend);
}
index -= 1;
}
}
LinphoneFriend *friend = linphone_friend_new_with_address("sip:pauline@sip.linphone.org");
BC_ASSERT_EQUAL(linphone_friend_get_rc_index(friend), -1, int, "%i");
linphone_friend_list_add_friend(friend_list, friend);
BC_ASSERT_EQUAL(bctbx_list_size(linphone_friend_list_get_friends(friend_list)), 4, int, "%i");
BC_ASSERT_EQUAL(linphone_friend_get_rc_index(friend), -1, int, "%i");
linphone_friend_list_remove_friend(friend_list, friend);
BC_ASSERT_EQUAL(bctbx_list_size(linphone_friend_list_get_friends(friend_list)), 3, int, "%i");
BC_ASSERT_EQUAL(linphone_friend_get_rc_index(friend), -1, int, "%i");
linphone_friend_unref(friend);
BC_ASSERT_PTR_NOT_NULL(francois);
if (francois) {
linphone_friend_remove(francois);
BC_ASSERT_PTR_NULL(linphone_friend_get_friend_list(francois));
const char *section = "friend_1";
BC_ASSERT_EQUAL(linphone_config_has_section(config, section), 0, int, "%i");
BC_ASSERT_PTR_NULL(linphone_friend_new_from_config_file(core, 1));
BC_ASSERT_EQUAL(bctbx_list_size(linphone_friend_list_get_friends(friend_list)), 2, int, "%i");
linphone_friend_unref(francois);
}
linphone_core_manager_destroy(manager);
}
static void dial_plan(void) {
bctbx_list_t *dial_plans = linphone_dial_plan_get_all_list();
bctbx_list_t *it;
......@@ -1598,6 +1649,7 @@ test_t setup_tests[] = {
TEST_ONE_TAG("Search friend in large friends database", search_friend_large_database, "MagicSearch"),
TEST_ONE_TAG("Search friend result has capabilities", search_friend_get_capabilities, "MagicSearch"),
TEST_ONE_TAG("Search friend result chat room remote", search_friend_chat_room_remote, "MagicSearch"),
TEST_NO_TAG("Delete friend in linphone rc", delete_friend_from_rc),
TEST_NO_TAG("Dialplan", dial_plan)
};
......
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