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.

198 lines
4.3 KiB

  1. //Copyright (c) Microsoft Corporation. All rights reserved.
  2. #include <windows.h>
  3. #include ".\tlntdynamicarray.h"
  4. CLIENT_LIST *client_list_head = NULL;
  5. HANDLE client_list_mutex = NULL;
  6. #ifdef DBG
  7. CHAR scratch[1024];
  8. #endif
  9. BOOL client_list_Add( PVOID client_class_ptr )
  10. {
  11. DWORD mutex_obtained;
  12. BOOL success = FALSE;
  13. #ifdef DBG
  14. wsprintfA(scratch, "BASKAR: Add : 0x%x : ", client_class_ptr);
  15. OutputDebugStringA(scratch);
  16. #endif
  17. if (NULL != client_class_ptr)
  18. {
  19. mutex_obtained = WaitForSingleObject( client_list_mutex, INFINITE );
  20. if ( mutex_obtained == WAIT_OBJECT_0 )
  21. {
  22. CLIENT_LIST *node = new CLIENT_LIST;
  23. if (node)
  24. {
  25. node->some_class_pointer = client_class_ptr;
  26. node->next = client_list_head;
  27. client_list_head = node;
  28. success = TRUE;
  29. }
  30. ReleaseMutex(client_list_mutex);
  31. }
  32. }
  33. #ifdef DBG
  34. wsprintfA(scratch, "%s\n", success ? "SUCCESS" : "FAILURE");
  35. OutputDebugStringA(scratch);
  36. #endif
  37. return (success);
  38. }
  39. PVOID client_list_Get( int client_index )
  40. {
  41. PVOID client_class_found = NULL;
  42. DWORD mutex_obtained;
  43. #ifdef DBG
  44. wsprintfA(scratch, "BASKAR: Get : 0x%d : ", client_index);
  45. OutputDebugStringA(scratch);
  46. #endif
  47. if (client_index >= 0)
  48. {
  49. mutex_obtained = WaitForSingleObject( client_list_mutex, INFINITE );
  50. if ( mutex_obtained == WAIT_OBJECT_0 )
  51. {
  52. CLIENT_LIST *node = client_list_head;
  53. int i;
  54. for (i = 0; (i < client_index) && node; i ++)
  55. {
  56. node = node->next;
  57. }
  58. if ((i == client_index) && node)
  59. {
  60. client_class_found = node->some_class_pointer;
  61. }
  62. ReleaseMutex(client_list_mutex);
  63. }
  64. }
  65. #ifdef DBG
  66. wsprintfA(scratch, "%s\n", (NULL != client_class_found) ? "SUCCESS" : "FAILURE");
  67. OutputDebugStringA(scratch);
  68. #endif
  69. return client_class_found;
  70. }
  71. BOOL client_list_RemoveElem(PVOID client_class_ptr)
  72. {
  73. DWORD mutex_obtained;
  74. BOOL success = FALSE;
  75. #ifdef DBG
  76. wsprintfA(scratch, "BASKAR: Remove : 0x%x : ", client_class_ptr);
  77. OutputDebugStringA(scratch);
  78. #endif
  79. if (NULL != client_class_ptr)
  80. {
  81. mutex_obtained = WaitForSingleObject( client_list_mutex, INFINITE );
  82. if ( mutex_obtained == WAIT_OBJECT_0 )
  83. {
  84. CLIENT_LIST *node = NULL;
  85. CLIENT_LIST *prev = NULL;
  86. for (
  87. node = client_list_head;
  88. node;
  89. prev = node, node = node->next
  90. )
  91. {
  92. if( node->some_class_pointer == client_class_ptr )
  93. {
  94. if (prev)
  95. {
  96. prev->next = node->next; // detach the node from middle
  97. }
  98. else
  99. {
  100. // It has got to be the head of the list
  101. client_list_head = node->next;
  102. }
  103. delete node;
  104. success = TRUE;
  105. break;
  106. }
  107. }
  108. ReleaseMutex(client_list_mutex);
  109. }
  110. }
  111. #ifdef DBG
  112. wsprintfA(scratch, "%s\n", success ? "SUCCESS" : "FAILURE");
  113. OutputDebugStringA(scratch);
  114. #endif
  115. return success;
  116. }
  117. int client_list_Count( void )
  118. {
  119. int count = 0;
  120. DWORD mutex_obtained;
  121. #ifdef DBG
  122. OutputDebugStringA("BASKAR: Count = ");
  123. #endif
  124. mutex_obtained = WaitForSingleObject( client_list_mutex, INFINITE );
  125. if ( mutex_obtained == WAIT_OBJECT_0 )
  126. {
  127. CLIENT_LIST *node = client_list_head;
  128. for (node = client_list_head; node; node = node->next)
  129. {
  130. count ++;
  131. }
  132. ReleaseMutex(client_list_mutex);
  133. }
  134. #ifdef DBG
  135. wsprintfA(scratch, "0x%d\n", count);
  136. OutputDebugStringA(scratch);
  137. #endif
  138. return count;
  139. }