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.

351 lines
12 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : ParserEngine.h
  4. Project Name : WMI Command Line
  5. Author Name : Ch.Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Brief Description : This file consist of class declaration of class
  9. CParserEngine.
  10. Revision History :
  11. Last Modified By : Sashank P
  12. Last Modified Date : 10th-April-2001
  13. *****************************************************************************/
  14. /*----------------------------------------------------------------------------
  15. Class Name : CParserEngine
  16. Class Type : Concrete
  17. Brief Description : This class encapsulates the functionality needed for
  18. parsing the command string entered as input and
  19. validating the same.
  20. Super Classes : None
  21. Sub Classes : None
  22. Classes Used : CParsedInfo
  23. CCmdTokenizer
  24. CCmdAlias
  25. Interfaces Used : WMI COM Interfaces
  26. ----------------------------------------------------------------------------*/
  27. // forward declaration of classes
  28. class CParsedInfo;
  29. class CCmdTokenizer;
  30. class CCmdAlias;
  31. class CParserEngine
  32. {
  33. public:
  34. // Construction
  35. CParserEngine();
  36. // Destruction
  37. ~CParserEngine();
  38. // Restrict Assignment
  39. CParserEngine& operator=(CParserEngine& rParserEngine);
  40. // Attributes
  41. private:
  42. // IWbemLocator interface to obtain the initial namespace pointer to the
  43. //Windows Management on a particular host computer
  44. IWbemLocator* m_pIWbemLocator;
  45. //IWbemServices interface is used by clients and providers to access WMI
  46. //services.This interface provides management services to client processes
  47. IWbemServices* m_pITargetNS;
  48. // Tokenizer object used for tokenize the command string
  49. CCmdTokenizer m_CmdTknzr;
  50. // Alias object used for accessing the alias information from the WMI.
  51. CCmdAlias m_CmdAlias;
  52. // flag to indicate whether <alias> name
  53. // is specified.
  54. BOOL m_bAliasName;
  55. // Operations
  56. private:
  57. // Parses the global switches.
  58. RETCODE ParseGlobalSwitches(CHARVECTOR& cvTokens,
  59. CHARVECTOR::iterator& theIterator,
  60. CParsedInfo& rParsedInfo);
  61. // Parses the <alias> information.
  62. RETCODE ParseAliasInfo(CHARVECTOR& cvTokens,
  63. CHARVECTOR::iterator& theIterator,
  64. CParsedInfo& rParsedInfo);
  65. // Parses the CLASS information.
  66. RETCODE ParseClassInfo(CHARVECTOR& cvTokens,
  67. CHARVECTOR::iterator& theIterator,
  68. CParsedInfo& rParsedInfo);
  69. // Parses the Verb information
  70. RETCODE ParseVerbInfo(CHARVECTOR& cvTokens,
  71. CHARVECTOR::iterator& theIterator,
  72. CParsedInfo& rParsedInfo);
  73. // Parse the GET verb information
  74. RETCODE ParseGETVerb(CHARVECTOR& cvTokens,
  75. CHARVECTOR::iterator& theIterator,
  76. CParsedInfo& rParsedInfo);
  77. // Parse the LIST verb information
  78. RETCODE ParseLISTVerb(CHARVECTOR& cvTokens,
  79. CHARVECTOR::iterator& theIterator,
  80. CParsedInfo& rParsedInfo);
  81. // Parse the SET | CREATE verb information
  82. RETCODE ParseSETorCREATEVerb(CHARVECTOR& cvTokens,
  83. CHARVECTOR::iterator& theIterator,
  84. CParsedInfo& rParsedInfo,
  85. HELPTYPE helpType);
  86. // Parse the ASSOC verb information
  87. RETCODE ParseASSOCVerb(CHARVECTOR& cvTokens,
  88. CHARVECTOR::iterator& theIterator,
  89. CParsedInfo& rParsedInfo);
  90. // Parse the CALL verb information
  91. RETCODE ParseCALLVerb(CHARVECTOR& cvTokens,
  92. CHARVECTOR::iterator& theIterator,
  93. CParsedInfo& rParsedInfo);
  94. // Parse the method information
  95. RETCODE ParseMethodInfo(CHARVECTOR& cvTokens,
  96. CHARVECTOR::iterator& theIterator,
  97. CParsedInfo& rParsedInfo);
  98. // Parses the GET verb switches information
  99. RETCODE ParseGETSwitches(CHARVECTOR& cvTokens,
  100. CHARVECTOR::iterator& theIterator,
  101. CParsedInfo& rParsedInfo);
  102. //Checks for help option in advance.
  103. RETCODE CheckForHelp(CHARVECTOR& cvTokens,
  104. CHARVECTOR::iterator& theIterator,
  105. CParsedInfo& rParsedInfo,
  106. UINT uErrataCode);
  107. // Parses the PATH expression.
  108. RETCODE ParsePathInfo(CHARVECTOR& cvTokens,
  109. CHARVECTOR::iterator& theIterator,
  110. CParsedInfo& rParsedInfo);
  111. // Parses the WHERE expression.
  112. RETCODE ParseWhereInfo(CHARVECTOR& cvTokens,
  113. CHARVECTOR::iterator& theIterator,
  114. CParsedInfo& rParsedInfo);
  115. // Parses the SET | CREATE | NamedParams verb argument list
  116. RETCODE ParseSETorCREATEOrNamedParamInfo(CHARVECTOR& cvTokens,
  117. CHARVECTOR::iterator& theIterator,
  118. CParsedInfo& rParsedInfo,
  119. HELPTYPE helpType);
  120. // Parses the LIST switches information
  121. RETCODE ParseLISTSwitches(CHARVECTOR& cvTokens,
  122. CHARVECTOR::iterator& theIterator,
  123. CParsedInfo& rParsedInfo,
  124. BOOL& bFormatSwitchSpecified);
  125. // Parses the Verb switches information
  126. RETCODE ParseVerbSwitches(CHARVECTOR& cvTokens,
  127. CHARVECTOR::iterator& theIterator,
  128. CParsedInfo& rParsedInfo);
  129. // Gets the next token from the Tokens vector - overload 1.
  130. BOOL GetNextToken(CHARVECTOR& cvTokens,
  131. CHARVECTOR::iterator& theIterator);
  132. // Gets the next token from the Tokens vector - overload 2.
  133. RETCODE GetNextToken(CHARVECTOR& cvTokens,
  134. CHARVECTOR::iterator& theIterator,
  135. CParsedInfo& rParsedInfo,
  136. HELPTYPE helpType,
  137. UINT uErrataCode);
  138. // Gets the next token from the Tokens vector - overload 3.
  139. RETCODE GetNextToken(CHARVECTOR& cvTokens,
  140. CHARVECTOR::iterator& theIterator,
  141. CParsedInfo& rParsedInfo,
  142. UINT uErrataCode);
  143. // Check whether the next token is '?'
  144. RETCODE IsHelp(CHARVECTOR& cvTokens,
  145. CHARVECTOR::iterator& theIterator,
  146. CParsedInfo& rParsedInfo,
  147. HELPTYPE helpType,
  148. UINT uErrataCode,
  149. TOKENLEVEL tokenLevel = LEVEL_ONE);
  150. // Parse for help information - overload 1
  151. RETCODE ParseHelp(CHARVECTOR& cvTokens,
  152. CHARVECTOR::iterator& theIterator,
  153. CParsedInfo& rParsedInfo,
  154. BOOL bGlobalHelp = FALSE);
  155. // Parse for help information - overload 2
  156. RETCODE ParseHelp(CHARVECTOR& cvTokens,
  157. CHARVECTOR::iterator& theIterator,
  158. HELPTYPE htHelp,
  159. CParsedInfo& rParsedInfo,
  160. BOOL bGlobalHelp = FALSE);
  161. // Parse and form a PWhere expression
  162. BOOL ParsePWhereExpr(CHARVECTOR& cvTokens,
  163. CHARVECTOR::iterator& theIterator,
  164. CParsedInfo& rParsedInfo,
  165. BOOL bIsParan);
  166. // Extracts the Classname and the where expression
  167. // out of the given path expression
  168. BOOL ExtractClassNameandWhereExpr(_TCHAR* pszPathExpr,
  169. CParsedInfo& rParsedInfo);
  170. // Obtains properties associated with the class for /get help
  171. // If bCheckWritePropsAvail == TRUE then functions checks for availibilty
  172. // of properties.
  173. BOOL ObtainClassProperties(CParsedInfo& rParsedInfo,
  174. BOOL bCheckWritePropsAvail = FALSE);
  175. // Obtains parameters of the method
  176. HRESULT ObtainMethodParamInfo(IWbemClassObject* pIObj,
  177. METHODDETAILS& mdMethDet,
  178. INOROUT ioInOrOut,
  179. BOOL bTrace, CParsedInfo& rParsedInfo);
  180. // Get the status of method ( implemented or not ).
  181. HRESULT GetMethodStatusAndDesc(IWbemClassObject* pIObj,
  182. BSTR bstrMethod,
  183. _bstr_t& bstrStatus,
  184. _bstr_t& bstrDesc,
  185. BOOL bTrace);
  186. // Obtain class methods. if bCheckForExists == TRUE then it
  187. // checks for availibility of methods with class.
  188. BOOL ObtainClassMethods(CParsedInfo& rParsedInfo,
  189. BOOL bCheckForExists = FALSE);
  190. // Connects to Target Namespace.
  191. HRESULT ConnectToNamespace(CParsedInfo& rParsedInfo);
  192. // Parses EVERY switch.
  193. RETCODE ParseEVERYSwitch(CHARVECTOR& cvTokens,
  194. CHARVECTOR::iterator& theIterator,
  195. CParsedInfo& rParsedInfo);
  196. // Parses FORMAT switch.
  197. RETCODE ParseFORMATSwitch(CHARVECTOR& cvTokens,
  198. CHARVECTOR::iterator& theIterator,
  199. CParsedInfo& rParsedInfo);
  200. // Validates the value passed with global switches.
  201. RETCODE ValidateGlobalSwitchValue(CHARVECTOR& cvTokens,
  202. CHARVECTOR::iterator& theIterator,
  203. UINT uErrataCode,
  204. CParsedInfo& rParsedInfo,
  205. UINT uErrataCode2,
  206. HELPTYPE htHelp);
  207. // Is pszToken is Std verb or User defined verb.
  208. BOOL IsStdVerbOrUserDefVerb( _bstr_t pszToken,
  209. CParsedInfo& rParsedInfo );
  210. // Parses the TRANSLATE switch.
  211. RETCODE ParseTRANSLATESwitch(CHARVECTOR& cvTokens,
  212. CHARVECTOR::iterator& theIterator,
  213. CParsedInfo& rParsedInfo);
  214. // Parsed the CONTEXT switch.
  215. RETCODE ParseContextInfo(CHARVECTOR& cvTokens,
  216. CHARVECTOR::iterator& theIterator,
  217. CParsedInfo& rParsedInfo);
  218. // Validates the node name/namespace
  219. BOOL ValidateNodeOrNS(_TCHAR* pszInput, BOOL bNode);
  220. // Parses the ASSOC switches information
  221. RETCODE ParseAssocSwitches(CHARVECTOR& cvTokens,
  222. CHARVECTOR::iterator& theIterator,
  223. CParsedInfo& rParsedInfo);
  224. // Parses the ASSOC switches - RESULTCLASSS,RESULTROLE ,ASSOCCLASSS
  225. RETCODE ParseAssocSwitchEx(CHARVECTOR& cvTokens,
  226. CHARVECTOR::iterator& theIterator,
  227. CParsedInfo& rParsedInfo,
  228. ASSOCSwitch assocSwitch);
  229. // Parsing Switch:Count ( /EVERY:N and /REPEAT:N )
  230. RETCODE ParseNumberedSwitch(CHARVECTOR& cvTokens,
  231. CHARVECTOR::iterator& theIterator,
  232. CParsedInfo& rParsedInfo,
  233. HELPTYPE htHelp,
  234. UINT uSwitchErrCode,
  235. UINT uNumberErrCode);
  236. // Validates a class;
  237. BOOL IsValidClass(CParsedInfo& rParsedInfo);
  238. // Checks whether methods are available with alias in case of alias specified.
  239. // and with class in case of class speicified.
  240. void ObtainMethodsAvailableFlag(CParsedInfo& rParsedInfo);
  241. // Checks whether Writeable Props are available with alias in case of alias
  242. // specified. and with class in case of class speicified.
  243. void ObtainWriteablePropsAvailailableFlag(CParsedInfo& rParsedInfo);
  244. // Checks whether FULL Props are available with alias in case of alias
  245. // specified. and with class in case of class speicified.
  246. void ObtainFULLPropsAvailailableFlag(CParsedInfo& rParsedInfo);
  247. // This function parses the verb interactive option
  248. RETCODE ParseVerbInteractive(CHARVECTOR& cvTokens,
  249. CHARVECTOR::iterator& theIterator,
  250. CParsedInfo& rParsedInfo, BOOL& bInvalidOption);
  251. // Prepares the output and append files for output redirection.
  252. RETCODE ProcessOutputAndAppendFiles(CParsedInfo& rParsedInfo, RETCODE retCode,
  253. BOOL bOpenOutInWriteMode);
  254. // Parse Unnamed Parameter list.
  255. RETCODE ParseUnnamedParamList(CHARVECTOR& cvTokens,
  256. CHARVECTOR::iterator& theIterator,
  257. CParsedInfo& rParsedInfo);
  258. // Validates the named params with verb or method parameters.
  259. RETCODE ValidateVerbOrMethodParams(CParsedInfo& rParsedInfo);
  260. // Parses paramName = paramValue strings.
  261. RETCODE ParseParamsString(CHARVECTOR& cvTokens,
  262. CHARVECTOR::iterator& theIterator,
  263. CParsedInfo& rParsedInfo,
  264. XSLTDET& xdXSLTDet);
  265. // Parses the node list file.
  266. RETCODE ParseNodeListFile(CHARVECTOR& cvTokens,
  267. CHARVECTOR::iterator& theIterator,
  268. CParsedInfo& rParsedInfo);
  269. // Retrieve Node by Node from Node list file
  270. BOOL GetNodeFromNodeFile(FILE* fpNodeListFile,
  271. FILETYPE eftNodeFileType,
  272. _TCHAR* szNodeName);
  273. public:
  274. // Gets the command tokenizer
  275. CCmdTokenizer& GetCmdTokenizer();
  276. // It does the Processing the token .
  277. RETCODE ProcessTokens(CParsedInfo& rParsedInfo);
  278. // Initializes the member variables
  279. void Initialize();
  280. // Uninitializes the member variables
  281. void Uninitialize(BOOL bFinal = FALSE);
  282. // Sets the locator object .
  283. BOOL SetLocatorObject(IWbemLocator* pIWbemLocator);
  284. };