nph-hello.cpp

00001 /*
00002  * $Id: nph-hello_8cpp-source.html,v 1.1 2007/07/03 21:34:47 sebdiaz Exp $ 
00003  *
00004  *  Copyright (C) 1996 - 2004 Stephen F. Booth
00005  *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
00006  *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Lesser General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 3 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public
00019  *  License along with this library; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
00021  *
00022  */
00023 
00024 #include <exception>
00025 #include <iostream>
00026 #include <ctime>
00027 
00028 #include "cgicc/Cgicc.h"
00029 #include "cgicc/HTTPResponseHeader.h"
00030 #include "cgicc/HTMLClasses.h"
00031 
00032 #if HAVE_SYS_TIME_H
00033 #  include <sys/time.h>
00034 #endif
00035 
00036 using namespace std;
00037 using namespace cgicc;
00038 
00039 int
00040 main(int /*argc*/, 
00041      char ** /*argv*/)
00042 {
00043   try {
00044     Cgicc cgi;
00045 
00046     // Get the current time in the format Sun, 06 Nov 1994 08:49:37 GMT
00047     char current_date [30];
00048     time_t now = time(&now);
00049     strftime(current_date, 30, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
00050 
00051     // Build our own server string
00052     string server_string("GNU cgicc/");
00053     server_string += cgi.getVersion();
00054 
00055     // Tell the server not to parse our headers
00056     cout << HTTPResponseHeader("HTTP/1.1", 200, "OK")
00057       .addHeader("Date", current_date)
00058       .addHeader("Server", server_string)
00059       .addHeader("Content-Language", "en")
00060       .addHeader("Content-Type", "text/html");
00061 
00062     cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
00063     
00064     cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
00065     cout << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" << endl;
00066 
00067     cout << "<head>" << endl;
00068 
00069     // Output the style sheet portion of the header
00070     cout << "<style><!-- " << endl;
00071     cout << "   body { color: black; background-color: white; }" << endl;
00072     cout << "   span.red { color: red; }" << endl;
00073     cout << " --></style>" << endl;
00074 
00075     cout << "<title>GNU cgicc v" << cgi.getVersion() << "</title>" << endl;
00076     cout << "</head>" << endl;
00077 
00078     cout << "<body>" << endl;
00079     cout << "<h1>Hello, world from GNU cgi<span class=\"red\">cc</span> v";
00080     cout << cgi.getVersion() << "</h1>" << endl;
00081     cout << "</body></html>" << endl;
00082   }
00083   
00084   catch(const exception& e) {
00085     // handle error condition
00086   }
00087   
00088   return 0;
00089 }

Generated on Tue Jul 3 15:44:29 2007 for GNUCgicc by  doxygen 1.5.1