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.

272 lines
4.4 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <wmimsg.h>
  9. #include "msmqhdr.h"
  10. const DWORD g_dwSig = 0x6d696d77;
  11. const BYTE g_chVersionMajor = 1;
  12. const BYTE g_chVersionMinor = 0;
  13. /****************************************************************************
  14. CMsgMsmqHdr
  15. *****************************************************************************/
  16. CMsgMsmqHdr::CMsgMsmqHdr( LPCWSTR wszTarget,
  17. LPCWSTR wszSource,
  18. PBYTE pDataHash,
  19. ULONG cDataHash,
  20. ULONG cAuxData )
  21. : m_wszTarget(wszTarget), m_wszSource( wszSource ),
  22. m_cAuxData(cAuxData), m_cDataHash(cDataHash)
  23. {
  24. GetSystemTime( &m_Time );
  25. memcpy( m_achDataHash, pDataHash, cDataHash );
  26. }
  27. HRESULT CMsgMsmqHdr::Unpersist( CBuffer& rStrm )
  28. {
  29. HRESULT hr;
  30. DWORD dwSig;
  31. BYTE chVersionMajor, chVersionMinor;
  32. //
  33. // read and verify signature.
  34. //
  35. hr = rStrm.Read( &dwSig, sizeof(DWORD), NULL );
  36. if ( hr != S_OK || dwSig != g_dwSig )
  37. {
  38. return WMIMSG_E_INVALIDMESSAGE;
  39. }
  40. //
  41. // read and check version major (currently no check).
  42. //
  43. hr = rStrm.Read( &chVersionMajor, 1, NULL );
  44. if ( hr != S_OK )
  45. {
  46. return WMIMSG_E_INVALIDMESSAGE;
  47. }
  48. //
  49. // read and check version minor (currently no check).
  50. //
  51. hr = rStrm.Read( &chVersionMinor, 1, NULL );
  52. if ( hr != S_OK )
  53. {
  54. return WMIMSG_E_INVALIDMESSAGE;
  55. }
  56. //
  57. // read reserved
  58. //
  59. DWORD dwReserved;
  60. hr = rStrm.Read( &dwReserved, sizeof(DWORD), NULL );
  61. if ( hr != S_OK )
  62. {
  63. return WMIMSG_E_INVALIDMESSAGE;
  64. }
  65. //
  66. // read source machine.
  67. //
  68. hr = rStrm.ReadLPWSTR( m_wszSource );
  69. if ( hr != S_OK )
  70. {
  71. return WMIMSG_E_INVALIDMESSAGE;
  72. }
  73. //
  74. // read target queue name.
  75. //
  76. hr = rStrm.ReadLPWSTR( m_wszTarget );
  77. if ( hr != S_OK )
  78. {
  79. return WMIMSG_E_INVALIDMESSAGE;
  80. }
  81. //
  82. // read sent time.
  83. //
  84. hr = rStrm.Read( &m_Time, sizeof(SYSTEMTIME), NULL );
  85. if ( hr != S_OK )
  86. {
  87. return WMIMSG_E_INVALIDMESSAGE;
  88. }
  89. //
  90. // read size of user data hash
  91. //
  92. hr = rStrm.Read( &m_cDataHash, sizeof(DWORD), NULL );
  93. if ( hr != S_OK || m_cDataHash > MAXHASHSIZE )
  94. {
  95. return WMIMSG_E_INVALIDMESSAGE;
  96. }
  97. //
  98. // read hash of user data.
  99. //
  100. hr = rStrm.Read( m_achDataHash, m_cDataHash, NULL );
  101. if ( hr != S_OK )
  102. {
  103. return WMIMSG_E_INVALIDMESSAGE;
  104. }
  105. //
  106. // read length of user header.
  107. //
  108. hr = rStrm.Read( &m_cAuxData, sizeof(DWORD), NULL );
  109. if ( hr != S_OK )
  110. {
  111. return WMIMSG_E_INVALIDMESSAGE;
  112. }
  113. return WBEM_S_NO_ERROR;
  114. }
  115. HRESULT CMsgMsmqHdr::Persist( CBuffer& rStrm )
  116. {
  117. HRESULT hr;
  118. hr = rStrm.Write( &g_dwSig, sizeof(DWORD), NULL );
  119. if ( FAILED(hr) )
  120. {
  121. return hr;
  122. }
  123. //
  124. // write version major.
  125. //
  126. hr = rStrm.Write( &g_chVersionMajor, 1, NULL );
  127. if ( FAILED(hr) )
  128. {
  129. return hr;
  130. }
  131. //
  132. // write version minor.
  133. //
  134. hr = rStrm.Write( &g_chVersionMinor, 1, NULL );
  135. if ( FAILED(hr) )
  136. {
  137. return hr;
  138. }
  139. //
  140. // write reserved flags ( currently not used ).
  141. //
  142. DWORD dwReserved = 0;
  143. hr = rStrm.Write( &dwReserved, sizeof(DWORD), NULL );
  144. if ( FAILED(hr) )
  145. {
  146. return hr;
  147. }
  148. //
  149. // write source machine
  150. //
  151. hr = rStrm.WriteLPWSTR( m_wszSource );
  152. if ( FAILED(hr) )
  153. {
  154. return hr;
  155. }
  156. //
  157. // write target queue.
  158. //
  159. hr = rStrm.WriteLPWSTR( m_wszTarget );
  160. if ( FAILED(hr) )
  161. {
  162. return hr;
  163. }
  164. //
  165. // write time sent.
  166. //
  167. hr = rStrm.Write( &m_Time, sizeof(SYSTEMTIME), NULL );
  168. if ( FAILED(hr) )
  169. {
  170. return hr;
  171. }
  172. //
  173. // write length of data hash
  174. //
  175. hr = rStrm.Write( &m_cDataHash, sizeof(DWORD), NULL );
  176. if ( FAILED(hr) )
  177. {
  178. return hr;
  179. }
  180. //
  181. // write hash of data section
  182. //
  183. hr = rStrm.Write( m_achDataHash, m_cDataHash, NULL );
  184. if ( FAILED(hr) )
  185. {
  186. return hr;
  187. }
  188. //
  189. // write the size of the user header.
  190. //
  191. return rStrm.Write( &m_cAuxData, sizeof(DWORD), NULL );
  192. }