dbus_message_demarshal() and partial messages

Avery Pennarun apenwarr at gmail.com
Tue Aug 14 16:40:10 PDT 2007


On 14/08/07, Thiago Macieira <thiago at kde.org> wrote:
> Avery Pennarun wrote:
> >After more digging around, I've found
> >_dbus_header_have_message_untrusted(). A slight variation on this
> >function (a normal program has no need for most of the information it
> >returns) would be great to add to the api.
>
> All you need is a function that takes a buffer and its length and returns
> the length of the first message in it.
>
> Return values would be:
> 0 -> impossible to determine, buffer is too small
> -1 -> error happened, message/buffer is corrupted
> x>0 -> length of the message
[...]
> I can't come up with a name for it. It seems wrong to me to use
> dbus_message_* because it doesn't actually operate on a message...

I might name it dbus_message_demarshal_bytes_needed().

Note that in my imagination, if the provided length is less than
DBUS_MINIMUM_HEADER_SIZE, then x should probably be
DBUS_MINIMUM_HEADER_SIZE.  If you come back with that number of bytes,
then you get a new, larger x.  This make it obvious how to write your
socket library:

x = dbus_message_demarshal_bytes_needed(buf, len);
if (x > len)
    read more bytes;
else
    dbus_message_demarshal();

Any comments?  How do we go about getting such a function into the library?

Thanks,

Avery


More information about the dbus mailing list