public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Ka Fai Lau <iamkafai2002@yahoo.com>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] ftp patch
Date: Mon, 4 Oct 2004 23:01:30 -0700 (PDT)	[thread overview]
Message-ID: <20041005060130.18216.qmail@web13125.mail.yahoo.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

I d/l the ftp from cvs but somehow broken to me.  I have made a patch to the obex and ftp.  It is
a really quick patch.  Hopefully, I didn't make too many mistakes :D

--KaFai


		
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: obex_ftp.patch --]
[-- Type: text/x-patch; name="obex_ftp.patch", Size: 3070 bytes --]

Index: ftp/main.c
===================================================================
RCS file: /cvsroot/bluez/obex/ftp/main.c,v
retrieving revision 1.3
diff -p -b -u -r1.3 main.c
--- ftp/main.c	12 Jul 2004 12:12:20 -0000	1.3
+++ ftp/main.c	5 Oct 2004 05:43:38 -0000
@@ -31,8 +31,11 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <signal.h>
+#include <libgen.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -126,6 +129,57 @@ static void cmd_get(int od, int argc, ch
 	}
 }
 
+static void cmd_put(int od, int argc, char **argv)
+{
+	int fd;
+	struct stat a_stat;
+	char *data;
+
+	if (argc != 1) {
+		printf("Usage: put local-file\n");
+		return;
+	}
+
+	fd = open(argv[0], O_RDONLY);
+	if (fd == -1) {
+		perror("open:");
+		return;
+	}
+
+	if (fstat(fd, &a_stat) == -1) {
+		perror("fstat:");
+		goto rel_fd;
+		return;
+	}
+
+	data = (char*)mmap(NULL, (size_t) a_stat.st_size, PROT_READ, 
+			   MAP_SHARED, fd, 0);
+	if(!data) {
+		perror("mmap:");
+		goto rel_fd;
+		return;
+	}
+
+	if (obex_put(od, NULL, basename(argv[0]), data, a_stat.st_size) == 0) {
+		printf("%lu bytes sent\n", a_stat.st_size);
+	}
+
+	munmap(data, a_stat.st_size);
+ rel_fd:
+	close(fd);
+}
+
+static void cmd_del(int od, int argc, char **argv)
+{
+	if (argc != 1) {
+		printf("Usage: del remote file\n");
+		return;
+	}
+
+	obex_put(od, NULL, argv[0], NULL, 0);
+
+}
+
 struct {
 	char *cmd;
 	char *alt;
@@ -138,6 +192,8 @@ struct {
 	{ "cd",    "chdir", cmd_chdir, "[dir]",  "Change directory"     },
 	{ "mkdir", "",      cmd_mkdir, "<dir>",  "Create new directory" },
 	{ "get",   "mget",  cmd_get,   "<file>", "Retrieve file"        },
+	{ "put",   "put",   cmd_put,   "<file>", "Upload file"          },
+ 	{ "del",   "delete",cmd_del,   "<file>"  "delete remove file"   },
 	{ NULL, NULL, NULL, 0, 0 }
 };
 
Index: goep/obex.c
===================================================================
RCS file: /cvsroot/bluez/obex/goep/obex.c,v
retrieving revision 1.4
diff -p -b -u -r1.4 obex.c
--- goep/obex.c	12 Jul 2004 12:11:48 -0000	1.4
+++ goep/obex.c	5 Oct 2004 05:43:38 -0000
@@ -207,6 +207,9 @@ static void obex_request_done(obex_t *ha
 				memset(context->data_buf, 0, hl + 1);
 				memcpy(context->data_buf, hd.bs, hl);
 				break;
+			case OBEX_HDR_TYPE:
+				/* [TODO]: interpret type later. MIME?? */
+				break;
 			default:
 				printf("Hdr: Unknown header %02x\n", hi);
 				break;
@@ -330,13 +333,17 @@ int obex_put(int od, const char *type, c
 			OBEX_HDR_NAME, hd, len, OBEX_FL_FIT_ONE_PACKET);
 	}
 
+	if (size) {
 	hd.bq4 = size;
 	OBEX_ObjectAddHeader(handle, object,
-		OBEX_HDR_LENGTH, hd, 4, OBEX_FL_FIT_ONE_PACKET);
+				     OBEX_HDR_LENGTH, hd, 4, 
+				     OBEX_FL_FIT_ONE_PACKET);
 
 	hd.bs = data;
 	OBEX_ObjectAddHeader(handle, object,
-		OBEX_HDR_BODY, hd, size, OBEX_FL_FIT_ONE_PACKET);
+				     OBEX_HDR_BODY, hd, size, 
+				     OBEX_FL_FIT_ONE_PACKET);
+	}
 
 	if ((err = OBEX_Request(handle, object)) < 0)
 		return err;

             reply	other threads:[~2004-10-05  6:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-05  6:01 Ka Fai Lau [this message]
2004-10-05 16:41 ` [Bluez-devel] ftp patch Marcel Holtmann

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=20041005060130.18216.qmail@web13125.mail.yahoo.com \
    --to=iamkafai2002@yahoo.com \
    --cc=bluez-devel@lists.sourceforge.net \
    /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