Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 21 | #ifndef CHRONOSHARE_SRC_DB_HELPER_HPP |
| 22 | #define CHRONOSHARE_SRC_DB_HELPER_HPP |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 24 | #include "core/chronoshare-common.hpp" |
| 25 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 26 | #include <boost/filesystem.hpp> |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 27 | #include <sqlite3.h> |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 29 | namespace ndn { |
| 30 | namespace chronoshare { |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 31 | |
| 32 | class DbHelper |
| 33 | { |
| 34 | public: |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 35 | class Error : public std::runtime_error |
| 36 | { |
| 37 | public: |
| 38 | explicit Error(const std::string& what) |
| 39 | : std::runtime_error(what) |
| 40 | { |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | public: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 45 | DbHelper(const boost::filesystem::path& path, const std::string& dbname); |
| 46 | virtual ~DbHelper(); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 48 | private: |
| 49 | static void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 50 | hash_xStep(sqlite3_context* context, int argc, sqlite3_value** argv); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 51 | |
| 52 | static void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 53 | hash_xFinal(sqlite3_context* context); |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 55 | static void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 56 | is_prefix_xFun(sqlite3_context* context, int argc, sqlite3_value** argv); |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 58 | static void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 59 | directory_name_xFun(sqlite3_context* context, int argc, sqlite3_value** argv); |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 20fd84a | 2013-02-27 12:17:00 -0800 | [diff] [blame] | 61 | static void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 62 | is_dir_prefix_xFun(sqlite3_context* context, int argc, sqlite3_value** argv); |
Alexander Afanasyev | 20fd84a | 2013-02-27 12:17:00 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 64 | protected: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 65 | sqlite3* m_db; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 68 | typedef shared_ptr<DbHelper> DbHelperPtr; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 70 | } // chronoshare |
| 71 | } // ndn |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | c7170bc | 2016-12-25 16:17:26 -0800 | [diff] [blame] | 73 | #endif // CHRONOSHARE_SRC_DB_HELPER_HPP |