LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2012, 07:53 PM   #1
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
  1. I could create a simple tool that transforms the HTML into C-source literal strings, and #include it into the source code. This doesn't directly accommodate things that aren't known until runtime, such as how many rows a table might have and what content is in each cell of the HTML tables. Some sort of templating system should solve that, but then I have to create a parser for the template data.
  2. I could create a template that the application reads at runtime, and instantiate it with runtime data. That is basically deferring the above from compile time to run time.
  3. I could just continue to embed HTML code into the C source code. It seems that PHP programs have used this method for years. Just doesn't seems clean to me.
  4. I could use some kind of hybrid system, where the HTML that is static is in static files and the changing data is generated on the fly. Messy. No way.

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.

Last edited by theNbomr; 07-02-2012 at 07:55 PM.
 
Old 07-03-2012, 12:19 PM   #2
elucches
Member
 
Registered: Jan 2011
Posts: 108

Rep: Reputation: 11
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.)
 
Old 07-03-2012, 03:53 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399

Original Poster
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 07-03-2012, 06:10 PM   #4
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
Please have a look at clearsilver: http://www.clearsilver.net/

Lyle.
 
Old 07-05-2012, 03:31 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399

Original Poster
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Getting xdebug 2.0.5 switch text output to html output lhorace Linux - Server 1 11-01-2009 05:23 PM
Gui App language for embedded platform? PatM Linux - Software 3 05-10-2008 08:11 PM
index.html in apache with multimedia embedded htm Linux - Software 3 05-27-2004 10:05 PM
which language is the best to manage database? poeta_boy General 1 12-09-2003 10:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration