diff --git a/obexd/src/bluetooth.c b/obexd/src/bluetooth.c
index 990a108..5c43d2b 100644
--- a/obexd/src/bluetooth.c
+++ b/obexd/src/bluetooth.c
}
info("New connection from: %s, channel %u", address, channel);
- g_io_channel_set_close_on_unref(io, FALSE);
if (server->services != OBEX_OPP) {
if (request_service_authorization(server, io, address) < 0)
diff --git a/obexd/src/main.c b/obexd/src/main.c
index f6fac74..84f318e 100644
--- a/obexd/src/main.c
+++ b/obexd/src/main.c
struct termios options;
int fd, err, arg;
glong flags;
+ GIOChannel *io = NULL;
tty_needs_reinit = TRUE;
server->rx_mtu = TTY_RX_MTU;
server->tx_mtu = TTY_TX_MTU;
- err = obex_session_start(fd, server);
+ io = g_io_channel_unix_new(fd);
+ g_io_channel_set_close_on_unref(io, TRUE);
+
+ err = obex_session_start(io, server);
+ g_io_channel_unref(io);
+
if (err < 0) {
server_free(server);
goto failed;
- } else
- tty_needs_reinit = FALSE;
+ }
+
+ tty_needs_reinit = FALSE;
debug("Successfully opened %s", devnode);
failed:
error("tty_init(): %s (%d)", strerror(-err), -err);
- close(fd);
+ if (io == NULL)
+ close(fd);
return err;
}
diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index 90f2663..0514b10 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
static struct agent *agent = NULL;
struct pending_request {
+ DBusPendingCall *call;
struct server *server;
gchar *adapter_path;
char address[18];
dbus_message_unref(reply);
}
-static void find_adapter(const char *pattern,
+static DBusPendingCall *find_adapter(const char *pattern,
DBusPendingCallNotifyFunction function,
gpointer user_data)
{
dbus_connection_send_with_reply(system_conn, msg, &call, -1);
dbus_pending_call_set_notify(call, function, user_data, NULL);
- dbus_pending_call_unref(call);
dbus_message_unref(msg);
+
+ return call;
}
-static gboolean find_adapter_any(gpointer user_data)
+static gboolean find_adapter_any_idle(gpointer user_data)
{
- find_adapter("any", find_adapter_any_reply, user_data);
+ DBusPendingCall *call;
+
+ call = find_adapter("any", find_adapter_any_reply, NULL);
+ dbus_pending_call_unref(call);
return FALSE;
}
static void name_acquired(DBusConnection *conn, void *user_data)
{
- find_adapter_any(NULL);
+ DBusPendingCall *call;
+
+ call = find_adapter("any", find_adapter_any_reply, NULL);
+ dbus_pending_call_unref(call);
+
bluetooth_start();
}
listener_id = g_dbus_add_service_watch(system_conn, "org.bluez",
name_acquired, name_released, NULL, NULL);
- g_idle_add(find_adapter_any, NULL);
+ g_idle_add(find_adapter_any_idle, NULL);
return g_dbus_register_interface(connection, OPENOBEX_MANAGER_PATH,
OPENOBEX_MANAGER_INTERFACE,
void obex_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
struct server *server = user_data;
- gint sk;
if (err) {
error("%s", err->message);
+ g_io_channel_shutdown(io, TRUE, NULL);
return;
}
- sk = g_io_channel_unix_get_fd(io);
-
- if (obex_session_start(sk, server) < 0)
+ if (obex_session_start(io, server) < 0)
g_io_channel_shutdown(io, TRUE, NULL);
}
+static void pending_request_free(struct pending_request *pending)
+{
+ if (pending->call)
+ dbus_pending_call_unref(pending->call);
+ g_io_channel_unref(pending->io);
+ g_free(pending->adapter_path);
+ g_free(pending);
+}
+
static void service_reply(DBusPendingCall *call, gpointer user_data)
{
struct pending_request *pending = user_data;
}
done:
- if (pending->watch)
- g_source_remove(pending->watch);
- g_free(pending->adapter_path);
- g_free(pending);
+ g_source_remove(pending->watch);
+ pending_request_free(pending);
dbus_message_unref(reply);
}
{
struct pending_request *pending = user_data;
- pending->watch = 0;
-
service_cancel(pending);
+ dbus_pending_call_cancel(pending->call);
+
+ pending_request_free(pending);
+
return FALSE;
}
DBusMessage *reply = dbus_pending_call_steal_reply(call);
DBusMessage *msg;
DBusPendingCall *pcall;
- const char *paddr = pending->address;
- const char *path;
+ const char *path, *paddr = pending->address;
DBusError derr;
dbus_error_init(&derr);
debug("RequestAuthorization(%s, %x)", paddr, pending->server->handle);
- if (!dbus_pending_call_set_notify(pcall, service_reply, pending, NULL))
+ if (!dbus_pending_call_set_notify(pcall, service_reply, pending,
+ NULL)) {
+ dbus_pending_call_unref(pcall);
goto failed;
+ }
- dbus_pending_call_unref(pcall);
+ dbus_pending_call_unref(pending->call);
+ pending->call = pcall;
/* Catches errors before authorization response comes */
- pending->watch = g_io_add_watch_full(pending->io, G_PRIORITY_DEFAULT,
+ pending->watch = g_io_add_watch(pending->io,
G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- service_error, pending, NULL);
- g_io_channel_unref(pending->io);
+ service_error, pending);
return;
failed:
- g_free(pending->adapter_path);
g_io_channel_shutdown(pending->io, TRUE, NULL);
- g_io_channel_unref(pending->io);
- g_free(pending);
+ pending_request_free(pending);
}
gint request_service_authorization(struct server *server, GIOChannel *io,
pending->io = g_io_channel_ref(io);
memcpy(pending->address, address, sizeof(pending->address));
- find_adapter(source, find_adapter_reply, pending);
+ pending->call = find_adapter(source, find_adapter_reply, pending);
return 0;
}
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 9dd302f..490b537 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
return FALSE;
}
-gint obex_session_start(gint fd, struct server *server)
+gint obex_session_start(GIOChannel *io, struct server *server)
{
struct obex_session *os;
- GIOChannel *io;
obex_t *obex;
- gint ret;
+ gint ret, fd;
os = g_new0(struct obex_session, 1);
OBEX_SetTransportMTU(obex, os->rx_mtu, os->tx_mtu);
+ fd = g_io_channel_unix_get_fd(io);
+
ret = FdOBEX_TransportSetup(obex, fd, fd, 0);
if (ret < 0) {
obex_session_free(os);
return ret;
}
- io = g_io_channel_unix_new(fd);
g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
obex_handle_input, obex, obex_handle_destroy);
- g_io_channel_set_close_on_unref(io, TRUE);
- os->io = io;
+ os->io = g_io_channel_ref(io);
sessions = g_slist_prepend(sessions, os);
diff --git a/obexd/src/obex.h b/obexd/src/obex.h
index 49f8b25..2f36597 100644
--- a/obexd/src/obex.h
+++ b/obexd/src/obex.h
gboolean finished;
};
-gint obex_session_start(gint fd, struct server *server);
+gint obex_session_start(GIOChannel *io, struct server *server);
gint obex_tty_session_stop(void);
void opp_get(obex_t *obex, obex_object_t *obj);