Browse Source

[trac493] Add canMessageBeCached() to message utility functions

Ocean Wang 14 years ago
parent
commit
6b5705bb7f

+ 1 - 4
src/lib/cache/message_cache.cc

@@ -61,10 +61,7 @@ MessageCache::lookup(const isc::dns::Name& qname,
 
 bool
 MessageCache::update(const Message& msg) {
-    // If the message is a negative response, but no SOA record is found in
-    // the authority section, the message cannot be cached
-    if (isNegativeResponse(msg) &&
-        !hasTheRecordInAuthoritySection(msg, RRType::SOA())){
+    if (!canMessageBeCached(msg)){
         return (false);
     }
 

+ 15 - 3
src/lib/cache/message_utility.cc

@@ -24,7 +24,8 @@ namespace cache {
 namespace MessageUtility{
 
 bool
-hasTheRecordInAuthoritySection(const isc::dns::Message& msg, const isc::dns::RRType& type)
+hasTheRecordInAuthoritySection(const isc::dns::Message& msg,
+                               const isc::dns::RRType& type)
 {
     for (RRsetIterator iter = msg.beginSection(Message::SECTION_AUTHORITY);
             iter != msg.endSection(Message::SECTION_AUTHORITY);
@@ -38,8 +39,7 @@ hasTheRecordInAuthoritySection(const isc::dns::Message& msg, const isc::dns::RRT
 }
 
 bool
-isNegativeResponse(const isc::dns::Message& msg)
-{
+isNegativeResponse(const isc::dns::Message& msg) {
     if (msg.getRcode() == Rcode::NXDOMAIN()) {
         return (true);
     } else if (msg.getRcode() == Rcode::NOERROR()) {
@@ -58,6 +58,18 @@ isNegativeResponse(const isc::dns::Message& msg)
     return (false);
 }
 
+bool
+canMessageBeCached(const isc::dns::Message& msg) {
+    // If the message is a negative response, but no SOA record is found in
+    // the authority section, the message cannot be cached
+    if (isNegativeResponse(msg) &&
+        !hasTheRecordInAuthoritySection(msg, RRType::SOA())){
+        return (false);
+    }
+
+    return (true);
+}
+
 } // namespace MessageUtility
 } // namespace cache
 } // namespace isc

+ 5 - 0
src/lib/cache/message_utility.h

@@ -43,6 +43,11 @@ bool hasTheRecordInAuthoritySection(const isc::dns::Message& msg,
 /// \param msg The response message
 bool isNegativeResponse(const isc::dns::Message& msg);
 
+/// \brief Check whether the message can be cached
+///
+/// \param msg The response message
+bool canMessageBeCached(const isc::dns::Message& msg);
+
 } // namespace MessageUtility
 } // namespace cache
 } // namespace isc