diff --git a/obexd/src/bluetooth.c b/obexd/src/bluetooth.c
deleted file mode 100644
index 3687473..0000000
--- a/obexd/src/bluetooth.c
+++ /dev/null
-/*
- *
- * OBEX Server
- *
- * Copyright (C) 2007-2010 Nokia Corporation
- * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * 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 <config.h>
-#endif
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <glib.h>
-
-#include <openobex/obex.h>
-
-#include "logging.h"
-#include "bluetooth.h"
-#include "obex.h"
-#include "obex-priv.h"
-#include "dbus.h"
-#include "btio.h"
-#include "service.h"
-
-#define BT_RX_MTU 32767
-#define BT_TX_MTU 32767
-
-static GSList *servers = NULL;
-
-static void confirm_event(GIOChannel *io, void *user_data)
-{
- struct server *server = user_data;
- struct obex_service_driver *driver;
- GError *err = NULL;
- char address[18];
- uint8_t channel;
-
- bt_io_get(io, BT_IO_RFCOMM, &err,
- BT_IO_OPT_DEST, address,
- BT_IO_OPT_CHANNEL, &channel,
- BT_IO_OPT_INVALID);
- if (err) {
- error("%s", err->message);
- g_error_free(err);
- goto drop;
- }
-
- info("New connection from: %s, channel %u", address, channel);
-
- driver = (struct obex_service_driver *) server->drivers->data;
-
- if (driver->service != OBEX_OPP) {
- if (request_service_authorization(server, io, address) < 0)
- goto drop;
-
- return;
- }
-
- if (!bt_io_accept(io, obex_connect_cb, server, NULL, &err)) {
- error("%s", err->message);
- g_error_free(err);
- goto drop;
- }
-
- return;
-
-drop:
- g_io_channel_shutdown(io, TRUE, NULL);
-}
-
-static int server_start(struct server *server)
-{
- GError *err = NULL;
- struct obex_service_driver *driver;
- BtIOSecLevel sec_level;
-
- driver = (struct obex_service_driver *) server->drivers->data;
-
- if (server->secure)
- sec_level = BT_IO_SEC_MEDIUM;
- else
- sec_level = BT_IO_SEC_LOW;
-
- server->io = bt_io_listen(BT_IO_RFCOMM, NULL, confirm_event,
- server, NULL, &err,
- BT_IO_OPT_CHANNEL, driver->channel,
- BT_IO_OPT_SEC_LEVEL, sec_level,
- BT_IO_OPT_INVALID);
- if (!server->io)
- goto failed;
-
- return 0;
-
-failed:
- error("Bluetooth server register failed: %s", err->message);
- g_error_free(err);
-
- return -EINVAL;
-}
-
-static int server_stop(struct server *server)
-{
- if (!server->io)
- return -EINVAL;
-
- if (server->watch) {
- g_source_remove(server->watch);
- server->watch = 0;
- }
-
- g_io_channel_shutdown(server->io, TRUE, NULL);
- g_io_channel_unref(server->io);
- server->io = NULL;
-
- return 0;
-}
-
-static int server_register(uint16_t service, const char *folder,
- gboolean secure, gboolean auto_accept,
- gboolean symlinks, const char *capability)
-{
- struct server *server;
- GSList *drivers;
-
- drivers = obex_service_driver_list(service);
- if (drivers == NULL)
- return -EINVAL;
-
- server = g_new0(struct server, 1);
- server->drivers = drivers;
- server->folder = g_strdup(folder);
- server->auto_accept = auto_accept;
- server->symlinks = symlinks;
- server->capability = g_strdup(capability);
- server->secure = secure;
- server->rx_mtu = BT_RX_MTU;
- server->tx_mtu = BT_TX_MTU;
-
- servers = g_slist_append(servers, server);
-
- return 0;
-}
-
-int bluetooth_init(unsigned int service, const char *folder, gboolean secure,
- gboolean auto_accept, gboolean symlinks,
- const char *capability)
-{
- return server_register(service, folder, secure, auto_accept, symlinks,
- capability);
-}
-
-void bluetooth_exit(void)
-{
- return;
-}
-
-void bluetooth_start(void)
-{
- GSList *l;
-
- for (l = servers; l; l = l->next) {
- struct server *server = l->data;
-
- if (server_start(server) < 0)
- continue;
-
- register_record(server);
- }
-}
-
-void bluetooth_stop(void)
-{
- GSList *l;
-
- for (l = servers; l; l = l->next) {
- struct server *server = l->data;
-
- server_stop(server);
- }
-}
diff --git a/obexd/src/bluetooth.h b/obexd/src/bluetooth.h
deleted file mode 100644
index 1a4e1d8..0000000
--- a/obexd/src/bluetooth.h
+++ /dev/null
-/*
- *
- * OBEX Server
- *
- * Copyright (C) 2007-2010 Nokia Corporation
- * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * 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 <config.h>
-#endif
-
-int bluetooth_init(unsigned int service, const char *folder, gboolean secure,
- gboolean auto_accept, gboolean symlinks,
- const char *capability);
-void bluetooth_exit(void);
-void bluetooth_start(void);
-void bluetooth_stop(void);
diff --git a/obexd/src/main.c b/obexd/src/main.c
index 3408c72..b60fcd2 100644
--- a/obexd/src/main.c
+++ b/obexd/src/main.c
#include <openobex/obex_const.h>
#include "logging.h"
-#include "bluetooth.h"
#include "obexd.h"
#include "obex.h"
#include "obex-priv.h"
+#include "server.h"
#include "service.h"
#define DEFAULT_ROOT_PATH "/tmp"
static GMainLoop *main_loop = NULL;
-static int services = 0;
-static gboolean tty_needs_reinit = FALSE;
-static gboolean tty_open_allowed = TRUE;
-static int signal_pipe[2];
-
-#define TTY_RX_MTU 65535
-#define TTY_TX_MTU 65535
-
-int tty_init(int services, const char *root_path,
- const char *capability, gboolean symlinks,
- const char *devnode)
-{
- struct server *server;
- struct termios options;
- int fd, err, arg;
- glong flags;
- GIOChannel *io = NULL;
-
- tty_needs_reinit = TRUE;
-
- if (!tty_open_allowed)
- return -EACCES;
-
- fd = open(devnode, O_RDWR | O_NOCTTY);
- if (fd < 0)
- return fd;
-
- flags = fcntl(fd, F_GETFL);
- fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
-
- tcgetattr(fd, &options);
- cfmakeraw(&options);
- options.c_oflag &= ~ONLCR;
- tcsetattr(fd, TCSANOW, &options);
-
- arg = fcntl(fd, F_GETFL);
- if (arg < 0) {
- err = -errno;
- goto failed;
- }
-
- arg |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, arg) < 0) {
- err = -errno;
- goto failed;
- }
-
- server = g_new0(struct server, 1);
- server->drivers = obex_service_driver_list(services);
- server->folder = g_strdup(root_path);
- server->auto_accept = TRUE;
- server->capability = g_strdup(capability);
- server->devnode = g_strdup(devnode);
- server->rx_mtu = TTY_RX_MTU;
- server->tx_mtu = TTY_TX_MTU;
- server->symlinks = symlinks;
-
- 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;
- }
-
- tty_needs_reinit = FALSE;
-
- debug("Successfully opened %s", devnode);
-
- return 0;
-
-failed:
- error("tty_init(): %s (%d)", strerror(-err), -err);
- if (io == NULL)
- close(fd);
- return err;
-}
-
-void tty_closed(void)
-{
- tty_needs_reinit = TRUE;
-}
-
static void sig_term(int sig)
{
info("Terminating due to signal %d", sig);
static char *option_root = NULL;
static char *option_root_setup = NULL;
static char *option_capability = NULL;
-static char *option_devnode = NULL;
static gboolean option_autoaccept = FALSE;
static gboolean option_opp = FALSE;
"Enable symlinks on root folder" },
{ "capability", 'c', 0, G_OPTION_ARG_STRING, &option_capability,
"Specify capability file", "FILE" },
- { "tty", 't', 0, G_OPTION_ARG_STRING, &option_devnode,
- "Specify the TTY device", "DEVICE" },
{ "auto-accept", 'a', 0, G_OPTION_ARG_NONE, &option_autoaccept,
"Automatically accept push requests" },
{ "opp", 'o', 0, G_OPTION_ARG_NONE, &option_opp,
return option_symlinks;
}
-static void sig_tty(int sig)
-{
- if (write(signal_pipe[1], &sig, sizeof(sig)) != sizeof(sig))
- error("unable to write to signal pipe");
-}
-
-static gboolean handle_signal(GIOChannel *io, GIOCondition cond,
- void *user_data)
-{
- int sig, fd = g_io_channel_unix_get_fd(io);
-
- if (read(fd, &sig, sizeof(sig)) != sizeof(sig)) {
- error("handle_signal: unable to read signal from pipe");
- return TRUE;
- }
-
- switch (sig) {
- case SIGUSR1:
- debug("SIGUSR1");
- tty_open_allowed = TRUE;
- if (tty_needs_reinit)
- tty_init(services, option_root, option_capability,
- option_symlinks, option_devnode);
- break;
- case SIGHUP:
- debug("SIGHUP");
- tty_open_allowed = FALSE;
- obex_tty_session_stop();
- break;
- default:
- error("handle_signal: got unexpected signal %d", sig);
- break;
- }
-
- return TRUE;
-}
-
-static int devnode_setup(void)
-{
- struct sigaction sa;
- GIOChannel *pipe_io;
-
- if (pipe(signal_pipe) < 0)
- return -errno;
-
- pipe_io = g_io_channel_unix_new(signal_pipe[0]);
- g_io_add_watch(pipe_io, G_IO_IN, handle_signal, NULL);
- g_io_channel_unref(pipe_io);
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = sig_tty;
- sigaction(SIGUSR1, &sa, NULL);
- sigaction(SIGHUP, &sa, NULL);
-
- if (option_pcsuite)
- tty_open_allowed = FALSE;
-
- return tty_init(services, option_root, option_capability,
- option_symlinks, option_devnode);
-}
-
static gboolean is_dir(const char *dir) {
struct stat st;
if (option_capability == NULL)
option_capability = g_strdup(DEFAULT_CAP_FILE);
- if (option_opp == TRUE) {
- services |= OBEX_OPP;
- bluetooth_init(OBEX_OPP, option_root, FALSE,
+ if (option_opp == TRUE)
+ obex_server_init(OBEX_OPP, option_root, FALSE,
option_autoaccept, option_symlinks,
NULL);
- }
- if (option_ftp == TRUE) {
- services |= OBEX_FTP;
- bluetooth_init(OBEX_FTP, option_root, TRUE,
+ if (option_ftp == TRUE)
+ obex_server_init(OBEX_FTP, option_root, TRUE,
option_autoaccept, option_symlinks,
option_capability);
- }
- if (option_pbap == TRUE) {
- services |= OBEX_PBAP;
- bluetooth_init(OBEX_PBAP, NULL, TRUE, FALSE, FALSE, NULL);
- }
+ if (option_pbap == TRUE)
+ obex_server_init(OBEX_PBAP, NULL, TRUE, FALSE, FALSE, NULL);
- if (option_pcsuite == TRUE) {
- services |= OBEX_PCSUITE;
- bluetooth_init(OBEX_PCSUITE, option_root, TRUE,
+ if (option_pcsuite == TRUE)
+ obex_server_init(OBEX_PCSUITE, option_root, TRUE,
option_autoaccept, option_symlinks,
option_capability);
- }
- if (option_syncevolution == TRUE) {
- services |= OBEX_SYNCEVOLUTION;
- bluetooth_init(OBEX_SYNCEVOLUTION, NULL, TRUE, FALSE,
+ if (option_syncevolution == TRUE)
+ obex_server_init(OBEX_SYNCEVOLUTION, NULL, TRUE, FALSE,
FALSE, NULL);
- }
-
- if (option_devnode)
- devnode_setup();
if (!root_folder_setup(option_root, option_root_setup)) {
error("Unable to setup root folder %s", option_root);
g_main_loop_run(main_loop);
- bluetooth_exit();
+ obex_server_exit();
plugin_cleanup();
g_main_loop_unref(main_loop);
- g_free(option_devnode);
g_free(option_capability);
g_free(option_root);
diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index 4eb518c..c5a3fc0 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
#include <openobex/obex.h>
-#include "bluetooth.h"
#include "obexd.h"
#include "obex.h"
#include "obex-priv.h"
+#include "server.h"
#include "dbus.h"
#include "logging.h"
#include "btio.h"
static struct agent *agent = NULL;
-struct pending_request {
- DBusPendingCall *call;
- struct server *server;
- char *adapter_path;
- char address[18];
- unsigned int watch;
- GIOChannel *io;
-};
-
-struct adapter_any {
- char *path; /* Adapter ANY path */
- GSList *servers; /* List of servers to register records */
-};
-
static DBusConnection *connection = NULL;
-static DBusConnection *system_conn = NULL;
-static struct adapter_any *any = NULL;
-static unsigned int listener_id = 0;
static void agent_free(struct agent *agent)
{
{ }
};
-static void add_record_reply(DBusPendingCall *call, void *user_data)
-{
- struct server *server = user_data;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusError derr;
- uint32_t handle;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- handle = 0;
- } else {
- struct obex_service_driver *driver;
-
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_UINT32, &handle,
- DBUS_TYPE_INVALID);
- server->handle = handle;
-
- driver = (struct obex_service_driver *) server->drivers->data;
-
- debug("Registered: %s, handle: 0x%x, folder: %s",
- driver->name, handle, server->folder);
- }
-
- dbus_message_unref(reply);
-}
-
-static int add_record(const char *path,
- const char *xml, struct server *server)
-{
- DBusMessage *msg;
- DBusPendingCall *call;
- int ret = 0;
-
- msg = dbus_message_new_method_call("org.bluez", path,
- "org.bluez.Service", "AddRecord");
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &xml,
- DBUS_TYPE_INVALID);
-
- if (dbus_connection_send_with_reply(system_conn,
- msg, &call, -1) == FALSE) {
- ret = -1;
- goto failed;
- }
-
- dbus_pending_call_set_notify(call, add_record_reply, server, NULL);
- dbus_pending_call_unref(call);
-
-failed:
- dbus_message_unref(msg);
- return ret;
-}
-
-void register_record(struct server *server)
-{
- struct obex_service_driver *driver;
- char *xml;
- int ret;
-
- if (system_conn == NULL)
- return;
-
- if (any->path == NULL) {
- /* Adapter ANY is not available yet: Add record later */
- any->servers = g_slist_append(any->servers, server);
- return;
- }
-
- driver = (struct obex_service_driver *) server->drivers->data;
- xml = g_markup_printf_escaped(driver->record, driver->channel,
- driver->name);
- ret = add_record(any->path, xml, server);
- g_free(xml);
-}
-
-static void find_adapter_any_reply(DBusPendingCall *call, void *user_data)
-{
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- const char *path;
- char *xml;
- GSList *l;
- DBusError derr;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- bluetooth_stop();
- goto done;
- }
-
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
- any->path = g_strdup(path);
-
- for (l = any->servers; l; l = l->next) {
- struct server *server = l->data;
- struct obex_service_driver *driver;
-
- driver = (struct obex_service_driver *) server->drivers->data;
- xml = g_markup_printf_escaped(driver->record, driver->channel,
- driver->name);
- add_record(path, xml, server);
- g_free(xml);
- }
-
-done:
- g_slist_free(any->servers);
- any->servers = NULL;
-
- dbus_message_unref(reply);
-}
-
-static DBusPendingCall *find_adapter(const char *pattern,
- DBusPendingCallNotifyFunction function,
- void *user_data)
-{
- DBusMessage *msg;
- DBusPendingCall *call;
-
- debug("FindAdapter(%s)", pattern);
-
- msg = dbus_message_new_method_call("org.bluez", "/",
- "org.bluez.Manager", "FindAdapter");
- if (!msg)
- return NULL;
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &pattern,
- DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send_with_reply(system_conn, msg, &call, -1)) {
- dbus_message_unref(msg);
- return NULL;
- }
-
- dbus_pending_call_set_notify(call, function, user_data, NULL);
-
- dbus_message_unref(msg);
-
- return call;
-}
-
-static void name_acquired(DBusConnection *conn, void *user_data)
-{
- DBusPendingCall *call;
-
- call = find_adapter("any", find_adapter_any_reply, NULL);
- if (call)
- dbus_pending_call_unref(call);
-
- bluetooth_start();
-}
-
-static void name_released(DBusConnection *conn, void *user_data)
-{
- g_free(any->path);
- any->path = NULL;
- bluetooth_stop();
-}
-
gboolean manager_init(void)
{
DBusError err;
DBG("");
- any = g_new0(struct adapter_any, 1);
-
dbus_error_init(&err);
- connection = g_dbus_setup_private(DBUS_BUS_SESSION, OPENOBEX_SERVICE,
+ connection = g_dbus_setup_bus(DBUS_BUS_SESSION, OPENOBEX_SERVICE,
&err);
if (connection == NULL) {
if (dbus_error_is_set(&err) == TRUE) {
return FALSE;
}
- system_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
- if (system_conn == NULL) {
- dbus_connection_unref(connection);
- connection = NULL;
- return FALSE;
- }
-
- listener_id = g_dbus_add_service_watch(system_conn, "org.bluez",
- name_acquired, name_released, NULL, NULL);
-
return g_dbus_register_interface(connection, OPENOBEX_MANAGER_PATH,
OPENOBEX_MANAGER_INTERFACE,
manager_methods, manager_signals, NULL,
if (agent)
agent_free(agent);
- g_dbus_remove_watch(system_conn, listener_id);
-
- if (any) {
- g_free(any->path);
- g_free(any);
- }
-
- if (system_conn)
- dbus_connection_unref(system_conn);
-
dbus_connection_unref(connection);
}
return 0;
}
-static void service_cancel(struct pending_request *pending)
-{
- DBusMessage *msg;
-
- msg = dbus_message_new_method_call("org.bluez",
- pending->adapter_path,
- "org.bluez.Service",
- "CancelAuthorization");
-
- g_dbus_send_message(system_conn, msg);
-}
-
-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, void *user_data)
-{
- struct pending_request *pending = user_data;
- GIOChannel *io = pending->io;
- struct server *server = pending->server;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusError derr;
- GError *err = NULL;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("RequestAuthorization error: %s, %s",
- derr.name, derr.message);
-
- if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY))
- service_cancel(pending);
-
- dbus_error_free(&derr);
- g_io_channel_shutdown(io, TRUE, NULL);
- goto done;
- }
-
- debug("RequestAuthorization succeeded");
-
- if (!bt_io_accept(io, obex_connect_cb, server, NULL, &err)) {
- error("%s", err->message);
- g_error_free(err);
- g_io_channel_shutdown(io, TRUE, NULL);
- }
-
-done:
- g_source_remove(pending->watch);
- pending_request_free(pending);
- dbus_message_unref(reply);
-}
-
-static gboolean service_error(GIOChannel *io, GIOCondition cond,
- void *user_data)
-{
- struct pending_request *pending = user_data;
-
- service_cancel(pending);
-
- dbus_pending_call_cancel(pending->call);
-
- pending_request_free(pending);
-
- return FALSE;
-}
-
-static void find_adapter_reply(DBusPendingCall *call, void *user_data)
-{
- struct pending_request *pending = user_data;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusMessage *msg;
- DBusPendingCall *pcall;
- const char *path, *paddr = pending->address;
- DBusError derr;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- goto failed;
- }
-
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- debug("FindAdapter -> %s", path);
- pending->adapter_path = g_strdup(path);
- dbus_message_unref(reply);
-
- msg = dbus_message_new_method_call("org.bluez", path,
- "org.bluez.Service", "RequestAuthorization");
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &paddr,
- DBUS_TYPE_UINT32, &pending->server->handle,
- DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send_with_reply(system_conn,
- msg, &pcall, TIMEOUT)) {
- dbus_message_unref(msg);
- goto failed;
- }
-
- dbus_message_unref(msg);
-
- debug("RequestAuthorization(%s, %x)", paddr, pending->server->handle);
-
- if (!dbus_pending_call_set_notify(pcall, service_reply, pending,
- NULL)) {
- dbus_pending_call_unref(pcall);
- goto failed;
- }
-
- dbus_pending_call_unref(pending->call);
- pending->call = pcall;
-
- /* Catches errors before authorization response comes */
- pending->watch = g_io_add_watch(pending->io,
- G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- service_error, pending);
-
- return;
-
-failed:
- g_io_channel_shutdown(pending->io, TRUE, NULL);
- pending_request_free(pending);
-}
-
-int request_service_authorization(struct server *server, GIOChannel *io,
- const char *address)
-{
- struct pending_request *pending;
- char source[18];
- GError *err = NULL;
-
- if (system_conn == NULL || any->path == NULL)
- return -1;
-
- bt_io_get(io, BT_IO_RFCOMM, &err,
- BT_IO_OPT_SOURCE, source,
- BT_IO_OPT_INVALID);
- if (err) {
- error("%s", err->message);
- g_error_free(err);
- return -EINVAL;
- }
-
- pending = g_new0(struct pending_request, 1);
- pending->call = find_adapter(source, find_adapter_reply, pending);
- if (!pending->call) {
- g_free(pending);
- return -ENOMEM;
- }
-
- pending->server = server;
- pending->io = g_io_channel_ref(io);
- memcpy(pending->address, address, sizeof(pending->address));
-
-
- return 0;
-}
-
void manager_register_session(struct obex_session *os)
{
char *path = g_strdup_printf("/session%u", os->cid);
diff --git a/obexd/src/obex-priv.h b/obexd/src/obex-priv.h
index 265ac8c..c9be1c5 100644
--- a/obexd/src/obex-priv.h
+++ b/obexd/src/obex-priv.h
*
*/
-struct server {
- gboolean auto_accept;
- char *folder;
- gboolean symlinks;
- char *capability;
- uint32_t handle;
- char *devnode;
- gboolean secure;
- GIOChannel *io;
- unsigned int watch;
- uint16_t tx_mtu;
- uint16_t rx_mtu;
- GSList *drivers;
-};
-
struct obex_session {
GIOChannel *io;
uint32_t cid;
gboolean aborted;
struct obex_service_driver *service;
void *service_data;
- struct server *server;
+ struct obex_server *server;
gboolean checked;
obex_t *obex;
obex_object_t *obj;
gboolean finished;
};
-int obex_session_start(GIOChannel *io, struct server *server);
-void server_free(struct server *server);
-
-void register_record(struct server *server);
-int request_service_authorization(struct server *server, GIOChannel *io,
- const char *address);
+int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
+ struct obex_server *server);
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 337c834..1679ec7 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
#include "logging.h"
#include "obex.h"
#include "obex-priv.h"
+#include "server.h"
#include "dbus.h"
#include "mimetype.h"
#include "service.h"
+#include "transport.h"
#include "btio.h"
/* Default MTU's */
}
}
-void server_free(struct server *server)
-{
- g_free(server->folder);
- g_free(server->capability);
- g_free(server->devnode);
- g_free(server);
-}
-
static void obex_handle_destroy(void *user_data)
{
struct obex_session *os;
OBEX_Cleanup(obex);
}
-static gboolean tty_reinit(void *data)
-{
- struct server *server = data;
- GSList *l;
- unsigned int services = 0;
-
- for (l = server->drivers; l; l = l->next) {
- struct obex_service_driver *driver = l->data;
-
- services |= driver->service;
- }
-
- tty_init(services, server->folder, server->capability,
- server->symlinks, server->devnode);
-
- server_free(server);
-
- return FALSE;
-}
-
static gboolean obex_handle_input(GIOChannel *io,
GIOCondition cond, void *user_data)
{
obex_t *obex = user_data;
- struct obex_session *os = OBEX_GetUserData(obex);
if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
error("obex_handle_input: poll event %s%s%s",
(cond & G_IO_HUP) ? "HUP " : "",
(cond & G_IO_ERR) ? "ERR " : "",
(cond & G_IO_NVAL) ? "NVAL " : "");
- goto failed;
+ return FALSE;
}
if (OBEX_HandleInput(obex, 1) < 0) {
error("Handle input error");
- goto failed;
+ return FALSE;
}
return TRUE;
-
-failed:
- if (os->server->devnode) {
- if (cond & G_IO_NVAL)
- tty_closed();
- else
- g_idle_add(tty_reinit, os->server);
- }
-
- return FALSE;
-}
-
-void obex_connect_cb(GIOChannel *io, GError *err, void *user_data)
-{
- struct server *server = user_data;
-
- if (err) {
- error("%s", err->message);
- g_io_channel_shutdown(io, TRUE, NULL);
- return;
- }
-
- if (obex_session_start(io, server) < 0)
- g_io_channel_shutdown(io, TRUE, NULL);
}
-int obex_session_start(GIOChannel *io, struct server *server)
+int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
+ struct obex_server *server)
{
struct obex_session *os;
obex_t *obex;
os = g_new0(struct obex_session, 1);
- os->service = obex_service_driver_find(server->drivers, NULL, 0,
- NULL, 0);
+ os->service = obex_service_driver_find(server->drivers, NULL,
+ 0, NULL, 0);
os->server = server;
- os->rx_mtu = server->rx_mtu ? server->rx_mtu : DEFAULT_RX_MTU;
- os->tx_mtu = server->tx_mtu ? server->tx_mtu : DEFAULT_TX_MTU;
+ os->rx_mtu = rx_mtu != 0 ? rx_mtu : DEFAULT_RX_MTU;
+ os->tx_mtu = tx_mtu != 0 ? tx_mtu : DEFAULT_TX_MTU;
os->size = OBJECT_SIZE_DELETE;
obex = OBEX_Init(OBEX_TRANS_FD, obex_event, 0);
return 0;
}
-int obex_tty_session_stop(void)
-{
- GSList *l;
-
- for (l = sessions; l != NULL; l = l->next) {
- struct obex_session *os = l->data;
-
- if (os->server->devnode && os->io)
- g_io_channel_shutdown(os->io, TRUE, NULL);
- }
-
- return 0;
-}
-
const char *obex_get_name(struct obex_session *os)
{
return os->name;
diff --git a/obexd/src/obex.h b/obexd/src/obex.h
index 7f65d9c..081e03b 100644
--- a/obexd/src/obex.h
+++ b/obexd/src/obex.h
#define OBJECT_SIZE_UNKNOWN -1
#define OBJECT_SIZE_DELETE -2
-#define OBEX_OPP (1 << 0)
+#define OBEX_OPP (1 << 1)
#define OBEX_FTP (1 << 2)
#define OBEX_BIP (1 << 3)
#define OBEX_PBAP (1 << 4)
const char *obex_option_root_folder(void);
gboolean obex_option_symlinks(void);
-int tty_init(int service, const char *folder, const char *capability,
- gboolean symlinks, const char *devnode);
-int obex_tty_session_stop(void);
-void tty_closed(void);
-
/* Just a thin wrapper around memcmp to deal with NULL values */
int memcmp0(const void *a, const void *b, size_t n);
diff --git a/obexd/src/server.c b/obexd/src/server.c
index 4ec5a86..1f96644 100644
--- a/obexd/src/server.c
+++ b/obexd/src/server.c
int obex_server_new_connection(struct obex_server *server, GIOChannel *io,
uint16_t tx_mtu, uint16_t rx_mtu)
{
- return 0;
+ return obex_session_start(io, tx_mtu, rx_mtu, server);
}