blob: 7fc3171663a8ec9e865fa66b6cb5d29621a18be4 [file] [log] [blame]
Yingdi Yuede8eaf2013-10-14 14:07:03 -07001/* -*- 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 Yu68aced92013-10-17 21:13:03 -070017#include "endorse-certificate.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070018#include <ndn.cxx/security/identity/identity-manager.h>
19#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
Yingdi Yuede8eaf2013-10-14 14:07:03 -070020
21class ContactStorage
22{
23public:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070024 ContactStorage(ndn::Ptr<ndn::security::IdentityManager> identityManager);
Yingdi Yuede8eaf2013-10-14 14:07:03 -070025
26 ~ContactStorage() {}
27
28 void
Yingdi Yu49eea9f2013-10-17 15:07:17 -070029 setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070030
31 ndn::Ptr<Profile>
Yingdi Yu49eea9f2013-10-17 15:07:17 -070032 getSelfProfile(const ndn::Name& identity);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070033
34 void
Yingdi Yuede8eaf2013-10-14 14:07:03 -070035 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 Yu0a6b6c52013-10-15 17:54:00 -070046 void
Yingdi Yu49eea9f2013-10-17 15:07:17 -070047 updateProfileData(const ndn::Name& identity) const;
Yingdi Yuc26af3c2013-10-17 17:03:46 -070048
49 inline ndn::Ptr<ndn::security::IdentityManager>
50 getIdentityManager()
51 { return m_identityManager; }
52
Yingdi Yuede8eaf2013-10-14 14:07:03 -070053private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070054 bool
Yingdi Yu49eea9f2013-10-17 15:07:17 -070055 doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070056
Yingdi Yuede8eaf2013-10-14 14:07:03 -070057 inline bool
58 doesTrustedContactExist(const ndn::Name& name)
59 { return doesContactExist(name, false); }
60
61 inline bool
62 doesNormalContactExist(const ndn::Name& name)
63 { return doesContactExist(name, true); }
64
65 bool
66 doesContactExist(const ndn::Name& name, bool normal);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070067
68 ndn::Ptr<Profile>
Yingdi Yu49eea9f2013-10-17 15:07:17 -070069 getSelfProfile(const ndn::Name& identity) const;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070070
Yingdi Yu68aced92013-10-17 21:13:03 -070071 ndn::Ptr<EndorseCertificate>
72 getSignedSelfEndorseCertificate(const ndn::Name& identity,
73 const Profile& profile) const;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070074
75private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070076 ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070077 sqlite3 *m_db;
78};
79
80#endif