ObjFW
OFDNSResolver.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFDNSQuery.h"
18 #import "OFDNSResourceRecord.h"
19 #import "OFDNSResponse.h"
20 #import "OFRunLoop.h"
21 #import "OFString.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
25 #define OF_DNS_RESOLVER_BUFFER_LENGTH 512
26 
27 @class OFArray OF_GENERIC(ObjectType);
28 @class OFDNSResolver;
29 @class OFDNSResolverContext;
30 @class OFDNSResolverSettings;
31 @class OFDate;
32 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
33 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
34 @class OFNumber;
35 @class OFTCPSocket;
36 @class OFUDPSocket;
37 
43 typedef enum of_dns_resolver_error_t {
45  OF_DNS_RESOLVER_ERROR_UNKNOWN,
47  OF_DNS_RESOLVER_ERROR_TIMEOUT,
49  OF_DNS_RESOLVER_ERROR_CANCELED,
56  OF_DNS_RESOLVER_ERROR_NO_RESULT,
58  OF_DNS_RESOLVER_ERROR_SERVER_INVALID_FORMAT,
60  OF_DNS_RESOLVER_ERROR_SERVER_FAILURE,
62  OF_DNS_RESOLVER_ERROR_SERVER_NAME_ERROR,
64  OF_DNS_RESOLVER_ERROR_SERVER_NOT_IMPLEMENTED,
66  OF_DNS_RESOLVER_ERROR_SERVER_REFUSED,
68  OF_DNS_RESOLVER_ERROR_NO_NAME_SERVER
69 } of_dns_resolver_error_t;
70 
86 - (void)resolver: (OFDNSResolver *)resolver
87  didPerformQuery: (OFDNSQuery *)query
88  response: (nullable OFDNSResponse *)response
89  exception: (nullable id)exception;
90 @end
91 
97 @protocol OFDNSResolverHostDelegate <OFObject>
108 - (void)resolver: (OFDNSResolver *)resolver
109  didResolveHost: (OFString *)host
110  addresses: (nullable OFData *)addresses
111  exception: (nullable id)exception;
112 @end
113 
124 OF_SUBCLASSING_RESTRICTED
126 {
127  OFDNSResolverSettings *_settings;
128  OFUDPSocket *_IPv4Socket;
129 #ifdef OF_HAVE_IPV6
130  OFUDPSocket *_IPv6Socket;
131 #endif
132  char _buffer[OF_DNS_RESOLVER_BUFFER_LENGTH];
133  OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverContext *)
134  *_queries;
135  OFMutableDictionary OF_GENERIC(OFTCPSocket *, OFDNSResolverContext *)
136  *_TCPQueries;
137 }
138 
144 @property (copy, nonatomic) OFDictionary OF_GENERIC(OFString *,
145  OFArray OF_GENERIC(OFString *) *) *staticHosts;
146 
152 @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers;
153 
157 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *localDomain;
158 
162 @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains;
163 
168 @property (nonatomic) of_time_interval_t timeout;
169 
175 @property (nonatomic) unsigned int maxAttempts;
176 
180 @property (nonatomic) unsigned int minNumberOfDotsInAbsoluteName;
181 
185 @property (nonatomic) bool usesTCP;
186 
192 @property (nonatomic) of_time_interval_t configReloadInterval;
193 
197 + (instancetype)resolver;
198 
202 - (instancetype)init;
203 
210 - (void)asyncPerformQuery: (OFDNSQuery *)query
211  delegate: (id <OFDNSResolverQueryDelegate>)delegate;
212 
220 - (void)asyncPerformQuery: (OFDNSQuery *)query
221  runLoopMode: (of_run_loop_mode_t)runLoopMode
222  delegate: (id <OFDNSResolverQueryDelegate>)delegate;
223 
230 - (void)asyncResolveAddressesForHost: (OFString *)host
231  delegate: (id <OFDNSResolverHostDelegate>)delegate;
232 
240 - (void)asyncResolveAddressesForHost: (OFString *)host
241  addressFamily: (of_socket_address_family_t)addressFamily
242  delegate: (id <OFDNSResolverHostDelegate>)delegate;
243 
252 - (void)asyncResolveAddressesForHost: (OFString *)host
253  addressFamily: (of_socket_address_family_t)addressFamily
254  runLoopMode: (of_run_loop_mode_t)runLoopMode
255  delegate: (id <OFDNSResolverHostDelegate>)delegate;
256 
264 - (OFData *)resolveAddressesForHost: (OFString *)host
265  addressFamily: (of_socket_address_family_t)addressFamily;
266 
270 - (void)close;
271 @end
272 
273 OF_ASSUME_NONNULL_END
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:138
An abstract class for storing objects in an array.
Definition: OFArray.h:92
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class representing a DNS query.
Definition: OFDNSQuery.h:30
A class for resolving DNS names.
Definition: OFDNSResolver.h:126
OFArray * searchDomains
The domains to search for queries for short names.
Definition: OFDNSResolver.h:162
OFString * localDomain
The local domain.
Definition: OFDNSResolver.h:157
OFArray * nameServers
An array of name servers to use.
Definition: OFDNSResolver.h:152
A class storing a response from OFDNSResolver.
Definition: OFDNSResponse.h:33
A class for storing arbitrary data in an array.
Definition: OFData.h:40
A class for storing, accessing and comparing dates.
Definition: OFDate.h:36
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
Provides a way to store a number in an object.
Definition: OFNumber.h:49
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:67
A class which provides methods to create and use UDP sockets.
Definition: OFUDPSocket.h:50
A delegate for performed DNS queries.
Definition: OFDNSResolver.h:76
of_socket_address_family_t
A socket address family.
Definition: socket.h:88