blob: e085e77a2d81e5ea7399e5505774bb5971cd8a64 [file] [log] [blame]
Yingdi Yub4be64a2013-10-13 17:24:50 -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>
9 */
10
Yingdi Yufa4ce792014-02-06 18:09:22 -080011#ifndef CHRONOS_PROFILE_H
12#define CHRONOS_PROFILE_H
Yingdi Yub4be64a2013-10-13 17:24:50 -070013
Yingdi Yufa4ce792014-02-06 18:09:22 -080014#include "config.h"
Yingdi Yub6fb0302014-01-21 11:05:11 -080015#include <ndn-cpp-dev/name.hpp>
16#include <ndn-cpp-dev/security/identity-certificate.hpp>
Yingdi Yub4be64a2013-10-13 17:24:50 -070017#include <map>
18#include <string>
Yingdi Yu76dd8002013-12-24 11:16:32 +080019#include "profile.pb.h"
Yingdi Yub4be64a2013-10-13 17:24:50 -070020
Yingdi Yufa4ce792014-02-06 18:09:22 -080021namespace chronos{
22
Yingdi Yub4be64a2013-10-13 17:24:50 -070023class Profile
24{
25public:
Yingdi Yu76dd8002013-12-24 11:16:32 +080026 typedef std::map<std::string, std::string>::iterator iterator;
27 typedef std::map<std::string, std::string>::const_iterator const_iterator;
Yingdi Yufa4ce792014-02-06 18:09:22 -080028
Yingdi Yub4be64a2013-10-13 17:24:50 -070029 Profile() {}
30
Yingdi Yu76dd8002013-12-24 11:16:32 +080031 Profile(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu2e3199c2013-11-06 18:42:34 -080032
Yingdi Yub4be64a2013-10-13 17:24:50 -070033 Profile(const ndn::Name& identityName);
34
35 Profile(const ndn::Name& identityName,
36 const std::string& name,
37 const std::string& institution);
38
39 Profile(const Profile& profile);
40
Yingdi Yub4be64a2013-10-13 17:24:50 -070041 ~Profile() {}
42
Yingdi Yufa4ce792014-02-06 18:09:22 -080043 std::string&
44 operator [] (const std::string& profileKey)
45 { return m_entries[profileKey]; }
46
47 std::string
48 get (const std::string& profileKey) const
49 {
50 std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey);
51 if(it != m_entries.end())
52 return it->second;
53 else
54 return std::string();
55 }
Yingdi Yub4be64a2013-10-13 17:24:50 -070056
57 inline Profile::iterator
58 begin()
59 { return m_entries.begin(); }
60
61 inline Profile::const_iterator
62 begin() const
63 { return m_entries.begin(); }
64
65 inline Profile::iterator
66 end()
67 { return m_entries.end(); }
68
69 inline Profile::const_iterator
70 end() const
71 { return m_entries.end(); }
72
Yingdi Yu76dd8002013-12-24 11:16:32 +080073 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080074 encode(std::ostream& os) const;
Yingdi Yub4be64a2013-10-13 17:24:50 -070075
Yingdi Yufa4ce792014-02-06 18:09:22 -080076 void
77 decode(std::istream& is);
Yingdi Yub4be64a2013-10-13 17:24:50 -070078
Yingdi Yufa4ce792014-02-06 18:09:22 -080079 ndn::Name
Yingdi Yu2e3199c2013-11-06 18:42:34 -080080 getIdentityName() const
Yingdi Yufa4ce792014-02-06 18:09:22 -080081 { return ndn::Name(m_entries.at("IDENTITY")); }
Yingdi Yu2e3199c2013-11-06 18:42:34 -080082
Yingdi Yufa4ce792014-02-06 18:09:22 -080083 inline bool
84 operator == (const Profile& profile) const;
85
86private:
87 static const std::string OID_NAME;
88 static const std::string OID_ORG;
89 static const std::string OID_GROUP;
90 static const std::string OID_HOMEPAGE;
91 static const std::string OID_ADVISOR;
92 static const std::string OID_EMAIL;
93
Yingdi Yu76dd8002013-12-24 11:16:32 +080094 std::map<std::string, std::string> m_entries;
Yingdi Yub4be64a2013-10-13 17:24:50 -070095};
96
Yingdi Yufa4ce792014-02-06 18:09:22 -080097Chronos::ProfileMsg&
98operator << (Chronos::ProfileMsg& msg, const Profile& profile);
99
100Chronos::ProfileMsg&
101operator >> (Chronos::ProfileMsg& msg, Profile& profile);
102
103bool
104Profile::operator == (const Profile& profile) const
105{
106 if(m_entries.size() != profile.m_entries.size())
107 return false;
108
109 std::map<std::string, std::string>::const_iterator it = m_entries.begin();
110 for(; it != m_entries.end(); it++)
111 {
112 std::map<std::string, std::string>::const_iterator found = profile.m_entries.find(it->first);
113 if(found == profile.m_entries.end())
114 return false;
115 if(found->second != it->second)
116 return false;
117 }
118
119 return true;
120}
121
122}//chronos
123
Yingdi Yub4be64a2013-10-13 17:24:50 -0700124#endif