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.

269 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. connperf.cxx
  5. Abstract:
  6. Contains the entry points for the WinNet Resource Info API supported
  7. by the Multi-Provider Router. The following functions are in this file:
  8. MultinetGetConnectionPerformanceW
  9. Author:
  10. Anirudh Sahni (anirudhs) 22-Jan-1996
  11. Environment:
  12. User Mode -Win32
  13. Notes:
  14. Revision History:
  15. 22-Jan-1996 anirudhs
  16. Created
  17. 05-May-1999 jschwart
  18. Make provider addition/removal dynamic
  19. --*/
  20. //
  21. // INCLUDES
  22. //
  23. #include "precomp.hxx"
  24. //===================================================================
  25. // CGetConnection
  26. //
  27. // This class retrieves the remote name and provider responsible for
  28. // a redirected device.
  29. // CODEWORK: This can/should replace MprGetConnection if we can be
  30. // sure that the error picking logic is equivalent. Code needs to be
  31. // added to handle remembered connections.
  32. //===================================================================
  33. class CGetConnection : public CRoutedOperation
  34. {
  35. public:
  36. CGetConnection(
  37. LPWSTR lpLocalName, // IN
  38. LPWSTR lpRemoteName, // OUT
  39. LPDWORD lpBufferSize, // IN OUT
  40. LPWSTR lpProviderName // IN OPTIONAL
  41. ) :
  42. CRoutedOperation(DBGPARM("GetConnection")
  43. PROVIDERFUNC(GetConnection)),
  44. _lpLocalName (lpLocalName),
  45. _lpRemoteName (lpRemoteName),
  46. _lpBufferSize (lpBufferSize),
  47. _lpProviderName (lpProviderName)
  48. { }
  49. PROVIDER * LastProvider() const // expose the base class' method
  50. { return (CRoutedOperation::LastProvider()); }
  51. private:
  52. LPWSTR _lpLocalName;
  53. LPWSTR _lpRemoteName;
  54. LPDWORD _lpBufferSize;
  55. LPWSTR _lpProviderName;
  56. DECLARE_CROUTED
  57. };
  58. DWORD
  59. CGetConnection::ValidateRoutedParameters(
  60. LPCWSTR * ppProviderName,
  61. LPCWSTR * ppRemoteName,
  62. LPCWSTR * ppLocalName
  63. )
  64. {
  65. if (MprDeviceType(_lpLocalName) != REDIR_DEVICE)
  66. {
  67. return WN_BAD_LOCALNAME;
  68. }
  69. //
  70. // Let the base class validate the provider name, if one was supplied
  71. //
  72. *ppProviderName = _lpProviderName;
  73. *ppLocalName = _lpLocalName;
  74. return WN_SUCCESS;
  75. }
  76. DWORD
  77. CGetConnection::TestProvider(
  78. const PROVIDER * pProvider
  79. )
  80. {
  81. ASSERT_INITIALIZED(NETWORK);
  82. return pProvider->GetConnection(_lpLocalName, _lpRemoteName, _lpBufferSize);
  83. }
  84. //===================================================================
  85. // MultinetGetConnectionPerformanceW
  86. //===================================================================
  87. class CGetConnectionPerformance : public CRoutedOperation
  88. {
  89. public:
  90. CGetConnectionPerformance(
  91. LPNETRESOURCEW lpNetResource,
  92. LPNETCONNECTINFOSTRUCT lpNetConnectInfo
  93. ) :
  94. CRoutedOperation(DBGPARM("GetConnectionPerformance")
  95. PROVIDERFUNC(GetConnectionPerformance)),
  96. _lpNetResource (lpNetResource),
  97. _lpNetConnectInfo(lpNetConnectInfo)
  98. { }
  99. private:
  100. LPNETRESOURCEW _lpNetResource;
  101. LPNETCONNECTINFOSTRUCT _lpNetConnectInfo;
  102. LPWSTR _pRemoteName;
  103. WCHAR _wszBuffer[MAX_PATH+1];
  104. DECLARE_CROUTED
  105. };
  106. DWORD
  107. CGetConnectionPerformance::ValidateRoutedParameters(
  108. LPCWSTR * ppProviderName,
  109. LPCWSTR * ppRemoteName,
  110. LPCWSTR * ppLocalName
  111. )
  112. {
  113. if (!(ARGUMENT_PRESENT(_lpNetResource) &&
  114. ARGUMENT_PRESENT(_lpNetConnectInfo)))
  115. {
  116. return WN_BAD_POINTER;
  117. }
  118. if (_lpNetConnectInfo->cbStructure < sizeof(NETCONNECTINFOSTRUCT))
  119. {
  120. return WN_BAD_VALUE;
  121. }
  122. //
  123. // Zero out the output structure, except for the first field.
  124. //
  125. memset((&_lpNetConnectInfo->cbStructure) + 1,
  126. 0,
  127. sizeof(*_lpNetConnectInfo) - sizeof(_lpNetConnectInfo->cbStructure));
  128. if (IS_EMPTY_STRING(_lpNetResource->lpLocalName))
  129. {
  130. //
  131. // No local name is specified, so a remote name should be specified.
  132. //
  133. _pRemoteName = _lpNetResource->lpRemoteName;
  134. if (IS_EMPTY_STRING(_pRemoteName))
  135. {
  136. return WN_BAD_NETNAME;
  137. }
  138. // Let the base class validate the provider name, if specified.
  139. *ppProviderName = _lpNetResource->lpProvider;
  140. }
  141. else
  142. {
  143. //
  144. // A local name is specified. Try to identify the remote name,
  145. // and, as a side effect, the provider that made the connection.
  146. //
  147. DWORD cchBuffer = LENGTH(_wszBuffer);
  148. CGetConnection GetConn(_lpNetResource->lpLocalName,
  149. _wszBuffer,
  150. &cchBuffer,
  151. _lpNetResource->lpProvider);
  152. DWORD status = GetConn.Perform(FALSE);
  153. if (status != WN_SUCCESS)
  154. {
  155. ASSERT(status != WN_MORE_DATA);
  156. return status;
  157. }
  158. _pRemoteName = _wszBuffer;
  159. // A somewhat roundabout way of telling the base class the real provider
  160. *ppProviderName = GetConn.LastProvider()->Resource.lpProvider;
  161. }
  162. // Have the base class cache the remote name (again). Note that
  163. // the local name, if present, was checked by CGetConnection
  164. *ppRemoteName = _pRemoteName;
  165. *ppLocalName = NULL;
  166. return WN_SUCCESS;
  167. }
  168. DWORD
  169. CGetConnectionPerformance::TestProvider(
  170. const PROVIDER * pProvider
  171. )
  172. {
  173. ASSERT_INITIALIZED(NETWORK);
  174. //
  175. // CODEWORK -- We should try to resolve the local name here
  176. // per connection and if it succeeds, then call
  177. // the provider's GetConnectionPerformance. We
  178. // could then remove the use of CGetConnection
  179. // from ValidateRoutedParameters.
  180. //
  181. return (pProvider->GetConnectionPerformance(
  182. _pRemoteName,
  183. _lpNetConnectInfo));
  184. }
  185. DWORD
  186. MultinetGetConnectionPerformanceW(
  187. LPNETRESOURCEW lpNetResource,
  188. LPNETCONNECTINFOSTRUCT lpNetConnectInfo
  189. )
  190. /*++
  191. Routine Description:
  192. This API returns information about the expected performance of a
  193. connection used to access a network resource.
  194. Arguments:
  195. lpNetResource -
  196. lpNetConnectInfo -
  197. Return Value:
  198. WN_SUCCESS - Indicates the operation was successful.
  199. Other errors -
  200. --*/
  201. {
  202. CGetConnectionPerformance GetConnPerf(lpNetResource, lpNetConnectInfo);
  203. return (GetConnPerf.Perform(TRUE));
  204. }