mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
small host lokup fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34629 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
566d9571f1
commit
1abad06f3a
3 changed files with 26 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
2012-01-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSSocketStream.m: fix possible nul pointer dereference.
|
||||
* Source/NSHost.m: cache failed lookup by name so that repeated
|
||||
lookups for a band host name do not cause repeated DNS queries.
|
||||
|
||||
2012-01-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSURLRequest.m: be tolerant about missing URL on init.
|
||||
|
|
|
@ -141,6 +141,10 @@ GSPrivateSockaddrSetup(NSString *machine, uint16_t port,
|
|||
n = [machine UTF8String];
|
||||
}
|
||||
|
||||
if (0 == n)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (0 == strchr(n, ':'))
|
||||
{
|
||||
struct sockaddr_in *addr = (struct sockaddr_in*)sin;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSEnumerator.h"
|
||||
#import "Foundation/NSNull.h"
|
||||
#import "Foundation/NSSet.h"
|
||||
#import "Foundation/NSCoder.h"
|
||||
|
||||
|
@ -57,6 +58,7 @@ static Class hostClass;
|
|||
static NSRecursiveLock *_hostCacheLock = nil;
|
||||
static BOOL _hostCacheEnabled = YES;
|
||||
static NSMutableDictionary *_hostCache = nil;
|
||||
static id null = nil;
|
||||
|
||||
|
||||
@interface NSHost (Private)
|
||||
|
@ -75,7 +77,7 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
[s addObject: name];
|
||||
ASSIGNCOPY(_names, s);
|
||||
RELEASE(s);
|
||||
if (_hostCacheEnabled == YES)
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
[_hostCache setObject: self forKey: name];
|
||||
}
|
||||
|
@ -91,7 +93,7 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
name = [name copy];
|
||||
_names = [[NSSet alloc] initWithObjects: &name count: 1];
|
||||
_addresses = RETAIN(_names);
|
||||
if (_hostCacheEnabled == YES)
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
[_hostCache setObject: self forKey: name];
|
||||
}
|
||||
|
@ -202,7 +204,7 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
_addresses = [addresses copy];
|
||||
RELEASE(addresses);
|
||||
|
||||
if (_hostCacheEnabled == YES)
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
[_hostCache setObject: self forKey: name];
|
||||
}
|
||||
|
@ -261,6 +263,7 @@ myHostName()
|
|||
if (self == [NSHost class])
|
||||
{
|
||||
hostClass = self;
|
||||
null = [[NSNull null] retain];
|
||||
_hostCacheLock = [[NSRecursiveLock alloc] init];
|
||||
_hostCache = [NSMutableDictionary new];
|
||||
}
|
||||
|
@ -298,7 +301,7 @@ myHostName()
|
|||
}
|
||||
|
||||
[_hostCacheLock lock];
|
||||
if (_hostCacheEnabled == YES)
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
host = [_hostCache objectForKey: name];
|
||||
}
|
||||
|
@ -332,6 +335,10 @@ myHostName()
|
|||
}
|
||||
else
|
||||
{
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
[_hostCache setObject: null forKey: name];
|
||||
}
|
||||
NSLog(@"Host '%@' not found using 'gethostbyname()' - "
|
||||
@"perhaps the hostname is wrong or networking is not "
|
||||
@"set up on your machine", name);
|
||||
|
@ -344,6 +351,10 @@ myHostName()
|
|||
}
|
||||
}
|
||||
}
|
||||
else if ((id)host == null)
|
||||
{
|
||||
host = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
IF_NO_GC([[host retain] autorelease];)
|
||||
|
@ -406,7 +417,7 @@ myHostName()
|
|||
#endif
|
||||
|
||||
[_hostCacheLock lock];
|
||||
if (_hostCacheEnabled == YES)
|
||||
if (YES == _hostCacheEnabled)
|
||||
{
|
||||
host = [_hostCache objectForKey: address];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue