version 1.74.2.1, 2009/10/20 13:21:19
|
version 1.79, 2010/10/13 14:24:46
|
|
|
| |
Boolean System::bindVerbose = false; | Boolean System::bindVerbose = false; |
| |
|
MutexType System::_mutexForGetHostName = PEGASUS_MUTEX_INITIALIZER; |
|
|
|
MutexType System::_mutexForGetFQHN = PEGASUS_MUTEX_INITIALIZER; |
|
|
Boolean System::copyFile(const char* fromPath, const char* toPath) | Boolean System::copyFile(const char* fromPath, const char* toPath) |
{ | { |
ifstream is(fromPath PEGASUS_IOS_BINARY); | ifstream is(fromPath PEGASUS_IOS_BINARY); |
|
|
String System::getHostName() | String System::getHostName() |
{ | { |
static String _hostname; | static String _hostname; |
static MutexType _mutex = PEGASUS_MUTEX_INITIALIZER; |
|
| |
// Use double-checked locking pattern to avoid overhead of | // Use double-checked locking pattern to avoid overhead of |
// mutex on subsequent calls. | // mutex on subsequent calls. |
| |
if (0 == _hostname.size()) | if (0 == _hostname.size()) |
{ | { |
mutex_lock(&_mutex); |
mutex_lock(&_mutexForGetHostName); |
| |
if (0 == _hostname.size()) | if (0 == _hostname.size()) |
{ | { |
|
|
_hostname.assign(hostname); | _hostname.assign(hostname); |
} | } |
| |
mutex_unlock(&_mutex); |
mutex_unlock(&_mutexForGetHostName); |
} | } |
| |
return _hostname; | return _hostname; |
|
|
String System::getFullyQualifiedHostName() | String System::getFullyQualifiedHostName() |
{ | { |
static String _hostname; | static String _hostname; |
static MutexType _mutex = PEGASUS_MUTEX_INITIALIZER; |
|
|
|
// Use double-checked locking pattern to avoid overhead of | // Use double-checked locking pattern to avoid overhead of |
// mutex on subsequent calls. | // mutex on subsequent calls. |
| |
if (0 == _hostname.size()) | if (0 == _hostname.size()) |
{ | { |
mutex_lock(&_mutex); |
mutex_lock(&_mutexForGetFQHN); |
| |
if (0 == _hostname.size()) | if (0 == _hostname.size()) |
{ | { |
|
|
} | } |
catch (...) | catch (...) |
{ | { |
mutex_unlock(&_mutex); |
mutex_unlock(&_mutexForGetFQHN); |
throw; | throw; |
} | } |
} | } |
| |
mutex_unlock(&_mutex); |
mutex_unlock(&_mutexForGetFQHN); |
} | } |
| |
return _hostname; | return _hostname; |
|
|
#ifdef PEGASUS_ENABLE_IPV6 | #ifdef PEGASUS_ENABLE_IPV6 |
struct in6_addr ip6 = PEGASUS_IPV6_LOOPBACK_INIT; | struct in6_addr ip6 = PEGASUS_IPV6_LOOPBACK_INIT; |
#endif | #endif |
Uint32 ip4 = PEGASUS_IPV4_LOOPBACK_INIT; |
|
switch (af) | switch (af) |
{ | { |
#ifdef PEGASUS_ENABLE_IPV6 | #ifdef PEGASUS_ENABLE_IPV6 |
|
|
Uint32 tmp; | Uint32 tmp; |
memcpy(&tmp, binIPAddress, sizeof(Uint32)); | memcpy(&tmp, binIPAddress, sizeof(Uint32)); |
Uint32 n = ntohl(tmp); | Uint32 n = ntohl(tmp); |
return !memcmp(&ip4, &n, sizeof (ip4)); |
return n >= PEGASUS_IPV4_LOOPBACK_RANGE_START && |
|
n <= PEGASUS_IPV4_LOOPBACK_RANGE_END; |
} | } |
} | } |
| |
|
|
| |
Boolean System::isLocalHost(const String &hostName) | Boolean System::isLocalHost(const String &hostName) |
{ | { |
|
// shortcut if hostname == localhost |
|
if (String::equalNoCase(hostName,String("localhost"))) return true; |
// Get all ip addresses on the node and compare them with the given hostname. | // Get all ip addresses on the node and compare them with the given hostname. |
#ifdef PEGASUS_ENABLE_IPV6 | #ifdef PEGASUS_ENABLE_IPV6 |
CString csName = hostName.getCString(); | CString csName = hostName.getCString(); |
|
|
| |
if (!hostNameIsIPNotation) // if hostname is not an IP address | if (!hostNameIsIPNotation) // if hostname is not an IP address |
{ | { |
// localhost ? |
|
if (String::equalNoCase(hostName,String("localhost"))) return true; |
|
char localHostName[PEGASUS_MAXHOSTNAMELEN]; | char localHostName[PEGASUS_MAXHOSTNAMELEN]; |
CString cstringLocalHostName = System::getHostName().getCString(); | CString cstringLocalHostName = System::getHostName().getCString(); |
strcpy(localHostName, (const char*) cstringLocalHostName); | strcpy(localHostName, (const char*) cstringLocalHostName); |
|
|
#endif | #endif |
| |
// System ID constants for Logger::put and Logger::trace | // System ID constants for Logger::put and Logger::trace |
|
#ifdef PEGASUS_FLAVOR |
|
const String System::CIMLISTENER = "cimlistener" PEGASUS_FLAVOR; |
|
#else |
const String System::CIMLISTENER = "cimlistener"; // Listener systme ID | const String System::CIMLISTENER = "cimlistener"; // Listener systme ID |
|
#endif |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |