Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 3 | * Copyright (c) 2020, Regents of the University of California |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 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 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 43 | Profile() = default; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 44 | |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 45 | Profile(const ndn::security::Certificate& identityCertificate); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 46 | |
| 47 | Profile(const Name& identityName); |
| 48 | |
| 49 | Profile(const Name& identityName, |
| 50 | const std::string& name, |
| 51 | const std::string& institution); |
| 52 | |
| 53 | Profile(const Profile& profile); |
| 54 | |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 55 | Profile(const Block& profileWire); |
| 56 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 57 | Profile& |
| 58 | operator=(const Profile&) = default; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 59 | |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 60 | const Block& |
| 61 | wireEncode() const; |
| 62 | |
| 63 | void |
| 64 | wireDecode(const Block& profileWire); |
| 65 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 66 | std::string& |
| 67 | operator[](const std::string& profileKey) |
| 68 | { |
| 69 | return m_entries[profileKey]; |
| 70 | } |
| 71 | |
| 72 | std::string |
| 73 | get(const std::string& profileKey) const |
| 74 | { |
| 75 | std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey); |
| 76 | if (it != m_entries.end()) |
| 77 | return it->second; |
| 78 | else |
| 79 | return std::string(); |
| 80 | } |
| 81 | |
| 82 | Profile::iterator |
| 83 | begin() |
| 84 | { |
| 85 | return m_entries.begin(); |
| 86 | } |
| 87 | |
| 88 | Profile::const_iterator |
| 89 | begin() const |
| 90 | { |
| 91 | return m_entries.begin(); |
| 92 | } |
| 93 | |
| 94 | Profile::iterator |
| 95 | end() |
| 96 | { |
| 97 | return m_entries.end(); |
| 98 | } |
| 99 | |
| 100 | Profile::const_iterator |
| 101 | end() const |
| 102 | { |
| 103 | return m_entries.end(); |
| 104 | } |
| 105 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 106 | Name |
| 107 | getIdentityName() const |
| 108 | { |
| 109 | return ndn::Name(m_entries.at("IDENTITY")); |
| 110 | } |
| 111 | |
| 112 | bool |
| 113 | operator==(const Profile& profile) const; |
| 114 | |
| 115 | bool |
| 116 | operator!=(const Profile& profile) const; |
| 117 | |
| 118 | private: |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 119 | template<ndn::encoding::Tag T> |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 120 | size_t |
| 121 | wireEncode(ndn::EncodingImpl<T>& block) const; |
| 122 | |
| 123 | |
| 124 | private: |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 125 | static const std::string OID_NAME; |
| 126 | static const std::string OID_ORG; |
| 127 | static const std::string OID_GROUP; |
| 128 | static const std::string OID_HOMEPAGE; |
| 129 | static const std::string OID_ADVISOR; |
| 130 | static const std::string OID_EMAIL; |
| 131 | |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 132 | mutable Block m_wire; |
| 133 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 134 | std::map<std::string, std::string> m_entries; |
| 135 | }; |
| 136 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 137 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 138 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 139 | #endif // CHRONOCHAT_PROFILE_HPP |