Source code of Windows XP (NT5)
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
3.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. handle.c
  5. Abstract:
  6. This module contains the handle table mgmt routines.
  7. Author:
  8. Wesley Witt (wesw) 12-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "faxsvc.h"
  12. #pragma hdrstop
  13. LIST_ENTRY HandleTableListHead;
  14. CRITICAL_SECTION CsHandleTable;
  15. extern LONG ConnectionCount;
  16. BOOL
  17. InitializeHandleTable(
  18. PREG_FAX_SERVICE FaxReg
  19. )
  20. {
  21. InitializeCriticalSection( &CsHandleTable );
  22. InitializeListHead( &HandleTableListHead );
  23. return TRUE;
  24. }
  25. PHANDLE_ENTRY
  26. CreateNewHandle(
  27. handle_t hBinding,
  28. DWORD Type,
  29. PLINE_INFO LineInfo,
  30. PJOB_ENTRY JobEntry,
  31. DWORD Flags
  32. )
  33. {
  34. PHANDLE_ENTRY HandleEntry;
  35. HandleEntry = (PHANDLE_ENTRY) MemAlloc( sizeof(HANDLE_ENTRY) );
  36. if (!HandleEntry) {
  37. return NULL;
  38. }
  39. EnterCriticalSection( &CsHandleTable );
  40. InsertTailList( &HandleTableListHead, &HandleEntry->ListEntry );
  41. HandleEntry->hBinding = hBinding;
  42. HandleEntry->Type = Type;
  43. HandleEntry->LineInfo = LineInfo;
  44. HandleEntry->JobEntry = JobEntry;
  45. HandleEntry->Flags = Flags;
  46. LeaveCriticalSection( &CsHandleTable );
  47. return HandleEntry;
  48. }
  49. PHANDLE_ENTRY
  50. CreateNewConnectionHandle(
  51. handle_t hBinding
  52. )
  53. {
  54. return CreateNewHandle(
  55. hBinding,
  56. FHT_CON,
  57. NULL,
  58. NULL,
  59. 0
  60. );
  61. }
  62. PHANDLE_ENTRY
  63. CreateNewPortHandle(
  64. handle_t hBinding,
  65. PLINE_INFO LineInfo,
  66. DWORD Flags
  67. )
  68. {
  69. return CreateNewHandle(
  70. hBinding,
  71. FHT_PORT,
  72. LineInfo,
  73. NULL,
  74. Flags
  75. );
  76. }
  77. VOID
  78. RemoveClientEntries(
  79. handle_t hBinding
  80. )
  81. {
  82. PFAX_CLIENT_DATA ClientData;
  83. PLIST_ENTRY Next;
  84. EnterCriticalSection( &CsClients );
  85. __try {
  86. DebugPrint(( TEXT("removing client connections\n") ));
  87. Next = ClientsListHead.Flink;
  88. if (Next) {
  89. while ((ULONG_PTR)Next != (ULONG_PTR)&ClientsListHead) {
  90. ClientData = CONTAINING_RECORD( Next, FAX_CLIENT_DATA, ListEntry );
  91. Next = ClientData->ListEntry.Flink;
  92. if (ClientData->hBinding == hBinding) {
  93. RemoveEntryList( &ClientData->ListEntry );
  94. MemFree(ClientData);
  95. }
  96. }
  97. }
  98. } __except (EXCEPTION_EXECUTE_HANDLER) {
  99. DebugPrint(( TEXT("RemoveClientEntries crashed, ec=0x%08x"), GetExceptionCode() ));
  100. }
  101. LeaveCriticalSection( &CsClients );
  102. }
  103. VOID
  104. CloseFaxHandle(
  105. PHANDLE_ENTRY HandleEntry
  106. )
  107. {
  108. //
  109. // note that the HandleEntry may be a context handle,
  110. // which may be NULL in some cases. Do nothing if
  111. // this is the case
  112. //
  113. if (!HandleEntry) {
  114. return;
  115. }
  116. EnterCriticalSection( &CsHandleTable );
  117. RemoveEntryList( &HandleEntry->ListEntry );
  118. if (HandleEntry->Type == FHT_CON) {
  119. // RemoveClientEntries(HandleEntry->hBinding);
  120. InterlockedDecrement( &ConnectionCount );
  121. }
  122. MemFree( HandleEntry );
  123. LeaveCriticalSection( &CsHandleTable );
  124. }
  125. BOOL
  126. IsPortOpenedForModify(
  127. PLINE_INFO LineInfo
  128. )
  129. {
  130. PLIST_ENTRY Next;
  131. PHANDLE_ENTRY HandleEntry;
  132. EnterCriticalSection( &CsHandleTable );
  133. Next = HandleTableListHead.Flink;
  134. if (Next == NULL) {
  135. LeaveCriticalSection( &CsHandleTable );
  136. return FALSE;
  137. }
  138. while ((ULONG_PTR)Next != (ULONG_PTR)&HandleTableListHead) {
  139. HandleEntry = CONTAINING_RECORD( Next, HANDLE_ENTRY, ListEntry );
  140. if (HandleEntry->Type == FHT_PORT && (HandleEntry->Flags & PORT_OPEN_MODIFY) && HandleEntry->LineInfo == LineInfo) {
  141. LeaveCriticalSection( &CsHandleTable );
  142. return TRUE;
  143. }
  144. Next = HandleEntry->ListEntry.Flink;
  145. }
  146. LeaveCriticalSection( &CsHandleTable );
  147. return FALSE;
  148. }