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.

270 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. connect.cxx
  5. Abstract:
  6. Contains methods for INTERNET_CONNECT_HANDLE_OBJECT class
  7. Contents:
  8. RMakeInternetConnectObjectHandle
  9. INTERNET_CONNECT_HANDLE_OBJECT::INTERNET_CONNECT_HANDLE_OBJECT
  10. INTERNET_CONNECT_HANDLE_OBJECT::~INTERNET_CONNECT_HANDLE_OBJECT
  11. Author:
  12. Madan Appiah (madana) 16-Nov-1994
  13. Environment:
  14. User Mode - Win32
  15. Revision History:
  16. Sophia Chung (sophiac) 14-Feb-1995 (added FTP and Archie class impl.)
  17. (code adopted from madana)
  18. --*/
  19. #include <wininetp.h>
  20. //
  21. // functions
  22. //
  23. DWORD
  24. RMakeInternetConnectObjectHandle(
  25. IN HINTERNET ParentHandle,
  26. IN OUT HINTERNET * ChildHandle,
  27. IN LPSTR lpszServerName,
  28. IN INTERNET_PORT nServerPort,
  29. IN DWORD dwFlags, // dead
  30. IN DWORD_PTR dwContext
  31. )
  32. /*++
  33. Routine Description:
  34. Creates an INTERNET_CONNECT_HANDLE_OBJECT. Wrapper function callable from
  35. C code
  36. Arguments:
  37. ParentHandle - parent InternetOpen() handle
  38. ChildHandle - IN: protocol-specific child handle
  39. OUT: address of handle object
  40. lpszServerName - pointer to server name
  41. nServerPort - server port to connect to
  42. dwFlags - various open flags from InternetConnect()
  43. dwContext - app-supplied context value to associate with the handle
  44. Return Value:
  45. DWORD
  46. Success - ERROR_SUCCESS
  47. Failure - ERROR_NOT_ENOUGH_MEMORY
  48. --*/
  49. {
  50. DWORD error;
  51. INTERNET_CONNECT_HANDLE_OBJECT * hConnect;
  52. hConnect = New INTERNET_CONNECT_HANDLE_OBJECT(
  53. (INTERNET_HANDLE_BASE *)ParentHandle,
  54. *ChildHandle,
  55. lpszServerName,
  56. nServerPort,
  57. dwFlags,
  58. dwContext
  59. );
  60. if (hConnect != NULL) {
  61. error = hConnect->GetStatus();
  62. if (error == ERROR_SUCCESS) {
  63. //
  64. // inform the app of the new handle
  65. //
  66. error = InternetIndicateStatusNewHandle((LPVOID)hConnect);
  67. //
  68. // ERROR_WINHTTP_OPERATION_CANCELLED is the only error that we are
  69. // expecting here. If we get this error then the app has cancelled
  70. // the operation. Either way, the handle we just generated will be
  71. // already deleted
  72. //
  73. if (error != ERROR_SUCCESS) {
  74. INET_ASSERT(error == ERROR_WINHTTP_OPERATION_CANCELLED);
  75. hConnect = NULL;
  76. }
  77. } else {
  78. delete hConnect;
  79. hConnect = NULL;
  80. }
  81. } else {
  82. error = ERROR_NOT_ENOUGH_MEMORY;
  83. }
  84. *ChildHandle = (HINTERNET)hConnect;
  85. return error;
  86. }
  87. //
  88. // INTERNET_CONNECT_HANDLE_OBJECT class implementation
  89. //
  90. INTERNET_CONNECT_HANDLE_OBJECT::INTERNET_CONNECT_HANDLE_OBJECT(
  91. INTERNET_CONNECT_HANDLE_OBJECT *InternetConnectObj
  92. ) : INTERNET_HANDLE_BASE((INTERNET_HANDLE_BASE *)InternetConnectObj)
  93. /*++
  94. Routine Description:
  95. Constructor that creates a copy of an INTERNET_CONNECT_HANDLE_OBJECT when
  96. generating a derived handle object, such as a HTTP_REQUEST_HANDLE_OBJECT
  97. Arguments:
  98. InternetConnectObj - INTERNET_CONNECT_HANDLE_OBJECT to copy
  99. Return Value:
  100. None.
  101. --*/
  102. {
  103. DEBUG_ENTER((DBG_OBJECTS,
  104. None,
  105. "INTERNET_CONNECT_HANDLE_OBJECT::INTERNET_CONNECT_HANDLE_OBJECT",
  106. "%#x",
  107. InternetConnectObj
  108. ));
  109. //
  110. // copy the name objects and server port
  111. //
  112. _HostName = InternetConnectObj->_HostName;
  113. _HostPort = InternetConnectObj->_HostPort;
  114. //
  115. // _SchemeType is actual scheme we use. May be different than original
  116. // object type when going via CERN proxy. Initially set to default (HTTP)
  117. //
  118. _SchemeType = InternetConnectObj->_SchemeType;
  119. DEBUG_LEAVE(0);
  120. }
  121. INTERNET_CONNECT_HANDLE_OBJECT::INTERNET_CONNECT_HANDLE_OBJECT(
  122. INTERNET_HANDLE_BASE * Parent,
  123. HINTERNET Child,
  124. LPTSTR lpszServerName,
  125. INTERNET_PORT nServerPort,
  126. DWORD dwFlags,
  127. DWORD_PTR dwContext
  128. ) : INTERNET_HANDLE_BASE(Parent)
  129. /*++
  130. Routine Description:
  131. Constructor for direct-to-net INTERNET_CONNECT_HANDLE_OBJECT
  132. Arguments:
  133. Parent - pointer to parent handle (INTERNET_HANDLE_BASE as
  134. created by InternetOpen())
  135. Child - handle of child object - typically an identifying value
  136. for the protocol-specific code
  137. lpszServerName - name of the server we are connecting to. May also be the
  138. IP address expressed as a string
  139. nServerPort - the port number at the server to which we connect
  140. dwFlags - creation flags from InternetConnect():
  141. dwContext - context value for call-backs
  142. Return Value:
  143. None.
  144. --*/
  145. {
  146. DEBUG_ENTER((DBG_OBJECTS,
  147. None,
  148. "INTERNET_CONNECT_HANDLE_OBJECT::INTERNET_CONNECT_HANDLE_OBJECT",
  149. "%#x, %#x, %q, %d, %#x, %#x",
  150. Parent,
  151. Child,
  152. lpszServerName,
  153. nServerPort,
  154. dwFlags,
  155. dwContext
  156. ));
  157. // record the parameters, making copies of string buffers
  158. _HostName = lpszServerName;
  159. _HostPort = nServerPort;
  160. SetSchemeType(INTERNET_SCHEME_HTTP);
  161. SetObjectType(TypeHttpConnectHandle);
  162. _Context = dwContext;
  163. _Status = ERROR_SUCCESS; // BUGBUG: what if we fail to allocate _HostName?
  164. DEBUG_LEAVE(0);
  165. }
  166. INTERNET_CONNECT_HANDLE_OBJECT::~INTERNET_CONNECT_HANDLE_OBJECT(VOID)
  167. /*++
  168. Routine Description:
  169. Destructor for INTERNET_CONNECT_HANDLE_OBJECT
  170. Arguments:
  171. None.
  172. Return Value:
  173. None.
  174. --*/
  175. {
  176. // Nothing to see here, people; move along!
  177. }