home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / UPCASE.C < prev    next >
C/C++ Source or Header  |  1997-10-25  |  5KB  |  177 lines

  1. /*++                                                                                                                             
  2.  
  3. Copyright (c) 1995-1996  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     upcase.c
  8.  
  9. Abstract:
  10.  
  11.     This filter converts HTML response data to upper case if requested
  12.     by the client. The request is made by specifying an extra 
  13.     subdirectory in the URL, which doesnt actually exist on the server,
  14.     but is used by the filter to indicate that upper case is desired.
  15.     The extra subdirectory is removed from the request before the HTTP
  16.     server sees the request.
  17.  
  18.     When a request is received, the filter inspects the 
  19.     subdirectories specified in the URL. If a subdirectory is 'UC'
  20.     or 'uc', the subdirectory is removed from the request, and the
  21.     filter saves in its pFilterContext field, a value indicating that
  22.     the response data should be converted to upper case.
  23.  
  24.     When the filter entrypoint is later called for the response, it 
  25.     checks the pFilterContext field and converts the data if 
  26.     the mime-type of the response indicates that its an html file.
  27.     This avoids conversions on binary data.
  28.  
  29.     An example URL entered by a user might be:
  30.  
  31.         http://www.myweb.com/sales/uc/projections.htm
  32.  
  33.     While the functionality of this filter is somewhat contrived, this
  34.     filter does a good job of demonstrating the following features of
  35.     filters:
  36.         - parsing/modifying HTTP headers (in the request)
  37.         - modifying data following HTTP headers (in the response)
  38.         - saving state to be used by the filter later
  39.         - adding request/response level functionality to the server
  40.             (instead of using a mechanism like this to convert to 
  41.              uppercase, you may use it to do on-the-fly customized
  42.              translations of HTML pages (English -> French perhaps?)
  43.  
  44. Author:
  45.  
  46.     Kerry Schwartz (kerrys) 05-Nov-1995
  47.  
  48. --*/      
  49.  
  50. #include <windows.h>
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <httpfilt.h>
  54.  
  55. BOOL
  56. WINAPI __stdcall
  57. GetFilterVersion(
  58.     HTTP_FILTER_VERSION * pVer
  59.     )
  60. {
  61.     //
  62.     //  Specify the types and order of notification
  63.     //
  64.  
  65.     pVer->dwFlags = (SF_NOTIFY_NONSECURE_PORT     |
  66.                      SF_NOTIFY_URL_MAP            |
  67.                      SF_NOTIFY_SEND_RAW_DATA      |
  68.                      SF_NOTIFY_ORDER_DEFAULT);
  69.  
  70.     pVer->dwFilterVersion = HTTP_FILTER_REVISION;
  71.  
  72.     strcpy( pVer->lpszFilterDesc, 
  73.             "Upper case conversion filter, Version 1.0");
  74.  
  75.     return TRUE;
  76. }
  77.  
  78. DWORD
  79. WINAPI __stdcall
  80. HttpFilterProc(
  81.     HTTP_FILTER_CONTEXT *      pfc,
  82.     DWORD                      NotificationType,
  83.     VOID *                     pvData )
  84. {
  85.     CHAR *pchIn, *pPhysPath;
  86.     DWORD cbBuffer, cbtemp;
  87.     PHTTP_FILTER_URL_MAP pURLMap;
  88.     PHTTP_FILTER_RAW_DATA pRawData;
  89.     
  90.   
  91.     switch ( NotificationType )
  92.     {
  93.     case SF_NOTIFY_URL_MAP:
  94.  
  95.         pURLMap = (PHTTP_FILTER_URL_MAP) pvData;
  96.         pPhysPath = pURLMap->pszPhysicalPath;
  97.         pfc->pFilterContext = 0;
  98.  
  99.         while (*pPhysPath)
  100.         {
  101.             if (*pPhysPath == '\\' &&
  102.                (*(pPhysPath+1) == 'u' || *(pPhysPath+1) == 'U') &&
  103.                (*(pPhysPath+2) == 'c' || *(pPhysPath+2) == 'C') &&
  104.                 *(pPhysPath+3) == '\\')
  105.             {
  106.                 while (*(pPhysPath+3))
  107.                 {
  108.                     *pPhysPath = *(pPhysPath+3);
  109.                     pPhysPath++;
  110.                 }
  111.                 *pPhysPath = '\0';
  112.                 pfc->pFilterContext = (VOID *) 1;
  113.                 break;
  114.             }
  115.             pPhysPath++;
  116.         }
  117.  
  118.         break;
  119.  
  120.     case SF_NOTIFY_SEND_RAW_DATA:
  121.  
  122.         pRawData = (PHTTP_FILTER_RAW_DATA) pvData;
  123.  
  124.         if (pfc->pFilterContext)
  125.         {
  126.             pchIn = (BYTE *) pRawData->pvInData;
  127.             cbBuffer = 0;
  128.             cbtemp = 0;
  129.  
  130.             if (pfc->pFilterContext == (VOID *) 1)      // first block?
  131.             {
  132.                 while (cbBuffer < pRawData->cbInData)
  133.                 {
  134.                     if (pchIn[cbBuffer] == '\n' &&
  135.                         pchIn[cbBuffer+2] == '\n')
  136.                     {
  137.                         cbBuffer +=3;
  138.                         break;
  139.                     }
  140.                     cbBuffer++;
  141.                 }
  142.             
  143.                 while (cbtemp < cbBuffer)
  144.                 {
  145.                     if (pchIn[cbtemp] == '/' && pchIn[cbtemp+1] == 'h' &&
  146.                         pchIn[cbtemp+2] == 't' && pchIn[cbtemp+3] == 'm')
  147.                     {
  148.                         pfc->pFilterContext = (VOID *) 2;
  149.                         break;
  150.                     }
  151.                     cbtemp++;
  152.                 }
  153.                 if (cbtemp == cbBuffer)
  154.                     pfc->pFilterContext = 0;        // not an html file
  155.             }
  156.             
  157.             if (pfc->pFilterContext)
  158.             {
  159.                 while (cbBuffer < pRawData->cbInData)
  160.                 {
  161.                     pchIn[cbBuffer] = 
  162.                         (pchIn[cbBuffer]>='a' && pchIn[cbBuffer]<='z') ? 
  163.                 (pchIn[cbBuffer]-'a'+'A') : pchIn[cbBuffer];
  164.                     cbBuffer++;
  165.                 }
  166.             
  167.             }
  168.         }
  169.         break;
  170.            
  171.     default:
  172.         break;        
  173.     }
  174.  
  175.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  176. }
  177.