Add getContact method of ContactManager, add supporting methods in ContactStorage
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 9b7d7a3..af094a7 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -171,6 +171,20 @@
return result;
}
+Ptr<ContactItem>
+ContactManager::getContact(const ndn::Name& contactNamespace)
+{
+ Ptr<ContactItem> contactItem = m_contactStorage->getNormalContact(contactNamespace);
+ if(NULL != contactItem)
+ return contactItem;
+
+ contactItem = m_contactStorage->getTrustedContact(contactNamespace);
+ if(NULL != contactItem)
+ return contactItem;
+
+ return NULL;
+}
+
Ptr<EndorseCertificate>
ContactManager::getSignedSelfEndorseCertificate(const Name& identity,
const Profile& profile)
diff --git a/src/contact-manager.h b/src/contact-manager.h
index 666cf9b..465a1cc 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -46,6 +46,9 @@
getContactStorage()
{ return m_contactStorage; }
+ ndn::Ptr<ContactItem>
+ getContact(const ndn::Name& contactNamespace);
+
inline ndn::Ptr<DnsStorage>
getDnsStorage()
{ return m_dnsStorage; }
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index 24c322e..7a24fdc 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -366,6 +366,53 @@
return normalContacts;
}
+Ptr<ContactItem>
+ContactStorage::getNormalContact(const Name& name)
+{
+ sqlite3_stmt *stmt;
+ sqlite3_prepare_v2 (m_db,
+ "SELECT contact_alias, self_certificate FROM NormalContact where contact_namespace=?",
+ -1,
+ &stmt,
+ 0);
+ sqlite3_bind_text (stmt, 1, name.toUri().c_str(), name.toUri().size(), SQLITE_TRANSIENT);
+
+ if( sqlite3_step (stmt) == SQLITE_ROW)
+ {
+ string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+ Ptr<Blob> certBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
+ Ptr<Data> certData = Data::decodeFromWire(certBlob);
+ EndorseCertificate endorseCertificate(*certData);
+
+ return Ptr<ContactItem>(new ContactItem(endorseCertificate, alias));
+ }
+ return NULL;
+}
+
+Ptr<TrustedContact>
+ContactStorage::getTrustedContact(const Name& name)
+{
+ sqlite3_stmt *stmt;
+ sqlite3_prepare_v2 (m_db,
+ "SELECT contact_alias, self_certificate, trust_scope FROM TrustedContact where contact_namespace=?",
+ -1,
+ &stmt,
+ 0);
+ sqlite3_bind_text (stmt, 1, name.toUri().c_str(), name.toUri().size(), SQLITE_TRANSIENT);
+
+ if( sqlite3_step (stmt) == SQLITE_ROW)
+ {
+ string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+ Ptr<Blob> certBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
+ Ptr<Data> certData = Data::decodeFromWire(certBlob);
+ EndorseCertificate endorseCertificate(*certData);
+ string trustScope(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 2)), sqlite3_column_bytes (stmt, 2));
+
+ return Ptr<TrustedContact>(new TrustedContact(endorseCertificate, trustScope, alias));
+ }
+ return NULL;
+}
+
Ptr<Profile>
ContactStorage::getSelfProfile(const Name& identity) const
{
diff --git a/src/contact-storage.h b/src/contact-storage.h
index e08790e..d0f5f5b 100644
--- a/src/contact-storage.h
+++ b/src/contact-storage.h
@@ -48,6 +48,12 @@
std::vector<ndn::Ptr<ContactItem> >
getAllNormalContacts() const;
+
+ ndn::Ptr<ContactItem>
+ getNormalContact(const ndn::Name& name);
+
+ ndn::Ptr<TrustedContact>
+ getTrustedContact(const ndn::Name& name);
ndn::Ptr<Profile>
getSelfProfile(const ndn::Name& identity) const;