From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH obexd 2/4] Add basic support for action commands on ftp driver
Date: Fri, 17 Jun 2011 09:26:45 +0300 [thread overview]
Message-ID: <1308292007-2111-2-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1308292007-2111-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This add basic support for copy and move actions for ftp service driver
---
plugins/ftp.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/plugins/ftp.c b/plugins/ftp.c
index 79223bf..7e2f1e4 100644
--- a/plugins/ftp.c
+++ b/plugins/ftp.c
@@ -403,6 +403,104 @@ done:
return err;
}
+static char *ftp_build_filename(struct ftp_session *ftp, const char *destname)
+{
+ char *filename;
+
+ /* DestName can either be relative or absolute (FTP style) */
+ if (g_path_is_absolute(destname))
+ filename = g_build_filename(destname, NULL);
+ else
+ filename = g_build_filename(ftp->folder, destname, NULL);
+
+ /* Check if destination is inside root path */
+ if (g_str_has_prefix(filename, ftp->folder))
+ return filename;
+
+ g_free(filename);
+
+ return NULL;
+}
+
+static int ftp_copy(struct ftp_session *ftp, const char *name,
+ const char *destname)
+{
+ char *source, *destination;
+ int ret;
+
+ DBG("%p name %s destination %s", ftp, name, destname);
+
+ if (ftp->folder == NULL) {
+ error("No folder set");
+ return -ENOENT;
+ }
+
+ if (name == NULL || destname == NULL)
+ return -EINVAL;
+
+ destination = ftp_build_filename(ftp, destname);
+
+ source = g_build_filename(ftp->folder, name, NULL);
+
+ ret = obex_copy(ftp->os, source, destination);
+
+ g_free(source);
+ g_free(destination);
+
+ return ret;
+}
+
+static int ftp_move(struct ftp_session *ftp, const char *name,
+ const char *destname)
+{
+ char *source, *destination;
+ int ret;
+
+ DBG("%p name %s destname %s", ftp, name, destname);
+
+ if (ftp->folder == NULL) {
+ error("No folder set");
+ return -ENOENT;
+ }
+
+ if (name == NULL || destname == NULL)
+ return -EINVAL;
+
+ destination = ftp_build_filename(ftp, destname);
+
+ source = g_build_filename(ftp->folder, name, NULL);
+
+ ret = obex_move(ftp->os, source, destination);
+
+ g_free(source);
+ g_free(destination);
+
+ return ret;
+}
+
+static int ftp_action(struct obex_session *os, obex_object_t *obj,
+ void *user_data)
+{
+ struct ftp_session *ftp = user_data;
+ const char *name, *destname;
+ uint8_t action_id;
+
+ name = obex_get_name(os);
+ destname = obex_get_destname(os);
+ action_id = obex_get_action_id(os);
+
+ DBG("%p action 0x%x", ftp, action_id);
+
+ switch (action_id) {
+ case 0x00: /* Copy Object */
+ return ftp_copy(ftp, name, destname);
+ case 0x01: /* Move/Rename Object */
+ return ftp_move(ftp, name, destname);
+ default:
+ return -EINVAL;
+ }
+}
+
void ftp_disconnect(struct obex_session *os, void *user_data)
{
struct ftp_session *ftp = user_data;
@@ -427,6 +525,7 @@ static struct obex_service_driver ftp = {
.put = ftp_put,
.chkput = ftp_chkput,
.setpath = ftp_setpath,
+ .action = ftp_action,
.disconnect = ftp_disconnect
};
--
1.7.5.4
next prev parent reply other threads:[~2011-06-17 6:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-17 6:26 [PATCH obexd 1/4] Add initial support for OBEX Action command Luiz Augusto von Dentz
2011-06-17 6:26 ` Luiz Augusto von Dentz [this message]
2011-06-17 10:19 ` [PATCH obexd 2/4] Add basic support for action commands on ftp driver Hendrik Sattler
2011-06-17 11:02 ` Luiz Augusto von Dentz
2011-06-17 11:41 ` Hendrik Sattler
2011-06-17 6:26 ` [PATCH obexd 3/4] Add support for Action command to pcsuite plugin Luiz Augusto von Dentz
2011-06-17 6:26 ` [PATCH obexd 4/4] Add copy and move support for filesystem plugin Luiz Augusto von Dentz
2011-06-17 10:28 ` Hendrik Sattler
2011-06-17 10:47 ` Johan Hedberg
2011-06-17 11:37 ` Hendrik Sattler
2011-06-17 12:06 ` Johan Hedberg
2011-06-17 10:56 ` Luiz Augusto von Dentz
2011-06-21 8:06 ` Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308292007-2111-2-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).