home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c14 / ucase / ucase.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.3 KB  |  115 lines

  1. // UCASE.CPP - Implementation file for your Internet Server
  2. //    UCase Filter
  3.  
  4. #include "stdafx.h"
  5. #include "UCase.h"
  6.  
  7. ///////////////////////////////////////////////////////////////////////
  8. // The one and only CUCaseFilter object
  9. CUCaseFilter theFilter;
  10.  
  11. ///////////////////////////////////////////////////////////////////////
  12. // CUCaseFilter implementation
  13. CUCaseFilter::CUCaseFilter()
  14. {
  15. }
  16.  
  17. CUCaseFilter::~CUCaseFilter()
  18. {
  19. }
  20.  
  21. BOOL CUCaseFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
  22. {
  23.     // Call default implementation for initialization
  24.     CHttpFilter::GetFilterVersion(pVer);
  25.  
  26.     // Clear the flags set by base class
  27.     pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
  28.  
  29.     // Set the flags we are interested in
  30.     pVer->dwFlags |= SF_NOTIFY_ORDER_MEDIUM 
  31.                 | SF_NOTIFY_NONSECURE_PORT 
  32.                 | SF_NOTIFY_SEND_RAW_DATA 
  33.                 | SF_NOTIFY_URL_MAP;
  34.  
  35.     // Load description string
  36.     TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
  37.     ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
  38.             IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
  39.     _tcscpy(pVer->lpszFilterDesc, sz);
  40.     return TRUE;
  41. }
  42.  
  43. DWORD CUCaseFilter::OnUrlMap(CHttpFilterContext* pCtxt,
  44.     PHTTP_FILTER_URL_MAP pMapInfo)
  45. {
  46.     // We'll need the physical path in lower case.    
  47.     LPTSTR pstrPhysPath = pMapInfo->pszPhysicalPath;
  48.     strlwr(pstrPhysPath);
  49.  
  50.     // The string we're searching for is "uppercase\"
  51.     static LPCTSTR pstrSearch = "uppercase\\";
  52.  
  53.     // Determine if the request contains pstrSearch. If so, do 2 things.
  54.     // First, remove "uppercase" from the Physical Path, since
  55.     // that symbol is NOT part of the filename.
  56.     // Second, set the filter context as a flag to 
  57.     // indicate to OnSendRawData that it should act on the
  58.     // outgoing data. The number 1111 carries no special significance.
  59.     // However. being an odd number it won't be a pointer to dynamically
  60.     // allocated memory. See OnSendRawData to determine how it's used.
  61.     LPTSTR p1 = strstr (pstrPhysPath, pstrSearch);
  62.     if (0 != p1)
  63.     {
  64.         LPTSTR p2 = p1 + lstrlen(pstrSearch);
  65.         lstrcpy(p1, p2);
  66.         pCtxt->m_pFC->pFilterContext = (PVOID) 1111;
  67.     }
  68.  
  69.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  70. }
  71.  
  72. DWORD CUCaseFilter::OnSendRawData(CHttpFilterContext* pCtxt,
  73.     PHTTP_FILTER_RAW_DATA pRawData)
  74. {
  75.     // This function is called twice to transmit the data
  76.     // back to the client. First time for the header,
  77.     // second time for the body.
  78.     LPTSTR    pstrIn;
  79.     
  80.     // If the context flag = 1111 then it's a header for a message
  81.     // this filter is interested in. Bump it to 1113 and return.
  82.     if ((PVOID) 1111 == pCtxt->m_pFC->pFilterContext)
  83.     {
  84.         pCtxt->m_pFC->pFilterContext = (VOID*) 1113;
  85.         return SF_STATUS_REQ_NEXT_NOTIFICATION;
  86.     }
  87.  
  88.     // At this point, if it's not 1113 it's some other page
  89.     // so just return.
  90.     if ((PVOID) 1113 != pCtxt->m_pFC->pFilterContext)
  91.     {
  92.         return SF_STATUS_REQ_NEXT_NOTIFICATION;
  93.     }
  94.  
  95.     // If we get to here, it's either the crlf pair or the body
  96.     // for the page I'm converting to upper case, so go to work.
  97.     pstrIn = (LPTSTR) pRawData->pvInData;
  98.     
  99.     while (*pstrIn)
  100.     {
  101.         *pstrIn = toupper(*pstrIn);
  102.         pstrIn++;
  103.     }
  104.     
  105.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  106. }
  107.  
  108. // Do not edit the following lines, which are needed by ClassWizard.
  109. #if 0
  110. BEGIN_MESSAGE_MAP(CUCaseFilter, CHttpFilter)
  111.     //{{AFX_MSG_MAP(CUCaseFilter)
  112.     //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114. #endif    // 0
  115.