build: reanimate the dead

Fix build with ndn-cxx 0.7.1 and ChronoSync 0.5.3

* Adapt to new API
* Upgrade to Qt5
* Several other bugs

Refs: #4563, #4087
Change-Id: Ic55d687caade08f557f9b9ec3e9569bc96798710
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index d59a707..d5e0fe2 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -13,11 +13,8 @@
 
 #include <boost/filesystem.hpp>
 #include "cryptopp.hpp"
-#include "logging.h"
 
 
-// INIT_LOGGER ("chronochat.ContactStorage");
-
 namespace chronochat {
 
 namespace fs = boost::filesystem;
@@ -25,8 +22,6 @@
 using std::string;
 using std::vector;
 
-using ndn::PublicKey;
-
 // user's own profile;
 const string INIT_SP_TABLE =
   "CREATE TABLE IF NOT EXISTS                          "
@@ -159,7 +154,7 @@
 static Block
 sqlite3_column_block(sqlite3_stmt* statement, int column)
 {
-  return Block(reinterpret_cast<const char*>(sqlite3_column_blob(statement, column)),
+  return Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(statement, column)),
                sqlite3_column_bytes(statement, column));
 }
 
@@ -257,6 +252,27 @@
   sqlite3_finalize(stmt);
 }
 
+shared_ptr<EndorseCertificate>
+ContactStorage::getSelfEndorseCertificate()
+{
+  shared_ptr<EndorseCertificate> cert;
+
+  sqlite3_stmt *stmt;
+  sqlite3_prepare_v2(m_db,
+                     "SELECT endorse_data FROM SelfEndorse where identity=?",
+                      -1, &stmt, 0);
+  sqlite3_bind_string(stmt, 1, m_identity.toUri(), SQLITE_TRANSIENT);
+
+  if (sqlite3_step(stmt) == SQLITE_ROW) {
+    cert = make_shared<EndorseCertificate>();
+    cert->wireDecode(sqlite3_column_block(stmt, 0));
+  }
+
+  sqlite3_finalize(stmt);
+
+  return cert;
+}
+
 void
 ContactStorage::addEndorseCertificate(const EndorseCertificate& endorseCertificate,
                                       const Name& identity)
@@ -283,7 +299,7 @@
   sqlite3_prepare_v2(m_db,
                      "INSERT OR REPLACE INTO CollectEndorse \
                       (endorser, endorse_name, endorse_data) \
-                      VALUES (?, ?, ?, ?)",
+                      VALUES (?, ?, ?)",
                      -1, &stmt, 0);
   sqlite3_bind_string(stmt, 1, endorserName.toUri(), SQLITE_TRANSIENT);
   sqlite3_bind_string(stmt, 2, certName.toUri(), SQLITE_TRANSIENT);
@@ -315,6 +331,27 @@
   sqlite3_finalize(stmt);
 }
 
+shared_ptr<EndorseCertificate>
+ContactStorage::getCollectEndorseByName(const Name& name)
+{
+  shared_ptr<EndorseCertificate> cert;
+
+  sqlite3_stmt *stmt;
+  sqlite3_prepare_v2(m_db,
+                     "SELECT endorse_name, endorse_data FROM CollectEndorse where endorse_name=?",
+                      -1, &stmt, 0);
+  sqlite3_bind_string(stmt, 1, name.toUri(), SQLITE_TRANSIENT);
+
+  if (sqlite3_step(stmt) == SQLITE_ROW) {
+    cert = make_shared<EndorseCertificate>();
+    cert->wireDecode(sqlite3_column_block(stmt, 1));
+  }
+
+  sqlite3_finalize(stmt);
+
+  return cert;
+}
+
 void
 ContactStorage::getEndorseList(const Name& identity, vector<string>& endorseList)
 {
@@ -375,8 +412,8 @@
   sqlite3_bind_string(stmt, 2, contact.getAlias(), SQLITE_TRANSIENT);
   sqlite3_bind_string(stmt, 3, contact.getPublicKeyName().toUri(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 4,
-                    reinterpret_cast<const char*>(contact.getPublicKey().get().buf()),
-                    contact.getPublicKey().get().size(), SQLITE_TRANSIENT);
+                    reinterpret_cast<const char*>(contact.getPublicKey().data()),
+                    contact.getPublicKey().size(), SQLITE_TRANSIENT);
   sqlite3_bind_int64(stmt, 5, time::toUnixTimestamp(contact.getNotBefore()).count());
   sqlite3_bind_int64(stmt, 6, time::toUnixTimestamp(contact.getNotAfter()).count());
   sqlite3_bind_int(stmt, 7, (isIntroducer ? 1 : 0));
@@ -433,7 +470,7 @@
   if (sqlite3_step(stmt) == SQLITE_ROW) {
     string alias = sqlite3_column_string(stmt, 0);
     string keyName = sqlite3_column_string(stmt, 1);
-    PublicKey key(sqlite3_column_text(stmt, 2), sqlite3_column_bytes (stmt, 2));
+    ndn::Buffer key(sqlite3_column_text(stmt, 2), sqlite3_column_bytes (stmt, 2));
     time::system_clock::TimePoint notBefore =
       time::fromUnixTimestamp(time::milliseconds(sqlite3_column_int64 (stmt, 3)));
     time::system_clock::TimePoint notAfter =
@@ -445,6 +482,9 @@
   }
   sqlite3_finalize(stmt);
 
+  if (!static_cast<bool>(contact))
+    return contact;
+
   sqlite3_prepare_v2(m_db,
                      "SELECT profile_type, profile_value FROM ContactProfile \
                       where profile_identity=?",