ObjFW  Check-in [6b2fb27dca]

Overview
Comment:Add OFDNSRequest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6b2fb27dca1cd94daafee2c86a33ecdb510b5bc22cf288f416ff4160f91e0985
User & Date: js on 2019-10-01 00:40:48
Other Links: manifest | tags
Context
2019-10-03
21:43
OFDNSResolver: Split out settings check-in: 4fd5a7086c user: js tags: trunk
2019-10-01
00:40
Add OFDNSRequest check-in: 6b2fb27dca user: js tags: trunk
2019-09-30
22:46
Add OFDNSResponse check-in: da8eb2d43a user: js tags: trunk
Changes

Modified src/Makefile from [0421509860] to [a0fa8bc5b7].

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 = OFDNSResolver.m			\

	       OFDNSResourceRecord.m		\
	       OFDNSResponse.m			\
	       OFHTTPClient.m			\
	       OFHTTPCookie.m			\
	       OFHTTPCookieManager.m		\
	       OFHTTPRequest.m			\
	       OFHTTPResponse.m			\







|
>







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
       ${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			\
	       OFHTTPResponse.m			\

Added 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

Added 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 [3d3d9eb630] to [2f064a7964].

12
13
14
15
16
17
18

19
20
21
22
23
24
25
 * 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"
#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 "OFDNSRequest.h"
#import "OFDNSResourceRecord.h"
#import "OFDNSResponse.h"
#import "OFRunLoop.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

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

/*!
 * @brief Asynchronously resolves the specified host.
 *
 * @param host The host to resolve
 * @param delegate The delegate to use for callbacks
 */
- (void)asyncResolveHost: (OFString *)host
		delegate: (id <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously resolves the specified host.
 *
 * @param host The host to resolve
 * @param recordClass The desired class of the records to query
 * @param recordType The desired type of the records to query
 * @param delegate The delegate to use for callbacks
 */
- (void)asyncResolveHost: (OFString *)host
	     recordClass: (of_dns_resource_record_class_t)recordClass
	      recordType: (of_dns_resource_record_type_t)recordType
		delegate: (id <OFDNSResolverDelegate>)delegate;

/*!
 * @brief Asynchronously resolves the specified host.
 *
 * @param host The host to resolve
 * @param recordClass The desired class of the records to query
 * @param recordType The desired type of the records to query
 * @param runLoopMode The run loop mode in which to resolve
 * @param delegate The delegate to use for callbacks
 */
- (void)asyncResolveHost: (OFString *)host
	     recordClass: (of_dns_resource_record_class_t)recordClass
	      recordType: (of_dns_resource_record_type_t)recordType
	     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
 */







|

|


|
|


|

<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<



|
<
<
|
|







197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214









215






216
217
218
219


220
221
222
223
224
225
226
227
228

/*!
 * @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
 */

Modified src/OFDNSResolver.m from [8025fe1282] to [c5d465decc].

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
#include <errno.h>
#include <string.h>
#include "unistd_wrapper.h"

#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFCharacterSet.h"


#import "OFData.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFString.h"
#import "OFTimer.h"
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif


#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFResolveHostFailedException.h"
#import "OFTruncatedDataException.h"

#ifdef OF_WINDOWS
# define interface struct
# include <iphlpapi.h>
# undef interface
#endif







>
>















>







<







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
#include <errno.h>
#include <string.h>
#include "unistd_wrapper.h"

#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDNSRequest.h"
#import "OFDNSResponse.h"
#import "OFData.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFString.h"
#import "OFTimer.h"
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif

#import "OFDNSRequestFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "OFTruncatedDataException.h"

#ifdef OF_WINDOWS
# define interface struct
# include <iphlpapi.h>
# undef interface
#endif
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
		      maxAttempts: (unsigned int)maxAttempts
    minNumberOfDotsInAbsoluteName: (unsigned int)minNumberOfDotsInAbsoluteName;
@end

@interface OFDNSResolverQuery: OFObject
{
@public

	OFString *_host, *_domainName;
	of_dns_resource_record_class_t _recordClass;
	of_dns_resource_record_type_t _recordType;
	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)initWithHost: (OFString *)host
		  domainName: (OFString *)domainName
		 recordClass: (of_dns_resource_record_class_t)recordClass
		  recordType: (of_dns_resource_record_type_t)recordType
			  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;







>
|
<
<












|
|
<
<
|
|
|
|
|
|
|







119
120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139
140
141


142
143
144
145
146
147
148
149
150
151
152
153
154
155
		      maxAttempts: (unsigned int)maxAttempts
    minNumberOfDotsInAbsoluteName: (unsigned int)minNumberOfDotsInAbsoluteName;
@end

@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;
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ifdef OF_AMIGAOS4
- (void)of_obtainAmigaOS4SystemConfig;
#endif
#ifdef OF_NINTENDO_3DS
- (void)of_obtainNintendo3DSSytemConfig;
#endif
- (void)of_reloadSystemConfig;
- (void)of_resolveHost: (OFString *)host
	   recordClass: (of_dns_resource_record_class_t)recordClass
	    recordType: (of_dns_resource_record_type_t)recordType
	      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_asyncResolveHost: (OFString *)host
		recordClass: (of_dns_resource_record_class_t)recordClass
		 recordType: (of_dns_resource_record_type_t)recordType
		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

#ifndef OF_WII
static OFString *







|
<
<
|
|
|
|
|
|
|
|
<
<
|
|
|
|







210
211
212
213
214
215
216
217


218
219
220
221
222
223
224
225


226
227
228
229
230
231
232
233
234
235
236
#ifdef OF_AMIGAOS4
- (void)of_obtainAmigaOS4SystemConfig;
#endif
#ifdef OF_NINTENDO_3DS
- (void)of_obtainNintendo3DSSytemConfig;
#endif
- (void)of_reloadSystemConfig;
- (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_asyncPerformRequest: (OFDNSRequest *)request


		   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

#ifndef OF_WII
static OFString *
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
	[_searchDomains release];

	[super dealloc];
}
@end

@implementation OFDNSResolverQuery
- (instancetype)initWithHost: (OFString *)host
		  domainName: (OFString *)domainName
		 recordClass: (of_dns_resource_record_class_t)recordClass
		  recordType: (of_dns_resource_record_type_t)recordType
			  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;

		_host = [host copy];
		_domainName = [domainName copy];
		_recordClass = recordClass;
		_recordType = recordType;
		_ID = [ID retain];
		_settings = [settings retain];
		_nameServersIndex = nameServersIndex;
		_searchDomainsIndex = searchDomainsIndex;
		_target = [target retain];
		_selector = selector;
		_context = [context retain];

		queryData = [OFMutableData dataWithCapacity: 512];

		/* Header */

		tmp = OF_BSWAP16_IF_LE(ID.uInt16Value);
		[queryData addItems: &tmp
			      count: 2];

		/* RD */
		tmp = OF_BSWAP16_IF_LE(1u << 8);
		[queryData addItems: &tmp
			      count: 2];

		/* QDCOUNT */
		tmp = OF_BSWAP16_IF_LE(1);
		[queryData addItems: &tmp
			      count: 2];

		/* ANCOUNT, NSCOUNT and ARCOUNT */
		[queryData increaseCountBy: 6];

		/* Question */

		/* QNAME */
		for (OFString *component in
		    [domainName componentsSeparatedByString: @"."]) {
			size_t length = component.UTF8StringLength;
			uint8_t length8;

			if (length > 63 || queryData.count + length > 512)
				@throw [OFOutOfRangeException exception];

			length8 = (uint8_t)length;
			[queryData addItem: &length8];
			[queryData addItems: component.UTF8String
				      count: length];
		}

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

		/* QCLASS */
		tmp = OF_BSWAP16_IF_LE(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
{
	[_host release];
	[_domainName release];
	[_ID release];
	[_settings release];
	[_target release];
	[_context release];
	[_queryData release];
	[_cancelTimer release];







|
|
<
<
|
|
|
|
|
|
|








|

<
<












|




















|













|




|

|
















|







689
690
691
692
693
694
695
696
697


698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714


715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
	[_searchDomains release];

	[super dealloc];
}
@end

@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 retain];
		_nameServersIndex = nameServersIndex;
		_searchDomainsIndex = searchDomainsIndex;
		_target = [target retain];
		_selector = selector;
		_context = [context retain];

		queryData = [OFMutableData dataWithCapacity: 512];

		/* Header */

		tmp = OF_BSWAP16_IF_LE(_ID.uInt16Value);
		[queryData addItems: &tmp
			      count: 2];

		/* RD */
		tmp = OF_BSWAP16_IF_LE(1u << 8);
		[queryData addItems: &tmp
			      count: 2];

		/* QDCOUNT */
		tmp = OF_BSWAP16_IF_LE(1);
		[queryData addItems: &tmp
			      count: 2];

		/* ANCOUNT, NSCOUNT and ARCOUNT */
		[queryData increaseCountBy: 6];

		/* Question */

		/* QNAME */
		for (OFString *component in
		    [_domainName componentsSeparatedByString: @"."]) {
			size_t length = component.UTF8StringLength;
			uint8_t length8;

			if (length > 63 || queryData.count + length > 512)
				@throw [OFOutOfRangeException exception];

			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];
891
892
893
894
895
896
897

898
899
900
901
902
903
904

905
906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
		found = true;

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


		_expectedResponses++;

		[result addObject:
		    [OFPair pairWithFirstObject: CNAME
				   secondObject: recordTypeNumber]];


		[_resolver of_asyncResolveHost: alias
				   recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				    recordType: recordType

				   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







>







>
|
|
|
>
|
|
|
|
|
|







882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
		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
				      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
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016



1017

1018
1019
1020
1021
1022
1023
1024
		default:
			break;
		}
	}

	[addresses makeImmutable];

	if (addresses.count == 0)
		exception = [OFResolveHostFailedException
		    exceptionWithHost: _host
			  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
			   recordType: 0



				error: OF_DNS_RESOLVER_ERROR_UNKNOWN];


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







|
|
|
|
|
>
>
>
|
>







999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
		default:
			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)
			       exception: exception];
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594

1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629

	[_lastConfigReload release];
	_lastConfigReload = nil;

	[self of_obtainSystemConfig];
}

- (void)of_resolveHost: (OFString *)host
	   recordClass: (of_dns_resource_record_class_t)recordClass
	    recordType: (of_dns_resource_record_type_t)recordType
	      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 *domainName;
	OFDNSResolverQuery *query;

	[self of_reloadSystemConfig];

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


	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]
		  initWithHost: host
		    domainName: domainName
		   recordClass: recordClass
		    recordType: recordType
			    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);







|
<
<
|
|
|
|
|
|
|



|









>

















|
|
<
<
|
|
|
|
|
|
|







1563
1564
1565
1566
1567
1568
1569
1570


1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610


1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624

	[_lastConfigReload release];
	_lastConfigReload = nil;

	[self of_obtainSystemConfig];
}

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

	[self of_reloadSystemConfig];

	/* 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);
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
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
	    didResolveDomainName:response:exception:)])
		[delegate	resolver: resolver
		    didResolveDomainName: domainName
				response: response
			       exception: exception];
}

- (void)asyncResolveHost: (OFString *)host
		delegate: (id <OFDNSResolverDelegate>)delegate
{
	[self of_asyncResolveHost: host
		      recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
		       recordType: OF_DNS_RESOURCE_RECORD_TYPE_ALL
		      runLoopMode: of_run_loop_mode_default
			   target: self
			 selector: @selector(of_resolver:didResolveDomainName:
				       response:context:exception:)
			  context: delegate];
}

- (void)asyncResolveHost: (OFString *)host
	     recordClass: (of_dns_resource_record_class_t)recordClass
	      recordType: (of_dns_resource_record_type_t)recordType
		delegate: (id <OFDNSResolverDelegate>)delegate
{
	[self of_asyncResolveHost: host
		      recordClass: recordClass
		       recordType: recordType
		      runLoopMode: of_run_loop_mode_default
			   target: self
			 selector: @selector(of_resolver:didResolveDomainName:
				       response:context:exception:)
			  context: delegate];
}

- (void)asyncResolveHost: (OFString *)host
	     recordClass: (of_dns_resource_record_class_t)recordClass
	      recordType: (of_dns_resource_record_type_t)recordType
	     runLoopMode: (of_run_loop_mode_t)runLoopMode
		delegate: (id <OFDNSResolverDelegate>)delegate
{
	[self of_asyncResolveHost: host
		      recordClass: recordClass
		       recordType: recordType
		      runLoopMode: runLoopMode
			   target: self
			 selector: @selector(of_resolver:didResolveDomainName:

				       response:context:exception:)
			  context: delegate];
}

- (void)of_asyncResolveHost: (OFString *)host
		recordClass: (of_dns_resource_record_class_t)recordClass
		 recordType: (of_dns_resource_record_type_t)recordType
		runLoopMode: (of_run_loop_mode_t)runLoopMode
		     target: (id)target
		   selector: (SEL)selector
		    context: (id)context
{
	void *pool = objc_autoreleasePoolPush();
	OFDNSResolverSettings *settings = [[[OFDNSResolverSettings alloc]
		      initWithNameServers: _nameServers
			    searchDomains: _searchDomains
				  timeout: _timeout
			      maxAttempts: _maxAttempts
	    minNumberOfDotsInAbsoluteName: _minNumberOfDotsInAbsoluteName]
	    autorelease];

	[self of_resolveHost: host
		 recordClass: recordClass
		  recordType: recordType
		    settings: settings
	    nameServersIndex: 0
	  searchDomainsIndex: 0
		 runLoopMode: runLoopMode
		      target: target
		    selector: selector
		     context: context];

	objc_autoreleasePoolPop(pool);
}

- (void)of_sendQuery: (OFDNSResolverQuery *)query
	 runLoopMode: (of_run_loop_mode_t)runLoopMode
{







|
|

|
<
<
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|


|
<
<
|
|

|
<
<
|
|
|
>
|
|


|
<
<
|
|
|
|










|
<
<
|
|
|
|
|
|
|







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
1687
1688
1689
1690
1691
1692
1693
1694
1695
	    didResolveDomainName:response:exception:)])
		[delegate	resolver: resolver
		    didResolveDomainName: domainName
				response: response
			       exception: exception];
}

- (void)asyncPerformRequest: (OFDNSRequest *)request
		   delegate: (id <OFDNSResolverDelegate>)delegate
{
	[self of_asyncPerformRequest: request


			 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


			 runLoopMode: runLoopMode
			      target: self
			    selector: @selector(of_resolver:
					  didResolveDomainName:response:context:
					  exception:)
			     context: delegate];
}

- (void)of_asyncPerformRequest: (OFDNSRequest *)request


		   runLoopMode: (of_run_loop_mode_t)runLoopMode
			target: (id)target
		      selector: (SEL)selector
		       context: (id)context
{
	void *pool = objc_autoreleasePoolPush();
	OFDNSResolverSettings *settings = [[[OFDNSResolverSettings alloc]
		      initWithNameServers: _nameServers
			    searchDomains: _searchDomains
				  timeout: _timeout
			      maxAttempts: _maxAttempts
	    minNumberOfDotsInAbsoluteName: _minNumberOfDotsInAbsoluteName]
	    autorelease];

	[self of_asyncPerformRequest: request


			    settings: settings
		    nameServersIndex: 0
		  searchDomainsIndex: 0
			 runLoopMode: runLoopMode
			      target: target
			    selector: selector
			     context: context];

	objc_autoreleasePoolPop(pool);
}

- (void)of_sendQuery: (OFDNSResolverQuery *)query
	 runLoopMode: (of_run_loop_mode_t)runLoopMode
{
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
	[sock asyncSendData: query->_queryData
		   receiver: &query->_usedNameServer
		runLoopMode: runLoopMode];
}

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

	if (query == nil)
		return;

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







|







1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
	[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++;
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
				     length: BUFFER_LENGTH];
#ifdef OF_HAVE_IPV6
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket asyncReceiveIntoBuffer: _buffer
				     length: BUFFER_LENGTH];
#endif

	exception = [OFResolveHostFailedException
	    exceptionWithHost: query->_host
		  recordClass: query->_recordClass
		   recordType: query->_recordType
			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_







|
|
<
<
|







1793
1794
1795
1796
1797
1798
1799
1800
1801


1802
1803
1804
1805
1806
1807
1808
1809
				     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_
1908
1909
1910
1911
1912
1913
1914




1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
			error = OF_DNS_RESOLVER_ERROR_SERVER_FAILURE;
			break;
		case 3:
			if (query->_searchDomainsIndex + 1 <
			    query->_settings->_searchDomains.count) {
				of_run_loop_mode_t runLoopMode =
				    [OFRunLoop currentRunLoop].currentMode;





				query->_searchDomainsIndex++;

				[self of_resolveHost: query->_host
					 recordClass: query->_recordClass
					  recordType: query->_recordType
					    settings: query->_settings
				    nameServersIndex: query->_nameServersIndex
				  searchDomainsIndex: query->_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 [OFResolveHostFailedException
			    exceptionWithHost: query->_host
				  recordClass: query->_recordClass
				   recordType: query->_recordType
					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;







>
>
>
>



<
<
|
|
|
|
|
|
|
|


















|
|
<
<
|







1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891


1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919


1920
1921
1922
1923
1924
1925
1926
1927
			error = OF_DNS_RESOLVER_ERROR_SERVER_FAILURE;
			break;
		case 3:
			if (query->_searchDomainsIndex + 1 <
			    query->_settings->_searchDomains.count) {
				of_run_loop_mode_t runLoopMode =
				    [OFRunLoop currentRunLoop].currentMode;
				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;
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110



2111
2112
2113
2114
2115
2116
2117
2118
			}

			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;

				exception = [OFResolveHostFailedException
				    exceptionWithHost: host
					  recordClass: recordClass
					   recordType: recordType



						error: error];
			}
		}

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







|
<
|
|
|
>
>
>
|







2069
2070
2071
2072
2073
2074
2075
2076

2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
			}

			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
2156
2157
2158
2159
2160
2161
2162




2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179

2180
2181
2182




2183
2184
2185
2186
2187
2188
2189

2190
2191
2192
2193
2194
2195
2196
	default:
		@throw [OFInvalidArgumentException exception];
	}

#ifdef OF_HAVE_IPV6
	if (addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV6 ||
	    addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) {




		OFNumber *recordTypeNumber =
		    [OFNumber numberWithInt: OF_DNS_RESOURCE_RECORD_TYPE_AAAA];

		[self of_asyncResolveHost: host
			      recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
			       recordType: OF_DNS_RESOURCE_RECORD_TYPE_AAAA
			      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)

		[self of_asyncResolveHost: host
			      recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
			       recordType: OF_DNS_RESOURCE_RECORD_TYPE_A




			      runLoopMode: runLoopMode
				   target: context
				 selector: @selector(resolver:
					       didResolveDomainName:
					       response:context:exception:)
				  context: [OFNumber numberWithInt:
					       OF_DNS_RESOURCE_RECORD_TYPE_A]];


	objc_autoreleasePoolPop(pool);
}

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







>
>
>
>



|
<
<
|
|
|
|
|
|




|
>
|
|
|
>
>
>
>
|
|
|
|
|
|
<
>







2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142


2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167

2168
2169
2170
2171
2172
2173
2174
2175
	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


				 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
				 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)
					       addressFamily
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
	[_IPv6Socket cancelAsyncRequests];
	[_IPv6Socket release];
	_IPv6Socket = nil;
#endif

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

		exception = [OFResolveHostFailedException
		    exceptionWithHost: query->_host
			  recordClass: query->_recordClass
			   recordType: query->_recordType
				error: OF_DNS_RESOLVER_ERROR_CANCELED];

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

	[_queries removeAllObjects];

	objc_autoreleasePoolPop(pool);
}
@end







|

|
|
<
<
|










2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229


2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
	[_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

Modified src/OFDNSResponse.h from [11c8212a83] to [9eabf8af48].

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
	of_dns_response_records_t _Nullable _additionalRecords;
	OF_RESERVE_IVARS(4)
}

/*!
 * @brief The answer records of the response.
 */
@property OF_NULLABLE_PROPERTY (nonatomic, readonly)
    of_dns_response_records_t answerRecords;

/*!
 * @brief The authority records of the response.
 */
@property OF_NULLABLE_PROPERTY (nonatomic, readonly)
    of_dns_response_records_t authorityRecords;

/*!
 * @brief The additional records of the response.
 */
@property OF_NULLABLE_PROPERTY (nonatomic, readonly)
    of_dns_response_records_t additionalRecords;

/*!
 * @brief Creates a new, autoreleased OFDNSResponse.
 *
 * @param answerRecords The answer records of the response
 * @param authorityRecords The authority records of the response







|





|





|







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
	of_dns_response_records_t _Nullable _additionalRecords;
	OF_RESERVE_IVARS(4)
}

/*!
 * @brief The answer records of the response.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    of_dns_response_records_t answerRecords;

/*!
 * @brief The authority records of the response.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    of_dns_response_records_t authorityRecords;

/*!
 * @brief The additional records of the response.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    of_dns_response_records_t additionalRecords;

/*!
 * @brief Creates a new, autoreleased OFDNSResponse.
 *
 * @param answerRecords The answer records of the response
 * @param authorityRecords The authority records of the response

Modified src/OFDNSResponse.m from [5e9ff2a6f6] to [944dbcc660].

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
		return false;

	other = object;

	if (other->_answerRecords != _answerRecords &&
	    ![other->_answerRecords isEqual: _answerRecords])
		return false;

	if (other->_authorityRecords != _authorityRecords &&
	    ![other->_authorityRecords isEqual: _authorityRecords])
		return false;

	if (other->_additionalRecords != _additionalRecords &&
	    ![other->_additionalRecords isEqual: _additionalRecords])
		return false;

	return true;
}








<



<







78
79
80
81
82
83
84

85
86
87

88
89
90
91
92
93
94
		return false;

	other = object;

	if (other->_answerRecords != _answerRecords &&
	    ![other->_answerRecords isEqual: _answerRecords])
		return false;

	if (other->_authorityRecords != _authorityRecords &&
	    ![other->_authorityRecords isEqual: _authorityRecords])
		return false;

	if (other->_additionalRecords != _additionalRecords &&
	    ![other->_additionalRecords isEqual: _additionalRecords])
		return false;

	return true;
}

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	OFString *additionalRecords = [_additionalRecords.description
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	return [OFString stringWithFormat:
	    @"<OFDNSResponse:\n"
	    @"\tAnswer records = %@\n"
	    @"\tAuthority records = %@\n"
	    @"\tAdditional records = %@\n"
	    @">",
	    answerRecords, authorityRecords, additionalRecords];
}
@end







|




|


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	OFString *additionalRecords = [_additionalRecords.description
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	return [OFString stringWithFormat:
	    @"<%@:\n"
	    @"\tAnswer records = %@\n"
	    @"\tAuthority records = %@\n"
	    @"\tAdditional records = %@\n"
	    @">",
	    self.className, answerRecords, authorityRecords, additionalRecords];
}
@end

Modified src/OFLHADecompressingStream.h from [f3042223df] to [e29da2420d].

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	uint16_t _codesCount, _codesReceived;
	bool _currentIsExtendedLength, _skip;
	uint8_t *_Nullable _codesLengths;
	uint16_t _length;
	uint32_t _distance;
}

@property (nonatomic, readonly) uint32_t bytesConsumed;

- (instancetype)of_initWithStream: (OFStream *)stream
		     distanceBits: (uint8_t)distanceBits
		   dictionaryBits: (uint8_t)dictionaryBits;
@end

OF_ASSUME_NONNULL_END







|







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	uint16_t _codesCount, _codesReceived;
	bool _currentIsExtendedLength, _skip;
	uint8_t *_Nullable _codesLengths;
	uint16_t _length;
	uint32_t _distance;
}

@property (readonly, nonatomic) uint32_t bytesConsumed;

- (instancetype)of_initWithStream: (OFStream *)stream
		     distanceBits: (uint8_t)distanceBits
		   dictionaryBits: (uint8_t)dictionaryBits;
@end

OF_ASSUME_NONNULL_END

Modified src/ObjFW.h from [3294117378] to [f502edafc8].

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 "OFResolveHostFailedException.h"
#endif
#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChecksumMismatchException.h"
#ifdef OF_HAVE_THREADS
# import "OFConditionBroadcastFailedException.h"
# import "OFConditionSignalFailedException.h"
# import "OFConditionStillWaitingException.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"

Modified src/exceptions/Makefile from [78ae506a77] to [2d5f98b062].

54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\

	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.m		\
	       OFResolveHostFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m	\
	       OFConditionSignalFailedException.m	\
	       OFConditionStillWaitingException.m	\
	       OFConditionWaitFailedException.m		\
	       OFThreadJoinFailedException.m		\
	       OFThreadStartFailedException.m		\
	       OFThreadStillRunningException.m







>


|
<







54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
       ${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		\
	       OFThreadJoinFailedException.m		\
	       OFThreadStartFailedException.m		\
	       OFThreadStillRunningException.m

Added 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

Added 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

Deleted src/exceptions/OFResolveHostFailedException.h version [cec0b8274f].

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
/*
 * 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 "OFDNSResolver.h"
#import "OFDNSResourceRecord.h"

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFResolveHostFailedException \
 *	  OFResolveHostFailedException.h ObjFW/OFResolveHostFailedException.h
 *
 * @brief An exception indicating the resolving a host failed.
 */
@interface OFResolveHostFailedException: OFException
{
	OFString *_host;
	of_dns_resource_record_class_t _recordClass;
	of_dns_resource_record_type_t _recordType;
	of_dns_resolver_error_t _error;
}

/*!
 * @brief The host which could not be resolved.
 */
@property (readonly, nonatomic) OFString *host;

/*!
 * @brief The class code for the resource record to resolve to.
 */
@property (readonly, nonatomic) of_dns_resource_record_class_t recordClass;

/*!
 * @brief The type code for the resource record to resolve to.
 */
@property (readonly, nonatomic) of_dns_resource_record_type_t recordType;

/*!
 * @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 host The host which could not be resolved
 * @param recordClass The class code for the resource record to resolve to
 * @param recordType The type code for the resource record to resolve to
 * @param error The error from the resolver
 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithHost: (OFString *)host
		      recordClass: (of_dns_resource_record_class_t)recordClass
		       recordType: (of_dns_resource_record_type_t)recordType
			    error: (of_dns_resolver_error_t)error;

/*!
 * @brief Initializes an already allocated address translation failed exception.
 *
 * @param host The host for which translation was requested
 * @param recordClass The class code for the resource record to resolve to
 * @param recordType The type code for the resource record to resolve to
 * @param error The error from the resolver
 * @return An initialized address translation failed exception
 */
- (instancetype)initWithHost: (OFString *)host
		 recordClass: (of_dns_resource_record_class_t)recordClass
		  recordType: (of_dns_resource_record_type_t)recordType
		       error: (of_dns_resolver_error_t)error;
@end

OF_ASSUME_NONNULL_END
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































































































































































Deleted src/exceptions/OFResolveHostFailedException.m version [5ebb9198c3].

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
/*
 * 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 "OFResolveHostFailedException.h"
#import "OFString.h"

@implementation OFResolveHostFailedException
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;
@synthesize error = _error;

+ (instancetype)exceptionWithHost: (OFString *)host
		      recordClass: (of_dns_resource_record_class_t)recordClass
		       recordType: (of_dns_resource_record_type_t)recordType
			    error: (of_dns_resolver_error_t)error
{
	return [[[self alloc] initWithHost: host
			       recordClass: recordClass
				recordType: recordType
				     error: error] autorelease];
}

- (instancetype)initWithHost: (OFString *)host
		 recordClass: (of_dns_resource_record_class_t)recordClass
		  recordType: (of_dns_resource_record_type_t)recordType
		       error: (of_dns_resolver_error_t)error
{
	self = [super init];

	@try {
		_host = [host copy];
		_recordClass = recordClass;
		_recordType = recordType;
		_error = error;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_host 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:
	    @"The host %@ could not be resolved: %@", _host, error];
}
@end
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















































































































































































































Modified utils/ofdns/OFDNS.m from [86ae145db7] to [5d1e72d5b4].

49
50
51
52
53
54
55

56
57
58
59
60
61
62
- (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;

	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;
	OFDNSRequest *request;
	OFDNSResolver *resolver;

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

96
97
98

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

	[resolver asyncResolveHost: [arguments objectAtIndex: 0]
		       recordClass: recordClass
			recordType: recordType

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

	request = [OFDNSRequest requestWithHost: [arguments objectAtIndex: 0]
				    recordClass: recordClass
				     recordType: recordType];
	[resolver asyncPerformRequest: request
			     delegate: self];
}
@end

Modified utils/ofhttp/OFHTTP.m from [03652a6d82] to [8c21bf2dad].

32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"

#import "OFConnectionFailedException.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFWriteFailedException.h"

#import "ProgressBar.h"

#define GIBIBYTE (1024 * 1024 * 1024)







>






<







32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
#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"
#import "OFUnsupportedProtocolException.h"
#import "OFWriteFailedException.h"

#import "ProgressBar.h"

#define GIBIBYTE (1024 * 1024 * 1024)
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: [OFResolveHostFailedException class]]) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

		[of_stderr writeLine:
		    OF_LOCALIZED(@"download_failed_resolve_host_failed",
		    @"%[prog]: Failed to download <%[url]>!\n"
		    @"  Failed to resolve host: %[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: [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"];

Modified utils/ofhttp/lang/de.json from [7ef06d4aaf] to [629be9f74b].

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_failed_resolve_host_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Adressauflösung 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_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",