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.

360 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  4. //
  5. // File: param.hxx
  6. //
  7. // Contents: Used to replace variables in strings
  8. //
  9. // History: 96/Jan/3 DwightKr Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #pragma once
  13. enum
  14. {
  15. eNone = 0x0,
  16. eParameter = 0x1,
  17. eString = 0x2,
  18. eIf = 0x3,
  19. eElse = 0x4,
  20. eEndIf = 0x5,
  21. eEscapeHTML = 0x6,
  22. eEscapeURL = 0x7,
  23. eEscapeRAW = 0x8,
  24. eParamRequiresNonSequentialCursor = 0x00010000, // Can be OR'ed with above
  25. eParamOwnsVariantMemory = 0x00100000,
  26. eParamDeferredValue = 0x00200000, // obtain when asked
  27. };
  28. const ULONG eJustParamMask = 0x0000ffff;
  29. const ULONG eParamMask = 0x0001FFFF;
  30. //
  31. // These are the parameters that are available in all HTX pages.
  32. //
  33. extern const WCHAR * ISAPI_CI_BOOKMARK;
  34. extern const WCHAR * ISAPI_CI_BOOKMARK_SKIP_COUNT;
  35. extern const WCHAR * ISAPI_CI_BOOL_VECTOR_PREFIX;
  36. extern const WCHAR * ISAPI_CI_BOOL_VECTOR_SEPARATOR;
  37. extern const WCHAR * ISAPI_CI_BOOL_VECTOR_SUFFIX;
  38. extern const WCHAR * ISAPI_CI_CATALOG;
  39. extern const WCHAR * ISAPI_CI_CODEPAGE;
  40. extern const char * ISAPI_CI_CODEPAGE_A;
  41. extern const WCHAR * ISAPI_CI_COLUMNS;
  42. extern const WCHAR * ISAPI_CI_CONTAINS_FIRST_RECORD;
  43. extern const WCHAR * ISAPI_CI_CONTAINS_LAST_RECORD;
  44. extern const WCHAR * ISAPI_CI_CURRENCY_VECTOR_PREFIX;
  45. extern const WCHAR * ISAPI_CI_CURRENCY_VECTOR_SEPARATOR;
  46. extern const WCHAR * ISAPI_CI_CURRENCY_VECTOR_SUFFIX;
  47. extern const WCHAR * ISAPI_CI_CURRENT_PAGE_NUMBER;
  48. extern const WCHAR * ISAPI_CI_CURRENT_RECORD_NUMBER;
  49. extern const WCHAR * ISAPI_CI_DATE_VECTOR_PREFIX;
  50. extern const WCHAR * ISAPI_CI_DATE_VECTOR_SEPARATOR;
  51. extern const WCHAR * ISAPI_CI_DATE_VECTOR_SUFFIX;
  52. extern const WCHAR * ISAPI_CI_DONT_TIMEOUT;
  53. extern const WCHAR * ISAPI_CI_ERROR_MESSAGE;
  54. extern const WCHAR * ISAPI_CI_ERROR_NUMBER;
  55. extern const WCHAR * ISAPI_CI_FIRST_RECORD_NUMBER;
  56. extern const WCHAR * ISAPI_CI_FORCE_USE_CI;
  57. extern const WCHAR * ISAPI_CI_DEFER_NONINDEXED_TRIMMING;
  58. extern const WCHAR * ISAPI_CI_DIALECT;
  59. extern const WCHAR * ISAPI_CI_FLAGS;
  60. extern const WCHAR * ISAPI_CI_LAST_RECORD_NUMBER;
  61. extern const WCHAR * ISAPI_CI_LOCALE;
  62. extern const WCHAR * ISAPI_CI_MATCHED_RECORD_COUNT;
  63. extern const WCHAR * ISAPI_CI_MAX_RECORDS_IN_RESULTSET;
  64. extern const WCHAR * ISAPI_CI_MAX_RECORDS_PER_PAGE;
  65. extern const WCHAR * ISAPI_CI_FIRST_ROWS_IN_RESULTSET;
  66. extern const WCHAR * ISAPI_CI_NUMBER_VECTOR_PREFIX;
  67. extern const WCHAR * ISAPI_CI_NUMBER_VECTOR_SEPARATOR;
  68. extern const WCHAR * ISAPI_CI_NUMBER_VECTOR_SUFFIX;
  69. extern const WCHAR * ISAPI_CI_OUT_OF_DATE;
  70. extern const WCHAR * ISAPI_CI_QUERY_INCOMPLETE;
  71. extern const WCHAR * ISAPI_CI_QUERY_TIMEDOUT;
  72. extern const WCHAR * ISAPI_CI_QUERY_DATE;
  73. extern const WCHAR * ISAPI_CI_QUERY_TIME;
  74. extern const WCHAR * ISAPI_CI_QUERY_TIMEZONE;
  75. extern const WCHAR * ISAPI_CI_RESTRICTION;
  76. extern const WCHAR * ISAPI_CI_RECORDS_NEXT_PAGE;
  77. extern const WCHAR * ISAPI_CI_SCOPE;
  78. extern const WCHAR * ISAPI_CI_SORT;
  79. extern const WCHAR * ISAPI_CI_STRING_VECTOR_PREFIX;
  80. extern const WCHAR * ISAPI_CI_STRING_VECTOR_SEPARATOR;
  81. extern const WCHAR * ISAPI_CI_STRING_VECTOR_SUFFIX;
  82. extern const WCHAR * ISAPI_CI_TEMPLATE;
  83. extern const WCHAR * ISAPI_CI_TOTAL_NUMBER_PAGES;
  84. extern const WCHAR * ISAPI_CI_ADMIN_OPERATION;
  85. extern const WCHAR * ISAPI_CI_CANONICAL_OUTPUT;
  86. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_WORDLISTS;
  87. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_PERSINDEX;
  88. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_QUERIES;
  89. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_FRESHTEST;
  90. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_UNIQUE;
  91. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_TOFILTER;
  92. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_FILTERED;
  93. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_PENDINGSCANS;
  94. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_COUNT_TOTAL;
  95. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_SIZE;
  96. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_MERGE_PROGRESS;
  97. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_SHADOWMERGE;
  98. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_MASTERMERGE;
  99. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_ANNEALINGMERGE;
  100. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_SCANREQUIRED;
  101. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_SCANNING;
  102. extern const WCHAR * ISAPI_CI_ADMIN_INDEX_STATE_RECOVERING;
  103. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_HITS;
  104. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_MISSES;
  105. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_ACTIVE;
  106. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_COUNT;
  107. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_PENDING;
  108. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_REJECTED;
  109. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_TOTAL;
  110. extern const WCHAR * ISAPI_CI_ADMIN_CACHE_QPM;
  111. extern const WCHAR * ISAPI_ALL_HTTP;
  112. extern const WCHAR * ISAPI_AUTH_TYPE;
  113. extern const WCHAR * ISAPI_CONTENT_LENGTH;
  114. extern const WCHAR * ISAPI_CONTENT_TYPE;
  115. extern const WCHAR * ISAPI_GATEWAY_INTERFACE;
  116. extern const WCHAR * ISAPI_HTTP_ACCEPT;
  117. extern const WCHAR * ISAPI_HTTP_ACCEPT_LANGUAGE;
  118. extern const WCHAR * ISAPI_HTTP_COOKIE;
  119. extern const WCHAR * ISAPI_HTTP_CONNECTION;
  120. extern const WCHAR * ISAPI_HTTP_CONTENT_TYPE;
  121. extern const WCHAR * ISAPI_HTTP_CONTENT_LENGTH;
  122. extern const WCHAR * ISAPI_HTTP_PRAGMA;
  123. extern const WCHAR * ISAPI_HTTP_REFERER;
  124. extern const WCHAR * ISAPI_HTTP_USER_AGENT;
  125. extern const WCHAR * ISAPI_PATH_INFO;
  126. extern const WCHAR * ISAPI_PATH_TRANSLATED;
  127. extern const WCHAR * ISAPI_QUERY_STRING;
  128. extern const WCHAR * ISAPI_REMOTE_ADDR;
  129. extern const WCHAR * ISAPI_REMOTE_HOST;
  130. extern const WCHAR * ISAPI_REMOTE_USER;
  131. extern const WCHAR * ISAPI_REQUEST_METHOD;
  132. extern const WCHAR * ISAPI_SCRIPT_NAME;
  133. extern const WCHAR * ISAPI_SERVER_NAME;
  134. extern const WCHAR * ISAPI_SERVER_PORT;
  135. extern const WCHAR * ISAPI_SERVER_PROTOCOL;
  136. extern const WCHAR * ISAPI_SERVER_SOFTWARE;
  137. class CParameterNodeIter;
  138. class CHTXScanner;
  139. class CVirtualString;
  140. struct tagCiGlobalVars
  141. {
  142. const WCHAR * wcsVariableName;
  143. VARTYPE vt;
  144. _int64 i64DefaultValue;
  145. int flags;
  146. };
  147. extern const struct tagCiGlobalVars aCiGlobalVars[];
  148. extern const unsigned cCiGlobalVars;
  149. extern const struct tagCiGlobalVars aISAPIGlobalVars[];
  150. extern const unsigned cISAPIGlobalVars;
  151. extern const WCHAR * aISAPI_CiParams[];
  152. extern const unsigned cISAPI_CiParams;
  153. //+---------------------------------------------------------------------------
  154. //
  155. // Class: CParameterNode
  156. //
  157. // Purpose: Contains information for a single node in a expression tree
  158. //
  159. // History: 96/Jan/23 DwightKr Created
  160. //
  161. //----------------------------------------------------------------------------
  162. class CParameterNode
  163. {
  164. friend class CParameterNodeIter;
  165. public:
  166. CParameterNode( WCHAR * ptr, ULONG eType = 0 ) :
  167. _ptr(ptr),
  168. _eType(eType),
  169. _pTrueNode(0),
  170. _pFalseNode(0),
  171. _cRefCount(1),
  172. _cwcString(0)
  173. {
  174. _ulHash = ISAPIVariableNameHash( ptr );
  175. END_CONSTRUCTION( CParameterNode );
  176. }
  177. ~CParameterNode();
  178. WCHAR const * String() const { return _ptr; }
  179. ULONG Hash() const { return _ulHash; }
  180. ULONG Type() const { return _eType; }
  181. ULONG Length()
  182. {
  183. if ( 0 == _cwcString )
  184. _cwcString = wcslen( _ptr );
  185. return _cwcString;
  186. }
  187. void SetNextNode( CParameterNode * pNext ) { _pTrueNode = pNext; }
  188. void SetTrueNode( CParameterNode * pTrueNode ) { SetNextNode( pTrueNode ); }
  189. void SetFalseNode( CParameterNode * pFalseNode ) { _pFalseNode = pFalseNode; }
  190. CParameterNode * GetNextNode() const { return _pTrueNode; }
  191. CParameterNode * GetTrueNode() const { return GetNextNode(); }
  192. CParameterNode * GetFalseNode() const { return _pFalseNode; }
  193. CParameterNode * GetEndNode()
  194. {
  195. CParameterNode *pEndNode = this;
  196. while ( 0 != pEndNode->GetNextNode() )
  197. {
  198. pEndNode = pEndNode->GetNextNode();
  199. }
  200. return pEndNode;
  201. }
  202. CParameterNode * QueryNextNode() { return QueryTrueNode(); }
  203. CParameterNode * QueryTrueNode()
  204. {
  205. CParameterNode * pTrueNode = _pTrueNode;
  206. _pTrueNode = 0;
  207. return pTrueNode;
  208. }
  209. CParameterNode * QueryFalseNode()
  210. {
  211. CParameterNode * pFalseNode = _pFalseNode;
  212. _pFalseNode = 0;
  213. return pFalseNode;
  214. }
  215. BOOL IsEmpty() const { return 0 == GetNextNode(); }
  216. ULONG GetRefCount() const { return _cRefCount; }
  217. void IncrementRefCount() { _cRefCount++; }
  218. void DecrementRefCount() { _cRefCount--; }
  219. private:
  220. ULONG _cRefCount; // # nodes pointing to this one
  221. ULONG _eType; // Type of node
  222. WCHAR * _ptr; // Ptr to string associated with node
  223. ULONG _ulHash; // Hash associated with node
  224. CParameterNode * _pTrueNode; // Node to follow if node evalutes TRUE
  225. CParameterNode * _pFalseNode; // Node to follow if FALSE
  226. ULONG _cwcString; // length of the string _ptr
  227. };
  228. //+---------------------------------------------------------------------------
  229. //
  230. // Class: CParameterNodeIter
  231. //
  232. // Purpose: Iterates over an CParaemterNode tree, following either the
  233. // TRUE or FALSE branches of the 'if' statements.
  234. //
  235. // History: 96/Jan/23 DwightKr Created
  236. //
  237. //----------------------------------------------------------------------------
  238. class CParameterNodeIter
  239. {
  240. public:
  241. CParameterNodeIter( CParameterNode * pNode,
  242. CVariableSet & variableSet,
  243. COutputFormat & outputFormat );
  244. void Next()
  245. {
  246. Win4Assert( !AtEnd() );
  247. if ( eIf == _root->Type() )
  248. {
  249. //
  250. // Evaluate the expression at the IF node to determine which
  251. // is the next node.
  252. //
  253. if ( EvaluateExpression( _root->String() ) )
  254. _root = _root->GetTrueNode();
  255. else
  256. _root = _root->GetFalseNode();
  257. }
  258. else
  259. {
  260. _root = _root->GetNextNode();
  261. }
  262. }
  263. BOOL AtEnd() const { return 0 == _root; }
  264. CParameterNode * Get() { return _root; }
  265. private:
  266. BOOL EvaluateExpression( WCHAR const * wcsCondition );
  267. CParameterNode * _root; // Root of the parameter tree
  268. CVariableSet & _variableSet; // Set of vars to evaluate if's
  269. COutputFormat & _outputFormat; // Format of #'s & dates
  270. };
  271. //+---------------------------------------------------------------------------
  272. //
  273. // Class: CParameterReplacer
  274. //
  275. // Purpose: Given a string, and a pair of delimiting tokens, this class
  276. // parses the string to identify the replaceable parameters
  277. // enclosed by the delimiting tokens. It then builds a new
  278. // string replacing the parameters with their actual values.
  279. //
  280. // History: 96/Jan/23 DwightKr Created
  281. //
  282. //----------------------------------------------------------------------------
  283. class CParameterReplacer
  284. {
  285. public:
  286. CParameterReplacer( WCHAR const * wcsString,
  287. WCHAR const * wcsPrefix,
  288. WCHAR const * wcsSuffix );
  289. ~CParameterReplacer()
  290. {
  291. delete _wcsString;
  292. }
  293. void ParseString( CVariableSet & variableSet );
  294. void ReplaceParams( CVirtualString & strResult,
  295. CVariableSet & variableSet,
  296. COutputFormat & outputFormat );
  297. ULONG GetFlags() const { return _ulFlags; }
  298. private:
  299. void BuildTree( CHTXScanner & scanner,
  300. CParameterNode *pBranch,
  301. CDynStackInPlace<ULONG> & ifStack );
  302. WCHAR * _wcsString; // The string we've parsed
  303. WCHAR const * _wcsPrefix; // Deliminating prefix
  304. WCHAR const * _wcsSuffix; // Deliminating suffix
  305. ULONG _ulFlags; // Flags associated with replaced variables
  306. CParameterNode _paramNode; // Tree of ptrs to replaceable params
  307. };