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.

215 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. cmmsprop.cpp
  5. Abstract:
  6. This module contains the implementation of the special property class
  7. Author:
  8. Keith Lau (keithlau@microsoft.com)
  9. Revision History:
  10. keithlau 04/19/98 created
  11. --*/
  12. #include "windows.h"
  13. #include <stdlib.h>
  14. #include "dbgtrace.h"
  15. #include "cmmsprop.h"
  16. // =================================================================
  17. // Implementation of CSpecialPropertyTable
  18. //
  19. int __cdecl CompareProperties(const void *pElem1, const void *pElem2)
  20. {
  21. return(
  22. (((LPSPECIAL_PROPERTY_ITEM)pElem1)->idProp ==
  23. ((LPSPECIAL_PROPERTY_ITEM)pElem2)->idProp) ?
  24. 0 :
  25. ((((LPSPECIAL_PROPERTY_ITEM)pElem1)->idProp >
  26. ((LPSPECIAL_PROPERTY_ITEM)pElem2)->idProp) ?
  27. 1 : -1)
  28. );
  29. }
  30. CSpecialPropertyTable::CSpecialPropertyTable(
  31. LPPTABLE pPropertyTable
  32. )
  33. {
  34. _ASSERT(pPropertyTable);
  35. _ASSERT(pPropertyTable->pProperties);
  36. m_pProperties = pPropertyTable->pProperties;
  37. m_dwProperties = pPropertyTable->dwProperties;
  38. m_fIsSorted = pPropertyTable->fIsSorted;
  39. }
  40. CSpecialPropertyTable::~CSpecialPropertyTable()
  41. {
  42. }
  43. HRESULT CSpecialPropertyTable::GetProperty(
  44. PROP_ID idProp,
  45. LPVOID pContext,
  46. LPVOID pParam,
  47. DWORD ptBaseType,
  48. DWORD cbLength,
  49. DWORD *pcbLength,
  50. LPBYTE pbBuffer,
  51. BOOL fCheckAccess
  52. )
  53. {
  54. HRESULT hrRes = S_OK;
  55. LPSPECIAL_PROPERTY_ITEM pItem;
  56. TraceFunctEnterEx((LPARAM)this, "CSpecialPropertyTable::GetProperty");
  57. if (!pcbLength || !pbBuffer)
  58. return(E_POINTER);
  59. // Find the property
  60. pItem = SearchForProperty(idProp);
  61. // Found?
  62. if (pItem)
  63. {
  64. // Access check if applicable
  65. if (fCheckAccess && !(pItem->fAccess & PA_READ))
  66. hrRes = E_ACCESSDENIED;
  67. else
  68. {
  69. // Check the type
  70. if ((ptBaseType != PT_NONE) &&
  71. (ptBaseType != pItem->ptBaseType))
  72. hrRes = TYPE_E_TYPEMISMATCH;
  73. else
  74. {
  75. // Call the special get accessor
  76. hrRes = pItem->pfnGetAccessor(
  77. idProp,
  78. pContext,
  79. pParam,
  80. cbLength,
  81. pcbLength,
  82. pbBuffer);
  83. }
  84. }
  85. }
  86. else
  87. hrRes = S_FALSE;
  88. TraceFunctLeave();
  89. return(hrRes);
  90. }
  91. HRESULT CSpecialPropertyTable::PutProperty(
  92. PROP_ID idProp,
  93. LPVOID pContext,
  94. LPVOID pParam,
  95. DWORD ptBaseType,
  96. DWORD cbLength,
  97. LPBYTE pbBuffer,
  98. BOOL fCheckAccess
  99. )
  100. {
  101. HRESULT hrRes = S_OK;
  102. LPSPECIAL_PROPERTY_ITEM pItem;
  103. TraceFunctEnterEx((LPARAM)this, "CSpecialPropertyTable::PutProperty");
  104. if (!pbBuffer)
  105. return(E_POINTER);
  106. // Find the property
  107. pItem = SearchForProperty(idProp);
  108. // Found?
  109. if (pItem)
  110. {
  111. // Access check if applicable
  112. if (fCheckAccess && !(pItem->fAccess & PA_WRITE))
  113. hrRes = E_ACCESSDENIED;
  114. else
  115. {
  116. // Check the type
  117. if ((ptBaseType != PT_NONE) &&
  118. (ptBaseType != pItem->ptBaseType))
  119. hrRes = TYPE_E_TYPEMISMATCH;
  120. else
  121. {
  122. // Call the special put accessor
  123. hrRes = pItem->pfnPutAccessor(
  124. idProp,
  125. pContext,
  126. pParam,
  127. cbLength,
  128. pbBuffer);
  129. }
  130. }
  131. }
  132. else
  133. hrRes = S_FALSE;
  134. TraceFunctLeave();
  135. return(hrRes);
  136. }
  137. LPSPECIAL_PROPERTY_ITEM CSpecialPropertyTable::SearchForProperty(
  138. PROP_ID idProp
  139. )
  140. {
  141. LPSPECIAL_PROPERTY_ITEM pItem = NULL;
  142. TraceFunctEnter("CSpecialPropertyTable::SearchForProperty");
  143. // If the table is sorted, we do a bsearch, otherwise we do
  144. // a inear search
  145. if (m_fIsSorted)
  146. {
  147. SPECIAL_PROPERTY_ITEM KeyItem;
  148. DebugTrace(NULL, "Property table is sorted");
  149. // Fill in the property name to look for
  150. KeyItem.idProp = idProp;
  151. // Bsearch
  152. pItem = (LPSPECIAL_PROPERTY_ITEM)bsearch(
  153. &KeyItem,
  154. m_pProperties,
  155. m_dwProperties,
  156. sizeof(SPECIAL_PROPERTY_ITEM),
  157. CompareProperties);
  158. }
  159. else
  160. {
  161. DWORD i;
  162. LPSPECIAL_PROPERTY_ITEM pCurrentItem;
  163. DebugTrace(NULL, "Property table is not sorted");
  164. // Linear search
  165. pItem = NULL;
  166. for (i = 0, pCurrentItem = m_pProperties;
  167. i < m_dwProperties;
  168. i++, pCurrentItem++)
  169. if (pCurrentItem->idProp == idProp)
  170. {
  171. pItem = pCurrentItem;
  172. break;
  173. }
  174. }
  175. TraceFunctLeave();
  176. return(pItem);
  177. }