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.

189 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: svcattch.cpp
  7. //
  8. // Contents: implementation of CComponentDataImpl
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "snapmgr.h"
  13. #include <scesvc.h>
  14. #define TEMPLATE_MAGIC_NUMBER (DWORD)-1
  15. /*-------------------------------------------------------------------------------
  16. This is a private structure used for SceSvcQueryInfo it expects the handle to
  17. be one step above what it is now.
  18. -------------------------------------------------------------------------------*/
  19. typedef struct _tag_SCEP_HANDLE
  20. {
  21. LPVOID hProfile; // SCE_HANDLE
  22. PWSTR ServiceName; // Service name.
  23. } SCEP_HANDLE, *LPSCEP_HANDLE;
  24. STDMETHODIMP
  25. CComponentDataImpl::GetData (SCESVC_HANDLE sceHandle,
  26. SCESVC_INFO_TYPE sceType,
  27. PVOID *ppvData,
  28. PSCE_ENUMERATION_CONTEXT psceEnumHandle) {
  29. SCESTATUS status;
  30. SCESVCP_HANDLE *scesvcHandle;
  31. // if (m_fSvcNotReady) {
  32. // return E_PENDING;
  33. // }
  34. if (!sceHandle) {
  35. return E_INVALIDARG;
  36. }
  37. if (!ppvData) {
  38. return E_POINTER;
  39. }
  40. scesvcHandle = (SCESVCP_HANDLE *) sceHandle;
  41. if (!scesvcHandle->ServiceName) {
  42. return E_INVALIDARG;
  43. }
  44. if (scesvcHandle->TemplateName &&
  45. lstrcmp(GT_COMPUTER_TEMPLATE, scesvcHandle->TemplateName) != 0 ) {
  46. if (psceEnumHandle &&
  47. *psceEnumHandle == TEMPLATE_MAGIC_NUMBER) {
  48. *ppvData = NULL;
  49. status = SCESTATUS_SUCCESS;
  50. } else {
  51. if (psceEnumHandle) {
  52. *psceEnumHandle = TEMPLATE_MAGIC_NUMBER;
  53. }
  54. status = SceSvcGetInformationTemplate(scesvcHandle->TemplateName,
  55. scesvcHandle->ServiceName,
  56. 0,
  57. (PSCESVC_CONFIGURATION_INFO *) ppvData);
  58. }
  59. } else {
  60. //
  61. // This structure needs to be sent to SceSvcQueryInfo;
  62. //
  63. SCEP_HANDLE hScep;
  64. ZeroMemory(&hScep, sizeof(SCEP_HANDLE));
  65. hScep.hProfile = SadHandle;
  66. hScep.ServiceName = scesvcHandle->ServiceName;
  67. status = SceSvcQueryInfo((SCE_HANDLE)&hScep,sceType,0,0,ppvData,psceEnumHandle);
  68. }
  69. if (SCESTATUS_SUCCESS == status) {
  70. return S_OK;
  71. } else {
  72. return E_FAIL;
  73. }
  74. }
  75. STDMETHODIMP
  76. CComponentDataImpl::Initialize(LPCTSTR ServiceName,
  77. LPCTSTR TemplateName,
  78. LPSCESVCATTACHMENTPERSISTINFO lpSceSvcPersistInfo,
  79. SCESVC_HANDLE *sceHandle) {
  80. SCESVCP_HANDLE *scesvcHandle;
  81. CEditTemplate *pET;
  82. ASSERT(ServiceName);
  83. ASSERT(lpSceSvcPersistInfo);
  84. ASSERT(sceHandle);
  85. if (!ServiceName || !lpSceSvcPersistInfo || !sceHandle) {
  86. return E_POINTER;
  87. }
  88. *sceHandle = NULL;
  89. //
  90. // Cache Service & Template -> lpUnknown.
  91. //
  92. if (TemplateName && lstrlen(TemplateName)) {
  93. //
  94. // If TemplateName is not NULL then find the template and store it there
  95. //
  96. pET = GetTemplate(TemplateName);
  97. if (!pET) {
  98. return E_FAIL;
  99. }
  100. pET->AddService(ServiceName,lpSceSvcPersistInfo);
  101. } else {
  102. return E_INVALIDARG;
  103. }
  104. // Open & retrieve SCE_HANDLE
  105. scesvcHandle = new SCESVCP_HANDLE;
  106. if (!scesvcHandle) {
  107. return E_OUTOFMEMORY;
  108. }
  109. scesvcHandle->ServiceName = new TCHAR [ lstrlen(ServiceName)+1 ];
  110. if (!scesvcHandle->ServiceName) {
  111. delete scesvcHandle;
  112. return E_OUTOFMEMORY;
  113. }
  114. lstrcpy(scesvcHandle->ServiceName,ServiceName);
  115. if (TemplateName) {
  116. scesvcHandle->TemplateName = new TCHAR [ lstrlen(TemplateName)+1 ];
  117. if (!scesvcHandle->TemplateName) {
  118. delete [] scesvcHandle->ServiceName;
  119. delete scesvcHandle;
  120. return E_OUTOFMEMORY;
  121. }
  122. lstrcpy(scesvcHandle->TemplateName,TemplateName);
  123. } else {
  124. scesvcHandle->TemplateName = NULL;
  125. }
  126. *sceHandle = (SCESVC_HANDLE *) scesvcHandle;
  127. return S_OK;
  128. }
  129. STDMETHODIMP
  130. CComponentDataImpl::FreeBuffer(PVOID pvData) {
  131. HRESULT hr;
  132. if (!pvData) {
  133. hr = E_POINTER;
  134. } else if (SCESTATUS_SUCCESS == SceSvcFree(pvData)) {
  135. hr = S_OK;
  136. } else {
  137. hr = E_FAIL;
  138. }
  139. return hr;
  140. }
  141. STDMETHODIMP
  142. CComponentDataImpl::CloseHandle(SCESVC_HANDLE sceHandle) {
  143. HRESULT hr;
  144. PSCESVCP_HANDLE pHandle;
  145. if (sceHandle) {
  146. pHandle = (PSCESVCP_HANDLE) sceHandle;
  147. // Free the handle
  148. if (pHandle->TemplateName) {
  149. delete[] pHandle->TemplateName;
  150. }
  151. delete[] pHandle->ServiceName;
  152. delete pHandle;
  153. hr = S_OK;
  154. } else {
  155. hr = E_INVALIDARG;
  156. }
  157. return hr;
  158. }