blob: b3271d271f230c1685a8e3c11540a484a48390cb [file] [log] [blame]
Yingdi Yuede8eaf2013-10-14 14:07:03 -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 "trusted-contact.h"
12#include <tinyxml.h>
13
14using namespace std;
15using namespace ndn;
16
17TrustedContact::TrustedContact(const EndorseCertificate& selfEndorseCertificate,
18 const string& trustScope,
19 const string& alias)
20 : ContactItem(selfEndorseCertificate, alias)
21{
22 TiXmlDocument xmlDoc;
23 xmlDoc.Parse(trustScope.c_str());
24
25 TiXmlNode * it = xmlDoc.FirstChild();
26 while(it != NULL)
27 {
28 m_trustScope.push_back(Regex::fromXmlElement(dynamic_cast<TiXmlElement *>(it)));
29 it = it->NextSibling();
30 }
31}
32
33bool
34TrustedContact::canBeTrustedFor(const Name& name)
35{
36 vector<Ptr<Regex> >::iterator it = m_trustScope.begin();
37
38 for(; it != m_trustScope.end(); it++)
39 if((*it)->match(name))
40 return true;
41 return false;
42}
43
44Ptr<Blob>
45TrustedContact::getTrustScopeBlob() const
46{
47 ostringstream oss;
48 TiXmlDocument * xmlDoc = new TiXmlDocument();
49
50 vector<Ptr<Regex> >::const_iterator it = m_trustScope.begin();
51 for(; it != m_trustScope.end(); it++)
52 xmlDoc->LinkEndChild((*it)->toXmlElement());
53
54 oss << *xmlDoc;
55 return Ptr<Blob>(new Blob(oss.str().c_str(), oss.str().size()));
56}