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.

261 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. xbf.hxx
  5. Abstract:
  6. Classes to handle cert wildcard mapping
  7. Author:
  8. Philippe Choquier (phillich) 17-oct-1996
  9. --*/
  10. #if !defined( _IISXBF_HXX )
  11. #define _IISXBF_HXX
  12. #if !defined(dllexp)
  13. #define dllexp __declspec( dllexport )
  14. #endif
  15. //
  16. // Extensible buffer class
  17. //
  18. // Use GetBuff() & GetUsed() to retrieve buffer ptr & length
  19. //
  20. class CStoreXBF
  21. {
  22. public:
  23. dllexp CStoreXBF( UINT cG = sizeof(DWORD) ) { m_pBuff = NULL; m_cAllocBuff = 0; m_cUsedBuff = 0; m_cGrain = cG; }
  24. dllexp ~CStoreXBF() { Reset(); }
  25. dllexp VOID Reset()
  26. {
  27. if ( m_pBuff )
  28. {
  29. LocalFree( m_pBuff );
  30. m_pBuff = NULL;
  31. m_cAllocBuff = 0;
  32. m_cUsedBuff = 0;
  33. }
  34. }
  35. dllexp VOID Clear()
  36. {
  37. m_cUsedBuff = 0;
  38. }
  39. dllexp BOOL DecreaseUse( DWORD dwD )
  40. {
  41. if ( dwD <= m_cUsedBuff )
  42. {
  43. m_cUsedBuff -= dwD;
  44. return TRUE;
  45. }
  46. return FALSE;
  47. }
  48. dllexp BOOL Append( LPSTR pszB )
  49. {
  50. return Append( (LPBYTE)pszB, strlen(pszB) );
  51. }
  52. dllexp BOOL AppendZ( LPSTR pszB )
  53. {
  54. return Append( (LPBYTE)pszB, strlen(pszB)+1 );
  55. }
  56. dllexp BOOL Append( DWORD dwB )
  57. {
  58. return Append( (LPBYTE)&dwB, (DWORD)sizeof(DWORD) );
  59. }
  60. dllexp BOOL Append( LPBYTE pB, DWORD cB )
  61. {
  62. DWORD dwNeed = m_cUsedBuff + cB;
  63. if ( Need( dwNeed ) )
  64. {
  65. memcpy( m_pBuff + m_cUsedBuff, pB, cB );
  66. m_cUsedBuff += cB;
  67. return TRUE;
  68. }
  69. return FALSE;
  70. }
  71. dllexp BOOL Need( DWORD dwNeed );
  72. //
  73. // Get ptr to buffer
  74. //
  75. dllexp LPBYTE GetBuff() { return m_pBuff; }
  76. //
  77. // Get count of bytes in buffer
  78. //
  79. dllexp DWORD GetUsed() { return m_cUsedBuff; }
  80. dllexp BOOL Save( HANDLE hFile );
  81. dllexp BOOL Load( HANDLE hFile );
  82. private:
  83. LPBYTE m_pBuff;
  84. DWORD m_cAllocBuff;
  85. DWORD m_cGrain;
  86. DWORD m_cUsedBuff;
  87. } ;
  88. //
  89. // extensible array of DWORDS
  90. // Added to make win64 stuff work
  91. //
  92. class CPtrDwordXBF : public CStoreXBF
  93. {
  94. public:
  95. dllexp CPtrDwordXBF() : CStoreXBF( sizeof(DWORD) ) {}
  96. dllexp DWORD GetNbPtr() { return GetUsed()/sizeof(DWORD); }
  97. dllexp DWORD AddPtr(DWORD dwEntry);
  98. dllexp DWORD InsertPtr(DWORD iBefore, DWORD dwEntry);
  99. dllexp LPDWORD GetPtr( DWORD i ) { return ( (LPDWORD*) GetBuff())[i]; }
  100. dllexp BOOL SetPtr( DWORD i, DWORD pV ) { ((LPDWORD)GetBuff())[i] = pV; return TRUE; }
  101. dllexp BOOL DeletePtr( DWORD i );
  102. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  103. dllexp BOOL Serialize( CStoreXBF* pX );
  104. } ;
  105. //
  106. // extensible array of LPVOID
  107. //
  108. class CPtrXBF : public CStoreXBF
  109. {
  110. public:
  111. dllexp CPtrXBF() : CStoreXBF( sizeof(LPVOID) ) {}
  112. dllexp DWORD GetNbPtr() { return GetUsed()/sizeof(LPVOID); }
  113. dllexp DWORD AddPtr( LPVOID pV);
  114. dllexp DWORD InsertPtr( DWORD iBefore, LPVOID pV );
  115. dllexp LPVOID GetPtr( DWORD i ) { return ((LPVOID*)GetBuff())[i]; }
  116. dllexp LPVOID GetPtrAddr( DWORD i ) { return ((LPVOID*)GetBuff())+i; }
  117. dllexp BOOL SetPtr( DWORD i, LPVOID pV ) { ((LPVOID*)GetBuff())[i] = pV; return TRUE; }
  118. dllexp BOOL DeletePtr( DWORD i );
  119. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  120. dllexp BOOL Serialize( CStoreXBF* pX );
  121. } ;
  122. //
  123. // string storage class
  124. //
  125. class CAllocString {
  126. public:
  127. dllexp CAllocString() { m_pStr = NULL; }
  128. dllexp ~CAllocString() { Reset(); }
  129. dllexp VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL;} }
  130. dllexp BOOL Set( LPSTR pS );
  131. dllexp BOOL Append( LPSTR pS );
  132. dllexp BOOL Unserialize( LPBYTE* ppb, LPDWORD pc );
  133. dllexp BOOL Serialize( CStoreXBF* pX );
  134. dllexp LPSTR Get() { return m_pStr; }
  135. private:
  136. LPSTR m_pStr;
  137. } ;
  138. //
  139. // binary object, contains ptr & size
  140. //
  141. class CBlob {
  142. public:
  143. dllexp CBlob() { m_pStr = NULL; m_cStr = 0; }
  144. dllexp ~CBlob() { Reset(); }
  145. dllexp VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL; m_cStr = 0;} }
  146. dllexp BOOL Set( LPBYTE pStr, DWORD cStr );
  147. dllexp BOOL InitSet( LPBYTE pStr, DWORD cStr );
  148. dllexp LPBYTE Get( LPDWORD pc ) { *pc = m_cStr; return m_pStr; }
  149. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC );
  150. dllexp BOOL Serialize( CStoreXBF* pX );
  151. private:
  152. LPBYTE m_pStr;
  153. DWORD m_cStr;
  154. } ;
  155. //
  156. // extensible array of strings
  157. //
  158. class CStrPtrXBF : public CPtrXBF {
  159. public:
  160. dllexp ~CStrPtrXBF();
  161. dllexp DWORD AddEntry( LPSTR pS );
  162. dllexp DWORD InsertEntry( DWORD iBefore, LPSTR pS );
  163. dllexp DWORD GetNbEntry() { return GetNbPtr(); }
  164. dllexp LPSTR GetEntry( DWORD i ) { return ((CAllocString*)GetPtrAddr(i))->Get(); }
  165. dllexp BOOL SetEntry( DWORD i, LPSTR pS ) { return ((CAllocString*)GetPtrAddr(i))->Set( pS ); }
  166. dllexp BOOL DeleteEntry( DWORD i );
  167. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  168. dllexp BOOL Serialize( CStoreXBF* pX );
  169. } ;
  170. //
  171. // extensible array of binary object
  172. // ptr & size are stored for each entry
  173. //
  174. class CBlobXBF : public CStoreXBF {
  175. public:
  176. dllexp CBlobXBF() : CStoreXBF( sizeof(CBlob) ) {}
  177. dllexp ~CBlobXBF();
  178. dllexp VOID Reset();
  179. dllexp DWORD AddEntry( LPBYTE pS, DWORD cS );
  180. dllexp DWORD InsertEntry( DWORD iBefore, LPSTR pS, DWORD cS );
  181. dllexp DWORD GetNbEntry() { return GetUsed()/sizeof(CBlob); }
  182. dllexp CBlob* GetBlob( DWORD i )
  183. { return (CBlob*)(GetBuff()+i*sizeof(CBlob)); }
  184. dllexp BOOL GetEntry( DWORD i, LPBYTE* ppB, LPDWORD pcB )
  185. {
  186. if ( i < (GetUsed()/sizeof(CBlob)) )
  187. {
  188. *ppB = GetBlob(i)->Get( pcB );
  189. return TRUE;
  190. }
  191. return FALSE;
  192. }
  193. dllexp BOOL SetEntry( DWORD i, LPBYTE pS, DWORD cS )
  194. { return GetBlob(i)->Set( pS, cS ); }
  195. dllexp BOOL DeleteEntry( DWORD i );
  196. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  197. dllexp BOOL Serialize( CStoreXBF* pX );
  198. } ;
  199. BOOL
  200. Unserialize(
  201. LPBYTE* ppB,
  202. LPDWORD pC,
  203. LPDWORD pU
  204. );
  205. BOOL
  206. Unserialize(
  207. LPBYTE* ppB,
  208. LPDWORD pC,
  209. LPBOOL pU
  210. );
  211. BOOL
  212. Serialize(
  213. CStoreXBF* pX,
  214. DWORD dw
  215. );
  216. BOOL
  217. Serialize(
  218. CStoreXBF* pX,
  219. BOOL f
  220. );
  221. #endif