示例#1
0
文件: friend.c 项目: 42p/linphone
void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) {
	LpConfig *lpc = NULL;
	LinphoneFriend *lf = NULL;
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(lc);
	int i;
#ifndef SQLITE_STORAGE_ENABLED
	ms_warning("linphone has been compiled without sqlite, can't migrate friends");
	return;
#endif
	if (!lc) {
		return;
	}

	lpc = linphone_core_get_config(lc);
	if (!lpc) {
		ms_warning("this core has been started without a rc file, nothing to migrate");
		return;
	}
	if (lp_config_get_int(lpc, "misc", "friends_migration_done", 0) == 1) {
		ms_warning("the friends migration has already been done, skipping...");
		return;
	}

	if (bctbx_list_size(linphone_friend_list_get_friends(lfl)) > 0 && lfl->storage_id == 0) {
		linphone_core_remove_friend_list(lc, lfl);
		lfl = linphone_core_create_friend_list(lc);
		linphone_core_add_friend_list(lc, lfl);
		linphone_friend_list_unref(lfl);
	}

	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);
		if (addr) {
			const char *displayName = linphone_address_get_display_name(addr);
			char *address = NULL;
			if (!displayName) {
				displayName = linphone_address_get_username(addr);
			}

			address = linphone_address_as_string(addr);
			if (!linphone_friend_create_vcard(lf, displayName)) {
				ms_warning("Couldn't create vCard for friend %s", address);
			} else {
				linphone_vcard_add_sip_address(linphone_friend_get_vcard(lf), address);
			}
			ms_free(address);

			linphone_friend_list_add_friend(lfl, lf);
			linphone_friend_unref(lf);

			snprintf(friend_section, sizeof(friend_section), "friend_%i", i);
			lp_config_clean_section(lpc, friend_section);
		}
	}

	ms_debug("friends migration successful: %i friends migrated", i);
	lp_config_set_int(lpc, "misc", "friends_migration_done", 1);
}
示例#2
0
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) {
	LinphoneVcard *vcard = NULL;
	if (!lf || !addr) {
		return;
	}
	if (lf->uri == NULL) {
		LinphoneAddress *fr = linphone_address_clone(addr);
		linphone_address_clean(fr);
		lf->uri = fr;
	}

	vcard = linphone_friend_get_vcard(lf);
	if (!vcard) {
		return;
	}

	linphone_vcard_add_sip_address(vcard, linphone_address_as_string_uri_only(addr));
}
示例#3
0
文件: friend.c 项目: 42p/linphone
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) {
	LinphoneVcard *vcard = NULL;
	char *address = NULL;
	
	if (!lf || !addr) {
		return;
	}
	if (lf->uri == NULL) {
		LinphoneAddress *fr = linphone_address_clone(addr);
		linphone_address_clean(fr);
		lf->uri = fr;
	}

	vcard = lf->vcard;
	if (!vcard) {
		return;
	}

	address = linphone_address_as_string_uri_only(addr);
	linphone_vcard_add_sip_address(vcard, address);
	ms_free(address);
}