C-language embedded HTTP server; how to manage HTML for output
I am creating an application in C, that includes an embedded HTTP server (uses GNU libmicrohttpd). That part works fine so far. The issue is more a question of style or best practice.
The application uses the HTTP server as a way of providing quasi real-time output of data that it is monitoring. As such, it generates a lot of the HTML on the fly, from data structures maintained by the application at runtime. Presently, the HTML source code is embedded right in the C source code, but this is becoming cumbersome to manage. I would prefer to be able to develop HTML independently from the program logic, and using proper HTML coding tools. I am already moving as much as possible into CSS, in an attempt to decouple the view from the model & controller. The question then becomes how to merge the HTML back into my application. I have thought of a few ways, and each has some strengths and weaknesses.
Anyone else solved this issue already? Are there existing standard tools to help with any particular solution? Googling for a solution seems to turn up mostly articles relating to publishing source code as HTML-formatted data (i.e. the reverse of what I want). --- rod. |
Hi,
I used Handballer as server (http://code.google.com/p/handballer/) and then I serve static pages with content responding to messages transmitted through the server bus. Handballer modifies the Thttpd server for bus messaging. Best regards, Esteban (Note: although I'm listed as one of its developers, the idea and the coding come from Sylvain Garden.) |
HandBaller seems like a most intriguing tool, but doesn't seem to match my present requirements. I don't see at all how it addresses the matter of separation of HTML code from programming source code.
Thanks for your feedback. My present muse is to modify libmicrohttpd. For those who aren't familiar with it, I will explain one of it's behaviors. It has a function which, given an open file descriptor, will send the file to the HTTP client, wrapped up in the associated HTTP machinery. I am considering adding a related function that would parse the specified file, and finding some special tag, perhaps using an existing HTML/XML SAX-style parser, would call a specified callback. The callback could then be used to expand the content of the tag with runtime data. This would allow one to craft pseudo-static HTML using traditional tools, but the runtime behavior would be to use it as a template. Anyone have thoughts on this approach? Especially anyone who has already used libmicrohttpd? --- rod. |
|
Okay, thanks guys, especially lyle_s. I've now located a few C-compatible 'HTML template engines' (that was the key; getting the right keywords to search for). I might go with clearsilver, but there are a few others that I'm looking at, and seem a bit simpler.
--- rod. |
All times are GMT -5. The time now is 04:26 PM. |