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.

402 lines
12 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. IncidentStore.cpp
  5. Abstract:
  6. File for Implementation of CIncidentStore
  7. Revision History:
  8. Steve Shih created 07/19/99
  9. Davide Massarenti rewrote 12/05/2000
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ IncidentStatusEnum& val ) { return stream.read ( &val, sizeof(val) ); }
  14. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in] */ const IncidentStatusEnum& val ) { return stream.write( &val, sizeof(val) ); }
  15. ////////////////////////////////////////////////////////////////////////////////
  16. static const WCHAR c_szEventObject[] = L"PCH_INCIDENTSTORE";
  17. static const WCHAR c_szStorePath [] = HC_HELPSVC_STORE_INCIDENTITEMS;
  18. static const DWORD l_dwVersion = 0x0100AF05; // SAF 01
  19. ////////////////////////////////////////////////////////////////////////////////
  20. CSAFIncidentRecord::CSAFIncidentRecord()
  21. {
  22. m_dwRecIndex = -1; // DWORD m_dwRecIndex;
  23. //
  24. // CComBSTR m_bstrVendorID;
  25. // CComBSTR m_bstrProductID;
  26. // CComBSTR m_bstrDisplay;
  27. // CComBSTR m_bstrURL;
  28. // CComBSTR m_bstrProgress;
  29. // CComBSTR m_bstrXMLDataFile;
  30. // CComBSTR m_bstrXMLBlob;
  31. m_dCreatedTime = 0; // DATE m_dCreatedTime;
  32. m_dChangedTime = 0; // DATE m_dChangedTime;
  33. m_dClosedTime = 0; // DATE m_dClosedTime;
  34. m_iStatus = pchIncidentInvalid; // IncidentStatusEnum m_iStatus;
  35. //
  36. // CComBSTR m_bstrSecurity;
  37. // CComBSTR m_bstrOwner;
  38. }
  39. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ CSAFIncidentRecord& increc )
  40. {
  41. __HCP_FUNC_ENTRY( "CSAFIncidentRecord::operator>>" );
  42. HRESULT hr;
  43. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_dwRecIndex );
  44. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrVendorID );
  45. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrProductID );
  46. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrDisplay );
  47. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrURL );
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrProgress );
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrXMLDataFile);
  50. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrXMLBlob );
  51. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_dCreatedTime );
  52. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_dChangedTime );
  53. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_dClosedTime );
  54. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_iStatus );
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrSecurity );
  56. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> increc.m_bstrOwner );
  57. hr = S_OK;
  58. __HCP_FUNC_CLEANUP;
  59. __HCP_FUNC_EXIT(hr);
  60. }
  61. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in] */ const CSAFIncidentRecord& increc )
  62. {
  63. __HCP_FUNC_ENTRY( "CSAFIncidentRecord::operator<<" );
  64. HRESULT hr;
  65. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_dwRecIndex );
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrVendorID );
  67. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrProductID );
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrDisplay );
  69. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrURL );
  70. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrProgress );
  71. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrXMLDataFile);
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrXMLBlob );
  73. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_dCreatedTime );
  74. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_dChangedTime );
  75. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_dClosedTime );
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_iStatus );
  77. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrSecurity );
  78. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << increc.m_bstrOwner );
  79. hr = S_OK;
  80. __HCP_FUNC_CLEANUP;
  81. __HCP_FUNC_EXIT(hr);
  82. }
  83. ////////////////////////////////////////////////////////////////////////////////
  84. ////////////////////////////////////////////////////////////////////////////////
  85. ////////////////////////////////////////////////////////////////////////////////
  86. CIncidentStore::CIncidentStore() : MPC::NamedMutex( c_szEventObject )
  87. {
  88. m_fLoaded = false; // bool m_fLoaded;
  89. m_fDirty = false; // bool m_fDirty;
  90. m_dwNextIndex = 0; // DWORD m_dwNextIndex;
  91. // List m_lstIncidents;
  92. m_strNotificationGuid = ""; // String m_strNotificationGuid;
  93. }
  94. CIncidentStore::~CIncidentStore()
  95. {
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. HRESULT CIncidentStore::Load()
  99. {
  100. __HCP_FUNC_ENTRY( "CIncidentStore::Load" );
  101. HRESULT hr;
  102. HANDLE hFile = INVALID_HANDLE_VALUE;
  103. if(m_fLoaded == false)
  104. {
  105. MPC::wstring szFile = c_szStorePath; MPC::SubstituteEnvVariables( szFile );
  106. m_dwNextIndex = 0;
  107. //
  108. // Get the named mutex, so that only one instance at a time can access the store.
  109. //
  110. __MPC_EXIT_IF_METHOD_FAILS(hr, Acquire());
  111. //
  112. // Open the store.
  113. //
  114. hFile = ::CreateFileW( szFile.c_str() ,
  115. GENERIC_READ ,
  116. 0 ,
  117. NULL ,
  118. OPEN_EXISTING ,
  119. FILE_ATTRIBUTE_NORMAL ,
  120. NULL );
  121. if(hFile == INVALID_HANDLE_VALUE)
  122. {
  123. DWORD dwRes = ::GetLastError();
  124. if(dwRes != ERROR_FILE_NOT_FOUND)
  125. {
  126. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, dwRes);
  127. }
  128. }
  129. else
  130. {
  131. MPC::Serializer& stream = MPC::Serializer_File( hFile );
  132. DWORD dwVer;
  133. if(SUCCEEDED(stream >> dwVer) && dwVer == l_dwVersion)
  134. {
  135. if(SUCCEEDED(stream >> m_dwNextIndex))
  136. {
  137. //if (SUCCEEDED( stream >> m_strNotificationGuid))
  138. //{
  139. while(1)
  140. {
  141. Iter it = m_lstIncidents.insert( m_lstIncidents.end() );
  142. if(FAILED(stream >> *it))
  143. {
  144. m_lstIncidents.erase( it );
  145. break;
  146. }
  147. }
  148. //}
  149. }
  150. }
  151. }
  152. }
  153. m_fLoaded = true;
  154. m_fDirty = false;
  155. hr = S_OK;
  156. __HCP_FUNC_CLEANUP;
  157. if(hFile != INVALID_HANDLE_VALUE) ::CloseHandle( hFile );
  158. __HCP_FUNC_EXIT(hr);
  159. }
  160. HRESULT CIncidentStore::Save()
  161. {
  162. __HCP_FUNC_ENTRY( "CIncidentStore::Save" );
  163. HRESULT hr;
  164. HANDLE hFile = INVALID_HANDLE_VALUE;
  165. if(m_fLoaded && m_fDirty)
  166. {
  167. MPC::wstring szFile = c_szStorePath; MPC::SubstituteEnvVariables( szFile );
  168. //
  169. // Open the store.
  170. //
  171. __MPC_EXIT_IF_INVALID_HANDLE(hr, hFile, ::CreateFileW( szFile.c_str() ,
  172. GENERIC_WRITE ,
  173. 0 ,
  174. NULL ,
  175. CREATE_ALWAYS ,
  176. FILE_ATTRIBUTE_NORMAL ,
  177. NULL ));
  178. {
  179. MPC::Serializer& stream = MPC::Serializer_File( hFile );
  180. Iter it;
  181. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << l_dwVersion );
  182. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << m_dwNextIndex);
  183. // Persist the string version of the notification GUID
  184. //__MPC_EXIT_IF_METHOD_FAILS(hr, stream << m_strNotificationGuid);
  185. for(it = m_lstIncidents.begin(); it != m_lstIncidents.end(); it++)
  186. {
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << *it);
  188. }
  189. }
  190. m_fDirty = false;
  191. }
  192. hr = S_OK;
  193. __HCP_FUNC_CLEANUP;
  194. if(hFile != INVALID_HANDLE_VALUE) ::CloseHandle( hFile );
  195. __HCP_FUNC_EXIT(hr);
  196. }
  197. ////////////////////////////////////////////////////////////////////////////////
  198. HRESULT CIncidentStore::OpenChannel( CSAFChannel* pChan )
  199. {
  200. __HCP_FUNC_ENTRY( "CIncidentStore::OpenChannel" );
  201. HRESULT hr;
  202. LPCWSTR szVendorID = pChan->GetVendorID ();
  203. LPCWSTR szProductID = pChan->GetProductID();
  204. IterConst it;
  205. SANITIZEWSTR( szVendorID );
  206. SANITIZEWSTR( szProductID );
  207. __MPC_EXIT_IF_METHOD_FAILS(hr, Load());
  208. for(it = m_lstIncidents.begin(); it != m_lstIncidents.end(); it++)
  209. {
  210. if(MPC::StrICmp( it->m_bstrVendorID , szVendorID ) == 0 &&
  211. MPC::StrICmp( it->m_bstrProductID, szProductID ) == 0 )
  212. {
  213. __MPC_EXIT_IF_METHOD_FAILS(hr, pChan->Import( *it, NULL ));
  214. }
  215. }
  216. hr = S_OK;
  217. __HCP_FUNC_CLEANUP;
  218. __HCP_FUNC_EXIT(hr);
  219. }
  220. HRESULT CIncidentStore::AddRec( CSAFChannel* pChan ,
  221. BSTR bstrOwner ,
  222. BSTR bstrDesc ,
  223. BSTR bstrURL ,
  224. BSTR bstrProgress ,
  225. BSTR bstrXMLDataFile,
  226. BSTR bstrXMLBlob,
  227. CSAFIncidentItem* *ppItem )
  228. {
  229. __HCP_FUNC_ENTRY( "CIncidentStore::Init" );
  230. HRESULT hr;
  231. Iter it;
  232. __MPC_EXIT_IF_METHOD_FAILS(hr, Load());
  233. it = m_lstIncidents.insert( m_lstIncidents.end() );
  234. it->m_dwRecIndex = m_dwNextIndex++;
  235. it->m_bstrVendorID = pChan->GetVendorID ();
  236. it->m_bstrProductID = pChan->GetProductID();
  237. it->m_bstrDisplay = bstrDesc;
  238. it->m_bstrURL = bstrURL;
  239. it->m_bstrProgress = bstrProgress;
  240. it->m_bstrXMLDataFile = bstrXMLDataFile;
  241. it->m_bstrXMLBlob = bstrXMLBlob;
  242. it->m_dCreatedTime = MPC::GetLocalTime();
  243. it->m_dChangedTime = it->m_dCreatedTime;
  244. it->m_dClosedTime = 0;
  245. it->m_iStatus = pchIncidentOpen;
  246. it->m_bstrOwner = bstrOwner;
  247. m_fDirty = true;
  248. //
  249. // Create the IncidentItem.
  250. //
  251. __MPC_EXIT_IF_METHOD_FAILS(hr, pChan->Import( *it, ppItem ));
  252. hr = S_OK;
  253. __HCP_FUNC_CLEANUP;
  254. __HCP_FUNC_EXIT(hr);
  255. }
  256. HRESULT CIncidentStore::DeleteRec( CSAFIncidentItem* pItem )
  257. {
  258. __HCP_FUNC_ENTRY( "CIncidentStore::DeleteRec" );
  259. HRESULT hr;
  260. DWORD dwIndex = pItem->GetRecIndex();
  261. Iter it;
  262. for(it = m_lstIncidents.begin(); it != m_lstIncidents.end(); it++)
  263. {
  264. if(it->m_dwRecIndex == dwIndex)
  265. {
  266. m_lstIncidents.erase( it );
  267. m_fDirty = true; break;
  268. }
  269. }
  270. hr = S_OK;
  271. __HCP_FUNC_EXIT(hr);
  272. }
  273. HRESULT CIncidentStore::UpdateRec( CSAFIncidentItem* pItem )
  274. {
  275. __HCP_FUNC_ENTRY( "CIncidentStore::UpdateRec" );
  276. HRESULT hr;
  277. DWORD dwIndex = pItem->GetRecIndex();
  278. Iter it;
  279. for(it = m_lstIncidents.begin(); it != m_lstIncidents.end(); it++)
  280. {
  281. if(it->m_dwRecIndex == dwIndex)
  282. {
  283. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->Export( *it ));
  284. m_fDirty = true; break;
  285. }
  286. }
  287. hr = S_OK;
  288. __HCP_FUNC_CLEANUP;
  289. __HCP_FUNC_EXIT(hr);
  290. }