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.

384 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: cbinding.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11-11-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef _CBINDING_HXX_
  18. #define _CBINDING_HXX_
  19. #define FLAG_BTO_STR_LENGTH 6
  20. #define FLAG_BTO_STR_TRUE L"TRUE"
  21. #define FLAG_BTO_STR_FALSE L"FALSE"
  22. #define MAX_DWORD_DIGITS 20
  23. typedef enum
  24. {
  25. OPS_Initialized // operation did not start yet
  26. ,OPS_StartBinding // downloading in progress
  27. ,OPS_GetBindInfo // downloading in progress
  28. ,OPS_Downloading // downloading in progress
  29. ,OPS_ObjectAvailable //
  30. ,OPS_Suspend // operation suspend
  31. ,OPS_Abort // operation abort
  32. ,OPS_Stopped // operation is done - stop was called
  33. ,OPS_Succeeded // operation is done
  34. ,OPS_INetError // operation stopped due wininet error
  35. } OperationState;
  36. class CTransactionMgr;
  37. class CTransPacket;
  38. class CTransaction;
  39. class CTransData;
  40. class CBindCtx;
  41. class CBinding : public IBinding
  42. , public IWinInetHttpInfo
  43. , public IOInetProtocolSink
  44. , public IOInetBindInfo
  45. , public IServiceProvider
  46. {
  47. public:
  48. CBinding(IUnknown *pUnk);
  49. ~CBinding();
  50. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  51. STDMETHOD_(ULONG,AddRef) (void);
  52. STDMETHOD_(ULONG,Release) (void);
  53. // IBinding methods
  54. STDMETHOD(Abort)( void);
  55. STDMETHOD(Suspend)( void);
  56. STDMETHOD(Resume)( void);
  57. STDMETHOD(SetPriority)(LONG nPriority);
  58. STDMETHOD(GetPriority)(LONG *pnPriority);
  59. STDMETHOD(GetBindResult)(CLSID *pclsidProtocol, DWORD *pdwResult, LPWSTR *pszResult,DWORD *pdwReserved);
  60. // IWinInetInfo methods
  61. STDMETHOD(QueryOption)(DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf);
  62. // IWinInetHttpInfo methods
  63. STDMETHOD(QueryInfo)(DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf, DWORD *pdwFlags, DWORD *pdwReserved);
  64. // *** IServiceProvider ***
  65. STDMETHOD (QueryService)(REFGUID rsid, REFIID iid, void ** ppvObj);
  66. //IOInetBindInfo methods
  67. STDMETHODIMP GetBindInfo(
  68. DWORD *grfBINDF,
  69. BINDINFO * pbindinfo);
  70. STDMETHODIMP GetBindString(
  71. ULONG ulStringType,
  72. LPOLESTR *ppwzStr,
  73. ULONG cEl,
  74. ULONG *pcElFetched
  75. );
  76. STDMETHODIMP Switch(
  77. PROTOCOLDATA *pStateInfo);
  78. STDMETHODIMP ReportProgress(
  79. ULONG ulStatusCode,
  80. LPCWSTR szStatusText);
  81. STDMETHODIMP ReportData(
  82. DWORD grfBSCF,
  83. ULONG ulProgress,
  84. ULONG ulProgressMax);
  85. STDMETHODIMP ReportResult(
  86. HRESULT hrResult,
  87. DWORD dwError,
  88. LPCWSTR wzResult);
  89. // private: // methods
  90. static HRESULT Create(IUnknown *pUnkOuter, LPCWSTR szUrl, LPBC pbc,
  91. REFIID riid, BOOL fBindToObject, CBinding **ppCBdg);
  92. STDMETHOD(Initialize)(LPCWSTR pUrl, IBindCtx *pbc, DWORD grfBindF, REFIID riid, BOOL fBindToObject);
  93. LPWSTR GetUrl()
  94. {
  95. return _lpwszUrl;
  96. }
  97. STDMETHOD_(HWND, GetNotificationWnd)()
  98. { return _hwndNotify; }
  99. STDMETHOD_(BOOL, IsAsyncBinding)()
  100. { return (_pBSCB!=NULL); }
  101. HRESULT StartBinding(LPCWSTR szUrl, IBindCtx *pbc, REFIID riid, BOOL fBindToObject, LPWSTR *ppwzExtra, LPVOID *ppv);
  102. STDMETHOD(CompleteTransaction)();
  103. STDMETHOD(GetRequestedObject)(IBindCtx *pbc, IUnknown **ppUnk);
  104. STDMETHODIMP_(BOOL) OnTransNotification(BINDSTATUS NotMsg, DWORD dwCurrrentSize, DWORD dwTotalSize, LPWSTR pwzStr, HRESULT hrINet);
  105. STDMETHOD(OnDataNotification)(DWORD grfBSCF, DWORD dwCurrrentSize, DWORD dwTotalSize, BOOL fLastNotification);
  106. STDMETHOD(OnObjectAvailable) (DWORD grfBSCF, DWORD dwCurrrentSize, DWORD dwTotalSize, BOOL fLastNotification);
  107. STDMETHOD(InstallIEFeature)();
  108. STDMETHOD(InstantiateObject)(CLSID *pclsid, REFIID riidResult, IUnknown **ppUnk, BOOL fFullyAvailable);
  109. STDMETHOD(ObjectPersistMnkLoad)(IUnknown *pUnk, BOOL fLocal, BOOL fFullyAvailable, CLSID *pclsid = NULL);
  110. STDMETHOD(ObjectPersistFileLoad)(IUnknown *pUnk);
  111. STDMETHOD(CreateObject)(CLSID *pclsid, REFIID riidResult, IUnknown **ppUnk);
  112. LPWSTR GetFileName();
  113. BOOL IsAsyncTransaction()
  114. {
  115. return ( IsAsyncBinding()
  116. && (_grfBINDF & BINDF_ASYNCHRONOUS) );
  117. }
  118. BOOL IsSyncTransaction()
  119. {
  120. return !IsAsyncTransaction();
  121. }
  122. IMoniker *GetMoniker()
  123. {
  124. return _pMnk;
  125. }
  126. void SetMoniker(IMoniker *pMnk)
  127. {
  128. if (_pMnk)
  129. {
  130. _pMnk->Release();
  131. }
  132. _pMnk = pMnk;
  133. if (_pMnk)
  134. {
  135. _pMnk->AddRef();
  136. }
  137. }
  138. IOInetProtocol *GetOInetBinding()
  139. {
  140. if (_pOInetBdg)
  141. {
  142. return _pOInetBdg;
  143. }
  144. else
  145. {
  146. return 0;
  147. }
  148. }
  149. REFCLSID GetProtocolClassID()
  150. {
  151. TransAssert((_clsidProtocol != CLSID_NULL ));
  152. return (REFCLSID)_clsidProtocol;
  153. }
  154. OperationState GetOperationState()
  155. { return _OperationState; }
  156. OperationState SetOperationState(OperationState newTS)
  157. {
  158. OperationState tsTemp = _OperationState;
  159. _OperationState = newTS;
  160. return tsTemp;
  161. }
  162. void SetInstantiateHresult(HRESULT hr)
  163. {
  164. _hrInstantiate = hr;
  165. }
  166. HRESULT GetInstantiateHresult()
  167. {
  168. return _hrInstantiate;
  169. }
  170. HRESULT GetHResult()
  171. {
  172. return _hrResult;
  173. }
  174. STDMETHOD(CallOnStartBinding)(DWORD grfBINDINFOF, IBinding * pib);
  175. STDMETHOD(CallGetBindInfo) (DWORD *grfBINDINFOF, BINDINFO *pbindinfo);
  176. STDMETHOD(CallOnProgress) (ULONG ulProgress, ULONG ulProgressMax,
  177. ULONG ulStatusCode, LPCWSTR szStatusText);
  178. STDMETHOD(CallOnStopBinding)(HRESULT hrRet, LPCWSTR szStatusText);
  179. STDMETHOD(CallOnLowResource) (DWORD reserved);
  180. STDMETHOD(CallGetPriority) (LONG * pnPriority);
  181. STDMETHOD(CallOnDataAvailable)(DWORD grfBSC,DWORD dwSize,FORMATETC *pformatetc,STGMEDIUM *pstgmed);
  182. STDMETHOD(CallOnObjectAvailable)(REFIID riid,IUnknown *punk);
  183. STDMETHOD(CallAuthenticate)(HWND* phwnd, LPWSTR *pszUsername,LPWSTR *pszPassword);
  184. STDMETHOD(LocalQueryInterface)(REFIID iid, void **ppvObj);
  185. DWORD GetTransBindFlags()
  186. {
  187. return _grfBINDF;
  188. }
  189. BOOL IsRequestedIIDValid(REFIID riid)
  190. {
  191. if( (riid != IID_IStream)
  192. && (riid != IID_IStorage)
  193. && (riid != IID_IUnknown) )
  194. {
  195. return FALSE;
  196. }
  197. else
  198. {
  199. return TRUE;
  200. }
  201. }
  202. private:
  203. CRefCount _CRefs; // refcount class
  204. DWORD _dwThreadId; // the thread id of this binding
  205. IUnknown *_pUnk; // controlling unknown
  206. IBindStatusCallback *_pBSCB;
  207. IAuthenticate *_pBasicAuth; // Pointer to IAuthenticate holder
  208. IInternetBindInfo *_pBindInfo; //
  209. LONG _nPriority; // priority of this binding
  210. DWORD _dwState; // state of operation
  211. OperationState _OperationState;
  212. HWND _hwndNotify; // Status window
  213. DWORD _grfBINDF; // Bind flags
  214. DWORD _dwLastSize; // Size at last notification
  215. LPWSTR _lpwszUrl; // Url for which download is proceeding
  216. LPWSTR _pwzRedirectUrl; // Url for which download is proceeding
  217. CLSID _clsidIn; // class found be oinet
  218. BOOL _fBindToObject;
  219. BOOL _fSentLastNotification;
  220. BOOL _fSentFirstNotification;
  221. BOOL _fCreateStgMed;
  222. BOOL _fLocal;
  223. BOOL _fCompleteDownloadHere;
  224. BOOL _fForceBindToObjFail;
  225. BOOL _fAcceptRanges;
  226. BOOL _fClsidFromProt;
  227. DWORD _grfInternalFlags;
  228. BIND_OPTS _bindopts;
  229. HRESULT _hrBindResult;
  230. HRESULT _hrInstantiate;
  231. HRESULT _hrResult;
  232. DWORD _dwBindError;
  233. LPWSTR _pwzResult;
  234. LPWSTR _wszDllName;
  235. CTransData *_pCTransData;
  236. IOInetProtocol *_pOInetBdg;
  237. IMoniker *_pMnk;
  238. CBindCtx *_pBndCtx;
  239. IID *_piidRes;
  240. IUnknown *_pUnkObject;
  241. CLSID _clsidProtocol;
  242. BINDINFO _BndInfo;
  243. BOOL _fCanGetIWinInetInfo;
  244. BOOL _fCanGetIWinInetHttpInfo;
  245. BOOL _fBTS_BTO;
  246. };
  247. //
  248. // this flags are used to during BindToObject - BindToStorage scenarios
  249. //
  250. typedef enum
  251. {
  252. BDGFLAGS_ATTACHED = 0x01000000
  253. ,BDGFLAGS_PARTIAL = 0x02000000
  254. ,BDGFLAGS_LOCALSERVER = 0x04000000
  255. ,BDGFLAGS_NOTIFICATIONS = 0x08000000
  256. ,BDGFLAGS_BTS_BTO = 0x10000000
  257. } BINDINGFLAGS;
  258. class CBindProtocol : public IBindProtocol
  259. {
  260. public:
  261. CBindProtocol();
  262. ~CBindProtocol();
  263. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  264. STDMETHOD_(ULONG,AddRef) (void);
  265. STDMETHOD_(ULONG,Release) (void);
  266. STDMETHOD(CreateBinding)(LPCWSTR url, IBindCtx *pBCtx, IBinding **ppBdg);
  267. private:
  268. CRefCount _CRefs; // refcount class
  269. IUnknown *_pUnk; // controlling unknown
  270. };
  271. typedef enum
  272. {
  273. Medium_Stream = 1
  274. ,Medium_Storage = 2
  275. ,Medium_Unknown = 3
  276. } Medium;
  277. class CBSC : public IBindStatusCallback
  278. {
  279. public:
  280. // *** IUnknown methods ***
  281. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj);
  282. STDMETHODIMP_(ULONG) AddRef(void);
  283. STDMETHODIMP_(ULONG) Release(void);
  284. // *** IBindStatusCallback methods ***
  285. STDMETHOD(OnStartBinding) (DWORD grfBINDINFOF, IBinding * pib);
  286. STDMETHOD(OnLowResource) (DWORD reserved);
  287. STDMETHOD(OnProgress) (ULONG ulProgress, ULONG ulProgressMax,
  288. ULONG ulStatusCode, LPCWSTR szStatusText);
  289. STDMETHOD(OnStopBinding) (HRESULT hresult, LPCWSTR szError);
  290. STDMETHOD(GetBindInfo)(DWORD *grfBINDINFOF, BINDINFO *pbindinfo);
  291. STDMETHOD(OnDataAvailable)(DWORD grfBSC,DWORD dwSize,FORMATETC *pformatetc,STGMEDIUM *pstgmed);
  292. STDMETHOD(OnObjectAvailable)(REFIID riid,IUnknown *punk);
  293. STDMETHOD(GetPriority)(LONG * pnPriority);
  294. public:
  295. CBSC(Medium Medium);
  296. CBSC(BOOL fBindToObject);
  297. ~CBSC();
  298. IStream * GetStream()
  299. {
  300. return _pStm;
  301. }
  302. //IStorage * GetStorage();
  303. HRESULT GetRequestedObject(IBindCtx *pbc, void **ppvObj);
  304. private:
  305. UINT _cRef;
  306. IBinding * _pBdg;
  307. BOOL _fBindToObject;
  308. BOOL _fGotStopBinding;
  309. IStream * _pStm;
  310. IStorage * _pStg;
  311. IUnknown * _pUnk;
  312. Medium _Medium;
  313. HRESULT _hrResult;
  314. WCHAR _wzPath[MAX_PATH];
  315. };
  316. HRESULT GetObjectParam(IBindCtx *pbc, LPOLESTR pszKey, REFIID riid, IUnknown **ppUnk);
  317. HRESULT CreateURLBinding(LPWSTR lpszUrl, IBindCtx *pbc, IBinding **ppBdg);
  318. BOOL IsKnownBindProtocolOld(LPCWSTR lpszProto);
  319. DWORD IsKnownProtocol(LPCWSTR wzProtocol);
  320. #endif //_CBINDING_HXX_