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.

270 lines
6.5 KiB

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