blob: 632e1263fa326eaa577ae9f304f4520c0ffb9bbc [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 Afanasyeva199f972013-01-02 19:37:26 -080021#ifndef DB_HELPER_H
22#define DB_HELPER_H
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080023
Alexander Afanasyev3abe2252013-01-02 20:45:29 -080024#include <stdint.h>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080025#include <sqlite3.h>
26#include <openssl/evp.h>
27#include <boost/exception/all.hpp>
28#include <string>
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080029#include "hash-helper.hpp"
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080030#include <boost/filesystem.hpp>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080031
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080032typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080033
34class DbHelper
35{
36public:
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080037 DbHelper (const boost::filesystem::path &path, const std::string &dbname);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080038 virtual ~DbHelper ();
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080039
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080040private:
41 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080042 hash_xStep (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080043
44 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080045 hash_xFinal (sqlite3_context *context);
46
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080047 static void
48 is_prefix_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
49
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080050 static void
51 directory_name_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
52
Alexander Afanasyev20fd84a2013-02-27 12:17:00 -080053 static void
54 is_dir_prefix_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
55
Alexander Afanasyeva199f972013-01-02 19:37:26 -080056protected:
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080057 sqlite3 *m_db;
58};
59
60namespace Error {
61struct Db : virtual boost::exception, virtual std::exception { };
62}
63
Alexander Afanasyeva199f972013-01-02 19:37:26 -080064typedef boost::shared_ptr<DbHelper> DbHelperPtr;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080065
Alexander Afanasyeva199f972013-01-02 19:37:26 -080066
67#endif // DB_HELPER_H