︙ | | | ︙ | |
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
@class OFArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;
/*!
* @class OFDNSResolver OFDNSResolver.h ObjFW/OFDNSResolver.h
*
* @brief A class for resolving DNS names.
*/
@interface OFDNSResolver: OFObject
{
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
@class OFArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFNumber;
@class OFUDPSocket;
/*!
* @enum of_dns_resolver_error_t OFDNSResolver.h ObjFW/OFDNSResolver.h
*
* @brief An enum describing why resolving a host failed.
*/
typedef enum of_dns_resolver_error_t {
/*! An unknown error */
OF_DNS_RESOLVER_ERROR_UNKNOWN,
/*! The query timed out */
OF_DNS_RESOLVER_ERROR_TIMEOUT,
/*! The query was canceled */
OF_DNS_RESOLVER_ERROR_CANCELED,
/*!
* No result for the specified host with the specified type and class.
*
* This is only used in situations where this is an error, e.g. when
* trying to connect to a host.
*/
OF_DNS_RESOLVER_ERROR_NO_RESULT,
/*! The server considered the query to be malformed */
OF_DNS_RESOLVER_ERROR_SERVER_INVALID_FORMAT,
/*! The server was unable to process due to an internal error */
OF_DNS_RESOLVER_ERROR_SERVER_FAILURE,
/*! 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.
*/
@interface OFDNSResolver: OFObject
{
|
︙ | | | ︙ | |
122
123
124
125
126
127
128
129
130
131
|
*/
- (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;
@end
OF_ASSUME_NONNULL_END
|
>
>
>
>
>
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
*/
- (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 Closes all sockets and cancels all ongoing requests.
*/
- (void)close;
@end
OF_ASSUME_NONNULL_END
|
︙ | | | ︙ | |
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# import "OFWindowsRegistryKey.h"
#endif
#import "OFInvalidArgumentException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#ifdef OF_WINDOWS
# define interface struct
# include <iphlpapi.h>
# undef interface
#endif
|
>
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# import "OFWindowsRegistryKey.h"
#endif
#import "OFInvalidArgumentException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFResolveHostFailedException.h"
#import "OFTruncatedDataException.h"
#ifdef OF_WINDOWS
# define interface struct
# include <iphlpapi.h>
# undef interface
#endif
|
︙ | | | ︙ | |
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
|
* - Iterate through name servers
* - Fallback to TCP
*/
@interface OFDNSResolver_context: OFObject
{
OFString *_host;
OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
size_t _nameServersIndex, _searchDomainsIndex;
OFNumber *_ID;
OFMutableData *_queryData;
id _target;
SEL _selector;
id _userContext;
}
@property (readonly, nonatomic) OFString *host;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains;
@property (nonatomic) size_t nameServersIndex;
@property (nonatomic) size_t searchDomainsIndex;
@property (readonly, nonatomic) OFNumber *ID;
@property (readonly, nonatomic) OFMutableData *queryData;
@property (readonly, nonatomic) id target;
@property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) id userContext;
- (instancetype)initWithHost: (OFString *)host
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
ID: (OFNumber *)ID
queryData: (OFMutableData *)queryData
target: (id)target
selector: (SEL)selector
userContext: (id)userContext;
@end
@interface OFDNSResolver ()
|
>
>
>
<
>
>
>
<
>
>
>
<
|
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
|
* - Iterate through name servers
* - Fallback to TCP
*/
@interface OFDNSResolver_context: OFObject
{
OFString *_host;
of_dns_resource_record_class_t _recordClass;
of_dns_resource_record_type_t _recordType;
OFNumber *_ID;
OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
size_t _nameServersIndex, _searchDomainsIndex;
OFMutableData *_queryData;
id _target;
SEL _selector;
id _userContext;
}
@property (readonly, nonatomic) OFString *host;
@property (readonly, nonatomic) of_dns_resource_record_class_t recordClass;
@property (readonly, nonatomic) of_dns_resource_record_type_t recordType;
@property (readonly, nonatomic) OFNumber *ID;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains;
@property (nonatomic) size_t nameServersIndex;
@property (nonatomic) size_t searchDomainsIndex;
@property (readonly, nonatomic) OFMutableData *queryData;
@property (readonly, nonatomic) id target;
@property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) id userContext;
- (instancetype)initWithHost: (OFString *)host
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
queryData: (OFMutableData *)queryData
target: (id)target
selector: (SEL)selector
userContext: (id)userContext;
@end
@interface OFDNSResolver ()
|
︙ | | | ︙ | |
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
initWithName: name
recordClass: recordClass
recordType: recordType
TTL: TTL] autorelease];
}
@implementation OFDNSResolver_context
@synthesize host = _host, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, ID = _ID;
@synthesize queryData = _queryData, target = _target, selector = _selector;
@synthesize userContext = _userContext;
- (instancetype)initWithHost: (OFString *)host
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
ID: (OFNumber *)ID
queryData: (OFMutableData *)queryData
target: (id)target
selector: (SEL)selector
userContext: (id)userContext
{
self = [super init];
@try {
_host = [host copy];
_nameServers = [nameServers copy];
_searchDomains = [searchDomains copy];
_ID = [ID retain];
_queryData = [queryData retain];
_target = [target retain];
_selector = selector;
_userContext = [userContext retain];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_host release];
[_nameServers release];
[_searchDomains release];
[_ID release];
[_queryData release];
[_target release];
[_userContext release];
[super dealloc];
}
@end
|
>
|
|
|
<
>
>
>
<
>
>
>
<
>
<
|
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
initWithName: name
recordClass: recordClass
recordType: recordType
TTL: TTL] autorelease];
}
@implementation OFDNSResolver_context
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;
@synthesize ID = _ID, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, queryData = _queryData;
@synthesize target = _target, selector = _selector, userContext = _userContext;
- (instancetype)initWithHost: (OFString *)host
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
queryData: (OFMutableData *)queryData
target: (id)target
selector: (SEL)selector
userContext: (id)userContext
{
self = [super init];
@try {
_host = [host copy];
_recordClass = recordClass;
_recordType = recordType;
_ID = [ID retain];
_nameServers = [nameServers copy];
_searchDomains = [searchDomains copy];
_queryData = [queryData retain];
_target = [target retain];
_selector = selector;
_userContext = [userContext retain];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_host release];
[_ID release];
[_nameServers release];
[_searchDomains release];
[_queryData release];
[_target release];
[_userContext release];
[super dealloc];
}
@end
|
︙ | | | ︙ | |
902
903
904
905
906
907
908
909
910
911
912
913
914
915
|
callback = (void (*)(id, SEL, OFArray *, id, id))
[target methodForSelector: selector];
queryData = [DNSResolverContext queryData];
@try {
const unsigned char *queryBuffer;
size_t i;
uint16_t numQuestions, numAnswers;
if (length < 12)
@throw [OFTruncatedDataException exception];
if ([queryData itemSize] != 1 || [queryData count] < 12)
@throw [OFInvalidArgumentException exception];
|
>
|
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
callback = (void (*)(id, SEL, OFArray *, id, id))
[target methodForSelector: selector];
queryData = [DNSResolverContext queryData];
@try {
const unsigned char *queryBuffer;
size_t i;
of_dns_resolver_error_t error;
uint16_t numQuestions, numAnswers;
if (length < 12)
@throw [OFTruncatedDataException exception];
if ([queryData itemSize] != 1 || [queryData count] < 12)
@throw [OFInvalidArgumentException exception];
|
︙ | | | ︙ | |
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
|
if ((buffer[2] & 0x78) != (queryBuffer[2] & 0x78))
@throw [OFInvalidServerReplyException exception];
/* TC */
if (buffer[2] & 0x02)
@throw [OFTruncatedDataException exception];
/* RA */
if ((buffer[3] & 0x80) == 0)
/* Server doesn't handle recursive queries */
/* TODO: Better exception */
@throw [OFInvalidServerReplyException exception];
/* RCODE */
switch (buffer[3] & 0x0F) {
case 0:
break;
default:
/* TODO: Better exception */
@throw [OFInvalidServerReplyException exception];
}
numQuestions = (buffer[4] << 8) | buffer[5];
numAnswers = (buffer[6] << 8) | buffer[7];
answers = [OFMutableArray arrayWithCapacity: numAnswers];
i = 12;
|
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
<
>
>
>
>
>
>
>
>
>
|
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
|
if ((buffer[2] & 0x78) != (queryBuffer[2] & 0x78))
@throw [OFInvalidServerReplyException exception];
/* TC */
if (buffer[2] & 0x02)
@throw [OFTruncatedDataException exception];
/* RCODE */
switch (buffer[3] & 0x0F) {
case 0:
break;
case 1:
error = OF_DNS_RESOLVER_ERROR_SERVER_INVALID_FORMAT;
break;
case 2:
error = OF_DNS_RESOLVER_ERROR_SERVER_FAILURE;
break;
case 3:
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: [DNSResolverContext host]
recordClass: [DNSResolverContext recordClass]
recordType: [DNSResolverContext recordType]
error: error];
numQuestions = (buffer[4] << 8) | buffer[5];
numAnswers = (buffer[6] << 8) | buffer[7];
answers = [OFMutableArray arrayWithCapacity: numAnswers];
i = 12;
|
︙ | | | ︙ | |
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
|
/* QCLASS */
tmp = OF_BSWAP16_IF_LE(recordClass);
[data addItems: &tmp
count: 2];
DNSResolverContext = [[[OFDNSResolver_context alloc]
initWithHost: host
nameServers: _nameServers
searchDomains: _searchDomains
ID: ID
queryData: data
target: target
selector: selector
userContext: context] autorelease];
[_queries setObject: DNSResolverContext
forKey: ID];
|
>
>
>
<
|
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
|
/* QCLASS */
tmp = OF_BSWAP16_IF_LE(recordClass);
[data addItems: &tmp
count: 2];
DNSResolverContext = [[[OFDNSResolver_context alloc]
initWithHost: host
recordClass: recordClass
recordType: recordType
ID: ID
nameServers: _nameServers
searchDomains: _searchDomains
queryData: data
target: target
selector: selector
userContext: context] autorelease];
[_queries setObject: DNSResolverContext
forKey: ID];
|
︙ | | | ︙ | |
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
|
context: DNSResolverContext];
objc_autoreleasePoolPop(pool);
}
- (void)close
{
[_IPv4Socket cancelAsyncRequests];
[_IPv4Socket close];
[_IPv4Socket release];
_IPv4Socket = nil;
#ifdef OF_HAVE_IPV6
[_IPv6Socket cancelAsyncRequests];
[_IPv6Socket close];
[_IPv6Socket release];
_IPv6Socket = nil;
#endif
}
@end
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
|
context: DNSResolverContext];
objc_autoreleasePoolPop(pool);
}
- (void)close
{
void *pool = objc_autoreleasePoolPush();
OFEnumerator *enumerator;
OFDNSResolver_context *DNSResolverContext;
[_IPv4Socket cancelAsyncRequests];
[_IPv4Socket close];
[_IPv4Socket release];
_IPv4Socket = nil;
#ifdef OF_HAVE_IPV6
[_IPv6Socket cancelAsyncRequests];
[_IPv6Socket close];
[_IPv6Socket release];
_IPv6Socket = nil;
#endif
enumerator = [_queries objectEnumerator];
while ((DNSResolverContext = [enumerator nextObject]) != nil) {
id target = [[[DNSResolverContext target] retain] autorelease];
SEL selector = [DNSResolverContext selector];
void (*callback)(id, SEL, OFArray *, id, id) =
(void (*)(id, SEL, OFArray *, id, id))
[target methodForSelector: selector];
OFResolveHostFailedException *exception;
exception = [OFResolveHostFailedException
exceptionWithHost: [DNSResolverContext host]
recordClass: [DNSResolverContext recordClass]
recordType: [DNSResolverContext recordType]
error: OF_DNS_RESOLVER_ERROR_CANCELED];
callback(target, selector, nil,
[DNSResolverContext userContext], exception);
}
[_queries removeAllObjects];
objc_autoreleasePoolPop(pool);
}
@end
|
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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018
* 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 "OFAddressTranslationFailedException.h"
#import "OFString.h"
#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"
#include "socket_helpers.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# include "threading.h"
static of_mutex_t mutex;
#endif
@implementation OFAddressTranslationFailedException
@synthesize host = _host;
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
+ (void)initialize
{
if (self != [OFAddressTranslationFailedException class])
return;
if (!of_mutex_new(&mutex))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
}
#endif
+ (instancetype)exceptionWithHost: (OFString *)host
{
return [[[self alloc] initWithHost: host] autorelease];
}
+ (instancetype)exceptionWithError: (int)error
{
return [[[self alloc] initWithError: error] autorelease];
}
+ (instancetype)exceptionWithHost: (OFString *)host
error: (int)error
{
return [[[self alloc] initWithHost: host
error: error] autorelease];
}
- (instancetype)init
{
return [self initWithHost: nil
error: 0];
}
- (instancetype)initWithHost: (OFString *)host
{
return [self initWithHost: host
error: 0];
}
- (instancetype)initWithError: (int)error
{
return [self initWithHost: nil
error: error];
}
- (instancetype)initWithHost: (OFString *)host
error: (int)error
{
self = [super init];
@try {
_host = [host copy];
_error = error;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_host release];
[super dealloc];
}
- (OFString *)description
{
/* FIXME: Add proper description for Win32 */
#ifndef OF_WINDOWS
if (_error == 0) {
#endif
if (_host != nil)
return [OFString stringWithFormat:
@"The host %@ could not be translated to an "
@"address!",
_host];
else
return @"An address could not be translated!";
#ifndef OF_WINDOWS
}
# ifdef HAVE_GETADDRINFO
# if defined(OF_HAVE_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO)
if (!of_mutex_lock(&mutex))
@throw [OFLockFailedException exception];
@try {
# endif
if (_host != nil)
return [OFString stringWithFormat:
@"The host %@ could not be translated to an "
@"address: %s",
_host, gai_strerror(_error)];
else
return [OFString stringWithFormat:
@"An address could not be translated: %s",
gai_strerror(_error)];
# if defined(OF_HAVE_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO)
} @finally {
if (!of_mutex_unlock(&mutex))
@throw [OFUnlockFailedException exception];
}
# endif
# else
# ifdef OF_HAVE_THREADS
if (!of_mutex_lock(&mutex))
@throw [OFLockFailedException exception];
@try {
# endif
if (_host != nil)
return [OFString stringWithFormat:
@"The host %@ could not be translated to an "
"address: %s",
_host, hstrerror(_error)];
else
return [OFString stringWithFormat:
@"An address could not be translated: %s",
hstrerror(_error)];
# ifdef OF_HAVE_THREADS
} @finally {
if (!of_mutex_unlock(&mutex))
@throw [OFUnlockFailedException exception];
}
# endif
# endif
#endif
}
@end
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
︙ | | | ︙ | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#import "resolver.h"
#import "macros.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# include "threading.h"
#endif
#import "OFAddressTranslationFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# import "OFLockFailedException.h"
# import "OFUnlockFailedException.h"
#endif
#import "socket_helpers.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;
OF_CONSTRUCTOR()
|
<
>
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#import "resolver.h"
#import "macros.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# include "threading.h"
#endif
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# import "OFLockFailedException.h"
# import "OFUnlockFailedException.h"
#endif
#import "OFResolveHostFailedException.h"
#import "socket_helpers.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;
OF_CONSTRUCTOR()
|
︙ | | | ︙ | |
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
|
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
if (!of_mutex_lock(&mutex))
@throw [OFLockFailedException exception];
@try {
# endif
int error;
if ((error = getaddrinfo([host UTF8String], portCString, &hints,
&res0)) != 0)
@throw [OFAddressTranslationFailedException
exceptionWithHost: host
error: error];
count = 0;
for (res = res0; res != NULL; res = res->ai_next)
count++;
if (count == 0) {
freeaddrinfo(res0);
@throw [OFAddressTranslationFailedException
exceptionWithHost: host];
}
if ((ret = calloc(count + 1, sizeof(*ret))) == NULL) {
freeaddrinfo(res0);
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: (count + 1) *
sizeof(*ret)];
|
<
<
|
|
|
>
>
|
|
|
>
>
>
|
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
|
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
if (!of_mutex_lock(&mutex))
@throw [OFLockFailedException exception];
@try {
# endif
if (getaddrinfo([host UTF8String], portCString, &hints,
&res0) != 0)
@throw [OFResolveHostFailedException
exceptionWithHost: host
recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
recordType: 0
error: OF_DNS_RESOLVER_ERROR_UNKNOWN];
count = 0;
for (res = res0; res != NULL; res = res->ai_next)
count++;
if (count == 0) {
freeaddrinfo(res0);
@throw [OFResolveHostFailedException
exceptionWithHost: host
recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
recordType: 0
error: OF_DNS_RESOLVER_ERROR_NO_RESULT];
}
if ((ret = calloc(count + 1, sizeof(*ret))) == NULL) {
freeaddrinfo(res0);
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: (count + 1) *
sizeof(*ret)];
|
︙ | | | ︙ | |
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
|
ret[1] = NULL;
return ret;
}
if ((he = gethostbyname((const void *)[host UTF8String])) ==
NULL || he->h_addrtype != AF_INET)
@throw [OFAddressTranslationFailedException
exceptionWithHost: host
error: h_errno];
count = 0;
for (ip = (char **)he->h_addr_list; *ip != NULL; ip++)
count++;
if (count == 0)
@throw [OFAddressTranslationFailedException
exceptionWithHost: host];
if ((ret = calloc(count + 1, sizeof(*ret))) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: (count + 1) *
sizeof(*ret)];
if ((results = malloc(count * sizeof(*results))) == NULL) {
|
|
>
>
|
|
|
>
>
>
|
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
|
ret[1] = NULL;
return ret;
}
if ((he = gethostbyname((const void *)[host UTF8String])) ==
NULL || he->h_addrtype != AF_INET)
@throw [OFResolveHostFailedException
exceptionWithHost: host
recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
recordType: 0
error: OF_DNS_RESOLVER_ERROR_UNKNOWN];
count = 0;
for (ip = (char **)he->h_addr_list; *ip != NULL; ip++)
count++;
if (count == 0)
@throw [OFResolveHostFailedException
exceptionWithHost: host
recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
recordType: 0
error: OF_DNS_RESOLVER_ERROR_NO_RESULT];
if ((ret = calloc(count + 1, sizeof(*ret))) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: (count + 1) *
sizeof(*ret)];
if ((results = malloc(count * sizeof(*results))) == NULL) {
|
︙ | | | ︙ | |
︙ | | | ︙ | |
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"
#import "OFLocale.h"
#import "OFSandbox.h"
#import "OFAddressTranslationFailedException.h"
#import "OFConnectionFailedException.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)
|
<
>
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"
#import "OFLocale.h"
#import "OFSandbox.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)
|
︙ | | | ︙ | |
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
}
- (void)client: (OFHTTPClient *)client
didEncounterException: (id)e
request: (OFHTTPRequest *)request
context: (id)context
{
if ([e isKindOfClass: [OFAddressTranslationFailedException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[of_stderr writeLine:
OF_LOCALIZED(@"download_failed_address_translation",
@"%[prog]: Failed to download <%[url]>!\n"
@" Address translation failed: %[exception]",
@"prog", [OFApplication programName],
@"url", [[request URL] string],
@"exception", e)];
} else if ([e isKindOfClass: [OFConnectionFailedException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
|
|
|
|
|
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
}
- (void)client: (OFHTTPClient *)client
didEncounterException: (id)e
request: (OFHTTPRequest *)request
context: (id)context
{
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"];
|
︙ | | | ︙ | |