Source code of Windows XP (NT5)
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.

250 lines
5.2 KiB

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