︙ | | | ︙ | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#import "OFDNSResolverSettings.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFString.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFInvalidFormatException.h"
#import "OFOpenItemFailedException.h"
|
>
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#import "OFDNSResolverSettings.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFInvalidFormatException.h"
#import "OFOpenItemFailedException.h"
|
︙ | | | ︙ | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#ifdef OF_MORPHOS
# include <proto/rexxsyslib.h>
# include <rexx/errors.h>
# include <rexx/storage.h>
#endif
#import "socket_helpers.h"
#if defined(OF_HAIKU)
# define HOSTS_PATH @"/system/settings/network/hosts"
# define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf"
#elif defined(OF_AMIGAOS4)
# define HOSTS_PATH @"DEVS:Internet/hosts"
#elif defined(OF_AMIGAOS)
# define HOSTS_PATH @"AmiTCP:db/hosts"
|
<
<
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#ifdef OF_MORPHOS
# include <proto/rexxsyslib.h>
# include <rexx/errors.h>
# include <rexx/storage.h>
#endif
#if defined(OF_HAIKU)
# define HOSTS_PATH @"/system/settings/network/hosts"
# define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf"
#elif defined(OF_AMIGAOS4)
# define HOSTS_PATH @"DEVS:Internet/hosts"
#elif defined(OF_AMIGAOS)
# define HOSTS_PATH @"AmiTCP:db/hosts"
|
︙ | | | ︙ | |
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
|
static OFString *
domainFromHostname(OFString *hostname)
{
if (hostname == nil)
return nil;
@try {
of_socket_address_parse_ip(hostname, 0);
/*
* If we are still here, the host name is a valid IP address.
* We can't use that as local domain.
*/
return nil;
} @catch (OFInvalidFormatException *e) {
/* Not an IP address -> we can use it if it contains a dot. */
size_t pos = [hostname rangeOfString: @"."].location;
if (pos == OF_NOT_FOUND)
return nil;
return [hostname substringFromIndex: pos + 1];
}
}
#endif
|
|
|
|
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
|
static OFString *
domainFromHostname(OFString *hostname)
{
if (hostname == nil)
return nil;
@try {
OFSocketAddressParseIP(hostname, 0);
/*
* If we are still here, the host name is a valid IP address.
* We can't use that as local domain.
*/
return nil;
} @catch (OFInvalidFormatException *e) {
/* Not an IP address -> we can use it if it contains a dot. */
size_t pos = [hostname rangeOfString: @"."].location;
if (pos == OFNotFound)
return nil;
return [hostname substringFromIndex: pos + 1];
}
}
#endif
|
︙ | | | ︙ | |
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
static OFArray OF_GENERIC(OFString *) *
parseNetStackArray(OFString *string)
{
if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"])
return nil;
string = [string substringWithRange: of_range(1, string.length - 2)];
return [string componentsSeparatedByString: @"|"];
}
#endif
@implementation OFDNSResolverSettings
- (void)dealloc
|
|
|
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
static OFArray OF_GENERIC(OFString *) *
parseNetStackArray(OFString *string)
{
if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"])
return nil;
string = [string substringWithRange: OFRangeMake(1, string.length - 2)];
return [string componentsSeparatedByString: @"|"];
}
#endif
@implementation OFDNSResolverSettings
- (void)dealloc
|
︙ | | | ︙ | |
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
|
while ((line = [file readLine]) != nil) {
OFArray *components, *hosts;
size_t pos;
OFString *address;
pos = [line rangeOfString: @"#"].location;
if (pos != OF_NOT_FOUND)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OF_STRING_SKIP_EMPTY];
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
of_range(1, components.count - 1)];
for (OFString *host in hosts) {
OFMutableArray *addresses =
[staticHosts objectForKey: host];
if (addresses == nil) {
addresses = [OFMutableArray array];
|
|
|
|
|
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
|
while ((line = [file readLine]) != nil) {
OFArray *components, *hosts;
size_t pos;
OFString *address;
pos = [line rangeOfString: @"#"].location;
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OFStringSkipEmptyComponents];
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
OFRangeMake(1, components.count - 1)];
for (OFString *host in hosts) {
OFMutableArray *addresses =
[staticHosts objectForKey: host];
if (addresses == nil) {
addresses = [OFMutableArray array];
|
︙ | | | ︙ | |
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
|
while ((line = [file readLine]) != nil) {
void *pool2 = objc_autoreleasePoolPush();
size_t pos;
OFArray *components, *arguments;
OFString *option;
pos = [line indexOfCharacterFromSet: commentCharacters];
if (pos != OF_NOT_FOUND)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OF_STRING_SKIP_EMPTY];
if (components.count < 2) {
objc_autoreleasePoolPop(pool2);
continue;
}
option = components.firstObject;
arguments = [components objectsInRange:
of_range(1, components.count - 1)];
if ([option isEqual: @"nameserver"]) {
if (arguments.count != 1) {
objc_autoreleasePoolPop(pool2);
continue;
}
|
|
|
|
|
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
|
while ((line = [file readLine]) != nil) {
void *pool2 = objc_autoreleasePoolPush();
size_t pos;
OFArray *components, *arguments;
OFString *option;
pos = [line indexOfCharacterFromSet: commentCharacters];
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OFStringSkipEmptyComponents];
if (components.count < 2) {
objc_autoreleasePoolPop(pool2);
continue;
}
option = components.firstObject;
arguments = [components objectsInRange:
OFRangeMake(1, components.count - 1)];
if ([option isEqual: @"nameserver"]) {
if (arguments.count != 1) {
objc_autoreleasePoolPop(pool2);
continue;
}
|
︙ | | | ︙ | |
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
}
# endif
#endif
#ifdef OF_WINDOWS
- (void)obtainWindowsSystemConfig
{
of_string_encoding_t encoding = [OFLocale encoding];
OFMutableArray *nameServers;
/*
* We need more space than FIXED_INFO in case we have more than one
* name server, but we also want it to be properly aligned, meaning we
* can't just get a buffer of bytes. Thus, we just get space for 8.
*/
FIXED_INFO fixedInfo[8];
|
|
|
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
}
# endif
#endif
#ifdef OF_WINDOWS
- (void)obtainWindowsSystemConfig
{
OFStringEncoding encoding = [OFLocale encoding];
OFMutableArray *nameServers;
/*
* We need more space than FIXED_INFO in case we have more than one
* name server, but we also want it to be properly aligned, meaning we
* can't just get a buffer of bytes. Thus, we just get space for 8.
*/
FIXED_INFO fixedInfo[8];
|
︙ | | | ︙ | |
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
OFArray *hosts;
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
of_range(1, components.count - 1)];
for (OFString *host in hosts) {
OFMutableArray *addresses =
[staticHosts objectForKey: host];
if (addresses == nil) {
addresses = [OFMutableArray array];
|
|
|
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
OFArray *hosts;
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
OFRangeMake(1, components.count - 1)];
for (OFString *host in hosts) {
OFMutableArray *addresses =
[staticHosts objectForKey: host];
if (addresses == nil) {
addresses = [OFMutableArray array];
|
︙ | | | ︙ | |
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
}
#endif
#ifdef OF_AMIGAOS4
- (void)obtainAmigaOS4SystemConfig
{
OFMutableArray *nameServers = [OFMutableArray array];
of_string_encoding_t encoding = [OFLocale encoding];
struct List *nameServerList = ObtainDomainNameServerList();
char buffer[MAXHOSTNAMELEN];
if (nameServerList == NULL)
@throw [OFOutOfMemoryException exception];
@try {
|
|
|
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
}
#endif
#ifdef OF_AMIGAOS4
- (void)obtainAmigaOS4SystemConfig
{
OFMutableArray *nameServers = [OFMutableArray array];
OFStringEncoding encoding = [OFLocale encoding];
struct List *nameServerList = ObtainDomainNameServerList();
char buffer[MAXHOSTNAMELEN];
if (nameServerList == NULL)
@throw [OFOutOfMemoryException exception];
@try {
|
︙ | | | ︙ | |
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
* We're fine if this gets smaller in a future release (unlikely), as
* long as two entries still fit.
*/
if (optLen < sizeof(buffer.entries))
return;
for (uint_fast8_t i = 0; i < 2; i++) {
uint32_t ip = OF_BSWAP32_IF_LE(buffer.entries[i].ip.s_addr);
if (ip == 0)
continue;
[nameServers addObject: [OFString stringWithFormat:
@"%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF,
(ip >> 8) & 0xFF, ip & 0xFF]];
|
|
|
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
* We're fine if this gets smaller in a future release (unlikely), as
* long as two entries still fit.
*/
if (optLen < sizeof(buffer.entries))
return;
for (uint_fast8_t i = 0; i < 2; i++) {
uint32_t ip = OFFromBigEndian32(buffer.entries[i].ip.s_addr);
if (ip == 0)
continue;
[nameServers addObject: [OFString stringWithFormat:
@"%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF,
(ip >> 8) & 0xFF, ip & 0xFF]];
|
︙ | | | ︙ | |