From cf27f8d3239b58d517a065b7d1dc6580a9d72ae2 Mon Sep 17 00:00:00 2001 From: Raymond Liu Date: Thu, 27 Nov 2008 12:44:21 +0800 Subject: [PATCH] obexd: Add framework code for pbap client --- obexd/client/main.c | 4 +-- obexd/client/pbap.c | 76 ++++++++++++++++++++++++++++++++++++++++++ obexd/client/session.c | 47 ++++++++++++++++++++------ 3 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 obexd/client/pbap.c diff --git a/obexd/client/main.c b/obexd/client/main.c index 9595af9e0..0ce274ac9 100644 --- a/obexd/client/main.c +++ b/obexd/client/main.c @@ -180,7 +180,7 @@ static DBusMessage *send_files(DBusConnection *connection, data->agent = g_strdup(agent); data->files = files; - if (session_create(NULL, dest, NULL, create_callback, data) == 0) + if (session_create(NULL, dest, "OPP", create_callback, data) == 0) return NULL; g_ptr_array_free(data->files, TRUE); @@ -256,7 +256,7 @@ static DBusMessage *pull_business_card(DBusConnection *connection, data->message = dbus_message_ref(message); data->sender = g_strdup(dbus_message_get_sender(message)); - if (session_create(source, dest, NULL, + if (session_create(source, dest, "OPP", pull_session_callback, data) == 0) return NULL; diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c new file mode 100644 index 000000000..c70286e57 --- /dev/null +++ b/obexd/client/pbap.c @@ -0,0 +1,76 @@ +/* + * + * OBEX Client + * + * Copyright (C) 2007-2008 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include +#include + +#include "session.h" + +static DBusMessage *pbap_pull_phone_book(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + return NULL; +} + +static DBusMessage *pbap_set_phone_book(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + return NULL; +} + +static DBusMessage *pbap_pull_vcard_listing(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + return NULL; +} + +static DBusMessage *pbap_pull_vcard_entry(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + return NULL; +} + +GDBusMethodTable pbap_methods[] = { +/* PullPhoneBook input parameters : Name, Filter, Format, MaxListCount, ListStartOffset */ + { "PullPhoneBook", "styqq", "s", pbap_pull_phone_book, + G_DBUS_METHOD_FLAG_ASYNC }, +/* SetPhoneBook input parameters : Name */ + { "SetPhoneBook", "s", "", pbap_set_phone_book }, +/* PullvCardListing input parameters : Name, Order, SearchValue, SearchAttribute, MaxListCount, ListStartOffset */ + { "PullvCardListing", "sysyqq", "s", pbap_pull_vcard_listing, + G_DBUS_METHOD_FLAG_ASYNC }, +/* PullPhoneBook input parameters : Name, Filter, Format */ + { "PullvCardEntry", "sty", "s", pbap_pull_vcard_entry, + G_DBUS_METHOD_FLAG_ASYNC }, + { } +}; diff --git a/obexd/client/session.c b/obexd/client/session.c index 03ddffd50..2e2c15965 100644 --- a/obexd/client/session.c +++ b/obexd/client/session.c @@ -50,9 +50,12 @@ #define SESSION_BASEPATH "/org/openobex" #define FTP_INTERFACE "org.openobex.FileTransfer" +#define PBAP_INTERFACE "org.openobex.PhonebookAccess" #define DEFAULT_BUFFER_SIZE 4096 +extern GDBusMethodTable pbap_methods[]; + static guint64 counter = 0; struct callback_data { @@ -388,12 +391,19 @@ int session_create(const char *source, str2ba(destination, &session->dst); - if (target != NULL) { + if (!g_ascii_strncasecmp(target, "OPP", 3)) { + session->uuid = OBEX_OBJPUSH_SVCLASS_ID; + } else if (!g_ascii_strncasecmp(target, "FTP", 3)) { session->uuid = OBEX_FILETRANS_SVCLASS_ID; session->target = OBEX_FTP_UUID; session->target_len = OBEX_FTP_UUID_LEN; - } else - session->uuid = OBEX_OBJPUSH_SVCLASS_ID; + } else if (!g_ascii_strncasecmp(target, "PBAP", 4)) { + session->uuid = PBAP_PSE_SVCLASS_ID; + session->target = OBEX_PBAP_UUID; + session->target_len = OBEX_PBAP_UUID_LEN; + } else { + return -EINVAL; + } callback = g_try_malloc0(sizeof(*callback)); if (callback == NULL) { @@ -1156,6 +1166,7 @@ complete: int session_get(struct session_data *session, const char *type, const char *filename, const char *targetname, + const guint8 *apparam, gint apparam_size, session_callback_t func) { struct callback_data *callback; @@ -1175,7 +1186,17 @@ int session_get(struct session_data *session, const char *type, fprintf(stderr, "open(): %s(%d)\n", strerror(err), err); return -err; } + } + session->transfer_path = register_transfer(session->conn, session); + if (session->transfer_path == NULL) { + if (fd) + close(fd); + + return -EIO; + } + + if (!g_str_equal(type, "x-obex/folder-listing")) { session->transfer_path = register_transfer(session->conn, session); if (session->transfer_path == NULL) { if (fd) @@ -1193,8 +1214,8 @@ int session_get(struct session_data *session, const char *type, session_ref(session); - xfer = gw_obex_get_async(session->obex, - filename, type, NULL); + xfer = gw_obex_get_async_with_apparam(session->obex, + filename, type, apparam, apparam_size, NULL); if (xfer == NULL) { close(session->fd); session_unref(session); @@ -1212,11 +1233,11 @@ int session_get(struct session_data *session, const char *type, callback->session = session; callback->func = func; - if (type && g_str_equal(type, "x-obex/folder-listing")) - gw_obex_xfer_set_callback(xfer, get_xfer_listing_progress, - callback); - else + if (type == NULL) gw_obex_xfer_set_callback(xfer, get_xfer_progress, callback); + else + gw_obex_xfer_set_callback(xfer, get_xfer_listing_progress, + callback); session->xfer = xfer; @@ -1283,7 +1304,7 @@ static DBusMessage *list_folder(DBusConnection *connection, "Transfer in progress"); if (session_get(session, "x-obex/folder-listing", - NULL, NULL, list_folder_callback) < 0) + NULL, NULL, NULL, 0, list_folder_callback) < 0) return g_dbus_create_error(message, "org.openobex.Error.Failed", "Failed"); @@ -1313,7 +1334,7 @@ static DBusMessage *get_file(DBusConnection *connection, "org.openobex.Error.InvalidArguments", NULL); if (session_get(session, NULL, source_file, - target_file, get_file_callback) < 0) + target_file, NULL, 0, get_file_callback) < 0) return g_dbus_create_error(message, "org.openobex.Error.Failed", "Failed"); @@ -1553,6 +1574,10 @@ int session_register(struct session_data *session) iface = FTP_INTERFACE; methods = ftp_methods; break; + case PBAP_PSE_SVCLASS_ID: + iface = PBAP_INTERFACE; + methods = pbap_methods; + break; default: return -EINVAL; } -- 2.47.3