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