lib: added warning checks for unsupported recursion fields in vevent.cc
[barry/progweb.git] / src / restore.h
blob6c3e3e3b264918b32958cb9bd928139145a0a0e4
1 ///
2 /// \file restore.h
3 /// Builder class for restoring from Barry Backup files
4 ///
6 /*
7 Copyright (C) 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRYBACKUP_RESTORE_H__
23 #define __BARRYBACKUP_RESTORE_H__
25 #include "dll.h"
26 #include "builder.h"
27 #include "configfile.h"
28 #include <string>
29 #include <vector>
30 #include <memory>
32 // forward declarations
33 namespace reuse {
34 class TarFile;
37 namespace Barry {
40 // Restore
42 /// Barry Backup Restore builder class. This class is suitable
43 /// to be used as a builder object anywhere a builder object is
44 /// accepted. It reads from a Barry Backup tar.gz backup file,
45 /// and builds records in a staged manner.
46 ///
47 /// If a backup file contains more than one database (for example
48 /// both Address Book and Calendar), then it will build one database
49 /// first, return false on Retrieve(), and then build the next.
50 /// If Retrieve() returns false, but EndOfFile() also returns false,
51 /// then more databases are available.
52 ///
53 /// The idea is that you can call Desktop::SaveDatabase() multiple
54 /// times with this same Restore object, for all the databases in
55 /// the backup file.
56 ///
57 /// It is safe to call Retrieve() multiple times, so when first
58 /// starting a restore:
59 /// - call the constructor
60 /// - call AddDB() with any filters
61 /// - then call Retrieve(), which will grab the first record,
62 /// and make GetDBName() valid.
63 ///
64 class BXEXPORT Restore : public Barry::Builder
66 public:
67 typedef Barry::ConfigFile::DBListType DBListType;
69 private:
70 enum RetrievalState
72 RS_EMPTY, // no record loaded
73 RS_UNKNOWN, // record data loaded, but not yet checked
74 // whether this is part of current database
75 RS_NEXT, // record loaded, part of current database
76 RS_DBEND, // next record loaded, but end-of-database
77 // not yet processed by Builder API
78 RS_EOF // no recrd loaded, end of tar file
81 DBListType m_dbList;
82 DBListType m_dbSkipList;
84 std::string m_tarpath;
85 std::auto_ptr<reuse::TarFile> m_tar;
87 bool m_default_all_db;
88 RetrievalState m_tar_record_state;
89 uint8_t m_rec_type;
90 uint32_t m_unique_id;
91 std::string m_current_dbname;
92 Barry::Data m_record_data;
93 std::string m_tar_id_text;
95 protected:
96 static bool SplitTarPath(const std::string &tarpath,
97 std::string &dbname, std::string &dbid_text,
98 uint8_t &dbrectype, uint32_t &dbid);
100 bool IsSelected(const std::string &dbName) const;
101 RetrievalState Retrieve(Data &record_data);
104 public:
105 /// If default_all_db is true, and none of the Add*() functions
106 /// are called (meaning that Restore has an empty database list),
107 /// then all records are restored. If false in this situation,
108 /// nothing is restored.
110 /// If any of the Add*() functions are called, then the database
111 /// list takes precedence, and default_all_db has no effect.
113 explicit Restore(const std::string &tarpath,
114 bool default_all_db = true);
115 ~Restore();
117 /// Add database name to the read filter.
118 void AddDB(const std::string &dbName);
120 /// Add all database names in dblist to the read filter
121 void Add(const DBListType &dbList);
123 /// Add all database names in the DBDB to the read filter
124 void Add(const DatabaseDatabase &dbdb);
126 /// Add database name to the skip list. The skip list prevents
127 /// any matching database from appearing in the restore process.
128 /// It is the converse of AddDB() in ultimate behaviour.
129 void AddSkipDB(const std::string &dbName);
131 // Skip the current DB, in case of error, or preference
132 void SkipCurrentDB();
134 /// Loads the given file, and counts all records according
135 /// to the current read filter. Does not use the main
136 /// Restore file, but opens the file separately.
137 /// It is safe to call this function as often as needed.
138 unsigned int GetRecordTotal() const;
140 /// Static version of above call
141 static unsigned int GetRecordTotal(const std::string &tarpath,
142 const DBListType &dbList, bool default_all_db);
144 /// Loads the given file, and creates a DBListType list of
145 /// all database names available in the tarball, using no filters.
146 /// Does not use the main Restore file, but opens the file separately.
147 /// It is safe to call this function as often as needed.
148 DBListType GetDBList() const;
150 /// Static version of GetDBList()
151 static DBListType GetDBList(const std::string &tarpath);
153 /// If this function returns true, it fills data with the
154 /// meta data that the next call to BuildRecord() will retrieve.
155 /// This is useful for applications that need to setup a manual
156 /// call to Desktop::SaveDatabase().
157 bool GetNextMeta(DBData &data);
159 // Barry::Builder overrides
160 bool BuildRecord(Barry::DBData &data, size_t &offset,
161 const Barry::IConverter *ic);
162 bool FetchRecord(Barry::DBData &data, const Barry::IConverter *ic);
163 bool EndOfFile() const;
166 } // namespace Barry
168 #endif