Hi,

This is a patch to add support for Put-Delete and Create-Empty
operations. The specs define them like this (in 3.3.3.6): "A PUT
operation with NO Body or End-of-Body header whatsoever should be
treated as a delete request. Similarly, a PUT operation with an empty
End-of-Body header request the recipient to create an empty object."

Currently it's not possible to recognise Put-Delete and Create-Empty
operations on the server side, because Body and End-of-Body data can't
be read separately by the programmer (since End-of-Body data is joined
with Body data by the library). So if you receive zero body data in a
Put operation, you know that it's either a Delete or Create operation,
but there's no way to know which one it is.

The patch allows for something like this within the user event
callback function, in order to distinguish between an ordinary Put
request, a Put-Delete and a Create-Empty:

        case OBEX_EV_REQ:
                if (obex_cmd == OBEX_CMD_PUT) {
                        int putFlags = OBEX_ObjectGetPutFlags(obj);

                        if ((putFlags & OBEX_FL_PUT_HAS_BODY) == 0) {
                                // no body present in request

                                if ((putFlags & OBEX_FL_PUT_HAS_BODY_END) == 0 
) {
                                        // no end-of-body either
                                        handleDeleteRequest();
                                        return;

                                } else if ((putFlags & 
OBEX_FL_PUT_HAS_BODY_END_DATA) == 0 ) {
                                        // end of body is empty
                                        handleCreateRequest();
                                        return;
                                }
                        }

                        // it's an ordinary put request
                        handlePutRequest();
                }



Regards,

Bea




--- obex_const.h.orig   2006-03-08 22:18:55.000000000 +1000
+++ obex_const.h        2006-11-29 17:23:05.000000000 +1000
@@ -104,6 +104,12 @@
#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_HAS_BODY            0x01
+#define OBEX_FL_PUT_HAS_BODY_DATA       0x02
+#define OBEX_FL_PUT_HAS_BODY_END        0x04
+#define OBEX_FL_PUT_HAS_BODY_END_DATA   0x08
+
 /* Transports */
#define OBEX_TRANS_IRDA         1
#define OBEX_TRANS_INET         2
--- obex.h.orig 2006-01-04 09:06:58.000000000 +1000
+++ obex.h      2006-11-29 17:23:10.000000000 +1000
@@ -101,6 +101,8 @@
 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);

--- obex.c.orig 2006-05-26 04:09:41.000000000 +1000
+++ obex.c      2006-11-29 17:21:20.000000000 +1000
@@ -725,6 +725,18 @@
        return obex_object_readstream(self, object, buf);
}

+/**
+ * OBEX_ObjectGetPutFlags - Get the flags for a Put request
+ * @object: OBEX object
+ *
+ * Returns the flags for a Put request. Returns -1 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.
--- obex_object.h.orig  2006-05-04 21:24:21.000000000 +1000
+++ obex_object.h       2006-11-29 17:21:35.000000000 +1000
@@ -82,6 +82,8 @@
        unsigned int s_offset;          /* Current offset in buf */
        int s_stop;                     /* End of stream */
        int s_srv;                      /* Deliver body as stream when server */
+
+       int putflags;   /* Gives extra info about a received Put request */

} obex_object_t;

@@ -101,5 +103,6 @@
 int obex_object_readstream(obex_t *self, obex_object_t *object, const
uint8_t **buf);
 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
--- obex_object.c.orig  2006-05-04 21:24:21.000000000 +1000
+++ obex_object.c       2006-11-29 17:21:26.000000000 +1000
@@ -55,6 +55,7 @@
                return(NULL);
        memset(object, 0, sizeof(obex_object_t));

+       object->putflags = 0;
        obex_object_setrsp(object, OBEX_RSP_NOT_IMPLEMENTED,
OBEX_RSP_NOT_IMPLEMENTED);
        return object;
}
@@ -320,7 +321,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 +802,19 @@
                        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->putflags |= 
OBEX_FL_PUT_HAS_BODY;
+                                               if (len > 0)
+                                                       object->putflags |= 
OBEX_FL_PUT_HAS_BODY_DATA;
+}
+                                       if (hi == OBEX_HDR_BODY_END) {
+                                               object->putflags |= 
OBEX_FL_PUT_HAS_BODY_END;
+                                               if (len > 0)
+                                                       object->putflags |= 
OBEX_FL_PUT_HAS_BODY_END_DATA;
+                                       }
+                               }
                                /* The body-header need special treatment */
                                if(object->s_srv) {
                                        obex_object_receive_stream(self, hi, 
source, len);
@@ -943,3 +957,10 @@

        return 0;
}
+
+int obex_object_getputflags(obex_object_t *object)
+{
+       if (object->cmd != OBEX_CMD_PUT)
+               return -1;
+       return object->putflags;
+}

-------------------------------------------------------------------------
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