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.

910 lines
15 KiB

  1. /*
  2. * Filename: NLB_Common.cpp
  3. * Description:
  4. * Author: shouse, 04.10.01
  5. */
  6. #include "NLB_Common.h"
  7. /*************************************************
  8. * Class: NLB_Label *
  9. *************************************************/
  10. /*
  11. * Method:
  12. * Description:
  13. * Author: Created by shouse, 4.26.01
  14. * Notes:
  15. */
  16. NLB_Label::NLB_Label () {
  17. Text[0] = L'\0';
  18. }
  19. /*
  20. * Method:
  21. * Description:
  22. * Author: Created by shouse, 4.26.01
  23. * Notes:
  24. */
  25. NLB_Label::~NLB_Label () {
  26. }
  27. /*
  28. * Method:
  29. * Description:
  30. * Author: Created by shouse, 4.26.01
  31. * Notes:
  32. */
  33. bool NLB_Label::IsValid () {
  34. return (Text[0] != L'\0');
  35. }
  36. /*
  37. * Method:
  38. * Description:
  39. * Author: Created by shouse, 4.26.01
  40. * Notes:
  41. */
  42. bool NLB_Label::GetText (PWSTR * outText) {
  43. *outText = SysAllocString(Text);
  44. return IsValid();
  45. }
  46. /*
  47. * Method:
  48. * Description:
  49. * Author: Created by shouse, 4.26.01
  50. * Notes:
  51. */
  52. bool NLB_Label::SetText (PWSTR inText) {
  53. if (lstrlen(inText) > NLB_MAX_LABEL) return false;
  54. lstrcpy(Text, inText);
  55. return true;
  56. }
  57. /*************************************************
  58. * Class: NLB_Name *
  59. *************************************************/
  60. /*
  61. * Method:
  62. * Description:
  63. * Author: Created by shouse, 4.26.01
  64. * Notes:
  65. */
  66. NLB_Name::NLB_Name () {
  67. Name[0] = L'\0';
  68. }
  69. /*
  70. * Method:
  71. * Description:
  72. * Author: Created by shouse, 4.26.01
  73. * Notes:
  74. */
  75. NLB_Name::~NLB_Name () {
  76. }
  77. /*
  78. * Method:
  79. * Description:
  80. * Author: Created by shouse, 4.26.01
  81. * Notes:
  82. */
  83. bool NLB_Name::IsValid () {
  84. return (Name[0] != L'\0');
  85. }
  86. /*
  87. * Method:
  88. * Description:
  89. * Author: Created by shouse, 4.26.01
  90. * Notes:
  91. */
  92. bool NLB_Name::GetName (PWSTR * outName) {
  93. *outName = SysAllocString(Name);
  94. return IsValid();
  95. }
  96. /*
  97. * Method:
  98. * Description:
  99. * Author: Created by shouse, 4.26.01
  100. * Notes:
  101. */
  102. bool NLB_Name::SetName (PWSTR inName) {
  103. if (lstrlen(inName) > NLB_MAX_NAME) return false;
  104. lstrcpy(Name, inName);
  105. return true;
  106. }
  107. /*************************************************
  108. * Class: NLB_HostID *
  109. *************************************************/
  110. /*
  111. * Method:
  112. * Description:
  113. * Author: Created by shouse, 4.26.01
  114. * Notes:
  115. */
  116. NLB_HostID::NLB_HostID () {
  117. ID = -1;
  118. }
  119. /*
  120. * Method:
  121. * Description:
  122. * Author: Created by shouse, 4.26.01
  123. * Notes:
  124. */
  125. NLB_HostID::~NLB_HostID () {
  126. }
  127. /*
  128. * Method:
  129. * Description:
  130. * Author: Created by shouse, 4.26.01
  131. * Notes:
  132. */
  133. bool NLB_HostID::IsValid () {
  134. return (ID != -1);
  135. }
  136. /*
  137. * Method:
  138. * Description:
  139. * Author: Created by shouse, 4.26.01
  140. * Notes:
  141. */
  142. bool NLB_HostID::GetID (int * outID) {
  143. *outID = ID;
  144. return IsValid();
  145. }
  146. /*
  147. * Method:
  148. * Description:
  149. * Author: Created by shouse, 4.26.01
  150. * Notes:
  151. */
  152. bool NLB_HostID::SetID (int inID) {
  153. if ((inID > NLB_MAX_HOST_ID) || (inID < NLB_MIN_HOST_ID)) return false;
  154. ID = inID;
  155. return true;
  156. }
  157. /*************************************************
  158. * Class: NLB_HostName *
  159. *************************************************/
  160. /*
  161. * Method:
  162. * Description:
  163. * Author: Created by shouse, 4.26.01
  164. * Notes:
  165. */
  166. NLB_HostName::NLB_HostName () {
  167. Name[0] = L'\0';
  168. }
  169. /*
  170. * Method:
  171. * Description:
  172. * Author: Created by shouse, 4.26.01
  173. * Notes:
  174. */
  175. NLB_HostName::~NLB_HostName () {
  176. }
  177. /*
  178. * Method:
  179. * Description:
  180. * Author: Created by shouse, 4.26.01
  181. * Notes:
  182. */
  183. bool NLB_HostName::IsValid () {
  184. return (Name[0] != L'\0');
  185. }
  186. /*
  187. * Method:
  188. * Description:
  189. * Author: Created by shouse, 4.26.01
  190. * Notes:
  191. */
  192. bool NLB_HostName::GetName (PWSTR * outName) {
  193. *outName = SysAllocString(Name);
  194. return IsValid();
  195. }
  196. /*
  197. * Method:
  198. * Description:
  199. * Author: Created by shouse, 4.26.01
  200. * Notes:
  201. */
  202. bool NLB_HostName::SetName (PWSTR inName) {
  203. if (lstrlen(inName) > NLB_MAX_HOST_NAME) return false;
  204. lstrcpy(Name, inName);
  205. return true;
  206. }
  207. /*************************************************
  208. * Class: NLB_RemoteControl *
  209. *************************************************/
  210. /*
  211. * Method:
  212. * Description:
  213. * Author: Created by shouse, 4.26.01
  214. * Notes:
  215. */
  216. NLB_RemoteControl::NLB_RemoteControl () {
  217. Enabled = Invalid;
  218. Password[0] = L'\0';
  219. }
  220. /*
  221. * Method:
  222. * Description:
  223. * Author: Created by shouse, 4.26.01
  224. * Notes:
  225. */
  226. NLB_RemoteControl::~NLB_RemoteControl () {
  227. }
  228. /*
  229. * Method:
  230. * Description:
  231. * Author: Created by shouse, 4.26.01
  232. * Notes:
  233. */
  234. bool NLB_RemoteControl::IsValid () {
  235. return (Enabled != Invalid);
  236. }
  237. /*
  238. * Method:
  239. * Description:
  240. * Author: Created by shouse, 4.26.01
  241. * Notes:
  242. */
  243. bool NLB_RemoteControl::GetEnabled (NLB_RemoteControlEnabled * outEnabled) {
  244. *outEnabled = Enabled;
  245. return IsValid();
  246. }
  247. /*
  248. * Method:
  249. * Description:
  250. * Author: Created by shouse, 4.26.01
  251. * Notes:
  252. */
  253. bool NLB_RemoteControl::GetPassword (PWSTR * outPassword) {
  254. *outPassword = SysAllocString(Password);
  255. return IsValid();
  256. }
  257. /*
  258. * Method:
  259. * Description:
  260. * Author: Created by shouse, 4.26.01
  261. * Notes:
  262. */
  263. bool NLB_RemoteControl::SetEnabled (NLB_RemoteControlEnabled inEnabled) {
  264. switch(inEnabled) {
  265. case No:
  266. Enabled = No;
  267. break;
  268. case Yes:
  269. Enabled = Yes;
  270. break;
  271. default:
  272. return false;
  273. }
  274. return true;
  275. }
  276. /*
  277. * Method:
  278. * Description:
  279. * Author: Created by shouse, 4.26.01
  280. * Notes:
  281. */
  282. bool NLB_RemoteControl::SetPassword (PWSTR inPassword) {
  283. if (lstrlen(inPassword) > NLB_MAX_PASSWORD) return false;
  284. lstrcpy(Password, inPassword);
  285. return true;
  286. }
  287. /*************************************************
  288. * Class: NLB_DomainName *
  289. *************************************************/
  290. /*
  291. * Method:
  292. * Description:
  293. * Author: Created by shouse, 4.26.01
  294. * Notes:
  295. */
  296. NLB_DomainName::NLB_DomainName () {
  297. Domain[0] = L'\0';
  298. }
  299. /*
  300. * Method:
  301. * Description:
  302. * Author: Created by shouse, 4.26.01
  303. * Notes:
  304. */
  305. NLB_DomainName::~NLB_DomainName () {
  306. }
  307. /*
  308. * Method:
  309. * Description:
  310. * Author: Created by shouse, 4.26.01
  311. * Notes:
  312. */
  313. bool NLB_DomainName::IsValid () {
  314. return (Domain[0] != L'\0');
  315. }
  316. /*
  317. * Method:
  318. * Description:
  319. * Author: Created by shouse, 4.26.01
  320. * Notes:
  321. */
  322. bool NLB_DomainName::GetDomain (PWSTR * outDomain) {
  323. *outDomain = SysAllocString(Domain);
  324. return IsValid();
  325. }
  326. /*
  327. * Method:
  328. * Description:
  329. * Author: Created by shouse, 4.26.01
  330. * Notes:
  331. */
  332. bool NLB_DomainName::SetDomain (PWSTR inDomain) {
  333. if (lstrlen(inDomain) > NLB_MAX_DOMAIN_NAME) return false;
  334. lstrcpy(Domain, inDomain);
  335. return true;
  336. }
  337. /*************************************************
  338. * Class: NLB_NetworkAddress *
  339. *************************************************/
  340. /*
  341. * Method:
  342. * Description:
  343. * Author: Created by shouse, 4.26.01
  344. * Notes:
  345. */
  346. NLB_NetworkAddress::NLB_NetworkAddress () {
  347. Address[0] = L'\0';
  348. }
  349. /*
  350. * Method:
  351. * Description:
  352. * Author: Created by shouse, 4.26.01
  353. * Notes:
  354. */
  355. NLB_NetworkAddress::~NLB_NetworkAddress () {
  356. }
  357. /*
  358. * Method:
  359. * Description:
  360. * Author: Created by shouse, 4.26.01
  361. * Notes:
  362. */
  363. bool NLB_NetworkAddress::IsValid () {
  364. return (Address[0] != L'\0');
  365. }
  366. /*
  367. * Method:
  368. * Description:
  369. * Author: Created by shouse, 4.26.01
  370. * Notes:
  371. */
  372. bool NLB_NetworkAddress::GetAddress (PWSTR * outAddress) {
  373. *outAddress = SysAllocString(Address);
  374. return IsValid();
  375. }
  376. /*
  377. * Method:
  378. * Description:
  379. * Author: Created by shouse, 4.26.01
  380. * Notes:
  381. */
  382. bool NLB_NetworkAddress::SetAddress (PWSTR inAddress) {
  383. if (lstrlen(inAddress) > NLB_MAX_NETWORK_ADDRESS) return false;
  384. lstrcpy(Address, inAddress);
  385. return true;
  386. }
  387. /*************************************************
  388. * Class: NLB_ClusterMode *
  389. *************************************************/
  390. /*
  391. * Method:
  392. * Description:
  393. * Author: Created by shouse, 4.26.01
  394. * Notes:
  395. */
  396. NLB_ClusterMode::NLB_ClusterMode () {
  397. Mode = Invalid;
  398. }
  399. /*
  400. * Method:
  401. * Description:
  402. * Author: Created by shouse, 4.26.01
  403. * Notes:
  404. */
  405. NLB_ClusterMode::~NLB_ClusterMode () {
  406. }
  407. /*
  408. * Method:
  409. * Description:
  410. * Author: Created by shouse, 4.26.01
  411. * Notes:
  412. */
  413. bool NLB_ClusterMode::IsValid () {
  414. return (Mode != Invalid);
  415. }
  416. /*
  417. * Method:
  418. * Description:
  419. * Author: Created by shouse, 4.26.01
  420. * Notes:
  421. */
  422. bool NLB_ClusterMode::GetMode (NLB_ClusterModeType * outMode) {
  423. *outMode = Mode;
  424. return IsValid();
  425. }
  426. /*
  427. * Method:
  428. * Description:
  429. * Author: Created by shouse, 4.26.01
  430. * Notes:
  431. */
  432. bool NLB_ClusterMode::SetMode (NLB_ClusterModeType inMode) {
  433. switch (inMode) {
  434. case Unicast:
  435. Mode = Unicast;
  436. break;
  437. case Multicast:
  438. Mode = Multicast;
  439. break;
  440. case IGMP:
  441. Mode = IGMP;
  442. break;
  443. default:
  444. return false;
  445. }
  446. return true;
  447. }
  448. /*************************************************
  449. * Class: NLB_HostState *
  450. *************************************************/
  451. /*
  452. * Method:
  453. * Description:
  454. * Author: Created by shouse, 4.26.01
  455. * Notes:
  456. */
  457. NLB_HostState::NLB_HostState () {
  458. State = Invalid;
  459. }
  460. /*
  461. * Method:
  462. * Description:
  463. * Author: Created by shouse, 4.26.01
  464. * Notes:
  465. */
  466. NLB_HostState::~NLB_HostState () {
  467. }
  468. /*
  469. * Method:
  470. * Description:
  471. * Author: Created by shouse, 4.26.01
  472. * Notes:
  473. */
  474. bool NLB_HostState::IsValid () {
  475. return (State != Invalid);
  476. }
  477. /*
  478. * Method:
  479. * Description:
  480. * Author: Created by shouse, 4.26.01
  481. * Notes:
  482. */
  483. bool NLB_HostState::GetState (NLB_HostStateType * outState) {
  484. *outState = State;
  485. return IsValid();
  486. }
  487. /*
  488. * Method:
  489. * Description:
  490. * Author: Created by shouse, 4.26.01
  491. * Notes:
  492. */
  493. bool NLB_HostState::SetState (NLB_HostStateType inState) {
  494. switch (inState) {
  495. case Started:
  496. State = Started;
  497. break;
  498. case Stopped:
  499. State = Stopped;
  500. break;
  501. case Suspended:
  502. State = Suspended;
  503. break;
  504. default:
  505. return false;
  506. }
  507. return true;
  508. }
  509. /*************************************************
  510. * Class: NLB_Adapter *
  511. *************************************************/
  512. /*
  513. * Method:
  514. * Description:
  515. * Author: Created by shouse, 4.26.01
  516. * Notes:
  517. */
  518. NLB_Adapter::NLB_Adapter () {
  519. IdentifiedBy = Invalid;
  520. Name[0] = L'\0';
  521. GUID[0] = L'\0';
  522. }
  523. /*
  524. * Method:
  525. * Description:
  526. * Author: Created by shouse, 4.26.01
  527. * Notes:
  528. */
  529. NLB_Adapter::~NLB_Adapter () {
  530. }
  531. /*
  532. * Method:
  533. * Description:
  534. * Author: Created by shouse, 4.26.01
  535. * Notes:
  536. */
  537. bool NLB_Adapter::IsValid () {
  538. return (IdentifiedBy != Invalid);
  539. }
  540. /*
  541. * Method:
  542. * Description:
  543. * Author: Created by shouse, 4.26.01
  544. * Notes:
  545. */
  546. bool NLB_Adapter::GetIdentifiedBy (NLB_AdapterIdentifier * outIdentifiedBy) {
  547. *outIdentifiedBy = IdentifiedBy;
  548. return IsValid();
  549. }
  550. /*
  551. * Method:
  552. * Description:
  553. * Author: Created by shouse, 4.26.01
  554. * Notes:
  555. */
  556. bool NLB_Adapter::GetAdapter (PWSTR * outAdapter) {
  557. switch(IdentifiedBy) {
  558. case ByGUID:
  559. *outAdapter = SysAllocString(GUID);
  560. break;
  561. case ByName:
  562. *outAdapter = SysAllocString(Name);
  563. break;
  564. default:
  565. *outAdapter = NULL;
  566. break;
  567. }
  568. return IsValid();
  569. }
  570. /*
  571. * Method:
  572. * Description:
  573. * Author: Created by shouse, 4.26.01
  574. * Notes:
  575. */
  576. bool NLB_Adapter::SetIdentifiedBy (NLB_AdapterIdentifier inIdentifiedBy) {
  577. switch(inIdentifiedBy) {
  578. case ByGUID:
  579. IdentifiedBy = ByGUID;
  580. break;
  581. case ByName:
  582. IdentifiedBy = ByName;
  583. break;
  584. default:
  585. return false;
  586. }
  587. return true;
  588. }
  589. /*
  590. * Method:
  591. * Description:
  592. * Author: Created by shouse, 4.26.01
  593. * Notes:
  594. */
  595. bool NLB_Adapter::SetAdapter (PWSTR inAdapter) {
  596. switch(IdentifiedBy) {
  597. case ByGUID:
  598. if (lstrlen(inAdapter) > NLB_MAX_ADAPTER_GUID) return false;
  599. lstrcpy(GUID, inAdapter);
  600. break;
  601. case ByName:
  602. if (lstrlen(inAdapter) > NLB_MAX_ADAPTER_NAME) return false;
  603. lstrcpy(Name, inAdapter);
  604. break;
  605. default:
  606. return false;
  607. }
  608. return true;
  609. }
  610. /*************************************************
  611. * Class: NLB_IPAddress *
  612. *************************************************/
  613. /*
  614. * Method:
  615. * Description:
  616. * Author: Created by shouse, 4.26.01
  617. * Notes:
  618. */
  619. NLB_IPAddress::NLB_IPAddress () {
  620. Type = Invalid;
  621. lstrcpy(IPAddress, CVY_DEF_CL_IP_ADDR);
  622. lstrcpy(SubnetMask, CVY_DEF_CL_NET_MASK);
  623. }
  624. /*
  625. * Method:
  626. * Description:
  627. * Author: Created by shouse, 4.26.01
  628. * Notes:
  629. */
  630. NLB_IPAddress::~NLB_IPAddress () {
  631. }
  632. /*
  633. * Method:
  634. * Description:
  635. * Author: Created by shouse, 4.26.01
  636. * Notes:
  637. */
  638. bool NLB_IPAddress::IsValid () {
  639. return (Type != Invalid);
  640. }
  641. /*
  642. * Method:
  643. * Description:
  644. * Author: Created by shouse, 4.26.01
  645. * Notes:
  646. */
  647. bool NLB_IPAddress::GetIPAddressType (NLB_IPAddressType * outType) {
  648. *outType = Type;
  649. return IsValid();
  650. }
  651. /*
  652. * Method:
  653. * Description:
  654. * Author: Created by shouse, 4.26.01
  655. * Notes:
  656. */
  657. bool NLB_IPAddress::GetIPAddress (PWSTR * outIPAddress) {
  658. *outIPAddress = SysAllocString(IPAddress);
  659. return IsValid();
  660. }
  661. /*
  662. * Method:
  663. * Description:
  664. * Author: Created by shouse, 4.26.01
  665. * Notes:
  666. */
  667. bool NLB_IPAddress::GetSubnetMask (PWSTR * outSubnetMask) {
  668. *outSubnetMask = SysAllocString(SubnetMask);
  669. return IsValid();
  670. }
  671. /*
  672. * Method:
  673. * Description:
  674. * Author: Created by shouse, 4.26.01
  675. * Notes:
  676. */
  677. bool NLB_IPAddress::SetIPAddressType (NLB_IPAddressType inType) {
  678. switch (inType) {
  679. case Primary:
  680. Type = Primary;
  681. break;
  682. case Secondary:
  683. Type = Secondary;
  684. break;
  685. case Virtual:
  686. Type = Virtual;
  687. break;
  688. case IGMP:
  689. Type = IGMP;
  690. break;
  691. case Dedicated:
  692. Type = Dedicated;
  693. break;
  694. case Connection:
  695. Type = Connection;
  696. break;
  697. default:
  698. return false;
  699. }
  700. return true;
  701. }
  702. /*
  703. * Method:
  704. * Description:
  705. * Author: Created by shouse, 4.26.01
  706. * Notes:
  707. */
  708. bool NLB_IPAddress::SetIPAddress (PWSTR inIPAddress) {
  709. if (lstrlen(inIPAddress) > NLB_MAX_IPADDRESS) return false;
  710. lstrcpy(IPAddress, inIPAddress);
  711. return true;
  712. }
  713. /*
  714. * Method:
  715. * Description:
  716. * Author: Created by shouse, 4.26.01
  717. * Notes:
  718. */
  719. bool NLB_IPAddress::SetSubnetMask (PWSTR inSubnetMask) {
  720. if (lstrlen(inSubnetMask) > NLB_MAX_SUBNETMASK) return false;
  721. lstrcpy(SubnetMask, inSubnetMask);
  722. return true;
  723. }
  724. /*
  725. * Method:
  726. * Description:
  727. * Author: Created by shouse, 4.26.01
  728. * Notes: Returning a pointer to a private member is voodoo, but do it anway.
  729. */
  730. NLB_Adapter * NLB_IPAddress::GetAdapter () {
  731. return &Adapter;
  732. }