Browse Source

Moved enums and added Q_ENUM

develop
Robin Thoni 6 years ago
parent
commit
3ffdd8a23e

+ 140
- 129
src/modules/dns-base/includes/dns-base/QDnsBase.h View File

@@ -5,143 +5,154 @@
5 5
 #ifndef QDNSAGG_QDNSBASE_H
6 6
 #define QDNSAGG_QDNSBASE_H
7 7
 
8
+#include <QObject>
9
+
8 10
 namespace QDns
9 11
 {
10 12
     namespace Base
11 13
     {
12
-        /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5 */
13
-        enum HeaderOpcode
14
+        class QDnsBase : public QObject
14 15
         {
15
-            Query = 0,
16
-            IQuery = 1,
17
-            Status = 2,
18
-            Notify = 4,
19
-            Update = 5
20
-        };
16
+            Q_OBJECT
17
+        public:
18
+            /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5 */
19
+            enum HeaderOpcode
20
+            {
21
+                Query = 0,
22
+                IQuery = 1,
23
+                Status = 2,
24
+                Notify = 4,
25
+                Update = 5
26
+            };
27
+            Q_ENUM(HeaderOpcode)
21 28
 
22
-        /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 */
23
-        enum HeaderReplyCode
24
-        {
25
-            NoError = 0,
26
-            FormErr = 1,
27
-            ServFail = 2,
28
-            NXDomain = 3,
29
-            NotImp = 4,
30
-            Refused = 5,
31
-            YXDomain = 6,
32
-            YXRRSet = 7,
33
-            NXRRSet = 8,
34
-            NotAuth = 9,
35
-            NotZone = 10,
36
-            BADVERS = 16, /* BADSIG */
37
-            BADKEY = 17,
38
-            BADTIME = 18,
39
-            BADMODE = 19,
40
-            BADNAME = 20,
41
-            BADALG = 21,
42
-            BADTRUNC = 22,
43
-            BADCOOKIE = 23,
44
-        };
29
+            /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 */
30
+            enum HeaderReplyCode
31
+            {
32
+                NoError = 0,
33
+                FormErr = 1,
34
+                ServFail = 2,
35
+                NXDomain = 3,
36
+                NotImp = 4,
37
+                Refused = 5,
38
+                YXDomain = 6,
39
+                YXRRSet = 7,
40
+                NXRRSet = 8,
41
+                NotAuth = 9,
42
+                NotZone = 10,
43
+                BADVERS = 16, /* BADSIG */
44
+                BADKEY = 17,
45
+                BADTIME = 18,
46
+                BADMODE = 19,
47
+                BADNAME = 20,
48
+                BADALG = 21,
49
+                BADTRUNC = 22,
50
+                BADCOOKIE = 23,
51
+            };
52
+            Q_ENUM(HeaderReplyCode)
45 53
 
46
-        /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 */
47
-        enum RecordType
48
-        {
49
-            A = 1,
50
-            NS = 2,
51
-            MD = 3,
52
-            MF = 4,
53
-            CNAME = 5,
54
-            SOA = 6,
55
-            MB = 7,
56
-            MG = 8,
57
-            MR = 9,
58
-            _NULL = 10,
59
-            WKS = 11,
60
-            PTR = 12,
61
-            HINFO = 13,
62
-            MINFO = 14,
63
-            MX = 15,
64
-            TXT = 16,
65
-            RP = 17,
66
-            AFSDB = 18,
67
-            X25 = 19,
68
-            ISDN = 20,
69
-            RT = 21,
70
-            NSAP = 22,
71
-            NSAPPTR = 23,
72
-            SIG = 24,
73
-            KEY = 25,
74
-            PX = 26,
75
-            GPOS = 27,
76
-            AAAA = 28,
77
-            LOC = 29,
78
-            NXT = 30,
79
-            EID = 31,
80
-            NIMLOC = 32,
81
-            SRV = 33,
82
-            ATMA = 34,
83
-            NAPTR = 35,
84
-            KX = 36,
85
-            CERT = 37,
86
-            A6 = 38,
87
-            DNAME = 39,
88
-            SINK = 40,
89
-            OPT = 41,
90
-            APL = 42,
91
-            DS = 43,
92
-            SSHFP = 44,
93
-            IPSECKEY = 45,
94
-            RRSIG = 46,
95
-            NSEC = 47,
96
-            DNSKEY = 48,
97
-            DHCID = 49,
98
-            NSEC3 = 50,
99
-            NSEC3PARAM = 51,
100
-            TLSA = 52,
101
-            SMIMEA = 53,
102
-            Unassigned = 54,
103
-            HIP = 55,
104
-            NINFO = 56,
105
-            RKEY = 57,
106
-            TALINK = 58,
107
-            CDS = 59,
108
-            CDNSKEY = 60,
109
-            OPENPGPKEY = 61,
110
-            CSYNC = 62,
111
-            SPF = 99,
112
-            UINFO = 100,
113
-            UID = 101,
114
-            GID = 102,
115
-            UNSPEC = 103,
116
-            NID = 104,
117
-            L32 = 105,
118
-            L64 = 106,
119
-            LP = 107,
120
-            EUI48 = 108,
121
-            EUI64 = 109,
122
-            TKEY = 249,
123
-            TSIG = 250,
124
-            IXFR = 251,
125
-            AXFR = 252,
126
-            MAILB = 253,
127
-            MAILA = 254,
128
-            ANY = 255,
129
-            URI = 256,
130
-            CAA = 257,
131
-            AVC = 258,
132
-            DOA = 259,
133
-            TA = 32768,
134
-            DLV = 32769
135
-        };
54
+            /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 */
55
+            enum RecordType
56
+            {
57
+                A = 1,
58
+                NS = 2,
59
+                MD = 3,
60
+                MF = 4,
61
+                CNAME = 5,
62
+                SOA = 6,
63
+                MB = 7,
64
+                MG = 8,
65
+                MR = 9,
66
+                _NULL = 10,
67
+                WKS = 11,
68
+                PTR = 12,
69
+                HINFO = 13,
70
+                MINFO = 14,
71
+                MX = 15,
72
+                TXT = 16,
73
+                RP = 17,
74
+                AFSDB = 18,
75
+                X25 = 19,
76
+                ISDN = 20,
77
+                RT = 21,
78
+                NSAP = 22,
79
+                NSAPPTR = 23,
80
+                SIG = 24,
81
+                KEY = 25,
82
+                PX = 26,
83
+                GPOS = 27,
84
+                AAAA = 28,
85
+                LOC = 29,
86
+                NXT = 30,
87
+                EID = 31,
88
+                NIMLOC = 32,
89
+                SRV = 33,
90
+                ATMA = 34,
91
+                NAPTR = 35,
92
+                KX = 36,
93
+                CERT = 37,
94
+                A6 = 38,
95
+                DNAME = 39,
96
+                SINK = 40,
97
+                OPT = 41,
98
+                APL = 42,
99
+                DS = 43,
100
+                SSHFP = 44,
101
+                IPSECKEY = 45,
102
+                RRSIG = 46,
103
+                NSEC = 47,
104
+                DNSKEY = 48,
105
+                DHCID = 49,
106
+                NSEC3 = 50,
107
+                NSEC3PARAM = 51,
108
+                TLSA = 52,
109
+                SMIMEA = 53,
110
+                Unassigned = 54,
111
+                HIP = 55,
112
+                NINFO = 56,
113
+                RKEY = 57,
114
+                TALINK = 58,
115
+                CDS = 59,
116
+                CDNSKEY = 60,
117
+                OPENPGPKEY = 61,
118
+                CSYNC = 62,
119
+                SPF = 99,
120
+                UINFO = 100,
121
+                UID = 101,
122
+                GID = 102,
123
+                UNSPEC = 103,
124
+                NID = 104,
125
+                L32 = 105,
126
+                L64 = 106,
127
+                LP = 107,
128
+                EUI48 = 108,
129
+                EUI64 = 109,
130
+                TKEY = 249,
131
+                TSIG = 250,
132
+                IXFR = 251,
133
+                AXFR = 252,
134
+                MAILB = 253,
135
+                MAILA = 254,
136
+                ANY = 255,
137
+                URI = 256,
138
+                CAA = 257,
139
+                AVC = 258,
140
+                DOA = 259,
141
+                TA = 32768,
142
+                DLV = 32769
143
+            };
144
+            Q_ENUM(RecordType)
136 145
 
137
-        /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-2 */
138
-        enum RecordClass
139
-        {
140
-            IN = 1,
141
-            CH = 3,
142
-            HS = 4,
143
-            QCLASSNONE = 254,
144
-            QCLASSANY = 255
146
+            /* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-2 */
147
+            enum RecordClass
148
+            {
149
+                IN = 1,
150
+                CH = 3,
151
+                HS = 4,
152
+                QCLASSNONE = 254,
153
+                QCLASSANY = 255
154
+            };
155
+            Q_ENUM(RecordClass)
145 156
         };
146 157
     }
147 158
 }

+ 4
- 4
src/modules/dns-base/includes/dns-base/QDnsHeader.h View File

@@ -50,9 +50,9 @@ namespace QDns
50 50
 
51 51
             void setIsQuery(bool isQuery);
52 52
 
53
-            HeaderOpcode getOpcode() const;
53
+            QDnsBase::HeaderOpcode getOpcode() const;
54 54
 
55
-            void setOpcode(HeaderOpcode opcode);
55
+            void setOpcode(QDnsBase::HeaderOpcode opcode);
56 56
 
57 57
             bool isAuthoritative() const;
58 58
 
@@ -78,9 +78,9 @@ namespace QDns
78 78
 
79 79
             void setNonAuthenticatedAcceptable(bool isNonAuthenticatedAcceptable);
80 80
 
81
-            HeaderReplyCode getReplyCode() const;
81
+            QDnsBase::HeaderReplyCode getReplyCode() const;
82 82
 
83
-            void setReplyCode(HeaderReplyCode replyCode);
83
+            void setReplyCode(QDnsBase::HeaderReplyCode replyCode);
84 84
 
85 85
 
86 86
             quint16 getQueryCount() const;

+ 1
- 1
src/modules/dns-base/includes/dns-base/QDnsPacket.h View File

@@ -53,7 +53,7 @@ namespace QDns
53 53
 
54 54
             void setAdditionalRecords(const QList<QDnsResourceRecord> &additionalRecords);
55 55
 
56
-            static QDnsPacket makeSimpleQuery(const QString& host, RecordType type);
56
+            static QDnsPacket makeSimpleQuery(const QString& host, QDnsBase::RecordType type);
57 57
 
58 58
         private:
59 59
             void parse(const QByteArray &data, QDataStream &dataStream);

+ 4
- 4
src/modules/dns-base/includes/dns-base/QDnsQuery.h View File

@@ -34,13 +34,13 @@ namespace QDns
34 34
 
35 35
             void setName(const QString &name);
36 36
 
37
-            RecordType getType() const;
37
+            QDnsBase::RecordType getType() const;
38 38
 
39
-            void setType(RecordType type);
39
+            void setType(QDnsBase::RecordType type);
40 40
 
41
-            RecordClass getClass() const;
41
+            QDnsBase::RecordClass getClass() const;
42 42
 
43
-            void setClass(RecordClass aClass);
43
+            void setClass(QDnsBase::RecordClass aClass);
44 44
 
45 45
         private:
46 46
             void parse(const QByteArray &packetData, QDataStream &dataStream);

+ 6
- 6
src/modules/dns-base/src/QDnsHeader.cpp View File

@@ -134,12 +134,12 @@ namespace QDns
134 134
             setFlagBits(0, (quint8) !isQuery, 1);
135 135
         }
136 136
 
137
-        HeaderOpcode QDnsHeader::getOpcode() const
137
+        QDnsBase::HeaderOpcode QDnsHeader::getOpcode() const
138 138
         {
139
-            return (HeaderOpcode) getFlagBits(4, 4);
139
+            return (QDnsBase::HeaderOpcode) getFlagBits(4, 4);
140 140
         }
141 141
 
142
-        void QDnsHeader::setOpcode(HeaderOpcode opcode)
142
+        void QDnsHeader::setOpcode(QDnsBase::HeaderOpcode opcode)
143 143
         {
144 144
             setFlagBits(4, (quint8) opcode, 4);
145 145
         }
@@ -204,12 +204,12 @@ namespace QDns
204 204
             setFlagBits(11, (quint8) isNonAuthenticatedAcceptable, 1);
205 205
         }
206 206
 
207
-        HeaderReplyCode QDnsHeader::getReplyCode() const
207
+        QDnsBase::HeaderReplyCode QDnsHeader::getReplyCode() const
208 208
         {
209
-            return (HeaderReplyCode) getFlagBits(15, 4);
209
+            return (QDnsBase::HeaderReplyCode) getFlagBits(15, 4);
210 210
         }
211 211
 
212
-        void QDnsHeader::setReplyCode(HeaderReplyCode replyCode)
212
+        void QDnsHeader::setReplyCode(QDnsBase::HeaderReplyCode replyCode)
213 213
         {
214 214
             setFlagBits(15, (quint8) replyCode, 4);
215 215
         }

+ 2
- 2
src/modules/dns-base/src/QDnsPacket.cpp View File

@@ -180,7 +180,7 @@ namespace QDns
180 180
             m_header.setAdditionalCount((quint16) m_additionalRecords.length());
181 181
         }
182 182
 
183
-        QDnsPacket QDnsPacket::makeSimpleQuery(const QString& host, RecordType type)
183
+        QDnsPacket QDnsPacket::makeSimpleQuery(const QString& host, QDnsBase::RecordType type)
184 184
         {
185 185
             QDns::Base::QDnsPacket packet;
186 186
             auto header = packet.getHeader();
@@ -189,7 +189,7 @@ namespace QDns
189 189
             packet.setHeader(header);
190 190
             QDns::Base::QDnsQuery query;
191 191
             query.setName(host);
192
-            query.setClass(QDns::Base::RecordClass::IN);
192
+            query.setClass(QDns::Base::QDnsBase::RecordClass::IN);
193 193
             query.setType(type);
194 194
             packet.setQueries(QList<QDns::Base::QDnsQuery>() << query);
195 195
             return packet;

+ 8
- 8
src/modules/dns-base/src/QDnsQuery.cpp View File

@@ -11,8 +11,8 @@ namespace QDns
11 11
     {
12 12
         QDnsQuery::QDnsQuery()
13 13
                 : m_isValid(true)
14
-                  , m_type(RecordType::A)
15
-                  , m_class(RecordClass::IN)
14
+                  , m_type(QDnsBase::RecordType::A)
15
+                  , m_class(QDnsBase::RecordClass::IN)
16 16
         {
17 17
         }
18 18
 
@@ -74,22 +74,22 @@ namespace QDns
74 74
             m_name = name;
75 75
         }
76 76
 
77
-        RecordType QDnsQuery::getType() const
77
+        QDnsBase::RecordType QDnsQuery::getType() const
78 78
         {
79
-            return (RecordType) m_type;
79
+            return (QDnsBase::RecordType) m_type;
80 80
         }
81 81
 
82
-        void QDnsQuery::setType(RecordType type)
82
+        void QDnsQuery::setType(QDnsBase::RecordType type)
83 83
         {
84 84
             m_type = type;
85 85
         }
86 86
 
87
-        RecordClass QDnsQuery::getClass() const
87
+        QDnsBase::RecordClass QDnsQuery::getClass() const
88 88
         {
89
-            return (RecordClass) m_class;
89
+            return (QDnsBase::RecordClass) m_class;
90 90
         }
91 91
 
92
-        void QDnsQuery::setClass(RecordClass aClass)
92
+        void QDnsQuery::setClass(QDnsBase::RecordClass aClass)
93 93
         {
94 94
             m_class = aClass;
95 95
         }

+ 10
- 10
src/modules/dns-base/tests/DnsHeader.cpp View File

@@ -15,7 +15,7 @@ struct DnsHeaderTestParams
15 15
 
16 16
     quint16 flags;
17 17
     bool flagQuery;
18
-    QDns::Base::HeaderOpcode flagOpcode;
18
+    QDns::Base::QDnsBase::HeaderOpcode flagOpcode;
19 19
     bool flagAuthoritative;
20 20
     bool flagTruncated;
21 21
     bool flagRecursionDesired;
@@ -23,7 +23,7 @@ struct DnsHeaderTestParams
23 23
     bool flagReserved0;
24 24
     bool flagAnswerAuthenticated;
25 25
     bool flagNonAuthenticatedAcceptable;
26
-    QDns::Base::HeaderReplyCode flagReplyCode;
26
+    QDns::Base::QDnsBase::HeaderReplyCode flagReplyCode;
27 27
 
28 28
     quint16 queryCount;
29 29
     quint16 answerCount;
@@ -166,7 +166,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
166 166
 
167 167
                                                      0x0100,
168 168
                                                      true,
169
-                                                     QDns::Base::HeaderOpcode::Query,
169
+                                                     QDns::Base::QDnsBase::HeaderOpcode::Query,
170 170
                                                      false,
171 171
                                                      false,
172 172
                                                      true,
@@ -174,7 +174,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
174 174
                                                      false,
175 175
                                                      false,
176 176
                                                      false,
177
-                                                     QDns::Base::HeaderReplyCode::NoError,
177
+                                                     QDns::Base::QDnsBase::HeaderReplyCode::NoError,
178 178
 
179 179
                                                      1,
180 180
                                                      0,
@@ -186,7 +186,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
186 186
                                                      0x3cdc,
187 187
                                                      0x8180,
188 188
                                                      false,
189
-                                                     QDns::Base::HeaderOpcode::Query,
189
+                                                     QDns::Base::QDnsBase::HeaderOpcode::Query,
190 190
                                                      false,
191 191
                                                      false,
192 192
                                                      true,
@@ -194,7 +194,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
194 194
                                                      false,
195 195
                                                      false,
196 196
                                                      false,
197
-                                                     QDns::Base::HeaderReplyCode::NoError,
197
+                                                     QDns::Base::QDnsBase::HeaderReplyCode::NoError,
198 198
 
199 199
                                                      1,
200 200
                                                      1,
@@ -207,7 +207,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
207 207
                                                      0x3cdc,
208 208
                                                      0xaaaa,
209 209
                                                      false,
210
-                                                     QDns::Base::HeaderOpcode::Update,
210
+                                                     QDns::Base::QDnsBase::HeaderOpcode::Update,
211 211
                                                      false,
212 212
                                                      true,
213 213
                                                      false,
@@ -215,7 +215,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
215 215
                                                      false,
216 216
                                                      true,
217 217
                                                      false,
218
-                                                     QDns::Base::HeaderReplyCode::NotZone,
218
+                                                     QDns::Base::QDnsBase::HeaderReplyCode::NotZone,
219 219
 
220 220
                                                      43690,
221 221
                                                      21845,
@@ -227,7 +227,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
227 227
                                                      0x3cdc,
228 228
                                                      0x5555,
229 229
                                                      true,
230
-                                                     (QDns::Base::HeaderOpcode) 10,
230
+                                                     (QDns::Base::QDnsBase::HeaderOpcode) 10,
231 231
                                                      true,
232 232
                                                      false,
233 233
                                                      true,
@@ -235,7 +235,7 @@ INSTANTIATE_TEST_CASE_P(DnsHeaderTestInst,
235 235
                                                      true,
236 236
                                                      false,
237 237
                                                      true,
238
-                                                     QDns::Base::HeaderReplyCode::Refused,
238
+                                                     QDns::Base::QDnsBase::HeaderReplyCode::Refused,
239 239
 
240 240
                                                      22015,
241 241
                                                      43690,

+ 8
- 8
src/modules/dns-base/tests/DnsQuery.cpp View File

@@ -72,8 +72,8 @@ struct DnsQuerySerializeTestParams
72 72
     const char* hexData;
73 73
 
74 74
     const char* name;
75
-    QDns::Base::RecordType type;
76
-    QDns::Base::RecordClass clazz;
75
+    QDns::Base::QDnsBase::RecordType type;
76
+    QDns::Base::QDnsBase::RecordClass clazz;
77 77
 };
78 78
 
79 79
 class DnsQuerySerializeTest : public ::testing::TestWithParam<DnsQuerySerializeTestParams>
@@ -97,17 +97,17 @@ INSTANTIATE_TEST_CASE_P(DnsQuerySerializeTestInst,
97 97
                         ::testing::Values(
98 98
                                 DnsQuerySerializeTestParams {"0266720000020004",
99 99
                                                              "fr",
100
-                                                             QDns::Base::RecordType::NS,
101
-                                                             QDns::Base::RecordClass::HS
100
+                                                             QDns::Base::QDnsBase::RecordType::NS,
101
+                                                             QDns::Base::QDnsBase::RecordClass::HS
102 102
                                 },
103 103
                                 DnsQuerySerializeTestParams {"06676f6f676c650266720000010001",
104 104
                                                              "google.fr",
105
-                                                             QDns::Base::RecordType::A,
106
-                                                             QDns::Base::RecordClass::IN
105
+                                                             QDns::Base::QDnsBase::RecordType::A,
106
+                                                             QDns::Base::QDnsBase::RecordClass::IN
107 107
                                 },
108 108
                                 DnsQuerySerializeTestParams {"03777777067274686f6e6903636f6d0000010001",
109 109
                                                              "www.rthoni.com",
110
-                                                             QDns::Base::RecordType::A,
111
-                                                             QDns::Base::RecordClass::IN
110
+                                                             QDns::Base::QDnsBase::RecordType::A,
111
+                                                             QDns::Base::QDnsBase::RecordClass::IN
112 112
                                 }
113 113
                         ));

Loading…
Cancel
Save