1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 
20 #ifndef journal_H
21 #define journal_H
22 
23 #include "settings-record.h"
24 #include "folder-record.h"
25 #include "file-record.h"
26 
27 #ifndef HAVE_WIN32
28 #include <sys/file.h>
29 #endif
30 
31 #ifdef HAVE_WIN32
32 #define JOURNAL_CLI_FNAME "bcdp-cli.journal"
33 #else
34 #define JOURNAL_CLI_FNAME ".bcdp-cli.journal"
35 #endif
36 
37 #define JOURNAL_VERSION 1
38 
39 /**
40  * @brief The Journal persists and retrieves @class FileRecord objects.
41  *
42  * Used by:
43  *
44  * 1-) The CDP Client, to store information about files that
45  * should backed up.
46  *
47  * 2-) The CDP FD Plugin, to decide which file should be backed
48  * up on a specific Job.
49  *
50  * The current implementation uses a plain text file to store the records.
51  */
52 class Journal
53 {
54 
55 private:
56     FILE * _fp;
57     int _fd;
58 
59 public:
60     char *_jPath;
61     bool hasTransaction;
62 
Journal()63     Journal():
64         _fp(NULL), _fd(-1), _jPath(NULL), hasTransaction(false)
65     {}
66 
~Journal()67     ~Journal() {}
68 
69     bool setJournalPath(const char *path);
70     bool setJournalPath(const char *path, const char *spoolDir);
71     bool migrateTo(const char* newPath);
72 
73     bool beginTransaction(const char *mode);
74     void endTransaction();
75 
76     bool writeSettings(SettingsRecord &record);
77     SettingsRecord *readSettings();
78 
79     bool writeFileRecord(const FileRecord &record);
80     FileRecord *readFileRecord();
81 
82     bool removeFolderRecord(const char *folder);
83     bool writeFolderRecord(const FolderRecord &record);
84     FolderRecord *readFolderRecord();
85 
86     /** Public only because it's used by Unit Tests */
87     char *extract_val(const char *key_val);
88 
89     //TODO: warnSizeFull();
90     //TODO: removeRecord()
91     //TODO: pruneRecords()
92 };
93 
94 #endif
95