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 #include #include +#include #include #include +#include +#include #include #include @@ -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, "", "Create new directory" }, { "get", "mget", cmd_get, "", "Retrieve file" }, + { "put", "put", cmd_put, "", "Upload file" }, + { "del", "delete",cmd_del, "" "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;