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.

162 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: attribute.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _ATTR_H
  11. #define _ATTR_H
  12. #include "common.h"
  13. ////////////////////////////////////////////////////////////////////////
  14. // Forward Declarations
  15. //
  16. class CAttrList2;
  17. ////////////////////////////////////////////////////////////////////////
  18. // CADSIAttribute
  19. class CADSIAttribute
  20. {
  21. public:
  22. // Constructors
  23. //
  24. CADSIAttribute(ADS_ATTR_INFO* pInfo, BOOL bMulti, PCWSTR pszSyntax, BOOL bReadOnly = TRUE);
  25. CADSIAttribute(PADS_ATTR_INFO pInfo);
  26. CADSIAttribute(LPCWSTR lpszAttr);
  27. CADSIAttribute(CADSIAttribute* pAttr);
  28. // Destructor
  29. //
  30. ~CADSIAttribute();
  31. // Data accessor functions
  32. //
  33. void GetProperty(CString& sProp) { sProp = m_pAttrInfo->pszAttrName; }
  34. DWORD GetNumValues() { return m_pAttrInfo->dwNumValues; }
  35. HRESULT SetValues(PADSVALUE pADsValue, DWORD dwNumValues);
  36. HRESULT SetValues(const CStringList& sValues);
  37. void GetValues(CStringList& psValues, DWORD dwMaxCharCount = 1024);
  38. BOOL GetMultivalued() { return m_bMulti; }
  39. void SetMultivalued(BOOL bMulti) { m_bMulti = bMulti; }
  40. void SetDirty(const BOOL bDirty) { m_bDirty = bDirty; }
  41. BOOL IsDirty() { return m_bDirty; }
  42. void SetMandatory(const BOOL bMandatory) { m_bMandatory = bMandatory; }
  43. BOOL IsMandatory() { return m_bMandatory; }
  44. BOOL IsValueSet() { return m_bSet; }
  45. void SetValueSet(const BOOL bSet) { m_bSet = bSet; }
  46. ADSTYPE GetADsType() { return m_pAttrInfo->dwADsType; }
  47. void SetADsType(ADSTYPE dwType) { m_pAttrInfo->dwADsType = dwType; }
  48. CString GetSyntax() { return m_szSyntax; }
  49. void SetSyntax(PCWSTR pszSyntax) { m_szSyntax = pszSyntax; }
  50. ADS_ATTR_INFO* GetAttrInfo();
  51. void SetAttrInfo(PADS_ATTR_INFO pAttrInfo)
  52. {
  53. if (m_pAttrInfo != NULL)
  54. {
  55. _FreeADsAttrInfo(&m_pAttrInfo, FALSE);
  56. }
  57. m_pAttrInfo = pAttrInfo;
  58. m_bReadOnly = TRUE;
  59. }
  60. ADSVALUE* GetADsValues() { return m_pAttrInfo->pADsValues; }
  61. static HRESULT SetValuesInDS(CAttrList2* ptouchAttr, IDirectoryObject* pDirObject);
  62. private:
  63. // Functions
  64. //
  65. ADSVALUE* GetADSVALUE(int idx);
  66. static BOOL _AllocOctetString(ADS_OCTET_STRING& rOldOctetString, ADS_OCTET_STRING& rNew);
  67. static void _FreeOctetString(BYTE* lpValue);
  68. static BOOL _AllocString(LPCWSTR lpsz, LPWSTR* lppszNew);
  69. static void _FreeString(LPWSTR* lppsz);
  70. static BOOL _CopyADsAttrInfo(ADS_ATTR_INFO* pAttrInfo, ADS_ATTR_INFO** ppNewAttrInfo);
  71. static BOOL _CopyADsAttrInfo(ADS_ATTR_INFO* pAttrInfo, ADS_ATTR_INFO* pNewAttrInfo);
  72. static void _FreeADsAttrInfo(ADS_ATTR_INFO** ppAttrInfo, BOOL bReadOnly);
  73. static void _FreeADsAttrInfo(ADS_ATTR_INFO* pAttrInfo);
  74. static BOOL _AllocValues(ADSVALUE** ppValues, DWORD dwLength);
  75. static BOOL _CopyADsValues(ADS_ATTR_INFO* pOldAttrInfo, ADS_ATTR_INFO* ppNewAttrInfo);
  76. static void _FreeADsValues(ADSVALUE** ppADsValues, DWORD dwLength);
  77. static HRESULT _SetADsFromString(LPCWSTR lpszValue, ADSTYPE adsType, ADSVALUE* pADsValue);
  78. // Member data
  79. //
  80. ADS_ATTR_INFO* m_pAttrInfo;
  81. BOOL m_bDirty;
  82. BOOL m_bMulti;
  83. BOOL m_bReadOnly;
  84. BOOL m_bMandatory;
  85. BOOL m_bSet;
  86. CString m_szSyntax;
  87. };
  88. ////////////////////////////////////////////////////////////////////////////////
  89. //
  90. //
  91. typedef CList<CADSIAttribute*,CADSIAttribute*> CAttrListBase2;
  92. class CAttrList2 : public CAttrListBase2
  93. {
  94. public:
  95. CAttrList2() : m_pMandatorySavedValues(NULL), m_pOptionalSavedValues(NULL)
  96. {
  97. }
  98. virtual ~CAttrList2()
  99. {
  100. if (m_pMandatorySavedValues != NULL)
  101. {
  102. FreeADsMem(m_pMandatorySavedValues);
  103. }
  104. if (m_pOptionalSavedValues != NULL)
  105. {
  106. FreeADsMem(m_pOptionalSavedValues);
  107. }
  108. RemoveAllAttr();
  109. }
  110. void RemoveAllAttr()
  111. {
  112. while (!IsEmpty())
  113. delete RemoveTail();
  114. }
  115. POSITION FindProperty(LPCWSTR lpszAttr);
  116. BOOL HasProperty(LPCWSTR lpszAttr);
  117. void GetNextDirty(POSITION& pos, CADSIAttribute** ppAttr);
  118. BOOL HasDirty();
  119. int GetDirtyCount()
  120. {
  121. int nCount = 0;
  122. POSITION pos = GetHeadPosition();
  123. while (pos != NULL)
  124. {
  125. if (GetNext(pos)->IsDirty())
  126. nCount++;
  127. }
  128. return nCount;
  129. }
  130. void SaveMandatoryValuesPointer(PADS_ATTR_INFO pAttrInfo) { m_pMandatorySavedValues = pAttrInfo; }
  131. void SaveOptionalValuesPointer(PADS_ATTR_INFO pAttrInfo) { m_pOptionalSavedValues = pAttrInfo; }
  132. private:
  133. PADS_ATTR_INFO m_pMandatorySavedValues;
  134. PADS_ATTR_INFO m_pOptionalSavedValues;
  135. };
  136. #endif //_ATTR_H