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.

260 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. lbcnfg.hxx
  5. Abstract:
  6. Classes to handle IIS load balancing configuration
  7. Author:
  8. Philippe Choquier (phillich)
  9. --*/
  10. #if !defined( _LBCNFG_HXX )
  11. #define _LBCNFG_HXX
  12. #if !defined(dllexp)
  13. #define dllexp __declspec( dllexport )
  14. #endif
  15. #define IISLOADBAL_REGISTRY_KEY "SOFTWARE\\Microsoft\\IISLoadBalancing"
  16. #define IPLIST_REGISTRY_VALUE "IpList"
  17. #define PERFMON_REGISTRY_VALUE "Perfmon"
  18. #define STICKY_REGISTRY_VALUE "StickyDuration"
  19. #define IPLIST_VERSION_1 1
  20. #define IPLIST_VERSION IPLIST_VERSION_1
  21. #define PERFLIST_VERSION_1 1
  22. #define PERFLIST_VERSION PERFLIST_VERSION_1
  23. //
  24. // Private helper classes and functions
  25. //
  26. class CComputerBalanceCnfg {
  27. public:
  28. CComputerBalanceCnfg() {}
  29. ~CComputerBalanceCnfg() {}
  30. BOOL Serialize( CStoreXBF* pX )
  31. { return m_ComputerName.Serialize( pX ) &&
  32. m_IpPrivate.Serialize( pX ) &&
  33. m_Name.Serialize( pX ); }
  34. BOOL Unserialize( LPBYTE* ppb, LPDWORD pdw, DWORD dwIpPublic )
  35. { return m_ComputerName.Unserialize( ppb, pdw ) &&
  36. m_IpPrivate.Unserialize( ppb, pdw, dwIpPublic ) &&
  37. m_Name.Unserialize( ppb, pdw, dwIpPublic ); }
  38. BOOL Init( LPWSTR pszName, UINT cIpPublic );
  39. BOOL AddIpPublic()
  40. { return m_IpPrivate.AddEntry( L"" )!=INDEX_ERROR &&
  41. m_Name.AddEntry( L"" )!=INDEX_ERROR; }
  42. BOOL DeleteIpPublic( UINT iIpPublic )
  43. { return m_IpPrivate.DeleteEntry( iIpPublic ) &&
  44. m_Name.DeleteEntry( iIpPublic ); }
  45. BOOL SetIpPrivate( UINT iIpPublic, LPWSTR pszIpPrivate, LPWSTR pszName )
  46. { return m_IpPrivate.SetEntry( iIpPublic, pszIpPrivate) &&
  47. m_Name.SetEntry( iIpPublic, pszName ); }
  48. BOOL GetName( LPWSTR* ppszName )
  49. { *ppszName = m_ComputerName.Get(); return TRUE; }
  50. BOOL GetIpPrivate( UINT iIpPublic, LPWSTR* ppszIpPrivate, LPWSTR* ppszName )
  51. { *ppszIpPrivate = m_IpPrivate.GetEntry( iIpPublic );
  52. *ppszName = m_Name.GetEntry( iIpPublic );
  53. return *ppszName != NULL && *ppszIpPrivate != NULL; }
  54. private:
  55. CAllocString m_ComputerName;
  56. CStrPtrXBF m_IpPrivate;
  57. CStrPtrXBF m_Name;
  58. } ;
  59. BOOL
  60. SaveBlobToReg(
  61. HKEY hKey,
  62. LPSTR pszRegKey,
  63. LPSTR pszRegValue,
  64. CStoreXBF* pX
  65. );
  66. BOOL
  67. LoadBlobFromReg(
  68. HKEY hKey,
  69. LPSTR pszRegKey,
  70. LPSTR pszRegValue,
  71. CStoreXBF* pX
  72. );
  73. //
  74. // Class giving access to public/private IP addr mapping
  75. //
  76. class CIPMap {
  77. public:
  78. dllexp CIPMap();
  79. dllexp ~CIPMap();
  80. dllexp VOID Reset();
  81. //
  82. // Serialize all rules info to buffer ( before COM call )
  83. //
  84. dllexp BOOL Serialize( CStoreXBF* pX );
  85. //
  86. // Un-serialize all rules from buffer ( using extensible buffer class )
  87. //
  88. dllexp BOOL Unserialize( CStoreXBF* pX );
  89. //
  90. // Un-serialize all rules from buffer ( after COM call )
  91. //
  92. dllexp BOOL Unserialize( LPBYTE*, LPDWORD );
  93. //
  94. // Load / save from registry. Should not be used if you access this class through COM
  95. // and Serialize() / Unserialize()
  96. //
  97. BOOL Load( HKEY hKey, LPSTR pszRegKey, LPSTR pszRegValue );
  98. BOOL Save( HKEY hKey, LPSTR pszRegKey, LPSTR pszRegValue );
  99. public:
  100. //
  101. // Server management : Add/Enum/Delete. Enum is 0-based
  102. // server name should not include leading "\\"
  103. //
  104. dllexp BOOL AddComputer( LPWSTR pszName );
  105. dllexp BOOL EnumComputer( UINT iComp, LPWSTR* ppszName );
  106. dllexp DWORD ComputerCount() { return m_Servers.GetNbPtr(); }
  107. dllexp BOOL DeleteComputer( UINT iComp );
  108. //
  109. // Public IP addr ( a.k.a. NAT resource ) management : Add/Enum/Delete. Enum is 0-based
  110. // IP addr means IP:port, e.g. 157.56.3.4:80
  111. //
  112. dllexp BOOL AddIpPublic( LPWSTR pszIpPublic, LPWSTR pszName, DWORD dwSticky, DWORD dwAttr );
  113. dllexp BOOL EnumIpPublic( UINT iIpPublic, LPWSTR* ppszIpPublic, LPWSTR* ppszName, LPDWORD pdwSticky, LPDWORD pdwAttr );
  114. dllexp DWORD IpPublicCount() { return m_IpPublic.GetNbEntry(); }
  115. dllexp BOOL DeleteIpPublic( UINT iIpPublic );
  116. //
  117. // Set/Get private IP addr for each (Server, PublicIp) target
  118. // IP addr means IP:port, e.g. 157.56.3.4:80
  119. // empty string means no such resource available on specified Server
  120. //
  121. dllexp BOOL SetIpPrivate( UINT iComp, UINT iIpPublic, LPWSTR pszIpPrivate, LPWSTR pszName );
  122. dllexp BOOL GetIpPrivate( UINT iComp, UINT iIpPublic, LPWSTR* ppszIpPrivate, LPWSTR* ppszName );
  123. private:
  124. CPtrXBF m_Servers; // array of CComputerBalanceCnfg
  125. CStrPtrXBF m_IpPublic; // list of public IP addresses
  126. CStrPtrXBF m_Name; // list of names associated with public IP addresses
  127. CPtrXBF m_Sticky; // array of sticky duration per IP public
  128. CPtrXBF m_Attr; // array of dword attr per IP public
  129. } ;
  130. //
  131. // Class giving access to performance counter list
  132. //
  133. #define LB_WEIGHT_AVAILABILITY_FLAG (DWORD)-2
  134. #define LB_WEIGHT_NORMALIZED_FLAG (DWORD)-3
  135. class CComputerPerfCounters {
  136. public:
  137. CComputerPerfCounters();
  138. ~CComputerPerfCounters();
  139. dllexp VOID Reset();
  140. //
  141. // Serialize all rules info to buffer
  142. //
  143. dllexp BOOL Serialize( CStoreXBF* pX );
  144. //
  145. // Un-serialize all rules from buffer ( using extensible buffer class )
  146. //
  147. dllexp BOOL Unserialize( CStoreXBF* pX );
  148. //
  149. // Un-serialize all rules from buffer
  150. //
  151. dllexp BOOL Unserialize( LPBYTE*, LPDWORD );
  152. BOOL Load( HKEY hKey, LPSTR pszRegKey, LPSTR pszRegValue );
  153. BOOL Save( HKEY hKey, LPSTR pszRegKey, LPSTR pszRegValue );
  154. public:
  155. // pszPerfCounter : w/o leading "\\" + computer name, but with leading "\"
  156. // pszServerName : w/ or w/o leading "\\"
  157. dllexp BOOL AddPerfCounter( LPWSTR pszServerName, LPWSTR pszPerfCounter, DWORD dwWeight );
  158. dllexp BOOL EnumPerfCounter( UINT iPerfCounter, LPWSTR* ppszServerName, LPWSTR* ppszPerfCounter, DWORD* pdwWeight );
  159. dllexp BOOL DeletePerfCounter( UINT iPerfCounter );
  160. dllexp BOOL SetPerfCounterWeight( UINT iPerfCounter, DWORD dwWeight );
  161. dllexp DWORD PerfCounterCount()
  162. { return m_PerfCounters.GetNbEntry(); }
  163. private:
  164. CStrPtrXBF m_PerfCounterServers;
  165. CStrPtrXBF m_PerfCounters;
  166. CPtrXBF m_Weight;
  167. } ;
  168. //
  169. // Class giving access to list of IP addresses on NAT box
  170. //
  171. class CIpEndpointList {
  172. public:
  173. CIpEndpointList();
  174. ~CIpEndpointList();
  175. dllexp BOOL BuildListFromLocalhost();
  176. dllexp VOID Reset();
  177. //
  178. // Serialize all rules info to buffer ( before COM call )
  179. //
  180. dllexp BOOL Serialize( CStoreXBF* pX );
  181. //
  182. // Un-serialize all rules from buffer ( using extensible buffer class )
  183. //
  184. dllexp BOOL Unserialize( CStoreXBF* pX );
  185. //
  186. // Un-serialize all rules from buffer ( as result of COM call )
  187. //
  188. dllexp BOOL Unserialize( LPBYTE*, LPDWORD );
  189. //
  190. // Enumerate IP addresses ( 0-based, returns FALSE if no more instance )
  191. //
  192. dllexp BOOL EnumIpEndpoint( UINT iIp, LPWSTR* ppszIp );
  193. private:
  194. CStrPtrXBF m_IpEndpoint; // list of IP addresses
  195. } ;
  196. #endif