home *** CD-ROM | disk | FTP | other *** search
- // ECHO.CPP - Implementation file for your Internet Server
- // Echo ISAPI App
-
- #include "stdafx.h"
- #include "Echo.h"
-
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CEchoExtension, CHttpServer)
- //{{AFX_MSG_MAP(CEchoExtension)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CWinApp object
- CWinApp theApp;
-
- ///////////////////////////////////////////////////////////////////////
- // command-parsing map
- BEGIN_PARSE_MAP(CEchoExtension, CHttpServer)
- ON_PARSE_COMMAND(EchoRequest, CEchoExtension, ITS_PSTR)
- ON_PARSE_COMMAND_PARAMS("option=full")
- ON_PARSE_COMMAND(Default, CEchoExtension, ITS_EMPTY)
- DEFAULT_PARSE_COMMAND(Default, CEchoExtension)
- END_PARSE_MAP(CEchoExtension)
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CEchoExtension object
- CEchoExtension theExtension;
-
- ///////////////////////////////////////////////////////////////////////
- // CEchoExtension implementation
-
- CEchoExtension::CEchoExtension()
- {
- }
-
- CEchoExtension::~CEchoExtension()
- {
- }
-
- BOOL CEchoExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
- {
- // Call default implementation for initialization
- CHttpServer::GetExtensionVersion(pVer);
-
- // Load description string
- TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
- ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
- IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
- _tcscpy(pVer->lpszExtensionDesc, sz);
- return TRUE;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // CEchoExtension command handlers
-
- void CEchoExtension::Default(CHttpServerContext* pCtxt)
- {
- StartContent(pCtxt);
- WriteTitle(pCtxt);
-
- *pCtxt << "<P><H1>Help for Echo.dll</H1><P><HR>";
- EchoHelp(pCtxt);
-
- EndContent(pCtxt);
- }
-
- void CEchoExtension::EchoRequest(CHttpServerContext *pCtxt, LPCTSTR pstrOption)
- {
- StartContent(pCtxt);
- WriteTitle(pCtxt);
-
- *pCtxt << "<P><H1>Echo.dll</H1><P><HR>";
-
- if ( _stricmp(pstrOption, "full") == 0)
- {
- EchoHead(pCtxt);
- *pCtxt << "<BR>";
- EchoBody(pCtxt);
- }
- else if ( _stricmp(pstrOption, "header") == 0)
- {
- EchoHead(pCtxt);
- }
- else if ( _stricmp(pstrOption, "body") == 0)
- {
- EchoBody(pCtxt);
- }
- else
- BadSyntax(pCtxt);
-
- EndContent(pCtxt);
- }
-
- void CEchoExtension::EchoBody(CHttpServerContext * pCtxt)
- {
- char pstrBuffer[4000];
- DWORD dwSize = sizeof(pstrBuffer);
-
- *pCtxt << "<P><H3>Request Body Information</H3><BR>";
-
- BOOL b = pCtxt->ReadClient(pstrBuffer, &dwSize);
- *pCtxt << "Body is " << (long int)dwSize << " bytes <BR>" ;
- if (b == TRUE)
- *pCtxt << pstrBuffer;
- }
-
- void CEchoExtension::EchoHead(CHttpServerContext * pCtxt)
- {
- char pstrBuffer[1000];
- DWORD dwSize = sizeof(pstrBuffer);
-
- *pCtxt << "<P><H3>Request Header Information</H3>";
- *pCtxt << "<BR>Request method: " << pCtxt->m_pECB->lpszMethod;
- *pCtxt << "<BR>Tranlsated path: " << pCtxt->m_pECB->lpszPathTranslated;
-
- pCtxt->GetServerVariable("QUERY_STRING", pstrBuffer, &dwSize);
- *pCtxt << "<BR>Query String: " << pstrBuffer;
-
- dwSize = sizeof(pstrBuffer); pstrBuffer[0] = 0;
- pCtxt->GetServerVariable("REMOTE_ADDR", pstrBuffer, &dwSize);
- *pCtxt << "<BR>Client IP address: " << pstrBuffer;
- }
-
- void CEchoExtension::BadSyntax(CHttpServerContext* pCtxt)
- {
- *pCtxt << "<H3>Bad Syntax Error!</H3><P>";
- *pCtxt << "Proper syntax is as follows:";
- EchoHelp(pCtxt);
- }
-
- void CEchoExtension::EchoHelp(CHttpServerContext* pCtxt)
- {
- *pCtxt << "<P><I>Supported method:</I>";
- *pCtxt << "<BR><B><TT>EchoRequest</TT></B> - currently the only method supported."
- << " Dynamically creates an HTML page containing HTTP request information.";
- *pCtxt << "<P><I>Supported arguments:</I>";
- *pCtxt << "<BR><B><TT>Full</TT></B> - echo back the entire HTTP request message.";
- *pCtxt << "<BR><B><TT>Body</TT></B> - echo back only the HTTP request message body.";
- *pCtxt << "<BR><B><TT>Header</TT></B> - echo back only the HTTP request message head.";
- }
-