blob: deb330a56beae40fa8ce9fa0ef9556b74b23c3da [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 Yu0a6b6c52013-10-15 17:54:00 -070017#include "profile-data.h"
18#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 Yu0a6b6c52013-10-15 17:54:00 -070029 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 Yuede8eaf2013-10-14 14:07:03 -070038 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 Yu0a6b6c52013-10-15 17:54:00 -070049 void
50 updateProfileData() const;
51
Yingdi Yuede8eaf2013-10-14 14:07:03 -070052private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070053 bool
54 doesSelfEntryExist(const std::string& profileType);
55
Yingdi Yuede8eaf2013-10-14 14:07:03 -070056 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 Yu0a6b6c52013-10-15 17:54:00 -070066
67 ndn::Ptr<Profile>
68 getSelfProfile() const;
69
70 ndn::Ptr<ProfileData>
71 getSignedSelfProfileData(const ndn::Name& identity,
72 const Profile& profile) const;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070073
74private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070075 ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070076 sqlite3 *m_db;
77};
78
79#endif