* [PATCH 1/5] Add support for pcsuite lock file
@ 2011-02-22 9:43 Luiz Augusto von Dentz
2011-02-22 9:43 ` [PATCH 2/5] Add flush callback to mimetype driver Luiz Augusto von Dentz
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2011-02-22 9:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
This should make others applications able to detect when pcsuite is
connected.
---
plugins/ftp.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 154 insertions(+), 6 deletions(-)
diff --git a/plugins/ftp.c b/plugins/ftp.c
index a952f64..38d058c 100644
--- a/plugins/ftp.c
+++ b/plugins/ftp.c
@@ -150,8 +150,16 @@ struct ftp_session {
char *folder;
};
+struct pcsuite_session {
+ struct ftp_session *ftp;
+ char *lock_file;
+ int fd;
+};
+
static void set_folder(struct ftp_session *ftp, const char *new_folder)
{
+ DBG("%p folder %s", ftp, new_folder);
+
g_free(ftp->folder);
ftp->folder = new_folder ? g_strdup(new_folder) : NULL;
@@ -165,6 +173,8 @@ static int get_by_type(struct ftp_session *ftp, const char *type)
char *path;
int err;
+ DBG("%p name %s type %s", ftp, name, type);
+
if (type == NULL && name == NULL)
return -EBADR;
@@ -184,6 +194,8 @@ static void *ftp_connect(struct obex_session *os, int *err)
struct ftp_session *ftp;
const char *root_folder;
+ DBG("");
+
root_folder = obex_get_root_folder(os);
manager_register_session(os);
@@ -195,6 +207,8 @@ static void *ftp_connect(struct obex_session *os, int *err)
if (err)
*err = 0;
+ DBG("session %p created", ftp);
+
return ftp;
}
@@ -205,6 +219,8 @@ static int ftp_get(struct obex_session *os, obex_object_t *obj,
const char *type = obex_get_type(os);
int ret;
+ DBG("%p", ftp);
+
if (ftp->folder == NULL)
return -ENOENT;
@@ -223,6 +239,8 @@ static int ftp_delete(struct ftp_session *ftp, const char *name)
char *path;
int ret = 0;
+ DBG("%p name %s", ftp, name);
+
if (!(ftp->folder && name))
return -EINVAL;
@@ -243,6 +261,8 @@ static int ftp_chkput(struct obex_session *os, void *user_data)
char *path;
int ret;
+ DBG("%p name %s", ftp, name);
+
if (name == NULL)
return -EBADR;
@@ -265,6 +285,8 @@ static int ftp_put(struct obex_session *os, obex_object_t *obj,
const char *name = obex_get_name(os);
ssize_t size = obex_get_size(os);
+ DBG("%p name %s size %d", ftp, name, size);
+
if (ftp->folder == NULL)
return -EPERM;
@@ -297,6 +319,8 @@ static int ftp_setpath(struct obex_session *os, obex_object_t *obj,
root_folder = obex_get_root_folder(os);
root = g_str_equal(root_folder, ftp->folder);
+ DBG("%p name %s", ftp, name);
+
/* Check flag "Backup" */
if ((nonhdr[0] & 0x01) == 0x01) {
DBG("Set to parent path");
@@ -384,12 +408,136 @@ static void ftp_disconnect(struct obex_session *os, void *user_data)
{
struct ftp_session *ftp = user_data;
+ DBG("%p", ftp);
+
manager_unregister_session(os);
g_free(ftp->folder);
g_free(ftp);
}
+static void *pcsuite_connect(struct obex_session *os, int *err)
+{
+ struct pcsuite_session *pcsuite;
+ struct ftp_session *ftp;
+ int fd;
+ char *filename;
+
+ DBG("");
+
+ ftp = ftp_connect(os, err);
+ if (ftp == NULL)
+ return NULL;
+
+ filename = g_build_filename(g_get_home_dir(), ".pcsuite", NULL);
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ if (fd < 0 && errno != EEXIST) {
+ error("open(%s): %s(%d)", filename, strerror(errno), errno);
+ goto fail;
+ }
+
+ /* Try to remove the file before retrying since it could be
+ that some process left/crash without removing it */
+ if (fd < 0) {
+ if (remove(filename) < 0) {
+ error("remove(%s): %s(%d)", filename, strerror(errno),
+ errno);
+ goto fail;
+ }
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ if (fd < 0) {
+ error("open(%s): %s(%d)", filename, strerror(errno),
+ errno);
+ goto fail;
+ }
+ }
+
+ DBG("%s created", filename);
+
+ pcsuite = g_new0(struct pcsuite_session, 1);
+ pcsuite->ftp = ftp;
+ pcsuite->lock_file = filename;
+ pcsuite->fd = fd;
+
+ DBG("session %p created", pcsuite);
+
+ if (err)
+ *err = 0;
+
+ return pcsuite;
+
+fail:
+ if (ftp)
+ ftp_disconnect(os, ftp);
+ if (err)
+ *err = -errno;
+
+ g_free(filename);
+
+ return NULL;
+}
+
+static int pcsuite_get(struct obex_session *os, obex_object_t *obj,
+ gboolean *stream, void *user_data)
+{
+ struct pcsuite_session *pcsuite = user_data;
+
+ DBG("%p", pcsuite);
+
+ return ftp_get(os, obj, stream, pcsuite->ftp);
+}
+
+static int pcsuite_chkput(struct obex_session *os, void *user_data)
+{
+ struct pcsuite_session *pcsuite = user_data;
+
+ DBG("%p", pcsuite);
+
+ return ftp_chkput(os, pcsuite->ftp);
+}
+
+static int pcsuite_put(struct obex_session *os, obex_object_t *obj,
+ void *user_data)
+{
+ struct pcsuite_session *pcsuite = user_data;
+
+ DBG("%p", pcsuite);
+
+ return ftp_put(os, obj, pcsuite->ftp);
+}
+
+static int pcsuite_setpath(struct obex_session *os, obex_object_t *obj,
+ void *user_data)
+{
+ struct pcsuite_session *pcsuite = user_data;
+
+ DBG("%p", pcsuite);
+
+ return ftp_setpath(os, obj, pcsuite->ftp);
+}
+
+static void pcsuite_disconnect(struct obex_session *os, void *user_data)
+{
+ struct pcsuite_session *pcsuite = user_data;
+
+ DBG("%p", pcsuite);
+
+ if (pcsuite->fd >= 0)
+ close(pcsuite->fd);
+
+ if (pcsuite->lock_file) {
+ remove(pcsuite->lock_file);
+ g_free(pcsuite->lock_file);
+ }
+
+ if (pcsuite->ftp)
+ ftp_disconnect(os, pcsuite->ftp);
+
+ g_free(pcsuite);
+}
+
static struct obex_service_driver pcsuite = {
.name = "Nokia OBEX PC Suite Services",
.service = OBEX_PCSUITE,
@@ -399,12 +547,12 @@ static struct obex_service_driver pcsuite = {
.target_size = TARGET_SIZE,
.who = PCSUITE_WHO,
.who_size = PCSUITE_WHO_SIZE,
- .connect = ftp_connect,
- .get = ftp_get,
- .put = ftp_put,
- .chkput = ftp_chkput,
- .setpath = ftp_setpath,
- .disconnect = ftp_disconnect
+ .connect = pcsuite_connect,
+ .get = pcsuite_get,
+ .put = pcsuite_put,
+ .chkput = pcsuite_chkput,
+ .setpath = pcsuite_setpath,
+ .disconnect = pcsuite_disconnect
};
static struct obex_service_driver ftp = {
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/5] Add flush callback to mimetype driver 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz @ 2011-02-22 9:43 ` Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 3/5] Add .flush callback to backup plugin Luiz Augusto von Dentz ` (3 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 9:43 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> This add the possibility to a driver to flush its data when final packet is received which is specially usefull for PUT to prevent auto response for objects with no body/body empty/size 0. Note that it should not block like fsync, instead it is assumed to always be asyncronous so request is suspended when .flush returns > 0, the driver should then use obex_object_set_io_flags to indicate that it has completed the operation. --- src/mimetype.h | 1 + src/obex.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mimetype.h b/src/mimetype.h index ff16a8c..5bf741c 100644 --- a/src/mimetype.h +++ b/src/mimetype.h @@ -36,6 +36,7 @@ struct obex_mime_type_driver { ssize_t (*read) (void *object, void *buf, size_t count, uint8_t *hi, unsigned int *flags); ssize_t (*write) (void *object, const void *buf, size_t count); + int (*flush) (void *object); int (*remove) (const char *name); int (*set_io_watch) (void *object, obex_object_io_func func, void *user_data); diff --git a/src/obex.c b/src/obex.c index f2a21b7..caba2fb 100644 --- a/src/obex.c +++ b/src/obex.c @@ -613,6 +613,11 @@ write: os->pending -= w; } + /* Flush on EOS */ + if (os->size != OBJECT_SIZE_UNKNOWN && os->size == os->offset && + os->driver->flush) + return os->driver->flush(os->object) > 0 ? -EAGAIN : 0; + return 0; } @@ -702,7 +707,7 @@ static gboolean handle_async_io(void *object, int flags, int err, if (flags & (G_IO_IN | G_IO_PRI)) ret = obex_write_stream(os, os->obex, os->obj); - else if (flags & G_IO_OUT) + else if ((flags & G_IO_OUT) && os->pending > 0) ret = obex_read_stream(os, os->obex, os->obj); proceed: @@ -1089,8 +1094,25 @@ static void cmd_put(struct obex_session *os, obex_t *obex, obex_object_t *obj) } err = os->service->put(os, obj, os->service_data); - if (err < 0) + if (err < 0) { os_set_response(obj, err); + return; + } + + /* Check if there is a body and it is not empty (size > 0), otherwise + openobex won't notify us with OBEX_EV_STREAMAVAIL and it gonna reply + right away */ + if (os->size != 0) + return; + + /* Flush immediatly since there is nothing to write so the driver + has a chance to do something before we reply */ + if (os->object && os->driver && os->driver->flush && + os->driver->flush(os->object) > 0) { + OBEX_SuspendRequest(obex, obj); + os->obj = obj; + os->driver->set_io_watch(os->object, handle_async_io, os); + } } static void obex_event_cb(obex_t *obex, obex_object_t *obj, int mode, -- 1.7.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/5] Add .flush callback to backup plugin 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 2/5] Add flush callback to mimetype driver Luiz Augusto von Dentz @ 2011-02-22 9:43 ` Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 4/5] Move pcsuite drivers to its own plugin Luiz Augusto von Dentz ` (2 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 9:43 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> --- plugins/nokia-backup.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/plugins/nokia-backup.c b/plugins/nokia-backup.c index 4a69d8f..cf17e16 100644 --- a/plugins/nokia-backup.c +++ b/plugins/nokia-backup.c @@ -278,6 +278,13 @@ static ssize_t backup_write(void *object, const void *buf, size_t count) return ret; } +static int backup_flush(void *object) +{ + DBG("%p", object); + + return 0; +} + static struct obex_mime_type_driver backup = { .target = FTP_TARGET, .target_size = TARGET_SIZE, @@ -286,6 +293,7 @@ static struct obex_mime_type_driver backup = { .close = backup_close, .read = backup_read, .write = backup_write, + .flush = backup_flush, }; static int backup_init(void) -- 1.7.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/5] Move pcsuite drivers to its own plugin 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 2/5] Add flush callback to mimetype driver Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 3/5] Add .flush callback to backup plugin Luiz Augusto von Dentz @ 2011-02-22 9:43 ` Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 5/5] Fix --enable-usb build Luiz Augusto von Dentz 2011-02-22 19:14 ` [PATCH 1/5] Add support for pcsuite lock file Johan Hedberg 4 siblings, 0 replies; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 9:43 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> This make it easier to enable/disable this funcionality as a whole. --- Makefile.am | 6 +- configure.ac | 10 +- plugins/ftp.c | 165 ++------------------------ plugins/nokia-backup.c | 309 ------------------------------------------------ 4 files changed, 17 insertions(+), 473 deletions(-) delete mode 100644 plugins/nokia-backup.c diff --git a/Makefile.am b/Makefile.am index fc996ec..d32d613 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,9 +43,9 @@ endif builtin_modules += filesystem builtin_sources += plugins/filesystem.c plugins/filesystem.h -if NOKIA_BACKUP -builtin_modules += backup -builtin_sources += plugins/nokia-backup.c +if NOKIA_PCSUITE +builtin_modules += pcsuite +builtin_sources += plugins/pcsuite.c endif builtin_modules += opp diff --git a/configure.ac b/configure.ac index da8fb64..602c948 100644 --- a/configure.ac +++ b/configure.ac @@ -158,12 +158,12 @@ AC_ARG_ENABLE(usb, AC_HELP_STRING([--enable-usb], AM_CONDITIONAL(USB, test "${enable_usb}" = "yes" && test "${enable_server}" != "no") -AC_ARG_ENABLE(nokia_backup, AC_HELP_STRING([--enable-nokia-backup], - [enable nokia-backup plugin]), [ - enable_nokia_backup=${enableval} +AC_ARG_ENABLE(pcsuite, AC_HELP_STRING([--enable-pcsuite], + [enable Nokia PcSuite plugin]), [ + enable_pcsuite=${enableval} ]) -AM_CONDITIONAL(NOKIA_BACKUP, test "${enable_nokia_backup}" = "yes" && - test "${enable_server}" != "no") +AM_CONDITIONAL(NOKIA_PCSUITE, test "${enable_pcsuite}" = "yes" && + test "${enable_pcsuite}" != "no") AC_ARG_ENABLE(client, AC_HELP_STRING([--disable-client], [disable compilation of OBEX client]), [ diff --git a/plugins/ftp.c b/plugins/ftp.c index 38d058c..b6ee75b 100644 --- a/plugins/ftp.c +++ b/plugins/ftp.c @@ -50,6 +50,7 @@ #include "dbus.h" #include "mimetype.h" #include "service.h" +#include "ftp.h" #define LST_TYPE "x-obex/folder-listing" #define CAP_TYPE "x-obex/capability" @@ -189,7 +190,7 @@ static int get_by_type(struct ftp_session *ftp, const char *type) return err; } -static void *ftp_connect(struct obex_session *os, int *err) +void *ftp_connect(struct obex_session *os, int *err) { struct ftp_session *ftp; const char *root_folder; @@ -212,8 +213,8 @@ static void *ftp_connect(struct obex_session *os, int *err) return ftp; } -static int ftp_get(struct obex_session *os, obex_object_t *obj, - gboolean *stream, void *user_data) +int ftp_get(struct obex_session *os, obex_object_t *obj, gboolean *stream, + void *user_data) { struct ftp_session *ftp = user_data; const char *type = obex_get_type(os); @@ -254,7 +255,7 @@ static int ftp_delete(struct ftp_session *ftp, const char *name) return ret; } -static int ftp_chkput(struct obex_session *os, void *user_data) +int ftp_chkput(struct obex_session *os, void *user_data) { struct ftp_session *ftp = user_data; const char *name = obex_get_name(os); @@ -278,8 +279,7 @@ static int ftp_chkput(struct obex_session *os, void *user_data) return ret; } -static int ftp_put(struct obex_session *os, obex_object_t *obj, - void *user_data) +int ftp_put(struct obex_session *os, obex_object_t *obj, void *user_data) { struct ftp_session *ftp = user_data; const char *name = obex_get_name(os); @@ -299,8 +299,7 @@ static int ftp_put(struct obex_session *os, obex_object_t *obj, return 0; } -static int ftp_setpath(struct obex_session *os, obex_object_t *obj, - void *user_data) +int ftp_setpath(struct obex_session *os, obex_object_t *obj, void *user_data) { struct ftp_session *ftp = user_data; const char *root_folder, *name; @@ -404,7 +403,7 @@ done: return err; } -static void ftp_disconnect(struct obex_session *os, void *user_data) +void ftp_disconnect(struct obex_session *os, void *user_data) { struct ftp_session *ftp = user_data; @@ -416,145 +415,6 @@ static void ftp_disconnect(struct obex_session *os, void *user_data) g_free(ftp); } -static void *pcsuite_connect(struct obex_session *os, int *err) -{ - struct pcsuite_session *pcsuite; - struct ftp_session *ftp; - int fd; - char *filename; - - DBG(""); - - ftp = ftp_connect(os, err); - if (ftp == NULL) - return NULL; - - filename = g_build_filename(g_get_home_dir(), ".pcsuite", NULL); - - fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644); - if (fd < 0 && errno != EEXIST) { - error("open(%s): %s(%d)", filename, strerror(errno), errno); - goto fail; - } - - /* Try to remove the file before retrying since it could be - that some process left/crash without removing it */ - if (fd < 0) { - if (remove(filename) < 0) { - error("remove(%s): %s(%d)", filename, strerror(errno), - errno); - goto fail; - } - - fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644); - if (fd < 0) { - error("open(%s): %s(%d)", filename, strerror(errno), - errno); - goto fail; - } - } - - DBG("%s created", filename); - - pcsuite = g_new0(struct pcsuite_session, 1); - pcsuite->ftp = ftp; - pcsuite->lock_file = filename; - pcsuite->fd = fd; - - DBG("session %p created", pcsuite); - - if (err) - *err = 0; - - return pcsuite; - -fail: - if (ftp) - ftp_disconnect(os, ftp); - if (err) - *err = -errno; - - g_free(filename); - - return NULL; -} - -static int pcsuite_get(struct obex_session *os, obex_object_t *obj, - gboolean *stream, void *user_data) -{ - struct pcsuite_session *pcsuite = user_data; - - DBG("%p", pcsuite); - - return ftp_get(os, obj, stream, pcsuite->ftp); -} - -static int pcsuite_chkput(struct obex_session *os, void *user_data) -{ - struct pcsuite_session *pcsuite = user_data; - - DBG("%p", pcsuite); - - return ftp_chkput(os, pcsuite->ftp); -} - -static int pcsuite_put(struct obex_session *os, obex_object_t *obj, - void *user_data) -{ - struct pcsuite_session *pcsuite = user_data; - - DBG("%p", pcsuite); - - return ftp_put(os, obj, pcsuite->ftp); -} - -static int pcsuite_setpath(struct obex_session *os, obex_object_t *obj, - void *user_data) -{ - struct pcsuite_session *pcsuite = user_data; - - DBG("%p", pcsuite); - - return ftp_setpath(os, obj, pcsuite->ftp); -} - -static void pcsuite_disconnect(struct obex_session *os, void *user_data) -{ - struct pcsuite_session *pcsuite = user_data; - - DBG("%p", pcsuite); - - if (pcsuite->fd >= 0) - close(pcsuite->fd); - - if (pcsuite->lock_file) { - remove(pcsuite->lock_file); - g_free(pcsuite->lock_file); - } - - if (pcsuite->ftp) - ftp_disconnect(os, pcsuite->ftp); - - g_free(pcsuite); -} - -static struct obex_service_driver pcsuite = { - .name = "Nokia OBEX PC Suite Services", - .service = OBEX_PCSUITE, - .channel = PCSUITE_CHANNEL, - .record = PCSUITE_RECORD, - .target = FTP_TARGET, - .target_size = TARGET_SIZE, - .who = PCSUITE_WHO, - .who_size = PCSUITE_WHO_SIZE, - .connect = pcsuite_connect, - .get = pcsuite_get, - .put = pcsuite_put, - .chkput = pcsuite_chkput, - .setpath = pcsuite_setpath, - .disconnect = pcsuite_disconnect -}; - static struct obex_service_driver ftp = { .name = "File Transfer server", .service = OBEX_FTP, @@ -572,19 +432,12 @@ static struct obex_service_driver ftp = { static int ftp_init(void) { - int err; - - err = obex_service_driver_register(&ftp); - if (err < 0) - return err; - - return obex_service_driver_register(&pcsuite); + return obex_service_driver_register(&ftp); } static void ftp_exit(void) { obex_service_driver_unregister(&ftp); - obex_service_driver_unregister(&pcsuite); } OBEX_PLUGIN_DEFINE(ftp, ftp_init, ftp_exit) diff --git a/plugins/nokia-backup.c b/plugins/nokia-backup.c deleted file mode 100644 index cf17e16..0000000 --- a/plugins/nokia-backup.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * - * OBEX Server - * - * Copyright (C) 2010 Nokia Corporation - * Copyright (C) 2010 Marcel Holtmann <marcel@holtmann.org> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/statvfs.h> -#include <fcntl.h> -#include <wait.h> - -#include <glib.h> -#include "gdbus.h" - - -#include <openobex/obex.h> -#include <openobex/obex_const.h> - -#include "plugin.h" -#include "log.h" -#include "obex.h" -#include "mimetype.h" -#include "service.h" - -#define BACKUP_BUS_NAME "com.nokia.backup.plugin" -#define BACKUP_PATH "/com/nokia/backup" -#define BACKUP_PLUGIN_INTERFACE "com.nokia.backup.plugin" -#define BACKUP_DBUS_TIMEOUT (1000 * 60 * 15) - -static const uint8_t FTP_TARGET[TARGET_SIZE] = { - 0xF9, 0xEC, 0x7B, 0xC4, 0x95, 0x3C, 0x11, 0xD2, - 0x98, 0x4E, 0x52, 0x54, 0x00, 0xDC, 0x9E, 0x09 }; - -struct backup_object{ - gchar *cmd; - int fd; - int oflag; - int error_code; - mode_t mode; - DBusPendingCall *pending_call; - DBusConnection *conn; -}; - -static void on_backup_dbus_notify(DBusPendingCall *pending_call, - void *user_data) -{ - struct backup_object *obj = user_data; - DBusMessage *reply; - const char *filename; - int error_code; - - DBG("Notification received for pending call - %s", obj->cmd); - - reply = dbus_pending_call_steal_reply(pending_call); - - if (reply && dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, - &error_code, DBUS_TYPE_STRING, - &filename, DBUS_TYPE_INVALID)) { - - obj->error_code = error_code; - - if (filename) { - DBG("Notification - file path = %s, error_code = %d", - filename, error_code); - if (error_code == 0) - obj->fd = open(filename,obj->oflag,obj->mode); - } - - } else - DBG("Notification timed out or connection got closed"); - - if (reply) - dbus_message_unref(reply); - - dbus_pending_call_unref(pending_call); - obj->pending_call = NULL; - dbus_connection_unref(obj->conn); - obj->conn = NULL; - - if (obj->fd >= 0) { - DBG("File opened, setting io flags, cmd = %s", - obj->cmd); - if (obj->oflag == O_RDONLY) - obex_object_set_io_flags(user_data, G_IO_IN, 0); - else - obex_object_set_io_flags(user_data, G_IO_OUT, 0); - } else { - DBG("File open error, setting io error, cmd = %s", - obj->cmd); - obex_object_set_io_flags(user_data, G_IO_ERR, -EPERM); - } -} - -static gboolean send_backup_dbus_message(const char *oper, - struct backup_object *obj, - size_t *size) -{ - DBusConnection *conn; - DBusMessage *msg; - DBusPendingCall *pending_call; - gboolean ret = FALSE; - dbus_uint32_t file_size; - - file_size = size ? *size : 0; - - conn = g_dbus_setup_bus(DBUS_BUS_SESSION, NULL, NULL); - - if (conn == NULL) - return FALSE; - - msg = dbus_message_new_method_call(BACKUP_BUS_NAME, BACKUP_PATH, - BACKUP_PLUGIN_INTERFACE, - "request"); - if (msg == NULL) { - dbus_connection_unref(conn); - return FALSE; - } - - dbus_message_append_args(msg, DBUS_TYPE_STRING, &oper, - DBUS_TYPE_STRING, &obj->cmd, - DBUS_TYPE_INT32, &file_size, - DBUS_TYPE_INVALID); - - if (strcmp(oper, "open") == 0) { - ret = dbus_connection_send_with_reply(conn, msg, &pending_call, - BACKUP_DBUS_TIMEOUT); - dbus_message_unref(msg); - if (ret) { - obj->conn = conn; - obj->pending_call = pending_call; - ret = dbus_pending_call_set_notify(pending_call, - on_backup_dbus_notify, - obj, NULL); - } else - dbus_connection_unref(conn); - } else { - ret = dbus_connection_send(conn, msg, NULL); - dbus_message_unref(msg); - dbus_connection_unref(conn); - } - - return ret; -} - -static void *backup_open(const char *name, int oflag, mode_t mode, - void *context, size_t *size, int *err) -{ - struct backup_object *obj = g_new0(struct backup_object, 1); - - DBG("cmd = %s", name); - - obj->cmd = g_path_get_basename(name); - obj->oflag = oflag; - obj->mode = mode; - obj->fd = -1; - obj->pending_call = NULL; - obj->conn = NULL; - obj->error_code = 0; - - if (send_backup_dbus_message("open", obj, size) == FALSE) { - g_free(obj); - obj = NULL; - } - - if (err) - *err = 0; - - return obj; -} - -static int backup_close(void *object) -{ - struct backup_object *obj = object; - size_t size = 0; - - DBG("cmd = %s", obj->cmd); - - if (obj->fd != -1) - close(obj->fd); - - if (obj->pending_call) { - dbus_pending_call_cancel(obj->pending_call); - dbus_pending_call_unref(obj->pending_call); - dbus_connection_unref(obj->conn); - } - - send_backup_dbus_message("close", obj, &size); - - g_free(obj->cmd); - g_free(obj); - - return 0; -} - -static ssize_t backup_read(void *object, void *buf, size_t count, - uint8_t *hi, unsigned int *flags) -{ - struct backup_object *obj = object; - ssize_t ret = 0; - - *hi = OBEX_HDR_BODY; - - if (flags) - *flags = 0; - - if (obj->pending_call) { - DBG("cmd = %s, IN WAITING STAGE", obj->cmd); - return -EAGAIN; - } - - if (obj->fd != -1) { - DBG("cmd = %s, READING DATA", obj->cmd); - ret = read(obj->fd, buf, count); - if (ret < 0) - ret = -errno; - } else { - DBG("cmd = %s, PERMANENT FAILURE", obj->cmd); - ret = obj->error_code ? -obj->error_code : -ENOENT; - } - - return ret; -} - -static ssize_t backup_write(void *object, const void *buf, size_t count) -{ - struct backup_object *obj = object; - ssize_t ret = 0; - - if (obj->pending_call) { - DBG("cmd = %s, IN WAITING STAGE", obj->cmd); - return -EAGAIN; - } - - if (obj->fd != -1) { - ret = write(obj->fd, buf, count); - - DBG("cmd = %s, WRITTING", obj->cmd); - - if (ret < 0) { - error("backup: cmd = %s", obj->cmd); - ret = -errno; - } - } else { - error("backup: cmd = %s", obj->cmd); - ret = obj->error_code ? -obj->error_code : -ENOENT; - } - - return ret; -} - -static int backup_flush(void *object) -{ - DBG("%p", object); - - return 0; -} - -static struct obex_mime_type_driver backup = { - .target = FTP_TARGET, - .target_size = TARGET_SIZE, - .mimetype = "application/vnd.nokia-backup", - .open = backup_open, - .close = backup_close, - .read = backup_read, - .write = backup_write, - .flush = backup_flush, -}; - -static int backup_init(void) -{ - return obex_mime_type_driver_register(&backup); -} - -static void backup_exit(void) -{ - obex_mime_type_driver_unregister(&backup); -} - -OBEX_PLUGIN_DEFINE(backup, backup_init, backup_exit) -- 1.7.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/5] Fix --enable-usb build 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz ` (2 preceding siblings ...) 2011-02-22 9:43 ` [PATCH 4/5] Move pcsuite drivers to its own plugin Luiz Augusto von Dentz @ 2011-02-22 9:43 ` Luiz Augusto von Dentz 2011-02-22 14:05 ` Vinicius Costa Gomes 2011-02-22 19:14 ` [PATCH 1/5] Add support for pcsuite lock file Johan Hedberg 4 siblings, 1 reply; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 9:43 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> --- configure.ac | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/configure.ac b/configure.ac index 602c948..fc63b8c 100644 --- a/configure.ac +++ b/configure.ac @@ -156,7 +156,7 @@ AC_ARG_ENABLE(usb, AC_HELP_STRING([--enable-usb], enable_usb=${enableval} ]) AM_CONDITIONAL(USB, test "${enable_usb}" = "yes" && - test "${enable_server}" != "no") + test "${enable_usb}" != "no") AC_ARG_ENABLE(pcsuite, AC_HELP_STRING([--enable-pcsuite], [enable Nokia PcSuite plugin]), [ -- 1.7.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 5/5] Fix --enable-usb build 2011-02-22 9:43 ` [PATCH 5/5] Fix --enable-usb build Luiz Augusto von Dentz @ 2011-02-22 14:05 ` Vinicius Costa Gomes 2011-02-22 14:13 ` Luiz Augusto von Dentz 0 siblings, 1 reply; 9+ messages in thread From: Vinicius Costa Gomes @ 2011-02-22 14:05 UTC (permalink / raw) To: Luiz Augusto von Dentz; +Cc: linux-bluetooth Hi Luiz, On 11:43 Tue 22 Feb, Luiz Augusto von Dentz wrote: > From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> > > --- > configure.ac | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/configure.ac b/configure.ac > index 602c948..fc63b8c 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -156,7 +156,7 @@ AC_ARG_ENABLE(usb, AC_HELP_STRING([--enable-usb], > enable_usb=${enableval} > ]) > AM_CONDITIONAL(USB, test "${enable_usb}" = "yes" && > - test "${enable_server}" != "no") > + test "${enable_usb}" != "no") I failed to notice how the new line that you added is different from the first line of the AM_CONDITIONAL(). Perhaps just removing the "enable_server" test is enough. Or am I missing something? > > AC_ARG_ENABLE(pcsuite, AC_HELP_STRING([--enable-pcsuite], > [enable Nokia PcSuite plugin]), [ > -- > 1.7.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Cheers, -- Vinicius ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 5/5] Fix --enable-usb build 2011-02-22 14:05 ` Vinicius Costa Gomes @ 2011-02-22 14:13 ` Luiz Augusto von Dentz 0 siblings, 0 replies; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 14:13 UTC (permalink / raw) To: Vinicius Costa Gomes; +Cc: linux-bluetooth Hi, On Tue, Feb 22, 2011 at 4:05 PM, Vinicius Costa Gomes <vinicius.gomes@openbossa.org> wrote: > Hi Luiz, > > On 11:43 Tue 22 Feb, Luiz Augusto von Dentz wrote: >> From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> >> >> --- >> configure.ac | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/configure.ac b/configure.ac >> index 602c948..fc63b8c 100644 >> --- a/configure.ac >> +++ b/configure.ac >> @@ -156,7 +156,7 @@ AC_ARG_ENABLE(usb, AC_HELP_STRING([--enable-usb], >> enable_usb=${enableval} >> ]) >> AM_CONDITIONAL(USB, test "${enable_usb}" = "yes" && >> - test "${enable_server}" != "no") >> + test "${enable_usb}" != "no") > > I failed to notice how the new line that you added is different from the > first line of the AM_CONDITIONAL(). Perhaps just removing the "enable_server" > test is enough. Or am I missing something? > >> >> AC_ARG_ENABLE(pcsuite, AC_HELP_STRING([--enable-pcsuite], >> [enable Nokia PcSuite plugin]), [ >> -- Actually this is wrong, I though it was a type but it is not, but you are right we should not need to check for server there as we do already in Makefile.am. -- Luiz Augusto von Dentz Computer Engineer ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/5] Add support for pcsuite lock file 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz ` (3 preceding siblings ...) 2011-02-22 9:43 ` [PATCH 5/5] Fix --enable-usb build Luiz Augusto von Dentz @ 2011-02-22 19:14 ` Johan Hedberg 2011-02-22 20:23 ` Luiz Augusto von Dentz 4 siblings, 1 reply; 9+ messages in thread From: Johan Hedberg @ 2011-02-22 19:14 UTC (permalink / raw) To: Luiz Augusto von Dentz; +Cc: linux-bluetooth Hi Luiz, On Tue, Feb 22, 2011, Luiz Augusto von Dentz wrote: > This should make others applications able to detect when pcsuite is > connected. > --- > plugins/ftp.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 files changed, 154 insertions(+), 6 deletions(-) Doesn't compile (ssize_t correct format string is %zd): plugins/ftp.c: In function 'ftp_put': plugins/ftp.c:288: error: format '%d' expects type 'int', but argument 6 has type 'ssize_t' Also, all the added debug prints don't seem to relate to the commit message in anyway. Probably better to split into a separate patch? Johan ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/5] Add support for pcsuite lock file 2011-02-22 19:14 ` [PATCH 1/5] Add support for pcsuite lock file Johan Hedberg @ 2011-02-22 20:23 ` Luiz Augusto von Dentz 0 siblings, 0 replies; 9+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-22 20:23 UTC (permalink / raw) To: Luiz Augusto von Dentz, linux-bluetooth; +Cc: Johan Hedberg Hi, On Tue, Feb 22, 2011 at 9:14 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote: > Hi Luiz, > > On Tue, Feb 22, 2011, Luiz Augusto von Dentz wrote: >> This should make others applications able to detect when pcsuite is >> connected. >> --- >> plugins/ftp.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- >> 1 files changed, 154 insertions(+), 6 deletions(-) > > Doesn't compile (ssize_t correct format string is %zd): > > plugins/ftp.c: In function 'ftp_put': > plugins/ftp.c:288: error: format '%d' expects type 'int', but argument 6 has type 'ssize_t' Will fix it and send a new version. > Also, all the added debug prints don't seem to relate to the commit > message in anyway. Probably better to split into a separate patch? Yep, will do it too. -- Luiz Augusto von Dentz Computer Engineer ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-02-22 20:23 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-22 9:43 [PATCH 1/5] Add support for pcsuite lock file Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 2/5] Add flush callback to mimetype driver Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 3/5] Add .flush callback to backup plugin Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 4/5] Move pcsuite drivers to its own plugin Luiz Augusto von Dentz 2011-02-22 9:43 ` [PATCH 5/5] Fix --enable-usb build Luiz Augusto von Dentz 2011-02-22 14:05 ` Vinicius Costa Gomes 2011-02-22 14:13 ` Luiz Augusto von Dentz 2011-02-22 19:14 ` [PATCH 1/5] Add support for pcsuite lock file Johan Hedberg 2011-02-22 20:23 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox