blob: 89d3876c02cfc797fd78b2028032f9b9e8bd7fb5 [file] [log] [blame]
Yingdi Yu783ce4b2013-10-18 17:04:19 -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
Yingdi Yufa4ce792014-02-06 18:09:22 -080011#ifndef CHRONOS_DNS_STORAGE_H
12#define CHRONOS_DNS_STORAGE_H
Yingdi Yu783ce4b2013-10-18 17:04:19 -070013
Yingdi Yufa4ce792014-02-06 18:09:22 -080014#include "config.h"
Yingdi Yu783ce4b2013-10-18 17:04:19 -070015#include <sqlite3.h>
Yingdi Yub6fb0302014-01-21 11:05:11 -080016#include <ndn-cpp-dev/data.hpp>
Yingdi Yu783ce4b2013-10-18 17:04:19 -070017
Yingdi Yufa4ce792014-02-06 18:09:22 -080018namespace chronos{
19
Yingdi Yu783ce4b2013-10-18 17:04:19 -070020class DnsStorage
21{
22public:
Yingdi Yuf8f572d2014-01-13 11:19:47 -080023 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
24
Yingdi Yu783ce4b2013-10-18 17:04:19 -070025 DnsStorage();
26
Yingdi Yufa4ce792014-02-06 18:09:22 -080027 ~DnsStorage()
28 { sqlite3_close(m_db); }
Yingdi Yu783ce4b2013-10-18 17:04:19 -070029
30 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080031 updateDnsSelfProfileData(const ndn::Data& data, const ndn::Name& identity)
32 { updateDnsData(data.wireEncode(), identity.toUri(), "N/A", "PROFILE", data.getName().toUri()); }
Yingdi Yu783ce4b2013-10-18 17:04:19 -070033
34 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080035 updateDnsEndorseOthers(const ndn::Data& data, const ndn::Name& identity, const ndn::Name& endorsee)
36 { updateDnsData(data.wireEncode(), identity.toUri(), endorsee.toUri(), "ENDORSEE", data.getName().toUri()); }
Yingdi Yu783ce4b2013-10-18 17:04:19 -070037
38 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080039 updateDnsOthersEndorse(const ndn::Data& data, const ndn::Name& identity)
40 { updateDnsData(data.wireEncode(), identity.toUri(), "N/A", "ENDORSED", data.getName().toUri()); }
Yingdi Yu783ce4b2013-10-18 17:04:19 -070041
Yingdi Yu76dd8002013-12-24 11:16:32 +080042 ndn::ptr_lib::shared_ptr<ndn::Data>
Yingdi Yu783ce4b2013-10-18 17:04:19 -070043 getData(const ndn::Name& name);
44
45private:
46 void
Yingdi Yuf8f572d2014-01-13 11:19:47 -080047 updateDnsData(const ndn::Block& data, const std::string& identity, const std::string& name, const std::string& type, const std::string& dataName);
Yingdi Yu783ce4b2013-10-18 17:04:19 -070048
49private:
50 sqlite3 *m_db;
51};
52
Yingdi Yufa4ce792014-02-06 18:09:22 -080053}//chronos
54
Yingdi Yu783ce4b2013-10-18 17:04:19 -070055#endif