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.

148 lines
3.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // vsadnary.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class VSADictionary.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/07/1998 Original version.
  16. // 08/13/1998 Use SQL query to retrieve attributes.
  17. // 09/16/1998 Add additional fields to VSA definition.
  18. // 04/17/2000 Port to new dictionary API.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #include <radcommon.h>
  22. #include <iastlb.h>
  23. #include <iastlutl.h>
  24. #include <iasutil.h>
  25. #include <sdoias.h>
  26. #include <vsadnary.h>
  27. ///////////////////////////////////////////////////////////////////////////////
  28. //
  29. // FUNCTION
  30. //
  31. // getFieldWidth
  32. //
  33. // DESCRIPTION
  34. //
  35. // Reads a byte width value from the dictionary.
  36. //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. DWORD getFieldWidth(
  39. IASTL::IASDictionary& table,
  40. ULONG ordinal
  41. ) throw ()
  42. {
  43. // If the width isn't set, assume 1 byte.
  44. if (table.isEmpty(ordinal)) { return 1; }
  45. DWORD width = (DWORD)table.getLong(ordinal);
  46. // Make sure the value is valid.
  47. switch (width)
  48. {
  49. case 0:
  50. case 1:
  51. case 2:
  52. case 4:
  53. break;
  54. default:
  55. width = 1;
  56. }
  57. return width;
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////
  60. //
  61. // METHOD
  62. //
  63. // VSADictionary::initialize
  64. //
  65. // DESCRIPTION
  66. //
  67. // Prepares the dictionary for use.
  68. //
  69. ///////////////////////////////////////////////////////////////////////////////
  70. HRESULT VSADictionary::initialize() throw ()
  71. {
  72. IASGlobalLockSentry sentry;
  73. // Have we already been initialized ?
  74. if (refCount != 0)
  75. {
  76. ++refCount;
  77. return S_OK;
  78. }
  79. try
  80. {
  81. // Names of various columns in the dictionary.
  82. const PCWSTR COLUMNS[] =
  83. {
  84. L"ID",
  85. L"Syntax",
  86. L"VendorID",
  87. L"VendorTypeID",
  88. L"VendorTypeWidth",
  89. L"VendorLengthWidth",
  90. NULL
  91. };
  92. // Open the attributes table.
  93. IASTL::IASDictionary dnary(COLUMNS);
  94. VSADef def;
  95. // Iterate through the attributes and populate our dictionary.
  96. while (dnary.next())
  97. {
  98. if (dnary.isEmpty(2) || dnary.isEmpty(3)) { continue; }
  99. def.iasID = (DWORD) dnary.getLong(0);
  100. def.iasType = (IASTYPE)dnary.getLong(1);
  101. def.vendorID = (DWORD) dnary.getLong(2);
  102. def.vendorType = (DWORD) dnary.getLong(3);
  103. def.vendorTypeWidth = getFieldWidth(dnary, 4);
  104. def.vendorLengthWidth = getFieldWidth(dnary, 5);
  105. insert(def);
  106. }
  107. }
  108. catch (std::bad_alloc)
  109. {
  110. clear();
  111. return E_OUTOFMEMORY;
  112. }
  113. catch (const _com_error& ce)
  114. {
  115. clear();
  116. return ce.Error();
  117. }
  118. // We were successful so add ref.
  119. refCount = 1;
  120. return S_OK;
  121. }
  122. void VSADictionary::shutdown() throw ()
  123. {
  124. IASGlobalLockSentry sentry;
  125. _ASSERT(refCount != 0);
  126. if (--refCount == 0) { clear(); }
  127. }