From 1d8b84a34d2a7e63aea1ac3108e6279a152640b5 Mon Sep 17 00:00:00 2001 From: Forrest Zhao Date: Fri, 12 Dec 2008 06:27:23 +0800 Subject: [PATCH] obexd: add support for PBAP Pullvcardentry --- obexd/plugins/ebook.c | 22 ++++++++++++++++++++++ obexd/src/pbap.c | 26 ++++++++++++++++++++++++++ obexd/src/phonebook.c | 10 ++++++++++ obexd/src/phonebook.h | 5 ++++- 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/obexd/plugins/ebook.c b/obexd/plugins/ebook.c index 96990ea7b..da8bc9b22 100644 --- a/obexd/plugins/ebook.c +++ b/obexd/plugins/ebook.c @@ -125,12 +125,34 @@ static int ebook_pullvcardlisting(struct phonebook_context *context, return 0; } +static int ebook_pullvcardentry(struct phonebook_context *context, + gchar *objname, guint64 filter, guint8 format) +{ + EBook *book; + EBookQuery *query; + + DBG("context %p", context); + + phonebook_ref(context); + + book = e_book_new_default_addressbook(NULL); + + e_book_open(book, FALSE, NULL); + + query = e_book_query_any_field_contains(""); + + e_book_async_get_contacts(book, query, ebooklist_cb, context); + + return 0; +} + static struct phonebook_driver ebook_driver = { .name = "ebook", .create = ebook_create, .destroy = ebook_destroy, .pullphonebook = ebook_pullphonebook, .pullvcardlisting = ebook_pullvcardlisting, + .pullvcardentry = ebook_pullvcardentry, }; static int ebook_init(void) diff --git a/obexd/src/pbap.c b/obexd/src/pbap.c index d9ebdb020..70f3d8ee1 100644 --- a/obexd/src/pbap.c +++ b/obexd/src/pbap.c @@ -37,6 +37,7 @@ #define PHONEBOOK_TYPE "x-bt/phonebook" #define VCARDLISTING_TYPE "x-bt/vcard-listing" +#define VCARDENTRY_TYPE "x-bt/vcard" #define ORDER_TAG 0x01 #define SEARCHVALUE_TAG 0x02 @@ -302,6 +303,29 @@ done: return err; } +static int pbap_pullvcardentry(obex_t *obex, obex_object_t *obj) +{ + struct obex_session *session = OBEX_GetUserData(obex); + gchar *fullname; + struct apparam_field apparam; + int err; + + memset(&apparam, 0, sizeof(struct apparam_field)); + err = pbap_parse_apparam_header(obex, obj, &apparam); + if (err < 0) + return err; + + fullname = g_build_filename(session->current_folder, + session->name, NULL); + err = phonebook_pullvcardentry(session->pbctx, fullname, + apparam.filter, apparam.format); + + g_free(apparam.searchval); + g_free(fullname); + return err; +} + + void pbap_get(obex_t *obex, obex_object_t *obj) { struct obex_session *session = OBEX_GetUserData(obex); @@ -321,6 +345,8 @@ void pbap_get(obex_t *obex, obex_object_t *obj) err = pbap_pullphonebook(obex, obj, &addbody); else if (g_str_equal(session->type, VCARDLISTING_TYPE) == TRUE) err = pbap_pullvcardlisting(obex, obj, &addbody); + else if (g_str_equal(session->type, VCARDENTRY_TYPE) == TRUE) + err = pbap_pullvcardentry(obex, obj); else goto fail; diff --git a/obexd/src/phonebook.c b/obexd/src/phonebook.c index 239fbafc8..ab97b97d0 100644 --- a/obexd/src/phonebook.c +++ b/obexd/src/phonebook.c @@ -128,6 +128,16 @@ int phonebook_pullvcardlisting(struct phonebook_context *context, liststartoffset, phonebooksize, newmissedcalls); } +int phonebook_pullvcardentry(struct phonebook_context *context, gchar *objname, + guint64 filter, guint8 format) +{ + if (!context->driver->pullvcardentry) + return -1; + + return context->driver->pullvcardentry(context, objname, filter, + format); +} + /* if buf is NULL or size is 0, this indicate that no more result will * be returned by PBAP plugin * */ diff --git a/obexd/src/phonebook.h b/obexd/src/phonebook.h index 311213c04..4a270e8d9 100644 --- a/obexd/src/phonebook.h +++ b/obexd/src/phonebook.h @@ -58,6 +58,8 @@ extern int phonebook_pullvcardlisting(struct phonebook_context *context, guint8 searchattrib, guint16 maxlistcount, guint16 liststartoffset, guint16 *phonebooksize, guint8 *newmissedcalls); +extern int phonebook_pullvcardentry(struct phonebook_context *context, + gchar *objname, guint64 filter, guint8 format); extern void phonebook_return(struct phonebook_context *context, char *buf, int size); @@ -74,7 +76,8 @@ struct phonebook_driver { guint8 searchattrib, guint16 maxlistcount, guint16 liststartoffset, guint16 *phonebooksize, guint8 *newmissedcalls); - int (*pullvcardentry) (struct phonebook_context *context); + int (*pullvcardentry) (struct phonebook_context *context, + gchar *objname, guint64 filter, guint8 format); }; extern int phonebook_driver_register(struct phonebook_driver *driver);