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.

193 lines
4.0 KiB

  1. #ifndef _TICKET_SCHEMA_H
  2. #define _TICKET_SCHEMA_H
  3. #include "xstring"
  4. #include "BstrHash.h"
  5. #import <msxml.tlb> rename_namespace("MSXML")
  6. // this schema object can only handles schema version within the following range
  7. #define VALID_SCHEMA_VERSION_MIN 1
  8. #define VALID_SCHEMA_VERSION_MAX 0x1ff
  9. class CRefCountObj
  10. {
  11. public:
  12. ULONG AddRef()
  13. {
  14. InterlockedIncrement(&m_refs);
  15. return m_refs;
  16. };
  17. ULONG Release()
  18. {
  19. InterlockedDecrement(&m_refs);
  20. if (m_refs == 0)
  21. {
  22. delete this;
  23. return 0;
  24. }
  25. else
  26. return m_refs;
  27. };
  28. protected:
  29. CRefCountObj(): m_refs(0){};
  30. virtual ~CRefCountObj(){};
  31. long m_refs;
  32. };
  33. // the value types supported in the schema
  34. enum TicketValueType {
  35. tNull = 0,
  36. tText,
  37. tChar,
  38. tByte,
  39. tWord,
  40. tLong,
  41. tDate,
  42. tInvalid
  43. };
  44. #define SIZE_TEXT (DWORD)(-1)
  45. // the size array of the types defines in TicketValueType
  46. const DWORD TicketTypeSizes[] =
  47. {
  48. 0,
  49. SIZE_TEXT,
  50. 1,
  51. 1,
  52. sizeof(short),
  53. sizeof(long),
  54. sizeof(long),
  55. 0
  56. };
  57. // attribute names in schema definition in partner.xml
  58. #define ATTRNAME_VERSION L"version"
  59. #define ATTRNAME_NAME L"name"
  60. #define ATTRNAME_TYPE L"type"
  61. #define ATTRNAME_SIZE L"size"
  62. #define ATTRNAME_FLAGS L"flags"
  63. // type name value map
  64. struct CTicketTypeNameMap {
  65. LPCWSTR name;
  66. DWORD type;
  67. };
  68. const CTicketTypeNameMap TicketTypeNameMap[] = {
  69. {L"text" , tText},
  70. {L"char" , tChar},
  71. {L"byte" , tByte},
  72. {L"word" , tWord},
  73. {L"text" , tLong},
  74. {L"long" , tLong},
  75. {L"date" , tDate},
  76. {L"long" , tLong},
  77. };
  78. struct TicketFieldDef
  79. {
  80. _bstr_t name;
  81. DWORD type;
  82. DWORD flags;
  83. };
  84. #define INVALID_OFFSET (DWORD)(-1)
  85. struct TicketProperty
  86. {
  87. TicketProperty():flags(0), offset(INVALID_OFFSET) {};
  88. _variant_t value;
  89. DWORD type; // type of the property, a value of TicketValueType
  90. DWORD flags; // the flags defined in schema
  91. DWORD offset; // the offset of the property in raw buf
  92. };
  93. class CTicketSchema;
  94. class C_Ticket_13X;
  95. class wstringLT
  96. {
  97. public:
  98. bool operator()(const std::wstring& x, const std::wstring& y) const
  99. {
  100. return (_wcsicmp(x.c_str(),y.c_str()) < 0);
  101. }
  102. };
  103. typedef std::map<std::wstring,TicketProperty, wstringLT> TicketPropertyMap;
  104. class CTicketPropertyBag
  105. {
  106. friend class CTicketSchema;
  107. friend class C_Ticket_13X;
  108. public:
  109. CTicketPropertyBag();
  110. virtual ~CTicketPropertyBag();
  111. HRESULT GetProperty(LPCWSTR name, TicketProperty& prop);
  112. int Size() const { return m_props.size();};
  113. protected:
  114. // this bag is read only to external
  115. HRESULT PutProperty(LPCWSTR name, const TicketProperty& prop);
  116. protected:
  117. TicketPropertyMap m_props;
  118. };
  119. class CTicketSchema : public CRefCountObj
  120. {
  121. public:
  122. // Read the raw blob according to the schema, and output the positions of
  123. // each element. Output array size MUST be >= Count()
  124. HRESULT parseTicket(LPCSTR raw, UINT size, CTicketPropertyBag& bag);
  125. CTicketSchema();
  126. virtual ~CTicketSchema();
  127. BOOL isValid() const { return m_isOk; }
  128. _bstr_t getErrorInfo() const { return m_szReason; }
  129. BOOL ReadSchema(MSXML::IXMLElementPtr &root);
  130. protected:
  131. BOOL m_isOk;
  132. _bstr_t m_szReason;
  133. // Valid until this time
  134. SYSTEMTIME m_validUntil;
  135. // verion #
  136. USHORT m_version;
  137. // name
  138. _bstr_t m_name;
  139. // Array of attribute types
  140. UINT m_numAtts;
  141. TicketFieldDef* m_attsDef;
  142. };
  143. #define MORE_MASKUNIT(n) (((n) & 0x8000) != 0)
  144. #define MASK_INDEX_INVALID (USHORT)(-1)
  145. class CTicketFieldMasks
  146. {
  147. public:
  148. CTicketFieldMasks(): m_fieldIndexes(NULL){};
  149. virtual ~CTicketFieldMasks(){delete[] m_fieldIndexes;};
  150. HRESULT Parse(LPBYTE mask, ULONG size, ULONG* pcParsed);
  151. unsigned short* GetIndexes(){ return m_fieldIndexes;};
  152. protected:
  153. unsigned short* m_fieldIndexes;
  154. };
  155. #endif // _TICKET_SCHEMA_H