ObjFW  Diff

Differences From Artifact [84af245824]:

To Artifact [0a1cb7aeaf]:


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







-
-
-
-
+
+
+
+






-
+
-
-







-
-
+








@interface OFDNS: OFObject <OFApplicationDelegate, OFDNSResolverDelegate>
@end

OF_APPLICATION_DELEGATE(OFDNS)

@implementation OFDNS
-	(void)resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	      response: (OFDNSResponse *)response
	     exception: (id)exception
- (void)resolver: (OFDNSResolver *)resolver
 didPerformQuery: (OFDNSQuery *)query
	response: (OFDNSResponse *)response
       exception: (id)exception
{
	if (exception != nil) {
		[of_stderr writeFormat: @"Failed to resolve: %@\n", exception];
		[OFApplication terminateWithStatus: 1];
	}

	[of_stdout writeFormat: @"FQDN: %@\n"
	[of_stdout writeFormat: @"%@\n", response];
				@"Response: %@\n",
				domainName, response];

	[OFApplication terminate];
}

- (void)applicationDidFinishLaunching
{
	OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments];
	of_dns_resource_record_class_t recordClass =
	    OF_DNS_RESOURCE_RECORD_CLASS_ANY;
	of_dns_class_t DNSClass = OF_DNS_CLASS_ANY;
	of_dns_resource_record_type_t recordType =
	    OF_DNS_RESOURCE_RECORD_TYPE_ALL;
	OFDNSQuery *query;
	OFDNSResolver *resolver;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [[OFSandbox alloc] init];
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96



97
98
99
100
75
76
77
78
79
80
81


82
83
84
85
86
87
88
89



90
91
92
93
94
95
96







-
-
+







-
-
-
+
+
+




	resolver = [OFDNSResolver resolver];

	if (arguments.count >= 2)
		recordType = of_dns_resource_record_type_parse(
		    [arguments objectAtIndex: 1]);

	if (arguments.count >= 3)
		recordClass = of_dns_resource_record_class_parse(
		    [arguments objectAtIndex: 2]);
		DNSClass = of_dns_class_parse([arguments objectAtIndex: 2]);

	if (arguments.count >= 4) {
		resolver.configReloadInterval = 0;
		resolver.nameServers =
		    [arguments objectsInRange: of_range(3, 1)];
	}

	query = [OFDNSQuery queryWithHost: [arguments objectAtIndex: 0]
			      recordClass: recordClass
			       recordType: recordType];
	query = [OFDNSQuery queryWithDomainName: [arguments objectAtIndex: 0]
				       DNSClass: DNSClass
				     recordType: recordType];
	[resolver asyncPerformQuery: query
			   delegate: self];
}
@end