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.

186 lines
5.0 KiB

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <winperf.h>
  4. #include "PerfUtils.h"
  5. WCHAR GLOBAL_STRING[] = L"Global";
  6. WCHAR FOREIGN_STRING[] = L"Foreign";
  7. WCHAR COSTLY_STRING[] = L"Costly";
  8. //-------------------------------------------------------------
  9. //
  10. // helper functions pinched from MSDN
  11. //
  12. //-------------------------------------------------------------
  13. BOOL IsNumberInUnicodeList (
  14. IN DWORD dwNumber,
  15. IN LPWSTR lpwszUnicodeList
  16. )
  17. {
  18. DWORD dwThisNumber;
  19. WCHAR *pwcThisChar;
  20. BOOL bValidNumber;
  21. BOOL bNewItem;
  22. WCHAR wcDelimiter; // could be an argument to be more flexible
  23. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not founde
  24. pwcThisChar = lpwszUnicodeList;
  25. dwThisNumber = 0;
  26. wcDelimiter = (WCHAR)' ';
  27. bValidNumber = FALSE;
  28. bNewItem = TRUE;
  29. while (TRUE) {
  30. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  31. case DIGIT:
  32. // if this is the first digit after a delimiter, then
  33. // set flags to start computing the new number
  34. if (bNewItem) {
  35. bNewItem = FALSE;
  36. bValidNumber = TRUE;
  37. }
  38. if (bValidNumber) {
  39. dwThisNumber *= 10;
  40. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  41. }
  42. break;
  43. case DELIMITER:
  44. // a delimter is either the delimiter character or the
  45. // end of the string ('\0') if when the delimiter has been
  46. // reached a valid number was found, then compare it to the
  47. // number from the argument list. if this is the end of the
  48. // string and no match was found, then return.
  49. //
  50. if (bValidNumber) {
  51. if (dwThisNumber == dwNumber) return TRUE;
  52. bValidNumber = FALSE;
  53. }
  54. if (*pwcThisChar == 0) {
  55. return FALSE;
  56. } else {
  57. bNewItem = TRUE;
  58. dwThisNumber = 0;
  59. }
  60. break;
  61. case INVALID:
  62. // if an invalid character was encountered, ignore all
  63. // characters up to the next delimiter and then start fresh.
  64. // the invalid number is not compared.
  65. bValidNumber = FALSE;
  66. break;
  67. default:
  68. break;
  69. }
  70. pwcThisChar++;
  71. }
  72. return FALSE;
  73. } // IsNumberInUnicodeList
  74. DWORD GetQueryType (IN LPWSTR lpValue)
  75. /*++
  76. GetQueryType
  77. returns the type of query described in the lpValue string so that
  78. the appropriate processing method may be used
  79. Arguments
  80. IN lpValue
  81. string passed to PerfRegQuery Value for processing
  82. Return Value
  83. QUERY_GLOBAL
  84. if lpValue == 0 (null pointer)
  85. lpValue == pointer to Null string
  86. lpValue == pointer to "Global" string
  87. QUERY_FOREIGN
  88. if lpValue == pointer to "Foriegn" string
  89. QUERY_COSTLY
  90. if lpValue == pointer to "Costly" string
  91. otherwise:
  92. QUERY_ITEMS
  93. --*/
  94. {
  95. WCHAR *pwcArgChar, *pwcTypeChar;
  96. BOOL bFound;
  97. if (lpValue == 0) {
  98. return QUERY_GLOBAL;
  99. } else if (*lpValue == 0) {
  100. return QUERY_GLOBAL;
  101. }
  102. // check for "Global" request
  103. pwcArgChar = lpValue;
  104. pwcTypeChar = GLOBAL_STRING;
  105. bFound = TRUE; // assume found until contradicted
  106. // check to the length of the shortest string
  107. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  108. if (*pwcArgChar++ != *pwcTypeChar++) {
  109. bFound = FALSE; // no match
  110. break; // bail out now
  111. }
  112. }
  113. if (bFound) return QUERY_GLOBAL;
  114. // check for "Foreign" request
  115. pwcArgChar = lpValue;
  116. pwcTypeChar = FOREIGN_STRING;
  117. bFound = TRUE; // assume found until contradicted
  118. // check to the length of the shortest string
  119. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  120. if (*pwcArgChar++ != *pwcTypeChar++) {
  121. bFound = FALSE; // no match
  122. break; // bail out now
  123. }
  124. }
  125. if (bFound) return QUERY_FOREIGN;
  126. // check for "Costly" request
  127. pwcArgChar = lpValue;
  128. pwcTypeChar = COSTLY_STRING;
  129. bFound = TRUE; // assume found until contradicted
  130. // check to the length of the shortest string
  131. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  132. if (*pwcArgChar++ != *pwcTypeChar++) {
  133. bFound = FALSE; // no match
  134. break; // bail out now
  135. }
  136. }
  137. if (bFound) return QUERY_COSTLY;
  138. // if not Global and not Foreign and not Costly,
  139. // then it must be an item list
  140. return QUERY_ITEMS;
  141. }