Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
6.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: Mft.hxx (sample stackable filter)
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 04-16-97 DanpoZ (Danpo Zhang) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef _CMFT_HXX_
  18. #define _CMFT_HXX_
  19. #include <urlmon.hxx>
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Class: CMft
  23. //
  24. // Purpose: Mime filter
  25. //
  26. // Interface: [support all IOInetProtocol interfaces]
  27. // [support all IOInetProtocolSink interfaces]
  28. //
  29. // History: 11-24-97 DanpoZ (Danpo Zhang) Created
  30. //
  31. //----------------------------------------------------------------------------
  32. class CMft : public IOInetProtocol,
  33. public IOInetProtocolSink,
  34. public IOInetProtocolSinkStackable
  35. {
  36. public:
  37. // IUnknown methods
  38. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj)
  39. {
  40. HRESULT hr = E_NOINTERFACE;
  41. *ppvObj = NULL;
  42. if( (iid == IID_IUnknown) ||
  43. (iid == IID_IOInetProtocol) ||
  44. (iid == IID_IOInetProtocolRoot) )
  45. {
  46. *ppvObj = (IOInetProtocol*)this;
  47. }
  48. else
  49. if( iid == IID_IOInetProtocolSink )
  50. {
  51. *ppvObj = (IOInetProtocolSink*)this;
  52. }
  53. else
  54. if( iid == IID_IOInetProtocolSinkStackable )
  55. {
  56. *ppvObj = (IOInetProtocolSinkStackable*)this;
  57. }
  58. if( *ppvObj )
  59. {
  60. hr = NOERROR;
  61. AddRef();
  62. }
  63. return hr;
  64. }
  65. STDMETHODIMP_(ULONG) AddRef(void)
  66. {
  67. LONG lRet = ++_CRefs;
  68. return lRet;
  69. }
  70. STDMETHODIMP_(ULONG) Release(void)
  71. {
  72. LONG lRet = --_CRefs;
  73. if( !lRet )
  74. {
  75. delete this;
  76. }
  77. return lRet;
  78. }
  79. // IOInetProtocol
  80. STDMETHODIMP Start(
  81. LPCWSTR szUrl,
  82. IOInetProtocolSink *pProtSink,
  83. IOInetBindInfo *pOIBindInfo,
  84. DWORD grfSTI,
  85. DWORD dwReserved
  86. )
  87. {
  88. PROTOCOLFILTERDATA* FiltData = (PROTOCOLFILTERDATA*) dwReserved;
  89. _pProt = FiltData->pProtocol;
  90. _pProtSink = pProtSink;
  91. _pProt->AddRef();
  92. _pProtSink->AddRef();
  93. return NOERROR;
  94. }
  95. STDMETHODIMP Continue( PROTOCOLDATA *pStateInfo)
  96. {
  97. return _pProt->Continue(pStateInfo);
  98. }
  99. STDMETHODIMP Abort( HRESULT hrReason, DWORD dwOptions)
  100. {
  101. return _pProt->Abort(hrReason, dwOptions);
  102. }
  103. STDMETHODIMP Terminate( DWORD dwOptions)
  104. {
  105. if( _pProtSink )
  106. {
  107. _pProtSink->Release();
  108. _pProtSink = NULL;
  109. }
  110. return _pProt->Terminate(dwOptions);
  111. }
  112. STDMETHODIMP Suspend()
  113. {
  114. return _pProt->Suspend();
  115. }
  116. STDMETHODIMP Resume()
  117. {
  118. return _pProt->Resume();
  119. }
  120. STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead)
  121. {
  122. return _pProt->Read(pv, cb, pcbRead);
  123. }
  124. STDMETHODIMP Seek(
  125. LARGE_INTEGER dlibMove,
  126. DWORD dwOrigin,
  127. ULARGE_INTEGER *plibNewPosition
  128. )
  129. {
  130. return _pProt->Seek(dlibMove, dwOrigin, plibNewPosition);
  131. }
  132. STDMETHODIMP LockRequest(DWORD dwOptions)
  133. {
  134. return _pProt->LockRequest(dwOptions);
  135. }
  136. STDMETHODIMP UnlockRequest()
  137. {
  138. return _pProt->UnlockRequest();
  139. }
  140. STDMETHODIMP Switch( PROTOCOLDATA *pStateInfo)
  141. {
  142. return _pProtSink->Switch(pStateInfo);
  143. }
  144. STDMETHODIMP ReportProgress( ULONG ulStatusCode, LPCWSTR szStatusText)
  145. {
  146. return _pProtSink->ReportProgress(ulStatusCode, szStatusText);
  147. }
  148. STDMETHODIMP ReportData(
  149. DWORD grfBSCF,
  150. ULONG ulProgress,
  151. ULONG ulProgressMax
  152. )
  153. {
  154. return _pProtSink->ReportData(grfBSCF, ulProgress, ulProgressMax);
  155. }
  156. STDMETHODIMP ReportResult(
  157. HRESULT hrResult,
  158. DWORD dwError,
  159. LPCWSTR wzResult
  160. )
  161. {
  162. return _pProtSink->ReportResult(hrResult, dwError, wzResult);
  163. }
  164. STDMETHODIMP SwitchSink(IOInetProtocolSink* pSink)
  165. {
  166. HRESULT hr = NOERROR;
  167. // keep track the existing sink (support for Commit/Rollback)
  168. // the release of the old sink will be done at the Commit time
  169. _pProtSinkOld = _pProtSink;
  170. // -----------------------------------------------------------
  171. // BUG: remove this block once enable the Commit-Rollback func
  172. // release the old sink
  173. //
  174. if( _pProtSinkOld )
  175. {
  176. _pProtSinkOld->Release();
  177. }
  178. // -----------------------------------------------------------
  179. // Change the sink
  180. _pProtSink = pSink;
  181. _pProtSink->AddRef();
  182. return hr;
  183. }
  184. STDMETHODIMP CommitSwitch()
  185. {
  186. // release the old sink
  187. //if( _pProtSinkOld )
  188. //{
  189. // _pProtSinkOld->Release();
  190. //}
  191. // reset
  192. //_pProtSinkOld = NULL;
  193. return NOERROR;
  194. }
  195. STDMETHODIMP RollbackSwitch()
  196. {
  197. // copy the old sink back, release the new sink
  198. // (new sink is AddRef'ed at SwitchSink time)
  199. //if( _pProtSink )
  200. //{
  201. // _pProtSink->Release();
  202. //}
  203. //_pProtSink = _pProtSinkOld;
  204. // reset
  205. //_pProtSinkOld = NULL;
  206. return NOERROR;
  207. }
  208. CMft()
  209. : _CRefs()
  210. {
  211. _pProtSink = NULL;
  212. _pProt = NULL;
  213. _pProtSinkOld = NULL;
  214. }
  215. virtual ~CMft()
  216. {
  217. if( _pProt )
  218. {
  219. _pProt->Release();
  220. }
  221. }
  222. private:
  223. CRefCount _CRefs;
  224. IOInetProtocol* _pProt;
  225. IOInetProtocolSink* _pProtSink;
  226. IOInetProtocolSink* _pProtSinkOld;
  227. };
  228. #endif