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

  1. // LST15_02.CPP - Implementation file for your Internet Server
  2. //    lst15_02 Filter
  3.  
  4. #include <afx.h>
  5. #include <afxwin.h>
  6. #include <afxisapi.h>
  7. #include "resource.h"
  8. #include "lst15_02.h"
  9.  
  10.  
  11. ///////////////////////////////////////////////////////////////////////
  12. // The one and only CLst15_02Filter object
  13.  
  14. CLst15_02Filter theFilter;
  15.  
  16.  
  17. ///////////////////////////////////////////////////////////////////////
  18. // CLst15_02Filter implementation
  19.  
  20. CLst15_02Filter::CLst15_02Filter()
  21. {
  22. }
  23.  
  24. CLst15_02Filter::~CLst15_02Filter()
  25. {
  26. }
  27.  
  28. BOOL CLst15_02Filter::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_SEND_RAW_DATA | 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. LPTSTR CLst15_02Filter::Replace(LPTSTR lpszString,LPTSTR lpszTarget, LPTSTR lpszReplacement)
  49. {
  50.     LPTSTR    lpszIndex;
  51.     LPTSTR    lpszSegment;
  52.      LPTSTR    lpszSegmentIndex;
  53.     LPTSTR    lpszData;
  54.     DWORD    dwIndexLength;
  55.        DWORD    dwDataLength;
  56.  
  57.     dwDataLength=_tcslen(lpszString)+_tcslen(lpszReplacement)+1;
  58.     lpszData=new TCHAR[dwDataLength];
  59.     _tcscpy(lpszData,lpszString);
  60.  
  61.     while (lpszIndex=_tcsstr(lpszData,lpszTarget))
  62.     {
  63.         dwIndexLength=_tcslen(lpszIndex)+1;
  64.         lpszSegment=new TCHAR[dwIndexLength];
  65.         _tcscpy(lpszSegment,lpszIndex);
  66.         _tcscpy(lpszIndex,lpszReplacement);
  67.         lpszSegmentIndex=lpszSegment+_tcslen(lpszTarget);
  68.         _tcscat(lpszIndex,lpszSegmentIndex);
  69.         delete lpszSegment;
  70.     }
  71.  
  72.     // If Needed Allocate some heap
  73.     if (_tcslen(lpszString)<_tcslen(lpszData))
  74.     {
  75.         delete lpszString;
  76.         lpszString = new TCHAR[_tcslen(lpszData)];
  77.     }
  78.  
  79.     // Padd the end with spaces so that the
  80.     // Content Length stays the same
  81.     while (_tcslen(lpszString)>_tcslen(lpszData))
  82.     {
  83.         _tcscat(lpszData," ");
  84.     }
  85.  
  86.     // Copy to Output
  87.     _tcscpy(lpszString,lpszData);
  88.  
  89.     delete lpszData;
  90.  
  91.     return lpszString;
  92. }
  93.  
  94.  
  95. DWORD CLst15_02Filter::OnSendRawData(CHttpFilterContext* pCtxt,
  96.     PHTTP_FILTER_RAW_DATA pRawData)
  97. {
  98.     LPTSTR    lpszData;
  99.     DWORD    cbBufferSize=pRawData->cbInBuffer;
  100.     DWORD    cbSize=pRawData->cbInData;
  101.     DWORD    cbReplacementSize;
  102.  
  103.     // This part creates the Date String
  104.  
  105.     CTime tCurrent = CTime::GetCurrentTime();
  106.     LPTSTR lpszTime;
  107.     lpszTime = new TCHAR[6];
  108.  
  109.     sprintf(lpszTime,_T("%d-%d"),tCurrent.GetMonth(),tCurrent.GetDay());
  110.  
  111.     lpszData=new TCHAR[cbSize+1];
  112.     memcpy(lpszData,pRawData->pvInData,cbSize);
  113.     lpszData[cbSize]='\0';
  114.  
  115.     lpszData=Replace(lpszData,_T("<DATE>"),(LPTSTR) lpszTime);
  116.  
  117.     cbReplacementSize=_tcslen(lpszData);
  118.  
  119.     // If the tag is smaller then the data that
  120.     // is replacing it them don't change the
  121.     // data.
  122.     if (cbReplacementSize <= (int)cbBufferSize)
  123.         {
  124.             _tcscpy((LPTSTR)pRawData->pvInData,lpszData);
  125.         }
  126.  
  127.     delete lpszData;
  128.     delete lpszTime;
  129.  
  130.     // TODO: React to this notification accordingly and
  131.     // return the appropriate status code
  132.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  133. }
  134.  
  135. DWORD CLst15_02Filter::OnEndOfNetSession(CHttpFilterContext* pCtxt)
  136. {
  137.     // TODO: React to this notification accordingly and
  138.     // return the appropriate status code
  139.     return SF_STATUS_REQ_NEXT_NOTIFICATION;
  140. }
  141.  
  142. ///////////////////////////////////////////////////////////////////////
  143. // If your extension will not use MFC, you'll need this code to make
  144. // sure the extension objects can find the resource handle for the
  145. // module.  If you convert your extension to not be dependent on MFC,
  146. // remove the comments arounn the following AfxGetResourceHandle()
  147. // and DllMain() functions, as well as the g_hInstance global.
  148.  
  149. /****
  150.  
  151. static HINSTANCE g_hInstance;
  152.  
  153. HINSTANCE AFXISAPI AfxGetResourceHandle()
  154. {
  155.     return g_hInstance;
  156. }
  157.  
  158. BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
  159.                     LPVOID lpReserved)
  160. {
  161.     if (ulReason == DLL_PROCESS_ATTACH)
  162.     {
  163.         g_hInstance = hInst;
  164.     }
  165.  
  166.     return TRUE;
  167. }
  168.  
  169. ****/
  170.