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.

163 lines
4.2 KiB

  1. //---------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1998 - 1999
  3. //
  4. // olist.c
  5. //
  6. // Maintain list of SERVER_OVERLAPPED structures, used in passing
  7. // the overlapped structure pointers between the RpcProxy filter
  8. // and its ISAPI. This happens on initial connection.
  9. //
  10. // Author:
  11. // 05-04-98 Edward Reus Initial version.
  12. //
  13. //---------------------------------------------------------------------------
  14. #define FD_SETSIZE 1
  15. #include <nt.h>
  16. #include <ntdef.h>
  17. #include <ntrtl.h>
  18. #include <sysinc.h>
  19. #include <mbstring.h>
  20. #include <rpc.h>
  21. #include <rpcdce.h>
  22. #include <winsock2.h>
  23. #include <httpfilt.h>
  24. #include <httpext.h>
  25. #include "ecblist.h"
  26. #include "filter.h"
  27. #include "olist.h"
  28. static RTL_CRITICAL_SECTION g_cs;
  29. static LIST_ENTRY g_OverlappedList;
  30. static DWORD g_dwIndex = 0;
  31. //-------------------------------------------------------------------------
  32. // InitializeOverlappedList()
  33. //
  34. //-------------------------------------------------------------------------
  35. BOOL InitializeOverlappedList()
  36. {
  37. DWORD dwStatus;
  38. dwStatus = RtlInitializeCriticalSection(&g_cs);
  39. if (dwStatus != 0)
  40. {
  41. return FALSE;
  42. }
  43. InitializeListHead(&g_OverlappedList);
  44. g_dwIndex = 1;
  45. return TRUE;
  46. }
  47. void
  48. UninitializeOverlappedList (
  49. void
  50. )
  51. {
  52. if (g_dwIndex)
  53. RtlDeleteCriticalSection(&g_cs);
  54. }
  55. //-------------------------------------------------------------------------
  56. // SaveOverlapped()
  57. //
  58. //-------------------------------------------------------------------------
  59. DWORD SaveOverlapped( SERVER_OVERLAPPED *pOverlapped )
  60. {
  61. DWORD dwStatus;
  62. DWORD dwIndex;
  63. dwStatus = RtlEnterCriticalSection(&g_cs);
  64. InsertTailList(&g_OverlappedList,&(pOverlapped->ListEntry));
  65. dwIndex = g_dwIndex++;
  66. pOverlapped->dwIndex = dwIndex;
  67. // Reset the index allocation so we'll never run out of
  68. // index values...
  69. if (g_dwIndex >= 0x7fffffff)
  70. {
  71. // 0x7fffffff is a LOT of connections...
  72. g_dwIndex = 1;
  73. }
  74. dwStatus = RtlLeaveCriticalSection(&g_cs);
  75. return dwIndex;
  76. }
  77. //-------------------------------------------------------------------------
  78. // GetOverlapped()
  79. //
  80. //-------------------------------------------------------------------------
  81. SERVER_OVERLAPPED *GetOverlapped( DWORD dwIndex )
  82. {
  83. DWORD dwStatus;
  84. LIST_ENTRY *pEntry;
  85. SERVER_OVERLAPPED *pOverlapped = NULL;
  86. dwStatus = RtlEnterCriticalSection(&g_cs);
  87. pEntry = g_OverlappedList.Flink;
  88. while (pEntry != &g_OverlappedList)
  89. {
  90. pOverlapped = CONTAINING_RECORD(pEntry,
  91. SERVER_OVERLAPPED,
  92. ListEntry );
  93. if (pOverlapped->dwIndex == dwIndex)
  94. {
  95. RemoveEntryList(pEntry);
  96. dwStatus = RtlLeaveCriticalSection(&g_cs);
  97. return pOverlapped;
  98. }
  99. pEntry = pEntry->Flink;
  100. }
  101. dwStatus = RtlLeaveCriticalSection(&g_cs);
  102. return NULL;
  103. }
  104. //-------------------------------------------------------------------------
  105. // IsValidOverlappedIndex()
  106. //
  107. // Return TRUE iff the specified index refers to a valid
  108. // SERVER_OVERLAPPED in the list.
  109. //-------------------------------------------------------------------------
  110. BOOL IsValidOverlappedIndex( DWORD dwIndex )
  111. {
  112. DWORD dwStatus;
  113. LIST_ENTRY *pEntry;
  114. SERVER_OVERLAPPED *pOverlapped = NULL;
  115. dwStatus = RtlEnterCriticalSection(&g_cs);
  116. pEntry = g_OverlappedList.Flink;
  117. while (pEntry != &g_OverlappedList)
  118. {
  119. pOverlapped = CONTAINING_RECORD(pEntry,
  120. SERVER_OVERLAPPED,
  121. ListEntry );
  122. if (pOverlapped->dwIndex == dwIndex)
  123. {
  124. dwStatus = RtlLeaveCriticalSection(&g_cs);
  125. return TRUE;
  126. }
  127. pEntry = pEntry->Flink;
  128. }
  129. dwStatus = RtlLeaveCriticalSection(&g_cs);
  130. return FALSE;
  131. }