Hi,

Thanks Marcel, I think the patch I included earlier works well, as
programmers can easily work out whether an OBEX_CMD_PUT means a
special Delete or Create operation. But I would appreciate any
suggestions for improving it.

Would the maintainers consider this patch, or point out any problems
with it that stop it from being applied?

I have included it again here as an attachment.


thanks,
Bea




On 1/25/07, Marcel Holtmann <[EMAIL PROTECTED]> wrote:
Hi Bea,

> Yes, it would definitely be much easier to ask the library instead of
> working it out yourself. I do have an updated patch that I have
> included below. It will return the appropriate flags for Put-Delete
> and Create-Empty operations. (I don't really see the point of the
> Create operation, but I have included it since it's defined in the
> spec, and anyway it would be odd to have only one possible flag.)
>
> Unfortunately the OBEX_ObjectGetPutFlags() will return the "wrong"
> value if called before the body headers are processed (e.g. in the
> OBEX_EV_REQHINT), but since that's how the operations are defined in
> the spec, there's not much that can be done about it. The programmer
> will just have to deal with the possibility that when you get a Put
> command at the OBEX_EV_REQHINT, it might actually turn out to be a
> Delete at the OBEX_EV_REQ.

I am fine with an API extension. Please work out the best patch and have
Hendrik and Johan agree on it.

Regards

Marcel



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users

--- lib/obex.c.orig	2006-05-26 04:09:41.000000000 +1000
+++ lib/obex.c	2007-01-25 11:37:10.000000000 +1000
@@ -725,6 +725,25 @@
 	return obex_object_readstream(self, object, buf);
 }
 
+/**
+ * OBEX_ObjectGetPutFlags - Get the flags for a received Put request 
+ * @object: OBEX object
+ *
+ * Returns the flags for a received Put request to indicate whether the request
+ * is for a special "Delete" or "Create" operation.
+ *
+ * Note! A Put request cannot be determined to be a "Delete" or "Create" operation
+ * until the appropriate headers have been received and read, so this function 
+ * effectively returns the wrong value if it is called before the request is 
+ * fully processed (i.e. before the OBEX_EV_REQ event).
+ *
+ * Returns 0 if the command for the object is not OBEX_CMD_PUT.
+ */
+int OBEX_ObjectGetPutFlags(obex_object_t *object)
+{
+	obex_return_val_if_fail(object != NULL, -1);
+	return obex_object_getputflags(object);
+}
 
 /**
  * OBEX_ObjectSetRsp - Sets the response to a received request.
--- lib/obex_object.c.orig	2006-05-04 21:24:21.000000000 +1000
+++ lib/obex_object.c	2007-01-25 11:18:59.000000000 +1000
@@ -55,6 +55,9 @@
 		return(NULL);
 	memset(object, 0, sizeof(obex_object_t));
 
+	object->body_received = 0;
+	object->bodyend_received = 0;
+	object->bodyend_received_empty = 0;
 	obex_object_setrsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED);
 	return object;
 }
@@ -320,7 +323,7 @@
 		}
 		
 		if(tx_left < object->s_len) {
-			/*There is more data left in buffer than tx_left */
+			/*There is more data left in buffer than tx_left */
 			DEBUG(4, "More data than tx_left. Buffer will not be empty\n");
 			
 			buf_insert_end(txmsg, (uint8_t*) object->s_buf + object->s_offset, tx_left);
@@ -801,6 +804,16 @@
 			len = hlen - 3;
 
 			if(hi == OBEX_HDR_BODY || hi == OBEX_HDR_BODY_END) {
+				/* if this is a Put, set some flags */
+				if (object->cmd == OBEX_CMD_PUT) {
+					if (hi == OBEX_HDR_BODY) {
+						object->body_received = 1;
+					} else {	/* OBEX_HDR_BODY_END */
+						object->bodyend_received = 1;
+						if (len == 0)
+							object->bodyend_received_empty = 1;
+					}
+				}				
 				/* The body-header need special treatment */
 				if(object->s_srv) {
 					obex_object_receive_stream(self, hi, source, len);
@@ -943,3 +956,22 @@
 	
 	return 0;
 }
+
+int obex_object_getputflags(obex_object_t *object)
+{
+	if (object->cmd != OBEX_CMD_PUT)
+		return 0;
+	
+	/* A Put-Delete has no body nor end-of-body, and a Create-Empty has no
+	   body and an empty end-of-body (spec 3.3.3.6) */
+	if (!object->body_received) {
+		if (!object->bodyend_received) {
+			return OBEX_FL_PUT_DELETE;
+		} else {
+			if (object->bodyend_received_empty)
+				return OBEX_FL_PUT_CREATE;
+		}
+	}
+	
+	return 0;
+}
--- lib/obex_object.h.orig	2006-05-04 21:24:21.000000000 +1000
+++ lib/obex_object.h	2007-01-25 11:19:03.000000000 +1000
@@ -82,6 +82,10 @@
 	unsigned int s_offset;		/* Current offset in buf */
 	int s_stop;			/* End of stream */
 	int s_srv;			/* Deliver body as stream when server */
+ 
+	int body_received;		/* a body header was found in received headers */
+	int bodyend_received;	/* an end-of-body header was found in received headers */
+	int bodyend_received_empty;	/* received an end-of-body header and it was empty */
 
 } obex_object_t;
 
@@ -102,4 +106,6 @@
 int obex_object_suspend(obex_object_t *object);
 int obex_object_resume(obex_t *self, obex_object_t *object);
 
+int obex_object_getputflags(obex_object_t *object);
+
 #endif
--- include/obex.h.orig	2006-01-04 09:06:58.000000000 +1000
+++ include/obex.h	2007-01-25 11:19:26.000000000 +1000
@@ -100,6 +100,7 @@
 int OBEX_ObjectSetNonHdrData(obex_object_t *object, const uint8_t *buffer, unsigned int len);
 int OBEX_ObjectSetHdrOffset(obex_object_t *object, unsigned int offset);
 int OBEX_ObjectReadStream(obex_t *self, obex_object_t *object, const uint8_t **buf);
+int OBEX_ObjectGetPutFlags(obex_object_t *object);
 
 int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size);
 int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size);
--- include/obex_const.h.orig	2006-03-08 22:18:55.000000000 +1000
+++ include/obex_const.h	2007-01-25 11:19:30.000000000 +1000
@@ -104,6 +104,10 @@
 #define OBEX_FL_STREAM_DATAEND	0x08	/* Body stream last data */
 #define OBEX_FL_SUSPEND		0x10	/* Suspend after sending this header */
 
+/* For OBEX_ObjectGetPutFlags() */
+#define OBEX_FL_PUT_DELETE 	0x01	/* The received Put request is for a Put-Delete */
+#define OBEX_FL_PUT_CREATE 	0x02	/* The received Put request is for a Create-Empty */
+
 /* Transports */
 #define OBEX_TRANS_IRDA		1
 #define OBEX_TRANS_INET		2
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users

Reply via email to