Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -133,11 +133,11 @@ OFINICategory.m \ OFINIFile.m \ OFSettings.m \ OFString+PathAdditions.m SRCS_PLUGINS = OFPlugin.m -SRCS_SOCKETS = OFDNSRequest.m \ +SRCS_SOCKETS = OFDNSQuery.m \ OFDNSResolver.m \ OFDNSResourceRecord.m \ OFDNSResponse.m \ OFHTTPClient.m \ OFHTTPCookie.m \ ADDED src/OFDNSQuery.h Index: src/OFDNSQuery.h ================================================================== --- src/OFDNSQuery.h +++ src/OFDNSQuery.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFObject.h" +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/*! + * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h + * + * @brief A class representing a DNS query. + */ +@interface OFDNSQuery: OFObject +{ + OFString *_host; + of_dns_resource_record_class_t _recordClass; + of_dns_resource_record_type_t _recordType; + OF_RESERVE_IVARS(4) +} + +/*! + * @brief The host to resolve. + */ +@property (readonly, nonatomic) OFString *host; + +/*! + * @brief The record class of the query. + */ +@property (readonly, nonatomic) of_dns_resource_record_class_t recordClass; + +/*! + * @brief The record type of the query. + */ +@property (readonly, nonatomic) of_dns_resource_record_type_t recordType; + +/*! + * @brief Creates a new, autoreleased OFDNSQuery with IN class and type ALL. + * + * @param host The host to resolve + * @return A new, autoreleased OFDNSQuery + */ ++ (instancetype)queryWithHost: (OFString *)host; + +/*! + * @brief Creates a new, autoreleased OFDNSQuery. + * + * @param host The host to resolve + * @param recordClass The record class of the query + * @param recordType The record type of the query + * @return A new, autoreleased OFDNSQuery + */ ++ (instancetype)queryWithHost: (OFString *)host + recordClass: (of_dns_resource_record_class_t)recordClass + recordType: (of_dns_resource_record_type_t)recordType; + +/*! + * @brief Initializes an already allocated OFDNSQuery with IN class and type + * ALL. + * + * @param host The host to resolve + * @return An initialized OFDNSQuery + */ +- (instancetype)initWithHost: (OFString *)host; + +/*! + * @brief Initializes an already allocated OFDNSQuery. + * + * @param host The host to resolve + * @param recordClass The record class of the query + * @param recordType The record type of the query + * @return An initialized OFDNSQuery + */ +- (instancetype)initWithHost: (OFString *)host + recordClass: (of_dns_resource_record_class_t)recordClass + recordType: (of_dns_resource_record_type_t)recordType + OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFDNSQuery.m Index: src/OFDNSQuery.m ================================================================== --- src/OFDNSQuery.m +++ src/OFDNSQuery.m @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFDNSQuery.h" +#import "OFString.h" + +@implementation OFDNSQuery +@synthesize host = _host, recordClass = _recordClass, recordType = _recordType; + ++ (instancetype)queryWithHost: (OFString *)host +{ + return [[[self alloc] initWithHost: host] autorelease]; +} + ++ (instancetype)queryWithHost: (OFString *)host + recordClass: (of_dns_resource_record_class_t)recordClass + recordType: (of_dns_resource_record_type_t)recordType +{ + return [[[self alloc] initWithHost: host + recordClass: recordClass + recordType: recordType] autorelease]; +} + +- (instancetype)initWithHost: (OFString *)host +{ + return [self initWithHost: host + recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN + recordType: OF_DNS_RESOURCE_RECORD_TYPE_ALL]; +} + +- (instancetype)initWithHost: (OFString *)host + recordClass: (of_dns_resource_record_class_t)recordClass + recordType: (of_dns_resource_record_type_t)recordType +{ + self = [super init]; + + @try { + _host = [host copy]; + _recordClass = recordClass; + _recordType = recordType; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_host release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFDNSQuery *query; + + if (![object isKindOfClass: [OFDNSQuery class]]) + return false; + + query = object; + + if (query->_host != _host && ![query->_host isEqual: _host]) + return false; + if (query->_recordClass != _recordClass) + return false; + if (query->_recordType != _recordType) + return false; + + return true; +} + +- (uint32_t)hash +{ + uint32_t hash; + + OF_HASH_INIT(hash); + OF_HASH_ADD_HASH(hash, _host.hash); + OF_HASH_ADD(hash, _recordClass); + OF_HASH_ADD(hash, _recordType); + OF_HASH_FINALIZE(hash); + + return hash; +} + +- (id)copy +{ + return [self retain]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: @"<%@ %@ %@ %@>", + self.className, _host, + of_dns_resource_record_class_to_string(_recordClass), + of_dns_resource_record_type_to_string(_recordType)]; +} +@end DELETED src/OFDNSRequest.h Index: src/OFDNSRequest.h ================================================================== --- src/OFDNSRequest.h +++ src/OFDNSRequest.h @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFObject.h" -#import "OFDNSResourceRecord.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! - * @class OFDNSRequest OFDNSRequest.h ObjFW/OFDNSRequest.h - * - * @brief A class representing a DNS request. - */ -@interface OFDNSRequest: OFObject -{ - OFString *_host; - of_dns_resource_record_class_t _recordClass; - of_dns_resource_record_type_t _recordType; - OF_RESERVE_IVARS(4) -} - -/*! - * @brief The host to resolve. - */ -@property (readonly, nonatomic) OFString *host; - -/*! - * @brief The requested record class. - */ -@property (readonly, nonatomic) of_dns_resource_record_class_t recordClass; - -/*! - * @brief The requested record type. - */ -@property (readonly, nonatomic) of_dns_resource_record_type_t recordType; - -/*! - * @brief Creates a new, autoreleased OFDNSRequest with IN class and type ALL. - * - * @param host The host to resolve - * @return A new, autoreleased OFDNSRequest. - */ -+ (instancetype)requestWithHost: (OFString *)host; - -/*! - * @brief Creates a new, autoreleased OFDNSRequest. - * - * @param host The host to resolve - * @param recordClass The requested record class - * @param recordType The requested record type - * @return A new, autoreleased OFDNSRequest. - */ -+ (instancetype)requestWithHost: (OFString *)host - recordClass: (of_dns_resource_record_class_t)recordClass - recordType: (of_dns_resource_record_type_t)recordType; - -/*! - * @brief Initializes an already allocated OFDNSRequest with IN class and type - * ALL. - * - * @param host The host to resolve - * @return An initialized OFDNSRequest - */ -- (instancetype)initWithHost: (OFString *)host; - -/*! - * @brief Initializes an already allocated OFDNSRequest. - * - * @param host The host to resolve - * @param recordClass The requested record class - * @param recordType The requested record type - * @return An initialized OFDNSRequest - */ -- (instancetype)initWithHost: (OFString *)host - recordClass: (of_dns_resource_record_class_t)recordClass - recordType: (of_dns_resource_record_type_t)recordType - OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFDNSRequest.m Index: src/OFDNSRequest.m ================================================================== --- src/OFDNSRequest.m +++ src/OFDNSRequest.m @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFDNSRequest.h" -#import "OFString.h" - -@implementation OFDNSRequest -@synthesize host = _host, recordClass = _recordClass, recordType = _recordType; - -+ (instancetype)requestWithHost: (OFString *)host -{ - return [[[self alloc] initWithHost: host] autorelease]; -} - -+ (instancetype)requestWithHost: (OFString *)host - recordClass: (of_dns_resource_record_class_t)recordClass - recordType: (of_dns_resource_record_type_t)recordType -{ - return [[[self alloc] initWithHost: host - recordClass: recordClass - recordType: recordType] autorelease]; -} - -- (instancetype)initWithHost: (OFString *)host -{ - return [self initWithHost: host - recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN - recordType: OF_DNS_RESOURCE_RECORD_TYPE_ALL]; -} - -- (instancetype)initWithHost: (OFString *)host - recordClass: (of_dns_resource_record_class_t)recordClass - recordType: (of_dns_resource_record_type_t)recordType -{ - self = [super init]; - - @try { - _host = [host copy]; - _recordClass = recordClass; - _recordType = recordType; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_host release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFDNSRequest *request; - - if (![object isKindOfClass: [OFDNSRequest class]]) - return false; - - request = object; - - if (request->_host != _host && ![request->_host isEqual: _host]) - return false; - if (request->_recordClass != _recordClass) - return false; - if (request->_recordType != _recordType) - return false; - - return true; -} - -- (uint32_t)hash -{ - uint32_t hash; - - OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, _host.hash); - OF_HASH_ADD(hash, _recordClass); - OF_HASH_ADD(hash, _recordType); - OF_HASH_FINALIZE(hash); - - return hash; -} - -- (id)copy -{ - return [self retain]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"<%@ %@ %@ %@>", - self.className, _host, - of_dns_resource_record_class_to_string(_recordClass), - of_dns_resource_record_type_to_string(_recordType)]; -} -@end Index: src/OFDNSResolver.h ================================================================== --- src/OFDNSResolver.h +++ src/OFDNSResolver.h @@ -14,11 +14,11 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFDNSRequest.h" +#import "OFDNSQuery.h" #import "OFDNSResourceRecord.h" #import "OFDNSResponse.h" #import "OFRunLoop.h" #import "OFString.h" @@ -191,28 +191,28 @@ * @brief Initializes an already allocated OFDNSResolver. */ - (instancetype)init; /*! - * @brief Asynchronously performs the specified request. + * @brief Asynchronously performs the specified query. * - * @param request The request to perform + * @param query The query to perform * @param delegate The delegate to use for callbacks */ -- (void)asyncPerformRequest: (OFDNSRequest *)request - delegate: (id )delegate; +- (void)asyncPerformQuery: (OFDNSQuery *)query + delegate: (id )delegate; /*! - * @brief Asynchronously performs the specified request. + * @brief Asynchronously performs the specified query. * - * @param request The request to perform + * @param query The query to perform * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ -- (void)asyncPerformRequest: (OFDNSRequest *)request - runLoopMode: (of_run_loop_mode_t)runLoopMode - delegate: (id )delegate; +- (void)asyncPerformQuery: (OFDNSQuery *)query + runLoopMode: (of_run_loop_mode_t)runLoopMode + delegate: (id )delegate; /*! * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve @@ -260,11 +260,11 @@ - (OFData *)resolveSocketAddressesForHost: (OFString *)host addressFamily: (of_socket_address_family_t) addressFamily; /*! - * @brief Closes all sockets and cancels all ongoing requests. + * @brief Closes all sockets and cancels all ongoing queries. */ - (void)close; @end OF_ASSUME_NONNULL_END Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -19,11 +19,11 @@ #include #import "OFDNSResolver.h" #import "OFArray.h" -#import "OFDNSRequest.h" +#import "OFDNSQuery.h" #import "OFDNSResolverSettings.h" #import "OFDNSResponse.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" @@ -32,11 +32,11 @@ #import "OFString.h" #import "OFTimer.h" #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" -#import "OFDNSRequestFailedException.h" +#import "OFDNSQueryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOutOfRangeException.h" @@ -68,11 +68,11 @@ @"of_dns_resolver_resolve_mode"; @interface OFDNSResolverQuery: OFObject { @public - OFDNSRequest *_request; + OFDNSQuery *_query; OFString *_domainName; OFNumber *_ID; OFDNSResolverSettings *_settings; size_t _nameServersIndex, _searchDomainsIndex; unsigned int _attempt; @@ -82,19 +82,19 @@ OFData *_queryData; of_socket_address_t _usedNameServer; OFTimer *_cancelTimer; } -- (instancetype)initWithRequest: (OFDNSRequest *)request - domainName: (OFString *)domainName - ID: (OFNumber *)ID - settings: (OFDNSResolverSettings *)settings - nameServersIndex: (size_t)nameServersIndex - searchDomainsIndex: (size_t)searchDomainsIndex - target: (id)target - selector: (SEL)selector - context: (id)context; +- (instancetype)initWithQuery: (OFDNSQuery *)query + domainName: (OFString *)domainName + ID: (OFNumber *)ID + settings: (OFDNSResolverSettings *)settings + nameServersIndex: (size_t)nameServersIndex + searchDomainsIndex: (size_t)searchDomainsIndex + target: (id)target + selector: (SEL)selector + context: (id)context; @end @interface OFDNSResolverAsyncResolveSocketAddressesContext: OFObject { OFString *_host; @@ -140,18 +140,18 @@ id _exception; } @end @interface OFDNSResolver () -- (void)of_asyncPerformRequest: (OFDNSRequest *)request - settings: (OFDNSResolverSettings *)settings - nameServersIndex: (size_t)nameServersIndex - searchDomainsIndex: (size_t)searchDomainsIndex - runLoopMode: (of_run_loop_mode_t)runLoopMode - target: (id)target - selector: (SEL)selector - context: (id)context; +- (void)of_asyncPerformQuery: (OFDNSQuery *)query + settings: (OFDNSResolverSettings *)settings + nameServersIndex: (size_t)nameServersIndex + searchDomainsIndex: (size_t)searchDomainsIndex + runLoopMode: (of_run_loop_mode_t)runLoopMode + target: (id)target + selector: (SEL)selector + context: (id)context; - (void)of_sendQuery: (OFDNSResolverQuery *)query runLoopMode: (of_run_loop_mode_t)runLoopMode; - (void)of_queryWithIDTimedOut: (OFDNSResolverQuery *)query; @end @@ -548,28 +548,28 @@ method(target, selector, resolver, domainName, response, context, exception); } @implementation OFDNSResolverQuery -- (instancetype)initWithRequest: (OFDNSRequest *)request - domainName: (OFString *)domainName - ID: (OFNumber *)ID - settings: (OFDNSResolverSettings *)settings - nameServersIndex: (size_t)nameServersIndex - searchDomainsIndex: (size_t)searchDomainsIndex - target: (id)target - selector: (SEL)selector - context: (id)context +- (instancetype)initWithQuery: (OFDNSQuery *)query + domainName: (OFString *)domainName + ID: (OFNumber *)ID + settings: (OFDNSResolverSettings *)settings + nameServersIndex: (size_t)nameServersIndex + searchDomainsIndex: (size_t)searchDomainsIndex + target: (id)target + selector: (SEL)selector + context: (id)context { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *queryData; uint16_t tmp; - _request = [request copy]; + _query = [query copy]; _domainName = [domainName copy]; _ID = [ID retain]; _settings = [settings copy]; _nameServersIndex = nameServersIndex; _searchDomainsIndex = searchDomainsIndex; @@ -614,16 +614,16 @@ [queryData addItems: component.UTF8String count: length]; } /* QTYPE */ - tmp = OF_BSWAP16_IF_LE(_request.recordType); + tmp = OF_BSWAP16_IF_LE(_query.recordType); [queryData addItems: &tmp count: 2]; /* QCLASS */ - tmp = OF_BSWAP16_IF_LE(_request.recordClass); + tmp = OF_BSWAP16_IF_LE(_query.recordClass); [queryData addItems: &tmp count: 2]; [queryData makeImmutable]; @@ -638,11 +638,11 @@ return self; } - (void)dealloc { - [_request release]; + [_query release]; [_domainName release]; [_ID release]; [_settings release]; [_target release]; [_context release]; @@ -741,32 +741,32 @@ if (!found) { of_run_loop_mode_t runLoopMode = [OFRunLoop currentRunLoop].currentMode; OFNumber *recordTypeNumber = [OFNumber numberWithInt: recordType]; - OFDNSRequest *request; + OFDNSQuery *query; _expectedResponses++; [result addObject: [OFPair pairWithFirstObject: CNAME secondObject: recordTypeNumber]]; - request = [OFDNSRequest - requestWithHost: alias - recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN - recordType: recordType]; - [_resolver of_asyncPerformRequest: request - settings: nil - nameServersIndex: 0 - searchDomainsIndex: 0 - runLoopMode: runLoopMode - target: self - selector: @selector(resolver: - didResolveCNAME:response: - context:exception:) - context: recordTypeNumber]; + query = [OFDNSQuery + queryWithHost: alias + recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN + recordType: recordType]; + [_resolver of_asyncPerformQuery: query + settings: nil + nameServersIndex: 0 + searchDomainsIndex: 0 + runLoopMode: runLoopMode + target: self + selector: @selector(resolver: + didResolveCNAME:response: + context:exception:) + context: recordTypeNumber]; } } - (void)resolver: (OFDNSResolver *)resolver didResolveCNAME: (OFString *)CNAME @@ -862,18 +862,18 @@ } [addresses makeImmutable]; if (addresses.count == 0) { - OFDNSRequest *request = [OFDNSRequest - requestWithHost: _host - recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN - recordType: 0]; - - exception = [OFDNSRequestFailedException - exceptionWithRequest: request - error: OF_DNS_RESOLVER_ERROR_UNKNOWN]; + OFDNSQuery *query = [OFDNSQuery + queryWithHost: _host + recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN + recordType: 0]; + + exception = [OFDNSQueryFailedException + exceptionWithQuery: query + error: OF_DNS_RESOLVER_ERROR_UNKNOWN]; } if ([_delegate respondsToSelector: @selector( resolver:didResolveDomainName:socketAddresses:exception:)]) [_delegate resolver: _resolver @@ -902,11 +902,11 @@ _expectedResponses--; if (_domainName != nil) { if (![domainName isEqual: _domainName]) - /* Did the config change between requests? */ + /* Did the config change in between? */ return; } else _domainName = [domainName copy]; if (exception != nil) { @@ -1089,23 +1089,23 @@ - (void)setConfigReloadInterval: (of_time_interval_t)configReloadInterval { _settings->_configReloadInterval = configReloadInterval; } -- (void)of_asyncPerformRequest: (OFDNSRequest *)request - settings: (OFDNSResolverSettings *)settings - nameServersIndex: (size_t)nameServersIndex - searchDomainsIndex: (size_t)searchDomainsIndex - runLoopMode: (of_run_loop_mode_t)runLoopMode - target: (id)target - selector: (SEL)selector - context: (id)context +- (void)of_asyncPerformQuery: (OFDNSQuery *)query + settings: (OFDNSResolverSettings *)settings + nameServersIndex: (size_t)nameServersIndex + searchDomainsIndex: (size_t)searchDomainsIndex + runLoopMode: (of_run_loop_mode_t)runLoopMode + target: (id)target + selector: (SEL)selector + context: (id)context { void *pool = objc_autoreleasePoolPush(); OFNumber *ID; OFString *host, *domainName; - OFDNSResolverQuery *query; + OFDNSResolverQuery *resolverQuery; if (settings == nil) { [_settings reload]; settings = _settings; } @@ -1113,11 +1113,11 @@ /* Random, unused ID */ do { ID = [OFNumber numberWithUInt16: (uint16_t)of_random()]; } while ([_queries objectForKey: ID] != nil); - host = request.host; + host = query.host; if (isFQDN(host, settings)) { domainName = host; if (![domainName hasSuffix: @"."]) domainName = [domainName stringByAppendingString: @"."]; @@ -1130,24 +1130,24 @@ } if (domainName.UTF8StringLength > 253) @throw [OFOutOfRangeException exception]; - query = [[[OFDNSResolverQuery alloc] - initWithRequest: request - domainName: domainName - ID: ID - settings: settings - nameServersIndex: nameServersIndex - searchDomainsIndex: searchDomainsIndex - target: target - selector: selector - context: context] autorelease]; - [_queries setObject: query + resolverQuery = [[[OFDNSResolverQuery alloc] + initWithQuery: query + domainName: domainName + ID: ID + settings: settings + nameServersIndex: nameServersIndex + searchDomainsIndex: searchDomainsIndex + target: target + selector: selector + context: context] autorelease]; + [_queries setObject: resolverQuery forKey: ID]; - [self of_sendQuery: query + [self of_sendQuery: resolverQuery runLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } @@ -1163,39 +1163,37 @@ didResolveDomainName: domainName response: response exception: exception]; } -- (void)asyncPerformRequest: (OFDNSRequest *)request - delegate: (id )delegate -{ - [self of_asyncPerformRequest: request - settings: nil - nameServersIndex: 0 - searchDomainsIndex: 0 - runLoopMode: of_run_loop_mode_default - target: self - selector: @selector(of_resolver: - didResolveDomainName:response:context: - exception:) - context: delegate]; -} - -- (void)asyncPerformRequest: (OFDNSRequest *)request - runLoopMode: (of_run_loop_mode_t)runLoopMode - delegate: (id )delegate -{ - [self of_asyncPerformRequest: request - settings: nil - nameServersIndex: 0 - searchDomainsIndex: 0 - runLoopMode: runLoopMode - target: self - selector: @selector(of_resolver: - didResolveDomainName:response:context: - exception:) - context: delegate]; +- (void)asyncPerformQuery: (OFDNSQuery *)query + delegate: (id )delegate +{ + [self of_asyncPerformQuery: query + settings: nil + nameServersIndex: 0 + searchDomainsIndex: 0 + runLoopMode: of_run_loop_mode_default + target: self + selector: @selector(of_resolver:didResolveDomainName: + response:context:exception:) + context: delegate]; +} + +- (void)asyncPerformQuery: (OFDNSQuery *)query + runLoopMode: (of_run_loop_mode_t)runLoopMode + delegate: (id )delegate +{ + [self of_asyncPerformQuery: query + settings: nil + nameServersIndex: 0 + searchDomainsIndex: 0 + runLoopMode: runLoopMode + target: self + selector: @selector(of_resolver:didResolveDomainName: + response:context:exception:) + context: delegate]; } - (void)of_sendQuery: (OFDNSResolverQuery *)query runLoopMode: (of_run_loop_mode_t)runLoopMode { @@ -1264,11 +1262,11 @@ runLoopMode: runLoopMode]; } - (void)of_queryWithIDTimedOut: (OFDNSResolverQuery *)query { - OFDNSRequestFailedException *exception; + OFDNSQueryFailedException *exception; if (query == nil) return; if (query->_nameServersIndex + 1 < @@ -1289,11 +1287,11 @@ query = [[query retain] autorelease]; [_queries removeObjectForKey: query->_ID]; /* - * Cancel any pending requests, to avoid a send being still pending and + * Cancel any pending queries, to avoid a send being still pending and * trying to access the query once it no longer exists. */ [_IPv4Socket cancelAsyncRequests]; [_IPv4Socket asyncReceiveIntoBuffer: _buffer length: BUFFER_LENGTH]; @@ -1301,13 +1299,13 @@ [_IPv6Socket cancelAsyncRequests]; [_IPv6Socket asyncReceiveIntoBuffer: _buffer length: BUFFER_LENGTH]; #endif - exception = [OFDNSRequestFailedException - exceptionWithRequest: query->_request - error: OF_DNS_RESOLVER_ERROR_TIMEOUT]; + exception = [OFDNSQueryFailedException + exceptionWithQuery: query->_query + error: OF_DNS_RESOLVER_ERROR_TIMEOUT]; callback(query->_target, query->_selector, self, query->_domainName, nil, query->_context, exception); } @@ -1393,18 +1391,18 @@ size_t searchDomainsIndex = query->_searchDomainsIndex; query->_searchDomainsIndex++; - [self of_asyncPerformRequest: query->_request - settings: query->_settings - nameServersIndex: nameServersIndex - searchDomainsIndex: searchDomainsIndex - runLoopMode: runLoopMode - target: query->_target - selector: query->_selector - context: query->_context]; + [self of_asyncPerformQuery: query->_query + settings: query->_settings + nameServersIndex: nameServersIndex + searchDomainsIndex: searchDomainsIndex + runLoopMode: runLoopMode + target: query->_target + selector: query->_selector + context: query->_context]; return true; } error = OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR; @@ -1419,13 +1417,13 @@ error = OF_DNS_RESOLVER_ERROR_UNKNOWN; break; } if (buffer[3] & 0x0F) - @throw [OFDNSRequestFailedException - exceptionWithRequest: query->_request - error: error]; + @throw [OFDNSQueryFailedException + exceptionWithQuery: query->_query + error: error]; numQuestions = (buffer[4] << 8) | buffer[5]; numAnswers = (buffer[6] << 8) | buffer[7]; numAuthorityRecords = (buffer[8] << 8) | buffer[9]; numAdditionalRecords = (buffer[10] << 8) | buffer[11]; @@ -1577,18 +1575,18 @@ if (exception == nil) { of_dns_resource_record_class_t recordClass = OF_DNS_RESOURCE_RECORD_CLASS_IN; of_dns_resolver_error_t error = OF_DNS_RESOLVER_ERROR_NO_RESULT; - OFDNSRequest *request = [OFDNSRequest - requestWithHost: host - recordClass: recordClass - recordType: recordType]; - - exception = [OFDNSRequestFailedException - exceptionWithRequest: request - error: error]; + OFDNSQuery *query = [OFDNSQuery + queryWithHost: host + recordClass: recordClass + recordType: recordType]; + + exception = [OFDNSQueryFailedException + exceptionWithQuery: query + error: error]; } } if ([delegate respondsToSelector: @selector(resolver: didResolveDomainName:socketAddresses:exception:)]) { @@ -1636,49 +1634,49 @@ } #ifdef OF_HAVE_IPV6 if (addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV6 || addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) { - OFDNSRequest *request = [OFDNSRequest - requestWithHost: host - recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN - recordType: OF_DNS_RESOURCE_RECORD_TYPE_AAAA]; + OFDNSQuery *query = [OFDNSQuery + queryWithHost: host + recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN + recordType: OF_DNS_RESOURCE_RECORD_TYPE_AAAA]; OFNumber *recordTypeNumber = [OFNumber numberWithInt: OF_DNS_RESOURCE_RECORD_TYPE_AAAA]; - [self of_asyncPerformRequest: request - settings: nil - nameServersIndex: 0 - searchDomainsIndex: 0 - runLoopMode: runLoopMode - target: context - selector: @selector(resolver: - didResolveDomainName:response: - context:exception:) - context: recordTypeNumber]; + [self of_asyncPerformQuery: query + settings: nil + nameServersIndex: 0 + searchDomainsIndex: 0 + runLoopMode: runLoopMode + target: context + selector: @selector(resolver: + didResolveDomainName:response: + context:exception:) + context: recordTypeNumber]; } #endif if (addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV4 || addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) { - OFDNSRequest *request = [OFDNSRequest - requestWithHost: host - recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN - recordType: OF_DNS_RESOURCE_RECORD_TYPE_A]; + OFDNSQuery *query = [OFDNSQuery + queryWithHost: host + recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN + recordType: OF_DNS_RESOURCE_RECORD_TYPE_A]; OFNumber *recordTypeNumber = [OFNumber numberWithInt: OF_DNS_RESOURCE_RECORD_TYPE_A]; - [self of_asyncPerformRequest: request - settings: nil - nameServersIndex: 0 - searchDomainsIndex: 0 - runLoopMode: runLoopMode - target: context - selector: @selector(resolver: - didResolveDomainName:response: - context:exception:) - context: recordTypeNumber]; + [self of_asyncPerformQuery: query + settings: nil + nameServersIndex: 0 + searchDomainsIndex: 0 + runLoopMode: runLoopMode + target: context + selector: @selector(resolver: + didResolveDomainName:response: + context:exception:) + context: recordTypeNumber]; } objc_autoreleasePoolPop(pool); } @@ -1733,15 +1731,15 @@ _IPv6Socket = nil; #endif enumerator = [_queries objectEnumerator]; while ((query = [enumerator nextObject]) != nil) { - OFDNSRequestFailedException *exception; + OFDNSQueryFailedException *exception; - exception = [OFDNSRequestFailedException - exceptionWithRequest: query->_request - error: OF_DNS_RESOLVER_ERROR_CANCELED]; + exception = [OFDNSQueryFailedException + exceptionWithQuery: query->_query + error: OF_DNS_RESOLVER_ERROR_CANCELED]; callback(query->_target, query->_selector, self, query->_domainName, nil, query->_context, exception); } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -73,10 +73,11 @@ # import "OFStreamSocket.h" # import "OFTCPSocket.h" # import "OFUDPSocket.h" # import "OFTLSSocket.h" # import "OFKernelEventObserver.h" +# import "OFDNSQuery.h" # import "OFDNSResourceRecord.h" # import "OFDNSResponse.h" # import "OFDNSResolver.h" #endif #ifdef OF_HAVE_SOCKETS @@ -145,11 +146,11 @@ #import "OFException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" -# import "OFDNSRequestFailedException.h" +# import "OFDNSQueryFailedException.h" #endif #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFChecksumMismatchException.h" #ifdef OF_HAVE_THREADS # import "OFConditionBroadcastFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -56,11 +56,11 @@ SRCS_PLUGINS = OFLoadPluginFailedException.m SRCS_SOCKETS = OFAcceptFailedException.m \ OFAlreadyConnectedException.m \ OFBindFailedException.m \ OFConnectionFailedException.m \ - OFDNSRequestFailedException.m \ + OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ OFListenFailedException.m \ OFObserveFailedException.m SRCS_THREADS = OFConditionBroadcastFailedException.m \ OFConditionSignalFailedException.m \ ADDED src/exceptions/OFDNSQueryFailedException.h Index: src/exceptions/OFDNSQueryFailedException.h ================================================================== --- src/exceptions/OFDNSQueryFailedException.h +++ src/exceptions/OFDNSQueryFailedException.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" +#import "OFDNSQuery.h" +#import "OFDNSResolver.h" +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/*! + * @class OFDNSQueryFailedException \ + * OFDNSQueryFailedException.h ObjFW/OFDNSQueryFailedException.h + * + * @brief An exception indicating the resolving a host failed. + */ +@interface OFDNSQueryFailedException: OFException +{ + OFDNSQuery *_query; + of_dns_resolver_error_t _error; +} + +/*! + * @brief The query which could not be performed. + */ +@property (readonly, nonatomic) OFDNSQuery *query; + +/*! + * @brief The error from the resolver. + */ +@property (readonly, nonatomic) of_dns_resolver_error_t error; + +/*! + * @brief Creates a new, autoreleased resolve host failed exception. + * + * @param query The query which could not be performed + * @param error The error from the resolver + * @return A new, autoreleased address translation failed exception + */ ++ (instancetype)exceptionWithQuery: (OFDNSQuery *)query + error: (of_dns_resolver_error_t)error; + +/*! + * @brief Initializes an already allocated address translation failed exception. + * + * @param query The query which could not be performed + * @param error The error from the resolver + * @return An initialized address translation failed exception + */ +- (instancetype)initWithQuery: (OFDNSQuery *)query + error: (of_dns_resolver_error_t)error; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFDNSQueryFailedException.m Index: src/exceptions/OFDNSQueryFailedException.m ================================================================== --- src/exceptions/OFDNSQueryFailedException.m +++ src/exceptions/OFDNSQueryFailedException.m @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFDNSQueryFailedException.h" +#import "OFString.h" + +@implementation OFDNSQueryFailedException +@synthesize query = _query, error = _error; + ++ (instancetype)exceptionWithQuery: (OFDNSQuery *)query + error: (of_dns_resolver_error_t)error +{ + return [[[self alloc] initWithQuery: query + error: error] autorelease]; +} + +- (instancetype)initWithQuery: (OFDNSQuery *)query + error: (of_dns_resolver_error_t)error +{ + self = [super init]; + + @try { + _query = [query copy]; + _error = error; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_query release]; + + [super dealloc]; +} + +- (OFString *)description +{ + OFString *error; + + switch (_error) { + case OF_DNS_RESOLVER_ERROR_TIMEOUT: + error = @"The query timed out."; + break; + case OF_DNS_RESOLVER_ERROR_CANCELED: + error = @"The query was canceled."; + break; + case OF_DNS_RESOLVER_ERROR_NO_RESULT: + error = @"No result for the specified host with the specified " + @"type and class."; + break; + case OF_DNS_RESOLVER_ERROR_SERVER_INVALID_FORMAT: + error = @"The server considered the query to be malformed."; + break; + case OF_DNS_RESOLVER_ERROR_SERVER_FAILURE: + error = @"The server was unable to process due to an internal " + @"error."; + break; + case OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR: + error = @"The server returned an error that the domain does " + @"not exist."; + break; + case OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED: + error = @"The server does not have support for the requested " + @"query."; + case OF_DNS_RESOLVER_ERROR_SERVER_REFUSED: + error = @"The server refused the query."; + break; + default: + error = @"Unknown error."; + break; + } + + return [OFString stringWithFormat: + @"Query %@ could not be performed: %@", _query, error]; +} +@end DELETED src/exceptions/OFDNSRequestFailedException.h Index: src/exceptions/OFDNSRequestFailedException.h ================================================================== --- src/exceptions/OFDNSRequestFailedException.h +++ src/exceptions/OFDNSRequestFailedException.h @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" -#import "OFDNSRequest.h" -#import "OFDNSResolver.h" -#import "OFDNSResourceRecord.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! - * @class OFDNSRequestFailedException \ - * OFDNSRequestFailedException.h ObjFW/OFDNSRequestFailedException.h - * - * @brief An exception indicating the resolving a host failed. - */ -@interface OFDNSRequestFailedException: OFException -{ - OFDNSRequest *_request; - of_dns_resolver_error_t _error; -} - -/*! - * @brief The request which could not be performed. - */ -@property (readonly, nonatomic) OFDNSRequest *request; - -/*! - * @brief The error from the resolver. - */ -@property (readonly, nonatomic) of_dns_resolver_error_t error; - -/*! - * @brief Creates a new, autoreleased resolve host failed exception. - * - * @param request The request which could not be performed - * @param error The error from the resolver - * @return A new, autoreleased address translation failed exception - */ -+ (instancetype)exceptionWithRequest: (OFDNSRequest *)request - error: (of_dns_resolver_error_t)error; - -/*! - * @brief Initializes an already allocated address translation failed exception. - * - * @param request The request which could not be performed - * @param error The error from the resolver - * @return An initialized address translation failed exception - */ -- (instancetype)initWithRequest: (OFDNSRequest *)request - error: (of_dns_resolver_error_t)error; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFDNSRequestFailedException.m Index: src/exceptions/OFDNSRequestFailedException.m ================================================================== --- src/exceptions/OFDNSRequestFailedException.m +++ src/exceptions/OFDNSRequestFailedException.m @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFDNSRequestFailedException.h" -#import "OFString.h" - -@implementation OFDNSRequestFailedException -@synthesize request = _request, error = _error; - -+ (instancetype)exceptionWithRequest: (OFDNSRequest *)request - error: (of_dns_resolver_error_t)error -{ - return [[[self alloc] initWithRequest: request - error: error] autorelease]; -} - -- (instancetype)initWithRequest: (OFDNSRequest *)request - error: (of_dns_resolver_error_t)error -{ - self = [super init]; - - @try { - _request = [request copy]; - _error = error; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_request release]; - - [super dealloc]; -} - -- (OFString *)description -{ - OFString *error; - - switch (_error) { - case OF_DNS_RESOLVER_ERROR_TIMEOUT: - error = @"The query timed out."; - break; - case OF_DNS_RESOLVER_ERROR_CANCELED: - error = @"The query was canceled."; - break; - case OF_DNS_RESOLVER_ERROR_NO_RESULT: - error = @"No result for the specified host with the specified " - @"type and class."; - break; - case OF_DNS_RESOLVER_ERROR_SERVER_INVALID_FORMAT: - error = @"The server considered the query to be malformed."; - break; - case OF_DNS_RESOLVER_ERROR_SERVER_FAILURE: - error = @"The server was unable to process due to an internal " - @"error."; - break; - case OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR: - error = @"The server returned an error that the domain does " - @"not exist."; - break; - case OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED: - error = @"The server does not have support for the requested " - @"query."; - case OF_DNS_RESOLVER_ERROR_SERVER_REFUSED: - error = @"The server refused the query."; - break; - default: - error = @"Unknown error."; - break; - } - - return [OFString stringWithFormat: - @"Request %@ could not be performed: %@", _request, error]; -} -@end Index: utils/ofdns/OFDNS.m ================================================================== --- utils/ofdns/OFDNS.m +++ utils/ofdns/OFDNS.m @@ -51,11 +51,11 @@ OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments]; of_dns_resource_record_class_t recordClass = OF_DNS_RESOURCE_RECORD_CLASS_ANY; of_dns_resource_record_type_t recordType = OF_DNS_RESOURCE_RECORD_TYPE_ALL; - OFDNSRequest *request; + OFDNSQuery *query; OFDNSResolver *resolver; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [[OFSandbox alloc] init]; @try { @@ -89,12 +89,12 @@ resolver.configReloadInterval = 0; resolver.nameServers = [arguments objectsInRange: of_range(3, 1)]; } - request = [OFDNSRequest requestWithHost: [arguments objectAtIndex: 0] - recordClass: recordClass - recordType: recordType]; - [resolver asyncPerformRequest: request - delegate: self]; + query = [OFDNSQuery queryWithHost: [arguments objectAtIndex: 0] + recordClass: recordClass + recordType: recordType]; + [resolver asyncPerformQuery: query + delegate: self]; } @end Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -34,11 +34,11 @@ #import "OFTCPSocket.h" #import "OFTLSSocket.h" #import "OFURL.h" #import "OFConnectionFailedException.h" -#import "OFDNSRequestFailedException.h" +#import "OFDNSQueryFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" @@ -610,18 +610,18 @@ - (void)client: (OFHTTPClient *)client didFailWithException: (id)e request: (OFHTTPRequest *)request { - if ([e isKindOfClass: [OFDNSRequestFailedException class]]) { + if ([e isKindOfClass: [OFDNSQueryFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: - OF_LOCALIZED(@"download_dns_request_failed", + OF_LOCALIZED(@"download_dns_query_failed", @"%[prog]: Failed to download <%[url]>!\n" - @" DNS request failed: %[exception]", + @" DNS query failed: %[exception]", @"prog", [OFApplication programName], @"url", request.URL.string, @"exception", e)]; } else if ([e isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) Index: utils/ofhttp/lang/de.json ================================================================== --- utils/ofhttp/lang/de.json +++ utils/ofhttp/lang/de.json @@ -36,13 +36,13 @@ ], "output_only_with_one_url": [ "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ", "werden!" ], - "download_dns_request_failed": [ + "download_dns_query_failed": [ "%[prog]: Fehler beim Download von <%[url]>!\n", - " DNS-Anfrage fehlgeschlagen: %[exception]" + " DNS-Abfrage fehlgeschlagen: %[exception]" ], "download_failed_connection_failed": [ "%[prog]: Fehler beim Download von <%[url]>!\n", " Verbindung fehlgeschlagen: %[exception]" ],