Source code of Windows XP (NT5)
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.

527 lines
10 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. LsServer.cpp
  5. Abstract:
  6. This Module contains the implementation of CKeyPack, CLicense,
  7. CLicServer, CAllServers classes
  8. Author:
  9. Arathi Kundapur (v-akunda) 11-Feb-1998
  10. Revision History:
  11. --*/
  12. #include <stdafx.h>
  13. #include "resource.h"
  14. #include "defines.h"
  15. #include "LSServer.h"
  16. ///////////////////////////////////////////////////////////
  17. int GetStatusPosition( CLicense *pLic );
  18. CKeyPack::CKeyPack(
  19. LSKeyPack &KeyPack
  20. )
  21. /*++
  22. --*/
  23. {
  24. m_hTreeItem = NULL;
  25. m_bIsExpanded = FALSE;
  26. m_pLicServer = NULL;
  27. m_KeyPack = KeyPack;
  28. return;
  29. }
  30. //---------------------------------------------------------
  31. CKeyPack::~CKeyPack()
  32. {
  33. PurgeCache();
  34. }
  35. //---------------------------------------------------------
  36. void
  37. CKeyPack::AddIssuedLicense(
  38. CLicense * pIssuedLicense
  39. )
  40. /*++
  41. --*/
  42. {
  43. if(NULL == pIssuedLicense)
  44. {
  45. return;
  46. }
  47. CString MachineName = pIssuedLicense->GetLicenseStruct().szMachineName;
  48. if(MachineName.IsEmpty())
  49. {
  50. MachineName.LoadString(IDS_UNKNOWN);
  51. lstrcpy(pIssuedLicense->GetLicenseStruct().szMachineName,(LPCTSTR)MachineName);
  52. }
  53. pIssuedLicense->SetKeyPack(this);
  54. m_IssuedLicenseList.AddTail(pIssuedLicense);
  55. return;
  56. }
  57. //---------------------------------------------------------
  58. void
  59. CKeyPack::PurgeCache()
  60. {
  61. CLicense *pLicense = NULL;
  62. POSITION pos = m_IssuedLicenseList.GetHeadPosition();
  63. while(pos)
  64. {
  65. pLicense = (CLicense *)m_IssuedLicenseList.GetNext(pos);
  66. ASSERT(pLicense);
  67. if(pLicense)
  68. {
  69. delete pLicense;
  70. pLicense = NULL;
  71. }
  72. }
  73. m_IssuedLicenseList.RemoveAll();
  74. m_bIsExpanded = FALSE;
  75. }
  76. //---------------------------------------------------------
  77. HRESULT
  78. CKeyPack::RefreshIssuedLicenses(
  79. LSLicense* pLicenses, /* = NULL */
  80. DWORD dwFreshParm, /* = 0 */
  81. BOOL bMatchAll /* = FALSE */
  82. )
  83. /*++
  84. None of the parameter is supported yet.
  85. --*/
  86. {
  87. PCONTEXT_HANDLE hBinding = NULL;
  88. BOOL bContext = FALSE;
  89. DWORD status = ERROR_SUCCESS;
  90. LSLicenseEx sLicense;
  91. CString Server;
  92. CLicServer *pServer = GetServer();
  93. HRESULT hResult = S_OK;
  94. ASSERT(pServer);
  95. if(NULL == pServer)
  96. {
  97. return E_FAIL;
  98. }
  99. PurgeCache();
  100. hBinding = pServer->GetContext();
  101. if(NULL == hBinding)
  102. {
  103. if(pServer->UseIpAddress())
  104. {
  105. Server = pServer->GetIpAddress();
  106. }
  107. else
  108. {
  109. Server = pServer->GetName();
  110. }
  111. hBinding = ConnectToLsServer(Server.GetBuffer(Server.GetLength()));
  112. if(hBinding == NULL)
  113. {
  114. hResult = CONNECTION_FAILED;
  115. goto cleanup;
  116. }
  117. }
  118. status = LSKeyPackEnumBegin(
  119. hBinding,
  120. LSKEYPACK_EXSEARCH_DWINTERNAL,
  121. FALSE,
  122. &m_KeyPack
  123. );
  124. if(status != ERROR_SUCCESS)
  125. {
  126. hResult = status;
  127. goto cleanup;
  128. }
  129. status = LSKeyPackEnumNext(
  130. hBinding,
  131. &m_KeyPack
  132. );
  133. LSKeyPackEnumEnd(hBinding);
  134. if(status != ERROR_SUCCESS)
  135. {
  136. hResult = status;
  137. goto cleanup;
  138. }
  139. memset(&sLicense, 0, sizeof(LSLicenseEx));
  140. sLicense.dwKeyPackId = m_KeyPack.dwKeyPackId;
  141. TLSLicenseEnumBegin(
  142. hBinding,
  143. LSLICENSE_SEARCH_KEYPACKID,
  144. FALSE,
  145. (LPLSLicenseSearchParm)&sLicense,
  146. &status
  147. );
  148. if(status != ERROR_SUCCESS)
  149. {
  150. hResult = status;
  151. goto cleanup;
  152. }
  153. do {
  154. memset(&sLicense, 0, sizeof(LSLicenseEx));
  155. TLSLicenseEnumNextEx(
  156. hBinding,
  157. &sLicense,
  158. &status
  159. );
  160. if(status == ERROR_SUCCESS)
  161. {
  162. CLicense * pLicense = new CLicense(sLicense);
  163. if(NULL == pLicense)
  164. {
  165. hResult = E_OUTOFMEMORY;
  166. goto cleanup;
  167. }
  168. AddIssuedLicense(pLicense);
  169. }
  170. } while(status == ERROR_SUCCESS);
  171. TLSLicenseEnumEnd(hBinding, &status);
  172. m_bIsExpanded = TRUE;
  173. cleanup:
  174. //put cleanup code here
  175. if(hBinding)
  176. {
  177. LSDisconnect(&hBinding);
  178. }
  179. return hResult;
  180. }
  181. ////////////////////////////////////////////////////////////
  182. void
  183. CLicServer::AddKeyPack(
  184. CKeyPack* pKeyPack
  185. )
  186. /*++
  187. --*/
  188. {
  189. if(NULL == pKeyPack)
  190. return;
  191. CString DisplayName;
  192. // CString For;
  193. // CString Platform;
  194. LSKeyPack &sKeypack = pKeyPack->GetKeyPackStruct();
  195. /* if(LSKEYPACKTYPE_TEMPORARY == sKeypack.ucKeyPackType)
  196. DisplayName.LoadString(IDS_TEMPORARY);
  197. else*/
  198. DisplayName = sKeypack.szProductDesc;
  199. // For.LoadString(IDS_FOR);
  200. // Platform.LoadString(IDS_PLATFORM1 + sKeypack.dwPlatformType - PLATFORM_WINNT_40);
  201. // DisplayName = DisplayName + _T(" ");
  202. // DisplayName = DisplayName + For;
  203. // DisplayName = DisplayName + _T(" ");
  204. // DisplayName = DisplayName + Platform;
  205. pKeyPack->SetDisplayName(DisplayName);
  206. m_KeyPackList.AddTail(pKeyPack);
  207. pKeyPack->SetServer(this);
  208. return;
  209. }
  210. ///////////////////////////////////////////////////////////
  211. CLicense::CLicense(LSLicenseEx &License)
  212. {
  213. m_pKeyPack = NULL;
  214. m_License = License;
  215. return;
  216. }
  217. //---------------------------------------------------------
  218. CLicense::~CLicense()
  219. {
  220. }
  221. ///////////////////////////////////////////////////////////
  222. CLicServer::CLicServer(
  223. CString& Name,
  224. SERVER_TYPE ServerType,
  225. CString& Scope,
  226. CString& IpAddress,
  227. PCONTEXT_HANDLE hBinding
  228. )
  229. /*++
  230. --*/
  231. {
  232. m_ServerName = Name;
  233. m_ServerScope = Scope;
  234. m_IpAddress = IpAddress;
  235. if(!m_IpAddress.IsEmpty())
  236. {
  237. m_bUseIpAddress = TRUE;
  238. }
  239. else
  240. {
  241. m_bUseIpAddress = FALSE;
  242. }
  243. m_ServerType = ServerType;
  244. if(ServerType == SERVER_TS4)
  245. {
  246. CString Temp;
  247. Temp.LoadString(IDS_TS4);
  248. m_DisplayName = m_ServerName + L" (" + Temp + L") ";
  249. }
  250. else
  251. {
  252. m_DisplayName = m_ServerName;
  253. }
  254. m_hTreeItem = NULL;
  255. m_hContext = hBinding;
  256. m_bIsExpanded = FALSE;
  257. m_dwRegStatus = ( DWORD )-1;
  258. m_bAdmin = FALSE;
  259. m_fDownloadedLicenses = FALSE;
  260. m_wizcon = ( WIZCONNECTION )-1;
  261. }
  262. ///////////////////////////////////////////////////////////
  263. void
  264. CAllServers::AddLicServer(
  265. CLicServer* pLicServer
  266. )
  267. /*++
  268. --*/
  269. {
  270. if(NULL == pLicServer)
  271. {
  272. return;
  273. }
  274. m_LicServerList.AddTail(pLicServer);
  275. return;
  276. }
  277. //---------------------------------------------------------
  278. CAllServers::CAllServers(
  279. CString Name
  280. )
  281. /*++
  282. --*/
  283. {
  284. m_hTreeItem = NULL;
  285. if(Name.IsEmpty())
  286. m_Name.LoadString(IDS_TREEROOT);
  287. else
  288. m_Name = Name;
  289. return;
  290. };
  291. CAllServers::~CAllServers()
  292. {
  293. CLicServer *pServer = NULL;
  294. POSITION pos = m_LicServerList.GetHeadPosition();
  295. while(pos)
  296. {
  297. pServer = (CLicServer *)m_LicServerList.GetNext(pos);
  298. ASSERT(pServer);
  299. if(pServer)
  300. {
  301. delete pServer;
  302. pServer = NULL;
  303. }
  304. }
  305. m_LicServerList.RemoveAll();
  306. }
  307. PCONTEXT_HANDLE CLicServer::GetContext()
  308. {
  309. return m_hContext;
  310. }
  311. void CLicServer::SetContext(PCONTEXT_HANDLE hContext)
  312. {
  313. m_hContext = hContext;
  314. }
  315. CLicServer::~CLicServer()
  316. {
  317. PurgeCache();
  318. }
  319. void
  320. CLicServer::PurgeCache()
  321. {
  322. CKeyPack *pKeyPack = NULL;
  323. POSITION pos = m_KeyPackList.GetHeadPosition();
  324. while(pos)
  325. {
  326. pKeyPack = (CKeyPack *)m_KeyPackList.GetNext(pos);
  327. ASSERT(pKeyPack);
  328. if(pKeyPack)
  329. {
  330. delete pKeyPack;
  331. pKeyPack = NULL;
  332. }
  333. }
  334. m_KeyPackList.RemoveAll();
  335. m_bIsExpanded = FALSE;
  336. }
  337. //-------------------------------------------------------------
  338. HRESULT
  339. CLicServer::RefreshCachedKeyPack()
  340. /*++
  341. --*/
  342. {
  343. HRESULT hResult = S_OK;
  344. PCONTEXT_HANDLE hBinding = NULL;
  345. BOOL bContext = FALSE;
  346. POSITION pos;
  347. CKeyPack *pKeyPack;
  348. CString Server;
  349. hBinding = GetContext();
  350. if(NULL == hBinding)
  351. {
  352. if(UseIpAddress())
  353. {
  354. Server = GetIpAddress();
  355. }
  356. else
  357. {
  358. Server = GetName();
  359. }
  360. hBinding = ConnectToLsServer(Server.GetBuffer(Server.GetLength()));
  361. if(hBinding == NULL)
  362. {
  363. hResult = CONNECTION_FAILED;
  364. goto cleanup;
  365. }
  366. }
  367. //
  368. // Code has too many other dependencies so
  369. // we only refresh licenses issued
  370. //
  371. pKeyPack = NULL;
  372. pos = m_KeyPackList.GetHeadPosition();
  373. while(pos)
  374. {
  375. pKeyPack = (CKeyPack *)m_KeyPackList.GetNext(pos);
  376. ASSERT(pKeyPack);
  377. if(pKeyPack)
  378. {
  379. pKeyPack->RefreshIssuedLicenses();
  380. }
  381. }
  382. cleanup:
  383. //put cleanup code here.
  384. if(hBinding)
  385. {
  386. LSDisconnect(&hBinding);
  387. }
  388. return hResult;
  389. }
  390. //-----------------------------------------------------------------------------------------
  391. // returns the license status position.
  392. // used for sorting licenses by status.
  393. //-----------------------------------------------------------------------------------------
  394. int GetStatusPosition( CLicense *pLic )
  395. {
  396. int val;
  397. ASSERT( pLic != NULL );
  398. switch( pLic->GetLicenseStruct().ucLicenseStatus )
  399. {
  400. case LSLICENSE_STATUS_ACTIVE:
  401. //case LSLICENSE_STATUS_PENDING_ACTIVE:
  402. case LSLICENSE_STATUS_CONCURRENT:
  403. val = 0;
  404. break;
  405. //case LSLICENSE_STATUS_REVOKE:
  406. //case LSLICENSE_STATUS_REVOKE_PENDING:
  407. // val = 1;
  408. // break;
  409. case LSLICENSE_STATUS_TEMPORARY:
  410. val = 2;
  411. break;
  412. case LSLICENSE_STATUS_UNKNOWN:
  413. val = 3;
  414. break;
  415. case LSLICENSE_STATUS_UPGRADED:
  416. val = 4;
  417. }
  418. return val;
  419. }