Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -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 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 11 | #ifndef CHRONOS_DNS_STORAGE_H |
| 12 | #define CHRONOS_DNS_STORAGE_H |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 14 | #include "config.h" |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 15 | #include <sqlite3.h> |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 16 | #include <ndn-cpp-dev/data.hpp> |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 17 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 18 | namespace chronos{ |
| 19 | |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 20 | class DnsStorage |
| 21 | { |
| 22 | public: |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 23 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 24 | |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 25 | DnsStorage(); |
| 26 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 27 | ~DnsStorage() |
| 28 | { sqlite3_close(m_db); } |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 29 | |
| 30 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 31 | updateDnsSelfProfileData(const ndn::Data& data, const ndn::Name& identity) |
| 32 | { updateDnsData(data.wireEncode(), identity.toUri(), "N/A", "PROFILE", data.getName().toUri()); } |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 33 | |
| 34 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 35 | 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 Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 37 | |
| 38 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 39 | updateDnsOthersEndorse(const ndn::Data& data, const ndn::Name& identity) |
| 40 | { updateDnsData(data.wireEncode(), identity.toUri(), "N/A", "ENDORSED", data.getName().toUri()); } |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 42 | ndn::ptr_lib::shared_ptr<ndn::Data> |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 43 | getData(const ndn::Name& name); |
| 44 | |
| 45 | private: |
| 46 | void |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 47 | updateDnsData(const ndn::Block& data, const std::string& identity, const std::string& name, const std::string& type, const std::string& dataName); |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | sqlite3 *m_db; |
| 51 | }; |
| 52 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 53 | }//chronos |
| 54 | |
Yingdi Yu | 783ce4b | 2013-10-18 17:04:19 -0700 | [diff] [blame] | 55 | #endif |