ObjFW  Check-in [af30016cfb]

Overview
Comment:OFDNSResolver: Allow specifying query class & type
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: af30016cfb886aab82236bd65506535bdb4b799ab5514748d258339459a2c8a7
User & Date: js on 2018-07-29 19:13:06
Other Links: manifest | tags
Context
2018-07-30
00:07
OFDNSResolver: Add support for parsing AAAAs check-in: 589a3e0f13 user: js tags: trunk
2018-07-29
19:13
OFDNSResolver: Allow specifying query class & type check-in: af30016cfb user: js tags: trunk
18:38
OFDNSResolver: Add support for parsing CNAMEs check-in: 3826822733 user: js tags: trunk
Changes

Modified src/OFDNSResolver.h from [1ab5027353] to [72b67bd9be].

96
97
98
99
100
101
102



















103
104
105
106
107
 * @param selector The selector to call on the target. The signature must be
 *		   `void (OFArray<OFDNSResourceRecord *> *response, id context,
 *		   id exception)`.
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveHost: (OFString *)host
		  target: (id)target



















		selector: (SEL)selector
		 context: (nullable id)context;
@end

OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





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
 * @param selector The selector to call on the target. The signature must be
 *		   `void (OFArray<OFDNSResourceRecord *> *response, id context,
 *		   id exception)`.
 * @param context A context object to pass along to the target
 */
- (void)asyncResolveHost: (OFString *)host
		  target: (id)target
		selector: (SEL)selector
		 context: (nullable id)context;

/*!
 * @brief Asynchronously resolves the specified host.
 *
 * @param host The host to resolve
 * @param recordClass The desired class of the records to query
 * @param recordType The desired type of the records to query
 * @param target The target to call with the result once resolving is done
 * @param selector The selector to call on the target. The signature must be
 *		   `void (OFArray<OFDNSResourceRecord *> *response, id context,
 *		   id exception)`.
 * @param context A context object to pass along to the target
 */
- (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

Modified src/OFDNSResolver.m from [f87770019a] to [11b30d4761].

745
746
747
748
749
750
751















752
753
754
755
756
757
758
	return 0;
}

- (void)asyncResolveHost: (OFString *)host
		  target: (id)target
		selector: (SEL)selector
		 context: (id)context















{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *data = [OFMutableData dataWithCapacity: 512];
	OFDNSResolver_context *DNSResolverContext;
	OFNumber *ID;
	uint16_t tmp;
	OFUDPSocket *sock;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
	return 0;
}

- (void)asyncResolveHost: (OFString *)host
		  target: (id)target
		selector: (SEL)selector
		 context: (id)context
{
	[self asyncResolveHost: host
		   recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
		    recordType: OF_DNS_RESOURCE_RECORD_TYPE_ALL
			target: target
		      selector: selector
		       context: context];
}

- (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: (id)context
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *data = [OFMutableData dataWithCapacity: 512];
	OFDNSResolver_context *DNSResolverContext;
	OFNumber *ID;
	uint16_t tmp;
	OFUDPSocket *sock;
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
		length8 = (uint8_t)length;
		[data addItem: &length8];
		[data addItems: [component UTF8String]
			 count: length];
	}

	/* QTYPE */
	tmp = OF_BSWAP16_IF_LE(OF_DNS_RESOURCE_RECORD_TYPE_A);
	[data addItems: &tmp
		 count: 2];

	/* QCLASS */
	tmp = OF_BSWAP16_IF_LE(OF_DNS_RESOURCE_RECORD_CLASS_IN);
	[data addItems: &tmp
		 count: 2];

	DNSResolverContext = [[[OFDNSResolver_context alloc]
	    initWithHost: host
	     nameServers: _nameServers
	   searchDomains: _searchDomains







|




|







817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
		length8 = (uint8_t)length;
		[data addItem: &length8];
		[data addItems: [component UTF8String]
			 count: length];
	}

	/* QTYPE */
	tmp = OF_BSWAP16_IF_LE(recordType);
	[data addItems: &tmp
		 count: 2];

	/* QCLASS */
	tmp = OF_BSWAP16_IF_LE(recordClass);
	[data addItems: &tmp
		 count: 2];

	DNSResolverContext = [[[OFDNSResolver_context alloc]
	    initWithHost: host
	     nameServers: _nameServers
	   searchDomains: _searchDomains

Modified src/OFDNSResourceRecord.h from [1e61fb86ab] to [b2d773ef59].

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

@class OFData;

/*!
 * @brief The class of a DNS resource record.
 */
typedef enum {
	OF_DNS_RESOURCE_RECORD_CLASS_IN = 1

} of_dns_resource_record_class_t;

/*!
 * @brief The type of a DNS resource record.
 */
typedef enum {
	OF_DNS_RESOURCE_RECORD_TYPE_A	  = 1,
	OF_DNS_RESOURCE_RECORD_TYPE_NS	  = 2,
	OF_DNS_RESOURCE_RECORD_TYPE_CNAME = 5,
	OF_DNS_RESOURCE_RECORD_TYPE_SOA	  = 6,
	OF_DNS_RESOURCE_RECORD_TYPE_PTR	  = 12,

	OF_DNS_RESOURCE_RECORD_TYPE_MX	  = 15,
	OF_DNS_RESOURCE_RECORD_TYPE_TXT	  = 16,
	OF_DNS_RESOURCE_RECORD_TYPE_AAAA  = 28
} of_dns_resource_record_type_t;

/*!
 * @class OFDNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h
 *
 * @brief A class represenging a DNS resource record.
 */







|
>






|
|
|
|
|
>
|
|
|







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

@class OFData;

/*!
 * @brief The class of a DNS resource record.
 */
typedef enum {
	OF_DNS_RESOURCE_RECORD_CLASS_IN	 =   1,
	OF_DNS_RESOURCE_RECORD_CLASS_ANY = 255,
} of_dns_resource_record_class_t;

/*!
 * @brief The type of a DNS resource record.
 */
typedef enum {
	OF_DNS_RESOURCE_RECORD_TYPE_A	  =   1,
	OF_DNS_RESOURCE_RECORD_TYPE_NS	  =   2,
	OF_DNS_RESOURCE_RECORD_TYPE_CNAME =   5,
	OF_DNS_RESOURCE_RECORD_TYPE_SOA	  =   6,
	OF_DNS_RESOURCE_RECORD_TYPE_PTR	  =  12,
	OF_DNS_RESOURCE_RECORD_TYPE_MX	  =  15,
	OF_DNS_RESOURCE_RECORD_TYPE_TXT	  =  16,
	OF_DNS_RESOURCE_RECORD_TYPE_AAAA  =  28,
	OF_DNS_RESOURCE_RECORD_TYPE_ALL	  = 255,
} of_dns_resource_record_type_t;

/*!
 * @class OFDNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h
 *
 * @brief A class represenging a DNS resource record.
 */

Modified src/OFDNSResourceRecord.m from [1fb8ff8a93] to [9ea581e271].

25
26
27
28
29
30
31


32
33
34
35
36
37
38
OFString *
of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass)
{
	switch (recordClass) {
	case OF_DNS_RESOURCE_RECORD_CLASS_IN:
		return @"IN";


	default:
		return [OFString stringWithFormat: @"%u", recordClass];
	}
}

OFString *
of_dns_resource_record_type_to_string(of_dns_resource_record_type_t recordType)







>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
OFString *
of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass)
{
	switch (recordClass) {
	case OF_DNS_RESOURCE_RECORD_CLASS_IN:
		return @"IN";
	case OF_DNS_RESOURCE_RECORD_CLASS_ANY:
		return @"any";
	default:
		return [OFString stringWithFormat: @"%u", recordClass];
	}
}

OFString *
of_dns_resource_record_type_to_string(of_dns_resource_record_type_t recordType)
50
51
52
53
54
55
56


57
58
59
60
61
62
63
		return @"PTR";
	case OF_DNS_RESOURCE_RECORD_TYPE_MX:
		return @"MX";
	case OF_DNS_RESOURCE_RECORD_TYPE_TXT:
		return @"TXT";
	case OF_DNS_RESOURCE_RECORD_TYPE_AAAA:
		return @"AAAA";


	default:
		return [OFString stringWithFormat: @"%u", recordType];
	}
}

@implementation OFDNSResourceRecord
@synthesize name = _name, recordClass = _recordClass, recordType = _recordType;







>
>







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		return @"PTR";
	case OF_DNS_RESOURCE_RECORD_TYPE_MX:
		return @"MX";
	case OF_DNS_RESOURCE_RECORD_TYPE_TXT:
		return @"TXT";
	case OF_DNS_RESOURCE_RECORD_TYPE_AAAA:
		return @"AAAA";
	case OF_DNS_RESOURCE_RECORD_TYPE_ALL:
		return @"all";
	default:
		return [OFString stringWithFormat: @"%u", recordType];
	}
}

@implementation OFDNSResourceRecord
@synthesize name = _name, recordClass = _recordClass, recordType = _recordType;
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	return hash;
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"<OFDNSResourceRecord:\n"
	    @"\tName = %@,\n"
	    @"\tClass = %@\n"
	    @"\tType = %@\n"
	    @"\tData = %@\n"
	    @"\tTTL = %" PRIu32 "\n"
	    @">",
	    _name, of_dns_resource_record_class_to_string(_recordClass),
	    of_dns_resource_record_type_to_string(_recordType), _data, _TTL];
}
@end







|









146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	return hash;
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"<OFDNSResourceRecord:\n"
	    @"\tName = %@\n"
	    @"\tClass = %@\n"
	    @"\tType = %@\n"
	    @"\tData = %@\n"
	    @"\tTTL = %" PRIu32 "\n"
	    @">",
	    _name, of_dns_resource_record_class_to_string(_recordClass),
	    of_dns_resource_record_type_to_string(_recordType), _data, _TTL];
}
@end