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.

232 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1994-1999 Microsoft Corporation
  3. Module Name :
  4. scache.cpp
  5. Abstract:
  6. IIS Server cache
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager (cluster edition)
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "common.h"
  15. #include "InetMgrApp.h"
  16. #include "iisobj.h"
  17. #include "scache.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. #define new DEBUG_NEW
  23. //
  24. // CIISServerCache implementation
  25. //
  26. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  27. BOOL
  28. CIISServerCache::Add(
  29. IN CIISMachine * pMachine
  30. )
  31. /*++
  32. Routine Description:
  33. Add server to server cache.
  34. Arguments:
  35. CIISMachine * pMachine : Pointer to machine
  36. Return Value:
  37. TRUE if the machine was added.
  38. FALSE if it was not (already existed)
  39. Notes:
  40. The CIISMachine pointer is not owned by the cache.
  41. --*/
  42. {
  43. BOOL fTossed = FALSE;
  44. int nSwitch;
  45. CIISMachine * pCurrent;
  46. POSITION pos = GetHeadPosition();
  47. //
  48. // Find proper insertion point. Fairly lame linear search,
  49. // but cache is not expected to contain above a dozen items or so
  50. // and routine is not called often.
  51. //
  52. while(pos)
  53. {
  54. pCurrent = (CIISMachine *)GetAt(pos);
  55. nSwitch = pMachine->CompareScopeItem(pCurrent);
  56. if (nSwitch < 0)
  57. {
  58. InsertBefore(pos, pMachine);
  59. break;
  60. }
  61. if (nSwitch == 0)
  62. {
  63. ++fTossed;
  64. break;
  65. }
  66. CPtrList::GetNext(pos);
  67. }
  68. if (!pos)
  69. {
  70. AddTail(pMachine);
  71. }
  72. //
  73. // Remember to save changes
  74. //
  75. if (!fTossed)
  76. {
  77. SetDirty();
  78. }
  79. #ifdef _DEBUG
  80. //
  81. // Do a quick sanity check of the cache
  82. //
  83. int cLocals = 0;
  84. CIISMachine * pPrev = NULL;
  85. pCurrent = GetFirst();
  86. while(pCurrent)
  87. {
  88. if (pPrev)
  89. {
  90. //
  91. // Make sure the list is sorted
  92. //
  93. ASSERT(pCurrent->CompareScopeItem(pPrev) > 0);
  94. }
  95. pPrev = pCurrent;
  96. pCurrent = GetNext();
  97. }
  98. //
  99. // Only one local computer
  100. //
  101. ASSERT(cLocals <= 1);
  102. #endif // _DEBUG
  103. return !fTossed;
  104. }
  105. BOOL
  106. CIISServerCache::Remove(
  107. IN CIISMachine * pMachine
  108. )
  109. /*++
  110. Routine Description:
  111. Remove server from the cache.
  112. Arguments:
  113. CIISMachine * pMachine : Server to be removed
  114. Return Value:
  115. TRUE for success, FALSE for failure
  116. --*/
  117. {
  118. BOOL fRemoved = FALSE;
  119. int nSwitch;
  120. CIISMachine * pCurrent;
  121. POSITION pos = GetHeadPosition();
  122. //
  123. // Look for machine object to be deleted
  124. //
  125. // ISSUE: We can currently rely on the actual CIISMachine ptr
  126. // to be matched, though we don't take advantage of that
  127. // with improved search.
  128. //
  129. while(pos)
  130. {
  131. pCurrent = (CIISMachine *)GetAt(pos);
  132. nSwitch = pMachine->CompareScopeItem(pCurrent);
  133. if (nSwitch < 0)
  134. {
  135. //
  136. // Not in the list -- won't find it either
  137. //
  138. ASSERT_MSG("Attempting to remove non-existing machine");
  139. break;
  140. }
  141. if (nSwitch == 0)
  142. {
  143. //
  144. // Found it. If the ASSERT fires, check the "ISSUE" above
  145. //
  146. ASSERT(pCurrent == pMachine);
  147. RemoveAt(pos);
  148. ++fRemoved;
  149. break;
  150. }
  151. CPtrList::GetNext(pos);
  152. }
  153. //
  154. // Remember to save changes
  155. //
  156. if (fRemoved)
  157. {
  158. SetDirty();
  159. }
  160. return fRemoved;
  161. }