Пример #1
0
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);
		}
	}
}
Пример #2
0
void linphone_friend_list_set_uri(LinphoneFriendList *list, const char *uri) {
	if (list->uri != NULL) {
		ms_free(list->uri);
		list->uri = NULL;
	}
	if (uri != NULL) {
		list->uri = ms_strdup(uri);
		linphone_core_store_friends_list_in_db(list->lc, list);
	}
}
Пример #3
0
void linphone_friend_list_set_display_name(LinphoneFriendList *list, const char *display_name) {
	if (list->display_name != NULL) {
		ms_free(list->display_name);
		list->display_name = NULL;
	}
	if (display_name != NULL) {
		list->display_name = ms_strdup(display_name);
		linphone_core_store_friends_list_in_db(list->lc, list);
	}
}
Пример #4
0
int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer) {
	bctbx_list_t *vcards = NULL;
	bctbx_list_t *vcards_iterator = NULL;
	int count = 0;

#ifndef VCARD_ENABLED
	ms_error("vCard support wasn't enabled at compilation time");
	return -1;
#endif
	if (!list) {
		ms_error("Can't import into a NULL list");
		return -1;
	}
	
	vcards = linphone_vcard_list_from_vcard4_buffer(list->lc->vcard_context, vcard_buffer);
	vcards_iterator = vcards;
	if (!vcards) {
		ms_error("Failed to parse the buffer");
		return -1;
	}

	while (vcards_iterator != NULL && vcards_iterator->data != NULL) {
		LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data;
		LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
		if (lf) {
			if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) {
				count++;
			}
			linphone_friend_unref(lf);
		} else {
			linphone_vcard_free(vcard);
		}
		vcards_iterator = bctbx_list_next(vcards_iterator);
	}
	bctbx_list_free(vcards);
	linphone_core_store_friends_list_in_db(list->lc, list);
	return count;
}
Пример #5
0
void linphone_friend_list_update_revision(LinphoneFriendList *list, int rev) {
	list->revision = rev;
	linphone_core_store_friends_list_in_db(list->lc, list);
}