Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 11 | #ifndef LINKNDN_CONTACT_STORAGE_H |
| 12 | #define LINKNDN_CONTACT_STORAGE_H |
| 13 | |
| 14 | #include <sqlite3.h> |
| 15 | #include "trusted-contact.h" |
| 16 | #include "contact-item.h" |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 17 | #include "profile-data.h" |
| 18 | #include <ndn.cxx/security/identity/identity-manager.h> |
| 19 | #include <ndn.cxx/fields/signature-sha256-with-rsa.h> |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 20 | |
| 21 | class ContactStorage |
| 22 | { |
| 23 | public: |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 24 | ContactStorage(ndn::Ptr<ndn::security::IdentityManager> identityManager); |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 25 | |
| 26 | ~ContactStorage() {} |
| 27 | |
| 28 | void |
Yingdi Yu | 54dcecc | 2013-10-17 15:07:17 -0700 | [diff] [blame^] | 29 | setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 30 | |
| 31 | ndn::Ptr<Profile> |
Yingdi Yu | 54dcecc | 2013-10-17 15:07:17 -0700 | [diff] [blame^] | 32 | getSelfProfile(const ndn::Name& identity); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 33 | |
| 34 | void |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 35 | addTrustedContact(const TrustedContact& trustedContact); |
| 36 | |
| 37 | void |
| 38 | addNormalContact(const ContactItem& contactItem); |
| 39 | |
| 40 | std::vector<ndn::Ptr<TrustedContact> > |
| 41 | getAllTrustedContacts() const; |
| 42 | |
| 43 | std::vector<ndn::Ptr<ContactItem> > |
| 44 | getAllNormalContacts() const; |
| 45 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 46 | void |
Yingdi Yu | 54dcecc | 2013-10-17 15:07:17 -0700 | [diff] [blame^] | 47 | updateProfileData(const ndn::Name& identity) const; |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 48 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 49 | private: |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 50 | bool |
Yingdi Yu | 54dcecc | 2013-10-17 15:07:17 -0700 | [diff] [blame^] | 51 | doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 52 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 53 | inline bool |
| 54 | doesTrustedContactExist(const ndn::Name& name) |
| 55 | { return doesContactExist(name, false); } |
| 56 | |
| 57 | inline bool |
| 58 | doesNormalContactExist(const ndn::Name& name) |
| 59 | { return doesContactExist(name, true); } |
| 60 | |
| 61 | bool |
| 62 | doesContactExist(const ndn::Name& name, bool normal); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 63 | |
| 64 | ndn::Ptr<Profile> |
Yingdi Yu | 54dcecc | 2013-10-17 15:07:17 -0700 | [diff] [blame^] | 65 | getSelfProfile(const ndn::Name& identity) const; |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 66 | |
| 67 | ndn::Ptr<ProfileData> |
| 68 | getSignedSelfProfileData(const ndn::Name& identity, |
| 69 | const Profile& profile) const; |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 70 | |
| 71 | private: |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 72 | ndn::Ptr<ndn::security::IdentityManager> m_identityManager; |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 73 | sqlite3 *m_db; |
| 74 | }; |
| 75 | |
| 76 | #endif |