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
|
* many. Since it's unspecified, we have to assume that it might happen, but we
* also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and
* immediately rejecting pointers to itself seems like a fair balance.
*/
#define MAX_ALLOWED_POINTERS 16
#define TIMEOUT 2
/*
* TODO:
*
* - Resolve with each search domain
* - Fallback to TCP
*/
@interface OFDNSResolverQuery: 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;
id _target;
SEL _selector;
id _context;
OFData *_queryData;
OFTimer *_cancelTimer;
}
@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) id target;
@property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) id context;
@property (readonly, nonatomic) OFData *queryData;
@property (retain, nonatomic) OFTimer *cancelTimer;
- (instancetype)initWithHost: (OFString *)host
|
>
>
>
|
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
|
* many. Since it's unspecified, we have to assume that it might happen, but we
* also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and
* immediately rejecting pointers to itself seems like a fair balance.
*/
#define MAX_ALLOWED_POINTERS 16
#define TIMEOUT 2
#define ATTEMPTS 3
/*
* TODO:
*
* - Resolve with each search domain
* - Fallback to TCP
*/
@interface OFDNSResolverQuery: 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;
size_t _attempt;
id _target;
SEL _selector;
id _context;
OFData *_queryData;
OFTimer *_cancelTimer;
}
@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 (nonatomic) size_t attempt;
@property (readonly, nonatomic) id target;
@property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) id context;
@property (readonly, nonatomic) OFData *queryData;
@property (retain, nonatomic) OFTimer *cancelTimer;
- (instancetype)initWithHost: (OFString *)host
|
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
}
@implementation OFDNSResolverQuery
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;
@synthesize ID = _ID, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, target = _target;
@synthesize selector = _selector, context = _context, queryData = _queryData;
@synthesize cancelTimer = _cancelTimer;
- (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
|
|
|
|
|
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
}
@implementation OFDNSResolverQuery
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;
@synthesize ID = _ID, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, attempt = _attempt;
@synthesize target = _target, selector = _selector, context = _context;
@synthesize queryData = _queryData, cancelTimer = _cancelTimer;
- (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
|
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
|
return;
if ([query nameServersIndex] + 1 < [[query nameServers] count]) {
[query setNameServersIndex: [query nameServersIndex] + 1];
[self of_sendQuery: query];
return;
}
target = [[[query target] retain] autorelease];
selector = [query selector];
callback = (void (*)(id, SEL, OFArray *, id, id))
[target methodForSelector: selector];
exception = [OFResolveHostFailedException
|
>
>
>
>
>
>
>
|
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
|
return;
if ([query nameServersIndex] + 1 < [[query nameServers] count]) {
[query setNameServersIndex: [query nameServersIndex] + 1];
[self of_sendQuery: query];
return;
}
if ([query attempt] < ATTEMPTS) {
[query setAttempt: [query attempt] + 1];
[query setNameServersIndex: 0];
[self of_sendQuery: query];
return;
}
target = [[[query target] retain] autorelease];
selector = [query selector];
callback = (void (*)(id, SEL, OFArray *, id, id))
[target methodForSelector: selector];
exception = [OFResolveHostFailedException
|