Hendrik Sattler | 30 Jun 2011 19:42
Picon

Several fixes for issues previous mentioned on this list

Hi,

These patches fix a bug when sending when using non-blocking sockets. It also
fixes bugs with sending (stream and non-stream). They also change obex_test
from scanf("%199c") to fgets() because the former simply doesn't work ("%s" did
but "%199c" ignores <Enter>) and the latter is way easier to use and understand.
After that was fixed, using obex_test actually revealed that the mode is wrong
for REQDONE event and probably all others where it is changed before the event.

HS

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
Hendrik Sattler | 30 Jun 2011 19:42
Picon

[PATCH 1/5] Add function buf_empty() and use it to fix send bug

If non-blocking file descriptors or sockets are used, it can happen that
incomplete message get sent.
---
 lib/databuffer.c |    7 +++++++
 lib/databuffer.h |    1 +
 lib/obex_main.c  |    2 +-
 3 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/lib/databuffer.c b/lib/databuffer.c
index 1c43324..72bd4ca 100644
--- a/lib/databuffer.c
+++ b/lib/databuffer.c
 <at>  <at>  -113,6 +113,13  <at>  <at>  size_t buf_total_size(const buf_t *p)
 	return p->head_avail + p->data_avail + p->tail_avail + p->data_size;
 }

+int buf_empty(const buf_t *p)
+{
+	if (!p)
+		return 1;
+	return (p->data_size == 0);
+}
+
 void buf_resize(buf_t *p, size_t new_size)
 {
 	uint8_t *tmp;
diff --git a/lib/databuffer.h b/lib/databuffer.h
index f55a056..2ef8204 100644
--- a/lib/databuffer.h
+++ b/lib/databuffer.h
(Continue reading)

Hendrik Sattler | 30 Jun 2011 19:42
Picon

[PATCH 3/5] Fix behaviour of STREAM send functionality

---
 lib/obex_object.c |   35 ++++++++++++++++-------------------
 1 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/lib/obex_object.c b/lib/obex_object.c
index e586ee7..124a09e 100644
--- a/lib/obex_object.c
+++ b/lib/obex_object.c
 <at>  <at>  -307,7 +307,7  <at>  <at>  static int send_stream(obex_t *self,
 	actual = sizeof(*hdr);

 	do {
-		if (object->s_len == 0) {
+		if (object->s_len == 0 && !object->s_stop) {
 			/* Ask app for more data if no more */
 			object->s_offset = 0;
 			object->s_buf = NULL;
 <at>  <at>  -315,20 +315,9  <at>  <at>  static int send_stream(obex_t *self,
 								0, FALSE);
 			DEBUG(4, "s_len=%d, s_stop = %d\n",
 						object->s_len, object->s_stop);
-			/* End of stream ?*/
-			if (object->s_stop)
-				break;
-
-			/* User suspended and didn't provide any new data */
-			if (object->suspend && object->s_buf == NULL)
-				break;
-
-			/* Error ?*/
(Continue reading)

Hendrik Sattler | 30 Jun 2011 19:42
Picon

[PATCH 2/5] Fix BODY_END header and its debug message

---
 lib/obex_object.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/obex_object.c b/lib/obex_object.c
index cbfd1f1..e586ee7 100644
--- a/lib/obex_object.c
+++ b/lib/obex_object.c
 <at>  <at>  -412,12 +412,14  <at>  <at>  static int send_body(obex_object_t *object, struct obex_header_element *h,
 		/* We have completely filled the tx-buffer */
 		actual = tx_left;
 	} else {
-		DEBUG(4, "Add BODY_END header\n");
-
-		if (slist_has_more(object->tx_headerq))
-			hdr->hi = OBEX_HDR_BODY_END;
-		else
+		if (slist_has_more(object->tx_headerq)) {
+			DEBUG(4, "Add BODY header\n");
 			hdr->hi = OBEX_HDR_BODY;
+		} else {
+			DEBUG(4, "Add BODY_END header\n");
+			hdr->hi = OBEX_HDR_BODY_END;
+		}
+
 		hdr->hl = htons((uint16_t)(h->buf->data_size + sizeof(*hdr)));
 		buf_insert_end(txmsg, h->buf->data, h->buf->data_size);
 		actual = h->buf->data_size;
--

-- 
1.7.5.4
(Continue reading)

Hendrik Sattler | 30 Jun 2011 19:42
Picon

[PATCH 4/5] Fix reading user input in obex_test

---
 apps/obex_test/obex_test.c        |   12 ++++---
 apps/obex_test/obex_test_client.c |   61 ++++++++++++++++++++++--------------
 2 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/apps/obex_test/obex_test.c b/apps/obex_test/obex_test.c
index 4200f9b..350d808 100644
--- a/apps/obex_test/obex_test.c
+++ b/apps/obex_test/obex_test.c
 <at>  <at>  -153,8 +153,8  <at>  <at>  static int inet_connect(obex_t *handle)
 //
 int main (int argc, char *argv[])
 {
-	char cmd[10];
-	int num, end = 0;
+	char cmd[3];
+	int end = 0;
 	int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE, usbobex = FALSE;
 	obex_t *handle;
 #ifdef HAVE_BLUETOOTH
 <at>  <at>  -350,10 +350,12  <at>  <at>  int main (int argc, char *argv[])

 	while (!end) {
 		printf("> ");
-		num = scanf("%s", cmd);
-		if (num == EOF)
+		fflush(stdout);
+		(void)fgets(cmd, sizeof(cmd), stdin);
+		if (cmd[0] == 0) /* EOF */
 			break;
(Continue reading)

Hendrik Sattler | 30 Jun 2011 19:42
Picon

[PATCH 5/5] Fix: set MODE_SRV/STATE_IDLE _after_ sending event

This is needed for obex_test to actually work.
---
 lib/obex_client.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/obex_client.c b/lib/obex_client.c
index 5107d62..0199fbf 100644
--- a/lib/obex_client.c
+++ b/lib/obex_client.c
 <at>  <at>  -61,10 +61,10  <at>  <at>  static int obex_client_recv(obex_t *self, buf_t *msg, int rsp)
 		/* Response of a CMD_CONNECT needs some special treatment.*/
 		DEBUG(2, "We expect a connect-rsp\n");
 		if (obex_parse_connect_header(self, msg) < 0) {
-			self->mode = MODE_SRV;
-			self->state = STATE_IDLE;
 			obex_deliver_event(self, OBEX_EV_PARSEERR,
 						self->object->opcode, 0, TRUE);
+			self->mode = MODE_SRV;
+			self->state = STATE_IDLE;
 			return -1;
 		}
 		self->object->headeroffset=4;
 <at>  <at>  -82,10 +82,10  <at>  <at>  static int obex_client_recv(obex_t *self, buf_t *msg, int rsp)
 	/* Receive any headers */
 	ret = obex_object_receive(self, msg);
 	if (ret < 0) {
-		self->mode = MODE_SRV;
-		self->state = STATE_IDLE;
 		obex_deliver_event(self, OBEX_EV_PARSEERR,
 						self->object->opcode, 0, TRUE);
(Continue reading)


Gmane