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.

229 lines
4.6 KiB

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