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.

132 lines
3.8 KiB

  1. #ifndef __FILEPARSER_HPP__
  2. #define __FILEPARSER_HPP__
  3. /*---------------------------------------------------------------------------
  4. File: FileParser.hpp
  5. Comments: Classes to parse text files generated by the Domain Admin dispatcher and agent.
  6. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  7. Proprietary and confidential to Mission Critical Software, Inc.
  8. REVISION LOG ENTRY
  9. Revision By: Christy Boles
  10. Revised on 03/26/99 15:16:31
  11. ---------------------------------------------------------------------------
  12. */
  13. #include "Common.hpp"
  14. #include "UString.hpp"
  15. #include "EaLen.hpp"
  16. #include "ServList.hpp"
  17. #define AR_Status_Created (0x00000001)
  18. #define AR_Status_Replaced (0x00000002)
  19. #define AR_Status_AlreadyExisted (0x00000004)
  20. #define AR_Status_RightsUpdated (0x00000008)
  21. #define AR_Status_DomainChanged (0x00000010)
  22. #define AR_Status_Rebooted (0x00000020)
  23. #define AR_Status_Warning (0x40000000)
  24. #define AR_Status_Error (0x80000000)
  25. class TFileParser
  26. {
  27. protected:
  28. FILE * m_pFile;
  29. WCHAR m_filename[MAX_PATH];
  30. BOOL m_bValidData;
  31. public:
  32. TFileParser()
  33. {
  34. m_filename[0] = 0;
  35. m_pFile = NULL;
  36. m_bValidData = FALSE;
  37. }
  38. ~TFileParser()
  39. {
  40. if ( m_pFile )
  41. fclose(m_pFile);
  42. }
  43. BOOL Open(WCHAR const * filename)
  44. {
  45. safecopy(m_filename,filename);
  46. if ( *m_filename )
  47. {
  48. m_pFile = _wfopen(m_filename,L"rb");
  49. }
  50. else
  51. {
  52. m_pFile = 0;
  53. }
  54. return ( m_pFile != 0 );
  55. }
  56. BOOL IsOpen() { return ( m_pFile != 0 ); }
  57. void Close() { if ( m_pFile ) { fclose(m_pFile); m_pFile = NULL; } }
  58. BOOL IsEof() { return m_pFile ? feof(m_pFile) : TRUE; }
  59. BOOL Restart()
  60. {
  61. BOOL bRc = FALSE;
  62. if ( m_pFile )
  63. {
  64. bRc = ( fseek(m_pFile,0,SEEK_SET) == 0 );
  65. }
  66. return bRc;
  67. }
  68. virtual BOOL ScanEntry() = 0;
  69. };
  70. class TErrorLogParser:public TFileParser
  71. {
  72. int m_Severity;
  73. int m_SourceLine; //
  74. WCHAR m_Timestamp[100]; // the timestamp of the entry
  75. WCHAR m_Message[1000]; // the message text part of the entry
  76. WCHAR m_strBuf[1000]; // a line from the log file
  77. public:
  78. virtual BOOL ScanEntry()
  79. {
  80. MCSASSERT(m_pFile);
  81. m_bValidData = FALSE;
  82. if ( m_pFile && fgetws(m_strBuf,1000,m_pFile) )
  83. {
  84. m_bValidData = ScanFileEntry(m_strBuf,m_Timestamp,&m_Severity,&m_SourceLine,m_Message);
  85. }
  86. return m_bValidData;
  87. }
  88. int GetSeverity() { MCSASSERT(m_bValidData); return m_Severity; }
  89. int GetSourceLine() { MCSASSERT(m_bValidData); return m_SourceLine; }
  90. WCHAR const * GetTimestamp() { MCSASSERT(m_bValidData); return m_Timestamp; }
  91. WCHAR const * GetMessage() { MCSASSERT(m_bValidData); return m_Message; }
  92. protected:
  93. BOOL
  94. ScanFileEntry(
  95. WCHAR * string, // in - line from TError log file
  96. WCHAR * timestamp, // out- timestamp from this line
  97. int * pSeverity, // out- severity level of this message
  98. int * pSourceLine, // out- the source line for this message
  99. WCHAR * msgtext // out- the textual part of the message
  100. );
  101. };
  102. void ParseInputFile(WCHAR const * gLogFile);
  103. void
  104. ReadResults(
  105. TServerNode * pServer,
  106. WCHAR const * directory,
  107. WCHAR const * filename,
  108. WCHAR const * dbName
  109. );
  110. #endif //__FILEPARSER_HPP__