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.

499 lines
10 KiB

  1. #include "precomp.h"
  2. #include <debug.h>
  3. #include "cluster.h"
  4. #include "control.h"
  5. #include "param.h"
  6. CWlbsControl g_WlbsControl;
  7. DWORD WINAPI WlbsInit
  8. (
  9. PTCHAR product,
  10. DWORD version,
  11. PVOID reserved
  12. )
  13. {
  14. return g_WlbsControl.Initialize();
  15. }
  16. DWORD WINAPI WlbsQuery
  17. (
  18. DWORD cluster,
  19. DWORD host,
  20. PWLBS_RESPONSE response,
  21. PDWORD num_hosts,
  22. PDWORD host_map,
  23. PFN_QUERY_CALLBACK pfnQueryCallBack
  24. )
  25. {
  26. return g_WlbsControl.WlbsQuery(cluster, host, response,num_hosts, host_map, pfnQueryCallBack);
  27. }
  28. DWORD WINAPI WlbsQueryState
  29. (
  30. DWORD cluster,
  31. DWORD host,
  32. DWORD operation,
  33. PNLB_OPTIONS pOptions,
  34. PWLBS_RESPONSE pResponse,
  35. PDWORD pcResponses
  36. )
  37. {
  38. return g_WlbsControl.WlbsQueryState(cluster, host, operation, pOptions, pResponse, pcResponses);
  39. }
  40. DWORD WINAPI WlbsSuspend
  41. (
  42. DWORD cluster,
  43. DWORD host,
  44. PWLBS_RESPONSE response,
  45. PDWORD num_hosts
  46. )
  47. {
  48. return g_WlbsControl.WlbsSuspend(cluster, host, response, num_hosts);
  49. }
  50. DWORD WINAPI WlbsResume
  51. (
  52. DWORD cluster,
  53. DWORD host,
  54. PWLBS_RESPONSE response,
  55. PDWORD num_hosts
  56. )
  57. {
  58. return g_WlbsControl.WlbsResume(cluster, host, response, num_hosts);
  59. }
  60. DWORD WINAPI WlbsStart
  61. (
  62. DWORD cluster,
  63. DWORD host,
  64. PWLBS_RESPONSE response,
  65. PDWORD num_hosts
  66. )
  67. {
  68. return g_WlbsControl.WlbsStart(cluster, host, response, num_hosts);
  69. }
  70. DWORD WINAPI WlbsStop
  71. (
  72. DWORD cluster,
  73. DWORD host,
  74. PWLBS_RESPONSE response,
  75. PDWORD num_hosts
  76. )
  77. {
  78. return g_WlbsControl.WlbsStop(cluster, host, response, num_hosts);
  79. }
  80. DWORD WINAPI WlbsDrainStop
  81. (
  82. DWORD cluster,
  83. DWORD host,
  84. PWLBS_RESPONSE response,
  85. PDWORD num_hosts
  86. )
  87. {
  88. return g_WlbsControl.WlbsDrainStop(cluster, host, response, num_hosts);
  89. }
  90. DWORD WINAPI WlbsEnable
  91. (
  92. DWORD cluster,
  93. DWORD host,
  94. PWLBS_RESPONSE response,
  95. PDWORD num_hosts,
  96. DWORD vip,
  97. DWORD port
  98. )
  99. {
  100. return g_WlbsControl.WlbsEnable(cluster, host, response, num_hosts, vip, port);
  101. }
  102. DWORD WINAPI WlbsDisable
  103. (
  104. DWORD cluster,
  105. DWORD host,
  106. PWLBS_RESPONSE response,
  107. PDWORD num_hosts,
  108. DWORD vip,
  109. DWORD port
  110. )
  111. {
  112. return g_WlbsControl.WlbsDisable(cluster, host, response, num_hosts, vip, port);
  113. }
  114. DWORD WINAPI WlbsDrain
  115. (
  116. DWORD cluster,
  117. DWORD host,
  118. PWLBS_RESPONSE response,
  119. PDWORD num_hosts,
  120. DWORD vip,
  121. DWORD port
  122. )
  123. {
  124. return g_WlbsControl.WlbsDrain(cluster, host, response, num_hosts, vip, port);
  125. }
  126. DWORD WINAPI WlbsResolve
  127. (
  128. const WCHAR* address
  129. )
  130. {
  131. struct hostent * host;
  132. char buf[256];
  133. if (address == NULL)
  134. return 0;
  135. unsigned long addr = IpAddressFromAbcdWsz (address);
  136. if (addr != INADDR_NONE)
  137. {
  138. return addr;
  139. }
  140. if (!WideCharToMultiByte(CP_ACP, 0, address, -1, buf, sizeof(buf), NULL, NULL))
  141. return 0;
  142. host = gethostbyname (buf);
  143. if (host == NULL)
  144. return 0;
  145. return((struct in_addr *) (host -> h_addr)) -> s_addr;
  146. } /* end WlbsResolve */
  147. #define MAXIPSTRLEN WLBS_MAX_CL_IP_ADDR + 1
  148. BOOL WINAPI WlbsAddressToString
  149. (
  150. DWORD address,
  151. PTCHAR buf,
  152. PDWORD lenp
  153. )
  154. {
  155. PCHAR temp;
  156. DWORD len;
  157. if ( lenp == NULL )
  158. return FALSE;
  159. if (*lenp < MAXIPSTRLEN)
  160. return FALSE;
  161. AbcdWszFromIpAddress(address, buf, *lenp);
  162. *lenp=lstrlen(buf);
  163. return TRUE;
  164. } /* end WlbsAddressToString */
  165. BOOL WINAPI WlbsAddressToName
  166. (
  167. DWORD address,
  168. PTCHAR buf,
  169. PDWORD lenp
  170. )
  171. {
  172. struct hostent * name;
  173. DWORD len;
  174. HRESULT hresult;
  175. if ( lenp == NULL )
  176. return FALSE;
  177. name = gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET);
  178. if (name == NULL)
  179. {
  180. *lenp = 0;
  181. return FALSE;
  182. }
  183. len = strlen (name -> h_name) + 1;
  184. /* This is to prevent stprintf from breaking */
  185. if (*lenp > 0)
  186. {
  187. name -> h_name [*lenp - 1] = 0;
  188. hresult = StringCchPrintf (buf, *lenp, L"%S", name -> h_name);
  189. if (FAILED(hresult))
  190. {
  191. return FALSE;
  192. }
  193. }
  194. if (len > *lenp)
  195. {
  196. *lenp = len;
  197. return FALSE;
  198. }
  199. *lenp = len;
  200. return TRUE;
  201. } /* end WlbsAddressToName */
  202. VOID WINAPI WlbsPortSet
  203. (
  204. DWORD cluster,
  205. WORD port
  206. )
  207. {
  208. g_WlbsControl.WlbsPortSet(cluster, port);
  209. }
  210. VOID WINAPI WlbsPasswordSet
  211. (
  212. DWORD cluster,
  213. PTCHAR password
  214. )
  215. {
  216. g_WlbsControl.WlbsPasswordSet(cluster, password);
  217. }
  218. VOID WINAPI WlbsCodeSet
  219. (
  220. DWORD cluster,
  221. DWORD passw
  222. )
  223. {
  224. g_WlbsControl.WlbsCodeSet(cluster, passw);
  225. }
  226. VOID WINAPI WlbsDestinationSet
  227. (
  228. DWORD cluster,
  229. DWORD dest
  230. )
  231. {
  232. g_WlbsControl.WlbsDestinationSet(cluster, dest);
  233. }
  234. VOID WINAPI WlbsTimeoutSet
  235. (
  236. DWORD cluster,
  237. DWORD milliseconds
  238. )
  239. {
  240. g_WlbsControl.WlbsTimeoutSet(cluster, milliseconds);
  241. }
  242. //+----------------------------------------------------------------------------
  243. //
  244. // Function: WlbsReadReg
  245. //
  246. // Description:
  247. //
  248. // Arguments: WORD cluster -
  249. // PWLBS_REG_PARAMS reg_data
  250. //
  251. // Returns: DWORD WINAPI -
  252. //
  253. // History: fengsun Created Header 3/9/00
  254. //
  255. //+----------------------------------------------------------------------------
  256. DWORD WINAPI WlbsReadReg(
  257. DWORD cluster,
  258. PWLBS_REG_PARAMS reg_data
  259. )
  260. {
  261. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  262. if(pCluster == NULL)
  263. {
  264. return WLBS_NOT_FOUND;
  265. }
  266. return pCluster->ReadConfig(reg_data);
  267. }
  268. //+----------------------------------------------------------------------------
  269. //
  270. // Function: WlbsWriteReg
  271. //
  272. // Description:
  273. //
  274. // Arguments: WORD cluster -
  275. // PWLBS_REG_PARAMS reg_data
  276. //
  277. // Returns: DWORD WINAPI -
  278. //
  279. // History: fengsun Created Header 3/9/00
  280. //
  281. //+----------------------------------------------------------------------------
  282. DWORD WINAPI WlbsWriteReg(
  283. DWORD cluster,
  284. const PWLBS_REG_PARAMS reg_data
  285. )
  286. {
  287. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  288. if(pCluster == NULL)
  289. {
  290. return WLBS_NOT_FOUND;
  291. }
  292. return pCluster->WriteConfig(reg_data);
  293. }
  294. //+----------------------------------------------------------------------------
  295. //
  296. // Function: WlbsCommitChanges
  297. //
  298. // Description:
  299. //
  300. // Arguments: DWORD cluster -
  301. //
  302. // Returns: DWORD WINAPI -
  303. //
  304. // History: fengsun Created Header 3/9/00
  305. //
  306. //+----------------------------------------------------------------------------
  307. DWORD WINAPI WlbsCommitChanges(DWORD cluster)
  308. {
  309. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  310. if(pCluster == NULL)
  311. {
  312. return WLBS_NOT_FOUND;
  313. }
  314. return pCluster->CommitChanges(&g_WlbsControl);
  315. }
  316. DWORD WINAPI WlbsSetDefaults
  317. (
  318. PWLBS_REG_PARAMS reg_data
  319. )
  320. {
  321. return ParamSetDefaults(reg_data);
  322. }
  323. BOOL WINAPI WlbsFormatMessage
  324. (
  325. DWORD, // error,
  326. WLBS_COMMAND, // command,
  327. BOOL, // cluster
  328. PTCHAR messagep,
  329. PDWORD lenp
  330. )
  331. {
  332. DWORD len;
  333. PTSTR error_str = _TEXT("Not yet implemented");
  334. len = _tcslen(error_str) + 1;
  335. /* This is to prevent stprintf from breaking */
  336. if (lenp == NULL)
  337. return FALSE;
  338. if (*lenp == 0)
  339. {
  340. *lenp = len;
  341. return FALSE;
  342. }
  343. // CODE REVIEW : Null terminate messagep. Verify that *lenp is the correct length (ie. length of destination)
  344. _tcsncpy(messagep, error_str, *lenp);
  345. messagep[*lenp - 1] = 0;
  346. if (len > *lenp)
  347. {
  348. *lenp = len;
  349. return FALSE;
  350. }
  351. *lenp = len;
  352. return TRUE;
  353. } /* end WlbsFormatMessage */
  354. DWORD WINAPI WlbsEnumClusters(OUT DWORD* pdwAddresses, OUT DWORD* pdwNum)
  355. {
  356. return g_WlbsControl.EnumClusters(pdwAddresses, pdwNum);
  357. }
  358. //+----------------------------------------------------------------------------
  359. //
  360. // Function: WlbsGetAdapterGuid
  361. //
  362. // Description:
  363. //
  364. // Arguments: IN DWORD cluster -
  365. // OUT GUID* pAdapterGuid -
  366. //
  367. // Returns: DWORD WINAPI -
  368. //
  369. // History: fengsun Created Header 3/10/00
  370. //
  371. //+----------------------------------------------------------------------------
  372. DWORD WINAPI WlbsGetAdapterGuid(IN DWORD cluster, OUT GUID* pAdapterGuid)
  373. {
  374. ASSERT(pAdapterGuid);
  375. if (pAdapterGuid == NULL)
  376. {
  377. return WLBS_BAD_PARAMS;
  378. }
  379. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  380. if(pCluster == NULL)
  381. {
  382. return WLBS_NOT_FOUND;
  383. }
  384. *pAdapterGuid = pCluster->GetAdapterGuid();
  385. return WLBS_OK;
  386. }
  387. //+----------------------------------------------------------------------------
  388. //
  389. // Function: WlbsNotifyConfigChange
  390. //
  391. // Description:
  392. //
  393. // Arguments: DWORD cluster -
  394. //
  395. // Returns: DWORD WINAPI -
  396. //
  397. // History: fengsun Created Header 7/3/00
  398. //
  399. //+----------------------------------------------------------------------------
  400. DWORD WINAPI WlbsNotifyConfigChange(DWORD cluster)
  401. {
  402. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  403. if(pCluster == NULL)
  404. {
  405. return WLBS_NOT_FOUND;
  406. }
  407. DWORD dwStatus = NotifyDriverConfigChanges(g_WlbsControl.GetDriverHandle(), pCluster->GetAdapterGuid());
  408. return dwStatus;
  409. }