ObjFW  Diff

Differences From Artifact [30c75fb63e]:

To Artifact [cebc2efbe7]:


33
34
35
36
37
38
39

40
41
42
43
44
45
46
#import "OFTimer.h"
#import "OFUDPSocket.h"
#ifdef OF_WINDOWS
# 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







>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "OFTimer.h"
#import "OFUDPSocket.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFResolveHostFailedException.h"
#import "OFTruncatedDataException.h"

#ifdef OF_WINDOWS
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
	OFString *_host, *_domainName;
	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;
	of_time_interval_t _timeout;
	unsigned int _maxRetries;
	size_t _attempt;
	id _target;
	SEL _selector;
	id _context;
	OFData *_queryData;
	OFTimer *_cancelTimer;
}

- (instancetype)initWithHost: (OFString *)host
		  domainName: (OFString *)domainName
		 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
		     timeout: (of_time_interval_t)timeout
		  maxRetries: (unsigned int)maxRetries
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context;
@end

@interface OFDNSResolver ()
- (void)of_setDefaults;







|
















|







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
	OFString *_host, *_domainName;
	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;
	of_time_interval_t _timeout;
	unsigned int _maxAttempts;
	size_t _attempt;
	id _target;
	SEL _selector;
	id _context;
	OFData *_queryData;
	OFTimer *_cancelTimer;
}

- (instancetype)initWithHost: (OFString *)host
		  domainName: (OFString *)domainName
		 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
		     timeout: (of_time_interval_t)timeout
		 maxAttempts: (unsigned int)maxAttempts
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context;
@end

@interface OFDNSResolver ()
- (void)of_setDefaults;
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
		  domainName: (OFString *)domainName
		 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
		     timeout: (of_time_interval_t)timeout
		  maxRetries: (unsigned int)maxRetries
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableData *queryData;
		uint16_t tmp;

		_host = [host copy];
		_domainName = [domainName copy];
		_recordClass = recordClass;
		_recordType = recordType;
		_ID = [ID retain];
		_nameServers = [nameServers copy];
		_searchDomains = [searchDomains copy];
		_timeout = timeout;
		_maxRetries = maxRetries;
		_target = [target retain];
		_selector = selector;
		_context = [context retain];

		queryData = [OFMutableData dataWithCapacity: 512];

		/* Header */







|



















|







530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
		  domainName: (OFString *)domainName
		 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
		     timeout: (of_time_interval_t)timeout
		 maxAttempts: (unsigned int)maxAttempts
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableData *queryData;
		uint16_t tmp;

		_host = [host copy];
		_domainName = [domainName copy];
		_recordClass = recordClass;
		_recordType = recordType;
		_ID = [ID retain];
		_nameServers = [nameServers copy];
		_searchDomains = [searchDomains copy];
		_timeout = timeout;
		_maxAttempts = maxAttempts;
		_target = [target retain];
		_selector = selector;
		_context = [context retain];

		queryData = [OFMutableData dataWithCapacity: 512];

		/* Header */
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
	[super dealloc];
}
@end

@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize timeout = _timeout, maxRetries = _maxRetries;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval;

+ (instancetype)resolver
{
	return [[[self alloc] init] autorelease];
}







|







635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
	[super dealloc];
}
@end

@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize timeout = _timeout, maxAttempts = _maxAttempts;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval;

+ (instancetype)resolver
{
	return [[[self alloc] init] autorelease];
}
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680


681
682
683
684
685
686
687

	return self;
}

- (void)of_setDefaults
{
	_timeout = 2;
	_maxRetries = 3;
	_minNumberOfDotsInAbsoluteName = 1;
	_usesTCP = false;
	_configReloadInterval = 2;
}

- (void)of_parseConfig
{
	void *pool = objc_autoreleasePoolPush();
#ifdef OF_WINDOWS
	OFString *path;
#endif



#if defined(OF_WINDOWS)
# ifdef OF_HAVE_FILES
	path = [[OFWindowsRegistryKey localMachineKey]
	    stringForValue: @"DataBasePath"
		subKeyPath: @"SYSTEM\\CurrentControlSet\\Services\\"
			    @"Tcpip\\Parameters"];







|











>
>







663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

	return self;
}

- (void)of_setDefaults
{
	_timeout = 2;
	_maxAttempts = 3;
	_minNumberOfDotsInAbsoluteName = 1;
	_usesTCP = false;
	_configReloadInterval = 2;
}

- (void)of_parseConfig
{
	void *pool = objc_autoreleasePoolPush();
#ifdef OF_WINDOWS
	OFString *path;
#endif

	[self of_setDefaults];

#if defined(OF_WINDOWS)
# ifdef OF_HAVE_FILES
	path = [[OFWindowsRegistryKey localMachineKey]
	    stringForValue: @"DataBasePath"
		subKeyPath: @"SYSTEM\\CurrentControlSet\\Services\\"
			    @"Tcpip\\Parameters"];
905
906
907
908
909
910
911

912
913
914
915
916
917
918



919




920




921

922
923


924
925
926
927
928
929
930
	_nameServers = [nameServers copy];

	objc_autoreleasePoolPop(pool);
}

- (void)of_parseResolvConfOption: (OFString *)option
{

	if ([option hasPrefix: @"ndots:"]) {
		option = [option substringWithRange:
		    of_range(6, [option length] - 6)];

		@try {
			_minNumberOfDotsInAbsoluteName =
			    (size_t)[option decimalValue];



		} @catch (id e) {




			return;




		}

	} else if ([option isEqual: @"tcp"])
		_usesTCP = true;


}
# endif
#endif

#ifdef OF_WINDOWS
- (void)of_parseNetworkParams
{







>
|
|
|

<


>
>
>
|
>
>
>
>
|
>
>
>
>
|
>
|
|
>
>







908
909
910
911
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
	_nameServers = [nameServers copy];

	objc_autoreleasePoolPop(pool);
}

- (void)of_parseResolvConfOption: (OFString *)option
{
	@try {
		if ([option hasPrefix: @"ndots:"]) {
			option = [option substringWithRange:
			    of_range(6, [option length] - 6)];


			_minNumberOfDotsInAbsoluteName =
			    (size_t)[option decimalValue];
		} else if ([option hasPrefix: @"timeout:"]) {
			option = [option substringWithRange:
			    of_range(8, [option length] - 8)];

			_timeout = [option decimalValue];
		} else if ([option hasPrefix: @"attempts:"]) {
			option = [option substringWithRange:
			    of_range(9, [option length] - 9)];

			_maxAttempts = (unsigned int)[option decimalValue];
		} else if ([option hasPrefix: @"reload-period:"]) {
			option = [option substringWithRange:
			    of_range(14, [option length] - 14)];

			_configReloadInterval = [option decimalValue];
		} else if ([option isEqual: @"tcp"])
			_usesTCP = true;
	} @catch (OFInvalidFormatException *e) {
	}
}
# endif
#endif

#ifdef OF_WINDOWS
- (void)of_parseNetworkParams
{
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
	      domainName: domainName
	     recordClass: recordClass
	      recordType: recordType
		      ID: ID
	     nameServers: _nameServers
	   searchDomains: _searchDomains
		 timeout: _timeout
	      maxRetries: _maxRetries
		  target: target
		selector: selector
		 context: context] autorelease];
	[_queries setObject: query
		     forKey: ID];

	[self of_sendQuery: query];







|







1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
	      domainName: domainName
	     recordClass: recordClass
	      recordType: recordType
		      ID: ID
	     nameServers: _nameServers
	   searchDomains: _searchDomains
		 timeout: _timeout
	     maxAttempts: _maxAttempts
		  target: target
		selector: selector
		 context: context] autorelease];
	[_queries setObject: query
		     forKey: ID];

	[self of_sendQuery: query];
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

	if (query->_nameServersIndex + 1 < [query->_nameServers count]) {
		query->_nameServersIndex++;
		[self of_sendQuery: query];
		return;
	}

	if (query->_attempt < query->_maxRetries) {
		query->_attempt++;
		query->_nameServersIndex = 0;
		[self of_sendQuery: query];
		return;
	}

	query = [[query retain] autorelease];







|







1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152

	if (query->_nameServersIndex + 1 < [query->_nameServers count]) {
		query->_nameServersIndex++;
		[self of_sendQuery: query];
		return;
	}

	if (query->_attempt < query->_maxAttempts) {
		query->_attempt++;
		query->_nameServersIndex = 0;
		[self of_sendQuery: query];
		return;
	}

	query = [[query retain] autorelease];