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.

183 lines
6.8 KiB

  1. //
  2. // MODULE: APGTSREGCONNECT.H
  3. //
  4. // PURPOSE: read - write to the registry
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 8-24-98
  11. //
  12. // NOTES:
  13. // 1. This file is shared by Local TS and Online TS, but implemented separately in each.
  14. // The relevant CPP files are OnlineRegConnect.cpp and LocalRegConnect.cpp, respectively.
  15. // 2. If we are moving toward a COM object at some point, we will probably have to establish an
  16. // abstract class in lieu of CAPGTSRegConnector and have Online & Local TS's each derive their
  17. // own version. Meanwhile (1/99), we share a common interface (defined in APGTSRegConnect.h)
  18. // but implement it differently.
  19. //
  20. // Version Date By Comments
  21. //--------------------------------------------------------------------
  22. // V3.0 08-04-98 OK
  23. //
  24. #ifndef __APGTSREGCONNECT_H_
  25. #define __APGTSREGCONNECT_H_
  26. #include "BaseException.h"
  27. #include "Stateless.h"
  28. #include "regutil.h"
  29. #include "MutexOwner.h"
  30. #include "commonregconnect.h"
  31. // no registry parameter can be larger than this value
  32. #define ABS_MAX_REG_PARAM_VAL 10000
  33. class CAPGTSRegConnectorException; // find class declaration under
  34. // CAPGTSRegConnector class declaration
  35. ////////////////////////////////////////////////////////////////////////////////////
  36. // CAPGTSRegConnector
  37. // Performs connection of APGTS project to the registry,
  38. // that means loading data stored in the registry,
  39. // creation of keys and values if not presented in the registry,
  40. // detecting what kind of registry - stored data has recently been changed.
  41. ////////////////////////////////////////////////////////////////////////////////////
  42. class CAPGTSRegConnector
  43. {
  44. public:
  45. enum ERegConnector {
  46. eIndefinite = 0x0,
  47. eResourcePath = 0x1,
  48. eVrootPath = 0x2,
  49. eMaxThreads = 0x4,
  50. // 0x8 is currently unassigned
  51. eThreadsPP = 0x10,
  52. eMaxWQItems = 0x20,
  53. eCookieLife = 0x40,
  54. eReloadDelay = 0x80,
  55. // 0x100 is currently unassigned
  56. eDetailedEventLogging= 0x200,
  57. eLogFilePath = 0x400,
  58. // only appropriate in Local Troubleshooter
  59. eTopicFileExtension = 0x800,
  60. // currently appropriate only in Local Troubleshooter
  61. eSniffAutomatic = 0x1000,
  62. eSniffManual = 0x2000,
  63. // the rest just for use in exception handling
  64. eProblemWithLogKey = 0x4000, // problem with key to IIS area where we get log file path
  65. eProblemWithKey = 0x8000
  66. };
  67. public:
  68. static CString & StringFromConnector(ERegConnector e, CString & str);
  69. static ERegConnector ConnectorFromString( const CString & str);
  70. static void AddBackslash(CString & str);
  71. static void BackslashIt(CString & str, bool bForce);
  72. static bool IsNumeric(ERegConnector e);
  73. static bool IsString(ERegConnector e);
  74. protected:
  75. static bool AssignString(CString & strPersist, const CString & strNew, DWORD dwEvent);
  76. static bool AssignNumeric(DWORD & dwPersist, DWORD dwNew,
  77. DWORD dwEvent, DWORD dwEventDecrease =0);
  78. static bool ForceRangeOfNumeric(DWORD & dw, DWORD dwDefault, DWORD dwEvent,
  79. DWORD dwMin=1, DWORD dwMax=ABS_MAX_REG_PARAM_VAL);
  80. protected:
  81. struct CRegistryInfo
  82. {
  83. CString strResourcePath; // DEF_FULLRESOURCE: resource directory
  84. // (configuration/support files)
  85. CString strVrootPath; // DEF_VROOTPATH: local web URL to the DLL
  86. DWORD dwMaxThreads; // desired number of pool threads
  87. DWORD dwThreadsPP; // (On Microsoft's server farm,
  88. // this system runs on a 4-processor box.)
  89. // If dwThreadsPP * (number of processors) > dwMaxThreads,
  90. // dwMaxThreads wins out as a limitation
  91. DWORD dwMaxWQItems; // Maximum size of Pool Queue (number of work items
  92. // not yet picked up by a pool thread)
  93. DWORD dwCookieLife; // cookie life in minutes
  94. DWORD dwReloadDelay; // Amount of time (in seconds) file system must settle
  95. // down before we try to read from files
  96. DWORD dwDetailedEventLogging; // really a boolean
  97. CString strLogFilePath; // Defaults to DEF_FULLRESOURCE, but expect always to
  98. // override that with the location of the IIS log.
  99. CString strTopicFileExtension; // appropriate only in Local Troubleshooter
  100. DWORD dwSniffAutomatic; // {1/0} control automatic sniffing
  101. DWORD dwSniffManual; // {1/0} control manual sniffing
  102. bool m_bIsRead; // indicates that there has been at least one attempt to read the registry
  103. CRegistryInfo() {SetToDefault();}
  104. void SetToDefault();
  105. };
  106. CRegistryInfo m_RegistryInfo;
  107. static CMutexOwner s_mx;
  108. CString m_strTopicName; // This string is ignored in the Online Troubleshooter.
  109. // Done under the guise of binary compatibility.
  110. public:
  111. CAPGTSRegConnector( const CString& strTopicName ); // strTopicName is ignored in the Online Troubleshooter.
  112. // Done under the guise of binary compatibility.
  113. ~CAPGTSRegConnector();
  114. bool Exists(); // the root key (In Online TS, "HKEY_LOCAL_MACHINE\SOFTWARE\\ISAPITroubleShoot") exists
  115. bool IsRead();
  116. bool Read(int & maskChanged, int & maskCreated); // pump data into m_RegistryInfo -
  117. // PLUS sets absent data in registry to default.
  118. DWORD GetDesiredThreadCount();
  119. bool GetNumericInfo(ERegConnector, DWORD&); // returns registry data - numeric
  120. bool GetStringInfo(ERegConnector, CString&); // returns registry data - string
  121. bool SetOneValue(const CString & strName, const CString & strValue, bool &bChanged);
  122. protected:
  123. void Lock();
  124. void Unlock();
  125. protected:
  126. void ReadUpdateRegistry(int & maskChanged, int & maskCreated);
  127. CString ThisProgramFullKey();
  128. void SetNumericValue(CRegUtil &reg, ERegConnector e, DWORD dwValue);
  129. void SetStringValue(CRegUtil &reg, ERegConnector e, CString strValue);
  130. bool SetOneNumericValue(ERegConnector e, DWORD dwValue);
  131. bool SetOneStringValue(ERegConnector e, const CString & strValue);
  132. private:
  133. void Clear();
  134. LPCTSTR RegSoftwareLoc();
  135. LPCTSTR RegThisProgram();
  136. };
  137. ////////////////////////////////////////////////////////////////////////////////////
  138. // CAPGTSRegConnectorException
  139. ////////////////////////////////////////////////////////////////////////////////////
  140. class CAPGTSRegConnectorException : public CBaseException
  141. {
  142. public:
  143. CAPGTSRegConnector::ERegConnector eVariable;
  144. CRegUtil& regUtil;
  145. // we are supposed to get WinErr (return of failed ::Reg function)
  146. // from the regUtil variable
  147. public:
  148. // source_file is LPCSTR rather than LPCTSTR because __FILE__ is char[35]
  149. CAPGTSRegConnectorException(LPCSTR source_file,
  150. int line,
  151. CRegUtil& reg_util,
  152. CAPGTSRegConnector::ERegConnector variable =CAPGTSRegConnector::eIndefinite)
  153. : CBaseException(source_file, line),
  154. regUtil(reg_util),
  155. eVariable(variable)
  156. {}
  157. void Close() {regUtil.Close();}
  158. void Log();
  159. };
  160. #endif