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.

261 lines
7.3 KiB

  1. #define PP_PRE_SWITCH 0x00000001
  2. #define PP_POST_SWITCH 0x00000002
  3. #define PP_DELETE 0x00000004
  4. class COInetProt : public IOInetProtocol
  5. , public IOInetProtocolSink
  6. , public IServiceProvider
  7. , public IOInetPriority
  8. {
  9. public:
  10. // IUnknown methods
  11. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj);
  12. STDMETHODIMP_(ULONG) AddRef(void);
  13. STDMETHODIMP_(ULONG) Release(void);
  14. //
  15. //IOInetProtocol methods
  16. STDMETHODIMP Start(LPCWSTR szUrl,IOInetProtocolSink *pProtSink,
  17. IOInetBindInfo *pOIBindInfo,DWORD grfSTI,DWORD_PTR dwReserved);
  18. STDMETHODIMP Continue(PROTOCOLDATA *pStateInfo);
  19. STDMETHODIMP Abort(HRESULT hrReason,DWORD dwOptions);
  20. STDMETHODIMP Terminate(DWORD dwOptions);
  21. STDMETHODIMP Suspend();
  22. STDMETHODIMP Resume();
  23. STDMETHODIMP Read(void *pv,ULONG cb,ULONG *pcbRead);
  24. STDMETHODIMP Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,
  25. ULARGE_INTEGER *plibNewPosition);
  26. STDMETHODIMP LockRequest(DWORD dwOptions);
  27. STDMETHODIMP UnlockRequest();
  28. //
  29. // IOInetProtocolSink methods
  30. STDMETHODIMP Switch(PROTOCOLDATA *pStateInfo);
  31. STDMETHODIMP ReportProgress(ULONG ulStatusCode, LPCWSTR szStatusText);
  32. STDMETHODIMP ReportData( DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax);
  33. STDMETHODIMP ReportResult(HRESULT hrResult, DWORD dwError, LPCWSTR wzResult);
  34. // IServiceProvider
  35. STDMETHODIMP QueryService(REFGUID rsid, REFIID iid, void ** ppvObj);
  36. // IOInetPriority
  37. STDMETHODIMP SetPriority(LONG nPriority);
  38. STDMETHODIMP GetPriority(LONG * pnPriority);
  39. public:
  40. STDMETHODIMP Create(COInetProt **ppCProtHandler);
  41. STDMETHODIMP OnDataReceived(DWORD *pgrfBSC, DWORD *pcbBytesAvailable, DWORD *pdwTotalSize);
  42. void SetServiceProvider(IServiceProvider *pSrvPrv)
  43. {
  44. if (pSrvPrv)
  45. {
  46. pSrvPrv->AddRef();
  47. }
  48. if (_pSrvPrv)
  49. {
  50. _pSrvPrv->Release();
  51. }
  52. _pSrvPrv = pSrvPrv;
  53. }
  54. void SetProtocolSink(IOInetProtocolSink *pProtSnk)
  55. {
  56. if (pProtSnk)
  57. {
  58. pProtSnk->AddRef();
  59. }
  60. if (_pProtSnk)
  61. {
  62. _pProtSnk->Release();
  63. }
  64. _pProtSnk = pProtSnk;
  65. }
  66. void SetProtocol(IOInetProtocol *pProt)
  67. {
  68. if (pProt)
  69. {
  70. pProt->AddRef();
  71. }
  72. if (_pProt)
  73. {
  74. _pProt->Release();
  75. }
  76. _pProt = pProt;
  77. }
  78. HRESULT GetProtocol( IOInetProtocol **ppProt)
  79. {
  80. if (_pProt)
  81. {
  82. _pProt->AddRef();
  83. *ppProt = _pProt;
  84. }
  85. return (_pProt) ? NOERROR : E_NOINTERFACE;
  86. }
  87. void SetHandler(IOInetProtocol *pProt, IOInetProtocolSink *pProtSnk)
  88. {
  89. if (_pProtHandler)
  90. {
  91. _pProtHandler->Release();
  92. }
  93. _pProtHandler = pProt;
  94. if (_pProtSnkHandler)
  95. {
  96. _pProtSnkHandler->Release();
  97. }
  98. _pProtSnkHandler = pProtSnk;
  99. if (_pProtHandler)
  100. {
  101. _pProtHandler->AddRef();
  102. }
  103. if (_pProtSnkHandler)
  104. {
  105. _pProtSnkHandler->AddRef();
  106. }
  107. }
  108. STDMETHODIMP Initialize(CTransaction *pCTrans, IServiceProvider *pSrvPrv, DWORD dwMode, DWORD dwOptions, IUnknown *pUnk, IOInetProtocol *pProt, IOInetProtocolSink *pProtSnk, LPWSTR pwzUrl = 0);
  109. static HRESULT Create(IUnknown *pUnk, IOInetProtocolSink *pProtSnk, COInetProt **pCOInetProtHndler)
  110. {
  111. HRESULT hr = NOERROR;
  112. if (!pUnk || !pProtSnk)
  113. {
  114. hr = E_INVALIDARG;
  115. }
  116. else
  117. {
  118. *pCOInetProtHndler = new COInetProt();
  119. if (*pCOInetProtHndler == NULL)
  120. {
  121. hr = E_OUTOFMEMORY;
  122. }
  123. }
  124. return hr;
  125. }
  126. DWORD GetOInetBindFlags()
  127. {
  128. return _dwOInetBdgFlags;
  129. }
  130. void SetOInetBindFlags(DWORD dwBdgFlags)
  131. {
  132. _dwOInetBdgFlags = dwBdgFlags;
  133. }
  134. COInetProt() : _CRefs()
  135. {
  136. _pUnk = 0;
  137. _pProt = 0;
  138. _pProtSnk = 0;
  139. _pCTrans = 0;
  140. _pSrvPrv = 0;
  141. _dwMode = 0;
  142. _dwOInetBdgFlags = 0;
  143. _pBuffer = 0; // DNLD_BUFFER_SIZE size buffer
  144. _cbBufferSize = 0;
  145. _cbTotalBytesRead = 0;
  146. _cbBufferFilled = 0; //how much of the buffer is in use
  147. _cbDataSniffMin = 0;
  148. _cbBytesReported = 0;
  149. _fDocFile = 0;
  150. _fMimeVerified = 0;
  151. _fMimeReported = 0;
  152. _pwzFileName = 0;
  153. _pwzMimeSuggested = 0;
  154. _fDelete = 0;
  155. _pProtHandler = 0;
  156. _pProtSnkHandler = 0;
  157. _fNeedMoreData = 0;
  158. _fGotHandler = 0;
  159. _fWaitOnHandler = 0;
  160. _pwzUrl = 0;
  161. _nPriority = THREAD_PRIORITY_NORMAL;
  162. _fClassInstallChecked = 0;
  163. _fReportedClassId = 0;
  164. _cbBufferUnread = 0;
  165. _pwzStrClsId = NULL;
  166. }
  167. void InitAttachedBindToObject()
  168. {
  169. _fReportedClassId = 0;
  170. if (_dwOInetBdgFlags & (PI_MIMEVERIFICATION|PI_DOCFILECLSIDLOOKUP))
  171. _dwOInetBdgFlags |= PI_CLASSINSTALL;
  172. }
  173. ~COInetProt()
  174. {
  175. delete [] _pwzFileName;
  176. delete [] _pwzMimeSuggested;
  177. delete [] _pwzStrClsId;
  178. delete [] _pBuffer;
  179. delete [] _pwzUrl;
  180. }
  181. private:
  182. CRefCount _CRefs; // the total refcount of this object
  183. CMutexSem _mxs; // used in Read, Seek, Abort and package list in case of apartment threaded
  184. IUnknown *_pUnk;
  185. IOInetProtocol *_pProt; // the prot the filter reads from
  186. IOInetProtocolSink *_pProtSnk; // the prot report progress
  187. IServiceProvider *_pSrvPrv;
  188. CTransaction *_pCTrans;
  189. LONG _nPriority;
  190. DWORD _dwOInetBdgFlags;
  191. DWORD _dwMode; //
  192. LPBYTE _pBuffer; // DNLD_BUFFER_SIZE size buffer
  193. ULONG _cbBufferSize;
  194. ULONG _cbTotalBytesRead;
  195. ULONG _cbBufferFilled; //how much of the buffer is in use
  196. //ULONG _cbDataSize;
  197. ULONG _cbDataSniffMin;
  198. ULONG _cbBytesReported; // how much was reported
  199. ULONG _cbBufferUnread;
  200. BOOL _fDocFile : 1;
  201. BOOL _fMimeVerified : 1;
  202. BOOL _fMimeReported : 1;
  203. BOOL _fDelete : 1;
  204. BOOL _fNeedMoreData : 1;
  205. BOOL _fGotHandler : 1;
  206. BOOL _fWaitOnHandler : 1;
  207. BOOL _fClassInstallChecked : 1;
  208. BOOL _fReportedClassId : 1;
  209. LPWSTR _pwzFileName;
  210. LPWSTR _pwzMimeSuggested;
  211. LPWSTR _pwzUrl;
  212. LPOLESTR _pwzStrClsId;
  213. IOInetProtocol *_pProtHandler;
  214. IOInetProtocolSink *_pProtSnkHandler;
  215. };