Add support for pcsuite lock file
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/6 Add support for pcsuite lock file
From: Luiz Augusto von Dentz <[email protected]>
This should make others applications able to detect when pcsuite is connected.
--- plugins/ftp.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 134 insertions(+), 6 deletions(-)
plugins/ftp.c +134 -6
@@ -150,6 +150,12 @@ 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) {g_free (ftp->folder);
@@ -390,6 +396,128 @@ 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 ,
@@ -399,12 +527,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 = {
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 2/6 Add more debug logs for ftp driver
From: Luiz Augusto von Dentz <[email protected]>
--- plugins/ftp.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-)
plugins/ftp.c +20 -0
@@ -158,6 +158,8 @@ struct pcsuite_session {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 ;
@@ -171,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 ;
@@ -190,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);
@@ -201,6 +207,8 @@ static void *ftp_connect(struct obex_session *os, int *err)if (err) *err =0 ; +DBG ("session %p created" , ftp); +return ftp; }
@@ -211,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 ;
@@ -229,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 ;
@@ -249,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 ;
@@ -271,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 %zd" , ftp, name, size); +if (ftp->folder ==NULL )return -EPERM ;
@@ -303,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" );
@@ -390,6 +408,8 @@ 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);
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 3/6 Add flush callback to mimetype driver
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
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(-)
src/mimetype.h +1 -0
@@ -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);
src/obex.c +24 -2
@@ -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,
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 4/6 Add .flush callback to backup plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- plugins/nokia-backup.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
plugins/nokia-backup.c +8 -0
@@ -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 )
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 5/6 Move pcsuite drivers to its own plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make it easier to enable/disable this funcionality as a whole.
--- Makefile.am | 6 +- configure.ac | 9 +- plugins/ftp.c | 165 ++------------------------ plugins/nokia-backup.c | 309 ------------------------------------------------ 4 files changed, 16 insertions(+), 473 deletions(-) delete mode 100644 plugins/nokia-backup.c
Makefile.am +3 -3
@@ -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
configure.ac +4 -5
@@ -158,12 +158,11 @@ 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") AC_ARG_ENABLE(client, AC_HELP_STRING([--disable-client], [disable compilation of OBEX client]), [
plugins/ftp.c +9 -156
224 lines not on this page · raw message
plugins/nokia-backup.c deleted +0 -309
309 lines not on this page · raw message
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 6/6 Remove redundante check for server when checking for usb
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
There is a check for this already on Makefile.am
--- configure.ac | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
configure.ac +1 -2
@@ -155,8 +155,7 @@ AC_ARG_ENABLE(usb, AC_HELP_STRING([--enable-usb], [enable usb plugin]), [ enable_usb=${enableval} ]) -AM_CONDITIONAL(USB, test "${enable_usb}" = "yes" && - test "${enable_server}" != "no") +AM_CONDITIONAL(USB, test "${enable_usb}" = "yes") AC_ARG_ENABLE(pcsuite, AC_HELP_STRING([--enable-pcsuite], [enable Nokia PcSuite plugin]), [
Signature · 1 line
1.7.1
Re: [PATCH 5/6] Move pcsuite drivers to its own plugin
In reply to Luiz Augusto von DentzHi Luiz,
Quoted 8 lines · Luiz Augusto von Dentz
This make it easier to enable/disable this funcionality as a whole.
--- Makefile.am | 6 +- configure.ac | 9 +- plugins/ftp.c | 165 ++------------------------ plugins/nokia-backup.c | 309 ------------------------------------------------ 4 files changed, 16 insertions(+), 473 deletions(-) delete mode 100644 plugins/nokia-backup.c
It seems like you've forgotten to do git add plugins/pcsuite.c?
Anyway, I went ahead and applied patches 1-4.
Johan
Luiz Augusto von Dentz
maintainerRe: [PATCH 5/6] Move pcsuite drivers to its own plugin
Hi,
Quoted 12 lines · Johan Hedberg
Hi Luiz,
Quoted 8 lines · Luiz Augusto von Dentz
This make it easier to enable/disable this funcionality as a whole.
---
Makefile.am | 6 +-
configure.ac | 9 +-
plugins/ftp.c | 165 ++------------------------plugins/nokia-backup.c| 309 ------------------------------------------------4 files changed, 16 insertions(+), 473 deletions(-)delete mode 100644
plugins/nokia-backup.c
Quoted 1 line
It seems like you've forgotten to do git add
plugins/pcsuite.c?
Apparently I did, I will resend it once a figure out where this file is or just redo it.
Quoted 4 lines
Anyway, I went ahead and applied patches 1-4.
Johan
Signature · 2 lines
Luiz Augusto von Dentz Computer Engineer