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.

376 lines
10 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Serializer.cpp
  5. Abstract:
  6. This file contains the implementation of various Serializer In/Out operators.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 04/20/99
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. /////////////////////////////////////////////////////////////////////////
  13. namespace UploadLibrary
  14. {
  15. MPC::Serializer* SelectStream( MPC::Serializer& stream, MPC::Serializer_Text& streamText )
  16. {
  17. switch(stream.get_Flags())
  18. {
  19. case UPLOAD_LIBRARY_PROTOCOL_VERSION_CLT__TEXTONLY:
  20. case UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV__TEXTONLY: return &streamText;
  21. }
  22. return &stream;
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////
  25. bool RequestHeader::VerifyClient() const
  26. {
  27. if(dwSignature == UPLOAD_LIBRARY_PROTOCOL_SIGNATURE)
  28. {
  29. switch(dwVersion)
  30. {
  31. case UPLOAD_LIBRARY_PROTOCOL_VERSION_CLT:
  32. case UPLOAD_LIBRARY_PROTOCOL_VERSION_CLT__TEXTONLY: return true;
  33. }
  34. }
  35. return false;
  36. }
  37. bool RequestHeader::VerifyServer() const
  38. {
  39. if(dwSignature == UPLOAD_LIBRARY_PROTOCOL_SIGNATURE)
  40. {
  41. switch(dwVersion)
  42. {
  43. case UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV:
  44. case UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV__TEXTONLY: return true;
  45. }
  46. }
  47. return false;
  48. }
  49. //
  50. // In/Out operators for RequestHeader
  51. //
  52. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct RequestHeader& rhVal )
  53. {
  54. __ULT_FUNC_ENTRY( "operator>> struct RequestHeader" );
  55. HRESULT hr;
  56. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> rhVal.dwSignature);
  57. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> rhVal.dwVersion ); stream.put_Flags( rhVal.dwVersion );
  58. hr = S_OK;
  59. __ULT_FUNC_CLEANUP;
  60. __ULT_FUNC_EXIT(hr);
  61. }
  62. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in]*/ const struct RequestHeader& rhVal )
  63. {
  64. __ULT_FUNC_ENTRY( "operator<< struct RequestHeader" );
  65. HRESULT hr;
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << rhVal.dwSignature);
  67. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << rhVal.dwVersion ); stream.put_Flags( rhVal.dwVersion );
  68. hr = S_OK;
  69. __ULT_FUNC_CLEANUP;
  70. __ULT_FUNC_EXIT(hr);
  71. }
  72. ////////////////////////////////////////////////////////////////////////////////
  73. //
  74. // In/Out operators for Signature
  75. //
  76. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct Signature& sigVal )
  77. {
  78. __ULT_FUNC_ENTRY( "operator>> struct Signature" );
  79. HRESULT hr;
  80. MPC::Serializer_Text streamText( stream );
  81. MPC::Serializer* pstream = SelectStream( stream, streamText );
  82. __MPC_EXIT_IF_METHOD_FAILS(hr, pstream->read( &sigVal, sizeof(sigVal) ));
  83. hr = S_OK;
  84. __ULT_FUNC_CLEANUP;
  85. __ULT_FUNC_EXIT(hr);
  86. }
  87. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in] */ const struct Signature& sigVal )
  88. {
  89. __ULT_FUNC_ENTRY( "operator<< struct Signature" );
  90. HRESULT hr;
  91. MPC::Serializer_Text streamText( stream );
  92. MPC::Serializer* pstream = SelectStream( stream, streamText );
  93. __MPC_EXIT_IF_METHOD_FAILS(hr, pstream->write( &sigVal, sizeof(sigVal) ));
  94. hr = S_OK;
  95. __ULT_FUNC_CLEANUP;
  96. __ULT_FUNC_EXIT(hr);
  97. }
  98. ////////////////////////////////////////////////////////////////////////////////
  99. bool ServerResponse::MatchVersion( /*[in]*/ const ClientRequest& cr )
  100. {
  101. rhProlog.dwVersion = UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV; // Set the version to the old default.
  102. if(cr.rhProlog.VerifyClient())
  103. {
  104. switch(cr.rhProlog.dwVersion)
  105. {
  106. case UPLOAD_LIBRARY_PROTOCOL_VERSION_CLT : rhProlog.dwVersion = UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV ; break;
  107. case UPLOAD_LIBRARY_PROTOCOL_VERSION_CLT__TEXTONLY: rhProlog.dwVersion = UPLOAD_LIBRARY_PROTOCOL_VERSION_SRV__TEXTONLY; break;
  108. default : return false; // Just in case...
  109. }
  110. return true;
  111. }
  112. return false;
  113. }
  114. //
  115. // In/Out operators for ServerResponse
  116. //
  117. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct ServerResponse& srVal )
  118. {
  119. __ULT_FUNC_ENTRY( "operator>> struct ServerResponse" );
  120. HRESULT hr;
  121. MPC::Serializer_Text streamText( stream );
  122. MPC::Serializer* pstream;
  123. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> srVal.rhProlog);
  124. pstream = SelectStream( stream, streamText );
  125. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> srVal.fResponse );
  126. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> srVal.dwPosition );
  127. hr = S_OK;
  128. __ULT_FUNC_CLEANUP;
  129. __ULT_FUNC_EXIT(hr);
  130. }
  131. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in]*/ const struct ServerResponse& srVal )
  132. {
  133. __ULT_FUNC_ENTRY( "operator<< struct ServerResponse" );
  134. HRESULT hr;
  135. MPC::Serializer_Text streamText( stream );
  136. MPC::Serializer* pstream;
  137. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << srVal.rhProlog);
  138. pstream = SelectStream( stream, streamText );
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << srVal.fResponse );
  140. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << srVal.dwPosition );
  141. hr = S_OK;
  142. __ULT_FUNC_CLEANUP;
  143. __ULT_FUNC_EXIT(hr);
  144. }
  145. ////////////////////////////////////////////////////////////////////////////////
  146. //
  147. // In/Out operators for ClientRequest
  148. //
  149. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct ClientRequest& crVal )
  150. {
  151. __ULT_FUNC_ENTRY( "operator>> struct ClientRequest" );
  152. HRESULT hr;
  153. MPC::Serializer_Text streamText( stream );
  154. MPC::Serializer* pstream;
  155. __MPC_EXIT_IF_METHOD_FAILS(hr, stream >> crVal.rhProlog);
  156. pstream = SelectStream( stream, streamText );
  157. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crVal.sigClient );
  158. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crVal.dwCommand );
  159. hr = S_OK;
  160. __ULT_FUNC_CLEANUP;
  161. __ULT_FUNC_EXIT(hr);
  162. }
  163. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in]*/ const struct ClientRequest& crVal )
  164. {
  165. __ULT_FUNC_ENTRY( "operator<< struct ClientRequest" );
  166. HRESULT hr;
  167. MPC::Serializer_Text streamText( stream );
  168. MPC::Serializer* pstream;
  169. __MPC_EXIT_IF_METHOD_FAILS(hr, stream << crVal.rhProlog);
  170. pstream = SelectStream( stream, streamText );
  171. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crVal.sigClient );
  172. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crVal.dwCommand );
  173. hr = S_OK;
  174. __ULT_FUNC_CLEANUP;
  175. __ULT_FUNC_EXIT(hr);
  176. }
  177. ////////////////////////////////////////////////////////////////////////////////
  178. //
  179. // In/Out operators for ClientRequest_OpenSession
  180. //
  181. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct ClientRequest_OpenSession& crosVal )
  182. {
  183. __ULT_FUNC_ENTRY( "operator>> struct ClientRequest_OpenSession" );
  184. HRESULT hr;
  185. MPC::Serializer_Text streamText( stream );
  186. MPC::Serializer* pstream = SelectStream( stream, streamText );
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.szJobID );
  188. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.szProviderID );
  189. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.szUsername );
  190. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.dwSize );
  191. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.dwSizeOriginal);
  192. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.dwCRC );
  193. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crosVal.fCompressed );
  194. hr = S_OK;
  195. __ULT_FUNC_CLEANUP;
  196. __ULT_FUNC_EXIT(hr);
  197. }
  198. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in]*/ const struct ClientRequest_OpenSession& crosVal )
  199. {
  200. __ULT_FUNC_ENTRY( "operator<< struct ClientRequest_OpenSession" );
  201. HRESULT hr;
  202. MPC::Serializer_Text streamText( stream );
  203. MPC::Serializer* pstream = SelectStream( stream, streamText );
  204. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.szJobID );
  205. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.szProviderID );
  206. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.szUsername );
  207. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.dwSize );
  208. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.dwSizeOriginal);
  209. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.dwCRC );
  210. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crosVal.fCompressed );
  211. hr = S_OK;
  212. __ULT_FUNC_CLEANUP;
  213. __ULT_FUNC_EXIT(hr);
  214. }
  215. ////////////////////////////////////////////////////////////////////////////////
  216. //
  217. // In/Out operators for ClientRequest_WriteSession
  218. //
  219. HRESULT operator>>( /*[in]*/ MPC::Serializer& stream, /*[out]*/ struct ClientRequest_WriteSession& crwsVal )
  220. {
  221. __ULT_FUNC_ENTRY( "operator>> struct ClientRequest_WriteSession" );
  222. HRESULT hr;
  223. MPC::Serializer_Text streamText( stream );
  224. MPC::Serializer* pstream = SelectStream( stream, streamText );
  225. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crwsVal.szJobID );
  226. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crwsVal.dwOffset);
  227. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) >> crwsVal.dwSize );
  228. hr = S_OK;
  229. __ULT_FUNC_CLEANUP;
  230. __ULT_FUNC_EXIT(hr);
  231. }
  232. HRESULT operator<<( /*[in]*/ MPC::Serializer& stream, /*[in]*/ const struct ClientRequest_WriteSession& crwsVal )
  233. {
  234. __ULT_FUNC_ENTRY( "operator<< struct ClientRequest_WriteSession" );
  235. HRESULT hr;
  236. MPC::Serializer_Text streamText( stream );
  237. MPC::Serializer* pstream = SelectStream( stream, streamText );
  238. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crwsVal.szJobID );
  239. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crwsVal.dwOffset);
  240. __MPC_EXIT_IF_METHOD_FAILS(hr, (*pstream) << crwsVal.dwSize );
  241. hr = S_OK;
  242. __ULT_FUNC_CLEANUP;
  243. __ULT_FUNC_EXIT(hr);
  244. }
  245. /////////////////////////////////////////////////////////////////////////
  246. }; // namespace