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.

181 lines
5.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // logfile.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // Declares the class LogFile.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #ifndef LOGFILE_H
  15. #define LOGFILE_H
  16. #pragma once
  17. #include "guard.h"
  18. #include "iaspolcy.h"
  19. #include "sdoias.h"
  20. // Assumes ownership of a string pointer allocated with operator new[] and
  21. // frees the string in its destructor.
  22. class StringSentry
  23. {
  24. public:
  25. explicit StringSentry(wchar_t* p = 0) throw ();
  26. ~StringSentry() throw ();
  27. const wchar_t* Get() const throw ();
  28. bool IsNull() const throw ();
  29. operator const wchar_t*() const throw ();
  30. operator wchar_t*() throw ();
  31. void Swap(StringSentry& other) throw ();
  32. StringSentry& operator=(wchar_t* p) throw ();
  33. private:
  34. wchar_t* sz;
  35. // Not implemented.
  36. StringSentry(const StringSentry&);
  37. StringSentry& operator=(const StringSentry&);
  38. };
  39. // Maintains a generic logfile that is periodically rolled over either when a
  40. // specified interval has elapsed or the logfile reaches a certain size.
  41. class LogFile : private Guardable
  42. {
  43. public:
  44. LogFile() throw ();
  45. ~LogFile() throw ();
  46. // Various properties supported by the logfile.
  47. void SetDeleteIfFull(bool newVal) throw ();
  48. DWORD SetDirectory(const wchar_t* newVal) throw ();
  49. void SetMaxSize(const ULONGLONG& newVal) throw ();
  50. DWORD SetPeriod(NEW_LOG_FILE_FREQUENCY newVal) throw ();
  51. // Write a record to the logfile.
  52. bool Write(
  53. IASPROTOCOL protocol,
  54. const SYSTEMTIME& st,
  55. const BYTE* buf,
  56. DWORD buflen,
  57. bool allowRetry = true
  58. ) throw ();
  59. // Close the logfile.
  60. void Close() throw ();
  61. private:
  62. // Checks the state of the current file handle and opens a new file if
  63. // necessary.
  64. void CheckFileHandle(
  65. IASPROTOCOL protocol,
  66. const SYSTEMTIME& st,
  67. DWORD buflen
  68. ) throw ();
  69. // Create a new file including the directory if necessary. The caller is
  70. // responsible for closing the returned handle.
  71. HANDLE CreateDirectoryAndFile() throw ();
  72. // Delete the oldest file in the logfile directory. Returns true if
  73. // successful.
  74. bool DeleteOldestFile(IASPROTOCOL protocol, const SYSTEMTIME& st) throw ();
  75. // Extends the file number to include the century if necessary.
  76. unsigned int ExtendFileNumber(
  77. const SYSTEMTIME& st,
  78. unsigned int narrow
  79. ) const throw ();
  80. // Finds the lowest or highest log file number.
  81. DWORD FindFileNumber(
  82. const SYSTEMTIME& st,
  83. bool findLowest,
  84. unsigned int& result
  85. ) const throw ();
  86. // Returns the formatted logfile name. The caller is responsible for
  87. // deleting the returned string.
  88. wchar_t* FormatFileName(unsigned int number) const throw ();
  89. // Returns the filter used to search for the file name.
  90. const wchar_t* GetFileNameFilter() const throw ();
  91. // Returns the format string used to create the file name.
  92. const wchar_t* GetFileNameFormat() const throw ();
  93. // Returns the numeric portion of the file name.
  94. unsigned int GetFileNumber(const SYSTEMTIME& st) const throw ();
  95. // Returns the 1-based week within the month for the given SYSTEMTIME.
  96. DWORD GetWeekOfMonth(const SYSTEMTIME& st) const throw ();
  97. // Tests the validity of a file number. len is the length in characters of
  98. // the file name containing the number -- useful for width tests.
  99. bool IsValidFileNumber(size_t len, unsigned int num) const throw ();
  100. // Releases the current file (if any) and opens a new one.
  101. void OpenFile(IASPROTOCOL protocol, const SYSTEMTIME& st) throw ();
  102. // Scans the logfile directory to determine the next sequence number.
  103. DWORD UpdateSequence() throw ();
  104. // Functions that report the result of deleting an old log file to free up
  105. // disk space.
  106. void ReportOldFileDeleteError(
  107. IASPROTOCOL protocol,
  108. const wchar_t* oldfile,
  109. DWORD error
  110. ) const throw ();
  111. void ReportOldFileDeleted(
  112. IASPROTOCOL protocol,
  113. const wchar_t* oldfile
  114. ) const throw ();
  115. void ReportOldFileNotFound(
  116. IASPROTOCOL protocol
  117. ) const throw ();
  118. // The logfile directory; does not have a trailing backslash.
  119. StringSentry directory;
  120. // true if old logfiles should be deleted if the disk is full.
  121. bool deleteIfFull;
  122. // The max size in bytes that the logfile will be allowed to reach.
  123. ULARGE_INTEGER maxSize;
  124. // The period at which new log files are opened.
  125. NEW_LOG_FILE_FREQUENCY period;
  126. // The current sequence number used for sized log files.
  127. unsigned int seqNum;
  128. // Handle to the log file; may be invalid.
  129. HANDLE file;
  130. // Current log file name; may be null.
  131. StringSentry filename;
  132. // Time at which we last opened or tried to open the logfile.
  133. SYSTEMTIME whenOpened;
  134. // Week at which we last opened or tried to open the logfile.
  135. DWORD weekOpened;
  136. // Current size of the log file in bytes. Zero if no file is open.
  137. ULARGE_INTEGER currentSize;
  138. // First day of the week for our locale.
  139. DWORD firstDayOfWeek;
  140. // Handle used for reporting IAS events.
  141. HANDLE iasEventSource;
  142. // Handle used for reporting RemoteAccess events.
  143. HANDLE rasEventSource;
  144. // Not implemented.
  145. LogFile(const LogFile&);
  146. LogFile& operator=(const LogFile&);
  147. };
  148. #endif // LOGFILE_H