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.

158 lines
3.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // logschema.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class LogSchema.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/04/1998 Original version.
  16. // 12/02/1998 Added excludeFromLog.
  17. // 04/14/2000 Port to new dictionary API.
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <ias.h>
  21. #include <iastlb.h>
  22. #include <iastlutl.h>
  23. #include <iasutil.h>
  24. #include <algorithm>
  25. #include <vector>
  26. #include <sdoias.h>
  27. #include <logschema.h>
  28. LogSchema::LogSchema() throw ()
  29. : numFields(0), refCount(0)
  30. { }
  31. LogSchema::~LogSchema() throw ()
  32. { }
  33. BOOL LogSchema::excludeFromLog(DWORD iasID) const throw ()
  34. {
  35. LogField key;
  36. key.iasID = iasID;
  37. const SchemaTable::value_type* p = schema.find(key);
  38. return p ? p->excludeFromLog : FALSE;
  39. }
  40. // Returns the LogField data for a given attribute ID.
  41. const LogField* LogSchema::find(DWORD iasID) const throw ()
  42. {
  43. LogField key;
  44. key.iasID = iasID;
  45. return schema.find(key);
  46. }
  47. DWORD LogSchema::getOrdinal(DWORD iasID) const throw ()
  48. {
  49. LogField key;
  50. key.iasID = iasID;
  51. const SchemaTable::value_type* p = schema.find(key);
  52. return p ? p->ordinal : 0;
  53. }
  54. HRESULT LogSchema::initialize() throw ()
  55. {
  56. IASGlobalLockSentry sentry;
  57. // Have we already been initialized ?
  58. if (refCount != 0)
  59. {
  60. ++refCount;
  61. return S_OK;
  62. }
  63. try
  64. {
  65. // Names of various columns in the dictionary.
  66. const PCWSTR COLUMNS[] =
  67. {
  68. L"ID",
  69. L"Name",
  70. L"Exclude from NT4 IAS Log",
  71. L"ODBC Log Ordinal",
  72. NULL
  73. };
  74. // Open the attributes table.
  75. IASTL::IASDictionary dnary(COLUMNS);
  76. std::vector< LogField > record;
  77. while (dnary.next())
  78. {
  79. // Read ID.
  80. DWORD iasID = (DWORD)dnary.getLong(0);
  81. // Read the name.
  82. const wchar_t* name = dnary.getBSTR(1);
  83. // Read [Exclude from NT4 IAS Log] if present.
  84. BOOL exclude = (BOOL)dnary.getBool(2);
  85. // Read [ODBC Log Ordinal] if present.
  86. DWORD ordinal = (DWORD)dnary.getLong(3);
  87. record.push_back(LogField(iasID, name, ordinal, exclude));
  88. }
  89. // Sort the fields by ordinal.
  90. std::sort(record.begin(), record.end());
  91. //////////
  92. // Insert the fields into the table.
  93. //////////
  94. numFields = 0;
  95. for (std::vector< LogField >::iterator i = record.begin();
  96. i != record.end();
  97. ++i)
  98. {
  99. // Normalize the ordinal.
  100. if (i->ordinal) { i->ordinal = ++numFields; }
  101. schema.insert(*i);
  102. }
  103. }
  104. catch (const std::bad_alloc&)
  105. {
  106. clear();
  107. return E_OUTOFMEMORY;
  108. }
  109. catch (const _com_error& ce)
  110. {
  111. clear();
  112. return ce.Error();
  113. }
  114. // We were successful so add ref.
  115. refCount = 1;
  116. return S_OK;
  117. }
  118. void LogSchema::shutdown() throw ()
  119. {
  120. IASGlobalLockSentry sentry;
  121. _ASSERT(refCount != 0);
  122. if (--refCount == 0) { clear(); }
  123. }
  124. void LogSchema::clear() throw ()
  125. {
  126. schema.clear();
  127. }