Replace ndnsType with NdnsContentType

Change-Id: I74afe92d31e78d80404816113063d7f996d666c5
diff --git a/src/clients/iterative-query-controller.cpp b/src/clients/iterative-query-controller.cpp
index 6bd99bd..899a35c 100644
--- a/src/clients/iterative-query-controller.cpp
+++ b/src/clients/iterative-query-controller.cpp
@@ -63,20 +63,16 @@
 void
 IterativeQueryController::onData(const ndn::Interest& interest, const Data& data)
 {
-  NdnsType ndnsType = NDNS_RAW;
-  const Block* block = data.getMetaInfo().findAppMetaInfo(ndns::tlv::NdnsType);
-  if (block != nullptr) {
-    ndnsType = static_cast<NdnsType>(readNonNegativeInteger(*block));
-  }
+  NdnsContentType contentType = NdnsContentType(data.getContentType());
 
-  NDNS_LOG_TRACE("[* -> *] get a " << ndnsType
+  NDNS_LOG_TRACE("[* -> *] get a " << contentType
                  << " Response: " << data.getName());
   if (m_validator == nullptr) {
-    this->onDataValidated(make_shared<Data>(data), ndnsType);
+    this->onDataValidated(make_shared<Data>(data), contentType);
   }
   else {
     m_validator->validate(data,
-                          bind(&IterativeQueryController::onDataValidated, this, _1, ndnsType),
+                          bind(&IterativeQueryController::onDataValidated, this, _1, contentType),
                           [this] (const shared_ptr<const Data>& data, const std::string& str) {
                             NDNS_LOG_WARN("data: " << data->getName() << " fails verification");
                             this->abort();
@@ -85,22 +81,22 @@
   }
 }
 void
-IterativeQueryController::onDataValidated(const shared_ptr<const Data>& data, NdnsType ndnsType)
+IterativeQueryController::onDataValidated(const shared_ptr<const Data>& data, NdnsContentType contentType)
 {
   switch (m_step) {
   case QUERY_STEP_QUERY_NS:
-    if (ndnsType == NDNS_NACK) {
+    if (contentType == NDNS_NACK) {
       m_step = QUERY_STEP_QUERY_RR;
     }
-    else if (ndnsType == NDNS_RESP) {
-      if (m_rrType == label::NS_RR_TYPE) {
-        Link link(data->wireEncode());
-        if (link.getDelegations().empty()) {
-          m_lastLink = Block();
-        } else {
-          m_lastLink = data->wireEncode();
-        }
+    else if (contentType == NDNS_LINK) {
+      Link link(data->wireEncode());
+      if (link.getDelegations().empty()) {
+        m_lastLink = Block();
+      } else {
+        m_lastLink = data->wireEncode();
       }
+
+      // for NS query, if already received, just return, instead of more queries until NACK
       if (m_nFinishedComps + m_nTryComps == m_dstLabel.size() && m_rrType == label::NS_RR_TYPE) {
         // NS_RR_TYPE is different, since its record is stored at higher level
         m_step = QUERY_STEP_ANSWER_STUB;
@@ -110,13 +106,17 @@
         m_nTryComps = 1;
       }
     }
-    else if (ndnsType == NDNS_AUTH) {
+    else if (contentType == NDNS_AUTH) {
       m_nTryComps += 1;
     }
-    else if (ndnsType == NDNS_RAW) {
+    else if (contentType == NDNS_BLOB) {
       std::ostringstream oss;
       oss << *this;
-      NDNS_LOG_WARN("get unexpected Response: NDNS_RAW for QUERY_NS: " << oss.str());
+      NDNS_LOG_WARN("get unexpected Response: NDNS_BLOB for QUERY_NS: " << oss.str());
+    } else {
+      std::ostringstream oss;
+      oss << *this;
+      NDNS_LOG_WARN("get unexpected Response for QUERY_NS: " << oss.str());
     }
     //
     if (m_nFinishedComps + m_nTryComps > m_dstLabel.size()) {
diff --git a/src/clients/iterative-query-controller.hpp b/src/clients/iterative-query-controller.hpp
index 8fc2a34..7f975da 100644
--- a/src/clients/iterative-query-controller.hpp
+++ b/src/clients/iterative-query-controller.hpp
@@ -78,7 +78,7 @@
   onData(const ndn::Interest& interest, const Data& data);
 
   void
-  onDataValidated(const shared_ptr<const Data>& data, NdnsType ndnsType);
+  onDataValidated(const shared_ptr<const Data>& data, NdnsContentType contentType);
 
   /**
    * @brief change the Controller state according to timeout. For current,
diff --git a/src/clients/response.cpp b/src/clients/response.cpp
index fc14346..0bbc9de 100644
--- a/src/clients/response.cpp
+++ b/src/clients/response.cpp
@@ -24,7 +24,7 @@
 namespace ndns {
 
 Response::Response()
-  : m_ndnsType(NDNS_RAW)
+  : m_contentType(NDNS_BLOB)
   , m_freshnessPeriod(DEFAULT_RR_FRESHNESS_PERIOD)
   , m_appContent(makeBinaryBlock(ndn::tlv::Content, reinterpret_cast<const uint8_t*>(0), 0))
 {
@@ -33,7 +33,7 @@
 Response::Response(const Name& zone, const name::Component& queryType)
   : m_zone(zone)
   , m_queryType(queryType)
-  , m_ndnsType(NDNS_RAW)
+  , m_contentType(NDNS_BLOB)
   , m_freshnessPeriod(DEFAULT_RR_FRESHNESS_PERIOD)
   , m_appContent(makeBinaryBlock(ndn::tlv::Content, reinterpret_cast<const uint8_t*>(0), 0))
 {
@@ -43,7 +43,7 @@
 inline size_t
 Response::wireEncode(EncodingImpl<T>& block) const
 {
-  if (m_ndnsType == NDNS_RAW) {
+  if (m_contentType == NDNS_BLOB) {
     // Raw application content
     return block.prependBlock(m_appContent);
   }
@@ -66,7 +66,7 @@
 const Block
 Response::wireEncode() const
 {
-  if (m_ndnsType == NDNS_RAW) {
+  if (m_contentType == NDNS_BLOB) {
     return m_appContent;
   }
 
@@ -80,7 +80,7 @@
 void
 Response::wireDecode(const Block& wire)
 {
-  if (m_ndnsType == NDNS_RAW) {
+  if (m_contentType == NDNS_BLOB) {
     m_appContent = wire;
     return;
   }
@@ -111,9 +111,7 @@
   MetaInfo info = data.getMetaInfo();
 
   m_freshnessPeriod = time::duration_cast<time::seconds>(info.getFreshnessPeriod());
-  const Block* block = info.findAppMetaInfo(tlv::NdnsType);
-  if (block != 0)
-    m_ndnsType = static_cast<NdnsType>(readNonNegativeInteger(*block));
+  m_contentType = NdnsContentType(data.getContentType());
 
   wireDecode(data.getContent());
   return true;
@@ -139,17 +137,14 @@
 
   shared_ptr<Data> data = make_shared<Data>(name);
 
-  MetaInfo info;
-  info.setFreshnessPeriod(m_freshnessPeriod);
-
-  if (m_ndnsType != NDNS_RAW) {
-    info.addAppMetaInfo(makeNonNegativeIntegerBlock(ndns::tlv::NdnsType, m_ndnsType));
+  if (m_contentType != NDNS_BLOB) {
     data->setContent(this->wireEncode());
   }
   else {
     data->setContent(m_appContent);
   }
-  data->setMetaInfo(info);
+  data->setFreshnessPeriod(m_freshnessPeriod);
+  data->setContentType(m_contentType);
 
   return data;
 }
@@ -198,12 +193,12 @@
   bool tmp = (getZone() == other.getZone() &&
               getQueryType() == other.getQueryType() && getRrLabel() == other.getRrLabel() &&
               getRrType() == other.getRrType() && getVersion() == other.getVersion() &&
-              getNdnsType() == other.getNdnsType());
+              getContentType() == other.getContentType());
 
   if (tmp == false)
     return tmp;
 
-  if (m_ndnsType == NDNS_RAW) {
+  if (m_contentType == NDNS_BLOB) {
     return tmp && (getAppContent() == other.getAppContent());
   }
   else
@@ -219,8 +214,8 @@
      << " rrType=" << response.getRrType()
      << " version=" << response.getVersion()
      << " freshnessPeriod=" << response.getFreshnessPeriod()
-     << " ndnsType=" << response.getNdnsType();
-  if (response.getNdnsType() == NDNS_RAW) {
+     << " NdnsContentType=" << response.getContentType();
+  if (response.getContentType() == NDNS_BLOB) {
     if (response.getAppContent().empty())
       os << " appContent=NULL";
     else
diff --git a/src/clients/response.hpp b/src/clients/response.hpp
index c6a2779..9f2138f 100644
--- a/src/clients/response.hpp
+++ b/src/clients/response.hpp
@@ -177,15 +177,15 @@
   }
 
   void
-  setNdnsType(NdnsType ndnsType)
+  setContentType(NdnsContentType contentType)
   {
-    m_ndnsType = ndnsType;
+    m_contentType = contentType;
   }
 
-  NdnsType
-  getNdnsType() const
+  NdnsContentType
+  getContentType() const
   {
-    return m_ndnsType;
+    return m_contentType;
   }
 
   const Block&
@@ -228,7 +228,7 @@
   name::Component m_rrType;
   name::Component m_version;
 
-  NdnsType m_ndnsType;
+  NdnsContentType m_contentType;
   time::seconds m_freshnessPeriod;
 
   /**