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.

247 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. autoprox.cxx
  5. Abstract:
  6. Contains class implementation for auto-proxy DLLs which can extent WININET's
  7. abilities (logic) for deciding what proxies to use.
  8. How auto-proxy works:
  9. By offloading requests to a specialized Win32 Thread which picks
  10. up queued up message requests for Queries, Shutdown, and Initialization
  11. Contents:
  12. AUTO_PROXY_ASYNC_MSG
  13. Author:
  14. Arthur L Bierer (arthurbi) 17-Dec-1996
  15. Revision History:
  16. 17-Dec-1996 arthurbi
  17. Created
  18. --*/
  19. #include <wininetp.h>
  20. AUTO_PROXY_ASYNC_MSG::AUTO_PROXY_ASYNC_MSG(
  21. IN INTERNET_SCHEME isUrlScheme,
  22. IN LPSTR lpszUrl,
  23. IN LPSTR lpszUrlHostName,
  24. IN DWORD dwUrlHostNameLength
  25. )
  26. {
  27. URL_COMPONENTS urlComponents;
  28. Initalize();
  29. if ( lpszUrl )
  30. {
  31. _lpszUrl = lpszUrl;
  32. _dwUrlLength = lstrlen(lpszUrl);
  33. _tUrlProtocol = isUrlScheme;
  34. _pmProxyQuery = PROXY_MSG_GET_PROXY_INFO;
  35. _pmaAllocMode = MSG_ALLOC_STACK_ONLY;
  36. memset(&urlComponents, 0, sizeof(urlComponents));
  37. urlComponents.dwStructSize = sizeof(urlComponents);
  38. urlComponents.lpszHostName = lpszUrlHostName;
  39. urlComponents.dwHostNameLength = dwUrlHostNameLength;
  40. //
  41. // parse out the host name and port. The host name will be decoded; the
  42. // original URL will not be modified
  43. //
  44. if (WinHttpCrackUrlA(lpszUrl, 0, ICU_DECODE, &urlComponents))
  45. {
  46. _nUrlPort = urlComponents.nPort;
  47. _lpszUrlHostName = urlComponents.lpszHostName;
  48. _dwUrlHostNameLength = urlComponents.dwHostNameLength;
  49. if ( _tUrlProtocol == INTERNET_SCHEME_UNKNOWN )
  50. {
  51. _tUrlProtocol = urlComponents.nScheme;
  52. }
  53. }
  54. else
  55. {
  56. _Error = GetLastError();
  57. }
  58. }
  59. else
  60. {
  61. _Error = ERROR_NOT_ENOUGH_MEMORY;
  62. }
  63. }
  64. AUTO_PROXY_ASYNC_MSG::AUTO_PROXY_ASYNC_MSG(
  65. IN INTERNET_SCHEME isUrlScheme,
  66. IN LPSTR lpszUrlHostName,
  67. IN DWORD dwUrlHostNameLength
  68. )
  69. {
  70. Initalize();
  71. _tUrlProtocol = isUrlScheme;
  72. _pmProxyQuery = PROXY_MSG_GET_PROXY_INFO;
  73. _pmaAllocMode = MSG_ALLOC_STACK_ONLY;
  74. _lpszUrlHostName = lpszUrlHostName;
  75. _dwUrlHostNameLength = dwUrlHostNameLength;
  76. }
  77. AUTO_PROXY_ASYNC_MSG::AUTO_PROXY_ASYNC_MSG(
  78. IN INTERNET_SCHEME isUrlScheme,
  79. IN LPSTR lpszUrl,
  80. IN DWORD dwUrlLength,
  81. IN LPSTR lpszUrlHostName,
  82. IN DWORD dwUrlHostNameLength,
  83. IN INTERNET_PORT nUrlPort
  84. )
  85. {
  86. Initalize();
  87. _tUrlProtocol = isUrlScheme;
  88. _pmProxyQuery = PROXY_MSG_GET_PROXY_INFO;
  89. _pmaAllocMode = MSG_ALLOC_STACK_ONLY;
  90. _nUrlPort = nUrlPort;
  91. _lpszUrlHostName = lpszUrlHostName;
  92. _dwUrlHostNameLength = dwUrlHostNameLength;
  93. _lpszUrl = lpszUrl;
  94. _dwUrlLength = dwUrlLength;
  95. }
  96. VOID
  97. AUTO_PROXY_ASYNC_MSG::SetProxyMsg(
  98. IN INTERNET_SCHEME isUrlScheme,
  99. IN LPSTR lpszUrl,
  100. IN DWORD dwUrlLength,
  101. IN LPSTR lpszUrlHostName,
  102. IN DWORD dwUrlHostNameLength,
  103. IN INTERNET_PORT nUrlPort
  104. )
  105. {
  106. _tUrlProtocol = isUrlScheme;
  107. _pmProxyQuery = PROXY_MSG_GET_PROXY_INFO;
  108. _pmaAllocMode = MSG_ALLOC_STACK_ONLY;
  109. _nUrlPort = nUrlPort;
  110. _lpszUrlHostName = lpszUrlHostName;
  111. _dwUrlHostNameLength = dwUrlHostNameLength;
  112. _lpszUrl = lpszUrl;
  113. _dwUrlLength = dwUrlLength;
  114. }
  115. AUTO_PROXY_ASYNC_MSG::AUTO_PROXY_ASYNC_MSG(
  116. IN PROXY_MESSAGE_TYPE pmProxyQuery
  117. )
  118. {
  119. Initalize();
  120. _pmaAllocMode = MSG_ALLOC_HEAP_MSG_OBJ_OWNS;
  121. _pmProxyQuery = pmProxyQuery;
  122. }
  123. AUTO_PROXY_ASYNC_MSG::AUTO_PROXY_ASYNC_MSG(
  124. IN AUTO_PROXY_ASYNC_MSG *pStaticAutoProxy
  125. )
  126. {
  127. Initalize();
  128. _tUrlProtocol = pStaticAutoProxy->_tUrlProtocol;
  129. _lpszUrl = (pStaticAutoProxy->_lpszUrl) ? NewString(pStaticAutoProxy->_lpszUrl) : NULL;
  130. _dwUrlLength = pStaticAutoProxy->_dwUrlLength;
  131. _lpszUrlHostName =
  132. (pStaticAutoProxy->_lpszUrlHostName ) ?
  133. NewString(pStaticAutoProxy->_lpszUrlHostName, pStaticAutoProxy->_dwUrlHostNameLength) :
  134. NULL;
  135. _dwUrlHostNameLength = pStaticAutoProxy->_dwUrlHostNameLength;
  136. _nUrlPort = pStaticAutoProxy->_nUrlPort;
  137. _tProxyScheme = pStaticAutoProxy->_tProxyScheme;
  138. //
  139. // ProxyHostName is something that is generated by the request,
  140. // therefore it should not be copied OR freed.
  141. //
  142. INET_ASSERT( pStaticAutoProxy->_lpszProxyHostName == NULL );
  143. //_lpszProxyHostName = (pStaticAutoProxy->_lpszProxyHostName ) ? NewString(pStaticAutoProxy->_lpszProxyHostName) : NULL;
  144. _dwProxyHostNameLength = pStaticAutoProxy->_dwProxyHostNameLength;
  145. _nProxyHostPort = pStaticAutoProxy->_nProxyHostPort;
  146. _pmProxyQuery = pStaticAutoProxy->_pmProxyQuery;
  147. _pmaAllocMode = MSG_ALLOC_HEAP_MSG_OBJ_OWNS;
  148. _pProxyState = pStaticAutoProxy->_pProxyState;
  149. INET_ASSERT(_pProxyState == NULL);
  150. _dwQueryResult = pStaticAutoProxy->_dwQueryResult;
  151. _Error = pStaticAutoProxy->_Error;
  152. _MessageFlags.Dword = pStaticAutoProxy->_MessageFlags.Dword;
  153. _dwProxyVersion = pStaticAutoProxy->_dwProxyVersion;
  154. }
  155. AUTO_PROXY_ASYNC_MSG::~AUTO_PROXY_ASYNC_MSG(
  156. VOID
  157. )
  158. {
  159. DEBUG_ENTER((DBG_OBJECTS,
  160. None,
  161. "~AUTO_PROXY_ASYNC_MSG",
  162. NULL
  163. ));
  164. if ( IsAlloced() )
  165. {
  166. DEBUG_PRINT(OBJECTS,
  167. INFO,
  168. ("Freeing Allocated MSG ptr=%x\n",
  169. this
  170. ));
  171. if ( _lpszUrl )
  172. {
  173. //DEBUG_PRINT(OBJECTS,
  174. // INFO,
  175. // ("Url ptr=%x, %q\n",
  176. // _lpszUrl,
  177. // _lpszUrl
  178. // ));
  179. FREE_MEMORY(_lpszUrl);
  180. }
  181. if ( _lpszUrlHostName )
  182. {
  183. FREE_MEMORY(_lpszUrlHostName);
  184. }
  185. if ( _pProxyState )
  186. {
  187. delete _pProxyState;
  188. }
  189. }
  190. if (_bFreeProxyHostName && (_lpszProxyHostName != NULL)) {
  191. FREE_MEMORY(_lpszProxyHostName);
  192. }
  193. DEBUG_LEAVE(0);
  194. }