void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) { if (lc && lc->friends_db) { char *buf; int store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1); LinphoneVcard *vcard = linphone_friend_get_vcard(lf); char *address = NULL; if (!store_friends) { return; } if (!lf || !lf->friend_list) { ms_warning("Either the friend or the friend list is null, skipping..."); 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); } address = linphone_address_as_string(linphone_friend_get_address(lf)); 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, lf->pol, lf->subscribe, lf->refkey, linphone_vcard_as_vcard4_string(vcard), linphone_vcard_get_etag(vcard), linphone_vcard_get_url(vcard), lf->presence_received, lf->storage_id ); } else { buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%u,%Q,%i,%i,%Q,%Q,%Q,%Q,%i);", lf->friend_list->storage_id, address, lf->pol, lf->subscribe, lf->refkey, linphone_vcard_as_vcard4_string(vcard), linphone_vcard_get_etag(vcard), linphone_vcard_get_url(vcard), lf->presence_received ); } ms_free(address); linphone_sql_request_generic(lc->friends_db, buf); sqlite3_free(buf); if (lf->storage_id == 0) { lf->storage_id = (unsigned int)sqlite3_last_insert_rowid(lc->friends_db); } } }
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); file = fopen(vcard_file, "wb"); if (file == NULL) { ms_warning("Could not write %s ! Maybe it is read-only. Contacts will not be saved.", vcard_file); 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; LinphoneVcard *vcard = linphone_friend_get_vcard(lf); if (vcard) { const char *vcard_text = linphone_vcard_as_vcard4_string(vcard); fprintf(file, "%s", vcard_text); } else { ms_warning("Couldn't export friend %s because it doesn't have a vCard attached", linphone_address_as_string(linphone_friend_get_address(lf))); } friends = bctbx_list_next(friends); } fclose(file); }