@@ -12,14 +12,13 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" +#import "OFSocket.h" #import "OFString.h" -#import "socket.h" - OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @@ -28,55 +27,55 @@ /** * @brief The DNS class. */ typedef enum { /** IN */ - OF_DNS_CLASS_IN = 1, + OFDNSClassIN = 1, /** Any class. Only for queries. */ - OF_DNS_CLASS_ANY = 255, -} of_dns_class_t; + OFDNSClassAny = 255, +} OFDNSClass; /** * @brief The type of a DNS resource record. */ typedef enum { /** A */ - OF_DNS_RECORD_TYPE_A = 1, + OFDNSRecordTypeA = 1, /** NS */ - OF_DNS_RECORD_TYPE_NS = 2, + OFDNSRecordTypeNS = 2, /** CNAME */ - OF_DNS_RECORD_TYPE_CNAME = 5, + OFDNSRecordTypeCNAME = 5, /** SOA */ - OF_DNS_RECORD_TYPE_SOA = 6, + OFDNSRecordTypeSOA = 6, /** PTR */ - OF_DNS_RECORD_TYPE_PTR = 12, + OFDNSRecordTypePTR = 12, /** HINFO */ - OF_DNS_RECORD_TYPE_HINFO = 13, + OFDNSRecordTypeHINFO = 13, /** MX */ - OF_DNS_RECORD_TYPE_MX = 15, + OFDNSRecordTypeMX = 15, /** TXT */ - OF_DNS_RECORD_TYPE_TXT = 16, + OFDNSRecordTypeTXT = 16, /** RP */ - OF_DNS_RECORD_TYPE_RP = 17, + OFDNSRecordTypeRP = 17, /** AAAA */ - OF_DNS_RECORD_TYPE_AAAA = 28, + OFDNSRecordTypeAAAA = 28, /** SRV */ - OF_DNS_RECORD_TYPE_SRV = 33, + OFDNSRecordTypeSRV = 33, /** All types. Only for queries. */ - OF_DNS_RECORD_TYPE_ALL = 255, -} of_dns_record_type_t; + OFDNSRecordTypeAll = 255, +} OFDNSRecordType; /** * @class OFDNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a DNS resource record. */ @interface OFDNSResourceRecord: OFObject { OFString *_name; - of_dns_class_t _DNSClass; - of_dns_record_type_t _recordType; + OFDNSClass _DNSClass; + OFDNSRecordType _recordType; uint32_t _TTL; OF_RESERVE_IVARS(OFDNSResourceRecord, 4) } /** @@ -85,16 +84,16 @@ @property (readonly, nonatomic) OFString *name; /** * @brief The DNS class. */ -@property (readonly, nonatomic) of_dns_class_t DNSClass; +@property (readonly, nonatomic) OFDNSClass DNSClass; /** * @brief The resource record type code. */ -@property (readonly, nonatomic) of_dns_record_type_t recordType; +@property (readonly, nonatomic) OFDNSRecordType recordType; /** * @brief The number of seconds after which the resource record should be * discarded from the cache. */ @@ -109,12 +108,12 @@ * @param recordType The type code for the resource record * @param TTL The time to live for the resource record * @return An initialized OFDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + DNSClass: (OFDNSClass)DNSClass + recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFADNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h @@ -122,21 +121,21 @@ * @brief A class representing an A DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFADNSResourceRecord: OFDNSResourceRecord { - of_socket_address_t _address; + OFSocketAddress _address; } /** * @brief The IPv4 address of the resource record. */ -@property (readonly, nonatomic) const of_socket_address_t *address; +@property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -145,11 +144,11 @@ * @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 of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFAAAADNSResourceRecord \ @@ -158,21 +157,21 @@ * @brief A class represenging a DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFAAAADNSResourceRecord: OFDNSResourceRecord { - of_socket_address_t _address; + OFSocketAddress _address; } /** * @brief The IPv6 address of the resource record. */ -@property (readonly, nonatomic) const of_socket_address_t *address; +@property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -181,11 +180,11 @@ * @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 of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFCNAMEDNSResourceRecord \ @@ -203,12 +202,12 @@ * @brief The alias of the resource record. */ @property (readonly, nonatomic) OFString *alias; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -218,11 +217,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass alias: (OFString *)alias TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** @@ -246,12 +245,12 @@ * @brief The OS of the host info of the resource record. */ @property (readonly, nonatomic) OFString *OS; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -262,11 +261,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass CPU: (OFString *)CPU OS: (OFString *)OS TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end @@ -292,12 +291,12 @@ * @brief The mail exchange of the resource record. */ @property (readonly, nonatomic) OFString *mailExchange; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -308,11 +307,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass preference: (uint16_t)preference mailExchange: (OFString *)mailExchange TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end @@ -332,12 +331,12 @@ * @brief The authoritative host of the resource record. */ @property (readonly, nonatomic) OFString *authoritativeHost; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -347,11 +346,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass authoritativeHost: (OFString *)authoritativeHost TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** @@ -370,12 +369,12 @@ * @brief The domain name of the resource record. */ @property (readonly, nonatomic) OFString *domainName; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -385,11 +384,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass domainName: (OFString *)domainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** @@ -414,12 +413,12 @@ * person of the resource record. */ @property (readonly, nonatomic) OFString *TXTDomainName; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -431,11 +430,11 @@ * 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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass mailbox: (OFString *)mailbox TXTDomainName: (OFString *)TXTDomainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end @@ -487,12 +486,12 @@ * @brief The minimum TTL of the zone. */ @property (readonly, nonatomic) uint32_t minTTL; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -508,11 +507,11 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass primaryNameServer: (OFString *)primaryNameServer responsiblePerson: (OFString *)responsiblePerson serialNumber: (uint32_t)serialNumber refreshInterval: (uint32_t)refreshInterval retryInterval: (uint32_t)retryInterval @@ -554,12 +553,12 @@ * @brief The port on the target of the resource record. */ @property (readonly, nonatomic) uint16_t port; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -596,12 +595,12 @@ * @brief The text of the resource record. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; - (instancetype)initWithName: (OFString *)name - DNSClass: (of_dns_class_t)DNSClass - recordType: (of_dns_record_type_t)recordType + 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. @@ -611,23 +610,49 @@ * @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: (of_dns_class_t)DNSClass + DNSClass: (OFDNSClass)DNSClass textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end #ifdef __cplusplus extern "C" { #endif -extern OFString *_Nonnull of_dns_class_to_string(of_dns_class_t DNSClass); -extern OFString *_Nonnull of_dns_record_type_to_string( - of_dns_record_type_t recordType); -extern of_dns_class_t of_dns_class_parse(OFString *_Nonnull string); -extern of_dns_record_type_t of_dns_record_type_parse(OFString *_Nonnull string); +/** + * @brief Returns the name for the specified OFDNSClass. + * + * @param DNSClass The OFDNSClass to return the name for + * @return The name for the specified OFDNSClass + */ +extern OFString *_Nonnull OFDNSClassName(OFDNSClass DNSClass); + +/** + * @brief Returns the name for the specified OFDNSRecordType. + * + * @param recordType The OFDNSRecordType to return the name for + * @return The name for the specified OFDNSRecordType + */ +extern OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType); + +/** + * @brief Parses the specified string as an @ref OFDNSClass. + * + * @param string The string to parse as an @ref OFDNSClass + * @return The parsed OFDNSClass + */ +extern OFDNSClass OFDNSClassParseName(OFString *_Nonnull string); + +/** + * @brief Parses the specified string as an @ref OFDNSRecordType. + * + * @param string The string to parse as an @ref OFDNSRecordType + * @return The parsed OFDNSRecordType + */ +extern OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END