Yingdi Yu | ede8eaf | 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 | 0a6b6c5 | 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 | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 20 | |
| 21 | class ContactStorage |
| 22 | { |
| 23 | public: |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 24 | ContactStorage(ndn::Ptr<ndn::security::IdentityManager> identityManager); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 25 | |
| 26 | ~ContactStorage() {} |
| 27 | |
| 28 | void |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 29 | setSelfProfileIdentity(const ndn::Name& identity); |
| 30 | |
| 31 | void |
| 32 | setSelfProfileEntry(const std::string& profileType, const ndn::Blob& profileValue); |
| 33 | |
| 34 | ndn::Ptr<Profile> |
| 35 | getSelfProfile(); |
| 36 | |
| 37 | void |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 38 | addTrustedContact(const TrustedContact& trustedContact); |
| 39 | |
| 40 | void |
| 41 | addNormalContact(const ContactItem& contactItem); |
| 42 | |
| 43 | std::vector<ndn::Ptr<TrustedContact> > |
| 44 | getAllTrustedContacts() const; |
| 45 | |
| 46 | std::vector<ndn::Ptr<ContactItem> > |
| 47 | getAllNormalContacts() const; |
| 48 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 49 | void |
| 50 | updateProfileData() const; |
| 51 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 52 | private: |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 53 | bool |
| 54 | doesSelfEntryExist(const std::string& profileType); |
| 55 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 56 | inline bool |
| 57 | doesTrustedContactExist(const ndn::Name& name) |
| 58 | { return doesContactExist(name, false); } |
| 59 | |
| 60 | inline bool |
| 61 | doesNormalContactExist(const ndn::Name& name) |
| 62 | { return doesContactExist(name, true); } |
| 63 | |
| 64 | bool |
| 65 | doesContactExist(const ndn::Name& name, bool normal); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 66 | |
| 67 | ndn::Ptr<Profile> |
| 68 | getSelfProfile() const; |
| 69 | |
| 70 | ndn::Ptr<ProfileData> |
| 71 | getSignedSelfProfileData(const ndn::Name& identity, |
| 72 | const Profile& profile) const; |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 73 | |
| 74 | private: |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 75 | ndn::Ptr<ndn::security::IdentityManager> m_identityManager; |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 76 | sqlite3 *m_db; |
| 77 | }; |
| 78 | |
| 79 | #endif |