daemon: Support query that explicitly specify version

Change-Id: I8eac2c5d2a646fbb965691498f8d416a86b70763
diff --git a/src/daemon/name-server.cpp b/src/daemon/name-server.cpp
index f796e13..7411697 100644
--- a/src/daemon/name-server.cpp
+++ b/src/daemon/name-server.cpp
@@ -95,7 +95,8 @@
 
   NDNS_LOG_TRACE("query record: " << interest.getName());
 
-  if (m_dbMgr.find(rrset)) {
+  if (m_dbMgr.find(rrset) &&
+      (re.version.empty() || re.version == rrset.getVersion())) {
     // find the record: NDNS-RESP, NDNS-AUTH, NDNS-RAW, or NDNS-NACK
     shared_ptr<Data> answer = make_shared<Data>(rrset.getData());
     NDNS_LOG_TRACE("answer query with existing Data: " << answer->getName());
diff --git a/src/ndns-label.cpp b/src/ndns-label.cpp
index 585509c..1b1cc80 100644
--- a/src/ndns-label.cpp
+++ b/src/ndns-label.cpp
@@ -18,6 +18,7 @@
  */
 
 #include "ndns-label.hpp"
+
 #include <ndn-cxx/data.hpp>
 #include <ndn-cxx/interest.hpp>
 
@@ -59,7 +60,7 @@
           const Name& hint, const Name& zone,
           MatchResult& result)
 {
-  // [hint / FHLabel] / zoneName / <Update>|rrLabel / UPDATE|rrType
+  // [hint / FHLabel] / zoneName / <Update>|rrLabel / UPDATE|rrType / [VERSION]
 
   const Name& name = interest.getName();
   size_t skip = calculateSkip(name, hint, zone);
@@ -67,9 +68,17 @@
   if (name.size() - skip < 1)
     return false;
 
-  result.rrType = name.get(-1);
-  result.rrLabel = name.getSubName(skip, std::max<size_t>(0, name.size() - skip - 1));
-  result.version = name::Component();
+  size_t offset = 1;
+  if (name.get(-offset).isVersion()) {
+    result.version = name.get(-offset);
+    ++offset;
+  }
+  else {
+    result.version = name::Component();
+  }
+
+  result.rrType = name.get(-offset);
+  result.rrLabel = name.getSubName(skip, std::max<size_t>(0, name.size() - skip - offset));
 
   return true;
 }