1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef DISCOVERY_DNSSD_IMPL_CONVERSION_LAYER_H_ 6 #define DISCOVERY_DNSSD_IMPL_CONVERSION_LAYER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "absl/strings/string_view.h" 12 #include "discovery/dnssd/impl/constants.h" 13 #include "discovery/dnssd/public/dns_sd_instance_endpoint.h" 14 #include "discovery/dnssd/public/dns_sd_txt_record.h" 15 #include "discovery/mdns/mdns_records.h" 16 #include "platform/base/error.h" 17 18 namespace openscreen { 19 namespace discovery { 20 21 class InstanceKey; 22 class ServiceKey; 23 24 // *** Conversions from DNS entities to DNS-SD Entities *** 25 26 // Attempts to create a new TXT record from the provided set of strings, 27 // returning a TxtRecord on success or an error if the provided strings are 28 // not valid. 29 ErrorOr<DnsSdTxtRecord> CreateFromDnsTxt(const TxtRecordRdata& txt); 30 31 bool IsPtrRecord(const MdnsRecord& record); 32 33 // Checks that the instance, service, and domain ids in this instance are valid. 34 bool HasValidDnsRecordAddress(const MdnsRecord& record); 35 bool HasValidDnsRecordAddress(const DomainName& domain); 36 37 //*** Conversions to DNS entities from DNS-SD Entities *** 38 39 // Returns the Domain Name associated with this InstanceKey. 40 DomainName GetDomainName(const InstanceKey& key); 41 42 // Returns the domain name associated with this MdnsRecord. In the case of a PTR 43 // record, this is the target domain, and it is the named domain in all other 44 // cases. 45 DomainName GetDomainName(const MdnsRecord& record); 46 47 // Returns the query required to get all instance information about the service 48 // instances described by the provided InstanceKey. 49 DnsQueryInfo GetInstanceQueryInfo(const InstanceKey& key); 50 51 // Returns the query required to get all service information that matches the 52 // provided key. 53 DnsQueryInfo GetPtrQueryInfo(const ServiceKey& key); 54 55 // Returns all MdnsRecord entities generated from this object. 56 std::vector<MdnsRecord> GetDnsRecords(const DnsSdInstanceEndpoint& endpoint); 57 std::vector<MdnsRecord> GetDnsRecords(const DnsSdInstance& instance); 58 59 } // namespace discovery 60 } // namespace openscreen 61 62 #endif // DISCOVERY_DNSSD_IMPL_CONVERSION_LAYER_H_ 63