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.

236 lines
5.1 KiB

  1. #include <crtdbg.h>
  2. #include <comdef.h>
  3. #include <iostream>
  4. #include <memory>
  5. #include <string>
  6. #include <wbemprov.h>
  7. #include <genlex.h> //for wmi object path parser
  8. #include <objbase.h>
  9. #include <wlbsconfig.h>
  10. #include <ntrkcomm.h>
  11. using namespace std;
  12. #include "objpath.h"
  13. #include "debug.h"
  14. #include "utils.h"
  15. ////////////////////////////////////////////////////////////////////////////////
  16. //
  17. // CErrorWlbsControl::CErrorWlbsControl
  18. //
  19. // Purpose: This object is ultimately caught and used to send WLBS error codes
  20. // back to the user via an __ExtendedStatus object. Strings are not
  21. // sent back in release mode due to localization concerns.
  22. //
  23. ////////////////////////////////////////////////////////////////////////////////
  24. CErrorWlbsControl::CErrorWlbsControl
  25. (
  26. DWORD a_dwError,
  27. WLBS_COMMAND a_CmdCommand,
  28. BOOL a_bAllClusterCall
  29. )
  30. {
  31. #ifdef DBG
  32. static char* pszWlbsCommand[] =
  33. {
  34. "WlbsAddPortRule",
  35. "WlbsAddressToName",
  36. "WlbsAddressToString",
  37. "WlbsAdjust",
  38. "WlbsCommitChanges",
  39. "WlbsDeletePortRule",
  40. "WlbsDestinationSet",
  41. "WlbsDisable",
  42. "WlbsDrain",
  43. "WlbsDrainStop",
  44. "WlbsEnable",
  45. "WlbsFormatMessage",
  46. "WlbsGetEffectiveVersion",
  47. "WlbsGetNumPortRules",
  48. "WlbsEnumPortRules",
  49. "WlbsGetPortRule",
  50. "WlbsInit",
  51. "WlbsPasswordSet",
  52. "WlbsPortSet",
  53. "WlbsQuery",
  54. "WlbsReadReg",
  55. "WlbsResolve",
  56. "WlbsResume",
  57. "WlbsSetDefaults",
  58. "WlbsSetRemotePassword",
  59. "WlbsStart",
  60. "WlbsStop",
  61. "WlbsSuspend",
  62. "WlbsTimeoutSet",
  63. "WlbsWriteReg"
  64. };
  65. char buf[512];
  66. if (a_CmdCommand <= CmdWlbsWriteReg)
  67. {
  68. if (a_CmdCommand != CmdWlbsQuery || a_dwError != WLBS_TIMEOUT)
  69. {
  70. sprintf(buf, "wlbsprov: %s failed, AllCluster = %d, error = %d\n",
  71. pszWlbsCommand[a_CmdCommand], (int)a_bAllClusterCall, a_dwError);
  72. }
  73. }
  74. else
  75. {
  76. sprintf(buf, "wlbsprov: %d failed, AllCluster = %d, error = %d\n",
  77. a_CmdCommand, (int)a_bAllClusterCall, a_dwError);
  78. }
  79. OutputDebugStringA(buf);
  80. #endif
  81. WlbsFormatMessageWrapper( a_dwError,
  82. a_CmdCommand,
  83. a_bAllClusterCall,
  84. m_wstrDescription );
  85. m_dwError = a_dwError;
  86. }
  87. ////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // AddressToString
  90. //
  91. // Purpose: Converts a DWORD address to a wstring in dotted notation. This
  92. // function wraps the WlbsAddressToString function.
  93. //
  94. //
  95. ////////////////////////////////////////////////////////////////////////////////
  96. void AddressToString( DWORD a_dwAddress, wstring& a_szIPAddress )
  97. {
  98. DWORD dwLenIPAddress = 32;
  99. WCHAR *szIPAddress = new WCHAR[dwLenIPAddress];
  100. if( !szIPAddress )
  101. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  102. try {
  103. for( short nTryTwice = 2; nTryTwice > 0; nTryTwice--) {
  104. if( ::WlbsAddressToString( a_dwAddress, szIPAddress, &dwLenIPAddress ) )
  105. break;
  106. delete [] szIPAddress;
  107. szIPAddress = new WCHAR[dwLenIPAddress];
  108. if( !szIPAddress )
  109. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  110. }
  111. if( !nTryTwice )
  112. throw _com_error( WBEM_E_FAILED );
  113. a_szIPAddress = szIPAddress;
  114. if ( szIPAddress ) {
  115. delete [] szIPAddress;
  116. szIPAddress = NULL;
  117. }
  118. }
  119. catch(...) {
  120. if ( szIPAddress )
  121. delete [] szIPAddress;
  122. throw;
  123. }
  124. }
  125. ////////////////////////////////////////////////////////////////////////////////
  126. //
  127. // CWmiWlbsCluster::FormatMessage
  128. //
  129. // Purpose: Obtains a descriptive string associated with a WLBS return value.
  130. //
  131. ////////////////////////////////////////////////////////////////////////////////
  132. void WlbsFormatMessageWrapper
  133. (
  134. DWORD a_dwError,
  135. WLBS_COMMAND a_Command,
  136. BOOL a_bClusterWide,
  137. wstring& a_wstrMessage
  138. )
  139. {
  140. DWORD dwBuffSize = 255;
  141. TCHAR* pszMessageBuff = new WCHAR[dwBuffSize];
  142. if( !pszMessageBuff )
  143. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  144. try {
  145. for( short nTryTwice = 2; nTryTwice > 0; nTryTwice-- ) {
  146. if( WlbsFormatMessage( a_dwError,
  147. a_Command,
  148. a_bClusterWide,
  149. pszMessageBuff,
  150. &dwBuffSize)
  151. ) break;
  152. delete [] pszMessageBuff;
  153. pszMessageBuff = new WCHAR[dwBuffSize];
  154. if( !pszMessageBuff )
  155. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  156. }
  157. if( !nTryTwice )
  158. throw _com_error( WBEM_E_FAILED );
  159. a_wstrMessage = pszMessageBuff;
  160. delete pszMessageBuff;
  161. } catch (...) {
  162. if( pszMessageBuff )
  163. delete [] pszMessageBuff;
  164. throw;
  165. }
  166. }
  167. ////////////////////////////////////////////////////////////////////////////////
  168. //
  169. // ClusterStatusOK
  170. //
  171. // Purpose:
  172. //
  173. ////////////////////////////////////////////////////////////////////////////////
  174. BOOL ClusterStatusOK(DWORD a_dwStatus)
  175. {
  176. if( a_dwStatus > 0 && a_dwStatus <= WLBS_MAX_HOSTS )
  177. return TRUE;
  178. switch( a_dwStatus ) {
  179. case WLBS_SUSPENDED:
  180. case WLBS_STOPPED:
  181. case WLBS_DRAINING:
  182. case WLBS_CONVERGING:
  183. case WLBS_CONVERGED:
  184. return TRUE;
  185. break;
  186. default:
  187. return FALSE;
  188. }
  189. }