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.

310 lines
8.6 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. QL.H
  5. Abstract:
  6. Level 1 Syntax QL Parser
  7. Implements the syntax described in QL.BNF. This translates the input
  8. into an RPN stream of tokens.
  9. History:
  10. a-raymcc, a-tomasp 21-Jun-96 Created.
  11. --*/
  12. #ifndef _QL__H_
  13. #define _QL__H_
  14. #include <wbemidl.h>
  15. #include <wbemint.h>
  16. #include <qllex.h>
  17. #include <corepol.h>
  18. #include <parmdefs.h>
  19. #include <stdio.h>
  20. class POLARITY CPropertyName : public WBEM_PROPERTY_NAME
  21. {
  22. protected:
  23. long m_lAllocated;
  24. void* m_pvHandle;
  25. void EnsureAllocated(long lElements);
  26. public:
  27. void Init();
  28. CPropertyName() {Init();}
  29. CPropertyName(const CPropertyName& Other);
  30. void operator=(const CPropertyName& Other);
  31. void operator=(const WBEM_PROPERTY_NAME& Other);
  32. BOOL operator==(const WBEM_PROPERTY_NAME& Other);
  33. void Empty();
  34. ~CPropertyName() {Empty();}
  35. long GetNumElements() const {return m_lNumElements;}
  36. LPCWSTR GetStringAt(long lIndex) const;
  37. void AddElement(LPCWSTR wszElement);
  38. DELETE_ME LPWSTR GetText();
  39. //
  40. // for convienience, a prop handle can be stored with this struct. example
  41. // of such a handle is the one used for fast access to properties on wbem
  42. // class objects. The handle is not used in any way by this implementation
  43. // but will be treated as a regular member var in that it will be nulled,
  44. // copied, etc..
  45. //
  46. void* GetHandle() { return m_pvHandle; }
  47. void SetHandle( void* pvHandle ) { m_pvHandle = pvHandle; }
  48. };
  49. class POLARITY CQl1ParseSink
  50. {
  51. public:
  52. virtual void SetClassName(LPCWSTR wszClass) = 0;
  53. virtual void SetTolerance(const WBEM_QL1_TOLERANCE& Tolerance) = 0;
  54. virtual void AddToken(const WBEM_QL1_TOKEN& Token) = 0;
  55. virtual void AddProperty(const CPropertyName& Property) = 0;
  56. virtual void AddAllProperties() = 0;
  57. virtual void SetCountQuery() = 0;
  58. virtual void SetAggregated() = 0;
  59. virtual void SetAggregationTolerance(const WBEM_QL1_TOLERANCE& Tolerance)= 0;
  60. virtual void AddAggregationProperty(const CPropertyName& Property) = 0;
  61. virtual void AddAllAggregationProperties() = 0;
  62. virtual void AddHavingToken(const WBEM_QL1_TOKEN& Token) = 0;
  63. virtual void InOrder(long lOp){}
  64. };
  65. class POLARITY CAbstractQl1Parser
  66. {
  67. protected:
  68. // Controls keyword parsing in Next().
  69. // ===================================
  70. enum {
  71. NO_KEYWORDS = 0,
  72. ALL_KEYWORDS,
  73. EXCLUDE_GROUP_KEYWORD,
  74. EXCLUDE_EXPRESSION_KEYWORDS
  75. };
  76. CQl1ParseSink* m_pSink;
  77. CGenLexer *m_pLexer;
  78. int m_nLine;
  79. wchar_t* m_pTokenText;
  80. int m_nCurrentToken;
  81. // Semantic transfer variables.
  82. // ============================
  83. VARIANT m_vTypedConst;
  84. BOOL m_bQuoted;
  85. int m_nRelOp;
  86. DWORD m_dwConstFunction;
  87. DWORD m_dwPropFunction;
  88. CPropertyName m_PropertyName;
  89. BOOL m_bInAggregation;
  90. CPropertyName m_PropertyName2;
  91. BOOL m_bPropComp;
  92. // Parsing functions.
  93. // ==================
  94. virtual BOOL Next(int nFlags = ALL_KEYWORDS);
  95. LPCWSTR GetSinglePropertyName();
  96. void DeletePropertyName();
  97. int FlipOperator(int nOp);
  98. void AddAppropriateToken(const WBEM_QL1_TOKEN& Token);
  99. int parse_property_name(CPropertyName& Prop);
  100. int parse(int nFlags);
  101. int prop_list();
  102. int class_name();
  103. int tolerance();
  104. int opt_where();
  105. int expr();
  106. int property_name();
  107. int prop_list_2();
  108. int term();
  109. int expr2();
  110. int simple_expr();
  111. int term2();
  112. int leading_ident_expr();
  113. int finalize();
  114. int rel_operator();
  115. int equiv_operator();
  116. int comp_operator();
  117. int is_operator();
  118. int trailing_prop_expr();
  119. int trailing_prop_expr2();
  120. int trailing_or_null();
  121. int trailing_const_expr();
  122. int trailing_ident_expr();
  123. int unknown_func_expr();
  124. int typed_constant();
  125. int opt_aggregation();
  126. int aggregation_params();
  127. int aggregate_by();
  128. int aggregate_within();
  129. int opt_having();
  130. static DWORD TranslateIntrinsic(LPCWSTR pFuncName);
  131. static void InitToken(WBEM_QL1_TOKEN* pToken);
  132. public:
  133. enum {
  134. SUCCESS = 0,
  135. SYNTAX_ERROR,
  136. LEXICAL_ERROR,
  137. FAILED,
  138. BUFFER_TOO_SMALL,
  139. OUT_OF_MEMORY
  140. };
  141. enum {
  142. FULL_PARSE = 0,
  143. NO_WHERE,
  144. JUST_WHERE
  145. };
  146. CAbstractQl1Parser(CGenLexSource *pSrc);
  147. virtual ~CAbstractQl1Parser();
  148. int Parse(CQl1ParseSink* pSink, int nFlags);
  149. int CurrentLine() { return m_nLine; }
  150. LPWSTR CurrentToken() { return m_pTokenText; }
  151. };
  152. struct POLARITY QL_LEVEL_1_TOKEN
  153. {
  154. enum
  155. {
  156. OP_EXPRESSION = QL1_OP_EXPRESSION,
  157. TOKEN_AND = QL1_AND,
  158. TOKEN_OR = QL1_OR,
  159. TOKEN_NOT = QL1_NOT
  160. };
  161. enum
  162. {
  163. IFUNC_NONE = QL1_FUNCTION_NONE,
  164. IFUNC_UPPER = QL1_FUNCTION_UPPER,
  165. IFUNC_LOWER = QL1_FUNCTION_LOWER
  166. };
  167. // If the field is a OP_EXPRESSION, then the following are used.
  168. enum
  169. {
  170. OP_EQUAL = QL1_OPERATOR_EQUALS,
  171. OP_NOT_EQUAL = QL1_OPERATOR_NOTEQUALS,
  172. OP_EQUALorGREATERTHAN = QL1_OPERATOR_GREATEROREQUALS,
  173. OP_EQUALorLESSTHAN = QL1_OPERATOR_LESSOREQUALS,
  174. OP_LESSTHAN = QL1_OPERATOR_LESS,
  175. OP_GREATERTHAN = QL1_OPERATOR_GREATER,
  176. OP_LIKE = QL1_OPERATOR_LIKE,
  177. OP_UNLIKE = QL1_OPERATOR_UNLIKE
  178. };
  179. int nTokenType; // OP_EXPRESSION,TOKEN_AND, TOKEN_OR, TOKEN_NOT
  180. CPropertyName PropertyName;
  181. // Name of the property on which the operator is applied
  182. int nOperator; // Operator that is applied on property
  183. VARIANT vConstValue; // Value applied by operator
  184. BOOL bQuoted; // FALSE if the string should not have quotes around it.
  185. CPropertyName PropertyName2; // Property to compare, if applicable.
  186. BOOL m_bPropComp; // TRUE if this is a property-to-property compare.
  187. DWORD dwPropertyFunction; // 0=no instrinsic function applied
  188. DWORD dwConstFunction; // "
  189. QL_LEVEL_1_TOKEN();
  190. QL_LEVEL_1_TOKEN(const QL_LEVEL_1_TOKEN&);
  191. ~QL_LEVEL_1_TOKEN();
  192. QL_LEVEL_1_TOKEN& operator=(const QL_LEVEL_1_TOKEN &Src);
  193. QL_LEVEL_1_TOKEN& operator=(const WBEM_QL1_TOKEN &Src);
  194. void Dump(FILE *);
  195. DELETE_ME LPWSTR GetText();
  196. };
  197. // Contains RPN version of expression.
  198. // ===================================
  199. struct POLARITY QL_LEVEL_1_RPN_EXPRESSION : public CQl1ParseSink
  200. {
  201. int nNumTokens;
  202. int nCurSize;
  203. QL_LEVEL_1_TOKEN *pArrayOfTokens;
  204. BSTR bsClassName;
  205. WBEM_QL1_TOLERANCE Tolerance;
  206. int nNumberOfProperties; // Zero means all properties selected
  207. int nCurPropSize;
  208. BOOL bStar;
  209. CPropertyName *pRequestedPropertyNames;
  210. // Array of property names which values are to be returned if
  211. BOOL bAggregated;
  212. BOOL bCount;
  213. WBEM_QL1_TOLERANCE AggregationTolerance;
  214. BOOL bAggregateAll;
  215. int nNumAggregatedProperties;
  216. int nCurAggPropSize;
  217. CPropertyName *pAggregatedPropertyNames;
  218. int nNumHavingTokens;
  219. int nCurHavingSize;
  220. QL_LEVEL_1_TOKEN *pArrayOfHavingTokens;
  221. long lRefCount;
  222. QL_LEVEL_1_RPN_EXPRESSION();
  223. QL_LEVEL_1_RPN_EXPRESSION(const QL_LEVEL_1_RPN_EXPRESSION& Other);
  224. ~QL_LEVEL_1_RPN_EXPRESSION();
  225. void AddRef();
  226. void Release();
  227. void SetClassName(LPCWSTR wszName);
  228. void SetTolerance(const WBEM_QL1_TOLERANCE& Tolerance);
  229. void AddToken(const WBEM_QL1_TOKEN& Tok);
  230. void AddToken(const QL_LEVEL_1_TOKEN& Tok);
  231. void AddProperty(const CPropertyName& Prop);
  232. void AddAllProperties();
  233. void SetCountQuery();
  234. void SetAggregated();
  235. void SetAggregationTolerance(const WBEM_QL1_TOLERANCE& Tolerance);
  236. void AddAggregationProperty(const CPropertyName& Property);
  237. void AddAllAggregationProperties();
  238. void AddHavingToken(const WBEM_QL1_TOKEN& Tok);
  239. void Dump(const char *pszTextFile);
  240. DELETE_ME LPWSTR GetText();
  241. };
  242. class POLARITY QL1_Parser : public CAbstractQl1Parser
  243. {
  244. QL_LEVEL_1_RPN_EXPRESSION* m_pExpression;
  245. BOOL m_bPartiallyParsed;
  246. public:
  247. QL1_Parser(CGenLexSource *pSrc);
  248. ~QL1_Parser();
  249. int GetQueryClass(LPWSTR pBuf, int nBufSize);
  250. int Parse(QL_LEVEL_1_RPN_EXPRESSION **pOutput);
  251. static LPWSTR ReplaceClassName(QL_LEVEL_1_RPN_EXPRESSION* pExpr,
  252. LPCWSTR wszClassName);
  253. };
  254. #endif