From: Jeroen H. <vex...@gm...> - 2010-02-11 16:34:37
|
Hi guys, On Thu, Feb 11, 2010 at 15:25, Dean Michael Berris <mik...@gm...> wrote: > I was thinking about this a little and thought it would be cool to > have a collection of utilities of commonly-performed actions that > others might find useful in the library. Off the top of my head I find > that these would be cool functions/mini-libraries to have: This would be very nice indeed. Also, in my opinion, we need a few more code examples as I've generally found them to be a good way to familiarize yourself with a library. Something like a simple HTTP proxy might even fall in both categories, showing off both the client and server side of the library. > * MIME Parser (Marshall Clow has a cool one worthy of more attention > and discussion, hopefully he merges it into cpp-netlib in time for > BoostCon 2010 ;) ). > * Form encoding/decoding (for HTTP clients/servers to handle HTML > form encoded data) > * Query string encoding/decoding (for GET queries) > * Base64 stream/string encoding/decoding (for Binary data) > * URI pattern-based dispatch (ala Rails, or Django/Tornado) > > I find myself wanting to write these myself or at least using them > when I write programs that use cpp-netlib. Simple things like for HTTP > server based applications I want to be able to parse a list of > parameters (remembering what Jeroen was proposing to do with the URI > parser one time). The query parser is indeed one of the things currently on the TODO list for the URI part of the library. Design-wise I was thinking of something like: template <class Tag> bool parse_query(basic_uri<Tag> const & uri, typename query_list<Tag>::type &) { // TODO Parse using Spirit return true; // Return whether it was successful. } with template <class Tag> struct query_list { typedef typename string<Tag>::type string_type; typedef typename std::list<std::pair<string_type, string_type> > type; } and something along the same lines for query_map for a std::map. This is off the top of my head, and your thoughts would be very much appreciated. As I've said before, most of the grunt work has already been done by Hartmunt in this brilliant article: http://boost-spirit.com/home/articles/qi-example/parsing-a-list-of-key-value-pairs-using-spirit-qi/ thus with some luck this is actually rather easy. Secondly, I have the basis of a dispatcher I wrote for libevent bindings some time ago, which I've attached. There seem to be a few things which need to be abstracted from though: - The comparison function - The type you're comparing to and quite probably a few more things, as ultimately I'd be very useful if you could stick in boost::starts_with, something from the regex library or from the xpressive library to find a match. If anyone finds this code is of any use for cpp-netlib, I'll stick a boost license on it. > Any takers? It would be cool if we had these in the library before May > where I will be presenting the library and the techniques used in the > library at a high level. ;) This is where things get tricky, considering I've just got an apartment this month and will be moving, I'm quite limited when it comes to free time unfortunately. > Hope this helps and I hope to hear from you guys soon too! > Hope this is of any use, Jeroen Habraken |