Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -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 "trusted-contact.h" |
| 12 | #include <tinyxml.h> |
| 13 | |
| 14 | using namespace std; |
| 15 | using namespace ndn; |
| 16 | |
| 17 | TrustedContact::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 | |
| 33 | bool |
| 34 | TrustedContact::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 | |
| 44 | Ptr<Blob> |
| 45 | TrustedContact::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 | } |