diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2011-07-05 18:32:28 +0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2011-07-16 17:50:47 +0300 |
commit | 04d77000ac3635ef5ced921676a399a0f206aae7 (patch) | |
tree | 0ae532a328a21d410271cb1a4dee18aaf1c9db9b /tools | |
parent | 03b2e7cb7be80b59b00d13914955dd393d9aaaef (diff) | |
download | obexd-04d77000ac3635ef5ced921676a399a0f206aae7.tar.gz |
gobex: Add support for put transfer in test-client
Diffstat (limited to 'tools')
-rw-r--r-- | tools/test-client.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/test-client.c b/tools/test-client.c index f544d0b..6664727 100644 --- a/tools/test-client.c +++ b/tools/test-client.c @@ -21,6 +21,7 @@ #include <sys/types.h> #include <sys/socket.h> +#include <fcntl.h> #include <sys/un.h> #include <unistd.h> #include <stdlib.h> @@ -32,6 +33,7 @@ #include <readline/history.h> #include <gobex/gobex.h> +#include <gobex/gobex-transfer.h> static GMainLoop *main_loop = NULL; static GObex *obex = NULL; @@ -113,6 +115,59 @@ static void cmd_connect(int argc, char **argv) g_obex_connect(obex, NULL, 0, conn_complete, NULL, NULL); } +struct put_data { + int fd; +}; + +static void put_complete(GObex *obex, GError *err, gpointer user_data) +{ + struct put_data *data = user_data; + + if (err != NULL) + g_printerr("put failed: %s\n", err->message); + else + g_print("put succeeded\n"); + + close(data->fd); + g_free(data); +} + +static gssize put_data_cb(void *buf, gsize len, gpointer user_data) +{ + struct put_data *data = user_data; + + return read(data->fd, buf, len); +} + +static void cmd_put(int argc, char **argv) +{ + struct put_data *data; + GError *err = NULL; + int fd; + + if (argc < 2) { + g_printerr("Filename required\n"); + return; + } + + fd = open(argv[1], O_RDONLY | O_NOCTTY, 0); + if (fd < 0) { + g_printerr("open: %s", strerror(errno)); + return; + } + + data = g_new0(struct put_data, 1); + data->fd = fd; + + g_obex_put(obex, NULL, argv[1], put_data_cb, put_complete, data, &err); + if (err != NULL) { + g_printerr("put failed: %s\n", err->message); + g_error_free(err); + close(data->fd); + g_free(data); + } +} + static void cmd_help(int argc, char **argv); static void cmd_exit(int argc, char **argv) @@ -130,6 +185,7 @@ static struct { { "exit", cmd_exit, "", "Exit application" }, { "quit", cmd_exit, "", "Exit application" }, { "connect", cmd_connect, "[target]", "OBEX Connect" }, + { "put", cmd_put, "<file>", "Send a file" }, { NULL }, }; |