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.

1132 lines
30 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #include "precomp.h"
  5. #include <snmptempl.h>
  6. #ifndef INITGUID
  7. #define INITGUID
  8. #endif
  9. #ifdef INITGUID_DEFINED
  10. #define INITGUID
  11. #include <initguid.h>
  12. #endif
  13. #include <wchar.h>
  14. #include <process.h>
  15. #include <wbemidl.h>
  16. #include <objbase.h>
  17. #include <initguid.h>
  18. #include <bool.hpp>
  19. #include <newString.hpp>
  20. #include <ui.hpp>
  21. #include <symbol.hpp>
  22. #include <type.hpp>
  23. #include <value.hpp>
  24. #include <valueRef.hpp>
  25. #include <typeRef.hpp>
  26. #include <oidValue.hpp>
  27. #include <objectType.hpp>
  28. #include <objectTypeV1.hpp>
  29. #include <objectTypeV2.hpp>
  30. #include <objectIdentity.hpp>
  31. #include <trapType.hpp>
  32. #include <notificationType.hpp>
  33. #include <group.hpp>
  34. #include <notificationGroup.hpp>
  35. #include <module.hpp>
  36. #include <stackValues.hpp>
  37. #include <lex_yy.hpp>
  38. #include <ytab.hpp>
  39. #include <errorMessage.hpp>
  40. #include <errorContainer.hpp>
  41. #include <scanner.hpp>
  42. #include <parser.hpp>
  43. #include <abstractParseTree.hpp>
  44. #include <oidTree.hpp>
  45. #include <parseTree.hpp>
  46. #include <infoLex.hpp>
  47. #include <infoYacc.hpp>
  48. #include <moduleInfo.hpp>
  49. #include <registry.hpp>
  50. #include "smir.h"
  51. #include "main.hpp"
  52. #include "generator.hpp"
  53. #include "smimsgif.hpp"
  54. // The errors container used to hold the error messages. This is global too.
  55. static SIMCErrorContainer errorContainer;
  56. // The DLL that contains the information messages
  57. static HINSTANCE infoMessagesDll = LoadLibrary(INFO_MESSAGES_DLL);
  58. // The string that represents the version# of Smi2smir. This is obtained from
  59. // the string resources of the exe.
  60. CString versionString;
  61. void SetEcho ()
  62. {
  63. HANDLE t_Input = GetStdHandle( STD_INPUT_HANDLE );
  64. DWORD t_Mode = 0 ;
  65. BOOL t_Status = GetConsoleMode ( t_Input , & t_Mode ) ;
  66. t_Mode = t_Mode | ENABLE_ECHO_INPUT ;
  67. t_Status = SetConsoleMode ( t_Input , t_Mode ) ;
  68. }
  69. void SetNoEcho ()
  70. {
  71. HANDLE t_Input = GetStdHandle( STD_INPUT_HANDLE );
  72. DWORD t_Mode = 0 ;
  73. BOOL t_Status = GetConsoleMode ( t_Input , & t_Mode ) ;
  74. t_Mode = t_Mode & ( 0xffffffff ^ ENABLE_ECHO_INPUT ) ;
  75. t_Status = SetConsoleMode ( t_Input , t_Mode ) ;
  76. }
  77. // A routine to generate information messages
  78. void InformationMessage(int messageType, ...)
  79. {
  80. if( !infoMessagesDll)
  81. {
  82. cerr << "smi2smir : Could not load \"" <<
  83. INFO_MESSAGES_DLL << "\".\n" << endl;
  84. return;
  85. }
  86. va_list argList;
  87. va_start(argList, messageType);
  88. char message[INFO_MESSAGE_SIZE];
  89. char messageText[INFO_MESSAGE_SIZE];
  90. const char *temp1, *temp2, *temp3;
  91. long temp4;
  92. if(!LoadString(infoMessagesDll, messageType, messageText, INFO_MESSAGE_SIZE))
  93. cerr << "smi2smir: Panic, unable to load message text from " << INFO_MESSAGES_DLL <<
  94. endl;
  95. SIMCErrorMessage e;
  96. if(messageType == FILE_NOT_FOUND || messageType == INVALID_MIB_FILE)
  97. {
  98. e.SetSeverityLevel(SIMCParseTree::FATAL);
  99. e.SetSeverityString("Fatal");
  100. }
  101. else
  102. {
  103. e.SetSeverityLevel(SIMCParseTree::INFORMATION);
  104. e.SetSeverityString("Information");
  105. }
  106. switch(messageType)
  107. {
  108. case SMIR_CONNECT_FAILED:
  109. case LISTING_MODULES:
  110. case LISTING_FAILED:
  111. case PURGE_SUCCEEDED:
  112. case PURGE_FAILED:
  113. case MODULE_LISTING:
  114. case MODULE_LISTING_NO_MODULES:
  115. case MIB_PATH_LISTING:
  116. case LISTING_MIB_PATHS:
  117. case LISTING_MIB_PATHS_NONE:
  118. temp1 = va_arg(argList, const char *);
  119. sprintf(message, messageText, temp1);
  120. break;
  121. case SMI2SMIR_INFO:
  122. case SYNTAX_CHECK_FAILED:
  123. case SYNTAX_CHECK_SUCCEEDED:
  124. case SEMANTIC_CHECK_FAILED:
  125. case SEMANTIC_CHECK_SUCCEEDED:
  126. case SMIR_LOAD_FAILED:
  127. case SMIR_LOAD_SUCCEEDED:
  128. case MOF_GENERATION_FAILED:
  129. case MOF_GENERATION_SUCCEEDED:
  130. case SYMBOL_RESOLUTION_FAILED:
  131. case DELETE_SUCCEEDED:
  132. case DELETE_FAILED:
  133. case DELETE_MODULE_NOT_FOUND:
  134. case FILE_NOT_FOUND:
  135. case MODULE_NAME_SUCCEEDED:
  136. case MODULE_INFO_FAILED:
  137. case DIRECTORY_ADDITION_SUCCEEDED:
  138. case DIRECTORY_ADDITION_FAILED:
  139. case DIRECTORY_DELETION_SUCCEEDED:
  140. case DIRECTORY_DELETION_FAILED:
  141. case INVALID_MIB_FILE:
  142. temp1 = va_arg(argList, const char *);
  143. temp2 = va_arg(argList, const char *);
  144. sprintf(message, messageText, temp1, temp2);
  145. break;
  146. case COMPILED_FILE:
  147. case DUPLICATE_MODULES:
  148. temp1 = va_arg(argList, const char *);
  149. temp2 = va_arg(argList, const char *);
  150. temp3 = va_arg(argList, const char *);
  151. sprintf(message, messageText, temp1, temp2, temp3);
  152. break;
  153. case NUMBER_OF_ENTRIES:
  154. temp1 = va_arg(argList, const char *);
  155. temp4 = va_arg(argList, long);
  156. sprintf(message, messageText, temp1, temp4);
  157. break;
  158. }
  159. va_end(argList);
  160. e.SetMessage(message);
  161. e.SetLineAndColumnValidity(FALSE);
  162. errorContainer.InsertMessage(e);
  163. }
  164. void CheckForDuplicateModules(SIMCFileMapList &dependencyList, const CString& applicationName)
  165. {
  166. POSITION pOuter = dependencyList.GetHeadPosition();
  167. SIMCFileMapElement nextElement, laterElement;
  168. while(pOuter)
  169. {
  170. nextElement = dependencyList.GetNext(pOuter);
  171. POSITION pInner = pOuter, pTemp;
  172. while(pInner)
  173. {
  174. pTemp = pInner;
  175. laterElement = dependencyList.GetNext(pInner);
  176. if(laterElement.moduleName == nextElement.moduleName)
  177. {
  178. InformationMessage(DUPLICATE_MODULES, applicationName,
  179. nextElement.moduleName,
  180. nextElement.fileName);
  181. if(pTemp == pOuter)
  182. pOuter = pInner;
  183. dependencyList.RemoveAt(pTemp);
  184. }
  185. }
  186. }
  187. }
  188. // Returns true if there's atleast one module in SMIR
  189. BOOL AreModulesInSmir(ISMIRWbemConfiguration *a_Configuration, const CString& applicationName)
  190. {
  191. // Create the interrogative interface
  192. ISmirInterrogator *pInterrogateInt;
  193. HRESULT result = a_Configuration->QueryInterface(IID_ISMIR_Interrogative,(PPVOID)&pInterrogateInt);
  194. if(FAILED(result))
  195. {
  196. if(simc_debug)
  197. cerr << "AreModulesInSmir(): CoCreate() failed on the Interrogator" << endl;
  198. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  199. return FALSE;
  200. }
  201. // Create an enumerator
  202. IEnumModule *pEnumInt;
  203. result = pInterrogateInt->EnumModules(&pEnumInt);
  204. if(FAILED(result))
  205. {
  206. if(simc_debug)
  207. cerr << "AreModulesInSmir(): EnumModules() failed on the Interrogator" << endl;
  208. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  209. pInterrogateInt->Release();
  210. return FALSE;
  211. }
  212. // If no modules return
  213. ISmirModHandle *nextModule = NULL;
  214. if(pEnumInt->Next(1, &nextModule, NULL) != S_OK)
  215. {
  216. pEnumInt->Release();
  217. pInterrogateInt->Release();
  218. return FALSE;
  219. }
  220. // Release all enumeration interfaces
  221. pEnumInt->Release();
  222. pInterrogateInt->Release();
  223. nextModule->Release();
  224. return TRUE;
  225. }
  226. // Lists all the modules in the SMIR
  227. BOOL SIMCListSmir(ISMIRWbemConfiguration *a_Configuration , const CString& applicationName)
  228. {
  229. // Create the interrogative interface
  230. ISmirInterrogator *pInterrogateInt;
  231. HRESULT result = a_Configuration->QueryInterface(IID_ISMIR_Interrogative,(PPVOID)&pInterrogateInt);
  232. if(FAILED(result))
  233. {
  234. if(simc_debug)
  235. cerr << "SIMCListSmir(): CoCreate() failed on the Interrogator" << endl;
  236. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  237. return FALSE;
  238. }
  239. IEnumModule *pEnumInt;
  240. result = pInterrogateInt->EnumModules(&pEnumInt);
  241. if(FAILED(result))
  242. {
  243. if(simc_debug)
  244. cerr << "SIMCListSmir(): EnumModules() failed on the Interrogator" << endl;
  245. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  246. pInterrogateInt->Release();
  247. return FALSE;
  248. }
  249. BOOL first = true;
  250. ISmirModHandle *nextModule = NULL;
  251. BSTR moduleName;
  252. while(pEnumInt->Next(1, &nextModule, NULL) == S_OK)
  253. {
  254. if(nextModule->GetName(&moduleName) == S_OK)
  255. {
  256. if(first)
  257. {
  258. InformationMessage(LISTING_MODULES, applicationName);
  259. cout << endl;
  260. first = false;
  261. }
  262. char *moduleNameStr = ConvertBstrToAnsi(moduleName);
  263. InformationMessage(MODULE_LISTING, moduleNameStr);
  264. delete moduleNameStr;
  265. SysFreeString(moduleName);
  266. }
  267. nextModule->Release();
  268. nextModule = NULL;
  269. }
  270. if(first)
  271. InformationMessage(MODULE_LISTING_NO_MODULES, applicationName);
  272. pEnumInt->Release();
  273. pInterrogateInt->Release();
  274. return TRUE;
  275. }
  276. // Lists all the MIB paths (directories) in the registry
  277. BOOL SIMCListMibPaths(const CString& applicationName)
  278. {
  279. SIMCStringList pathList;
  280. if(SIMCRegistryController::GetMibPaths(pathList))
  281. {
  282. // Successful in reading the MIB path list from registry
  283. POSITION p = pathList.GetHeadPosition();
  284. if(p) // There's atleast one MIB path
  285. {
  286. InformationMessage(LISTING_MIB_PATHS, applicationName);
  287. while(p)
  288. InformationMessage(MODULE_LISTING, pathList.GetNext(p));
  289. }
  290. else // There are no MIB paths in the registry
  291. InformationMessage(LISTING_MIB_PATHS_NONE, applicationName);
  292. }
  293. else // Failed to read the list of paths. Report that there are no paths
  294. InformationMessage(LISTING_MIB_PATHS_NONE, applicationName);
  295. return true;
  296. }
  297. // Deletes a specified module in the SMIR
  298. BOOL SIMCDeleteModule(ISMIRWbemConfiguration *a_Configuration , const CString& applicationName, const CString& moduleName)
  299. {
  300. // Create the administrator, to delete the module
  301. ISmirAdministrator *pAdminInt = NULL;
  302. HRESULT result=a_Configuration->QueryInterface(IID_ISMIR_Administrative,(PPVOID)&pAdminInt);
  303. if(FAILED(result))
  304. {
  305. if(simc_debug)
  306. cerr << "SIMCDeleteModule() : CoCreate() failed on the Administrator" << endl;
  307. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  308. return FALSE;
  309. }
  310. // Create the Interrogator to get the module handle of the
  311. // module to be deleted
  312. ISmirInterrogator *pInterrogateInt = NULL;
  313. result = a_Configuration->QueryInterface(IID_ISMIR_Interrogative,(PPVOID)&pInterrogateInt);
  314. if(FAILED(result))
  315. {
  316. if(simc_debug)
  317. cerr << "SIMCDeleteModule() : CoCreate() failed on the Interrogator" << endl;
  318. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  319. return FALSE;
  320. }
  321. // Get the module handle using the enumerator and interrogator
  322. IEnumModule *pEnumInt = NULL;
  323. result = pInterrogateInt->EnumModules(&pEnumInt);
  324. if(FAILED(result))
  325. {
  326. if(simc_debug)
  327. cerr << "SIMCDeleteModule() : EnumModules() failed on the Interrogator" << endl;
  328. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  329. pAdminInt->Release();
  330. pInterrogateInt->Release();
  331. return FALSE;
  332. }
  333. ISmirModHandle *nextModule = NULL;
  334. BSTR moduleNameBstr;
  335. char * moduleNameAnsi;
  336. while( pEnumInt->Next(1, &nextModule, NULL) == S_OK && nextModule)
  337. {
  338. nextModule->GetName(&moduleNameBstr);
  339. moduleNameAnsi = ConvertBstrToAnsi(moduleNameBstr);
  340. SysFreeString(moduleNameBstr);
  341. if(_stricmp(moduleNameAnsi, moduleName) == 0)
  342. {
  343. delete moduleNameAnsi;
  344. //nextModule->AddRef();
  345. BOOL retval = SUCCEEDED(pAdminInt->DeleteModule(nextModule));
  346. pAdminInt->Release();
  347. pInterrogateInt->Release();
  348. nextModule->Release();
  349. return retval;
  350. }
  351. nextModule->Release();
  352. nextModule = NULL;
  353. }
  354. InformationMessage(DELETE_MODULE_NOT_FOUND, applicationName, moduleName);
  355. pAdminInt->Release();
  356. pInterrogateInt->Release();
  357. return FALSE;
  358. }
  359. // Deletes all the modules in the SMIR
  360. BOOL SIMCPurgeSmir(ISMIRWbemConfiguration *a_Configuration , const CString& applicationName)
  361. {
  362. // Create the administrator, to delete the modules
  363. ISmirAdministrator *pAdminInt = NULL;
  364. HRESULT result = a_Configuration->QueryInterface(IID_ISMIR_Administrative,(PPVOID)&pAdminInt);
  365. if(FAILED(result))
  366. {
  367. if(simc_debug)
  368. cerr << "SIMCPurgeSmir() : CoCreate() failed on the Admionistrator" << endl;
  369. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  370. return FALSE;
  371. }
  372. BOOL retval = SUCCEEDED(pAdminInt->DeleteAllModules());
  373. pAdminInt->Release();
  374. return retval;
  375. }
  376. // Filters the errors based on the switches on the command-line
  377. void FilterErrors(SIMCErrorContainer *errorContainer,
  378. const SIMCUI& theUI)
  379. {
  380. errorContainer->MoveToFirstMessage();
  381. SIMCErrorMessage e;
  382. int i = theUI.GetMaxDiagnosticCount();
  383. int maxSeverityLevel = theUI.GetDiagnosticLevel();
  384. while(errorContainer->GetNextMessage(e))
  385. {
  386. if(e.GetSeverityLevel() == 3 )
  387. cerr << e;
  388. else if(e.GetSeverityLevel() <= maxSeverityLevel && i>0)
  389. {
  390. cerr << e;
  391. i--;
  392. }
  393. }
  394. }
  395. // Checks whether the main mib file and the subsidiary files are
  396. // compilable, and adds them to the priority map
  397. // Adds any files in the include directories to the priority map
  398. BOOL PrepareSubsidiariesAndIncludes(const CString& applicationName,
  399. const CString& mainFileName,
  400. const SIMCFileList& subsidiaryFiles,
  401. const SIMCPathList& includePaths,
  402. SIMCFileMapList& priorityMap)
  403. {
  404. // Parse the subsidiaries and add em to dependency list or
  405. //issue messages
  406. // Same with includes?
  407. BOOL retVal = TRUE;
  408. FILE * fp = fopen(mainFileName, "r");
  409. if(fp)
  410. {
  411. SIMCModuleInfoScanner smallScanner;
  412. SIMCModuleInfoParser smallParser;
  413. smallScanner.setinput(fp);
  414. if(smallParser.GetModuleInfo(&smallScanner))
  415. priorityMap.AddTail(SIMCFileMapElement(smallParser.GetModuleName(), mainFileName));
  416. else
  417. {
  418. InformationMessage(INVALID_MIB_FILE,
  419. applicationName, mainFileName);
  420. retVal = FALSE;
  421. }
  422. fclose(fp);
  423. }
  424. else
  425. {
  426. retVal = FALSE;
  427. InformationMessage(FILE_NOT_FOUND, applicationName, mainFileName);
  428. }
  429. POSITION pFiles = subsidiaryFiles.GetHeadPosition();
  430. CString nextFile;
  431. while(pFiles)
  432. {
  433. nextFile = subsidiaryFiles.GetNext(pFiles);
  434. fp = fopen(nextFile, "r");
  435. if(fp)
  436. {
  437. SIMCModuleInfoScanner smallScanner;
  438. SIMCModuleInfoParser smallParser;
  439. smallScanner.setinput(fp);
  440. if(smallParser.GetModuleInfo(&smallScanner))
  441. priorityMap.AddTail(SIMCFileMapElement(smallParser.GetModuleName(), nextFile));
  442. else
  443. {
  444. InformationMessage(INVALID_MIB_FILE,
  445. applicationName, nextFile);
  446. retVal = FALSE;
  447. }
  448. fclose(fp);
  449. }
  450. else
  451. {
  452. retVal = FALSE;
  453. InformationMessage(FILE_NOT_FOUND, applicationName, nextFile);
  454. }
  455. }
  456. // Make sure that there arent any duplicates
  457. CheckForDuplicateModules(priorityMap, applicationName);
  458. // Now do the same for the files in the include list
  459. SIMCStringList suffixList;
  460. if(!SIMCRegistryController::GetMibSuffixes(suffixList))
  461. return retVal;
  462. POSITION pPaths = includePaths.GetHeadPosition();
  463. CString nextPath;
  464. while(pPaths)
  465. {
  466. nextPath = includePaths.GetNext(pPaths);
  467. SIMCRegistryController::RebuildDirectory(nextPath,
  468. suffixList, priorityMap);
  469. }
  470. return retVal;
  471. }
  472. int _cdecl main( int argc, const char *argv[])
  473. {
  474. SIMCUI theUI;
  475. // Parse the command-line
  476. if( !theUI.ProcessCommandLine(argc, argv))
  477. return 1;
  478. // Create and initialize variables
  479. simc_debug = theUI.IsSimcDebug();
  480. SIMCParseTree theTree(&errorContainer);
  481. CString inputFileName = theUI.GetInputFileName(),
  482. applicationName = theUI.GetApplicationName();
  483. long snmpVersion = theUI.GetSnmpVersion();
  484. BOOL retVal = TRUE, generateMof = FALSE;
  485. versionString = theUI.GetVersionNumber();
  486. ISMIRWbemConfiguration *t_Configuration = NULL ;
  487. switch (theUI.GetCommandArgument())
  488. {
  489. /*
  490. * These commands access the SMIR so Authenticate first.
  491. */
  492. case SIMCUI::COMMAND_PURGE:
  493. case SIMCUI::COMMAND_DELETE:
  494. case SIMCUI::COMMAND_LIST:
  495. case SIMCUI::COMMAND_GENERATE:
  496. case SIMCUI::COMMAND_GENERATE_CLASSES_ONLY:
  497. case SIMCUI::COMMAND_ADD:
  498. case SIMCUI::COMMAND_SILENT_ADD:
  499. {
  500. HRESULT result = CoInitialize(NULL);
  501. result = CoCreateInstance (
  502. CLSID_SMIR_Database , NULL ,
  503. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  504. IID_ISMIRWbemConfiguration,
  505. (PPVOID)&t_Configuration
  506. ) ;
  507. if ( SUCCEEDED ( result ) )
  508. {
  509. #if 0
  510. cout << "Enter password:" << flush;
  511. char response[80];
  512. SetNoEcho ();
  513. cin.get(response, 80);
  514. SetEcho () ;
  515. #endif
  516. result = t_Configuration->Authenticate (
  517. NULL,
  518. NULL,
  519. NULL,
  520. NULL,
  521. 0 ,
  522. NULL,
  523. FALSE
  524. ) ;
  525. if ( ! SUCCEEDED ( result ) )
  526. {
  527. InformationMessage(SMIR_CONNECT_FAILED, applicationName);
  528. if( theUI.GetCommandArgument() != SIMCUI::COMMAND_SILENT_ADD)
  529. FilterErrors(&errorContainer, theUI);
  530. return 1;
  531. }
  532. }
  533. else
  534. {
  535. if(result != S_OK)
  536. {
  537. InformationMessage(SMIR_CONNECT_FAILED,
  538. applicationName);
  539. if( theUI.GetCommandArgument() != SIMCUI::COMMAND_SILENT_ADD)
  540. FilterErrors(&errorContainer, theUI);
  541. return 1;
  542. }
  543. }
  544. }
  545. }
  546. // Do the action specified on the command-line
  547. switch (theUI.GetCommandArgument())
  548. {
  549. case SIMCUI::COMMAND_HELP1:
  550. case SIMCUI::COMMAND_HELP2:
  551. theUI.Usage();
  552. break;
  553. case SIMCUI::COMMAND_PURGE:
  554. {
  555. // Check to see if there is atleast 1 module
  556. if(!AreModulesInSmir(t_Configuration, applicationName)) {
  557. InformationMessage(MODULE_LISTING_NO_MODULES, applicationName);
  558. retVal = FALSE;
  559. break;
  560. }
  561. // Confirm the purge
  562. if(!theUI.ConfirmedPurge()) {
  563. cout << applicationName << " : Version:" << versionString << ": Delete all modules from the SMIR? [y/n]" << flush;
  564. char response[80];
  565. cin.get(response, 80);
  566. if(strcmp(response, "y") != 0)
  567. {
  568. retVal = TRUE;
  569. break;
  570. }
  571. }
  572. // Get on with the purging now.
  573. if(!SIMCPurgeSmir(t_Configuration, applicationName) )
  574. {
  575. InformationMessage(PURGE_FAILED, applicationName);
  576. retVal = FALSE;
  577. break;
  578. }
  579. else
  580. {
  581. InformationMessage(PURGE_SUCCEEDED, applicationName);
  582. retVal = TRUE;
  583. break;
  584. }
  585. }
  586. break;
  587. case SIMCUI::COMMAND_DELETE:
  588. {
  589. InformationMessage(SMI2SMIR_INFO, applicationName, versionString);
  590. cout << endl;
  591. CString moduleName = theUI.GetModuleName();
  592. if(!SIMCDeleteModule(t_Configuration,applicationName, moduleName))
  593. {
  594. InformationMessage(DELETE_FAILED, applicationName, moduleName);
  595. retVal = FALSE;
  596. break;
  597. }
  598. else
  599. {
  600. InformationMessage(DELETE_SUCCEEDED, applicationName, moduleName);
  601. retVal = TRUE;
  602. break;
  603. }
  604. }
  605. break;
  606. case SIMCUI::COMMAND_LIST:
  607. {
  608. InformationMessage(SMI2SMIR_INFO, applicationName, versionString);
  609. cout << endl;
  610. if(!SIMCListSmir(t_Configuration,applicationName))
  611. {
  612. InformationMessage(LISTING_FAILED, applicationName);
  613. retVal = FALSE;
  614. }
  615. else
  616. {
  617. retVal = TRUE;
  618. }
  619. }
  620. break;
  621. case SIMCUI::COMMAND_MODULE_NAME:
  622. {
  623. FILE *fp = fopen(inputFileName, "r");
  624. if(!fp)
  625. {
  626. InformationMessage(FILE_NOT_FOUND, applicationName, inputFileName);
  627. retVal = FALSE;
  628. }
  629. else
  630. {
  631. SIMCModuleInfoScanner smallScanner;
  632. smallScanner.setinput(fp);
  633. SIMCModuleInfoParser smallParser;
  634. if(smallParser.GetModuleInfo(&smallScanner))
  635. InformationMessage(MODULE_NAME_SUCCEEDED, applicationName, smallParser.GetModuleName() );
  636. else
  637. {
  638. retVal = FALSE;
  639. InformationMessage(MODULE_INFO_FAILED, applicationName, inputFileName);
  640. }
  641. fclose(fp);
  642. }
  643. }
  644. break;
  645. case SIMCUI::COMMAND_IMPORTS_INFO:
  646. {
  647. FILE *fp = fopen(inputFileName, "r");
  648. if(!fp)
  649. {
  650. InformationMessage(FILE_NOT_FOUND, applicationName, inputFileName);
  651. retVal = FALSE;
  652. }
  653. else
  654. {
  655. SIMCModuleInfoScanner smallScanner;
  656. smallScanner.setinput(fp);
  657. SIMCModuleInfoParser smallParser;
  658. if(smallParser.GetModuleInfo(&smallScanner))
  659. {
  660. const SIMCStringList * importList = smallParser.GetImportModuleList();
  661. POSITION p = importList->GetHeadPosition();
  662. if(p)
  663. {
  664. cout << "IMPORT MODULES" << endl;
  665. while(p)
  666. cout << "\t" << importList->GetNext(p) << endl;
  667. }
  668. else
  669. cout << "NO IMPORT MODULES" << endl;
  670. }
  671. else
  672. {
  673. retVal = FALSE;
  674. InformationMessage(MODULE_INFO_FAILED, applicationName, inputFileName);
  675. }
  676. fclose(fp);
  677. }
  678. }
  679. break;
  680. case SIMCUI::COMMAND_REBUILD_TABLE:
  681. InformationMessage(NUMBER_OF_ENTRIES,
  682. applicationName, SIMCRegistryController::RebuildMibTable());
  683. break;
  684. case SIMCUI::COMMAND_LIST_MIB_PATHS:
  685. InformationMessage(SMI2SMIR_INFO, applicationName, versionString);
  686. cout << endl;
  687. SIMCListMibPaths(applicationName);
  688. break;
  689. case SIMCUI::COMMAND_LOCAL_CHECK:
  690. {
  691. //----------- 1. Do Syntax Checking -----------------------
  692. FILE *fp = fopen(inputFileName, "r");
  693. if(!fp)
  694. {
  695. InformationMessage(FILE_NOT_FOUND, applicationName, inputFileName);
  696. retVal = FALSE;
  697. }
  698. else
  699. {
  700. fclose(fp);
  701. InformationMessage(COMPILED_FILE, applicationName, versionString, inputFileName);
  702. theTree.SetSnmpVersion(snmpVersion);
  703. if(!theTree.CheckSyntax(theUI.GetInputFileName()) )
  704. {
  705. retVal = FALSE;
  706. InformationMessage(SYNTAX_CHECK_FAILED, applicationName, inputFileName );
  707. }
  708. else
  709. InformationMessage(SYNTAX_CHECK_SUCCEEDED, applicationName, inputFileName);
  710. //----------- 2. Do Symbol resolution ----------------------
  711. if(retVal)
  712. {
  713. if(!theTree.Resolve(TRUE))
  714. {
  715. retVal = FALSE;
  716. InformationMessage(SYMBOL_RESOLUTION_FAILED, applicationName,
  717. inputFileName);
  718. }
  719. }
  720. //------------ 3. Do Semantic Checking ----------------------
  721. if(retVal)
  722. {
  723. if(!theTree.CheckSemantics(TRUE))
  724. {
  725. retVal = FALSE;
  726. InformationMessage(SEMANTIC_CHECK_FAILED, applicationName,
  727. inputFileName);
  728. }
  729. else
  730. InformationMessage(SEMANTIC_CHECK_SUCCEEDED, applicationName,
  731. inputFileName);
  732. }
  733. }
  734. }
  735. break;
  736. case SIMCUI::COMMAND_EXTERNAL_CHECK:
  737. {
  738. if(theUI.AutoRefresh())
  739. InformationMessage(NUMBER_OF_ENTRIES,
  740. applicationName, SIMCRegistryController::RebuildMibTable());
  741. SIMCFileMapList dependencyList, priorityList;
  742. const SIMCFileList * subsidiaryFiles = theUI.GetSubsidiaryFiles();
  743. const SIMCPathList * includePaths = theUI.GetPaths();
  744. // Make sure that the files that *have* to be compiled, exist
  745. // and are valid. Add the files in the includePaths to the
  746. // priority list
  747. // Bail out if the subsidiaries or the main file cant be processed
  748. if(!PrepareSubsidiariesAndIncludes(applicationName, inputFileName,
  749. *subsidiaryFiles, *includePaths, priorityList))
  750. {
  751. retVal = FALSE;
  752. break;
  753. }
  754. FILE * fp = fopen(inputFileName, "r");
  755. if(fp)
  756. {
  757. SIMCModuleInfoScanner smallScanner;
  758. smallScanner.setinput(fp);
  759. SIMCModuleInfoParser smallParser;
  760. CString dependentFile, dependentModule;
  761. if(smallParser.GetModuleInfo(&smallScanner))
  762. {
  763. fclose(fp); // Better close it rightnow, because of the recursion below
  764. // Add the current file to the dependency list
  765. dependencyList.AddTail(SIMCFileMapElement(smallParser.GetModuleName(), inputFileName));
  766. }
  767. }
  768. // Do a depth first search for dependencies
  769. SIMCRegistryController::GetDependentModules(inputFileName,
  770. dependencyList, priorityList);
  771. theTree.SetSnmpVersion(snmpVersion);
  772. POSITION p;
  773. p = dependencyList.GetHeadPosition();
  774. SIMCFileMapElement element;
  775. BOOL first = TRUE;
  776. while(p)
  777. {
  778. element = dependencyList.GetNext(p);
  779. fp = fopen(element.fileName, "r");
  780. if(!fp)
  781. {
  782. if(first)
  783. retVal = FALSE;
  784. InformationMessage(FILE_NOT_FOUND, applicationName, element.fileName);
  785. }
  786. else
  787. {
  788. fclose(fp);
  789. InformationMessage(COMPILED_FILE, applicationName, versionString, element.fileName);
  790. if(!theTree.CheckSyntax(element.fileName) )
  791. {
  792. if(first)
  793. retVal = FALSE;
  794. InformationMessage(SYNTAX_CHECK_FAILED, applicationName, element.fileName);
  795. }
  796. else
  797. InformationMessage(SYNTAX_CHECK_SUCCEEDED, applicationName, element.fileName);
  798. }
  799. if(first)
  800. first = FALSE;
  801. }
  802. if(retVal)
  803. {
  804. if(!theTree.Resolve(FALSE))
  805. {
  806. retVal = FALSE;
  807. InformationMessage(SYMBOL_RESOLUTION_FAILED, applicationName,
  808. inputFileName);
  809. }
  810. }
  811. if(retVal)
  812. {
  813. if(!theTree.CheckSemantics(FALSE))
  814. {
  815. retVal = FALSE;
  816. InformationMessage(SEMANTIC_CHECK_FAILED, applicationName,
  817. inputFileName);
  818. }
  819. else
  820. InformationMessage(SEMANTIC_CHECK_SUCCEEDED, applicationName,
  821. inputFileName);
  822. }
  823. }
  824. break;
  825. case SIMCUI::COMMAND_GENERATE: // Fall thru
  826. case SIMCUI::COMMAND_GENERATE_CLASSES_ONLY:
  827. generateMof = TRUE;
  828. case SIMCUI::COMMAND_ADD: // Fall thru
  829. case SIMCUI::COMMAND_SILENT_ADD:
  830. {
  831. if(theUI.AutoRefresh())
  832. InformationMessage(NUMBER_OF_ENTRIES,
  833. applicationName, SIMCRegistryController::RebuildMibTable());
  834. SIMCFileMapList dependencyList, priorityList;
  835. const SIMCFileList * subsidiaryFiles = theUI.GetSubsidiaryFiles();
  836. const SIMCPathList * includePaths = theUI.GetPaths();
  837. // Make sure that the files that *have* to be compiled, exist
  838. // and are valid. Add the files in the includePaths to the
  839. // priority list
  840. // Bail out if the subsidiaries or the main file cant be processed
  841. if(!PrepareSubsidiariesAndIncludes(applicationName, inputFileName,
  842. *subsidiaryFiles, *includePaths, priorityList))
  843. {
  844. retVal = FALSE;
  845. break;
  846. }
  847. FILE * fp = fopen(inputFileName, "r");
  848. if(fp)
  849. {
  850. SIMCModuleInfoScanner smallScanner;
  851. smallScanner.setinput(fp);
  852. SIMCModuleInfoParser smallParser;
  853. CString dependentFile, dependentModule;
  854. if(smallParser.GetModuleInfo(&smallScanner))
  855. {
  856. fclose(fp); // Better close it rightnow, because of the recursion below
  857. // Add the current file to the dependency list
  858. dependencyList.AddTail(SIMCFileMapElement(smallParser.GetModuleName(), inputFileName));
  859. }
  860. }
  861. // Do a dpeth first seacrh for dependencies
  862. SIMCRegistryController::GetDependentModules(inputFileName,
  863. dependencyList, priorityList);
  864. theTree.SetSnmpVersion(snmpVersion);
  865. POSITION p;
  866. p = dependencyList.GetHeadPosition();
  867. SIMCFileMapElement element;
  868. BOOL first = TRUE; // Special treatment for the first module
  869. while(p)
  870. {
  871. element = dependencyList.GetNext(p);
  872. fp = fopen(element.fileName, "r");
  873. if(!fp)
  874. {
  875. InformationMessage(FILE_NOT_FOUND, applicationName, element.fileName);
  876. if(first)
  877. retVal = FALSE;
  878. }
  879. else
  880. {
  881. fclose(fp);
  882. InformationMessage(COMPILED_FILE, applicationName, versionString, element.fileName);
  883. if(!theTree.CheckSyntax(element.fileName) )
  884. {
  885. if(first)
  886. retVal = FALSE;
  887. InformationMessage(SYNTAX_CHECK_FAILED, applicationName, element.fileName);
  888. }
  889. else
  890. InformationMessage(SYNTAX_CHECK_SUCCEEDED, applicationName, element.fileName);
  891. }
  892. if(first)
  893. first = FALSE;
  894. }
  895. if(retVal)
  896. {
  897. if(!theTree.Resolve(FALSE))
  898. {
  899. retVal = FALSE;
  900. InformationMessage(SYMBOL_RESOLUTION_FAILED, applicationName,
  901. inputFileName);
  902. }
  903. }
  904. if(retVal)
  905. {
  906. if(!theTree.CheckSemantics(FALSE))
  907. {
  908. retVal = FALSE;
  909. InformationMessage(SEMANTIC_CHECK_FAILED, applicationName,
  910. inputFileName);
  911. }
  912. else
  913. InformationMessage(SEMANTIC_CHECK_SUCCEEDED, applicationName,
  914. inputFileName);
  915. }
  916. if(retVal && simc_debug) cout << theTree;
  917. // Load the module, or generate mof
  918. if(retVal)
  919. {
  920. if(FAILED(GenerateClassDefinitions(t_Configuration,theUI, theTree, generateMof)))
  921. {
  922. retVal = FALSE;
  923. if(generateMof)
  924. InformationMessage(MOF_GENERATION_FAILED, applicationName,
  925. inputFileName);
  926. else
  927. InformationMessage(SMIR_LOAD_FAILED, applicationName,
  928. inputFileName);
  929. }
  930. else
  931. {
  932. if(generateMof)
  933. InformationMessage(MOF_GENERATION_SUCCEEDED, applicationName,
  934. inputFileName);
  935. else
  936. InformationMessage(SMIR_LOAD_SUCCEEDED, applicationName,
  937. inputFileName);
  938. }
  939. }
  940. }
  941. break;
  942. case SIMCUI::COMMAND_ADD_DIRECTORY:
  943. if(SIMCRegistryController::AddRegistryDirectory(theUI.GetDirectory()))
  944. {
  945. InformationMessage(DIRECTORY_ADDITION_SUCCEEDED, applicationName,
  946. theUI.GetDirectory());
  947. InformationMessage(NUMBER_OF_ENTRIES,
  948. applicationName, SIMCRegistryController::RebuildMibTable());
  949. }
  950. else
  951. {
  952. InformationMessage(DIRECTORY_ADDITION_FAILED, applicationName,
  953. theUI.GetDirectory());
  954. retVal = FALSE;
  955. }
  956. break;
  957. case SIMCUI::COMMAND_DELETE_DIRECTORY_ENTRY:
  958. if(SIMCRegistryController::DeleteRegistryDirectory(theUI.GetDirectory()))
  959. {
  960. InformationMessage(DIRECTORY_DELETION_SUCCEEDED, applicationName,
  961. theUI.GetDirectory());
  962. InformationMessage(NUMBER_OF_ENTRIES,
  963. applicationName, SIMCRegistryController::RebuildMibTable());
  964. }
  965. else
  966. {
  967. InformationMessage(DIRECTORY_DELETION_FAILED, applicationName,
  968. theUI.GetDirectory());
  969. retVal = FALSE;
  970. }
  971. break;
  972. case SIMCUI::COMMAND_NONE:
  973. default:
  974. assert(0);
  975. }
  976. if ( t_Configuration )
  977. {
  978. t_Configuration->Release () ;
  979. CoUninitialize () ;
  980. }
  981. if( theUI.GetCommandArgument() != SIMCUI::COMMAND_SILENT_ADD)
  982. FilterErrors(&errorContainer, theUI);
  983. if (NULL != infoMessagesDll)
  984. FreeLibrary(infoMessagesDll);
  985. if (NULL != SIMCParseTree::semanticErrorsDll)
  986. FreeLibrary(SIMCParseTree::semanticErrorsDll);
  987. if (NULL != SIMCParser::semanticErrorsDll)
  988. FreeLibrary(SIMCParser::semanticErrorsDll);
  989. if (NULL != SIMCParser::syntaxErrorsDll)
  990. FreeLibrary(SIMCParser::syntaxErrorsDll);
  991. return (retVal)? 0 : 1;
  992. }