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
2.2 KiB

  1. #include "CUserList.h"
  2. BOOL CUserList::AddNode(PUSER_DATA UserData )
  3. {
  4. PUSER_DATA Temp;
  5. if (UserData)
  6. {
  7. if (m_Head == NULL)
  8. {
  9. m_Head = UserData;
  10. UserData->Prev = NULL;
  11. UserData->Next = NULL;
  12. m_CurrentPos = m_Head;
  13. }
  14. else
  15. {
  16. Temp = m_Head;
  17. while (Temp->Next != NULL )
  18. Temp = Temp->Next;
  19. // Insert the new node.
  20. Temp->Next = UserData;
  21. UserData->Prev = Temp;
  22. UserData->Next = NULL;
  23. }
  24. return TRUE;
  25. }
  26. else
  27. return FALSE;
  28. }
  29. BOOL CUserList::GetNextEntry(PUSER_DATA CurrentNode, BOOL *bEOF)
  30. {
  31. if ((!m_CurrentPos) || (!CurrentNode))
  32. {
  33. *bEOF = TRUE;
  34. return FALSE;
  35. }
  36. memcpy(CurrentNode, m_CurrentPos, sizeof USER_DATA);
  37. m_CurrentPos = m_CurrentPos->Next;
  38. return TRUE;
  39. }
  40. void CUserList::CleanupList()
  41. {
  42. PUSER_DATA Temp;
  43. Temp = m_Head;
  44. while (Temp != NULL)
  45. {
  46. if (Temp->Next != NULL)
  47. {
  48. Temp = Temp->Next;
  49. free(Temp->Prev);
  50. Temp->Prev = NULL;
  51. }
  52. else
  53. {
  54. free(Temp);
  55. Temp = NULL;
  56. m_Head=NULL;
  57. }
  58. }
  59. }
  60. PUSER_DATA CUserList::GetEntry(int iIndex)
  61. {
  62. // search the linked list for the requested index.
  63. BOOL Done = FALSE;
  64. m_CurrentPos = m_Head;
  65. if (!m_CurrentPos)
  66. {
  67. return NULL;
  68. }
  69. while (m_CurrentPos != NULL && !Done)
  70. {
  71. if (m_CurrentPos->iIndex == iIndex)
  72. {
  73. Done = TRUE;
  74. }
  75. else
  76. {
  77. m_CurrentPos = m_CurrentPos->Next;
  78. }
  79. }
  80. if (Done)
  81. {
  82. return m_CurrentPos;
  83. }
  84. else
  85. {
  86. return NULL;
  87. }
  88. }
  89. BOOL CUserList::GetNextEntryNoMove(PUSER_DATA CurrentNode, BOOL *bEOF)
  90. {
  91. if ((!m_CurrentPos) || (!CurrentNode))
  92. {
  93. *bEOF = TRUE;
  94. return FALSE;
  95. }
  96. memcpy(CurrentNode, m_CurrentPos, sizeof USER_DATA);
  97. return TRUE;
  98. }
  99. int CUserList::SetCurrentEntry(PUSER_DATA CurrentNode)
  100. {
  101. if (CurrentNode && m_CurrentPos)
  102. {
  103. memcpy(m_CurrentPos, CurrentNode, sizeof USER_DATA);
  104. }
  105. return 0;
  106. }
  107. void CUserList::SetIndex (int iIndex)
  108. {
  109. if (m_CurrentPos)
  110. {
  111. m_CurrentPos->iIndex = iIndex;
  112. }
  113. }
  114. BOOL CUserList::MoveNext( BOOL *bEOF)
  115. {
  116. if (!m_CurrentPos)
  117. {
  118. *bEOF = TRUE;
  119. return FALSE;
  120. }
  121. else
  122. {
  123. m_CurrentPos = m_CurrentPos->Next;
  124. if (!m_CurrentPos)
  125. {
  126. *bEOF = TRUE;
  127. return FALSE;
  128. }
  129. }
  130. return TRUE;
  131. }