ObjFW  Diff

Differences From Artifact [3471ccf224]:

To Artifact [83d8704f5a]:

  • File src/OFDNSResolver.h — part of check-in [0afb04d93c] at 2018-12-22 00:29:42 on branch trunk — OFDNSResolver: Use a delegate for async operations

    Because there is usually only one resolver per thread, having the
    delegate as a property on the resolver would not work. It is therefore
    passed as an argument.

    This only changes the public API so far. Internally, the old target /
    selector / context pattern is still being used. This will be changed
    later. (user: js, size: 9700) [annotate] [blame] [check-ins using]


21
22
23
24
25
26
27

28
29
30
31
32
33
34
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

#define OF_DNS_RESOLVER_BUFFER_LENGTH 512

@class OFArray OF_GENERIC(ObjectType);

@class OFDNSResolverQuery;
@class OFDate;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;








>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

#define OF_DNS_RESOLVER_BUFFER_LENGTH 512

@class OFArray OF_GENERIC(ObjectType);
@class OFDNSResolver;
@class OFDNSResolverQuery;
@class OFDate;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;

58
59
60
61
62
63
64















































65
66
67
68
69
70
71
	/*! The server returned an error that the domain does not exist */
	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;
















































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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
	/*! The server returned an error that the domain does not exist */
	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
 *
 * @brief A delegate for OFDNSResolver.
 */
@protocol OFDNSResolverDelegate <OFObject>
@optional
/*!
 * @brief This method is called when a DNS resolver resolved a domain name.
 *
 * @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
 *			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
      authorityRecords: (nullable of_dns_resolver_records_t)authorityRecords
     additionalRecords: (nullable of_dns_resolver_records_t)additionalRecords
	     exception: (nullable id)exception;

/*!
 * @brief This method is called when a DNS resolver resolved a domain name to
 *	  socket 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 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;
@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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
 */
- (instancetype)init;

/*!
 * @brief Asynchronously resolves the specified host.
 *
 * @param host The host to resolve
 * @param target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable answerRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable authorityRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable additionalRecords,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `answerRecords` are the answer records from the name server,
 *		   grouped by domain name.
 *		   @n
 *		   `authorityRecords` are the authority records from the name
 *		   server, grouped by domain name.@n
 *		   `additionalRecords` are additional records sent by the name
 *		   server, grouped by domain name.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveHost: (OFString *)host
		  target: (id)target
		selector: (SEL)selector
		 context: (nullable id)context;

/*!
 * @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 target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable answerRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable authorityRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable additionalRecords,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `answerRecords` are the answer records from the name server,
 *		   grouped by domain name.
 *		   @n
 *		   `authorityRecords` are the authority records from the name
 *		   server, grouped by domain name.@n
 *		   `additionalRecords` are additional records sent by the name
 *		   server, grouped by domain name.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveHost: (OFString *)host
	     recordClass: (of_dns_resource_record_class_t)recordClass
	      recordType: (of_dns_resource_record_type_t)recordType
		  target: (id)target
		selector: (SEL)selector
		 context: (nullable id)context;

/*!
 * @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 target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable answerRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable authorityRecords,
 *		           OFArray<OFDictionary<OFString *,
 *		           __kindof OFDNSResourceRecord *> *>
 *		           *_Nullable additionalRecords,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `answerRecords` are the answer records from the name server,
 *		   grouped by domain name.
 *		   @n
 *		   `authorityRecords` are the authority records from the name
 *		   server, grouped by domain name.@n
 *		   `additionalRecords` are additional records sent by the name
 *		   server, grouped by domain name.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (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
		  target: (id)target
		selector: (SEL)selector
		 context: (nullable id)context;

/*!
 * @brief Asynchronously resolves the specified host to socket addresses.
 *
 * @param host The host to resolve
 * @param target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFData *_Nullable, socketAddresses,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `socketAddresses` is OFData containing several
 *		   of_socket_address_t.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
				    target: (id)target
				  selector: (SEL)selector
				   context: (nullable id)context;

/*!
 * @brief Asynchronously resolves the specified host to socket addresses.
 *
 * @param host The host to resolve
 * @param addressFamily The desired socket address family
 * @param target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFData *_Nullable socketAddresses,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `socketAddresses` is OFData containing several
 *		   of_socket_address_t.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
			     addressFamily: (of_socket_address_family_t)
						addressFamily
				    target: (id)target
				  selector: (SEL)selector
				   context: (nullable id)context;

/*!
 * @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 target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   the following:
 *		   @parblock
 *
 *		       void (OFDNSResolver *resolver, OFString *domainName,
 *		           OFData *_Nullable socketAddresses,
 *		           id _Nullable context, id _Nullable exception)
 *
 *		   `resolver` is the acting resolver.@n
 *		   `domainName` is the fully qualified domain name used to
 *		   resolve the host.@n
 *		   `socketAddresses` is OFData containing several
 *		   of_socket_address_t.@n
 *		   `context` is the context object originally passed.@n
 *		   `exception` is an exception that happened during resolving,
 *		   otherwise nil.
 *		   @endparblock
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
			     addressFamily: (of_socket_address_family_t)
						addressFamily
			       runLoopMode: (of_run_loop_mode_t)runLoopMode
				    target: (id)target
				  selector: (SEL)selector
				   context: (nullable id)context;

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







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


|
<
<







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




|
<
<








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





|
<
<





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


|
|
<






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




|
|
<







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





|
|
<







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
 */
- (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
 */
- (void)asyncResolveSocketAddressesForHost: (OFString *)host
				  delegate: (id <OFDNSResolverDelegate>)
						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)
						addressFamily
				  delegate: (id <OFDNSResolverDelegate>)
						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)
						addressFamily
			       runLoopMode: (of_run_loop_mode_t)runLoopMode
				  delegate: (id <OFDNSResolverDelegate>)
						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