Leaked source code of windows server 2003
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.

277 lines
8.2 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //
  6. // File: propvar.h
  7. //
  8. // Contents: PROPVARIANT manipulation code
  9. //
  10. // History: 15-Aug-95 vich created
  11. // 01-Jul-96 MikeHill Updated to allow Win32 SEH removal
  12. //
  13. //---------------------------------------------------------------------------
  14. #ifndef _PROPVAR_H_
  15. #define _PROPVAR_H_
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif
  19. #include <debnot.h>
  20. #include <propset.h>
  21. #include <propapi.h> // PROPASSERT
  22. SERIALIZEDPROPERTYVALUE *
  23. RtlConvertVariantToProperty(
  24. IN PROPVARIANT const *pvar,
  25. IN USHORT CodePage,
  26. OUT SERIALIZEDPROPERTYVALUE *pprop,
  27. IN OUT ULONG *pcb,
  28. IN PROPID pid,
  29. IN BOOLEAN fVariantVector,
  30. OPTIONAL OUT ULONG *pcIndirect);
  31. SERIALIZEDPROPERTYVALUE *
  32. RtlConvertVariantToPropertyNoEH( // No NT Exception Handling version
  33. IN PROPVARIANT const *pvar,
  34. IN USHORT CodePage,
  35. OUT SERIALIZEDPROPERTYVALUE *pprop,
  36. IN OUT ULONG *pcb,
  37. IN PROPID pid,
  38. IN BOOLEAN fVariantVector,
  39. OPTIONAL OUT ULONG *pcIndirect,
  40. OUT NTSTATUS *pstatus);
  41. BOOLEAN
  42. RtlConvertPropertyToVariant(
  43. IN SERIALIZEDPROPERTYVALUE const *pprop,
  44. IN USHORT CodePage,
  45. OUT PROPVARIANT *pvar,
  46. IN PMemoryAllocator *pma);
  47. BOOLEAN
  48. RtlConvertPropertyToVariantNoEH( // No NT Exception Handling version
  49. IN SERIALIZEDPROPERTYVALUE const *pprop,
  50. IN USHORT CodePage,
  51. OUT PROPVARIANT *pvar,
  52. IN PMemoryAllocator *pma,
  53. OUT NTSTATUS *pstatus);
  54. EXTERN_C SERIALIZEDPROPERTYVALUE * __stdcall
  55. StgConvertVariantToProperty(
  56. IN PROPVARIANT const *pvar,
  57. IN USHORT CodePage,
  58. OUT SERIALIZEDPROPERTYVALUE *pprop,
  59. IN OUT ULONG *pcb,
  60. IN PROPID pid,
  61. IN BOOLEAN fVector,
  62. OPTIONAL OUT ULONG *pcIndirect);
  63. EXTERN_C SERIALIZEDPROPERTYVALUE * __stdcall
  64. StgConvertVariantToPropertyNoEH( // No NT Exception Handling version
  65. IN PROPVARIANT const *pvar,
  66. IN USHORT CodePage,
  67. OUT SERIALIZEDPROPERTYVALUE *pprop,
  68. IN OUT ULONG *pcb,
  69. IN PROPID pid,
  70. IN BOOLEAN fVector,
  71. IN BOOLEAN fArray,
  72. OPTIONAL OUT ULONG *pcIndirect,
  73. OPTIONAL OUT WORD *pwMinFormatRequired,
  74. OUT NTSTATUS *pstatus);
  75. EXTERN_C BOOLEAN __stdcall
  76. StgConvertPropertyToVariant(
  77. IN SERIALIZEDPROPERTYVALUE const *pprop,
  78. IN USHORT CodePage,
  79. OUT PROPVARIANT *pvar,
  80. IN PMemoryAllocator *pma);
  81. EXTERN_C BOOLEAN __stdcall
  82. StgConvertPropertyToVariantNoEH( // No NT Exception Handling version
  83. IN SERIALIZEDPROPERTYVALUE const *pprop,
  84. IN ULONG cbprop,
  85. IN USHORT CodePage,
  86. OUT PROPVARIANT *pvar,
  87. IN PMemoryAllocator *pma,
  88. OUT NTSTATUS *pstatus);
  89. #ifndef KERNEL
  90. VOID
  91. CleanupVariants(
  92. IN PROPVARIANT *pvar,
  93. IN ULONG cprop,
  94. IN PMemoryAllocator *pma);
  95. #endif
  96. #if DBGPROP
  97. BOOLEAN IsUnicodeString(WCHAR const *pwszname, ULONG cb);
  98. BOOLEAN IsAnsiString(CHAR const *pszname, ULONG cb);
  99. #endif
  100. //+--------------------------------------------------------------------------
  101. // Function: SignalOverflow, SignalInvalidParameter, SignalStatus
  102. //
  103. // Synopsis: ASSERT and raise data corrupt/overflow/specified error
  104. //
  105. // Arguments: [szReason] -- string explanation
  106. // [Status] -- Status to raise (SignalStatus only)
  107. //
  108. // Returns: None
  109. //+--------------------------------------------------------------------------
  110. #define StatusOverflow(pstatus, szReason) \
  111. *(pstatus) = STATUS_BUFFER_OVERFLOW; \
  112. TraceStatus(szReason)
  113. #define StatusAccessDenied(pstatus, szReason) \
  114. *(pstatus) = STATUS_ACCESS_DENIED; \
  115. TraceStatus(szReason);
  116. #define StatusInvalidParameter(pstatus, szReason) \
  117. *(pstatus) = STATUS_INVALID_PARAMETER; \
  118. TraceStatus(szReason);
  119. #define StatusNoMemory(pstatus, szReason) \
  120. *(pstatus) = STATUS_INSUFFICIENT_RESOURCES;\
  121. TraceStatus(szReason);
  122. #define StatusDiskFull(pstatus, szReason) \
  123. *(pstatus) = STATUS_DISK_FULL; \
  124. TraceStatus(szReason);
  125. #define StatusError(pstatus, szReason, Status) \
  126. *(pstatus) = Status; \
  127. TraceStatus(szReason);
  128. #ifdef KERNEL
  129. #define StatusKBufferOverflow(pstatus, szReason) StatusOverflow(pstatus, szReason)
  130. #else
  131. #define StatusKBufferOverflow(pstatus, szReason) StatusNoMemory(pstatus, szReason)
  132. #endif
  133. #ifdef KERNEL
  134. #define KERNELSELECT(k, u) k
  135. #else
  136. #define KERNELSELECT(k, u) u
  137. #endif
  138. #define DBGPROPASSERT KERNELSELECT(DBGPROP, DBG)
  139. #if DBGPROPASSERT
  140. #define TraceStatus(szReason) \
  141. { \
  142. DebugTrace(0, DEBTRACE_ERROR, (szReason "\n")); \
  143. PROPASSERTMSG(szReason, !(DebugLevel & DEBTRACE_WARN)); \
  144. }
  145. #else
  146. #define TraceStatus(szReason)
  147. #endif
  148. #define AssertVarField(field, cb) \
  149. PROPASSERT(FIELD_OFFSET(PROPVARIANT, iVal) == FIELD_OFFSET(PROPVARIANT, field) && \
  150. sizeof(((PROPVARIANT *) 0)->field) == (cb))
  151. #define AssertVarVector(field, cbElem) \
  152. PROPASSERT(FIELD_OFFSET(PROPVARIANT, cai.cElems) == \
  153. FIELD_OFFSET(PROPVARIANT, field.cElems) && \
  154. FIELD_OFFSET(PROPVARIANT, cai.pElems) == \
  155. FIELD_OFFSET(PROPVARIANT, field.pElems) && \
  156. sizeof(((PROPVARIANT *) 0)->field.pElems[0]) == (cbElem))
  157. #define AssertByteField(field) AssertVarField(field, sizeof(BYTE))
  158. #define AssertShortField(field) AssertVarField(field, sizeof(SHORT))
  159. #define AssertLongField(field) AssertVarField(field, sizeof(LONG))
  160. #define AssertLongLongField(field) AssertVarField(field, sizeof(LONGLONG))
  161. #define AssertStringField(field) AssertVarField(field, sizeof(VOID *))
  162. #define AssertByteVector(field) AssertVarVector(field, sizeof(BYTE))
  163. #define AssertShortVector(field) AssertVarVector(field, sizeof(SHORT))
  164. #define AssertLongVector(field) AssertVarVector(field, sizeof(LONG))
  165. #define AssertLongLongVector(field) AssertVarVector(field, sizeof(LONGLONG))
  166. #define AssertStringVector(field) AssertVarVector(field, sizeof(VOID *))
  167. #define AssertVariantVector(field) AssertVarVector(field, sizeof(PROPVARIANT))
  168. #define BSTRLEN(bstrVal) *((ULONG *) bstrVal - 1)
  169. //+-------------------------------------------------------------------
  170. // Class: CBufferAllocator, private
  171. //
  172. // Synopsis: allocation from a buffer
  173. //
  174. // Notes: The Summary catalog APIs use a single buffer to serialize row
  175. // values on input and deserialize them on output. This class
  176. // encapsulates the memory allocation routines for these APIs.
  177. //--------------------------------------------------------------------
  178. class CBufferAllocator : public PMemoryAllocator
  179. {
  180. public:
  181. inline CBufferAllocator(ULONG cbBuffer, VOID *pvBuffer)
  182. {
  183. _cbFree = cbBuffer;
  184. _pvCur = _pvBuffer = pvBuffer;
  185. #if _X86_ // stack variables on x86 are not aligned
  186. PROPASSERT(((ULONG) _pvCur & (sizeof(LONG) - 1)) == 0);
  187. #else // RISC
  188. PROPASSERT(((ULONG_PTR) _pvCur & (sizeof(LONGLONG) - 1)) == 0);
  189. #endif // X86/RISC
  190. }
  191. VOID *Allocate(ULONG cbSize);
  192. VOID Free(VOID *pv) { }
  193. inline ULONG GetFreeSize(VOID) { return(_cbFree); }
  194. private:
  195. ULONG _cbFree;
  196. VOID *_pvCur;
  197. VOID *_pvBuffer;
  198. };
  199. //+-------------------------------------------------------------------
  200. // Member: CBufferAllocator::Allocate, private
  201. //
  202. // Synopsis: allocation from a buffer
  203. //
  204. // Arguments: [cb] -- Count of bytes to be allocated.
  205. //
  206. // Returns: pointer to 'allocated' memory -- NULL if no space left
  207. //--------------------------------------------------------------------
  208. #define DEFINE_CBufferAllocator__Allocate \
  209. VOID * \
  210. CBufferAllocator::Allocate(ULONG cb) \
  211. { \
  212. VOID *pv; \
  213. \
  214. cb = (cb + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1); \
  215. if (cb > _cbFree) \
  216. { \
  217. return(NULL); \
  218. } \
  219. pv = _pvCur; \
  220. _pvCur = (BYTE *) _pvCur + cb; \
  221. _cbFree -= cb; \
  222. return(pv); \
  223. }
  224. #endif // !_PROPVAR_H_