Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. lhourset.hxx
  7. An encapsulation of the logon hours control setting
  8. This file provides communication between the USER class of
  9. LMOBJ and the LOGON_HOURS_CONTROL class of BLTCC.
  10. FILE HISTORY:
  11. beng 06-May-1992 Created (from lmouser.hxx)
  12. */
  13. #ifndef _LHOURSET_HXX_
  14. #define _LHOURSET_HXX_
  15. #include "base.hxx"
  16. #include "uibuffer.hxx"
  17. // needed for clients who must bind at compile-time rather than link-time
  18. // clients should use cDaysPerWeek etc. when possible
  19. //
  20. #define HOURS_PER_DAY (24)
  21. #define DAYS_PER_WEEK (7)
  22. #define HOURS_PER_WEEK (HOURS_PER_DAY * DAYS_PER_WEEK)
  23. #define MINUTES_PER_HOUR (60)
  24. #define MINUTES_PER_WEEK (MINUTES_PER_HOUR * HOURS_PER_WEEK)
  25. /*************************************************************************
  26. NAME: LOGON_HOURS_SETTING
  27. SYNOPSIS: Helper class for USER_11 to manage logon hours settings
  28. This class help manage the 7 * 24 (hours/week) packed
  29. bit field which the LanMan API uses to represent logon
  30. hours settings. LOGON_HOURS_SETTING should not be confused
  31. with the BLT Logon Hours custom control, this class is more
  32. like a collection.
  33. INTERFACE: Construct with initial setting, or no parameters for
  34. new user default.
  35. SetFromBits():
  36. Set the logon hours setting. Pass the number of
  37. bits in the bit block (should be uHoursPerWeek).
  38. SetFromBytes():
  39. Set the logon hours setting. Pass the number of
  40. bytes in the bytes block (should be uHoursPerWeek/8).
  41. PermitAll():
  42. Permit logon at any time.
  43. MakeDefault():
  44. Revert to new user default. Default is
  45. UnitsPerWeek == HoursPerWeek and all hours set.
  46. QueryHoursBlock():
  47. Returns the logon hours setting in byte block
  48. format (BYTE *). Note that the return value is
  49. not const; it is permitted to modify this value
  50. directly, which in turn modifies the
  51. LOGON_HOURS_SETTING directly. This pointer
  52. ceases to be valid when the LOGON_HOURS_SETTING
  53. is destructed.
  54. QueryUnitsPerWeek():
  55. Returns the number of bits in the QueryHoursBlock
  56. block.
  57. QueryByteCount():
  58. Returns the number of bytes in the QueryHoursBlock
  59. block.
  60. IsEditableUnitsPerWeek():
  61. Returns TRUE iff a logon hours block with this
  62. unitsPerWeek value is valid for the QueryHour
  63. and SetHour APIs.
  64. QueryHourInWeek():
  65. QueryHourInDay():
  66. Determines whether an individual hour is enabled.
  67. Only valid if IsEditableUnitsPerWeek.
  68. SetHourInWeek():
  69. SetHourInDay():
  70. Changes whether an individual hour is enabled.
  71. Only valid if IsEditableUnitsPerWeek.
  72. IsIdentical():
  73. IsIdenticalToBits():
  74. IsIdenticalToBytes():
  75. operator==():
  76. Returns TRUE iff the setting is identical to the
  77. parameter setting, where the parameter may be
  78. another LOGON_HOURS_SETTING, or a logon hours
  79. setting in byte string format. In the
  80. IsIdenticalToBits and Bytes forms, extra bits in
  81. the last byte must be 0.
  82. ConvertToHoursPerWeek
  83. Converts a LOGON_HOUR_SETTING in DaysPerWeek
  84. format into HoursPerWeek format. Will not
  85. convert from MinutesPerWeek or any other format.
  86. ConvertToGMT
  87. Rotate the logonhours to GMT
  88. ConvertFromGMT
  89. Rotate the logonhours from GMT
  90. NOTES:
  91. The UnitsPerWeek setting is required to always be
  92. uHoursPerWeek, or 7*24 (168). We do not even remember
  93. this value, instead we just assert out if it is wrong.
  94. Similarly, the count of bytes is expected to always be
  95. uHoursPerWeek / 8, or 21.
  96. PARENT: BASE
  97. USES: BUFFER
  98. HISTORY:
  99. jonn 12/11/91 Created
  100. beng 06-May-1992 Religious whitespace/naming delta
  101. beng 06-Jul-1992 Tinker the consts to make it work in a DLL
  102. KeithMo 25-Aug-1992 Changed consts to enum to quite linker.
  103. **************************************************************************/
  104. DLL_CLASS LOGON_HOURS_SETTING : public BASE
  105. {
  106. private:
  107. UINT _cUnitsPerWeek;
  108. BUFFER _buf;
  109. static UINT QueryByteCount( UINT unitsperweek )
  110. { return (unitsperweek + 7) / 8; }
  111. public:
  112. enum { cHoursPerDay = HOURS_PER_DAY,
  113. cDaysPerWeek = DAYS_PER_WEEK,
  114. cHoursPerWeek = HOURS_PER_WEEK,
  115. cMinutesPerHour = MINUTES_PER_HOUR,
  116. cMinutesPerWeek = MINUTES_PER_WEEK };
  117. LOGON_HOURS_SETTING( const BYTE * pLogonHours = NULL,
  118. UINT unitsperweek = HOURS_PER_WEEK );
  119. LOGON_HOURS_SETTING( const LOGON_HOURS_SETTING & lhours );
  120. ~LOGON_HOURS_SETTING();
  121. static BOOL IsEditableUnitsPerWeek( UINT cUnitsperweek )
  122. { return ( cUnitsperweek == cHoursPerWeek ); }
  123. static BOOL IsConvertibleUnitsPerWeek( UINT cUnitsperweek )
  124. { return ( (cUnitsperweek == cHoursPerWeek)
  125. || (cUnitsperweek == cDaysPerWeek) ); }
  126. APIERR SetFromBits( const BYTE * pLogonHours, UINT cUnitsperweek );
  127. APIERR SetFromBytes( const BYTE * pb, UINT cb )
  128. { return SetFromBits( pb, cb * 8 ); }
  129. APIERR Set( const LOGON_HOURS_SETTING & lhours )
  130. { return SetFromBits( lhours.QueryHoursBlock(),
  131. lhours.QueryUnitsPerWeek() ); }
  132. APIERR PermitAll();
  133. APIERR MakeDefault();
  134. BYTE * QueryHoursBlock() const
  135. { return _buf.QueryPtr(); }
  136. UINT QueryUnitsPerWeek() const
  137. { return _cUnitsPerWeek; }
  138. UINT QueryByteCount() const
  139. { return QueryByteCount( QueryUnitsPerWeek() ); }
  140. // only valid for editable UnitsPerWeek values
  141. BOOL QueryHourInWeek( UINT hourinweek ) const;
  142. BOOL QueryHourInDay( UINT hourinday, UINT dayinweek ) const;
  143. // only valid for editable UnitsPerWeek values
  144. APIERR SetHourInWeek( BOOL fLogonAllowed, UINT hourinweek );
  145. APIERR SetHourInDay( BOOL fLogonAllowed,
  146. UINT hourinday, UINT dayinweek );
  147. // only valid for editable UnitsPerWeek values
  148. BOOL IsIdenticalToBits( const BYTE * pbLogonHours,
  149. UINT unitsperweek ) const;
  150. BOOL IsIdenticalToBytes( const BYTE * pb, UINT cb ) const
  151. { return IsIdenticalToBits( pb, cb * 8 ); }
  152. BOOL IsIdentical( const LOGON_HOURS_SETTING & lhours ) const
  153. { return IsIdenticalToBits( lhours.QueryHoursBlock(),
  154. lhours.QueryUnitsPerWeek() ); }
  155. BOOL operator==( const LOGON_HOURS_SETTING & lhours ) const
  156. { return IsIdentical( lhours ); }
  157. APIERR ConvertToHoursPerWeek();
  158. BOOL ConvertToGMT();
  159. BOOL ConvertFromGMT();
  160. };
  161. #endif // end of file - _LHOURSET_HXX_