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.

527 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. PVOID reserved
  24. )
  25. {
  26. return g_WlbsControl.WlbsQuery(cluster, host, response,num_hosts, host_map,reserved);
  27. }
  28. DWORD WINAPI WlbsSuspend
  29. (
  30. DWORD cluster,
  31. DWORD host,
  32. PWLBS_RESPONSE response,
  33. PDWORD num_hosts
  34. )
  35. {
  36. return g_WlbsControl.WlbsSuspend(cluster, host, response, num_hosts);
  37. }
  38. DWORD WINAPI WlbsResume
  39. (
  40. DWORD cluster,
  41. DWORD host,
  42. PWLBS_RESPONSE response,
  43. PDWORD num_hosts
  44. )
  45. {
  46. return g_WlbsControl.WlbsResume(cluster, host, response, num_hosts);
  47. }
  48. DWORD WINAPI WlbsStart
  49. (
  50. DWORD cluster,
  51. DWORD host,
  52. PWLBS_RESPONSE response,
  53. PDWORD num_hosts
  54. )
  55. {
  56. return g_WlbsControl.WlbsStart(cluster, host, response, num_hosts);
  57. }
  58. DWORD WINAPI WlbsStop
  59. (
  60. DWORD cluster,
  61. DWORD host,
  62. PWLBS_RESPONSE response,
  63. PDWORD num_hosts
  64. )
  65. {
  66. return g_WlbsControl.WlbsStop(cluster, host, response, num_hosts);
  67. }
  68. DWORD WINAPI WlbsDrainStop
  69. (
  70. DWORD cluster,
  71. DWORD host,
  72. PWLBS_RESPONSE response,
  73. PDWORD num_hosts
  74. )
  75. {
  76. return g_WlbsControl.WlbsDrainStop(cluster, host, response, num_hosts);
  77. }
  78. DWORD WINAPI WlbsEnable
  79. (
  80. DWORD cluster,
  81. DWORD host,
  82. PWLBS_RESPONSE response,
  83. PDWORD num_hosts,
  84. DWORD vip,
  85. DWORD port
  86. )
  87. {
  88. return g_WlbsControl.WlbsEnable(cluster, host, response, num_hosts, vip, port);
  89. }
  90. DWORD WINAPI WlbsDisable
  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.WlbsDisable(cluster, host, response, num_hosts, vip, port);
  101. }
  102. DWORD WINAPI WlbsDrain
  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.WlbsDrain(cluster, host, response, num_hosts, vip, port);
  113. }
  114. extern "C" DWORD WINAPI WlbsAdjust
  115. (
  116. DWORD cluster,
  117. DWORD host,
  118. PWLBS_RESPONSE response,
  119. PDWORD num_hosts,
  120. DWORD port,
  121. DWORD value
  122. )
  123. {
  124. return g_WlbsControl.WlbsAdjust(cluster, host, response, num_hosts, port, value);
  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);
  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. if ( lenp == NULL )
  175. return FALSE;
  176. name = gethostbyaddr ((char *) & address, sizeof (DWORD), AF_INET);
  177. if (name == NULL)
  178. {
  179. *lenp = 0;
  180. return FALSE;
  181. }
  182. len = strlen (name -> h_name) + 1;
  183. /* This is to prevent stprintf from breaking */
  184. if (*lenp > 0)
  185. {
  186. name -> h_name [*lenp - 1] = 0;
  187. #ifdef UNICODE
  188. wsprintf (buf, L"%S", name -> h_name);
  189. #else
  190. sprintf (buf, "%s", name -> h_name);
  191. #endif
  192. }
  193. if (len > *lenp)
  194. {
  195. *lenp = len;
  196. return FALSE;
  197. }
  198. *lenp = len;
  199. return TRUE;
  200. } /* end WlbsAddressToName */
  201. VOID WINAPI WlbsPortSet
  202. (
  203. DWORD cluster,
  204. WORD port
  205. )
  206. {
  207. g_WlbsControl.WlbsPortSet(cluster, port);
  208. }
  209. VOID WINAPI WlbsPasswordSet
  210. (
  211. DWORD cluster,
  212. PTCHAR password
  213. )
  214. {
  215. g_WlbsControl.WlbsPasswordSet(cluster, password);
  216. }
  217. VOID WINAPI WlbsCodeSet
  218. (
  219. DWORD cluster,
  220. DWORD passw
  221. )
  222. {
  223. g_WlbsControl.WlbsCodeSet(cluster, passw);
  224. }
  225. VOID WINAPI WlbsDestinationSet
  226. (
  227. DWORD cluster,
  228. DWORD dest
  229. )
  230. {
  231. g_WlbsControl.WlbsDestinationSet(cluster, dest);
  232. }
  233. VOID WINAPI WlbsTimeoutSet
  234. (
  235. DWORD cluster,
  236. DWORD milliseconds
  237. )
  238. {
  239. g_WlbsControl.WlbsTimeoutSet(cluster, milliseconds);
  240. }
  241. //+----------------------------------------------------------------------------
  242. //
  243. // Function: WlbsReadReg
  244. //
  245. // Description:
  246. //
  247. // Arguments: WORD cluster -
  248. // PWLBS_REG_PARAMS reg_data
  249. //
  250. // Returns: DWORD WINAPI -
  251. //
  252. // History: fengsun Created Header 3/9/00
  253. //
  254. //+----------------------------------------------------------------------------
  255. DWORD WINAPI WlbsReadReg(
  256. DWORD cluster,
  257. PWLBS_REG_PARAMS reg_data
  258. )
  259. {
  260. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  261. if(pCluster == NULL)
  262. {
  263. return WLBS_NOT_FOUND;
  264. }
  265. return pCluster->ReadConfig(reg_data);
  266. }
  267. //+----------------------------------------------------------------------------
  268. //
  269. // Function: WlbsWriteReg
  270. //
  271. // Description:
  272. //
  273. // Arguments: WORD cluster -
  274. // PWLBS_REG_PARAMS reg_data
  275. //
  276. // Returns: DWORD WINAPI -
  277. //
  278. // History: fengsun Created Header 3/9/00
  279. //
  280. //+----------------------------------------------------------------------------
  281. DWORD WINAPI WlbsWriteReg(
  282. DWORD cluster,
  283. const PWLBS_REG_PARAMS reg_data
  284. )
  285. {
  286. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  287. if(pCluster == NULL)
  288. {
  289. return WLBS_NOT_FOUND;
  290. }
  291. return pCluster->WriteConfig(reg_data);
  292. }
  293. //+----------------------------------------------------------------------------
  294. //
  295. // Function: WlbsCommitChanges
  296. //
  297. // Description:
  298. //
  299. // Arguments: DWORD cluster -
  300. //
  301. // Returns: DWORD WINAPI -
  302. //
  303. // History: fengsun Created Header 3/9/00
  304. //
  305. //+----------------------------------------------------------------------------
  306. DWORD WINAPI WlbsCommitChanges(DWORD cluster)
  307. {
  308. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  309. if(pCluster == NULL)
  310. {
  311. return WLBS_NOT_FOUND;
  312. }
  313. return pCluster->CommitChanges(&g_WlbsControl);
  314. }
  315. DWORD WINAPI WlbsSetDefaults
  316. (
  317. PWLBS_REG_PARAMS reg_data
  318. )
  319. {
  320. return ParamSetDefaults(reg_data);
  321. }
  322. BOOL WINAPI WlbsFormatMessage
  323. (
  324. DWORD, // error,
  325. WLBS_COMMAND, // command,
  326. BOOL, // cluster
  327. PTCHAR messagep,
  328. PDWORD lenp
  329. )
  330. {
  331. DWORD len;
  332. PTSTR error_str = _TEXT("Not yet implemented");
  333. #if 0
  334. va_list arglist;
  335. DWORD error;
  336. va_start(arglist, id);
  337. if (FormatMessage (FORMAT_MESSAGE_FROM_HMODULE, NULL, id, 0,
  338. message, CVY_BUF_SIZE, & arglist) == 0)
  339. {
  340. error = GetLastError();
  341. wprintf(L"Could not print error message due to: ");
  342. if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0,
  343. message, CVY_BUF_SIZE, NULL) == 0)
  344. {
  345. wprintf(L"%d\n", error);
  346. }
  347. else
  348. wprintf(L"\n %ls\n", message);
  349. }
  350. else
  351. {
  352. wprintf(L"%ls", message);
  353. }
  354. #endif
  355. len = _tcslen(error_str) + 1;
  356. /* This is to prevent stprintf from breaking */
  357. if (lenp == NULL)
  358. return FALSE;
  359. if (*lenp == 0)
  360. {
  361. *lenp = len;
  362. return FALSE;
  363. }
  364. _tcsncpy(messagep, error_str, *lenp);
  365. if (len > *lenp)
  366. {
  367. *lenp = len;
  368. return FALSE;
  369. }
  370. *lenp = len;
  371. return TRUE;
  372. } /* end WlbsFormatMessage */
  373. DWORD WINAPI WlbsEnumClusters(OUT DWORD* pdwAddresses, OUT DWORD* pdwNum)
  374. {
  375. return g_WlbsControl.EnumClusters(pdwAddresses, pdwNum);
  376. }
  377. //+----------------------------------------------------------------------------
  378. //
  379. // Function: WlbsGetAdapterGuid
  380. //
  381. // Description:
  382. //
  383. // Arguments: IN DWORD cluster -
  384. // OUT GUID* pAdapterGuid -
  385. //
  386. // Returns: DWORD WINAPI -
  387. //
  388. // History: fengsun Created Header 3/10/00
  389. //
  390. //+----------------------------------------------------------------------------
  391. DWORD WINAPI WlbsGetAdapterGuid(IN DWORD cluster, OUT GUID* pAdapterGuid)
  392. {
  393. ASSERT(pAdapterGuid);
  394. if (pAdapterGuid == NULL)
  395. {
  396. return WLBS_BAD_PARAMS;
  397. }
  398. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  399. if(pCluster == NULL)
  400. {
  401. return WLBS_NOT_FOUND;
  402. }
  403. *pAdapterGuid = pCluster->GetAdapterGuid();
  404. return WLBS_OK;
  405. }
  406. //+----------------------------------------------------------------------------
  407. //
  408. // Function: WlbsNotifyConfigChange
  409. //
  410. // Description:
  411. //
  412. // Arguments: DWORD cluster -
  413. //
  414. // Returns: DWORD WINAPI -
  415. //
  416. // History: fengsun Created Header 7/3/00
  417. //
  418. //+----------------------------------------------------------------------------
  419. DWORD WINAPI WlbsNotifyConfigChange(DWORD cluster)
  420. {
  421. CWlbsCluster* pCluster = g_WlbsControl.GetClusterFromIpOrIndex(cluster);
  422. if(pCluster == NULL)
  423. {
  424. return WLBS_NOT_FOUND;
  425. }
  426. DWORD dwStatus = NotifyDriverConfigChanges(g_WlbsControl.GetDriverHandle(), pCluster->GetAdapterGuid());
  427. return dwStatus;
  428. }