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.

235 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tcnotify.c
  5. Abstract:
  6. This module contains the notification interaction with WMI
  7. Author:
  8. Shreedhar Madhavapeddi ( shreem ) Jan 12, 1999.
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. int
  13. IsEqualGUIDx(
  14. LPGUID guid1,
  15. LPGUID guid2
  16. )
  17. {
  18. return !memcmp(guid1, guid2, sizeof(GUID));
  19. }
  20. //
  21. // Add the guid/ifchandle to the NotificationList.
  22. // Although it shouldn't happen - check for dupes before adding it.
  23. // Interface handle leads to Client handle
  24. //
  25. ULONG
  26. TcipAddToNotificationList(
  27. IN LPGUID Guid,
  28. IN PINTERFACE_STRUC IfcHandle,
  29. IN ULONG Flags
  30. )
  31. {
  32. PLIST_ENTRY pCurrent;
  33. PNOTIFICATION_ELEMENT pNotifyElem, pNewElem;
  34. int i = 0;
  35. //
  36. // Take the List Lock.
  37. //
  38. pNotifyElem = NULL;
  39. GetLock(NotificationListLock);
  40. pCurrent = NotificationListHead.Flink;
  41. while (&NotificationListHead != pCurrent) {
  42. pNotifyElem = CONTAINING_RECORD(pCurrent, NOTIFICATION_ELEMENT, Linkage.Flink);
  43. if ((pNotifyElem->IfcHandle != IfcHandle) ||
  44. (FALSE == IsEqualGUIDx(&pNotifyElem->NotificationGuid, Guid))) {
  45. pCurrent = pNotifyElem->Linkage.Flink;
  46. } else {
  47. //
  48. // We found a guid/ifchandle combo already!
  49. //DEBUGBREAK();
  50. goto exit;
  51. }
  52. }
  53. //
  54. // If we are here, we couldnt find the GUID/IfcHAndle combo
  55. // Allocate a new element and add it to the list, return TRUE;
  56. //
  57. AllocMem(&pNewElem, sizeof(NOTIFICATION_ELEMENT));
  58. if (!pNewElem) {
  59. // cant alloc memory;
  60. goto exit;
  61. }
  62. pNewElem->IfcHandle = IfcHandle;
  63. pNewElem->NotificationGuid = *Guid;
  64. InsertHeadList(&NotificationListHead, &pNewElem->Linkage);
  65. FreeLock(NotificationListLock);
  66. return TRUE;
  67. exit:
  68. FreeLock(NotificationListLock);
  69. return FALSE;
  70. }
  71. //
  72. // Remove the guid/ifchandle from the NotificationListHead.
  73. // If DBG - check for more than one entries.
  74. //
  75. ULONG
  76. TcipDeleteFromNotificationList(
  77. IN LPGUID Guid,
  78. IN PINTERFACE_STRUC IfcHandle,
  79. IN ULONG Flags
  80. )
  81. {
  82. PLIST_ENTRY pCurrent;
  83. PNOTIFICATION_ELEMENT pNotifyElem;
  84. pNotifyElem = NULL;
  85. GetLock(NotificationListLock);
  86. pCurrent = NotificationListHead.Flink;
  87. while (&NotificationListHead != pCurrent) {
  88. pNotifyElem = CONTAINING_RECORD(pCurrent, NOTIFICATION_ELEMENT, Linkage.Flink);
  89. if ((pNotifyElem->IfcHandle == IfcHandle) &&
  90. (TRUE == IsEqualGUIDx(&pNotifyElem->NotificationGuid, Guid))) {
  91. //
  92. // We found the guid/ifchandle combo - remove it.
  93. RemoveEntryList(&pNotifyElem->Linkage);
  94. FreeMem(pNotifyElem);
  95. break;
  96. } else {
  97. pCurrent = pNotifyElem->Linkage.Flink;
  98. }
  99. }
  100. FreeLock(NotificationListLock);
  101. return TRUE;
  102. }
  103. // Take a Interface & GUID that has a notification from WMI, and
  104. // find if this Client registered to be notified.
  105. ULONG
  106. TcipClientRegisteredForNotification(
  107. IN LPGUID Guid,
  108. IN PINTERFACE_STRUC IfcHandle,
  109. IN ULONG Flags
  110. )
  111. {
  112. PLIST_ENTRY pCurrent;
  113. PNOTIFICATION_ELEMENT pNotifyElem;
  114. pNotifyElem = NULL;
  115. // make sure the list doesn't change under us.
  116. GetLock(NotificationListLock);
  117. pCurrent = NotificationListHead.Flink;
  118. while (&NotificationListHead != pCurrent) {
  119. pNotifyElem = CONTAINING_RECORD(pCurrent, NOTIFICATION_ELEMENT, Linkage.Flink);
  120. if ((pNotifyElem->IfcHandle == IfcHandle) &&
  121. (IsEqualGUIDx(&pNotifyElem->NotificationGuid, Guid))) {
  122. FreeLock(NotificationListLock);
  123. return TRUE;
  124. }
  125. pCurrent = pNotifyElem->Linkage.Flink;
  126. }
  127. FreeLock(NotificationListLock);
  128. return FALSE;
  129. }
  130. //
  131. // Remove the guid/ifchandle from the NotificationListHead.
  132. //
  133. ULONG
  134. TcipDeleteInterfaceFromNotificationList(
  135. IN PINTERFACE_STRUC IfcHandle,
  136. IN ULONG Flags
  137. )
  138. {
  139. PLIST_ENTRY pCurrent;
  140. PNOTIFICATION_ELEMENT pNotifyElem;
  141. pNotifyElem = NULL;
  142. ASSERT(IfcHandle);
  143. GetLock(NotificationListLock);
  144. pCurrent = NotificationListHead.Flink;
  145. while (&NotificationListHead != pCurrent) {
  146. pNotifyElem = CONTAINING_RECORD(pCurrent, NOTIFICATION_ELEMENT, Linkage.Flink);
  147. if (pNotifyElem->IfcHandle == IfcHandle) {
  148. pCurrent = pNotifyElem->Linkage.Flink;
  149. //
  150. // We found the guid/ifchandle combo - remove it.
  151. RemoveEntryList(&pNotifyElem->Linkage);
  152. FreeMem(pNotifyElem);
  153. } else {
  154. pCurrent = pNotifyElem->Linkage.Flink;
  155. }
  156. }
  157. FreeLock(NotificationListLock);
  158. return TRUE;
  159. }