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
|
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
|
+
+
-
+
+
|
* 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
#define OF_DNS_RESOLVER_BUFFER_LENGTH 512
@class OFArray OF_GENERIC(ObjectType);
@class OFDNSResolver;
@class OFDNSResolverQuery;
@class OFDNSResolverContext;
@class OFDNSResolverSettings;
@class OFDate;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;
/*!
|
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
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
|
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
-
-
-
-
+
-
+
-
+
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
|
OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR,
/*! The server does not have support for the requested query */
OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED,
/*! The server refused the query */
OF_DNS_RESOLVER_ERROR_SERVER_REFUSED
} of_dns_resolver_error_t;
typedef OFDictionary OF_GENERIC(OFString *,
OFArray OF_GENERIC(OFDNSResourceRecord *) *) *of_dns_resolver_records_t;
/*!
* @protocol OFDNSResolverDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h
* @protocol OFDNSResolverQueryDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h
*
* @brief A delegate for OFDNSResolver.
* @brief A delegate for performed DNS queries.
*/
@protocol OFDNSResolverDelegate <OFObject>
@protocol OFDNSResolverQueryDelegate <OFObject>
@optional
/*!
* @brief This method is called when a DNS resolver resolved a domain name.
* @brief This method is called when a DNS resolver performed a query.
*
* @param resolver The acting resolver
* @param domainName The fully qualified domain name used to resolve the host
* @param answerRecords The answer records from the name server, grouped by
* @param query The query performed by the resolver
* @param response The response from the DNS server, or nil on error
* domain name
* @param authorityRecords The authority records from the name server, grouped
* by domain name
* @param additionalRecords Additional records sent by the name server, grouped
* by domain name
* @param exception An exception that happened during resolving, or nil on
* success
*/
- (void)resolver: (OFDNSResolver *)resolver
didResolveDomainName: (OFString *)domainName
answerRecords: (nullable of_dns_resolver_records_t)answerRecords
- (void)resolver: (OFDNSResolver *)resolver
didPerformQuery: (OFDNSQuery *)query
response: (nullable OFDNSResponse *)response
authorityRecords: (nullable of_dns_resolver_records_t)authorityRecords
additionalRecords: (nullable of_dns_resolver_records_t)additionalRecords
exception: (nullable id)exception;
exception: (nullable id)exception;
@end
/*!
* @protocol OFDNSResolverQueryDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h
*
* @brief A delegate for resolved hosts.
*/
@protocol OFDNSResolverHostDelegate <OFObject>
/*!
* @brief This method is called when a DNS resolver resolved a domain name to
* socket addresses.
* @brief This method is called when a DNS resolver resolved a host to
* addresses.
*
* @param resolver The acting resolver
* @param domainName The fully qualified domain name used to resolve the host
* @param socketAddresses OFData containing several of_socket_address_t
* @param host The host the resolver resolved
* @param addresses OFData containing several of_socket_address_t
* @param exception The exception that occurred during resolving, or nil on
* success
*/
- (void)resolver: (OFDNSResolver *)resolver
didResolveDomainName: (OFString *)domainName
socketAddresses: (nullable OFData *)socketAddresses
exception: (nullable id)exception;
- (void)resolver: (OFDNSResolver *)resolver
didResolveHost: (OFString *)host
addresses: (nullable OFData *)addresses
exception: (nullable id)exception;
@end
/*!
* @class OFDNSResolver OFDNSResolver.h ObjFW/OFDNSResolver.h
*
* @brief A class for resolving DNS names.
*
* @note If you change any of the properties, make sure to set
* @ref configReloadInterval to 0, as otherwise your changes will be
* reverted back to the system configuration on the next periodic config
* reload.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFDNSResolver: OFObject
{
OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *)
*_staticHosts;
OFDNSResolverSettings *_settings;
OFArray OF_GENERIC(OFString *) *_nameServers;
OFString *_Nullable _localDomain;
OFArray OF_GENERIC(OFString *) *_searchDomains;
of_time_interval_t _timeout;
unsigned int _maxAttempts, _minNumberOfDotsInAbsoluteName;
bool _usesTCP;
of_time_interval_t _configReloadInterval;
OFDate *_lastConfigReload;
OFUDPSocket *_IPv4Socket;
#ifdef OF_HAVE_IPV6
OFUDPSocket *_IPv6Socket;
#endif
char _buffer[OF_DNS_RESOLVER_BUFFER_LENGTH];
OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverQuery *)
OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverContext *)
*_queries;
}
/*!
* @brief A dictionary of static hosts.
*
* This dictionary is checked before actually looking up a host.
|
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
-
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+
|
/*!
* @brief Initializes an already allocated OFDNSResolver.
*/
- (instancetype)init;
/*!
* @brief Asynchronously resolves the specified host.
* @brief Asynchronously performs the specified query.
*
* @param host The host to resolve
* @param query The query to perform
* @param delegate The delegate to use for callbacks
*/
- (void)asyncResolveHost: (OFString *)host
delegate: (id <OFDNSResolverDelegate>)delegate;
- (void)asyncPerformQuery: (OFDNSQuery *)query
delegate: (id <OFDNSResolverQueryDelegate>)delegate;
/*!
* @brief Asynchronously resolves the specified host.
* @brief Asynchronously performs the specified query.
*
* @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;
* @param query The query to perform
/*!
* @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
- (void)asyncPerformQuery: (OFDNSQuery *)query
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;
runLoopMode: (of_run_loop_mode_t)runLoopMode
delegate: (id <OFDNSResolverQueryDelegate>)delegate;
/*!
* @brief Asynchronously resolves the specified host to socket addresses.
*
* @param host The host to resolve
* @param delegate The delegate to use for callbacks
*/
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
delegate: (id <OFDNSResolverDelegate>)
- (void)asyncResolveAddressesForHost: (OFString *)host
delegate: (id <OFDNSResolverHostDelegate>)delegate;
delegate;
/*!
* @brief Asynchronously resolves the specified host to socket addresses.
*
* @param host The host to resolve
* @param addressFamily The desired socket address family
* @param delegate The delegate to use for callbacks
*/
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)
- (void)asyncResolveAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)addressFamily
addressFamily
delegate: (id <OFDNSResolverDelegate>)
delegate: (id <OFDNSResolverHostDelegate>)delegate;
delegate;
/*!
* @brief Asynchronously resolves the specified host to socket addresses.
*
* @param host The host to resolve
* @param addressFamily The desired socket address family
* @param runLoopMode The run loop mode in which to resolve
* @param delegate The delegate to use for callbacks
*/
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)
- (void)asyncResolveAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)addressFamily
addressFamily
runLoopMode: (of_run_loop_mode_t)runLoopMode
delegate: (id <OFDNSResolverDelegate>)
runLoopMode: (of_run_loop_mode_t)runLoopMode
delegate: (id <OFDNSResolverHostDelegate>)delegate;
delegate;
/*!
* @brief Synchronously resolves the specified host to socket addresses.
*
* @param host The host to resolve
* @param addressFamily The desired socket address family
* @return OFData containing several of_socket_address_t
*/
- (OFData *)resolveSocketAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)
- (OFData *)resolveAddressesForHost: (OFString *)host
addressFamily: (of_socket_address_family_t)addressFamily;
addressFamily;
/*!
* @brief Closes all sockets and cancels all ongoing requests.
* @brief Closes all sockets and cancels all ongoing queries.
*/
- (void)close;
@end
OF_ASSUME_NONNULL_END
|