libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Missing Feature: Custom HTTP decoding


From: Gerrit Telkamp
Subject: Re: [libmicrohttpd] Missing Feature: Custom HTTP decoding
Date: Mon, 23 Aug 2010 14:34:55 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

A good solution might be to support a custom-specific character decoder,
that is called by libmicrohttpd instead of its internal
MHD_http_unescape(). This custom-specific decoder should be provided as a
call-back method by the user. If it is not defined, the internal
MHD_http_unescape() will be used.

The decoder should get a pointer to the input butter, and might return a
new pointer to the output buffer. This would be useful if the decoded
characters in the output buffer need more memory space than what is
available in the input buffer.
I think your argument for a custom decoder makes sense; however, I'm not sure
about allowing the custom decoder to return a new pointer.  That would require
it to do memory allocation (at least as an option, and if it is optional the
interface will be even messier), and then we'd have to handle failures of that
(yuck).

This is especially critical given that your points do not seem to justify any
need for an unescape function to return a string that is longer than the
original input.  If there is such a case, please describe it.
You are right, when we fix the charcter encoding to UTF-8, we are sure that the size of a decoded buffer will never exceed the size of the unescaped buffer. But an application using libmicrohttpd might need the HTTP stream encoded as UCS-2 (2 bytes per character).

Another option might be to allocate the buffer for the decoded stream at startup, in case it is needed. So the input buffer for the raw HTTP stream (containing escapes) might be 32k, and the output buffer used to store he the decoded stream ("unescaped") might be set to a user-defined size, lets say 64k. If this buffer is more than 0k, it is used for the unescaped stream; if it is 0k, the existing buffer is used.

Best regards

Gerrit.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]