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.

496 lines
11 KiB

  1. class ICSocket;
  2. //
  3. // class implementations
  4. //
  5. /*++
  6. Class Description:
  7. This class defines the INTERNET_HANDLE_OBJECT.
  8. Private Member functions:
  9. None.
  10. Public Member functions:
  11. --*/
  12. class INTERNET_HANDLE_BASE : public HANDLE_OBJECT {
  13. friend class INTERNET_HANDLE_OBJECT;
  14. private:
  15. //
  16. // Passport Auth package's "Session Handle"
  17. //
  18. PP_CONTEXT _PPContext;
  19. //
  20. // _IsCopy - TRUE if this is part of a derived object handle (e.g. a
  21. // connect handle object)
  22. // BUGBUG - post-beta cleanup - combine into bitfield
  23. //
  24. BOOL _IsCopy;
  25. //
  26. // _UserAgent - name by why which the application wishes to be known to
  27. // HTTP servers. Provides the User-Agent header unless overridden by
  28. // specific User-Agent header from app
  29. //
  30. ICSTRING _UserAgent;
  31. //
  32. // _ProxyInfo - maintains the proxy server and bypass lists
  33. //
  34. PROXY_INFO * _ProxyInfo;
  35. //
  36. // _ProxyInfoResourceLock - must acquire for exclusive access in order to
  37. // modify the proxy info
  38. //
  39. RESOURCE_LOCK _ProxyInfoResourceLock;
  40. BOOL AcquireProxyInfo(BOOL bExclusiveMode) {
  41. return _ProxyInfoResourceLock.Acquire(bExclusiveMode);
  42. }
  43. VOID ReleaseProxyInfo(VOID) {
  44. _ProxyInfoResourceLock.Release();
  45. }
  46. VOID SafeDeleteProxyInfo(VOID) {
  47. DEBUG_ENTER((DBG_OBJECTS,
  48. None,
  49. "SafeDeleteProxyInfo",
  50. ""
  51. ));
  52. if ((_ProxyInfo != NULL) && (_ProxyInfo != PROXY_INFO_DIRECT)) {
  53. if (AcquireProxyInfo(TRUE)) { // must check since asking for exclusive access
  54. if (!IsProxyGlobal()) {
  55. if (_ProxyInfo != NULL) {
  56. delete _ProxyInfo;
  57. }
  58. }
  59. _ProxyInfo = NULL;
  60. ReleaseProxyInfo();
  61. }
  62. }
  63. DEBUG_LEAVE(0);
  64. }
  65. //
  66. // _dwInternetOpenFlags - flags from InternetOpen()
  67. //
  68. // BUGBUG - there should only be ONE flags DWORD for all handles descended
  69. // from this one. This is it
  70. // Rename to just _Flags, or _OpenFlags
  71. //
  72. DWORD _dwInternetOpenFlags;
  73. //
  74. // _WinsockLoaded - TRUE if we managed to successfully load winsock
  75. //
  76. //
  77. // BUGBUG - post-beta cleanup - combine into bitfield
  78. //
  79. BOOL _WinsockLoaded;
  80. //
  81. // _pICSocket - pointer to ICSocket for new HTTP async code
  82. //
  83. ICSocket * _pICSocket;
  84. protected:
  85. //
  86. // _Async - TRUE if the InternetOpen() handle, and all handles descended
  87. // from it, support asynchronous I/O
  88. //
  89. //
  90. // BUGBUG - post-beta cleanup - get from flags
  91. //
  92. BOOL _Async;
  93. DWORD _MaxConnectionsPerServer;
  94. DWORD _MaxConnectionsPer1_0Server;
  95. //
  96. // _DataAvailable - the number of bytes that can be read from this handle
  97. // (i.e. only protocol handles) immediately. This avoids a read request
  98. // being made asynchronously if it can be satisfied immediately
  99. //
  100. DWORD _DataAvailable;
  101. //
  102. // _EndOfFile - TRUE when we have received all data for this request. This
  103. // is used to avoid the API having to perform an extraneous read (possibly
  104. // asynchronously) just to discover that we reached end-of-file already
  105. //
  106. //
  107. // BUGBUG - post-beta cleanup - combine into bitfield
  108. //
  109. BOOL _EndOfFile;
  110. //
  111. // _StatusCallback - we now maintain callbacks on a per-handle basis. The
  112. // callback address comes from the parent handle or the DLL if this is an
  113. // InternetOpen() handle. The status callback can be changed for an
  114. // individual handle object using the ExchangeStatusCallback() method
  115. // (called from InternetSetStatusCallback())
  116. //
  117. //
  118. // BUGBUG - this should go in HANDLE_OBJECT
  119. //
  120. WINHTTP_STATUS_CALLBACK _StatusCallback;
  121. BOOL _StatusCallbackType;
  122. DWORD _dwStatusCallbackFlags;
  123. // Codepage: required for conversion of object from unicode to mbcs in WinHttpOpenRequest.
  124. DWORD _dwCodePage;
  125. HANDLE _ThreadToken;
  126. public:
  127. INTERNET_HANDLE_BASE(
  128. LPCSTR UserAgent,
  129. DWORD AccessMethod,
  130. LPSTR ProxyName,
  131. LPSTR ProxyBypass,
  132. DWORD Flags
  133. );
  134. INTERNET_HANDLE_BASE(INTERNET_HANDLE_BASE *INetObj);
  135. virtual ~INTERNET_HANDLE_BASE(VOID);
  136. //
  137. // BUGBUG - rfirth 04/05/96 - remove virtual functions
  138. //
  139. // For the most part, these functions aren't required to be
  140. // virtual. They should just be moved to the relevant handle type
  141. // (e.g. FTP_FILE_HANDLE_OBJECT). Even GetHandleType() is overkill.
  142. // Replacing with a method that just returns
  143. // HANDLE_OBJECT::_ObjectType would be sufficient
  144. //
  145. virtual HINTERNET_HANDLE_TYPE GetHandleType(VOID)
  146. {
  147. return TypeInternetHandle;
  148. }
  149. HANDLE GetThreadToken(void) const { return _ThreadToken; }
  150. PP_CONTEXT GetPPContext(void) const {
  151. return _PPContext;
  152. }
  153. void SetPPContext(PP_CONTEXT PPContext) {
  154. _PPContext = PPContext;
  155. }
  156. BOOL IsCopy(VOID) const {
  157. return _IsCopy;
  158. }
  159. VOID GetUserAgent(LPSTR Buffer, LPDWORD BufferLength) {
  160. _UserAgent.CopyTo(Buffer, BufferLength);
  161. }
  162. LPSTR GetUserAgent(VOID) {
  163. return _UserAgent.StringAddress();
  164. }
  165. LPSTR GetUserAgent(LPDWORD lpdwLength) {
  166. *lpdwLength = _UserAgent.StringLength();
  167. return _UserAgent.StringAddress();
  168. }
  169. VOID SetUserAgent(LPSTR lpszUserAgent) {
  170. INET_ASSERT(lpszUserAgent != NULL);
  171. _UserAgent = lpszUserAgent;
  172. }
  173. BOOL IsProxy(VOID) const {
  174. //
  175. // we can return this info without acquiring the critical section
  176. //
  177. return ((_ProxyInfo != NULL) && (_ProxyInfo != PROXY_INFO_DIRECT)) ?
  178. _ProxyInfo->IsProxySettingsConfigured()
  179. : FALSE;
  180. }
  181. BOOL IsProxyGlobal(VOID) const {
  182. INET_ASSERT(g_pGlobalProxyInfo != NULL);
  183. return (_ProxyInfo == g_pGlobalProxyInfo) ? TRUE : FALSE;
  184. }
  185. PROXY_INFO * GetProxyInfo(VOID) const {
  186. return _ProxyInfo;
  187. }
  188. VOID SetProxyInfo(PROXY_INFO * ProxyInfo) {
  189. _ProxyInfo = ProxyInfo;
  190. }
  191. VOID ResetProxyInfo(VOID) {
  192. SetProxyInfo(NULL);
  193. }
  194. DWORD
  195. Refresh();
  196. DWORD
  197. SetProxyInfo(
  198. IN DWORD dwAccessType,
  199. IN LPCSTR lpszProxy OPTIONAL,
  200. IN LPCSTR lpszProxyBypass OPTIONAL
  201. );
  202. DWORD
  203. GetProxyStringInfo(
  204. OUT LPVOID lpBuffer,
  205. IN OUT LPDWORD lpdwBufferLength
  206. );
  207. DWORD
  208. GetProxyInfo(
  209. IN AUTO_PROXY_ASYNC_MSG **ppQueryForProxyInfo
  210. );
  211. BOOL
  212. RedoSendRequest(
  213. IN OUT LPDWORD lpdwError,
  214. IN DWORD dwSecureStatus,
  215. IN AUTO_PROXY_ASYNC_MSG *pQueryForProxyInfo,
  216. IN CServerInfo *pOriginServer,
  217. IN CServerInfo *pProxyServer
  218. );
  219. VOID SetContext(DWORD_PTR NewContext) {
  220. _Context = NewContext;
  221. }
  222. BOOL IsAsyncHandle(VOID) {
  223. return _Async;
  224. }
  225. VOID SetAvailableDataLength(DWORD Amount) {
  226. INET_ASSERT((int)Amount >= 0);
  227. _DataAvailable = Amount;
  228. }
  229. DWORD AvailableDataLength(VOID) const {
  230. INET_ASSERT((int)_DataAvailable >= 0);
  231. return _DataAvailable;
  232. }
  233. BOOL IsDataAvailable(VOID) {
  234. INET_ASSERT((int)_DataAvailable >= 0);
  235. return (_DataAvailable != 0) ? TRUE : FALSE;
  236. }
  237. VOID ReduceAvailableDataLength(DWORD Amount) {
  238. //
  239. // why would Amount be > _DataAvailable?
  240. //
  241. if (Amount > _DataAvailable) {
  242. _DataAvailable = 0;
  243. } else {
  244. _DataAvailable -= Amount;
  245. }
  246. INET_ASSERT((int)_DataAvailable >= 0);
  247. }
  248. VOID IncreaseAvailableDataLength(DWORD Amount) {
  249. _DataAvailable += Amount;
  250. INET_ASSERT((int)_DataAvailable >= 0);
  251. }
  252. VOID SetEndOfFile(VOID) {
  253. _EndOfFile = TRUE;
  254. }
  255. VOID ResetEndOfFile(VOID) {
  256. _EndOfFile = FALSE;
  257. }
  258. BOOL IsEndOfFile(VOID) const {
  259. return _EndOfFile;
  260. }
  261. WINHTTP_STATUS_CALLBACK GetStatusCallback(VOID)
  262. {
  263. return _StatusCallback;
  264. }
  265. DWORD GetStatusCallbackFlags(VOID)
  266. {
  267. return _dwStatusCallbackFlags;
  268. }
  269. BOOL IsUnicodeStatusCallback()
  270. {
  271. return _StatusCallbackType;
  272. }
  273. BOOL IsNotificationEnabled(DWORD dwStatus)
  274. {
  275. return (_dwStatusCallbackFlags & dwStatus);
  276. }
  277. VOID ResetStatusCallback(VOID) {
  278. _StatusCallback = NULL;
  279. _StatusCallbackType = FALSE;
  280. _dwStatusCallbackFlags = 0;
  281. }
  282. //VOID AcquireAsyncSpinLock(VOID);
  283. //
  284. //VOID ReleaseAsyncSpinLock(VOID);
  285. DWORD ExchangeStatusCallback(LPWINHTTP_STATUS_CALLBACK lpStatusCallback, BOOL fType, DWORD dwFlags);
  286. //DWORD AddAsyncRequest(BOOL fNoCallbackOK);
  287. //
  288. //VOID RemoveAsyncRequest(VOID);
  289. //
  290. //DWORD GetAsyncRequestCount(VOID) {
  291. //
  292. // //
  293. // // it doesn't matter about locking this variable - it can change before
  294. // // we have returned it to the caller anyway
  295. // //
  296. //
  297. // return _PendingAsyncRequests;
  298. //}
  299. // random methods on flags
  300. DWORD GetInternetOpenFlags() {
  301. return _dwInternetOpenFlags;
  302. }
  303. VOID
  304. SetAbortHandle(
  305. IN ICSocket * pSocket
  306. );
  307. ICSocket * GetAbortHandle(VOID) const {
  308. return _pICSocket;
  309. }
  310. VOID
  311. ResetAbortHandle(
  312. VOID
  313. );
  314. BOOL IsFromCacheTimeoutSet(VOID) const {
  315. return FALSE;
  316. }
  317. DWORD
  318. GetMaxConnectionsPerServer(DWORD dwOption)
  319. {
  320. INET_ASSERT(dwOption == WINHTTP_OPTION_MAX_CONNS_PER_SERVER ||
  321. dwOption == WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER);
  322. return (dwOption == WINHTTP_OPTION_MAX_CONNS_PER_SERVER) ?
  323. _MaxConnectionsPerServer
  324. : _MaxConnectionsPer1_0Server;
  325. }
  326. void
  327. SetMaxConnectionsPerServer(DWORD dwOption, DWORD dwMaxConnections)
  328. {
  329. INET_ASSERT(dwOption == WINHTTP_OPTION_MAX_CONNS_PER_SERVER ||
  330. dwOption == WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER);
  331. if (dwOption == WINHTTP_OPTION_MAX_CONNS_PER_SERVER)
  332. _MaxConnectionsPerServer = dwMaxConnections;
  333. else
  334. _MaxConnectionsPer1_0Server = dwMaxConnections;
  335. }
  336. DWORD GetCodePage() { return _dwCodePage; }
  337. void SetCodePage(DWORD dwCodePage) { _dwCodePage = dwCodePage; }
  338. void AbortSocket (void);
  339. void DisableTweener(void) {
  340. _fDisableTweener = TRUE;
  341. }
  342. void EnableTweener(void) {
  343. _fDisableTweener = FALSE;
  344. }
  345. BOOL TweenerDisabled(void) const {
  346. return _fDisableTweener;
  347. }
  348. void DisableKeyring(void) {
  349. _fDisableKeyring = TRUE;
  350. }
  351. void EnableKeyring(void) {
  352. _fDisableKeyring = FALSE;
  353. }
  354. BOOL KeyringDisabled(void) const {
  355. return _fDisableKeyring;
  356. }
  357. private:
  358. BOOL _fDisableTweener;
  359. BOOL _fDisableKeyring;
  360. };