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.

232 lines
6.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File : prfutil.CXX
  7. //
  8. // Contents : Utility procedures stolen from the VGACTRS code in the DDK
  9. //
  10. // History: 22-Mar-94 t-joshh Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #define DEFINE_STRING
  16. #include "prfutil.hxx"
  17. WCHAR const wcsGlobal[] = L"Global";
  18. WCHAR const wcsForeign[] = L"Foreign";
  19. WCHAR const wcsCostly[] = L"Costly";
  20. QueryType GetQueryType( WCHAR * lpValue )
  21. {
  22. if (lpValue == 0)
  23. return QUERY_GLOBAL;
  24. else if (*lpValue == 0)
  25. return QUERY_GLOBAL;
  26. //
  27. // check for "Global" request
  28. //
  29. unsigned ccValue = wcslen( lpValue ) + 1;
  30. if ( ccValue == sizeof(wcsGlobal)/sizeof(WCHAR) &&
  31. RtlEqualMemory( lpValue, wcsGlobal, sizeof(wcsGlobal) ) )
  32. {
  33. return QUERY_GLOBAL;
  34. }
  35. //
  36. // check for "Foreign" request
  37. //
  38. if ( ccValue == sizeof(wcsForeign)/sizeof(WCHAR) &&
  39. RtlEqualMemory( lpValue, wcsForeign, sizeof(wcsForeign) ) )
  40. {
  41. return QUERY_FOREIGN;
  42. }
  43. //
  44. // check for "Costly" request
  45. //
  46. if ( ccValue == sizeof(wcsCostly)/sizeof(WCHAR) &&
  47. RtlEqualMemory( lpValue, wcsCostly, sizeof(wcsCostly) ) )
  48. {
  49. return QUERY_COSTLY;
  50. }
  51. // if not Global and not Foreign and not Costly,
  52. // then it must be an item list
  53. return QUERY_ITEMS;
  54. }
  55. BOOL
  56. IsNumberInUnicodeList (
  57. IN DWORD dwNumber,
  58. IN LPWSTR lpwszUnicodeList
  59. )
  60. /*++
  61. IsNumberInUnicodeList
  62. Arguments:
  63. IN dwNumber
  64. DWORD number to find in list
  65. IN lpwszUnicodeList
  66. Null terminated, Space delimited list of decimal numbers
  67. Return Value:
  68. TRUE:
  69. dwNumber was found in the list of unicode number strings
  70. FALSE:
  71. dwNumber was not found in the list.
  72. --*/
  73. {
  74. DWORD dwThisNumber;
  75. TCHAR *pwcThisChar;
  76. BOOL bValidNumber;
  77. BOOL bNewItem;
  78. TCHAR wcDelimiter; // could be an argument to be more flexible
  79. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not founde
  80. pwcThisChar = lpwszUnicodeList;
  81. dwThisNumber = 0;
  82. wcDelimiter = TEXT(' ');
  83. bValidNumber = FALSE;
  84. bNewItem = TRUE;
  85. while (TRUE) {
  86. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  87. case DIGIT:
  88. // if this is the first digit after a delimiter, then
  89. // set flags to start computing the new number
  90. if (bNewItem) {
  91. bNewItem = FALSE;
  92. bValidNumber = TRUE;
  93. }
  94. if (bValidNumber) {
  95. dwThisNumber *= 10;
  96. dwThisNumber += (*pwcThisChar - TEXT('0'));
  97. }
  98. break;
  99. case DELIMITER:
  100. // a delimter is either the delimiter character or the
  101. // end of the string ('\0') if when the delimiter has been
  102. // reached a valid number was found, then compare it to the
  103. // number from the argument list. if this is the end of the
  104. // string and no match was found, then return.
  105. //
  106. if (bValidNumber) {
  107. if (dwThisNumber == dwNumber) return TRUE;
  108. bValidNumber = FALSE;
  109. }
  110. if (*pwcThisChar == 0) {
  111. return FALSE;
  112. } else {
  113. bNewItem = TRUE;
  114. dwThisNumber = 0;
  115. }
  116. break;
  117. case INVALID:
  118. // if an invalid character was encountered, ignore all
  119. // characters up to the next delimiter and then start fresh.
  120. // the invalid number is not compared.
  121. bValidNumber = FALSE;
  122. break;
  123. default:
  124. break;
  125. }
  126. pwcThisChar++;
  127. }
  128. } // IsNumberInUnicodeList
  129. BOOL
  130. MonBuildInstanceDefinition(
  131. PERF_INSTANCE_DEFINITION *pBuffer,
  132. PVOID *pBufferNext,
  133. DWORD ParentObjectTitleIndex,
  134. DWORD ParentObjectInstance,
  135. DWORD UniqueID,
  136. PUNICODE_STRING Name
  137. )
  138. /*++
  139. MonBuildInstanceDefinition - Build an instance of an object
  140. Inputs:
  141. pBuffer - pointer to buffer where instance is to
  142. be constructed
  143. pBufferNext - pointer to a pointer which will contain
  144. next available location, DWORD aligned
  145. ParentObjectTitleIndex
  146. - Title Index of parent object type; 0 if
  147. no parent object
  148. ParentObjectInstance
  149. - Index into instances of parent object
  150. type, starting at 0, for this instances
  151. parent object instance
  152. UniqueID - a unique identifier which should be used
  153. instead of the Name for identifying
  154. this instance
  155. Name - Name of this instance
  156. --*/
  157. {
  158. DWORD NameLength;
  159. WCHAR *pName;
  160. //
  161. // Include trailing null in name size
  162. //
  163. NameLength = Name->Length;
  164. if ( !NameLength ||
  165. Name->Buffer[(NameLength/sizeof(WCHAR))-1] != UNICODE_NULL ) {
  166. NameLength += sizeof(WCHAR);
  167. }
  168. pBuffer->ByteLength = sizeof(PERF_INSTANCE_DEFINITION) +
  169. EIGHT_BYTE_MULTIPLE(NameLength);
  170. pBuffer->ParentObjectTitleIndex = ParentObjectTitleIndex;
  171. pBuffer->ParentObjectInstance = ParentObjectInstance;
  172. pBuffer->UniqueID = UniqueID;
  173. pBuffer->NameOffset = sizeof(PERF_INSTANCE_DEFINITION);
  174. pBuffer->NameLength = NameLength;
  175. pName = (PWCHAR)&pBuffer[1];
  176. RtlMoveMemory(pName,Name->Buffer,Name->Length);
  177. // Always null terminated. Space for this reserved above.
  178. pName[(NameLength/sizeof(WCHAR))-1] = UNICODE_NULL;
  179. *pBufferNext = (PVOID) ((PCHAR) pBuffer + pBuffer->ByteLength);
  180. return 0;
  181. }