mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 03:28:07 +00:00
Started rework of friend lists management in linphone + database storage of friend lists
This commit is contained in:
parent
6cbaaf687b
commit
bce8c3cc76
11 changed files with 507 additions and 181 deletions
|
|
@ -112,7 +112,6 @@ static void linphone_carddav_vcards_pulled(LinphoneCardDavContext *cdc, MSList *
|
|||
LinphoneFriend *lf2 = (LinphoneFriend *)local_friend->data;
|
||||
if (cdc->contact_updated_cb) {
|
||||
ms_debug("Contact updated: %s", linphone_friend_get_name(lf));
|
||||
lf2 = linphone_friend_ref(lf2);
|
||||
cdc->contact_updated_cb(cdc, lf, lf2);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -173,6 +172,7 @@ static int find_matching_vcard(LinphoneCardDavResponse *response, LinphoneFriend
|
|||
LinphoneVCard *lvc2 = linphone_friend_get_vcard(lf);
|
||||
const char *uid1 = NULL, *uid2 = NULL;
|
||||
if (!lvc1 || !lvc2) {
|
||||
if (lvc1) linphone_vcard_free(lvc1);
|
||||
return 1;
|
||||
}
|
||||
uid1 = linphone_vcard_get_uid(lvc1);
|
||||
|
|
@ -187,17 +187,15 @@ static int find_matching_vcard(LinphoneCardDavResponse *response, LinphoneFriend
|
|||
static void linphone_carddav_vcards_fetched(LinphoneCardDavContext *cdc, MSList *vCards) {
|
||||
if (vCards != NULL && ms_list_size(vCards) > 0) {
|
||||
MSList *friends = cdc->friend_list->friends;
|
||||
MSList *friends_to_remove = NULL;
|
||||
|
||||
while (friends) {
|
||||
LinphoneFriend *lf = (LinphoneFriend *)friends->data;
|
||||
if (lf) {
|
||||
MSList *vCard = ms_list_find_custom(vCards, (int (*)(const void*, const void*))find_matching_vcard, lf);
|
||||
if (!vCard) {
|
||||
ms_debug("Local friend %s isn't in the remote vCard list, delete it", linphone_friend_get_name(lf));
|
||||
if (cdc->contact_removed_cb) {
|
||||
ms_debug("Contact removed: %s", linphone_friend_get_name(lf));
|
||||
lf = linphone_friend_ref(lf);
|
||||
cdc->contact_removed_cb(cdc, lf);
|
||||
}
|
||||
ms_error("Local friend %s isn't in the remote vCard list, delete it", linphone_friend_get_name(lf));
|
||||
friends_to_remove = ms_list_append(friends_to_remove, lf);
|
||||
} else {
|
||||
LinphoneCardDavResponse *response = (LinphoneCardDavResponse *)vCard->data;
|
||||
ms_debug("Local friend %s is in the remote vCard list, check eTag", linphone_friend_get_name(lf));
|
||||
|
|
@ -213,6 +211,18 @@ static void linphone_carddav_vcards_fetched(LinphoneCardDavContext *cdc, MSList
|
|||
}
|
||||
friends = ms_list_next(friends);
|
||||
}
|
||||
while(friends_to_remove) {
|
||||
LinphoneFriend *lf = (LinphoneFriend *)friends_to_remove->data;
|
||||
if (lf) {
|
||||
if (cdc->contact_removed_cb) {
|
||||
ms_error("Contact removed: %s", linphone_friend_get_name(lf));
|
||||
cdc->contact_removed_cb(cdc, lf);
|
||||
}
|
||||
}
|
||||
friends_to_remove = ms_list_next(friends_to_remove);
|
||||
}
|
||||
friends_to_remove = ms_list_free(friends_to_remove);
|
||||
|
||||
linphone_carddav_pull_vcards(cdc, vCards);
|
||||
}
|
||||
ms_list_free(vCards);
|
||||
|
|
@ -376,7 +386,33 @@ static void process_io_error_from_carddav_request(void *data, const belle_sip_io
|
|||
}
|
||||
|
||||
static void process_auth_requested_from_carddav_request(void *data, belle_sip_auth_event_t *event) {
|
||||
//TODO //FIXME: find a way around this
|
||||
LinphoneCardDavQuery *query = (LinphoneCardDavQuery *)data;
|
||||
LinphoneCardDavContext *cdc = query->context;
|
||||
const char *realm = belle_sip_auth_event_get_realm(event);
|
||||
belle_generic_uri_t *uri = belle_generic_uri_parse(query->url);
|
||||
const char *domain = belle_generic_uri_get_host(uri);
|
||||
LinphoneCore *lc = cdc->friend_list->lc;
|
||||
const MSList *auth_infos = linphone_core_get_auth_info_list(lc);
|
||||
|
||||
ms_debug("Looking for auth info for domain %s and realm %s", domain, realm);
|
||||
while (auth_infos) {
|
||||
LinphoneAuthInfo *auth_info = (LinphoneAuthInfo *)auth_infos->data;
|
||||
if (auth_info->domain && strcmp(domain, auth_info->domain) == 0) {
|
||||
if (!auth_info->realm || strcmp(realm, auth_info->realm) == 0) {
|
||||
belle_sip_auth_event_set_username(event, auth_info->username);
|
||||
belle_sip_auth_event_set_passwd(event, auth_info->passwd);
|
||||
belle_sip_auth_event_set_ha1(event, auth_info->ha1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
auth_infos = ms_list_next(auth_infos);
|
||||
}
|
||||
|
||||
if (!auth_infos) {
|
||||
ms_error("Authentication requested during CardDAV request sending, and username/password weren't provided");
|
||||
linphone_carddav_sync_done(query->context, FALSE, "Authentication requested during CardDAV request sending, and username/password weren't provided");
|
||||
linphone_carddav_query_free(query);
|
||||
}
|
||||
}
|
||||
|
||||
static void linphone_carddav_send_query(LinphoneCardDavQuery *query) {
|
||||
|
|
|
|||
308
coreapi/friend.c
308
coreapi/friend.c
|
|
@ -521,7 +521,7 @@ void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc) {
|
|||
fr->inc_subscribe_pending = FALSE;
|
||||
}
|
||||
if (fr->lc) {
|
||||
linphone_friend_list_update_subscriptions(fr->lc->friendlist, NULL, linphone_core_should_subscribe_friends_only_when_registered(fr->lc));
|
||||
linphone_friend_list_update_subscriptions(fr->friend_list, NULL, linphone_core_should_subscribe_friends_only_when_registered(fr->lc));
|
||||
}
|
||||
ms_debug("linphone_friend_apply() done.");
|
||||
lc->bl_refresh=TRUE;
|
||||
|
|
@ -561,7 +561,7 @@ LinphoneFriend * linphone_core_create_friend_with_address(LinphoneCore *lc, cons
|
|||
}
|
||||
|
||||
void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) {
|
||||
if ((lc->friendlist == NULL) || (linphone_friend_list_add_friend(lc->friendlist, lf) != LinphoneFriendListOK)) return;
|
||||
if ((lc->friends_lists == NULL) || (linphone_friend_list_add_friend(linphone_core_get_default_friend_list(lc), lf) != LinphoneFriendListOK)) return;
|
||||
if (ms_list_find(lc->subscribers, lf)) {
|
||||
/*if this friend was in the pending subscriber list, now remove it from this list*/
|
||||
lc->subscribers = ms_list_remove(lc->subscribers, lf);
|
||||
|
|
@ -574,14 +574,19 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) {
|
|||
}
|
||||
|
||||
void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend *lf) {
|
||||
if (linphone_friend_list_remove_friend(lc->friendlist, lf) == LinphoneFriendListNonExistentFriend) {
|
||||
ms_error("linphone_core_remove_friend(): friend [%p] is not part of core's list.", lf);
|
||||
if (lf && lf->friend_list) {
|
||||
if (linphone_friend_list_remove_friend(lf->friend_list, lf) == LinphoneFriendListNonExistentFriend) {
|
||||
ms_error("linphone_core_remove_friend(): friend [%p] is not part of core's list.", lf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_core_update_friends_subscriptions(LinphoneCore *lc, LinphoneProxyConfig *cfg, bool_t only_when_registered){
|
||||
if (lc->friendlist != NULL) {
|
||||
linphone_friend_list_update_subscriptions(lc->friendlist, cfg, only_when_registered);
|
||||
void linphone_core_update_friends_subscriptions(LinphoneCore *lc, LinphoneProxyConfig *cfg, bool_t only_when_registered) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
while (lists) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
linphone_friend_list_update_subscriptions(list, cfg, only_when_registered);
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -589,40 +594,49 @@ bool_t linphone_core_should_subscribe_friends_only_when_registered(const Linphon
|
|||
return lp_config_get_int(lc->config,"sip","subscribe_presence_only_when_registered",1);
|
||||
}
|
||||
|
||||
void linphone_core_send_initial_subscribes(LinphoneCore *lc){
|
||||
void linphone_core_send_initial_subscribes(LinphoneCore *lc) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
bool_t proxy_config_for_rls_presence_uri_domain = FALSE;
|
||||
LinphoneAddress *rls_address = NULL;
|
||||
const MSList *elem;
|
||||
|
||||
if (lc->initial_subscribes_sent) return;
|
||||
lc->initial_subscribes_sent=TRUE;
|
||||
if (lc->friendlist->rls_uri != NULL) {
|
||||
rls_address = linphone_core_create_address(lc, lc->friendlist->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;
|
||||
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;
|
||||
break;
|
||||
while (lists) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
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;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
linphone_address_unref(rls_address);
|
||||
}
|
||||
if (proxy_config_for_rls_presence_uri_domain == TRUE) {
|
||||
ms_message("Presence list activated so do not send initial subscribes it will be done when registered");
|
||||
} else {
|
||||
linphone_core_update_friends_subscriptions(lc,NULL,linphone_core_should_subscribe_friends_only_when_registered(lc));
|
||||
}
|
||||
}
|
||||
linphone_address_unref(rls_address);
|
||||
}
|
||||
if (proxy_config_for_rls_presence_uri_domain == TRUE) {
|
||||
ms_message("Presence list activated so do not send initial subscribes it will be done when registered");
|
||||
} else {
|
||||
linphone_core_update_friends_subscriptions(lc,NULL,linphone_core_should_subscribe_friends_only_when_registered(lc));
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_core_invalidate_friend_subscriptions(LinphoneCore *lc){
|
||||
if (lc->friendlist != NULL)
|
||||
linphone_friend_list_invalidate_subscriptions(lc->friendlist);
|
||||
void linphone_core_invalidate_friend_subscriptions(LinphoneCore *lc) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
while (lists) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
linphone_friend_list_invalidate_subscriptions(list);
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
lc->initial_subscribes_sent=FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -643,16 +657,37 @@ const char *linphone_friend_get_ref_key(const LinphoneFriend *lf){
|
|||
return lf->refkey;
|
||||
}
|
||||
|
||||
LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc, const LinphoneAddress *addr){
|
||||
return linphone_friend_list_find_friend_by_address(lc->friendlist, addr);
|
||||
LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc, const LinphoneAddress *addr) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
LinphoneFriend *lf = NULL;
|
||||
while (lists && !lf) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
lf = linphone_friend_list_find_friend_by_address(list, addr);
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
return lf;
|
||||
}
|
||||
|
||||
LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri){
|
||||
return linphone_friend_list_find_friend_by_uri(lc->friendlist, uri);
|
||||
LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
LinphoneFriend *lf = NULL;
|
||||
while (lists && !lf) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
lf = linphone_friend_list_find_friend_by_uri(list, uri);
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
return lf;
|
||||
}
|
||||
|
||||
LinphoneFriend *linphone_core_get_friend_by_ref_key(const LinphoneCore *lc, const char *key){
|
||||
return linphone_friend_list_find_friend_by_ref_key(lc->friendlist, key);
|
||||
LinphoneFriend *linphone_core_get_friend_by_ref_key(const LinphoneCore *lc, const char *key) {
|
||||
MSList *lists = lc->friends_lists;
|
||||
LinphoneFriend *lf = NULL;
|
||||
while (lists && !lf) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lists->data;
|
||||
lf = linphone_friend_list_find_friend_by_ref_key(list, key);
|
||||
lists = ms_list_next(lists);
|
||||
}
|
||||
return lf;
|
||||
}
|
||||
|
||||
#define key_compare(s1,s2) strcmp(s1,s2)
|
||||
|
|
@ -766,7 +801,8 @@ void linphone_core_write_friends_config(LinphoneCore* lc) {
|
|||
if (! linphone_core_ready(lc)) return; /*dont write config when reading it !*/
|
||||
store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1);
|
||||
if (store_friends) {
|
||||
for (elem=lc->friendlist->friends,i=0; elem!=NULL; elem=ms_list_next(elem),i++){
|
||||
|
||||
for (elem=linphone_core_get_default_friend_list(lc)->friends,i=0; elem!=NULL; elem=ms_list_next(elem),i++){
|
||||
linphone_friend_write_to_config_file(lc->config,(LinphoneFriend*)elem->data,i);
|
||||
}
|
||||
linphone_friend_write_to_config_file(lc->config,NULL,i); /* set the end */
|
||||
|
|
@ -893,11 +929,8 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *
|
|||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(lc->friendlist, lf)) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(linphone_core_get_default_friend_list(lc), lf)) {
|
||||
lf->lc = lc;
|
||||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_store_friend_in_db(lc, lf);
|
||||
#endif
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
|
|
@ -965,6 +998,7 @@ static void linphone_create_table(sqlite3* db) {
|
|||
int ret;
|
||||
ret = sqlite3_exec(db,"CREATE TABLE IF NOT EXISTS friends ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"friend_list_id INTEGER,"
|
||||
"sip_uri TEXT NOT NULL,"
|
||||
"subscribe_policy INTEGER,"
|
||||
"send_subscribe INTEGER,"
|
||||
|
|
@ -979,6 +1013,19 @@ static void linphone_create_table(sqlite3* db) {
|
|||
ms_error("Error in creation: %s.\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
|
||||
ret = sqlite3_exec(db,"CREATE TABLE IF NOT EXISTS friends_lists ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"display_name TEXT,"
|
||||
"rls_uri TEXT,"
|
||||
"uri TEXT,"
|
||||
"revision INTEGER"
|
||||
");",
|
||||
0, 0, &errmsg);
|
||||
if (ret != SQLITE_OK) {
|
||||
ms_error("Error in creation: %s.\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void linphone_update_table(sqlite3* db) {
|
||||
|
|
@ -989,7 +1036,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
|
|||
int ret;
|
||||
const char *errmsg;
|
||||
sqlite3 *db;
|
||||
const MSList *friends = NULL;
|
||||
const MSList *friends_lists = NULL;
|
||||
|
||||
linphone_core_friends_storage_close(lc);
|
||||
|
||||
|
|
@ -1005,13 +1052,11 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
|
|||
linphone_update_table(db);
|
||||
lc->friends_db = db;
|
||||
|
||||
friends = linphone_core_fetch_friends_from_db(lc);
|
||||
while (friends && friends->data) {
|
||||
LinphoneFriend *lf = friends->data;
|
||||
linphone_core_add_friend(lc, lf);
|
||||
linphone_friend_unref(lf);
|
||||
|
||||
friends = ms_list_next(friends);
|
||||
friends_lists = linphone_core_fetch_friends_lists_from_db(lc);
|
||||
while (friends_lists) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)friends_lists->data;
|
||||
linphone_core_add_friend_list(lc, list);
|
||||
friends_lists = ms_list_next(friends_lists);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1024,14 +1069,38 @@ void linphone_core_friends_storage_close(LinphoneCore *lc) {
|
|||
|
||||
/* DB layout:
|
||||
* | 0 | storage_id
|
||||
* | 1 | sip_uri
|
||||
* | 2 | subscribe_policy
|
||||
* | 3 | send_subscribe
|
||||
* | 4 | ref_key
|
||||
* | 5 | vCard
|
||||
* | 6 | vCard eTag
|
||||
* | 7 | vCard URL
|
||||
* | 8 | presence_received
|
||||
* | 1 | display_name
|
||||
* | 2 | rls_uri
|
||||
* | 3 | uri
|
||||
* | 4 | revision
|
||||
*/
|
||||
static int create_friend_list(void *data, int argc, char **argv, char **colName) {
|
||||
MSList **list = (MSList **)data;
|
||||
unsigned int storage_id = atoi(argv[0]);
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(NULL);
|
||||
|
||||
lfl->storage_id = storage_id;
|
||||
linphone_friend_list_set_display_name(lfl, argv[1]);
|
||||
linphone_friend_list_set_rls_uri(lfl, argv[2]);
|
||||
linphone_friend_list_set_uri(lfl, argv[3]);
|
||||
lfl->revision = atoi(argv[4]);
|
||||
|
||||
*list = ms_list_append(*list, linphone_friend_list_ref(lfl));
|
||||
linphone_friend_list_unref(lfl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* DB layout:
|
||||
* | 0 | storage_id
|
||||
* | 1 | friend_list_id
|
||||
* | 2 | sip_uri
|
||||
* | 3 | subscribe_policy
|
||||
* | 4 | send_subscribe
|
||||
* | 5 | ref_key
|
||||
* | 6 | vCard
|
||||
* | 7 | vCard eTag
|
||||
* | 8 | vCard URL
|
||||
* | 9 | presence_received
|
||||
*/
|
||||
static int create_friend(void *data, int argc, char **argv, char **colName) {
|
||||
MSList **list = (MSList **)data;
|
||||
|
|
@ -1039,22 +1108,22 @@ static int create_friend(void *data, int argc, char **argv, char **colName) {
|
|||
LinphoneVCard *vcard = NULL;
|
||||
unsigned int storage_id = atoi(argv[0]);
|
||||
|
||||
vcard = linphone_vcard_new_from_vcard4_buffer(argv[5]);
|
||||
vcard = linphone_vcard_new_from_vcard4_buffer(argv[6]);
|
||||
if (vcard) {
|
||||
linphone_vcard_set_etag(vcard, argv[6]);
|
||||
linphone_vcard_set_url(vcard, argv[7]);
|
||||
linphone_vcard_set_etag(vcard, argv[7]);
|
||||
linphone_vcard_set_url(vcard, argv[8]);
|
||||
lf = linphone_friend_new_from_vcard(vcard);
|
||||
}
|
||||
if (!lf) {
|
||||
LinphoneAddress *addr = linphone_address_new(argv[1]);
|
||||
LinphoneAddress *addr = linphone_address_new(argv[2]);
|
||||
lf = linphone_friend_new();
|
||||
linphone_friend_set_address(lf, addr);
|
||||
linphone_address_unref(addr);
|
||||
}
|
||||
linphone_friend_set_inc_subscribe_policy(lf, atoi(argv[2]));
|
||||
linphone_friend_send_subscribe(lf, atoi(argv[3]));
|
||||
linphone_friend_set_ref_key(lf, ms_strdup(argv[4]));
|
||||
lf->presence_received = atoi(argv[8]);
|
||||
linphone_friend_set_inc_subscribe_policy(lf, atoi(argv[3]));
|
||||
linphone_friend_send_subscribe(lf, atoi(argv[4]));
|
||||
linphone_friend_set_ref_key(lf, ms_strdup(argv[5]));
|
||||
lf->presence_received = atoi(argv[9]);
|
||||
lf->storage_id = storage_id;
|
||||
|
||||
*list = ms_list_append(*list, linphone_friend_ref(lf));
|
||||
|
|
@ -1073,6 +1142,17 @@ static int linphone_sql_request_friend(sqlite3* db, const char *stmt, MSList **l
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int linphone_sql_request_friends_list(sqlite3* db, const char *stmt, MSList **list) {
|
||||
char* errmsg = NULL;
|
||||
int ret;
|
||||
ret = sqlite3_exec(db, stmt, create_friend_list, list, &errmsg);
|
||||
if (ret != SQLITE_OK) {
|
||||
ms_error("linphone_sql_request: statement %s -> error sqlite3_exec(): %s.", stmt, errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int linphone_sql_request_generic(sqlite3* db, const char *stmt) {
|
||||
char* errmsg = NULL;
|
||||
int ret;
|
||||
|
|
@ -1093,9 +1173,15 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
|||
if (!store_friends) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lf->friend_list->storage_id == 0) {
|
||||
ms_warning("Trying to add a friend in db, but friend list isn't, let's do that first");
|
||||
linphone_core_store_friends_list_in_db(lc, lf->friend_list);
|
||||
}
|
||||
|
||||
if (lf->storage_id > 0) {
|
||||
buf = sqlite3_mprintf("UPDATE friends SET 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 = %i);",
|
||||
buf = sqlite3_mprintf("UPDATE friends SET friend_list_id=%i,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 = %i);",
|
||||
lf->friend_list->storage_id,
|
||||
linphone_address_as_string(linphone_friend_get_address(lf)),
|
||||
lf->pol,
|
||||
lf->subscribe,
|
||||
|
|
@ -1107,7 +1193,8 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
|||
lf->storage_id
|
||||
);
|
||||
} else {
|
||||
buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%Q,%i,%i,%Q,%Q,%Q,%Q,%i);",
|
||||
buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%i,%Q,%i,%i,%Q,%Q,%Q,%Q,%i);",
|
||||
lf->friend_list->storage_id,
|
||||
linphone_address_as_string(linphone_friend_get_address(lf)),
|
||||
lf->pol,
|
||||
lf->subscribe,
|
||||
|
|
@ -1127,6 +1214,40 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
|||
}
|
||||
}
|
||||
|
||||
void linphone_core_store_friends_list_in_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
if (lc && lc->friends_db) {
|
||||
char *buf;
|
||||
int store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1);
|
||||
|
||||
if (!store_friends) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (list->storage_id > 0) {
|
||||
buf = sqlite3_mprintf("UPDATE friends_lists SET display_name=%Q,rls_uri=%Q,uri=%Q,revision=%i WHERE (id = %i);",
|
||||
list->display_name,
|
||||
list->rls_uri,
|
||||
list->uri,
|
||||
list->revision,
|
||||
list->storage_id
|
||||
);
|
||||
} else {
|
||||
buf = sqlite3_mprintf("INSERT INTO friends_lists VALUES(NULL,%Q,%Q,%Q,%i);",
|
||||
list->display_name,
|
||||
list->rls_uri,
|
||||
list->uri,
|
||||
list->revision
|
||||
);
|
||||
}
|
||||
linphone_sql_request_generic(lc->friends_db, buf);
|
||||
sqlite3_free(buf);
|
||||
|
||||
if (list->storage_id == 0) {
|
||||
list->storage_id = sqlite3_last_insert_rowid(lc->friends_db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
||||
if (lc && lc->friends_db) {
|
||||
char *buf;
|
||||
|
|
@ -1143,7 +1264,44 @@ void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
|||
}
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
|
||||
void linphone_core_remove_friends_list_from_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
if (lc && lc->friends_db) {
|
||||
char *buf;
|
||||
if (list->storage_id == 0) {
|
||||
ms_error("Friends list doesn't have a storage_id !");
|
||||
return;
|
||||
}
|
||||
|
||||
buf = sqlite3_mprintf("DELETE FROM friends_lists WHERE id = %i", list->storage_id);
|
||||
linphone_sql_request_generic(lc->friends_db, buf);
|
||||
sqlite3_free(buf);
|
||||
|
||||
list->storage_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
char *buf;
|
||||
uint64_t begin,end;
|
||||
MSList *result = NULL;
|
||||
|
||||
if (!lc || lc->friends_db == NULL || list == NULL) {
|
||||
ms_warning("Either lc (or list) is NULL or friends database wasn't initialized with linphone_core_friends_storage_init() yet");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = sqlite3_mprintf("SELECT * FROM friends WHERE friend_list_id = %i ORDER BY id", list->storage_id);
|
||||
|
||||
begin = ortp_get_cur_time_ms();
|
||||
linphone_sql_request_friend(lc->friends_db, buf, &result);
|
||||
end = ortp_get_cur_time_ms();
|
||||
ms_message("%s(): completed in %i ms",__FUNCTION__, (int)(end-begin));
|
||||
sqlite3_free(buf);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_lists_from_db(LinphoneCore *lc) {
|
||||
char *buf;
|
||||
uint64_t begin,end;
|
||||
MSList *result = NULL;
|
||||
|
|
@ -1153,10 +1311,10 @@ MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
buf = sqlite3_mprintf("SELECT * FROM friends ORDER BY id");
|
||||
buf = sqlite3_mprintf("SELECT * FROM friends_lists ORDER BY id");
|
||||
|
||||
begin = ortp_get_cur_time_ms();
|
||||
linphone_sql_request_friend(lc->friends_db, buf, &result);
|
||||
linphone_sql_request_friends_list(lc->friends_db, buf, &result);
|
||||
end = ortp_get_cur_time_ms();
|
||||
ms_message("%s(): completed in %i ms",__FUNCTION__, (int)(end-begin));
|
||||
sqlite3_free(buf);
|
||||
|
|
@ -1175,10 +1333,20 @@ void linphone_core_friends_storage_close(LinphoneCore *lc) {
|
|||
void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
||||
}
|
||||
|
||||
void linphone_core_store_friends_list_in_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
}
|
||||
|
||||
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
|
||||
void linphone_core_remove_friends_list_from_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MSList* linphone_core_fetch_friends_lists_from_db(LinphoneCore *lc) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -280,8 +280,8 @@ static void linphone_friend_list_destroy(LinphoneFriendList *list) {
|
|||
if (list->event != NULL) linphone_event_unref(list->event);
|
||||
if (list->uri != NULL) ms_free(list->uri);
|
||||
if (list->cbs) linphone_friend_list_cbs_unref(list->cbs);
|
||||
list->friends = ms_list_free_with_data(list->friends, (void (*)(void *))linphone_friend_unref);
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))_linphone_friend_release);
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))linphone_friend_unref);
|
||||
list->friends = ms_list_free_with_data(list->friends, (void (*)(void *))_linphone_friend_release);
|
||||
}
|
||||
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFriendList);
|
||||
|
|
@ -316,9 +316,9 @@ void _linphone_friend_list_release(LinphoneFriendList *list){
|
|||
linphone_friend_list_cbs_unref(list->cbs);
|
||||
list->cbs = NULL;
|
||||
}
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))linphone_friend_unref);
|
||||
list->friends = ms_list_free_with_data(list->friends, (void (*)(void *))_linphone_friend_release);
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))_linphone_friend_release);
|
||||
belle_sip_object_unref(list);
|
||||
linphone_friend_list_unref(list);
|
||||
}
|
||||
|
||||
void linphone_friend_list_unref(LinphoneFriendList *list) {
|
||||
|
|
@ -361,6 +361,23 @@ void linphone_friend_list_set_rls_uri(LinphoneFriendList *list, const char *rls_
|
|||
}
|
||||
}
|
||||
|
||||
LinphoneFriendListStatus _linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *lf) {
|
||||
if (lf->uri == NULL || lf->friend_list) {
|
||||
if (!lf->uri)
|
||||
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");
|
||||
return LinphoneFriendListInvalidFriend;
|
||||
}
|
||||
list->friends = ms_list_append(list->friends, linphone_friend_ref(lf));
|
||||
lf->friend_list = list;
|
||||
lf->lc = list->lc;
|
||||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_store_friend_in_db(lf->lc, lf);
|
||||
#endif
|
||||
return LinphoneFriendListOK;
|
||||
}
|
||||
|
||||
LinphoneFriendListStatus linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *lf) {
|
||||
if (lf->uri == NULL || lf->friend_list) {
|
||||
if (!lf->uri)
|
||||
|
|
@ -386,6 +403,10 @@ LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList *
|
|||
list->friends = ms_list_append(list->friends, linphone_friend_ref(lf));
|
||||
list->dirty_friends_to_update = ms_list_append(list->dirty_friends_to_update, linphone_friend_ref(lf));
|
||||
lf->friend_list = list;
|
||||
lf->lc = list->lc;
|
||||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_store_friend_in_db(lf->lc, lf);
|
||||
#endif
|
||||
return LinphoneFriendListOK;
|
||||
}
|
||||
|
||||
|
|
@ -425,19 +446,18 @@ void linphone_friend_list_update_dirty_friends(LinphoneFriendList *list) {
|
|||
}
|
||||
dirty_friends = ms_list_next(dirty_friends);
|
||||
}
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))linphone_friend_unref);
|
||||
}
|
||||
list->dirty_friends_to_update = ms_list_free_with_data(list->dirty_friends_to_update, (void (*)(void *))linphone_friend_unref);
|
||||
}
|
||||
|
||||
static void carddav_created(LinphoneCardDavContext *cdc, LinphoneFriend *lf) {
|
||||
if (cdc) {
|
||||
LinphoneFriendList *lfl = cdc->friend_list;
|
||||
lfl->friends = ms_list_append(lfl->friends, linphone_friend_ref(lf));
|
||||
_linphone_friend_list_add_friend(lfl, lf);
|
||||
if (cdc->friend_list->cbs->contact_created_cb) {
|
||||
cdc->friend_list->cbs->contact_created_cb(lfl, linphone_friend_ref(lf));
|
||||
cdc->friend_list->cbs->contact_created_cb(lfl, lf);
|
||||
}
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
}
|
||||
|
||||
static void carddav_removed(LinphoneCardDavContext *cdc, LinphoneFriend *lf) {
|
||||
|
|
@ -448,10 +468,9 @@ static void carddav_removed(LinphoneCardDavContext *cdc, LinphoneFriend *lf) {
|
|||
lfl->friends = ms_list_remove_link(lfl->friends, elem);
|
||||
}
|
||||
if (cdc->friend_list->cbs->contact_deleted_cb) {
|
||||
cdc->friend_list->cbs->contact_deleted_cb(lfl, linphone_friend_ref(lf));
|
||||
cdc->friend_list->cbs->contact_deleted_cb(lfl, lf);
|
||||
}
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
}
|
||||
|
||||
static void carddav_updated(LinphoneCardDavContext *cdc, LinphoneFriend *lf_new, LinphoneFriend *lf_old) {
|
||||
|
|
|
|||
|
|
@ -62,11 +62,32 @@ typedef struct _LinphoneFriendList LinphoneFriendList;
|
|||
LINPHONE_PUBLIC LinphoneFriendList * linphone_core_create_friend_list(LinphoneCore *lc);
|
||||
|
||||
/**
|
||||
* Set the friend list.
|
||||
* Add a friend list.
|
||||
* @param[in] lc LinphoneCore object
|
||||
* @param[in] list LinphoneFriendList object
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_core_set_friend_list(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
LINPHONE_PUBLIC void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
|
||||
/**
|
||||
* Removes a friend list.
|
||||
* @param[in] lc LinphoneCore object
|
||||
* @param[in] list LinphoneFriendList object
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_core_remove_friend_list(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
|
||||
/**
|
||||
* Retrieves the list of LinphoneFriendList from the core.
|
||||
* @param[in] lc LinphoneCore object
|
||||
* @return \mslist{LinphoneFriendList} a list of LinphoneFriendList
|
||||
*/
|
||||
LINPHONE_PUBLIC const MSList * linphone_core_get_friends_lists(const LinphoneCore *lc);
|
||||
|
||||
/**
|
||||
* Retrieves the first list of LinphoneFriend from the core.
|
||||
* @param[in] lc LinphoneCore object
|
||||
* @return the first LinphoneFriendList object or NULL
|
||||
*/
|
||||
LINPHONE_PUBLIC LinphoneFriendList * linphone_core_get_default_friend_list(const LinphoneCore *lc);
|
||||
|
||||
/**
|
||||
* Acquire a reference to the friend list.
|
||||
|
|
@ -130,6 +151,7 @@ LINPHONE_PUBLIC void linphone_friend_list_set_rls_uri(LinphoneFriendList *list,
|
|||
* @return LinphoneFriendListOK if successfully added, LinphoneFriendListInvalidFriend if the friend is not valid.
|
||||
**/
|
||||
LINPHONE_PUBLIC LinphoneFriendListStatus linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *afriend);
|
||||
LinphoneFriendListStatus _linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *afriend);
|
||||
|
||||
/**
|
||||
* Remove a friend from a friend list.
|
||||
|
|
|
|||
|
|
@ -1679,7 +1679,7 @@ static void linphone_core_register_default_codecs(LinphoneCore *lc){
|
|||
|
||||
static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body) {
|
||||
if (strcmp(notified_event, "Presence") == 0) {
|
||||
linphone_friend_list_notify_presence_received(lc->friendlist, lev, body);
|
||||
linphone_friend_list_notify_presence_received(linphone_core_get_default_friend_list(lc), lev, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1687,13 +1687,23 @@ static void linphone_core_init(LinphoneCore * lc, const LinphoneCoreVTable *vtab
|
|||
const char *remote_provisioning_uri = NULL;
|
||||
LinphoneCoreVTable* local_vtable= linphone_core_v_table_new();
|
||||
LinphoneCoreVTable *internal_vtable = linphone_core_v_table_new();
|
||||
LinphoneFriendList *list = NULL;
|
||||
const char *rls_uri = NULL;
|
||||
|
||||
ms_message("Initializing LinphoneCore %s", linphone_core_get_version());
|
||||
|
||||
lc->config=lp_config_ref(config);
|
||||
lc->data=userdata;
|
||||
lc->ringstream_autorelease=TRUE;
|
||||
linphone_core_set_friend_list(lc, NULL);
|
||||
|
||||
list = linphone_core_create_friend_list(lc);
|
||||
rls_uri = lp_config_get_string(lc->config, "sip", "rls_uri", NULL);
|
||||
if (rls_uri && lp_config_get_int(lc->config, "sip", "use_rls_presence", 0)) {
|
||||
linphone_friend_list_set_rls_uri(list, rls_uri);
|
||||
}
|
||||
linphone_core_add_friend_list(lc, list);
|
||||
linphone_friend_list_unref(list);
|
||||
|
||||
linphone_task_list_init(&lc->hooks);
|
||||
|
||||
internal_vtable->notify_received = linphone_core_internal_notify_received;
|
||||
|
|
@ -1930,24 +1940,47 @@ bool_t linphone_core_generic_confort_noise_enabled(const LinphoneCore *lc){
|
|||
return lp_config_get_int(lc->config, "misc", "use_cn", FALSE);
|
||||
}
|
||||
|
||||
const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
|
||||
{
|
||||
return lc->friendlist->friends;
|
||||
const MSList* linphone_core_get_friend_list(const LinphoneCore *lc) {
|
||||
if (lc->friends_lists && lc->friends_lists->data) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)lc->friends_lists->data;
|
||||
return list->friends;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void linphone_core_set_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
if (lc->friendlist != NULL) {
|
||||
linphone_friend_list_unref(lc->friendlist);
|
||||
lc->friendlist = NULL;
|
||||
const MSList* linphone_core_get_friends_lists(const LinphoneCore *lc) {
|
||||
return lc->friends_lists;
|
||||
}
|
||||
|
||||
LinphoneFriendList* linphone_core_get_default_friend_list(const LinphoneCore *lc) {
|
||||
LinphoneFriendList *list = NULL;
|
||||
if (!lc->friends_lists) {
|
||||
return NULL;
|
||||
}
|
||||
if (list != NULL) {
|
||||
lc->friendlist = linphone_friend_list_ref(list);
|
||||
} else {
|
||||
const char *rls_uri = NULL;
|
||||
lc->friendlist = linphone_core_create_friend_list(lc);
|
||||
rls_uri = lp_config_get_string(lc->config, "sip", "rls_uri", NULL);
|
||||
if (rls_uri && lp_config_get_int(lc->config, "sip", "use_rls_presence", 0))
|
||||
linphone_friend_list_set_rls_uri(lc->friendlist, rls_uri);
|
||||
list = (LinphoneFriendList *)lc->friends_lists->data;
|
||||
return list;
|
||||
}
|
||||
|
||||
void linphone_core_remove_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
MSList *elem = ms_list_find(lc->friends_lists, list);
|
||||
if (elem == NULL) return;
|
||||
list->lc = NULL;
|
||||
linphone_friend_list_unref(list);
|
||||
lc->friends_lists = ms_list_remove_link(lc->friends_lists, elem);
|
||||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_remove_friends_list_from_db(lc, list);
|
||||
#endif
|
||||
}
|
||||
|
||||
void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
|
||||
if (list) {
|
||||
if (!list->lc) {
|
||||
list->lc = lc;
|
||||
}
|
||||
lc->friends_lists = ms_list_append(lc->friends_lists, linphone_friend_list_ref(list));
|
||||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_store_friends_list_in_db(lc, list);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2733,11 +2766,15 @@ void linphone_core_iterate(LinphoneCore *lc){
|
|||
}
|
||||
|
||||
if (one_second_elapsed) {
|
||||
MSList *elem = NULL;
|
||||
if (lp_config_needs_commit(lc->config)) {
|
||||
lp_config_sync(lc->config);
|
||||
}
|
||||
if (lc->friendlist->dirty_friends_to_update) {
|
||||
linphone_friend_list_update_dirty_friends(lc->friendlist);
|
||||
for (elem = lc->friends_lists; elem != NULL; elem = ms_list_next(elem)) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)elem->data;
|
||||
if (list->dirty_friends_to_update) {
|
||||
linphone_friend_list_update_dirty_friends(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6354,10 +6391,14 @@ static void codecs_config_uninit(LinphoneCore *lc)
|
|||
|
||||
void ui_config_uninit(LinphoneCore* lc)
|
||||
{
|
||||
MSList *elem = NULL;
|
||||
ms_message("Destroying friends.");
|
||||
_linphone_friend_list_release(lc->friendlist);
|
||||
lc->friendlist = NULL;
|
||||
if (lc->subscribers){
|
||||
for (elem = lc->friends_lists; elem != NULL; elem = ms_list_next(elem)) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)elem->data;
|
||||
_linphone_friend_list_release(list);
|
||||
}
|
||||
lc->friends_lists = NULL;
|
||||
if (lc->subscribers) {
|
||||
lc->subscribers = ms_list_free_with_data(lc->subscribers, (void (*)(void *))_linphone_friend_release);
|
||||
}
|
||||
if (lc->presence_model) {
|
||||
|
|
@ -6385,18 +6426,22 @@ LpConfig * linphone_core_create_lp_config(LinphoneCore *lc, const char *filename
|
|||
|
||||
static void linphone_core_uninit(LinphoneCore *lc)
|
||||
{
|
||||
MSList *elem = NULL;
|
||||
linphone_task_list_free(&lc->hooks);
|
||||
lc->video_conf.show_local = FALSE;
|
||||
|
||||
while(lc->calls)
|
||||
{
|
||||
while(lc->calls) {
|
||||
LinphoneCall *the_call = lc->calls->data;
|
||||
linphone_core_terminate_call(lc,the_call);
|
||||
linphone_core_iterate(lc);
|
||||
ms_usleep(50000);
|
||||
}
|
||||
|
||||
linphone_friend_list_close_subscriptions(lc->friendlist);
|
||||
for (elem = lc->friends_lists; elem != NULL; elem = ms_list_next(elem)) {
|
||||
LinphoneFriendList *list = (LinphoneFriendList *)elem->data;
|
||||
linphone_friend_list_close_subscriptions(list);
|
||||
}
|
||||
|
||||
lc->chatrooms = ms_list_free_with_data(lc->chatrooms, (MSIterateFunc)linphone_chat_room_release);
|
||||
|
||||
linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
|
||||
|
|
@ -6455,10 +6500,12 @@ static void linphone_core_uninit(LinphoneCore *lc)
|
|||
if (lc->ringtoneplayer) {
|
||||
linphone_ringtoneplayer_destroy(lc->ringtoneplayer);
|
||||
}
|
||||
|
||||
linphone_core_free_payload_types(lc);
|
||||
if (lc->supported_formats) ms_free(lc->supported_formats);
|
||||
linphone_core_message_storage_close(lc);
|
||||
linphone_core_call_log_storage_close(lc);
|
||||
linphone_core_friends_storage_close(lc);
|
||||
ms_exit();
|
||||
linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
|
||||
linphone_core_deactivate_log_serialization_if_needed();
|
||||
|
|
|
|||
|
|
@ -1469,7 +1469,7 @@ void linphone_core_notify_all_friends(LinphoneCore *lc, LinphonePresenceModel *p
|
|||
char *activity_str = linphone_presence_activity_to_string(activity);
|
||||
ms_message("Notifying all friends that we are [%s]", activity_str);
|
||||
if (activity_str != NULL) ms_free(activity_str);
|
||||
linphone_friend_list_notify_presence(lc->friendlist, presence);
|
||||
linphone_friend_list_notify_presence(linphone_core_get_default_friend_list(lc), presence);
|
||||
}
|
||||
|
||||
void linphone_subscription_new(LinphoneCore *lc, SalOp *op, const char *from){
|
||||
|
|
@ -1483,8 +1483,8 @@ void linphone_subscription_new(LinphoneCore *lc, SalOp *op, const char *from){
|
|||
ms_message("Receiving new subscription from %s.",from);
|
||||
|
||||
/* check if we answer to this subscription */
|
||||
if (lc->friendlist != NULL) {
|
||||
lf = linphone_friend_list_find_friend_by_address(lc->friendlist, uri);
|
||||
if (linphone_core_get_default_friend_list(lc) != NULL) {
|
||||
lf = linphone_friend_list_find_friend_by_address(linphone_core_get_default_friend_list(lc), uri);
|
||||
}
|
||||
if (lf!=NULL){
|
||||
linphone_friend_add_incoming_subscription(lf, op);
|
||||
|
|
@ -1854,11 +1854,11 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa
|
|||
LinphoneAddress *friend=NULL;
|
||||
LinphonePresenceModel *presence = model ? (LinphonePresenceModel *)model:linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline, NULL);
|
||||
|
||||
if (lc->friendlist != NULL)
|
||||
lf=linphone_friend_list_find_friend_by_out_subscribe(lc->friendlist,op);
|
||||
if (linphone_core_get_default_friend_list(lc) != NULL)
|
||||
lf=linphone_friend_list_find_friend_by_out_subscribe(linphone_core_get_default_friend_list(lc), op);
|
||||
if (lf==NULL && lp_config_get_int(lc->config,"sip","allow_out_of_subscribe_presence",0)){
|
||||
const SalAddress *addr=sal_op_get_from_address(op);
|
||||
lf = linphone_friend_list_find_friend_by_address(lc->friendlist, (LinphoneAddress *)addr);
|
||||
lf = linphone_friend_list_find_friend_by_address(linphone_core_get_default_friend_list(lc), (LinphoneAddress *)addr);
|
||||
}
|
||||
if (lf!=NULL){
|
||||
LinphonePresenceActivity *activity = NULL;
|
||||
|
|
@ -1904,8 +1904,8 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa
|
|||
void linphone_subscription_closed(LinphoneCore *lc, SalOp *op){
|
||||
LinphoneFriend *lf = NULL;
|
||||
|
||||
if (lc->friendlist != NULL)
|
||||
lf=linphone_friend_list_find_friend_by_inc_subscribe(lc->friendlist,op);
|
||||
if (linphone_core_get_default_friend_list(lc) != NULL)
|
||||
lf = linphone_friend_list_find_friend_by_inc_subscribe(linphone_core_get_default_friend_list(lc), op);
|
||||
|
||||
if (lf!=NULL){
|
||||
/*this will release the op*/
|
||||
|
|
|
|||
|
|
@ -420,8 +420,12 @@ void linphone_core_friends_storage_init(LinphoneCore *lc);
|
|||
void linphone_core_friends_storage_close(LinphoneCore *lc);
|
||||
void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf);
|
||||
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf);
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc);
|
||||
void linphone_core_store_friends_list_in_db(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
void linphone_core_remove_friends_list_from_db(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc, LinphoneFriendList *list);
|
||||
MSList* linphone_core_fetch_friends_lists_from_db(LinphoneCore *lc);
|
||||
LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList *list, LinphoneFriend *lf);
|
||||
LinphoneFriendListStatus _linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *lf);
|
||||
|
||||
int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, socklen_t *socklen, int default_port);
|
||||
|
||||
|
|
@ -897,7 +901,7 @@ struct _LinphoneCore
|
|||
ui_config_t ui_conf;
|
||||
autoreplier_config_t autoreplier_conf;
|
||||
LinphoneProxyConfig *default_proxy;
|
||||
LinphoneFriendList *friendlist;
|
||||
MSList *friends_lists;
|
||||
MSList *auth_info;
|
||||
struct _RingStream *ringstream;
|
||||
time_t dmfs_playing_start_time;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ RCFILES = \
|
|||
rcfiles/stun_rc\
|
||||
rcfiles/upnp_rc\
|
||||
rcfiles/zero_length_params_rc\
|
||||
rcfiles/friends_rc
|
||||
rcfiles/friends_rc\
|
||||
rcfiles/carddav_rc
|
||||
|
||||
IMAGE_FILES = images/nowebcamCIF.jpg
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ static void subscribe_failure_handle_by_app(void) {
|
|||
sal_set_recv_error(marie->lc->sal, 1);
|
||||
|
||||
lf = linphone_core_get_friend_by_address(marie->lc,lf_identity);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(lf);
|
||||
linphone_friend_edit(lf);
|
||||
linphone_friend_enable_subscribes(lf,FALSE); /*disable subscription*/
|
||||
linphone_friend_done(lf);
|
||||
|
|
@ -600,7 +601,8 @@ static void test_presence_list(void) {
|
|||
linphone_friend_list_add_friend(lfl, lf);
|
||||
lf = linphone_core_create_friend_with_address(laure->lc, "sip:michelle@sip.inexistentdomain.com");
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_core_set_friend_list(laure->lc, lfl);
|
||||
linphone_core_remove_friend_list(laure->lc, linphone_core_get_default_friend_list(laure->lc));
|
||||
linphone_core_add_friend_list(laure->lc, lfl);
|
||||
linphone_friend_list_unref(lfl);
|
||||
linphone_core_set_presence_model(laure->lc, linphone_core_create_presence_model_with_activity(laure->lc, LinphonePresenceActivityOnline, NULL));
|
||||
|
||||
|
|
@ -610,16 +612,16 @@ static void test_presence_list(void) {
|
|||
|
||||
wait_for_list(lcs, &laure->stat.number_of_NotifyPresenceReceived, 2, 2000);
|
||||
BC_ASSERT_EQUAL(laure->stat.number_of_NotifyPresenceReceived, 2, int, "%d");
|
||||
BC_ASSERT_EQUAL(laure->lc->friendlist->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_core_get_default_friend_list(laure->lc)->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusBusy, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, pauline_identity);
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), pauline_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusVacation, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, "sip:michelle@sip.inexistentdomain.com");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), "sip:michelle@sip.inexistentdomain.com");
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, FALSE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
|
|
@ -628,14 +630,15 @@ static void test_presence_list(void) {
|
|||
linphone_friend_list_set_rls_uri(lfl, rls_uri);
|
||||
lf = linphone_core_create_friend_with_address(marie->lc, laure_identity);
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_core_set_friend_list(marie->lc, lfl);
|
||||
linphone_core_remove_friend_list(marie->lc, linphone_core_get_default_friend_list(marie->lc));
|
||||
linphone_core_add_friend_list(marie->lc, lfl);
|
||||
linphone_friend_list_unref(lfl);
|
||||
linphone_friend_list_update_subscriptions(marie->lc->friendlist, NULL, FALSE);
|
||||
linphone_friend_list_update_subscriptions(linphone_core_get_default_friend_list(marie->lc), NULL, FALSE);
|
||||
|
||||
wait_for_list(lcs, &marie->stat.number_of_NotifyPresenceReceived, 1, 2000);
|
||||
BC_ASSERT_EQUAL(marie->stat.number_of_NotifyPresenceReceived, 1, int, "%d");
|
||||
BC_ASSERT_EQUAL(marie->lc->friendlist->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(marie->lc->friendlist, laure_identity);
|
||||
BC_ASSERT_EQUAL(linphone_core_get_default_friend_list(marie->lc)->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(marie->lc), laure_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOnline, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
|
|
@ -644,14 +647,15 @@ static void test_presence_list(void) {
|
|||
linphone_friend_list_set_rls_uri(lfl, rls_uri);
|
||||
lf = linphone_core_create_friend_with_address(pauline->lc, marie_identity);
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_core_set_friend_list(pauline->lc, lfl);
|
||||
linphone_core_remove_friend_list(pauline->lc, linphone_core_get_default_friend_list(pauline->lc));
|
||||
linphone_core_add_friend_list(pauline->lc, lfl);
|
||||
linphone_friend_list_unref(lfl);
|
||||
linphone_friend_list_update_subscriptions(pauline->lc->friendlist, NULL, FALSE);
|
||||
linphone_friend_list_update_subscriptions(linphone_core_get_default_friend_list(pauline->lc), NULL, FALSE);
|
||||
|
||||
wait_for_list(lcs, &pauline->stat.number_of_NotifyPresenceReceived, 1, 2000);
|
||||
BC_ASSERT_EQUAL(pauline->stat.number_of_NotifyPresenceReceived, 1, int, "%d");
|
||||
BC_ASSERT_EQUAL(pauline->lc->friendlist->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(pauline->lc->friendlist, marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_core_get_default_friend_list(pauline->lc)->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(pauline->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusBusy, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
|
|
@ -662,14 +666,14 @@ static void test_presence_list(void) {
|
|||
/* The number of PresenceReceived events can be 3 or 4 here. TODO: ideally it should always be 3. */
|
||||
BC_ASSERT_GREATER(laure->stat.number_of_NotifyPresenceReceived, 3, int, "%d");
|
||||
BC_ASSERT_LOWER(laure->stat.number_of_NotifyPresenceReceived, 4, int, "%d");
|
||||
BC_ASSERT_EQUAL(laure->lc->friendlist->expected_notification_version, 2, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_core_get_default_friend_list(laure->lc)->expected_notification_version, 2, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOnThePhone, int, "%d");
|
||||
|
||||
wait_for_list(lcs, &pauline->stat.number_of_NotifyPresenceReceived, 2, 2000);
|
||||
BC_ASSERT_EQUAL(pauline->stat.number_of_NotifyPresenceReceived, 2, int, "%d");
|
||||
BC_ASSERT_EQUAL(pauline->lc->friendlist->expected_notification_version, 2, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(pauline->lc->friendlist, marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_core_get_default_friend_list(pauline->lc)->expected_notification_version, 2, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(pauline->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOnThePhone, int, "%d");
|
||||
|
||||
enable_publish(laure, FALSE);
|
||||
|
|
@ -678,14 +682,14 @@ static void test_presence_list(void) {
|
|||
|
||||
wait_for_list(lcs, &dummy, 1, 2000); /* Wait a little bit for the presence notifications. TODO: Wait for the correct number of PresenceReceived events. */
|
||||
|
||||
lf = linphone_friend_list_find_friend_by_uri(pauline->lc->friendlist, marie_identity);
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(pauline->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, pauline_identity);
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), pauline_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, marie_identity);
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), marie_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
|
||||
lf = linphone_friend_list_find_friend_by_uri(marie->lc->friendlist, laure_identity);
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(marie->lc), laure_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
|
||||
linphone_core_manager_destroy(laure);
|
||||
|
|
@ -713,10 +717,11 @@ static void test_presence_list_subscribe_before_publish(void) {
|
|||
linphone_friend_list_add_friend(lfl, lf);
|
||||
lf = linphone_core_create_friend_with_address(laure->lc, "sip:michelle@sip.inexistentdomain.com");
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_core_set_friend_list(laure->lc, lfl);
|
||||
linphone_core_remove_friend_list(laure->lc, linphone_core_get_default_friend_list(laure->lc));
|
||||
linphone_core_add_friend_list(laure->lc, lfl);
|
||||
linphone_friend_list_unref(lfl);
|
||||
linphone_core_set_presence_model(laure->lc, linphone_core_create_presence_model_with_activity(laure->lc, LinphonePresenceActivityOnline, NULL));
|
||||
linphone_friend_list_update_subscriptions(laure->lc->friendlist, NULL, FALSE);
|
||||
linphone_friend_list_update_subscriptions(linphone_core_get_default_friend_list(laure->lc), NULL, FALSE);
|
||||
|
||||
lcs = ms_list_append(lcs, laure->lc);
|
||||
lcs = ms_list_append(lcs, pauline->lc);
|
||||
|
|
@ -726,12 +731,12 @@ static void test_presence_list_subscribe_before_publish(void) {
|
|||
enable_publish(pauline, TRUE);
|
||||
wait_for_list(lcs, &pauline->stat.number_of_NotifyPresenceReceived, 1, 2000);
|
||||
BC_ASSERT_GREATER(laure->stat.number_of_NotifyPresenceReceived, 1, int, "%d");
|
||||
BC_ASSERT_GREATER(laure->lc->friendlist->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, pauline_identity);
|
||||
BC_ASSERT_GREATER(linphone_core_get_default_friend_list(laure->lc)->expected_notification_version, 1, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), pauline_identity);
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusVacation, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, "sip:michelle@sip.inexistentdomain.com");
|
||||
lf = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(laure->lc), "sip:michelle@sip.inexistentdomain.com");
|
||||
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->presence_received, FALSE, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
|
||||
|
|
|
|||
12
tester/rcfiles/carddav_rc
Normal file
12
tester/rcfiles/carddav_rc
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[net]
|
||||
mtu=1300
|
||||
|
||||
[sip]
|
||||
ping_with_options=0
|
||||
sip_random_port=1
|
||||
|
||||
[auth_info_0]
|
||||
domain=192.168.0.230
|
||||
username=sylvain
|
||||
ha1=4747ce2517a985f2fc20234a38f068b6
|
||||
realm=SabreDAV
|
||||
|
|
@ -36,6 +36,7 @@ static void linphone_vcard_import_export_friends_test(void) {
|
|||
int count = 0;
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(linphone_core_get_default_friend_list(manager->lc));
|
||||
count = linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath);
|
||||
BC_ASSERT_EQUAL(count, 3, int, "%d");
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
|
|
@ -43,10 +44,11 @@ static void linphone_vcard_import_export_friends_test(void) {
|
|||
|
||||
linphone_core_export_friends_as_vcard4_file(manager->lc, export_filepath);
|
||||
|
||||
linphone_core_set_friend_list(manager->lc, NULL);
|
||||
linphone_core_remove_friend_list(manager->lc, linphone_core_get_default_friend_list(manager->lc));
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
linphone_core_add_friend_list(manager->lc, linphone_core_create_friend_list(manager->lc));
|
||||
count = linphone_core_import_friends_from_vcard4_file(manager->lc, export_filepath);
|
||||
BC_ASSERT_EQUAL(count, 3, int, "%d");
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
|
|
@ -98,7 +100,6 @@ static void friends_if_no_db_set(void) {
|
|||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
static void friends_migration(void) {
|
||||
LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE);
|
||||
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
|
||||
const MSList *friends = linphone_core_get_friend_list(manager->lc);
|
||||
MSList *friends_from_db = NULL;
|
||||
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
|
||||
|
|
@ -108,7 +109,7 @@ static void friends_migration(void) {
|
|||
linphone_core_set_friends_database_path(manager->lc, friends_db);
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, linphone_core_get_default_friend_list(manager->lc));
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d");
|
||||
if (ms_list_size(friends_from_db) < 3) {
|
||||
goto end;
|
||||
|
|
@ -117,25 +118,28 @@ static void friends_migration(void) {
|
|||
end:
|
||||
unlink(friends_db);
|
||||
ms_free(friends_db);
|
||||
linphone_address_unref(addr);
|
||||
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
|
||||
linphone_core_manager_destroy(manager);
|
||||
}
|
||||
|
||||
static void friends_sqlite_storage(void) {
|
||||
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
|
||||
LinphoneVCard *lvc = linphone_vcard_new();
|
||||
LinphoneFriend *lf = linphone_friend_new();
|
||||
LinphoneFriend *lf2 = NULL;
|
||||
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
|
||||
const MSList *friends = linphone_core_get_friend_list(manager->lc);
|
||||
MSList *friends_from_db = NULL;
|
||||
MSList *friends_lists_from_db = NULL;
|
||||
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
unlink(friends_db);
|
||||
linphone_core_set_friends_database_path(manager->lc, friends_db);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, linphone_core_get_default_friend_list(manager->lc));
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
linphone_vcard_set_etag(lvc, "\"123-456789\"");
|
||||
|
|
@ -143,14 +147,22 @@ static void friends_sqlite_storage(void) {
|
|||
linphone_friend_set_vcard(lf, lvc);
|
||||
linphone_friend_set_address(lf, addr);
|
||||
linphone_friend_set_name(lf, "Sylvain");
|
||||
linphone_core_add_friend(manager->lc, lf);
|
||||
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
|
||||
linphone_friend_list_set_display_name(lfl, "Test");
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_friend_unref(lf);
|
||||
BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d");
|
||||
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d");
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
|
||||
friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d");
|
||||
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
|
||||
if (ms_list_size(friends_from_db) < 1) {
|
||||
goto end;
|
||||
|
|
@ -166,7 +178,7 @@ static void friends_sqlite_storage(void) {
|
|||
linphone_friend_set_name(lf, "Margaux");
|
||||
linphone_friend_done(lf);
|
||||
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
|
||||
if (ms_list_size(friends_from_db) < 1) {
|
||||
goto end;
|
||||
|
|
@ -178,7 +190,7 @@ static void friends_sqlite_storage(void) {
|
|||
linphone_core_remove_friend(manager->lc, lf);
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
|
||||
|
||||
end:
|
||||
|
|
@ -206,14 +218,12 @@ static void carddav_sync_done(LinphoneCardDavContext *c, bool_t success, const c
|
|||
static void carddav_new_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(lf);
|
||||
linphone_friend_unref(lf);
|
||||
stats->new_contact_count++;
|
||||
}
|
||||
|
||||
static void carddav_removed_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(lf);
|
||||
linphone_friend_unref(lf);
|
||||
stats->removed_contact_count++;
|
||||
}
|
||||
|
||||
|
|
@ -221,19 +231,17 @@ static void carddav_updated_contact(LinphoneCardDavContext *c, LinphoneFriend *n
|
|||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(new_lf);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(old_lf);
|
||||
linphone_friend_unref(new_lf);
|
||||
linphone_friend_unref(old_lf);
|
||||
stats->updated_contact_count++;
|
||||
}
|
||||
|
||||
static void carddav_sync(void) {
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
|
||||
LinphoneCardDavContext *c = NULL;
|
||||
|
||||
linphone_friend_list_set_uri(lfl, "http://192.168.0.230/sabredav/addressbookserver.php/addressbooks/sylvain/default");
|
||||
linphone_core_set_friend_list(manager->lc, lfl);
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
c = linphone_carddav_context_new(lfl);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(c);
|
||||
|
||||
|
|
@ -256,7 +264,7 @@ static void carddav_sync(void) {
|
|||
}
|
||||
|
||||
static void carddav_sync_2(void) {
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
|
||||
LinphoneFriend *lf = linphone_friend_new_with_address("\"Sylvain\" <sip:sylvain@sip.linphone.org>");
|
||||
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
|
||||
|
|
@ -264,13 +272,13 @@ static void carddav_sync_2(void) {
|
|||
LinphoneCardDavContext *c = NULL;
|
||||
|
||||
linphone_friend_list_set_uri(lfl, "http://192.168.0.230/sabredav/addressbookserver.php/addressbooks/sylvain/default");
|
||||
linphone_core_set_friend_list(manager->lc, lfl);
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
c = linphone_carddav_context_new(lfl);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(c);
|
||||
|
||||
unlink(friends_db);
|
||||
linphone_core_set_friends_database_path(manager->lc, friends_db);
|
||||
linphone_core_add_friend(manager->lc, lf);
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_friend_unref(lf);
|
||||
|
||||
linphone_carddav_set_user_data(c, stats);
|
||||
|
|
@ -297,7 +305,7 @@ static void carddav_sync_2(void) {
|
|||
}
|
||||
|
||||
static void carddav_sync_3(void) {
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
|
||||
LinphoneVCard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nFN:Sylvain Berfini\r\nIMPP;TYPE=work:sip:sylvain@sip.linphone.org\r\nEND:VCARD\r\n");
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
|
||||
|
|
@ -306,13 +314,13 @@ static void carddav_sync_3(void) {
|
|||
LinphoneCardDavContext *c = NULL;
|
||||
|
||||
linphone_friend_list_set_uri(lfl, "http://192.168.0.230/sabredav/addressbookserver.php/addressbooks/sylvain/default");
|
||||
linphone_core_set_friend_list(manager->lc, lfl);
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
c = linphone_carddav_context_new(lfl);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(c);
|
||||
|
||||
unlink(friends_db);
|
||||
linphone_core_set_friends_database_path(manager->lc, friends_db);
|
||||
linphone_core_add_friend(manager->lc, lf);
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
linphone_friend_unref(lf);
|
||||
|
||||
linphone_carddav_set_user_data(c, stats);
|
||||
|
|
@ -337,7 +345,7 @@ static void carddav_sync_3(void) {
|
|||
}
|
||||
|
||||
static void carddav_sync_4(void) {
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
|
||||
LinphoneVCard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
|
||||
|
|
@ -345,7 +353,7 @@ static void carddav_sync_4(void) {
|
|||
LinphoneCardDavContext *c = NULL;
|
||||
|
||||
linphone_friend_list_set_uri(lfl, "http://192.168.0.230/sabredav/addressbookserver.php/addressbooks/sylvain/default");
|
||||
linphone_core_set_friend_list(manager->lc, lfl);
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
c = linphone_carddav_context_new(lfl);
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(c);
|
||||
|
||||
|
|
@ -377,17 +385,15 @@ static void carddav_sync_4(void) {
|
|||
static void carddav_contact_created(LinphoneFriendList *list, LinphoneFriend *lf) {
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
|
||||
stats->new_contact_count++;
|
||||
linphone_friend_unref(lf);
|
||||
}
|
||||
|
||||
static void carddav_contact_deleted(LinphoneFriendList *list, LinphoneFriend *lf) {
|
||||
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
|
||||
stats->removed_contact_count++;
|
||||
linphone_friend_unref(lf);
|
||||
}
|
||||
|
||||
static void carddav_integration(void) {
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("empty_rc", FALSE);
|
||||
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
|
||||
LinphoneVCard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
|
||||
|
|
@ -399,7 +405,7 @@ static void carddav_integration(void) {
|
|||
linphone_friend_list_cbs_set_user_data(cbs, stats);
|
||||
linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);
|
||||
linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);
|
||||
linphone_core_set_friend_list(manager->lc, lfl);
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
|
||||
BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
|
||||
BC_ASSERT_TRUE(linphone_vcard_generate_unique_id(lvc));
|
||||
|
|
@ -408,12 +414,18 @@ static void carddav_integration(void) {
|
|||
wait_for_until(manager->lc, NULL, NULL, 1, 2000);
|
||||
linphone_friend_list_remove_friend(lfl, lf);
|
||||
wait_for_until(manager->lc, NULL, NULL, 1, 2000);
|
||||
linphone_friend_unref(lf);
|
||||
|
||||
lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n");
|
||||
lf = linphone_friend_new_from_vcard(lvc);
|
||||
_linphone_friend_list_add_friend(lfl, lf);
|
||||
|
||||
BC_ASSERT_EQUAL(lfl->revision, 0, int, "%i");
|
||||
|
||||
linphone_friend_list_synchronize_friends_from_server(lfl);
|
||||
wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, 2000);
|
||||
BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i");
|
||||
wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 2000);
|
||||
BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i");
|
||||
BC_ASSERT_NOT_EQUAL(lfl->revision, 0, int, "%i");
|
||||
|
||||
ms_free(stats);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue