ObjFW
OFDNSResolver.h
1 /*
2  * Copyright (c) 2008-2024 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 OFDNSResolverBufferLength 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 {
45  OFDNSResolverErrorCodeUnknown,
47  OFDNSResolverErrorCodeTimeout,
49  OFDNSResolverErrorCodeCanceled,
56  OFDNSResolverErrorCodeNoResult,
58  OFDNSResolverErrorCodeServerInvalidFormat,
60  OFDNSResolverErrorCodeServerFailure,
62  OFDNSResolverErrorCodeServerNameError,
64  OFDNSResolverErrorCodeServerNotImplemented,
66  OFDNSResolverErrorCodeServerRefused,
68  OFDNSResolverErrorCodeNoNameServer
69 } OFDNSResolverErrorCode;
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[OFDNSResolverBufferLength];
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) OFTimeInterval timeout;
169 
175 @property (nonatomic) unsigned int maxAttempts;
176 
180 @property (nonatomic) unsigned int minNumberOfDotsInAbsoluteName;
181 
185 @property (nonatomic) bool forcesTCP;
186 
192 @property (nonatomic) OFTimeInterval 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: (OFRunLoopMode)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: (OFSocketAddressFamily)addressFamily
242  delegate: (id <OFDNSResolverHostDelegate>)delegate;
243 
252 - (void)asyncResolveAddressesForHost: (OFString *)host
253  addressFamily: (OFSocketAddressFamily)addressFamily
254  runLoopMode: (OFRunLoopMode)runLoopMode
255  delegate: (id <OFDNSResolverHostDelegate>)delegate;
256 
266 - (OFData *)resolveAddressesForHost: (OFString *)host
267  addressFamily: (OFSocketAddressFamily)addressFamily;
268 
272 - (void)close;
273 @end
274 
275 OF_ASSUME_NONNULL_END
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:150
OFSocketAddressFamily
A socket address family.
Definition: OFSocket.h:103
An abstract class for storing objects in an array.
Definition: OFArray.h:105
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:38
A class representing a DNS query.
Definition: OFDNSQuery.h:31
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:34
A class for storing arbitrary data in an array.
Definition: OFData.h:42
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:80
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:43
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A class for handling strings.
Definition: OFString.h:135
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:51
A delegate for performed DNS queries.
Definition: OFDNSResolver.h:76