]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bvfs.h
Tweak leave SQL library links in rpm
[bacula/bacula] / bacula / src / cats / bvfs.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 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
21 #ifndef __BVFS_H_
22 #define __BVFS_H_ 1
23
24
25 /*
26  * This object can be use to browse the catalog
27  *
28  * Bvfs fs;
29  * fs.set_jobid(10);
30  * fs.update_cache();
31  * fs.ch_dir("/");
32  * fs.ls_dirs();
33  * fs.ls_files();
34  */
35
36 /* Helper for result handler */
37 typedef enum {
38    BVFS_FILE_RECORD  = 'F',
39    BVFS_DIR_RECORD   = 'D',
40    BVFS_FILE_VERSION = 'V',
41    BVFS_VOLUME_LIST  = 'L'
42 } bvfs_handler_type;
43
44 typedef enum {
45    BVFS_Type    = 0,            /* Could be D, F, V, L */
46    BVFS_PathId  = 1, 
47    BVFS_FilenameId = 2,
48
49    BVFS_Name    = 3,
50    BVFS_JobId   = 4,
51
52    BVFS_LStat   = 5,            /* Can be empty for missing directories */
53    BVFS_FileId  = 6,            /* Can be empty for missing directories */
54
55    /* Only if File Version record */
56    BVFS_Md5     = 3,
57    BVFS_VolName = 7,
58    BVFS_VolInchanger = 8
59 } bvfs_row_index;
60
61 class Bvfs {
62
63 public:
64    Bvfs(JCR *j, BDB *mdb);
65    virtual ~Bvfs();
66
67    void set_jobid(JobId_t id);
68    void set_jobids(char *ids);
69
70    char *get_jobids() {
71       return jobids;
72    }
73
74    void set_limit(uint32_t max) {
75       limit = max;
76    }
77
78    void set_offset(uint32_t nb) {
79       offset = nb;
80    }
81
82    void set_pattern(char *p) {
83       uint32_t len = strlen(p);
84       pattern = check_pool_memory_size(pattern, len*2+1);
85       db->bdb_escape_string(jcr, pattern, p, len);
86    }
87
88    void set_filename(char *p) {
89       uint32_t len = strlen(p);
90       filename = check_pool_memory_size(filename, len*2+1);
91       db->bdb_escape_string(jcr, filename, p, len);
92    }
93
94    /* Get the root point */
95    DBId_t get_root();
96
97    /* It's much better to access Path though their PathId, it
98     * avoids mistakes with string encoding
99     */
100    void ch_dir(DBId_t pathid) {
101       reset_offset();
102       pwd_id = pathid;
103    }
104
105    /*
106     * Returns true if the directory exists
107     */
108    bool ch_dir(const char *path);
109
110    bool ls_files();             /* Returns true if we have more files to read */
111    bool ls_dirs();              /* Returns true if we have more dir to read */
112    void ls_special_dirs();      /* get . and .. */
113    void get_all_file_versions(DBId_t pathid, FileId_t fnid, const char *client);
114
115    void update_cache();
116
117    /* bfileview */
118    void fv_update_cache();
119
120    void set_see_all_versions(bool val) {
121       see_all_versions = val;
122    }
123
124    void set_see_copies(bool val) {
125       see_copies = val;
126    }
127
128    void filter_jobid();         /* Call after set_username */
129
130    void set_username(char *user) {
131       if (user) {
132          username = bstrdup(user);
133       }
134    }
135
136    char *escape_list(alist *list);
137
138    bool copy_acl(alist *list) {
139       if (!list ||
140           (list->size() > 0 &&
141            (strcasecmp((char *)list->get(0), "*all*") == 0)))
142       {
143          return false;
144       }
145       return true;
146    }
147
148    /* Keep a pointer to various ACLs */
149    void set_job_acl(alist *lst) {
150       job_acl = copy_acl(lst)?lst:NULL;
151    }
152    void set_fileset_acl(alist *lst) {
153       fileset_acl = copy_acl(lst)?lst:NULL;
154    }
155    void set_client_acl(alist *lst) {
156       client_acl = copy_acl(lst)?lst:NULL;
157    }
158    void set_pool_acl(alist *lst) {
159       pool_acl = copy_acl(lst)?lst:NULL;
160    }
161
162    void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
163       list_entries = h;
164       user_data = ctx;
165    }
166
167    DBId_t get_pwd() {
168       return pwd_id;
169    }
170
171    ATTR *get_attr() {
172       return attr;
173    }
174
175    JCR *get_jcr() {
176       return jcr;
177    }
178
179    void reset_offset() {
180       offset=0;
181    }
182
183    void next_offset() {
184       offset+=limit;
185    }
186
187    /* Clear all cache */
188    void clear_cache();
189
190    /* Compute restore list */
191    bool compute_restore_list(char *fileid, char *dirid, char *hardlink,
192                              char *output_table);
193
194    /* Drop previous restore list */
195    bool drop_restore_list(char *output_table);
196
197    /* for internal use */
198    int _handle_path(void *, int, char **);
199
200    /* Handle Delta parts if any */
201    void insert_missing_delta(char *output_table, int64_t *res);
202
203    /* Get a list of volumes */
204    void get_volumes(FileId_t fileid);
205
206 private:
207    Bvfs(const Bvfs &);               /* prohibit pass by value */
208    Bvfs & operator = (const Bvfs &); /* prohibit class assignment */
209
210    JCR *jcr;
211    BDB *db;
212    POOLMEM *jobids;
213    char *username;              /* Used with Bweb */
214
215    POOLMEM *prev_dir; /* ls_dirs query returns all versions, take the 1st one */
216    POOLMEM *pattern;
217    POOLMEM *filename;
218
219    POOLMEM *tmp;
220    POOLMEM *escaped_list;
221
222    /* Pointer to Console ACL */
223    alist *job_acl;
224    alist *client_acl;
225    alist *fileset_acl;
226    alist *pool_acl;
227
228    ATTR *attr;        /* Can be use by handler to call decode_stat() */
229
230    uint32_t limit;
231    uint32_t offset;
232    uint32_t nb_record;          /* number of records of the last query */
233    DBId_t pwd_id;               /* Current pathid */
234    DBId_t dir_filenameid;       /* special FilenameId where Name='' */
235
236    bool see_all_versions;
237    bool see_copies;
238
239    DBId_t get_dir_filenameid();
240
241    /* bfileview */
242    void fv_get_big_files(int64_t pathid, int64_t min_size, int32_t limit);
243    void fv_update_size_and_count(int64_t pathid, int64_t size, int64_t count);
244    void fv_compute_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
245    void fv_get_current_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
246    void fv_get_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
247
248    DB_RESULT_HANDLER *list_entries;
249    void *user_data;
250 };
251
252 #define bvfs_is_dir(row) ((row)[BVFS_Type][0] == BVFS_DIR_RECORD)
253 #define bvfs_is_file(row) ((row)[BVFS_Type][0] == BVFS_FILE_RECORD)
254 #define bvfs_is_version(row) ((row)[BVFS_Type][0] == BVFS_FILE_VERSION)
255 #define bvfs_is_volume_list(row) ((row)[BVFS_Type][0] == BVFS_VOLUME_LIST)
256
257 void bvfs_update_fv_cache(JCR *jcr, BDB *mdb, char *jobids);
258 int bvfs_update_path_hierarchy_cache(JCR *jcr, BDB *mdb, char *jobids);
259 void bvfs_update_cache(JCR *jcr, BDB *mdb);
260 char *bvfs_parent_dir(char *path);
261
262 /* Return the basename of the with the trailing /  (update the given string)
263  * TODO: see in the rest of bacula if we don't have
264  * this function already
265  */
266 char *bvfs_basename_dir(char *path);
267
268
269 #endif /* __BVFS_H_ */