From b8b6009552ce76000247d61ced8b46be981e82b9 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Oct 2008 23:23:11 +0200 Subject: [PATCH] obexd: Add initial steps for phonebook retrieval --- obexd/plugins/ebook.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/obexd/plugins/ebook.c b/obexd/plugins/ebook.c index 504efee52..7c78a5722 100644 --- a/obexd/plugins/ebook.c +++ b/obexd/plugins/ebook.c @@ -25,6 +25,8 @@ #include #endif +#include + #include #include #include @@ -43,10 +45,52 @@ static void ebook_destroy(struct phonebook_context *context) DBG("context %p", context); } +static int ebook_pullphonebook(struct phonebook_context *context) +{ + EBook *book; + EBookQuery *query; + GList *contacts = NULL; + GString *pb; + gchar *result; + + DBG("context %p", context); + + book = e_book_new_default_addressbook(NULL); + + e_book_open(book, FALSE, NULL); + + query = e_book_query_any_field_contains(""); + + e_book_get_contacts(book, query, &contacts, NULL); + + pb = g_string_new(NULL); + + for (; contacts != NULL; contacts = g_list_next(contacts)) { + EContact *contact = E_CONTACT(contacts->data); + char *vcard; + + vcard = e_vcard_to_string(E_VCARD(contact), + EVC_FORMAT_VCARD_30); + g_string_append_printf(pb, "%s\n", vcard); + g_free(vcard); + } + + result = g_string_free(pb, FALSE); + phonebook_return(context, result, strlen(result)); + g_free(result); + + e_book_query_unref(query); + + g_object_unref(book); + + return 0; +} + static struct phonebook_driver ebook_driver = { .name = "ebook", .create = ebook_create, .destroy = ebook_destroy, + .pullphonebook = ebook_pullphonebook, }; static int ebook_init(void) -- 2.47.3