Hello Gerald,

I recomend to use tntnet as a http server. The cxxtools http server is more 
limited. But if it is sufficient for you, you can go for it. It is due to the 
limitations even faster than tntnet.

Let me answer the second question first, since it is just easier. To convert 
http query parameters you have to use one of the parse_url methods in 
QueryParams. Like this (untested):

void MyResponder::reply(std::ostream& out, cxxtools::http::Request& request, 
cxxtools::http::Reply& reply)
{
  cxxtools::QueryParams q;
  if (request.method() == "POST")
    q.parse_url(request.bodyStr());
  else
    q.parse_url(request.qparams());

  std::string parameterA = q.param("A");
  ...


The json formatter uses the serialization framework of cxxtools as mentioned 
in the xmlrpc article. Lets assume, we want to serialize a std::vector of 
MyStruct elements like in the example. It goes like this:

void MyResponder::reply(std::ostream& out, cxxtools::http::Request& request, 
cxxtools::http::Reply& reply)
{
  std::vector<MyStruct> theStructs = fetchFromSomewhere();
  // the serializer writes the result to a std::ostream. To get the result to
  // a std::string you may use a std::ostringstream
  cxxtools::JsonSerializer serializer(reply.body());
  serializer.serialize(theStructs, "theStructs");
  serializer.finish();
}

Now you get a json object, with a object with the name "theStructs". To access 
the object in javascript you may use something like:

theJsonObject.theStructs[2].aValue;
theJsonObject.theStructs[14].aList[6];

The javascript object has no unnecessary whitespace so it will be somewhat 
hard to read if you look at it. It may be useful to format it nicer. This can 
be done using the beautify flag in the json formatter. Then it looks like this:

  cxxtools::JsonSerializer serializer;
  serializer.beautify(true);
  serializer.begin(reply.body());


Tommi


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to