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.

1747 lines
51 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. incident.cpp
  5. Abstract:
  6. Incident object
  7. Revision History:
  8. DerekM created 07/21/99
  9. Kalyani Narlanka (KalyaniN) 03/15/01
  10. Moved Incident Object from HelpService to HelpCtr to improve Perf.
  11. Impersonation code removed while loading an incident XML file as this no longer
  12. lives in a service.
  13. ********************************************************************/
  14. #include "stdafx.h"
  15. #include "msxml.h"
  16. #include <HCP_trace.h>
  17. const DWORD c_dwidDone = 0;
  18. const DWORD c_dwidMisc = 1;
  19. const DWORD c_dwidSnap = 2;
  20. const DWORD c_dwidHist = 3;
  21. const DWORD c_dwidTrace = 4;
  22. const DWORD c_dwidType = 5;
  23. const DWORD c_dwidUser = 6;
  24. const DWORD c_dwidProb = 7;
  25. const DWORD c_dwidID = 8;
  26. const DWORD c_dwidName = 9;
  27. const DWORD c_dwidXSL = 10;
  28. const DWORD c_dwidRCReq = 11;
  29. const DWORD c_dwidRCEnc = 12;
  30. const DWORD c_dwidRCTkt = 13;
  31. const DWORD c_dwidStartPg = 14;
  32. #define TEXT_TAG_UPLOADINFO L"UPLOADINFO"
  33. #define TEXT_TAG_UPLOADDATA L"UPLOADDATA"
  34. #define TEXT_TAG_SNAPSHOT L"//SNAPSHOT"
  35. #define TEXT_TAG_HISTORY L"//HISTORY"
  36. #define TEXT_TAG_HELPSESSION L"//HELPSESSIONCOLLECTION"
  37. #define TEXT_ATTR_INC_TYPE L"TYPE"
  38. #define TEXT_UT_BUG L"Bug"
  39. #define TEXT_TRUE L"1"
  40. #define TEXT_FALSE L"0"
  41. static CComBSTR l_bstrXmlSkeleton( L"<?xml version=\"1.0\" encoding=\"Unicode\" ?><ROOTNODE ATTRIB=\"VALUE\"><CHILDNODE/></ROOTNODE>" );
  42. /////////////////////////////////////////////////////////////////////////////
  43. // utility functions
  44. static HRESULT WriteData( IStream* pstmDest, DWORD dw )
  45. {
  46. __HCP_FUNC_ENTRY( "WriteData(DWORD)" );
  47. HRESULT hr;
  48. DWORD cbWritten;
  49. __MPC_PARAMCHECK_BEGIN(hr)
  50. __MPC_PARAMCHECK_NOTNULL(pstmDest);
  51. __MPC_PARAMCHECK_END();
  52. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmDest->Write( &dw, sizeof(dw), &cbWritten ));
  53. _ASSERT(cbWritten == sizeof(dw));
  54. hr = S_OK;
  55. __HCP_FUNC_CLEANUP;
  56. __HCP_FUNC_EXIT(hr);
  57. }
  58. // **************************************************************************
  59. static HRESULT WriteData( IStream* pstmDest, LPCWSTR wszSrc, BOOL fWriteSize = FALSE )
  60. {
  61. __HCP_FUNC_ENTRY( "WriteData(WCHAR)" );
  62. HRESULT hr;
  63. DWORD cbWritten;
  64. DWORD cbToWrite;
  65. __MPC_PARAMCHECK_BEGIN(hr)
  66. __MPC_PARAMCHECK_NOTNULL(pstmDest);
  67. // __MPC_PARAMCHECK_NOTNULL(wszSrc);
  68. __MPC_PARAMCHECK_END();
  69. SANITIZEWSTR(wszSrc);
  70. cbToWrite = wcslen(wszSrc) * sizeof(WCHAR);
  71. if(fWriteSize)
  72. {
  73. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pstmDest, cbToWrite ));
  74. }
  75. if(cbToWrite)
  76. {
  77. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmDest->Write( wszSrc, cbToWrite, &cbWritten ));
  78. _ASSERT(cbWritten == cbToWrite);
  79. }
  80. hr = S_OK;
  81. __HCP_FUNC_CLEANUP;
  82. __HCP_FUNC_EXIT(hr);
  83. }
  84. // **************************************************************************
  85. static HRESULT WriteXMLAttribute( IStream* pStm, LPCWSTR wszName, LPCWSTR wszValue, IXMLDOMDocument* pDoc )
  86. {
  87. __HCP_FUNC_ENTRY( "WriteXMLAttribute" );
  88. HRESULT hr;
  89. __MPC_PARAMCHECK_BEGIN(hr)
  90. __MPC_PARAMCHECK_NOTNULL(pStm);
  91. __MPC_PARAMCHECK_NOTNULL(wszName);
  92. __MPC_PARAMCHECK_NOTNULL(pDoc);
  93. __MPC_PARAMCHECK_END();
  94. if(wszValue)
  95. {
  96. CComPtr<IXMLDOMAttribute> pAttrib;
  97. CComBSTR bstrXML;
  98. __MPC_EXIT_IF_METHOD_FAILS(hr, pDoc->createAttribute ( CComBSTR ( wszName ), &pAttrib ));
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, pAttrib->put_nodeValue( CComVariant( wszValue ) ));
  100. __MPC_EXIT_IF_METHOD_FAILS(hr, pAttrib->get_xml( &bstrXML ));
  101. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, bstrXML ));
  102. }
  103. else
  104. {
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, wszName ));
  106. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"=\"\"" ));
  107. }
  108. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L" " ));
  109. hr = S_OK;
  110. __HCP_FUNC_CLEANUP;
  111. __HCP_FUNC_EXIT(hr);
  112. }
  113. // **************************************************************************
  114. static HRESULT WriteData( IStream* pstmDest, SHelpSessionItem &hsi, IXMLDOMDocument* pDoc = NULL )
  115. {
  116. __HCP_FUNC_ENTRY( "WriteData(SHelpSessionItem)" );
  117. HRESULT hr;
  118. DWORD cbWritten;
  119. __MPC_PARAMCHECK_BEGIN(hr)
  120. __MPC_PARAMCHECK_NOTNULL(pstmDest);
  121. __MPC_PARAMCHECK_END();
  122. // write out the URL
  123. if(pDoc)
  124. {
  125. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData ( pstmDest, L"<HELPSESSIONITEM " ));
  126. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pstmDest, L"URL", hsi.bstrURL, pDoc ));
  127. }
  128. else
  129. {
  130. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pstmDest, hsi.bstrURL, TRUE ));
  131. }
  132. // write out the title
  133. if(pDoc)
  134. {
  135. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pstmDest, L"TITLE", hsi.bstrTitle, pDoc ));
  136. }
  137. else
  138. {
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pstmDest, hsi.bstrTitle, TRUE ));
  140. }
  141. // write out the last visited date
  142. if(pDoc)
  143. {
  144. MPC::wstring strDate;
  145. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertDateToString( hsi.dtLastVisited, strDate, /*fGMT*/false, /*fCIM*/false, -1 )); // Always use US locale.
  146. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pstmDest, L"LASTVISITED", strDate.c_str(), pDoc ));
  147. }
  148. else
  149. {
  150. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmDest->Write( &(hsi.dtLastVisited), sizeof(hsi.dtLastVisited), &cbWritten ));
  151. _ASSERT(cbWritten == sizeof(hsi.dtLastVisited));
  152. }
  153. // write out the last visited date
  154. if(pDoc)
  155. {
  156. MPC::wstring strDate;
  157. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertDateToString( hsi.dtDuration, strDate, /*fGMT*/false, /*fCIM*/false, -1 )); // Always use US locale.
  158. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pstmDest, L"DURATION", strDate.c_str(), pDoc ));
  159. }
  160. else
  161. {
  162. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmDest->Write( &(hsi.dtDuration), sizeof(hsi.dtDuration), &cbWritten ));
  163. _ASSERT(cbWritten == sizeof(hsi.dtDuration));
  164. }
  165. // write out the # of hits
  166. if(pDoc)
  167. {
  168. CComVariant var;
  169. var = hsi.cHits;
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, var.ChangeType( VT_BSTR ));
  171. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pstmDest, L"HITS", V_BSTR(&var), pDoc ));
  172. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pstmDest, L"/>" ));
  173. }
  174. else
  175. {
  176. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmDest->Write( &(hsi.cHits), sizeof(hsi.cHits), &cbWritten ));
  177. _ASSERT(cbWritten == sizeof(hsi.cHits));
  178. }
  179. hr = S_OK;
  180. __HCP_FUNC_CLEANUP;
  181. __HCP_FUNC_EXIT(hr);
  182. }
  183. // **************************************************************************
  184. // **************************************************************************
  185. // **************************************************************************
  186. // **************************************************************************
  187. static HRESULT ReadData( IStream* pstmSrc, DWORD *pdw )
  188. {
  189. __HCP_FUNC_ENTRY( "ReadData(DWORD)" );
  190. HRESULT hr;
  191. DWORD cbRead;
  192. __MPC_PARAMCHECK_BEGIN(hr)
  193. __MPC_PARAMCHECK_NOTNULL(pstmSrc);
  194. __MPC_PARAMCHECK_NOTNULL(pdw);
  195. __MPC_PARAMCHECK_END();
  196. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( pdw, sizeof(DWORD), &cbRead ));
  197. _ASSERT(cbRead == sizeof(DWORD));
  198. hr = S_OK;
  199. __HCP_FUNC_CLEANUP;
  200. __HCP_FUNC_EXIT(hr);
  201. }
  202. // **************************************************************************
  203. static HRESULT ReadData( IStream* pstmSrc, BSTR *pbstr )
  204. {
  205. __HCP_FUNC_ENTRY( "ReadData(BSTR)" );
  206. HRESULT hr;
  207. DWORD cbRead;
  208. DWORD cbToRead;
  209. CComBSTR bstr;
  210. __MPC_PARAMCHECK_BEGIN(hr)
  211. __MPC_PARAMCHECK_NOTNULL(pstmSrc);
  212. __MPC_PARAMCHECK_POINTER_AND_SET(pbstr,NULL);
  213. __MPC_PARAMCHECK_END();
  214. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pstmSrc, &cbToRead ));
  215. // return S_FALSE to indicate we didn't successfully didn't read anything
  216. if(cbToRead == 0)
  217. {
  218. __MPC_SET_ERROR_AND_EXIT(hr, S_FALSE);
  219. }
  220. bstr.Attach( ::SysAllocStringByteLen(NULL, cbToRead) );
  221. if(bstr.m_str == NULL)
  222. {
  223. __MPC_SET_ERROR_AND_EXIT(hr, E_OUTOFMEMORY);
  224. }
  225. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( bstr, cbToRead, &cbRead ));
  226. *pbstr = bstr.Detach();
  227. hr = S_OK;
  228. __HCP_FUNC_CLEANUP;
  229. __HCP_FUNC_EXIT(hr);
  230. }
  231. // **************************************************************************
  232. static HRESULT ReadData( IStream* pstmSrc, LPVOID *ppv, DWORD *pcb)
  233. {
  234. __HCP_FUNC_ENTRY( "ReadData(LPVOID)" );
  235. HRESULT hr;
  236. BYTE* pv = NULL;
  237. DWORD cb;
  238. DWORD cbRead;
  239. __MPC_PARAMCHECK_BEGIN(hr)
  240. __MPC_PARAMCHECK_NOTNULL(pstmSrc);
  241. __MPC_PARAMCHECK_POINTER_AND_SET(ppv,NULL);
  242. __MPC_PARAMCHECK_POINTER_AND_SET(pcb,0);
  243. __MPC_PARAMCHECK_END();
  244. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pstmSrc, &cb ));
  245. *pcb = cb;
  246. // return S_FALSE to indicate we didn't successfully didn't read anything
  247. if(cb == 0)
  248. {
  249. __MPC_SET_ERROR_AND_EXIT(hr, S_FALSE);
  250. }
  251. __MPC_EXIT_IF_ALLOC_FAILS(hr, pv, new BYTE[ cb ]);
  252. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( pv, cb, &cbRead ));
  253. _ASSERT(cb == cbRead);
  254. *ppv = pv; pv = NULL;
  255. hr = S_OK;
  256. __HCP_FUNC_CLEANUP;
  257. if(pv) delete [] pv;
  258. __HCP_FUNC_EXIT(hr);
  259. }
  260. // **************************************************************************
  261. static HRESULT ReadData( IStream* pstmSrc, SHelpSessionItem &hsi )
  262. {
  263. __HCP_FUNC_ENTRY( "ReadData(SHelpSessionItem)" );
  264. HRESULT hr;
  265. DWORD cbRead;
  266. __MPC_PARAMCHECK_BEGIN(hr)
  267. __MPC_PARAMCHECK_NOTNULL(pstmSrc);
  268. __MPC_PARAMCHECK_END();
  269. // read the URL
  270. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData(pstmSrc, &hsi.bstrURL ));
  271. // read the Title
  272. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData(pstmSrc, &hsi.bstrTitle ));
  273. // read the last visited date
  274. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( &(hsi.dtLastVisited), sizeof(hsi.dtLastVisited), &cbRead ));
  275. _ASSERT(cbRead == sizeof(hsi.dtLastVisited));
  276. // read the duration
  277. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( &(hsi.dtDuration), sizeof(hsi.dtDuration), &cbRead ));
  278. _ASSERT(cbRead == sizeof(hsi.dtDuration));
  279. // read the # of hits
  280. __MPC_EXIT_IF_METHOD_FAILS(hr, pstmSrc->Read( &(hsi.cHits), sizeof(hsi.cHits), &cbRead ));
  281. _ASSERT(cbRead == sizeof(hsi.cHits));
  282. hr = S_OK;
  283. __HCP_FUNC_CLEANUP;
  284. __HCP_FUNC_EXIT(hr);
  285. }
  286. // **************************************************************************
  287. static HRESULT SetStream( /*[in/out]*/ CComBSTR& bstrXML, /*[in]*/ IUnknown *punkStm )
  288. {
  289. __HCP_FUNC_ENTRY( "SetStream" );
  290. HRESULT hr;
  291. CComPtr<IXMLDOMDocument> xddDoc;
  292. CComPtr<IXMLDOMElement> xdeRoot;
  293. CComVariant vStream = punkStm;
  294. VARIANT_BOOL fSuccess;
  295. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoCreateInstance( CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&xddDoc ));
  296. __MPC_EXIT_IF_METHOD_FAILS(hr, xddDoc->load( vStream, &fSuccess ));
  297. if(fSuccess != VARIANT_TRUE)
  298. {
  299. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  300. }
  301. __MPC_EXIT_IF_METHOD_FAILS(hr, xddDoc->get_documentElement( &xdeRoot ));
  302. bstrXML.Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, xdeRoot->get_xml( &bstrXML ));
  303. hr = S_OK;
  304. __HCP_FUNC_CLEANUP;
  305. __HCP_FUNC_EXIT(hr);
  306. }
  307. /////////////////////////////////////////////////////////////////////////////
  308. // construction / destruction
  309. // **************************************************************************
  310. CSAFIncident::CSAFIncident()
  311. {
  312. m_rghsi = NULL;
  313. m_chsi = 0;
  314. m_eut = eutEscalated;
  315. // By default RCRequested is False and RCTicketEncrypted is False.
  316. m_fRCRequested = VARIANT_FALSE;
  317. m_fRCTicketEncrypted = VARIANT_FALSE;
  318. // MPC::Impersonation m_imp;
  319. }
  320. // **************************************************************************
  321. CSAFIncident::~CSAFIncident()
  322. {
  323. Cleanup();
  324. }
  325. // **************************************************************************
  326. void CSAFIncident::Cleanup()
  327. {
  328. m_pDict .Release();
  329. m_bstrUser .Empty ();
  330. m_bstrID .Empty ();
  331. m_bstrName .Empty ();
  332. m_bstrProb .Empty ();
  333. m_bstrSnapshot.Empty ();
  334. m_bstrHistory .Empty ();
  335. m_bstrXSL .Empty ();
  336. m_bstrRCTicket.Empty ();
  337. m_bstrStartPg .Empty ();
  338. delete [] m_rghsi; m_rghsi = NULL;
  339. m_chsi = 0;
  340. m_eut = eutEscalated;
  341. }
  342. ////////////////////
  343. /////////////////////////////////////////////////////////////////////////////
  344. // CSAFIncident properties
  345. // **************************************************************************
  346. STDMETHODIMP CSAFIncident::get_IncidentXSL(BSTR *pbstrUser)
  347. {
  348. MPC::SmartLock<_ThreadModel> lock( this );
  349. return MPC::GetBSTR( m_bstrXSL, pbstrUser );
  350. }
  351. // **************************************************************************
  352. STDMETHODIMP CSAFIncident::put_IncidentXSL(BSTR bstrUser)
  353. {
  354. MPC::SmartLock<_ThreadModel> lock( this );
  355. return MPC::PutBSTR( m_bstrXSL, bstrUser );
  356. }
  357. // **************************************************************************
  358. STDMETHODIMP CSAFIncident::get_UserName(BSTR *pbstrUser)
  359. {
  360. MPC::SmartLock<_ThreadModel> lock( this );
  361. return MPC::GetBSTR( m_bstrUser, pbstrUser );
  362. }
  363. // **************************************************************************
  364. STDMETHODIMP CSAFIncident::put_UserName(BSTR bstrUser)
  365. {
  366. MPC::SmartLock<_ThreadModel> lock( this );
  367. return MPC::PutBSTR( m_bstrUser, bstrUser );
  368. }
  369. // **************************************************************************
  370. STDMETHODIMP CSAFIncident::get_ProductID(BSTR *pbstrID)
  371. {
  372. MPC::SmartLock<_ThreadModel> lock( this );
  373. return MPC::GetBSTR( m_bstrID, pbstrID );
  374. }
  375. // **************************************************************************
  376. STDMETHODIMP CSAFIncident::put_ProductID(BSTR bstrID)
  377. {
  378. MPC::SmartLock<_ThreadModel> lock( this );
  379. return MPC::PutBSTR( m_bstrID, bstrID );
  380. }
  381. // **************************************************************************
  382. STDMETHODIMP CSAFIncident::get_ProductName(BSTR *pbstrName)
  383. {
  384. MPC::SmartLock<_ThreadModel> lock( this );
  385. return MPC::GetBSTR( m_bstrName, pbstrName );
  386. }
  387. // **************************************************************************
  388. STDMETHODIMP CSAFIncident::put_ProductName(BSTR bstrName)
  389. {
  390. MPC::SmartLock<_ThreadModel> lock( this );
  391. return MPC::PutBSTR( m_bstrName, bstrName );
  392. }
  393. // **************************************************************************
  394. STDMETHODIMP CSAFIncident::get_ProblemDescription(BSTR *pbstrProb)
  395. {
  396. MPC::SmartLock<_ThreadModel> lock( this );
  397. return MPC::GetBSTR( m_bstrProb, pbstrProb );
  398. }
  399. // **************************************************************************
  400. STDMETHODIMP CSAFIncident::put_ProblemDescription(BSTR bstrProb)
  401. {
  402. MPC::SmartLock<_ThreadModel> lock( this );
  403. return MPC::PutBSTR( m_bstrProb, bstrProb );
  404. }
  405. // **************************************************************************
  406. STDMETHODIMP CSAFIncident::put_MachineSnapshot(IUnknown *punkStm)
  407. {
  408. MPC::SmartLock<_ThreadModel> lock( this );
  409. return SetStream( m_bstrSnapshot, punkStm );
  410. }
  411. // **************************************************************************
  412. STDMETHODIMP CSAFIncident::put_MachineHistory(IUnknown *punkStm)
  413. {
  414. MPC::SmartLock<_ThreadModel> lock( this );
  415. return SetStream( m_bstrHistory, punkStm );
  416. }
  417. // **************************************************************************
  418. STDMETHODIMP CSAFIncident::put_SelfHelpTrace( IUnknown* punkStm )
  419. {
  420. __HCP_FUNC_ENTRY("CSAFIncident::put_SelfHelpTrace");
  421. HRESULT hr;
  422. CComPtr<IPCHCollection> pClct;
  423. int i;
  424. MPC::SmartLock<_ThreadModel> lock( this );
  425. __MPC_PARAMCHECK_BEGIN(hr)
  426. __MPC_PARAMCHECK_NOTNULL(punkStm);
  427. __MPC_PARAMCHECK_END();
  428. __MPC_EXIT_IF_METHOD_FAILS(hr, punkStm->QueryInterface( IID_IPCHCollection, (LPVOID *)&pClct ));
  429. __MPC_EXIT_IF_METHOD_FAILS(hr, pClct->get_Count( &m_chsi ));
  430. delete [] m_rghsi; __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rghsi, new SHelpSessionItem[m_chsi]);
  431. for(i = 0; i < m_chsi; i++)
  432. {
  433. SHelpSessionItem& rghsi = m_rghsi[i];
  434. CComPtr<IPCHHelpSessionItem> pItem;
  435. CComVariant var;
  436. __MPC_EXIT_IF_METHOD_FAILS(hr, pClct->get_Item( i+1, &var ));
  437. _ASSERT(V_VT(&var) == VT_DISPATCH || V_VT(&var) == VT_UNKNOWN);
  438. __MPC_EXIT_IF_METHOD_FAILS(hr, V_UNKNOWN(&var)->QueryInterface( IID_IPCHHelpSessionItem, (LPVOID *)&pItem ));
  439. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->get_URL ( &rghsi.bstrURL ));
  440. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->get_Title ( &rghsi.bstrTitle ));
  441. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->get_LastVisited( &rghsi.dtLastVisited ));
  442. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->get_Duration ( &rghsi.dtDuration ));
  443. __MPC_EXIT_IF_METHOD_FAILS(hr, pItem->get_NumOfHits ( &rghsi.cHits ));
  444. }
  445. hr = S_OK;
  446. __HCP_FUNC_CLEANUP;
  447. __HCP_FUNC_EXIT(hr);
  448. }
  449. // **************************************************************************
  450. HRESULT CSAFIncident::InitDictionary()
  451. {
  452. if(m_pDict) return S_OK;
  453. return ::CoCreateInstance( CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER, IID_IDictionary, (LPVOID *)&m_pDict );
  454. }
  455. STDMETHODIMP CSAFIncident::get_Misc( IDispatch* *ppdispDict )
  456. {
  457. __HCP_BEGIN_PROPERTY_GET("SAFIncident::get_Misc",hr,ppdispDict);
  458. __MPC_EXIT_IF_METHOD_FAILS(hr, InitDictionary());
  459. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict.QueryInterface( ppdispDict ));
  460. __HCP_END_PROPERTY(hr);
  461. }
  462. // **************************************************************************
  463. STDMETHODIMP CSAFIncident::put_UploadType( EUploadType eut )
  464. {
  465. __HCP_BEGIN_PROPERTY_PUT("SAFIncident::put_UploadType",hr);
  466. // As the valid upload types are 0,1,2 if the value of UploadType is
  467. // outside this range we should not set it and also flag an error.
  468. switch(eut)
  469. {
  470. case eutBug:
  471. case eutEscalated:
  472. case eutNonEscalated:
  473. m_eut = eut;
  474. break;
  475. default:
  476. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  477. }
  478. __HCP_END_PROPERTY(hr);
  479. }
  480. // **************************************************************************
  481. STDMETHODIMP CSAFIncident::get_UploadType( EUploadType *pVal )
  482. {
  483. __HCP_BEGIN_PROPERTY_GET2("CSAFIncident::get_UploadType",hr,pVal,m_eut);
  484. __HCP_END_PROPERTY(hr);
  485. }
  486. // RC Additions
  487. // **************************************************************************
  488. STDMETHODIMP CSAFIncident::get_RCRequested(VARIANT_BOOL *pVal)
  489. {
  490. __HCP_BEGIN_PROPERTY_GET2("CSAFIncident::get_RCRequested",hr,pVal,m_fRCRequested);
  491. __HCP_END_PROPERTY(hr);
  492. }
  493. // **************************************************************************
  494. STDMETHODIMP CSAFIncident::put_RCRequested(VARIANT_BOOL Val)
  495. {
  496. __HCP_BEGIN_PROPERTY_PUT("CSAFIncident::put_RCRequested",hr);
  497. m_fRCRequested = Val;
  498. __HCP_END_PROPERTY(hr);
  499. }
  500. // **************************************************************************
  501. STDMETHODIMP CSAFIncident::get_RCTicketEncrypted( VARIANT_BOOL *pVal )
  502. {
  503. __HCP_BEGIN_PROPERTY_GET2("CSAFIncident::get_RCTicketEncrypted",hr,pVal,m_fRCTicketEncrypted);
  504. __HCP_END_PROPERTY(hr);
  505. }
  506. // **************************************************************************
  507. STDMETHODIMP CSAFIncident::put_RCTicketEncrypted( VARIANT_BOOL newVal )
  508. {
  509. __HCP_BEGIN_PROPERTY_PUT("CSAFIncident::put_RCTicketEncrypted",hr);
  510. m_fRCTicketEncrypted = newVal;
  511. __HCP_END_PROPERTY(hr);
  512. }
  513. // **************************************************************************
  514. STDMETHODIMP CSAFIncident::get_RCTicket( BSTR *pVal )
  515. {
  516. MPC::SmartLock<_ThreadModel> lock( this );
  517. return MPC::GetBSTR( m_bstrRCTicket, pVal, true );
  518. }
  519. // **************************************************************************
  520. STDMETHODIMP CSAFIncident::put_RCTicket( BSTR bstrVal )
  521. {
  522. MPC::SmartLock<_ThreadModel> lock( this );
  523. return MPC::PutBSTR( m_bstrRCTicket, bstrVal, true );
  524. }
  525. // **************************************************************************
  526. STDMETHODIMP CSAFIncident::get_StartPage( BSTR *pVal )
  527. {
  528. MPC::SmartLock<_ThreadModel> lock( this );
  529. return MPC::GetBSTR( m_bstrStartPg, pVal );
  530. }
  531. // **************************************************************************
  532. STDMETHODIMP CSAFIncident::put_StartPage( BSTR newVal)
  533. {
  534. MPC::SmartLock<_ThreadModel> lock( this );
  535. return MPC::PutBSTR( m_bstrStartPg, newVal );
  536. }
  537. /////////////////////////////////////////////////////////////////////////////
  538. // CSAFIncident methods
  539. STDMETHODIMP CSAFIncident::GetXML( BSTR bstrFileName )
  540. {
  541. __HCP_FUNC_ENTRY("CSAFIncident::GetXML");
  542. HRESULT hr;
  543. CComPtr<MPC::FileStream> pfs;
  544. MPC::SmartLock<_ThreadModel> lock( this );
  545. __MPC_PARAMCHECK_BEGIN(hr)
  546. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFileName);
  547. __MPC_PARAMCHECK_END();
  548. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pfs ));
  549. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->InitForWrite( bstrFileName ));
  550. __MPC_EXIT_IF_METHOD_FAILS(hr, DoXML( pfs ));
  551. hr = S_OK;
  552. __HCP_FUNC_CLEANUP;
  553. __HCP_FUNC_EXIT(hr);
  554. }
  555. // **************************************************************************
  556. STDMETHODIMP CSAFIncident::GetXMLAsStream( IUnknown* *ppunkStm )
  557. {
  558. __HCP_FUNC_ENTRY("CSAFIncident::GetXMLAsStream");
  559. HRESULT hr;
  560. CComPtr<MPC::FileStream> pfs;
  561. MPC::wstring szTempFile;
  562. LARGE_INTEGER liFilePos = { 0, 0 };
  563. MPC::SmartLock<_ThreadModel> lock( this );
  564. __MPC_PARAMCHECK_BEGIN(hr)
  565. __MPC_PARAMCHECK_POINTER_AND_SET(ppunkStm,NULL);
  566. __MPC_PARAMCHECK_END();
  567. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pfs ));
  568. //
  569. // create a temporary file to hold the stream. We want to use a file cuz
  570. // otherwise, we're going to be using boatloads of memory for all the CIM
  571. // stuff...
  572. //
  573. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetTemporaryFileName( szTempFile ));
  574. // Adding GENERIC_READ
  575. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->InitForReadWrite( szTempFile.c_str() ));
  576. // Call release on delete similar to close on delete.
  577. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->DeleteOnRelease());
  578. __MPC_EXIT_IF_METHOD_FAILS(hr, DoXML( pfs ));
  579. // Rewind the stream pointer.
  580. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->Seek( liFilePos, STREAM_SEEK_SET, NULL ));
  581. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->QueryInterface( IID_IUnknown, (LPVOID *)ppunkStm ));
  582. hr = S_OK;
  583. __HCP_FUNC_CLEANUP;
  584. __HCP_FUNC_EXIT(hr);
  585. }
  586. // **************************************************************************
  587. HRESULT CSAFIncident::DoXML( IStream* pStm )
  588. {
  589. __HCP_FUNC_ENTRY("CSAFIncident::DoXML");
  590. HRESULT hr;
  591. CComPtr<IXMLDOMDocument> pDoc;
  592. ULARGE_INTEGER uli = { 0, 0 };
  593. VARIANT_BOOL varf;
  594. DWORD cbWritten;
  595. WCHAR wch = 0xfeff;
  596. __MPC_PARAMCHECK_BEGIN(hr)
  597. __MPC_PARAMCHECK_NOTNULL(pStm);
  598. __MPC_PARAMCHECK_END();
  599. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoCreateInstance( CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (LPVOID *)&pDoc ));
  600. __MPC_EXIT_IF_METHOD_FAILS(hr, pDoc->loadXML( l_bstrXmlSkeleton, &varf ));
  601. if(FAILED(hr = pStm->SetSize( uli )) && hr != E_NOTIMPL)
  602. {
  603. __MPC_FUNC_LEAVE;
  604. }
  605. // need to write out the character that marks the file as unicode
  606. __MPC_EXIT_IF_METHOD_FAILS(hr, pStm->Write( &wch, sizeof(wch), &cbWritten ));
  607. _ASSERT(cbWritten == sizeof(wch));
  608. // write out the header crap
  609. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"<?xml version=\"1.0\" encoding=\"Unicode\" ?>" ));
  610. // write out the XSL node if we have any
  611. if(m_bstrXSL.Length() > 0)
  612. {
  613. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrXSL.m_str ));
  614. }
  615. // write out the root node
  616. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"<UPLOADINFO" ));
  617. switch(m_eut)
  618. {
  619. case eutBug : __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L" TYPE=\"Bug\">" )); break;
  620. case eutEscalated : __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L" TYPE=\"Escalated\">" )); break;
  621. case eutNonEscalated: __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L" TYPE=\"NonEscalated\">" )); break;
  622. default : __MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
  623. }
  624. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"<UPLOADDATA " ));
  625. if(m_bstrUser.Length() > 0)
  626. {
  627. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"USERNAME", m_bstrUser.m_str, pDoc ));
  628. }
  629. if(m_bstrID.Length() > 0)
  630. {
  631. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"PRODUCTID", m_bstrID.m_str, pDoc ));
  632. }
  633. if(m_bstrName.Length() > 0)
  634. {
  635. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"PRODUCTNAME", m_bstrName.m_str, pDoc ));
  636. }
  637. if(m_bstrProb.Length() > 0)
  638. {
  639. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"PROBLEMDESCRIPTION", m_bstrProb.m_str, pDoc ));
  640. }
  641. if(m_bstrRCTicket.Length() > 0)
  642. {
  643. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"RCTICKET", m_bstrRCTicket.m_str, pDoc ));
  644. }
  645. #if 0 // This is no longer used.
  646. if(m_fRCRequested == VARIANT_TRUE)
  647. {
  648. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"RCREQUESTED", TEXT_TRUE, pDoc ));
  649. }
  650. else
  651. {
  652. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"RCREQUESTED", TEXT_FALSE, pDoc ));
  653. }
  654. #endif
  655. if(m_fRCTicketEncrypted == VARIANT_TRUE)
  656. {
  657. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"RCTICKETENCRYPTED", TEXT_TRUE, pDoc ));
  658. }
  659. else
  660. {
  661. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"RCTICKETENCRYPTED", TEXT_FALSE, pDoc ));
  662. }
  663. if(m_bstrStartPg.Length() > 0)
  664. {
  665. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, L"STARTPAGE", m_bstrStartPg.m_str, pDoc ));
  666. }
  667. // write out the contents of the dictionary object here...
  668. if(m_pDict)
  669. {
  670. CComPtr<IUnknown> punkEnum;
  671. CComPtr<IEnumVARIANT> pEnum;
  672. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->_NewEnum( &punkEnum ));
  673. __MPC_EXIT_IF_METHOD_FAILS(hr, punkEnum.QueryInterface( &pEnum ));
  674. for(;;)
  675. {
  676. CComVariant varKey;
  677. CComVariant varValue;
  678. ULONG cFetched;
  679. __MPC_EXIT_IF_METHOD_FAILS(hr, pEnum->Next( 1, &varKey, &cFetched ));
  680. // we're done enuming
  681. if(hr == S_FALSE || cFetched != 1) break;
  682. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->get_Item( &varKey, &varValue ));
  683. __MPC_EXIT_IF_METHOD_FAILS(hr, varKey .ChangeType( VT_BSTR ));
  684. __MPC_EXIT_IF_METHOD_FAILS(hr, varValue.ChangeType( VT_BSTR ));
  685. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteXMLAttribute( pStm, V_BSTR(&varKey), V_BSTR(&varValue), pDoc ));
  686. }
  687. }
  688. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"/>" ));
  689. // write out the CIM data streams
  690. if(m_bstrSnapshot.Length() > 0)
  691. {
  692. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrSnapshot ));
  693. }
  694. // write out the CIM data streams
  695. if(m_bstrHistory.Length() > 0)
  696. {
  697. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrHistory ));
  698. }
  699. // write out the trace stuff
  700. if(m_rghsi && m_chsi > 0)
  701. {
  702. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"<HELPSESSIONCOLLECTION>" ));
  703. for(int i = 0; i < m_chsi; i++)
  704. {
  705. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_rghsi[i], pDoc ));
  706. }
  707. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"</HELPSESSIONCOLLECTION>" ));
  708. }
  709. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, L"</UPLOADINFO>" ));
  710. hr = S_OK;
  711. __HCP_FUNC_CLEANUP;
  712. __HCP_FUNC_EXIT(hr);
  713. }
  714. // **************************************************************************
  715. STDMETHODIMP CSAFIncident::Save( BSTR bstrFileName )
  716. {
  717. __HCP_FUNC_ENTRY( "CSAFIncident::Save" );
  718. HRESULT hr;
  719. CComPtr<MPC::FileStream> pfs;
  720. MPC::SmartLock<_ThreadModel> lock( this );
  721. __MPC_PARAMCHECK_BEGIN(hr)
  722. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFileName);
  723. __MPC_PARAMCHECK_END();
  724. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pfs ));
  725. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->InitForWrite( bstrFileName ));
  726. __MPC_EXIT_IF_METHOD_FAILS(hr, DoSave( pfs ));
  727. hr = S_OK;
  728. __HCP_FUNC_CLEANUP;
  729. __HCP_FUNC_EXIT(hr);
  730. }
  731. STDMETHODIMP CSAFIncident::SaveToStream( IUnknown* *ppunkStm )
  732. {
  733. __HCP_FUNC_ENTRY("CSAFIncident::SaveToStream");
  734. HRESULT hr;
  735. CComPtr<MPC::FileStream> pfs;
  736. TCHAR szTempPath[MAX_PATH];
  737. TCHAR szTempFile[MAX_PATH];
  738. LARGE_INTEGER liFilePos = { 0, 0 };
  739. MPC::SmartLock<_ThreadModel> lock( this );
  740. __MPC_PARAMCHECK_BEGIN(hr)
  741. __MPC_PARAMCHECK_POINTER_AND_SET(ppunkStm,NULL);
  742. __MPC_PARAMCHECK_END();
  743. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pfs ));
  744. // create a temporary file to hold the stream. We want to use a file cuz
  745. // otherwise, we're going to be using boatloads of memory for all the CIM
  746. // stuff...
  747. __MPC_EXIT_IF_CALL_RETURNS_ZERO(hr, ::GetTempPath ( MAX_PATH, szTempPath ));
  748. __MPC_EXIT_IF_CALL_RETURNS_ZERO(hr, ::GetTempFileName( szTempPath, _T("PCH"), 0, szTempFile ));
  749. // To fix Bug 115618 open the file with read and write attributes.
  750. // hr = pfs->InitForReadWrite(bstrFileName, hFile);
  751. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->InitForReadWrite( CComBSTR( szTempFile ) ));
  752. // Mark the file for deletion
  753. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->DeleteOnRelease());
  754. __MPC_EXIT_IF_METHOD_FAILS(hr, DoSave( pfs ));
  755. // Rewind the stream after writing to it.
  756. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->Seek( liFilePos, STREAM_SEEK_SET, NULL ));
  757. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->QueryInterface( IID_IUnknown, (LPVOID *)ppunkStm ));
  758. hr = S_OK;
  759. __HCP_FUNC_CLEANUP;
  760. __HCP_FUNC_EXIT(hr);
  761. }
  762. HRESULT CSAFIncident::DoSave( IStream* pStm )
  763. {
  764. __HCP_FUNC_ENTRY("CSAFIncident::DoSave");
  765. HRESULT hr;
  766. ULARGE_INTEGER uli = { 0, 0 };
  767. __MPC_PARAMCHECK_BEGIN(hr)
  768. __MPC_PARAMCHECK_NOTNULL(pStm);
  769. __MPC_PARAMCHECK_END();
  770. if(FAILED(hr = pStm->SetSize( uli )) && hr != E_NOTIMPL)
  771. {
  772. __MPC_FUNC_LEAVE;
  773. }
  774. // write out upload type
  775. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidType ));
  776. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, (DWORD)m_eut ));
  777. // write out username
  778. if(m_bstrUser.Length() > 0)
  779. {
  780. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidUser ));
  781. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrUser.m_str, TRUE ));
  782. }
  783. // write out product ID
  784. if(m_bstrID.Length() > 0)
  785. {
  786. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidID ));
  787. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrID.m_str, TRUE ));
  788. }
  789. // write out product name
  790. if(m_bstrName.Length() > 0)
  791. {
  792. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidName ));
  793. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrName.m_str, TRUE ));
  794. }
  795. // write out problem description
  796. if(m_bstrProb.Length() > 0)
  797. {
  798. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidProb ));
  799. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrProb.m_str, TRUE ));
  800. }
  801. // write out XSL stream
  802. if(m_bstrXSL.Length() > 0)
  803. {
  804. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidXSL ));
  805. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrXSL.m_str, TRUE ));
  806. }
  807. // write out RC Ticket
  808. if(m_bstrRCTicket.Length() > 0)
  809. {
  810. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidRCTkt ));
  811. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrRCTicket.m_str, TRUE ));
  812. }
  813. // write out RCRequested Flag
  814. if(m_fRCRequested == VARIANT_TRUE)
  815. {
  816. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidRCReq ));
  817. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, TEXT_TRUE, TRUE ));
  818. }
  819. else
  820. {
  821. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidRCReq ));
  822. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, TEXT_FALSE, TRUE ));
  823. }
  824. // write out RCTicketEncrypted Flag
  825. if(m_fRCTicketEncrypted == VARIANT_TRUE)
  826. {
  827. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidRCEnc ));
  828. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, TEXT_TRUE, TRUE ));
  829. }
  830. else
  831. {
  832. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidRCEnc ));
  833. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, TEXT_FALSE, TRUE ));
  834. }
  835. // write out Start Page
  836. if(m_bstrStartPg.Length() > 0)
  837. {
  838. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidStartPg ));
  839. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrStartPg.m_str, TRUE ));
  840. }
  841. // write out snapshot stream
  842. if(m_bstrSnapshot.Length() > 0)
  843. {
  844. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidSnap ));
  845. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrSnapshot, TRUE ));
  846. }
  847. // write out history stream
  848. if(m_bstrHistory.Length() > 0)
  849. {
  850. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidHist ));
  851. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_bstrHistory, TRUE ));
  852. }
  853. // write out the trace list
  854. if(m_rghsi && m_chsi > 0)
  855. {
  856. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidTrace ));
  857. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_chsi ));
  858. for(int i = 0; i < m_chsi; i++)
  859. {
  860. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, m_rghsi[i] ));
  861. }
  862. }
  863. // write out the property list
  864. if(m_pDict)
  865. {
  866. CComPtr<IUnknown> punkEnum;
  867. CComPtr<IEnumVARIANT> pEnum;
  868. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidMisc ));
  869. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->_NewEnum( &punkEnum ));
  870. __MPC_EXIT_IF_METHOD_FAILS(hr, punkEnum.QueryInterface( &pEnum ));
  871. for(;;)
  872. {
  873. CComVariant varKey;
  874. CComVariant varValue;
  875. ULONG cFetched;
  876. DWORD cb;
  877. __MPC_EXIT_IF_METHOD_FAILS(hr, pEnum->Next( 1, &varKey, &cFetched ));
  878. // we're done enuming
  879. if(hr == S_FALSE || cFetched != 1) break;
  880. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->get_Item( &varKey, &varValue ));
  881. __MPC_EXIT_IF_METHOD_FAILS(hr, varKey .ChangeType( VT_BSTR ));
  882. __MPC_EXIT_IF_METHOD_FAILS(hr, varValue.ChangeType( VT_BSTR ));
  883. if(::SysStringLen( V_BSTR(&varValue) ) > 0)
  884. {
  885. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, V_BSTR(&varKey ), TRUE ));
  886. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, V_BSTR(&varValue), TRUE ));
  887. }
  888. }
  889. //
  890. // Emit end of dictionary (DWORD == 0).
  891. //
  892. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, (DWORD)0 ));
  893. }
  894. __MPC_EXIT_IF_METHOD_FAILS(hr, WriteData( pStm, c_dwidDone ));
  895. hr = S_OK;
  896. __HCP_FUNC_CLEANUP;
  897. __HCP_FUNC_EXIT(hr);
  898. }
  899. // **************************************************************************
  900. STDMETHODIMP CSAFIncident::Load( BSTR bstrFileName )
  901. {
  902. __HCP_FUNC_ENTRY("CSAFIncident::Load");
  903. HRESULT hr;
  904. CComPtr<MPC::FileStream> pfs;
  905. MPC::SmartLock<_ThreadModel> lock( this );
  906. __MPC_PARAMCHECK_BEGIN(hr)
  907. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFileName);
  908. __MPC_PARAMCHECK_END();
  909. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pfs ));
  910. __MPC_EXIT_IF_METHOD_FAILS(hr, pfs->InitForRead( bstrFileName ));
  911. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadFromStream( pfs ));
  912. hr = S_OK;
  913. __HCP_FUNC_CLEANUP;
  914. __HCP_FUNC_EXIT(hr);
  915. }
  916. STDMETHODIMP CSAFIncident::LoadFromStream( IUnknown* punkStm )
  917. {
  918. __HCP_FUNC_ENTRY("CSAFIncident::LoadFromStream");
  919. HRESULT hr;
  920. CComPtr<IStream> pStm;
  921. DWORD i;
  922. MPC::SmartLock<_ThreadModel> lock( this );
  923. __MPC_PARAMCHECK_BEGIN(hr)
  924. __MPC_PARAMCHECK_NOTNULL(punkStm);
  925. __MPC_PARAMCHECK_END();
  926. Cleanup();
  927. __MPC_EXIT_IF_METHOD_FAILS(hr, punkStm->QueryInterface( IID_IStream, (LPVOID *)&pStm ));
  928. for(;;)
  929. {
  930. CComVariant varName;
  931. CComVariant varVal;
  932. DWORD dwid;
  933. CComBSTR bstrRCReq;
  934. CComBSTR bstrRCEnc;
  935. // figure out which dwid we're processing
  936. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &dwid ));
  937. if(dwid == c_dwidDone) break;
  938. switch(dwid)
  939. {
  940. case c_dwidUser: m_bstrUser .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrUser )); break;
  941. case c_dwidProb: m_bstrProb .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrProb )); break;
  942. case c_dwidID : m_bstrID .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrID )); break;
  943. case c_dwidName: m_bstrName .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrName )); break;
  944. case c_dwidXSL: m_bstrXSL .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrXSL )); break;
  945. case c_dwidRCTkt: m_bstrRCTicket.Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrRCTicket)); break;
  946. case c_dwidStartPg:m_bstrStartPg .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrStartPg)); break;
  947. case c_dwidRCReq:
  948. m_fRCRequested=VARIANT_FALSE;
  949. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &bstrRCReq ));
  950. if(MPC::StrICmp( bstrRCReq, TEXT_TRUE ) == 0)
  951. {
  952. m_fRCRequested = VARIANT_TRUE;
  953. }
  954. break;
  955. case c_dwidRCEnc:
  956. m_fRCTicketEncrypted=VARIANT_FALSE;
  957. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &bstrRCEnc ));
  958. if(MPC::StrICmp( bstrRCEnc, TEXT_TRUE ) == 0)
  959. {
  960. m_fRCTicketEncrypted = VARIANT_TRUE;
  961. }
  962. break;
  963. case c_dwidSnap: m_bstrSnapshot.Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrSnapshot )); break;
  964. case c_dwidHist: m_bstrHistory .Empty(); __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &m_bstrHistory )); break;
  965. case c_dwidType: __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, (DWORD *)&m_eut )); break;
  966. case c_dwidTrace:
  967. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData(pStm, (DWORD *)&m_chsi ));
  968. delete [] m_rghsi; __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rghsi, new SHelpSessionItem[m_chsi]);
  969. for(i = 0; i < m_chsi; i++)
  970. {
  971. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, m_rghsi[i] ));
  972. }
  973. break;
  974. case c_dwidMisc:
  975. __MPC_EXIT_IF_METHOD_FAILS(hr, InitDictionary());
  976. for(;;)
  977. {
  978. CComBSTR bstrVal;
  979. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &bstrVal ));
  980. if(hr == S_FALSE) break;
  981. varName = bstrVal; bstrVal.Empty();
  982. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadData( pStm, &bstrVal ));
  983. if(hr == S_FALSE) varVal = "";
  984. else varVal = bstrVal;
  985. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->put_Item( &varName, &varVal ));
  986. }
  987. break;
  988. default:
  989. __MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
  990. }
  991. }
  992. hr = S_OK;
  993. __HCP_FUNC_CLEANUP;
  994. __HCP_FUNC_EXIT(hr);
  995. }
  996. // **************************************************************************
  997. //
  998. // Given a XML Stream, this method initializes the Incident Object with its contents.
  999. //
  1000. HRESULT CSAFIncident::LoadFromXMLObject( /*[in]*/ MPC::XmlUtil& xmldocIncident )
  1001. {
  1002. __HCP_FUNC_ENTRY( "CSAFIncident::LoadFromXMLObject" );
  1003. HRESULT hr;
  1004. Cleanup();
  1005. //
  1006. // Initialize the XSL value.
  1007. //
  1008. //
  1009. // Initialize the Upload Type. ------------------------------------------------------------------------------
  1010. //
  1011. {
  1012. CComBSTR bstrValue;
  1013. bool fFound;
  1014. __MPC_EXIT_IF_METHOD_FAILS(hr, xmldocIncident.GetAttribute( NULL, TEXT_ATTR_INC_TYPE, bstrValue, fFound, NULL ));
  1015. if(fFound == false)
  1016. {
  1017. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_BAD_FORMAT);
  1018. }
  1019. if(bstrValue == L"Bug")
  1020. {
  1021. m_eut = eutBug;
  1022. }
  1023. else if(bstrValue == L"Escalated")
  1024. {
  1025. m_eut = eutEscalated;
  1026. }
  1027. else if(bstrValue == L"NonEscalated")
  1028. {
  1029. m_eut = eutNonEscalated;
  1030. }
  1031. else
  1032. {
  1033. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  1034. }
  1035. }
  1036. //
  1037. // Get the Upload Data Attributes--------------------------------------------------------------------------------
  1038. //
  1039. {
  1040. CComPtr<IXMLDOMNode> xdnNode;
  1041. __MPC_EXIT_IF_METHOD_FAILS(hr, xmldocIncident.GetNode( TEXT_TAG_UPLOADDATA, &xdnNode ));
  1042. if(xdnNode)
  1043. {
  1044. CComPtr<IXMLDOMNamedNodeMap> xdnnmAttributes;
  1045. long nAttribLen;
  1046. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnNode ->get_attributes( &xdnnmAttributes ));
  1047. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnnmAttributes->get_length ( &nAttribLen ));
  1048. // Add the miscellaneous properties to the Dictionary object a property of the Incident object.
  1049. __MPC_EXIT_IF_METHOD_FAILS(hr, InitDictionary());
  1050. for(long i=0; i<nAttribLen; i++)
  1051. {
  1052. CComPtr<IXMLDOMNode> xdnAttribItem;
  1053. CComBSTR bstrAttribName;
  1054. CComVariant vAttribValue;
  1055. // Get the attribute Name and Value.
  1056. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnnmAttributes->get_item( i, &xdnAttribItem ));
  1057. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnAttribItem->get_nodeName ( &bstrAttribName ));
  1058. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnAttribItem->get_nodeValue( &vAttribValue ));
  1059. if(vAttribValue.vt == VT_BSTR)
  1060. {
  1061. // Initialize the well known attributes.
  1062. if(bstrAttribName == L"PRODUCTID")
  1063. {
  1064. // Initialize the Product ID varaible.
  1065. m_bstrID = vAttribValue.bstrVal;
  1066. continue;
  1067. }
  1068. if(bstrAttribName == L"PRODUCTNAME")
  1069. {
  1070. // Initialize the Product Name varaible.
  1071. m_bstrName = vAttribValue.bstrVal;
  1072. continue;
  1073. }
  1074. if(bstrAttribName == L"PROBLEMDESCRIPTION")
  1075. {
  1076. // Initialize the Problem Description varaible.
  1077. m_bstrProb = vAttribValue.bstrVal;
  1078. continue;
  1079. }
  1080. if(bstrAttribName == L"USERNAME")
  1081. {
  1082. // Initialize the UserName varaible.
  1083. m_bstrUser = vAttribValue.bstrVal;
  1084. continue;
  1085. }
  1086. if(bstrAttribName == L"RCTICKET")
  1087. {
  1088. // Initialize the RCTICKET varaible.
  1089. m_bstrRCTicket = vAttribValue.bstrVal;
  1090. continue;
  1091. }
  1092. if(bstrAttribName == L"RCREQUESTED")
  1093. {
  1094. // Initialize the RCREQUESTED varaible.
  1095. if(MPC::StrICmp( vAttribValue.bstrVal, TEXT_TRUE ) == 0)
  1096. {
  1097. m_fRCRequested = VARIANT_TRUE;
  1098. }
  1099. continue;
  1100. }
  1101. if(bstrAttribName == L"RCTICKETENCRYPTED")
  1102. {
  1103. // Initialize the RCTICKETENCRYPTED varaible.
  1104. m_fRCTicketEncrypted = (MPC::StrICmp( vAttribValue.bstrVal, TEXT_TRUE ) == 0) ? VARIANT_TRUE : VARIANT_FALSE;
  1105. continue;
  1106. }
  1107. if(bstrAttribName == L"STARTPAGE")
  1108. {
  1109. // Initialize the Start Page varaible.
  1110. m_bstrStartPg = vAttribValue.bstrVal;
  1111. continue;
  1112. }
  1113. }
  1114. // This is a miscellaneous property.
  1115. // Initialize the Dictionary Object Property varaible.
  1116. {
  1117. CComVariant v( bstrAttribName );
  1118. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pDict->put_Item( &v, &vAttribValue ));
  1119. }
  1120. }
  1121. }
  1122. }
  1123. //
  1124. // Get the SnapShot Data--------------------------------------------------------------------------------------------------
  1125. //
  1126. {
  1127. CComPtr<IXMLDOMNode> xdnNode;
  1128. if(SUCCEEDED(hr = xmldocIncident.GetNode( TEXT_TAG_SNAPSHOT, &xdnNode )) && xdnNode)
  1129. {
  1130. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnNode->get_xml( &m_bstrSnapshot ));
  1131. }
  1132. }
  1133. //
  1134. // Get the History Data---------------------------------------------------------------------------------------------------
  1135. //
  1136. {
  1137. CComPtr<IXMLDOMNode> xdnNode;
  1138. if(SUCCEEDED(hr = xmldocIncident.GetNode( TEXT_TAG_HISTORY, &xdnNode )) && xdnNode)
  1139. {
  1140. __MPC_EXIT_IF_METHOD_FAILS(hr, xdnNode->get_xml( &m_bstrHistory ));
  1141. }
  1142. }
  1143. //
  1144. // Get the trace stuff HELPSESSIONCOLLECTION-------------------------------------------------------------------------------
  1145. //
  1146. {
  1147. CComPtr<IXMLDOMNode> xdnNode;
  1148. if(SUCCEEDED(hr = xmldocIncident.GetNode( TEXT_TAG_HELPSESSION, &xdnNode )) && xdnNode)
  1149. {
  1150. // __MPC_EXIT_IF_METHOD_FAILS(hr, xdnNodeHistory->get_xml(&m_bstrHistory));
  1151. }
  1152. }
  1153. hr = S_OK;
  1154. __HCP_FUNC_CLEANUP;
  1155. __HCP_FUNC_EXIT(hr);
  1156. }
  1157. STDMETHODIMP CSAFIncident::LoadFromXMLStream( /*[in]*/ IUnknown* punkStm )
  1158. {
  1159. __HCP_FUNC_ENTRY("CSAFIncident::LoadFromXMLStream");
  1160. HRESULT hr;
  1161. MPC::XmlUtil xmldocIncident;
  1162. bool fLoaded;
  1163. bool fFound;
  1164. __MPC_EXIT_IF_METHOD_FAILS(hr, xmldocIncident.LoadAsStream( punkStm, TEXT_TAG_UPLOADINFO, fLoaded, &fFound ));
  1165. if(fLoaded == false ||
  1166. fFound == false )
  1167. {
  1168. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_OPEN_FAILED);
  1169. }
  1170. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadFromXMLObject( xmldocIncident ));
  1171. hr = S_OK;
  1172. __HCP_FUNC_CLEANUP;
  1173. __HCP_FUNC_EXIT(hr);
  1174. }
  1175. // **************************************************************************
  1176. // Given a XML File this method initializes the Incident Object with its contents.
  1177. STDMETHODIMP CSAFIncident::LoadFromXMLFile( BSTR bstrFileName )
  1178. {
  1179. __HCP_FUNC_ENTRY("CSAFIncident::LoadFromXMLFile");
  1180. HRESULT hr;
  1181. MPC::XmlUtil xmldocIncident;
  1182. bool fLoaded;
  1183. bool fFound;
  1184. __MPC_EXIT_IF_METHOD_FAILS(hr, xmldocIncident.Load( bstrFileName, TEXT_TAG_UPLOADINFO, fLoaded, &fFound ));
  1185. if(fLoaded == false ||
  1186. fFound == false )
  1187. {
  1188. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_OPEN_FAILED);
  1189. }
  1190. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadFromXMLObject( xmldocIncident ));
  1191. hr = S_OK;
  1192. __HCP_FUNC_CLEANUP;
  1193. __HCP_FUNC_EXIT(hr);
  1194. }
  1195. // **************************************************************************
  1196. // Given a XML String this method initializes the Incident Object with its contents.
  1197. STDMETHODIMP CSAFIncident::LoadFromXMLString( BSTR bstrXMLBlob )
  1198. {
  1199. __HCP_FUNC_ENTRY("CSAFIncident::LoadFromXMLString");
  1200. HRESULT hr;
  1201. MPC::XmlUtil xmldocIncident;
  1202. bool fLoaded;
  1203. bool fFound;
  1204. __MPC_EXIT_IF_METHOD_FAILS(hr, xmldocIncident.LoadAsString( bstrXMLBlob, TEXT_TAG_UPLOADINFO, fLoaded, &fFound ));
  1205. if(fLoaded == false ||
  1206. fFound == false )
  1207. {
  1208. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_OPEN_FAILED);
  1209. }
  1210. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadFromXMLObject( xmldocIncident ));
  1211. hr = S_OK;
  1212. __HCP_FUNC_CLEANUP;
  1213. __HCP_FUNC_EXIT(hr);
  1214. }
  1215. // *************************************************************************
  1216. // If this object contains a valid SALEM session id, then we should close that session.
  1217. STDMETHODIMP CSAFIncident::CloseRemoteAssistanceIncident()
  1218. {
  1219. __HCP_FUNC_ENTRY("CSAFIncident::CloseRemoteAssistanceIncident");
  1220. HRESULT hr;
  1221. REMOTE_DESKTOP_SHARING_CLASS sharingClass = VIEWDESKTOP_PERMISSION_NOT_REQUIRE;
  1222. CComBSTR pRcTicket;
  1223. CComBSTR pNull;
  1224. CComPtr<ISAFRemoteDesktopSession> pSession;
  1225. CComPtr<IClassFactory> fact;
  1226. CComQIPtr<IPCHUtility> disp;
  1227. __MPC_EXIT_IF_METHOD_FAILS(hr, get_RCTicket(&pRcTicket));
  1228. if (pRcTicket.Length() == 0)
  1229. {
  1230. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  1231. }
  1232. //
  1233. // This is handled in a special way.
  1234. //
  1235. // We QI the PCHSVC broker and then forward the call to it.
  1236. //
  1237. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoGetClassObject( CLSID_PCHService, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&fact ));
  1238. if((disp = fact))
  1239. {
  1240. __MPC_EXIT_IF_METHOD_FAILS(hr, disp->CreateObject_RemoteDesktopSession( sharingClass, 0, (BSTR)pRcTicket, (BSTR)pNull, &pSession));
  1241. }
  1242. else
  1243. {
  1244. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE);
  1245. }
  1246. __MPC_EXIT_IF_METHOD_FAILS(hr, pSession->CloseRemoteDesktopSession());
  1247. __HCP_FUNC_CLEANUP;
  1248. __HCP_FUNC_EXIT(hr);
  1249. }