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.

1906 lines
43 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. autoprox.hxx
  5. Abstract:
  6. Contains interface definition for a specialized DLL that automatically configurares WININET proxy
  7. information. The DLL can reroute proxy infromation based on a downloaded set of data that matches
  8. it registered MIME type. The DLL can also control WININET proxy use, on a request by request basis.
  9. Contents:
  10. AUTO_PROXY_LIST_ENTRY
  11. AUTO_PROXY_DLLS
  12. AUTO_PROXY_ASYNC_MSG
  13. PROXY_STATE
  14. Author:
  15. Arthur L Bierer (arthurbi) 01-Dec-1996
  16. Revision History:
  17. 01-Dec-1996 arthurbi
  18. Created
  19. --*/
  20. #ifndef _AUTOPROX_HXX_
  21. #define _AUTOPROX_HXX_
  22. #define CSZMAINSECKEY "AutoProxyTypes"
  23. //
  24. // functions
  25. //
  26. BOOL
  27. InitalizeAutoConfigDllIfNeeded(
  28. VOID
  29. );
  30. //
  31. // Callback functions implimented in WININET
  32. //
  33. class AUTO_PROXY_HELPER_APIS {
  34. public:
  35. virtual
  36. BOOL IsResolvable(
  37. IN LPSTR lpszHost
  38. );
  39. virtual
  40. DWORD GetIPAddress(
  41. IN OUT LPSTR lpszIPAddress,
  42. IN OUT LPDWORD lpdwIPAddressSize
  43. );
  44. virtual
  45. DWORD ResolveHostName(
  46. IN LPSTR lpszHostName,
  47. IN OUT LPSTR lpszIPAddress,
  48. IN OUT LPDWORD lpdwIPAddressSize
  49. );
  50. virtual
  51. BOOL IsInNet(
  52. IN LPSTR lpszIPAddress,
  53. IN LPSTR lpszDest,
  54. IN LPSTR lpszMask
  55. );
  56. };
  57. //
  58. // external func declariations
  59. //
  60. #define AUTO_PROXY_VERSION 0x00010000
  61. #define EXT_PROXY_FUNC *
  62. typedef BOOL
  63. (EXT_PROXY_FUNC PROXY_INFO_INVALID_FN) (
  64. IN LPSTR lpszMime,
  65. IN LPSTR lpszUrl,
  66. IN DWORD dwUrlLength,
  67. IN LPSTR lpszProxyHostName,
  68. IN DWORD dwProxyHostNameLength
  69. );
  70. typedef BOOL
  71. (EXT_PROXY_FUNC PROXY_DLL_DEINIT_FN) (
  72. IN LPSTR lpszMime,
  73. IN DWORD dwReserved
  74. );
  75. typedef BOOL
  76. (EXT_PROXY_FUNC GET_PROXY_INFO_FN) (
  77. IN LPCSTR lpszUrl,
  78. IN DWORD dwUrlLength,
  79. IN LPSTR lpszUrlHostName,
  80. IN DWORD dwUrlHostNameLength,
  81. OUT LPSTR * lplpszProxyHostName,
  82. OUT LPDWORD lpdwProxyHostNameLength
  83. ) ;
  84. typedef BOOL
  85. (EXT_PROXY_FUNC GET_PROXY_INFO_EX_FN) (
  86. IN INTERNET_SCHEME tUrlProtocol,
  87. IN LPCSTR lpszUrl,
  88. IN DWORD dwUrlLength,
  89. IN LPSTR lpszUrlHostName,
  90. IN DWORD dwUrlHostNameLength,
  91. IN INTERNET_PORT nUrlPort,
  92. OUT LPINTERNET_SCHEME lptProxyScheme,
  93. OUT LPSTR * lplpszProxyHostName,
  94. OUT LPDWORD lpdwProxyHostNameLength,
  95. OUT LPINTERNET_PORT lpProxyHostPort
  96. ) ;
  97. typedef BOOL
  98. (EXT_PROXY_FUNC PROXY_DLL_INIT_FN) (
  99. IN DWORD dwVersion,
  100. IN LPSTR lpszDownloadedTempFile,
  101. IN LPSTR lpszMime,
  102. IN AUTO_PROXY_HELPER_APIS *pAutoProxyCallbacks,
  103. IN DWORD_PTR dwReserved
  104. );
  105. #define PROXY_INFO_INVALID_FN_NAME "InternetProxyInfoInvalid"
  106. #define GET_PROXY_INFO_FN_NAME "InternetGetProxyInfo"
  107. #define GET_PROXY_INFO_EX_FN_NAME "InternetGetProxyInfoEx"
  108. #define PROXY_DLL_INIT_FN_NAME "InternetInitializeAutoProxyDll"
  109. #define PROXY_DLL_DEINIT_FN_NAME "InternetDeInitializeAutoProxyDll"
  110. //
  111. // Flags stored in registry for Auto-Proxy Entry
  112. //
  113. #define AUTOPROX_FLAGS_SINGLE_THREAD 0x01
  114. //
  115. // defines ...
  116. //
  117. #define DEFAULT_AUTO_PROXY_THREAD_TIME_OUT 30000 // 30 secs BUGBUG, up before checkin
  118. //
  119. // PROXY_MESSAGE_TYPE - this represents a type of query that is used
  120. // to submit a request through proxy "knowledge-base" ( ie script, db, etc )
  121. // for async processing of Java-Script auto-proxy scripts.
  122. //
  123. typedef enum {
  124. PROXY_MSG_INVALID,
  125. PROXY_MSG_INIT,
  126. PROXY_MSG_DEINIT,
  127. PROXY_MSG_SELF_DESTRUCT,
  128. PROXY_MSG_GET_PROXY_INFO,
  129. PROXY_MSG_SET_BAD_PROXY
  130. } PROXY_MESSAGE_TYPE;
  131. //
  132. // PROXY_MESSAGE_ALLOC_TYPE - this is needed to track what allocation of member vars
  133. // are currently used in my object. This allows us to use stack vars
  134. // for simple, local calls, but then have allocation done-on-the-fly
  135. // when we need to queue the message.
  136. //
  137. typedef enum {
  138. MSG_ALLOC_NONE,
  139. MSG_ALLOC_STACK_ONLY,
  140. MSG_ALLOC_HEAP,
  141. MSG_ALLOC_HEAP_MSG_OBJ_OWNS
  142. } PROXY_MESSAGE_ALLOC_TYPE;
  143. //
  144. // AUTO_PROXY_STATE - is used to track the state of the auto-proxy list object
  145. // in order to maintain syncronization across readers and writers.
  146. //
  147. typedef enum {
  148. AUTO_PROXY_DISABLED,
  149. AUTO_PROXY_BLOCKED,
  150. AUTO_PROXY_PENDING, // blocked, but we can still fallback to static settings
  151. AUTO_PROXY_ENABLED
  152. } AUTO_PROXY_STATE;
  153. class BAD_PROXY_LIST; // forward decl
  154. //
  155. // PROXY_STATE - keeps track of multiple proxies stored in a Netscape Style
  156. // proxy list string format. Ex:
  157. // "PROXY itgproxy:80; PROXY proxy:80; PROXY 192.168.100.2:1080; SOCKS 192.168.100.2; DIRECT"
  158. //
  159. // Can also be used to link the GetProxyInfo return with a failure in the proxies it gave.
  160. // This needed so we call back into an Auto-Proxy DLL letting them know that we failed
  161. // to be able to utilize its auto-proxy that it gave us.
  162. //
  163. class PROXY_STATE {
  164. private:
  165. //
  166. // _lpszAutoProxyList - List, or Proxy that we are tracking.
  167. //
  168. LPSTR _lpszAutoProxyList;
  169. //
  170. // _dwcbAutoProxyList - size of _lpszAutoProxyList.
  171. //
  172. DWORD _dwcbAutoProxyList;
  173. //
  174. // _lpszOffset - Current Offset into _lpszAutoProxyList
  175. //
  176. LPSTR _lpszOffset;
  177. //
  178. // _lpszLastProxyUsed - Tracks the last proxy that was returned.
  179. //
  180. LPSTR _lpszLastProxyUsed;
  181. //
  182. // _LastProxyUsedPort - Last used Internet Port on the Proxy
  183. //
  184. INTERNET_PORT _LastProxyUsedPort;
  185. //
  186. // _Error - Error code in constructor.
  187. //
  188. DWORD _Error;
  189. //
  190. // _fIsMultiProxyList - TRUE if we a Netscape type list of proxies, as opposed to a simple proxyhostname string.
  191. //
  192. BOOL _fIsMultiProxyList;
  193. //
  194. // _fIsAnotherProxyAvail - TRUE if we have another proxy to process
  195. //
  196. BOOL _fIsAnotherProxyAvail;
  197. //
  198. // tProxyScheme - for the non-multi proxy case we track the type of proxy we are storing.
  199. //
  200. INTERNET_SCHEME _tProxyScheme;
  201. //
  202. // ProxyHostPort - for the non-multi proxy case we track the host port.
  203. //
  204. INTERNET_PORT _proxyHostPort;
  205. public:
  206. PROXY_STATE(
  207. LPSTR lpszAutoProxyList,
  208. DWORD dwcbAutoProxyList,
  209. BOOL fIsMultiProxyList,
  210. INTERNET_SCHEME tProxyScheme,
  211. INTERNET_PORT proxyHostPort
  212. )
  213. {
  214. _lpszAutoProxyList = NULL;
  215. _dwcbAutoProxyList = 0;
  216. _lpszOffset = NULL;
  217. _Error = ERROR_SUCCESS;
  218. _lpszLastProxyUsed = NULL;
  219. _LastProxyUsedPort = INTERNET_DEFAULT_HTTP_PORT;
  220. _fIsMultiProxyList = fIsMultiProxyList;
  221. _tProxyScheme = tProxyScheme;
  222. _proxyHostPort = proxyHostPort;
  223. _fIsAnotherProxyAvail = FALSE;
  224. if ( lpszAutoProxyList &&
  225. dwcbAutoProxyList > 0 )
  226. {
  227. _lpszAutoProxyList = (LPSTR)
  228. ALLOCATE_MEMORY(LMEM_FIXED, dwcbAutoProxyList+1);
  229. if ( _lpszAutoProxyList )
  230. {
  231. lstrcpyn(_lpszAutoProxyList, lpszAutoProxyList, dwcbAutoProxyList );
  232. _lpszAutoProxyList[dwcbAutoProxyList] = '\0';
  233. _dwcbAutoProxyList = dwcbAutoProxyList;
  234. _lpszOffset = _lpszAutoProxyList;
  235. }
  236. else
  237. {
  238. _Error = ERROR_NOT_ENOUGH_MEMORY;
  239. }
  240. }
  241. }
  242. ~PROXY_STATE()
  243. {
  244. DEBUG_ENTER((DBG_OBJECTS,
  245. None,
  246. "~PROXY_STATE",
  247. NULL
  248. ));
  249. if ( _lpszAutoProxyList )
  250. {
  251. FREE_MEMORY(_lpszAutoProxyList );
  252. _lpszAutoProxyList = NULL;
  253. }
  254. DEBUG_LEAVE(0);
  255. }
  256. DWORD
  257. GetError(VOID) const
  258. {
  259. return _Error;
  260. }
  261. BOOL
  262. IsEmpty(VOID) const
  263. {
  264. return (!_lpszOffset || *_lpszOffset == '\0' ) ? TRUE : FALSE;
  265. }
  266. BOOL
  267. IsAnotherProxyAvail(VOID) const
  268. {
  269. return _fIsAnotherProxyAvail;
  270. }
  271. LPSTR
  272. GetLastProxyUsed(INTERNET_PORT *pProxyPort)
  273. {
  274. *pProxyPort = _LastProxyUsedPort;
  275. return _lpszLastProxyUsed;
  276. }
  277. BOOL
  278. GetNextProxy(
  279. IN INTERNET_SCHEME tUrlScheme,
  280. IN BAD_PROXY_LIST & BadProxyList,
  281. OUT LPINTERNET_SCHEME lptProxyScheme,
  282. OUT LPSTR * lplpszProxyHostName,
  283. OUT LPBOOL lpbFreeProxyHostName,
  284. OUT LPDWORD lpdwProxyHostNameLength,
  285. OUT LPINTERNET_PORT lpProxyHostPort
  286. );
  287. };
  288. //
  289. // AUTO_PROXY_ASYNC_MSG - this object is used to pass queries for proxy information across
  290. // from requestors (HTTP_REQUEST_HANDLE_OBJECT, parseUrl, etc) to responders
  291. // (AutoProxy DLL, PROXY_INFO object) who can process the request in a syncronious
  292. // or asyncrouns manner.
  293. //
  294. class AUTO_PROXY_ASYNC_MSG {
  295. friend class AUTO_PROXY_LIST_ENTRY;
  296. public: //BUGBUG, I'm being lazy, need to make methods to guard access
  297. //
  298. // _List - We're a list entry on a queue. But we don't always have to be,
  299. // We can be borne a structure that justs gets passed around and is never
  300. // queued.
  301. //
  302. LIST_ENTRY _List;
  303. //
  304. // _tUrlProtocol - Protocol that this request is using.
  305. //
  306. INTERNET_SCHEME _tUrlProtocol;
  307. //
  308. // _lpszUrl - The requested URL that we are navigating to.
  309. //
  310. LPSTR _lpszUrl;
  311. //
  312. // _dwUrlLength - The size of the URL.
  313. //
  314. DWORD _dwUrlLength;
  315. //
  316. // _lpszUrlHostName - The host name found in the URL.
  317. //
  318. LPSTR _lpszUrlHostName;
  319. //
  320. // _dwUrlHostNameLength - Host name Length
  321. //
  322. DWORD _dwUrlHostNameLength;
  323. //
  324. // _nUrlPort - Dest port used on this Url.
  325. //
  326. INTERNET_PORT _nUrlPort;
  327. //
  328. // _tProxyScheme - Type of proxy we will use. ( HTTP, HTTPS, etc )
  329. //
  330. INTERNET_SCHEME _tProxyScheme;
  331. //
  332. // _lpszProxyHostName - Host name of the proxy we are to use.
  333. //
  334. LPSTR _lpszProxyHostName;
  335. //
  336. // _bFreeProxyHostName - TRUE if _lpszProxyHostName is a copy
  337. //
  338. BOOL _bFreeProxyHostName;
  339. //
  340. // _dwProxyHostNameLength - Proxy Host name length.
  341. //
  342. DWORD _dwProxyHostNameLength;
  343. //
  344. // _nProxyHostPort - Proxy port to use
  345. //
  346. INTERNET_PORT _nProxyHostPort;
  347. //
  348. // _pProxyState - State for enumerating multiple proxies.
  349. //
  350. PROXY_STATE *_pProxyState;
  351. //
  352. // _pmProxyQuery - The Action aka Query we're are doing with this message.
  353. //
  354. PROXY_MESSAGE_TYPE _pmProxyQuery;
  355. //
  356. // _pmaAllocMode - Used to track who owns the allocated string ptrs.
  357. //
  358. PROXY_MESSAGE_ALLOC_TYPE _pmaAllocMode;
  359. //
  360. // _dwQueryResult - TRUE if we are going through a proxy
  361. //
  362. DWORD _dwQueryResult;
  363. //
  364. // _Error - Return code after this call is made.
  365. //
  366. DWORD _Error;
  367. //
  368. // dwProxyVersion - Proxy Verion this was issue a result for
  369. //
  370. DWORD _dwProxyVersion;
  371. VOID SetVersion(VOID) {
  372. _dwProxyVersion = GlobalProxyVersionCount;
  373. }
  374. DWORD GetVersion(VOID) {
  375. return _dwProxyVersion;
  376. }
  377. //
  378. // _MessageFlags - Various
  379. //
  380. union {
  381. struct {
  382. //
  383. // DontWantProxyStrings, don't waste time with allocating strings for my result,
  384. // since I all I care about is generalized proxy info (ie do I have a proxy for ...).
  385. //
  386. DWORD DontWantProxyStrings : 1;
  387. //
  388. // BlockUntilCompletetion, don't return from an async call until the async thread has
  389. // completed processing my proxy query.
  390. //
  391. DWORD BlockUntilCompletetion : 1;
  392. //
  393. // AvoidAsyncCall, don't go async under any curcumstances, so we will return
  394. // what every we can get, even if this means giving incorrect data.
  395. //
  396. DWORD AvoidAsyncCall : 1;
  397. //
  398. // BlockedOnFsm, true a fsm is blocked on this message to complete
  399. //
  400. DWORD BlockedOnFsm : 1 ;
  401. //
  402. // QueryOnCallback, TRUE if we're making a call with this object
  403. // on a FSM callback. Basically we've received results from
  404. // the async thread, but we need to do a final a call so
  405. // the results can be parsed out.
  406. //
  407. DWORD QueryOnCallback : 1;
  408. //
  409. // ForceRefresh, TRUE if we are to force a refresh of cached settings and scripts.
  410. //
  411. DWORD ForceRefresh : 1;
  412. //
  413. // ShowIndication, TRUE if we indicate via callback
  414. // to the user that we performing auto-detection
  415. //
  416. DWORD ShowIndication : 1;
  417. //
  418. // BackroundDetectionPending, TRUE if a backround detection
  419. // is being done while this page is loading
  420. //
  421. DWORD BackroundDetectionPending : 1;
  422. //
  423. // CanCacheResult - TRUE if this result can be cached
  424. //
  425. DWORD CanCacheResult : 1;
  426. } Flags;
  427. //
  428. // Dword - used in initialization ONLY, do NOT use ELSEWHERE !
  429. //
  430. DWORD Dword;
  431. } _MessageFlags;
  432. //public:
  433. AUTO_PROXY_ASYNC_MSG(
  434. IN INTERNET_SCHEME isUrlScheme,
  435. IN LPSTR lpszUrl,
  436. IN LPSTR lpszUrlHostName,
  437. IN DWORD dwUrlHostNameLength
  438. );
  439. AUTO_PROXY_ASYNC_MSG(
  440. IN INTERNET_SCHEME isUrlScheme,
  441. IN LPSTR lpszUrl,
  442. IN DWORD dwUrlLength,
  443. IN LPSTR lpszUrlHostName,
  444. IN DWORD dwUrlHostNameLength,
  445. IN INTERNET_PORT nUrlPort
  446. );
  447. AUTO_PROXY_ASYNC_MSG(
  448. PROXY_MESSAGE_TYPE pmProxyQuery
  449. );
  450. AUTO_PROXY_ASYNC_MSG(
  451. AUTO_PROXY_ASYNC_MSG *pStaticAutoProxy
  452. );
  453. AUTO_PROXY_ASYNC_MSG(
  454. IN INTERNET_SCHEME isUrlScheme,
  455. IN LPSTR lpszUrlHostName,
  456. IN DWORD dwUrlHostNameLength
  457. );
  458. AUTO_PROXY_ASYNC_MSG(
  459. VOID
  460. )
  461. {
  462. Initalize();
  463. }
  464. ~AUTO_PROXY_ASYNC_MSG(
  465. VOID
  466. );
  467. VOID Initalize(
  468. VOID
  469. )
  470. {
  471. InitializeListHead(&_List);
  472. // this is bogus, we should just memset this.
  473. _tUrlProtocol = INTERNET_SCHEME_UNKNOWN;
  474. _lpszUrl = NULL;
  475. _dwUrlLength = 0;
  476. _lpszUrlHostName = NULL;
  477. _dwUrlHostNameLength = 0;
  478. _nUrlPort = INTERNET_INVALID_PORT_NUMBER;
  479. _tProxyScheme = INTERNET_SCHEME_UNKNOWN;
  480. _lpszProxyHostName = NULL;
  481. _bFreeProxyHostName = FALSE;
  482. _dwProxyHostNameLength = 0;
  483. _nProxyHostPort = INTERNET_INVALID_PORT_NUMBER;
  484. _pmProxyQuery = PROXY_MSG_INVALID;
  485. _pmaAllocMode = MSG_ALLOC_NONE;
  486. _pProxyState = NULL;
  487. _dwQueryResult = FALSE;
  488. _Error = ERROR_SUCCESS;
  489. _dwProxyVersion = 0;
  490. _MessageFlags.Dword = 0;
  491. }
  492. VOID
  493. SetProxyMsg(
  494. IN INTERNET_SCHEME isUrlScheme,
  495. IN LPSTR lpszUrl,
  496. IN DWORD dwUrlLength,
  497. IN LPSTR lpszUrlHostName,
  498. IN DWORD dwUrlHostNameLength,
  499. IN INTERNET_PORT nUrlPort
  500. );
  501. BOOL IsProxyEnumeration(VOID) const {
  502. if ( _pProxyState &&
  503. !IsDontWantProxyStrings() &&
  504. !_pProxyState->IsEmpty() )
  505. {
  506. return TRUE;
  507. }
  508. return FALSE;
  509. }
  510. BOOL IsAlloced(VOID) const {
  511. return ( _pmaAllocMode == MSG_ALLOC_HEAP ||
  512. _pmaAllocMode == MSG_ALLOC_HEAP_MSG_OBJ_OWNS ) ?
  513. TRUE : FALSE;
  514. }
  515. BOOL IsUrl(VOID) const {
  516. return (_lpszUrl && _dwUrlLength > 0 );
  517. }
  518. BOOL IsUseProxy(VOID) const {
  519. return _dwQueryResult;
  520. }
  521. VOID SetUseProxy(BOOL Value) {
  522. _dwQueryResult = Value;
  523. }
  524. INTERNET_SCHEME GetProxyScheme(VOID) const {
  525. return _tProxyScheme;
  526. }
  527. INTERNET_SCHEME GetUrlScheme(VOID) const {
  528. return _tUrlProtocol;
  529. }
  530. BOOL IsShowIndication(VOID) const {
  531. return (BOOL) _MessageFlags.Flags.ShowIndication;
  532. }
  533. VOID SetShowIndication(BOOL Value) {
  534. _MessageFlags.Flags.ShowIndication = (Value) ? TRUE : FALSE;
  535. }
  536. BOOL IsBackroundDetectionPending(VOID) const {
  537. return (BOOL) _MessageFlags.Flags.BackroundDetectionPending;
  538. }
  539. VOID SetBackroundDetectionPending(BOOL Value) {
  540. _MessageFlags.Flags.BackroundDetectionPending = (Value) ? TRUE : FALSE;
  541. }
  542. BOOL IsDontWantProxyStrings(VOID) const {
  543. return (BOOL) _MessageFlags.Flags.DontWantProxyStrings;
  544. }
  545. VOID SetDontWantProxyStrings(BOOL Value) {
  546. _MessageFlags.Flags.DontWantProxyStrings = (Value) ? TRUE : FALSE;
  547. }
  548. BOOL IsAvoidAsyncCall(VOID) const {
  549. return (BOOL) _MessageFlags.Flags.AvoidAsyncCall;
  550. }
  551. VOID SetAvoidAsyncCall(BOOL Value) {
  552. _MessageFlags.Flags.AvoidAsyncCall = (Value) ? TRUE : FALSE;
  553. }
  554. BOOL IsQueryOnCallback(VOID) const {
  555. return (BOOL) _MessageFlags.Flags.QueryOnCallback;
  556. }
  557. VOID SetQueryOnCallback(BOOL Value) {
  558. _MessageFlags.Flags.QueryOnCallback = (Value) ? TRUE : FALSE;
  559. }
  560. BOOL IsForceRefresh(VOID) const {
  561. return (BOOL) _MessageFlags.Flags.ForceRefresh;
  562. }
  563. VOID SetForceRefresh(BOOL Value) {
  564. _MessageFlags.Flags.ForceRefresh = (Value) ? TRUE : FALSE;
  565. }
  566. BOOL IsBlockUntilCompletetion(VOID) const {
  567. return (BOOL) _MessageFlags.Flags.BlockUntilCompletetion;
  568. }
  569. VOID SetBlockUntilCompletetion(BOOL Value) {
  570. _MessageFlags.Flags.BlockUntilCompletetion = (Value) ? TRUE : FALSE;
  571. }
  572. BOOL IsCanCacheResult(VOID) const {
  573. return (BOOL) _MessageFlags.Flags.CanCacheResult;
  574. }
  575. VOID SetCanCacheResult(BOOL Value) {
  576. _MessageFlags.Flags.CanCacheResult = (Value) ? TRUE : FALSE;
  577. }
  578. BOOL IsBlockedOnFsm(VOID) const {
  579. return (BOOL) _MessageFlags.Flags.BlockedOnFsm;
  580. }
  581. VOID SetBlockedOnFsm(BOOL Value) {
  582. _MessageFlags.Flags.BlockedOnFsm = (Value) ? TRUE : FALSE;
  583. }
  584. PROXY_MESSAGE_TYPE QueryForInfoMessage(VOID) const {
  585. return _pmProxyQuery;
  586. }
  587. DWORD GetError(VOID) {
  588. return _Error;
  589. }
  590. DWORD GetNextProxy(
  591. IN BAD_PROXY_LIST & BadProxyList
  592. )
  593. {
  594. BOOL fSuccess;
  595. INET_ASSERT(_pProxyState);
  596. fSuccess = _pProxyState->GetNextProxy(
  597. _tUrlProtocol,
  598. BadProxyList,
  599. &_tProxyScheme,
  600. &_lpszProxyHostName,
  601. &_bFreeProxyHostName,
  602. &_dwProxyHostNameLength,
  603. &_nProxyHostPort
  604. );
  605. SetUseProxy(fSuccess);
  606. return ERROR_SUCCESS;
  607. }
  608. };
  609. //
  610. // AUTO_PROXY_LIST_ENTRY - contains DLL entry points, and state information,
  611. // for a particalar Auto-Proxy DLL.
  612. //
  613. class AUTO_PROXY_LIST_ENTRY {
  614. private:
  615. friend class AUTO_PROXY_DLLS;
  616. //
  617. // _fDelayedInitialization - TRUE when we are to have queued initializiation of
  618. // this DLL so, it is not done until the first GetProxyInfo call.
  619. //
  620. BOOL _fDelayedInitialization;
  621. //
  622. // _List - there may be a variable number of bypass entries
  623. //
  624. LIST_ENTRY _List;
  625. //
  626. // _fDefault - TRUE, if this entry is the default auto-proxy entry.
  627. //
  628. BOOL _fDefault;
  629. //
  630. // _fInitializedSuccessfully - TRUE, if we have an initalization function
  631. // in the autoproxy dll that initalized successfully. This is to
  632. // prevent calling other callbacks in the auto-proxy dll if it
  633. // failed to initalize.
  634. //
  635. BOOL _fInitializedSuccessfully;
  636. //
  637. // _lpszDllFilePath - file path of DLL to load
  638. //
  639. LPSTR _lpszDllFilePath;
  640. //
  641. // _lpszFileExtensions - string of ';' delimited file extensions to match against
  642. //
  643. LPSTR _lpszFileExtensions;
  644. //
  645. // _lpszMimeType - Mime type string associated with this Auto-Proxy type.
  646. //
  647. LPSTR _lpszMimeType;
  648. //
  649. // _hAutoConfigDLL - open handle to DLL that we are handling.
  650. //
  651. HINSTANCE _hAutoConfigDLL;
  652. //
  653. // (_pGetProxyInfo) ( ... ) - Callback made into auto-proxy DLL to gather
  654. // what proxy(s) we should use for a specific connection.
  655. //
  656. GET_PROXY_INFO_FN _pGetProxyInfo;
  657. //
  658. // (_pGetProxyInfoEx) ( ... ) - Callback made into auto-proxy DLL to gather
  659. // what proxy(s) we should use for a specific connection. Ex versions
  660. // givers caller more control. If Ex is exported, it is used otherwise
  661. // GetProyInfo is used.
  662. //
  663. GET_PROXY_INFO_EX_FN _pGetProxyInfoEx;
  664. //
  665. // (_pProxyDllInit) ( ... ) - Callback made into auto-proxy DLL to notify
  666. // DLL of initialization.
  667. //
  668. PROXY_DLL_INIT_FN _pProxyDllInit;
  669. //
  670. // (_pProxyDllInit) ( ... ) - Notifies DLL before shutdown
  671. //
  672. PROXY_DLL_DEINIT_FN _pProxyDllDeInit;
  673. //
  674. // (_pProxyInfoInvalid) ( ... ) - A request using the returned proxy in GetProxyInfo was invalid.
  675. //
  676. PROXY_INFO_INVALID_FN _pProxyInfoInvalid;
  677. //
  678. // _dwFlags - DWORD flags stored in the registry for this entry.
  679. //
  680. DWORD _dwFlags;
  681. #ifdef INET_DEBUG
  682. BOOL _fUnInited;
  683. #endif
  684. public:
  685. AUTO_PROXY_LIST_ENTRY(
  686. IN LPSTR lpszDllName,
  687. IN LPSTR lpszExtensions,
  688. IN LPSTR lpszMimeType,
  689. IN BOOL fIsDefault,
  690. IN DWORD dwFlags
  691. )
  692. {
  693. DEBUG_ENTER((DBG_OBJECTS,
  694. None,
  695. "AUTO_PROXY_LIST_ENTRY",
  696. NULL
  697. ));
  698. InitializeListHead(&_List);
  699. _pGetProxyInfo = NULL;
  700. _pGetProxyInfoEx = NULL;
  701. _pProxyDllInit = NULL;
  702. _pProxyDllDeInit = NULL;
  703. _pProxyInfoInvalid = NULL;
  704. _hAutoConfigDLL = NULL;
  705. _lpszDllFilePath = lpszDllName ? NewString(lpszDllName) : NULL;
  706. _lpszFileExtensions = lpszExtensions ? NewString(lpszExtensions) : NULL;
  707. _lpszMimeType = lpszMimeType ? NewString(lpszMimeType) : NULL;
  708. _fDefault = fIsDefault;
  709. _fInitializedSuccessfully = FALSE;
  710. _fDelayedInitialization = FALSE;
  711. _dwFlags = dwFlags;
  712. #ifdef INET_DEBUG
  713. _fUnInited = FALSE;
  714. #endif
  715. DEBUG_LEAVE(0);
  716. }
  717. ~AUTO_PROXY_LIST_ENTRY() {
  718. DEBUG_ENTER((DBG_OBJECTS,
  719. None,
  720. "~AUTO_PROXY_LIST_ENTRY",
  721. NULL
  722. ));
  723. if ( _lpszFileExtensions )
  724. {
  725. _lpszFileExtensions = (LPSTR)
  726. FREE_MEMORY(_lpszFileExtensions);
  727. INET_ASSERT(_lpszFileExtensions == NULL);
  728. }
  729. if ( _lpszDllFilePath )
  730. {
  731. _lpszDllFilePath = (LPSTR) FREE_MEMORY(_lpszDllFilePath );
  732. INET_ASSERT(_lpszDllFilePath == NULL);
  733. }
  734. if ( _lpszMimeType )
  735. {
  736. _lpszMimeType = (LPSTR) FREE_MEMORY(_lpszMimeType);
  737. INET_ASSERT(_lpszMimeType == NULL);
  738. }
  739. //INET_ASSERT(_hAutoConfigDLL == NULL); // should have free libed DLL before calling destructor
  740. DEBUG_LEAVE(0);
  741. }
  742. VOID
  743. SetDllName(
  744. IN LPSTR lpszDllPath
  745. )
  746. {
  747. if ( _lpszDllFilePath )
  748. {
  749. _lpszDllFilePath = (LPSTR)
  750. FREE_MEMORY(_lpszDllFilePath);
  751. INET_ASSERT(_lpszDllFilePath == NULL);
  752. }
  753. _lpszDllFilePath = lpszDllPath;
  754. }
  755. DWORD
  756. LoadEntry(
  757. VOID
  758. );
  759. VOID
  760. UnloadEntry(
  761. VOID
  762. );
  763. BOOL
  764. ProxyInfoInvalid(
  765. IN LPSTR lpszMime,
  766. IN LPSTR lpszUrl,
  767. IN DWORD dwUrlLength,
  768. IN LPSTR lpszProxyHostName,
  769. IN DWORD dwProxyHostNameLength
  770. );
  771. BOOL
  772. ProxyDllDeInit(
  773. IN LPSTR lpszMime,
  774. IN DWORD dwReserved
  775. );
  776. DWORD
  777. GetProxyInfoEx(
  778. IN AUTO_PROXY_ASYNC_MSG *pQueryForProxyInfo
  779. );
  780. DWORD
  781. GetProxyInfo(
  782. IN AUTO_PROXY_ASYNC_MSG *pQueryForProxyInfo
  783. );
  784. BOOL
  785. DelayProxyDllInit(
  786. IN DWORD dwVersion,
  787. IN LPSTR lpszDownloadedTempFile,
  788. IN LPSTR lpszMime,
  789. IN AUTO_PROXY_HELPER_APIS *pAutoProxyCallbacks,
  790. IN DWORD dwReserved,
  791. OUT LPBOOL lpfCleanupFile
  792. );
  793. BOOL
  794. ProxyDllInit (
  795. IN DWORD dwVersion,
  796. IN LPSTR lpszDownloadedTempFile,
  797. IN LPSTR lpszMime,
  798. IN AUTO_PROXY_HELPER_APIS *pAutoProxyCallbacks,
  799. IN DWORD_PTR dwReserved
  800. );
  801. BOOL
  802. IsGetProxyInfoEx(
  803. VOID
  804. )
  805. {
  806. if ( _pGetProxyInfoEx )
  807. {
  808. return TRUE;
  809. }
  810. else
  811. {
  812. return FALSE;
  813. }
  814. }
  815. BOOL
  816. IsGetProxyInfo(
  817. VOID
  818. )
  819. {
  820. if ( _pGetProxyInfo )
  821. {
  822. return TRUE;
  823. }
  824. else
  825. {
  826. return FALSE;
  827. }
  828. }
  829. BOOL
  830. IsLoaded(
  831. VOID
  832. )
  833. {
  834. if ( _hAutoConfigDLL )
  835. {
  836. return TRUE;
  837. }
  838. return FALSE;
  839. }
  840. BOOL
  841. IsDefault(
  842. VOID
  843. )
  844. {
  845. return _fDefault;
  846. }
  847. };
  848. #define MAX_RELOAD_DELAY 45000 // in mins
  849. //
  850. // AUTO_PROXY_DLLS - tracks a list of regisitered DLLs that handle auto-proxy.
  851. // Auto-Proxy is the ability to download a specialized configuration file,
  852. // match the file with a registered DLL. The DLL, once matched, will calculate
  853. // which proxy(s) to use.
  854. //
  855. class AUTO_PROXY_DLLS {
  856. private:
  857. //
  858. // _List - serialized list of AUTO_PROXY_LIST_ENTRY objects
  859. //
  860. SERIALIZED_LIST _List;
  861. //
  862. // _Error - errors stored here from initialization
  863. //
  864. DWORD _Error;
  865. //
  866. // _ProxySettings - the various fields to track our proxy settings
  867. //
  868. INTERNET_PROXY_INFO_EX _ProxySettings;
  869. INTERNET_PROXY_INFO_EX * _pTempProxySettings;
  870. //
  871. // _pSelectedAutoProxyEntry - selected auto-proxy entry that will
  872. // accept all auto-proxy operations.
  873. //
  874. AUTO_PROXY_LIST_ENTRY * _pSelectedAutoProxyEntry;
  875. //
  876. // _aphAutoProxyAPIs - A V-Table that is passed into to the Auto-ProxyDll
  877. // to allow them to call us for DNS requests.
  878. //
  879. AUTO_PROXY_HELPER_APIS _aphAutoProxyAPIs;
  880. //
  881. // _CritSec - acquire this when accessing header structure - stops multiple
  882. // threads clashing while modifying or changing auto-proxy information
  883. //
  884. CRITICAL_SECTION _CritSec;
  885. //
  886. // _apsState - Used to track the state of this object state, for
  887. // syncronization purposes, ( ie when to go async or not )
  888. //
  889. AUTO_PROXY_STATE _apsState;
  890. //
  891. // _dwWaitTimeOut - time till WaitForSingleObject times out.
  892. //
  893. DWORD _dwWaitTimeOut;
  894. //
  895. // _fEnableReload - Forces a reload of auto-proxy files every X seconds.
  896. //
  897. BOOL _fEnableReload;
  898. //
  899. // _dwLastThreadAccess - Last GetTickCount(). Used to calculate a basic
  900. // timer for reloads of auto-proxy files.
  901. //
  902. DWORD _dwLastThreadAccess;
  903. //
  904. // _lpszUserAgent - User agent passed in.
  905. //
  906. LPSTR _lpszUserAgent;
  907. //
  908. // _hInstUrlmon - to get user agent from
  909. //
  910. HINSTANCE _hInstUrlmon;
  911. //
  912. // _fModifiedInProcess - TRUE, if the settings passed in, SHOULD NOT BE PERSISTED to the registry
  913. //
  914. BOOL _fModifiedInProcess;
  915. //
  916. // _dwUpdatedProxySettingsVersion - an counter that is updated to match the current version.
  917. // that has been refreshed to. Used to note when we need to refresh proxy settings.
  918. //
  919. DWORD _dwUpdatedProxySettingsVersion;
  920. VOID
  921. ResetTimerCounter(
  922. BOOL fEnableTimer,
  923. DWORD dwWaitTimeOut
  924. )
  925. {
  926. _fEnableReload = fEnableTimer ;
  927. if ( _fEnableReload )
  928. {
  929. _dwWaitTimeOut = dwWaitTimeOut;
  930. _dwLastThreadAccess = GetTickCountWrap();
  931. INET_ASSERT(_dwWaitTimeOut != 0);
  932. }
  933. else
  934. {
  935. _dwWaitTimeOut = g_bHibernating ? (DWORD(MAX_RELOAD_DELAY) * 1000 * 60) : DEFAULT_AUTO_PROXY_THREAD_TIME_OUT;
  936. }
  937. }
  938. BOOL
  939. ChkForAndUpdateTimerCounter(
  940. VOID
  941. )
  942. {
  943. BOOL fTimetoUpdate = FALSE;
  944. if ( _fEnableReload )
  945. {
  946. DWORD dwMsecsElapsed = GetTickCountWrap() - _dwLastThreadAccess;
  947. if ( dwMsecsElapsed >= _dwWaitTimeOut )
  948. {
  949. _dwWaitTimeOut = 0;
  950. fTimetoUpdate = TRUE;
  951. }
  952. else
  953. {
  954. fTimetoUpdate = FALSE;
  955. _dwWaitTimeOut -= dwMsecsElapsed;
  956. }
  957. _dwLastThreadAccess = GetTickCountWrap();
  958. }
  959. else
  960. {
  961. _dwWaitTimeOut = g_bHibernating ? (DWORD(MAX_RELOAD_DELAY) * 1000 * 60) : DEFAULT_AUTO_PROXY_THREAD_TIME_OUT;
  962. }
  963. return fTimetoUpdate;
  964. }
  965. DWORD
  966. ReadAutoProxyRegistrySettings(
  967. VOID
  968. );
  969. VOID
  970. SelectAutoProxy(
  971. AUTO_PROXY_LIST_ENTRY * pSelectedEntry
  972. )
  973. {
  974. _pSelectedAutoProxyEntry = pSelectedEntry;
  975. }
  976. VOID SetState(AUTO_PROXY_STATE apsState) {
  977. _apsState = apsState;
  978. }
  979. AUTO_PROXY_STATE GetState(VOID) {
  980. return _apsState;
  981. }
  982. //
  983. // _AsyncQueueList - serialized list of AUTO_PROXY_ASYNC_MSG objects
  984. //
  985. SERIALIZED_LIST _AsyncQueueList;
  986. //
  987. // _hAutoProxyThread - handle to thread that processes Auto-Proxy commands.
  988. //
  989. HANDLE _hAutoProxyThread;
  990. //
  991. // _hAutoProxyThreadEvent - handle to event that will become signaled when
  992. // new auto-proxy messages are to be processed
  993. //
  994. HANDLE _hAutoProxyThreadEvent;
  995. //
  996. // _hAutoProxyStartEvent - handle to event that will be used to block
  997. // until the auto-proxy thread starts to run.
  998. //
  999. HANDLE _hAutoProxyStartEvent;
  1000. //
  1001. // _dwAutoProxyCurrentThreadId - thread ID of our Auto-Proxy Thread.
  1002. //
  1003. DWORD _dwAutoProxyThreadId;
  1004. //
  1005. // _hInternetAbortHandle - handle used to forcibly unblock, and thus shutdown auto-proxy
  1006. //
  1007. HINTERNET _hInternetAbortHandle;
  1008. //
  1009. // _fInAutoProxyThreadShutDown - Set to TRUE when attempting to shutdown Auto-Proxy thread.
  1010. //
  1011. BOOL _fInAutoProxyThreadShutDown;
  1012. VOID
  1013. SafeThreadShutdown(
  1014. BOOL fItsTheFinalShutDown
  1015. );
  1016. DWORD
  1017. StartDownloadOfProxyInfo(
  1018. IN BOOL fForceRefresh
  1019. );
  1020. DWORD
  1021. DownloadProxyInfo(
  1022. IN LPCSTR lpszAutoProxy,
  1023. IN BOOL fForceRefresh
  1024. );
  1025. DWORD
  1026. DoNestedProxyInfoDownload(
  1027. IN LPCSTR lpszAutoProxy,
  1028. IN LPINTERNET_PROXY_INFO_EX lpProxySettings,
  1029. IN BOOL fForceRefresh
  1030. );
  1031. DWORD
  1032. StartBackroundDetectionIfNeeded(
  1033. VOID
  1034. );
  1035. DWORD
  1036. GetAutoProxyStringEntry(
  1037. IN LPSTR lpszRegName,
  1038. IN OUT LPSTR * lplpszAllocatedRegValue
  1039. );
  1040. DWORD
  1041. GetHostAddresses(
  1042. DWORD ** ppdwDetectedInterfaceIp,
  1043. DWORD * pdwDetectedInterfaceIpCount
  1044. ) ;
  1045. BOOL
  1046. IsExpiredUrl(
  1047. LPCSTR lpszUrl
  1048. );
  1049. VOID
  1050. SetExpiredUrl(
  1051. LPCSTR lpszUrl
  1052. );
  1053. BOOL IsModifiedInProcess(VOID) {
  1054. return _fModifiedInProcess;
  1055. }
  1056. public:
  1057. AUTO_PROXY_DLLS() {
  1058. DEBUG_ENTER((DBG_OBJECTS,
  1059. None,
  1060. "AUTO_PROXY_DLLS",
  1061. ""
  1062. ));
  1063. InitializeSerializedList(&_List);
  1064. InitializeSerializedList(&_AsyncQueueList);
  1065. //
  1066. // Warning: Initalize vars to NULL, BEFORE AddListFromRegistry is called.
  1067. //
  1068. _pSelectedAutoProxyEntry = NULL;
  1069. _hAutoProxyThreadEvent = NULL;
  1070. _hAutoProxyThread = NULL;
  1071. _hAutoProxyStartEvent = NULL;
  1072. _apsState = AUTO_PROXY_DISABLED;
  1073. _dwWaitTimeOut = g_bHibernating ? (DWORD(MAX_RELOAD_DELAY) * 1000 * 60) : DEFAULT_AUTO_PROXY_THREAD_TIME_OUT;
  1074. _fEnableReload = FALSE;
  1075. _hInternetAbortHandle = NULL;
  1076. _fInAutoProxyThreadShutDown = FALSE;
  1077. _dwUpdatedProxySettingsVersion = 0;
  1078. //_adMode = APDETECT_CHECK_DISABLE; // default for now
  1079. //_dwLastIPHost = 0;
  1080. //_dwLastRunCount = 0;
  1081. //_lpszLastKnownGoodAutoConfigUrl = NULL;
  1082. //_fNeedInitialDetect = TRUE;
  1083. //
  1084. // Zero out our settings structure
  1085. //
  1086. memset((void *) &_ProxySettings, 0, sizeof(_ProxySettings));
  1087. _pTempProxySettings = NULL;
  1088. _lpszUserAgent = NULL;
  1089. _hInstUrlmon = NULL;
  1090. //_fNeedsDownload = TRUE;
  1091. //_fAllQueriesMustGoAsync = FALSE;
  1092. InitializeCriticalSection(&_CritSec);
  1093. _Error = ReadAutoProxyRegistrySettings();
  1094. DEBUG_LEAVE(0);
  1095. }
  1096. ~AUTO_PROXY_DLLS() {
  1097. DEBUG_ENTER((DBG_OBJECTS,
  1098. None,
  1099. "~AUTO_PROXY_DLLS",
  1100. NULL
  1101. ));
  1102. INET_ASSERT(!_fInAutoProxyThreadShutDown); // should have shut down thread before hitting destructor
  1103. DestroyAutoProxyDll(FALSE); // only destroys reg vars.
  1104. DestroyAutoProxyMsgQueue();
  1105. WipeProxySettings();
  1106. TerminateSerializedList(&_AsyncQueueList);
  1107. TerminateSerializedList(&_List);
  1108. DeleteCriticalSection(&_CritSec);
  1109. if ( _lpszUserAgent ) {
  1110. FREE_MEMORY(_lpszUserAgent);
  1111. }
  1112. if (_hInstUrlmon)
  1113. {
  1114. FreeLibrary (_hInstUrlmon);
  1115. }
  1116. DEBUG_LEAVE(0);
  1117. }
  1118. VOID
  1119. ActivateThread()
  1120. {
  1121. if (_hAutoProxyThreadEvent)
  1122. {
  1123. SetEvent(_hAutoProxyThreadEvent);
  1124. }
  1125. }
  1126. VOID
  1127. DestroyAutoProxyDll(
  1128. IN BOOL fUnloadDlls
  1129. )
  1130. {
  1131. LockAutoProxy();
  1132. LockSerializedList(&_List);
  1133. while (!IsSerializedListEmpty(&_List)) {
  1134. //
  1135. // remove the PROXY_BYPASS_LIST_ENTRY at the head of the serialized
  1136. // list
  1137. //
  1138. LPVOID entry = SlDequeueHead(&_List);
  1139. AUTO_PROXY_LIST_ENTRY *pAutoProxyDllEntry;
  1140. //
  1141. // entry should not be NULL - IsSerializedListEmpty() told us we
  1142. // could expect something
  1143. //
  1144. INET_ASSERT(entry != NULL);
  1145. pAutoProxyDllEntry = CONTAINING_RECORD(entry, AUTO_PROXY_LIST_ENTRY, _List);
  1146. if ( fUnloadDlls )
  1147. {
  1148. pAutoProxyDllEntry->UnloadEntry();
  1149. }
  1150. delete pAutoProxyDllEntry;
  1151. }
  1152. UnlockSerializedList(&_List);
  1153. UnlockAutoProxy();
  1154. }
  1155. VOID
  1156. DestroyAutoProxyMsgQueue(
  1157. VOID
  1158. )
  1159. {
  1160. //
  1161. // Destroy any Async Queue.
  1162. //
  1163. LockSerializedList(&_AsyncQueueList);
  1164. while (!IsSerializedListEmpty(&_AsyncQueueList)) {
  1165. //INET_ASSERT(IsOnAsyncAutoProxyThread());
  1166. //
  1167. // remove the PROXY_BYPASS_LIST_ENTRY at the head of the serialized
  1168. // list
  1169. //
  1170. LPVOID entry = SlDequeueHead(&_AsyncQueueList);
  1171. //
  1172. // entry should not be NULL - IsSerializedListEmpty() told us we
  1173. // could expect something
  1174. //
  1175. INET_ASSERT(entry != NULL);
  1176. //
  1177. // get the address of the object (should be the same as entry) and
  1178. // delete it
  1179. //
  1180. delete CONTAINING_RECORD(entry, AUTO_PROXY_ASYNC_MSG, _List);
  1181. }
  1182. UnlockSerializedList(&_AsyncQueueList);
  1183. }
  1184. VOID
  1185. WipeProxySettings(
  1186. LPINTERNET_PROXY_INFO_EX lpProxySettings
  1187. );
  1188. VOID
  1189. WipeProxySettings(VOID) {
  1190. WipeProxySettings(&_ProxySettings);
  1191. }
  1192. DWORD GetError(VOID) const {
  1193. return _Error;
  1194. }
  1195. VOID SetAbortHandle(HINTERNET hInternet)
  1196. {
  1197. _hInternetAbortHandle = hInternet;
  1198. }
  1199. VOID AbortAutoProxy(VOID)
  1200. {
  1201. if ( _hInternetAbortHandle ) {
  1202. InternetCloseHandle(_hInternetAbortHandle);
  1203. }
  1204. }
  1205. BOOL
  1206. SelectAutoProxyByFileExtension(
  1207. LPCSTR lpszAutoProxyPath
  1208. );
  1209. BOOL
  1210. SelectAutoProxyByDefault(
  1211. VOID
  1212. );
  1213. BOOL
  1214. SelectAutoProxyByMime(
  1215. IN LPSTR lpszMimeType
  1216. );
  1217. BOOL
  1218. IsAutoProxy(
  1219. VOID
  1220. )
  1221. {
  1222. BOOL fIsAutoProxy;
  1223. LockAutoProxy();
  1224. fIsAutoProxy = ! IsSerializedListEmpty(&_List);
  1225. UnlockAutoProxy();
  1226. return fIsAutoProxy;
  1227. }
  1228. BOOL IsAutoProxyThreadReadyForRequests(
  1229. VOID
  1230. )
  1231. {
  1232. BOOL fReady;
  1233. LockAutoProxy();
  1234. fReady = (GetState() == AUTO_PROXY_ENABLED) ? TRUE : FALSE;
  1235. UnlockAutoProxy();
  1236. return fReady;
  1237. }
  1238. AUTO_PROXY_LIST_ENTRY *
  1239. GetSelectedAutoProxyEntry(
  1240. VOID
  1241. )
  1242. {
  1243. return _pSelectedAutoProxyEntry;
  1244. }
  1245. VOID LockAutoProxy(VOID) {
  1246. EnterCriticalSection(&_CritSec);
  1247. }
  1248. VOID UnlockAutoProxy(VOID) {
  1249. LeaveCriticalSection(&_CritSec);
  1250. }
  1251. BOOL IsOnAsyncAutoProxyThread(VOID) const {
  1252. return ( GetCurrentThreadId() == _dwAutoProxyThreadId );
  1253. }
  1254. BOOL IsProxyAutoDetectEnabled(LPINTERNET_PROXY_INFO_EX lpProxySettings) {
  1255. return (lpProxySettings->dwFlags & PROXY_TYPE_AUTO_DETECT);
  1256. }
  1257. BOOL IsProxyAutoDetectEnabled(VOID) {
  1258. return (IsProxyAutoDetectEnabled(&_ProxySettings));
  1259. }
  1260. BOOL IsProxyAutoConfigEnabled(LPINTERNET_PROXY_INFO_EX lpProxySettings) {
  1261. return (lpProxySettings->dwFlags & PROXY_TYPE_AUTO_PROXY_URL);
  1262. }
  1263. BOOL IsProxyAutoConfigEnabled(VOID) {
  1264. return (IsProxyAutoConfigEnabled(&_ProxySettings));
  1265. }
  1266. BOOL
  1267. IsConfigValidForAutoProxyThread(
  1268. VOID
  1269. );
  1270. BOOL
  1271. IsProxyAutoDetectNeeded(
  1272. LPINTERNET_PROXY_INFO_EX lpProxySettings
  1273. );
  1274. BOOL
  1275. IsStaticFallbackEnabled(
  1276. VOID
  1277. );
  1278. DWORD
  1279. CheckForTimerConfigChanges(
  1280. IN DWORD dwMinsToPoll
  1281. );
  1282. BOOL
  1283. IsAutoProxyEnabled(
  1284. VOID
  1285. );
  1286. BOOL
  1287. IsAutoProxyGetProxyInfoCallNeeded(
  1288. IN AUTO_PROXY_ASYNC_MSG *pQueryForInfo
  1289. );
  1290. DWORD
  1291. QueueAsyncAutoProxyRequest(
  1292. IN OUT AUTO_PROXY_ASYNC_MSG **ppQueryForInfo
  1293. );
  1294. DWORD
  1295. ProcessProxyQueryForInfo(
  1296. IN OUT AUTO_PROXY_ASYNC_MSG **ppQueryForInfo
  1297. ) ;
  1298. DWORD
  1299. DoThreadProcessing(
  1300. VOID
  1301. );
  1302. DWORD
  1303. ProcessAsyncAutoProxyRequest(
  1304. VOID
  1305. );
  1306. DWORD
  1307. SignalAsyncRequestCompleted(
  1308. IN AUTO_PROXY_ASYNC_MSG *pQueryForInfo
  1309. );
  1310. VOID
  1311. FreeAutoProxyInfo(
  1312. VOID
  1313. );
  1314. DWORD
  1315. SetProxySettings(
  1316. IN LPINTERNET_PROXY_INFO_EX lpProxySettings,
  1317. IN BOOL fModifiedInProcess,
  1318. IN BOOL fAllowOverwrite
  1319. );
  1320. DWORD
  1321. GetProxySettings(
  1322. OUT LPINTERNET_PROXY_INFO_EX lpProxySettings,
  1323. IN BOOL fCheckVersion = FALSE
  1324. );
  1325. BOOL
  1326. GetAutoProxyThreadSettings(
  1327. OUT LPINTERNET_PROXY_INFO_EX lpProxySettings
  1328. )
  1329. {
  1330. if ( _pTempProxySettings )
  1331. {
  1332. *lpProxySettings = *_pTempProxySettings;
  1333. return TRUE;
  1334. }
  1335. //else
  1336. return FALSE;
  1337. }
  1338. BOOL
  1339. SetAutoProxyThreadSettings(
  1340. OUT LPINTERNET_PROXY_INFO_EX lpProxySettings
  1341. )
  1342. {
  1343. if ( _pTempProxySettings )
  1344. {
  1345. *_pTempProxySettings = *lpProxySettings;
  1346. return TRUE;
  1347. }
  1348. // else
  1349. return FALSE;
  1350. }
  1351. DWORD
  1352. RefreshProxySettings(
  1353. IN BOOL fForceRefresh
  1354. );
  1355. DWORD
  1356. QueryProxySettings(
  1357. IN OUT AUTO_PROXY_ASYNC_MSG **ppQueryForInfo
  1358. );
  1359. VOID
  1360. SaveDetectedProxySettings(
  1361. IN LPINTERNET_PROXY_INFO_EX lpProxySettings,
  1362. IN BOOL fNeedHostIPChk
  1363. );
  1364. };
  1365. //
  1366. // external func declariations, note that the DLL does not have to export the full set of these
  1367. // functions, rather the DLL can export only the functions it impliments.
  1368. //
  1369. BOOL
  1370. CALLBACK
  1371. InternetProxyInfoInvalid ( // NOT implimented
  1372. IN LPSTR lpszMime,
  1373. IN LPSTR lpszUrl,
  1374. IN DWORD dwUrlLength,
  1375. IN LPSTR lpszProxyHostName,
  1376. IN DWORD dwProxyHostNameLength
  1377. );
  1378. EXTERN_C BOOL CALLBACK
  1379. AUTOCONF_InternetDeInitializeAutoProxyDll(
  1380. IN LPSTR lpszMime,
  1381. IN DWORD dwReserved
  1382. );
  1383. EXTERN_C BOOL CALLBACK
  1384. InternetGetProxyInfo(
  1385. IN LPCSTR lpszUrl,
  1386. IN DWORD dwUrlLength,
  1387. IN LPSTR lpszUrlHostName,
  1388. IN DWORD dwUrlHostNameLength,
  1389. OUT LPSTR * lplpszProxyHostName,
  1390. OUT LPDWORD lpdwProxyHostNameLength
  1391. ) ;
  1392. BOOL
  1393. CALLBACK
  1394. InternetGetProxyInfoEx(
  1395. IN INTERNET_SCHEME tUrlProtocol,
  1396. IN LPCSTR lpszUrl,
  1397. IN DWORD dwUrlLength,
  1398. IN LPSTR lpszUrlHostName,
  1399. IN DWORD dwUrlHostNameLength,
  1400. IN INTERNET_PORT nUrlPort,
  1401. OUT LPINTERNET_SCHEME lptProxyScheme,
  1402. OUT LPSTR * lplpszProxyHostName,
  1403. OUT LPDWORD lpdwProxyHostNameLength,
  1404. OUT LPINTERNET_PORT lpProxyHostPort
  1405. ) ;
  1406. EXTERN_C BOOL CALLBACK
  1407. AUTOCONF_InternetInitializeAutoProxyDll(
  1408. IN DWORD dwVersion,
  1409. IN LPSTR lpszDownloadedTempFile,
  1410. IN LPSTR lpszMime,
  1411. IN AUTO_PROXY_HELPER_APIS *pAutoProxyCallbacks,
  1412. IN DWORD dwReserved
  1413. );
  1414. INTERNETAPI_(BOOL)
  1415. DetectAutoProxyUrl(
  1416. IN OUT LPSTR lpszAutoProxyUrl,
  1417. IN DWORD dwAutoProxyUrlLength,
  1418. IN DWORD dwDetectFlags
  1419. );
  1420. EXTERN_C BOOL CALLBACK
  1421. InternetInitializeAutoProxyDll(
  1422. DWORD dwReserved
  1423. );
  1424. #endif /* _AUTOPROX_HXX_ */