blob: 3ea941b9c81b7363334f67e363073f75d2dc6a0c [file] [log] [blame]
Yingdi Yu53b8a9c2013-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 Yu53b8a9c2013-10-14 09:36:31 -070012
Yingdi Yu79c25a22013-10-21 13:38:38 -070013#include "logging.h"
14
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070015using namespace std;
16using namespace ndn;
Yingdi Yu64206112013-12-24 11:16:32 +080017using namespace ndn::ptr_lib;
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070018
Yingdi Yu79c25a22013-10-21 13:38:38 -070019INIT_LOGGER("ContactItem");
20
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070021ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
Yingdi Yu813d4e92013-11-03 16:22:05 -080022 bool isIntroducer,
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070023 const string& alias)
24 : m_selfEndorseCertificate(selfEndorseCertificate)
Yingdi Yu813d4e92013-11-03 16:22:05 -080025 , m_isIntroducer(isIntroducer)
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070026{
27 Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName();
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070028
29 m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
Yingdi Yub35b8652013-11-07 11:32:40 -080030
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070031
Yingdi Yu64206112013-12-24 11:16:32 +080032 const ProfileData& profileData = selfEndorseCertificate.getProfileData();
33 m_name = profileData.getProfile().getProfileEntry("name");
Yingdi Yub35b8652013-11-07 11:32:40 -080034 m_alias = alias.empty() ? m_name : alias;
Yingdi Yu64206112013-12-24 11:16:32 +080035 m_institution = profileData.getProfile().getProfileEntry("institution");
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070036}
37
Yingdi Yua50c3252013-11-03 15:05:26 -080038ContactItem::ContactItem(const ContactItem& contactItem)
39 : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate)
40 , m_namespace(contactItem.m_namespace)
41 , m_alias(contactItem.m_alias)
42 , m_name(contactItem.m_name)
43 , m_institution(contactItem.m_institution)
Yingdi Yu813d4e92013-11-03 16:22:05 -080044 , m_isIntroducer(contactItem.m_isIntroducer)
45 , m_trustScope(contactItem.m_trustScope)
46 , m_trustScopeName(contactItem.m_trustScopeName)
Yingdi Yua50c3252013-11-03 15:05:26 -080047{}
48
Yingdi Yu813d4e92013-11-03 16:22:05 -080049bool
50ContactItem::canBeTrustedFor(const Name& name)
51{
Yingdi Yu64206112013-12-24 11:16:32 +080052 vector<shared_ptr<Regex> >::iterator it = m_trustScope.begin();
Yingdi Yu813d4e92013-11-03 16:22:05 -080053
54 for(; it != m_trustScope.end(); it++)
55 if((*it)->match(name))
56 return true;
57 return false;
58}