blob: a6604d28db47ea09ede72c37f97e01e57be3d77f [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * 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 Afanasyev71b43e72012-12-27 01:03:43 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * 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 Afanasyev71b43e72012-12-27 01:03:43 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * 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 Afanasyev71b43e72012-12-27 01:03:43 -080019 */
20
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080021#ifndef CHRONOSHARE_SRC_DB_HELPER_HPP
22#define CHRONOSHARE_SRC_DB_HELPER_HPP
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080023
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080024#include "core/chronoshare-common.hpp"
25
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080026#include <boost/filesystem.hpp>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080027#include <sqlite3.h>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080028
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080029namespace ndn {
30namespace chronoshare {
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080031
32class DbHelper
33{
34public:
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080035 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
44public:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080045 DbHelper(const boost::filesystem::path& path, const std::string& dbname);
46 virtual ~DbHelper();
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080047
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080048private:
49 static void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080050 hash_xStep(sqlite3_context* context, int argc, sqlite3_value** argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080051
52 static void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080053 hash_xFinal(sqlite3_context* context);
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080054
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080055 static void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080056 is_prefix_xFun(sqlite3_context* context, int argc, sqlite3_value** argv);
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080057
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080058 static void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080059 directory_name_xFun(sqlite3_context* context, int argc, sqlite3_value** argv);
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080060
Alexander Afanasyev20fd84a2013-02-27 12:17:00 -080061 static void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080062 is_dir_prefix_xFun(sqlite3_context* context, int argc, sqlite3_value** argv);
Alexander Afanasyev20fd84a2013-02-27 12:17:00 -080063
Alexander Afanasyeva199f972013-01-02 19:37:26 -080064protected:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 sqlite3* m_db;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080066};
67
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080068typedef shared_ptr<DbHelper> DbHelperPtr;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080069
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080070} // chronoshare
71} // ndn
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080072
Alexander Afanasyevc7170bc2016-12-25 16:17:26 -080073#endif // CHRONOSHARE_SRC_DB_HELPER_HPP