diff --git a/obexd/client/main.c b/obexd/client/main.c
index ea36115..39f65bb 100644
--- a/obexd/client/main.c
+++ b/obexd/client/main.c
#include <glib.h>
#include <gdbus.h>
+#include "session.h"
+
#define CLIENT_SERVICE "org.openobex.client"
#define CLIENT_INTERFACE "org.openobex.Client"
#define CLIENT_PATH "/"
+struct send_data {
+ DBusConnection *connection;
+ DBusMessage *message;
+ gchar *agent;
+ gchar *file;
+};
+
+static void create_callback(struct session_data *session, void *user_data)
+{
+ struct send_data *data = user_data;
+
+ g_dbus_send_reply(data->connection, data->message, DBUS_TYPE_INVALID);
+
+ dbus_message_unref(data->message);
+ dbus_connection_unref(data->connection);
+
+ session_set_agent(session, data->agent);
+ g_free(data->agent);
+
+ session_send(session, data->file);
+ g_free(data->file);
+
+ g_free(data);
+}
+
static DBusMessage *send_files(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
DBusMessageIter iter, array;
- const char *agent;
+ struct send_data *data;
+ const char *agent, *dest = NULL, *file = NULL;
dbus_message_iter_init(message, &iter);
-
dbus_message_iter_recurse(&iter, &array);
while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
- const char *key, *val;
+ const char *key;
dbus_message_iter_recurse(&array, &entry);
dbus_message_iter_get_basic(&entry, &key);
dbus_message_iter_next(&entry);
-
dbus_message_iter_recurse(&entry, &value);
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_STRING:
- dbus_message_iter_get_basic(&value, &val);
- printf("%s %s\n", key, val);
+ if (g_str_equal(key, "Destination") == TRUE)
+ dbus_message_iter_get_basic(&value, &dest);
break;
}
}
dbus_message_iter_next(&iter);
-
dbus_message_iter_recurse(&iter, &array);
while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
- const char *file;
-
- dbus_message_iter_get_basic(&array, &file);
- printf(" Filename %s\n", file);
+ if (file == NULL)
+ dbus_message_iter_get_basic(&array, &file);
dbus_message_iter_next(&array);
}
dbus_message_iter_next(&iter);
-
dbus_message_iter_get_basic(&iter, &agent);
- printf(" Agent %s\n", agent);
- return dbus_message_new_method_return(message);
+ if (dest == NULL)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.InvalidArguments", NULL);
+
+ data = g_try_malloc0(sizeof(*data));
+ if (data == NULL)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.NoMemory", NULL);
+
+ data->connection = dbus_connection_ref(connection);
+ data->message = dbus_message_ref(message);
+ data->agent = g_strdup(agent);
+ data->file = g_strdup(file);
+
+ if (session_create(NULL, dest, NULL, create_callback, data) == 0)
+ return NULL;
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+ g_free(data->agent);
+ g_free(data->file);
+ g_free(data);
+
+ return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
}
static GDBusMethodTable client_methods[] = {
- { "SendFiles", "a{sv}aso", "",send_files },
+ { "SendFiles", "a{sv}aso", "", send_files, G_DBUS_METHOD_FLAG_ASYNC },
{ }
};
diff --git a/obexd/client/session.c b/obexd/client/session.c
new file mode 100644
index 0000000..28993e0
--- /dev/null
+++ b/obexd/client/session.c
+/*
+ *
+ * OBEX Client
+ *
+ * Copyright (C) 2007-2008 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 <errno.h>
+
+#include <glib.h>
+
+#include "session.h"
+
+int session_create(const char *source,
+ const char *destination, const char *target,
+ session_callback callback, void *user_data)
+{
+ struct session_data *session;
+
+ if (destination == NULL)
+ return -EINVAL;
+
+ session = g_try_malloc0(sizeof(*session));
+ if (session == NULL)
+ return -ENOMEM;
+
+ if (source == NULL)
+ bacpy(&session->src, BDADDR_ANY);
+ else
+ str2ba(source, &session->src);
+
+ str2ba(destination, &session->dst);
+
+ if (target != NULL)
+ session->target = g_strdup(target);
+
+ callback(session, user_data);
+
+ g_free(session->agent);
+ g_free(session->target);
+ g_free(session);
+
+ return 0;
+}
+
+int session_set_agent(struct session_data *session, const char *agent)
+{
+ if (session == NULL)
+ return -EINVAL;
+
+ if (session->agent != NULL)
+ return -EALREADY;
+
+ printf("Using agent at %s\n", agent);
+
+ session->agent = g_strdup(agent);
+
+ return 0;
+}
+
+int session_send(struct session_data *session, const char *filename)
+{
+ printf("Sending file %s\n", filename);
+
+ return 0;
+}
diff --git a/obexd/client/session.h b/obexd/client/session.h
new file mode 100644
index 0000000..3f4edfd
--- /dev/null
+++ b/obexd/client/session.h
+/*
+ *
+ * OBEX Client
+ *
+ * Copyright (C) 2007-2008 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
+ *
+ */
+
+#include <bluetooth/bluetooth.h>
+
+struct session_data {
+ bdaddr_t src;
+ bdaddr_t dst;
+ char *target;
+ char *agent;
+};
+
+typedef void (*session_callback) (struct session_data *session,
+ void *user_data);
+
+int session_create(const char *source,
+ const char *destination, const char *target,
+ session_callback callback, void *user_data);
+int session_set_agent(struct session_data *session, const char *agent);
+int session_send(struct session_data *session, const char *filename);