ObjFW  Check-in [aefaa06dd1]

Overview
Comment:Add utils/ofdns
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: aefaa06dd1daf591f4d242c78159dc99d2634a2d2a5bb48673f622434484cb0b
User & Date: js on 2018-08-04 00:48:31
Other Links: manifest | tags
Context
2018-08-04
13:05
OFDNSResolver: Add support for parsing HINFOs check-in: 86e9130742 user: js tags: trunk
00:48
Add utils/ofdns check-in: aefaa06dd1 user: js tags: trunk
00:06
OFDNSResolver: Add a fallback for localhost check-in: 4671310302 user: js tags: trunk
Changes

Modified .gitignore from [2dd8f8ceb8] to [6b7c38a229].

45
46
47
48
49
50
51


52
53
54
55
tests/tests.3dsx
tests/tests.arm9
tests/tests.exe
tests/tests.nds
utils/objfw-config
utils/ofarc/ofarc
utils/ofarc/ofarc.exe


utils/ofhash/ofhash
utils/ofhash/ofhash.exe
utils/ofhttp/ofhttp
utils/ofhttp/ofhttp.exe







>
>




45
46
47
48
49
50
51
52
53
54
55
56
57
tests/tests.3dsx
tests/tests.arm9
tests/tests.exe
tests/tests.nds
utils/objfw-config
utils/ofarc/ofarc
utils/ofarc/ofarc.exe
utils/ofdns/ofdns
utils/ofdns/ofdns.exe
utils/ofhash/ofhash
utils/ofhash/ofhash.exe
utils/ofhttp/ofhttp
utils/ofhttp/ofhttp.exe

Modified configure.ac from [72c336e559] to [86aa9a8c41].

1387
1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399
1400
])

AS_IF([test x"$enable_sockets" != x"no" -a x"$enable_threads" != x"no"], [
	AC_SUBST(OFHTTPCLIENT_M, "OFHTTPClient.m")
	AC_SUBST(OFHTTPCLIENTTESTS_M, "OFHTTPClientTests.m")
	AC_SUBST(OFURLHANDLER_HTTP_M, "OFURLHandler_HTTP.m")


	AS_IF([test x"$enable_files" != x"no"], [
		AC_SUBST(OFHTTP, "ofhttp")
	])
])

AC_DEFUN([CHECK_BUILTIN_BSWAP], [
	AC_MSG_CHECKING(for __builtin_bswap$1)







>







1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
])

AS_IF([test x"$enable_sockets" != x"no" -a x"$enable_threads" != x"no"], [
	AC_SUBST(OFHTTPCLIENT_M, "OFHTTPClient.m")
	AC_SUBST(OFHTTPCLIENTTESTS_M, "OFHTTPClientTests.m")
	AC_SUBST(OFURLHANDLER_HTTP_M, "OFURLHandler_HTTP.m")

	AC_SUBST(OFDNS, "ofdns")
	AS_IF([test x"$enable_files" != x"no"], [
		AC_SUBST(OFHTTP, "ofhttp")
	])
])

AC_DEFUN([CHECK_BUILTIN_BSWAP], [
	AC_MSG_CHECKING(for __builtin_bswap$1)

Modified extra.mk.in from [b30b9951cf] to [7aaf17249f].

49
50
51
52
53
54
55

56
57
58
59
60
61
62
LOOKUP_ASM_A = @LOOKUP_ASM_A@
LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@
LOOKUP_ASM_LOOKUP_ASM_A = @LOOKUP_ASM_LOOKUP_ASM_A@
LOOKUP_ASM_LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LOOKUP_ASM_LIB_A@
MAP_LDFLAGS = @MAP_LDFLAGS@
OFARC = @OFARC@
OFBLOCKTESTS_M = @OFBLOCKTESTS_M@

OFHASH = @OFHASH@
OFHTTP = @OFHTTP@
OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@
OFHTTPCLIENT_M = @OFHTTPCLIENT_M@
OFKERNELEVENTOBSERVER_EPOLL_M = @OFKERNELEVENTOBSERVER_EPOLL_M@
OFKERNELEVENTOBSERVER_KQUEUE_M = @OFKERNELEVENTOBSERVER_KQUEUE_M@
OFKERNELEVENTOBSERVER_POLL_M = @OFKERNELEVENTOBSERVER_POLL_M@







>







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
LOOKUP_ASM_A = @LOOKUP_ASM_A@
LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@
LOOKUP_ASM_LOOKUP_ASM_A = @LOOKUP_ASM_LOOKUP_ASM_A@
LOOKUP_ASM_LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LOOKUP_ASM_LIB_A@
MAP_LDFLAGS = @MAP_LDFLAGS@
OFARC = @OFARC@
OFBLOCKTESTS_M = @OFBLOCKTESTS_M@
OFDNS = @OFDNS@
OFHASH = @OFHASH@
OFHTTP = @OFHTTP@
OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@
OFHTTPCLIENT_M = @OFHTTPCLIENT_M@
OFKERNELEVENTOBSERVER_EPOLL_M = @OFKERNELEVENTOBSERVER_EPOLL_M@
OFKERNELEVENTOBSERVER_KQUEUE_M = @OFKERNELEVENTOBSERVER_KQUEUE_M@
OFKERNELEVENTOBSERVER_POLL_M = @OFKERNELEVENTOBSERVER_POLL_M@

Modified src/OFDNSResourceRecord.h from [0348cf6ab0] to [3a8b820e6d].

446
447
448
449
450
451
452




453
454
455
456
457
#ifdef __cplusplus
extern "C" {
#endif
extern OFString *_Nonnull of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass);
extern OFString *_Nonnull of_dns_resource_record_type_to_string(
    of_dns_resource_record_type_t recordType);




#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







>
>
>
>





446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#ifdef __cplusplus
extern "C" {
#endif
extern OFString *_Nonnull of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass);
extern OFString *_Nonnull of_dns_resource_record_type_to_string(
    of_dns_resource_record_type_t recordType);
extern of_dns_resource_record_class_t of_dns_resource_record_class_parse(
    OFString *_Nonnull string);
extern of_dns_resource_record_type_t of_dns_resource_record_type_parse(
    OFString *_Nonnull string);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/OFDNSResourceRecord.m from [22eebc795b] to [1dfbf5ebc6].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
 */

#include "config.h"

#import "OFDNSResourceRecord.h"
#import "OFData.h"


#import "OFInvalidFormatException.h"

OFString *
of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass)
{
	switch (recordClass) {







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 */

#include "config.h"

#import "OFDNSResourceRecord.h"
#import "OFData.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"

OFString *
of_dns_resource_record_class_to_string(
    of_dns_resource_record_class_t recordClass)
{
	switch (recordClass) {
60
61
62
63
64
65
66




















































67
68
69
70
71
72
73
		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;
@synthesize TTL = _TTL;

- (instancetype)initWithName: (OFString *)name
		 recordClass: (of_dns_resource_record_class_t)recordClass







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







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
122
123
124
125
126
		return @"AAAA";
	case OF_DNS_RESOURCE_RECORD_TYPE_ALL:
		return @"all";
	default:
		return [OFString stringWithFormat: @"%u", recordType];
	}
}

of_dns_resource_record_class_t of_dns_resource_record_class_parse(
    OFString *string)
{
	void *pool = objc_autoreleasePoolPush();
	of_dns_resource_record_class_t recordClass;

	string = [string uppercaseString];

	if ([string isEqual: @"IN"])
		recordClass = OF_DNS_RESOURCE_RECORD_CLASS_IN;
	else
		@throw [OFInvalidArgumentException exception];

	objc_autoreleasePoolPop(pool);

	return recordClass;
}

of_dns_resource_record_type_t of_dns_resource_record_type_parse(
    OFString *string)
{
	void *pool = objc_autoreleasePoolPush();
	of_dns_resource_record_type_t recordType;

	string = [string uppercaseString];

	if ([string isEqual: @"A"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_A;
	else if ([string isEqual: @"NS"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_NS;
	else if ([string isEqual: @"CNAME"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_CNAME;
	else if ([string isEqual: @"SOA"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_SOA;
	else if ([string isEqual: @"PTR"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_PTR;
	else if ([string isEqual: @"HINFO"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_HINFO;
	else if ([string isEqual: @"MX"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_MX;
	else if ([string isEqual: @"TXT"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_TXT;
	else if ([string isEqual: @"AAAA"])
		recordType = OF_DNS_RESOURCE_RECORD_TYPE_AAAA;
	else
		@throw [OFInvalidArgumentException exception];

	objc_autoreleasePoolPop(pool);

	return recordType;
}

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

- (instancetype)initWithName: (OFString *)name
		 recordClass: (of_dns_resource_record_class_t)recordClass

Modified utils/Makefile from [a54d55eb6d] to [7b9873de4d].

1
2
3

4
5
6
7
8
9
10
include ../extra.mk

SUBDIRS += ${OFARC}	\

	   ${OFHASH}	\
	   ${OFHTTP}

include ../buildsys.mk

DISTCLEAN = objfw-config




>







1
2
3
4
5
6
7
8
9
10
11
include ../extra.mk

SUBDIRS += ${OFARC}	\
	   ${OFDNS}	\
	   ${OFHASH}	\
	   ${OFHTTP}

include ../buildsys.mk

DISTCLEAN = objfw-config

Added utils/ofdns/Makefile version [83fe6860c6].









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
include ../../extra.mk

PROG = ofdns${PROG_SUFFIX}
SRCS = OFDNS.m

include ../../buildsys.mk

PACKAGE_NAME = ofdns

${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFW_RT_DEP_LVL2}

CPPFLAGS += -I../../src					\
	    -I../../src/runtime				\
	    -I../../src/exceptions			\
	    -I../..
LIBS := -L../../src -lobjfw						\
	-L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS}	\
	${LIBS}
LD = ${OBJC}
LDFLAGS += ${LDFLAGS_RPATH}

Added utils/ofdns/OFDNS.m version [8f48efd875].







































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFDNSResolver.h"
#import "OFStdIOStream.h"

@interface OFDNS: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(OFDNS)

@implementation OFDNS
- (void)handleDNSResponse: (OFArray OF_GENERIC(OFDNSResourceRecord *) *)response
		  context: (id)context
		exception: (id)exception
{
	if (exception != nil) {
		[of_stderr writeFormat: @"Failed to resolve: %@\n", exception];
		[OFApplication terminateWithStatus: 1];
	}

	[of_stdout writeLine: [response description]];

	[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_resource_record_type_t recordType =
	    OF_DNS_RESOURCE_RECORD_TYPE_ALL;
	OFDNSResolver *resolver;

	if ([arguments count] < 1 || [arguments count] > 4) {
		[of_stderr writeFormat:
		    @"Usage: %@ host [type [class [server]]]\n",
		    [OFApplication programName]];
		[OFApplication terminateWithStatus: 1];
	}

	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]);

	if ([arguments count] >= 4)
		[resolver setNameServers:
		    [OFArray arrayWithObject: [arguments objectAtIndex: 3]]];

	[resolver asyncResolveHost: [arguments objectAtIndex: 0]
		       recordClass: recordClass
			recordType: recordType
			    target: self
			  selector: @selector(handleDNSResponse:context:
					exception:)
			   context: nil];
}
@end