[mapguide-commits] r1162 - in trunk/MgDev:
Common/MapGuideCommon/Resources Common/MapGuideCommon/Util
Server/src/Common/Manager
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue Mar 6 23:47:31 EST 2007
Author: stevedang
Date: 2007-03-06 23:47:30 -0500 (Tue, 06 Mar 2007)
New Revision: 1162
Modified:
trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
trunk/MgDev/Common/MapGuideCommon/Util/IpUtil.cpp
trunk/MgDev/Server/src/Common/Manager/ServerManager.cpp
Log:
Resolved some IP lookup issues to meet MapGuide RFC 3 - Session Affinity's requirements.
Modified: trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res 2007-03-07 01:05:59 UTC (rev 1161)
+++ trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res 2007-03-07 04:47:30 UTC (rev 1162)
@@ -197,9 +197,8 @@
MgInvalidGeometryType = The geometry type is invalid because it is not recognized.
MgInvalidHour = The hour is invalid because it must be between 0 and 23.
MgInvalidImageSizeTooBig = The requested image size exceeds the maximum.
-MgInvalidIpConfigurationForLocalMachine = The machine IP is not a local host.
-MgInvalidIpConfigurationForSiteServer = This server (%1) is configured as a site server but has a different IP address than the site server (%2).
-MgInvalidIpConfigurationForSupportServer = This server (%1) is configured as a support server but has the same IP address as the site server (%2).
+MgInvalidIpConfigurationForSiteServer = The site server (%1) must have the same IP address as this local server (%2).
+MgInvalidIpConfigurationForSupportServer = The site server (%1) must have a different IP address than this support server (%2).
MgInvalidLogType = The log type is invalid because it is not recognized.
MgInvalidMapPlotCollectionMapPlotInstruction = The map plot is invalid because it contains an unrecognized map plot instruction.
MgInvalidMicroSecond = The microsecond is invalid because it must be between 0 and 999999.
@@ -226,6 +225,7 @@
MgInvalidWebWidgetType = The web widget type is invalid because it is not recognized.
MgInvalidXmlDateTime = The Xml date time is invalid because not all of the fields were found.
MgInvalidYear = The year is invalid because it must be between 1 and 9999.
+MgMachineIpMustBeLocalHost = The machine IP address must be a local host.
MgMapCacheCleared = The Tile Service map cache has been cleared. Please increase TiledMapCacheSize in serverconfig.ini.
MgMapLayerGroupNameNotFound = The map layer group name was not found.
MgMissingClassDef = No class definition specified.
@@ -241,6 +241,7 @@
MgResourceRootPathsDifferent = The resource root paths cannot be different.
MgResourceTypesDifferent = The resource types cannot be different.
MgResourcesIdentical = The resources cannot be the same.
+MgSiteServerIpMustNotBeLocalHost = The site server IP address must not be a local host.
MgSqlReaderIdNotFound = The SQL reader ID was not found.
MgStringContainsReservedCharacters = The string cannot contain reserved characters %1
MgStringEmpty = The string cannot be empty.
Modified: trunk/MgDev/Common/MapGuideCommon/Util/IpUtil.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Util/IpUtil.cpp 2007-03-07 01:05:59 UTC (rev 1161)
+++ trunk/MgDev/Common/MapGuideCommon/Util/IpUtil.cpp 2007-03-07 04:47:30 UTC (rev 1162)
@@ -89,8 +89,8 @@
{
bool isLocalHost = false;
- if (0 == _wcsicmp(address.c_str(), L"localhost") ||
- 0 == ::wcscmp(address.c_str(), L"127.0.0.1"))
+ if (0 == ::wcscmp(address.c_str(), L"127.0.0.1")
+ || 0 == _wcsnicmp(address.c_str(), L"localhost", ::wcslen(L"localhost")))
{
isLocalHost = true;
}
@@ -117,7 +117,8 @@
HostAddressToName(address, name1, strict);
HostAddressToName(L"localhost", name2, strict);
- isLocalHost = (0 == _wcsicmp(name1.c_str(), name2.c_str()));
+ isLocalHost = (0 == _wcsnicmp(name1.c_str(), name2.c_str(),
+ ACE_MIN(name1.length(), name2.length())));
}
}
@@ -143,7 +144,8 @@
#ifdef WIN32
- // Note that on Linux, ACE_OS::gethostbyname always returns "localhost".
+ // On Windows, use ACE_OS::gethostbyname because ACE_OS::hostname may
+ // return the correct host name but not in a fully qualified form.
ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, STRING(L"")));
// This is not thread safe - requires guard.
@@ -156,8 +158,8 @@
#else
- // Note that on Windows, ACE_OS::hostname returns the correct host name
- // but not in a fully qualified form.
+ // On Linux, use ACE_OS::hostname because ACE_OS::gethostbyname may
+ // just return "localhost".
char buf[MAXHOSTNAMELEN + 1];
@@ -172,8 +174,8 @@
if (localHostName.empty())
{
- throw new MgDomainException(
- L"MgIpUtil.GetLocalHostName", __LINE__, __WFILE__, NULL, L"", NULL);
+ throw new MgDomainException(L"MgIpUtil.GetLocalHostName",
+ __LINE__, __WFILE__, NULL, L"", NULL);
}
return localHostName;
@@ -194,11 +196,11 @@
STRING MgIpUtil::GetLocalHostAddress()
{
- STRING address;
+ STRING localHostAddress;
- HostNameToAddress(L"localhost", address, true);
+ HostNameToAddress(L"localhost", localHostAddress);
- return address;
+ return localHostAddress;
}
///----------------------------------------------------------------------------
@@ -223,8 +225,8 @@
{
if (address.empty())
{
- throw new MgNullArgumentException(
- L"MgIpUtil.ValidateAddress", __LINE__, __WFILE__, NULL, L"", NULL);
+ throw new MgNullArgumentException(L"MgIpUtil.ValidateAddress",
+ __LINE__, __WFILE__, NULL, L"", NULL);
}
if (STRING::npos != address.rfind(L':'))
@@ -237,7 +239,8 @@
whyArguments.Add(L":");
throw new MgInvalidArgumentException(L"MgIpUtil.ValidateAddress",
- __LINE__, __WFILE__, &arguments, L"MgStringContainsReservedCharacters", &whyArguments);
+ __LINE__, __WFILE__, &arguments,
+ L"MgStringContainsReservedCharacters", &whyArguments);
}
if (strict)
@@ -250,8 +253,7 @@
MgStringCollection arguments;
arguments.Add(address);
- throw new MgInvalidIpAddressException(
- L"MgIpUtil.ValidateAddress",
+ throw new MgInvalidIpAddressException(L"MgIpUtil.ValidateAddress",
__LINE__, __WFILE__, &arguments, L"", NULL);
}
}
@@ -300,10 +302,8 @@
// Note that the following code still works even if the input parameter is
// an IP address instead of a host name.
- // There is some ACE bug where on Linux the local host can NOT be converted
- // to its real IP address. Here is the workaround on Linux: If the input is
- // "127.0.0.1", "localhost" or "localhost.localdomain", the output will be
- // a fully qualified domain name.
+ // It converts "127.0.0.1", "localhost" or "localhost.localdomain" to
+ // the actual IP address if DNS entries are set up correctly.
ACE_INET_Addr inetAddr;
@@ -345,8 +345,7 @@
MgStringCollection arguments;
arguments.Add(name);
- throw new MgInvalidIpAddressException(
- L"MgIpUtil.HostNameToAddress",
+ throw new MgInvalidIpAddressException(L"MgIpUtil.HostNameToAddress",
__LINE__, __WFILE__, &arguments, L"", NULL);
}
else
@@ -388,10 +387,21 @@
bool MgIpUtil::HostAddressToName(CREFSTRING address, REFSTRING name,
bool strict)
{
+ // No conversion is needed if the input parameter already contains a host name.
+
+ if (!IsIpAddress(address, false) && !IsLocalHost(address, false))
+ {
+ name = address;
+
+ ValidateAddress(name, strict);
+
+ return true;
+ }
+
// Note that the following code still works even if the input parameter is
// a host name instead of an IP address.
- // It also converts "127.0.0.1", "localhost" or "localhost.localdomain" to
- // the real IP address if necessary.
+ // It converts "127.0.0.1", "localhost" or "localhost.localdomain" to
+ // the actual host name if DNS entries are set up correctly.
ACE_INET_Addr inetAddr;
@@ -423,8 +433,7 @@
MgStringCollection arguments;
arguments.Add(address);
- throw new MgInvalidIpAddressException(
- L"MgIpUtil.HostAddressToName",
+ throw new MgInvalidIpAddressException(L"MgIpUtil.HostAddressToName",
__LINE__, __WFILE__, &arguments, L"", NULL);
}
else
Modified: trunk/MgDev/Server/src/Common/Manager/ServerManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/ServerManager.cpp 2007-03-07 01:05:59 UTC (rev 1161)
+++ trunk/MgDev/Server/src/Common/Manager/ServerManager.cpp 2007-03-07 04:47:30 UTC (rev 1162)
@@ -153,53 +153,56 @@
pConfiguration->GetIntValue(MgConfigProperties::ClientConnectionPropertiesSection, MgConfigProperties::ClientConnectionPropertyThreadPoolSize, m_nClientThreads, MgConfigProperties::DefaultClientConnectionPropertyThreadPoolSize);
// Site Connection
- STRING siteServerAddress;
-
- pConfiguration->GetStringValue(
- MgConfigProperties::SiteConnectionPropertiesSection,
- MgConfigProperties::SiteConnectionPropertyIpAddress,
- siteServerAddress,
- MgConfigProperties::DefaultSiteConnectionPropertyIpAddress);
pConfiguration->GetIntValue(MgConfigProperties::SiteConnectionPropertiesSection, MgConfigProperties::SiteConnectionPropertyPort, m_nSitePort, MgConfigProperties::DefaultSiteConnectionPropertyPort);
pConfiguration->GetIntValue(MgConfigProperties::SiteConnectionPropertiesSection, MgConfigProperties::SiteConnectionPropertyThreadPoolSize, m_nSiteThreads, MgConfigProperties::DefaultSiteConnectionPropertyThreadPoolSize);
- MgIpUtil::HostNameToAddress(siteServerAddress, m_siteServerAddress);
-
// Validate IP configurations for this server.
- STRING localServerAddress, hostAddress;
+ STRING localServerAddress, siteServerAddress;
pConfiguration->GetStringValue(
MgConfigProperties::GeneralPropertiesSection,
MgConfigProperties::GeneralPropertyMachineIp,
localServerAddress,
MgConfigProperties::DefaultGeneralPropertyMachineIp);
+ pConfiguration->GetStringValue(
+ MgConfigProperties::SiteConnectionPropertiesSection,
+ MgConfigProperties::SiteConnectionPropertyIpAddress,
+ siteServerAddress,
+ MgConfigProperties::DefaultSiteConnectionPropertyIpAddress);
- if (m_isSiteServer && MgIpUtil::IsLocalHost(localServerAddress, false))
- {
- localServerAddress = siteServerAddress;
- }
-
MgIpUtil::HostNameToAddress(localServerAddress, m_localServerAddress);
+ MgIpUtil::HostNameToAddress(siteServerAddress, m_siteServerAddress);
- if (MgIpUtil::HostNameToAddress(L"localhost", hostAddress, false)
- && (MgIpUtil::IsIpAddress(hostAddress, false) == MgIpUtil::IsIpAddress(m_localServerAddress, false))
- && (0 != MgIpUtil::CompareAddresses(hostAddress, m_localServerAddress)))
+ STRING localHostAddress = MgIpUtil::GetLocalHostAddress();
+
+ if (!MgIpUtil::IsLocalHost(localHostAddress, false)
+ && !MgIpUtil::IsLocalHost(m_localServerAddress, false)
+ && (0 != _wcsicmp(localHostAddress.c_str(), m_localServerAddress.c_str())))
{
MgStringCollection arguments;
arguments.Add(localServerAddress);
throw new MgInvalidIpAddressException(
L"MgServerManager.Initialize", __LINE__, __WFILE__, &arguments,
- L"MgInvalidIpConfigurationForLocalMachine", NULL);
+ L"MgMachineIpMustBeLocalHost", NULL);
}
-
+
if (m_isSiteServer)
{
- if (0 != MgIpUtil::CompareAddresses(m_siteServerAddress, m_localServerAddress))
+ if (MgIpUtil::IsLocalHost(m_localServerAddress, false))
{
+ m_localServerAddress = m_siteServerAddress;
+ }
+ else if (MgIpUtil::IsLocalHost(m_siteServerAddress, false))
+ {
+ m_siteServerAddress = m_localServerAddress;
+ }
+
+ if (0 != _wcsicmp(m_siteServerAddress.c_str(), m_localServerAddress.c_str()))
+ {
MgStringCollection arguments;
+ arguments.Add(siteServerAddress);
arguments.Add(localServerAddress);
- arguments.Add(siteServerAddress);
throw new MgLogicException(
L"MgServerManager.Initialize", __LINE__, __WFILE__, NULL,
@@ -208,12 +211,22 @@
}
else
{
- if (0 == MgIpUtil::CompareAddresses(m_siteServerAddress, m_localServerAddress))
+ if (MgIpUtil::IsLocalHost(siteServerAddress))
{
MgStringCollection arguments;
- arguments.Add(localServerAddress);
arguments.Add(siteServerAddress);
+ throw new MgInvalidIpAddressException(
+ L"MgServerManager.Initialize", __LINE__, __WFILE__, &arguments,
+ L"MgSiteServerIpMustNotBeLocalHost", NULL);
+ }
+
+ if (0 == _wcsicmp(m_siteServerAddress.c_str(), m_localServerAddress.c_str()))
+ {
+ MgStringCollection arguments;
+ arguments.Add(siteServerAddress);
+ arguments.Add(localServerAddress);
+
throw new MgLogicException(
L"MgServerManager.Initialize", __LINE__, __WFILE__, NULL,
L"MgInvalidIpConfigurationForSupportServer", &arguments);
More information about the mapguide-commits
mailing list