/* * Copyright (C) 2007-2010 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * terms of the license contained in the file LICENSE. */ #include "bu/fastcgi.h" #include class Cgi : public Bu::FastCgi { public: Cgi() : Bu::FastCgi::FastCgi() { } Cgi( int iPort ) : Bu::FastCgi::FastCgi( iPort ) { } virtual ~Cgi() { } virtual int onRequest( const StrHash &hParams, const Bu::String &sStdIn, Bu::Stream &sStdOut, Bu::Stream &/*sStdErr*/ ) { Bu::String sOut("Content-Type: text/html\r\n\r\n"); sOut += "

Environment:

"; char buf[2048]; sOut += "

Cwd:

"; sOut += "

Stdin:

"; sOut.formatAppend("%d bytes
", sStdIn.getSize() );
		Bu::String sL, sR;
		for( Bu::String::const_iterator i = sStdIn.begin();
			i; i++ )
		{
			sL.formatAppend("%02X ",
				(unsigned int)((unsigned char)*i) );
			if( *i < 27 )
				sR += ". ";
			else
				sR.formatAppend("&#%d; ",
					(unsigned int)((unsigned char)*i) );
			if( sL.getSize()/3 == 8 )
			{
				sOut += sL + " | " + sR + "\n";
				sL = sR = "";
			}
		}
		if( sL != "" )
		{
			while( sL.getSize()/3 < 8 )
				sL += "   ";
			sOut += sL + " | " + sR + "\n";
		}
		sOut += "

";
		sOut += sStdIn;
		sOut += "
"; sOut += "


"; sOut += ""; sStdOut.write( sOut ); return 0; } }; int main() { Cgi c( 8789 ); c.run(); return 0; }