Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -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 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 11 | #ifndef CHRONOS_PROFILE_H |
| 12 | #define CHRONOS_PROFILE_H |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 14 | #include "config.h" |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 15 | #include <ndn-cpp-dev/name.hpp> |
| 16 | #include <ndn-cpp-dev/security/identity-certificate.hpp> |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 17 | #include <map> |
| 18 | #include <string> |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 19 | #include "profile.pb.h" |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 20 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 21 | namespace chronos{ |
| 22 | |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 23 | class Profile |
| 24 | { |
| 25 | public: |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 26 | typedef std::map<std::string, std::string>::iterator iterator; |
| 27 | typedef std::map<std::string, std::string>::const_iterator const_iterator; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 28 | |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 29 | Profile() {} |
| 30 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 31 | Profile(const ndn::IdentityCertificate& identityCertificate); |
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 32 | |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 33 | Profile(const ndn::Name& identityName); |
| 34 | |
| 35 | Profile(const ndn::Name& identityName, |
| 36 | const std::string& name, |
| 37 | const std::string& institution); |
| 38 | |
| 39 | Profile(const Profile& profile); |
| 40 | |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 41 | ~Profile() {} |
| 42 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 43 | std::string& |
| 44 | operator [] (const std::string& profileKey) |
| 45 | { return m_entries[profileKey]; } |
| 46 | |
| 47 | std::string |
| 48 | get (const std::string& profileKey) const |
| 49 | { |
| 50 | std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey); |
| 51 | if(it != m_entries.end()) |
| 52 | return it->second; |
| 53 | else |
| 54 | return std::string(); |
| 55 | } |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 56 | |
| 57 | inline Profile::iterator |
| 58 | begin() |
| 59 | { return m_entries.begin(); } |
| 60 | |
| 61 | inline Profile::const_iterator |
| 62 | begin() const |
| 63 | { return m_entries.begin(); } |
| 64 | |
| 65 | inline Profile::iterator |
| 66 | end() |
| 67 | { return m_entries.end(); } |
| 68 | |
| 69 | inline Profile::const_iterator |
| 70 | end() const |
| 71 | { return m_entries.end(); } |
| 72 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 73 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 74 | encode(std::ostream& os) const; |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 75 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 76 | void |
| 77 | decode(std::istream& is); |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 78 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 79 | ndn::Name |
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 80 | getIdentityName() const |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 81 | { return ndn::Name(m_entries.at("IDENTITY")); } |
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 82 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 83 | inline bool |
| 84 | operator == (const Profile& profile) const; |
| 85 | |
| 86 | private: |
| 87 | static const std::string OID_NAME; |
| 88 | static const std::string OID_ORG; |
| 89 | static const std::string OID_GROUP; |
| 90 | static const std::string OID_HOMEPAGE; |
| 91 | static const std::string OID_ADVISOR; |
| 92 | static const std::string OID_EMAIL; |
| 93 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 94 | std::map<std::string, std::string> m_entries; |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 97 | Chronos::ProfileMsg& |
| 98 | operator << (Chronos::ProfileMsg& msg, const Profile& profile); |
| 99 | |
| 100 | Chronos::ProfileMsg& |
| 101 | operator >> (Chronos::ProfileMsg& msg, Profile& profile); |
| 102 | |
| 103 | bool |
| 104 | Profile::operator == (const Profile& profile) const |
| 105 | { |
| 106 | if(m_entries.size() != profile.m_entries.size()) |
| 107 | return false; |
| 108 | |
| 109 | std::map<std::string, std::string>::const_iterator it = m_entries.begin(); |
| 110 | for(; it != m_entries.end(); it++) |
| 111 | { |
| 112 | std::map<std::string, std::string>::const_iterator found = profile.m_entries.find(it->first); |
| 113 | if(found == profile.m_entries.end()) |
| 114 | return false; |
| 115 | if(found->second != it->second) |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | }//chronos |
| 123 | |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 124 | #endif |