Thursday, April 29, 2004
Alive and well on Ganymede
It was a quiet week, and surprisingly, The Kids have been back nearly a week now and it's still quiet. Well, not as quiet as it was when they were off with their father driving through Florida, but still, after a year, the concept of “quiet” seems to have percolated down into their psyche and they are quieter now then they were this time last year.
Woot!
I've also been somewhat busy over the past two weeks. One task I've been working on is a “Getting Started Guide” for Seminole, Mark'a webserver. As Seminole is an embedable webserver, the guide is geared towards programmers who need to link Seminole into a larger project, and as writing assignments go, it is bloody difficult.
The problem I have is that I simply don't want to parrot in English what the demonstration code (which I'm also writing) is doing. I think I rewrote the CGI chapter two or three times and hating each revision, and I'm still not fully satisified with the results, but hey, that chapter is done (for the most part), and besides, what can one say about the following code?
bool DemoCgiHandler::Handle(HttpdRequest *p_req) { assert(p_req != NULL); if (IsMe(p_req)) { //------------------------------------------------------- // we only accept POST methods in this handler, which is // the most common method of handling HTML forms. //------------------------------------------------------- if (strcmp(p_req->Method(),HttpdUtilities::mPostRequest) != 0) { p_req->Respond(HTTPD_RESP_METHOD_NOT_ALLOWED); return(true); } //---------------------------------------------------------- // This call collects the parameters into an array for us // to use. If there is no Content-type passed in, or it's of // the wrong type, then HttpdCgiParameter::ParsePostData() // will return NULL. //---------------------------------------------------------- HttpdCgiParameter *list = HttpdCgiParameter::ParsePostData(p_req); if (list == NULL) { p_req->Respond(HTTPD_RESP_SRV_ERROR); return(true); } //--------------------------------------------------------- // We accept three parameters, "name", "title" and "age". // We don't do much with the data, other than print it out, // but this is the basics of getting CGI data from the client. //------------------------------------------------------------ HttpdDynamicOutput output(p_req,false); p_req->Respond(HTTPD_RESP_OK); const char *name = list->Find("name"); const char *title = list->Find("title"); const char *age = list->Find("age"); output.Header("Content-Type","text/plain"); output.HeaderComplete(); output.Body()->Printf( "Name: %s\r\n" "Title: %s\r\n" "Age: %s\r\n", name ? name : "none given", title ? title : "none given", age ? age : "none given" ); return(true); } return(false); }
(I don't think Mark will be too upset for me posting the code here—this is, after all, just a demonstration of how to use Seminole and the code (at least to me) is fairly obvious in what it does).
If the CGI chapter was bad, the template system was even worse. The demo code for that was about the size of the CGI demo, and just as drop dead simple (well, as simple as C++ code can be).
I guess part of the problem is that I'm having a hard time placing myself into the mindset of an embedded programmer (which I'm not) who has to learn how to use Seminole (which I am, mostly by going through the source code to Seminole, and following the few examples written by Mark) and knows C++ (which I'm learning) but might not know how this web stuff works (which I know all too well). So yes, it's kind of hard to get into the right mindset to write this guide.
But I'm forging ahead anyway.
One thing I did learn this week is how to pipe highlighted text from joe
(the editor I use) through an external program (and I've been using
joe
for how long now? I'm not going to bother
answering that). What this means is that I can now embed code, highlight
it, and run it through a filter to convert certain characters like “<”
or “&” into “<” and “&” (which is required since
the documentation is in XML) or to indent the block or even (much to Mark's
delight) expand tabs to spaces (to Mark, tabs are
eeeeeeeeeeeeeeeeeeeeeevil).
Another thing I learned this week—how to hard boil eggs. I've learned that fresh eggs are important to the success of hard boiled eggs.