Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -115,26 +115,37 @@ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFFile.m \ OFString+PathAdditions.m SRCS_PLUGINS = OFPlugin.m -SRCS_SOCKETS = OFDNSQuery.m \ +SRCS_SOCKETS = OFAAAADNSResourceRecord.m \ + OFADNSResourceRecord.m \ + OFCNAMEDNSResourceRecord.m \ + OFDNSQuery.m \ OFDNSResolver.m \ OFDNSResourceRecord.m \ OFDNSResponse.m \ OFDatagramSocket.m \ + OFHINFODNSResourceRecord.m \ OFHTTPClient.m \ OFHTTPCookie.m \ OFHTTPCookieManager.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ + OFMXDNSResourceRecord.m \ + OFNSDNSResourceRecord.m \ + OFPTRDNSResourceRecord.m \ + OFRPDNSResourceRecord.m \ + OFSOADNSResourceRecord.m \ + OFSRVDNSResourceRecord.m \ OFSequencedPacketSocket.m \ OFSocket.m \ OFStreamSocket.m \ OFSystemInfo+NetworkInterfaces.m \ OFTCPSocket.m \ + OFTXTDNSResourceRecord.m \ OFTLSStream.m \ OFUDPSocket.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} ADDED src/OFAAAADNSResourceRecord.h Index: src/OFAAAADNSResourceRecord.h ================================================================== --- src/OFAAAADNSResourceRecord.h +++ src/OFAAAADNSResourceRecord.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFAAAADNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class represenging a DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFAAAADNSResourceRecord: OFDNSResourceRecord +{ + OFSocketAddress _address; +} + +/** + * @brief The IPv6 address of the resource record. + */ +@property (readonly, nonatomic) const OFSocketAddress *address; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFAAAADNSResourceRecord with the + * specified name, class, address and time to live. + * + * @param name The name for the resource record + * @param address The address for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFAAAADNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + address: (const OFSocketAddress *)address + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFAAAADNSResourceRecord.m Index: src/OFAAAADNSResourceRecord.m ================================================================== --- src/OFAAAADNSResourceRecord.m +++ src/OFAAAADNSResourceRecord.m @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFAAAADNSResourceRecord.h" + +@implementation OFAAAADNSResourceRecord +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + address: (const OFSocketAddress *)address + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: OFDNSClassIN + recordType: OFDNSRecordTypeAAAA + TTL: TTL]; + + _address = *address; + + return self; +} + +- (const OFSocketAddress *)address +{ + return &_address; +} + +- (bool)isEqual: (id)object +{ + OFAAAADNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFAAAADNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (!OFSocketAddressEqual(&record->_address, &_address)) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, OFSocketAddressHash(&_address)); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tAddress = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFSocketAddressString(&_address), _TTL]; +} +@end ADDED src/OFADNSResourceRecord.h Index: src/OFADNSResourceRecord.h ================================================================== --- src/OFADNSResourceRecord.h +++ src/OFADNSResourceRecord.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFADNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an A DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFADNSResourceRecord: OFDNSResourceRecord +{ + OFSocketAddress _address; +} + +/** + * @brief The IPv4 address of the resource record. + */ +@property (readonly, nonatomic) const OFSocketAddress *address; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFADNSResourceRecord with the + * specified name, class, address and time to live. + * + * @param name The name for the resource record + * @param address The address for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFADNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + address: (const OFSocketAddress *)address + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFADNSResourceRecord.m Index: src/OFADNSResourceRecord.m ================================================================== --- src/OFADNSResourceRecord.m +++ src/OFADNSResourceRecord.m @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFADNSResourceRecord.h" + +@implementation OFADNSResourceRecord +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + address: (const OFSocketAddress *)address + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: OFDNSClassIN + recordType: OFDNSRecordTypeA + TTL: TTL]; + + _address = *address; + + return self; +} + +- (const OFSocketAddress *)address +{ + return &_address; +} + +- (bool)isEqual: (id)object +{ + OFADNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFADNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (!OFSocketAddressEqual(&record->_address, &_address)) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, OFSocketAddressHash(&_address)); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tAddress = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFSocketAddressString(&_address), _TTL]; +} +@end ADDED src/OFCNAMEDNSResourceRecord.h Index: src/OFCNAMEDNSResourceRecord.h ================================================================== --- src/OFCNAMEDNSResourceRecord.h +++ src/OFCNAMEDNSResourceRecord.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFCNAMEDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing a CNAME DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFCNAMEDNSResourceRecord: OFDNSResourceRecord +{ + OFString *_alias; +} + +/** + * @brief The alias of the resource record. + */ +@property (readonly, nonatomic) OFString *alias; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFCNAMEDNSResourceRecord with the + * specified name, class, alias and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param alias The alias for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFCNAMEDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + alias: (OFString *)alias + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFCNAMEDNSResourceRecord.m Index: src/OFCNAMEDNSResourceRecord.m ================================================================== --- src/OFCNAMEDNSResourceRecord.m +++ src/OFCNAMEDNSResourceRecord.m @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFCNAMEDNSResourceRecord.h" + +@implementation OFCNAMEDNSResourceRecord +@synthesize alias = _alias; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + alias: (OFString *)alias + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeCNAME + TTL: TTL]; + + @try { + _alias = [alias copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_alias release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFCNAMEDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFCNAMEDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_alias != _alias && ![record->_alias isEqual: _alias]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _alias.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tAlias = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), _alias, _TTL]; +} +@end Index: src/OFDNSResourceRecord.h ================================================================== --- src/OFDNSResourceRecord.h +++ src/OFDNSResourceRecord.h @@ -113,512 +113,10 @@ DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end -/** - * @class OFADNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an A DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFADNSResourceRecord: OFDNSResourceRecord -{ - OFSocketAddress _address; -} - -/** - * @brief The IPv4 address of the resource record. - */ -@property (readonly, nonatomic) const OFSocketAddress *address; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFADNSResourceRecord with the - * specified name, class, address and time to live. - * - * @param name The name for the resource record - * @param address The address for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFADNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - address: (const OFSocketAddress *)address - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFAAAADNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class represenging a DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFAAAADNSResourceRecord: OFDNSResourceRecord -{ - OFSocketAddress _address; -} - -/** - * @brief The IPv6 address of the resource record. - */ -@property (readonly, nonatomic) const OFSocketAddress *address; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFAAAADNSResourceRecord with the - * specified name, class, address and time to live. - * - * @param name The name for the resource record - * @param address The address for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFAAAADNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - address: (const OFSocketAddress *)address - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFCNAMEDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing a CNAME DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFCNAMEDNSResourceRecord: OFDNSResourceRecord -{ - OFString *_alias; -} - -/** - * @brief The alias of the resource record. - */ -@property (readonly, nonatomic) OFString *alias; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFCNAMEDNSResourceRecord with the - * specified name, class, alias and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param alias The alias for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFCNAMEDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - alias: (OFString *)alias - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFHINFODNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an HINFO DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFHINFODNSResourceRecord: OFDNSResourceRecord -{ - OFString *_CPU, *_OS; -} - -/** - * @brief The CPU of the host info of the resource record. - */ -@property (readonly, nonatomic) OFString *CPU; - -/** - * @brief The OS of the host info of the resource record. - */ -@property (readonly, nonatomic) OFString *OS; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFHINFODNSResourceRecord with the - * specified name, class, domain name and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param CPU The CPU of the host info for the resource record - * @param OS The OS of the host info for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFHINFODNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - CPU: (OFString *)CPU - OS: (OFString *)OS - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFMXDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an MX DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFMXDNSResourceRecord: OFDNSResourceRecord -{ - uint16_t _preference; - OFString *_mailExchange; -} - -/** - * @brief The preference of the resource record. - */ -@property (readonly, nonatomic) uint16_t preference; - -/** - * @brief The mail exchange of the resource record. - */ -@property (readonly, nonatomic) OFString *mailExchange; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFMXDNSResourceRecord with the - * specified name, class, preference, mail exchange and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param preference The preference for the resource record - * @param mailExchange The mail exchange for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFMXDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - preference: (uint16_t)preference - mailExchange: (OFString *)mailExchange - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFNSDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an NS DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFNSDNSResourceRecord: OFDNSResourceRecord -{ - OFString *_authoritativeHost; -} - -/** - * @brief The authoritative host of the resource record. - */ -@property (readonly, nonatomic) OFString *authoritativeHost; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFNSDNSResourceRecord with the - * specified name, class, authoritative host and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param authoritativeHost The authoritative host for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFNSDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - authoritativeHost: (OFString *)authoritativeHost - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFPTRDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing a PTR DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFPTRDNSResourceRecord: OFDNSResourceRecord -{ - OFString *_domainName; -} - -/** - * @brief The domain name of the resource record. - */ -@property (readonly, nonatomic) OFString *domainName; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFPTRDNSResourceRecord with the - * specified name, class, domain name and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param domainName The domain name for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFPTRDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - domainName: (OFString *)domainName - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFRPNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an RP DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFRPDNSResourceRecord: OFDNSResourceRecord -{ - OFString *_mailbox, *_TXTDomainName; -} - -/** - * @brief The mailbox of the responsible person of the resource record. - */ -@property (readonly, nonatomic) OFString *mailbox; - -/** - * @brief A domain name that contains a TXT resource record for the responsible - * person of the resource record. - */ -@property (readonly, nonatomic) OFString *TXTDomainName; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFRPDNSResourceRecord with the - * specified name, class, alias and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param mailbox The mailbox of the responsible person of the resource record - * @param TXTDomainName A domain name that contains a TXT resource record for - * the responsible person of the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFRPDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - mailbox: (OFString *)mailbox - TXTDomainName: (OFString *)TXTDomainName - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFSOADNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an SOA DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFSOADNSResourceRecord: OFDNSResourceRecord -{ - OFString *_primaryNameServer, *_responsiblePerson; - uint32_t _serialNumber, _refreshInterval, _retryInterval; - uint32_t _expirationInterval, _minTTL; -} - -/** - * @brief The the primary name server for the zone. - */ -@property (readonly, nonatomic) OFString *primaryNameServer; - -/** - * @brief The mailbox of the person responsible for the zone. - */ -@property (readonly, nonatomic) OFString *responsiblePerson; - -/** - * @brief The serial number of the original copy of the zone. - */ -@property (readonly, nonatomic) uint32_t serialNumber; - -/** - * @brief The refresh interval of the zone. - */ -@property (readonly, nonatomic) uint32_t refreshInterval; - -/** - * @brief The retry interval of the zone. - */ -@property (readonly, nonatomic) uint32_t retryInterval; - -/** - * @brief The expiration interval of the zone. - */ -@property (readonly, nonatomic) uint32_t expirationInterval; - -/** - * @brief The minimum TTL of the zone. - */ -@property (readonly, nonatomic) uint32_t minTTL; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFSOADNSResourceRecord with the - * specified name, class, text data and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param primaryNameServer The the primary name server for the zone - * @param responsiblePerson The mailbox of the person responsible for the zone - * @param serialNumber The serial number of the original copy of the zone - * @param refreshInterval The refresh interval of the zone - * @param retryInterval The retry interval of the zone - * @param expirationInterval The expiration interval of the zone - * @param minTTL The minimum TTL of the zone - * @param TTL The time to live for the resource record - * @return An initialized OFSOADNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - primaryNameServer: (OFString *)primaryNameServer - responsiblePerson: (OFString *)responsiblePerson - serialNumber: (uint32_t)serialNumber - refreshInterval: (uint32_t)refreshInterval - retryInterval: (uint32_t)retryInterval - expirationInterval: (uint32_t)expirationInterval - minTTL: (uint32_t)minTTL - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFSRVDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing an SRV DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFSRVDNSResourceRecord: OFDNSResourceRecord -{ - uint16_t _priority, _weight; - OFString *_target; - uint16_t _port; -} - -/** - * @brief The priority of the resource record. - */ -@property (readonly, nonatomic) uint16_t priority; - -/** - * @brief The weight of the resource record. - */ -@property (readonly, nonatomic) uint16_t weight; - -/** - * @brief The target of the resource record. - */ -@property (readonly, nonatomic) OFString *target; - -/** - * @brief The port on the target of the resource record. - */ -@property (readonly, nonatomic) uint16_t port; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFSRVDNSResourceRecord with the - * specified name, class, preference, mail exchange and time to live. - * - * @param name The name for the resource record - * @param priority The priority for the resource record - * @param weight The weight for the resource record - * @param target The target for the resource record - * @param port The port on the target for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFSRVDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - priority: (uint16_t)priority - weight: (uint16_t)weight - target: (OFString *)target - port: (uint16_t)port - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - -/** - * @class OFTXTDNSResourceRecord \ - * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h - * - * @brief A class representing a TXT DNS resource record. - */ -OF_SUBCLASSING_RESTRICTED -@interface OFTXTDNSResourceRecord: OFDNSResourceRecord -{ - OFArray OF_GENERIC(OFData *) *_textStrings; -} - -/** - * @brief The text of the resource record. - */ -@property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFTXTDNSResourceRecord with the - * specified name, class, text data and time to live. - * - * @param name The name for the resource record - * @param DNSClass The class code for the resource record - * @param textStrings An array of text strings for the resource record - * @param TTL The time to live for the resource record - * @return An initialized OFTXTDNSResourceRecord - */ -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings - TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; -@end - #ifdef __cplusplus extern "C" { #endif /** * @brief Returns the name for the specified OFDNSClass. @@ -656,5 +154,17 @@ #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END + +#import "OFAAAADNSResourceRecord.h" +#import "OFADNSResourceRecord.h" +#import "OFCNAMEDNSResourceRecord.h" +#import "OFHINFODNSResourceRecord.h" +#import "OFMXDNSResourceRecord.h" +#import "OFNSDNSResourceRecord.h" +#import "OFPTRDNSResourceRecord.h" +#import "OFRPDNSResourceRecord.h" +#import "OFSOADNSResourceRecord.h" +#import "OFSRVDNSResourceRecord.h" +#import "OFTXTDNSResourceRecord.h" Index: src/OFDNSResourceRecord.m ================================================================== --- src/OFDNSResourceRecord.m +++ src/OFDNSResourceRecord.m @@ -175,1201 +175,6 @@ @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), OFDNSRecordTypeName(_recordType), _TTL]; } -@end - -@implementation OFADNSResourceRecord -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - address: (const OFSocketAddress *)address - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: OFDNSClassIN - recordType: OFDNSRecordTypeA - TTL: TTL]; - - _address = *address; - - return self; -} - -- (const OFSocketAddress *)address -{ - return &_address; -} - -- (bool)isEqual: (id)object -{ - OFADNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFADNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (!OFSocketAddressEqual(&record->_address, &_address)) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, OFSocketAddressHash(&_address)); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tAddress = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFSocketAddressString(&_address), _TTL]; -} -@end - -@implementation OFAAAADNSResourceRecord -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - address: (const OFSocketAddress *)address - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: OFDNSClassIN - recordType: OFDNSRecordTypeAAAA - TTL: TTL]; - - _address = *address; - - return self; -} - -- (const OFSocketAddress *)address -{ - return &_address; -} - -- (bool)isEqual: (id)object -{ - OFAAAADNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFAAAADNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (!OFSocketAddressEqual(&record->_address, &_address)) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, OFSocketAddressHash(&_address)); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tAddress = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFSocketAddressString(&_address), _TTL]; -} -@end - -@implementation OFCNAMEDNSResourceRecord -@synthesize alias = _alias; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - alias: (OFString *)alias - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeCNAME - TTL: TTL]; - - @try { - _alias = [alias copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_alias release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFCNAMEDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFCNAMEDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_alias != _alias && ![record->_alias isEqual: _alias]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _alias.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tAlias = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), _alias, _TTL]; -} -@end - -@implementation OFHINFODNSResourceRecord -@synthesize CPU = _CPU, OS = _OS; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - CPU: (OFString *)CPU - OS: (OFString *)OS - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeHINFO - TTL: TTL]; - - @try { - _CPU = [CPU copy]; - _OS = [OS copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_CPU release]; - [_OS release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFHINFODNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFHINFODNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_CPU != _CPU && ![record->_CPU isEqual: _CPU]) - return false; - - if (record->_OS != _OS && ![record->_OS isEqual: _OS]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _CPU.hash); - OFHashAddHash(&hash, _OS.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tCPU = %@\n" - @"\tOS = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), _CPU, _OS, _TTL]; -} -@end - -@implementation OFMXDNSResourceRecord -@synthesize preference = _preference, mailExchange = _mailExchange; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - preference: (uint16_t)preference - mailExchange: (OFString *)mailExchange - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeMX - TTL: TTL]; - - @try { - _preference = preference; - _mailExchange = [mailExchange copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_mailExchange release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFMXDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFMXDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_preference != _preference) - return false; - - if (record->_mailExchange != _mailExchange && - ![record->_mailExchange isEqual: _mailExchange]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddByte(&hash, _preference >> 8); - OFHashAddByte(&hash, _preference); - OFHashAddHash(&hash, _mailExchange.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tPreference = %" PRIu16 "\n" - @"\tMail Exchange = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), _preference, - _mailExchange, _TTL]; -} -@end - -@implementation OFNSDNSResourceRecord -@synthesize authoritativeHost = _authoritativeHost; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - authoritativeHost: (OFString *)authoritativeHost - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeNS - TTL: TTL]; - - @try { - _authoritativeHost = [authoritativeHost copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_authoritativeHost release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFNSDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFNSDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_authoritativeHost != _authoritativeHost && - ![record->_authoritativeHost isEqual: _authoritativeHost]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _authoritativeHost.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tAuthoritative Host = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), - _authoritativeHost, _TTL]; -} -@end - -@implementation OFPTRDNSResourceRecord -@synthesize domainName = _domainName; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - domainName: (OFString *)domainName - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypePTR - TTL: TTL]; - - @try { - _domainName = [domainName copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_domainName release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFPTRDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFPTRDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_domainName != _domainName && - ![record->_domainName isEqual: _domainName]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _domainName.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tDomain Name = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), _domainName, - _TTL]; -} -@end - -@implementation OFRPDNSResourceRecord -@synthesize mailbox = _mailbox, TXTDomainName = _TXTDomainName; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - mailbox: (OFString *)mailbox - TXTDomainName: (OFString *)TXTDomainName - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeRP - TTL: TTL]; - - @try { - _mailbox = [mailbox copy]; - _TXTDomainName = [TXTDomainName copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_mailbox release]; - [_TXTDomainName release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFRPDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFRPDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_mailbox != _mailbox && - ![record->_mailbox isEqual: _mailbox]) - return false; - - if (record->_TXTDomainName != _TXTDomainName && - ![record->_TXTDomainName isEqual: _TXTDomainName]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _mailbox.hash); - OFHashAddHash(&hash, _TXTDomainName.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tMailbox = %@\n" - @"\tTXT Domain Name = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), _mailbox, - _TXTDomainName, _TTL]; -} -@end - -@implementation OFSOADNSResourceRecord -@synthesize primaryNameServer = _primaryNameServer; -@synthesize responsiblePerson = _responsiblePerson; -@synthesize serialNumber = _serialNumber, refreshInterval = _refreshInterval; -@synthesize retryInterval = _retryInterval; -@synthesize expirationInterval = _expirationInterval, minTTL = _minTTL; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - primaryNameServer: (OFString *)primaryNameServer - responsiblePerson: (OFString *)responsiblePerson - serialNumber: (uint32_t)serialNumber - refreshInterval: (uint32_t)refreshInterval - retryInterval: (uint32_t)retryInterval - expirationInterval: (uint32_t)expirationInterval - minTTL: (uint32_t)minTTL - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeSOA - TTL: TTL]; - - @try { - _primaryNameServer = [primaryNameServer copy]; - _responsiblePerson = [responsiblePerson copy]; - _serialNumber = serialNumber; - _refreshInterval = refreshInterval; - _retryInterval = retryInterval; - _expirationInterval = expirationInterval; - _minTTL = minTTL; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_primaryNameServer release]; - [_responsiblePerson release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFSOADNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFSOADNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_primaryNameServer != _primaryNameServer && - ![record->_primaryNameServer isEqual: _primaryNameServer]) - return false; - - if (record->_responsiblePerson != _responsiblePerson && - ![record->_responsiblePerson isEqual: _responsiblePerson]) - return false; - - if (record->_serialNumber != _serialNumber) - return false; - - if (record->_refreshInterval != _refreshInterval) - return false; - - if (record->_retryInterval != _retryInterval) - return false; - - if (record->_expirationInterval != _expirationInterval) - return false; - - if (record->_minTTL != _minTTL) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _primaryNameServer.hash); - OFHashAddHash(&hash, _responsiblePerson.hash); - OFHashAddByte(&hash, _serialNumber >> 24); - OFHashAddByte(&hash, _serialNumber >> 16); - OFHashAddByte(&hash, _serialNumber >> 8); - OFHashAddByte(&hash, _serialNumber); - OFHashAddByte(&hash, _refreshInterval >> 24); - OFHashAddByte(&hash, _refreshInterval >> 16); - OFHashAddByte(&hash, _refreshInterval >> 8); - OFHashAddByte(&hash, _refreshInterval); - OFHashAddByte(&hash, _retryInterval >> 24); - OFHashAddByte(&hash, _retryInterval >> 16); - OFHashAddByte(&hash, _retryInterval >> 8); - OFHashAddByte(&hash, _retryInterval); - OFHashAddByte(&hash, _expirationInterval >> 24); - OFHashAddByte(&hash, _expirationInterval >> 16); - OFHashAddByte(&hash, _expirationInterval >> 8); - OFHashAddByte(&hash, _expirationInterval); - OFHashAddByte(&hash, _minTTL >> 24); - OFHashAddByte(&hash, _minTTL >> 16); - OFHashAddByte(&hash, _minTTL >> 8); - OFHashAddByte(&hash, _minTTL); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tPrimary Name Server = %@\n" - @"\tResponsible Person = %@\n" - @"\tSerial Number = %" PRIu32 "\n" - @"\tRefresh Interval = %" PRIu32 "\n" - @"\tRetry Interval = %" PRIu32 "\n" - @"\tExpiration Interval = %" PRIu32 "\n" - @"\tMinimum TTL = %" PRIu32 "\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), - _primaryNameServer, _responsiblePerson, _serialNumber, - _refreshInterval, _retryInterval, _expirationInterval, _minTTL, - _TTL]; -} -@end - -@implementation OFSRVDNSResourceRecord -@synthesize priority = _priority, weight = _weight, target = _target; -@synthesize port = _port; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - priority: (uint16_t)priority - weight: (uint16_t)weight - target: (OFString *)target - port: (uint16_t)port - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: OFDNSClassIN - recordType: OFDNSRecordTypeSRV - TTL: TTL]; - - @try { - _priority = priority; - _weight = weight; - _target = [target copy]; - _port = port; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_target release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFSRVDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFSRVDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_priority != _priority) - return false; - - if (record->_weight != _weight) - return false; - - if (record->_target != _target && ![record->_target isEqual: _target]) - return false; - - if (record->_port != _port) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddByte(&hash, _priority >> 8); - OFHashAddByte(&hash, _priority); - OFHashAddByte(&hash, _weight >> 8); - OFHashAddByte(&hash, _weight); - OFHashAddHash(&hash, _target.hash); - OFHashAddByte(&hash, _port >> 8); - OFHashAddByte(&hash, _port); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tPriority = %" PRIu16 "\n" - @"\tWeight = %" PRIu16 "\n" - @"\tTarget = %@\n" - @"\tPort = %" PRIu16 "\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, _priority, _weight, _target, _port, _TTL]; -} -@end - -@implementation OFTXTDNSResourceRecord -@synthesize textStrings = _textStrings; - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - recordType: (OFDNSRecordType)recordType - TTL: (uint32_t)TTL -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - DNSClass: (OFDNSClass)DNSClass - textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings - TTL: (uint32_t)TTL -{ - self = [super initWithName: name - DNSClass: DNSClass - recordType: OFDNSRecordTypeTXT - TTL: TTL]; - - @try { - _textStrings = [textStrings copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_textStrings release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFTXTDNSResourceRecord *record; - - if (object == self) - return true; - - if (![object isKindOfClass: [OFTXTDNSResourceRecord class]]) - return false; - - record = object; - - if (record->_name != _name && ![record->_name isEqual: _name]) - return false; - - if (record->_DNSClass != _DNSClass) - return false; - - if (record->_recordType != _recordType) - return false; - - if (record->_textStrings != _textStrings && - ![record->_textStrings isEqual: _textStrings]) - return false; - - return true; -} - -- (unsigned long)hash -{ - unsigned long hash; - - OFHashInit(&hash); - - OFHashAddHash(&hash, _name.hash); - OFHashAddByte(&hash, _DNSClass >> 8); - OFHashAddByte(&hash, _DNSClass); - OFHashAddByte(&hash, _recordType >> 8); - OFHashAddByte(&hash, _recordType); - OFHashAddHash(&hash, _textStrings.hash); - - OFHashFinalize(&hash); - - return hash; -} - -- (OFString *)description -{ - void *pool = objc_autoreleasePoolPush(); - OFMutableString *text = [OFMutableString string]; - bool first = true; - OFString *ret; - - for (OFData *string in _textStrings) { - const unsigned char *stringItems = string.items; - size_t stringCount = string.count; - - if (first) { - first = false; - [text appendString: @"\""]; - } else - [text appendString: @" \""]; - - for (size_t i = 0; i < stringCount; i++) { - if (stringItems[i] == '\\') - [text appendString: @"\\\\"]; - else if (stringItems[i] == '"') - [text appendString: @"\\\""]; - else if (stringItems[i] < 0x20) - [text appendFormat: @"\\x%02X", stringItems[i]]; - else if (stringItems[i] < 0x7F) - [text appendFormat: @"%c", stringItems[i]]; - else - [text appendFormat: @"\\x%02X", stringItems[i]]; - } - - [text appendString: @"\""]; - } - - ret = [OFString stringWithFormat: - @"<%@:\n" - @"\tName = %@\n" - @"\tClass = %@\n" - @"\tText strings = %@\n" - @"\tTTL = %" PRIu32 "\n" - @">", - self.className, _name, OFDNSClassName(_DNSClass), text, _TTL]; - - [ret retain]; - - objc_autoreleasePoolPop(pool); - - return [ret autorelease]; -} @end ADDED src/OFHINFODNSResourceRecord.h Index: src/OFHINFODNSResourceRecord.h ================================================================== --- src/OFHINFODNSResourceRecord.h +++ src/OFHINFODNSResourceRecord.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFHINFODNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an HINFO DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFHINFODNSResourceRecord: OFDNSResourceRecord +{ + OFString *_CPU, *_OS; +} + +/** + * @brief The CPU of the host info of the resource record. + */ +@property (readonly, nonatomic) OFString *CPU; + +/** + * @brief The OS of the host info of the resource record. + */ +@property (readonly, nonatomic) OFString *OS; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFHINFODNSResourceRecord with the + * specified name, class, domain name and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param CPU The CPU of the host info for the resource record + * @param OS The OS of the host info for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFHINFODNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + CPU: (OFString *)CPU + OS: (OFString *)OS + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFHINFODNSResourceRecord.m Index: src/OFHINFODNSResourceRecord.m ================================================================== --- src/OFHINFODNSResourceRecord.m +++ src/OFHINFODNSResourceRecord.m @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFHINFODNSResourceRecord.h" + +@implementation OFHINFODNSResourceRecord +@synthesize CPU = _CPU, OS = _OS; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + CPU: (OFString *)CPU + OS: (OFString *)OS + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeHINFO + TTL: TTL]; + + @try { + _CPU = [CPU copy]; + _OS = [OS copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_CPU release]; + [_OS release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFHINFODNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFHINFODNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_CPU != _CPU && ![record->_CPU isEqual: _CPU]) + return false; + + if (record->_OS != _OS && ![record->_OS isEqual: _OS]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _CPU.hash); + OFHashAddHash(&hash, _OS.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tCPU = %@\n" + @"\tOS = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), _CPU, _OS, _TTL]; +} +@end ADDED src/OFMXDNSResourceRecord.h Index: src/OFMXDNSResourceRecord.h ================================================================== --- src/OFMXDNSResourceRecord.h +++ src/OFMXDNSResourceRecord.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFMXDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an MX DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFMXDNSResourceRecord: OFDNSResourceRecord +{ + uint16_t _preference; + OFString *_mailExchange; +} + +/** + * @brief The preference of the resource record. + */ +@property (readonly, nonatomic) uint16_t preference; + +/** + * @brief The mail exchange of the resource record. + */ +@property (readonly, nonatomic) OFString *mailExchange; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFMXDNSResourceRecord with the + * specified name, class, preference, mail exchange and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param preference The preference for the resource record + * @param mailExchange The mail exchange for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFMXDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + preference: (uint16_t)preference + mailExchange: (OFString *)mailExchange + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFMXDNSResourceRecord.m Index: src/OFMXDNSResourceRecord.m ================================================================== --- src/OFMXDNSResourceRecord.m +++ src/OFMXDNSResourceRecord.m @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFMXDNSResourceRecord.h" + +@implementation OFMXDNSResourceRecord +@synthesize preference = _preference, mailExchange = _mailExchange; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + preference: (uint16_t)preference + mailExchange: (OFString *)mailExchange + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeMX + TTL: TTL]; + + @try { + _preference = preference; + _mailExchange = [mailExchange copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_mailExchange release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFMXDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFMXDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_preference != _preference) + return false; + + if (record->_mailExchange != _mailExchange && + ![record->_mailExchange isEqual: _mailExchange]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddByte(&hash, _preference >> 8); + OFHashAddByte(&hash, _preference); + OFHashAddHash(&hash, _mailExchange.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tPreference = %" PRIu16 "\n" + @"\tMail Exchange = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), _preference, + _mailExchange, _TTL]; +} +@end ADDED src/OFNSDNSResourceRecord.h Index: src/OFNSDNSResourceRecord.h ================================================================== --- src/OFNSDNSResourceRecord.h +++ src/OFNSDNSResourceRecord.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFNSDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an NS DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFNSDNSResourceRecord: OFDNSResourceRecord +{ + OFString *_authoritativeHost; +} + +/** + * @brief The authoritative host of the resource record. + */ +@property (readonly, nonatomic) OFString *authoritativeHost; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFNSDNSResourceRecord with the + * specified name, class, authoritative host and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param authoritativeHost The authoritative host for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFNSDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + authoritativeHost: (OFString *)authoritativeHost + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFNSDNSResourceRecord.m Index: src/OFNSDNSResourceRecord.m ================================================================== --- src/OFNSDNSResourceRecord.m +++ src/OFNSDNSResourceRecord.m @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFMXDNSResourceRecord.h" + +@implementation OFNSDNSResourceRecord +@synthesize authoritativeHost = _authoritativeHost; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + authoritativeHost: (OFString *)authoritativeHost + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeNS + TTL: TTL]; + + @try { + _authoritativeHost = [authoritativeHost copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_authoritativeHost release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFNSDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFNSDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_authoritativeHost != _authoritativeHost && + ![record->_authoritativeHost isEqual: _authoritativeHost]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _authoritativeHost.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tAuthoritative Host = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), + _authoritativeHost, _TTL]; +} +@end ADDED src/OFPTRDNSResourceRecord.h Index: src/OFPTRDNSResourceRecord.h ================================================================== --- src/OFPTRDNSResourceRecord.h +++ src/OFPTRDNSResourceRecord.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFPTRDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing a PTR DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFPTRDNSResourceRecord: OFDNSResourceRecord +{ + OFString *_domainName; +} + +/** + * @brief The domain name of the resource record. + */ +@property (readonly, nonatomic) OFString *domainName; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFPTRDNSResourceRecord with the + * specified name, class, domain name and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param domainName The domain name for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFPTRDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + domainName: (OFString *)domainName + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFPTRDNSResourceRecord.m Index: src/OFPTRDNSResourceRecord.m ================================================================== --- src/OFPTRDNSResourceRecord.m +++ src/OFPTRDNSResourceRecord.m @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFPTRDNSResourceRecord.h" + +@implementation OFPTRDNSResourceRecord +@synthesize domainName = _domainName; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + domainName: (OFString *)domainName + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypePTR + TTL: TTL]; + + @try { + _domainName = [domainName copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_domainName release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFPTRDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFPTRDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_domainName != _domainName && + ![record->_domainName isEqual: _domainName]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _domainName.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tDomain Name = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), _domainName, + _TTL]; +} +@end ADDED src/OFRPDNSResourceRecord.h Index: src/OFRPDNSResourceRecord.h ================================================================== --- src/OFRPDNSResourceRecord.h +++ src/OFRPDNSResourceRecord.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFRPDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an RP DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFRPDNSResourceRecord: OFDNSResourceRecord +{ + OFString *_mailbox, *_TXTDomainName; +} + +/** + * @brief The mailbox of the responsible person of the resource record. + */ +@property (readonly, nonatomic) OFString *mailbox; + +/** + * @brief A domain name that contains a TXT resource record for the responsible + * person of the resource record. + */ +@property (readonly, nonatomic) OFString *TXTDomainName; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFRPDNSResourceRecord with the + * specified name, class, alias and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param mailbox The mailbox of the responsible person of the resource record + * @param TXTDomainName A domain name that contains a TXT resource record for + * the responsible person of the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFRPDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + mailbox: (OFString *)mailbox + TXTDomainName: (OFString *)TXTDomainName + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFRPDNSResourceRecord.m Index: src/OFRPDNSResourceRecord.m ================================================================== --- src/OFRPDNSResourceRecord.m +++ src/OFRPDNSResourceRecord.m @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFRPDNSResourceRecord.h" + +@implementation OFRPDNSResourceRecord +@synthesize mailbox = _mailbox, TXTDomainName = _TXTDomainName; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + mailbox: (OFString *)mailbox + TXTDomainName: (OFString *)TXTDomainName + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeRP + TTL: TTL]; + + @try { + _mailbox = [mailbox copy]; + _TXTDomainName = [TXTDomainName copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_mailbox release]; + [_TXTDomainName release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFRPDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFRPDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_mailbox != _mailbox && + ![record->_mailbox isEqual: _mailbox]) + return false; + + if (record->_TXTDomainName != _TXTDomainName && + ![record->_TXTDomainName isEqual: _TXTDomainName]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _mailbox.hash); + OFHashAddHash(&hash, _TXTDomainName.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tMailbox = %@\n" + @"\tTXT Domain Name = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), _mailbox, + _TXTDomainName, _TTL]; +} +@end ADDED src/OFSOADNSResourceRecord.h Index: src/OFSOADNSResourceRecord.h ================================================================== --- src/OFSOADNSResourceRecord.h +++ src/OFSOADNSResourceRecord.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFSOADNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an SOA DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFSOADNSResourceRecord: OFDNSResourceRecord +{ + OFString *_primaryNameServer, *_responsiblePerson; + uint32_t _serialNumber, _refreshInterval, _retryInterval; + uint32_t _expirationInterval, _minTTL; +} + +/** + * @brief The the primary name server for the zone. + */ +@property (readonly, nonatomic) OFString *primaryNameServer; + +/** + * @brief The mailbox of the person responsible for the zone. + */ +@property (readonly, nonatomic) OFString *responsiblePerson; + +/** + * @brief The serial number of the original copy of the zone. + */ +@property (readonly, nonatomic) uint32_t serialNumber; + +/** + * @brief The refresh interval of the zone. + */ +@property (readonly, nonatomic) uint32_t refreshInterval; + +/** + * @brief The retry interval of the zone. + */ +@property (readonly, nonatomic) uint32_t retryInterval; + +/** + * @brief The expiration interval of the zone. + */ +@property (readonly, nonatomic) uint32_t expirationInterval; + +/** + * @brief The minimum TTL of the zone. + */ +@property (readonly, nonatomic) uint32_t minTTL; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFSOADNSResourceRecord with the + * specified name, class, text data and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param primaryNameServer The the primary name server for the zone + * @param responsiblePerson The mailbox of the person responsible for the zone + * @param serialNumber The serial number of the original copy of the zone + * @param refreshInterval The refresh interval of the zone + * @param retryInterval The retry interval of the zone + * @param expirationInterval The expiration interval of the zone + * @param minTTL The minimum TTL of the zone + * @param TTL The time to live for the resource record + * @return An initialized OFSOADNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + primaryNameServer: (OFString *)primaryNameServer + responsiblePerson: (OFString *)responsiblePerson + serialNumber: (uint32_t)serialNumber + refreshInterval: (uint32_t)refreshInterval + retryInterval: (uint32_t)retryInterval + expirationInterval: (uint32_t)expirationInterval + minTTL: (uint32_t)minTTL + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFSOADNSResourceRecord.m Index: src/OFSOADNSResourceRecord.m ================================================================== --- src/OFSOADNSResourceRecord.m +++ src/OFSOADNSResourceRecord.m @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFSOADNSResourceRecord.h" + +@implementation OFSOADNSResourceRecord +@synthesize primaryNameServer = _primaryNameServer; +@synthesize responsiblePerson = _responsiblePerson; +@synthesize serialNumber = _serialNumber, refreshInterval = _refreshInterval; +@synthesize retryInterval = _retryInterval; +@synthesize expirationInterval = _expirationInterval, minTTL = _minTTL; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + primaryNameServer: (OFString *)primaryNameServer + responsiblePerson: (OFString *)responsiblePerson + serialNumber: (uint32_t)serialNumber + refreshInterval: (uint32_t)refreshInterval + retryInterval: (uint32_t)retryInterval + expirationInterval: (uint32_t)expirationInterval + minTTL: (uint32_t)minTTL + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeSOA + TTL: TTL]; + + @try { + _primaryNameServer = [primaryNameServer copy]; + _responsiblePerson = [responsiblePerson copy]; + _serialNumber = serialNumber; + _refreshInterval = refreshInterval; + _retryInterval = retryInterval; + _expirationInterval = expirationInterval; + _minTTL = minTTL; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_primaryNameServer release]; + [_responsiblePerson release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFSOADNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFSOADNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_primaryNameServer != _primaryNameServer && + ![record->_primaryNameServer isEqual: _primaryNameServer]) + return false; + + if (record->_responsiblePerson != _responsiblePerson && + ![record->_responsiblePerson isEqual: _responsiblePerson]) + return false; + + if (record->_serialNumber != _serialNumber) + return false; + + if (record->_refreshInterval != _refreshInterval) + return false; + + if (record->_retryInterval != _retryInterval) + return false; + + if (record->_expirationInterval != _expirationInterval) + return false; + + if (record->_minTTL != _minTTL) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _primaryNameServer.hash); + OFHashAddHash(&hash, _responsiblePerson.hash); + OFHashAddByte(&hash, _serialNumber >> 24); + OFHashAddByte(&hash, _serialNumber >> 16); + OFHashAddByte(&hash, _serialNumber >> 8); + OFHashAddByte(&hash, _serialNumber); + OFHashAddByte(&hash, _refreshInterval >> 24); + OFHashAddByte(&hash, _refreshInterval >> 16); + OFHashAddByte(&hash, _refreshInterval >> 8); + OFHashAddByte(&hash, _refreshInterval); + OFHashAddByte(&hash, _retryInterval >> 24); + OFHashAddByte(&hash, _retryInterval >> 16); + OFHashAddByte(&hash, _retryInterval >> 8); + OFHashAddByte(&hash, _retryInterval); + OFHashAddByte(&hash, _expirationInterval >> 24); + OFHashAddByte(&hash, _expirationInterval >> 16); + OFHashAddByte(&hash, _expirationInterval >> 8); + OFHashAddByte(&hash, _expirationInterval); + OFHashAddByte(&hash, _minTTL >> 24); + OFHashAddByte(&hash, _minTTL >> 16); + OFHashAddByte(&hash, _minTTL >> 8); + OFHashAddByte(&hash, _minTTL); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tPrimary Name Server = %@\n" + @"\tResponsible Person = %@\n" + @"\tSerial Number = %" PRIu32 "\n" + @"\tRefresh Interval = %" PRIu32 "\n" + @"\tRetry Interval = %" PRIu32 "\n" + @"\tExpiration Interval = %" PRIu32 "\n" + @"\tMinimum TTL = %" PRIu32 "\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), + _primaryNameServer, _responsiblePerson, _serialNumber, + _refreshInterval, _retryInterval, _expirationInterval, _minTTL, + _TTL]; +} +@end ADDED src/OFSRVDNSResourceRecord.h Index: src/OFSRVDNSResourceRecord.h ================================================================== --- src/OFSRVDNSResourceRecord.h +++ src/OFSRVDNSResourceRecord.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFSRVDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing an SRV DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFSRVDNSResourceRecord: OFDNSResourceRecord +{ + uint16_t _priority, _weight; + OFString *_target; + uint16_t _port; +} + +/** + * @brief The priority of the resource record. + */ +@property (readonly, nonatomic) uint16_t priority; + +/** + * @brief The weight of the resource record. + */ +@property (readonly, nonatomic) uint16_t weight; + +/** + * @brief The target of the resource record. + */ +@property (readonly, nonatomic) OFString *target; + +/** + * @brief The port on the target of the resource record. + */ +@property (readonly, nonatomic) uint16_t port; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFSRVDNSResourceRecord with the + * specified name, class, preference, mail exchange and time to live. + * + * @param name The name for the resource record + * @param priority The priority for the resource record + * @param weight The weight for the resource record + * @param target The target for the resource record + * @param port The port on the target for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFSRVDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + priority: (uint16_t)priority + weight: (uint16_t)weight + target: (OFString *)target + port: (uint16_t)port + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFSRVDNSResourceRecord.m Index: src/OFSRVDNSResourceRecord.m ================================================================== --- src/OFSRVDNSResourceRecord.m +++ src/OFSRVDNSResourceRecord.m @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFSRVDNSResourceRecord.h" + +@implementation OFSRVDNSResourceRecord +@synthesize priority = _priority, weight = _weight, target = _target; +@synthesize port = _port; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + priority: (uint16_t)priority + weight: (uint16_t)weight + target: (OFString *)target + port: (uint16_t)port + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: OFDNSClassIN + recordType: OFDNSRecordTypeSRV + TTL: TTL]; + + @try { + _priority = priority; + _weight = weight; + _target = [target copy]; + _port = port; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_target release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFSRVDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFSRVDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_priority != _priority) + return false; + + if (record->_weight != _weight) + return false; + + if (record->_target != _target && ![record->_target isEqual: _target]) + return false; + + if (record->_port != _port) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddByte(&hash, _priority >> 8); + OFHashAddByte(&hash, _priority); + OFHashAddByte(&hash, _weight >> 8); + OFHashAddByte(&hash, _weight); + OFHashAddHash(&hash, _target.hash); + OFHashAddByte(&hash, _port >> 8); + OFHashAddByte(&hash, _port); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tPriority = %" PRIu16 "\n" + @"\tWeight = %" PRIu16 "\n" + @"\tTarget = %@\n" + @"\tPort = %" PRIu16 "\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, _priority, _weight, _target, _port, _TTL]; +} +@end ADDED src/OFTXTDNSResourceRecord.h Index: src/OFTXTDNSResourceRecord.h ================================================================== --- src/OFTXTDNSResourceRecord.h +++ src/OFTXTDNSResourceRecord.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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. + */ + +#import "OFDNSResourceRecord.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFTXTDNSResourceRecord \ + * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h + * + * @brief A class representing a TXT DNS resource record. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFTXTDNSResourceRecord: OFDNSResourceRecord +{ + OFArray OF_GENERIC(OFData *) *_textStrings; +} + +/** + * @brief The text of the resource record. + */ +@property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated OFTXTDNSResourceRecord with the + * specified name, class, text data and time to live. + * + * @param name The name for the resource record + * @param DNSClass The class code for the resource record + * @param textStrings An array of text strings for the resource record + * @param TTL The time to live for the resource record + * @return An initialized OFTXTDNSResourceRecord + */ +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings + TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFTXTDNSResourceRecord.m Index: src/OFTXTDNSResourceRecord.m ================================================================== --- src/OFTXTDNSResourceRecord.m +++ src/OFTXTDNSResourceRecord.m @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * 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 "OFTXTDNSResourceRecord.h" +#import "OFArray.h" +#import "OFData.h" + +@implementation OFTXTDNSResourceRecord +@synthesize textStrings = _textStrings; + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType + TTL: (uint32_t)TTL +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + DNSClass: (OFDNSClass)DNSClass + textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings + TTL: (uint32_t)TTL +{ + self = [super initWithName: name + DNSClass: DNSClass + recordType: OFDNSRecordTypeTXT + TTL: TTL]; + + @try { + _textStrings = [textStrings copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_textStrings release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFTXTDNSResourceRecord *record; + + if (object == self) + return true; + + if (![object isKindOfClass: [OFTXTDNSResourceRecord class]]) + return false; + + record = object; + + if (record->_name != _name && ![record->_name isEqual: _name]) + return false; + + if (record->_DNSClass != _DNSClass) + return false; + + if (record->_recordType != _recordType) + return false; + + if (record->_textStrings != _textStrings && + ![record->_textStrings isEqual: _textStrings]) + return false; + + return true; +} + +- (unsigned long)hash +{ + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddByte(&hash, _DNSClass >> 8); + OFHashAddByte(&hash, _DNSClass); + OFHashAddByte(&hash, _recordType >> 8); + OFHashAddByte(&hash, _recordType); + OFHashAddHash(&hash, _textStrings.hash); + + OFHashFinalize(&hash); + + return hash; +} + +- (OFString *)description +{ + void *pool = objc_autoreleasePoolPush(); + OFMutableString *text = [OFMutableString string]; + bool first = true; + OFString *ret; + + for (OFData *string in _textStrings) { + const unsigned char *stringItems = string.items; + size_t stringCount = string.count; + + if (first) { + first = false; + [text appendString: @"\""]; + } else + [text appendString: @" \""]; + + for (size_t i = 0; i < stringCount; i++) { + if (stringItems[i] == '\\') + [text appendString: @"\\\\"]; + else if (stringItems[i] == '"') + [text appendString: @"\\\""]; + else if (stringItems[i] < 0x20) + [text appendFormat: @"\\x%02X", stringItems[i]]; + else if (stringItems[i] < 0x7F) + [text appendFormat: @"%c", stringItems[i]]; + else + [text appendFormat: @"\\x%02X", stringItems[i]]; + } + + [text appendString: @"\""]; + } + + ret = [OFString stringWithFormat: + @"<%@:\n" + @"\tName = %@\n" + @"\tClass = %@\n" + @"\tText strings = %@\n" + @"\tTTL = %" PRIu32 "\n" + @">", + self.className, _name, OFDNSClassName(_DNSClass), text, _TTL]; + + [ret retain]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} +@end