ObjFW  Diff

Differences From Artifact [d423cb9874]:

To Artifact [d09f4dcede]:


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
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







-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
+

-
-
-
+
+
+


-
+
-
-
-
-
-
-
+
-
-
-
+




+
-
-
+
+
+
+
+
+

+
+















-
+













-
+
+

-
+












-
-
+
+














-
+
-




#include "config.h"

#import "OFDNSQuery.h"
#import "OFString.h"

@implementation OFDNSQuery
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;

@synthesize domainName = _domainName, DNSClass = _DNSClass;
@synthesize recordType = _recordType;
+ (instancetype)queryWithHost: (OFString *)host
{

	return [[[self alloc] initWithHost: host] autorelease];
}

+ (instancetype)queryWithHost: (OFString *)host
		  recordClass: (of_dns_resource_record_class_t)recordClass
		   recordType: (of_dns_resource_record_type_t)recordType
+ (instancetype)queryWithDomainName: (OFString *)domainName
			   DNSClass: (of_dns_class_t)DNSClass
			 recordType: (of_dns_resource_record_type_t)recordType
{
	return [[[self alloc] initWithHost: host
			       recordClass: recordClass
				recordType: recordType] autorelease];
	return [[[self alloc] initWithDomainName: domainName
					DNSClass: DNSClass
				      recordType: recordType] autorelease];
}

- (instancetype)initWithHost: (OFString *)host
- (instancetype)initWithDomainName: (OFString *)domainName
{
	return [self initWithHost: host
		      recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
		       recordType: OF_DNS_RESOURCE_RECORD_TYPE_ALL];
}

			  DNSClass: (of_dns_class_t)DNSClass
- (instancetype)initWithHost: (OFString *)host
		 recordClass: (of_dns_resource_record_class_t)recordClass
		  recordType: (of_dns_resource_record_type_t)recordType
			recordType: (of_dns_resource_record_type_t)recordType
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		_host = [host copy];
		_recordClass = recordClass;

		if (![domainName hasSuffix: @"."])
			domainName = [domainName stringByAppendingString: @"."];

		_domainName = [domainName copy];
		_DNSClass = DNSClass;
		_recordType = recordType;

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_host release];
	[_domainName release];

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFDNSQuery *query;

	if (![object isKindOfClass: [OFDNSQuery class]])
		return false;

	query = object;

	if (query->_host != _host && ![query->_host isEqual: _host])
	if (query->_domainName != _domainName &&
	    ![query->_domainName isEqual: _domainName])
		return false;
	if (query->_recordClass != _recordClass)
	if (query->_DNSClass != _DNSClass)
		return false;
	if (query->_recordType != _recordType)
		return false;

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);
	OF_HASH_ADD_HASH(hash, _host.hash);
	OF_HASH_ADD(hash, _recordClass);
	OF_HASH_ADD_HASH(hash, _domainName.hash);
	OF_HASH_ADD(hash, _DNSClass);
	OF_HASH_ADD(hash, _recordType);
	OF_HASH_FINALIZE(hash);

	return hash;
}

- (id)copy
{
	return [self retain];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@ %@ %@ %@>",
	    self.className, _host,
	    self.className, _domainName, of_dns_class_to_string(_DNSClass),
	    of_dns_resource_record_class_to_string(_recordClass),
	    of_dns_resource_record_type_to_string(_recordType)];
}
@end