Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020 Project CHIP Authors
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #pragma once
19 :
20 : #include <inet/IPAddress.h>
21 :
22 : #include <lib/dnssd/minimal_mdns/core/BytesRange.h>
23 : #include <lib/dnssd/minimal_mdns/core/QName.h>
24 :
25 : namespace mdns {
26 : namespace Minimal {
27 :
28 : class TxtRecordDelegate
29 : {
30 : public:
31 27 : virtual ~TxtRecordDelegate() {}
32 :
33 : /// Reports that a record was found
34 : ///
35 : /// name is mandatory
36 : /// value will be empty if '=' is missing in the TXT record. I.e code does
37 : /// *NOT* differentiate between "foo=" and "foo" as record.
38 : virtual void OnRecord(const BytesRange & name, const BytesRange & value) = 0;
39 : };
40 :
41 : /// Parses TXT record data
42 : /// https://tools.ietf.org/html/rfc1035 (included in base RFC)
43 : bool ParseTxtRecord(const BytesRange & data, TxtRecordDelegate * callback);
44 :
45 : /// Parses SRV record data
46 : /// https://tools.ietf.org/html/rfc2782
47 : class SrvRecord
48 : {
49 : public:
50 12 : SrvRecord() {}
51 :
52 : /// Parses a SRV record within [data]
53 : ///
54 : /// [packet] specifies the range of valid data for PTR addresses within
55 : /// the name
56 : bool Parse(const BytesRange & data, const BytesRange & packet);
57 :
58 : uint16_t GetPriority() const { return mPriority; }
59 : uint16_t GetWeight() const { return mWeight; }
60 18 : uint16_t GetPort() const { return mPort; }
61 36 : SerializedQNameIterator GetName() const { return mName; }
62 :
63 : private:
64 : uint16_t mPriority = 0;
65 : uint16_t mWeight = 0;
66 : uint16_t mPort = 0;
67 : SerializedQNameIterator mName;
68 : };
69 :
70 : /// Parses an IPV4 (A) record data
71 : /// https://tools.ietf.org/html/rfc1035 (included in base RFC)
72 : bool ParseARecord(const BytesRange & data, chip::Inet::IPAddress * addr);
73 :
74 : /// Parses an IPV6 (AAAA) record data
75 : /// https://tools.ietf.org/html/rfc3596
76 : bool ParseAAAARecord(const BytesRange & data, chip::Inet::IPAddress * addr);
77 :
78 : /// Parses a PTR record data
79 : /// https://tools.ietf.org/html/rfc1035 (included in base RFC)
80 : bool ParsePtrRecord(const BytesRange & data, const BytesRange & packet, SerializedQNameIterator * name);
81 :
82 : } // namespace Minimal
83 :
84 : } // namespace mdns
|