home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap15 / lst15_03 / lst15_03.cpp next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  3.5 KB  |  147 lines

  1. // LST15_03.CPP - Implementation file for your Internet Server
  2. //    lst15_03 Filter
  3.  
  4. #include <afx.h>
  5. #include <afxwin.h>
  6. #include <afxisapi.h>
  7. #include "resource.h"
  8. #include "lst15_03.h"
  9.  
  10.  
  11. ///////////////////////////////////////////////////////////////////////
  12. // The one and only CLst17_03Filter object
  13.  
  14. CLst15_03Filter theFilter;
  15.  
  16.  
  17. ///////////////////////////////////////////////////////////////////////
  18. // CLst15_03Filter implementation
  19.  
  20. CLst15_03Filter::CLst15_03Filter()
  21. {
  22. }
  23.  
  24. CLst15_03Filter::~CLst15_03Filter()
  25. {
  26. }
  27.  
  28. BOOL CLst15_03Filter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
  29. {
  30.     // Call default implementation for initialization
  31.     CHttpFilter::GetFilterVersion(pVer);
  32.  
  33.     // Clear the flags set by base class
  34.     pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
  35.  
  36.     // Set the flags we are interested in
  37.     pVer->dwFlags |= SF_NOTIFY_ORDER_LOW | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT
  38.              | SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_END_OF_NET_SESSION;
  39.  
  40.     // Load description string
  41.     TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
  42.     ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
  43.             IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
  44.     _tcscpy(pVer->lpszFilterDesc, sz);
  45.     return TRUE;
  46. }
  47.  
  48. // The Caller must delete the memory, unless error in which case returns NULL
  49. LPTSTR CLst15_03Filter::GetServerVariable(CHttpFilterContext* pCtxt, LPCTSTR pszVariableName)
  50. {
  51.     LPVOID lpvBuffer=NULL;
  52.     DWORD dwSize=0;
  53.  
  54.     pCtxt->GetServerVariable((LPTSTR)pszVariableName,NULL,(LPDWORD)&dwSize);
  55.  
  56.     // Check to see if variable exists
  57.     if(dwSize==0)
  58.         return(NULL);
  59.  
  60.     lpvBuffer=(LPVOID)new TCHAR[dwSize+1];
  61.  
  62.     if (!(pCtxt->GetServerVariable((LPTSTR)pszVariableName,lpvBuffer,(LPDWORD)&dwSize)))
  63.     {
  64.          delete lpvBuffer;
  65.         return(NULL);
  66.     }
  67.  
  68.     if(dwSize==0)
  69.     {
  70.          delete lpvBuffer;
  71.         return(NULL);
  72.     }
  73.  
  74.     return((LPTSTR)lpvBuffer);
  75. };
  76.  
  77. DWORD CLst15_03Filter::OnAuthentication(CHttpFilterContext* pCtxt,
  78.     PHTTP_FILTER_AUTHENT pHeaderInfo)
  79. {
  80.     BOOL bNotAuthorized=TRUE;
  81.     LPTSTR lpszUser;
  82.     LPTSTR lpszIndex;
  83.     
  84.     if(lpszUser=GetServerVariable(pCtxt,"REMOTE_ADDR"))
  85.     {
  86.         lpszIndex=_tcsstr(lpszUser,_T("."))+1;
  87.          lpszIndex=_tcsstr(lpszIndex,_T("."));
  88.         (*lpszIndex)=_T('\0');
  89.  
  90.         bNotAuthorized=_tcscmp(lpszUser,"157.56");
  91.  
  92.         delete lpszUser;
  93.     }
  94.  
  95.     if (bNotAuthorized)
  96.     {
  97.         DWORD dwDataSize=_tcslen(_T("401    Unauthorized"));
  98.         pCtxt->ServerSupportFunction( 
  99.                         SF_REQ_SEND_RESPONSE_HEADER,
  100.                        _T("401    Unauthorized"),  
  101.                        NULL,
  102.                        &dwDataSize);
  103.         return SF_STATUS_REQ_FINISHED;
  104.     }
  105.     else
  106.     {
  107.         return SF_STATUS_REQ_NEXT_NOTIFICATION;
  108.     }
  109.  
  110. }
  111.  
  112. DWORD CLst15_03Filter::OnEndOfNetSession(CHttpFilterContext* pCtxt)
  113. {
  114.     // TODO: React to this notification accordingly and
  115.     // return the appropriate status code
  116.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  117. }
  118.  
  119. ///////////////////////////////////////////////////////////////////////
  120. // If your extension will not use MFC, you'll need this code to make
  121. // sure the extension objects can find the resource handle for the
  122. // module.  If you convert your extension to not be dependent on MFC,
  123. // remove the comments arounn the following AfxGetResourceHandle()
  124. // and DllMain() functions, as well as the g_hInstance global.
  125.  
  126. /****
  127.  
  128. static HINSTANCE g_hInstance;
  129.  
  130. HINSTANCE AFXISAPI AfxGetResourceHandle()
  131. {
  132.     return g_hInstance;
  133. }
  134.  
  135. BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
  136.                     LPVOID lpReserved)
  137. {
  138.     if (ulReason == DLL_PROCESS_ATTACH)
  139.     {
  140.         g_hInstance = hInst;
  141.     }
  142.  
  143.     return TRUE;
  144. }
  145.  
  146. ****/
  147.