home *** CD-ROM | disk | FTP | other *** search
- // LST15_03.CPP - Implementation file for your Internet Server
- // lst15_03 Filter
-
- #include <afx.h>
- #include <afxwin.h>
- #include <afxisapi.h>
- #include "resource.h"
- #include "lst15_03.h"
-
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CLst17_03Filter object
-
- CLst15_03Filter theFilter;
-
-
- ///////////////////////////////////////////////////////////////////////
- // CLst15_03Filter implementation
-
- CLst15_03Filter::CLst15_03Filter()
- {
- }
-
- CLst15_03Filter::~CLst15_03Filter()
- {
- }
-
- BOOL CLst15_03Filter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
- {
- // Call default implementation for initialization
- CHttpFilter::GetFilterVersion(pVer);
-
- // Clear the flags set by base class
- pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
-
- // Set the flags we are interested in
- pVer->dwFlags |= SF_NOTIFY_ORDER_LOW | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT
- | SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_END_OF_NET_SESSION;
-
- // Load description string
- TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
- ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
- IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
- _tcscpy(pVer->lpszFilterDesc, sz);
- return TRUE;
- }
-
- // The Caller must delete the memory, unless error in which case returns NULL
- LPTSTR CLst15_03Filter::GetServerVariable(CHttpFilterContext* pCtxt, LPCTSTR pszVariableName)
- {
- LPVOID lpvBuffer=NULL;
- DWORD dwSize=0;
-
- pCtxt->GetServerVariable((LPTSTR)pszVariableName,NULL,(LPDWORD)&dwSize);
-
- // Check to see if variable exists
- if(dwSize==0)
- return(NULL);
-
- lpvBuffer=(LPVOID)new TCHAR[dwSize+1];
-
- if (!(pCtxt->GetServerVariable((LPTSTR)pszVariableName,lpvBuffer,(LPDWORD)&dwSize)))
- {
- delete lpvBuffer;
- return(NULL);
- }
-
- if(dwSize==0)
- {
- delete lpvBuffer;
- return(NULL);
- }
-
- return((LPTSTR)lpvBuffer);
- };
-
- DWORD CLst15_03Filter::OnAuthentication(CHttpFilterContext* pCtxt,
- PHTTP_FILTER_AUTHENT pHeaderInfo)
- {
- BOOL bNotAuthorized=TRUE;
- LPTSTR lpszUser;
- LPTSTR lpszIndex;
-
- if(lpszUser=GetServerVariable(pCtxt,"REMOTE_ADDR"))
- {
- lpszIndex=_tcsstr(lpszUser,_T("."))+1;
- lpszIndex=_tcsstr(lpszIndex,_T("."));
- (*lpszIndex)=_T('\0');
-
- bNotAuthorized=_tcscmp(lpszUser,"157.56");
-
- delete lpszUser;
- }
-
- if (bNotAuthorized)
- {
- DWORD dwDataSize=_tcslen(_T("401 Unauthorized"));
- pCtxt->ServerSupportFunction(
- SF_REQ_SEND_RESPONSE_HEADER,
- _T("401 Unauthorized"),
- NULL,
- &dwDataSize);
- return SF_STATUS_REQ_FINISHED;
- }
- else
- {
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
- }
-
- }
-
- DWORD CLst15_03Filter::OnEndOfNetSession(CHttpFilterContext* pCtxt)
- {
- // TODO: React to this notification accordingly and
- // return the appropriate status code
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // If your extension will not use MFC, you'll need this code to make
- // sure the extension objects can find the resource handle for the
- // module. If you convert your extension to not be dependent on MFC,
- // remove the comments arounn the following AfxGetResourceHandle()
- // and DllMain() functions, as well as the g_hInstance global.
-
- /****
-
- static HINSTANCE g_hInstance;
-
- HINSTANCE AFXISAPI AfxGetResourceHandle()
- {
- return g_hInstance;
- }
-
- BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
- LPVOID lpReserved)
- {
- if (ulReason == DLL_PROCESS_ATTACH)
- {
- g_hInstance = hInst;
- }
-
- return TRUE;
- }
-
- ****/
-