home *** CD-ROM | disk | FTP | other *** search
- // LST15_02.CPP - Implementation file for your Internet Server
- // lst15_02 Filter
-
- #include <afx.h>
- #include <afxwin.h>
- #include <afxisapi.h>
- #include "resource.h"
- #include "lst15_02.h"
-
-
- ///////////////////////////////////////////////////////////////////////
- // The one and only CLst15_02Filter object
-
- CLst15_02Filter theFilter;
-
-
- ///////////////////////////////////////////////////////////////////////
- // CLst15_02Filter implementation
-
- CLst15_02Filter::CLst15_02Filter()
- {
- }
-
- CLst15_02Filter::~CLst15_02Filter()
- {
- }
-
- BOOL CLst15_02Filter::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_SEND_RAW_DATA | 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;
- }
-
- LPTSTR CLst15_02Filter::Replace(LPTSTR lpszString,LPTSTR lpszTarget, LPTSTR lpszReplacement)
- {
- LPTSTR lpszIndex;
- LPTSTR lpszSegment;
- LPTSTR lpszSegmentIndex;
- LPTSTR lpszData;
- DWORD dwIndexLength;
- DWORD dwDataLength;
-
- dwDataLength=_tcslen(lpszString)+_tcslen(lpszReplacement)+1;
- lpszData=new TCHAR[dwDataLength];
- _tcscpy(lpszData,lpszString);
-
- while (lpszIndex=_tcsstr(lpszData,lpszTarget))
- {
- dwIndexLength=_tcslen(lpszIndex)+1;
- lpszSegment=new TCHAR[dwIndexLength];
- _tcscpy(lpszSegment,lpszIndex);
- _tcscpy(lpszIndex,lpszReplacement);
- lpszSegmentIndex=lpszSegment+_tcslen(lpszTarget);
- _tcscat(lpszIndex,lpszSegmentIndex);
- delete lpszSegment;
- }
-
- // If Needed Allocate some heap
- if (_tcslen(lpszString)<_tcslen(lpszData))
- {
- delete lpszString;
- lpszString = new TCHAR[_tcslen(lpszData)];
- }
-
- // Padd the end with spaces so that the
- // Content Length stays the same
- while (_tcslen(lpszString)>_tcslen(lpszData))
- {
- _tcscat(lpszData," ");
- }
-
- // Copy to Output
- _tcscpy(lpszString,lpszData);
-
- delete lpszData;
-
- return lpszString;
- }
-
-
- DWORD CLst15_02Filter::OnSendRawData(CHttpFilterContext* pCtxt,
- PHTTP_FILTER_RAW_DATA pRawData)
- {
- LPTSTR lpszData;
- DWORD cbBufferSize=pRawData->cbInBuffer;
- DWORD cbSize=pRawData->cbInData;
- DWORD cbReplacementSize;
-
- // This part creates the Date String
-
- CTime tCurrent = CTime::GetCurrentTime();
- LPTSTR lpszTime;
- lpszTime = new TCHAR[6];
-
- sprintf(lpszTime,_T("%d-%d"),tCurrent.GetMonth(),tCurrent.GetDay());
-
- lpszData=new TCHAR[cbSize+1];
- memcpy(lpszData,pRawData->pvInData,cbSize);
- lpszData[cbSize]='\0';
-
- lpszData=Replace(lpszData,_T("<DATE>"),(LPTSTR) lpszTime);
-
- cbReplacementSize=_tcslen(lpszData);
-
- // If the tag is smaller then the data that
- // is replacing it them don't change the
- // data.
- if (cbReplacementSize <= (int)cbBufferSize)
- {
- _tcscpy((LPTSTR)pRawData->pvInData,lpszData);
- }
-
- delete lpszData;
- delete lpszTime;
-
- // TODO: React to this notification accordingly and
- // return the appropriate status code
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
- }
-
- DWORD CLst15_02Filter::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;
- }
-
- ****/
-