--- /dev/null
+# Microsoft Developer Studio Project File - Name="echo_cpp" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102\r
+\r
+CFG=echo_cpp - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "echo_cpp.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "echo_cpp.mak" CFG="echo_cpp - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "echo_cpp - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "echo_cpp - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+MTL=midl.exe\r
+RSC=rc.exe\r
+\r
+!IF "$(CFG)" == "echo_cpp - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "echo-cpp\Release"\r
+# PROP BASE Intermediate_Dir "echo-cpp\Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\examples\echo-cpp\Release"\r
+# PROP Intermediate_Dir "..\examples\echo-cpp\Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIB_EXPORTS" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /Gi /O2 /Ob2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# SUBTRACT CPP /Fr\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 libfcgi.lib /nologo /pdb:none /machine:IX86 /out:"..\examples\echo-cpp\Release\echo-cpp.exe" /libpath:"..\libfcgi\Release"\r
+\r
+!ELSEIF "$(CFG)" == "echo_cpp - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "../examples/echo-cpp\Debug"\r
+# PROP Intermediate_Dir "../examples/echo-cpp\Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIB_EXPORTS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W4 /Gm /Gi /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c\r
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 libfcgi.lib /nologo /profile /debug /machine:IX86 /out:"..\examples\echo-cpp\Debug\echo-cpp.exe" /libpath:"..\libfcgi\Debug"\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "echo_cpp - Win32 Release"\r
+# Name "echo_cpp - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE="..\examples\echo-cpp.cpp"\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
--- /dev/null
+/*\r
+ * A simple FastCGI application example in C++.\r
+ * \r
+ * $Id: echo-cpp.cpp,v 1.1 2001/11/20 02:32:49 robs Exp $\r
+ * \r
+ * Copyright (c) 2001 Rob Saccoccio and Chelsea Networks\r
+ * All rights reserved.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * \r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ * derived from this software without specific prior written permission.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include <stdlib.h>\r
+#ifdef _WIN32\r
+#include <process.h>\r
+#endif\r
+#include "fcgio.h"\r
+\r
+// Maximum number of bytes allowed to be read from stdin\r
+static const unsigned long STDIN_MAX = 1000000;\r
+\r
+static void penv(const char * const * envp)\r
+{\r
+ cout << "<PRE>\n";\r
+ for ( ; *envp; ++envp) \r
+ {\r
+ cout << *envp << "\n";\r
+ }\r
+ cout << "</PRE>\n";\r
+}\r
+\r
+static long gstdin(FCGX_Request * request, char ** content)\r
+{\r
+ char * clenstr = FCGX_GetParam("CONTENT_LENGTH", request->envp);\r
+ unsigned long clen = STDIN_MAX;\r
+\r
+ if (clenstr)\r
+ {\r
+ clen = strtol(clenstr, &clenstr, 10);\r
+ if (*clenstr)\r
+ {\r
+ cerr << "can't parse \"CONTENT_LENGTH=" \r
+ << FCGX_GetParam("CONTENT_LENGTH", request->envp) \r
+ << "\"\n";\r
+ clen = STDIN_MAX;\r
+ }\r
+ }\r
+\r
+ // Note that *you* should not read stdin when CONTENT_LENGTH\r
+ // is missing or unparsable (this is a demo/test program).\r
+\r
+ // *always* put a cap on the amount of data that will be read\r
+ if (clen > STDIN_MAX) clen = STDIN_MAX;\r
+\r
+ *content = new char[clen];\r
+\r
+ cin.read(*content, clen);\r
+ clen = cin.gcount();\r
+\r
+ // chew up any remaining stdin - this shouldn't be necessary\r
+ // but it is because mod_fastcgi doesn't handle it correctly\r
+ do cin.ignore(1024); while (! cin.eof());\r
+\r
+ return clen;\r
+}\r
+\r
+int main (void)\r
+{\r
+ int count = 0;\r
+ long pid = getpid();\r
+\r
+ FCGX_Request request;\r
+\r
+ FCGX_Init();\r
+ FCGX_InitRequest(&request, 0, 0);\r
+\r
+ while (FCGX_Accept_r(&request) == 0) \r
+ {\r
+ fcgi_streambuf fin(request.in);\r
+ fcgi_streambuf fout(request.out);\r
+ fcgi_streambuf ferr(request.err);\r
+ \r
+#ifdef _WIN32\r
+ cin = &fin;\r
+ cout = &fout;\r
+ cerr = &ferr;\r
+#else\r
+ cin.rdbuf(&fin);\r
+ cout.rdbuf(&fout);\r
+ cerr.rdbuf(&ferr);\r
+#endif\r
+\r
+ // Although FastCGI supports writing before reading,\r
+ // many http clients (browsers) don't support it (so \r
+ // the connection deadlocks until a timeout expires!).\r
+ char * content;\r
+ unsigned long clen = gstdin(&request, &content);\r
+\r
+ cout << "Content-type: text/html\r\n"\r
+ "\r\n"\r
+ "<TITLE>echo-cpp</TITLE>\n"\r
+ "<H1>echo-cpp</H1>\n"\r
+ "<H4>PID: " << pid << "</H4>\n"\r
+ "<H4>Request Number: " << ++count << "</H4>\n";\r
+\r
+ cout << "<H4>Request Environment</H4>\n";\r
+ penv(request.envp);\r
+\r
+ cout << "<H4>Process/Initial Environment</H4>\n";\r
+ penv(environ);\r
+\r
+ cout << "<H4>Standard Input - " << clen;\r
+ if (clen == STDIN_MAX) cout << " (STDIN_MAX)";\r
+ cout << " bytes</H4>\n";\r
+ if (clen) cout.write(content, clen);\r
+\r
+ if (content) delete []content;\r
+ }\r
+\r
+ return 0;\r
+}\r