blob: a89a800c91a361fb061f1c834dc49ba80df4db27 [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>
Yingdi Yu0b0a7362014-08-05 16:31:30 -070021#include <ndn-cxx/security/identity-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
47 Profile(const ndn::IdentityCertificate& identityCertificate);
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
57 ~Profile()
58 {
59 }
60
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080061 const Block&
62 wireEncode() const;
63
64 void
65 wireDecode(const Block& profileWire);
66
Yingdi Yu0b0a7362014-08-05 16:31:30 -070067 std::string&
68 operator[](const std::string& profileKey)
69 {
70 return m_entries[profileKey];
71 }
72
73 std::string
74 get(const std::string& profileKey) const
75 {
76 std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey);
77 if (it != m_entries.end())
78 return it->second;
79 else
80 return std::string();
81 }
82
83 Profile::iterator
84 begin()
85 {
86 return m_entries.begin();
87 }
88
89 Profile::const_iterator
90 begin() const
91 {
92 return m_entries.begin();
93 }
94
95 Profile::iterator
96 end()
97 {
98 return m_entries.end();
99 }
100
101 Profile::const_iterator
102 end() const
103 {
104 return m_entries.end();
105 }
106
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700107 Name
108 getIdentityName() const
109 {
110 return ndn::Name(m_entries.at("IDENTITY"));
111 }
112
113 bool
114 operator==(const Profile& profile) const;
115
116 bool
117 operator!=(const Profile& profile) const;
118
119private:
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800120 template<bool T>
121 size_t
122 wireEncode(ndn::EncodingImpl<T>& block) const;
123
124
125private:
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700126 static const std::string OID_NAME;
127 static const std::string OID_ORG;
128 static const std::string OID_GROUP;
129 static const std::string OID_HOMEPAGE;
130 static const std::string OID_ADVISOR;
131 static const std::string OID_EMAIL;
132
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800133 mutable Block m_wire;
134
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700135 std::map<std::string, std::string> m_entries;
136};
137
Yingdi Yueb692ac2015-02-10 18:46:18 -0800138} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700139
Yingdi Yueb692ac2015-02-10 18:46:18 -0800140#endif // CHRONOCHAT_PROFILE_HPP