blob: 46cc4a3ab8cd53e7eead182ff6b2fe8fbf7b2df1 [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"
12#include "exception.h"
Yingdi Yu64206112013-12-24 11:16:32 +080013#include "null-ptrs.h"
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070014
Yingdi Yu79c25a22013-10-21 13:38:38 -070015#include "logging.h"
16
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070017using namespace std;
18using namespace ndn;
Yingdi Yu64206112013-12-24 11:16:32 +080019using namespace ndn::ptr_lib;
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070020
Yingdi Yu79c25a22013-10-21 13:38:38 -070021INIT_LOGGER("ContactItem");
22
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070023ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
Yingdi Yu813d4e92013-11-03 16:22:05 -080024 bool isIntroducer,
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070025 const string& alias)
26 : m_selfEndorseCertificate(selfEndorseCertificate)
Yingdi Yu813d4e92013-11-03 16:22:05 -080027 , m_isIntroducer(isIntroducer)
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070028{
29 Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName();
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070030
31 m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
Yingdi Yub35b8652013-11-07 11:32:40 -080032
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070033
Yingdi Yu64206112013-12-24 11:16:32 +080034 const ProfileData& profileData = selfEndorseCertificate.getProfileData();
35 m_name = profileData.getProfile().getProfileEntry("name");
Yingdi Yub35b8652013-11-07 11:32:40 -080036 m_alias = alias.empty() ? m_name : alias;
Yingdi Yu64206112013-12-24 11:16:32 +080037 m_institution = profileData.getProfile().getProfileEntry("institution");
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070038}
39
Yingdi Yua50c3252013-11-03 15:05:26 -080040ContactItem::ContactItem(const ContactItem& contactItem)
41 : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate)
42 , m_namespace(contactItem.m_namespace)
43 , m_alias(contactItem.m_alias)
44 , m_name(contactItem.m_name)
45 , m_institution(contactItem.m_institution)
Yingdi Yu813d4e92013-11-03 16:22:05 -080046 , m_isIntroducer(contactItem.m_isIntroducer)
47 , m_trustScope(contactItem.m_trustScope)
48 , m_trustScopeName(contactItem.m_trustScopeName)
Yingdi Yua50c3252013-11-03 15:05:26 -080049{}
50
Yingdi Yu813d4e92013-11-03 16:22:05 -080051bool
52ContactItem::canBeTrustedFor(const Name& name)
53{
Yingdi Yu64206112013-12-24 11:16:32 +080054 vector<shared_ptr<Regex> >::iterator it = m_trustScope.begin();
Yingdi Yu813d4e92013-11-03 16:22:05 -080055
56 for(; it != m_trustScope.end(); it++)
57 if((*it)->match(name))
58 return true;
59 return false;
60}