Stop using deprecated Data::{get,set}FinalBlockId()

This commit also fixes several build failures with gcc-8 and guards
against a potential crash in WriteHandle::onSegmentDataValidated()

Change-Id: I054f0f8e55f225c293e74fa219b6ee3103dd8e46
Refs: #4526
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index 5c06015..17882bb 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -44,7 +44,7 @@
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
diff --git a/src/handles/watch-handle.cpp b/src/handles/watch-handle.cpp
index bee036f..6fe93d4 100644
--- a/src/handles/watch-handle.cpp
+++ b/src/handles/watch-handle.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -59,7 +59,7 @@
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
@@ -223,7 +223,7 @@
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
@@ -254,7 +254,7 @@
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index 4586bad..0283728 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -57,12 +57,11 @@
 void
 WriteHandle::onValidated(const Interest& interest, const Name& prefix)
 {
-  //m_validResult = 1;
   RepoCommandParameter parameter;
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
@@ -133,23 +132,23 @@
 void
 WriteHandle::onSegmentDataValidated(const Interest& interest, const Data& data, ProcessId processId)
 {
-  if (m_processes.count(processId) == 0) {
+  auto it = m_processes.find(processId);
+  if (it == m_processes.end()) {
     return;
   }
-  RepoCommandResponse& response = m_processes[processId].response;
+  RepoCommandResponse& response = it->second.response;
 
   //refresh endBlockId
-  Name::Component finalBlockId = data.getFinalBlockId();
-
-  if (!finalBlockId.empty()) {
-    SegmentNo final = finalBlockId.toSegment();
+  auto finalBlock = data.getFinalBlock();
+  if (finalBlock && finalBlock->isSegment()) {
+    auto finalSeg = finalBlock->toSegment();
     if (response.hasEndBlockId()) {
-      if (final < response.getEndBlockId()) {
-        response.setEndBlockId(final);
+      if (finalSeg < response.getEndBlockId()) {
+        response.setEndBlockId(finalSeg);
       }
     }
     else {
-      response.setEndBlockId(final);
+      response.setEndBlockId(finalSeg);
     }
   }
 
@@ -386,7 +385,7 @@
   try {
     extractParameter(interest, prefix, parameter);
   }
-  catch (RepoCommandParameter::Error) {
+  catch (const RepoCommandParameter::Error&) {
     negativeReply(interest, 403);
     return;
   }
diff --git a/tools/ndngetfile.cpp b/tools/ndngetfile.cpp
index dbc5b5d..4d26763 100644
--- a/tools/ndngetfile.cpp
+++ b/tools/ndngetfile.cpp
@@ -167,7 +167,7 @@
   uint64_t segment = name[-1].toSegment();
   BOOST_VERIFY(segment == (m_nextSegment - 1));
 
-  const ndn::name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
+  auto finalBlockId = data.getFinalBlock();
   if (finalBlockId == name[-1]) {
     m_isFinished = true;
   }
diff --git a/tools/ndnputfile.cpp b/tools/ndnputfile.cpp
index 6b34376..583d478 100644
--- a/tools/ndnputfile.cpp
+++ b/tools/ndnputfile.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -201,7 +201,7 @@
                                     .appendSegment(m_currentSegmentNo));
 
     if (insertStream->peek() == std::istream::traits_type::eof()) {
-      data->setFinalBlockId(ndn::name::Component::fromSegment(m_currentSegmentNo));
+      data->setFinalBlock(ndn::name::Component::fromSegment(m_currentSegmentNo));
       m_isFinished = true;
     }
 
@@ -318,8 +318,7 @@
 
   if (m_isFinished) {
     uint64_t final = m_currentSegmentNo - 1;
-    item->second->setFinalBlockId(ndn::name::Component::fromSegment(final));
-
+    item->second->setFinalBlock(ndn::name::Component::fromSegment(final));
   }
   m_face.put(*item->second);
 }