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.

480 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C F U T I L S . C P P
  7. //
  8. // Contents: Various utility functions for the connections folder
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 20 Jan 1998
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "foldinc.h" // Standard shell\folder includes
  18. #include "nsres.h" // Netshell strings
  19. #include "cfutils.h" // Connection folder utility functions
  20. #include "wzcdlg.h"
  21. VOID MapNCMToResourceId(
  22. IN NETCON_MEDIATYPE nct,
  23. IN DWORD dwCharacteristics,
  24. OUT INT * piStringRes)
  25. {
  26. Assert(piStringRes);
  27. if (dwCharacteristics & NCCF_BRANDED)
  28. {
  29. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_CONMAN;
  30. }
  31. else
  32. if (dwCharacteristics & NCCF_INCOMING_ONLY)
  33. {
  34. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_INBOUND;
  35. }
  36. else
  37. {
  38. switch(nct)
  39. {
  40. case NCM_NONE:
  41. Assert(dwCharacteristics & NCCF_INCOMING_ONLY);
  42. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_INBOUND;
  43. break;
  44. case NCM_DIRECT:
  45. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_DIRECT;
  46. break;
  47. case NCM_ISDN:
  48. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PHONE;
  49. break;
  50. case NCM_LAN:
  51. if(dwCharacteristics & NCCF_BRIDGED)
  52. {
  53. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_BRIDGE;
  54. }
  55. else
  56. {
  57. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_LAN;
  58. }
  59. break;
  60. case NCM_PHONE:
  61. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PHONE;
  62. break;
  63. case NCM_TUNNEL:
  64. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_TUNNEL;
  65. break;
  66. case NCM_BRIDGE:
  67. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_BRIDGE;
  68. break;
  69. case NCM_SHAREDACCESSHOST_LAN:
  70. case NCM_SHAREDACCESSHOST_RAS:
  71. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_SHAREDACCESSHOST;
  72. break;
  73. case NCM_PPPOE:
  74. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_PPPOE;
  75. break;
  76. default:
  77. AssertSz(FALSE, "Marfa -- I can't find my teef! (You may ignore.)");
  78. *piStringRes = IDS_CONFOLD_OBJECT_TYPE_UNKNOWN;
  79. break;
  80. }
  81. }
  82. }
  83. VOID MapNCSToComplexStatus(
  84. IN NETCON_STATUS ncs,
  85. IN NETCON_MEDIATYPE ncm,
  86. IN NETCON_SUBMEDIATYPE ncsm,
  87. IN DWORD dwCharacteristics,
  88. OUT LPWSTR pszString,
  89. IN DWORD cString,
  90. IN GUID gdDevice)
  91. {
  92. Assert(cString >= CONFOLD_MAX_STATUS_LENGTH);
  93. *pszString = L'\0';
  94. PCWSTR szArgs[4] = {L"", L"", L"", L""};
  95. DWORD dwArg = 0;
  96. WCHAR szTmpString[MAX_PATH];
  97. INT iStringRes = 0;
  98. if ((NCM_NONE == ncm) && (dwCharacteristics & NCCF_INCOMING_ONLY) )
  99. {
  100. DWORD dwIncomingCount;
  101. HRESULT hr = g_ccl.HasActiveIncomingConnections(&dwIncomingCount);
  102. if (SUCCEEDED(hr) && dwIncomingCount)
  103. {
  104. if (1 == dwIncomingCount)
  105. {
  106. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_ONE);
  107. }
  108. else
  109. {
  110. if (DwFormatString(SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_MULTI), szTmpString, MAX_PATH, dwIncomingCount))
  111. {
  112. szArgs[dwArg++] = szTmpString;
  113. }
  114. }
  115. }
  116. else
  117. {
  118. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_INCOMING_NONE);
  119. }
  120. }
  121. else
  122. {
  123. MapNCSToStatusResourceId(ncs, ncm, ncsm, dwCharacteristics, &iStringRes, gdDevice);
  124. }
  125. if (iStringRes)
  126. {
  127. szArgs[dwArg++] = SzLoadIds(iStringRes);
  128. }
  129. if (ncs == NCS_DISCONNECTED || fIsConnectedStatus(ncs))
  130. {
  131. if(NCCF_BRIDGED & dwCharacteristics)
  132. {
  133. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_BRIDGED);
  134. }
  135. if(NCCF_SHARED & dwCharacteristics)
  136. {
  137. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_SHARED);
  138. }
  139. if(NCCF_FIREWALLED & dwCharacteristics)
  140. {
  141. szArgs[dwArg++] = SzLoadIds(IDS_CONFOLD_STATUS_FIREWALLED);
  142. }
  143. }
  144. if(0 == FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, L"%1%2%3%4", 0, 0, pszString, cString, (va_list*) &szArgs))
  145. {
  146. *pszString = L'\0'; // on error return empty
  147. }
  148. if ( (NCS_CREDENTIALS_REQUIRED == ncs) || (NCS_AUTHENTICATING == ncs) )
  149. {
  150. BSTR szStatusText = NULL;
  151. HRESULT hrT = WZCQueryConnectionStatusText(&gdDevice, ncs, &szStatusText);
  152. if (S_OK == hrT)
  153. {
  154. wcsncpy(pszString, szStatusText, cString);
  155. SysFreeString(szStatusText);
  156. }
  157. }
  158. }
  159. VOID MapNCSToStatusResourceId(
  160. IN NETCON_STATUS ncs,
  161. IN NETCON_MEDIATYPE ncm,
  162. IN NETCON_SUBMEDIATYPE ncsm,
  163. IN DWORD dwCharacteristics,
  164. OUT INT * piStringRes,
  165. IN GUID gdDevice)
  166. {
  167. Assert(piStringRes);
  168. switch(ncs)
  169. {
  170. case NCS_DISCONNECTED:
  171. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  172. {
  173. *piStringRes = IDS_CONFOLD_STATUS_DISABLED;
  174. }
  175. else
  176. {
  177. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTED;
  178. }
  179. break;
  180. case NCS_CONNECTING:
  181. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  182. *piStringRes = IDS_CONFOLD_STATUS_ENABLING;
  183. else
  184. *piStringRes = IDS_CONFOLD_STATUS_CONNECTING;
  185. break;
  186. case NCS_CONNECTED:
  187. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  188. {
  189. *piStringRes = IDS_CONFOLD_STATUS_ENABLED;
  190. }
  191. else
  192. {
  193. *piStringRes = IDS_CONFOLD_STATUS_CONNECTED;
  194. }
  195. break;
  196. case NCS_DISCONNECTING:
  197. if (IsMediaLocalType(ncm) || NCM_SHAREDACCESSHOST_LAN == ncm)
  198. *piStringRes = IDS_CONFOLD_STATUS_DISABLING;
  199. else
  200. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTING;
  201. break;
  202. case NCS_HARDWARE_NOT_PRESENT:
  203. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_NOT_PRESENT;
  204. break;
  205. case NCS_HARDWARE_DISABLED:
  206. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_DISABLED;
  207. break;
  208. case NCS_HARDWARE_MALFUNCTION:
  209. *piStringRes = IDS_CONFOLD_STATUS_HARDWARE_MALFUNCTION;
  210. break;
  211. case NCS_MEDIA_DISCONNECTED:
  212. if ( (ncm == NCM_LAN) && (ncsm == NCSM_WIRELESS) )
  213. {
  214. *piStringRes = IDS_CONFOLD_STATUS_WIRELESS_DISCONNECTED;
  215. }
  216. else
  217. {
  218. *piStringRes = IDS_CONFOLD_STATUS_MEDIA_DISCONNECTED;
  219. }
  220. break;
  221. case NCS_INVALID_ADDRESS:
  222. *piStringRes = IDS_CONFOLD_STATUS_INVALID_ADDRESS;
  223. break;
  224. case NCS_AUTHENTICATION_FAILED:
  225. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATION_FAILED;
  226. break;
  227. case NCS_AUTHENTICATING:
  228. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATING;
  229. break;
  230. case NCS_AUTHENTICATION_SUCCEEDED:
  231. *piStringRes = IDS_CONFOLD_STATUS_AUTHENTICATION_SUCCEEDED;
  232. break;
  233. case NCS_CREDENTIALS_REQUIRED:
  234. *piStringRes = IDS_CONFOLD_STATUS_CREDENTIALS_REQUIRED;
  235. break;
  236. default:
  237. AssertSz(FALSE, "Unknown status in MapNCSToStatusResourceId");
  238. *piStringRes = IDS_CONFOLD_STATUS_DISCONNECTED;
  239. break;
  240. }
  241. }
  242. DWORD MapRSSIToWirelessSignalStrength(IN int iRSSI) throw()
  243. {
  244. if (iRSSI < -90)
  245. {
  246. return 0;
  247. }
  248. if (iRSSI < -81)
  249. {
  250. return 1;
  251. }
  252. if (iRSSI < -71)
  253. {
  254. return 2;
  255. }
  256. if (iRSSI < -67)
  257. {
  258. return 3;
  259. }
  260. if (iRSSI < -57)
  261. {
  262. return 4;
  263. }
  264. return 5;
  265. }
  266. PCWSTR PszGetRSSIString(IN INT iRSSI) throw()
  267. {
  268. DWORD wss = MapRSSIToWirelessSignalStrength(iRSSI);
  269. Assert(wss <= (IDS_802_11_LEVEL5 - IDS_802_11_LEVEL0) );
  270. return SzLoadIds(IDS_802_11_LEVEL0 + wss);
  271. }
  272. //+---------------------------------------------------------------------------
  273. //
  274. // Function: PszGetOwnerStringFromCharacteristics
  275. //
  276. // Purpose: Get the owner string from the CONFOLDENTRY. This will
  277. // return the string for "System" if the connection is for
  278. // all users, and will return the particular user if
  279. // appropriate
  280. //
  281. // Arguments:
  282. // pszUserName [in] The name for the currently logged in user
  283. // dwCharacteristics [in] The current characteristics of the connection
  284. //
  285. // Returns: The string for the user name
  286. //
  287. // Author: jeffspr 20 Jan 1998
  288. //
  289. // Notes:
  290. //
  291. PCWSTR PszGetOwnerStringFromCharacteristics(IN PCWSTR pszUserName, IN DWORD dwCharacteristics) throw()
  292. {
  293. PCWSTR pszOwner = NULL;
  294. BOOL fAllUsers = (dwCharacteristics & NCCF_ALL_USERS) > 0;
  295. // If they both have the same user type, then they're equal
  296. //
  297. if (fAllUsers)
  298. {
  299. pszOwner = SzLoadIds(IDS_CONFOLD_DETAILS_OWNER_SYSTEM);
  300. }
  301. else
  302. {
  303. pszOwner = pszUserName;
  304. }
  305. return pszOwner;
  306. }
  307. BOOL IsMediaLocalType(IN NETCON_MEDIATYPE ncm) throw()
  308. {
  309. return (ncm == NCM_LAN || ncm == NCM_BRIDGE);
  310. }
  311. BOOL IsMediaRASType(IN NETCON_MEDIATYPE ncm) throw()
  312. {
  313. return (ncm == NCM_DIRECT || ncm == NCM_ISDN || ncm == NCM_PHONE || ncm == NCM_TUNNEL || ncm == NCM_PPPOE);// REVIEW DIRECT correct?
  314. }
  315. BOOL IsMediaSharedAccessHostType(IN NETCON_MEDIATYPE ncm) throw()
  316. {
  317. return (ncm == NCM_SHAREDACCESSHOST_LAN || ncm == NCM_SHAREDACCESSHOST_RAS);
  318. }
  319. //+---------------------------------------------------------------------------
  320. //
  321. // Function Name: ImageList_LoadImageAndMirror
  322. //
  323. // Purpose: This function creates an image list from the specified bitmap or icon resource.
  324. //
  325. // Arguments:
  326. // hi [in] Handle to the instance of an application or DLL that contains an image.
  327. // lpbmp [in] Long pointer to the image to load.
  328. // If the uFlags parameter includes LR_LOADFROMFILE, lpbmp is the address
  329. // of a null-terminated string that names the file containing the image to load.
  330. //
  331. // If the hi parameter is non-NULL and LR_LOADFROMFILE is not specified, lpbmp is the
  332. // address of a null-terminated string that contains the name of the image resource in the hi module.
  333. //
  334. // If hi is NULL and LR_LOADFROMFILE is not specified, the low-order word of this
  335. // parameter must be the identifier of an OEM image to load. To create this value, use the
  336. // MAKEINTRESOURCE macro with one of the OEM image identifiers defined in Winuser.h.
  337. // These identifiers have the following prefixes:
  338. // OBM_ for OEM bitmaps
  339. // OIC_ for OEM icons
  340. //
  341. // cx [in] Width of each image. The height of each image and the initial number of images are inferred
  342. // by the dimensions of the specified resource.
  343. // cGrow [in] Number of images by which the image list can grow when the system needs to make room for new
  344. // images. This parameter represents the number of new images that the resized image list can contain.
  345. // crMask [in] Color used to generate a mask. Each pixel of this color in the specified bitmap or icon is changed to
  346. // black, and the corresponding bit in the mask is set to 1. If this parameter is the CLR_NONE value,
  347. // no mask is generated. If this parameter is the CLR_DEFAULT value, the color of the pixel at the
  348. // upper-left corner of the image is treated as the mask color.
  349. // uType [in] Flag that specifies the type of image to load. This parameter can be one of the following values:
  350. // IMAGE_BITMAP Loads a bitmap.
  351. // IMAGE_ICON Loads an icon.
  352. // uFlags [in] Unsupported; set to 0.
  353. //
  354. // Returns:
  355. // The handle to the image list indicates success. NULL indicates failure.
  356. //
  357. // Author: deonb 8 Feb 2001
  358. //
  359. // Notes:
  360. // This is an exact duplication of the implementation of shell's ImageList_LoadImage function EXCEPT for the
  361. // fact that we set ILC_MIRROR in order to create the second, mirrored image list which will be used
  362. // by RTL languages
  363. //
  364. HIMAGELIST WINAPI ImageList_LoadImageAndMirror(
  365. IN HINSTANCE hi,
  366. IN LPCTSTR lpbmp,
  367. IN int cx,
  368. IN int cGrow,
  369. IN COLORREF crMask,
  370. IN UINT uType,
  371. IN UINT uFlags) throw()
  372. {
  373. HBITMAP hbmImage;
  374. HIMAGELIST piml = NULL;
  375. BITMAP bm;
  376. int cy, cInitial;
  377. UINT flags;
  378. hbmImage = (HBITMAP)LoadImage(hi, lpbmp, uType, 0, 0, uFlags);
  379. if (hbmImage && (sizeof(bm) == GetObject(hbmImage, sizeof(bm), &bm)))
  380. {
  381. // If cx is not stated assume it is the same as cy.
  382. // ASSERT(cx);
  383. cy = bm.bmHeight;
  384. if (cx == 0)
  385. cx = cy;
  386. cInitial = bm.bmWidth / cx;
  387. flags = 0;
  388. if (crMask != CLR_NONE)
  389. flags |= ILC_MASK;
  390. if (bm.bmBits)
  391. flags |= (bm.bmBitsPixel & ILC_COLORMASK);
  392. flags |= ILC_MIRROR;
  393. piml = ImageList_Create(cx, cy, flags, cInitial, cGrow);
  394. if (piml)
  395. {
  396. int added;
  397. if (crMask == CLR_NONE)
  398. added = ImageList_Add(piml, hbmImage, NULL);
  399. else
  400. added = ImageList_AddMasked(piml, hbmImage, crMask);
  401. if (added < 0)
  402. {
  403. ImageList_Destroy(piml);
  404. piml = NULL;
  405. }
  406. }
  407. }
  408. if (hbmImage)
  409. DeleteObject(hbmImage);
  410. return reinterpret_cast<HIMAGELIST>(piml);
  411. }