Hi Johan,

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.

So with the updated patch you could do this in the event callback:


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

        if (putFlags & OBEX_FL_PUT_DELETE) {
            handleDeleteRequest();

        } else if (putFlags & OBEX_FL_PUT_CREATE) {
            handleCreateRequest();

        } else {
            handleOrdinaryPutRequest();
        }
    }
}


Except the create could be handled the same way as an ordinary Put anyway.

Also you could subsitute "&" for "==" since it can't be a Create and a
Delete at the same time.

Here is the patch:


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





Regards,

Bea





On 1/25/07, Johan Hedberg <[EMAIL PROTECTED]> wrote:
> Hi Bea,
>
> On Wed, Jan 24, 2007, Bea Lam wrote:
> > I've looked at it again and I've realised it's possible to recognise
> > the Delete and Create commands without a patch. To work around it, the
> > user just has to keep track of whether the OBEX_EV_STREAMAVAIL event
> > is received or not in order to determine whether the command is a
> > Put-Delete, since this event is not received if no Body nor
> > End-of-Body headers are received while streaming a Put.
> >
> > To recognise a Create command, the user needs to recognise Delete
> > commands; i.e. if it's a Put operation that's not a Delete, and the
> > body length is zero, it must be a Create. So with this workaround, the
> > Create command cannot be recognised without also recognising the
> > Delete command.
>
> It seems that even if detecting these cases is currently possible, a
> simpler (and more intuitive) way to do it would be a good thing to have.
> A "get flags" function would probably do the trick. Is the patch you
> sent still your latest proposal or do you have an updated version? (I
> don't really have any strong opinion about whether it should be
> OBEX_ObjectGetPutFlags or a generic OBEX_ObjectGetRequestFlags).
>
> Johan
>
> -------------------------------------------------------------------------
> 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
>

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