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.

1297 lines
35 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: CNet.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-04-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef _CNET_HXX_
  18. #define _CNET_HXX_
  19. #include <wininet.h>
  20. const ULONG SENDBUFFER_MAX = 8192;
  21. const ULONG MAX_ACP_ENCHEADERS_SIZE=128;
  22. #ifdef unix
  23. #undef offsetof
  24. #endif /* unix */
  25. #define offsetof(s,m) ( (SIZE_T) &(((s *)0)->m) )
  26. //+----------------------------------------------------------------------------
  27. //
  28. // Macro:
  29. // GETPPARENT
  30. //
  31. // Synopsis:
  32. // Given a pointer to something contained by a struct (or
  33. // class,) the type name of the containing struct (or class),
  34. // and the name of the member being pointed to, return a pointer
  35. // to the container.
  36. //
  37. // Arguments:
  38. // [pmemb] -- pointer to member of struct (or class.)
  39. // [struc] -- type name of containing struct (or class.)
  40. // [membname] - name of member within the struct (or class.)
  41. //
  42. // Returns:
  43. // pointer to containing struct (or class)
  44. //
  45. // Notes:
  46. // Assumes all pointers are FAR.
  47. //
  48. // History:
  49. //
  50. //-----------------------------------------------------------------------------
  51. #define GETPPARENT(pmemb, struc, membname) (\
  52. (struc*)(((char*)(pmemb))-offsetof(struc, membname)))
  53. #define INET_E_OK NOERROR
  54. #define INET_E_DONE _HRESULT_TYPEDEF_(0x800A0001L)
  55. #define AUTHENTICATE_MAX 3 // number of authentication retries
  56. typedef enum
  57. {
  58. INetState_None = 0
  59. ,INetState_START = 1
  60. ,INetState_OPEN_REQUEST
  61. ,INetState_CONNECT_REQUEST
  62. ,INetState_PROTOPEN_REQUEST
  63. ,INetState_SEND_REQUEST
  64. ,INetState_AUTHENTICATE
  65. ,INetState_DISPLAY_UI
  66. ,INetState_READ
  67. ,INetState_DATA_AVAILABLE
  68. ,INetState_READ_DIRECT
  69. ,INetState_DATA_AVAILABLE_DIRECT
  70. ,INetState_INETSTATE_CHANGE
  71. ,INetState_DONE
  72. ,INetState_ABORT
  73. ,INetState_ERROR
  74. } INetState;
  75. typedef enum
  76. {
  77. HandleState_None = 0
  78. ,HandleState_Pending = 1
  79. ,HandleState_Initialized
  80. ,HandleState_Aborted
  81. ,HandleState_Closed
  82. } HandleState;
  83. class CUrl;
  84. class CAuthData;
  85. class CINet;
  86. class CINetEmbdFilter;
  87. class CINetProtImpl;
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Class: CINet ()
  91. //
  92. // Purpose: class to interact with WinINet
  93. //
  94. // Interface: dwFlags --
  95. // hThread --
  96. // dwThreadID --
  97. // state --
  98. // uError --
  99. // ipPort --
  100. // postData --
  101. // dwProto --
  102. // _hServer --
  103. // _hRequest --
  104. // _dwIsA --
  105. // _cbDataSize --
  106. // _cbTotalBytesRead --
  107. // _cbReadReturn --
  108. // _pCTransData --
  109. // _pCTrans --
  110. // _hrINet --
  111. // _dwState --
  112. // _hr --
  113. // INetAsyncStart --
  114. // OnINetStart --
  115. // INetAsyncOpen --
  116. // OnINetAsyncOpen --
  117. // OnINetOpen --
  118. // INetAsyncConnect --
  119. // OnINetConnect --
  120. // INetAsyncOpenRequest --
  121. // OnINetOpenRequest --
  122. // INetAsyncSendRequest --
  123. // OnINetSendRequest --
  124. // INetQueryInfo --
  125. // OnINetRead --
  126. // INetRead --
  127. // GetTransBindInfo --
  128. // CINetCallback --
  129. // TransitState --
  130. // OnINetInternal --
  131. // OnINetError --
  132. // ReportResultAndStop --
  133. // TerminateRequest --
  134. // FindTagInHeader --
  135. // ReportNotification --
  136. // szBaseURL --
  137. // szBaseURL --
  138. // OperationOnAparmentThread --
  139. // QueryInfoOnResponse --
  140. // CINet --
  141. // _dwIsA --
  142. // ~CINet --
  143. // QueryStatusOnResponse --
  144. // QueryHeaderOnResponse --
  145. // RedirectRequest --
  146. // AuthenticationRequest --
  147. //
  148. // History: 2-10-96 JohannP (Johann Posch) Created
  149. //
  150. // Notes:
  151. //
  152. //----------------------------------------------------------------------------
  153. class CINet : public IOInetProtocol, public IWinInetHttpInfo, public IOInetThreadSwitch, public IOInetPriority, public CUrl
  154. {
  155. public:
  156. // IUnknown methods
  157. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj);
  158. STDMETHODIMP_(ULONG) AddRef(void);
  159. STDMETHODIMP_(ULONG) Release(void);
  160. STDMETHODIMP Start(
  161. LPCWSTR szUrl,
  162. IOInetProtocolSink *pProtSink,
  163. IOInetBindInfo *pOIBindInfo,
  164. DWORD grfSTI,
  165. DWORD_PTR dwReserved
  166. );
  167. STDMETHODIMP Continue(
  168. PROTOCOLDATA *pStateInfo
  169. );
  170. STDMETHODIMP Abort(
  171. HRESULT hrReason,
  172. DWORD dwOptions
  173. );
  174. STDMETHODIMP Terminate(
  175. DWORD dwOptions
  176. );
  177. STDMETHODIMP Suspend();
  178. STDMETHODIMP Resume();
  179. STDMETHODIMP SetPriority(LONG nPriority);
  180. STDMETHODIMP GetPriority(LONG * pnPriority);
  181. virtual STDMETHODIMP Read(
  182. void *pv,
  183. ULONG cb,
  184. ULONG *pcbRead);
  185. STDMETHODIMP Seek(
  186. LARGE_INTEGER dlibMove,
  187. DWORD dwOrigin,
  188. ULARGE_INTEGER *plibNewPosition);
  189. STDMETHODIMP LockRequest(
  190. DWORD dwOptions);
  191. STDMETHODIMP UnlockRequest();
  192. // IWinInetInfo
  193. STDMETHODIMP QueryOption(DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf);
  194. // IWinInetHttpInfo
  195. STDMETHODIMP QueryInfo(DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf, DWORD *pdwFlags, DWORD *pdwReserved);
  196. // IOInetThreadSwitch
  197. STDMETHODIMP Prepare();
  198. STDMETHODIMP Continue();
  199. static DWORD CALLBACK InternetAuthNotifyCallback(
  200. DWORD_PTR dwContext, // the this pointer
  201. DWORD dwAction, // action to be taken
  202. LPVOID lpReserved); // unused
  203. // My Interface
  204. STDMETHODIMP MyContinue(
  205. PROTOCOLDATA *pStateInfo
  206. );
  207. STDMETHODIMP MyAbort(
  208. HRESULT hrReason,
  209. DWORD dwOptions
  210. );
  211. STDMETHODIMP MyTerminate(
  212. DWORD dwOptions
  213. );
  214. STDMETHODIMP MySuspend();
  215. STDMETHODIMP MyResume();
  216. STDMETHODIMP MySetPriority(LONG nPriority);
  217. STDMETHODIMP MyGetPriority(LONG * pnPriority);
  218. virtual STDMETHODIMP MyRead(
  219. void *pv,
  220. ULONG cb,
  221. ULONG *pcbRead);
  222. STDMETHODIMP MySeek(
  223. LARGE_INTEGER dlibMove,
  224. DWORD dwOrigin,
  225. ULARGE_INTEGER *plibNewPosition);
  226. STDMETHODIMP MyLockRequest(
  227. DWORD dwOptions);
  228. STDMETHODIMP MyUnlockRequest();
  229. // Helper function for _pEmbdFilter sanity check:
  230. bool IsEmbdFilterOk();
  231. public: //CINet data
  232. //private:
  233. //protected:
  234. DWORD _dwFlags;
  235. DWORD _dwThreadID;
  236. HRESULT _hrError; // error code
  237. INetState _INState;
  238. LPWSTR _pwzUrl;
  239. LPSTR _pszUserAgentStr;
  240. // wininet handles
  241. HINTERNET _hServer;
  242. HINTERNET _hRequest;
  243. DWORD _dwIsA;
  244. ULONG _cbDataSize;
  245. ULONG _cbTotalBytesRead;
  246. ULONG _cbReadReturn;
  247. ULONG _cbReadyToRead;
  248. ULONG _cbRedirect;
  249. ULONG _cbAuthenticate;
  250. ULONG _cbProxyAuthenticate;
  251. ULONG _cbSizeLastReportData;
  252. DWORD _bscf;
  253. BOOL _fProxyAuth;
  254. IOInetProtocolSink *_pCTrans;
  255. IOInetBindInfo *_pOIBindInfo;
  256. IServiceProvider *_pServiceProvider;
  257. IWindowForBindingUI *_pWindow; // Pointer to IWindowForBindingUI
  258. // Filter Handler, can handle cascade filters
  259. CINetEmbdFilter* _pEmbdFilter;
  260. DWORD _dwEmbdFilter;
  261. HRESULT _hrINet;
  262. INetState _dwState;
  263. HRESULT _hrPending;
  264. CRefCount _cReadCount;
  265. CMutexSem _mxs;
  266. DWORD _dwCacheFlags;
  267. DWORD _dwConnectFlags;
  268. DWORD _dwOpenFlags;
  269. DWORD _dwSendRequestResult;
  270. LPVOID _lpvExtraSendRequestResult;
  271. BOOL _fRedirected;
  272. BOOL _fP2PRedirected;
  273. BOOL _fLocked;
  274. BOOL _fDoSimpleRetry;
  275. BOOL _fCompleted;
  276. BOOL _fSendAgain;
  277. BOOL _fSendRequestAgain;
  278. BOOL _fForceSwitch;
  279. BOOL _fFilenameReported;
  280. BOOL _fHandlesRecycled;
  281. HANDLE _hFile;
  282. HANDLE _hLockHandle;
  283. REFCLSID _pclsidProtocol;
  284. DWORD _dwResult;
  285. LPSTR _pszResult;
  286. HandleState _HandleStateServer;
  287. HandleState _HandleStateRequest;
  288. CAuthData *_pCAuthData;
  289. HWND _hwndAuth;
  290. //new
  291. DWORD _grfBindF;
  292. BINDINFO _BndInfo;
  293. LONG _nPriority;
  294. // read direct stuff
  295. INTERNET_BUFFERS _inetBufferSend;
  296. INTERNET_BUFFERS _inetBufferReceived;
  297. private:
  298. CRefCount _CRefs; // the total refcount of this object
  299. CRefCount _CRefsHandles; // the number of handles in use by this object
  300. union
  301. {
  302. ULONG _flags;
  303. #ifndef unix
  304. struct
  305. {
  306. #endif /* unix */
  307. unsigned _fAborted : 1;
  308. unsigned _fDone : 1;
  309. #ifndef unix
  310. };
  311. #endif /* unix */
  312. };
  313. public:
  314. class CPrivUnknown : public IUnknown
  315. {
  316. public:
  317. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  318. STDMETHOD_(ULONG,AddRef) (void);
  319. STDMETHOD_(ULONG,Release) (void);
  320. ~CPrivUnknown() {}
  321. CPrivUnknown() : _CRefs() {}
  322. private:
  323. CRefCount _CRefs; // the total refcount of this object
  324. };
  325. friend class CPrivUnknown;
  326. CPrivUnknown _Unknown;
  327. IUnknown *_pUnkOuter;
  328. BYTE* _pbRootSecurityId;
  329. DWORD _cbRootSecurityId;
  330. public:
  331. CINet(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  332. virtual ~CINet();
  333. IUnknown *GetIUnkInner(BOOL fReleaseOuter = FALSE)
  334. {
  335. if (fReleaseOuter)
  336. {
  337. PProtAssert((_CRefs > 0));
  338. _CRefs--;
  339. }
  340. return &_Unknown;
  341. }
  342. protected:
  343. HRESULT INetAsyncStart();
  344. HRESULT OnINetStart();
  345. HRESULT CINet::OnCookieNotification(DWORD dwStatus, LPVOID pvInfo);
  346. virtual HRESULT INetAsyncOpen();
  347. HRESULT OnINetAsyncOpen(DWORD_PTR dwResult);
  348. HRESULT OnINetOpen(DWORD dwResult);
  349. virtual HRESULT INetAsyncConnect();
  350. HRESULT OnINetConnect(DWORD_PTR dwResult);
  351. virtual HRESULT INetAsyncOpenRequest();
  352. HRESULT OnINetOpenRequest(DWORD_PTR dwResult);
  353. virtual HRESULT INetAsyncSendRequest();
  354. HRESULT OnINetSendRequest( DWORD dwResult);
  355. HRESULT OnINetSuspendSendRequest( DWORD dwResult, LPVOID lpvExtraResult);
  356. HRESULT INetResumeAsyncRequest(DWORD dwResultCode);
  357. virtual HRESULT INetStateChange();
  358. HRESULT OnINetStateChange(DWORD dwResult);
  359. HRESULT INetQueryInfo();
  360. HRESULT INetAuthenticate();
  361. HRESULT OnINetAuthenticate(DWORD dwResult);
  362. HRESULT INetDisplayUI();
  363. HRESULT OnINetRead(DWORD_PTR dwResult);
  364. HRESULT INetRead();
  365. virtual HRESULT INetWrite();
  366. HRESULT INetDataAvailable();
  367. HRESULT OnINetDataAvailable( DWORD dwResult);
  368. HRESULT INetReportAvailableData();
  369. HRESULT OnINetReadDirect(DWORD dwResult);
  370. HRESULT INetReadDirect();
  371. HRESULT ReadDirect(BYTE *pBuffer, DWORD cbBytes, DWORD *pcbBytes);
  372. HRESULT GetBindResult(CLSID *pclsidProtocol, DWORD *pdwResult, LPWSTR *pszResult,DWORD *pdwReserved);
  373. virtual HRESULT SetBindResult(DWORD dwResult, HRESULT hrSuggested = NOERROR);
  374. void SetCNetBindResult(DWORD dwResult, LPSTR szResult = NULL)
  375. {
  376. _dwResult = dwResult;
  377. PProtAssert((_pszResult == NULL));
  378. _pszResult = szResult;
  379. }
  380. BOOL IsApartmentThread()
  381. {
  382. PProtAssert((_dwThreadID != 0));
  383. return (_dwThreadID == GetCurrentThreadId());
  384. }
  385. void TransitState(DWORD dwState, BOOL fAsync = FALSE);
  386. void OnINetInternal(DWORD_PTR dwState);
  387. HRESULT ReportResultAndStop(HRESULT hr,ULONG ulProgress = 0, ULONG ulProgressMax = 0,LPWSTR pwzStr = 0);
  388. HRESULT ReportNotification(BINDSTATUS NMsg, LPCSTR szStr = NULL);
  389. HRESULT ReportNotificationW(BINDSTATUS NMsg, LPCWSTR wzStr = NULL);
  390. void TerminateRequest();
  391. virtual HRESULT LockFile(BOOL fRetrieve = FALSE);
  392. virtual HRESULT UnlockFile();
  393. virtual HRESULT INetSeek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition);
  394. HRESULT SetStatePending(HRESULT hrNew);
  395. HRESULT GetStatePending();
  396. REFCLSID GetProtocolClassID()
  397. {
  398. return _pclsidProtocol;
  399. }
  400. static VOID CALLBACK CINetCallback(
  401. IN HINTERNET hInternet, //
  402. IN DWORD_PTR dwContext, // could be LPDLD
  403. IN DWORD dwInternetStatus,
  404. IN LPVOID lpvStatusInformation,
  405. IN DWORD dwStatusInformationLength);
  406. LPSTR FindTagInHeader(LPCSTR lpBuffer, LPCSTR lpszTag);
  407. HRESULT ReadDataHere(BYTE *pBuffer, DWORD cbBytes, DWORD *pcbBytes);
  408. HRESULT GetUrlCacheFilename(LPSTR szFilename, DWORD dwSize);
  409. BOOL OperationOnAparmentThread(DWORD dwState);
  410. HRESULT QueryInfoOnResponse();
  411. HRESULT OnRedirect(LPSTR szNewUrl);
  412. HRESULT HResultFromInternetError(DWORD dwStatus);
  413. INetState SetINetState(INetState inState);
  414. INetState GetINetState();
  415. void SetByteCountReadyToRead(LONG cbReadyReadNow);
  416. ULONG GetByteCountReadyToRead();
  417. BOOL UTF8Enabled();
  418. BOOL IsThirdPartyUrl(LPCWSTR pwszUrl);
  419. BOOL IsThirdPartyUrl(LPCSTR pszUrl);
  420. // If this was not public we get an error from
  421. // cnet.cxx line that:
  422. // cnet.cxx", line 238: static CINet::operator delete(void*, unsigned) is not accessible from CreateKnownProtocolInstance(unsigned long, const _GUID&, IUnknown*, const _GUID&, IUnknown**).
  423. public:
  424. void operator delete( void *pBuffer, size_t size)
  425. {
  426. memset(pBuffer,0, size);
  427. ::delete pBuffer;
  428. }
  429. protected:
  430. DWORD IsA() { return _dwIsA; };
  431. virtual HRESULT QueryStatusOnResponse();
  432. virtual HRESULT QueryStatusOnResponseDefault(DWORD dwStat);
  433. virtual HRESULT QueryHeaderOnResponse();
  434. virtual HRESULT RedirectRequest(LPSTR lpszBuffer, DWORD *pdwBuffSize, DWORD dwStatus);
  435. virtual HRESULT AuthenticationRequest();
  436. //NEW
  437. DWORD GetBindFlags()
  438. {
  439. return _grfBindF;
  440. }
  441. BINDINFO *GetBindInfo()
  442. {
  443. return &_BndInfo;
  444. }
  445. LPWSTR GetUrl()
  446. {
  447. return _pwzUrl;
  448. }
  449. LPSTR GetUserAgentString();
  450. BOOL IsUpLoad();
  451. HRESULT QueryService(REFIID riid, void ** ppvObj)
  452. {
  453. HRESULT hr = E_NOINTERFACE;
  454. if (!_pServiceProvider)
  455. {
  456. hr = _pCTrans->QueryInterface(IID_IServiceProvider, (void **)&_pServiceProvider);
  457. }
  458. if (_pServiceProvider)
  459. {
  460. hr = _pServiceProvider->QueryService(riid, riid, ppvObj);
  461. }
  462. return hr;
  463. }
  464. STDMETHODIMP_(ULONG) PrivAddRef(BOOL fAddRefHandle = FALSE)
  465. {
  466. if (fAddRefHandle)
  467. {
  468. _CRefsHandles++;
  469. }
  470. return _Unknown.AddRef();
  471. }
  472. STDMETHODIMP_(ULONG) PrivRelease(BOOL fReleaseHandle = FALSE)
  473. {
  474. if (fReleaseHandle)
  475. {
  476. _CRefsHandles--;
  477. }
  478. return _Unknown.Release();
  479. }
  480. void ReleaseTransAndBindInfo();
  481. };
  482. class CAuthData : public INTERNET_AUTH_NOTIFY_DATA
  483. {
  484. public:
  485. CAuthData(CINet *pCINet)
  486. {
  487. PProtAssert((pCINet));
  488. cbStruct = sizeof(INTERNET_AUTH_NOTIFY_DATA);
  489. dwOptions = 0;
  490. pfnNotify = &CINet::InternetAuthNotifyCallback;
  491. dwContext = (DWORD_PTR) pCINet;
  492. pCINet->AddRef();
  493. }
  494. ~CAuthData()
  495. {
  496. PProtAssert((dwContext));
  497. ((CINet *)dwContext)->Release();
  498. }
  499. friend CINet;
  500. };
  501. class CStateInfo : public PROTOCOLDATA
  502. {
  503. public:
  504. CStateInfo(DWORD dwSt, DWORD dwFl, LPVOID pD = NULL, DWORD cb = 0)
  505. {
  506. grfFlags = dwFl;
  507. dwState = dwSt;
  508. pData = pD;
  509. cbData = cb;
  510. }
  511. ~CStateInfo()
  512. {
  513. if (pData && cbData)
  514. {
  515. delete pData;
  516. }
  517. }
  518. private:
  519. };
  520. //+---------------------------------------------------------------------------
  521. //
  522. // Class: CINetFile ()
  523. //
  524. // Purpose: Simple file protocol
  525. //
  526. // Interface: CINetFile --
  527. // ~CINetFile --
  528. // INetAsyncOpen --
  529. //
  530. // History: 2-10-96 JohannP (Johann Posch) Created
  531. //
  532. // Notes:
  533. //
  534. //----------------------------------------------------------------------------
  535. class CINetFile : public CINet
  536. {
  537. public:
  538. CINetFile(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  539. virtual ~CINetFile();
  540. virtual HRESULT INetAsyncOpen();
  541. virtual HRESULT LockFile(BOOL fRetrieve = FALSE);
  542. virtual HRESULT UnlockFile();
  543. virtual STDMETHODIMP Read(void *pBuffer, DWORD cbBytes, DWORD *pcbBytes);
  544. private:
  545. LPWSTR GetObjectNameW()
  546. {
  547. if( _wzFileName[0] == '\0' )
  548. {
  549. DWORD dwLen = MAX_PATH;
  550. PathCreateFromUrlW(_pwzUrl, _wzFileName, &dwLen, 0);
  551. }
  552. return _wzFileName;
  553. }
  554. HANDLE _hFile; // handle to open file for locking the file
  555. WCHAR _wzFileName[MAX_PATH];
  556. };
  557. //+---------------------------------------------------------------------------
  558. //
  559. // Class: CINetHttp ()
  560. //
  561. // Purpose: Http protocoll class
  562. //
  563. // Interface: INetAsyncOpenRequest --
  564. // INetAsyncSendRequest --
  565. // QueryStatusOnResponse --
  566. // QueryHeaderOnResponse --
  567. // RedirectRequest --
  568. // GetVerb --
  569. // GetDataToSend --
  570. // GetAdditionalHeader --
  571. // CallHttpNegBeginningTransaction --
  572. // CallHttpNegOnResponse --
  573. // CINetHttp --
  574. // ~CINetHttp --
  575. // _pszHeader --
  576. // _pHttpNeg --
  577. //
  578. // History: 2-10-96 JohannP (Johann Posch) Created
  579. //
  580. // Notes:
  581. //
  582. //----------------------------------------------------------------------------
  583. class CINetHttp : public CINet
  584. {
  585. public:
  586. STDMETHODIMP Terminate(DWORD dwOptions);
  587. virtual HRESULT INetAsyncOpenRequest();
  588. virtual HRESULT INetAsyncSendRequest();
  589. virtual HRESULT QueryStatusOnResponse();
  590. virtual HRESULT QueryStatusOnResponseDefault(DWORD dwStat);
  591. virtual HRESULT QueryHeaderOnResponse();
  592. virtual HRESULT RedirectRequest(LPSTR lpszBuffer, DWORD *pdwBuffSize, DWORD dwStatus);
  593. LPSTR GetVerb();
  594. HRESULT GetDataToSend(LPVOID *ppBuffer, DWORD *pdwSize);
  595. HRESULT GetAdditionalHeader();
  596. HRESULT ErrorHandlingRequest(DWORD dwstatus, LPSTR szBuffer);
  597. HRESULT HResultFromHttpStatus(DWORD dwStatus);
  598. HRESULT HttpSecurity(DWORD dwProblem);
  599. HRESULT HttpNegBeginningTransaction();
  600. HRESULT HttpNegOnHeadersAvailable(DWORD dwResponseCode, LPSTR szHeaders);
  601. HRESULT HttpNegOnError(DWORD dwResponseCode, LPSTR szResponseHeaders);
  602. HRESULT HttpSecurityProblem(HWND* phwnd, DWORD dwProblem);
  603. HRESULT ZonesSecurityCheck(HWND hWnd, DWORD dwProblem, DWORD *pdwError);
  604. HRESULT HttpNegGetRootSecurityId();
  605. // new definitions for file upload
  606. HRESULT INetAsyncSendRequestEx();
  607. virtual HRESULT INetWrite();
  608. HRESULT GetNextSendBuffer(INTERNET_BUFFERS *pIB, IStream *pStm, BOOL fFirst = FALSE);
  609. CINetHttp(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  610. virtual ~CINetHttp();
  611. private:
  612. LPSTR _pszHeader;
  613. LPSTR _pszSendHeader;
  614. LPSTR _pwzAddHeader;
  615. IHttpNegotiate *_pHttpNeg; // point to HttpNeg holder
  616. IHttpSecurity *_pHttSecurity; // Pointer to
  617. // file upload stuff
  618. char *_pBuffer; //[SENDBUFFER_MAX];
  619. DWORD _dwBufferSize;
  620. DWORD _dwBytesSent;
  621. IStream *_pStm; // the stream we read from
  622. LPSTR _pszVerb;
  623. DWORD _dwSendTotalSize;
  624. BOOL _fSendEnd : 1;
  625. BOOL _f2ndCacheKeySet;
  626. IHttpNegotiate2 *_pHttpNeg2; // for GetRootSecurityId ( for cookies fix. )
  627. };
  628. //+---------------------------------------------------------------------------
  629. //
  630. // Class: CINetHttpS ()
  631. //
  632. // Purpose:
  633. //
  634. // Interface: CINetHttpS --
  635. // ~CINetHttpS --
  636. //
  637. // History: 2-10-96 JohannP (Johann Posch) Created
  638. //
  639. // Notes:
  640. //
  641. //----------------------------------------------------------------------------
  642. class CINetHttpS : public CINetHttp
  643. {
  644. public:
  645. // constructor does some special initialization
  646. CINetHttpS(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  647. virtual ~CINetHttpS();
  648. private:
  649. };
  650. //+---------------------------------------------------------------------------
  651. //
  652. // Class: CINetSimple ()
  653. //
  654. // Purpose: Class for simple protocolls such as ftp and gopher
  655. //
  656. // Interface: INetAsyncOpenRequest --
  657. // INetAsyncSendRequest --
  658. // INetAsyncConnect --
  659. // CINetSimple --
  660. // ~CINetSimple --
  661. //
  662. // History: 2-10-96 JohannP (Johann Posch) Created
  663. //
  664. // Notes:
  665. //
  666. //----------------------------------------------------------------------------
  667. class CINetSimple : public CINet
  668. {
  669. public:
  670. // CINetSimple implements the following methods
  671. virtual HRESULT INetAsyncOpenRequest();
  672. virtual HRESULT INetAsyncSendRequest();
  673. virtual HRESULT INetAsyncConnect();
  674. virtual HRESULT QueryStatusOnResponse();
  675. virtual HRESULT QueryStatusOnResponseDefault(DWORD dwStat);
  676. virtual HRESULT QueryHeaderOnResponse();
  677. CINetSimple(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  678. virtual ~CINetSimple();
  679. private:
  680. };
  681. //+---------------------------------------------------------------------------
  682. //
  683. // Class: CINetFtp ()
  684. //
  685. // Purpose: class for ftp
  686. //
  687. // Interface: CINetFtp -- does all special ftp intialization
  688. // ~CINetFtp --
  689. //
  690. // History: 2-10-96 JohannP (Johann Posch) Created
  691. //
  692. // Notes:
  693. //
  694. //----------------------------------------------------------------------------
  695. class CINetFtp : public CINetSimple
  696. {
  697. public:
  698. // constructor does some special initialization
  699. CINetFtp(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  700. HRESULT INetAsyncSendRequest();
  701. virtual ~CINetFtp();
  702. private:
  703. };
  704. //+---------------------------------------------------------------------------
  705. //
  706. // Class: CINetGopher ()
  707. //
  708. // Purpose:
  709. //
  710. // Interface: CINetGopher -- does all gopher special initialization
  711. // ~CINetGopher --
  712. //
  713. // History: 2-10-96 JohannP (Johann Posch) Created
  714. //
  715. // Notes:
  716. //
  717. //----------------------------------------------------------------------------
  718. class CINetGopher : public CINetSimple
  719. {
  720. public:
  721. // constructor does some special initialization
  722. CINetGopher(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  723. virtual ~CINetGopher();
  724. private:
  725. };
  726. class CINetStream : public CINet
  727. {
  728. public:
  729. CINetStream(REFCLSID rclsid, IUnknown *pUnkOuter = 0);
  730. virtual ~CINetStream();
  731. virtual HRESULT INetAsyncOpen();
  732. virtual STDMETHODIMP Read(void *pBuffer, DWORD cbBytes, DWORD *pcbBytes);
  733. virtual HRESULT INetSeek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition);
  734. virtual HRESULT LockFile(BOOL fRetrieve = FALSE);
  735. virtual HRESULT UnlockFile();
  736. private:
  737. IStream *_pstm;
  738. };
  739. //+---------------------------------------------------------------------------
  740. //
  741. // Class: CINetProtImpl()
  742. //
  743. // Purpose: the implementation of CINet's protocol interface
  744. //
  745. // Interface: supports OINetProtocol methods.
  746. //
  747. // History: 11-17-97 DanpoZ(Danpo Zhang) Created
  748. //
  749. // Notes: 1. this object is ONLY used by CINetEmbdFilter,
  750. // the IUnknown interface thus is not implemented
  751. // when CINetEmbdFilter get destroied, this object
  752. // will be destroied as well.
  753. //
  754. // 2. All the IOInetProtocol methods gets delegated
  755. // to CINet->MyXXXXX() method, where XXXXX are the
  756. // names of the IOInetProtocol method
  757. //
  758. //----------------------------------------------------------------------------
  759. class CINetProtImpl : public IInternetProtocol
  760. {
  761. public:
  762. // IUnknown methods
  763. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj)
  764. {
  765. return _pCINet->QueryInterface(iid, ppvObj);
  766. }
  767. STDMETHODIMP_(ULONG) AddRef(void)
  768. {
  769. return 1;
  770. }
  771. STDMETHODIMP_(ULONG) Release(void)
  772. {
  773. return 1;
  774. }
  775. STDMETHODIMP Start( LPCWSTR, IOInetProtocolSink*, IOInetBindInfo*,
  776. DWORD, DWORD_PTR )
  777. {
  778. return NOERROR;
  779. }
  780. STDMETHODIMP Continue(PROTOCOLDATA *pStateInfo)
  781. {
  782. return _pCINet->MyContinue(pStateInfo);
  783. }
  784. STDMETHODIMP Abort(HRESULT hrReason,DWORD dwOptions)
  785. {
  786. return _pCINet->MyAbort(hrReason, dwOptions);
  787. }
  788. STDMETHODIMP Terminate(DWORD dwOptions)
  789. {
  790. return _pCINet->MyTerminate(dwOptions);
  791. }
  792. STDMETHODIMP Suspend()
  793. {
  794. return _pCINet->MySuspend();
  795. }
  796. STDMETHODIMP Resume()
  797. {
  798. return _pCINet->MyResume();
  799. }
  800. STDMETHODIMP Read(void *pv,ULONG cb,ULONG *pcbRead)
  801. {
  802. return _pCINet->MyRead(pv, cb, pcbRead);
  803. }
  804. STDMETHODIMP Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,
  805. ULARGE_INTEGER *plibNewPosition)
  806. {
  807. return _pCINet->MySeek(dlibMove, dwOrigin, plibNewPosition);
  808. }
  809. STDMETHODIMP LockRequest(DWORD dwOptions)
  810. {
  811. return _pCINet->MyLockRequest(dwOptions);
  812. }
  813. STDMETHODIMP UnlockRequest()
  814. {
  815. return _pCINet->MyUnlockRequest();
  816. }
  817. CINetProtImpl(CINet* pCINet)
  818. {
  819. _pCINet = pCINet;
  820. }
  821. virtual ~CINetProtImpl()
  822. {
  823. }
  824. void Destroy()
  825. {
  826. delete this;
  827. }
  828. friend class CINetEmbdFilter;
  829. private:
  830. CINet* _pCINet; // Filters' Imp
  831. };
  832. //+---------------------------------------------------------------------------
  833. //
  834. // Class: CINetEmbdFilter()
  835. //
  836. // Purpose: Default protocol filter for CINet, all the filter
  837. // stacking and chaining are implemented thorugh this
  838. // object
  839. //
  840. // Interface: supports OINetProtocol and OINetProtocolSink methods.
  841. // However, this is not a COM object
  842. //
  843. // History: 11-17-97 DanpoZ(Danpo Zhang) Created
  844. //
  845. // Notes:
  846. //
  847. //----------------------------------------------------------------------------
  848. class CINetEmbdFilter
  849. {
  850. public:
  851. CINetEmbdFilter(CINet* pCINet, IOInetProtocolSink* pSnk)
  852. {
  853. // Construct is called via CINet::Start()
  854. _pProtSink = pSnk;
  855. // Get Prot, only CINet can generate that
  856. _pProt = new CINetProtImpl(pCINet);
  857. if(!_pProt)
  858. {
  859. _bInited = FALSE;
  860. return;
  861. }
  862. _pProtSink->AddRef();
  863. _pProtImp = NULL;
  864. _pProtSinkOrig = NULL;
  865. // number of filter stacked
  866. _cbStacked = 0;
  867. _bInited = TRUE;
  868. }
  869. virtual ~CINetEmbdFilter()
  870. {
  871. //
  872. // dtor is called via CINet::~CINet()
  873. // _pProtSink is released on Terminate, otherwise, CTrans
  874. // won't be destroyed, thus CINet never get destory
  875. // ole style destroy, since delete _pProt won't fire
  876. // CINetProtImpl's dtor
  877. //
  878. if(_pProt)
  879. {
  880. ((CINetProtImpl*)_pProt)->Destroy();
  881. }
  882. _pProt = NULL;
  883. _pProtSink = NULL;
  884. }
  885. BOOL IsInited()
  886. {
  887. return _bInited;
  888. }
  889. STDMETHODIMP Continue(PROTOCOLDATA *pStateInfo)
  890. {
  891. return _pProt->Continue(pStateInfo);
  892. }
  893. STDMETHODIMP Abort(HRESULT hrReason,DWORD dwOptions)
  894. {
  895. return _pProt->Abort(hrReason, dwOptions);
  896. }
  897. STDMETHODIMP Terminate(DWORD dwOptions)
  898. {
  899. HRESULT hr = NOERROR;
  900. hr = _pProt->Terminate(dwOptions);
  901. // unload all the filters
  902. _pProt->Release();
  903. _pProtSink->Release();
  904. // all filters are gone now
  905. // reconnect Imp for the last call (usually UnlockRequest)
  906. if( _pProtImp )
  907. {
  908. _pProt = _pProtImp;
  909. }
  910. // we need to release this original pointer (CTrans)
  911. if( _pProtSinkOrig )
  912. {
  913. _pProtSink = _pProtSinkOrig;
  914. _pProtSinkOrig->Release();
  915. }
  916. return hr;
  917. }
  918. STDMETHODIMP Suspend()
  919. {
  920. return _pProt->Suspend();
  921. }
  922. STDMETHODIMP Resume()
  923. {
  924. return _pProt->Resume();
  925. }
  926. STDMETHODIMP Read(void *pv,ULONG cb,ULONG *pcbRead)
  927. {
  928. return _pProt->Read(pv, cb, pcbRead);
  929. }
  930. STDMETHODIMP Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,
  931. ULARGE_INTEGER *plibNewPosition)
  932. {
  933. return _pProt->Seek(dlibMove, dwOrigin, plibNewPosition);
  934. }
  935. STDMETHODIMP LockRequest(DWORD dwOptions)
  936. {
  937. return _pProt->LockRequest(dwOptions);
  938. }
  939. STDMETHODIMP UnlockRequest()
  940. {
  941. return _pProt->UnlockRequest();
  942. }
  943. //
  944. // IOInetProtocolSink methods
  945. STDMETHODIMP Switch(PROTOCOLDATA *pStateInfo)
  946. {
  947. return _pProtSink->Switch(pStateInfo);
  948. }
  949. STDMETHODIMP ReportProgress(ULONG ulStatusCode, LPCWSTR szStatusText)
  950. {
  951. return _pProtSink->ReportProgress(ulStatusCode, szStatusText);
  952. }
  953. STDMETHODIMP ReportData( DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
  954. {
  955. return _pProtSink->ReportData(grfBSCF, ulProgress, ulProgressMax);
  956. }
  957. STDMETHODIMP ReportResult(HRESULT hrResult, DWORD dwError, LPCWSTR wzResult)
  958. {
  959. return _pProtSink->ReportResult(hrResult, dwError, wzResult);
  960. }
  961. // Plug in filters
  962. // BUG, only support 1, pProt is OK, the logic for pSink needs some
  963. // work so that it can be STACKED...
  964. //
  965. STDMETHODIMP StackFilter(
  966. LPCWSTR pwzUrl,
  967. IOInetProtocol* pProt,
  968. IOInetProtocolSink* pProtSink,
  969. IOInetBindInfo* pBindInfo )
  970. {
  971. HRESULT hr = E_FAIL;
  972. // keep the original prot and sink
  973. if( !_pProtImp )
  974. {
  975. //
  976. // _pProtImp should always be the last pProt on the Prot Chain
  977. // we only need to change once
  978. // no matter how many times ::StackFilter() gets called.
  979. //
  980. _pProtImp = _pProt;
  981. }
  982. // If another filter already stacked, we have to
  983. // move the additional ref count on the protocol
  984. // interface of that filter
  985. if( _pProt != _pProtImp )
  986. {
  987. _pProt->Release();
  988. }
  989. // the new filter is plugged on top of _pProt and
  990. // under _pProtSinkOrig
  991. IOInetProtocol* pProtUnder = _pProt;
  992. _pProt = pProt;
  993. PROTOCOLFILTERDATA FilterData =
  994. {sizeof(PROTOCOLFILTERDATA), 0 ,0, 0,0};
  995. FilterData.pProtocolSink = 0;
  996. FilterData.pProtocol = 0;
  997. FilterData.pUnk = 0;
  998. FilterData.dwFilterFlags = 0;
  999. FilterData.pProtocol = pProtUnder;
  1000. //
  1001. // since we are stacking, so the newly stacked filter should
  1002. // ALWAYS points to _pProtSinkOrig
  1003. //
  1004. hr = _pProt->Start(
  1005. pwzUrl, _pProtSinkOrig, pBindInfo, PI_FILTER_MODE | PI_FORCE_ASYNC,
  1006. (DWORD_PTR) &FilterData );
  1007. _cbStacked++;
  1008. return hr;
  1009. }
  1010. //
  1011. // Before SwitchSink get called, the sink of the top filter
  1012. // is pointing to _pProtSinkOrig
  1013. // After SwitchSink, the sink of the top filter is pointing
  1014. // to the sink we just passed in (which is the sink for the new
  1015. // top level filter)
  1016. //
  1017. STDMETHODIMP SwitchSink(IOInetProtocolSink* pProtSink)
  1018. {
  1019. HRESULT hr = NOERROR;
  1020. if( _pProtSinkOrig )
  1021. {
  1022. // _pProt is pointing to the top level filter
  1023. IOInetProtocolSinkStackable* pSinkStackable = NULL;
  1024. hr = _pProt->QueryInterface(
  1025. IID_IOInetProtocolSinkStackable, (void**)&pSinkStackable);
  1026. if( hr == NOERROR )
  1027. {
  1028. pSinkStackable->SwitchSink(pProtSink);
  1029. pSinkStackable->Release();
  1030. }
  1031. }
  1032. else
  1033. {
  1034. //
  1035. // there is no filter existing at this moment
  1036. // we need toremember the _pProtSinkOrig, which should
  1037. // always be the LAST sink on the chain
  1038. //
  1039. _pProtSinkOrig = _pProtSink;
  1040. //
  1041. // switch the existing sink to the filter's sink
  1042. // the filter's sink will be set via StackFilter
  1043. // method later
  1044. //
  1045. _pProtSink = pProtSink;
  1046. }
  1047. return hr;
  1048. }
  1049. STDMETHODIMP CommitSwitch()
  1050. {
  1051. return NOERROR;
  1052. }
  1053. STDMETHODIMP RollbackSwitch()
  1054. {
  1055. return NOERROR;
  1056. }
  1057. ULONG FilterStacked()
  1058. {
  1059. return _cbStacked;
  1060. }
  1061. private:
  1062. IInternetProtocolSink* _pProtSink; // Filter's sink
  1063. IInternetProtocol* _pProt; // Filter's Prot
  1064. IInternetProtocolSink* _pProtSinkOrig; // Filter's original sink
  1065. IInternetProtocol* _pProtImp; // Filter's original Prot
  1066. ULONG _cbStacked; // number of filter stacked
  1067. BOOL _bInited; // Constructor succeeded
  1068. };
  1069. // global variables
  1070. extern char vszHttp[];
  1071. extern char vszFtp[];
  1072. extern char vszGopher[];
  1073. extern char vszFile[];
  1074. extern char vszLocal[];
  1075. extern char vszHttps[];
  1076. extern char vszLocationTag[];
  1077. extern LPSTR ppszAcceptTypes[];
  1078. extern char vszStream[];
  1079. BOOL AppendToString(LPSTR* pszDest, LPDWORD pcbDest,
  1080. LPDWORD pcbAlloced, LPSTR szSrc, DWORD cbSrc);
  1081. //LPCSTR GetUserAgentString();
  1082. #define HTTP_STATUS_BEGIN HTTP_STATUS_OK
  1083. #define HTTP_STATUS_END HTTP_STATUS_VERSION_NOT_SUP
  1084. #endif // _CNET_HXX_