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> |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 15 | #include "contact-item.h" |
Yingdi Yu | 68aced9 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 16 | #include "endorse-certificate.h" |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 17 | #include <ndn-cpp/security/identity/identity-manager.hpp> |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 18 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 20 | class ContactStorage |
| 21 | { |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 23 | public: |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 24 | ContactStorage(); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 25 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 26 | ~ContactStorage() |
| 27 | {sqlite3_close(m_db);} |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 28 | |
| 29 | void |
Yingdi Yu | 49eea9f | 2013-10-17 15:07:17 -0700 | [diff] [blame] | 30 | setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 31 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 32 | ndn::ptr_lib::shared_ptr<Profile> |
Yingdi Yu | 49eea9f | 2013-10-17 15:07:17 -0700 | [diff] [blame] | 33 | getSelfProfile(const ndn::Name& identity); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 34 | |
| 35 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 36 | removeContact(const ndn::Name& identity); |
| 37 | |
| 38 | void |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 39 | addContact(const ContactItem& contactItem); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 40 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 41 | void |
| 42 | updateIsIntroducer(const ndn::Name& identity, bool isIntroducer); |
| 43 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 44 | void |
| 45 | updateAlias(const ndn::Name& identity, std::string alias); |
| 46 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 47 | void |
| 48 | getAllContacts(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts) const; |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 49 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 50 | ndn::ptr_lib::shared_ptr<ContactItem> |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 51 | getContact(const ndn::Name& name); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 52 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 53 | ndn::ptr_lib::shared_ptr<Profile> |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 54 | getSelfProfile(const ndn::Name& identity) const; |
| 55 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 56 | |
| 57 | //SelfEndorse |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 58 | ndn::Blob |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 59 | getSelfEndorseCertificate(const ndn::Name& identity); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 60 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 61 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 62 | updateSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 63 | |
| 64 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 65 | addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 66 | |
| 67 | |
| 68 | //ProfileEndorse |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 69 | ndn::Blob |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 70 | getEndorseCertificate(const ndn::Name& identity); |
| 71 | |
| 72 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 73 | updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 74 | |
| 75 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 76 | addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 77 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 78 | void |
| 79 | getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 80 | |
Yingdi Yu | c26af3c | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 81 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 82 | //CollectEndorse |
| 83 | void |
| 84 | updateCollectEndorse(const EndorseCertificate& endorseCertificate); |
| 85 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 86 | void |
| 87 | getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Blob>& endorseList); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 88 | |
| 89 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 90 | private: |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 91 | bool |
Yingdi Yu | 49eea9f | 2013-10-17 15:07:17 -0700 | [diff] [blame] | 92 | doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 93 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 94 | bool |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 95 | doesContactExist(const ndn::Name& name); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 96 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 97 | private: |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 98 | sqlite3 *m_db; |
| 99 | }; |
| 100 | |
| 101 | #endif |