Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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