ObjXMPP  Diff

Differences From Artifact [d3b6deb6f8]:

To Artifact [bed03f8f6f]:


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <openssl/rand.h>

#import "XMPPSRVLookup.h"

#import <ObjFW/OFLocalization.h>

OF_ASSUME_NONNULL_BEGIN

@interface XMPPSRVLookup ()
- (void)XMPP_lookup;
- (void)XMPP_addEntry: (XMPPSRVEntry *)item;
@end







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <openssl/rand.h>

#import "XMPPSRVLookup.h"

#import <ObjFW/OFLocale.h>

OF_ASSUME_NONNULL_BEGIN

@interface XMPPSRVLookup ()
- (void)XMPP_lookup;
- (void)XMPP_addEntry: (XMPPSRVEntry *)item;
@end
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
		if (dn_expand(ns_msg_base(handle), ns_msg_end(handle),
		    (uint8_t *)&rdata[3], buffer, NS_MAXDNAME) < 1)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

		_target = [[OFString alloc]
		    initWithCString: buffer
			   encoding: [OFLocalization encoding]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
		if (dn_expand(ns_msg_base(handle), ns_msg_end(handle),
		    (uint8_t *)&rdata[3], buffer, NS_MAXDNAME) < 1)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

		_target = [[OFString alloc]
		    initWithCString: buffer
			   encoding: [OFLocale encoding]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
221
222
223

	@try {
		int answerLen, resourceRecordCount, i;
		ns_rr resourceRecord;
		ns_msg handle;

		if (res_ninit(&_resState))
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: _domain];




		answer = [self allocMemoryWithSize: pageSize];
		answerLen = res_nsearch(&_resState, [request
		    cStringWithEncoding: [OFLocalization encoding]],
		    ns_c_in, ns_t_srv, answer, (int)pageSize);

		if ((answerLen == -1) && ((h_errno == HOST_NOT_FOUND) ||
		    (h_errno == NO_DATA)))
			return;

		if (answerLen < 1 || answerLen > pageSize)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: _domain];




		if (ns_initparse(answer, answerLen, &handle))
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: _domain];




		resourceRecordCount = ns_msg_count(handle, ns_s_an);
		for (i = 0; i < resourceRecordCount; i++) {
			if (ns_parserr(&handle, ns_s_an, i, &resourceRecord))
				continue;

			if (ns_rr_type(resourceRecord) != ns_t_srv ||







|
|
>
>
>


|
|







|
|
>
>
>


|
|
>
>
>







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
221
222
223
224
225
226
227
228
229
230
231
232

	@try {
		int answerLen, resourceRecordCount, i;
		ns_rr resourceRecord;
		ns_msg handle;

		if (res_ninit(&_resState))
			@throw [OFResolveHostFailedException
			    exceptionWithHost: _domain
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: OF_DNS_RESOURCE_RECORD_TYPE_SRV
					error: OF_DNS_RESOLVER_ERROR_UNKNOWN];

		answer = [self allocMemoryWithSize: pageSize];
		answerLen = res_nsearch(&_resState,
		    [request cStringWithEncoding: [OFLocale encoding]],
		    ns_c_in, ns_t_srv, answer, (int)pageSize);

		if ((answerLen == -1) && ((h_errno == HOST_NOT_FOUND) ||
		    (h_errno == NO_DATA)))
			return;

		if (answerLen < 1 || answerLen > pageSize)
			@throw [OFResolveHostFailedException
			    exceptionWithHost: _domain
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: OF_DNS_RESOURCE_RECORD_TYPE_SRV
					error: OF_DNS_RESOLVER_ERROR_UNKNOWN];

		if (ns_initparse(answer, answerLen, &handle))
			@throw [OFResolveHostFailedException
			    exceptionWithHost: _domain
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: OF_DNS_RESOURCE_RECORD_TYPE_SRV
					error: OF_DNS_RESOLVER_ERROR_UNKNOWN];

		resourceRecordCount = ns_msg_count(handle, ns_s_an);
		for (i = 0; i < resourceRecordCount; i++) {
			if (ns_parserr(&handle, ns_s_an, i, &resourceRecord))
				continue;

			if (ns_rr_type(resourceRecord) != ns_t_srv ||