obexd/client: Allow suspending transfer while they are queued
Luiz Augusto von Dentz
maintainerPATCH 1/7 obexd/client: Allow suspending transfer while they are queued
From: Luiz Augusto von Dentz <[email protected]>
Transfer may be created by different processes so it make sense to allow them to be suspended even if they are not active.
--- obexd/client/transfer.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-)
obexd/client/transfer.c +38 -9
@@ -62,6 +62,7 @@ enum {TRANSFER_STATUS_ACTIVE ,TRANSFER_STATUS_SUSPENDED ,TRANSFER_STATUS_COMPLETE , +TRANSFER_STATUS_SUSPENDED_QUEUED , TRANSFER_STATUS_ERROR };
@@ -213,6 +214,7 @@ static DBusMessage *obc_transfer_suspend(DBusConnection *connection, {struct obc_transfer *transfer = user_data;const char *sender; +uint8_t status; sender =dbus_message_get_sender (message);if (g_strcmp0 (transfer->owner, sender) !=0 )
@@ -220,14 +222,22 @@ static DBusMessage *obc_transfer_suspend(DBusConnection *connection,ERROR_INTERFACE ".NotAuthorized" , "Not Authorized"); -if (transfer->xfer ==0 ) +switch (transfer->status) { +case TRANSFER_STATUS_QUEUED : + status =TRANSFER_STATUS_SUSPENDED_QUEUED ; +break ; +case TRANSFER_STATUS_ACTIVE : +if (transfer->xfer) +g_obex_suspend (transfer->obex); + status =TRANSFER_STATUS_SUSPENDED ; +break ; +default :return g_dbus_create_error (message,ERROR_INTERFACE ".NotInProgress" ,"Not in progress" ); + } -g_obex_suspend (transfer->obex); - -transfer_set_status (transfer,TRANSFER_STATUS_SUSPENDED ); +transfer_set_status (transfer, status);return g_dbus_create_reply (message,DBUS_TYPE_INVALID ); }
@@ -237,6 +247,7 @@ static DBusMessage *obc_transfer_resume(DBusConnection *connection, {struct obc_transfer *transfer = user_data;const char *sender; +uint8_t status; sender =dbus_message_get_sender (message);if (g_strcmp0 (transfer->owner, sender) !=0 )
@@ -244,14 +255,24 @@ static DBusMessage *obc_transfer_resume(DBusConnection *connection,ERROR_INTERFACE ".NotAuthorized" , "Not Authorized"); -if (transfer->xfer ==0 ) +switch (transfer->status) { +case TRANSFER_STATUS_SUSPENDED_QUEUED : + status =TRANSFER_STATUS_QUEUED ; +break ; +case TRANSFER_STATUS_SUSPENDED : +if (transfer->xfer) +g_obex_resume (transfer->obex); +else +obc_transfer_start (transfer,NULL ,NULL ); + status =TRANSFER_STATUS_ACTIVE ; +break ; +default :return g_dbus_create_error (message,ERROR_INTERFACE ".NotInProgress" ,"Not in progress" ); + } -g_obex_resume (transfer->obex); - -transfer_set_status (transfer,TRANSFER_STATUS_ACTIVE ); +transfer_set_status (transfer, status);return g_dbus_create_reply (message,DBUS_TYPE_INVALID ); }
@@ -338,6 +359,7 @@ static const char *status2str(uint8_t status)return "queued" ;case TRANSFER_STATUS_ACTIVE :return "active" ; +case TRANSFER_STATUS_SUSPENDED_QUEUED :case TRANSFER_STATUS_SUSPENDED :return "suspended" ;case TRANSFER_STATUS_COMPLETE :
@@ -861,7 +883,14 @@ static gboolean transfer_start_put(struct obc_transfer *transfer, GError **err)gboolean obc_transfer_start (struct obc_transfer *transfer,void *obex,GError **err) { - transfer->obex =g_obex_ref (obex); +if (!transfer->obex) + transfer->obex =g_obex_ref (obex); + +if (transfer->status ==TRANSFER_STATUS_SUSPENDED_QUEUED ) { +/* Reset status so the transfer can be resumed */ + transfer->status =TRANSFER_STATUS_SUSPENDED ; +return TRUE; + }switch (transfer->op) {case G_OBEX_OP_GET :
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 2/7 obexd/client: Fix not being able to cancel a suspended transfer
From: Luiz Augusto von Dentz <[email protected]>
If a transfer is suspended it should be resumed before cancelling otherwise it will timeout.
--- obexd/client/transfer.c | 9 +++++++++ 1 file changed, 9 insertions(+)
obexd/client/transfer.c +9 -0
@@ -160,6 +160,9 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,ERROR_INTERFACE ".InProgress" , "Cancellation already in progress"); +if (transfer->status ==TRANSFER_STATUS_SUSPENDED ) +g_obex_resume (transfer->obex); +if (transfer->req >0 ) {if (!g_obex_cancel_req (transfer->obex, transfer->req, TRUE)) return g_dbus_create_error(message,
@@ -414,6 +417,9 @@ static void obc_transfer_free(struct obc_transfer *transfer) {DBG ("%p" , transfer); +if (transfer->status ==TRANSFER_STATUS_SUSPENDED ) +g_obex_resume (transfer->obex); +if (transfer->req >0 )g_obex_cancel_req (transfer->obex, transfer->req, TRUE);
@@ -659,6 +665,9 @@ static void xfer_complete(GObex *obex, GError *err, gpointer user_data) transfer->progress_id =0 ; } +if (transfer->status ==TRANSFER_STATUS_SUSPENDED ) +g_obex_resume (transfer->obex); +if (err)transfer_set_status (transfer,TRANSFER_STATUS_ERROR );else
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 3/7 gobex: Fix warning if g_obex_resume is called when disconnected
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- gobex/gobex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
gobex/gobex.c +1 -1
@@ -514,7 +514,7 @@ static void enable_tx(GObex *obex)if (obex->suspended)return ; -if (obex->write_source >0 ) +if (!obex->io || obex->write_source >0 )return ; cond =G_IO_OUT |G_IO_HUP |G_IO_ERR |G_IO_NVAL ;
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 4/7 gobex: Fix crash when debug is enabled
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
GError can be NULL thus causing invalid read when trying to a message member such as bellow:
Invalid read of size 8
at 0x41190F: g_obex_send_internal (gobex.c:531)
by 0x4130A6: g_obex_send_req (gobex.c:756)
by 0x4268A5: obc_session_unref (session.c:289)
by 0x41396A: incoming_data (gobex.c:1397)
by 0x59712A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x5971627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x5971A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x40D78C: main (main.c:320)
Address 0x0 is not stack'd, malloc'd or (recently) free'd
--- gobex/gobex-header.c | 2 ++ gobex/gobex-packet.c | 6 ++++++ gobex/gobex.c | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
gobex/gobex-header.c +2 -0
@@ -146,6 +146,8 @@ GObexHeader *g_obex_header_decode(const void *data, gsize len,GError *conv_err =NULL ;if (len <2 ) { +if (!err) +return NULL ;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_PARSE_ERROR ,"Too short header in packet" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
gobex/gobex-packet.c +6 -0
@@ -325,6 +325,8 @@ GObexPacket *g_obex_packet_decode(const void *data, gsize len,g_obex_debug (G_OBEX_DEBUG_PACKET ,"" );if (data_policy ==G_OBEX_DATA_INHERIT ) { +if (!err) +return NULL ;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_INVALID_ARGS ,"Invalid data policy" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
@@ -332,6 +334,8 @@ GObexPacket *g_obex_packet_decode(const void *data, gsize len, }if (len <3 + header_offset) { +if (!err) +return NULL ;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_PARSE_ERROR ,"Not enough data to decode packet" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
@@ -343,6 +347,8 @@ GObexPacket *g_obex_packet_decode(const void *data, gsize len, packet_len =g_ntohs (packet_len);if (packet_len != len) { +if (!err) +return NULL ;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_PARSE_ERROR ,"Incorrect packet length (%u != %zu)" , packet_len, len);
gobex/gobex.c +9 -1
@@ -526,6 +526,8 @@ static gboolean g_obex_send_internal(GObex *obex, struct pending_pkt *p, {if (obex->io ==NULL ) { +if (!err) +return FALSE;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_DISCONNECTED ,"The transport is not connected" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
@@ -663,6 +665,8 @@ gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err)g_obex_debug (G_OBEX_DEBUG_COMMAND ,"conn %u" , obex->conn_id);if (obex ==NULL || pkt ==NULL ) { +if (!err) +return FALSE;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_INVALID_ARGS ,"Invalid arguments" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
@@ -1230,6 +1234,8 @@ static gboolean read_stream(GObex *obex, GError **err) obex->rx_pkt_len =g_ntohs (u16);if (obex->rx_pkt_len > obex->rx_mtu) { +if (!err) +return FALSE;g_set_error (err,G_OBEX_ERROR ,G_OBEX_ERROR_PARSE_ERROR ,"Too big incoming packet" );g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message);
@@ -1302,7 +1308,9 @@ static gboolean read_packet(GObex *obex, GError **err)return TRUE; fail: -g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message); +if (err) +g_obex_debug (G_OBEX_DEBUG_ERROR ,"%s" , (*err)->message); +return FALSE; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 5/7 obexd/client: Fix crash while disconnecting
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
In case the transport is disconnected while disconnect command is pending the session is freed on disconnect_complete but disconnect callback is still valid causing the following crash:
Invalid read of size 4
at 0x42682A: obc_session_ref (session.c:132)
by 0x42797B: obc_session_shutdown (session.c:580)
by 0x4139DA: incoming_data (gobex.c:1406)
by 0x59712A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x5971627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x5971A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x40D78C: main (main.c:320)
Address 0x728d814 is 4 bytes inside a block of size 120 free'd
at 0x4C28577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5976F7E: g_free (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x4134B9: handle_response (gobex.c:1129)
by 0x4139BD: incoming_data (gobex.c:1403)
by 0x59712A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x5971627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
by 0x5971A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2) by 0x40D78C: main (main.c:320)
--- obexd/client/session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
obexd/client/session.c +3 -1
@@ -225,8 +225,10 @@ static void session_free(struct obc_session *session)if (session->watch)g_dbus_remove_watch (session->conn, session->watch); -if (session->obex !=NULL ) +if (session->obex) { +g_obex_set_disconnect_function (session->obex,NULL ,NULL );g_obex_unref (session->obex); + }if (session->id >0 && session->transport !=NULL ) session->transport->disconnect (session->id);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 6/7 gobex: Add g_obex_abort
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- gobex/gobex-transfer.c | 7 ++----- gobex/gobex.c | 10 ++++++++++ gobex/gobex.h | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-)
gobex/gobex-transfer.c +2 -5
@@ -152,11 +152,8 @@ static gssize put_get_data(void *buf, gsize len, gpointer user_data) goto done; } - req =g_obex_packet_new (G_OBEX_OP_ABORT , TRUE,G_OBEX_HDR_INVALID ); - - transfer->req_id =g_obex_send_req (transfer->obex, req,-1 , - transfer_abort_response, - transfer, &err); + transfer->req_id =g_obex_abort (transfer->obex, transfer_abort_response, + transfer, &err); done:if (err !=NULL ) {transfer_complete (transfer, err);
gobex/gobex.c +10 -0
@@ -1676,6 +1676,16 @@ guint g_obex_move(GObex *obex, const char *name, const char *dest,return g_obex_send_req (obex, req,-1 , func, user_data, err); } +guint g_obex_abort (GObex *obex,GObexResponseFunc func,gpointer user_data, +GError **err) +{ +GObexPacket *req; + + req =g_obex_packet_new (G_OBEX_OP_ABORT , TRUE,G_OBEX_HDR_INVALID ); + +return g_obex_send_req (obex, req,-1 , func, user_data, err); +} +guint8 g_obex_errno_to_rsp (int err) {switch (err) {
gobex/gobex.h +3 -0
@@ -95,6 +95,9 @@ guint g_obex_move(GObex *obex, const char *name, const char *dest, GObexResponseFunc func, gpointer user_data, GError **err); +guint g_obex_abort (GObex *obex,GObexResponseFunc func,gpointer user_data, +GError **err); +/* Transfer related high-level functions */ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 7/7 gobex: Abort if there is no request to cancel
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If there is no request to cancel send an abort since otherwise the remote may hang waiting.
--- gobex/gobex-transfer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
gobex/gobex-transfer.c +7 -2
@@ -653,8 +653,13 @@ gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func, transfer->complete_func = complete_func; transfer->user_data = user_data; -if (transfer->req_id ==0 ) - goto done; +if (!transfer->req_id) { + transfer->req_id =g_obex_abort (transfer->obex, + transfer_abort_response, + transfer,NULL ); +if (transfer->req_id) +return TRUE; + } ret =g_obex_cancel_req (transfer->obex, transfer->req_id, FALSE);if (ret)
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerHi,
Quoted 117 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
Transfer may be created by different processes so it make sense to allow them to be suspended even if they are not active.
--- obexd/client/transfer.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-)obexd/client/transfer.c +38
-10@@ -62,6 +62,7 @@ enum {TRANSFER_STATUS_ACTIVE ,TRANSFER_STATUS_SUSPENDED ,TRANSFER_STATUS_COMPLETE , +TRANSFER_STATUS_SUSPENDED_QUEUED , TRANSFER_STATUS_ERROR };@@ -213,6 +214,7 @@ static DBusMessage *obc_transfer_suspend(DBusConnection *connection, {struct obc_transfer *transfer = user_data;const char *sender; +uint8_t status; sender =dbus_message_get_sender (message);if (g_strcmp0 (transfer->owner, sender) !=0 )@@ -220,14 +222,22 @@ static DBusMessage *obc_transfer_suspend(DBusConnection *connection,ERROR_INTERFACE ".NotAuthorized" , "Not Authorized"); -if (transfer->xfer ==0 ) +switch (transfer->status) { +case TRANSFER_STATUS_QUEUED : + status =TRANSFER_STATUS_SUSPENDED_QUEUED ; +break ; +case TRANSFER_STATUS_ACTIVE : +if (transfer->xfer) +g_obex_suspend (transfer->obex); + status =TRANSFER_STATUS_SUSPENDED ; +break ; +default :return g_dbus_create_error (message,ERROR_INTERFACE ".NotInProgress" ,"Not in progress" ); + } -g_obex_suspend (transfer->obex); - -transfer_set_status (transfer,TRANSFER_STATUS_SUSPENDED ); +transfer_set_status (transfer, status);return g_dbus_create_reply (message,DBUS_TYPE_INVALID ); }@@ -237,6 +247,7 @@ static DBusMessage *obc_transfer_resume(DBusConnection *connection, {struct obc_transfer *transfer = user_data;const char *sender; +uint8_t status; sender =dbus_message_get_sender (message);if (g_strcmp0 (transfer->owner, sender) !=0 )@@ -244,14 +255,24 @@ static DBusMessage *obc_transfer_resume(DBusConnection *connection,ERROR_INTERFACE ".NotAuthorized" , "Not Authorized"); -if (transfer->xfer ==0 ) +switch (transfer->status) { +case TRANSFER_STATUS_SUSPENDED_QUEUED : + status =TRANSFER_STATUS_QUEUED ; +break ; +case TRANSFER_STATUS_SUSPENDED : +if (transfer->xfer) +g_obex_resume (transfer->obex); +else +obc_transfer_start (transfer,NULL ,NULL ); + status =TRANSFER_STATUS_ACTIVE ; +break ; +default :return g_dbus_create_error (message,ERROR_INTERFACE ".NotInProgress" ,"Not in progress" ); + } -g_obex_resume (transfer->obex); - -transfer_set_status (transfer,TRANSFER_STATUS_ACTIVE ); +transfer_set_status (transfer, status);return g_dbus_create_reply (message,DBUS_TYPE_INVALID ); }@@ -338,6 +359,7 @@ static const char *status2str(uint8_t status)return "queued" ;case TRANSFER_STATUS_ACTIVE :return "active" ; +case TRANSFER_STATUS_SUSPENDED_QUEUED :case TRANSFER_STATUS_SUSPENDED :return "suspended" ;case TRANSFER_STATUS_COMPLETE :@@ -861,7 +883,14 @@ static gboolean transfer_start_put(struct obc_transfer *transfer, GError **err)gboolean obc_transfer_start (struct obc_transfer *transfer,void *obex,GError **err) { - transfer->obex =g_obex_ref (obex); +if (!transfer->obex) + transfer->obex =g_obex_ref (obex); + +if (transfer->status ==TRANSFER_STATUS_SUSPENDED_QUEUED ) { +/* Reset status so the transfer can be resumed */ + transfer->status =TRANSFER_STATUS_SUSPENDED ; +return TRUE; + }switch (transfer->op) {case G_OBEX_OP_GET : --
Quoted 1 line
1.9.3
Pushed.
Signature · 1 line
Luiz Augusto von Dentz