From 081dcc327d951af3903b73971abe079f266881cf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 27 Nov 2008 14:38:39 +0100 Subject: [PATCH] obexd: Fix PBAP interface registration --- obexd/client/pbap.c | 44 +++++++++++++++++------------ obexd/client/pbap.h | 31 +++++++++++++++++++++ obexd/client/session.c | 63 +++++++++++++++++++++--------------------- 3 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 obexd/client/pbap.h diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c index c70286e57..e29d3c9ee 100644 --- a/obexd/client/pbap.c +++ b/obexd/client/pbap.c @@ -2,7 +2,9 @@ * * OBEX Client * - * Copyright (C) 2007-2008 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2008 Intel Corporation + * Copyright (C) 2007-2008 Marcel Holtmann + * * * 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 @@ -20,29 +22,23 @@ * */ - #ifdef HAVE_CONFIG_H #include #endif -#include -#include -#include -#include -#include - #include #include #include "session.h" +#include "pbap.h" -static DBusMessage *pbap_pull_phone_book(DBusConnection *connection, +static DBusMessage *pbap_pull_phonebook(DBusConnection *connection, DBusMessage *message, void *user_data) { return NULL; } -static DBusMessage *pbap_set_phone_book(DBusConnection *connection, +static DBusMessage *pbap_set_phonebook(DBusConnection *connection, DBusMessage *message, void *user_data) { return NULL; @@ -60,17 +56,31 @@ static DBusMessage *pbap_pull_vcard_entry(DBusConnection *connection, return NULL; } -GDBusMethodTable pbap_methods[] = { -/* PullPhoneBook input parameters : Name, Filter, Format, MaxListCount, ListStartOffset */ - { "PullPhoneBook", "styqq", "s", pbap_pull_phone_book, +static GDBusMethodTable pbap_methods[] = { + /* PullPhoneBook input parameters : Name, Filter, Format, + MaxListCount, ListStartOffset */ + { "PullPhoneBook", "styqq", "s", pbap_pull_phonebook, G_DBUS_METHOD_FLAG_ASYNC }, -/* SetPhoneBook input parameters : Name */ - { "SetPhoneBook", "s", "", pbap_set_phone_book }, -/* PullvCardListing input parameters : Name, Order, SearchValue, SearchAttribute, MaxListCount, ListStartOffset */ + /* SetPhoneBook input parameters : Name */ + { "SetPhoneBook", "s", "", pbap_set_phonebook }, + /* 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 */ + /* PullPhoneBook input parameters : Name, Filter, Format */ { "PullvCardEntry", "sty", "s", pbap_pull_vcard_entry, G_DBUS_METHOD_FLAG_ASYNC }, { } }; + +gboolean pbap_register_interface(DBusConnection *connection, const char *path, + void *user_data, GDBusDestroyFunction destroy) +{ + return g_dbus_register_interface(connection, path, PBAP_INTERFACE, + pbap_methods, NULL, NULL, user_data, destroy); +} + +void pbap_unregister_interface(DBusConnection *connection, const char *path) +{ + g_dbus_unregister_interface(connection, path, PBAP_INTERFACE); +} diff --git a/obexd/client/pbap.h b/obexd/client/pbap.h new file mode 100644 index 000000000..76d781935 --- /dev/null +++ b/obexd/client/pbap.h @@ -0,0 +1,31 @@ +/* + * + * OBEX Client + * + * Copyright (C) 2007-2008 Intel Corporation + * Copyright (C) 2007-2008 Marcel Holtmann + * + * + * 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 + * + */ + +#include + +#define PBAP_INTERFACE "org.openobex.PhonebookAccess" + +gboolean pbap_register_interface(DBusConnection *connection, const char *path, + void *user_data, GDBusDestroyFunction destroy); +void pbap_unregister_interface(DBusConnection *connection, const char *path); diff --git a/obexd/client/session.c b/obexd/client/session.c index 2e2c15965..30231fd6f 100644 --- a/obexd/client/session.c +++ b/obexd/client/session.c @@ -39,6 +39,7 @@ #include #include +#include "pbap.h" #include "session.h" #define AGENT_INTERFACE "org.openobex.Agent" @@ -50,12 +51,9 @@ #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 { @@ -107,9 +105,19 @@ static void session_unref(struct session_data *session) close(session->sock); if (session->conn) { - if (session->transfer_path) - g_dbus_unregister_interface(session->conn, - session->transfer_path, TRANSFER_INTERFACE); + if (session->transfer_path) { + switch (session->uuid) { + case OBEX_FILETRANS_SVCLASS_ID: + g_dbus_unregister_interface(session->conn, + session->transfer_path, + TRANSFER_INTERFACE); + break; + case PBAP_PSE_SVCLASS_ID: + pbap_unregister_interface(session->conn, + session->transfer_path); + break; + } + } dbus_connection_unref(session->conn); } @@ -1450,7 +1458,6 @@ static void put_xfer_progress(GwObexXfer *xfer, gpointer user_data) return; complete: - if (len == 0) agent_notify_complete(session->conn, session->agent_name, session->agent_path, session->transfer_path); @@ -1566,43 +1573,37 @@ int session_pull(struct session_data *session, int session_register(struct session_data *session) { - GDBusMethodTable *methods; - const char *iface; + gboolean result = FALSE; + + session->path = g_strdup_printf("%s/session%ju", + SESSION_BASEPATH, counter++); + + if (g_dbus_register_interface(session->conn, session->path, + SESSION_INTERFACE, session_methods, + NULL, NULL, session, NULL) == FALSE) + return -EIO; switch (session->uuid) { case OBEX_FILETRANS_SVCLASS_ID: - iface = FTP_INTERFACE; - methods = ftp_methods; + result = g_dbus_register_interface(session->conn, + session->path, FTP_INTERFACE, + ftp_methods, NULL, NULL, session, NULL); break; case PBAP_PSE_SVCLASS_ID: - iface = PBAP_INTERFACE; - methods = pbap_methods; + result = pbap_register_interface(session->conn, + session->path, session, NULL); break; - default: - return -EINVAL; } - session->path = g_strdup_printf("%s/session%ju", - SESSION_BASEPATH, counter++); - - if (g_dbus_register_interface(session->conn, session->path, - SESSION_INTERFACE, - session_methods, NULL, NULL, - session, NULL) == FALSE) - return -EIO; - - if (g_dbus_register_interface(session->conn, session->path, - iface, - methods, NULL, NULL, - session, NULL) == FALSE) { + if (result == FALSE) { g_dbus_unregister_interface(session->conn, - session->path, SESSION_INTERFACE); + session->path, SESSION_INTERFACE); return -EIO; } session->owner_watch = g_dbus_add_disconnect_watch(session->conn, - session->owner, owner_disconnected, session, - NULL); + session->owner, owner_disconnected, + session, NULL); session_ref(session); -- 2.47.3