blob: 43dba9660f3becda4fd922b2faa94bcf5dae59fa [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- 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 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
43 Profile()
44 {
45 }
46
Varun Patil3d850902020-11-23 12:19:14 +053047 Profile(const ndn::security::Certificate& identityCertificate);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070048
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 Patil3d850902020-11-23 12:19:14 +053057 Profile(const Block& profileWire);
58
Yingdi Yu0b0a7362014-08-05 16:31:30 -070059 ~Profile()
60 {
61 }
62
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080063 const Block&
64 wireEncode() const;
65
66 void
67 wireDecode(const Block& profileWire);
68
Yingdi Yu0b0a7362014-08-05 16:31:30 -070069 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 Yu0b0a7362014-08-05 16:31:30 -0700109 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
121private:
Varun Patil3d850902020-11-23 12:19:14 +0530122 template<ndn::encoding::Tag T>
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800123 size_t
124 wireEncode(ndn::EncodingImpl<T>& block) const;
125
126
127private:
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700128 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 Ding0cfc1512015-02-17 17:44:11 -0800135 mutable Block m_wire;
136
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700137 std::map<std::string, std::string> m_entries;
138};
139
Yingdi Yueb692ac2015-02-10 18:46:18 -0800140} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700141
Yingdi Yueb692ac2015-02-10 18:46:18 -0800142#endif // CHRONOCHAT_PROFILE_HPP