fcgi-test.cpp

00001 /*
00002  * $Id: fcgi-test_8cpp-source.html,v 1.1 2007/07/03 21:34:48 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 
00027 #include <unistd.h>
00028 
00029 #include "cgicc/Cgicc.h"
00030 #include "cgicc/HTTPHTMLHeader.h"
00031 #include "cgicc/HTMLClasses.h"
00032 
00033 #include "FCgiIO.h"
00034 
00035 using namespace std;
00036 using namespace cgicc;
00037 
00038 int 
00039 main(int /*argc*/, 
00040      const char **/*argv*/, 
00041      char **/*envp*/)
00042 {
00043   unsigned count = 0;
00044 
00045   FCGX_Request request;
00046 
00047   FCGX_Init();
00048   FCGX_InitRequest(&request, 0, 0);
00049 
00050   while(FCGX_Accept_r(&request) == 0) {
00051 
00052     try {
00053       FCgiIO IO(request);
00054       Cgicc CGI(&IO);
00055 
00056       // Output the HTTP headers for an HTML document, and the HTML 4.0 DTD info
00057       IO << HTTPHTMLHeader() << HTMLDoctype( HTMLDoctype::eStrict ) << endl
00058          << html().set( "lang", "en" ).set( "dir", "ltr" ) << endl;
00059 
00060       // Set up the page's header and title.
00061       IO << head() << endl
00062          << title() << "GNU cgicc v" << CGI.getVersion() << title() << endl
00063          << head() << endl;
00064 
00065       // Start the HTML body
00066       IO << body() << endl;
00067 
00068       // Print out a message
00069       IO << h1("Cgicc/FastCGI Test") << endl
00070          << "PID: " << getpid() << br() << endl
00071          << "count: " << count++ << br() << endl;
00072 
00073       IO  << "Form Elements:" << br() << endl;
00074 
00075       for(const_form_iterator i = CGI.getElements().begin(); 
00076           i != CGI.getElements().end(); ++i )
00077         IO << i->getName() << " = " << i->getValue() << br() << endl;
00078 
00079       // Close the document
00080       IO << body() << html();
00081     }
00082     catch(const exception&) {
00083       // handle error condition
00084     }
00085 
00086     FCGX_Finish_r(&request);
00087   }
00088 
00089   return 0;
00090 }

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