Browse Source

Added SOA record data

develop
Robin Thoni 6 years ago
parent
commit
6fa7eaf325

+ 1
- 1
src/modules/dns-base/CMakeLists.txt View File

@@ -30,7 +30,7 @@ add_library(${PROJECT_NAME}
30 30
         src/RecordData/QDnsRecordDataRaw.cpp
31 31
         includes/dns-base/RecordData/QDnsRecordDataRaw.h
32 32
         src/RecordData/QDnsRecordDataAAAA.cpp
33
-        includes/dns-base/RecordData/QDnsRecordDataAAAA.h src/RecordData/QDnsRecordDataMX.cpp includes/dns-base/RecordData/QDnsRecordDataMX.h)
33
+        includes/dns-base/RecordData/QDnsRecordDataAAAA.h src/RecordData/QDnsRecordDataMX.cpp includes/dns-base/RecordData/QDnsRecordDataMX.h src/RecordData/QDnsRecordDataSOA.cpp includes/dns-base/RecordData/QDnsRecordDataSOA.h)
34 34
 
35 35
 target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network)
36 36
 

+ 83
- 0
src/modules/dns-base/includes/dns-base/RecordData/QDnsRecordDataSOA.h View File

@@ -0,0 +1,83 @@
1
+//
2
+// Created by robin on 1/23/18.
3
+//
4
+
5
+#ifndef QDNSAGG_QDNSRECORDDATASOA_H
6
+#define QDNSAGG_QDNSRECORDDATASOA_H
7
+
8
+#include <qplatformdefs.h>
9
+#include <QByteArray>
10
+#include <QDataStream>
11
+#include <QHostAddress>
12
+
13
+#include "QDnsRecordData.h"
14
+
15
+namespace QDns
16
+{
17
+    namespace Base
18
+    {
19
+        class QDnsRecordDataSOA : public QDnsRecordData
20
+        {
21
+        public:
22
+            QDnsRecordDataSOA();
23
+
24
+            QDnsRecordDataSOA(const QByteArray &packetData, quint32 pos);
25
+
26
+            QDnsRecordDataSOA(const QByteArray &packetData, QDataStream &dataStream);
27
+
28
+            QByteArray serialize() const override;
29
+
30
+            void serialize(QDataStream &dataStream) const override;
31
+
32
+            virtual QDnsRecordData* clone() const override;
33
+
34
+            const QString &getPrimaryNs() const;
35
+
36
+            void setPrimaryNs(const QString &primaryNs);
37
+
38
+            const QString &getAdminMb() const;
39
+
40
+            void setAdminMb(const QString &adminMb);
41
+
42
+            quint32 getSerialNumber() const;
43
+
44
+            void setSerialNumber(quint32 serialNumber);
45
+
46
+            quint32 getRefreshInterval() const;
47
+
48
+            void setRefreshInterval(quint32 refreshInterval);
49
+
50
+            quint32 getRetryInterval() const;
51
+
52
+            void setRetryInterval(quint32 retryInterval);
53
+
54
+            quint32 getExpirationLimit() const;
55
+
56
+            void setExpirationLimit(quint32 expirationLimit);
57
+
58
+            quint32 getMinimumTtl() const;
59
+
60
+            void setMinimumTtl(quint32 minimumTtl);
61
+
62
+        private:
63
+            void parse(const QByteArray &packetData, QDataStream &dataStream);
64
+
65
+            QString m_primaryNs;
66
+
67
+            QString m_adminMb;
68
+
69
+            quint32 m_serialNumber;
70
+
71
+            quint32 m_refreshInterval;
72
+
73
+            quint32 m_retryInterval;
74
+
75
+            quint32 m_expirationLimit;
76
+
77
+            quint32 m_minimumTtl;
78
+        };
79
+    }
80
+}
81
+
82
+
83
+#endif //QDNSAGG_QDNSRECORDDATASOA_H

+ 166
- 0
src/modules/dns-base/src/RecordData/QDnsRecordDataSOA.cpp View File

@@ -0,0 +1,166 @@
1
+//
2
+// Created by robin on 1/23/18.
3
+//
4
+
5
+#include "dns-base/QDnsLabel.h"
6
+#include "dns-base/RecordData/QDnsRecordDataSOA.h"
7
+
8
+namespace QDns
9
+{
10
+    namespace Base
11
+    {
12
+        QDnsRecordDataSOA::QDnsRecordDataSOA()
13
+                : QDnsRecordData()
14
+        {
15
+        }
16
+
17
+        QDnsRecordDataSOA::QDnsRecordDataSOA(const QByteArray &packetData, quint32 pos)
18
+                : QDnsRecordDataSOA()
19
+        {
20
+            QDataStream dataStream(packetData);
21
+            dataStream.skipRawData(pos);
22
+            parse(packetData, dataStream);
23
+        }
24
+
25
+        QDnsRecordDataSOA::QDnsRecordDataSOA(const QByteArray &packetData, QDataStream &dataStream)
26
+                : QDnsRecordDataSOA()
27
+        {
28
+            parse(packetData, dataStream);
29
+        }
30
+
31
+        void QDnsRecordDataSOA::parse(const QByteArray &packetData, QDataStream &dataStream)
32
+        {
33
+            if (dataStream.device()->bytesAvailable() < 22)
34
+            {
35
+                m_isValid = false;
36
+            }
37
+            else
38
+            {
39
+                m_primaryNs = QDnsLabel::parse(packetData, dataStream);
40
+                if (m_primaryNs.isNull())
41
+                {
42
+                    m_isValid = false;
43
+                }
44
+                else
45
+                {
46
+                    m_adminMb = QDnsLabel::parse(packetData, dataStream);
47
+                    if (m_adminMb.isNull())
48
+                    {
49
+                        m_isValid = false;
50
+                    }
51
+                    else
52
+                    {
53
+                        dataStream >> m_serialNumber;
54
+                        dataStream >> m_refreshInterval;
55
+                        dataStream >> m_retryInterval;
56
+                        dataStream >> m_expirationLimit;
57
+                        dataStream >> m_minimumTtl;
58
+                    }
59
+                }
60
+            }
61
+        }
62
+
63
+        QByteArray QDnsRecordDataSOA::serialize() const
64
+        {
65
+            QByteArray byteArray;
66
+            QDataStream dataStream(&byteArray, QIODevice::WriteOnly);
67
+            serialize(dataStream);
68
+            return byteArray;
69
+        }
70
+
71
+        void QDnsRecordDataSOA::serialize(QDataStream &dataStream) const
72
+        {
73
+            QDnsLabel::serialize(m_primaryNs, dataStream);
74
+            QDnsLabel::serialize(m_adminMb, dataStream);
75
+            dataStream << m_serialNumber;
76
+            dataStream << m_refreshInterval;
77
+            dataStream << m_retryInterval;
78
+            dataStream << m_expirationLimit;
79
+            dataStream << m_minimumTtl;
80
+        }
81
+
82
+        QDnsRecordData *QDnsRecordDataSOA::clone() const
83
+        {
84
+            auto data = new QDnsRecordDataSOA();
85
+            data->m_isValid = m_isValid;
86
+            data->m_primaryNs = m_primaryNs;
87
+            data->m_adminMb = m_adminMb;
88
+            data->m_serialNumber = m_serialNumber;
89
+            data->m_refreshInterval = m_refreshInterval;
90
+            data->m_retryInterval = m_retryInterval;
91
+            data->m_expirationLimit = m_expirationLimit;
92
+            data->m_minimumTtl = m_minimumTtl;
93
+            return data;
94
+        }
95
+
96
+        const QString &QDnsRecordDataSOA::getPrimaryNs() const
97
+        {
98
+            return m_primaryNs;
99
+        }
100
+
101
+        void QDnsRecordDataSOA::setPrimaryNs(const QString &primaryNs)
102
+        {
103
+            m_primaryNs = primaryNs;
104
+        }
105
+
106
+        const QString &QDnsRecordDataSOA::getAdminMb() const
107
+        {
108
+            return m_adminMb;
109
+        }
110
+
111
+        void QDnsRecordDataSOA::setAdminMb(const QString &adminMb)
112
+        {
113
+            m_adminMb = adminMb;
114
+        }
115
+
116
+        quint32 QDnsRecordDataSOA::getSerialNumber() const
117
+        {
118
+            return m_serialNumber;
119
+        }
120
+
121
+        void QDnsRecordDataSOA::setSerialNumber(quint32 serialNumber)
122
+        {
123
+            m_serialNumber = serialNumber;
124
+        }
125
+
126
+        quint32 QDnsRecordDataSOA::getRefreshInterval() const
127
+        {
128
+            return m_refreshInterval;
129
+        }
130
+
131
+        void QDnsRecordDataSOA::setRefreshInterval(quint32 refreshInterval)
132
+        {
133
+            m_refreshInterval = refreshInterval;
134
+        }
135
+
136
+        quint32 QDnsRecordDataSOA::getRetryInterval() const
137
+        {
138
+            return m_retryInterval;
139
+        }
140
+
141
+        void QDnsRecordDataSOA::setRetryInterval(quint32 retryInterval)
142
+        {
143
+            m_retryInterval = retryInterval;
144
+        }
145
+
146
+        quint32 QDnsRecordDataSOA::getExpirationLimit() const
147
+        {
148
+            return m_expirationLimit;
149
+        }
150
+
151
+        void QDnsRecordDataSOA::setExpirationLimit(quint32 expirationLimit)
152
+        {
153
+            m_expirationLimit = expirationLimit;
154
+        }
155
+
156
+        quint32 QDnsRecordDataSOA::getMinimumTtl() const
157
+        {
158
+            return m_minimumTtl;
159
+        }
160
+
161
+        void QDnsRecordDataSOA::setMinimumTtl(quint32 minimumTtl)
162
+        {
163
+            m_minimumTtl = minimumTtl;
164
+        }
165
+    }
166
+}

+ 2
- 1
src/modules/dns-base/tests/CMakeLists.txt View File

@@ -10,7 +10,8 @@ add_executable(${PROJECT_NAME}
10 10
         DnsPacket.cpp
11 11
         RecordData/DnsRDataA.cpp
12 12
         RecordData/DnsRDataAAAA.cpp
13
-        RecordData/DnsRDataMX.cpp)
13
+        RecordData/DnsRDataMX.cpp
14
+        RecordData/DnsRDataSOA.cpp)
14 15
 
15 16
 target_link_libraries(${PROJECT_NAME} gtest pthread qdnsagg-dns-base)
16 17
 

+ 57
- 0
src/modules/dns-base/tests/RecordData/DnsRDataSOA.cpp View File

@@ -0,0 +1,57 @@
1
+//
2
+// Created by robin on 1/14/18.
3
+//
4
+
5
+#include <gtest/gtest.h>
6
+#include <QByteArray>
7
+#include <QString>
8
+#include <QtNetwork/QHostAddress>
9
+#include <dns-base/RecordData/QDnsRecordDataSOA.h>
10
+
11
+struct DnsRDataSOATestParams
12
+{
13
+    bool isValid;
14
+    const char* hexData;
15
+    quint32 pos;
16
+
17
+    QString primaryNs;
18
+    QString adminMb;
19
+    quint32 serialNumber;
20
+    quint32 refreshInterval;
21
+    quint32 retryInterval;
22
+    quint32 expirationLimit;
23
+    quint32 minimumTtl;
24
+};
25
+
26
+class DnsRDataSOATest : public ::testing::TestWithParam<DnsRDataSOATestParams>
27
+{
28
+};
29
+
30
+TEST_P(DnsRDataSOATest, parseAndGetters)
31
+{
32
+    auto params = GetParam();
33
+    auto data = QByteArray::fromHex(params.hexData);
34
+    auto rdata = QDns::Base::QDnsRecordDataSOA(data, params.pos);
35
+    ASSERT_EQ(rdata.isValid(), params.isValid);
36
+
37
+    if (rdata.isValid())
38
+    {
39
+        ASSERT_EQ(params.primaryNs, rdata.getPrimaryNs());
40
+        ASSERT_EQ(params.adminMb, rdata.getAdminMb());
41
+        ASSERT_EQ(params.serialNumber, rdata.getSerialNumber());
42
+        ASSERT_EQ(params.refreshInterval, rdata.getRefreshInterval());
43
+        ASSERT_EQ(params.retryInterval, rdata.getRetryInterval());
44
+        ASSERT_EQ(params.expirationLimit, rdata.getExpirationLimit());
45
+        ASSERT_EQ(params.minimumTtl, rdata.getMinimumTtl());
46
+
47
+        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
48
+    }
49
+}
50
+
51
+INSTANTIATE_TEST_CASE_P(DnsRDataSOATestInst,
52
+                        DnsRDataSOATest,
53
+                        ::testing::Values(
54
+                                DnsRDataSOATestParams {false, "", 0},
55
+                                DnsRDataSOATestParams {false, "00", 0},
56
+                                DnsRDataSOATestParams {true, "036e733106676f6f676c6503636f6d0009646e732d61646d696e06676f6f676c6503636f6d000ae6ef6f0000038400000384000007080000003c", 0, "ns1.google.com", "dns-admin.google.com", 182906735, 900, 900, 1800, 60}
57
+                        ));

Loading…
Cancel
Save