From : eric dot lapuyade at access-company dot com
The fix Frederic proposed on the mailing list is actually not good. There is a problem when the event callback starts a new request. For example, I use the CONNECT EV_REQDONE to start a new PUT request, and that would fail with this change. The new PUT request initializes the state as it likes and then the event callback returns. But at this time, the state would be overridden with MODE_SRV.
Let me summarize the last changes:
At changestate 262, the state initialization was moved before calling obex_deliver_event. This was bad because obex_deliver_event uses it to determine the current mode. So it broke all the code who actually use the mode parameter in the event callback.
Frederic proposed to move the state initialization after obex_deliver_event. This is the patch Christian W. Zuckschwerdt said he put on his todo list. But it is also bad to set the state after obex_deliver_event for the reason I mentioned above.
I think the right way to fix this is to pre-initialize the next state before calling obex_deliver_event, and to pass the current state to obex_deliver_event as follows:
OLD IMPLEMENTATION
------------------
void obex_deliver_event(obex_t *self, int event, int cmd, int rsp, int
del)
{
obex_object_t *object = self->object;
if (del == TRUE)
self->object = NULL;
if (self->state & MODE_SRV)
self->eventcb(self, object, OBEX_MODE_SERVER, event, cmd, rsp);
else
self->eventcb(self, object, OBEX_MODE_CLIENT, event, cmd, rsp);
if (del == TRUE)
obex_object_delete(object);
}
NEW PROPOSED IMPLEMENTATION
---------------------------
void obex_deliver_event(obex_t *self, int event, int cmd, int rsp, int del, int mode) {
obex_object_t *object = self->object;
if (del == TRUE)
self->object = NULL;
self->eventcb(self, object, mode, event, cmd, rsp);
if (del == TRUE)
obex_object_delete(object);
}
I have attached a patch file.
patch file