summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-10-24 10:08:15 -0300
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-10-24 14:17:52 -0300
commit90205a7f178f0cb325ff7864e4cae03146b23689 (patch)
tree1e4f66649502fd9372efffa6ee6c2dc6e7269bd6
parent6e5868231d61f87e5d0b9b8fc0d54ffe48ddc983 (diff)
downloadobexd-90205a7f178f0cb325ff7864e4cae03146b23689.tar.gz
Added CreateSession skeleton
-rw-r--r--client/main.c76
1 files changed, 54 insertions, 22 deletions
diff --git a/client/main.c b/client/main.c
index 0923a49..1f8a140 100644
--- a/client/main.c
+++ b/client/main.c
@@ -79,27 +79,14 @@ failed:
g_free(data);
}
-static DBusMessage *send_files(DBusConnection *connection,
- DBusMessage *message, void *user_data)
+static int parse_device_dict(DBusMessageIter *iter,
+ const char **source, const char **dest, const char **target)
{
- DBusMessageIter iter, array;
- GPtrArray *files;
- struct send_data *data;
- const char *agent, *dest = NULL;
-
- files = g_ptr_array_new();
- if (files == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.NoMemory", 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) {
+ while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
const char *key;
- dbus_message_iter_recurse(&array, &entry);
+ dbus_message_iter_recurse(iter, &entry);
dbus_message_iter_get_basic(&entry, &key);
dbus_message_iter_next(&entry);
@@ -107,17 +94,44 @@ static DBusMessage *send_files(DBusConnection *connection,
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_STRING:
- if (g_str_equal(key, "Destination") == TRUE)
- dbus_message_iter_get_basic(&value, &dest);
- break;
+ if (g_str_equal(key, "Source") == TRUE)
+ dbus_message_iter_get_basic(&value, source);
+ else if (g_str_equal(key, "Destination") == TRUE)
+ dbus_message_iter_get_basic(&value, dest);
+ else if (g_str_equal(key, "Target") == TRUE)
+ dbus_message_iter_get_basic(&value, target);
}
- dbus_message_iter_next(&array);
+ dbus_message_iter_next(iter);
}
+ return 0;
+}
+
+static DBusMessage *send_files(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ DBusMessageIter iter, array;
+ GPtrArray *files;
+ struct send_data *data;
+ const char *agent, *source = NULL, *dest = NULL, *target = NULL;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+
+ parse_device_dict(&array, &source, &dest, &target);
+ if (dest == NULL)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.InvalidArguments", NULL);
+
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &array);
+ files = g_ptr_array_new();
+ if (files == NULL)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.NoMemory", NULL);
+
while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
char *value;
@@ -130,7 +144,7 @@ static DBusMessage *send_files(DBusConnection *connection,
dbus_message_iter_next(&iter);
dbus_message_iter_get_basic(&iter, &agent);
- if (dest == NULL || files->len == 0) {
+ if (files->len == 0) {
g_ptr_array_free(files, TRUE);
return g_dbus_create_error(message,
"org.openobex.Error.InvalidArguments", NULL);
@@ -162,8 +176,26 @@ static DBusMessage *send_files(DBusConnection *connection,
return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
}
+static DBusMessage *create_session(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ DBusMessageIter iter, dict;
+ const char *source = NULL, *dest = NULL, *target = NULL;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_recurse(&iter, &dict);
+
+ parse_device_dict(&dict, &source, &dest, &target);
+ if (dest == NULL || target == NULL)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.InvalidArguments", NULL);
+
+ return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
+}
+
static GDBusMethodTable client_methods[] = {
{ "SendFiles", "a{sv}aso", "", send_files, G_DBUS_METHOD_FLAG_ASYNC },
+ { "CreateSession", "a{sv}", "", create_session },
{ }
};