blob: 8c02b29f843b1ccec55edcb13c6efa56183f3c72 [file] [log] [blame]
Yingdi Yudbeb8e22013-10-14 09:36:31 -07001/* -*- 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 Yu76dd8002013-12-24 11:16:32 +080012#include "null-ptrs.h"
Yingdi Yudbeb8e22013-10-14 09:36:31 -070013
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070014#include "logging.h"
15
Yingdi Yudbeb8e22013-10-14 09:36:31 -070016using namespace std;
17using namespace ndn;
Yingdi Yu76dd8002013-12-24 11:16:32 +080018using namespace ndn::ptr_lib;
Yingdi Yudbeb8e22013-10-14 09:36:31 -070019
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070020INIT_LOGGER("ContactItem");
21
Yingdi Yudbeb8e22013-10-14 09:36:31 -070022ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
Yingdi Yu71c01872013-11-03 16:22:05 -080023 bool isIntroducer,
Yingdi Yudbeb8e22013-10-14 09:36:31 -070024 const string& alias)
25 : m_selfEndorseCertificate(selfEndorseCertificate)
Yingdi Yu71c01872013-11-03 16:22:05 -080026 , m_isIntroducer(isIntroducer)
Yingdi Yudbeb8e22013-10-14 09:36:31 -070027{
28 Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName();
Yingdi Yudbeb8e22013-10-14 09:36:31 -070029
30 m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
Yingdi Yue35bdb82013-11-07 11:32:40 -080031
Yingdi Yudbeb8e22013-10-14 09:36:31 -070032
Yingdi Yu76dd8002013-12-24 11:16:32 +080033 const ProfileData& profileData = selfEndorseCertificate.getProfileData();
34 m_name = profileData.getProfile().getProfileEntry("name");
Yingdi Yue35bdb82013-11-07 11:32:40 -080035 m_alias = alias.empty() ? m_name : alias;
Yingdi Yu76dd8002013-12-24 11:16:32 +080036 m_institution = profileData.getProfile().getProfileEntry("institution");
Yingdi Yudbeb8e22013-10-14 09:36:31 -070037}
38
Yingdi Yuec5e72a2013-11-03 15:05:26 -080039ContactItem::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 Yu71c01872013-11-03 16:22:05 -080045 , m_isIntroducer(contactItem.m_isIntroducer)
46 , m_trustScope(contactItem.m_trustScope)
47 , m_trustScopeName(contactItem.m_trustScopeName)
Yingdi Yuec5e72a2013-11-03 15:05:26 -080048{}
49
Yingdi Yu71c01872013-11-03 16:22:05 -080050bool
51ContactItem::canBeTrustedFor(const Name& name)
52{
Yingdi Yu76dd8002013-12-24 11:16:32 +080053 vector<shared_ptr<Regex> >::iterator it = m_trustScope.begin();
Yingdi Yu71c01872013-11-03 16:22:05 -080054
55 for(; it != m_trustScope.end(); it++)
56 if((*it)->match(name))
57 return true;
58 return false;
59}