bug+codestyle: Fix compile bugs and adjust code style
Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/src/contact.hpp b/src/contact.hpp
new file mode 100644
index 0000000..8052ac7
--- /dev/null
+++ b/src/contact.hpp
@@ -0,0 +1,239 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHRONOS_CONTACT_HPP
+#define CHRONOS_CONTACT_HPP
+
+#include "common.hpp"
+#include <ndn-cxx/security/identity-certificate.hpp>
+#include <ndn-cxx/util/regex.hpp>
+#include "endorse-certificate.hpp"
+
+namespace chronos {
+
+class Contact
+{
+public:
+ typedef std::map<Name, shared_ptr<ndn::Regex> >::const_iterator const_iterator;
+ typedef std::map<Name, shared_ptr<ndn::Regex> >::iterator iterator;
+
+ Contact(const ndn::IdentityCertificate& identityCertificate,
+ bool isIntroducer = false,
+ const std::string& alias = "")
+ : m_notBefore(identityCertificate.getNotBefore())
+ , m_notAfter(identityCertificate.getNotAfter())
+ , m_isIntroducer(isIntroducer)
+ , m_profile(identityCertificate)
+ {
+ m_name = m_profile.get("name");
+ m_alias = alias.empty() ? m_name : alias;
+ m_institution = m_profile.get("institution");
+
+ m_keyName = identityCertificate.getPublicKeyName();
+ m_namespace = m_keyName.getPrefix(-1);
+ m_publicKey = identityCertificate.getPublicKeyInfo();
+ }
+
+ Contact(const EndorseCertificate& endorseCertificate,
+ bool isIntroducer = false,
+ const std::string& alias = "")
+ : m_notBefore(endorseCertificate.getNotBefore())
+ , m_notAfter(endorseCertificate.getNotAfter())
+ , m_isIntroducer(isIntroducer)
+ {
+ m_profile = endorseCertificate.getProfile();
+
+ m_name = m_profile.get("name");
+ m_alias = alias.empty() ? m_name : alias;
+ m_institution = m_profile.get("institution");
+
+ m_keyName = endorseCertificate.getPublicKeyName();;
+ m_namespace = m_keyName.getPrefix(-1);
+ m_publicKey = endorseCertificate.getPublicKeyInfo();
+ }
+
+ Contact(const Name& identity,
+ const std::string& alias,
+ const Name& keyName,
+ const time::system_clock::TimePoint& notBefore,
+ const time::system_clock::TimePoint& notAfter,
+ const ndn::PublicKey& key,
+ bool isIntroducer)
+ : m_namespace(identity)
+ , m_alias(alias)
+ , m_keyName(keyName)
+ , m_publicKey(key)
+ , m_notBefore(notBefore)
+ , m_notAfter(notAfter)
+ , m_isIntroducer(isIntroducer)
+ {
+ }
+
+ Contact(const Contact& contact)
+ : m_namespace(contact.m_namespace)
+ , m_alias(contact.m_alias)
+ , m_name(contact.m_name)
+ , m_institution(contact.m_institution)
+ , m_keyName(contact.m_keyName)
+ , m_publicKey(contact.m_publicKey)
+ , m_notBefore(contact.m_notBefore)
+ , m_notAfter(contact.m_notAfter)
+ , m_isIntroducer(contact.m_isIntroducer)
+ , m_profile(contact.m_profile)
+ , m_trustScope(contact.m_trustScope)
+ {
+ }
+
+ virtual
+ ~Contact()
+ {
+ }
+
+ const Name&
+ getNameSpace() const
+ {
+ return m_namespace;
+ }
+
+ const std::string&
+ getAlias() const
+ {
+ return m_alias;
+ }
+
+ const std::string&
+ getName() const
+ {
+ return m_name;
+ }
+
+ const std::string&
+ getInstitution() const
+ {
+ return m_institution;
+ }
+
+ const Name&
+ getPublicKeyName() const
+ {
+ return m_keyName;
+ }
+
+ const ndn::PublicKey&
+ getPublicKey() const
+ {
+ return m_publicKey;
+ }
+
+ const time::system_clock::TimePoint&
+ getNotBefore() const
+ {
+ return m_notBefore;
+ }
+
+ const time::system_clock::TimePoint&
+ getNotAfter() const
+ {
+ return m_notAfter;
+ }
+
+ const Profile&
+ getProfile() const
+ {
+ return m_profile;
+ }
+
+ void
+ setProfile(const Profile& profile)
+ {
+ m_name = profile.get("name");
+ m_institution = profile.get("institution");
+ m_profile = profile;
+ }
+
+ bool
+ isIntroducer() const
+ {
+ return m_isIntroducer;
+ }
+
+ void
+ setIsIntroducer(bool isIntroducer)
+ {
+ m_isIntroducer = isIntroducer;
+ }
+
+ void
+ addTrustScope(const Name& nameSpace)
+ {
+ m_trustScope[nameSpace] = ndn::Regex::fromName(nameSpace);
+ }
+
+ void
+ deleteTrustScope(const Name& nameSpace)
+ {
+ m_trustScope.erase(nameSpace);
+ }
+
+ bool
+ canBeTrustedFor(const Name& name)
+ {
+ for (std::map<Name, shared_ptr<ndn::Regex> >::iterator it = m_trustScope.begin();
+ it != m_trustScope.end(); it++)
+ if (it->second->match(name))
+ return true;
+ return false;
+ }
+
+ const_iterator
+ trustScopeBegin() const
+ {
+ return m_trustScope.begin();
+ }
+
+ const_iterator
+ trustScopeEnd() const
+ {
+ return m_trustScope.end();
+ }
+
+ iterator
+ trustScopeBegin()
+ {
+ return m_trustScope.begin();
+ }
+
+ iterator
+ trustScopeEnd()
+ {
+ return m_trustScope.end();
+ }
+
+protected:
+ typedef std::map<Name, shared_ptr<ndn::Regex> > TrustScopes;
+
+ Name m_namespace;
+ std::string m_alias;
+ std::string m_name;
+ std::string m_institution;
+ Name m_keyName;
+ ndn::PublicKey m_publicKey;
+ time::system_clock::TimePoint m_notBefore;
+ time::system_clock::TimePoint m_notAfter;
+
+ bool m_isIntroducer;
+ Profile m_profile;
+
+ TrustScopes m_trustScope;
+};
+
+} // namespace chronos
+
+#endif // CHRONOS_CONTACT_HPP