build: Finalizing waf building system (removing legacy code)

Change-Id: Ie7e7cc84e19551e3dd5dd0405b14f289ea54e7cd
diff --git a/src/util/blob-stream.hpp b/src/util/blob-stream.hpp
deleted file mode 100644
index 3bad4b7..0000000
--- a/src/util/blob-stream.hpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BLOB_STREAM_HPP
-#define NDN_BLOB_STREAM_HPP
-
-#include <ndn-cpp-dev/common.hpp>
-
-#if NDN_CPP_USE_SYSTEM_BOOST
-#include <boost/iostreams/detail/ios.hpp>
-#include <boost/iostreams/categories.hpp>
-#include <boost/iostreams/stream.hpp>
-namespace ndnboost = boost;
-#else
-// We can use ndnboost::iostreams because this is internal and will not conflict with the application if it uses boost::iostreams.
-#include <ndnboost/iostreams/detail/ios.hpp>
-#include <ndnboost/iostreams/categories.hpp>
-#include <ndnboost/iostreams/stream.hpp>
-#endif
-
-namespace ndn {
-
-class blob_append_device {
-public:
-  typedef char  char_type;
-  typedef ndnboost::iostreams::sink_tag category;
-  
-  blob_append_device(std::vector<uint8_t>& container)
-  : container_(container)
-  {
-  }
-  
-  std::streamsize
-  write(const char_type* s, std::streamsize n)
-  {
-    std::copy(s, s+n, std::back_inserter(container_));
-    return n;
-  }
-  
-protected:
-  std::vector<uint8_t>& container_;
-};
-
-/**
- * This is called "blob_stream" but it doesn't use an ndn::Blob which is immutable.  It uses a pointer to a vector<uint8_t>.
- * This is inteded for internal library use, not exported in the API.
- */
-struct blob_stream : public ndnboost::iostreams::stream<blob_append_device>
-{
-  blob_stream()
-    : buffer_(new std::vector<uint8_t>())
-    , device_(*buffer_)
-  {
-    open(device_);
-  }
-
-  ptr_lib::shared_ptr<std::vector<uint8_t> >
-  buf()
-  {
-    flush();
-    return buffer_;
-  }
-
-private:
-  ptr_lib::shared_ptr<std::vector<uint8_t> > buffer_;
-  blob_append_device device_;
-};
-
-}
-
-#endif
diff --git a/src/util/blob.cpp b/src/util/blob.cpp
deleted file mode 100644
index 46297c6..0000000
--- a/src/util/blob.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "../c/util/blob.h"
-#include <ndn-cpp-dev/util/blob.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-Blob::Blob(const struct ndn_Blob& blobStruct)
-  : ptr_lib::shared_ptr<const vector<uint8_t> >(new vector<uint8_t>(blobStruct.value, blobStruct.value + blobStruct.length))
-{
-}
-
-void 
-Blob::get(struct ndn_Blob& blobStruct) const 
-{
-  blobStruct.length = size(); 
-  if (size() > 0)
-    blobStruct.value = (uint8_t*)buf();
-  else
-    blobStruct.value = 0;
-}
-
-}
diff --git a/src/util/changed-event.cpp b/src/util/changed-event.cpp
deleted file mode 100644
index 08dcb98..0000000
--- a/src/util/changed-event.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "changed-event.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-void 
-ChangedEvent::fire()
-{
-  for (size_t i = 0; i < listeners_.size(); ++i)
-    listeners_[i]();
-}
-
-}
diff --git a/src/util/changed-event.hpp b/src/util/changed-event.hpp
deleted file mode 100644
index aee8549..0000000
--- a/src/util/changed-event.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_CHANGED_EVENT_HPP
-#define NDN_CHANGED_EVENT_HPP
-
-#include <vector>
-#include <ndn-cpp-dev/common.hpp>
-
-namespace ndn {
-
-/**
- * An OnChanged function object is called to notify a listener of a changed event.
- */
-typedef func_lib::function<void()> OnChanged;
-
-class ChangedEvent {
-public:
-  /**
-   * Add onChanged to the listener list. This does not check if a duplicate is already in the list.
-   * @param onChanged The OnChanged function object.
-   */
-  void 
-  add(OnChanged onChanged)
-  {
-    listeners_.push_back(onChanged);
-  }
-  
-  /**
-   * Call all the listeners.
-   */
-  void 
-  fire();
-
-#if 0  
-private:
-#endif
-  std::vector<OnChanged> listeners_;
-};
-
-}
-
-#endif
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
new file mode 100644
index 0000000..ce17259
--- /dev/null
+++ b/src/util/crypto.cpp
@@ -0,0 +1,19 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "ndn-cpp-dev/util/crypto.hpp"
+
+namespace ndn {
+
+void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
+{
+  SHA256_CTX sha256;
+  SHA256_Init(&sha256);
+  SHA256_Update(&sha256, data, dataLength);
+  SHA256_Final(digest, &sha256);
+}
+
+} // namespace ndn
diff --git a/src/util/dynamic-uint8-vector.cpp b/src/util/dynamic-uint8-vector.cpp
deleted file mode 100644
index 197fc0e..0000000
--- a/src/util/dynamic-uint8-vector.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "dynamic-uint8-vector.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-DynamicUInt8Vector::DynamicUInt8Vector(size_t initialLength)
-: vector_(new vector<uint8_t>(initialLength))
-{
-  ndn_DynamicUInt8Array_initialize(this, &vector_->front(), initialLength, DynamicUInt8Vector::realloc);
-}
-
-uint8_t*
-DynamicUInt8Vector::realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length)
-{
-  // Because this method is private, assume there is not a problem with upcasting.
-  DynamicUInt8Vector *thisObject = (DynamicUInt8Vector *)self;
-  
-  if (array != &thisObject->vector_->front())
-    // We don't expect this to ever happen. The caller didn't pass the array from this object.
-    return 0;
-  
-  thisObject->vector_->resize(length);
-  return &thisObject->vector_->front();
-}
-
-}
diff --git a/src/util/dynamic-uint8-vector.hpp b/src/util/dynamic-uint8-vector.hpp
deleted file mode 100644
index 55ed1ee..0000000
--- a/src/util/dynamic-uint8-vector.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_DYNAMIC_UCHAR_VECTOR_HPP
-#define NDN_DYNAMIC_UCHAR_VECTOR_HPP
-
-#include <vector>
-#include <ndn-cpp-dev/common.hpp>
-#include "../c/util/dynamic-uint8-array.h"
-
-namespace ndn {
-
-/**
- * A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr<vector<uint8_t> > for use with
- * C functions which need an ndn_DynamicUInt8Array.
- */
-class DynamicUInt8Vector : public ndn_DynamicUInt8Array {
-public:
-  /**
-   * Create a new DynamicUInt8Vector with an initial length.
-   * @param initialLength The initial size of the allocated vector.
-   */
-  DynamicUInt8Vector(size_t initialLength);
-  
-  /**
-   * Get the shared_ptr to the allocated vector.
-   * @return The shared_ptr to the allocated vector. 
-   */
-  ptr_lib::shared_ptr<std::vector<uint8_t> >& 
-  get() { return vector_; }
-  
-private:
-  /**
-   * Implement the static realloc function using vector resize.
-   * @param self A pointer to this object.
-   * @param array Should be the front of the vector.
-   * @param length The new length for the vector.
-   * @return The front of the allocated vector.
-   */
-  static uint8_t*
-  realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length);
-  
-  ptr_lib::shared_ptr<std::vector<uint8_t> > vector_;
-};
-
-}
-
-#endif
diff --git a/src/util/ndnd-id-fetcher.hpp b/src/util/ndnd-id-fetcher.hpp
index 6a1224e..e10eb38 100644
--- a/src/util/ndnd-id-fetcher.hpp
+++ b/src/util/ndnd-id-fetcher.hpp
@@ -9,7 +9,7 @@
 #define NDN_NDND_ID_FETCHER_HPP
 
 #include <ndn-cpp-dev/common.hpp>
-#include "ndn-cpp-dev/c/util/crypto.h"
+#include "ndn-cpp-dev/util/crypto.hpp"
 
 namespace ndn {
 
diff --git a/src/util/time.cpp b/src/util/time.cpp
new file mode 100644
index 0000000..03eb81b
--- /dev/null
+++ b/src/util/time.cpp
@@ -0,0 +1,85 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <ndn-cpp-dev/ndn-cpp-config.h>
+#if NDN_CPP_HAVE_TIME_H
+#include <time.h>
+#endif
+#if NDN_CPP_HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <math.h>
+#include <string.h>
+#include <stdio.h>
+#include "time.hpp"
+
+namespace ndn {
+
+MillisecondsSince1970 
+ndn_getNowMilliseconds()
+{
+  struct timeval t;
+  // Note: configure.ac requires gettimeofday.
+  gettimeofday(&t, 0);
+  return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
+}
+
+int
+ndn_toIsoString(MillisecondsSince1970 milliseconds, char *isoString)
+{
+#if NDN_CPP_HAVE_GMTIME_SUPPORT
+  if (milliseconds < 0)
+    return -1;
+  else if (milliseconds > 2e14)
+    // 2e14 is about the year 8300.  We don't want to go over a 4-digit year.
+    return -1;
+  
+  double secondsSince1970 = milliseconds / 1000.0;
+  char fractionBuffer[10];
+  sprintf(fractionBuffer, "%.06lf", fmod(secondsSince1970, 1.0));
+  const char *fraction = strchr(fractionBuffer, '.');
+  if (!fraction)
+    // Don't expect this to happen.
+    fraction = ".000000";
+    
+  time_t seconds = (time_t)secondsSince1970;
+  struct tm* gmt = gmtime(&seconds);
+  sprintf(isoString, "%04d%02d%02dT%02d%02d%02d%s", 1900 + gmt->tm_year, gmt->tm_mon + 1, gmt->tm_mday,
+    gmt->tm_hour, gmt->tm_min, gmt->tm_sec, fraction);
+  
+  return 0;
+#else
+  return -1;
+#endif
+}
+
+int
+ndn_fromIsoString(const char* isoString, MillisecondsSince1970 *milliseconds)
+{
+#if NDN_CPP_HAVE_GMTIME_SUPPORT
+  // Initialize time zone, etc.
+  time_t dummyTime = 0;
+  struct tm tm1 = *gmtime(&dummyTime);
+  
+  sscanf(isoString, "%4d%2d%2dT%2d%2d", &tm1.tm_year, &tm1.tm_mon, &tm1.tm_mday, &tm1.tm_hour, &tm1.tm_min);
+  // Skip the time past minutes and get the float seconds.
+  double seconds;
+  sscanf(isoString + (4 + 2 + 2 + 1 + 2 + 2), "%lf", &seconds);
+  
+  // tm_year starts from 1900.
+  tm1.tm_year -= 1900;
+  // tm_mon starts from 0, not 1.
+  tm1.tm_mon -= 1;
+  tm1.tm_sec = 0;
+  
+  *milliseconds = (timegm(&tm1) + seconds) * 1000.0;
+  return 0;
+#else
+  return -1;
+#endif
+}
+
+} // namespace ndn
diff --git a/src/util/time.hpp b/src/util/time.hpp
index 90482d9..5e5dc7c 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -8,11 +8,19 @@
 #ifndef NDN_TIME_HPP
 #define NDN_TIME_HPP
 
-#include <stdexcept>
-#include "../c/util/time.h"
+#include "ndn-cpp-dev/common.hpp"
 
 namespace ndn {
 
+MillisecondsSince1970 
+ndn_getNowMilliseconds();
+
+int
+ndn_toIsoString(MillisecondsSince1970 milliseconds, char *isoString);
+
+int
+ndn_fromIsoString(const char* isoString, MillisecondsSince1970 *milliseconds);
+
 /**
  * Convert to the ISO string representation of the time.
  * @param time Milliseconds since 1/1/1970.
@@ -22,9 +30,9 @@
 toIsoString(const MillisecondsSince1970& time)
 {
   char isoString[25];
-  ndn_Error error;
+  int error;
   if ((error = ndn_toIsoString(time, isoString)))
-    throw std::runtime_error(ndn_getErrorString(error));
+    throw std::runtime_error("toIsoString");
   
   return isoString;
 }
@@ -38,9 +46,9 @@
 fromIsoString(const std::string& isoString)
 {
   MillisecondsSince1970 milliseconds;
-  ndn_Error error;
+  int error;
   if ((error = ndn_fromIsoString(isoString.c_str(), &milliseconds)))
-    throw std::runtime_error(ndn_getErrorString(error));
+    throw std::runtime_error("fromIsoString");
   
   return milliseconds;
 }