Changing API from ndn.cxx to ndn-cpp

Change-Id: Ie0fe7d75e4ed056dec6e9da906f9c8808ad9a0ca
diff --git a/src/profile.cpp b/src/profile.cpp
index 24372a4..af805b0 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -9,13 +9,12 @@
  */
 
 #include "profile.h"
-#include <ndn.cxx/helpers/der/der.h>
-#include <ndn.cxx/helpers/der/visitor/print-visitor.h>
-#include <ndn.cxx/helpers/der/visitor/simple-visitor.h>
+#include "null-ptrs.h"
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("Profile");
 
@@ -26,47 +25,44 @@
 static string advisor("2.5.4.80");
 static string emailOid("1.2.840.113549.1.9.1");
 
-Profile::Profile(const security::IdentityCertificate& oldIdentityCertificate)
+Profile::Profile(const IdentityCertificate& oldIdentityCertificate)
 {
-  using namespace ndn::security;
-  security::IdentityCertificate identityCertificate(oldIdentityCertificate);
+  IdentityCertificate identityCertificate(oldIdentityCertificate);
 
   Name keyName = identityCertificate.getPublicKeyName();
-  m_identityName = keyName.getPrefix(keyName.size()-1);
+  m_identityName = keyName.getPrefix(-1);
 
   const string& identityString = m_identityName.toUri();
-  Blob identityBlob (identityString.c_str(), identityString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  m_entries[string("IDENTITY")] = identityString;
   
-  const vector<CertificateSubDescrypt>& subList = identityCertificate.getSubjectDescriptionList();
-  vector<CertificateSubDescrypt>::const_iterator it = subList.begin();
+  const vector<CertificateSubjectDescription>& subList = identityCertificate.getSubjectDescriptionList();
+  vector<CertificateSubjectDescription>::const_iterator it = subList.begin();
   for(; it != subList.end(); it++)
     {
-      string oidStr = it->getOidStr();
-      Blob blob (it->getValue().c_str(), it->getValue().size());
+      const string oidStr = it->getOidString();
+      string valueStr = it->getValue();
       if(oidStr == nameOid)
-        m_entries[string("name")] = blob;
+        m_entries[string("name")] = valueStr;
       else if(oidStr == orgOid)
-        m_entries[string("institution")] = blob;
+        m_entries[string("institution")] = valueStr;
       else if(oidStr == groupOid)
-        m_entries[string("group")] = blob;
+        m_entries[string("group")] = valueStr;
       else if(oidStr == homepageOid)
-        m_entries[string("homepage")] = blob;
+        m_entries[string("homepage")] = valueStr;
       else if(oidStr == advisor)
-        m_entries[string("advisor")] = blob;
+        m_entries[string("advisor")] = valueStr;
       else if(oidStr == emailOid)
-        m_entries[string("email")] = blob;
+        m_entries[string("email")] = valueStr;
       else
-        m_entries[oidStr] = blob;
+        m_entries[oidStr] = valueStr;
     }
 }
 
 Profile::Profile(const Name& identityName)
   : m_identityName(identityName)
 {
-  const string& nameString = identityName.toUri();
-  Blob identityBlob (nameString.c_str(), nameString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  const string& identityString = identityName.toUri();
+  m_entries[string("IDENTITY")] = identityString;
 }
 
 Profile::Profile(const Name& identityName,
@@ -74,15 +70,11 @@
 		 const string& institution)
   : m_identityName(identityName)
 {
-  const string& nameString = identityName.toUri();
-  Blob identityBlob (nameString.c_str(), nameString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  const string& identityString = identityName.toUri();
+  m_entries[string("IDENTITY")] = identityString;
 
-  Blob nameBlob (name.c_str(), name.size());
-  Blob institutionBlob (institution.c_str(), institution.size());
-
-  m_entries[string("name")] = nameBlob;
-  m_entries[string("institution")] = institutionBlob;
+  m_entries[string("name")] = name;
+  m_entries[string("institution")] = institution;
 }
 
 Profile::Profile(const Profile& profile)
@@ -92,63 +84,50 @@
 
 void
 Profile::setProfileEntry(const string& profileType,
-			 const Blob& profileValue)
+			 const string& profileValue)
 { m_entries[profileType] = profileValue; }
 
-Ptr<const Blob>
+string
 Profile::getProfileEntry(const string& profileType) const
 {
   if(m_entries.find(profileType) != m_entries.end())
-    return Ptr<Blob>(new Blob(m_entries.at(profileType).buf(), m_entries.at(profileType).size()));
+    return m_entries.at(profileType);
 
-  return NULL;
+  return CHRONOCHAT_NULL_STR;
 }
 
-Ptr<Blob>
-Profile::toDerBlob() const
+void
+Profile::encode(string* output) const
 {
-  Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
-  
-  Ptr<der::DerPrintableString> identityName = Ptr<der::DerPrintableString>(new der::DerPrintableString(m_identityName.toUri()));
-  root->addChild(identityName);
 
-  map<string, Blob>::const_iterator it = m_entries.begin();
+  Chronos::ProfileMsg profileMsg;
+
+  profileMsg.set_identityname(m_identityName.toUri());
+  
+  map<string, string>::const_iterator it = m_entries.begin();
   for(; it != m_entries.end(); it++)
     {
-      Ptr<der::DerSequence> entry = Ptr<der::DerSequence>::Create();
-      Ptr<der::DerPrintableString> type = Ptr<der::DerPrintableString>(new der::DerPrintableString(it->first));
-      Ptr<der::DerOctetString> value = Ptr<der::DerOctetString>(new der::DerOctetString(it->second));
-      entry->addChild(type);
-      entry->addChild(value);
-      root->addChild(entry);
+      Chronos::ProfileMsg::ProfileEntry* profileEntry = profileMsg.add_entry();
+      profileEntry->set_oid(it->first);
+      profileEntry->set_data(it->second);
     }
-  
-  blob_stream blobStream;
-  OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
-  root->encode(start);
 
-  return blobStream.buf ();
+  profileMsg.SerializeToString(output);
 }
 
-Ptr<Profile>
-Profile::fromDerBlob(const Blob& derBlob)
+shared_ptr<Profile>
+Profile::decode(const string& input)
 {
-  boost::iostreams::stream
-    <boost::iostreams::array_source> is (derBlob.buf(), derBlob.size());
+  Chronos::ProfileMsg profileMsg;
+    
+  profileMsg.ParseFromString(input);
 
-  Ptr<der::DerSequence> root = DynamicCast<der::DerSequence>(der::DerNode::parse(reinterpret_cast<InputIterator &>(is)));
-  const der::DerNodePtrList & children = root->getChildren();
-  der::SimpleVisitor simpleVisitor;
-  string identityName = boost::any_cast<string>(children[0]->accept(simpleVisitor));
-  Ptr<Profile> profile = Ptr<Profile>(new Profile(identityName));
+  shared_ptr<Profile> profile = make_shared<Profile>(profileMsg.identityname());
 
-  for(int i = 1; i < children.size(); i++)
+  for(int i = 0; i < profileMsg.entry_size(); i++)
     {
-      Ptr<der::DerSequence> entry = DynamicCast<der::DerSequence>(children[i]);
-      const der::DerNodePtrList & tuple = entry->getChildren();
-      string type = boost::any_cast<string>(tuple[0]->accept(simpleVisitor));
-      Ptr<Blob> value = boost::any_cast<Ptr<Blob> >(tuple[1]->accept(simpleVisitor));
-      profile->setProfileEntry(type, *value);
+      const Chronos::ProfileMsg::ProfileEntry& profileEntry = profileMsg.entry(i);
+      profile->setProfileEntry(profileEntry.oid(), profileEntry.data());
     }
 
   return profile;