ObjFW  Diff

Differences From Artifact [7f7fd809d0]:

To Artifact [4b3c509e3e]:


246
247
248
249
250
251
252
253
254
255
256


257

258
259
260
261
262


263
264
265

266
267

268
269
270
271
272



273
274
275
276
277



278
279
280


281
282
283


284
285
286
287
288



289
290
291
292
293




294
295

296
297
298
299


300
301
302
303
304



305
306
307
308
309




310
311
312


313
314
315


316
317
318
319
320



321
322
323
324
325
326









327
328
329

330
331

332
333
334


335
336
337


338
339
340

341
342
343
344
345

346
347
348
349



350
351
352
353



354
355
356
357
358
359
360









361
362

363
364
365


366
367
368
369
370
371
372
373

374
375
376
377
378
379

380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
246
247
248
249
250
251
252




253
254

255
256




257
258

259

260


261

262



263
264
265





266
267
268



269
270
271


272
273

274



275
276
277





278
279
280
281


282
283
284


285
286

287



288
289
290





291
292
293
294



295
296
297


298
299

300



301
302
303






304
305
306
307
308
309
310
311
312

313

314
315

316



317
318
319


320
321

322

323
324
325

326

327
328



329
330
331
332



333
334
335







336
337
338
339
340
341
342
343
344
345

346
347


348
349








350






351


352



353
354
355
356

357

358
359
360
361
362
363
364







-
-
-
-
+
+
-
+

-
-
-
-
+
+
-

-
+
-
-
+
-

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

-
-
+
+
-

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


-
-
+
+
-

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

-
-
+
+
-

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

-
+

-
+
-
-
-
+
+

-
-
+
+
-

-
+


-

-
+

-
-
-
+
+
+

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

-
+

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




-

-







}

static OF_KINDOF(OFDNSResourceRecord *)
createResourceRecord(OFString *name, of_dns_resource_record_class_t recordClass,
    of_dns_resource_record_type_t recordType, uint32_t TTL,
    const unsigned char *buffer, size_t length, size_t i, size_t dataLength)
{
	uint16_t preference;
	id data;

	if (recordClass == OF_DNS_RESOURCE_RECORD_CLASS_IN) {
	if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_A &&
	    recordClass == OF_DNS_RESOURCE_RECORD_CLASS_IN) {
		size_t j;
		OFString *address;

		switch (recordType) {
		case OF_DNS_RESOURCE_RECORD_TYPE_A:
			if (dataLength != 4)
				@throw [OFInvalidServerReplyException
		if (dataLength != 4)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			data = [OFString stringWithFormat:
		address = [OFString stringWithFormat: @"%u.%u.%u.%u",
			    @"%u.%u.%u.%u",
			    buffer[i], buffer[i + 1],
		    buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3]];
			    buffer[i + 2], buffer[i + 3]];

			return [[[OFADNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
		return [[[OFADNSResourceRecord alloc]
		    initWithName: name
			 address: address
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_NS:
			j = i;
			     TTL: TTL] autorelease];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_NS) {
		size_t j = i;

			data = parseName(buffer, length, &j,
			    ALLOWED_POINTER_LEVELS);
		OFString *authoritativeHost = parseName(buffer, length, &j,
		    ALLOWED_POINTER_LEVELS);

			if (j != i + dataLength)
				@throw [OFInvalidServerReplyException
		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			return [[[OFNSDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
		return [[[OFNSDNSResourceRecord alloc]
			 initWithName: name
			  recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_CNAME:
			j = i;
		    authoritativeHost: authoritativeHost
				  TTL: TTL] autorelease];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_CNAME) {
		size_t j = i;

			data = parseName(buffer, length, &j,
		OFString *alias = parseName(buffer, length, &j,
			    ALLOWED_POINTER_LEVELS);

			if (j != i + dataLength)
				@throw [OFInvalidServerReplyException
		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			return [[[OFCNAMEDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
		return [[[OFCNAMEDNSResourceRecord alloc]
		    initWithName: name
		     recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_PTR:
			j = i;
			   alias: alias
			     TTL: TTL] autorelease];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_PTR) {
		size_t j = i;

			data = parseName(buffer, length, &j,
			    ALLOWED_POINTER_LEVELS);
		OFString *domainName = parseName(buffer, length, &j,
		    ALLOWED_POINTER_LEVELS);

			if (j != i + dataLength)
				@throw [OFInvalidServerReplyException
		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			return [[[OFPTRDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
		return [[[OFPTRDNSResourceRecord alloc]
		    initWithName: name
		     recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_MX:
			if (dataLength < 2)
				@throw [OFInvalidServerReplyException
		      domainName: domainName
			     TTL: TTL] autorelease];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_MX) {
		uint16_t preference;
		size_t j;
		OFString *mailExchange;

		if (dataLength < 2)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			preference = (buffer[i] << 8) | buffer[i + 1];
		preference = (buffer[i] << 8) | buffer[i + 1];

			j = i + 2;
		j = i + 2;

			data = parseName(buffer, length, &j,
			    ALLOWED_POINTER_LEVELS);
		mailExchange = parseName(buffer, length, &j,
		    ALLOWED_POINTER_LEVELS);

			if (j != i + dataLength)
				@throw [OFInvalidServerReplyException
		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
				    exception];

			return [[[OFMXDNSResourceRecord alloc]
		return [[[OFMXDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
			      recordType: recordType
			      preference: preference
				    data: data
			    mailExchange: mailExchange
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_TXT:
			data = [OFData dataWithItems: &buffer[i]
					       count: dataLength];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_TXT) {
		OFData *textData = [OFData dataWithItems: &buffer[i]
						   count: dataLength];

			return [[[OFTXTDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
		return [[[OFTXTDNSResourceRecord alloc]
		    initWithName: name
		     recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		case OF_DNS_RESOURCE_RECORD_TYPE_AAAA:
			if (dataLength != 16)
				@throw [OFInvalidServerReplyException
				    exception];
			textData: textData
			     TTL: TTL] autorelease];
	} else if (recordType == OF_DNS_RESOURCE_RECORD_TYPE_AAAA &&
	    recordClass == OF_DNS_RESOURCE_RECORD_CLASS_IN) {
		OFString *address;

		if (dataLength != 16)
			@throw [OFInvalidServerReplyException
			    exception];

			data = parseAAAAData(&buffer[i]);
		address = parseAAAAData(&buffer[i]);

			return [[[OFAAAADNSResourceRecord alloc]
			    initWithName: name
		return [[[OFAAAADNSResourceRecord alloc]
		    initWithName: name
			     recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
		default:
			data = [OFData dataWithItems: &buffer[i]
					       count: dataLength];

			 address: address
			return [[[OFDNSResourceRecord alloc]
			    initWithName: name
			     recordClass: recordClass
			      recordType: recordType
				    data: data
				     TTL: TTL] autorelease];
			     TTL: TTL] autorelease];
		}
	} else {
	} else
		data = [OFData dataWithItems: &buffer[i]
				       count: dataLength];

		return [[[OFDNSResourceRecord alloc]
		    initWithName: name
		     recordClass: recordClass
		      recordType: recordType
			    data: data
			     TTL: TTL] autorelease];
	}
}

@implementation OFDNSResolver_context
@synthesize host = _host, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, queryData = _queryData;