On 05/17/2018 06:52 AM, Austin Einter wrote: > Hello > I am using libmicrohttpd and facing issue with POST processing. > > The POST message received contains xml or json data. libmicrohttpd does > not support xml / json. So I can not use post process or iterate > callbacks for body data processing. In fact I tried and it does not work > (iterate callbacks not called even when I call post process). > > So I am left with two options. > > 1) Either write body parser, where I need to take care of content-length > case, chunked data case etc.
Nope, that is _always_ take care of by MHD. You just need to feed the "upload_data" you get in your MHD_AccessHandlerCallback as you receive it to your XML or JSON parser, either incrementally or as a whole. > Is there anyway in libmicrohttpd, I can collect the entire POST message > as it comes / received at socket level? Sure. You should look at GNU Taler (https://git.taler.net/), the exchange and the merchant-backend both use MHD to receive JSON-formatted uploads. The core logic for this is actually from/in GNUnet (https://gnunet.org/git/, gnunet.git, src/json/json_mhd.c). So if you are happy with libjansson, you can link against libgnunetjson (like Taler does) and use that code to parse JSON. XML usage would be analogous (and this is ~200 LOC only). Happy hacking! Christian
0xE29FC3CC.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature