From: Luiz Augusto von Dentz Date: Tue, 1 Oct 2013 07:12:10 +0000 (+0300) Subject: tools/obexctl: Add cp command support for PBAP sessions X-Git-Tag: android-x86-4.4-r3~7389 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ae7d33d35005fa55ce8a49ce0d0ffd229b5dfaed;p=android-x86%2Fexternal-bluetooth-bluez.git tools/obexctl: Add cp command support for PBAP sessions Add cp command support for PBAP sessions which can be used to pull contacts for the current phonebook using PhonebookAccess interface. --- diff --git a/tools/obexctl.c b/tools/obexctl.c index b50470449..e3a859a20 100644 --- a/tools/obexctl.c +++ b/tools/obexctl.c @@ -1010,17 +1010,10 @@ static void copy_file_reply(DBusMessage *message, void *user_data) rl_printf("CopyFile successful\n"); } -static void cmd_copy(int argc, char *argv[]) +static void ftp_copy(GDBusProxy *proxy, int argc, char *argv[]) { - GDBusProxy *proxy; struct cp_args *args; - proxy = find_ftp(g_dbus_proxy_get_path(default_session)); - if (proxy == NULL) { - rl_printf("Command not supported\n"); - return; - } - args = cp_new(argv); if (g_dbus_proxy_method_call(proxy, "CopyFile", cp_setup, @@ -1058,19 +1051,12 @@ static void get_file_setup(DBusMessageIter *iter, void *user_data) dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &args->source); } -static void cmd_get(int argc, char *argv[]) +static void ftp_get(GDBusProxy *proxy, int argc, char *argv[]) { - GDBusProxy *proxy; struct cp_args *args; if (rindex(argv[2], ':') == NULL) - return cmd_copy(argc, argv); - - proxy = find_ftp(g_dbus_proxy_get_path(default_session)); - if (proxy == NULL) { - rl_printf("Command not supported\n"); - return; - } + return ftp_copy(proxy, argc, argv); args = cp_new(argv); @@ -1101,9 +1087,8 @@ static void put_file_reply(DBusMessage *message, void *user_data) print_transfer_iter(&iter); } -static void cmd_put(int argc, char *argv[]) +static void ftp_put(GDBusProxy *proxy, int argc, char *argv[]) { - GDBusProxy *proxy; struct cp_args *args; if (rindex(argv[2], ':') != NULL) { @@ -1111,12 +1096,6 @@ static void cmd_put(int argc, char *argv[]) return; } - proxy = find_ftp(g_dbus_proxy_get_path(default_session)); - if (proxy == NULL) { - rl_printf("Command not supported\n"); - return; - } - args = cp_new(argv); if (g_dbus_proxy_method_call(proxy, "PutFile", cp_setup, put_file_reply, @@ -1128,11 +1107,120 @@ static void cmd_put(int argc, char *argv[]) rl_printf("Attempting to PutFile\n"); } -static void cmd_cp(int argc, char *argv[]) +static void ftp_cp(GDBusProxy *proxy, int argc, char *argv[]) { - if (!check_default_session()) + if (argc < 2) { + rl_printf("Missing source file argument\n"); + return; + } + + if (argc < 3) { + rl_printf("Missing target file argument\n"); + return; + } + + if (rindex(argv[1], ':') == NULL) + return ftp_get(proxy, argc, argv); + + return ftp_put(proxy, argc, argv); +} + +static void pull_all_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 PullAll: %s\n", error.name); + dbus_error_free(&error); return; + } + + + rl_printf("PullAll successful\n"); +} + +static void pull_all_setup(DBusMessageIter *iter, void *user_data) +{ + const char *file = user_data; + DBusMessageIter dict; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &file); + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + + dbus_message_iter_close_container(iter, &dict); +} + +static void pbap_pull_all(GDBusProxy *proxy, int argc, char *argv[]) +{ + if (g_dbus_proxy_method_call(proxy, "PullAll", pull_all_setup, + pull_all_reply, g_strdup(argv[2]), + g_free) == FALSE) { + rl_printf("Failed to PullAll\n"); + return; + } + + rl_printf("Attempting to PullAll\n"); +} + +static void pull_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 Pull: %s\n", error.name); + dbus_error_free(&error); + return; + } + + + rl_printf("Pull successful\n"); +} + +static void pull_setup(DBusMessageIter *iter, void *user_data) +{ + struct cp_args *args = user_data; + DBusMessageIter dict; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &args->source); + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &args->target); + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + + dbus_message_iter_close_container(iter, &dict); +} + +static void pbap_pull(GDBusProxy *proxy, int argc, char *argv[]) +{ + struct cp_args *args; + + args = cp_new(argv); + + if (g_dbus_proxy_method_call(proxy, "Pull", pull_setup, pull_reply, + args, cp_free) == FALSE) { + rl_printf("Failed to Pull\n"); + return; + } + + rl_printf("Attempting to Pull\n"); +} + +static void pbap_cp(GDBusProxy *proxy, int argc, char *argv[]) +{ if (argc < 2) { rl_printf("Missing source file argument\n"); return; @@ -1143,10 +1231,33 @@ static void cmd_cp(int argc, char *argv[]) return; } - if (rindex(argv[1], ':') == NULL) - return cmd_get(argc, argv); + if (strcmp(argv[1], "*") == 0) + return pbap_pull_all(proxy, argc, argv); + + return pbap_pull(proxy, argc, argv); +} + +static void cmd_cp(int argc, char *argv[]) +{ - return cmd_put(argc, argv); + GDBusProxy *proxy; + + if (!check_default_session()) + return; + + proxy = find_ftp(g_dbus_proxy_get_path(default_session)); + if (proxy) { + ftp_cp(proxy, argc, argv); + return; + } + + proxy = find_pbap(g_dbus_proxy_get_path(default_session)); + if (proxy) { + pbap_cp(proxy, argc, argv); + return; + } + + rl_printf("Command not supported\n"); } static void move_file_reply(DBusMessage *message, void *user_data)