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.

261 lines
6.2 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. perfutil.c
  5. Abstract:
  6. This file implements the utility routines used to construct the
  7. common parts of a PERF_INSTANCE_DEFINITION (see winperf.h) and
  8. perform event logging functions.
  9. Created:
  10. Russ Blake 07/30/92
  11. Revision History:
  12. Jing Chen 07/98
  13. --*/
  14. //
  15. // include files
  16. //
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <rpc.h>
  22. #include <winperf.h>
  23. #include "perfconfig.h"
  24. #include "perfutil.h"
  25. #define INITIAL_SIZE 1024L
  26. #define EXTEND_SIZE 1024L
  27. //
  28. // Global data definitions.
  29. //
  30. WCHAR GLOBAL_STRING[] = L"Global";
  31. WCHAR FOREIGN_STRING[] = L"Foreign";
  32. WCHAR COSTLY_STRING[] = L"Costly";
  33. WCHAR NULL_STRING[] = L"\0"; // pointer to null string
  34. // test for delimiter, end of line and non-digit characters
  35. // used by IsNumberInUnicodeList routine
  36. //
  37. #define DIGIT 1
  38. #define DELIMITER 2
  39. #define INVALID 3
  40. #define EvalThisChar(c,d) ( \
  41. (c == d) ? DELIMITER : \
  42. (c == 0) ? DELIMITER : \
  43. (c < (WCHAR)'0') ? INVALID : \
  44. (c > (WCHAR)'9') ? INVALID : \
  45. DIGIT)
  46. DWORD
  47. GetQueryType (
  48. IN LPWSTR lpValue
  49. )
  50. /*++
  51. GetQueryType
  52. returns the type of query described in the lpValue string so that
  53. the appropriate processing method may be used
  54. Arguments
  55. IN lpValue
  56. string passed to PerfRegQuery Value for processing
  57. Return Value
  58. QUERY_GLOBAL
  59. if lpValue == 0 (null pointer)
  60. lpValue == pointer to Null string
  61. lpValue == pointer to "Global" string
  62. QUERY_FOREIGN
  63. if lpValue == pointer to "Foriegn" string
  64. QUERY_COSTLY
  65. if lpValue == pointer to "Costly" string
  66. otherwise:
  67. QUERY_ITEMS
  68. --*/
  69. {
  70. WCHAR *pwcArgChar, *pwcTypeChar;
  71. BOOL bFound;
  72. if (lpValue == 0) {
  73. return QUERY_GLOBAL;
  74. } else if (*lpValue == 0) {
  75. return QUERY_GLOBAL;
  76. }
  77. // check for "Global" request
  78. pwcArgChar = lpValue;
  79. pwcTypeChar = GLOBAL_STRING;
  80. bFound = TRUE; // assume found until contradicted
  81. // check to the length of the shortest string
  82. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  83. if (*pwcArgChar++ != *pwcTypeChar++) {
  84. bFound = FALSE; // no match
  85. break; // bail out now
  86. }
  87. }
  88. if (bFound) return QUERY_GLOBAL;
  89. // check for "Foreign" request
  90. pwcArgChar = lpValue;
  91. pwcTypeChar = FOREIGN_STRING;
  92. bFound = TRUE; // assume found until contradicted
  93. // check to the length of the shortest string
  94. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  95. if (*pwcArgChar++ != *pwcTypeChar++) {
  96. bFound = FALSE; // no match
  97. break; // bail out now
  98. }
  99. }
  100. if (bFound) return QUERY_FOREIGN;
  101. // check for "Costly" request
  102. pwcArgChar = lpValue;
  103. pwcTypeChar = COSTLY_STRING;
  104. bFound = TRUE; // assume found until contradicted
  105. // check to the length of the shortest string
  106. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  107. if (*pwcArgChar++ != *pwcTypeChar++) {
  108. bFound = FALSE; // no match
  109. break; // bail out now
  110. }
  111. }
  112. if (bFound) return QUERY_COSTLY;
  113. // if not Global and not Foreign and not Costly,
  114. // then it must be an item list
  115. return QUERY_ITEMS;
  116. }
  117. BOOL
  118. IsNumberInUnicodeList (
  119. IN DWORD dwNumber,
  120. IN LPWSTR lpwszUnicodeList
  121. )
  122. /*++
  123. IsNumberInUnicodeList
  124. Arguments:
  125. IN dwNumber
  126. DWORD number to find in list
  127. IN lpwszUnicodeList
  128. Null terminated, Space delimited list of decimal numbers
  129. Return Value:
  130. TRUE:
  131. dwNumber was found in the list of unicode number strings
  132. FALSE:
  133. dwNumber was not found in the list.
  134. --*/
  135. {
  136. DWORD dwThisNumber;
  137. WCHAR *pwcThisChar;
  138. BOOL bValidNumber;
  139. BOOL bNewItem;
  140. WCHAR wcDelimiter; // could be an argument to be more flexible
  141. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not founde
  142. pwcThisChar = lpwszUnicodeList;
  143. dwThisNumber = 0;
  144. wcDelimiter = (WCHAR)' ';
  145. bValidNumber = FALSE;
  146. bNewItem = TRUE;
  147. while (TRUE) {
  148. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  149. case DIGIT:
  150. // if this is the first digit after a delimiter, then
  151. // set flags to start computing the new number
  152. if (bNewItem) {
  153. bNewItem = FALSE;
  154. bValidNumber = TRUE;
  155. }
  156. if (bValidNumber) {
  157. dwThisNumber *= 10;
  158. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  159. }
  160. break;
  161. case DELIMITER:
  162. // a delimter is either the delimiter character or the
  163. // end of the string ('\0') if when the delimiter has been
  164. // reached a valid number was found, then compare it to the
  165. // number from the argument list. if this is the end of the
  166. // string and no match was found, then return.
  167. //
  168. if (bValidNumber) {
  169. if (dwThisNumber == dwNumber) return TRUE;
  170. bValidNumber = FALSE;
  171. }
  172. if (*pwcThisChar == 0) {
  173. return FALSE;
  174. } else {
  175. bNewItem = TRUE;
  176. dwThisNumber = 0;
  177. }
  178. break;
  179. case INVALID:
  180. // if an invalid character was encountered, ignore all
  181. // characters up to the next delimiter and then start fresh.
  182. // the invalid number is not compared.
  183. bValidNumber = FALSE;
  184. break;
  185. default:
  186. break;
  187. }
  188. pwcThisChar++;
  189. }
  190. } // IsNumberInUnicodeList