ObjFW  Check-in [d69f7bc1ff]

Overview
Comment:Rename OFDNSRequest -> OFDNSQuery

This is now in alignment with the terminology of the RFC.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d69f7bc1ff238cf07c9d46e56c8e7d474e0b0361f6393aa9b6eb0f6d19d07b0a
User & Date: js on 2019-10-06 16:27:12
Other Links: manifest | tags
Context
2019-10-06
17:05
OFDNSResolver: Improved error handling check-in: d31e244f55 user: js tags: trunk
16:27
Rename OFDNSRequest -> OFDNSQuery check-in: d69f7bc1ff user: js tags: trunk
2019-10-03
23:29
OFXMLElementBuilder: Allow subclassing check-in: b4614c3b1e user: js tags: trunk
Changes

Modified src/Makefile from [f694f561e0] to [7bc7134513].

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFFile.m			\
	     OFINICategory.m		\
	     OFINIFile.m		\
	     OFSettings.m		\
	     OFString+PathAdditions.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SOCKETS = OFDNSRequest.m			\
	       OFDNSResolver.m			\
	       OFDNSResourceRecord.m		\
	       OFDNSResponse.m			\
	       OFHTTPClient.m			\
	       OFHTTPCookie.m			\
	       OFHTTPCookieManager.m		\
	       OFHTTPRequest.m			\







|







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFFile.m			\
	     OFINICategory.m		\
	     OFINIFile.m		\
	     OFSettings.m		\
	     OFString+PathAdditions.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SOCKETS = OFDNSQuery.m			\
	       OFDNSResolver.m			\
	       OFDNSResourceRecord.m		\
	       OFDNSResponse.m			\
	       OFHTTPClient.m			\
	       OFHTTPCookie.m			\
	       OFHTTPCookieManager.m		\
	       OFHTTPRequest.m			\

Added src/OFDNSQuery.h version [62a8b467ea].

































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 <OFCopying>
{
	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 version [d423cb9874].



















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 version [67f43b812e].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 <OFCopying>
{
	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 version [d5a6e314f1].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















































































































































































































































Modified src/OFDNSResolver.h from [5daf5f77ab] to [3539989488].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * 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 "OFDNSRequest.h"
#import "OFDNSResourceRecord.h"
#import "OFDNSResponse.h"
#import "OFRunLoop.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN








|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * 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 "OFDNSQuery.h"
#import "OFDNSResourceRecord.h"
#import "OFDNSResponse.h"
#import "OFRunLoop.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

/*!
 * @brief Initializes an already allocated OFDNSResolver.
 */
- (instancetype)init;

/*!
 * @brief Asynchronously performs the specified request.
 *
 * @param request The request to perform
 * @param delegate The delegate to use for callbacks
 */
- (void)asyncPerformRequest: (OFDNSRequest *)request
		   delegate: (id <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously performs the specified request.
 *
 * @param request The request 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 <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously resolves the specified host to socket addresses.
 *
 * @param host The host to resolve
 * @param delegate The delegate to use for callbacks
 */







|

|


|
|


|

|



|
|
|







189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

/*!
 * @brief Initializes an already allocated OFDNSResolver.
 */
- (instancetype)init;

/*!
 * @brief Asynchronously performs the specified query.
 *
 * @param query The query to perform
 * @param delegate The delegate to use for callbacks
 */
- (void)asyncPerformQuery: (OFDNSQuery *)query
		 delegate: (id <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously performs the specified query.
 *
 * @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)asyncPerformQuery: (OFDNSQuery *)query
	      runLoopMode: (of_run_loop_mode_t)runLoopMode
		 delegate: (id <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously resolves the specified host to socket addresses.
 *
 * @param host The host to resolve
 * @param delegate The delegate to use for callbacks
 */
258
259
260
261
262
263
264
265
266
267
268
269
270
 * @return OFData containing several of_socket_address_t
 */
- (OFData *)resolveSocketAddressesForHost: (OFString *)host
			    addressFamily: (of_socket_address_family_t)
					       addressFamily;

/*!
 * @brief Closes all sockets and cancels all ongoing requests.
 */
- (void)close;
@end

OF_ASSUME_NONNULL_END







|





258
259
260
261
262
263
264
265
266
267
268
269
270
 * @return OFData containing several of_socket_address_t
 */
- (OFData *)resolveSocketAddressesForHost: (OFString *)host
			    addressFamily: (of_socket_address_family_t)
					       addressFamily;

/*!
 * @brief Closes all sockets and cancels all ongoing queries.
 */
- (void)close;
@end

OF_ASSUME_NONNULL_END

Modified src/OFDNSResolver.m from [f3fddc6663] to [d5d7184bab].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include "config.h"

#include <string.h>

#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFDNSRequest.h"
#import "OFDNSResolverSettings.h"
#import "OFDNSResponse.h"
#import "OFData.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFString.h"
#import "OFTimer.h"
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"

#import "OFDNSRequestFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"








|












|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include "config.h"

#include <string.h>

#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFDNSQuery.h"
#import "OFDNSResolverSettings.h"
#import "OFDNSResponse.h"
#import "OFData.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFString.h"
#import "OFTimer.h"
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"

#import "OFDNSQueryFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

static const of_run_loop_mode_t resolveRunLoopMode =
    @"of_dns_resolver_resolve_mode";

@interface OFDNSResolverQuery: OFObject
{
@public
	OFDNSRequest *_request;
	OFString *_domainName;
	OFNumber *_ID;
	OFDNSResolverSettings *_settings;
	size_t _nameServersIndex, _searchDomainsIndex;
	unsigned int _attempt;
	id _target;
	SEL _selector;
	id _context;
	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;
@end

@interface OFDNSResolverAsyncResolveSocketAddressesContext: OFObject
{
	OFString *_host;
	id _delegate;
	OFMutableArray OF_GENERIC(OF_KINDOF(OFDNSResourceRecord *)) *_records;







|













|
|
|
|
|
|
|
|
|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

static const of_run_loop_mode_t resolveRunLoopMode =
    @"of_dns_resolver_resolve_mode";

@interface OFDNSResolverQuery: OFObject
{
@public
	OFDNSQuery *_query;
	OFString *_domainName;
	OFNumber *_ID;
	OFDNSResolverSettings *_settings;
	size_t _nameServersIndex, _searchDomainsIndex;
	unsigned int _attempt;
	id _target;
	SEL _selector;
	id _context;
	OFData *_queryData;
	of_socket_address_t _usedNameServer;
	OFTimer *_cancelTimer;
}

- (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;
	id _delegate;
	OFMutableArray OF_GENERIC(OF_KINDOF(OFDNSResourceRecord *)) *_records;
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	bool _done;
	OFData *_socketAddresses;
	id _exception;
}
@end

@interface OFDNSResolver () <OFUDPSocketDelegate>
- (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_sendQuery: (OFDNSResolverQuery *)query
	 runLoopMode: (of_run_loop_mode_t)runLoopMode;
- (void)of_queryWithIDTimedOut: (OFDNSResolverQuery *)query;
@end

static bool
isFQDN(OFString *host, OFDNSResolverSettings *settings)







|
|
|
|
|
|
|
|







138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	bool _done;
	OFData *_socketAddresses;
	id _exception;
}
@end

@interface OFDNSResolver () <OFUDPSocketDelegate>
- (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

static bool
isFQDN(OFString *host, OFDNSResolverSettings *settings)
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
	    OFDNSResponse *, id, id))[target methodForSelector: selector];

	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
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableData *queryData;
		uint16_t tmp;

		_request = [request copy];
		_domainName = [domainName copy];
		_ID = [ID retain];
		_settings = [settings copy];
		_nameServersIndex = nameServersIndex;
		_searchDomainsIndex = searchDomainsIndex;
		_target = [target retain];
		_selector = selector;







|
|
|
|
|
|
|
|
|








|







546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
	    OFDNSResponse *, id, id))[target methodForSelector: selector];

	method(target, selector, resolver, domainName, response, context,
	    exception);
}

@implementation OFDNSResolverQuery
- (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;

		_query = [query copy];
		_domainName = [domainName copy];
		_ID = [ID retain];
		_settings = [settings copy];
		_nameServersIndex = nameServersIndex;
		_searchDomainsIndex = searchDomainsIndex;
		_target = [target retain];
		_selector = selector;
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
			length8 = (uint8_t)length;
			[queryData addItem: &length8];
			[queryData addItems: component.UTF8String
				      count: length];
		}

		/* QTYPE */
		tmp = OF_BSWAP16_IF_LE(_request.recordType);
		[queryData addItems: &tmp
			      count: 2];

		/* QCLASS */
		tmp = OF_BSWAP16_IF_LE(_request.recordClass);
		[queryData addItems: &tmp
			      count: 2];

		[queryData makeImmutable];

		_queryData = [queryData copy];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_request release];
	[_domainName release];
	[_ID release];
	[_settings release];
	[_target release];
	[_context release];
	[_queryData release];
	[_cancelTimer release];







|




|


















|







612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
			length8 = (uint8_t)length;
			[queryData addItem: &length8];
			[queryData addItems: component.UTF8String
				      count: length];
		}

		/* QTYPE */
		tmp = OF_BSWAP16_IF_LE(_query.recordType);
		[queryData addItems: &tmp
			      count: 2];

		/* QCLASS */
		tmp = OF_BSWAP16_IF_LE(_query.recordClass);
		[queryData addItems: &tmp
			      count: 2];

		[queryData makeImmutable];

		_queryData = [queryData copy];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_query release];
	[_domainName release];
	[_ID release];
	[_settings release];
	[_target release];
	[_context release];
	[_queryData release];
	[_cancelTimer release];
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
		found = true;

	if (!found) {
		of_run_loop_mode_t runLoopMode =
		    [OFRunLoop currentRunLoop].currentMode;
		OFNumber *recordTypeNumber =
		    [OFNumber numberWithInt: recordType];
		OFDNSRequest *request;

		_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];
	}
}

-  (void)resolver: (OFDNSResolver *)resolver
  didResolveCNAME: (OFString *)CNAME
	 response: (OFDNSResponse *)response
	  context: (OFNumber *)context







|







|
|
|
|
|
|
|
|
|
|
|
|
|
|







739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
		found = true;

	if (!found) {
		of_run_loop_mode_t runLoopMode =
		    [OFRunLoop currentRunLoop].currentMode;
		OFNumber *recordTypeNumber =
		    [OFNumber numberWithInt: recordType];
		OFDNSQuery *query;

		_expectedResponses++;

		[result addObject:
		    [OFPair pairWithFirstObject: CNAME
				   secondObject: 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
	 response: (OFDNSResponse *)response
	  context: (OFNumber *)context
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
			break;
		}
	}

	[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];
	}

	if ([_delegate respondsToSelector: @selector(
	    resolver:didResolveDomainName:socketAddresses:exception:)])
		[_delegate	resolver: _resolver
		    didResolveDomainName: _domainName
			 socketAddresses: (exception == nil ? addresses : nil)







|
|
|
|

|
|
|







860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
			break;
		}
	}

	[addresses makeImmutable];

	if (addresses.count == 0) {
		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
		    didResolveDomainName: _domainName
			 socketAddresses: (exception == nil ? addresses : nil)
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
	else
		_resolver = [resolver retain];

	_expectedResponses--;

	if (_domainName != nil) {
		if (![domainName isEqual: _domainName])
			/* Did the config change between requests? */
			return;
	} else
		_domainName = [domainName copy];

	if (exception != nil) {
		if (_expectedResponses == 0)
			[self done];







|







900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
	else
		_resolver = [resolver retain];

	_expectedResponses--;

	if (_domainName != nil) {
		if (![domainName isEqual: _domainName])
			/* Did the config change in between? */
			return;
	} else
		_domainName = [domainName copy];

	if (exception != nil) {
		if (_expectedResponses == 0)
			[self done];
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
}

- (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 *pool = objc_autoreleasePoolPush();
	OFNumber *ID;
	OFString *host, *domainName;
	OFDNSResolverQuery *query;

	if (settings == nil) {
		[_settings reload];
		settings = _settings;
	}

	/* Random, unused ID */
	do {
		ID = [OFNumber numberWithUInt16: (uint16_t)of_random()];
	} while ([_queries objectForKey: ID] != nil);

	host = request.host;
	if (isFQDN(host, settings)) {
		domainName = host;

		if (![domainName hasSuffix: @"."])
			domainName = [domainName stringByAppendingString: @"."];
	} else {
		OFString *searchDomain = [settings->_searchDomains
		    objectAtIndex: searchDomainsIndex];

		domainName = [OFString stringWithFormat: @"%@.%@.",
		    host, searchDomain];
	}

	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
		     forKey: ID];

	[self of_sendQuery: query
	       runLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}

-    (void)of_resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	      response: (OFDNSResponse *)response
	       context: (id)delegate
	     exception: (id)exception
{
	if ([delegate respondsToSelector: @selector(resolver:
	    didResolveDomainName:response:exception:)])
		[delegate	resolver: resolver
		    didResolveDomainName: domainName
				response: response
			       exception: exception];
}

- (void)asyncPerformRequest: (OFDNSRequest *)request
		   delegate: (id <OFDNSResolverDelegate>)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 <OFDNSResolverDelegate>)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)of_sendQuery: (OFDNSResolverQuery *)query
	 runLoopMode: (of_run_loop_mode_t)runLoopMode
{
	OFUDPSocket *sock;
	OFString *nameServer;







|
|
|
|
|
|
|
|




|











|
















|
|
|
|
|
|
|
|
|
|
|


|



















|
|

|
|
|
|
|
|
|
<
|
|


|
|
|

|
|
|
|
|
|
|
<
|
|







1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1201
}

- (void)setConfigReloadInterval: (of_time_interval_t)configReloadInterval
{
	_settings->_configReloadInterval = configReloadInterval;
}

- (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 *resolverQuery;

	if (settings == nil) {
		[_settings reload];
		settings = _settings;
	}

	/* Random, unused ID */
	do {
		ID = [OFNumber numberWithUInt16: (uint16_t)of_random()];
	} while ([_queries objectForKey: ID] != nil);

	host = query.host;
	if (isFQDN(host, settings)) {
		domainName = host;

		if (![domainName hasSuffix: @"."])
			domainName = [domainName stringByAppendingString: @"."];
	} else {
		OFString *searchDomain = [settings->_searchDomains
		    objectAtIndex: searchDomainsIndex];

		domainName = [OFString stringWithFormat: @"%@.%@.",
		    host, searchDomain];
	}

	if (domainName.UTF8StringLength > 253)
		@throw [OFOutOfRangeException exception];

	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: resolverQuery
	       runLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}

-    (void)of_resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	      response: (OFDNSResponse *)response
	       context: (id)delegate
	     exception: (id)exception
{
	if ([delegate respondsToSelector: @selector(resolver:
	    didResolveDomainName:response:exception:)])
		[delegate	resolver: resolver
		    didResolveDomainName: domainName
				response: response
			       exception: exception];
}

- (void)asyncPerformQuery: (OFDNSQuery *)query
		 delegate: (id <OFDNSResolverDelegate>)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 <OFDNSResolverDelegate>)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
{
	OFUDPSocket *sock;
	OFString *nameServer;
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
	[sock asyncSendData: query->_queryData
		   receiver: &query->_usedNameServer
		runLoopMode: runLoopMode];
}

- (void)of_queryWithIDTimedOut: (OFDNSResolverQuery *)query
{
	OFDNSRequestFailedException *exception;

	if (query == nil)
		return;

	if (query->_nameServersIndex + 1 <
	    query->_settings->_nameServers.count) {
		query->_nameServersIndex++;







|







1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
	[sock asyncSendData: query->_queryData
		   receiver: &query->_usedNameServer
		runLoopMode: runLoopMode];
}

- (void)of_queryWithIDTimedOut: (OFDNSResolverQuery *)query
{
	OFDNSQueryFailedException *exception;

	if (query == nil)
		return;

	if (query->_nameServersIndex + 1 <
	    query->_settings->_nameServers.count) {
		query->_nameServersIndex++;
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
		return;
	}

	query = [[query retain] autorelease];
	[_queries removeObjectForKey: query->_ID];

	/*
	 * Cancel any pending requests, 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];
#ifdef OF_HAVE_IPV6
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket asyncReceiveIntoBuffer: _buffer
				     length: BUFFER_LENGTH];
#endif

	exception = [OFDNSRequestFailedException
	    exceptionWithRequest: query->_request
			   error: OF_DNS_RESOLVER_ERROR_TIMEOUT];

	callback(query->_target, query->_selector, self, query->_domainName,
	    nil, query->_context, exception);
}

-	  (bool)socket: (OFUDPSocket *)sock
  didReceiveIntoBuffer: (void *)buffer_







|











|
|
|







1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
		return;
	}

	query = [[query retain] autorelease];
	[_queries removeObjectForKey: query->_ID];

	/*
	 * 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];
#ifdef OF_HAVE_IPV6
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket asyncReceiveIntoBuffer: _buffer
				     length: BUFFER_LENGTH];
#endif

	exception = [OFDNSQueryFailedException
	    exceptionWithQuery: query->_query
			 error: OF_DNS_RESOLVER_ERROR_TIMEOUT];

	callback(query->_target, query->_selector, self, query->_domainName,
	    nil, query->_context, exception);
}

-	  (bool)socket: (OFUDPSocket *)sock
  didReceiveIntoBuffer: (void *)buffer_
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
				size_t nameServersIndex =
				    query->_nameServersIndex;
				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];

				return true;
			}

			error = OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR;
			break;
		case 4:
			error = OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED;
			break;
		case 5:
			error = OF_DNS_RESOLVER_ERROR_SERVER_REFUSED;
			break;
		default:
			error = OF_DNS_RESOLVER_ERROR_UNKNOWN;
			break;
		}

		if (buffer[3] & 0x0F)
			@throw [OFDNSRequestFailedException
			    exceptionWithRequest: query->_request
					   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];

		i = 12;







|
|
|
|
|
|
|
|


















|
|
|







1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
				size_t nameServersIndex =
				    query->_nameServersIndex;
				size_t searchDomainsIndex =
				    query->_searchDomainsIndex;

				query->_searchDomainsIndex++;

				[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;
			break;
		case 4:
			error = OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED;
			break;
		case 5:
			error = OF_DNS_RESOLVER_ERROR_SERVER_REFUSED;
			break;
		default:
			error = OF_DNS_RESOLVER_ERROR_UNKNOWN;
			break;
		}

		if (buffer[3] & 0x0F)
			@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];

		i = 12;
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
			}

			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];
			}
		}

		if ([delegate respondsToSelector: @selector(resolver:
		    didResolveDomainName:socketAddresses:exception:)]) {
			OFTimer *timer = [OFTimer
			    timerWithTimeInterval: 0







|
|
|
|

|
|
|







1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
			}

			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;
				OFDNSQuery *query = [OFDNSQuery
				    queryWithHost: host
				      recordClass: recordClass
				       recordType: recordType];

				exception = [OFDNSQueryFailedException
				    exceptionWithQuery: query
						 error: error];
			}
		}

		if ([delegate respondsToSelector: @selector(resolver:
		    didResolveDomainName:socketAddresses:exception:)]) {
			OFTimer *timer = [OFTimer
			    timerWithTimeInterval: 0
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
	default:
		@throw [OFInvalidArgumentException exception];
	}

#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];
		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];
	}
#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];
		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];
	}

	objc_autoreleasePoolPop(pool);
}

- (OFData *)resolveSocketAddressesForHost: (OFString *)host
			    addressFamily: (of_socket_address_family_t)







|
|
|
|



|
|
|
|
|
|
|
|
|
|





|
|
|
|



|
|
|
|
|
|
|
|
|
|







1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
	default:
		@throw [OFInvalidArgumentException exception];
	}

#ifdef OF_HAVE_IPV6
	if (addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV6 ||
	    addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) {
		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_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) {
		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_asyncPerformQuery: query
				  settings: nil
			  nameServersIndex: 0
			searchDomainsIndex: 0
			       runLoopMode: runLoopMode
				    target: context
				  selector: @selector(resolver:
						didResolveDomainName:response:
						context:exception:)
				   context: recordTypeNumber];
	}

	objc_autoreleasePoolPop(pool);
}

- (OFData *)resolveSocketAddressesForHost: (OFString *)host
			    addressFamily: (of_socket_address_family_t)
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket release];
	_IPv6Socket = nil;
#endif

	enumerator = [_queries objectEnumerator];
	while ((query = [enumerator nextObject]) != nil) {
		OFDNSRequestFailedException *exception;

		exception = [OFDNSRequestFailedException
		    exceptionWithRequest: query->_request
				   error: OF_DNS_RESOLVER_ERROR_CANCELED];

		callback(query->_target, query->_selector, self,
		    query->_domainName, nil, query->_context, exception);
	}

	[_queries removeAllObjects];

	objc_autoreleasePoolPop(pool);
}
@end







|

|
|
|










1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket release];
	_IPv6Socket = nil;
#endif

	enumerator = [_queries objectEnumerator];
	while ((query = [enumerator nextObject]) != nil) {
		OFDNSQueryFailedException *exception;

		exception = [OFDNSQueryFailedException
		    exceptionWithQuery: query->_query
				 error: OF_DNS_RESOLVER_ERROR_CANCELED];

		callback(query->_target, query->_selector, self,
		    query->_domainName, nil, query->_context, exception);
	}

	[_queries removeAllObjects];

	objc_autoreleasePoolPop(pool);
}
@end

Modified src/ObjFW.h from [f502edafc8] to [1f291aba5e].

71
72
73
74
75
76
77

78
79
80
81
82
83
84
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFStreamSocket.h"
# import "OFTCPSocket.h"
# import "OFUDPSocket.h"
# import "OFTLSSocket.h"
# import "OFKernelEventObserver.h"

# import "OFDNSResourceRecord.h"
# import "OFDNSResponse.h"
# import "OFDNSResolver.h"
#endif
#ifdef OF_HAVE_SOCKETS
# ifdef OF_HAVE_THREADS
#  import "OFHTTPClient.h"







>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#endif
#ifdef OF_HAVE_SOCKETS
# 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
# ifdef OF_HAVE_THREADS
#  import "OFHTTPClient.h"
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAlreadyConnectedException.h"
# import "OFBindFailedException.h"
# import "OFDNSRequestFailedException.h"
#endif
#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChecksumMismatchException.h"
#ifdef OF_HAVE_THREADS
# import "OFConditionBroadcastFailedException.h"
# import "OFConditionSignalFailedException.h"
# import "OFConditionStillWaitingException.h"







|







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAlreadyConnectedException.h"
# import "OFBindFailedException.h"
# import "OFDNSQueryFailedException.h"
#endif
#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChecksumMismatchException.h"
#ifdef OF_HAVE_THREADS
# import "OFConditionBroadcastFailedException.h"
# import "OFConditionSignalFailedException.h"
# import "OFConditionStillWaitingException.h"

Modified src/exceptions/Makefile from [2d5f98b062] to [1de3299d3f].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\
	       OFDNSRequestFailedException.m		\
	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m	\
	       OFConditionSignalFailedException.m	\
	       OFConditionStillWaitingException.m	\
	       OFConditionWaitFailedException.m		\







|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\
	       OFDNSQueryFailedException.m		\
	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m	\
	       OFConditionSignalFailedException.m	\
	       OFConditionStillWaitingException.m	\
	       OFConditionWaitFailedException.m		\

Added src/exceptions/OFDNSQueryFailedException.h version [1266a73c9c].









































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 version [bf9ae11420].

































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 version [8af2cbe08d].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 version [c1ec9c220e].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
































































































































































































Modified utils/ofdns/OFDNS.m from [5d1e72d5b4] to [84af245824].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
- (void)applicationDidFinishLaunching
{
	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;
	OFDNSResolver *resolver;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [[OFSandbox alloc] init];
	@try {
		sandbox.allowsStdIO = true;
		sandbox.allowsDNS = true;







|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
- (void)applicationDidFinishLaunching
{
	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;
	OFDNSQuery *query;
	OFDNSResolver *resolver;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [[OFSandbox alloc] init];
	@try {
		sandbox.allowsStdIO = true;
		sandbox.allowsDNS = true;
87
88
89
90
91
92
93
94
95
96
97
98
99
100

	if (arguments.count >= 4) {
		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];
}
@end







|
|
|
|
|


87
88
89
90
91
92
93
94
95
96
97
98
99
100

	if (arguments.count >= 4) {
		resolver.configReloadInterval = 0;
		resolver.nameServers =
		    [arguments objectsInRange: of_range(3, 1)];
	}

	query = [OFDNSQuery queryWithHost: [arguments objectAtIndex: 0]
			      recordClass: recordClass
			       recordType: recordType];
	[resolver asyncPerformQuery: query
			   delegate: self];
}
@end

Modified utils/ofhttp/OFHTTP.m from [8c21bf2dad] to [77758e69da].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"

#import "OFConnectionFailedException.h"
#import "OFDNSRequestFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"

#import "OFConnectionFailedException.h"
#import "OFDNSQueryFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
	return true;
}

-	  (void)client: (OFHTTPClient *)client
  didFailWithException: (id)e
	       request: (OFHTTPRequest *)request
{
	if ([e isKindOfClass: [OFDNSRequestFailedException class]]) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

		[of_stderr writeLine:
		    OF_LOCALIZED(@"download_dns_request_failed",
		    @"%[prog]: Failed to download <%[url]>!\n"
		    @"  DNS request failed: %[exception]",
		    @"prog", [OFApplication programName],
		    @"url", request.URL.string,
		    @"exception", e)];
	} else if ([e isKindOfClass: [OFConnectionFailedException class]]) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];








|




|

|







608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
	return true;
}

-	  (void)client: (OFHTTPClient *)client
  didFailWithException: (id)e
	       request: (OFHTTPRequest *)request
{
	if ([e isKindOfClass: [OFDNSQueryFailedException class]]) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

		[of_stderr writeLine:
		    OF_LOCALIZED(@"download_dns_query_failed",
		    @"%[prog]: Failed to download <%[url]>!\n"
		    @"  DNS query failed: %[exception]",
		    @"prog", [OFApplication programName],
		    @"url", request.URL.string,
		    @"exception", e)];
	} else if ([e isKindOfClass: [OFConnectionFailedException class]]) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

Modified utils/ofhttp/lang/de.json from [629be9f74b] to [401e7794d9].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        "%[prog]: -o / --output und -O / --detect-filename schließen sich ",
        "gegenseitig aus!"
    ],
    "output_only_with_one_url": [
        "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ",
        "werden!"
    ],
    "download_dns_request_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  DNS-Anfrage fehlgeschlagen: %[exception]"
    ],
    "download_failed_connection_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Verbindung fehlgeschlagen: %[exception]"
    ],
    "download_failed_invalid_server_reply": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",







|

|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        "%[prog]: -o / --output und -O / --detect-filename schließen sich ",
        "gegenseitig aus!"
    ],
    "output_only_with_one_url": [
        "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ",
        "werden!"
    ],
    "download_dns_query_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  DNS-Abfrage fehlgeschlagen: %[exception]"
    ],
    "download_failed_connection_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Verbindung fehlgeschlagen: %[exception]"
    ],
    "download_failed_invalid_server_reply": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",