diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2013-09-10 16:19:38 +0300 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2013-10-15 16:50:20 +0300 |
commit | 01f7250d33b36ddbab46e7175453b4e08a4fc47d (patch) | |
tree | 651a80fd8fc3dd7186fab985bda7dded4e022b7b /tools/obexctl.c | |
parent | 25189bbd3953485e89ef82c0bc00946393eeacec (diff) | |
download | bluez-01f7250d33b36ddbab46e7175453b4e08a4fc47d.tar.gz |
tools/obexctl: Add cd command
Add support for cd command which can be used to change current directory
using FileTransfer interface.
Diffstat (limited to 'tools/obexctl.c')
-rw-r--r-- | tools/obexctl.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/obexctl.c b/tools/obexctl.c index 96eaccc6e..d19dfe078 100644 --- a/tools/obexctl.c +++ b/tools/obexctl.c @@ -622,6 +622,70 @@ static void cmd_send(int argc, char *argv[]) g_dbus_proxy_get_path(proxy)); } +static void change_folder_reply(DBusMessage *message, void *user_data) +{ + DBusError error; + + dbus_error_init(&error); + + if (dbus_set_error_from_message(&error, message) == TRUE) { + rl_printf("Failed to ChangeFolder: %s\n", error.name); + dbus_error_free(&error); + return; + } + + rl_printf("ChangeFolder successful\n"); +} + +static void change_folder_setup(DBusMessageIter *iter, void *user_data) +{ + const char *folder = user_data; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &folder); +} + +static GDBusProxy *find_ftp(const char *path) +{ + GSList *l; + + for (l = ftps; l; l = g_slist_next(l)) { + GDBusProxy *proxy = l->data; + + if (strcmp(path, g_dbus_proxy_get_path(proxy)) == 0) + return proxy; + } + + return NULL; +} + +static void cmd_cd(int argc, char *argv[]) +{ + GDBusProxy *proxy; + + if (!check_default_session()) + return; + + proxy = find_ftp(g_dbus_proxy_get_path(default_session)); + if (proxy == NULL) { + rl_printf("Command not supported\n"); + return; + } + + if (argc < 2) { + rl_printf("Missing path argument\n"); + return; + } + + if (g_dbus_proxy_method_call(proxy, "ChangeFolder", change_folder_setup, + change_folder_reply, g_strdup(argv[1]), + g_free) == FALSE) { + rl_printf("Failed to ChangeFolder\n"); + return; + } + + rl_printf("Attempting to ChangeFolder to %s\n", argv[1]); +} + static const struct { const char *cmd; const char *arg; @@ -636,6 +700,7 @@ static const struct { { "info", "<transfer>", cmd_info, "Transfer information" }, { "cancel", "<transfer>", cmd_cancel, "Cancel transfer" }, { "send", "<file>", cmd_send, "Send file" }, + { "cd", "<path>", cmd_cd, "Change current folder" }, { "quit", NULL, cmd_quit, "Quit program" }, { "exit", NULL, cmd_quit }, { "help" }, |