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.

186 lines
5.0 KiB

  1. /*
  2. * Filename: Main.cpp
  3. * Description:
  4. * Author: shouse, 04.10.01
  5. */
  6. #include <stdio.h>
  7. #include "msxml3.tlh"
  8. #include <string.h>
  9. #include "NLB_XMLDocument.h"
  10. #include <vector>
  11. #include <string>
  12. #include <map>
  13. using namespace std;
  14. void BuildNLBCluster (NLB_Cluster & Cluster) {
  15. NLB_IPAddress IPAddress;
  16. NLB_Host Host;
  17. NLB_PortRule Rule;
  18. Cluster.SetName(L"Heyfoxymophandlemama");
  19. Cluster.SetLabel(L"That's me");
  20. IPAddress.Clear();
  21. IPAddress.SetIPAddressType(NLB_IPAddress::Primary);
  22. IPAddress.SetIPAddress(L"129.237.220.105");
  23. Cluster.SetPrimaryClusterIPAddress(IPAddress);
  24. IPAddress.Clear();
  25. IPAddress.SetIPAddressType(NLB_IPAddress::Secondary);
  26. IPAddress.SetIPAddress(L"129.237.120.110");
  27. IPAddress.SetSubnetMask(L"255.255.248.0");
  28. Cluster.AddSecondaryClusterIPAddress(IPAddress);
  29. IPAddress.Clear();
  30. IPAddress.SetIPAddressType(NLB_IPAddress::Secondary);
  31. IPAddress.SetIPAddress(L"129.237.29.1");
  32. Cluster.AddSecondaryClusterIPAddress(IPAddress);
  33. Cluster.SetClusterMode(NLB_ClusterMode::Multicast);
  34. Cluster.SetMACAddress(L"03-bf-0a-0b-0c-0d");
  35. Host.SetName(L"PEZ");
  36. Host.SetDNSHostname(L"shouse-laptop.ntdev.microsoft.com");
  37. Host.SetHostID(4);
  38. IPAddress.Clear();
  39. IPAddress.SetIPAddressType(NLB_IPAddress::Dedicated);
  40. IPAddress.SetIPAddress(L"192.110.32.11");
  41. Host.SetDedicatedIPAddress(IPAddress);
  42. Cluster.AddHost(Host);
  43. Rule.SetName(L"TheWholeNineYards");
  44. Rule.SetPortRange(0, 65535);
  45. IPAddress.Clear();
  46. IPAddress.SetIPAddressType(NLB_IPAddress::Virtual);
  47. IPAddress.SetIPAddress(L"129.237.120.110");
  48. Rule.SetVirtualIPAddress(IPAddress);
  49. Rule.SetFilteringMode(NLB_PortRuleFilteringMode::Multiple);
  50. Rule.AddMultipleHostFilteringLoadWeight(L"PEZ", 65);
  51. Rule.ChangeMultipleHostFilteringLoadWeight(L"PEZ", 80);
  52. Cluster.AddPortRule(Rule);
  53. }
  54. int __cdecl wmain (int argc, WCHAR ** argv) {
  55. vector<NLB_Cluster> Clusters;
  56. WCHAR InFilename[MAX_PATH];
  57. WCHAR OutFilename[MAX_PATH];
  58. bool bValidateOnly = false;
  59. bool bCreateCluster = false;
  60. bool bParseFile = false;
  61. bool bSaveFile = false;
  62. NLB_XMLDocument * pDocument;
  63. NLB_XMLError error;
  64. NLB_Cluster myCluster;
  65. int arg;
  66. HRESULT hr = S_OK;
  67. for (arg = 1; arg < argc; arg++) {
  68. if (argv[arg][0] == L'-') {
  69. if (!lstrcmpi(argv[arg] + 1, L"in")) {
  70. arg++;
  71. wcsncpy(InFilename, argv[arg], MAX_PATH);
  72. bParseFile = true;
  73. } else if (!lstrcmpi(argv[arg] + 1, L"out")) {
  74. arg++;
  75. wcsncpy(OutFilename, argv[arg], MAX_PATH);
  76. bSaveFile = true;
  77. } else if (!lstrcmpi(argv[arg] + 1, L"create")) {
  78. bCreateCluster = true;
  79. } else if (!lstrcmpi(argv[arg] + 1, L"validate")) {
  80. bValidateOnly = true;
  81. } else {
  82. printf("Invalid argument: %ls\n", argv[arg]);
  83. goto usage;
  84. }
  85. } else {
  86. printf("Invalid argument: %ls\n", argv[arg]);
  87. goto usage;
  88. }
  89. }
  90. pDocument = new NLB_XMLDocument();
  91. if (bParseFile) {
  92. if (bValidateOnly) {
  93. printf("\nValidating %ls...\n", InFilename);
  94. hr = pDocument->Validate(InFilename);
  95. } else {
  96. printf("\nParsing %ls...\n", InFilename);
  97. hr = pDocument->Parse(InFilename, Clusters);
  98. }
  99. printf("\n");
  100. if (FAILED(hr)) {
  101. pDocument->GetParseError(error);
  102. fprintf(stderr, "Error 0x%08x:\n\n%ls\n", error.code, error.wszReason);
  103. if (error.line > 0) fprintf(stderr, "Error on line %d, position %d in \"%ls\".\n", error.line, error.character, error.wszURL);
  104. return -1;
  105. } else {
  106. fprintf(stderr, "XML document loaded successfully...\n");
  107. }
  108. pDocument->Print(Clusters);
  109. }
  110. if (bCreateCluster) {
  111. NLB_IPAddress IPAddress;
  112. BuildNLBCluster(myCluster);
  113. Clusters.push_back(myCluster);
  114. myCluster.Clear();
  115. myCluster.SetName(L"www.msn.com");
  116. myCluster.SetLabel(L"Duplicate");
  117. IPAddress.SetIPAddressType(NLB_IPAddress::Primary);
  118. IPAddress.SetIPAddress(L"10.0.0.109");
  119. myCluster.SetPrimaryClusterIPAddress(IPAddress);
  120. Clusters.push_back(myCluster);
  121. pDocument->Print(Clusters);
  122. }
  123. if (bSaveFile) pDocument->Save(OutFilename, Clusters);
  124. return 0;
  125. usage:
  126. printf("Usage: %ls [-in <XML filename>] [-out <XML filename>] [-create] [-validate]\n", argv[0]);
  127. return -1;
  128. }