@@ -35,10 +35,11 @@ #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFInvalidArgumentException.h" +#import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFResolveHostFailedException.h" #import "OFTruncatedDataException.h" @@ -89,11 +90,11 @@ of_dns_resource_record_type_t _recordType; OFNumber *_ID; OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains; size_t _nameServersIndex, _searchDomainsIndex; of_time_interval_t _timeout; - unsigned int _maxRetries; + unsigned int _maxAttempts; size_t _attempt; id _target; SEL _selector; id _context; OFData *_queryData; @@ -106,11 +107,11 @@ recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains timeout: (of_time_interval_t)timeout - maxRetries: (unsigned int)maxRetries + maxAttempts: (unsigned int)maxAttempts target: (id)target selector: (SEL)selector context: (id)context; @end @@ -531,11 +532,11 @@ recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains timeout: (of_time_interval_t)timeout - maxRetries: (unsigned int)maxRetries + maxAttempts: (unsigned int)maxAttempts target: (id)target selector: (SEL)selector context: (id)context { self = [super init]; @@ -551,11 +552,11 @@ _recordType = recordType; _ID = [ID retain]; _nameServers = [nameServers copy]; _searchDomains = [searchDomains copy]; _timeout = timeout; - _maxRetries = maxRetries; + _maxAttempts = maxAttempts; _target = [target retain]; _selector = selector; _context = [context retain]; queryData = [OFMutableData dataWithCapacity: 512]; @@ -636,11 +637,11 @@ @end @implementation OFDNSResolver @synthesize staticHosts = _staticHosts, nameServers = _nameServers; @synthesize localDomain = _localDomain, searchDomains = _searchDomains; -@synthesize timeout = _timeout, maxRetries = _maxRetries; +@synthesize timeout = _timeout, maxAttempts = _maxAttempts; @synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName; @synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval; + (instancetype)resolver { @@ -664,11 +665,11 @@ } - (void)of_setDefaults { _timeout = 2; - _maxRetries = 3; + _maxAttempts = 3; _minNumberOfDotsInAbsoluteName = 1; _usesTCP = false; _configReloadInterval = 2; } @@ -676,10 +677,12 @@ { void *pool = objc_autoreleasePoolPush(); #ifdef OF_WINDOWS OFString *path; #endif + + [self of_setDefaults]; #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES path = [[OFWindowsRegistryKey localMachineKey] stringForValue: @"DataBasePath" @@ -907,22 +910,36 @@ objc_autoreleasePoolPop(pool); } - (void)of_parseResolvConfOption: (OFString *)option { - if ([option hasPrefix: @"ndots:"]) { - option = [option substringWithRange: - of_range(6, [option length] - 6)]; + @try { + if ([option hasPrefix: @"ndots:"]) { + option = [option substringWithRange: + of_range(6, [option length] - 6)]; - @try { _minNumberOfDotsInAbsoluteName = (size_t)[option decimalValue]; - } @catch (id e) { - return; - } - } else if ([option isEqual: @"tcp"]) - _usesTCP = true; + } else if ([option hasPrefix: @"timeout:"]) { + option = [option substringWithRange: + of_range(8, [option length] - 8)]; + + _timeout = [option decimalValue]; + } else if ([option hasPrefix: @"attempts:"]) { + option = [option substringWithRange: + of_range(9, [option length] - 9)]; + + _maxAttempts = (unsigned int)[option decimalValue]; + } else if ([option hasPrefix: @"reload-period:"]) { + option = [option substringWithRange: + of_range(14, [option length] - 14)]; + + _configReloadInterval = [option decimalValue]; + } else if ([option isEqual: @"tcp"]) + _usesTCP = true; + } @catch (OFInvalidFormatException *e) { + } } # endif #endif #ifdef OF_WINDOWS @@ -1044,11 +1061,11 @@ recordType: recordType ID: ID nameServers: _nameServers searchDomains: _searchDomains timeout: _timeout - maxRetries: _maxRetries + maxAttempts: _maxAttempts target: target selector: selector context: context] autorelease]; [_queries setObject: query forKey: ID]; @@ -1123,11 +1140,11 @@ query->_nameServersIndex++; [self of_sendQuery: query]; return; } - if (query->_attempt < query->_maxRetries) { + if (query->_attempt < query->_maxAttempts) { query->_attempt++; query->_nameServersIndex = 0; [self of_sendQuery: query]; return; }