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.

469 lines
18 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. NameSpace_Impl.h
  5. Abstract:
  6. This file contains the declaration of the classes used to implement the
  7. pluggable protocol: CHCPProtocol, CHCPProtocolInfo and CHCPBindStatusCallback.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 07/05/99
  10. created
  11. Davide Massarenti (Dmassare) 07/23/99
  12. moved to "include"
  13. ******************************************************************************/
  14. #if !defined(__INCLUDED___HCP___NAMESPACE_H___)
  15. #define __INCLUDED___HCP___NAMESPACE_H___
  16. #include <MPC_utils.h>
  17. #include <MPC_streams.h>
  18. #include <TaxonomyDatabase.h>
  19. /////////////////////////////////////////////////////////////////////////////
  20. extern bool g_Debug_BLOCKERRORS;
  21. extern bool g_Debug_CONTEXTMENU;
  22. extern bool g_Debug_BUILDTREE;
  23. extern WCHAR g_Debug_FORCESTYLE[];
  24. ////////////////////////////////////////////////////////////////////////////////
  25. #ifdef DEBUG_PROTOCOLLEAK
  26. #include <set>
  27. class CHCPProtocol;
  28. class DEBUG_ProtocolLeak
  29. {
  30. typedef std::set<CHCPProtocol*> Set;
  31. typedef Set::iterator Iter;
  32. typedef Set::const_iterator IterConst;
  33. Set m_set;
  34. Set m_setStart;
  35. Set m_setComplete;
  36. int m_num;
  37. int m_numOut;
  38. int m_numStart;
  39. int m_numComplete;
  40. public:
  41. DEBUG_ProtocolLeak();
  42. ~DEBUG_ProtocolLeak();
  43. void Add( CHCPProtocol* ptr );
  44. void Del( CHCPProtocol* ptr );
  45. void CheckStart( CHCPProtocol* ptr );
  46. void Completed ( CHCPProtocol* ptr );
  47. };
  48. #endif
  49. /////////////////////////////////////////////////////////////////////////////
  50. class CHCPBindStatusCallback;
  51. /////////////////////////////////////////////////////////////////////////////
  52. class ATL_NO_VTABLE ISimpleBindStatusCallback : public IUnknown
  53. {
  54. public:
  55. STDMETHOD(ForwardQueryInterface)( REFIID riid, void** ppv );
  56. STDMETHOD(GetBindInfo)( BINDINFO *pbindInfo );
  57. STDMETHOD(PreBindMoniker)( IBindCtx* pBindCtx, IMoniker* pMoniker );
  58. STDMETHOD(OnProgress)( ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText );
  59. STDMETHOD(OnData)( CHCPBindStatusCallback* pbsc, BYTE* pBytes, DWORD dwSize, DWORD grfBSCF, FORMATETC *pformatetc, STGMEDIUM *pstgmed );
  60. STDMETHOD(OnBindingFailure)( HRESULT hr, LPCWSTR szError );
  61. };
  62. class ATL_NO_VTABLE CHCPBindStatusCallback : // Hungarian: bscb
  63. public CComObjectRootEx<MPC::CComSafeMultiThreadModel>,
  64. public IBindStatusCallback,
  65. public IHttpNegotiate
  66. {
  67. CComPtr<ISimpleBindStatusCallback> m_pT;
  68. DWORD m_dwTotalRead;
  69. DWORD m_dwAvailableToRead;
  70. CComPtr<IMoniker> m_spMoniker;
  71. CComPtr<IBindCtx> m_spBindCtx;
  72. CComPtr<IBinding> m_spBinding;
  73. CComPtr<IStream> m_spStream;
  74. public:
  75. BEGIN_COM_MAP(CHCPBindStatusCallback)
  76. COM_INTERFACE_ENTRY(IBindStatusCallback)
  77. COM_INTERFACE_ENTRY(IHttpNegotiate)
  78. // COM_INTERFACE_ENTRY_FUNC_BLIND(0,TestQuery)
  79. // COM_INTERFACE_ENTRY(IServiceProvider)
  80. END_COM_MAP()
  81. CHCPBindStatusCallback();
  82. virtual ~CHCPBindStatusCallback();
  83. //static HRESULT TestQuery( void* pv, REFIID iid, void** ppvObject, DWORD dw )
  84. //{
  85. // *ppvObject = NULL;
  86. // return E_NOINTERFACE;
  87. //}
  88. /////////////////////////////////////////////////////////////////////////////
  89. // IBindStatusCallback
  90. STDMETHOD(OnStartBinding)( DWORD dwReserved ,
  91. IBinding *pBinding );
  92. STDMETHOD(GetPriority)( LONG *pnPriority );
  93. STDMETHOD(OnLowResource)( DWORD reserved );
  94. STDMETHOD(OnProgress)( ULONG ulProgress ,
  95. ULONG ulProgressMax ,
  96. ULONG ulStatusCode ,
  97. LPCWSTR szStatusText );
  98. STDMETHOD(OnStopBinding)( HRESULT hresult ,
  99. LPCWSTR szError );
  100. STDMETHOD(GetBindInfo)( DWORD *pgrfBINDF ,
  101. BINDINFO *pbindInfo );
  102. STDMETHOD(OnDataAvailable)( DWORD grfBSCF ,
  103. DWORD dwSize ,
  104. FORMATETC *pformatetc ,
  105. STGMEDIUM *pstgmed );
  106. STDMETHOD(OnObjectAvailable)( REFIID riid ,
  107. IUnknown *punk );
  108. /////////////////////////////////////////////////////////////////////////////
  109. // IHttpNegotiate
  110. STDMETHOD(BeginningTransaction)( LPCWSTR szURL ,
  111. LPCWSTR szHeaders ,
  112. DWORD dwReserved ,
  113. LPWSTR *pszAdditionalHeaders );
  114. STDMETHOD(OnResponse)( DWORD dwResponseCode ,
  115. LPCWSTR szResponseHeaders ,
  116. LPCWSTR szRequestHeaders ,
  117. LPWSTR *pszAdditionalRequestHeaders );
  118. /////////////////////////////////////////////////////////////////////////////
  119. HRESULT StartAsyncDownload( ISimpleBindStatusCallback* pT, BSTR bstrURL, IUnknown* pUnkContainer = NULL, BOOL bRelative = FALSE );
  120. HRESULT Abort();
  121. };
  122. /////////////////////////////////////////////////////////////////////////////
  123. class ATL_NO_VTABLE CHCPProtocol :
  124. public CComObjectRootEx<CComSingleThreadModel>,
  125. public CComCoClass<CHCPProtocol>,
  126. public ISimpleBindStatusCallback,
  127. public IInternetProtocol,
  128. public IWinInetInfo
  129. {
  130. #ifdef DEBUG
  131. friend class DEBUG_ProtocolLeak;
  132. #endif
  133. typedef CComObject< CHCPBindStatusCallback > InnerDownloader;
  134. bool m_fDone; // Indicates whether we've received LASTDATANOTIFICATION yet
  135. bool m_fReportResult; // Indicates whether we've called ReportResult on the sink.
  136. //
  137. DWORD m_cbAvailableSize; // Amount of data received up to now.
  138. DWORD m_cbTotalSize; // Total number of bytes to be expected. For redirected requests,
  139. // it comes from "ulProgressMax" parm to OnProgress for BEGINDOWNLOADDATA
  140. //
  141. CComPtr<IStream> m_pstrmRead; // Streams used for redirected request. We use two stream pointers to allow
  142. CComPtr<IStream> m_pstrmWrite; // concurrent access to the same bits from two seek ptrs.
  143. //
  144. CComPtr<IInternetProtocolSink> m_pIProtSink; // Sink interface through which we should report progress.
  145. CComPtr<IInternetBindInfo> m_pIBindInfo; // BindInfo interface used to get info about the binding.
  146. DWORD m_grfSTI; // STI flags handed to us
  147. BINDINFO m_bindinfo; // From m_pIBindInfo
  148. DWORD m_bindf; // From m_pIBindInfo
  149. //
  150. CComBSTR m_bstrUrlComplete; // The complete URL requested.
  151. CComBSTR m_bstrUrlRedirected; // The part that has been used as a redirection.
  152. InnerDownloader* m_pDownloader; // The object that performs the redirection.
  153. //
  154. bool m_fRedirected; // The request has been redirected.
  155. bool m_fCSS; // The request has been redirected.
  156. bool m_fBypass; // The request has been sent to ms-its, with a bypass.
  157. //
  158. CComPtr<IInternetProtocol> m_ipiBypass; // Aggregated object.
  159. //
  160. CComBSTR m_bstrMimeType; // Type of the content.
  161. DWORD m_dwContentLength; // Length of the page.
  162. //
  163. HANDLE m_hCache; // Handle for the cache entry.
  164. WCHAR m_szCacheFileName[MAX_PATH]; // Name of the file inside the cache.
  165. ////////////////////////////////////////////////////////////////////////////////
  166. HRESULT InnerReportProgress( /*[in]*/ ULONG ulStatusCode, /*[in]*/ LPCWSTR szStatusText );
  167. HRESULT InnerReportData( /*[in]*/ DWORD grfBSCF, /*[in]*/ ULONG ulProgress, /*[in]*/ ULONG ulProgressMax );
  168. HRESULT InnerReportResult( /*[in]*/ HRESULT hrResult, /*[in]*/ DWORD dwError, /*[in]*/ LPCWSTR szResult );
  169. public:
  170. DECLARE_NO_REGISTRY()
  171. BEGIN_COM_MAP(CHCPProtocol)
  172. COM_INTERFACE_ENTRY(IInternetProtocol )
  173. COM_INTERFACE_ENTRY(IInternetProtocolRoot)
  174. COM_INTERFACE_ENTRY(IWinInetInfo)
  175. END_COM_MAP()
  176. CHCPProtocol();
  177. virtual ~CHCPProtocol();
  178. ////////////////////////////////////////////////////////////////////////////////
  179. bool OpenCacheEntry ( );
  180. void WriteCacheEntry( /*[in]*/ void *pv, /*[in]*/ ULONG cbRead );
  181. void CloseCacheEntry( /*[in]*/ bool fDelete );
  182. ////////////////////////////////////////////////////////////////////////////////
  183. void Shutdown( /*[in]*/ bool fAll = true );
  184. /////////////////////////////////////////////////////////////////////////////
  185. // IInternetProtocol interface
  186. STDMETHOD(Start)( LPCWSTR szUrl ,
  187. IInternetProtocolSink *pIProtSink ,
  188. IInternetBindInfo *pIBindInfo ,
  189. DWORD grfSTI ,
  190. HANDLE_PTR dwReserved );
  191. STDMETHOD(Continue)( PROTOCOLDATA *pStateInfo );
  192. STDMETHOD(Abort )( HRESULT hrReason, DWORD dwOptions );
  193. STDMETHOD(Terminate)( DWORD dwOptions );
  194. STDMETHOD(Suspend )( );
  195. STDMETHOD(Resume )( );
  196. STDMETHOD(Read)( void *pv, ULONG cb, ULONG *pcbRead );
  197. STDMETHOD(Seek)( LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition );
  198. STDMETHOD(LockRequest )( DWORD dwOptions );
  199. STDMETHOD(UnlockRequest)( );
  200. /////////////////////////////////////////////////////////////////////////////
  201. // IWinInetInfo interface
  202. STDMETHOD(QueryOption)( DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf );
  203. public:
  204. HRESULT DoParse( /*[in]*/ LPCWSTR wstr );
  205. HRESULT DoBind();
  206. HRESULT DoBind_Exists( /*[in] */ MPC::FileSystemObject& fso, /*[out]*/ bool& fFound, /*[out]*/ bool& fIsAFile );
  207. HRESULT DoBind_Redirect_UrlMoniker();
  208. HRESULT DoBind_Redirect_MSITS ();
  209. HRESULT DoBind_CSS ();
  210. HRESULT DoBind_File ();
  211. HRESULT DoBind_ReturnData ( /*[in]*/ bool fCloneStream, /*[in]*/ LPCWSTR szMimeType );
  212. /////////////////////////////////////////////////////////////////////////////
  213. // ISimpleBindStatusCallback
  214. STDMETHOD(ForwardQueryInterface)( REFIID riid, void** ppv );
  215. STDMETHOD(GetBindInfo)( BINDINFO *pbindInfo );
  216. STDMETHOD(PreBindMoniker)( IBindCtx* pBindCtx, IMoniker* pMoniker );
  217. STDMETHOD(OnBindingFailure)( HRESULT hr, LPCWSTR szError );
  218. STDMETHOD(OnProgress)( ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText );
  219. STDMETHOD(OnData)( CHCPBindStatusCallback* pbsc, BYTE* pBytes, DWORD dwSize, DWORD grfBSCF, FORMATETC *pformatetc, STGMEDIUM *pstgmed );
  220. /////////////////////////////////////////////////////////////////////////////
  221. static bool IsHCPRedirection(LPCWSTR szURL);
  222. };
  223. /////////////////////////////////////////////////////////////////////////////
  224. class ATL_NO_VTABLE CHCPProtocolInfo :
  225. public CComObjectRootEx<CComSingleThreadModel>,
  226. public IClassFactory,
  227. public IInternetProtocolInfo
  228. {
  229. public:
  230. DECLARE_NO_REGISTRY()
  231. BEGIN_COM_MAP(CHCPProtocolInfo)
  232. COM_INTERFACE_ENTRY(IClassFactory)
  233. COM_INTERFACE_ENTRY(IInternetProtocolInfo)
  234. END_COM_MAP()
  235. CHCPProtocolInfo();
  236. virtual ~CHCPProtocolInfo();
  237. // IClassFactory interface
  238. STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj);
  239. STDMETHOD(LockServer)(BOOL fLock);
  240. // IInternetProtocolInfo interface
  241. STDMETHOD(ParseUrl)( LPCWSTR pwzUrl ,
  242. PARSEACTION ParseAction ,
  243. DWORD dwParseFlags,
  244. LPWSTR pwzResult ,
  245. DWORD cchResult ,
  246. DWORD *pcchResult ,
  247. DWORD dwReserved );
  248. STDMETHOD(CombineUrl)( LPCWSTR pwzBaseUrl ,
  249. LPCWSTR pwzRelativeUrl,
  250. DWORD dwCombineFlags,
  251. LPWSTR pwzResult ,
  252. DWORD cchResult ,
  253. DWORD *pcchResult ,
  254. DWORD dwReserved );
  255. STDMETHOD(CompareUrl)( LPCWSTR pwzUrl1 ,
  256. LPCWSTR pwzUrl2 ,
  257. DWORD dwCompareFlags );
  258. STDMETHOD(QueryInfo)( LPCWSTR pwzUrl ,
  259. QUERYOPTION QueryOption ,
  260. DWORD dwQueryFlags,
  261. LPVOID pBuffer ,
  262. DWORD cbBuffer ,
  263. DWORD *pcbBuf ,
  264. DWORD dwReserved );
  265. /////////////////////////////////////////////////////////////////////////////
  266. static bool LookForHCP( LPCWSTR pwzUrl, bool& fRedirect, LPCWSTR& pwzRedirect );
  267. };
  268. /////////////////////////////////////////////////////////////////////////////
  269. class ATL_NO_VTABLE CPCHWrapProtocolInfo :
  270. public CComObjectRootEx<CComSingleThreadModel>,
  271. public IClassFactory,
  272. public IInternetProtocolInfo
  273. {
  274. CComPtr<IClassFactory> m_realClass;
  275. CComPtr<IInternetProtocolInfo> m_realInfo;
  276. static void ExpandAndConcat( /*[out]*/ CComBSTR& bstrStorageName, /*[in]*/ LPCWSTR szVariable, /*[in]*/ LPCWSTR szAppend );
  277. public:
  278. DECLARE_NO_REGISTRY()
  279. BEGIN_COM_MAP(CHCPProtocolInfo)
  280. COM_INTERFACE_ENTRY(IClassFactory)
  281. COM_INTERFACE_ENTRY(IInternetProtocolInfo)
  282. END_COM_MAP()
  283. CPCHWrapProtocolInfo();
  284. virtual ~CPCHWrapProtocolInfo();
  285. HRESULT Init( REFGUID realClass );
  286. ////////////////////
  287. static void NormalizeUrl( /*[in]*/ LPCWSTR pwzUrl, /*[out]*/ MPC::wstring& strUrlModified, /*[in]*/ bool fReverse );
  288. ////////////////////
  289. // IClassFactory interface
  290. STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj);
  291. STDMETHOD(LockServer)(BOOL fLock);
  292. // IInternetProtocolInfo interface
  293. STDMETHOD(ParseUrl)( LPCWSTR pwzUrl ,
  294. PARSEACTION ParseAction ,
  295. DWORD dwParseFlags,
  296. LPWSTR pwzResult ,
  297. DWORD cchResult ,
  298. DWORD *pcchResult ,
  299. DWORD dwReserved );
  300. STDMETHOD(CombineUrl)( LPCWSTR pwzBaseUrl ,
  301. LPCWSTR pwzRelativeUrl,
  302. DWORD dwCombineFlags,
  303. LPWSTR pwzResult ,
  304. DWORD cchResult ,
  305. DWORD *pcchResult ,
  306. DWORD dwReserved );
  307. STDMETHOD(CompareUrl)( LPCWSTR pwzUrl1 ,
  308. LPCWSTR pwzUrl2 ,
  309. DWORD dwCompareFlags );
  310. STDMETHOD(QueryInfo)( LPCWSTR pwzUrl ,
  311. QUERYOPTION QueryOption ,
  312. DWORD dwQueryFlags,
  313. LPVOID pBuffer ,
  314. DWORD cbBuffer ,
  315. DWORD *pcbBuf ,
  316. DWORD dwReserved );
  317. };
  318. ////////////////////////////////////////////////////////////////////////////////
  319. class CHCPProtocolEnvironment
  320. {
  321. bool m_fHighContrast;
  322. bool m_f16Colors;
  323. Taxonomy::Instance m_inst;
  324. MPC::string m_strCSS;
  325. ////////////////////
  326. HRESULT ProcessCSS();
  327. public:
  328. CHCPProtocolEnvironment();
  329. ~CHCPProtocolEnvironment();
  330. ////////////////////////////////////////////////////////////////////////////////
  331. static CHCPProtocolEnvironment* s_GLOBAL;
  332. static HRESULT InitializeSystem();
  333. static void FinalizeSystem ();
  334. ////////////////////////////////////////////////////////////////////////////////
  335. bool UpdateState();
  336. void ReformatURL( CComBSTR& bstrURL );
  337. void SetHelpLocation( /*[in]*/ const Taxonomy::Instance& inst );
  338. LPCWSTR HelpLocation ( );
  339. LPCWSTR System ( );
  340. const Taxonomy::Instance& Instance ( );
  341. HRESULT GetCSS( /*[out]*/ CComPtr<IStream>& stream );
  342. };
  343. #endif // !defined(__INCLUDED___HCP___NAMESPACE_H___)