Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include "contact-item.h" |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 12 | #include "null-ptrs.h" |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 14 | #include "logging.h" |
| 15 | |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 16 | using namespace std; |
| 17 | using namespace ndn; |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 18 | using namespace ndn::ptr_lib; |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 20 | INIT_LOGGER("ContactItem"); |
| 21 | |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 22 | ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate, |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 23 | bool isIntroducer, |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 24 | const string& alias) |
| 25 | : m_selfEndorseCertificate(selfEndorseCertificate) |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 26 | , m_isIntroducer(isIntroducer) |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 27 | { |
| 28 | Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName(); |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 29 | |
| 30 | m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 31 | |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 32 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 33 | const ProfileData& profileData = selfEndorseCertificate.getProfileData(); |
| 34 | m_name = profileData.getProfile().getProfileEntry("name"); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 35 | m_alias = alias.empty() ? m_name : alias; |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 36 | m_institution = profileData.getProfile().getProfileEntry("institution"); |
Yingdi Yu | dbeb8e2 | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 39 | ContactItem::ContactItem(const ContactItem& contactItem) |
| 40 | : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate) |
| 41 | , m_namespace(contactItem.m_namespace) |
| 42 | , m_alias(contactItem.m_alias) |
| 43 | , m_name(contactItem.m_name) |
| 44 | , m_institution(contactItem.m_institution) |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 45 | , m_isIntroducer(contactItem.m_isIntroducer) |
| 46 | , m_trustScope(contactItem.m_trustScope) |
| 47 | , m_trustScopeName(contactItem.m_trustScopeName) |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 48 | {} |
| 49 | |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 50 | bool |
| 51 | ContactItem::canBeTrustedFor(const Name& name) |
| 52 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 53 | vector<shared_ptr<Regex> >::iterator it = m_trustScope.begin(); |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 54 | |
| 55 | for(; it != m_trustScope.end(); it++) |
| 56 | if((*it)->match(name)) |
| 57 | return true; |
| 58 | return false; |
| 59 | } |