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.

723 lines
17 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. //
  23. // Flags stored in registry for Auto-Proxy Entry
  24. //
  25. #define AUTOPROX_FLAGS_SINGLE_THREAD 0x01
  26. //
  27. // defines ...
  28. //
  29. #define DEFAULT_AUTO_PROXY_THREAD_TIME_OUT 30000 // 30 secs BUGBUG, up before checkin
  30. //
  31. // PROXY_MESSAGE_TYPE - this represents a type of query that is used
  32. // to submit a request through proxy "knowledge-base" ( ie script, db, etc )
  33. // for async processing of Java-Script auto-proxy scripts.
  34. //
  35. typedef enum {
  36. PROXY_MSG_INVALID,
  37. PROXY_MSG_INIT,
  38. PROXY_MSG_DEINIT,
  39. PROXY_MSG_SELF_DESTRUCT,
  40. PROXY_MSG_GET_PROXY_INFO,
  41. PROXY_MSG_SET_BAD_PROXY
  42. } PROXY_MESSAGE_TYPE;
  43. //
  44. // PROXY_MESSAGE_ALLOC_TYPE - this is needed to track what allocation of member vars
  45. // are currently used in my object. This allows us to use stack vars
  46. // for simple, local calls, but then have allocation done-on-the-fly
  47. // when we need to queue the message.
  48. //
  49. typedef enum {
  50. MSG_ALLOC_NONE,
  51. MSG_ALLOC_STACK_ONLY,
  52. MSG_ALLOC_HEAP,
  53. MSG_ALLOC_HEAP_MSG_OBJ_OWNS
  54. } PROXY_MESSAGE_ALLOC_TYPE;
  55. //
  56. // AUTO_PROXY_STATE - is used to track the state of the auto-proxy list object
  57. // in order to maintain syncronization across readers and writers.
  58. //
  59. typedef enum {
  60. AUTO_PROXY_DISABLED,
  61. AUTO_PROXY_BLOCKED,
  62. AUTO_PROXY_PENDING, // blocked, but we can still fallback to static settings
  63. AUTO_PROXY_ENABLED
  64. } AUTO_PROXY_STATE;
  65. class BAD_PROXY_LIST; // forward decl
  66. //
  67. // PROXY_STATE - keeps track of multiple proxies stored in a Netscape Style
  68. // proxy list string format. Ex:
  69. // "PROXY itgproxy:80; PROXY proxy:80; PROXY 192.168.100.2:1080; SOCKS 192.168.100.2; DIRECT"
  70. //
  71. // Can also be used to link the GetProxyInfo return with a failure in the proxies it gave.
  72. // This needed so we call back into an Auto-Proxy DLL letting them know that we failed
  73. // to be able to utilize its auto-proxy that it gave us.
  74. //
  75. class PROXY_STATE {
  76. private:
  77. //
  78. // _lpszAutoProxyList - List, or Proxy that we are tracking.
  79. //
  80. LPSTR _lpszAutoProxyList;
  81. //
  82. // _dwcbAutoProxyList - size of _lpszAutoProxyList.
  83. //
  84. DWORD _dwcbAutoProxyList;
  85. //
  86. // _lpszOffset - Current Offset into _lpszAutoProxyList
  87. //
  88. LPSTR _lpszOffset;
  89. //
  90. // _lpszLastProxyUsed - Tracks the last proxy that was returned.
  91. //
  92. LPSTR _lpszLastProxyUsed;
  93. //
  94. // _LastProxyUsedPort - Last used Internet Port on the Proxy
  95. //
  96. INTERNET_PORT _LastProxyUsedPort;
  97. //
  98. // _Error - Error code in constructor.
  99. //
  100. DWORD _Error;
  101. //
  102. // _fIsMultiProxyList - TRUE if we a Netscape type list of proxies, as opposed to a simple proxyhostname string.
  103. //
  104. BOOL _fIsMultiProxyList;
  105. //
  106. // _fIsAnotherProxyAvail - TRUE if we have another proxy to process
  107. //
  108. BOOL _fIsAnotherProxyAvail;
  109. //
  110. // tProxyScheme - for the non-multi proxy case we track the type of proxy we are storing.
  111. //
  112. INTERNET_SCHEME _tProxyScheme;
  113. //
  114. // ProxyHostPort - for the non-multi proxy case we track the host port.
  115. //
  116. INTERNET_PORT _proxyHostPort;
  117. public:
  118. PROXY_STATE(
  119. LPSTR lpszAutoProxyList,
  120. DWORD dwcbAutoProxyList,
  121. BOOL fIsMultiProxyList,
  122. INTERNET_SCHEME tProxyScheme,
  123. INTERNET_PORT proxyHostPort
  124. )
  125. {
  126. _lpszAutoProxyList = NULL;
  127. _dwcbAutoProxyList = 0;
  128. _lpszOffset = NULL;
  129. _Error = ERROR_SUCCESS;
  130. _lpszLastProxyUsed = NULL;
  131. _LastProxyUsedPort = INTERNET_DEFAULT_HTTP_PORT;
  132. _fIsMultiProxyList = fIsMultiProxyList;
  133. _tProxyScheme = tProxyScheme;
  134. _proxyHostPort = proxyHostPort;
  135. _fIsAnotherProxyAvail = FALSE;
  136. if ( lpszAutoProxyList &&
  137. dwcbAutoProxyList > 0 )
  138. {
  139. _lpszAutoProxyList = (LPSTR)
  140. ALLOCATE_MEMORY(LMEM_FIXED, dwcbAutoProxyList+1);
  141. if ( _lpszAutoProxyList )
  142. {
  143. lstrcpyn(_lpszAutoProxyList, lpszAutoProxyList, dwcbAutoProxyList );
  144. _lpszAutoProxyList[dwcbAutoProxyList] = '\0';
  145. _dwcbAutoProxyList = dwcbAutoProxyList;
  146. _lpszOffset = _lpszAutoProxyList;
  147. }
  148. else
  149. {
  150. _Error = ERROR_NOT_ENOUGH_MEMORY;
  151. }
  152. }
  153. }
  154. ~PROXY_STATE()
  155. {
  156. DEBUG_ENTER((DBG_OBJECTS,
  157. None,
  158. "~PROXY_STATE",
  159. NULL
  160. ));
  161. if ( _lpszAutoProxyList )
  162. {
  163. FREE_MEMORY(_lpszAutoProxyList );
  164. _lpszAutoProxyList = NULL;
  165. }
  166. DEBUG_LEAVE(0);
  167. }
  168. DWORD
  169. GetError(VOID) const
  170. {
  171. return _Error;
  172. }
  173. BOOL
  174. IsEmpty(VOID) const
  175. {
  176. return (!_lpszOffset || *_lpszOffset == '\0' ) ? TRUE : FALSE;
  177. }
  178. BOOL
  179. IsAnotherProxyAvail(VOID) const
  180. {
  181. return _fIsAnotherProxyAvail;
  182. }
  183. LPSTR
  184. GetLastProxyUsed(INTERNET_PORT *pProxyPort)
  185. {
  186. *pProxyPort = _LastProxyUsedPort;
  187. return _lpszLastProxyUsed;
  188. }
  189. BOOL
  190. GetNextProxy(
  191. IN INTERNET_SCHEME tUrlScheme,
  192. IN BAD_PROXY_LIST & BadProxyList,
  193. OUT LPINTERNET_SCHEME lptProxyScheme,
  194. OUT LPSTR * lplpszProxyHostName,
  195. OUT LPBOOL lpbFreeProxyHostName,
  196. OUT LPDWORD lpdwProxyHostNameLength,
  197. OUT LPINTERNET_PORT lpProxyHostPort
  198. );
  199. };
  200. //
  201. // AUTO_PROXY_ASYNC_MSG - this object is used to pass queries for proxy information across
  202. // from requestors (HTTP_REQUEST_HANDLE_OBJECT, parseUrl, etc) to responders
  203. // (AutoProxy DLL, PROXY_INFO object) who can process the request in a syncronious
  204. // or asyncrouns manner.
  205. //
  206. class AUTO_PROXY_ASYNC_MSG {
  207. public: //BUGBUG, I'm being lazy, need to make methods to guard access
  208. //
  209. // _List - We're a list entry on a queue. But we don't always have to be,
  210. // We can be borne a structure that justs gets passed around and is never
  211. // queued.
  212. //
  213. LIST_ENTRY _List;
  214. //
  215. // _tUrlProtocol - Protocol that this request is using.
  216. //
  217. INTERNET_SCHEME _tUrlProtocol;
  218. //
  219. // _lpszUrl - The requested URL that we are navigating to.
  220. //
  221. LPSTR _lpszUrl;
  222. //
  223. // _dwUrlLength - The size of the URL.
  224. //
  225. DWORD _dwUrlLength;
  226. //
  227. // _lpszUrlHostName - The host name found in the URL.
  228. //
  229. LPSTR _lpszUrlHostName;
  230. //
  231. // _dwUrlHostNameLength - Host name Length
  232. //
  233. DWORD _dwUrlHostNameLength;
  234. //
  235. // _nUrlPort - Dest port used on this Url.
  236. //
  237. INTERNET_PORT _nUrlPort;
  238. //
  239. // _tProxyScheme - Type of proxy we will use. ( HTTP, HTTPS, etc )
  240. //
  241. INTERNET_SCHEME _tProxyScheme;
  242. //
  243. // _lpszProxyHostName - Host name of the proxy we are to use.
  244. //
  245. LPSTR _lpszProxyHostName;
  246. //
  247. // _bFreeProxyHostName - TRUE if _lpszProxyHostName is a copy
  248. //
  249. BOOL _bFreeProxyHostName;
  250. //
  251. // _dwProxyHostNameLength - Proxy Host name length.
  252. //
  253. DWORD _dwProxyHostNameLength;
  254. //
  255. // _nProxyHostPort - Proxy port to use
  256. //
  257. INTERNET_PORT _nProxyHostPort;
  258. //
  259. // _pProxyState - State for enumerating multiple proxies.
  260. //
  261. PROXY_STATE *_pProxyState;
  262. //
  263. // _pmProxyQuery - The Action aka Query we're are doing with this message.
  264. //
  265. PROXY_MESSAGE_TYPE _pmProxyQuery;
  266. //
  267. // _pmaAllocMode - Used to track who owns the allocated string ptrs.
  268. //
  269. PROXY_MESSAGE_ALLOC_TYPE _pmaAllocMode;
  270. //
  271. // _dwQueryResult - TRUE if we are going through a proxy
  272. //
  273. DWORD _dwQueryResult;
  274. //
  275. // _Error - Return code after this call is made.
  276. //
  277. DWORD _Error;
  278. //
  279. // dwProxyVersion - Proxy Verion this was issue a result for
  280. //
  281. DWORD _dwProxyVersion;
  282. VOID SetVersion(VOID) {
  283. _dwProxyVersion = GlobalProxyVersionCount;
  284. }
  285. DWORD GetVersion(VOID) {
  286. return _dwProxyVersion;
  287. }
  288. //
  289. // _MessageFlags - Various
  290. //
  291. union {
  292. struct {
  293. //
  294. // DontWantProxyStrings, don't waste time with allocating strings for my result,
  295. // since I all I care about is generalized proxy info (ie do I have a proxy for ...).
  296. //
  297. DWORD DontWantProxyStrings : 1;
  298. //
  299. // BlockUntilCompletetion, don't return from an async call until the async thread has
  300. // completed processing my proxy query.
  301. //
  302. DWORD BlockUntilCompletetion : 1;
  303. //
  304. // AvoidAsyncCall, don't go async under any curcumstances, so we will return
  305. // what every we can get, even if this means giving incorrect data.
  306. //
  307. DWORD AvoidAsyncCall : 1;
  308. //
  309. // BlockedOnFsm, true a fsm is blocked on this message to complete
  310. //
  311. DWORD BlockedOnFsm : 1 ;
  312. //
  313. // QueryOnCallback, TRUE if we're making a call with this object
  314. // on a FSM callback. Basically we've received results from
  315. // the async thread, but we need to do a final a call so
  316. // the results can be parsed out.
  317. //
  318. DWORD QueryOnCallback : 1;
  319. //
  320. // ForceRefresh, TRUE if we are to force a refresh of cached settings and scripts.
  321. //
  322. DWORD ForceRefresh : 1;
  323. //
  324. // ShowIndication, TRUE if we indicate via callback
  325. // to the user that we performing auto-detection
  326. //
  327. DWORD ShowIndication : 1;
  328. //
  329. // BackroundDetectionPending, TRUE if a backround detection
  330. // is being done while this page is loading
  331. //
  332. DWORD BackroundDetectionPending : 1;
  333. //
  334. // CanCacheResult - TRUE if this result can be cached
  335. //
  336. DWORD CanCacheResult : 1;
  337. } Flags;
  338. //
  339. // Dword - used in initialization ONLY, do NOT use ELSEWHERE !
  340. //
  341. DWORD Dword;
  342. } _MessageFlags;
  343. //public:
  344. AUTO_PROXY_ASYNC_MSG(
  345. IN INTERNET_SCHEME isUrlScheme,
  346. IN LPSTR lpszUrl,
  347. IN LPSTR lpszUrlHostName,
  348. IN DWORD dwUrlHostNameLength
  349. );
  350. AUTO_PROXY_ASYNC_MSG(
  351. IN INTERNET_SCHEME isUrlScheme,
  352. IN LPSTR lpszUrl,
  353. IN DWORD dwUrlLength,
  354. IN LPSTR lpszUrlHostName,
  355. IN DWORD dwUrlHostNameLength,
  356. IN INTERNET_PORT nUrlPort
  357. );
  358. AUTO_PROXY_ASYNC_MSG(
  359. PROXY_MESSAGE_TYPE pmProxyQuery
  360. );
  361. AUTO_PROXY_ASYNC_MSG(
  362. AUTO_PROXY_ASYNC_MSG *pStaticAutoProxy
  363. );
  364. AUTO_PROXY_ASYNC_MSG(
  365. IN INTERNET_SCHEME isUrlScheme,
  366. IN LPSTR lpszUrlHostName,
  367. IN DWORD dwUrlHostNameLength
  368. );
  369. AUTO_PROXY_ASYNC_MSG(
  370. VOID
  371. )
  372. {
  373. Initalize();
  374. }
  375. ~AUTO_PROXY_ASYNC_MSG(
  376. VOID
  377. );
  378. VOID Initalize(
  379. VOID
  380. )
  381. {
  382. InitializeListHead(&_List);
  383. // this is odd, we should just memset it.
  384. _tUrlProtocol = INTERNET_SCHEME_UNKNOWN;
  385. _lpszUrl = NULL;
  386. _dwUrlLength = 0;
  387. _lpszUrlHostName = NULL;
  388. _dwUrlHostNameLength = 0;
  389. _nUrlPort = INTERNET_INVALID_PORT_NUMBER;
  390. _tProxyScheme = INTERNET_SCHEME_UNKNOWN;
  391. _lpszProxyHostName = NULL;
  392. _bFreeProxyHostName = FALSE;
  393. _dwProxyHostNameLength = 0;
  394. _nProxyHostPort = INTERNET_INVALID_PORT_NUMBER;
  395. _pmProxyQuery = PROXY_MSG_INVALID;
  396. _pmaAllocMode = MSG_ALLOC_NONE;
  397. _pProxyState = NULL;
  398. _dwQueryResult = FALSE;
  399. _Error = ERROR_SUCCESS;
  400. _dwProxyVersion = 0;
  401. _MessageFlags.Dword = 0;
  402. }
  403. VOID
  404. SetProxyMsg(
  405. IN INTERNET_SCHEME isUrlScheme,
  406. IN LPSTR lpszUrl,
  407. IN DWORD dwUrlLength,
  408. IN LPSTR lpszUrlHostName,
  409. IN DWORD dwUrlHostNameLength,
  410. IN INTERNET_PORT nUrlPort
  411. );
  412. BOOL IsProxyEnumeration(VOID) const {
  413. if ( _pProxyState &&
  414. !IsDontWantProxyStrings() &&
  415. !_pProxyState->IsEmpty() )
  416. {
  417. return TRUE;
  418. }
  419. return FALSE;
  420. }
  421. BOOL IsAlloced(VOID) const {
  422. return ( _pmaAllocMode == MSG_ALLOC_HEAP ||
  423. _pmaAllocMode == MSG_ALLOC_HEAP_MSG_OBJ_OWNS ) ?
  424. TRUE : FALSE;
  425. }
  426. BOOL IsUrl(VOID) const {
  427. return (_lpszUrl && _dwUrlLength > 0 );
  428. }
  429. BOOL IsUseProxy(VOID) const {
  430. return _dwQueryResult;
  431. }
  432. VOID SetUseProxy(BOOL Value) {
  433. _dwQueryResult = Value;
  434. }
  435. INTERNET_SCHEME GetProxyScheme(VOID) const {
  436. return _tProxyScheme;
  437. }
  438. INTERNET_SCHEME GetUrlScheme(VOID) const {
  439. return _tUrlProtocol;
  440. }
  441. BOOL IsShowIndication(VOID) const {
  442. return (BOOL) _MessageFlags.Flags.ShowIndication;
  443. }
  444. VOID SetShowIndication(BOOL Value) {
  445. _MessageFlags.Flags.ShowIndication = (Value) ? TRUE : FALSE;
  446. }
  447. BOOL IsBackroundDetectionPending(VOID) const {
  448. return (BOOL) _MessageFlags.Flags.BackroundDetectionPending;
  449. }
  450. VOID SetBackroundDetectionPending(BOOL Value) {
  451. _MessageFlags.Flags.BackroundDetectionPending = (Value) ? TRUE : FALSE;
  452. }
  453. BOOL IsDontWantProxyStrings(VOID) const {
  454. return (BOOL) _MessageFlags.Flags.DontWantProxyStrings;
  455. }
  456. VOID SetDontWantProxyStrings(BOOL Value) {
  457. _MessageFlags.Flags.DontWantProxyStrings = (Value) ? TRUE : FALSE;
  458. }
  459. BOOL IsAvoidAsyncCall(VOID) const {
  460. return (BOOL) _MessageFlags.Flags.AvoidAsyncCall;
  461. }
  462. VOID SetAvoidAsyncCall(BOOL Value) {
  463. _MessageFlags.Flags.AvoidAsyncCall = (Value) ? TRUE : FALSE;
  464. }
  465. BOOL IsQueryOnCallback(VOID) const {
  466. return (BOOL) _MessageFlags.Flags.QueryOnCallback;
  467. }
  468. VOID SetQueryOnCallback(BOOL Value) {
  469. _MessageFlags.Flags.QueryOnCallback = (Value) ? TRUE : FALSE;
  470. }
  471. BOOL IsForceRefresh(VOID) const {
  472. return (BOOL) _MessageFlags.Flags.ForceRefresh;
  473. }
  474. VOID SetForceRefresh(BOOL Value) {
  475. _MessageFlags.Flags.ForceRefresh = (Value) ? TRUE : FALSE;
  476. }
  477. BOOL IsBlockUntilCompletetion(VOID) const {
  478. return (BOOL) _MessageFlags.Flags.BlockUntilCompletetion;
  479. }
  480. VOID SetBlockUntilCompletetion(BOOL Value) {
  481. _MessageFlags.Flags.BlockUntilCompletetion = (Value) ? TRUE : FALSE;
  482. }
  483. BOOL IsCanCacheResult(VOID) const {
  484. return (BOOL) _MessageFlags.Flags.CanCacheResult;
  485. }
  486. VOID SetCanCacheResult(BOOL Value) {
  487. _MessageFlags.Flags.CanCacheResult = (Value) ? TRUE : FALSE;
  488. }
  489. BOOL IsBlockedOnFsm(VOID) const {
  490. return (BOOL) _MessageFlags.Flags.BlockedOnFsm;
  491. }
  492. VOID SetBlockedOnFsm(BOOL Value) {
  493. _MessageFlags.Flags.BlockedOnFsm = (Value) ? TRUE : FALSE;
  494. }
  495. PROXY_MESSAGE_TYPE QueryForInfoMessage(VOID) const {
  496. return _pmProxyQuery;
  497. }
  498. DWORD GetError(VOID) {
  499. return _Error;
  500. }
  501. DWORD GetNextProxy(
  502. IN BAD_PROXY_LIST & BadProxyList
  503. )
  504. {
  505. BOOL fSuccess;
  506. INET_ASSERT(_pProxyState);
  507. fSuccess = _pProxyState->GetNextProxy(
  508. _tUrlProtocol,
  509. BadProxyList,
  510. &_tProxyScheme,
  511. &_lpszProxyHostName,
  512. &_bFreeProxyHostName,
  513. &_dwProxyHostNameLength,
  514. &_nProxyHostPort
  515. );
  516. SetUseProxy(fSuccess);
  517. return ERROR_SUCCESS;
  518. }
  519. };
  520. #endif /* _AUTOPROX_HXX_ */