[PATCH BlueZ 2/3] gobex: Make PUT request with just filler byte to set the final bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

This make PUT request with just filler byte 0x30 to be treated as there
is no data and thus avoid an extra packet to be sent.

Some profiles such as MAP use this to workaround PUT being interpreted as
a delete request:

"5.7.5 Body/EndOfBody
To avoid PUT with empty Body leading to a 'delete' of the related
message these headers shall contain a filler byte. The value of this
byte shall be set to 0x30 (="0")."

Future PIM related specs in development also seems to be following the
use of filler byte.
---
 gobex/gobex-packet.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gobex/gobex-packet.c b/gobex/gobex-packet.c
index 4c14cf7..96f8c76 100644
--- a/gobex/gobex-packet.c
+++ b/gobex/gobex-packet.c
@@ -387,9 +387,15 @@ static gssize get_body(GObexPacket *pkt, guint8 *buf, gsize len)
 	if (ret < 0)
 		return ret;
 
-	if (ret > 0)
-		buf[0] = G_OBEX_HDR_BODY;
-	else
+	if (ret > 0) {
+		/* To avoid PUT with empty Body leading to a 'delete' some
+		 * transfer may use a filler byte of 0x30 (="0").
+		 */
+		if (ret == 2 && strcmp((char *) buf + 3, "0") == 0)
+			buf[0] = G_OBEX_HDR_BODY_END;
+		else
+			buf[0] = G_OBEX_HDR_BODY;
+	} else
 		buf[0] = G_OBEX_HDR_BODY_END;
 
 	u16 = g_htons(ret + 3);
@@ -440,7 +446,7 @@ gssize g_obex_packet_encode(GObexPacket *pkt, guint8 *buf, gsize len)
 		ret = get_body(pkt, buf + count, len - count);
 		if (ret < 0)
 			return ret;
-		if (ret == 0) {
+		if (ret == 0 || buf[count] == G_OBEX_HDR_BODY_END) {
 			if (pkt->opcode == G_OBEX_RSP_CONTINUE)
 				buf[0] = G_OBEX_RSP_SUCCESS;
 			buf[0] |= FINAL_BIT;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux