home *** CD-ROM | disk | FTP | other *** search
- // LST14_03.CPP - Implementation file for your Internet Server
- // lst14_03 Extension
-
- #include <afx.h>
- #include <afxwin.h>
- #include <afxisapi.h>
- #include "resource.h"
- #include "lst14_03.h"
-
-
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CLst14_03Extension object
-
- CLst14_03Extension theExtension;
- CWinApp BugFix;
-
- ///////////////////////////////////////////////////////////////////////
- // CLst14_03Extension implementation
-
- CLst14_03Extension::CLst14_03Extension()
- {
- m_pnCounter = new UINT;
- (*m_pnCounter) = 0;
-
- m_lpCriticalExtension = new CRITICAL_SECTION;
- InitializeCriticalSection(m_lpCriticalExtension);
- }
-
- CLst14_03Extension::~CLst14_03Extension()
- {
- delete m_pnCounter;
-
- DeleteCriticalSection(m_lpCriticalExtension);
- delete m_lpCriticalExtension;
- }
-
- BOOL CLst14_03Extension::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;
- }
-
- int CLst14_03Extension::CallFunction(CHttpServerContext* pCtxt,LPTSTR pszQuery, LPTSTR pszCommand)
- {
- int nRet=callOK;
-
- ISAPIASSERT(pCtxt->m_pStream == NULL);
- pCtxt->m_pStream = ConstructStream();
- if (pCtxt->m_pStream == NULL)
- nRet = callNoStream;
- else
- {
- pCtxt->m_pStream->InitStream();
- Enterance(pCtxt,pszQuery);
- }
-
- return(nRet);
- }
-
- void CLst14_03Extension::Enterance(CHttpServerContext* pCtxt,LPTSTR pszQuery)
- {
- ThreadPool();
- (*pCtxt) << _T("<HTML><BODY>Name: ");
-
- LPTSTR lpszValue;
- if (lpszValue=FindNameValue(pszQuery,_T("Name"),_T('='),_T('&')))
- {
- (*pCtxt) << lpszValue;
- delete lpszValue;
- }
-
- (*pCtxt) << _T("</BODY</HTML>");
-
- LeavePool();
- };
-
- void CLst14_03Extension::ThreadPool()
- {
- BOOL bGoodToGo=FALSE;
-
- while (!bGoodToGo)
- {
- EnterCriticalSection(m_lpCriticalExtension);
-
- bGoodToGo=((*m_pnCounter)<15);
-
- if(bGoodToGo)
- (*m_pnCounter)++;
-
- LeaveCriticalSection(m_lpCriticalExtension);
-
- }
-
- }
-
- void CLst14_03Extension::LeavePool()
- {
- EnterCriticalSection(m_lpCriticalExtension);
- (*m_pnCounter)--;
- LeaveCriticalSection(m_lpCriticalExtension);
- };
-
- // The Caller must delete the memory
- LPTSTR CLst14_03Extension::FindNameValue(LPCTSTR lpszString,LPCTSTR lpszName,TCHAR cSeparator,TCHAR cDelimiter)
- {
- LPTSTR lpszIndex;
- LPTSTR lpszEnd;
- DWORD dwValueSize=0;
- LPTSTR lpszValue;
-
- LPTSTR lpszStringCopy;
- LPTSTR lpszNameCopy;
- DWORD dwNameLength;
-
- lpszStringCopy = new TCHAR[_tcslen(lpszString)+1];
- _tcscpy(lpszStringCopy,lpszString);
-
- lpszNameCopy = new TCHAR[_tcslen(lpszName)+2];
- _tcscpy(lpszNameCopy,lpszName);
- dwNameLength=_tcslen(lpszNameCopy);
-
- lpszNameCopy[dwNameLength]=cSeparator;
- lpszNameCopy[dwNameLength+1]=(TCHAR)_T('\0');
-
- // Find The Name in the Query String
- lpszIndex=_tcsstr(lpszStringCopy,lpszNameCopy);
-
- delete lpszNameCopy;
-
- // Error: The Name part of the Name value pair doesn't exist
- if (!lpszIndex)
- {
- delete lpszStringCopy;
- return (NULL);
- }
-
- // Increase the pointer passed the Name and Get to the Value
- lpszIndex+=_tcslen(lpszName)+1;
-
- // Find the End of the Value by looking for the Demiliter
- lpszEnd=_tcschr(lpszIndex,_T(cDelimiter));
-
- // if we find a Demiliter set it as the end
- if (lpszEnd)
- (*lpszEnd)='\0';
-
- // Remove the CGI Syntax
- PreprocessString(lpszIndex);
-
- // Calculate the Value Size
- dwValueSize=_tcslen(lpszIndex);
-
- lpszValue = new TCHAR[dwValueSize+1];
-
- _tcscpy(lpszValue,lpszIndex);
-
- delete lpszStringCopy;
-
- return lpszValue;
- }
-