blob: 6692127e23545804d09f047d73bfe1e0b716f0dc [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yu0b0a7362014-08-05 16:31:30 -07004 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
Qiuhan Ding0cfc1512015-02-17 17:44:11 -08009 * Qiuhan Ding <qiuhanding@cs.ucla.edu>
Yingdi Yu0b0a7362014-08-05 16:31:30 -070010 */
11
Yingdi Yueb692ac2015-02-10 18:46:18 -080012#ifndef CHRONOCHAT_PROFILE_HPP
13#define CHRONOCHAT_PROFILE_HPP
Yingdi Yu0b0a7362014-08-05 16:31:30 -070014
15#include "common.hpp"
16
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080017#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 Patil3d850902020-11-23 12:19:14 +053021#include <ndn-cxx/security/certificate.hpp>
Yingdi Yu0b0a7362014-08-05 16:31:30 -070022
Yingdi Yueb692ac2015-02-10 18:46:18 -080023namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070024
25class Profile
26{
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080027
28public:
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 Yu0b0a7362014-08-05 16:31:30 -070039public:
40 typedef std::map<std::string, std::string>::iterator iterator;
41 typedef std::map<std::string, std::string>::const_iterator const_iterator;
42
Varun Patila24bd3e2020-11-24 10:08:33 +053043 Profile() = default;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070044
Varun Patil3d850902020-11-23 12:19:14 +053045 Profile(const ndn::security::Certificate& identityCertificate);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070046
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 Patil3d850902020-11-23 12:19:14 +053055 Profile(const Block& profileWire);
56
Varun Patila24bd3e2020-11-24 10:08:33 +053057 Profile&
58 operator=(const Profile&) = default;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070059
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080060 const Block&
61 wireEncode() const;
62
63 void
64 wireDecode(const Block& profileWire);
65
Yingdi Yu0b0a7362014-08-05 16:31:30 -070066 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 Yu0b0a7362014-08-05 16:31:30 -0700106 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
118private:
Varun Patil3d850902020-11-23 12:19:14 +0530119 template<ndn::encoding::Tag T>
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800120 size_t
121 wireEncode(ndn::EncodingImpl<T>& block) const;
122
123
124private:
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700125 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 Ding0cfc1512015-02-17 17:44:11 -0800132 mutable Block m_wire;
133
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700134 std::map<std::string, std::string> m_entries;
135};
136
Yingdi Yueb692ac2015-02-10 18:46:18 -0800137} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700138
Yingdi Yueb692ac2015-02-10 18:46:18 -0800139#endif // CHRONOCHAT_PROFILE_HPP