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.

279 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1994-1999 Microsoft Corporation
  3. Module Name :
  4. utcls.h
  5. Abstract:
  6. Some utility functions and classes.
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonov (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. #ifndef _UTCLS_H_
  15. #define _UTCLS_H_
  16. #pragma warning(disable : 4275)
  17. //
  18. // CDialog parameters
  19. //
  20. #define USE_DEFAULT_CAPTION (0)
  21. //
  22. // Determine if the given server name refers to the local machine
  23. //
  24. BOOL _EXPORT
  25. IsServerLocal(
  26. IN LPCTSTR lpszServer
  27. );
  28. //
  29. // Get volume information system flags for the given path
  30. //
  31. BOOL _EXPORT
  32. GetVolumeInformationSystemFlags(
  33. IN LPCTSTR lpszPath,
  34. OUT DWORD * pdwSystemFlags
  35. );
  36. //
  37. // Build registry key name
  38. //
  39. LPCTSTR _EXPORT GenerateRegistryKey(
  40. OUT CString & strBuffer,
  41. IN LPCTSTR lpszSubKey = NULL
  42. );
  43. class _EXPORT CStringListEx : public std::list<CString>
  44. {
  45. public:
  46. CStringListEx();
  47. ~CStringListEx();
  48. void PushBack(LPCTSTR str);
  49. void Clear();
  50. DWORD ConvertFromDoubleNullList(LPCTSTR lpstrSrc, int cChars = -1);
  51. DWORD ConvertToDoubleNullList(DWORD & cchDest, LPTSTR & lpstrDest);
  52. };
  53. class _EXPORT CBlob
  54. /*++
  55. Class Description:
  56. Binary large object class, which owns its pointer
  57. Public Interface:
  58. CBlob : Constructors
  59. ~CBlob : Destructor
  60. SetValue : Assign the value
  61. GetSize : Get the byte size
  62. GetData : Get pointer to the byte stream
  63. --*/
  64. {
  65. //
  66. // Constructors/Destructor
  67. //
  68. public:
  69. //
  70. // Initialize empty blob
  71. //
  72. CBlob();
  73. //
  74. // Initialize with binary data
  75. //
  76. CBlob(
  77. IN DWORD dwSize,
  78. IN PBYTE pbItem,
  79. IN BOOL fMakeCopy = TRUE
  80. );
  81. //
  82. // Copy constructor
  83. //
  84. CBlob(IN const CBlob & blob);
  85. //
  86. // Destructor destroys the pointer
  87. //
  88. ~CBlob();
  89. //
  90. // Operators
  91. //
  92. public:
  93. CBlob & operator =(const CBlob & blob);
  94. BOOL operator ==(const CBlob & blob) const;
  95. BOOL operator !=(const CBlob & blob) const { return !operator ==(blob); }
  96. //
  97. // Access
  98. //
  99. public:
  100. //
  101. // Clean up internal data
  102. //
  103. void CleanUp();
  104. //
  105. // Set the current value of the blob
  106. //
  107. void SetValue(
  108. IN DWORD dwSize,
  109. IN PBYTE pbItem,
  110. IN BOOL fMakeCopy = TRUE
  111. );
  112. //
  113. // TRUE if the blob is currently empty
  114. //
  115. BOOL IsEmpty() const { return m_dwSize == 0L; }
  116. //
  117. // Return the size of the blob in bytes
  118. //
  119. DWORD GetSize() const { return m_dwSize; }
  120. //
  121. // Get a pointer to the byte stream
  122. //
  123. PBYTE GetData();
  124. private:
  125. DWORD m_dwSize;
  126. PBYTE m_pbItem;
  127. };
  128. // Blob for use in CryptoAPI functions
  129. //
  130. class CCryptBlob
  131. {
  132. public:
  133. CCryptBlob()
  134. {
  135. m_blob.cbData = 0;
  136. m_blob.pbData = NULL;
  137. }
  138. virtual ~CCryptBlob()
  139. {
  140. }
  141. DWORD GetSize() {return m_blob.cbData;}
  142. BYTE * GetData() {return m_blob.pbData;}
  143. void Set(DWORD cb, BYTE * pb)
  144. {
  145. Destroy();
  146. m_blob.cbData = cb;
  147. m_blob.pbData = pb;
  148. }
  149. BOOL Resize(DWORD cb)
  150. {
  151. BOOL res = TRUE;
  152. BYTE * p = m_blob.pbData;
  153. if (NULL != (m_blob.pbData = Realloc(m_blob.pbData, cb)))
  154. {
  155. m_blob.cbData = cb;
  156. }
  157. else
  158. {
  159. m_blob.pbData = p;
  160. res = FALSE;
  161. }
  162. return res;
  163. }
  164. operator CRYPT_DATA_BLOB *()
  165. {
  166. return &m_blob;
  167. }
  168. protected:
  169. void Destroy()
  170. {
  171. if (m_blob.pbData != NULL)
  172. Free(m_blob.pbData);
  173. }
  174. virtual BYTE * Realloc(BYTE * pb, DWORD cb) = 0;
  175. virtual void Free(BYTE * pb) = 0;
  176. CRYPT_DATA_BLOB m_blob;
  177. };
  178. class CCryptBlobIMalloc : public CCryptBlob
  179. {
  180. public:
  181. virtual ~CCryptBlobIMalloc()
  182. {
  183. CCryptBlob::Destroy();
  184. }
  185. protected:
  186. virtual BYTE * Realloc(BYTE * pb, DWORD cb)
  187. {
  188. return (BYTE *)CoTaskMemRealloc(pb, cb);
  189. }
  190. virtual void Free(BYTE * pb)
  191. {
  192. CoTaskMemFree(pb);
  193. }
  194. };
  195. class CCryptBlobLocal : public CCryptBlob
  196. {
  197. public:
  198. virtual ~CCryptBlobLocal()
  199. {
  200. CCryptBlob::Destroy();
  201. }
  202. protected:
  203. virtual BYTE * Realloc(BYTE * pb, DWORD cb)
  204. {
  205. return (BYTE *)realloc(pb, cb);
  206. }
  207. virtual void Free(BYTE * pb)
  208. {
  209. free(pb);
  210. }
  211. };
  212. //
  213. // Inline Expansion
  214. //
  215. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  216. inline CBlob::~CBlob()
  217. {
  218. CleanUp();
  219. }
  220. inline PBYTE CBlob::GetData()
  221. {
  222. return m_pbItem;
  223. }
  224. #endif // _UTCLS_H_