Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -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> |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 9 | * Qiuhan Ding <qiuhanding@cs.ucla.edu> |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 12 | #ifndef CHRONOCHAT_PROFILE_HPP |
| 13 | #define CHRONOCHAT_PROFILE_HPP |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 14 | |
| 15 | #include "common.hpp" |
| 16 | |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 17 | #include "tlv.hpp" |
| 18 | #include <ndn-cxx/util/concepts.hpp> |
| 19 | #include <ndn-cxx/encoding/block.hpp> |
| 20 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 21 | #include <ndn-cxx/security/certificate.hpp> |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 23 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 24 | |
| 25 | class Profile |
| 26 | { |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 27 | |
| 28 | public: |
| 29 | class Error : public std::runtime_error |
| 30 | { |
| 31 | public: |
| 32 | explicit |
| 33 | Error(const std::string& what) |
| 34 | : std::runtime_error(what) |
| 35 | { |
| 36 | } |
| 37 | }; |
| 38 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 39 | public: |
| 40 | typedef std::map<std::string, std::string>::iterator iterator; |
| 41 | typedef std::map<std::string, std::string>::const_iterator const_iterator; |
| 42 | |
| 43 | Profile() |
| 44 | { |
| 45 | } |
| 46 | |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 47 | Profile(const ndn::security::Certificate& identityCertificate); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 48 | |
| 49 | Profile(const Name& identityName); |
| 50 | |
| 51 | Profile(const Name& identityName, |
| 52 | const std::string& name, |
| 53 | const std::string& institution); |
| 54 | |
| 55 | Profile(const Profile& profile); |
| 56 | |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 57 | Profile(const Block& profileWire); |
| 58 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 59 | ~Profile() |
| 60 | { |
| 61 | } |
| 62 | |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 63 | const Block& |
| 64 | wireEncode() const; |
| 65 | |
| 66 | void |
| 67 | wireDecode(const Block& profileWire); |
| 68 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 69 | std::string& |
| 70 | operator[](const std::string& profileKey) |
| 71 | { |
| 72 | return m_entries[profileKey]; |
| 73 | } |
| 74 | |
| 75 | std::string |
| 76 | get(const std::string& profileKey) const |
| 77 | { |
| 78 | std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey); |
| 79 | if (it != m_entries.end()) |
| 80 | return it->second; |
| 81 | else |
| 82 | return std::string(); |
| 83 | } |
| 84 | |
| 85 | Profile::iterator |
| 86 | begin() |
| 87 | { |
| 88 | return m_entries.begin(); |
| 89 | } |
| 90 | |
| 91 | Profile::const_iterator |
| 92 | begin() const |
| 93 | { |
| 94 | return m_entries.begin(); |
| 95 | } |
| 96 | |
| 97 | Profile::iterator |
| 98 | end() |
| 99 | { |
| 100 | return m_entries.end(); |
| 101 | } |
| 102 | |
| 103 | Profile::const_iterator |
| 104 | end() const |
| 105 | { |
| 106 | return m_entries.end(); |
| 107 | } |
| 108 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 109 | Name |
| 110 | getIdentityName() const |
| 111 | { |
| 112 | return ndn::Name(m_entries.at("IDENTITY")); |
| 113 | } |
| 114 | |
| 115 | bool |
| 116 | operator==(const Profile& profile) const; |
| 117 | |
| 118 | bool |
| 119 | operator!=(const Profile& profile) const; |
| 120 | |
| 121 | private: |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 122 | template<ndn::encoding::Tag T> |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 123 | size_t |
| 124 | wireEncode(ndn::EncodingImpl<T>& block) const; |
| 125 | |
| 126 | |
| 127 | private: |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 128 | static const std::string OID_NAME; |
| 129 | static const std::string OID_ORG; |
| 130 | static const std::string OID_GROUP; |
| 131 | static const std::string OID_HOMEPAGE; |
| 132 | static const std::string OID_ADVISOR; |
| 133 | static const std::string OID_EMAIL; |
| 134 | |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 135 | mutable Block m_wire; |
| 136 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 137 | std::map<std::string, std::string> m_entries; |
| 138 | }; |
| 139 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 140 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 141 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 142 | #endif // CHRONOCHAT_PROFILE_HPP |