blob: d0f5f5bbfb5a32d7bf6119b036a29cab6b0ef0fb [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
Yingdi Yuaa8d7692013-10-18 17:05:02 -070021
Yingdi Yuede8eaf2013-10-14 14:07:03 -070022class ContactStorage
23{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070024
Yingdi Yuede8eaf2013-10-14 14:07:03 -070025public:
Yingdi Yuaa8d7692013-10-18 17:05:02 -070026 ContactStorage();
Yingdi Yuede8eaf2013-10-14 14:07:03 -070027
Yingdi Yuaa8d7692013-10-18 17:05:02 -070028 ~ContactStorage()
29 {sqlite3_close(m_db);}
Yingdi Yuede8eaf2013-10-14 14:07:03 -070030
31 void
Yingdi Yu49eea9f2013-10-17 15:07:17 -070032 setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070033
34 ndn::Ptr<Profile>
Yingdi Yu49eea9f2013-10-17 15:07:17 -070035 getSelfProfile(const ndn::Name& identity);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070036
37 void
Yingdi Yuede8eaf2013-10-14 14:07:03 -070038 addTrustedContact(const TrustedContact& trustedContact);
39
40 void
41 addNormalContact(const ContactItem& contactItem);
42
Yingdi Yu79c25a22013-10-21 13:38:38 -070043 void
44 updateAlias(const ndn::Name& identity, std::string alias);
45
Yingdi Yuede8eaf2013-10-14 14:07:03 -070046 std::vector<ndn::Ptr<TrustedContact> >
47 getAllTrustedContacts() const;
48
49 std::vector<ndn::Ptr<ContactItem> >
50 getAllNormalContacts() const;
Yingdi Yud40226b2013-10-23 14:05:12 -070051
52 ndn::Ptr<ContactItem>
53 getNormalContact(const ndn::Name& name);
54
55 ndn::Ptr<TrustedContact>
56 getTrustedContact(const ndn::Name& name);
Yingdi Yuaa8d7692013-10-18 17:05:02 -070057
58 ndn::Ptr<Profile>
59 getSelfProfile(const ndn::Name& identity) const;
60
61 ndn::Ptr<ndn::Blob>
62 getSelfEndorseCertificate(const ndn::Name& identity);
Yingdi Yuede8eaf2013-10-14 14:07:03 -070063
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070064 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070065 updateSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
66
67 void
68 addSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
Yingdi Yuc26af3c2013-10-17 17:03:46 -070069
Yingdi Yuede8eaf2013-10-14 14:07:03 -070070private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070071 bool
Yingdi Yu49eea9f2013-10-17 15:07:17 -070072 doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070073
Yingdi Yuede8eaf2013-10-14 14:07:03 -070074 inline bool
75 doesTrustedContactExist(const ndn::Name& name)
76 { return doesContactExist(name, false); }
77
78 inline bool
79 doesNormalContactExist(const ndn::Name& name)
80 { return doesContactExist(name, true); }
81
82 bool
83 doesContactExist(const ndn::Name& name, bool normal);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070084
Yingdi Yuede8eaf2013-10-14 14:07:03 -070085private:
Yingdi Yuede8eaf2013-10-14 14:07:03 -070086 sqlite3 *m_db;
87};
88
89#endif