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.

274 lines
7.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: Pickle.cxx
  7. //
  8. // Contents: Pickling/Unpickling routines for restrictions.
  9. //
  10. // History: 22-Dec-92 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <coldesc.hxx>
  16. #include <pidmap.hxx>
  17. #include <rstprop.hxx>
  18. #include <sizeser.hxx>
  19. #include <memser.hxx>
  20. #include <memdeser.hxx>
  21. #include <pickle.hxx>
  22. //+-------------------------------------------------------------------------
  23. //
  24. // Function: DoPickle
  25. //
  26. // Synopsis: Pickles a query into a stream
  27. //
  28. // Arguments: [sver] -- version of the server we are targeting
  29. // [ss] -- Stream into which query is pickled
  30. // [cb] -- Size of pickled query
  31. // [pcol] -- Columns in table
  32. // [prst] -- Restriction
  33. // [pso] -- Sort order
  34. // [pcateg] -- Categorization specification
  35. // [ulFlags] -- Flags
  36. // [pidmap] -- Pid Mapper
  37. //
  38. // History: 18-Apr-95 dlee From duplicate code in Pickle & PickledSize
  39. //
  40. //--------------------------------------------------------------------------
  41. void DoPickle( int sver,
  42. PSerStream &ss,
  43. ULONG cb,
  44. CColumnSet const * pcol,
  45. CRestriction const * prst,
  46. CSortSet const * pso,
  47. CCategorizationSet const *pcateg,
  48. CRowsetProperties const *pProps,
  49. CPidMapper const * pidmap )
  50. {
  51. // must be 8-byte aligned
  52. ss.PutULong( cb ); // Size
  53. if ( 0 == pcol )
  54. ss.PutByte( PickleColNone );
  55. else
  56. {
  57. ss.PutByte( PickleColSet );
  58. pcol->Marshall( ss );
  59. }
  60. if ( 0 == prst )
  61. ss.PutByte( FALSE );
  62. else
  63. {
  64. if ( !prst->IsValid() )
  65. {
  66. vqDebugOut(( DEB_ERROR, "Marshalling invalid restriction!\n" ));
  67. THROW( CException( QUERY_E_INVALIDRESTRICTION ) );
  68. }
  69. ss.PutByte( TRUE );
  70. prst->Marshall( ss );
  71. }
  72. if ( 0 == pso )
  73. ss.PutByte( FALSE );
  74. else
  75. {
  76. ss.PutByte( TRUE );
  77. pso->Marshall( ss );
  78. }
  79. if ( 0 == pcateg )
  80. ss.PutByte( FALSE );
  81. else
  82. {
  83. ss.PutByte( TRUE );
  84. pcateg->Marshall( ss );
  85. }
  86. pProps->Marshall(ss);
  87. Win4Assert( 0 != pidmap );
  88. pidmap->Marshall( ss );
  89. } //DoPickle
  90. //+-------------------------------------------------------------------------
  91. //
  92. // Function: PickledSize, public
  93. //
  94. // Synopsis: Computes size of buffer required to pickle query.
  95. //
  96. // Arguments: [sver] -- version of the server we are targeting
  97. // [pcol] -- Columns in table
  98. // [prst] -- Restriction
  99. // [pso] -- Sort order
  100. // [pcateg] -- Categorization specification
  101. // [ulFlags] -- Flags
  102. // [pidmap] -- Pid Mapper
  103. //
  104. // Returns: Size (in bytes) of buffer needed to serialize query.
  105. //
  106. // History: 22-Dec-92 KyleP Added header
  107. //
  108. //--------------------------------------------------------------------------
  109. ULONG PickledSize( int sver,
  110. CColumnSet const * pcol,
  111. CRestriction const * prst,
  112. CSortSet const * pso,
  113. CCategorizationSet const *pcateg,
  114. CRowsetProperties const *pProps,
  115. CPidMapper const * pidmap )
  116. {
  117. CSizeSerStream ss;
  118. DoPickle( sver, ss, 0, pcol, prst, pso, pcateg, pProps, pidmap );
  119. vqDebugOut(( DEB_ITRACE, "Marshalled size = %d bytes\n", ss.Size() ));
  120. return ss.Size();
  121. } //PickledSize
  122. //+-------------------------------------------------------------------------
  123. //
  124. // Function: Pickle, public
  125. //
  126. // Synopsis: Pickles query
  127. //
  128. // Arguments: [sver] -- version of the server we are targeting
  129. // [pcol] -- Columns in table
  130. // [prst] -- Restriction
  131. // [pso] -- Sort order
  132. // [pcateg] -- Categorization specification
  133. // [ulFlags] -- Flags
  134. // [pidmap] -- Pid Mapper
  135. // [pb] -- Buffer to serialize query into
  136. // [cb] -- Size (in bytes) of pb.
  137. //
  138. // History: 22-Dec-92 KyleP Added header
  139. //
  140. //--------------------------------------------------------------------------
  141. void Pickle( int sver,
  142. CColumnSet const * pcol,
  143. CRestriction const * prst,
  144. CSortSet const * pso,
  145. CCategorizationSet const *pcateg,
  146. CRowsetProperties const *pProps,
  147. CPidMapper const * pidmap,
  148. BYTE * pb,
  149. ULONG cb )
  150. {
  151. CMemSerStream ss( pb, cb );
  152. DoPickle( sver, ss, cb, pcol, prst, pso, pcateg, pProps, pidmap );
  153. } //Pickle
  154. //+-------------------------------------------------------------------------
  155. //
  156. // Function: UnPickle, public
  157. //
  158. // Synopsis: Deserializes pickled query into buffer.
  159. //
  160. // Arguments: [cver] -- version of the client that pickled the query
  161. // [col] -- Columns in table here on exit
  162. // [rst] -- Restriction here on exit
  163. // [sort] -- Sort order here on exit
  164. // [categ] -- Categorization specification here on exit
  165. // [RstProp] -- Rowset properties initialized here on exit
  166. // [pidmap] -- Pidmap here on exit
  167. // [pbInput] -- Buffer containing pickled query
  168. // [cbInput] -- Size (in bytes) of pbInput.
  169. //
  170. // History: 22-Dec-92 KyleP Added header
  171. //
  172. //--------------------------------------------------------------------------
  173. void UnPickle( int cver,
  174. XColumnSet & col,
  175. XRestriction & rst,
  176. XSortSet & sort,
  177. XCategorizationSet & categ,
  178. CRowsetProperties & RstProps,
  179. XPidMapper & pidmap,
  180. BYTE * pbInput,
  181. ULONG cbInput )
  182. {
  183. CMemDeSerStream ss( pbInput, cbInput );
  184. ULONG cbPickleBuf = 0;
  185. cbPickleBuf = ss.GetULong(); // length of buffer
  186. if (cbPickleBuf > cbInput)
  187. {
  188. vqDebugOut(( DEB_ERROR, "cbPickleBuf %d, cbInput %d\n",
  189. cbPickleBuf, cbInput ));
  190. Win4Assert(cbPickleBuf <= cbInput);
  191. THROW(CException(STATUS_INVALID_PARAMETER_MIX));
  192. }
  193. BYTE bColType = ss.GetByte();
  194. switch (bColType)
  195. {
  196. case PickleColSet:
  197. col.Set( new CColumnSet(ss) );
  198. break;
  199. default:
  200. Win4Assert(bColType <= PickleColSet);
  201. case PickleColNone:
  202. break;
  203. }
  204. BOOL fNonZero = ss.GetByte();
  205. if ( fNonZero )
  206. {
  207. rst.Set( CRestriction::UnMarshall(ss) );
  208. // would have thrown on out of memory, so rst must be valid
  209. Win4Assert( !rst.IsNull() );
  210. Win4Assert( rst->IsValid() );
  211. }
  212. fNonZero = ss.GetByte();
  213. if ( fNonZero )
  214. sort.Set( new CSortSet(ss) );
  215. fNonZero = ss.GetByte();
  216. if ( fNonZero )
  217. categ.Set( new CCategorizationSet(ss) );
  218. RstProps.Unmarshall(ss);
  219. pidmap.Set( new CPidMapper(ss) );
  220. } //UnPickle
  221. void CRowsetProperties::Marshall( PSerStream & ss ) const
  222. {
  223. ss.PutULong( _uBooleanOptions );
  224. ss.PutULong( _ulMaxOpenRows );
  225. ss.PutULong( _ulMemoryUsage );
  226. ss.PutULong( _cMaxResults );
  227. ss.PutULong( _cCmdTimeout );
  228. } //Marshall
  229. void CRowsetProperties::Unmarshall( PDeSerStream & ss )
  230. {
  231. _uBooleanOptions = ss.GetULong();
  232. _ulMaxOpenRows = ss.GetULong();
  233. _ulMemoryUsage = ss.GetULong();
  234. _cMaxResults = ss.GetULong();
  235. _cCmdTimeout = ss.GetULong();
  236. } //Unmarshall