]> granicus.if.org Git - pdns/commitdiff
Add useful comparison and methods to QType
authorRuben d'Arco <cyclops@prof-x.net>
Mon, 3 Dec 2012 04:06:40 +0000 (05:06 +0100)
committermind04 <mind04@monshouwer.org>
Fri, 12 Jul 2013 15:08:00 +0000 (17:08 +0200)
These methods are used for rfc2136 to determine some requirements. The comparison operaters simply make it easy to compare things
in the code itself.

Some QTypes have been added because that's how RFC2136 defines them.

pdns/qtype.cc
pdns/qtype.hh

index 3b00d6ab338e3d381c76a955c048182c6d81813b..52ee10176cea81a265059167ccebb52f2ac50193 100644 (file)
@@ -35,11 +35,30 @@ QType::QType()
 {
 }
 
+bool QType::isSupportedType() {
+  for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
+    if(pos->second==code) 
+      return true;
+  return false;
+}
+
+bool QType::isMetadataType() {
+  if (code == QType::AXFR ||
+      code == QType::MAILA ||
+      code == QType::MAILB ||
+      code == QType::TSIG ||
+      code == QType::IXFR)  
+    return true;
+
+  return false;
+}
+
 uint16_t QType::getCode() const
 {
   return code;
 }
 
+
 const string QType::getName() const
 {
   vector<namenum>::iterator pos;
@@ -80,6 +99,21 @@ QType &QType::operator=(const char *p)
   return *this;
 }
 
+bool QType::operator==(const QType &comp) const
+{
+  return(comp.code==code);
+}
+
+bool QType::operator!=(const QType &comp) const
+{
+  return(comp.code!=code);
+}
+
+bool QType::operator==(const uint16_t comp) const
+{
+  return(comp==code);
+}
+
 QType &QType::operator=(const string &s)
 {
   code=chartocode(s.c_str());
index a4d34267ee29bd617b72312a3991297d9d313cb6..42729128d3278cc7a9824b92e7d9f6ecc36f46c5 100644 (file)
@@ -69,15 +69,22 @@ public:
     ar & code;
   }
 
+  bool operator!=(const QType &) const; //!< not equal operator
+  bool operator==(const QType &) const; //!< equality operator
+  bool operator==(const uint16_t) const; //!< equality operator
+
   const string getName() const; //!< Get a string representation of this type
   uint16_t getCode() const; //!< Get the integer representation of this type
+  bool isSupportedType();
+  bool isMetadataType();
 
   static int chartocode(const char *p); //!< convert a character string to a code
 // more solaris fun
 #undef DS   
-  enum typeenum {A=1,NS=2,CNAME=5,SOA=6, MR=9, PTR=12,HINFO=13,MX=15,TXT=16,RP=17,AFSDB=18, SIG=24, KEY=25,AAAA=28,LOC=29,SRV=33,NAPTR=35, KX=36, 
-                CERT=37, A6=38, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51,
-                TLSA=52, SPF=99, EUI48=108, EUI64=109, TSIG=250, AXFR=252, IXFR=251, ANY=255, URL=256, MBOXFW=257, CURL=258, ADDR=259, DLV=32769} types;
+  enum typeenum {A=1,NS=2,CNAME=5,SOA=6, MR=9, PTR=12,HINFO=13,MX=15,TXT=16,RP=17,AFSDB=18, SIG=24, KEY=25,AAAA=28,LOC=29,SRV=33,NAPTR=35, KX=36,
+    CERT=37, A6=38, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51,
+    TLSA=52, SPF=99, EUI48=108, EUI64=109, TSIG=250, AXFR=252, IXFR=251, ANY=255, URL=256, MBOXFW=257, CURL=258, ADDR=259, DLV=32769} types;
+    
   typedef pair<string,uint16_t> namenum; 
   static vector<namenum> names;