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