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.

6249 lines
178 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : ParserEngine.cpp
  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 class encapsulates the functionality needed
  9. for parsing the command string entered as input
  10. and validating the same.
  11. Revision History :
  12. Last Modified By : Ch. Sriramachandramurthy
  13. Last Modified Date : 18th-December-2000
  14. *****************************************************************************/
  15. // include files
  16. #include "Precomp.h"
  17. #include "GlobalSwitches.h"
  18. #include "CommandSwitches.h"
  19. #include "HelpInfo.h"
  20. #include "ErrorLog.h"
  21. #include "ParsedInfo.h"
  22. #include "CmdTokenizer.h"
  23. #include "CmdAlias.h"
  24. #include "ParserEngine.h"
  25. #include "WMICliXMLLog.h"
  26. #include "ErrorInfo.h"
  27. #include "FormatEngine.h"
  28. #include "ExecEngine.h"
  29. #include "WmiCmdLn.h"
  30. /*----------------------------------------------------------------------------
  31. Name :CParserEngine
  32. Synopsis :This function initializes the member variables when an
  33. object of the class type is instantiated.
  34. Type :Constructor
  35. Input Parameter(s):None
  36. Output parameters :None
  37. Return Type :None
  38. Global Variables :None
  39. Calling Syntax :None
  40. Notes :None
  41. ----------------------------------------------------------------------------*/
  42. CParserEngine::CParserEngine()
  43. {
  44. m_pIWbemLocator = NULL;
  45. m_pITargetNS = NULL;
  46. m_bAliasName = FALSE;
  47. }
  48. /*----------------------------------------------------------------------------
  49. Name :~CParserEngine
  50. Synopsis :This function uninitializes the member variables when an
  51. object of the class type goes out of scope.
  52. Type :Destructor
  53. Input Parameter(s):None
  54. Output parameters :None
  55. Return Type :None
  56. Global Variables :None
  57. Calling Syntax :None
  58. Notes :None
  59. ----------------------------------------------------------------------------*/
  60. CParserEngine::~CParserEngine()
  61. {
  62. SAFEIRELEASE(m_pITargetNS);
  63. SAFEIRELEASE(m_pIWbemLocator);
  64. }
  65. /*----------------------------------------------------------------------------
  66. Name :GetCmdTokenizer
  67. Synopsis :This function returns a reference to the CCmdTokenizer
  68. object, a data member of this class.
  69. Type :Member Function
  70. Input Parameter(s):None
  71. Output parameters :None
  72. Return Type :CCmdTokenizer&
  73. Global Variables :None
  74. Calling Syntax :GetCmdTokenizer()
  75. Notes :None
  76. ----------------------------------------------------------------------------*/
  77. CCmdTokenizer& CParserEngine::GetCmdTokenizer()
  78. {
  79. return m_CmdTknzr;
  80. }
  81. /*----------------------------------------------------------------------------
  82. Name :Initialize
  83. Synopsis :This function initializes the neeeded data members of
  84. this class.
  85. Type :Member Function
  86. Input Parameter(s):None
  87. Output parameters :None
  88. Return Type :void
  89. Global Variables :None
  90. Calling Syntax :Initialize()
  91. Notes :None
  92. ----------------------------------------------------------------------------*/
  93. void CParserEngine::Initialize()
  94. {
  95. m_bAliasName = FALSE;
  96. }
  97. /*----------------------------------------------------------------------------
  98. Name :Uninitialize
  99. Synopsis :This function uninitializes the member variables when
  100. the execution of a command string issued on the command
  101. line is completed and then the parser engine variables
  102. are also uninitialized.
  103. Type :Member Function
  104. Input Parameter(s):
  105. bFinal - boolean value which when set indicates that the program
  106. Output parameters :None
  107. Return Type :void
  108. Global Variables :None
  109. Calling Syntax :Uninitialize()
  110. Notes :None
  111. ----------------------------------------------------------------------------*/
  112. void CParserEngine::Uninitialize(BOOL bFinal)
  113. {
  114. m_bAliasName = FALSE;
  115. m_CmdTknzr.Uninitialize();
  116. m_CmdAlias.Uninitialize();
  117. if (bFinal)
  118. {
  119. m_CmdAlias.Uninitialize(TRUE);
  120. SAFEIRELEASE(m_pITargetNS);
  121. SAFEIRELEASE(m_pIWbemLocator);
  122. }
  123. }
  124. /*----------------------------------------------------------------------------
  125. Name :SetLocatorObject
  126. Synopsis :This function sets the WMI Locator Object to the
  127. m_pIWbemLocator.
  128. Type :Member Function
  129. Input Parameter(s):
  130. pIWbemLocator - pointer to IWbemLocator interface .
  131. Output parameters :None
  132. Return Type :BOOL
  133. Global Variables :None
  134. Calling Syntax :SetLocatorObject(pIWbemLocator)
  135. Notes :None
  136. ----------------------------------------------------------------------------*/
  137. BOOL CParserEngine::SetLocatorObject(IWbemLocator* pIWbemLocator)
  138. {
  139. static BOOL bFirst = TRUE;
  140. BOOL bRet = TRUE;
  141. if (bFirst)
  142. {
  143. if (pIWbemLocator != NULL)
  144. {
  145. SAFEIRELEASE(m_pIWbemLocator);
  146. m_pIWbemLocator = pIWbemLocator;
  147. m_pIWbemLocator->AddRef();
  148. }
  149. else
  150. bRet = FALSE;
  151. bFirst = FALSE;
  152. }
  153. return bRet;
  154. }
  155. /*----------------------------------------------------------------------------
  156. Name :ProcessTokens
  157. Synopsis :This function does the processing of the tokens. It
  158. checks for the presence of switches and calls the
  159. appropriate Parsing function and updates the CParsedInfo
  160. object passed to it.
  161. Type :Member Function
  162. Input Parameter(s):
  163. rParsedInfo - reference to CParsedInfo class object
  164. Output parameters :
  165. rParsedInfo - reference to CParsedInfo class object
  166. Return Type :RETCODE - enumerated data type
  167. Global Variables :None
  168. Calling Syntax :ProcessTokens(rParsedInfo)
  169. Notes :None
  170. ----------------------------------------------------------------------------*/
  171. RETCODE CParserEngine::ProcessTokens(CParsedInfo& rParsedInfo)
  172. {
  173. BOOL bContinue = TRUE;
  174. RETCODE retCode = PARSER_EXECCOMMAND;
  175. // Obtain the token vector.
  176. CHARVECTOR cvTokens = m_CmdTknzr.GetTokenVector();
  177. //the iterator to span throuh the vector variable
  178. CHARVECTOR::iterator theIterator = NULL;
  179. // Check for the presence of tokens. Absence of tokens indicates
  180. // no command string is fed as input.
  181. if (!cvTokens.empty())
  182. {
  183. // Obtain the pointer to the beginning of the token vector.
  184. theIterator = cvTokens.begin();
  185. // Check for the presence of the global switches and
  186. // store the values specified with them (if any) in the
  187. // CGlobalSwitches object. Global switches are followed
  188. // '/' character.
  189. if (IsOption(*theIterator))
  190. {
  191. retCode = ParseGlobalSwitches(cvTokens,
  192. theIterator, rParsedInfo);
  193. if (retCode == PARSER_CONTINUE)
  194. {
  195. // If no more tokens are present
  196. if (theIterator >= cvTokens.end())
  197. {
  198. retCode = PARSER_MESSAGE;
  199. bContinue = FALSE;
  200. }
  201. }
  202. else
  203. bContinue = FALSE;
  204. }
  205. if (bContinue)
  206. {
  207. // Suppress Information Msg before Executing command.
  208. rParsedInfo.GetCmdSwitchesObject().SetInformationCode(0);
  209. // Check for the presence of the CLASS keyword
  210. if (CompareTokens(*theIterator, CLI_TOKEN_CLASS))
  211. {
  212. // Move to next token, and check its validity
  213. retCode = GetNextToken(cvTokens, theIterator,
  214. rParsedInfo, CLASS,
  215. IDS_E_INVALID_CLASS_SYNTAX);
  216. if (retCode == PARSER_CONTINUE)
  217. {
  218. // NOTE: Indicates direct escaping to WMI schema
  219. // Parse and interpret the remaining tokens following
  220. // the CLASS keyword
  221. retCode = ParseClassInfo(cvTokens, theIterator,
  222. rParsedInfo);
  223. }
  224. }
  225. // Check for the presence of the PATH keyword
  226. else if (CompareTokens(*theIterator, CLI_TOKEN_PATH))
  227. {
  228. //NOTE: Indicates PATH clause without an alias name
  229. // Move to next token
  230. retCode = GetNextToken(cvTokens, theIterator,
  231. rParsedInfo, PATH,
  232. IDS_E_INVALID_PATH_SYNTAX);
  233. if (retCode == PARSER_CONTINUE)
  234. // Parse and interpret the remaining tokens
  235. // following the PATH clause
  236. retCode = ParsePathInfo(cvTokens, theIterator,
  237. rParsedInfo);
  238. }
  239. // Check for the presence of the CONTEXT keyword
  240. else if (CompareTokens(*theIterator, CLI_TOKEN_CONTEXT))
  241. {
  242. if (GetNextToken(cvTokens, theIterator))
  243. {
  244. retCode = ParseContextInfo(cvTokens,
  245. theIterator, rParsedInfo);
  246. }
  247. else
  248. {
  249. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(TRUE);
  250. rParsedInfo.GetHelpInfoObject().SetHelp(GLBLCONTEXT, TRUE);
  251. retCode = PARSER_DISPHELP;
  252. }
  253. }
  254. // If the token value does not match against the
  255. // pre-defiend keywords, it is considered as an alias.
  256. else
  257. {
  258. // Validate the alias name and parse the remaining
  259. // tokens following the <alias> name.
  260. retCode = ParseAliasInfo(cvTokens,
  261. theIterator, rParsedInfo);
  262. if (retCode == PARSER_EXECCOMMAND)
  263. {
  264. try
  265. {
  266. _bstr_t bstrTrgtClass;
  267. _TCHAR *pszClass = NULL;
  268. // Check the validity of the path expression w.r.t the
  269. // alias specified using the following steps:
  270. // (i.e to check for alias - path conflict)
  271. // step1: Obtain the alias target class.
  272. rParsedInfo.GetCmdSwitchesObject().
  273. GetClassOfAliasTarget(bstrTrgtClass);
  274. // step2: Obtain the explicitly specified class.
  275. pszClass = rParsedInfo.GetCmdSwitchesObject().
  276. GetClassPath();
  277. if (!(!bstrTrgtClass) && (pszClass != NULL))
  278. {
  279. // If both are not same, set the errata code
  280. if(!CompareTokens((_TCHAR*)bstrTrgtClass,pszClass))
  281. {
  282. // Set the error code
  283. rParsedInfo.GetCmdSwitchesObject().
  284. SetErrataCode(IDS_I_ALIAS_PATH_CONFLICT);
  285. retCode = PARSER_ERROR;
  286. }
  287. }
  288. }
  289. catch(_com_error& e)
  290. {
  291. _com_issue_error(e.Error());
  292. }
  293. }
  294. }
  295. }
  296. }
  297. else
  298. {
  299. // Indicates NULL string specified as input on the WMI Command Line.
  300. rParsedInfo.GetCmdSwitchesObject().
  301. SetErrataCode(IDS_E_BLANK_COMMAND_MESSAGE);
  302. retCode = PARSER_ERROR;
  303. }
  304. // Get the Property qualifiers information from the alias - SET and CREATE.
  305. if ((retCode == PARSER_EXECCOMMAND) &&
  306. ((CompareTokens(rParsedInfo.GetCmdSwitchesObject().GetVerbName(),
  307. CLI_TOKEN_SET)) ||
  308. (CompareTokens(rParsedInfo.GetCmdSwitchesObject().GetVerbName(),
  309. CLI_TOKEN_CREATE))))
  310. {
  311. if (m_bAliasName)
  312. {
  313. if (FAILED(m_CmdAlias.ObtainAliasPropDetails(rParsedInfo)))
  314. retCode = PARSER_ERRMSG;
  315. }
  316. }
  317. if ( retCode == PARSER_DISPHELP )
  318. {
  319. if ( m_bAliasName ||
  320. rParsedInfo.GetCmdSwitchesObject().GetClassPath() != NULL )
  321. {
  322. ObtainMethodsAvailableFlag(rParsedInfo);
  323. ObtainWriteablePropsAvailailableFlag(rParsedInfo);
  324. }
  325. if ( m_bAliasName == TRUE )
  326. {
  327. rParsedInfo.GetCmdSwitchesObject().
  328. SetLISTFormatsAvailable(
  329. m_CmdAlias.ObtainAliasFormat(rParsedInfo, TRUE));
  330. }
  331. }
  332. if ( retCode == PARSER_EXECCOMMAND || retCode == PARSER_DISPHELP )
  333. {
  334. retCode = ProcessOutputAndAppendFiles(rParsedInfo, retCode, FALSE);
  335. }
  336. else if (rParsedInfo.GetCmdSwitchesObject().GetOutputSwitchFlag() == TRUE
  337. && retCode == PARSER_MESSAGE)
  338. rParsedInfo.GetCmdSwitchesObject().SetOutputSwitchFlag(FALSE);
  339. return retCode;
  340. }
  341. /*----------------------------------------------------------------------------
  342. Name :ParseClassInfo
  343. Synopsis :This function does the parsing and interprets if command
  344. has CLASS keyword specified in it. It parses the
  345. remaining tokens following and updates the same in
  346. CParsedInfo object passed to it.
  347. Type :Member Function
  348. Input Parameter(s) :
  349. cvTokens - the tokens vector
  350. theIterator - the Iterator to the cvTokens vector.
  351. rParsedInfo - reference to CParsedInfo class object
  352. Output parameter(s):
  353. rParsedInfo - reference to CParsedInfo class object
  354. Return Type :RETCODE - enumerated data type
  355. Global Variables :None
  356. Calling Syntax :ParseClassInfo(cvTokens,theIterator,rParsedInfo)
  357. Notes :None
  358. ----------------------------------------------------------------------------*/
  359. RETCODE CParserEngine::ParseClassInfo(CHARVECTOR& cvTokens,
  360. CHARVECTOR::iterator& theIterator,
  361. CParsedInfo& rParsedInfo )
  362. {
  363. // BNF: CLASS <class path expression> [<verb clause>]
  364. BOOL bContinue = TRUE;
  365. RETCODE retCode = PARSER_EXECCOMMAND;
  366. // If option
  367. if (IsOption(*theIterator))
  368. {
  369. // Check for help
  370. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, CLASS,
  371. IDS_E_INVALID_HELP_SYNTAX, LEVEL_ONE);
  372. if (retCode != PARSER_CONTINUE)
  373. bContinue = FALSE;
  374. }
  375. else
  376. {
  377. // Store the class path in the CCommandSwitches object.
  378. if(!rParsedInfo.GetCmdSwitchesObject().SetClassPath(*theIterator))
  379. {
  380. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(OUT_OF_MEMORY);
  381. bContinue = FALSE;
  382. retCode = PARSER_OUTOFMEMORY;
  383. }
  384. else if ( IsValidClass(rParsedInfo) == FALSE )
  385. {
  386. rParsedInfo.GetCmdSwitchesObject().
  387. SetErrataCode(IDS_E_INVALID_CLASS);
  388. retCode = PARSER_ERROR;
  389. bContinue = FALSE;
  390. }
  391. if(bContinue)
  392. {
  393. // Move to next token
  394. if (!GetNextToken(cvTokens, theIterator))
  395. {
  396. // i.e. <verb clause> is not specified.
  397. bContinue = FALSE;
  398. retCode = PARSER_EXECCOMMAND;
  399. }
  400. }
  401. }
  402. if (bContinue)
  403. {
  404. // Check for the presence of /?
  405. if (IsOption(*theIterator))
  406. {
  407. // Check for help
  408. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, CLASS,
  409. IDS_E_INVALID_HELP_SYNTAX, LEVEL_ONE);
  410. }
  411. else
  412. {
  413. // Parse and interpret the verb tokens that follow
  414. retCode = ParseVerbInfo(cvTokens,theIterator,rParsedInfo);
  415. if (retCode == PARSER_EXECCOMMAND)
  416. {
  417. // Check for verb switches
  418. if (GetNextToken(cvTokens, theIterator))
  419. retCode = ParseVerbSwitches(cvTokens, theIterator,
  420. rParsedInfo);
  421. }
  422. }
  423. }
  424. return retCode;
  425. }
  426. /*----------------------------------------------------------------------------
  427. Name :ParseAliasInfo
  428. Synopsis :This function does the parsing and interprets if command
  429. has <alias> name in it.It Validate the alias name and
  430. parses the remaining tokens following the <alias> name.
  431. Type :Member Function
  432. Input Parameter(s):
  433. cvTokens - the tokens vector
  434. theIterator - the Iterator to the cvTokens vector.
  435. rParsedInfo - reference to CParsedInfo class object
  436. Output parameter(s):
  437. rParsedInfo - reference to CParsedInfo class object
  438. Return Type :RETCODE - enumerated data type
  439. Global Variables :None
  440. Calling Syntax :ParseAliasInfo(cvTokens,theIterator,rParsedInfo)
  441. Notes :None
  442. ----------------------------------------------------------------------------*/
  443. RETCODE CParserEngine::ParseAliasInfo(CHARVECTOR& cvTokens,
  444. CHARVECTOR::iterator& theIterator,
  445. CParsedInfo& rParsedInfo)
  446. {
  447. //BNF: (<alias> | [<WMI object>] | [<alias>] <path where>) [<verb clause>]
  448. RETCODE retCode = PARSER_EXECCOMMAND;
  449. HRESULT hr = S_OK;
  450. BOOL bContinue = TRUE;
  451. RETCODE tRetCode = PARSER_ERROR;
  452. // Store the AliasName in the CommandSwitches object.
  453. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasName(*theIterator))
  454. {
  455. rParsedInfo.GetCmdSwitchesObject().
  456. SetErrataCode(OUT_OF_MEMORY);
  457. retCode = PARSER_OUTOFMEMORY;
  458. }
  459. else
  460. {
  461. m_bAliasName = TRUE;
  462. // Move to next token
  463. retCode = GetNextToken(cvTokens, theIterator,
  464. rParsedInfo, CmdAllInfo, IDS_E_INVALID_COMMAND);
  465. if (retCode == PARSER_ERROR)
  466. tRetCode = PARSER_EXECCOMMAND;
  467. else if(retCode == PARSER_DISPHELP &&
  468. rParsedInfo.GetGlblSwitchesObject().GetInteractiveStatus() == TRUE)
  469. {
  470. tRetCode = PARSER_EXECCOMMAND;
  471. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(FALSE);
  472. rParsedInfo.GetHelpInfoObject().SetHelp(CmdAllInfo, FALSE);
  473. }
  474. // Connect to alias and retrieve the alias information
  475. try
  476. {
  477. // Connect to the AliasNamespace.
  478. hr = m_CmdAlias.ConnectToAlias(rParsedInfo, m_pIWbemLocator);
  479. ONFAILTHROWERROR(hr);
  480. // Obtain the alias information ( Target, Namespace,...)
  481. retCode = m_CmdAlias.ObtainAliasInfo(rParsedInfo);
  482. if((retCode == PARSER_OUTOFMEMORY) || (retCode == PARSER_ERRMSG))
  483. {
  484. if (retCode == PARSER_OUTOFMEMORY)
  485. {
  486. rParsedInfo.GetCmdSwitchesObject().
  487. SetErrataCode(OUT_OF_MEMORY);
  488. retCode = PARSER_OUTOFMEMORY;
  489. }
  490. bContinue = FALSE;
  491. }
  492. }
  493. catch(_com_error& e)
  494. {
  495. retCode = PARSER_ERRMSG;
  496. bContinue = FALSE;
  497. _com_issue_error(e.Error());
  498. }
  499. if (bContinue && tRetCode != PARSER_EXECCOMMAND)
  500. {
  501. // Check for the presence of the PATH keyword
  502. if (CompareTokens(*theIterator, CLI_TOKEN_PATH))
  503. {
  504. // NOTE: Indicates PATH clause preceded by an alias name
  505. // Move to next token
  506. retCode = GetNextToken(cvTokens, theIterator,
  507. rParsedInfo, PATH, IDS_E_INVALID_PATH);
  508. if (retCode == PARSER_CONTINUE)
  509. // Parse and interpret the remaining tokens following
  510. // the PATH clause
  511. retCode = ParsePathInfo(cvTokens, theIterator,
  512. rParsedInfo);
  513. }
  514. // Check for the presence of the WHERE keyword
  515. else if (CompareTokens(*theIterator, CLI_TOKEN_WHERE))
  516. {
  517. // NOTE: Indicates WHERE clause preceded by an alias name
  518. // Move to next token
  519. retCode = GetNextToken(cvTokens, theIterator, rParsedInfo,
  520. WHERE, IDS_E_INVALID_QUERY);
  521. if (retCode == PARSER_CONTINUE)
  522. // Parse and interpret the remaining tokens following
  523. // the WHERE clause
  524. retCode = ParseWhereInfo(cvTokens, theIterator,
  525. rParsedInfo);
  526. }
  527. // Check for the presence of the '('
  528. else if (CompareTokens(*theIterator, CLI_TOKEN_LEFT_PARAN))
  529. {
  530. // Frame the parameterized WHERE expression
  531. if (!ParsePWhereExpr(cvTokens, theIterator, rParsedInfo,
  532. TRUE))
  533. {
  534. retCode = PARSER_ERROR;
  535. }
  536. else
  537. {
  538. // Move to next token
  539. if (theIterator >= cvTokens.end())
  540. {
  541. // PARSER_ERROR if no more tokens are present
  542. rParsedInfo.GetCmdSwitchesObject().
  543. SetErrataCode(IDS_E_INVALID_COMMAND);
  544. retCode = PARSER_ERROR;
  545. }
  546. else
  547. {
  548. if (CompareTokens(*theIterator, CLI_TOKEN_RIGHT_PARAN))
  549. {
  550. // Move to next token
  551. if (!GetNextToken(cvTokens, theIterator))
  552. {
  553. // if no more tokens are present.
  554. retCode = PARSER_EXECCOMMAND;
  555. }
  556. else
  557. {
  558. if (IsOption(*theIterator))
  559. {
  560. retCode = IsHelp(cvTokens,
  561. theIterator,
  562. rParsedInfo,
  563. PWhere,
  564. IDS_E_INVALID_HELP_SYNTAX,
  565. LEVEL_ONE);
  566. if ( retCode == PARSER_DISPHELP )
  567. {
  568. if (FAILED(m_CmdAlias.
  569. ObtainAliasVerbDetails(rParsedInfo)))
  570. retCode = PARSER_ERRMSG;
  571. }
  572. }
  573. else
  574. {
  575. retCode = ParseVerbInfo(cvTokens,
  576. theIterator, rParsedInfo);
  577. // Parse and interpret the verb tokens
  578. // that follow
  579. if (retCode == PARSER_EXECCOMMAND)
  580. {
  581. if(GetNextToken(cvTokens,
  582. theIterator))
  583. // check for the common verb
  584. // switches /INTERACTIVE,
  585. // /NOINTERACTIVE
  586. retCode = ParseVerbSwitches(
  587. cvTokens,
  588. theIterator,
  589. rParsedInfo);
  590. }
  591. }
  592. }
  593. }
  594. else
  595. {
  596. // PARSER_ERROR if no more tokens are present
  597. rParsedInfo.GetCmdSwitchesObject().
  598. SetErrataCode(IDS_E_INVALID_COMMAND);
  599. retCode = PARSER_ERROR;
  600. }
  601. }
  602. }
  603. }
  604. else
  605. {
  606. if (IsOption(*theIterator))
  607. {
  608. // Check for help
  609. retCode = IsHelp(cvTokens, theIterator, rParsedInfo,
  610. CmdAllInfo, IDS_E_INVALID_HELP_SYNTAX,
  611. LEVEL_ONE);
  612. if (retCode == PARSER_DISPHELP)
  613. {
  614. rParsedInfo.GetCmdSwitchesObject().
  615. AddToAlsFrnNmsOrTrnsTblMap(
  616. CharUpper(rParsedInfo.GetCmdSwitchesObject().
  617. GetAliasName()),
  618. rParsedInfo.GetCmdSwitchesObject().GetAliasDesc());
  619. }
  620. }
  621. else
  622. {
  623. if (bContinue)
  624. {
  625. // Frame the parameterized WHERE expression
  626. if (!ParsePWhereExpr(cvTokens, theIterator,
  627. rParsedInfo, FALSE))
  628. {
  629. retCode = PARSER_ERROR;
  630. }
  631. else
  632. {
  633. if ( theIterator >= cvTokens.end() )
  634. retCode = PARSER_EXECCOMMAND;
  635. else
  636. {
  637. // Parse the verb.
  638. if (IsOption(*theIterator))
  639. {
  640. retCode = IsHelp(cvTokens,
  641. theIterator,
  642. rParsedInfo,
  643. PWhere,
  644. IDS_E_INVALID_HELP_SYNTAX,
  645. LEVEL_ONE);
  646. if ( retCode == PARSER_DISPHELP )
  647. {
  648. if (FAILED(m_CmdAlias.
  649. ObtainAliasVerbDetails(rParsedInfo)))
  650. retCode = PARSER_ERRMSG;
  651. }
  652. }
  653. else
  654. {
  655. retCode = ParseVerbInfo(cvTokens,
  656. theIterator, rParsedInfo);
  657. if (retCode == PARSER_EXECCOMMAND)
  658. {
  659. if (GetNextToken(cvTokens, theIterator))
  660. // check for the common verb switches
  661. // /INTERACTIVE, /NOINTERACTIVE
  662. retCode = ParseVerbSwitches(cvTokens,
  663. theIterator,
  664. rParsedInfo);
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. if(tRetCode == PARSER_EXECCOMMAND)
  675. {
  676. if ((retCode != PARSER_ERRMSG) && (retCode != PARSER_OUTOFMEMORY))
  677. {
  678. retCode = tRetCode;
  679. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(0);
  680. }
  681. }
  682. return retCode;
  683. }
  684. /*----------------------------------------------------------------------------
  685. Name :ParseWhereInfo
  686. Synopsis :This function does the parsing and interprets if command
  687. has alias, with where clause also specified it.It parses
  688. the remaining tokens following and updates the same in
  689. CParsedInfo object passed to it.
  690. Type :Member Function
  691. Input Parameter(s) :
  692. cvTokens - the tokens vector
  693. theIterator - the Iterator to the cvTokens vector.
  694. rParsedInfo - reference to CParsedInfo class object
  695. Output parameter(s) :
  696. rParsedInfo - reference to CParsedInfo class object
  697. Return Type :RETCODE - enumerated data type
  698. Global Variables :None
  699. Calling Syntax :ParseWhereInfo(cvTokens,theIterator,rParsedInfo)
  700. Notes :None
  701. ----------------------------------------------------------------------------*/
  702. RETCODE CParserEngine::ParseWhereInfo(CHARVECTOR& cvTokens,
  703. CHARVECTOR::iterator& theIterator,
  704. CParsedInfo& rParsedInfo)
  705. {
  706. RETCODE retCode = PARSER_EXECCOMMAND;
  707. BOOL bContinue = TRUE;
  708. rParsedInfo.GetCmdSwitchesObject().SetExplicitWhereExprFlag(TRUE);
  709. if (IsOption(*theIterator))
  710. {
  711. // Check for help
  712. retCode = IsHelp(cvTokens, theIterator, rParsedInfo,
  713. WHERE, IDS_E_INVALID_WHERE_SYNTAX, LEVEL_ONE);
  714. if (retCode != PARSER_CONTINUE)
  715. bContinue = FALSE;
  716. }
  717. if (bContinue)
  718. {
  719. if ( !m_bAliasName && rParsedInfo.GetCmdSwitchesObject().
  720. GetClassPath() == NULL )
  721. {
  722. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  723. IDS_E_ALIAS_OR_PATH_SHOULD_PRECEED_WHERE);
  724. retCode = PARSER_ERROR;
  725. }
  726. // Store the WHERE expression in the CCommandSwitches object.
  727. else if(!rParsedInfo.GetCmdSwitchesObject().SetWhereExpression(
  728. *theIterator))
  729. {
  730. rParsedInfo.GetCmdSwitchesObject().
  731. SetErrataCode(OUT_OF_MEMORY);
  732. retCode = PARSER_OUTOFMEMORY;
  733. }
  734. else
  735. {
  736. // Move to next token
  737. if (!GetNextToken(cvTokens, theIterator))
  738. {
  739. // If no more tokens are present. i.e no verb clause is present
  740. retCode = PARSER_EXECCOMMAND;
  741. }
  742. else
  743. {
  744. if (IsOption(*theIterator))
  745. {
  746. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, WHERE,
  747. IDS_E_INVALID_HELP_SYNTAX, LEVEL_ONE);
  748. }
  749. else
  750. {
  751. // Parse and interpret the verb tokens that follow
  752. // Handled for /verb to verb
  753. retCode = ParseVerbInfo(cvTokens, theIterator,
  754. rParsedInfo);
  755. if (retCode == PARSER_EXECCOMMAND)
  756. {
  757. if (GetNextToken(cvTokens, theIterator))
  758. //check for the common verb switches /INTERACTIVE,
  759. // /NOINTERACTIVE
  760. retCode = ParseVerbSwitches(cvTokens, theIterator,
  761. rParsedInfo);
  762. }
  763. }
  764. }
  765. }
  766. }
  767. return retCode;
  768. }
  769. /*----------------------------------------------------------------------------
  770. Name :ParsePathInfo
  771. Synopsis :This function does the parsing and interprets if command
  772. has alias with path clause also specified it.It parses
  773. the remaining tokens following and updates the same in
  774. CParsedInfo object passed to it.
  775. Type :Member Function
  776. Input Parameter(s):
  777. cvTokens - the tokens vector
  778. theIterator - the Iterator to the cvTokens vector.
  779. rParsedInfo - reference to CParsedInfo class object
  780. Output Parameter(s) :
  781. rParsedInfo - reference to CParsedInfo class object
  782. Return Type :RETCODE - enumerated data type
  783. Global Variables :None
  784. Calling Syntax :ParsePathInfo(cvTokens,theIterator,rParsedInfo)
  785. Notes :None
  786. ----------------------------------------------------------------------------*/
  787. RETCODE CParserEngine::ParsePathInfo(CHARVECTOR& cvTokens,
  788. CHARVECTOR::iterator& theIterator,
  789. CParsedInfo& rParsedInfo)
  790. {
  791. RETCODE retCode = PARSER_EXECCOMMAND;
  792. BOOL bContinue = TRUE;
  793. if (IsOption(*theIterator))
  794. {
  795. retCode = IsHelp(cvTokens, theIterator, rParsedInfo,
  796. PATH, IDS_E_INVALID_PATH_SYNTAX, LEVEL_ONE);
  797. if (retCode != PARSER_CONTINUE)
  798. bContinue = FALSE;
  799. }
  800. if (bContinue)
  801. {
  802. // Store the object PATH expression in the CCommandSwitches object.
  803. if(!rParsedInfo.GetCmdSwitchesObject().SetPathExpression(*theIterator))
  804. {
  805. rParsedInfo.GetCmdSwitchesObject().
  806. SetErrataCode(OUT_OF_MEMORY);
  807. retCode = PARSER_OUTOFMEMORY;
  808. }
  809. else
  810. {
  811. //Extract the classname and where expression given path expression
  812. _TCHAR pszPathExpr[MAX_BUFFER] = NULL_STRING;
  813. lstrcpy(pszPathExpr,CLI_TOKEN_NULL);
  814. lstrcpy(pszPathExpr, rParsedInfo.GetCmdSwitchesObject().
  815. GetPathExpression());
  816. if (!ExtractClassNameandWhereExpr(pszPathExpr, rParsedInfo))
  817. retCode = PARSER_ERROR;
  818. // Move to next token
  819. else if ( IsValidClass(rParsedInfo) == FALSE )
  820. {
  821. rParsedInfo.GetCmdSwitchesObject().
  822. SetErrataCode(IDS_E_INVALID_CLASS);
  823. bContinue = FALSE;
  824. retCode = PARSER_ERROR;
  825. }
  826. else if (!GetNextToken(cvTokens, theIterator))
  827. // If no more tokens are present. i.e no verb clause is present
  828. retCode = PARSER_EXECCOMMAND;
  829. else
  830. {
  831. if ( CompareTokens(*theIterator, CLI_TOKEN_WHERE) )
  832. {
  833. if ( rParsedInfo.GetCmdSwitchesObject().
  834. GetWhereExpression() != NULL )
  835. {
  836. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  837. IDS_E_KEY_CLASS_NOT_ALLOWED_WITH_PATHWHERE);
  838. retCode = PARSER_ERROR;
  839. }
  840. else
  841. {
  842. retCode = GetNextToken(cvTokens, theIterator,
  843. rParsedInfo, WHERE,
  844. IDS_E_INVALID_WHERE_SYNTAX);
  845. if (retCode == PARSER_CONTINUE)
  846. // Parse and interpret the remaining tokens
  847. // following the WHERE clause
  848. retCode = ParseWhereInfo(cvTokens, theIterator,
  849. rParsedInfo);
  850. }
  851. }
  852. else
  853. {
  854. if (IsOption(*theIterator))
  855. {
  856. retCode = IsHelp(cvTokens, theIterator, rParsedInfo,
  857. PATH, IDS_E_INVALID_HELP_SYNTAX,
  858. LEVEL_ONE);
  859. }
  860. else
  861. {
  862. // Parse and interpret the verb tokens that follow
  863. // Handled for /verb => verb.
  864. retCode = ParseVerbInfo(cvTokens,theIterator,rParsedInfo);
  865. if (retCode == PARSER_EXECCOMMAND)
  866. {
  867. if (GetNextToken(cvTokens, theIterator))
  868. //check for the common verb switches /INTERACTIVE,
  869. ///NOINTERACTIVE
  870. retCode = ParseVerbSwitches(cvTokens, theIterator,
  871. rParsedInfo);
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. return retCode;
  879. }
  880. /*----------------------------------------------------------------------------
  881. Name :ParseVerbInfo
  882. Synopsis :This function does the parsing and interprets if command
  883. has verb clause specified in it.It parses the remaining
  884. tokens following the verb and updates the same in
  885. CParsedInfo object passed to it.
  886. Type :Member Function
  887. Input Parameter(s):
  888. cvTokens - the tokens vector
  889. theIterator - the Iterator to the cvTokens vector.
  890. rParsedInfo - reference to CParsedInfo class object
  891. Output Parameter(s):
  892. rParsedInfo - reference to CParsedInfo class object
  893. Return Type :RETCODE - enumerated data type
  894. Global Variables :None
  895. Calling Syntax :ParseVerbInfo(cvTokens,theIterator,rParsedInfo)
  896. Notes :None
  897. ----------------------------------------------------------------------------*/
  898. RETCODE CParserEngine::ParseVerbInfo(CHARVECTOR& cvTokens,
  899. CHARVECTOR::iterator& theIterator,
  900. CParsedInfo& rParsedInfo)
  901. {
  902. RETCODE retCode = PARSER_EXECCOMMAND;
  903. BOOL bContinue = TRUE;
  904. // STORE the verb name in the CCommandSwitches object
  905. if ( rParsedInfo.GetCmdSwitchesObject().SetVerbName(*theIterator)
  906. == FALSE )
  907. {
  908. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(IDS_E_MEMALLOC_FAIL);
  909. retCode = PARSER_ERROR;
  910. }
  911. // Check for the presence of the following standard verbs:
  912. // 1.GET 2.SHOW 3.SET 4.CALL 5.ASSOC 6. CREATE 7. DELETE
  913. // GET verb specified
  914. else if (CompareTokens(*theIterator, CLI_TOKEN_GET))
  915. {
  916. retCode = ParseGETVerb(cvTokens, theIterator, rParsedInfo);
  917. }
  918. // LIST verb specified
  919. else if (CompareTokens(*theIterator, CLI_TOKEN_LIST))
  920. {
  921. if (m_bAliasName == FALSE)
  922. {
  923. rParsedInfo.GetCmdSwitchesObject().
  924. SetErrataCode(IDS_E_INVALID_LIST_USAGE);
  925. retCode = PARSER_ERROR;
  926. }
  927. else
  928. retCode = ParseLISTVerb(cvTokens, theIterator, rParsedInfo);
  929. }
  930. // SET | CREATE verb specified
  931. else if (CompareTokens(*theIterator, CLI_TOKEN_SET) ||
  932. CompareTokens(*theIterator, CLI_TOKEN_CREATE))
  933. {
  934. // <path expression> and <where expression> cannot be specified with
  935. // CREATE verb. Only <class expression> should be specified.
  936. if (CompareTokens(*theIterator, CLI_TOKEN_CREATE)
  937. && rParsedInfo.GetCmdSwitchesObject().
  938. GetExplicitWhereExprFlag())
  939. {
  940. rParsedInfo.GetCmdSwitchesObject().
  941. SetErrataCode(IDS_E_INVALID_CREATE_EXPRESSION);
  942. retCode = PARSER_ERROR;
  943. }
  944. else
  945. {
  946. HELPTYPE helpType =
  947. CompareTokens(*theIterator, CLI_TOKEN_CREATE)
  948. ? CREATEVerb : SETVerb;
  949. retCode = ParseSETorCREATEVerb(cvTokens, theIterator,
  950. rParsedInfo, helpType);
  951. }
  952. }
  953. // CALL verb specified
  954. else if (CompareTokens(*theIterator, CLI_TOKEN_CALL))
  955. {
  956. retCode = ParseCALLVerb(cvTokens, theIterator, rParsedInfo);
  957. }
  958. // ASSOC verb specified
  959. else if (CompareTokens(*theIterator, CLI_TOKEN_ASSOC))
  960. {
  961. retCode = ParseASSOCVerb(cvTokens, theIterator, rParsedInfo);
  962. }
  963. // DELETE verb specified.
  964. else if (CompareTokens(*theIterator, CLI_TOKEN_DELETE))
  965. {
  966. retCode = PARSER_EXECCOMMAND;
  967. //ParseDELETEVerb(cvTokens, theIterator, rParsedInfo);
  968. }
  969. // User defined verb
  970. else if (m_bAliasName)
  971. {
  972. // User defined verbs can only be associated with alias
  973. retCode = ParseMethodInfo(cvTokens, theIterator, rParsedInfo);
  974. if (retCode == PARSER_CONTINUE)
  975. retCode = PARSER_EXECCOMMAND;
  976. }
  977. else
  978. {
  979. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(IDS_E_INVALID_VERB);
  980. retCode = PARSER_ERROR;
  981. }
  982. return retCode;
  983. }
  984. /*----------------------------------------------------------------------------
  985. Name :ParseMethodInfo
  986. Synopsis :This function parses the tokens following the user
  987. defined verb and updates the info in CParsedInfo object
  988. passed to it.
  989. Type :Member Function
  990. Input Parameter(s):
  991. cvTokens - the tokens vector
  992. theIterator - the Iterator to the cvTokens vector.
  993. rParsedInfo - reference to CParsedInfo class object
  994. Output Parameter(s):
  995. rParsedInfo - reference to CParsedInfo class object
  996. Return Type :RETCODE - enumerated data type
  997. Global Variables :None
  998. Calling Syntax :ParseMethodInfo(cvTokens,theIterator,rParsedInfo)
  999. Notes :None
  1000. ----------------------------------------------------------------------------*/
  1001. RETCODE CParserEngine::ParseMethodInfo(CHARVECTOR& cvTokens,
  1002. CHARVECTOR::iterator& theIterator,
  1003. CParsedInfo& rParsedInfo)
  1004. {
  1005. RETCODE retCode = PARSER_EXECCOMMAND;
  1006. BOOL bContinue = TRUE;
  1007. // Store the method name
  1008. if(!rParsedInfo.GetCmdSwitchesObject().SetMethodName(*theIterator))
  1009. {
  1010. rParsedInfo.GetCmdSwitchesObject().
  1011. SetErrataCode(OUT_OF_MEMORY);
  1012. retCode = PARSER_OUTOFMEMORY;
  1013. }
  1014. else
  1015. {
  1016. if(m_bAliasName)
  1017. {
  1018. if (FAILED(m_CmdAlias.ObtainAliasVerbDetails(rParsedInfo)))
  1019. {
  1020. retCode = PARSER_ERRMSG;
  1021. bContinue =FALSE;
  1022. }
  1023. else
  1024. {
  1025. VERBTYPE vtVerbType =
  1026. rParsedInfo.GetCmdSwitchesObject().GetVerbType();
  1027. _TCHAR* pszVerbDerivation =
  1028. rParsedInfo.GetCmdSwitchesObject().GetVerbDerivation();
  1029. if ( rParsedInfo.GetCmdSwitchesObject().GetMethDetMap().empty())
  1030. {
  1031. DisplayMessage(*theIterator, CP_OEMCP, TRUE, TRUE);
  1032. rParsedInfo.GetCmdSwitchesObject().
  1033. SetErrataCode(IDS_E_INVALID_ALIAS_VERB);
  1034. retCode = PARSER_ERROR;
  1035. bContinue = FALSE;
  1036. }
  1037. else if ( pszVerbDerivation == NULL )
  1038. {
  1039. rParsedInfo.GetCmdSwitchesObject().
  1040. SetErrataCode(IDS_E_VERB_DERV_NOT_AVAIL_IN_ALIAS);
  1041. retCode = PARSER_ERROR;
  1042. bContinue = FALSE;
  1043. }
  1044. else if ( vtVerbType == CLASSMETHOD )
  1045. {
  1046. if (!rParsedInfo.GetCmdSwitchesObject().SetMethodName(
  1047. pszVerbDerivation))
  1048. {
  1049. rParsedInfo.GetCmdSwitchesObject().
  1050. SetErrataCode(OUT_OF_MEMORY);
  1051. retCode = PARSER_OUTOFMEMORY;
  1052. bContinue = FALSE;
  1053. }
  1054. }
  1055. else if ( vtVerbType == STDVERB )
  1056. {
  1057. (*theIterator) = pszVerbDerivation;
  1058. // Parse and interpret the verb tokens that follow
  1059. // Handled for /verb => verb.
  1060. retCode = ParseVerbInfo(cvTokens,theIterator,rParsedInfo);
  1061. if (retCode == PARSER_EXECCOMMAND)
  1062. {
  1063. if (GetNextToken(cvTokens, theIterator))
  1064. retCode = ParseVerbSwitches(cvTokens, theIterator,
  1065. rParsedInfo);
  1066. }
  1067. bContinue =FALSE;
  1068. }
  1069. }
  1070. }
  1071. else
  1072. {
  1073. if (!ObtainClassMethods(rParsedInfo))
  1074. {
  1075. retCode = PARSER_ERRMSG;
  1076. bContinue =FALSE;
  1077. }
  1078. else if (rParsedInfo.GetCmdSwitchesObject().GetMethDetMap().empty())
  1079. {
  1080. DisplayMessage(*theIterator, CP_OEMCP, TRUE, TRUE);
  1081. rParsedInfo.GetCmdSwitchesObject().
  1082. SetErrataCode(IDS_E_INVALID_CLASS_METHOD);
  1083. retCode = PARSER_ERROR;
  1084. bContinue =FALSE;
  1085. }
  1086. }
  1087. // Move to next token
  1088. if ( bContinue == TRUE && !GetNextToken(cvTokens, theIterator) )
  1089. {
  1090. // indicates method with no parameters
  1091. retCode = PARSER_EXECCOMMAND;
  1092. bContinue =FALSE;
  1093. }
  1094. if (bContinue)
  1095. {
  1096. if (IsOption(*theIterator))
  1097. {
  1098. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, AliasVerb,
  1099. IDS_E_INVALID_EXPRESSION, LEVEL_TWO);
  1100. if (retCode == PARSER_CONTINUE)
  1101. // To facilitate ParseVerbSwitches to continue
  1102. theIterator = theIterator - 2;
  1103. else if (retCode == PARSER_DISPHELP)
  1104. {
  1105. rParsedInfo.GetCmdSwitchesObject().GetMethDetMap().
  1106. clear();
  1107. if(m_bAliasName)
  1108. {
  1109. if (FAILED(m_CmdAlias.ObtainAliasVerbDetails(
  1110. rParsedInfo)))
  1111. retCode = PARSER_ERRMSG;
  1112. }
  1113. else if (!ObtainClassMethods(rParsedInfo))
  1114. retCode = PARSER_ERRMSG;
  1115. }
  1116. }
  1117. else
  1118. {
  1119. BOOL bNamedParamList;
  1120. // Check for NamedParamList or UnnamedParamList.
  1121. if ( (theIterator + 1) < cvTokens.end() &&
  1122. CompareTokens(*(theIterator + 1), CLI_TOKEN_EQUALTO ) )
  1123. {
  1124. retCode = ParseSETorCREATEOrNamedParamInfo(cvTokens,
  1125. theIterator,
  1126. rParsedInfo,
  1127. CALLVerb);
  1128. if ( retCode == PARSER_EXECCOMMAND )
  1129. retCode = ValidateVerbOrMethodParams(rParsedInfo);
  1130. bNamedParamList = TRUE;
  1131. }
  1132. else
  1133. {
  1134. retCode = ParseUnnamedParamList(cvTokens, theIterator,
  1135. rParsedInfo);
  1136. bNamedParamList = FALSE;
  1137. }
  1138. rParsedInfo.GetCmdSwitchesObject().SetNamedParamListFlag(
  1139. bNamedParamList);
  1140. }
  1141. }
  1142. }
  1143. return retCode;
  1144. }
  1145. /*----------------------------------------------------------------------------
  1146. Name :ParseSETorCREATEVerb
  1147. Synopsis :This function parses the tokens following SET|CREATE verb
  1148. and updates the info in CParsedInfo object passed to it.
  1149. Type :Member Function
  1150. Input Parameter(s):
  1151. cvTokens - the tokens vector
  1152. theIterator - the Iterator to the cvTokens vector.
  1153. rParsedInfo - reference to CParsedInfo class object
  1154. HELPTYPE - helpType
  1155. Output Parameter(s):
  1156. rParsedInfo - reference to CParsedInfo class object
  1157. Return Type :RETCODE - enumerated data type
  1158. Global Variables :None
  1159. Calling Syntax :ParseSETorCREATEVerb(cvTokens,theIterator,rParsedInfo)
  1160. Notes :None
  1161. ----------------------------------------------------------------------------*/
  1162. RETCODE CParserEngine::ParseSETorCREATEVerb(CHARVECTOR& cvTokens,
  1163. CHARVECTOR::iterator& theIterator,
  1164. CParsedInfo& rParsedInfo,
  1165. HELPTYPE helpType)
  1166. {
  1167. RETCODE retCode = PARSER_EXECCOMMAND;
  1168. BOOL bContinue = TRUE;
  1169. try
  1170. {
  1171. retCode = GetNextToken(cvTokens, theIterator, rParsedInfo,
  1172. helpType, IDS_E_INCOMPLETE_COMMAND);
  1173. if (retCode == PARSER_CONTINUE)
  1174. {
  1175. if (IsOption(*theIterator))
  1176. {
  1177. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, helpType,
  1178. IDS_E_INVALID_COMMAND, LEVEL_ONE);
  1179. if (retCode == PARSER_DISPHELP)
  1180. {
  1181. if (m_bAliasName)
  1182. {
  1183. if (FAILED(m_CmdAlias.
  1184. ObtainAliasPropDetails(rParsedInfo)))
  1185. retCode = PARSER_ERRMSG;
  1186. }
  1187. else
  1188. {
  1189. if (!ObtainClassProperties(rParsedInfo))
  1190. retCode = PARSER_ERRMSG;
  1191. }
  1192. }
  1193. }
  1194. else
  1195. retCode = ParseSETorCREATEOrNamedParamInfo(cvTokens,
  1196. theIterator, rParsedInfo, helpType);
  1197. }
  1198. }
  1199. catch(_com_error& e)
  1200. {
  1201. retCode = PARSER_ERROR;
  1202. _com_issue_error(e.Error());
  1203. }
  1204. return retCode;
  1205. }
  1206. /*----------------------------------------------------------------------------
  1207. Name :ParseGETVerb
  1208. Synopsis :This function parses the tokens following the GET verb
  1209. and updates the info in CParsedInfo.
  1210. Type :Member Function
  1211. Input Parameter(s):
  1212. cvTokens - the tokens vector
  1213. theIterator - the Iterator to the cvTokens vector.
  1214. rParsedInfo - reference to CParsedInfo class object
  1215. Output Parameter(s):
  1216. rParsedInfo - reference to CParsedInfo class object
  1217. Return Type :RETCODE - enumerated data type
  1218. Global Variables :None
  1219. Calling Syntax :ParseGETVerb(cvTokens,theIterator,rParsedInfo)
  1220. Notes :None
  1221. ----------------------------------------------------------------------------*/
  1222. RETCODE CParserEngine::ParseGETVerb(CHARVECTOR& cvTokens,
  1223. CHARVECTOR::iterator& theIterator,
  1224. CParsedInfo& rParsedInfo)
  1225. {
  1226. BOOL bPropList = FALSE;
  1227. RETCODE retCode = PARSER_EXECCOMMAND;
  1228. BOOL bContinue = TRUE;
  1229. _TCHAR *pszNewEntry = NULL;
  1230. // Move to next token
  1231. if (!GetNextToken(cvTokens, theIterator))
  1232. {
  1233. // GET format | switches not specified.
  1234. retCode = PARSER_EXECCOMMAND;
  1235. }
  1236. else
  1237. {
  1238. BOOL bClass = FALSE;
  1239. if(IsClassOperation(rParsedInfo))
  1240. {
  1241. bClass = TRUE;
  1242. }
  1243. if(!bClass)
  1244. {
  1245. // Process the property list specified
  1246. if (!IsOption(*theIterator))
  1247. {
  1248. bPropList = TRUE;
  1249. // Obtain the list of properties specified.
  1250. while (TRUE)
  1251. {
  1252. // Add the property to the property vector of the
  1253. // CCommandSwitches object
  1254. if(!rParsedInfo.GetCmdSwitchesObject().
  1255. AddToPropertyList(*theIterator))
  1256. {
  1257. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  1258. IDS_E_ADD_TO_PROP_LIST_FAILURE);
  1259. bPropList = FALSE;
  1260. bContinue = FALSE;
  1261. retCode = PARSER_ERROR;
  1262. break;
  1263. }
  1264. // Move to next token
  1265. if (!GetNextToken(cvTokens, theIterator))
  1266. {
  1267. // set the return code as PARSER_EXECCOMMAND
  1268. // if no more tokens are present
  1269. retCode = PARSER_EXECCOMMAND;
  1270. bContinue = FALSE;
  1271. break;
  1272. }
  1273. // Check for the presence of ',' token
  1274. if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  1275. {
  1276. if (!GetNextToken(cvTokens, theIterator))
  1277. {
  1278. rParsedInfo.GetCmdSwitchesObject().
  1279. SetErrataCode(IDS_E_INVALID_EXPRESSION);
  1280. retCode = PARSER_ERROR;
  1281. bContinue = FALSE;
  1282. break;
  1283. }
  1284. }
  1285. else
  1286. break;
  1287. }
  1288. }
  1289. }
  1290. if (bContinue)
  1291. {
  1292. // alias|class get param1,param2... /getswitches
  1293. if (IsOption(*theIterator))
  1294. {
  1295. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, GETVerb,
  1296. IDS_E_INVALID_EXPRESSION, LEVEL_TWO);
  1297. if (retCode != PARSER_CONTINUE)
  1298. {
  1299. if (retCode == PARSER_DISPHELP)
  1300. {
  1301. if (m_bAliasName)
  1302. {
  1303. if (FAILED(m_CmdAlias.
  1304. ObtainAliasPropDetails(rParsedInfo)))
  1305. retCode = PARSER_ERRMSG;
  1306. }
  1307. else
  1308. {
  1309. if (!ObtainClassProperties(rParsedInfo))
  1310. retCode = PARSER_ERRMSG;
  1311. }
  1312. }
  1313. bContinue = FALSE;
  1314. }
  1315. if (bContinue)
  1316. retCode = ParseGETSwitches(cvTokens, theIterator,
  1317. rParsedInfo);
  1318. }
  1319. else
  1320. {
  1321. rParsedInfo.GetCmdSwitchesObject().
  1322. SetErrataCode(IDS_E_INVALID_GET_EXPRESSION);
  1323. retCode = PARSER_ERROR;
  1324. }
  1325. }
  1326. // If property names are specified then replace them with their
  1327. // derivations.
  1328. if ( retCode == PARSER_EXECCOMMAND )
  1329. {
  1330. if (m_bAliasName)
  1331. {
  1332. if (FAILED(m_CmdAlias.
  1333. ObtainAliasPropDetails(rParsedInfo)))
  1334. retCode = PARSER_ERRMSG;
  1335. }
  1336. else
  1337. {
  1338. if (!ObtainClassProperties(rParsedInfo))
  1339. retCode = PARSER_ERRMSG;
  1340. }
  1341. PROPDETMAP pdmPropDet = rParsedInfo.GetCmdSwitchesObject().
  1342. GetPropDetMap();
  1343. PROPDETMAP::iterator itrPropDet = NULL;
  1344. CHARVECTOR cvPropsSpecified = rParsedInfo.
  1345. GetCmdSwitchesObject().
  1346. GetPropertyList();
  1347. CHARVECTOR::iterator theIterator = NULL;
  1348. CHARVECTOR cvPropDerivations;
  1349. for ( theIterator = cvPropsSpecified.begin();
  1350. theIterator != cvPropsSpecified.end();
  1351. theIterator++ )
  1352. {
  1353. try
  1354. {
  1355. BOOL bFind = Find(pdmPropDet, *theIterator, itrPropDet);
  1356. _bstr_t bstrPropDerivation;
  1357. if ( bFind )
  1358. bstrPropDerivation = _bstr_t(
  1359. (*itrPropDet).second.Derivation);
  1360. else
  1361. bstrPropDerivation = _bstr_t(*theIterator);
  1362. _TCHAR* pszNewEntry =
  1363. new _TCHAR[bstrPropDerivation.length()+1];
  1364. if (pszNewEntry == NULL)
  1365. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  1366. lstrcpy(pszNewEntry, bstrPropDerivation);
  1367. cvPropDerivations.push_back(pszNewEntry);
  1368. }
  1369. catch(_com_error& e)
  1370. {
  1371. SAFEDELETE(pszNewEntry);
  1372. retCode = PARSER_ERROR;
  1373. CleanUpCharVector(cvPropDerivations);
  1374. _com_issue_error(e.Error());
  1375. }
  1376. }
  1377. rParsedInfo.GetCmdSwitchesObject().ClearPropertyList();
  1378. for ( theIterator = cvPropDerivations.begin();
  1379. theIterator != cvPropDerivations.end();
  1380. theIterator++ )
  1381. {
  1382. rParsedInfo.GetCmdSwitchesObject().
  1383. AddToPropertyList(*theIterator);
  1384. }
  1385. CleanUpCharVector(cvPropDerivations);
  1386. }
  1387. }
  1388. return retCode;
  1389. }
  1390. /*----------------------------------------------------------------------------
  1391. Name :ParseLISTVerb
  1392. Synopsis :This function parses the tokens following the LIST verb
  1393. and updates the info in CParsedInfo.
  1394. Type :Member Function
  1395. Input Parameter(s):
  1396. cvTokens - the tokens vector
  1397. theIterator - the Iterator to the cvTokens vector.
  1398. rParsedInfo - reference to CParsedInfo class object
  1399. Output Parameter(s) :
  1400. rParsedInfo - reference to CParsedInfo class object
  1401. Return Type :RETCODE - enumerated data type
  1402. Global Variables :None
  1403. Calling Syntax :ParseLISTVerb(cvTokens,theIterator,rParsedInfo)
  1404. Notes :None
  1405. ----------------------------------------------------------------------------*/
  1406. RETCODE CParserEngine::ParseLISTVerb(CHARVECTOR& cvTokens,
  1407. CHARVECTOR::iterator& theIterator,
  1408. CParsedInfo& rParsedInfo)
  1409. {
  1410. RETCODE retCode = PARSER_EXECCOMMAND;
  1411. BOOL bContinue = TRUE;
  1412. HRESULT hr = S_OK;
  1413. BOOL bSetDefaultFormat = TRUE;
  1414. // Set the default LIST format
  1415. if(!rParsedInfo.GetCmdSwitchesObject().SetListFormat(CLI_TOKEN_FULL))
  1416. {
  1417. rParsedInfo.GetCmdSwitchesObject().
  1418. SetErrataCode(OUT_OF_MEMORY);
  1419. retCode = PARSER_OUTOFMEMORY;
  1420. }
  1421. if (bContinue)
  1422. {
  1423. // If <list format> <list switches> specified.
  1424. if (GetNextToken(cvTokens, theIterator))
  1425. {
  1426. // Check for LIST formats (LIST formats are not preceded by '/')
  1427. if (!IsOption(*theIterator))
  1428. {
  1429. // If token is not followed by "/" or "-" then it is LIST format.
  1430. if(!rParsedInfo.GetCmdSwitchesObject().
  1431. SetListFormat(*theIterator))
  1432. {
  1433. rParsedInfo.GetCmdSwitchesObject().
  1434. SetErrataCode(OUT_OF_MEMORY);
  1435. retCode = PARSER_OUTOFMEMORY;
  1436. bContinue = FALSE;
  1437. }
  1438. // If list format explicitly specified then do not set
  1439. // default format.
  1440. bSetDefaultFormat = FALSE;
  1441. // Get all the properties from alias definition for the format
  1442. // specified
  1443. if (bContinue)
  1444. {
  1445. // no more tokens are present.
  1446. if (!GetNextToken(cvTokens, theIterator))
  1447. {
  1448. bContinue = FALSE;
  1449. retCode = PARSER_EXECCOMMAND;
  1450. }
  1451. else
  1452. rParsedInfo.GetHelpInfoObject().SetHelp(
  1453. LISTSwitchesOnly, TRUE);
  1454. }
  1455. }
  1456. if (bContinue == TRUE )
  1457. {
  1458. if ( IsOption(*theIterator) )
  1459. {
  1460. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, LISTVerb,
  1461. IDS_E_INVALID_EXPRESSION, LEVEL_TWO);
  1462. // If more tokens are present.
  1463. if (retCode == PARSER_CONTINUE)
  1464. {
  1465. BOOL bFormatSwitchSpecified;
  1466. // Parse for LIST switches.
  1467. retCode = ParseLISTSwitches(cvTokens, theIterator,
  1468. rParsedInfo,
  1469. bFormatSwitchSpecified);
  1470. // If /format is specified in list switches then
  1471. // do not set default format.
  1472. if ( bFormatSwitchSpecified == TRUE )
  1473. bSetDefaultFormat = FALSE;
  1474. }
  1475. else if ( retCode == PARSER_DISPHELP )
  1476. {
  1477. if ( rParsedInfo.GetHelpInfoObject().
  1478. GetHelp(LISTSwitchesOnly) == FALSE )
  1479. {
  1480. hr = m_CmdAlias.PopulateAliasFormatMap(
  1481. rParsedInfo);
  1482. ONFAILTHROWERROR(hr);
  1483. }
  1484. }
  1485. }
  1486. else
  1487. {
  1488. rParsedInfo.GetCmdSwitchesObject().
  1489. SetErrataCode(IDS_E_INVALID_LIST_EXPRESSION);
  1490. retCode = PARSER_ERROR;
  1491. }
  1492. }
  1493. }
  1494. }
  1495. if (retCode == PARSER_EXECCOMMAND)
  1496. {
  1497. // Obtain all properties from alias definition
  1498. if (!m_CmdAlias.ObtainAliasFormat(rParsedInfo))
  1499. {
  1500. // If failed to obtain the alias properties return PARSER_ERROR
  1501. if (rParsedInfo.GetCmdSwitchesObject().GetErrataCode() == 0)
  1502. {
  1503. rParsedInfo.GetCmdSwitchesObject().
  1504. SetErrataCode(IDS_E_INVALID_LIST_FORMAT);
  1505. }
  1506. retCode = PARSER_ERROR;
  1507. }
  1508. if ( bSetDefaultFormat == TRUE )
  1509. {
  1510. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  1511. XSLTDET xdXSLTDet;
  1512. g_wmiCmd.GetFileFromKey(CLI_TOKEN_TABLE, xdXSLTDet.FileName);
  1513. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet, rParsedInfo))
  1514. retCode = PARSER_ERRMSG;
  1515. }
  1516. }
  1517. return retCode;
  1518. }
  1519. /*----------------------------------------------------------------------------
  1520. Name :ParseASSOCVerb
  1521. Synopsis :This function parses the tokens following the ASSOC verb
  1522. and updates the info in CParsedInfo.
  1523. Type :Member Function
  1524. Input Parameter(s):
  1525. cvTokens - the tokens vector
  1526. theIterator - the Iterator to the cvTokens vector.
  1527. rParsedInfo - reference to CParsedInfo class object
  1528. Output Parameter(s):
  1529. rParsedInfo - reference to CParsedInfo class object
  1530. Return Type :RETCODE - enumerated data type
  1531. Global Variables :None
  1532. Calling Syntax :ParseASSOCVerb(cvTokens,theIterator,rParsedInfo)
  1533. Notes :None
  1534. ----------------------------------------------------------------------------*/
  1535. RETCODE CParserEngine::ParseASSOCVerb(CHARVECTOR& cvTokens,
  1536. CHARVECTOR::iterator& theIterator,
  1537. CParsedInfo& rParsedInfo)
  1538. {
  1539. RETCODE retCode = PARSER_EXECCOMMAND;
  1540. BOOL bContinue = TRUE;
  1541. // Move to next token
  1542. if (!GetNextToken(cvTokens, theIterator))
  1543. {
  1544. retCode = PARSER_EXECCOMMAND;
  1545. }
  1546. // If it is followed by a ":" <assoc format specifier is given
  1547. // Move to next token
  1548. else
  1549. {
  1550. if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  1551. {
  1552. // Move to next token
  1553. if (!GetNextToken(cvTokens, theIterator))
  1554. {
  1555. // PARSER_ERROR if <format specifier> is missing
  1556. rParsedInfo.GetCmdSwitchesObject().
  1557. SetErrataCode(IDS_E_INVALID_ASSOC_FORMATSPECIFIER);
  1558. retCode = PARSER_ERROR;
  1559. }
  1560. else if (IsOption(*theIterator))
  1561. {
  1562. rParsedInfo.GetCmdSwitchesObject().
  1563. SetErrataCode(IDS_E_INVALID_ASSOC_FORMATSPECIFIER);
  1564. retCode = PARSER_ERROR;
  1565. }
  1566. else
  1567. {
  1568. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  1569. BOOL bFrameXSLFile = TRUE;
  1570. XSLTDET xdXSLTDet;
  1571. xdXSLTDet.FileName = *theIterator;
  1572. if(!g_wmiCmd.GetFileFromKey(*theIterator, xdXSLTDet.FileName))
  1573. bFrameXSLFile = FALSE;
  1574. if ( bFrameXSLFile == TRUE )
  1575. {
  1576. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  1577. rParsedInfo))
  1578. retCode = PARSER_ERRMSG;
  1579. }
  1580. else
  1581. rParsedInfo.GetCmdSwitchesObject().
  1582. AddToXSLTDetailsVector(xdXSLTDet);
  1583. }
  1584. GetNextToken(cvTokens, theIterator);
  1585. rParsedInfo.GetHelpInfoObject().SetHelp(ASSOCSwitchesOnly, TRUE);
  1586. }///END for check of ":"
  1587. if ( retCode == PARSER_EXECCOMMAND &&
  1588. theIterator < cvTokens.end() )
  1589. {
  1590. if (IsOption(*theIterator))
  1591. {
  1592. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, ASSOCVerb,
  1593. IDS_E_INVALID_COMMAND,LEVEL_TWO);
  1594. // If more tokens are present.
  1595. if (retCode == PARSER_CONTINUE)
  1596. {
  1597. //Parse for Assoc switches.
  1598. retCode = ParseAssocSwitches(cvTokens, theIterator,
  1599. rParsedInfo);
  1600. }
  1601. }
  1602. else
  1603. {
  1604. rParsedInfo.GetCmdSwitchesObject().
  1605. SetErrataCode(IDS_E_INVALID_ASSOC_SYNTAX);
  1606. retCode = PARSER_ERROR;
  1607. }
  1608. }
  1609. }
  1610. return retCode;
  1611. }
  1612. /*----------------------------------------------------------------------------
  1613. Name :ParseCALLVerb
  1614. Synopsis :This function parses the tokens following the CALL verb
  1615. and updates the info in CParsedInfo.
  1616. Type :Member Function
  1617. Input Parameter(s):
  1618. cvTokens - the tokens vector
  1619. theIterator - the Iterator to the cvTokens vector.
  1620. rParsedInfo - reference to CParsedInfo class object
  1621. Output Parameter(s):
  1622. rParsedInfo - reference to CParsedInfo class object
  1623. Return Type :RETCODE - enumerated data type
  1624. Global Variables :None
  1625. Calling Syntax :ParseCALLVerb(cvTokens,theIterator,rParsedInfo)
  1626. Notes :None
  1627. ----------------------------------------------------------------------------*/
  1628. RETCODE CParserEngine::ParseCALLVerb(CHARVECTOR& cvTokens,
  1629. CHARVECTOR::iterator& theIterator,
  1630. CParsedInfo& rParsedInfo)
  1631. {
  1632. RETCODE retCode = PARSER_EXECCOMMAND;
  1633. BOOL bContinue = TRUE;
  1634. // Move to next token
  1635. retCode = GetNextToken(cvTokens, theIterator, rParsedInfo,
  1636. CALLVerb, IDS_E_INCOMPLETE_COMMAND);
  1637. if (retCode == PARSER_CONTINUE)
  1638. {
  1639. if (IsOption(*theIterator))
  1640. {
  1641. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, CALLVerb,
  1642. IDS_E_INVALID_EXPRESSION, LEVEL_TWO);
  1643. if (retCode != PARSER_CONTINUE)
  1644. {
  1645. if (retCode == PARSER_DISPHELP)
  1646. {
  1647. if(m_bAliasName)
  1648. {
  1649. if (FAILED(m_CmdAlias.ObtainAliasVerbDetails(rParsedInfo)))
  1650. retCode = PARSER_ERRMSG;
  1651. }
  1652. else
  1653. {
  1654. if (!ObtainClassMethods(rParsedInfo))
  1655. retCode = PARSER_ERRMSG;
  1656. }
  1657. }
  1658. }
  1659. else
  1660. {
  1661. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  1662. IDS_E_VERB_OR_METHOD_NOT_SPECIFIED);
  1663. retCode = PARSER_ERROR;
  1664. /* theIterator = theIterator-2;
  1665. retCode = PARSER_EXECCOMMAND;
  1666. */ }
  1667. }
  1668. else
  1669. {
  1670. retCode = ParseMethodInfo(cvTokens, theIterator, rParsedInfo);
  1671. if (retCode == PARSER_CONTINUE)
  1672. retCode = PARSER_EXECCOMMAND;
  1673. }
  1674. }
  1675. else if (retCode == PARSER_DISPHELP)
  1676. {
  1677. if(m_bAliasName)
  1678. {
  1679. if (FAILED(m_CmdAlias.ObtainAliasVerbDetails(rParsedInfo)))
  1680. retCode = PARSER_ERRMSG;
  1681. }
  1682. else
  1683. {
  1684. if (!ObtainClassMethods(rParsedInfo))
  1685. retCode = PARSER_ERRMSG;
  1686. }
  1687. }
  1688. return retCode;
  1689. }
  1690. /*----------------------------------------------------------------------------
  1691. Name :ParseGlobalSwitches
  1692. Synopsis :This function does the parsing and interprets if command
  1693. has global switches specified in it. It parses the
  1694. remaining tokens following and updates the same in
  1695. CParsedInfo.
  1696. Type :Member Function
  1697. Input Parameter(s):
  1698. cvTokens - the tokens vector
  1699. theIterator - the Iterator to the cvTokens vector.
  1700. rParsedInfo - reference to CParsedInfo class object
  1701. Output Parameter(s):
  1702. rParsedInfo - reference to CParsedInfo class object
  1703. Return Type :RETCODE - enumerated data type
  1704. Global Variables :None
  1705. Calling Syntax :ParseGlobalSwitches(cvTokens,theIterator,rParsedInfo)
  1706. Notes :None
  1707. ----------------------------------------------------------------------------*/
  1708. RETCODE CParserEngine::ParseGlobalSwitches(CHARVECTOR& cvTokens,
  1709. CHARVECTOR::iterator& theIterator,
  1710. CParsedInfo &rParsedInfo)
  1711. {
  1712. RETCODE retCode = PARSER_CONTINUE;
  1713. BOOL bContinue = TRUE;
  1714. BOOL bPassFlag = FALSE;
  1715. BOOL bUserFlag = FALSE;
  1716. BOOL bOpenOutFileInWriteMode = FALSE;
  1717. while (TRUE)
  1718. {
  1719. // Move to next token
  1720. retCode = GetNextToken(cvTokens, theIterator, rParsedInfo,
  1721. IDS_E_INVALID_GLOBAL_SWITCH);
  1722. if (retCode != PARSER_CONTINUE)
  1723. break;
  1724. // Check for the presence of NAMESPACE global switch
  1725. if (CompareTokens(*theIterator, CLI_TOKEN_NAMESPACE))
  1726. {
  1727. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  1728. IDS_E_INCORRECT_NAMESPACE,
  1729. rParsedInfo,
  1730. IDS_E_INVALID_NAMESPACE_SYNTAX,
  1731. Namespace);
  1732. if (retCode == PARSER_CONTINUE)
  1733. {
  1734. LONG lPresNamespaceLen =
  1735. lstrlen(rParsedInfo.GetGlblSwitchesObject().GetNameSpace());
  1736. LONG lUserInputNamespaceLen = lstrlen(*theIterator);
  1737. _TCHAR *pszNamespaceToBeUpdated = new _TCHAR[
  1738. // +2 for '\' and '\0'
  1739. lUserInputNamespaceLen + lPresNamespaceLen + 2];
  1740. if (pszNamespaceToBeUpdated == NULL)
  1741. throw OUT_OF_MEMORY;
  1742. lstrcpy(pszNamespaceToBeUpdated,
  1743. rParsedInfo.GetGlblSwitchesObject().GetNameSpace());
  1744. FrameNamespace(*theIterator, pszNamespaceToBeUpdated);
  1745. if (!CompareTokens(pszNamespaceToBeUpdated, CLI_TOKEN_NULL) &&
  1746. rParsedInfo.GetGlblSwitchesObject().
  1747. GetInteractiveStatus() == TRUE)
  1748. {
  1749. if (!ValidateNodeOrNS(pszNamespaceToBeUpdated, FALSE))
  1750. {
  1751. rParsedInfo.GetCmdSwitchesObject().
  1752. SetErrataCode(IDS_E_INVALID_NAMESPACE);
  1753. retCode = PARSER_ERROR;
  1754. break;
  1755. }
  1756. }
  1757. if(!rParsedInfo.GetGlblSwitchesObject().
  1758. SetNameSpace(pszNamespaceToBeUpdated))
  1759. {
  1760. rParsedInfo.GetCmdSwitchesObject().
  1761. SetErrataCode(OUT_OF_MEMORY);
  1762. retCode = PARSER_OUTOFMEMORY;
  1763. break;
  1764. }
  1765. SAFEDELETE(pszNamespaceToBeUpdated);
  1766. }
  1767. else
  1768. break;
  1769. }
  1770. // Check for the presence of ROLE global switch
  1771. else if (CompareTokens(*theIterator, CLI_TOKEN_ROLE))
  1772. {
  1773. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  1774. IDS_E_INVALID_ROLE,
  1775. rParsedInfo,
  1776. IDS_E_INVALID_ROLE_SYNTAX,
  1777. Role);
  1778. if (retCode == PARSER_CONTINUE)
  1779. {
  1780. LONG lPresRoleLen =
  1781. lstrlen(rParsedInfo.GetGlblSwitchesObject().GetRole());
  1782. LONG lUserInputRoleLen = lstrlen(*theIterator);
  1783. _TCHAR *pszRoleToBeUpdated = new _TCHAR[
  1784. // +2 one for '\' and one for '\0'
  1785. lPresRoleLen + lUserInputRoleLen + 2];
  1786. if (pszRoleToBeUpdated == NULL)
  1787. throw OUT_OF_MEMORY;
  1788. lstrcpy(pszRoleToBeUpdated,
  1789. rParsedInfo.GetGlblSwitchesObject().GetRole());
  1790. FrameNamespace(*theIterator, pszRoleToBeUpdated);
  1791. if (!CompareTokens(pszRoleToBeUpdated, CLI_TOKEN_NULL) &&
  1792. rParsedInfo.GetGlblSwitchesObject().
  1793. GetInteractiveStatus() == TRUE)
  1794. {
  1795. if (!ValidateNodeOrNS(pszRoleToBeUpdated, FALSE))
  1796. {
  1797. rParsedInfo.GetCmdSwitchesObject().
  1798. SetErrataCode(IDS_E_INVALID_ROLE);
  1799. retCode = PARSER_ERROR;
  1800. break;
  1801. }
  1802. }
  1803. if(!rParsedInfo.GetGlblSwitchesObject().
  1804. SetRole(pszRoleToBeUpdated))
  1805. {
  1806. rParsedInfo.GetCmdSwitchesObject().
  1807. SetErrataCode(OUT_OF_MEMORY);
  1808. retCode = PARSER_OUTOFMEMORY;
  1809. break;
  1810. }
  1811. SAFEDELETE(pszRoleToBeUpdated);
  1812. }
  1813. else
  1814. break;
  1815. }
  1816. else if (CompareTokens(*theIterator, CLI_TOKEN_NODE))
  1817. {
  1818. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  1819. IDS_E_INVALID_MACHINE_NAME,
  1820. rParsedInfo,
  1821. IDS_E_INVALID_NODE_SYNTAX,
  1822. Node);
  1823. if (retCode == PARSER_CONTINUE)
  1824. {
  1825. BOOL bBreakOuterLoop = FALSE;
  1826. BOOL bGetValidNode = FALSE;
  1827. BOOL bNodeListCleared = FALSE;
  1828. while ( TRUE )
  1829. {
  1830. try
  1831. {
  1832. CHString chsNodeName(*theIterator);
  1833. chsNodeName.TrimLeft();
  1834. chsNodeName.TrimRight();
  1835. lstrcpy(*theIterator, (LPCWSTR) chsNodeName);
  1836. }
  1837. catch(CHeap_Exception)
  1838. {
  1839. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  1840. }
  1841. if ( *theIterator[0] == _T('@') )
  1842. {
  1843. retCode = ParseNodeListFile(cvTokens, theIterator,
  1844. rParsedInfo);
  1845. if ( retCode != PARSER_CONTINUE )
  1846. {
  1847. bBreakOuterLoop = TRUE;
  1848. break;
  1849. }
  1850. }
  1851. // If interactive mode then check for the validity of
  1852. // nodes
  1853. if(rParsedInfo.GetGlblSwitchesObject().
  1854. GetInteractiveStatus())
  1855. {
  1856. BOOL bNodeExist = TRUE;
  1857. if ( rParsedInfo.GetGlblSwitchesObject().
  1858. GetFailFast() == TRUE )
  1859. {
  1860. bNodeExist =
  1861. IsFailFastAndNodeExist(rParsedInfo, *theIterator);
  1862. }
  1863. else
  1864. bNodeExist = ValidateNodeOrNS(*theIterator, TRUE);
  1865. if( bNodeExist == FALSE)
  1866. {
  1867. // Display error message for invalid node
  1868. DisplayString(IDS_E_INVALID_NODE,
  1869. ::GetOEMCP(), *theIterator, TRUE);
  1870. if ( !GetNextToken(cvTokens, theIterator))
  1871. {
  1872. // If no more tokens are present then stop
  1873. // further processing
  1874. bBreakOuterLoop = TRUE;
  1875. break;
  1876. }
  1877. else
  1878. {
  1879. // If multiple nodes are defined then check
  1880. // tokens
  1881. if (CompareTokens(*theIterator,
  1882. CLI_TOKEN_COMMA))
  1883. {
  1884. // If invalid node syntax given then report
  1885. // error
  1886. if ( !GetNextToken(cvTokens, theIterator) )
  1887. {
  1888. rParsedInfo.GetCmdSwitchesObject().
  1889. SetErrataCode(IDS_E_INVALID_NODE_SYNTAX);
  1890. retCode=PARSER_ERROR;
  1891. bBreakOuterLoop = TRUE;
  1892. break;
  1893. }
  1894. else if ( IsOption (*theIterator) )
  1895. {
  1896. rParsedInfo.GetCmdSwitchesObject().
  1897. SetErrataCode(IDS_E_INVALID_NODE_SYNTAX);
  1898. retCode=PARSER_ERROR;
  1899. bBreakOuterLoop = TRUE;
  1900. break;
  1901. }
  1902. //Skip adding this invalid node to node list
  1903. continue;
  1904. }
  1905. else
  1906. {
  1907. // If no more node present
  1908. theIterator--;
  1909. break;
  1910. }
  1911. }
  1912. }
  1913. else
  1914. // Set flag for valid node
  1915. bGetValidNode = TRUE;
  1916. // If valid node(s) are present and list is not
  1917. // already cleared then clear it
  1918. if(bGetValidNode && !bNodeListCleared)
  1919. {
  1920. if (!rParsedInfo.GetGlblSwitchesObject().
  1921. ClearNodesList())
  1922. {
  1923. rParsedInfo.GetCmdSwitchesObject().
  1924. SetErrataCode(OUT_OF_MEMORY);
  1925. retCode = PARSER_OUTOFMEMORY;
  1926. break;
  1927. }
  1928. bNodeListCleared = TRUE;
  1929. }
  1930. }
  1931. else if( bNodeListCleared == FALSE )
  1932. {
  1933. // If not in interactive mode then clear
  1934. // previous node list
  1935. if (!rParsedInfo.GetGlblSwitchesObject().
  1936. ClearNodesList())
  1937. {
  1938. rParsedInfo.GetCmdSwitchesObject().
  1939. SetErrataCode(OUT_OF_MEMORY);
  1940. retCode = PARSER_OUTOFMEMORY;
  1941. break;
  1942. }
  1943. bNodeListCleared = TRUE;
  1944. }
  1945. if (rParsedInfo.GetGlblSwitchesObject().
  1946. AddToNodesList(*theIterator))
  1947. {
  1948. if ( GetNextToken(cvTokens, theIterator) )
  1949. {
  1950. if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  1951. {
  1952. if ( !GetNextToken(cvTokens, theIterator) )
  1953. {
  1954. rParsedInfo.GetCmdSwitchesObject().
  1955. SetErrataCode(IDS_E_INVALID_NODE_SYNTAX);
  1956. retCode=PARSER_ERROR;
  1957. bBreakOuterLoop = TRUE;
  1958. }
  1959. else if ( IsOption (*theIterator) )
  1960. {
  1961. rParsedInfo.GetCmdSwitchesObject().
  1962. SetErrataCode(IDS_E_INVALID_NODE_SYNTAX);
  1963. retCode=PARSER_ERROR;
  1964. bBreakOuterLoop = TRUE;
  1965. }
  1966. }
  1967. else
  1968. {
  1969. theIterator--;
  1970. break;
  1971. }
  1972. }
  1973. else
  1974. bBreakOuterLoop = TRUE;
  1975. }
  1976. else
  1977. {
  1978. rParsedInfo.GetCmdSwitchesObject().
  1979. SetErrataCode(OUT_OF_MEMORY);
  1980. retCode = PARSER_OUTOFMEMORY;
  1981. bBreakOuterLoop = FALSE;
  1982. }
  1983. if ( bBreakOuterLoop == TRUE )
  1984. break;
  1985. }
  1986. if ( bBreakOuterLoop == TRUE )
  1987. break;
  1988. }
  1989. else
  1990. break;
  1991. }
  1992. else if (CompareTokens(*theIterator, CLI_TOKEN_IMPLEVEL))
  1993. {
  1994. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  1995. IDS_E_INVALID_IMP_LEVEL,
  1996. rParsedInfo,
  1997. IDS_E_INVALID_IMP_LEVEL_SYNTAX,
  1998. Level);
  1999. if (retCode == PARSER_CONTINUE)
  2000. {
  2001. if (!rParsedInfo.GetGlblSwitchesObject().
  2002. SetImpersonationLevel(*theIterator))
  2003. {
  2004. rParsedInfo.GetCmdSwitchesObject().
  2005. SetErrataCode(IDS_E_INVALID_IMP_LEVEL);
  2006. retCode = PARSER_ERROR;
  2007. break;
  2008. }
  2009. }
  2010. else
  2011. break;
  2012. }
  2013. else if (CompareTokens(*theIterator, CLI_TOKEN_AUTHLEVEL))
  2014. {
  2015. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2016. IDS_E_INVALID_AUTH_LEVEL,
  2017. rParsedInfo,
  2018. IDS_E_INVALID_AUTH_LEVEL_SYNTAX,
  2019. AuthLevel);
  2020. if (retCode == PARSER_CONTINUE)
  2021. {
  2022. if (!rParsedInfo.GetGlblSwitchesObject().
  2023. SetAuthenticationLevel(*theIterator))
  2024. {
  2025. rParsedInfo.GetCmdSwitchesObject().
  2026. SetErrataCode(IDS_E_INVALID_AUTH_LEVEL);
  2027. retCode = PARSER_ERROR;
  2028. break;
  2029. }
  2030. }
  2031. else
  2032. break;
  2033. }
  2034. else if (CompareTokens(*theIterator, CLI_TOKEN_LOCALE))
  2035. {
  2036. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2037. IDS_E_INVALID_LOCALE,
  2038. rParsedInfo,
  2039. IDS_E_INVALID_LOCALE_SYNTAX,
  2040. Locale);
  2041. if (retCode == PARSER_CONTINUE)
  2042. {
  2043. if(!rParsedInfo.GetGlblSwitchesObject().SetLocale(*theIterator))
  2044. {
  2045. rParsedInfo.GetCmdSwitchesObject().
  2046. SetErrataCode(OUT_OF_MEMORY);
  2047. retCode = PARSER_OUTOFMEMORY;
  2048. break;
  2049. }
  2050. }
  2051. else
  2052. break;
  2053. }
  2054. else if (CompareTokens(*theIterator, CLI_TOKEN_PRIVILEGES))
  2055. {
  2056. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2057. IDS_E_INVALID_PRIVILEGES_OPTION,
  2058. rParsedInfo,
  2059. IDS_E_INVALID_PRIVILEGES_SYNTAX,
  2060. Privileges);
  2061. if (retCode == PARSER_CONTINUE)
  2062. {
  2063. if (CompareTokens(*theIterator, CLI_TOKEN_ENABLE))
  2064. rParsedInfo.GetGlblSwitchesObject().SetPrivileges(TRUE);
  2065. else if (CompareTokens(*theIterator, CLI_TOKEN_DISABLE))
  2066. rParsedInfo.GetGlblSwitchesObject().SetPrivileges(FALSE);
  2067. else
  2068. {
  2069. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2070. IDS_E_INVALID_PRIVILEGES_OPTION);
  2071. retCode = PARSER_ERROR;
  2072. break;
  2073. }
  2074. }
  2075. else
  2076. break;
  2077. }
  2078. else if (CompareTokens(*theIterator, CLI_TOKEN_TRACE))
  2079. {
  2080. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2081. IDS_E_INVALID_TRACE_OPTION,
  2082. rParsedInfo,
  2083. IDS_E_INVALID_TRACE_SYNTAX,
  2084. Trace);
  2085. if (retCode == PARSER_CONTINUE)
  2086. {
  2087. if (CompareTokens(*theIterator, CLI_TOKEN_ON))
  2088. rParsedInfo.GetGlblSwitchesObject().SetTraceMode(TRUE);
  2089. else if (CompareTokens(*theIterator, CLI_TOKEN_OFF))
  2090. rParsedInfo.GetGlblSwitchesObject().SetTraceMode(FALSE);
  2091. else
  2092. {
  2093. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2094. IDS_E_INVALID_TRACE_OPTION);
  2095. retCode = PARSER_ERROR;
  2096. break;
  2097. }
  2098. }
  2099. else
  2100. break;
  2101. }
  2102. else if (CompareTokens(*theIterator, CLI_TOKEN_RECORD))
  2103. {
  2104. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2105. IDS_E_INVALID_RECORD_PATH,
  2106. rParsedInfo,
  2107. IDS_E_INVALID_RECORD_SYNTAX,
  2108. RecordPath);
  2109. if (retCode == PARSER_CONTINUE)
  2110. {
  2111. // TRUE for getting output file name.
  2112. _TCHAR* pszOutputFileName = rParsedInfo.
  2113. GetGlblSwitchesObject().
  2114. GetOutputOrAppendFileName(TRUE);
  2115. if ( pszOutputFileName != NULL &&
  2116. CompareTokens(*theIterator, pszOutputFileName) )
  2117. {
  2118. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2119. IDS_E_RECORD_FILE_ALREADY_OPEN_FOR_OUTPUT);
  2120. retCode = PARSER_ERROR;
  2121. break;
  2122. }
  2123. // FALSE for getting append file name.
  2124. _TCHAR* pszAppendFileName = rParsedInfo.
  2125. GetGlblSwitchesObject().
  2126. GetOutputOrAppendFileName(FALSE);
  2127. if ( pszAppendFileName != NULL &&
  2128. CompareTokens(*theIterator, pszAppendFileName) )
  2129. {
  2130. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2131. IDS_E_RECORD_FILE_ALREADY_OPEN_FOR_APPEND);
  2132. retCode = PARSER_ERROR;
  2133. break;
  2134. }
  2135. // /record:"" indicates stop logging.
  2136. if (!CompareTokens(*theIterator, CLI_TOKEN_NULL))
  2137. {
  2138. if ( IsValidFile(*theIterator) == FALSE )
  2139. {
  2140. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2141. IDS_E_INVALID_FILENAME);
  2142. retCode = PARSER_ERROR;
  2143. break;
  2144. }
  2145. }
  2146. if(!rParsedInfo.GetGlblSwitchesObject().
  2147. SetRecordPath(*theIterator))
  2148. {
  2149. rParsedInfo.GetCmdSwitchesObject().
  2150. SetErrataCode(OUT_OF_MEMORY);
  2151. retCode = PARSER_OUTOFMEMORY;
  2152. break;
  2153. }
  2154. }
  2155. else
  2156. break;
  2157. }
  2158. else if (CompareTokens(*theIterator, CLI_TOKEN_INTERACTIVE))
  2159. {
  2160. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2161. IDS_E_INVALID_INTERACTIVE_OPTION,
  2162. rParsedInfo,
  2163. IDS_E_INVALID_INTERACTIVE_SYNTAX,
  2164. Interactive);
  2165. if (retCode == PARSER_CONTINUE)
  2166. {
  2167. if (CompareTokens(*theIterator, CLI_TOKEN_ON))
  2168. {
  2169. if (rParsedInfo.GetGlblSwitchesObject().GetInteractiveStatus())
  2170. {
  2171. rParsedInfo.GetCmdSwitchesObject().
  2172. SetInformationCode(IDS_I_INTERACTIVE_ALREADY_SET);
  2173. }
  2174. else
  2175. rParsedInfo.GetCmdSwitchesObject().
  2176. SetInformationCode(IDS_I_INTERACTIVE_SET);
  2177. rParsedInfo.GetGlblSwitchesObject().SetInteractiveMode(TRUE);
  2178. }
  2179. else if (CompareTokens(*theIterator, CLI_TOKEN_OFF))
  2180. {
  2181. if (!rParsedInfo.GetGlblSwitchesObject().GetInteractiveStatus())
  2182. {
  2183. rParsedInfo.GetCmdSwitchesObject().
  2184. SetInformationCode(IDS_I_INTERACTIVE_ALREADY_RESET);
  2185. }
  2186. else
  2187. rParsedInfo.GetCmdSwitchesObject().
  2188. SetInformationCode(IDS_I_INTERACTIVE_RESET);
  2189. rParsedInfo.GetGlblSwitchesObject().SetInteractiveMode(FALSE);
  2190. }
  2191. else
  2192. {
  2193. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2194. IDS_E_INVALID_INTERACTIVE_OPTION);
  2195. retCode = PARSER_ERROR;
  2196. break;
  2197. }
  2198. }
  2199. else
  2200. break;
  2201. }
  2202. else if (CompareTokens(*theIterator, CLI_TOKEN_FAILFAST))
  2203. {
  2204. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2205. IDS_E_INVALID_FAILFAST_OPTION,
  2206. rParsedInfo,
  2207. IDS_E_INVALID_FAILFAST_SYNTAX,
  2208. FAILFAST);
  2209. if (retCode == PARSER_CONTINUE)
  2210. {
  2211. if (CompareTokens(*theIterator, CLI_TOKEN_ON))
  2212. {
  2213. if (rParsedInfo.GetGlblSwitchesObject().GetFailFast())
  2214. {
  2215. rParsedInfo.GetCmdSwitchesObject().
  2216. SetInformationCode(IDS_I_FAILFAST_ALREADY_SET);
  2217. }
  2218. else
  2219. rParsedInfo.GetCmdSwitchesObject().
  2220. SetInformationCode(IDS_I_FAILFAST_SET);
  2221. rParsedInfo.GetGlblSwitchesObject().SetFailFast(TRUE);
  2222. }
  2223. else if (CompareTokens(*theIterator, CLI_TOKEN_OFF))
  2224. {
  2225. if (!rParsedInfo.GetGlblSwitchesObject().GetFailFast())
  2226. {
  2227. rParsedInfo.GetCmdSwitchesObject().
  2228. SetInformationCode(IDS_I_FAILFAST_ALREADY_RESET);
  2229. }
  2230. else
  2231. rParsedInfo.GetCmdSwitchesObject().
  2232. SetInformationCode(IDS_I_FAILFAST_RESET);
  2233. rParsedInfo.GetGlblSwitchesObject().SetFailFast(FALSE);
  2234. }
  2235. else
  2236. {
  2237. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2238. IDS_E_INVALID_FAILFAST_OPTION);
  2239. retCode = PARSER_ERROR;
  2240. break;
  2241. }
  2242. }
  2243. else
  2244. break;
  2245. }
  2246. else if (CompareTokens(*theIterator, CLI_TOKEN_USER))
  2247. {
  2248. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2249. IDS_E_INVALID_USER_ID,
  2250. rParsedInfo,
  2251. IDS_E_INVALID_USER_SYNTAX,
  2252. User);
  2253. if (retCode == PARSER_CONTINUE)
  2254. {
  2255. if(!rParsedInfo.GetGlblSwitchesObject().SetUser(*theIterator))
  2256. {
  2257. rParsedInfo.GetCmdSwitchesObject().
  2258. SetErrataCode(OUT_OF_MEMORY);
  2259. retCode = PARSER_OUTOFMEMORY;
  2260. break;
  2261. }
  2262. bUserFlag = TRUE;
  2263. }
  2264. else
  2265. break;
  2266. }
  2267. else if (CompareTokens(*theIterator, CLI_TOKEN_PASSWORD))
  2268. {
  2269. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2270. IDS_E_INVALID_PASSWORD,
  2271. rParsedInfo,
  2272. IDS_E_INVALID_PASSWORD_SYNTAX,
  2273. Password);
  2274. if (retCode == PARSER_CONTINUE)
  2275. {
  2276. if(!rParsedInfo.GetGlblSwitchesObject().SetPassword(*theIterator))
  2277. {
  2278. rParsedInfo.GetCmdSwitchesObject().
  2279. SetErrataCode(OUT_OF_MEMORY);
  2280. retCode=PARSER_OUTOFMEMORY;
  2281. break;
  2282. }
  2283. bPassFlag = TRUE;
  2284. }
  2285. else
  2286. break;
  2287. }
  2288. else if (CompareTokens(*theIterator, CLI_TOKEN_OUTPUT))
  2289. {
  2290. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2291. IDS_E_INVALID_OUTPUT_OPTION,
  2292. rParsedInfo,
  2293. IDS_E_INVALID_OUTPUT_SYNTAX,
  2294. OUTPUT);
  2295. if (retCode == PARSER_CONTINUE)
  2296. {
  2297. rParsedInfo.GetCmdSwitchesObject().SetOutputSwitchFlag(TRUE);
  2298. if (CompareTokens(*theIterator, CLI_TOKEN_STDOUT))
  2299. {
  2300. // TRUE for setting output file.
  2301. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(
  2302. STDOUT, TRUE);
  2303. rParsedInfo.GetGlblSwitchesObject().
  2304. SetOutputOrAppendFileName(NULL, TRUE);
  2305. }
  2306. else if (CompareTokens(*theIterator, CLI_TOKEN_CLIPBOARD))
  2307. {
  2308. // TRUE for setting output file.
  2309. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(
  2310. CLIPBOARD, TRUE);
  2311. rParsedInfo.GetGlblSwitchesObject().
  2312. SetOutputOrAppendFileName(NULL, TRUE);
  2313. }
  2314. else if ( CompareTokens(*theIterator, CLI_TOKEN_NULL))
  2315. {
  2316. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2317. IDS_E_INVALID_FILENAME);
  2318. retCode = PARSER_ERROR;
  2319. break;
  2320. }
  2321. else
  2322. {
  2323. // FALSE for getting append file name.
  2324. _TCHAR* pszAppendFileName = rParsedInfo.
  2325. GetGlblSwitchesObject().
  2326. GetOutputOrAppendFileName(FALSE);
  2327. if ( pszAppendFileName != NULL &&
  2328. CompareTokens(*theIterator, pszAppendFileName) )
  2329. {
  2330. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2331. IDS_E_OUTPUT_FILE_ALREADY_OPEN_FOR_APPEND);
  2332. retCode = PARSER_ERROR;
  2333. break;
  2334. }
  2335. _TCHAR* pszRecordFileName = rParsedInfo.
  2336. GetGlblSwitchesObject().
  2337. GetRecordPath();
  2338. if ( pszRecordFileName != NULL &&
  2339. CompareTokens(*theIterator, pszRecordFileName) )
  2340. {
  2341. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2342. IDS_E_OUTPUT_FILE_ALREADY_OPEN_FOR_RECORD);
  2343. retCode = PARSER_ERROR;
  2344. break;
  2345. }
  2346. if ( CloseOutputFile() == TRUE )
  2347. {
  2348. // TRUE for getting output file name.
  2349. _TCHAR* pszOutputFileName = rParsedInfo.
  2350. GetGlblSwitchesObject().
  2351. GetOutputOrAppendFileName(TRUE);
  2352. if ( pszOutputFileName == NULL ||
  2353. ( pszOutputFileName != NULL &&
  2354. !CompareTokens(*theIterator, pszOutputFileName)))
  2355. {
  2356. retCode = IsValidFile(*theIterator);
  2357. if ( retCode == PARSER_ERROR )
  2358. {
  2359. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2360. IDS_E_INVALID_FILENAME);
  2361. break;
  2362. }
  2363. else if ( retCode == PARSER_ERRMSG )
  2364. break;
  2365. }
  2366. }
  2367. else
  2368. {
  2369. retCode = PARSER_ERRMSG;
  2370. break;
  2371. }
  2372. // TRUE for setting output file.
  2373. if(!rParsedInfo.GetGlblSwitchesObject().
  2374. SetOutputOrAppendFileName(*theIterator, TRUE))
  2375. {
  2376. rParsedInfo.GetCmdSwitchesObject().
  2377. SetErrataCode(OUT_OF_MEMORY);
  2378. retCode=PARSER_OUTOFMEMORY;
  2379. break;
  2380. }
  2381. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(FILEOUTPUT,
  2382. TRUE);
  2383. bOpenOutFileInWriteMode = TRUE;
  2384. }
  2385. }
  2386. else
  2387. break;
  2388. }
  2389. else if (CompareTokens(*theIterator, CLI_TOKEN_APPEND))
  2390. {
  2391. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2392. IDS_E_INVALID_APPEND_OPTION,
  2393. rParsedInfo,
  2394. IDS_E_INVALID_APPEND_SYNTAX,
  2395. APPEND);
  2396. if (retCode == PARSER_CONTINUE)
  2397. {
  2398. if ( CompareTokens(*theIterator, CLI_TOKEN_STDOUT) )
  2399. {
  2400. // FALSE for setting append file.
  2401. rParsedInfo.GetGlblSwitchesObject().
  2402. SetOutputOrAppendFileName(NULL, FALSE);
  2403. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(STDOUT,
  2404. FALSE);
  2405. }
  2406. else if ( CompareTokens(*theIterator, CLI_TOKEN_CLIPBOARD) )
  2407. {
  2408. // FALSE for setting append file.
  2409. rParsedInfo.GetGlblSwitchesObject().
  2410. SetOutputOrAppendFileName(NULL, FALSE);
  2411. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(CLIPBOARD,
  2412. FALSE);
  2413. }
  2414. else if ( CompareTokens(*theIterator, CLI_TOKEN_NULL))
  2415. {
  2416. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2417. IDS_E_INVALID_FILENAME);
  2418. retCode = PARSER_ERROR;
  2419. break;
  2420. }
  2421. else
  2422. {
  2423. // TRUE for getting output file name.
  2424. _TCHAR* pszOutputFileName = rParsedInfo.
  2425. GetGlblSwitchesObject().
  2426. GetOutputOrAppendFileName(TRUE);
  2427. if ( pszOutputFileName != NULL &&
  2428. CompareTokens(*theIterator, pszOutputFileName) )
  2429. {
  2430. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2431. IDS_E_APPEND_FILE_ALREADY_OPEN_FOR_OUTPUT);
  2432. retCode = PARSER_ERROR;
  2433. break;
  2434. }
  2435. _TCHAR* pszRecordFileName = rParsedInfo.
  2436. GetGlblSwitchesObject().
  2437. GetRecordPath();
  2438. if ( pszRecordFileName != NULL &&
  2439. CompareTokens(*theIterator, pszRecordFileName) )
  2440. {
  2441. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2442. IDS_E_APPEND_FILE_ALREADY_OPEN_FOR_RECORD);
  2443. retCode = PARSER_ERROR;
  2444. break;
  2445. }
  2446. if ( CloseAppendFile() == TRUE )
  2447. {
  2448. // FALSE for getting append file name.
  2449. _TCHAR* pszAppendFileName = rParsedInfo.
  2450. GetGlblSwitchesObject().
  2451. GetOutputOrAppendFileName(FALSE);
  2452. if ( pszAppendFileName == NULL ||
  2453. ( pszAppendFileName != NULL &&
  2454. !CompareTokens(*theIterator, pszAppendFileName)))
  2455. {
  2456. retCode = IsValidFile(*theIterator);
  2457. if ( retCode == PARSER_ERROR )
  2458. {
  2459. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2460. IDS_E_INVALID_FILENAME);
  2461. break;
  2462. }
  2463. else if ( retCode == PARSER_ERRMSG )
  2464. break;
  2465. }
  2466. }
  2467. else
  2468. {
  2469. retCode = PARSER_ERRMSG;
  2470. break;
  2471. }
  2472. // FALSE for setting append file.
  2473. if (!rParsedInfo.GetGlblSwitchesObject().
  2474. SetOutputOrAppendFileName(*theIterator, FALSE))
  2475. {
  2476. rParsedInfo.GetCmdSwitchesObject().
  2477. SetErrataCode(OUT_OF_MEMORY);
  2478. retCode = PARSER_OUTOFMEMORY;
  2479. break;
  2480. }
  2481. rParsedInfo.GetGlblSwitchesObject().SetOutputOrAppendOption(FILEOUTPUT,
  2482. FALSE);
  2483. }
  2484. }
  2485. else
  2486. break;
  2487. }
  2488. else if (CompareTokens(*theIterator,CLI_TOKEN_AGGREGATE))
  2489. {
  2490. retCode = ValidateGlobalSwitchValue(cvTokens, theIterator,
  2491. IDS_E_INVALID_AGGREGATE_OPTION,
  2492. rParsedInfo,
  2493. IDS_E_INVALID_AGGREGATE_SYNTAX,
  2494. Aggregate);
  2495. if(retCode == PARSER_CONTINUE)
  2496. {
  2497. if(CompareTokens(*theIterator, CLI_TOKEN_ON))
  2498. rParsedInfo.GetGlblSwitchesObject().SetAggregateFlag(TRUE);
  2499. else if(CompareTokens(*theIterator, CLI_TOKEN_OFF))
  2500. rParsedInfo.GetGlblSwitchesObject().SetAggregateFlag(FALSE);
  2501. else
  2502. {
  2503. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2504. IDS_E_INVALID_AGGREGATE_OPTION);
  2505. retCode = PARSER_ERROR;
  2506. break;
  2507. }
  2508. }
  2509. else
  2510. break;
  2511. }
  2512. else if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  2513. {
  2514. retCode = ParseHelp(cvTokens, theIterator, rParsedInfo, TRUE);
  2515. break;
  2516. }
  2517. else
  2518. {
  2519. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2520. IDS_E_INVALID_GLOBAL_SWITCH);
  2521. retCode = PARSER_ERROR;
  2522. break;
  2523. }
  2524. // Move to next token
  2525. if (!GetNextToken(cvTokens, theIterator))
  2526. // Break the loop if no more tokens are present
  2527. break;
  2528. // Break the loop if no more global switches are present
  2529. if (!IsOption(*theIterator))
  2530. break;
  2531. }
  2532. if ( bUserFlag == TRUE && bPassFlag == FALSE )
  2533. rParsedInfo.GetGlblSwitchesObject().SetAskForPassFlag(TRUE);
  2534. if ( rParsedInfo.GetGlblSwitchesObject().GetPassword() != NULL &&
  2535. rParsedInfo.GetGlblSwitchesObject().GetUser() == NULL )
  2536. {
  2537. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2538. IDS_E_PASSWORD_WITHOUT_USER);
  2539. rParsedInfo.GetGlblSwitchesObject().SetPassword(CLI_TOKEN_NULL);
  2540. retCode = PARSER_ERROR;
  2541. }
  2542. if ( retCode == PARSER_CONTINUE &&
  2543. bOpenOutFileInWriteMode == TRUE )
  2544. retCode = ProcessOutputAndAppendFiles(rParsedInfo, retCode, TRUE);
  2545. return retCode;
  2546. }
  2547. /*----------------------------------------------------------------------------
  2548. Name :ParseGETSwitches
  2549. Synopsis :This function does the parsing and interprets if command
  2550. has GET as the verb. It parses the remaining tokens
  2551. following and updates the same in CParsedInfo.
  2552. Type :Member Function
  2553. Input Parameter(s):
  2554. cvTokens - the tokens vector
  2555. theIterator - the Iterator to the cvTokens vector.
  2556. rParsedInfo - reference to CParsedInfo class object
  2557. Output Parameter(s):
  2558. rParsedInfo - reference to CParsedInfo class object
  2559. Return Type :RETCODE - enumerated data type
  2560. Global Variables :None
  2561. Calling Syntax :ParseGETSwitches(cvTokens,theIterator,rParsedInfo)
  2562. Notes :None
  2563. ----------------------------------------------------------------------------*/
  2564. RETCODE CParserEngine::ParseGETSwitches(CHARVECTOR& cvTokens,
  2565. CHARVECTOR::iterator& theIterator,
  2566. CParsedInfo& rParsedInfo)
  2567. {
  2568. RETCODE retCode = PARSER_EXECCOMMAND;
  2569. BOOL bContinue = TRUE;
  2570. while ( retCode == PARSER_EXECCOMMAND )
  2571. {
  2572. // Check for the presence of VALUE switch
  2573. if (CompareTokens(*theIterator, CLI_TOKEN_VALUE))
  2574. {
  2575. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  2576. XSLTDET xdXSLTDet;
  2577. g_wmiCmd.GetFileFromKey(CLI_TOKEN_VALUE, xdXSLTDet.FileName);
  2578. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet, rParsedInfo))
  2579. retCode = PARSER_ERRMSG;
  2580. }
  2581. // Check for the presence of ALL switch
  2582. else if (CompareTokens(*theIterator, CLI_TOKEN_ALL))
  2583. {
  2584. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  2585. XSLTDET xdXSLTDet;
  2586. g_wmiCmd.GetFileFromKey(CLI_TOKEN_TABLE, xdXSLTDet.FileName);
  2587. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet, rParsedInfo))
  2588. retCode = PARSER_ERRMSG;
  2589. }
  2590. // Check for the presence of FORMAT switch
  2591. else if (CompareTokens(*theIterator, CLI_TOKEN_FORMAT))
  2592. {
  2593. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  2594. retCode = ParseFORMATSwitch(cvTokens, theIterator, rParsedInfo);
  2595. }
  2596. // Check for the presence of EVERY switch
  2597. else if (CompareTokens(*theIterator, CLI_TOKEN_EVERY))
  2598. {
  2599. retCode = ParseEVERYSwitch(cvTokens, theIterator, rParsedInfo);
  2600. }
  2601. // Check for the presence of TRANSLATE switch
  2602. else if (CompareTokens(*theIterator, CLI_TOKEN_TRANSLATE))
  2603. {
  2604. retCode = ParseTRANSLATESwitch(cvTokens, theIterator, rParsedInfo);
  2605. }
  2606. // Check whether /REPEAT follows /EVERY
  2607. else if (CompareTokens(*theIterator, CLI_TOKEN_REPEAT))
  2608. {
  2609. if (!CompareTokens(*(theIterator-4), CLI_TOKEN_EVERY))
  2610. {
  2611. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2612. IDS_I_REPEAT_EVERY_RELATED);
  2613. retCode = PARSER_ERROR;
  2614. break;
  2615. }
  2616. }
  2617. // Check for the presence of HELP switch
  2618. else if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  2619. {
  2620. rParsedInfo.GetHelpInfoObject().SetHelp(GETSwitchesOnly, TRUE);
  2621. retCode = ParseHelp(cvTokens, theIterator, GETVerb, rParsedInfo);
  2622. if ( retCode == PARSER_DISPHELP )
  2623. {
  2624. if (m_bAliasName)
  2625. {
  2626. if (FAILED(m_CmdAlias.
  2627. ObtainAliasPropDetails(rParsedInfo)))
  2628. retCode = PARSER_ERRMSG;
  2629. }
  2630. else
  2631. {
  2632. if (!ObtainClassProperties(rParsedInfo))
  2633. retCode = PARSER_ERRMSG;
  2634. }
  2635. }
  2636. }
  2637. else
  2638. {
  2639. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2640. IDS_E_INVALID_GET_SWITCH);
  2641. retCode = PARSER_ERROR;
  2642. break;
  2643. }
  2644. if ( retCode == PARSER_EXECCOMMAND )
  2645. {
  2646. if ( !GetNextToken(cvTokens, theIterator) )
  2647. break;
  2648. if ( !IsOption(*theIterator) )
  2649. {
  2650. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2651. IDS_E_INVALID_COMMAND);
  2652. retCode = PARSER_ERROR;
  2653. break;
  2654. }
  2655. if ( !GetNextToken(cvTokens, theIterator) )
  2656. {
  2657. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2658. IDS_E_INVALID_GET_SWITCH);
  2659. retCode = PARSER_ERROR;
  2660. break;
  2661. }
  2662. }
  2663. }
  2664. return retCode;
  2665. }
  2666. /*----------------------------------------------------------------------------
  2667. Name :ParseLISTSwitches
  2668. Synopsis :This function does the parsing and interprets if command
  2669. has LIST as the verb. It parses the remaining tokens
  2670. following and updates the same in CParsedInfo.
  2671. Type :Member Function
  2672. Input Parameter(s):
  2673. cvTokens - the tokens vector
  2674. theIterator - the Iterator to the cvTokens vector.
  2675. rParsedInfo - reference to CParsedInfo class object
  2676. Output Parameter(s):
  2677. rParsedInfo - reference to CParsedInfo class object
  2678. Return Type :RETCODE - enumerated data type
  2679. Global Variables :None
  2680. Calling Syntax :ParseLISTSwitches(cvTokens,theIterator,rParsedInfo,
  2681. bFormatSwitchSpecified)
  2682. Notes :None
  2683. ----------------------------------------------------------------------------*/
  2684. RETCODE CParserEngine::ParseLISTSwitches(CHARVECTOR& cvTokens,
  2685. CHARVECTOR::iterator& theIterator,
  2686. CParsedInfo& rParsedInfo,
  2687. BOOL& bFormatSwitchSpecified)
  2688. {
  2689. RETCODE retCode = PARSER_EXECCOMMAND;
  2690. bFormatSwitchSpecified = FALSE;
  2691. while ( retCode == PARSER_EXECCOMMAND )
  2692. {
  2693. if (CompareTokens(*theIterator, CLI_TOKEN_TRANSLATE))
  2694. {
  2695. retCode = ParseTRANSLATESwitch(cvTokens, theIterator, rParsedInfo);
  2696. }
  2697. else if (CompareTokens(*theIterator, CLI_TOKEN_EVERY))
  2698. {
  2699. retCode = ParseEVERYSwitch(cvTokens, theIterator, rParsedInfo);
  2700. }
  2701. else if (CompareTokens(*theIterator, CLI_TOKEN_FORMAT))
  2702. {
  2703. retCode = ParseFORMATSwitch(cvTokens, theIterator, rParsedInfo);
  2704. bFormatSwitchSpecified = TRUE;
  2705. }
  2706. // Check whether /REPEAT follows /EVERY
  2707. else if (CompareTokens(*theIterator, CLI_TOKEN_REPEAT))
  2708. {
  2709. if (!CompareTokens(*(theIterator-4), CLI_TOKEN_EVERY))
  2710. {
  2711. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2712. IDS_I_REPEAT_EVERY_RELATED);
  2713. retCode = PARSER_ERROR;
  2714. break;
  2715. }
  2716. }
  2717. else if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  2718. {
  2719. rParsedInfo.GetHelpInfoObject().SetHelp(LISTSwitchesOnly, TRUE);
  2720. retCode = ParseHelp(cvTokens, theIterator, LISTVerb, rParsedInfo);
  2721. }
  2722. else
  2723. {
  2724. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2725. IDS_E_INVALID_LIST_SWITCH);
  2726. retCode = PARSER_ERROR;
  2727. break;
  2728. }
  2729. if ( retCode == PARSER_EXECCOMMAND )
  2730. {
  2731. if ( !GetNextToken(cvTokens, theIterator) )
  2732. break;
  2733. if ( !IsOption(*theIterator) )
  2734. {
  2735. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2736. IDS_E_INVALID_COMMAND);
  2737. retCode = PARSER_ERROR;
  2738. break;
  2739. }
  2740. if ( !GetNextToken(cvTokens, theIterator) )
  2741. {
  2742. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2743. IDS_E_INVALID_LIST_SWITCH);
  2744. retCode = PARSER_ERROR;
  2745. break;
  2746. }
  2747. }
  2748. }
  2749. return retCode;
  2750. }
  2751. /*----------------------------------------------------------------------------
  2752. Name :ParseSETorCREATEOrNamedParamInfo
  2753. Synopsis :This function does the parsing and interprets if command
  2754. has SET as the verb. It parses the remaining tokens
  2755. following and updates the same in CParsedInfo.
  2756. Type :Member Function
  2757. Input Parameter(s):
  2758. cvTokens - the tokens vector
  2759. theIterator - the Iterator to the cvTokens vector.
  2760. rParsedInfo - reference to CParsedInfo class object
  2761. Output parameters :
  2762. rParsedInfo - reference to CParsedInfo class object
  2763. Return Type :RETCODE - enumerated data type
  2764. Global Variables :None
  2765. Calling Syntax :ParseSETorCREATEOrNamedParamInfo(cvTokens,theIterator,rParsedInfo, helpType)
  2766. Notes :None
  2767. -------------------------------------------------------------------------*/
  2768. RETCODE CParserEngine::ParseSETorCREATEOrNamedParamInfo(CHARVECTOR& cvTokens,
  2769. CHARVECTOR::iterator& theIterator,
  2770. CParsedInfo& rParsedInfo,
  2771. HELPTYPE helpType)
  2772. {
  2773. RETCODE retCode = PARSER_EXECCOMMAND;
  2774. _TCHAR *pszProp,*pszVal;
  2775. try
  2776. {
  2777. // Process the SET|CREATE verb related info i.e properties with new values.
  2778. while (TRUE)
  2779. {
  2780. pszProp = NULL;
  2781. pszVal = NULL;
  2782. // Tokenize the expression checking for '='
  2783. pszProp = *theIterator;
  2784. if ( GetNextToken(cvTokens, theIterator) &&
  2785. CompareTokens(*theIterator, CLI_TOKEN_EQUALTO) &&
  2786. GetNextToken(cvTokens, theIterator))
  2787. pszVal = *theIterator;
  2788. if ((pszProp == NULL) || (pszVal == NULL))
  2789. {
  2790. if ( helpType != CALLVerb &&
  2791. IsOption(*(theIterator+1)) &&
  2792. theIterator + 2 < cvTokens.end() &&
  2793. CompareTokens(*(theIterator+2), CLI_TOKEN_HELP) )
  2794. {
  2795. theIterator++;
  2796. theIterator++;
  2797. retCode = ParseHelp(cvTokens, theIterator, helpType, rParsedInfo);
  2798. if (retCode == PARSER_DISPHELP)
  2799. {
  2800. // Adding to PropertyList only for use in displaying help of
  2801. // properties
  2802. if(!rParsedInfo.GetCmdSwitchesObject().
  2803. AddToPropertyList(pszProp))
  2804. {
  2805. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2806. IDS_E_ADD_TO_PROP_LIST_FAILURE);
  2807. retCode = PARSER_ERROR;
  2808. break;
  2809. }
  2810. if (m_bAliasName)
  2811. {
  2812. if (FAILED(m_CmdAlias.
  2813. ObtainAliasPropDetails(rParsedInfo)))
  2814. retCode = PARSER_ERRMSG;
  2815. }
  2816. else
  2817. {
  2818. if (!ObtainClassProperties(rParsedInfo))
  2819. retCode = PARSER_ERRMSG;
  2820. }
  2821. }
  2822. }
  2823. else
  2824. {
  2825. UINT nErrID;
  2826. if ( helpType == CALLVerb )
  2827. nErrID = IDS_E_INVALID_NAMED_PARAM_LIST;
  2828. else
  2829. nErrID = IDS_E_INVALID_ASSIGNLIST;
  2830. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(nErrID);
  2831. retCode = PARSER_ERROR;
  2832. }
  2833. break;
  2834. }
  2835. // Unquote the strings
  2836. UnQuoteString(pszProp);
  2837. UnQuoteString(pszVal);
  2838. // Add to the list of parameters
  2839. if(!rParsedInfo.GetCmdSwitchesObject().
  2840. AddToParameterMap(_bstr_t(pszProp), _bstr_t(pszVal)))
  2841. {
  2842. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2843. IDS_E_ADD_TO_PARAM_MAP_FAILURE);
  2844. retCode = PARSER_ERROR;
  2845. break;
  2846. }
  2847. // Adding to PropertyList only for use in displaying help of
  2848. // properties
  2849. if(!rParsedInfo.GetCmdSwitchesObject().
  2850. AddToPropertyList(pszProp))
  2851. {
  2852. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2853. IDS_E_ADD_TO_PROP_LIST_FAILURE);
  2854. retCode = PARSER_ERROR;
  2855. break;
  2856. }
  2857. // Get the next token
  2858. if (GetNextToken(cvTokens, theIterator))
  2859. {
  2860. // If option (i.e either '/' or '-') specified.
  2861. if (IsOption(*theIterator))
  2862. {
  2863. theIterator--;
  2864. break;
  2865. }
  2866. else
  2867. {
  2868. if ( helpType != CALLVerb )
  2869. {
  2870. // check for the presence of ','
  2871. if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  2872. {
  2873. if (!GetNextToken(cvTokens, theIterator))
  2874. {
  2875. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2876. IDS_E_INVALID_ASSIGNLIST);
  2877. retCode = PARSER_ERROR;
  2878. break;
  2879. }
  2880. }
  2881. else
  2882. {
  2883. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  2884. IDS_E_INVALID_ASSIGNLIST);
  2885. retCode = PARSER_ERROR;
  2886. break;
  2887. }
  2888. }
  2889. }
  2890. }
  2891. else
  2892. {
  2893. retCode = PARSER_EXECCOMMAND;
  2894. break;
  2895. }
  2896. }
  2897. }
  2898. catch(_com_error& e)
  2899. {
  2900. retCode = PARSER_ERROR;
  2901. _com_issue_error(e.Error());
  2902. }
  2903. return retCode;
  2904. }
  2905. /*----------------------------------------------------------------------------
  2906. Name :ParseVerbSwitches
  2907. Synopsis :This function does the parsing and interprets if command
  2908. has verb switches specified. It parses the remaining
  2909. tokens following and updates the same in CParsedInfo.
  2910. Type :Member Function
  2911. Input Parameter(s):
  2912. cvTokens - the tokens vector
  2913. theIterator - the Iterator to the cvTokens vector.
  2914. rParsedInfo - reference to CParsedInfo class object
  2915. Output Parameter(s):
  2916. rParsedInfo - reference to CParsedInfo class object
  2917. Return Type :RETCODE - enumerated data type
  2918. Global Variables :None
  2919. Calling Syntax :ParseVerbSwitches(cvTokens,theIterator,rParsedInfo)
  2920. Notes :None
  2921. ----------------------------------------------------------------------------*/
  2922. RETCODE CParserEngine::ParseVerbSwitches(CHARVECTOR& cvTokens,
  2923. CHARVECTOR::iterator& theIterator,
  2924. CParsedInfo& rParsedInfo)
  2925. {
  2926. RETCODE retCode = PARSER_EXECCOMMAND;
  2927. BOOL bInvalidVerbSwitch = FALSE;
  2928. // Check for the '/' | '-' token
  2929. if (IsOption(*theIterator))
  2930. {
  2931. // Move to next token
  2932. if (!GetNextToken(cvTokens, theIterator))
  2933. bInvalidVerbSwitch = TRUE;
  2934. else if (CompareTokens(*theIterator, CLI_TOKEN_INTERACTIVE))
  2935. {
  2936. rParsedInfo.GetCmdSwitchesObject().
  2937. SetInteractiveMode(INTERACTIVE);
  2938. _TCHAR *pszVerbName = rParsedInfo.GetCmdSwitchesObject().
  2939. GetVerbName();
  2940. BOOL bInstanceLevel = TRUE;
  2941. if(CompareTokens(pszVerbName, CLI_TOKEN_CALL)
  2942. || CompareTokens(pszVerbName, CLI_TOKEN_SET)
  2943. || CompareTokens(pszVerbName, CLI_TOKEN_DELETE))
  2944. {
  2945. if(IsClassOperation(rParsedInfo))
  2946. {
  2947. bInstanceLevel = FALSE;
  2948. }
  2949. else
  2950. {
  2951. if(CompareTokens(pszVerbName, CLI_TOKEN_CALL))
  2952. {
  2953. if ( rParsedInfo.GetCmdSwitchesObject().
  2954. GetAliasName() != NULL )
  2955. {
  2956. if (rParsedInfo.GetCmdSwitchesObject().
  2957. GetWhereExpression() == NULL)
  2958. {
  2959. bInstanceLevel = FALSE;
  2960. }
  2961. else
  2962. bInstanceLevel = TRUE;
  2963. }
  2964. else
  2965. {
  2966. if ((rParsedInfo.GetCmdSwitchesObject().
  2967. GetPathExpression() != NULL)
  2968. && (rParsedInfo.GetCmdSwitchesObject().
  2969. GetWhereExpression() == NULL))
  2970. {
  2971. bInstanceLevel = FALSE;
  2972. }
  2973. else
  2974. bInstanceLevel = TRUE;
  2975. }
  2976. }
  2977. else
  2978. bInstanceLevel = TRUE;
  2979. }
  2980. }
  2981. else
  2982. retCode = PARSER_EXECCOMMAND;
  2983. if(bInstanceLevel)
  2984. {
  2985. retCode = ParseVerbInteractive( cvTokens, theIterator,
  2986. rParsedInfo, bInvalidVerbSwitch);
  2987. }
  2988. else
  2989. retCode = PARSER_EXECCOMMAND;
  2990. }
  2991. else if (CompareTokens(*theIterator, CLI_TOKEN_NONINTERACT))
  2992. {
  2993. rParsedInfo.GetCmdSwitchesObject().
  2994. SetInteractiveMode(NOINTERACTIVE);
  2995. retCode = PARSER_EXECCOMMAND;
  2996. }
  2997. else if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  2998. {
  2999. retCode = ParseHelp(cvTokens, theIterator, VERBSWITCHES,
  3000. rParsedInfo);
  3001. }
  3002. else
  3003. bInvalidVerbSwitch = TRUE;
  3004. if ( GetNextToken(cvTokens, theIterator ) )
  3005. {
  3006. rParsedInfo.GetCmdSwitchesObject().
  3007. SetErrataCode(IDS_E_INVALID_COMMAND);
  3008. retCode = PARSER_ERROR;
  3009. }
  3010. }
  3011. else
  3012. bInvalidVerbSwitch = TRUE;
  3013. if ( bInvalidVerbSwitch == TRUE )
  3014. {
  3015. // no valid <verb switch> type is specified.
  3016. rParsedInfo.GetCmdSwitchesObject().
  3017. SetErrataCode(IDS_E_INVALID_VERB_SWITCH);
  3018. retCode = PARSER_ERROR;
  3019. }
  3020. return retCode;
  3021. }
  3022. /*----------------------------------------------------------------------------
  3023. Name :GetNextToken
  3024. Synopsis :This function retrieves the next token from the token
  3025. vector list, returns FALSE if no more tokens are present
  3026. Type :Member Function
  3027. Input Parameter(s):
  3028. cvTokens - the tokens vector
  3029. theIterator - the Iterator to the cvTokens vector.
  3030. Output Parameter(s):None
  3031. Return Type :BOOL
  3032. Global Variables :None
  3033. Calling Syntax :GetNextToken(cvTokens,theIterator)
  3034. Notes :None
  3035. ----------------------------------------------------------------------------*/
  3036. BOOL CParserEngine::GetNextToken(CHARVECTOR& cvTokens,
  3037. CHARVECTOR::iterator& theIterator)
  3038. {
  3039. theIterator++;
  3040. return (theIterator >= cvTokens.end()) ? FALSE : TRUE;
  3041. }
  3042. /*----------------------------------------------------------------------------
  3043. Name :ParsePWhereExpr
  3044. Synopsis :This function does the parsing and interprets if command
  3045. has Path and Where expression It parses the remaining
  3046. tokens following and updates the same in CParsedInfo.
  3047. Type :Member Function
  3048. Input Parameter(s):
  3049. cvTokens - the tokens vector
  3050. theIterator - the Iterator to the cvTokens vector.
  3051. rParsedInfo - reference to CParsedInfo class object
  3052. Output Parameter(s):
  3053. rParsedInfo - reference to CParsedInfo class object
  3054. Return Type :BOOL
  3055. Global Variables :None
  3056. Calling Syntax :ParsePWhereExpr(cvTokens,theIterator,rParsedInfo)
  3057. Notes :None
  3058. ----------------------------------------------------------------------------*/
  3059. BOOL CParserEngine::ParsePWhereExpr(CHARVECTOR& cvTokens,
  3060. CHARVECTOR::iterator& theIterator,
  3061. CParsedInfo& rParsedInfo,
  3062. BOOL bIsParan)
  3063. {
  3064. BOOL bRet = TRUE, bContinue = FALSE;
  3065. try
  3066. {
  3067. while (TRUE)
  3068. {
  3069. if ( bIsParan == TRUE &&
  3070. CompareTokens(*theIterator, CLI_TOKEN_RIGHT_PARAN) )
  3071. break;
  3072. if ( bIsParan == FALSE &&
  3073. IsStdVerbOrUserDefVerb(*theIterator, rParsedInfo) )
  3074. break;
  3075. if ( bIsParan == FALSE ||
  3076. !CompareTokens(*theIterator, CLI_TOKEN_LEFT_PARAN))
  3077. {
  3078. if(!rParsedInfo.GetCmdSwitchesObject().
  3079. AddToPWhereParamsList(*theIterator))
  3080. {
  3081. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3082. IDS_E_ADD_TO_PARAMS_LIST_FAILURE);
  3083. bRet = FALSE;
  3084. break;
  3085. }
  3086. bContinue = TRUE;
  3087. }
  3088. if (!GetNextToken(cvTokens, theIterator))
  3089. break;
  3090. if ( IsOption(*theIterator) )
  3091. {
  3092. bContinue = FALSE;
  3093. break;
  3094. }
  3095. }
  3096. if(bRet != FALSE && bContinue == TRUE)
  3097. {
  3098. CHARVECTOR theParam = rParsedInfo.GetCmdSwitchesObject().
  3099. GetPWhereParamsList();
  3100. CHARVECTOR::iterator theItr = theParam.begin();
  3101. _TCHAR pszPWhere[MAX_BUFFER] = NULL_STRING;
  3102. lstrcpy(pszPWhere, CLI_TOKEN_NULL);
  3103. _TCHAR* pszToken = NULL;;
  3104. CHString sTemp;
  3105. if ((rParsedInfo.GetCmdSwitchesObject().GetPWhereExpr() != NULL))
  3106. {
  3107. sTemp.Format(rParsedInfo.GetCmdSwitchesObject().
  3108. GetPWhereExpr());
  3109. sTemp.TrimLeft();
  3110. if(!sTemp.IsEmpty())
  3111. {
  3112. _bstr_t bstrPWhere = _bstr_t(rParsedInfo.
  3113. GetCmdSwitchesObject().
  3114. GetPWhereExpr());
  3115. pszToken = _tcstok((WCHAR*)bstrPWhere,
  3116. CLI_TOKEN_HASH);
  3117. lstrcpy(pszPWhere, CLI_TOKEN_NULL);
  3118. while (pszToken != NULL)
  3119. {
  3120. lstrcat(pszPWhere, pszToken);
  3121. if (theItr != theParam.end())
  3122. {
  3123. lstrcat(pszPWhere, *theItr);
  3124. theItr++;
  3125. }
  3126. pszToken = _tcstok(NULL, CLI_TOKEN_HASH);
  3127. }
  3128. if(bRet != FALSE)
  3129. {
  3130. // Set the classpath and where expression
  3131. pszToken = NULL;
  3132. pszToken = _tcstok(pszPWhere, CLI_TOKEN_SPACE);
  3133. if (pszToken != NULL)
  3134. {
  3135. if (CompareTokens(CLI_TOKEN_FROM, pszToken))
  3136. {
  3137. pszToken = _tcstok(NULL, CLI_TOKEN_SPACE);
  3138. if (pszToken != NULL)
  3139. {
  3140. if(!rParsedInfo.GetCmdSwitchesObject().
  3141. SetClassPath(pszToken))
  3142. {
  3143. rParsedInfo.GetCmdSwitchesObject().
  3144. SetErrataCode(OUT_OF_MEMORY);
  3145. bRet = FALSE;
  3146. }
  3147. }
  3148. if(bRet != FALSE)
  3149. pszToken = _tcstok(NULL, CLI_TOKEN_SPACE);
  3150. }
  3151. if (CompareTokens(CLI_TOKEN_WHERE, pszToken))
  3152. {
  3153. pszToken = _tcstok(NULL, CLI_TOKEN_NULL);
  3154. if (pszToken != NULL)
  3155. {
  3156. if(!rParsedInfo.GetCmdSwitchesObject().
  3157. SetWhereExpression(pszToken))
  3158. {
  3159. rParsedInfo.GetCmdSwitchesObject().
  3160. SetErrataCode(OUT_OF_MEMORY);
  3161. bRet = FALSE;
  3162. }
  3163. }
  3164. }
  3165. }
  3166. }
  3167. }
  3168. else
  3169. {
  3170. rParsedInfo.GetCmdSwitchesObject().
  3171. SetErrataCode(IDS_E_PWHERE_UNDEF);
  3172. bRet = FALSE;
  3173. }
  3174. }
  3175. else
  3176. {
  3177. rParsedInfo.GetCmdSwitchesObject().
  3178. SetErrataCode(IDS_E_PWHERE_UNDEF);
  3179. bRet = FALSE;
  3180. }
  3181. }
  3182. if (!bContinue && bIsParan)
  3183. {
  3184. rParsedInfo.GetCmdSwitchesObject().
  3185. SetErrataCode(IDS_E_INVALID_PWHERE_EXPR);
  3186. bRet = FALSE;
  3187. }
  3188. }
  3189. catch(_com_error& e)
  3190. {
  3191. bRet = FALSE;
  3192. _com_issue_error(e.Error());
  3193. }
  3194. catch(CHeap_Exception)
  3195. {
  3196. bRet = FALSE;
  3197. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  3198. }
  3199. return bRet;
  3200. }
  3201. /*----------------------------------------------------------------------------
  3202. Name :ExtractClassNameandWhereExpr
  3203. Synopsis :This function takes the input as a path expression and
  3204. extracts the Class and Where expression part from the
  3205. path expression.
  3206. Type :Member Function
  3207. Input Parameter(s):
  3208. pszPathExpr - the path expression
  3209. rParsedInfo - reference to CParsedInfo class object
  3210. Output Parameter(s):
  3211. rParsedInfo - reference to CParsedInfo class object
  3212. Return Type :BOOL
  3213. Global Variables :None
  3214. Calling Syntax :ParsePWhereExpr(cvTokens,theIterator)
  3215. Notes :None
  3216. ----------------------------------------------------------------------------*/
  3217. BOOL CParserEngine::ExtractClassNameandWhereExpr(_TCHAR* pszPathExpr,
  3218. CParsedInfo& rParsedInfo)
  3219. {
  3220. // Frame the class name and where expression based on the object path
  3221. BOOL bRet = TRUE;
  3222. _TCHAR* pszToken = NULL;
  3223. BOOL bFirst = TRUE;
  3224. _TCHAR pszWhere[MAX_BUFFER] = NULL_STRING;
  3225. lstrcpy(pszWhere, CLI_TOKEN_NULL);
  3226. if (pszPathExpr == NULL)
  3227. bRet = FALSE;
  3228. try
  3229. {
  3230. if ( bRet == TRUE )
  3231. {
  3232. lstrcpy(pszWhere, CLI_TOKEN_NULL);
  3233. pszToken = _tcstok(pszPathExpr, CLI_TOKEN_DOT);
  3234. if (pszToken != NULL)
  3235. {
  3236. if(!rParsedInfo.GetCmdSwitchesObject().SetClassPath(pszToken))
  3237. {
  3238. rParsedInfo.GetCmdSwitchesObject().
  3239. SetErrataCode(OUT_OF_MEMORY);
  3240. bRet = FALSE;
  3241. }
  3242. }
  3243. if(bRet != FALSE)
  3244. {
  3245. while (pszToken != NULL)
  3246. {
  3247. pszToken = _tcstok(NULL, CLI_TOKEN_COMMA);
  3248. if (pszToken != NULL)
  3249. {
  3250. if (!bFirst)
  3251. lstrcat(pszWhere, CLI_TOKEN_AND);
  3252. lstrcat(pszWhere, pszToken);
  3253. bFirst = FALSE;
  3254. }
  3255. else
  3256. break;
  3257. }
  3258. if (lstrlen(pszWhere))
  3259. {
  3260. if(!rParsedInfo.GetCmdSwitchesObject().SetWhereExpression(pszWhere))
  3261. {
  3262. rParsedInfo.GetCmdSwitchesObject().
  3263. SetErrataCode(OUT_OF_MEMORY);
  3264. bRet = FALSE;
  3265. }
  3266. }
  3267. }
  3268. }
  3269. }
  3270. catch(...)
  3271. {
  3272. rParsedInfo.GetCmdSwitchesObject().
  3273. SetErrataCode(IDS_E_INVALID_PATH);
  3274. bRet = FALSE;
  3275. }
  3276. return bRet;
  3277. }
  3278. /*----------------------------------------------------------------------------
  3279. Name :GetNextToken
  3280. Synopsis :This function retrieves the next token from the token
  3281. vector list, returns enumerated return code depending
  3282. upon the context.
  3283. Type :Member Function
  3284. Input Parameter(s):
  3285. cvTokens - the tokens vector
  3286. theIterator - the Iterator to the cvTokens vector.
  3287. rParsedInfo - reference to CParsedInfo class object
  3288. helpType - enumerated help type
  3289. uErrataCode - error string ID.
  3290. Output Parameter(s):
  3291. rParsedInfo - reference to CParsedInfo class object
  3292. Return Type :RETCODE - enumerated data type.
  3293. Global Variables :None
  3294. Calling Syntax :GetNextToken(cvTokens, theIterator,
  3295. rParsedInfo, helpType, uErrataCode)
  3296. Notes :overloaded function
  3297. ----------------------------------------------------------------------------*/
  3298. RETCODE CParserEngine::GetNextToken(CHARVECTOR& cvTokens,
  3299. CHARVECTOR::iterator& theIterator,
  3300. CParsedInfo& rParsedInfo,
  3301. HELPTYPE helpType,
  3302. UINT uErrataCode)
  3303. {
  3304. RETCODE retCode = PARSER_CONTINUE;
  3305. // Move to next token
  3306. theIterator++;
  3307. // If no more tokens are present
  3308. if (theIterator >= cvTokens.end())
  3309. {
  3310. // If interactive mode is set
  3311. if (rParsedInfo.GetGlblSwitchesObject().GetInteractiveStatus())
  3312. {
  3313. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(TRUE);
  3314. rParsedInfo.GetHelpInfoObject().SetHelp(helpType, TRUE);
  3315. retCode = PARSER_DISPHELP;
  3316. }
  3317. else
  3318. {
  3319. // PARSER_ERROR if no more tokens are present.
  3320. rParsedInfo.GetCmdSwitchesObject().
  3321. SetErrataCode(uErrataCode);
  3322. retCode = PARSER_ERROR;
  3323. }
  3324. }
  3325. return retCode;
  3326. }
  3327. /*----------------------------------------------------------------------------
  3328. Name :GetNextToken
  3329. Synopsis :This function retrieves the next token from the token
  3330. vector list, returns enumerated return code depending
  3331. upon the context.
  3332. Type :Member Function
  3333. Input Parameter(s):
  3334. cvTokens - the tokens vector
  3335. theIterator - the Iterator to the cvTokens vector.
  3336. rParsedInfo - reference to CParsedInfo class object
  3337. uErrataCode - error string ID.
  3338. Output Parameter(s):
  3339. rParsedInfo - reference to CParsedInfo class object
  3340. Return Type :RETCODE - enumerated data type.
  3341. Global Variables :None
  3342. Calling Syntax :GetNextToken(cvTokens, theIterator,
  3343. rParsedInfo, uErrataCode)
  3344. Notes :overloaded function
  3345. ----------------------------------------------------------------------------*/
  3346. RETCODE CParserEngine::GetNextToken(CHARVECTOR& cvTokens,
  3347. CHARVECTOR::iterator& theIterator,
  3348. CParsedInfo& rParsedInfo,
  3349. UINT uErrataCode)
  3350. {
  3351. RETCODE retCode = PARSER_CONTINUE;
  3352. // Move to next token
  3353. theIterator++;
  3354. // If no more tokens are present
  3355. if (theIterator >= cvTokens.end())
  3356. {
  3357. // PARSER_ERROR if no more tokens are present
  3358. rParsedInfo.GetCmdSwitchesObject().
  3359. SetErrataCode(uErrataCode);
  3360. retCode = PARSER_ERROR;
  3361. }
  3362. return retCode;
  3363. }
  3364. /*----------------------------------------------------------------------------
  3365. Name :IsHelp
  3366. Synopsis :This function retrieves the next token from the token
  3367. vector list, checks if it is '?' and returns enumerated
  3368. return code depending upon the context.
  3369. Type :Member Function
  3370. Input Parameter(s):
  3371. cvTokens - the tokens vector
  3372. theIterator - the Iterator to the cvTokens vector.
  3373. rParsedInfo - reference to CParsedInfo class object
  3374. helpType - enumerated help type
  3375. uErrataCode - error string ID.
  3376. tokenLevel - token level
  3377. Output Parameter(s):
  3378. rParsedInfo - reference to CParsedInfo class object
  3379. Return Type :RETCODE - enumerated data type.
  3380. Global Variables :None
  3381. Calling Syntax :IsHelp(cvTokens, theIterator, rParsedInfo,
  3382. helpType, uErrataCode, tokenLevel)
  3383. Notes :None
  3384. ----------------------------------------------------------------------------*/
  3385. RETCODE CParserEngine::IsHelp(CHARVECTOR& cvTokens,
  3386. CHARVECTOR::iterator& theIterator,
  3387. CParsedInfo& rParsedInfo,
  3388. HELPTYPE helpType,
  3389. UINT uErrataCode,
  3390. TOKENLEVEL tokenLevel)
  3391. {
  3392. BOOL bContinue = TRUE;
  3393. RETCODE retCode = PARSER_CONTINUE;
  3394. // Move to next token
  3395. if (!GetNextToken(cvTokens, theIterator))
  3396. {
  3397. // Set the retCode as PARSER_ERROR if no more tokens are present.
  3398. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(uErrataCode);
  3399. retCode = PARSER_ERROR;
  3400. }
  3401. else
  3402. {
  3403. // Is '?'
  3404. if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  3405. retCode = ParseHelp(cvTokens, theIterator, helpType, rParsedInfo);
  3406. else
  3407. {
  3408. // If LEVEL_ONE token then only allowed is /?, other
  3409. // switches are invalid.
  3410. if (tokenLevel == LEVEL_ONE)
  3411. {
  3412. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(uErrataCode);
  3413. retCode = PARSER_ERROR;
  3414. }
  3415. else
  3416. retCode = PARSER_CONTINUE;
  3417. }
  3418. }
  3419. return retCode;
  3420. }
  3421. /*----------------------------------------------------------------------------
  3422. Name :ParseHelp
  3423. Synopsis :This function takes care of identifying the appropriate
  3424. help informtion to be displayed using the HELPTYPE
  3425. Type :Member Function
  3426. Input Parameter(s):
  3427. cvTokens - the tokens vector
  3428. theIterator - the Iterator to the cvTokens vector.
  3429. rParsedInfo - reference to CParsedInfo class object
  3430. bGlobalHelp - global help flag
  3431. Output Parameter(s):
  3432. rParsedInfo - reference to CParsedInfo class object
  3433. Return Type :RETCODE
  3434. Global Variables :None
  3435. Calling Syntax :ParseHelp(cvTokens, theIterator, rParsedInfo)
  3436. Notes :overloaded fucntion
  3437. ----------------------------------------------------------------------------*/
  3438. RETCODE CParserEngine::ParseHelp(CHARVECTOR& cvTokens,
  3439. CHARVECTOR::iterator& theIterator,
  3440. CParsedInfo& rParsedInfo,
  3441. BOOL bGlobalHelp)
  3442. {
  3443. BOOL bContinue = TRUE;
  3444. RETCODE retCode = PARSER_CONTINUE;
  3445. // Move to next token (if no more tokens are present)
  3446. if (!GetNextToken(cvTokens, theIterator))
  3447. {
  3448. retCode = PARSER_DISPHELP;
  3449. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(TRUE);
  3450. // Check for "/?"
  3451. if (((theIterator - 2) == cvTokens.begin()) || bGlobalHelp)
  3452. {
  3453. rParsedInfo.GetHelpInfoObject().SetHelp(GlblAllInfo, TRUE);
  3454. if(SUCCEEDED(m_CmdAlias.ConnectToAlias(rParsedInfo,m_pIWbemLocator)))
  3455. {
  3456. if(FAILED(m_CmdAlias.ObtainAliasFriendlyNames(rParsedInfo)))
  3457. retCode = PARSER_ERRMSG;
  3458. }
  3459. else
  3460. rParsedInfo.GetCmdSwitchesObject().FreeCOMError();
  3461. }
  3462. }
  3463. // Check for the presence of the ':"
  3464. else if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  3465. {
  3466. // Move to next token
  3467. if (!GetNextToken(cvTokens, theIterator, rParsedInfo,
  3468. IDS_E_INVALID_HELP_OPTION))
  3469. // Set the retCode to PARSER_ERROR if no more tokens are specified.
  3470. {
  3471. retCode = PARSER_ERROR;
  3472. }
  3473. else
  3474. {
  3475. if (CompareTokens(*theIterator, CLI_TOKEN_BRIEF))
  3476. rParsedInfo.GetGlblSwitchesObject().SetHelpOption(HELPBRIEF);
  3477. else if (CompareTokens(*theIterator, CLI_TOKEN_FULL))
  3478. rParsedInfo.GetGlblSwitchesObject().SetHelpOption(HELPFULL);
  3479. else
  3480. {
  3481. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3482. IDS_E_INVALID_HELP_OPTION);
  3483. retCode = PARSER_ERROR;
  3484. }
  3485. if ( retCode != PARSER_ERROR )
  3486. {
  3487. if ( GetNextToken(cvTokens, theIterator) )
  3488. {
  3489. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3490. IDS_E_INVALID_COMMAND);
  3491. retCode = PARSER_ERROR;
  3492. }
  3493. else
  3494. {
  3495. retCode = PARSER_DISPHELP;
  3496. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(TRUE);
  3497. // Check for "/?:(BRIEF|FULL)
  3498. if (((theIterator - 3) == cvTokens.begin()) || bGlobalHelp)
  3499. {
  3500. rParsedInfo.GetHelpInfoObject().
  3501. SetHelp(GlblAllInfo, TRUE);
  3502. if(SUCCEEDED(m_CmdAlias.ConnectToAlias
  3503. (rParsedInfo,m_pIWbemLocator)))
  3504. {
  3505. if(FAILED(m_CmdAlias.ObtainAliasFriendlyNames
  3506. (rParsedInfo)))
  3507. {
  3508. retCode = PARSER_ERRMSG;
  3509. }
  3510. }
  3511. else
  3512. rParsedInfo.GetCmdSwitchesObject().FreeCOMError();
  3513. }
  3514. }
  3515. }
  3516. }
  3517. }
  3518. else
  3519. {
  3520. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3521. IDS_E_INVALID_COMMAND);
  3522. retCode = PARSER_ERROR;
  3523. }
  3524. return retCode;
  3525. }
  3526. /*----------------------------------------------------------------------------
  3527. Name :ParseHelp
  3528. Synopsis :This function takes care of identifying the appropriate
  3529. help informtion to be displayed using the HELPTYPE
  3530. Type :Member Function
  3531. Input Parameter(s):
  3532. cvTokens - the tokens vector
  3533. theIterator - the Iterator to the cvTokens vector.
  3534. htHelp - help type
  3535. rParsedInfo - reference to CParsedInfo class object
  3536. bGlobalHelp - global help flag
  3537. Output Parameter(s):
  3538. rParsedInfo - ref. to CParsedInfo object
  3539. Return Type :RETCODE
  3540. Global Variables :None
  3541. Calling Syntax :ParseHelp(cvTokens, theIterator, htHelp,
  3542. rParsedInfo)
  3543. Notes :overloaded fucntion
  3544. ----------------------------------------------------------------------------*/
  3545. RETCODE CParserEngine::ParseHelp(CHARVECTOR& cvTokens,
  3546. CHARVECTOR::iterator& theIterator,
  3547. HELPTYPE htHelp,
  3548. CParsedInfo& rParsedInfo,
  3549. BOOL bGlobalHelp)
  3550. {
  3551. rParsedInfo.GetHelpInfoObject().SetHelp(htHelp, TRUE);
  3552. return ParseHelp(cvTokens, theIterator, rParsedInfo, bGlobalHelp);
  3553. }
  3554. /*----------------------------------------------------------------------------
  3555. Name :ObtainClassProperties
  3556. Synopsis :This function obtains the information about the
  3557. available properties for a given WMI class
  3558. Type :Member Function
  3559. Input Parameter(s):
  3560. rParsedInfo - reference to CParsedInfo class object
  3561. Output Parameter(s):
  3562. rParsedInfo - reference to CParsedInfo class object
  3563. Return Type :BOOL
  3564. Global Variables :None
  3565. Calling Syntax :ObtainClassProperties(rParsedInfo)
  3566. Notes :If bCheckWritePropsAvail == TRUE then functions checks for
  3567. availibilty of properties.
  3568. ----------------------------------------------------------------------------*/
  3569. BOOL CParserEngine::ObtainClassProperties(CParsedInfo& rParsedInfo,
  3570. BOOL bCheckWritePropsAvail)
  3571. {
  3572. HRESULT hr = S_OK;
  3573. IWbemClassObject* pIObject = NULL;
  3574. SAFEARRAY* psaNames = NULL;
  3575. BSTR bstrPropName = NULL;
  3576. BOOL bRet = TRUE;
  3577. BOOL bTrace = FALSE;
  3578. CHString chsMsg;
  3579. ERRLOGOPT eloErrLogOpt = NO_LOGGING;
  3580. DWORD dwThreadId = GetCurrentThreadId();
  3581. BOOL bSetVerb = FALSE;
  3582. BOOL bPropsAvail = FALSE;
  3583. if (rParsedInfo.GetCmdSwitchesObject().GetVerbName() != NULL)
  3584. {
  3585. if (CompareTokens(rParsedInfo.GetCmdSwitchesObject().GetVerbName(),
  3586. CLI_TOKEN_SET))
  3587. {
  3588. bSetVerb = TRUE;
  3589. }
  3590. }
  3591. // Obtain the trace flag status
  3592. bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  3593. eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  3594. if (SUCCEEDED(ConnectToNamespace(rParsedInfo)))
  3595. {
  3596. CHARVECTOR cvPropList;
  3597. BOOL bPropList = FALSE;
  3598. try
  3599. {
  3600. cvPropList = rParsedInfo.GetCmdSwitchesObject().GetPropertyList();
  3601. if ( cvPropList.size() != 0 )
  3602. bPropList = TRUE;
  3603. hr = m_pITargetNS->GetObject(_bstr_t(rParsedInfo.
  3604. GetCmdSwitchesObject().GetClassPath()),
  3605. WBEM_FLAG_USE_AMENDED_QUALIFIERS,
  3606. NULL, &pIObject, NULL);
  3607. if (bTrace || eloErrLogOpt)
  3608. {
  3609. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", "
  3610. L"WBEM_FLAG_USE_AMENDED_QUALIFIERS, 0, NULL, -, -)",
  3611. (rParsedInfo.GetCmdSwitchesObject().GetClassPath())?
  3612. rParsedInfo.GetCmdSwitchesObject().GetClassPath():L"<NULL>");
  3613. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3614. rParsedInfo, bTrace);
  3615. }
  3616. ONFAILTHROWERROR(hr);
  3617. hr = pIObject->GetNames(NULL, WBEM_FLAG_ALWAYS |
  3618. WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  3619. if (bTrace || eloErrLogOpt)
  3620. {
  3621. chsMsg.Format(L"IWbemClassObject::GetNames(NULL, "
  3622. L"WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, "
  3623. L"NULL, -)");
  3624. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3625. rParsedInfo, bTrace);
  3626. }
  3627. ONFAILTHROWERROR(hr);
  3628. // Get the number of properties.
  3629. LONG lLower = 0, lUpper = 0;
  3630. hr = SafeArrayGetLBound(psaNames, 1, &lLower);
  3631. if ( eloErrLogOpt )
  3632. {
  3633. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  3634. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3635. rParsedInfo, FALSE);
  3636. }
  3637. ONFAILTHROWERROR(hr);
  3638. hr = SafeArrayGetUBound(psaNames, 1, &lUpper);
  3639. if ( eloErrLogOpt )
  3640. {
  3641. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  3642. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3643. rParsedInfo, FALSE);
  3644. }
  3645. ONFAILTHROWERROR(hr);
  3646. // For each property obtain the information of our interest
  3647. for (LONG lVar = lLower; lVar <= lUpper; lVar++)
  3648. {
  3649. // Get the property.
  3650. hr = SafeArrayGetElement(psaNames, &lVar, &bstrPropName);
  3651. if ( eloErrLogOpt )
  3652. {
  3653. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  3654. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  3655. dwThreadId, rParsedInfo, FALSE);
  3656. }
  3657. ONFAILTHROWERROR(hr);
  3658. CHARVECTOR::iterator tempIterator;
  3659. if ( bPropList == TRUE && !Find(cvPropList,
  3660. _bstr_t(bstrPropName),
  3661. tempIterator))
  3662. {
  3663. SAFEBSTRFREE(bstrPropName);
  3664. continue;
  3665. }
  3666. PROPERTYDETAILS pdPropDet;
  3667. hr = GetPropertyAttributes(pIObject, bstrPropName,
  3668. pdPropDet,
  3669. rParsedInfo.GetGlblSwitchesObject().GetTraceStatus());
  3670. ONFAILTHROWERROR(hr);
  3671. if (bSetVerb == TRUE || bCheckWritePropsAvail == TRUE)
  3672. {
  3673. if ( !_tcsstr((_TCHAR*)pdPropDet.Operation, CLI_TOKEN_WRITE) )
  3674. {
  3675. SAFEBSTRFREE(bstrPropName);
  3676. continue;
  3677. }
  3678. }
  3679. if ( bCheckWritePropsAvail == TRUE )
  3680. {
  3681. bPropsAvail = TRUE;
  3682. SAFEBSTRFREE(bstrPropName);
  3683. break;
  3684. }
  3685. pdPropDet.Derivation = bstrPropName;
  3686. if(!rParsedInfo.GetCmdSwitchesObject().AddToPropDetMap(
  3687. bstrPropName, pdPropDet))
  3688. {
  3689. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3690. IDS_E_ADD_TO_PROP_DET_MAP_FAILURE);
  3691. bRet = FALSE;
  3692. }
  3693. SAFEBSTRFREE(bstrPropName);
  3694. }
  3695. SAFEIRELEASE(pIObject);
  3696. SAFEADESTROY(psaNames);
  3697. SAFEBSTRFREE(bstrPropName);
  3698. }
  3699. catch(_com_error& e)
  3700. {
  3701. bRet = FALSE;
  3702. SAFEIRELEASE(pIObject);
  3703. SAFEADESTROY(psaNames);
  3704. SAFEBSTRFREE(bstrPropName);
  3705. _com_issue_error(e.Error());
  3706. }
  3707. catch(CHeap_Exception)
  3708. {
  3709. bRet = FALSE;
  3710. SAFEIRELEASE(pIObject);
  3711. SAFEADESTROY(psaNames);
  3712. SAFEBSTRFREE(bstrPropName);
  3713. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  3714. }
  3715. }
  3716. else
  3717. bRet = FALSE;
  3718. if ( bCheckWritePropsAvail == TRUE )
  3719. bRet = bPropsAvail;
  3720. return bRet;
  3721. }
  3722. /*----------------------------------------------------------------------------
  3723. Name :ObtainClassMethods
  3724. Synopsis :This function obtains the information about the
  3725. available methods for a given WMI class
  3726. Type :Member Function
  3727. Input Parameter(s):
  3728. rParsedInfo - ref. to CParsedInfo object
  3729. Output Parameter(s):
  3730. rParsedInfo - ref. to CParsedInfo object
  3731. Return Type :BOOL
  3732. Global Variables :None
  3733. Calling Syntax :ObtainClassMethods(rParsedInfo)
  3734. Notes :none
  3735. ----------------------------------------------------------------------------*/
  3736. BOOL CParserEngine::ObtainClassMethods(CParsedInfo& rParsedInfo,
  3737. BOOL bCheckForExists)
  3738. {
  3739. BOOL bRet = TRUE;
  3740. BOOL bTrace = FALSE;
  3741. CHString chsMsg;
  3742. ERRLOGOPT eloErrLogOpt = NO_LOGGING;
  3743. DWORD dwThreadId = GetCurrentThreadId();
  3744. BOOL bMethAvail = FALSE;
  3745. _TCHAR* pMethodName = NULL;
  3746. bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  3747. eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  3748. if (SUCCEEDED(ConnectToNamespace(rParsedInfo)))
  3749. {
  3750. HRESULT hr = S_OK;
  3751. IWbemClassObject *pIObject = NULL,*pIInSign = NULL,*pIOutSign = NULL;
  3752. BSTR bstrMethodName = NULL;
  3753. try
  3754. {
  3755. hr = m_pITargetNS->GetObject(_bstr_t(rParsedInfo.
  3756. GetCmdSwitchesObject().GetClassPath()),
  3757. WBEM_FLAG_USE_AMENDED_QUALIFIERS,
  3758. NULL, &pIObject, NULL);
  3759. if ( eloErrLogOpt )
  3760. {
  3761. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", "
  3762. L"WBEM_FLAG_USE_AMENDED_QUALIFIERS, 0, NULL, -, -)",
  3763. rParsedInfo.GetCmdSwitchesObject().GetClassPath());
  3764. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3765. rParsedInfo, FALSE);
  3766. }
  3767. ONFAILTHROWERROR(hr);
  3768. // Begin an enumeration of the methods available for the object.
  3769. hr = pIObject->BeginMethodEnumeration(0);
  3770. if ( eloErrLogOpt )
  3771. {
  3772. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3773. _T("BeginMethodEnumeration(0)"),
  3774. dwThreadId, rParsedInfo, FALSE);
  3775. }
  3776. ONFAILTHROWERROR(hr);
  3777. //To get info about only method if method is specified
  3778. pMethodName = rParsedInfo.GetCmdSwitchesObject().
  3779. GetMethodName();
  3780. // Retrieve the next method in the method enumeration
  3781. // sequence
  3782. while ((pIObject->NextMethod(0, &bstrMethodName, &pIInSign,
  3783. &pIOutSign)) != WBEM_S_NO_MORE_DATA)
  3784. {
  3785. if ( bCheckForExists == TRUE )
  3786. {
  3787. bMethAvail = TRUE;
  3788. SAFEBSTRFREE(bstrMethodName);
  3789. SAFEIRELEASE(pIInSign);
  3790. SAFEIRELEASE(pIOutSign);
  3791. break;
  3792. }
  3793. if(pMethodName != NULL &&
  3794. !CompareTokens(pMethodName, (_TCHAR*)bstrMethodName))
  3795. {
  3796. SAFEBSTRFREE(bstrMethodName);
  3797. SAFEIRELEASE(pIInSign);
  3798. SAFEIRELEASE(pIOutSign);
  3799. continue;
  3800. }
  3801. METHODDETAILS mdMethDet;
  3802. if (pIInSign)
  3803. hr = ObtainMethodParamInfo(pIInSign, mdMethDet, INP,
  3804. rParsedInfo.GetGlblSwitchesObject().GetTraceStatus(),
  3805. rParsedInfo);
  3806. ONFAILTHROWERROR(hr);
  3807. if (pIOutSign)
  3808. hr = ObtainMethodParamInfo(pIOutSign, mdMethDet, OUTP,
  3809. rParsedInfo.GetGlblSwitchesObject().GetTraceStatus(),
  3810. rParsedInfo);
  3811. ONFAILTHROWERROR(hr);
  3812. _bstr_t bstrStatus, bstrDesc;
  3813. hr = GetMethodStatusAndDesc(pIObject,
  3814. bstrMethodName, bstrStatus, bstrDesc,
  3815. rParsedInfo.GetGlblSwitchesObject().GetTraceStatus());
  3816. mdMethDet.Status = _bstr_t(bstrStatus);
  3817. mdMethDet.Description = _bstr_t(bstrDesc);
  3818. ONFAILTHROWERROR(hr);
  3819. if(!rParsedInfo.GetCmdSwitchesObject().AddToMethDetMap(
  3820. _bstr_t(bstrMethodName),mdMethDet))
  3821. {
  3822. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  3823. IDS_E_ADD_TO_METH_DET_MAP_FAILURE);
  3824. SAFEBSTRFREE(bstrMethodName);
  3825. SAFEIRELEASE(pIInSign);
  3826. SAFEIRELEASE(pIOutSign);
  3827. bRet = FALSE;
  3828. break;
  3829. }
  3830. SAFEBSTRFREE(bstrMethodName);
  3831. SAFEIRELEASE(pIInSign);
  3832. SAFEIRELEASE(pIOutSign);
  3833. }
  3834. SAFEIRELEASE(pIObject);
  3835. }
  3836. catch(_com_error& e)
  3837. {
  3838. SAFEBSTRFREE(bstrMethodName);
  3839. SAFEIRELEASE(pIInSign);
  3840. SAFEIRELEASE(pIOutSign);
  3841. SAFEIRELEASE(pIObject);
  3842. _com_issue_error(e.Error());
  3843. bRet = FALSE;
  3844. }
  3845. catch(CHeap_Exception)
  3846. {
  3847. bRet = FALSE;
  3848. SAFEBSTRFREE(bstrMethodName);
  3849. SAFEIRELEASE(pIInSign);
  3850. SAFEIRELEASE(pIOutSign);
  3851. SAFEIRELEASE(pIObject);
  3852. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  3853. }
  3854. }
  3855. else
  3856. bRet = FALSE;
  3857. if ( bCheckForExists == TRUE )
  3858. bRet = bMethAvail;
  3859. return bRet;
  3860. }
  3861. /*----------------------------------------------------------------------------
  3862. Name :ConnectToNamespace
  3863. Synopsis :This function connects to the WMI namespace on the
  3864. target machine using the supplied user credentials.
  3865. Type :Member Function
  3866. Input Parameter(s):
  3867. rParsedInfo - reference to CParsedInfo class object
  3868. Output Parameter(s):
  3869. rParsedInfo - reference to CParsedInfo class object
  3870. Return Type :HRESULT
  3871. Global Variables :None
  3872. Calling Syntax :ConnectToNamespace(rParsedInfo)
  3873. Notes :none
  3874. ----------------------------------------------------------------------------*/
  3875. HRESULT CParserEngine::ConnectToNamespace(CParsedInfo& rParsedInfo)
  3876. {
  3877. HRESULT hr = S_OK;
  3878. DWORD dwThreadId = GetCurrentThreadId();
  3879. if (rParsedInfo.GetGlblSwitchesObject().GetNameSpaceFlag())
  3880. {
  3881. BOOL bTrace = FALSE;
  3882. CHString chsMsg;
  3883. ERRLOGOPT eloErrLogOpt = NO_LOGGING;
  3884. // Obtain the trace status
  3885. bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  3886. eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  3887. SAFEIRELEASE(m_pITargetNS);
  3888. try
  3889. {
  3890. // Connect to the WMI namespace on the target machine
  3891. // using the supplied user credentials.
  3892. hr = Connect(m_pIWbemLocator, &m_pITargetNS,
  3893. _bstr_t(rParsedInfo.GetNamespace()),
  3894. NULL,
  3895. NULL,
  3896. _bstr_t(rParsedInfo.GetLocale()),
  3897. rParsedInfo);
  3898. if (bTrace || eloErrLogOpt)
  3899. {
  3900. chsMsg.Format(L"IWbemLocator::ConnectServer(L\"%s\", NULL, "
  3901. L"NULL, L\"%s\", 0L, NULL, NULL, -)",
  3902. rParsedInfo.GetNamespace(),
  3903. rParsedInfo.GetLocale());
  3904. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3905. rParsedInfo, bTrace);
  3906. }
  3907. ONFAILTHROWERROR(hr);
  3908. // set the security privileges at the interface level
  3909. hr = SetSecurity(m_pITargetNS, NULL, NULL, NULL, NULL,
  3910. rParsedInfo.GetGlblSwitchesObject().
  3911. GetAuthenticationLevel(),
  3912. rParsedInfo.GetGlblSwitchesObject().
  3913. GetImpersonationLevel());
  3914. if (bTrace || eloErrLogOpt)
  3915. {
  3916. chsMsg.Format(L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, "
  3917. L"RPC_C_AUTHZ_NONE, NULL, %d, %d, -, EOAC_NONE)",
  3918. rParsedInfo.GetGlblSwitchesObject().
  3919. GetAuthenticationLevel(),
  3920. rParsedInfo.GetGlblSwitchesObject().
  3921. GetImpersonationLevel());
  3922. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3923. rParsedInfo, bTrace);
  3924. }
  3925. ONFAILTHROWERROR(hr);
  3926. rParsedInfo.GetGlblSwitchesObject().SetNameSpaceFlag(FALSE);
  3927. }
  3928. catch(_com_error& e)
  3929. {
  3930. // execption handling
  3931. _com_issue_error(e.Error());
  3932. }
  3933. catch(CHeap_Exception)
  3934. {
  3935. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  3936. }
  3937. }
  3938. return hr;
  3939. }
  3940. /*----------------------------------------------------------------------------
  3941. Name :ObtainMethodParamInfo
  3942. Synopsis :This function obtains the information about the method
  3943. arguments (both input and output arguments)
  3944. Type :Member Function
  3945. Input Parameter(s):
  3946. pIObj - pointer to IWbemClassObject object
  3947. bTrace - trace flag
  3948. ioInOrOut - INOROUT type specifies in or out parameter type.
  3949. Output Parameter(s):
  3950. mdMethDet - method details structure
  3951. Return Type :HRESULT
  3952. Global Variables :None
  3953. Calling Syntax :ObtainMethodParamInfo(pIObj, mdMethDet, IN, bTrace, rParsedInfo)
  3954. Notes :none
  3955. ----------------------------------------------------------------------------*/
  3956. HRESULT CParserEngine::ObtainMethodParamInfo(IWbemClassObject* pIObj,
  3957. METHODDETAILS& mdMethDet,
  3958. INOROUT ioInOrOut,
  3959. BOOL bTrace, CParsedInfo& rParsedInfo)
  3960. {
  3961. HRESULT hr = S_OK;
  3962. SAFEARRAY* psaNames = NULL;
  3963. BSTR bstrPropName = NULL;
  3964. CHString chsMsg;
  3965. _TCHAR szNumber[BUFFER512] = NULL_STRING;
  3966. ERRLOGOPT eloErrLogOpt = NO_LOGGING;
  3967. DWORD dwThreadId = GetCurrentThreadId();
  3968. // Get the property names
  3969. try
  3970. {
  3971. if ( pIObj != NULL )
  3972. {
  3973. hr = pIObj->GetNames(NULL,
  3974. WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY,
  3975. NULL, &psaNames);
  3976. if (bTrace || eloErrLogOpt)
  3977. {
  3978. chsMsg.Format(L"IWbemClassObject::GetNames(NULL, "
  3979. L"WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, "
  3980. L"NULL, -)");
  3981. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3982. rParsedInfo, bTrace);
  3983. }
  3984. ONFAILTHROWERROR(hr);
  3985. // Get the number of properties.
  3986. LONG lLower = 0, lUpper = 0;
  3987. hr = SafeArrayGetLBound(psaNames, 1, &lLower);
  3988. if ( eloErrLogOpt )
  3989. {
  3990. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  3991. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3992. rParsedInfo, FALSE);
  3993. }
  3994. ONFAILTHROWERROR(hr);
  3995. hr = SafeArrayGetUBound(psaNames, 1, &lUpper);
  3996. if ( eloErrLogOpt )
  3997. {
  3998. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  3999. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  4000. rParsedInfo, FALSE);
  4001. }
  4002. ONFAILTHROWERROR(hr);
  4003. // For each property obtian the information of our interest
  4004. for (LONG lVar = lLower; lVar <= lUpper; lVar++)
  4005. {
  4006. // Get the property.
  4007. hr = SafeArrayGetElement(psaNames, &lVar, &bstrPropName);
  4008. if ( eloErrLogOpt )
  4009. {
  4010. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  4011. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  4012. dwThreadId, rParsedInfo, FALSE);
  4013. }
  4014. ONFAILTHROWERROR(hr);
  4015. PROPERTYDETAILS pdPropDet;
  4016. hr = GetPropertyAttributes(pIObj,
  4017. bstrPropName, pdPropDet, bTrace);
  4018. ONFAILTHROWERROR(hr);
  4019. // 'ReturnValue' is not a property of our interest as per
  4020. // the expected output given in the sample, hence omitting
  4021. // the same.
  4022. if ( bstrPropName != NULL )
  4023. {
  4024. PROPERTYDETAILS pdIPropDet;
  4025. pdIPropDet.Type = pdPropDet.Type;
  4026. pdIPropDet.InOrOut = ioInOrOut;
  4027. // Making bstrPropName begin with numbers to maintain
  4028. // the order of method arguments in map.
  4029. // while displaying remove numbers and display the
  4030. // parameters in case of help only.
  4031. _bstr_t bstrNumberedPropName;
  4032. if ( rParsedInfo.GetGlblSwitchesObject().GetHelpFlag() )
  4033. {
  4034. if ( ioInOrOut == INP )
  4035. _ltot(lVar, szNumber, 10);
  4036. else
  4037. _ltot(lVar + 500, szNumber, 10);
  4038. chsMsg.Format(L"%-5s", szNumber);
  4039. bstrNumberedPropName = _bstr_t(chsMsg) +
  4040. _bstr_t(bstrPropName);
  4041. }
  4042. else
  4043. bstrNumberedPropName = _bstr_t(bstrPropName);
  4044. mdMethDet.Params.insert(PROPDETMAP::value_type(
  4045. bstrNumberedPropName,pdIPropDet));
  4046. }
  4047. // Free the memory allocated using SysAllocString for
  4048. // bstrPropName
  4049. SAFEBSTRFREE(bstrPropName);
  4050. }
  4051. // Destroy array descriptor and all of the data in the array
  4052. SAFEADESTROY(psaNames);
  4053. }
  4054. }
  4055. catch(_com_error& e)
  4056. {
  4057. SAFEBSTRFREE(bstrPropName);
  4058. SAFEADESTROY(psaNames);
  4059. hr = e.Error();
  4060. }
  4061. catch(CHeap_Exception)
  4062. {
  4063. SAFEBSTRFREE(bstrPropName);
  4064. SAFEADESTROY(psaNames);
  4065. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  4066. }
  4067. return hr;
  4068. }
  4069. /*----------------------------------------------------------------------------
  4070. Name :GetMethodStatusAndDesc
  4071. Synopsis :This function obtains the implementation status and
  4072. description of the verbs available
  4073. Type :Member Function
  4074. Input Parameter(s):
  4075. pIObj - pointer to IWbemClassObject object
  4076. bstrMethod - method name
  4077. bTrace - trace flag
  4078. Output Parameter(s):
  4079. bstrStatus - implementation status
  4080. bstrDesc - Method description
  4081. Return Type :HRESULT
  4082. Global Variables :None
  4083. Calling Syntax : GetMethodStatusAndDesc(pIObj, bstrMethod,
  4084. bstrStatus, bstrDesc, bTrace)
  4085. Notes :none
  4086. ----------------------------------------------------------------------------*/
  4087. HRESULT CParserEngine::GetMethodStatusAndDesc(IWbemClassObject* pIObj,
  4088. BSTR bstrMethod,
  4089. _bstr_t& bstrStatus,
  4090. _bstr_t& bstrDesc,
  4091. BOOL bTrace)
  4092. {
  4093. HRESULT hr = S_OK;
  4094. IWbemQualifierSet* pIQualSet = NULL;
  4095. VARIANT vtStatus, vtDesc;
  4096. VariantInit(&vtStatus);
  4097. VariantInit(&vtDesc);
  4098. try
  4099. {
  4100. if ( pIObj != NULL )
  4101. {
  4102. // Obtain the method qualifier set.
  4103. hr = pIObj->GetMethodQualifierSet(bstrMethod, &pIQualSet);
  4104. if ( pIQualSet != NULL )
  4105. {
  4106. // Retrieve the 'Implemented' qualifier status value
  4107. hr = pIQualSet->Get(_bstr_t(L"Implemented"),
  4108. 0L, &vtStatus, NULL);
  4109. if (SUCCEEDED(hr))
  4110. {
  4111. if (vtStatus.vt != VT_EMPTY && vtStatus.vt != VT_NULL )
  4112. {
  4113. if ( vtStatus.boolVal )
  4114. bstrStatus = L"Implemented";
  4115. else
  4116. bstrStatus = L"Not Implemented";
  4117. }
  4118. else
  4119. bstrStatus = L"Not Found";
  4120. }
  4121. else
  4122. bstrStatus = L"Not Found";
  4123. VARIANTCLEAR(vtStatus);
  4124. // Should not break here, hence the HRESULT should be set to S_OK
  4125. hr = S_OK;
  4126. // Retrieve the 'Description' qualifier text
  4127. hr = pIQualSet->Get(_bstr_t(L"Description"), 0L ,
  4128. &vtDesc, NULL);
  4129. if (SUCCEEDED(hr))
  4130. {
  4131. if (vtDesc.vt == VT_BSTR)
  4132. bstrDesc = _bstr_t(vtDesc.bstrVal);
  4133. else
  4134. bstrDesc = L"Not available";
  4135. }
  4136. else
  4137. bstrDesc = L"Not available";
  4138. VARIANTCLEAR(vtDesc);
  4139. // Should not break here, hence the HRESULT should be set to S_OK
  4140. hr = S_OK;
  4141. SAFEIRELEASE(pIQualSet);
  4142. }
  4143. else
  4144. hr = S_OK;
  4145. }
  4146. }
  4147. catch(_com_error& e)
  4148. {
  4149. VARIANTCLEAR(vtStatus);
  4150. VARIANTCLEAR(vtDesc);
  4151. SAFEIRELEASE(pIQualSet);
  4152. hr = e.Error();
  4153. }
  4154. return hr;
  4155. }
  4156. /*----------------------------------------------------------------------------
  4157. Name :CheckforHelp
  4158. Synopsis :This function looks ahead one token to see if the next
  4159. token is '?'
  4160. Type :Member Function
  4161. Input Parameter(s):
  4162. cvTokens - the tokens vector
  4163. theIterator - the Iterator to the cvTokens vector.
  4164. rParsedInfo - reference to CParsedInfo class object.
  4165. uErrataCode - error string ID
  4166. Output Parameter(s):
  4167. rParsedInfo - reference to CParsedInfo class object
  4168. Return Type :RETCODE - enumerated data type.
  4169. Global Variables :None
  4170. Calling Syntax :CheckforHelp(cvtokens,theIterator,rParsedInfo,uErrataCode)
  4171. Notes :none
  4172. ----------------------------------------------------------------------------*/
  4173. RETCODE CParserEngine::CheckForHelp(CHARVECTOR& cvTokens,
  4174. CHARVECTOR::iterator& theIterator,
  4175. CParsedInfo& rParsedInfo,
  4176. UINT uErrataCode)
  4177. {
  4178. RETCODE retCode = PARSER_DISPHELP;
  4179. // Set the retCode as PARSER_ERROR if no more tokens
  4180. // are present.
  4181. if(!GetNextToken(cvTokens, theIterator))
  4182. {
  4183. retCode = PARSER_ERROR;
  4184. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(uErrataCode);
  4185. }
  4186. else if(!CompareTokens(*theIterator, CLI_TOKEN_HELP))
  4187. {
  4188. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4189. uErrataCode);
  4190. retCode = PARSER_ERROR;
  4191. }
  4192. else
  4193. {
  4194. retCode = ParseHelp(cvTokens, theIterator, rParsedInfo, FALSE);
  4195. }
  4196. return retCode;
  4197. }
  4198. /*----------------------------------------------------------------------------
  4199. Name :ValidateGlobalSwitchValue
  4200. Synopsis :This function checks whether global switches are
  4201. specified in the expected format or not.
  4202. Type :Member Function
  4203. Input Parameter(s):
  4204. cvTokens - the tokens vector
  4205. theIterator - the Iterator to the cvTokens vector.
  4206. uErrataCode - error string
  4207. rParsedInfo - reference to CParsedInfo class object.
  4208. uErrataCode2 - error string2 ID
  4209. htHelp - help type
  4210. Output Parameter(s):
  4211. rParsedInfo - reference to CParsedInfo class object
  4212. Return Type :RETCODE - enumerated data type.
  4213. Global Variables :None
  4214. Calling Syntax :ValidateGlobalSwitchValue(cvTokens, theIterator,
  4215. uErrataCode, rParsedInfo,
  4216. uErrataCode2, htHelp)
  4217. Notes :none
  4218. ----------------------------------------------------------------------------*/
  4219. RETCODE CParserEngine::ValidateGlobalSwitchValue(CHARVECTOR& cvTokens,
  4220. CHARVECTOR::iterator& theIterator,
  4221. UINT uErrataCode,
  4222. CParsedInfo& rParsedInfo,
  4223. UINT uErrataCode2,
  4224. HELPTYPE htHelp)
  4225. {
  4226. RETCODE retCode = PARSER_CONTINUE;
  4227. retCode = GetNextToken(cvTokens, theIterator, rParsedInfo,
  4228. htHelp, uErrataCode2);
  4229. if (retCode == PARSER_CONTINUE)
  4230. {
  4231. // Check for the presence of the ':'
  4232. if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  4233. {
  4234. // Move to next token
  4235. if (GetNextToken(cvTokens, theIterator, rParsedInfo,
  4236. uErrataCode))
  4237. {
  4238. if (IsOption(*theIterator))
  4239. {
  4240. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4241. uErrataCode);
  4242. retCode = PARSER_ERROR;
  4243. }
  4244. else
  4245. retCode = PARSER_CONTINUE;
  4246. }
  4247. else
  4248. retCode = PARSER_ERROR;
  4249. }
  4250. else if (IsOption(*theIterator))
  4251. {
  4252. retCode = CheckForHelp(cvTokens, theIterator,
  4253. rParsedInfo, uErrataCode2);
  4254. if (retCode == PARSER_DISPHELP)
  4255. {
  4256. rParsedInfo.GetGlblSwitchesObject().SetHelpFlag(TRUE);
  4257. rParsedInfo.GetHelpInfoObject().SetHelp(htHelp, TRUE);
  4258. }
  4259. }
  4260. else
  4261. {
  4262. rParsedInfo.GetCmdSwitchesObject().
  4263. SetErrataCode(uErrataCode2);
  4264. retCode = PARSER_ERROR;
  4265. }
  4266. }
  4267. return retCode;
  4268. }
  4269. /*----------------------------------------------------------------------------
  4270. Name :ParseEVERYSwitch
  4271. Synopsis :This function checks whether the value specified for the
  4272. /EVERY swith is valid or not.
  4273. Type :Member Function
  4274. Input Parameter(s):
  4275. cvTokens - the tokens vector
  4276. theIterator - the Iterator to the cvTokens vector.
  4277. rParsedInfo - reference to CParsedInfo class object.
  4278. Output Parameter(s):
  4279. rParsedInfo - reference to CParsedInfo class object
  4280. Return Type :RETCODE - enumerated data type.
  4281. Global Variables :None
  4282. Calling Syntax :ParseEVERYSwitch(cvTokens, theIterator, rParsedInfo)
  4283. Notes :none
  4284. ----------------------------------------------------------------------------*/
  4285. RETCODE CParserEngine::ParseEVERYSwitch(CHARVECTOR& cvTokens,
  4286. CHARVECTOR::iterator& theIterator,
  4287. CParsedInfo& rParsedInfo)
  4288. {
  4289. RETCODE retCode = PARSER_EXECCOMMAND;
  4290. retCode = ParseNumberedSwitch(cvTokens, theIterator, rParsedInfo,
  4291. EVERY, IDS_E_INVALID_EVERY_SWITCH,
  4292. IDS_E_INVALID_INTERVAL);
  4293. if ( retCode == PARSER_EXECCOMMAND )
  4294. {
  4295. if (GetNextToken(cvTokens, theIterator) == TRUE )
  4296. {
  4297. if ( CompareTokens(*theIterator, CLI_TOKEN_FSLASH) == TRUE )
  4298. {
  4299. if ( GetNextToken(cvTokens, theIterator) == TRUE )
  4300. {
  4301. if (CompareTokens(*theIterator, CLI_TOKEN_REPEAT) == TRUE)
  4302. {
  4303. retCode = ParseNumberedSwitch(cvTokens,
  4304. theIterator,
  4305. rParsedInfo,
  4306. REPEAT,
  4307. IDS_E_INVALID_REPEAT_SWITCH,
  4308. IDS_E_INVALID_REPEATCOUNT);
  4309. }
  4310. else
  4311. theIterator = theIterator - 2;
  4312. }
  4313. else
  4314. theIterator = theIterator - 2;
  4315. }
  4316. else
  4317. theIterator = theIterator - 1;
  4318. }
  4319. }
  4320. return retCode;
  4321. }
  4322. /*----------------------------------------------------------------------------
  4323. Name :ParseFORMATSwitch
  4324. Synopsis :This function checks whether the value specified for the
  4325. /FORMAT swith is valid or not.
  4326. Type :Member Function
  4327. Input Parameter(s):
  4328. cvTokens - the tokens vector
  4329. theIterator - the Iterator to the cvTokens vector.
  4330. rParsedInfo - reference to CParsedInfo class object.
  4331. Output Parameter(s):
  4332. rParsedInfo - reference to CParsedInfo class object
  4333. Return Type :RETCODE - enumerated data type.
  4334. Global Variables :None
  4335. Calling Syntax :ParseFORMATSwitch(cvTokens, theIterator, rParsedInfo)
  4336. Notes :none
  4337. ----------------------------------------------------------------------------*/
  4338. RETCODE CParserEngine::ParseFORMATSwitch(CHARVECTOR& cvTokens,
  4339. CHARVECTOR::iterator& theIterator,
  4340. CParsedInfo& rParsedInfo)
  4341. {
  4342. RETCODE retCode = PARSER_EXECCOMMAND;
  4343. // Reset the XSL file path.
  4344. rParsedInfo.GetCmdSwitchesObject().ClearXSLTDetailsVector();
  4345. // Move to next token
  4346. if (!GetNextToken(cvTokens, theIterator))
  4347. {
  4348. retCode = PARSER_EXECCOMMAND;
  4349. // If Translate table name is given then set the flag
  4350. if( rParsedInfo.GetCmdSwitchesObject().
  4351. GetTranslateTableName() != NULL )
  4352. {
  4353. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(TRUE);
  4354. }
  4355. else
  4356. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(FALSE);
  4357. }
  4358. else if ( IsOption(*theIterator) &&
  4359. (theIterator + 1) < cvTokens.end() &&
  4360. CompareTokens(*(theIterator+1), CLI_TOKEN_HELP) )
  4361. {
  4362. theIterator++;
  4363. retCode = ParseHelp(cvTokens, theIterator, FORMAT, rParsedInfo);
  4364. }
  4365. else if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  4366. {
  4367. while ( retCode == PARSER_EXECCOMMAND &&
  4368. theIterator < cvTokens.end() )
  4369. {
  4370. XSLTDET xdXSLTDet;
  4371. BOOL bFrameXSLFile = TRUE;
  4372. // Move to next token
  4373. if (!GetNextToken(cvTokens, theIterator))
  4374. {
  4375. // PARSER_ERROR if <format specifier> is missing
  4376. rParsedInfo.GetCmdSwitchesObject().
  4377. SetErrataCode(IDS_E_INVALID_FORMAT);
  4378. retCode = PARSER_ERROR;
  4379. }
  4380. else if ( IsOption(*theIterator) )
  4381. {
  4382. rParsedInfo.GetCmdSwitchesObject().
  4383. SetErrataCode(IDS_E_INVALID_FORMAT);
  4384. retCode = PARSER_ERROR;
  4385. }
  4386. else
  4387. {
  4388. xdXSLTDet.FileName = *theIterator;
  4389. if(!g_wmiCmd.GetFileFromKey(*theIterator, xdXSLTDet.FileName))
  4390. bFrameXSLFile = FALSE;
  4391. }
  4392. if ( retCode == PARSER_EXECCOMMAND )
  4393. {
  4394. if ( !GetNextToken(cvTokens, theIterator) )
  4395. {
  4396. if ( bFrameXSLFile == TRUE )
  4397. {
  4398. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  4399. rParsedInfo))
  4400. retCode = PARSER_ERRMSG;
  4401. }
  4402. else
  4403. rParsedInfo.GetCmdSwitchesObject().
  4404. AddToXSLTDetailsVector(xdXSLTDet);
  4405. break;
  4406. }
  4407. else if ( IsOption(*theIterator) )
  4408. {
  4409. theIterator--;
  4410. if ( bFrameXSLFile == TRUE )
  4411. {
  4412. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  4413. rParsedInfo))
  4414. retCode = PARSER_ERRMSG;
  4415. }
  4416. else
  4417. rParsedInfo.GetCmdSwitchesObject().
  4418. AddToXSLTDetailsVector(xdXSLTDet);
  4419. break;
  4420. }
  4421. else if ( CompareTokens(*theIterator, CLI_TOKEN_COLON ) )
  4422. {
  4423. _TCHAR* pszXSLFile = NULL;
  4424. retCode = ParseParamsString(cvTokens, theIterator,
  4425. rParsedInfo, xdXSLTDet,
  4426. pszXSLFile);
  4427. if ( retCode == PARSER_EXECCOMMAND &&
  4428. (theIterator != cvTokens.end()) && IsOption(*theIterator) )
  4429. {
  4430. theIterator--;
  4431. if ( bFrameXSLFile == TRUE )
  4432. {
  4433. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  4434. rParsedInfo))
  4435. retCode = PARSER_ERRMSG;
  4436. }
  4437. else
  4438. rParsedInfo.GetCmdSwitchesObject().
  4439. AddToXSLTDetailsVector(xdXSLTDet);
  4440. if ( pszXSLFile != NULL &&
  4441. retCode == PARSER_EXECCOMMAND )
  4442. {
  4443. XSLTDET xdXSLDetOnlyFile;
  4444. BOOL bInnerFrameXSLFile = TRUE;
  4445. xdXSLDetOnlyFile.FileName = pszXSLFile;
  4446. if(!g_wmiCmd.GetFileFromKey(pszXSLFile,
  4447. xdXSLTDet.FileName))
  4448. bInnerFrameXSLFile = FALSE;
  4449. if ( bInnerFrameXSLFile == TRUE )
  4450. {
  4451. if (!FrameFileAndAddToXSLTDetVector(xdXSLDetOnlyFile,
  4452. rParsedInfo))
  4453. retCode = PARSER_ERRMSG;
  4454. }
  4455. else
  4456. rParsedInfo.GetCmdSwitchesObject().
  4457. AddToXSLTDetailsVector(xdXSLDetOnlyFile);
  4458. }
  4459. break;
  4460. }
  4461. }
  4462. else if ( !CompareTokens(*theIterator, CLI_TOKEN_COMMA ) )
  4463. {
  4464. rParsedInfo.GetCmdSwitchesObject().
  4465. SetErrataCode(IDS_E_INVALID_FORMAT);
  4466. retCode = PARSER_ERROR;
  4467. }
  4468. }
  4469. if ( retCode == PARSER_EXECCOMMAND )
  4470. {
  4471. if ( bFrameXSLFile == TRUE )
  4472. {
  4473. if (!FrameFileAndAddToXSLTDetVector(xdXSLTDet, rParsedInfo))
  4474. retCode = PARSER_ERRMSG;
  4475. }
  4476. else
  4477. rParsedInfo.GetCmdSwitchesObject().
  4478. AddToXSLTDetailsVector(xdXSLTDet);
  4479. }
  4480. }
  4481. // If Translate table name is given then set the flag
  4482. if( rParsedInfo.GetCmdSwitchesObject().
  4483. GetTranslateTableName() != NULL )
  4484. {
  4485. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(TRUE);
  4486. }
  4487. else
  4488. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(FALSE);
  4489. }
  4490. else
  4491. {
  4492. theIterator--;
  4493. }
  4494. return retCode;
  4495. }
  4496. /*----------------------------------------------------------------------------
  4497. Name :IsStdVerbOrUserDefVerb
  4498. Synopsis :This function checks whether the verb is standard verb
  4499. or user defined verb for alias.
  4500. Type :Member Function
  4501. Input Parameter(s):
  4502. pszToken - the verb name string
  4503. rParsedInfo - reference to CParsedInfo class object
  4504. Output Parameter(s): None
  4505. Return Type :BOOL
  4506. Global Variables :None
  4507. Calling Syntax :IsStdVerbOrUserDefVerb( pszToken,rParsedInfo)
  4508. Notes :none
  4509. ----------------------------------------------------------------------------*/
  4510. BOOL CParserEngine::IsStdVerbOrUserDefVerb(_bstr_t bstrToken,
  4511. CParsedInfo& rParsedInfo)
  4512. {
  4513. BOOL bStdVerbOrUserDefVerb = FALSE;
  4514. try
  4515. {
  4516. if ( CompareTokens(bstrToken, CLI_TOKEN_GET) ||
  4517. CompareTokens(bstrToken, CLI_TOKEN_LIST) ||
  4518. CompareTokens(bstrToken, CLI_TOKEN_SET) ||
  4519. CompareTokens(bstrToken, CLI_TOKEN_CREATE) ||
  4520. CompareTokens(bstrToken, CLI_TOKEN_CALL) ||
  4521. CompareTokens(bstrToken, CLI_TOKEN_ASSOC) ||
  4522. CompareTokens(bstrToken, CLI_TOKEN_DELETE) )
  4523. bStdVerbOrUserDefVerb = TRUE;
  4524. else
  4525. {
  4526. if ( m_bAliasName )
  4527. {
  4528. METHDETMAP mdmMethDetMap = rParsedInfo.GetCmdSwitchesObject()
  4529. .GetMethDetMap();
  4530. if ( mdmMethDetMap.empty() )
  4531. {
  4532. m_CmdAlias.ObtainAliasVerbDetails(rParsedInfo);
  4533. mdmMethDetMap = rParsedInfo.GetCmdSwitchesObject()
  4534. .GetMethDetMap();
  4535. }
  4536. METHDETMAP::iterator theMethIterator = NULL;
  4537. for ( theMethIterator = mdmMethDetMap.begin();
  4538. theMethIterator != mdmMethDetMap.end(); theMethIterator++ )
  4539. {
  4540. if ( CompareTokens((*theMethIterator).first,bstrToken) )
  4541. {
  4542. bStdVerbOrUserDefVerb = TRUE;
  4543. break;
  4544. }
  4545. }
  4546. }
  4547. }
  4548. }
  4549. catch(_com_error& e)
  4550. {
  4551. bStdVerbOrUserDefVerb = FALSE;
  4552. _com_issue_error(e.Error());
  4553. }
  4554. return bStdVerbOrUserDefVerb;
  4555. }
  4556. /*----------------------------------------------------------------------------
  4557. Name :ParseTRANSLATESwitch
  4558. Synopsis :This function parses for translate switch in the command.
  4559. Type :Member Function
  4560. Input Parameter(s):
  4561. cvTokens - the tokens vector
  4562. theIterator - the Iterator to the cvTokens vector.
  4563. rParsedInfo - reference to CParsedInfo class object.
  4564. Output Parameter(s) :
  4565. rParsedInfo - reference to CParsedInfo class object
  4566. Return Type :RETCODE-enumerated type
  4567. Global Variables :None
  4568. Calling Syntax :ParseTRANSLATESwitch(cvTokens,theIterator,rParsedInfo)
  4569. Notes :none
  4570. ----------------------------------------------------------------------------*/
  4571. RETCODE CParserEngine::ParseTRANSLATESwitch(CHARVECTOR& cvTokens,
  4572. CHARVECTOR::iterator& theIterator,
  4573. CParsedInfo& rParsedInfo)
  4574. {
  4575. RETCODE retCode = PARSER_EXECCOMMAND;
  4576. if ( GetNextToken(cvTokens, theIterator, rParsedInfo, TRANSLATE,
  4577. IDS_E_INVALID_TRANSLATE_SWITCH) == PARSER_CONTINUE )
  4578. {
  4579. if ( IsOption(*theIterator) &&
  4580. (theIterator + 1) < cvTokens.end() &&
  4581. CompareTokens(*(theIterator+1), CLI_TOKEN_HELP) )
  4582. {
  4583. theIterator++;
  4584. retCode = ParseHelp(cvTokens, theIterator, TRANSLATE,
  4585. rParsedInfo);
  4586. if ( retCode == PARSER_DISPHELP )
  4587. {
  4588. if( FAILED(m_CmdAlias.ConnectToAlias(rParsedInfo,
  4589. m_pIWbemLocator)))
  4590. retCode = PARSER_ERRMSG;
  4591. if ( FAILED(m_CmdAlias.ObtainTranslateTables(rParsedInfo)))
  4592. retCode = PARSER_ERRMSG;
  4593. }
  4594. }
  4595. else if ( CompareTokens( *theIterator, CLI_TOKEN_COLON ) &&
  4596. GetNextToken(cvTokens, theIterator, rParsedInfo, TRANSLATE,
  4597. IDS_E_INVALID_TRANSLATE_SWITCH) == PARSER_CONTINUE )
  4598. {
  4599. rParsedInfo.GetCmdSwitchesObject().SetTranslateTableName(*theIterator);
  4600. if ( IsOption(*theIterator) )
  4601. {
  4602. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4603. IDS_E_INVALID_TRANSLATE_SWITCH);
  4604. retCode = PARSER_ERROR;
  4605. }
  4606. else if(FAILED(m_CmdAlias.ConnectToAlias(rParsedInfo,
  4607. m_pIWbemLocator)))
  4608. retCode = PARSER_ERRMSG;
  4609. else if ( m_CmdAlias.ObtainTranslateTableEntries(rParsedInfo) == TRUE )
  4610. retCode = PARSER_EXECCOMMAND;
  4611. else
  4612. {
  4613. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4614. IDS_E_TRANSLATE_TABLE_NOT_EXIST);
  4615. retCode = PARSER_ERROR;
  4616. }
  4617. // If Format switch is specified after translate switch then
  4618. // set the flag else reset it
  4619. if(rParsedInfo.GetCmdSwitchesObject().GetXSLTDetailsVector().
  4620. empty())
  4621. {
  4622. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(TRUE);
  4623. }
  4624. else
  4625. rParsedInfo.GetCmdSwitchesObject().SetTranslateFirstFlag(FALSE);
  4626. }
  4627. else
  4628. {
  4629. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4630. IDS_E_INVALID_TRANSLATE_SWITCH);
  4631. retCode = PARSER_ERROR;
  4632. }
  4633. }
  4634. else
  4635. retCode = PARSER_ERROR;
  4636. return retCode;
  4637. }
  4638. /*----------------------------------------------------------------------------
  4639. Name :ParseContextInfo
  4640. Synopsis :This function does the parsing of the help on context
  4641. information
  4642. Type :Member Function
  4643. Input Parameter(s):
  4644. cvTokens - the tokens vector
  4645. theIterator - the Iterator to the cvTokens vector.
  4646. rParsedInfo - reference to CParsedInfo class object
  4647. Output parameter(s):
  4648. rParsedInfo - reference to CParsedInfo class object
  4649. Return Type :RETCODE - enumerated data type
  4650. Global Variables :None
  4651. Calling Syntax :ParseContextInfo(cvTokens, theIterator, rParsedInfo)
  4652. Notes :None
  4653. ----------------------------------------------------------------------------*/
  4654. RETCODE CParserEngine::ParseContextInfo(CHARVECTOR& cvTokens,
  4655. CHARVECTOR::iterator& theIterator,
  4656. CParsedInfo& rParsedInfo)
  4657. {
  4658. //BNF: CONTEXT /?[:<FULL|BRIEF>]
  4659. BOOL bContinue = TRUE;
  4660. RETCODE retCode = PARSER_MESSAGE;
  4661. // If option
  4662. if (IsOption(*theIterator))
  4663. {
  4664. // Check for help
  4665. retCode = IsHelp(cvTokens, theIterator, rParsedInfo, CONTEXTHELP,
  4666. IDS_E_INVALID_CONTEXT_SYNTAX, LEVEL_ONE);
  4667. // If more tokens are present.
  4668. if (retCode == PARSER_CONTINUE)
  4669. {
  4670. rParsedInfo.GetCmdSwitchesObject().
  4671. SetErrataCode(IDS_E_INVALID_CONTEXT_SYNTAX);
  4672. retCode = PARSER_ERROR;
  4673. }
  4674. }
  4675. else
  4676. {
  4677. rParsedInfo.GetCmdSwitchesObject().
  4678. SetErrataCode(IDS_E_INVALID_CONTEXT_SYNTAX);
  4679. retCode = PARSER_ERROR;
  4680. }
  4681. return retCode;
  4682. }
  4683. /*----------------------------------------------------------------------------
  4684. Name :ValidateNodeOrNS
  4685. Synopsis :This function validates the node or namespace
  4686. Type :Member Function
  4687. Input Parameter(s):
  4688. pszInput - node/namesapce to be validated
  4689. bNode - TRUE - pszInput refers to NODE
  4690. FALSE - pszInput refers to NAMESPACE
  4691. Output parameter(s):None
  4692. Return Type :BOOL
  4693. Global Variables :None
  4694. Calling Syntax :ValidateNodeOrNS(pszInput, bNode)
  4695. Notes :None
  4696. ----------------------------------------------------------------------------*/
  4697. BOOL CParserEngine::ValidateNodeOrNS(_TCHAR* pszInput, BOOL bNode)
  4698. {
  4699. IWbemServices* pISvc = NULL;
  4700. BOOL bRet = TRUE;
  4701. HRESULT hr = S_OK;
  4702. try
  4703. {
  4704. if(pszInput == NULL)
  4705. bRet = FALSE;
  4706. if(bRet)
  4707. {
  4708. if (m_pIWbemLocator != NULL)
  4709. {
  4710. // Check for the presence of the following invalid
  4711. // characters for NODE.
  4712. if (bNode)
  4713. {
  4714. CHString str(pszInput);
  4715. if (str.FindOneOf(L"\"\\,/[]:<>+=;?$#{}~`^@!'()*") != -1)
  4716. {
  4717. bRet = FALSE;
  4718. };
  4719. }
  4720. if (bRet)
  4721. {
  4722. // Try to connect to root namespace
  4723. _bstr_t bstrNS;
  4724. if (bNode)
  4725. bstrNS = _bstr_t(L"\\\\") + _bstr_t(pszInput) + _bstr_t(L"\\root");
  4726. else
  4727. bstrNS = _bstr_t(L"\\\\.\\") + _bstr_t(pszInput);
  4728. // Call the ConnectServer method of the IWbemLocator
  4729. hr = m_pIWbemLocator->ConnectServer(bstrNS, NULL, NULL, NULL, 0L,
  4730. NULL, NULL, &pISvc);
  4731. if (FAILED(hr))
  4732. {
  4733. // If invalid machine name
  4734. // 0x800706ba - RPC_SERVER_UNAVAILABLE
  4735. if (bNode && (hr == 0x800706ba))
  4736. {
  4737. bRet = FALSE;
  4738. }
  4739. // If invalid namespace
  4740. // 0x8004100E - WBEM_E_INVALID_NAMESPACE
  4741. if (!bNode
  4742. && ((hr == WBEM_E_INVALID_NAMESPACE) ||
  4743. (hr == WBEM_E_INVALID_PARAMETER)))
  4744. {
  4745. bRet = FALSE;
  4746. }
  4747. }
  4748. SAFEIRELEASE(pISvc);
  4749. }
  4750. }
  4751. }
  4752. }
  4753. catch(_com_error& e)
  4754. {
  4755. bRet = FALSE;
  4756. SAFEIRELEASE(pISvc);
  4757. _com_issue_error(e.Error());
  4758. }
  4759. catch(CHeap_Exception)
  4760. {
  4761. bRet = FALSE;
  4762. SAFEIRELEASE(pISvc);
  4763. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  4764. }
  4765. return bRet;
  4766. }
  4767. /*----------------------------------------------------------------------------
  4768. Name :ParseAssocSwitches
  4769. Synopsis :This function does the parsing and interprets if command
  4770. has ASSOC as the verb. It parses the remaining tokens
  4771. following and updates the same in CParsedInfo.
  4772. Type :Member Function
  4773. Input Parameter(s) :cvTokens - the tokens vector
  4774. theIterator - the Iterator to the cvTokens vector.
  4775. rParsedInfo - reference to CParsedInfo class object
  4776. Output Parameter(s) :rParsedInfo - reference to CParsedInfo class object
  4777. Return Type :RETCODE - enumerated data type
  4778. Global Variables :None
  4779. Calling Syntax :ParseAssocSwitch(cvTokens,theIterator,rParsedInfo)
  4780. Notes :None
  4781. ----------------------------------------------------------------------------*/
  4782. RETCODE CParserEngine::ParseAssocSwitches(CHARVECTOR& cvTokens,
  4783. CHARVECTOR::iterator& theIterator,
  4784. CParsedInfo& rParsedInfo)
  4785. {
  4786. RETCODE retCode = PARSER_EXECCOMMAND;
  4787. while ( retCode == PARSER_EXECCOMMAND )
  4788. {
  4789. // Check for the presence of RESULT CLASS switch
  4790. if (CompareTokens(*theIterator, CLI_TOKEN_RESULTCLASS))
  4791. {
  4792. retCode = ParseAssocSwitchEx(cvTokens, theIterator, rParsedInfo ,RESULTCLASS );
  4793. }
  4794. // Check for the presence of RESULT ROLE switch
  4795. else if (CompareTokens(*theIterator,CLI_TOKEN_RESULTROLE ))
  4796. {
  4797. retCode = ParseAssocSwitchEx(cvTokens, theIterator, rParsedInfo ,RESULTROLE );
  4798. }
  4799. // Check for the presence of ASSOC CLASS switch
  4800. else if (CompareTokens(*theIterator,CLI_TOKEN_ASSOCCLASS ))
  4801. {
  4802. retCode = ParseAssocSwitchEx(cvTokens, theIterator, rParsedInfo , ASSOCCLASS);
  4803. }
  4804. // Check for the presence of help
  4805. else if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  4806. {
  4807. rParsedInfo.GetHelpInfoObject().SetHelp(ASSOCSwitchesOnly, TRUE);
  4808. retCode = ParseHelp(cvTokens, theIterator, ASSOCVerb, rParsedInfo);
  4809. }
  4810. else
  4811. {
  4812. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4813. IDS_E_INVALID_ASSOC_SWITCH);
  4814. retCode = PARSER_ERROR;
  4815. break;
  4816. }
  4817. //Checking the next tokens
  4818. if ( retCode == PARSER_EXECCOMMAND )
  4819. {
  4820. if ( !GetNextToken(cvTokens, theIterator) )
  4821. break;
  4822. if ( !IsOption(*theIterator) )
  4823. {
  4824. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4825. IDS_E_INVALID_COMMAND);
  4826. retCode = PARSER_ERROR;
  4827. break;
  4828. }
  4829. if ( !GetNextToken(cvTokens, theIterator) )
  4830. {
  4831. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4832. IDS_E_INVALID_ASSOC_SWITCH);
  4833. retCode = PARSER_ERROR;
  4834. break;
  4835. }
  4836. }
  4837. }
  4838. return retCode;
  4839. }
  4840. /*----------------------------------------------------------------------------
  4841. Name :ParseAssocSwitchEx
  4842. Synopsis :This function does the parsing of tokens for the assoc
  4843. switches It parses the remaining tokens following and
  4844. updates the same in CParsedInfo.
  4845. Type :Member Function
  4846. Input Parameter(s) :cvTokens - the tokens vector
  4847. theIterator - the Iterator to the cvTokens vector.
  4848. rParsedInfo - reference to CParsedInfo class object
  4849. assocSwitch - the type of assoc switch
  4850. Output Parameter(s) :rParsedInfo - reference to CParsedInfo class object
  4851. Return Type :RETCODE - enumerated data type
  4852. Global Variables :None
  4853. Calling Syntax :ParseAssocSwitchEx(cvTokens,theIterator,
  4854. rParsedInfo,assocSwitch)
  4855. Notes :None
  4856. ----------------------------------------------------------------------------*/
  4857. RETCODE CParserEngine::ParseAssocSwitchEx(CHARVECTOR& cvTokens,
  4858. CHARVECTOR::iterator& theIterator,
  4859. CParsedInfo& rParsedInfo ,
  4860. ASSOCSwitch assocSwitch)
  4861. {
  4862. RETCODE retCode = PARSER_EXECCOMMAND;
  4863. //Checking the next token to continue parsing
  4864. if ( GetNextToken(cvTokens, theIterator, rParsedInfo, ASSOCVerb,
  4865. IDS_E_INVALID_ASSOC_SWITCH) == PARSER_CONTINUE )
  4866. {
  4867. //Checking for help option
  4868. if ( IsOption(*theIterator) &&
  4869. (theIterator + 1) < cvTokens.end() &&
  4870. CompareTokens(*(theIterator+1), CLI_TOKEN_HELP) )
  4871. {
  4872. theIterator++;
  4873. //Help on RESULTCLASS
  4874. if (assocSwitch == RESULTCLASS)
  4875. {
  4876. retCode = ParseHelp(cvTokens, theIterator, RESULTCLASShelp,
  4877. rParsedInfo);
  4878. }
  4879. //Help on RESULTROLE
  4880. if (assocSwitch == RESULTROLE)
  4881. {
  4882. retCode = ParseHelp(cvTokens, theIterator, RESULTROLEhelp,
  4883. rParsedInfo);
  4884. }
  4885. //Help on ASSOCCLASS
  4886. if (assocSwitch == ASSOCCLASS)
  4887. {
  4888. retCode = ParseHelp(cvTokens, theIterator, ASSOCCLASShelp,
  4889. rParsedInfo);
  4890. }
  4891. }
  4892. //If the command has ":" , then the corresponding data
  4893. //has to be set in Command object
  4894. else if ( CompareTokens( *theIterator, CLI_TOKEN_COLON ) &&
  4895. GetNextToken(cvTokens, theIterator, rParsedInfo, ASSOCVerb,
  4896. IDS_E_INVALID_ASSOC_SWITCH) == PARSER_CONTINUE )
  4897. {
  4898. if ( IsOption(*theIterator) )
  4899. {
  4900. rParsedInfo.GetCmdSwitchesObject().
  4901. SetErrataCode(IDS_E_INVALID_ASSOC_SWITCH);
  4902. retCode = PARSER_ERROR;
  4903. }
  4904. else
  4905. {
  4906. //Setting the ResultClassName
  4907. if (assocSwitch == RESULTCLASS)
  4908. {
  4909. if(rParsedInfo.GetCmdSwitchesObject().
  4910. SetResultClassName(*theIterator))
  4911. {
  4912. retCode = PARSER_EXECCOMMAND;
  4913. }
  4914. else
  4915. {
  4916. retCode = PARSER_ERROR;
  4917. }
  4918. }
  4919. //Setting the Result Role Name
  4920. if (assocSwitch == RESULTROLE)
  4921. {
  4922. if(rParsedInfo.GetCmdSwitchesObject().
  4923. SetResultRoleName(*theIterator))
  4924. {
  4925. retCode = PARSER_EXECCOMMAND;
  4926. }
  4927. else
  4928. {
  4929. retCode = PARSER_ERROR;
  4930. }
  4931. }
  4932. //Setting the Assoc Class Name
  4933. if (assocSwitch == ASSOCCLASS)
  4934. {
  4935. if(rParsedInfo.GetCmdSwitchesObject().
  4936. SetAssocClassName(*theIterator))
  4937. {
  4938. retCode = PARSER_EXECCOMMAND;
  4939. }
  4940. else
  4941. {
  4942. retCode = PARSER_ERROR;
  4943. }
  4944. }
  4945. }
  4946. }
  4947. else
  4948. {
  4949. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  4950. IDS_E_INVALID_ASSOC_SWITCH);
  4951. retCode = PARSER_ERROR;
  4952. }
  4953. }
  4954. else
  4955. retCode = PARSER_ERROR;
  4956. return retCode;
  4957. }
  4958. /*----------------------------------------------------------------------------
  4959. Name :ParseNumberedSwitch
  4960. Synopsis :This function does the parsing of tokens for the every
  4961. and repeat switches. It parses the remaining tokens
  4962. following and updates the same in CParsedInfo.
  4963. Type :Member Function
  4964. Input Parameter(s) :cvTokens - the tokens vector
  4965. theIterator - the Iterator to the cvTokens vector.
  4966. rParsedInfo - reference to CParsedInfo class object
  4967. htHelp - enumerated help type
  4968. uSwitchErrCode - error string ID.
  4969. uNumberErrCode - error string ID.
  4970. Output Parameter(s) :rParsedInfo - reference to CParsedInfo class object
  4971. Return Type :RETCODE - enumerated data type
  4972. Global Variables :None
  4973. Calling Syntax :ParseNumberedSwitch(cvTokens, theIterator, rParsedInfo,
  4974. EVERYorREPEAT, uSwitchErrCode,
  4975. uNumberErrCode);
  4976. Notes :None
  4977. ----------------------------------------------------------------------------*/
  4978. RETCODE CParserEngine::ParseNumberedSwitch(CHARVECTOR& cvTokens,
  4979. CHARVECTOR::iterator& theIterator,
  4980. CParsedInfo& rParsedInfo,
  4981. HELPTYPE htHelp,
  4982. UINT uSwitchErrCode,
  4983. UINT uNumberErrCode)
  4984. {
  4985. RETCODE retCode = PARSER_EXECCOMMAND;
  4986. BOOL bInvalidSwitch = FALSE;
  4987. // Move to next token
  4988. if (!GetNextToken(cvTokens, theIterator, rParsedInfo, htHelp,
  4989. uSwitchErrCode))
  4990. bInvalidSwitch = TRUE;
  4991. else if ( IsOption(*theIterator) &&
  4992. (theIterator + 1) < cvTokens.end() &&
  4993. CompareTokens(*(theIterator+1), CLI_TOKEN_HELP) )
  4994. {
  4995. theIterator++;
  4996. retCode = ParseHelp(cvTokens, theIterator, htHelp, rParsedInfo);
  4997. }
  4998. else if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  4999. {
  5000. BOOL bSuccess = FALSE;
  5001. // Move to next token
  5002. if (GetNextToken(cvTokens, theIterator))
  5003. {
  5004. if ( IsOption(*theIterator) )
  5005. {
  5006. rParsedInfo.GetCmdSwitchesObject().
  5007. SetErrataCode(uSwitchErrCode);
  5008. retCode = PARSER_ERROR;
  5009. }
  5010. else
  5011. {
  5012. _TCHAR* pszEndPtr = NULL;
  5013. ULONG ulNumber = _tcstoul(*theIterator, &pszEndPtr, 10);
  5014. if (!lstrlen(pszEndPtr))
  5015. {
  5016. BOOL bSetValue = TRUE;
  5017. if ( htHelp == EVERY )
  5018. {
  5019. bSetValue = rParsedInfo.GetCmdSwitchesObject().
  5020. SetRetrievalInterval(ulNumber);
  5021. }
  5022. else if ( htHelp == REPEAT )
  5023. {
  5024. if ( ulNumber == 0)
  5025. {
  5026. rParsedInfo.GetCmdSwitchesObject().
  5027. SetErrataCode(
  5028. IDS_E_INVALID_REPEATCOUNT);
  5029. retCode = PARSER_ERROR;
  5030. bSetValue = FALSE;
  5031. }
  5032. else
  5033. {
  5034. bSetValue = rParsedInfo.GetCmdSwitchesObject().
  5035. SetRepeatCount(ulNumber);
  5036. }
  5037. }
  5038. if ( bSetValue == TRUE)
  5039. {
  5040. bSuccess = TRUE;
  5041. rParsedInfo.GetCmdSwitchesObject().SetEverySwitchFlag(TRUE);
  5042. retCode = PARSER_EXECCOMMAND;
  5043. }
  5044. else
  5045. {
  5046. bSuccess = FALSE;
  5047. retCode = PARSER_ERROR;
  5048. }
  5049. }
  5050. }
  5051. }
  5052. if ( bSuccess == FALSE )
  5053. {
  5054. // PARSER_ERROR if no more tokens are present. i.e <interval>
  5055. // is not specified.
  5056. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(uNumberErrCode);
  5057. retCode = PARSER_ERROR;
  5058. }
  5059. }
  5060. else
  5061. bInvalidSwitch = TRUE;
  5062. if ( bInvalidSwitch == TRUE )
  5063. {
  5064. // PARSER_ERROR if no more tokens are present. i.e <interval>
  5065. // is not specified.
  5066. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(uSwitchErrCode);
  5067. retCode = PARSER_ERROR;
  5068. }
  5069. return retCode;
  5070. }
  5071. /*----------------------------------------------------------------------------
  5072. Name :IsValidClass
  5073. Synopsis :This function validates the class specified and
  5074. returns True or False accordingly as the validity of
  5075. the class
  5076. Type :Member Function
  5077. Input Parameter(s) :rParsedInfo - reference to CParsedInfo class object
  5078. Output Parameter(s) :rParsedInfo - reference to CParsedInfo class object
  5079. Return Type :BOOL
  5080. Global Variables :None
  5081. Calling Syntax :IsValidClass(rParsedInfo)
  5082. Notes :None
  5083. ----------------------------------------------------------------------------*/
  5084. BOOL CParserEngine::IsValidClass(CParsedInfo& rParsedInfo)
  5085. {
  5086. HRESULT hr = S_OK;
  5087. IWbemClassObject* pIObject = NULL;
  5088. CHString chsMsg;
  5089. DWORD dwThreadId = GetCurrentThreadId();
  5090. BOOL bTrace = FALSE;
  5091. ERRLOGOPT eloErrLogOpt = NO_LOGGING;
  5092. // Obtain the trace flag status
  5093. bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  5094. eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  5095. try
  5096. {
  5097. hr = ConnectToNamespace(rParsedInfo);
  5098. ONFAILTHROWERROR(hr);
  5099. hr = m_pITargetNS->GetObject(_bstr_t(rParsedInfo.
  5100. GetCmdSwitchesObject().GetClassPath()),
  5101. WBEM_FLAG_USE_AMENDED_QUALIFIERS,
  5102. NULL, &pIObject, NULL);
  5103. if (bTrace || eloErrLogOpt)
  5104. {
  5105. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", "
  5106. L"WBEM_FLAG_USE_AMENDED_QUALIFIERS, 0, NULL, -, -)",
  5107. rParsedInfo.GetCmdSwitchesObject().GetClassPath());
  5108. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  5109. rParsedInfo, bTrace);
  5110. }
  5111. // do not add ONFAILTHROWERROR() here.
  5112. SAFEIRELEASE(pIObject);
  5113. }
  5114. catch(_com_error &e)
  5115. {
  5116. hr = e.Error();
  5117. SAFEIRELEASE(pIObject);
  5118. _com_issue_error(e.Error());
  5119. }
  5120. catch(CHeap_Exception)
  5121. {
  5122. SAFEIRELEASE(pIObject);
  5123. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  5124. }
  5125. return (SUCCEEDED(hr))? TRUE : FALSE;
  5126. }
  5127. /*----------------------------------------------------------------------------
  5128. Name :ObtainMethodsAvailableFlag
  5129. Synopsis :This function Checks whether methods are available with
  5130. alias in case of alias specified.and with class in case
  5131. of class speicified.
  5132. Type :Member Function
  5133. Input Parameter(s) :
  5134. rParsedInfo - reference to CParsedInfo class object
  5135. Output Parameter(s) :None
  5136. Return Type :void
  5137. Global Variables :None
  5138. Calling Syntax :ObtainMethodsAvailableFlag(rParsedInfo)
  5139. Notes :None
  5140. ----------------------------------------------------------------------------*/
  5141. void CParserEngine::ObtainMethodsAvailableFlag(CParsedInfo& rParsedInfo)
  5142. {
  5143. BOOL bMethAvail = TRUE;
  5144. if ( m_bAliasName == TRUE )
  5145. bMethAvail = m_CmdAlias.AreMethodsAvailable(rParsedInfo);
  5146. else
  5147. bMethAvail = ObtainClassMethods(rParsedInfo, TRUE);
  5148. rParsedInfo.GetCmdSwitchesObject().SetMethodsAvailable(bMethAvail);
  5149. }
  5150. /*----------------------------------------------------------------------------
  5151. Name :ObtainWriteablePropsAvailailableFlag
  5152. Synopsis :Checks whether writable props are available with alias in
  5153. case of alias specified. and with class in case of class
  5154. speicified.
  5155. Type :Member Function
  5156. Input Parameter(s) :
  5157. rParsedInfo - reference to CParsedInfo class object
  5158. Output Parameter(s) :None
  5159. Return Type :void
  5160. Global Variables :None
  5161. Calling Syntax :ObtainWriteablePropsAvailailableFlag(rParsedInfo)
  5162. Notes :None
  5163. ----------------------------------------------------------------------------*/
  5164. void CParserEngine::ObtainWriteablePropsAvailailableFlag(
  5165. CParsedInfo& rParsedInfo)
  5166. {
  5167. BOOL bWritePropsAvail = TRUE;
  5168. HRESULT hr = S_OK;
  5169. try
  5170. {
  5171. if ( m_bAliasName == TRUE )
  5172. {
  5173. hr = m_CmdAlias.ObtainAliasPropDetails(rParsedInfo, &bWritePropsAvail);
  5174. ONFAILTHROWERROR(hr);
  5175. }
  5176. else
  5177. bWritePropsAvail = ObtainClassProperties(rParsedInfo, TRUE);
  5178. rParsedInfo.GetCmdSwitchesObject().SetWriteablePropsAvailable(
  5179. bWritePropsAvail);
  5180. }
  5181. catch(_com_error& e)
  5182. {
  5183. _com_issue_error(e.Error());
  5184. }
  5185. }
  5186. /*----------------------------------------------------------------------------
  5187. Name :ParseVerbInteractive
  5188. Synopsis :This function parses the verb interactive option
  5189. Type :Member Function
  5190. Input Parameter(s) :
  5191. cvTokens - the tokens vector
  5192. theIterator - the Iterator to the cvTokens vector.
  5193. rParsedInfo - reference to CParsedInfo class object
  5194. Output Parameter(s) :
  5195. rParsedInfo - reference to CParsedInfo class object
  5196. bInvalidOption - Invalid syntax for interactive
  5197. Return Type :RETCODE
  5198. Global Variables :None
  5199. Calling Syntax :ParseVerbInteractive(rParsedInfo)
  5200. Notes :None
  5201. ----------------------------------------------------------------------------*/
  5202. RETCODE CParserEngine::ParseVerbInteractive(CHARVECTOR& cvTokens,
  5203. CHARVECTOR::iterator& theIterator,
  5204. CParsedInfo& rParsedInfo, BOOL& bInvalidOption)
  5205. {
  5206. RETCODE retCode = PARSER_EXECCOMMAND;
  5207. if (GetNextToken(cvTokens, theIterator))
  5208. {
  5209. // check for the presence of ':'
  5210. if (CompareTokens(*theIterator, CLI_TOKEN_COLON))
  5211. {
  5212. if (GetNextToken(cvTokens, theIterator))
  5213. {
  5214. if (IsOption(*theIterator))
  5215. {
  5216. if (GetNextToken(cvTokens, theIterator))
  5217. {
  5218. if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  5219. {
  5220. retCode = ParseHelp(cvTokens, theIterator, VERBSWITCHES,
  5221. rParsedInfo);
  5222. }
  5223. else
  5224. {
  5225. bInvalidOption = TRUE;
  5226. }
  5227. }
  5228. else
  5229. {
  5230. bInvalidOption = TRUE;
  5231. }
  5232. }
  5233. else
  5234. {
  5235. while (TRUE)
  5236. {
  5237. if(!rParsedInfo.GetCmdSwitchesObject().
  5238. AddToInteractivePropertyList(*theIterator))
  5239. {
  5240. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5241. IDS_E_ADD_TO_PROP_LIST_FAILURE);
  5242. retCode = PARSER_ERROR;
  5243. }
  5244. if (GetNextToken(cvTokens, theIterator))
  5245. {
  5246. // check for the presence of ','
  5247. if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  5248. {
  5249. if (!GetNextToken(cvTokens, theIterator))
  5250. {
  5251. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5252. IDS_E_INVALID_PARAMLIST);
  5253. retCode = PARSER_ERROR;
  5254. break;
  5255. }
  5256. }
  5257. else
  5258. {
  5259. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5260. IDS_E_INVALID_PARAMLIST);
  5261. retCode = PARSER_ERROR;
  5262. break;
  5263. }
  5264. }
  5265. else
  5266. {
  5267. retCode = PARSER_EXECCOMMAND;
  5268. break;
  5269. }
  5270. }
  5271. }
  5272. }
  5273. else
  5274. {
  5275. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5276. IDS_E_INVALID_PARAMLIST);
  5277. retCode = PARSER_ERROR;
  5278. }
  5279. }
  5280. else if (IsOption(*theIterator))
  5281. {
  5282. if (GetNextToken(cvTokens, theIterator))
  5283. {
  5284. if (CompareTokens(*theIterator, CLI_TOKEN_HELP))
  5285. {
  5286. retCode = ParseHelp(cvTokens, theIterator, VERBSWITCHES,
  5287. rParsedInfo);
  5288. }
  5289. else
  5290. {
  5291. bInvalidOption = TRUE;
  5292. }
  5293. }
  5294. else
  5295. {
  5296. bInvalidOption = TRUE;
  5297. }
  5298. }
  5299. else
  5300. {
  5301. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5302. IDS_E_INVALID_PARAMLIST);
  5303. retCode = PARSER_ERROR;
  5304. }
  5305. }
  5306. return retCode;
  5307. }
  5308. /*----------------------------------------------------------------------------
  5309. Name :ProcessOutputAndAppendFiles
  5310. Synopsis :Prepares the output and append files for output
  5311. redirection.
  5312. Type :Member Function
  5313. Input Parameter(s) :
  5314. rParsedInfo - reference to CParsedInfo class object.
  5315. retOCode - RETCODE type, specifies the initial RETCODE before
  5316. calling the function.
  5317. bOpenOutInWriteMode - boolean type, to specify flag of OpenOutInWriteMode.
  5318. Output Parameter(s) :
  5319. rParsedInfo - reference to CParsedInfo class object
  5320. Return Type :RETCODE
  5321. Global Variables :None
  5322. Calling Syntax :ProcessOutputAndAppendFiles(rParsedInfo, retCode, FALSE)
  5323. Notes :None
  5324. ----------------------------------------------------------------------------*/
  5325. RETCODE CParserEngine::ProcessOutputAndAppendFiles(CParsedInfo& rParsedInfo,
  5326. RETCODE retOCode,
  5327. BOOL bOpenOutInWriteMode)
  5328. {
  5329. RETCODE retCode = retOCode;
  5330. // TRUE for getting output file name.
  5331. _TCHAR* pszOutputFileName =
  5332. rParsedInfo.GetGlblSwitchesObject().GetOutputOrAppendFileName(
  5333. TRUE);
  5334. if ( pszOutputFileName != NULL )
  5335. {
  5336. // redirect the output to file.
  5337. if ( CloseOutputFile() == TRUE )
  5338. {
  5339. FILE *fpOutFile;
  5340. if ( bOpenOutInWriteMode == TRUE )
  5341. fpOutFile = _tfopen(pszOutputFileName, _T("w"));
  5342. else
  5343. fpOutFile = _tfopen(pszOutputFileName, _T("a"));
  5344. if ( fpOutFile == NULL )
  5345. {
  5346. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5347. IDS_E_OPEN_OUTPUT_FILE_FAILURE);
  5348. retCode = PARSER_ERROR;
  5349. }
  5350. else // TRUE for setting output file pointer.
  5351. rParsedInfo.GetGlblSwitchesObject().
  5352. SetOutputOrAppendFilePointer(fpOutFile, TRUE);
  5353. }
  5354. }
  5355. // Processing for append file.
  5356. if ( retCode == retOCode && bOpenOutInWriteMode == FALSE)
  5357. {
  5358. // FALSE for getting append file name.
  5359. _TCHAR* pszAppendFileName =
  5360. rParsedInfo.GetGlblSwitchesObject().GetOutputOrAppendFileName(
  5361. FALSE);
  5362. if ( pszAppendFileName != NULL )
  5363. {
  5364. if ( CloseAppendFile() == TRUE )
  5365. {
  5366. FILE* fpOpenAppendFile = _tfopen(pszAppendFileName, _T("a"));
  5367. if ( fpOpenAppendFile == NULL )
  5368. {
  5369. rParsedInfo.GetCmdSwitchesObject().
  5370. SetErrataCode(IDS_E_OPEN_APPEND_FILE_FAILURE);
  5371. retCode = PARSER_ERROR;
  5372. }
  5373. else
  5374. {
  5375. // FALSE for setting append file pointer.
  5376. rParsedInfo.GetGlblSwitchesObject().
  5377. SetOutputOrAppendFilePointer(fpOpenAppendFile,
  5378. FALSE);
  5379. }
  5380. }
  5381. }
  5382. }
  5383. return retCode;
  5384. }
  5385. /*----------------------------------------------------------------------------
  5386. Name :ParseUnnamedParamList
  5387. Synopsis :Parses Unnamed Parameter list.
  5388. Type :Member Function
  5389. Input Parameter(s) :
  5390. rParsedInfo - reference to CParsedInfo class object.
  5391. cvTokens - the tokens vector
  5392. theIterator - the Iterator to the cvTokens vector.
  5393. Output Parameter(s) :
  5394. rParsedInfo - reference to CParsedInfo class object
  5395. Return Type :RETCODE
  5396. Global Variables :None
  5397. Calling Syntax :ParseUnnamedParamList(cvTokens, theIterator,rParsedInfo);
  5398. Notes :None
  5399. ----------------------------------------------------------------------------*/
  5400. RETCODE CParserEngine::ParseUnnamedParamList(CHARVECTOR& cvTokens,
  5401. CHARVECTOR::iterator& theIterator,
  5402. CParsedInfo& rParsedInfo)
  5403. {
  5404. RETCODE retCode = PARSER_EXECCOMMAND;
  5405. while (TRUE)
  5406. {
  5407. if(!rParsedInfo.GetCmdSwitchesObject().
  5408. AddToPropertyList(*theIterator))
  5409. {
  5410. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5411. IDS_E_ADD_TO_PROP_LIST_FAILURE);
  5412. retCode = PARSER_ERROR;
  5413. }
  5414. if (GetNextToken(cvTokens, theIterator))
  5415. {
  5416. if (IsOption(*theIterator))
  5417. {
  5418. // To facilitate ParseVerbSwitches to continue
  5419. theIterator--;
  5420. break;
  5421. }
  5422. else
  5423. {
  5424. // check for the presence of ','
  5425. if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  5426. {
  5427. if (!GetNextToken(cvTokens, theIterator))
  5428. {
  5429. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5430. IDS_E_INVALID_PARAMLIST);
  5431. retCode = PARSER_ERROR;
  5432. break;
  5433. }
  5434. }
  5435. else
  5436. {
  5437. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5438. IDS_E_INVALID_PARAMLIST);
  5439. retCode = PARSER_ERROR;
  5440. break;
  5441. }
  5442. }
  5443. }
  5444. else
  5445. break;
  5446. }
  5447. return retCode;
  5448. }
  5449. /*----------------------------------------------------------------------------
  5450. Name :ValidateVerbOrMethodParams
  5451. Synopsis :Validates the named params with verb or method parameters.
  5452. Type :Member Function
  5453. Input Parameter(s) :
  5454. rParsedInfo - reference to CParsedInfo class object.
  5455. Output Parameter(s) :
  5456. rParsedInfo - reference to CParsedInfo class object
  5457. Return Type :RETCODE
  5458. Global Variables :None
  5459. Calling Syntax :ValidateVerbOrMethodParams(rParsedInfo);
  5460. Notes :None
  5461. ----------------------------------------------------------------------------*/
  5462. RETCODE CParserEngine::ValidateVerbOrMethodParams(CParsedInfo& rParsedInfo)
  5463. {
  5464. RETCODE retCode = PARSER_EXECCOMMAND;
  5465. BSTRMAP::iterator theIterator;
  5466. PROPDETMAP::iterator propIterator;
  5467. // Info about verb or method params.
  5468. PROPDETMAP pdmVerbOrMethParams = (*(rParsedInfo.GetCmdSwitchesObject().
  5469. GetMethDetMap().begin())).second.Params;
  5470. BSTRMAP bmNamedParams = rParsedInfo.GetCmdSwitchesObject().
  5471. GetParameterMap();
  5472. for ( theIterator = bmNamedParams.begin();
  5473. theIterator != bmNamedParams.end(); theIterator++ )
  5474. {
  5475. BOOL bFind;
  5476. if ( rParsedInfo.GetCmdSwitchesObject().GetVerbType() == CMDLINE )
  5477. bFind = Find(pdmVerbOrMethParams,(*theIterator).first,
  5478. propIterator, TRUE);
  5479. else
  5480. bFind = Find(pdmVerbOrMethParams,(*theIterator).first,
  5481. propIterator);
  5482. if ( bFind == FALSE )
  5483. {
  5484. DisplayMessage((*theIterator).first, CP_OEMCP, TRUE, TRUE);
  5485. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5486. IDS_E_NOT_A_VERBORMETH_PARAM);
  5487. retCode = PARSER_ERROR;
  5488. break;
  5489. }
  5490. else if ( (*propIterator).second.InOrOut != INP )
  5491. {
  5492. DisplayMessage((*theIterator).first, CP_OEMCP, TRUE, TRUE);
  5493. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5494. IDS_E_NOT_A_INPUT_PARAM);
  5495. retCode = PARSER_ERROR;
  5496. break;
  5497. }
  5498. }
  5499. return retCode;
  5500. }
  5501. /*----------------------------------------------------------------------------
  5502. Name :ParseParamsString
  5503. Synopsis :Parses the parameter string
  5504. Type :Member Function
  5505. Input Parameter(s) :
  5506. rParsedInfo - reference to CParsedInfo class object.
  5507. cvTokens - the tokens vector
  5508. theIterator - the Iterator to the cvTokens vector.
  5509. xdXSLTDet - reference to the XSLdetails vector
  5510. pszXSLFile - string type, XSL file name.
  5511. Output Parameter(s) :
  5512. rParsedInfo - reference to CParsedInfo class object
  5513. Return Type :RETCODE
  5514. Global Variables :None
  5515. Calling Syntax :ParseParamsString(cvTokens, theIterator, rParsedInfo,
  5516. xdXSLTDet, pszXSLFile);
  5517. Notes :None
  5518. ----------------------------------------------------------------------------*/
  5519. RETCODE CParserEngine::ParseParamsString(CHARVECTOR& cvTokens,
  5520. CHARVECTOR::iterator& theIterator,
  5521. CParsedInfo& rParsedInfo,
  5522. XSLTDET& xdXSLTDet,
  5523. _TCHAR* pszXSLFile)
  5524. {
  5525. pszXSLFile = NULL;
  5526. RETCODE retCode = PARSER_EXECCOMMAND ;
  5527. try
  5528. {
  5529. if ( !GetNextToken(cvTokens, theIterator) )
  5530. {
  5531. rParsedInfo.GetCmdSwitchesObject().
  5532. SetErrataCode(IDS_E_INVALID_FORMAT);
  5533. retCode = PARSER_ERROR;
  5534. }
  5535. else if ( IsOption(*theIterator) )
  5536. {
  5537. rParsedInfo.GetCmdSwitchesObject().
  5538. SetErrataCode(IDS_E_INVALID_FORMAT);
  5539. retCode = PARSER_ERROR;
  5540. }
  5541. else
  5542. {
  5543. while ( retCode == PARSER_EXECCOMMAND )
  5544. {
  5545. _TCHAR* pszParam = NULL;
  5546. _TCHAR* pszParamValue = NULL;
  5547. pszParam = _tcstok(*theIterator,CLI_TOKEN_EQUALTO);
  5548. if(pszParam != NULL)
  5549. {
  5550. pszParamValue = _tcstok(NULL,CLI_TOKEN_EQUALTO);
  5551. if(pszParamValue != NULL)
  5552. {
  5553. _bstr_t bstrParam = pszParam;
  5554. _bstr_t bstrParamValue = pszParamValue;
  5555. if(IsOption(pszParamValue))
  5556. {
  5557. rParsedInfo.GetCmdSwitchesObject().
  5558. SetErrataCode(IDS_E_INVALID_FORMAT);
  5559. retCode = PARSER_ERROR;
  5560. }
  5561. else
  5562. xdXSLTDet.ParamMap.insert(BSTRMAP::value_type(
  5563. bstrParam, bstrParamValue));
  5564. }
  5565. else
  5566. pszXSLFile = pszParam;
  5567. }
  5568. else
  5569. {
  5570. rParsedInfo.GetCmdSwitchesObject().
  5571. SetErrataCode(IDS_E_INVALID_FORMAT);
  5572. retCode = PARSER_ERROR;
  5573. }
  5574. if ( retCode == PARSER_EXECCOMMAND )
  5575. {
  5576. if ( !GetNextToken(cvTokens, theIterator) )
  5577. break;
  5578. else if ( IsOption(*theIterator) )
  5579. break;
  5580. else if (CompareTokens(*theIterator, CLI_TOKEN_COMMA))
  5581. {
  5582. if ( theIterator + 1 == cvTokens.end() )
  5583. break;
  5584. else if ( theIterator + 2 == cvTokens.end() )
  5585. break;
  5586. else if ( pszParamValue == NULL )
  5587. break;
  5588. else
  5589. theIterator++;
  5590. }
  5591. }
  5592. }
  5593. }
  5594. }
  5595. catch(_com_error& e)
  5596. {
  5597. retCode = PARSER_ERROR;
  5598. _com_issue_error(e.Error());
  5599. }
  5600. return retCode;
  5601. }
  5602. /*----------------------------------------------------------------------------
  5603. Name :ParseNodeListFile
  5604. Synopsis :Parses the node list file.
  5605. Type :Member Function
  5606. Input Parameter(s) :
  5607. rParsedInfo - reference to CParsedInfo class object.
  5608. cvTokens - the tokens vector
  5609. theIterator - the Iterator to the cvTokens vector.
  5610. Output Parameter(s) :
  5611. rParsedInfo - reference to CParsedInfo class object
  5612. Return Type :RETCODE
  5613. Global Variables :None
  5614. Calling Syntax :ParseNodeListFile(cvTokens, theIterator,rParsedInfo);
  5615. Notes :None
  5616. ----------------------------------------------------------------------------*/
  5617. RETCODE CParserEngine::ParseNodeListFile(CHARVECTOR& cvTokens,
  5618. CHARVECTOR::iterator& theIterator,
  5619. CParsedInfo& rParsedInfo)
  5620. {
  5621. RETCODE retCode = PARSER_CONTINUE;
  5622. _TCHAR *pszTempFileName = (*theIterator+1);
  5623. _TCHAR *szNodeListFileName = new _TCHAR [BUFFER512];
  5624. if (szNodeListFileName == NULL)
  5625. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  5626. lstrcpy(szNodeListFileName, pszTempFileName);
  5627. UnQuoteString(szNodeListFileName);
  5628. FILE *fpNodeListFile =
  5629. _tfopen(szNodeListFileName, _T("rb"));
  5630. LONG lNumberOfInserts = 0;
  5631. CHARVECTOR::iterator itrVectorInCmdTkzr = NULL;
  5632. _TCHAR *pszComma = NULL;
  5633. _TCHAR *pszNode = NULL;
  5634. FILETYPE eftNodeFileType = ANSI_FILE;
  5635. char *pszFirstTwoBytes = NULL;
  5636. try
  5637. {
  5638. if ( fpNodeListFile != NULL )
  5639. {
  5640. Find(m_CmdTknzr.GetTokenVector(), *theIterator, itrVectorInCmdTkzr);
  5641. SAFEDELETE(*itrVectorInCmdTkzr);
  5642. itrVectorInCmdTkzr = m_CmdTknzr.GetTokenVector().erase(itrVectorInCmdTkzr);
  5643. // Remove @nodelistfile token from token vector.
  5644. theIterator = cvTokens.erase(theIterator);
  5645. // Indentifing the file type whether Unicode or ANSI.
  5646. pszFirstTwoBytes = new char[2];
  5647. fread(pszFirstTwoBytes, 2, 1, fpNodeListFile);
  5648. if ( memcmp(pszFirstTwoBytes, UNICODE_SIGNATURE, 2) == 0 )
  5649. {
  5650. eftNodeFileType = UNICODE_FILE;
  5651. }
  5652. else if (memcmp(pszFirstTwoBytes, UNICODE_BIGEND_SIGNATURE, 2) == 0 )
  5653. {
  5654. eftNodeFileType = UNICODE_BIGENDIAN_FILE;
  5655. }
  5656. else if( memcmp(pszFirstTwoBytes, UTF8_SIGNATURE, 2) == 0 )
  5657. {
  5658. eftNodeFileType = UTF8_FILE;
  5659. }
  5660. else
  5661. {
  5662. eftNodeFileType = ANSI_FILE;
  5663. fseek(fpNodeListFile, 0, SEEK_SET);
  5664. }
  5665. SAFEDELETE(pszFirstTwoBytes);
  5666. _TCHAR szNodeName[BUFFER512] = NULL_STRING;
  5667. if ( GetNodeFromNodeFile(fpNodeListFile, eftNodeFileType,
  5668. szNodeName) == FALSE )
  5669. {
  5670. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5671. IDS_E_NODELISTFILE_EMPTY);
  5672. retCode = PARSER_ERROR;
  5673. }
  5674. else
  5675. {
  5676. BOOL bFirstTime = TRUE;
  5677. do
  5678. {
  5679. LONG lNodeStrLen = lstrlen(szNodeName);
  5680. if ( szNodeName[lNodeStrLen-1] == _T('\n') )
  5681. szNodeName[lNodeStrLen-1] = _T('\0');
  5682. CHString strRawNodeName(szNodeName);
  5683. strRawNodeName.TrimLeft();
  5684. strRawNodeName.TrimRight();
  5685. lstrcpy(szNodeName, strRawNodeName.GetBuffer(BUFFER512));
  5686. if ( szNodeName[0] != _T('#') &&
  5687. strRawNodeName.IsEmpty() == FALSE )
  5688. {
  5689. if ( bFirstTime == FALSE )
  5690. {
  5691. pszComma = new _TCHAR[lstrlen(
  5692. CLI_TOKEN_COMMA) + 1];
  5693. if (pszComma == NULL)
  5694. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  5695. lstrcpy(pszComma, CLI_TOKEN_COMMA);
  5696. theIterator = cvTokens.insert(theIterator, pszComma);
  5697. theIterator++;
  5698. itrVectorInCmdTkzr = m_CmdTknzr.GetTokenVector().
  5699. insert(itrVectorInCmdTkzr,
  5700. pszComma);
  5701. itrVectorInCmdTkzr++;
  5702. lNumberOfInserts++;
  5703. }
  5704. else
  5705. bFirstTime = FALSE;
  5706. lNodeStrLen = lstrlen(szNodeName);
  5707. pszNode = new _TCHAR[lNodeStrLen + 1];
  5708. if (pszNode == NULL)
  5709. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  5710. lstrcpy(pszNode, szNodeName);
  5711. theIterator = cvTokens.insert(theIterator, pszNode);
  5712. theIterator++;
  5713. itrVectorInCmdTkzr = m_CmdTknzr.GetTokenVector().insert(
  5714. itrVectorInCmdTkzr, pszNode);
  5715. itrVectorInCmdTkzr++;
  5716. lNumberOfInserts++;
  5717. }
  5718. }
  5719. while ( GetNodeFromNodeFile(fpNodeListFile, eftNodeFileType,
  5720. szNodeName) == TRUE );
  5721. if ( lNumberOfInserts == 0 )
  5722. {
  5723. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5724. IDS_E_NO_NODES_FOR_INSERTION);
  5725. retCode = PARSER_ERROR;
  5726. }
  5727. theIterator = theIterator - lNumberOfInserts;
  5728. }
  5729. fclose(fpNodeListFile);
  5730. }
  5731. else
  5732. {
  5733. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  5734. IDS_E_NODELISTFILE_OPEN_FAILURE);
  5735. retCode = PARSER_ERROR;
  5736. }
  5737. SAFEDELETE(szNodeListFileName);
  5738. }
  5739. catch(CHeap_Exception)
  5740. {
  5741. retCode = PARSER_ERROR;
  5742. SAFEDELETE(szNodeListFileName);
  5743. SAFEDELETE(pszFirstTwoBytes);
  5744. retCode = PARSER_ERROR;
  5745. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  5746. }
  5747. catch(_com_error& e)
  5748. {
  5749. retCode = PARSER_ERROR;
  5750. SAFEDELETE(szNodeListFileName);
  5751. SAFEDELETE(pszComma);
  5752. SAFEDELETE(pszNode);
  5753. SAFEDELETE(pszFirstTwoBytes);
  5754. _com_issue_error(e.Error());
  5755. }
  5756. return retCode;
  5757. }
  5758. /*----------------------------------------------------------------------------
  5759. Name :GetNodeFromNodeFile
  5760. Synopsis :Retrieves the node list file.
  5761. Type :Member Function
  5762. Input Parameter(s) :
  5763. fpNodeListFile - pointer to File containing node list.
  5764. eftNodeFileType - Enum value specifing unicode or ANSI ....
  5765. Output Parameter(s) :
  5766. szNodeName - pointer to string specifing node to be returned.
  5767. Return Type :BOOL
  5768. Global Variables :None
  5769. Calling Syntax :GetNodeFromNodeFile(fpNodeListFile, eftNodeFileType,
  5770. szNodeName);
  5771. Notes :None
  5772. ----------------------------------------------------------------------------*/
  5773. BOOL CParserEngine::GetNodeFromNodeFile(FILE* fpNodeListFile,
  5774. FILETYPE eftNodeFileType,
  5775. _TCHAR* szNodeName)
  5776. {
  5777. WCHAR wszNodeName[2] = L"";
  5778. char cszNodeName[2] = "";
  5779. _TCHAR szTemp[2] = NULL_STRING;
  5780. try
  5781. {
  5782. lstrcpy(szNodeName, NULL_STRING);
  5783. while( TRUE )
  5784. {
  5785. lstrcpy(szTemp, NULL_STRING);
  5786. if ( eftNodeFileType == UNICODE_FILE )
  5787. {
  5788. if ( fgetws(wszNodeName, 2, fpNodeListFile) != NULL )
  5789. {
  5790. lstrcpy(szTemp, (_TCHAR*)_bstr_t(wszNodeName));
  5791. }
  5792. else
  5793. break;
  5794. }
  5795. else if ( eftNodeFileType == UNICODE_BIGENDIAN_FILE )
  5796. {
  5797. if ( fgetws(wszNodeName, 2, fpNodeListFile) != NULL )
  5798. {
  5799. BYTE HiByte = HIBYTE(wszNodeName[0]);
  5800. BYTE LowByte = LOBYTE(wszNodeName[0]);
  5801. wszNodeName[0] = MAKEWORD(HiByte, LowByte);
  5802. lstrcpy(szTemp, (_TCHAR*)_bstr_t(wszNodeName));
  5803. }
  5804. else
  5805. break;
  5806. }
  5807. else if ( eftNodeFileType == UTF8_FILE )
  5808. {
  5809. if ( fgets(cszNodeName, 2, fpNodeListFile) != NULL )
  5810. {
  5811. MultiByteToWideChar(
  5812. CP_UTF8, // code page
  5813. 0, // character-type options
  5814. cszNodeName, // string to map
  5815. 2, // number of bytes in string
  5816. wszNodeName, // wide-character buffer
  5817. 2 // size of buffer
  5818. );
  5819. lstrcpy(szTemp, (_TCHAR*)_bstr_t(wszNodeName));
  5820. }
  5821. else
  5822. break;
  5823. }
  5824. else
  5825. {
  5826. if ( fgets(cszNodeName, 2, fpNodeListFile) != NULL )
  5827. {
  5828. lstrcpy(szTemp, (_TCHAR*)_bstr_t(cszNodeName));
  5829. }
  5830. else
  5831. break;
  5832. }
  5833. if ( _tcscmp(szTemp, CLI_TOKEN_SPACE) == 0 ||
  5834. _tcscmp(szTemp, CLI_TOKEN_TAB) == 0 ||
  5835. _tcscmp(szTemp, CLI_TOKEN_SEMICOLON) == 0 ||
  5836. _tcscmp(szTemp, CLI_TOKEN_COMMA) == 0 ||
  5837. _tcscmp(szTemp, CLI_TOKEN_DOUBLE_QUOTE)== 0 ||
  5838. _tcscmp(szTemp, CLI_TOKEN_NEWLINE) == 0 )
  5839. {
  5840. break;
  5841. }
  5842. else
  5843. {
  5844. lstrcat(szNodeName, szTemp);
  5845. }
  5846. }
  5847. }
  5848. catch(_com_error& e)
  5849. {
  5850. _com_issue_error(e.Error());
  5851. }
  5852. return (!feof(fpNodeListFile) || _tcscmp(szNodeName, NULL_STRING));
  5853. }