]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/breg.h
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / bacula / src / lib / breg.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  * Bacula BREGEXP Structure definition for FileDaemon
21  * Eric Bollengier March 2007
22  */
23
24
25 #ifndef __BREG_H_
26 #define __BREG_H_ 1
27
28 //#undef HAVE_REGEX_H
29
30 #ifndef HAVE_REGEX_H
31 #include "bregex.h"
32 #else
33 #include <regex.h>
34 #endif
35
36 /* Usage:
37  *
38  * #include "lib/breg.h"
39  *
40  * BREGEXP *breg = new_bregexp("!/prod!/test!");
41  * char *filename = breg->replace("/prod/data.dat");
42  *   or
43  * char *filename = breg->result;
44  * free_bregexp(breg);
45  */
46
47 #define BREG_NREGS 11
48
49 /*
50  * Structure for BREGEXP ressource
51  */
52 class BREGEXP {
53 public:
54    POOLMEM *result;             /* match result */
55    bool success;                /* match is ok */
56
57    char *replace(const char *fname); /* return this.result */
58    void debug();
59
60    /* private */
61    POOLMEM *expr;               /* search epression */
62    POOLMEM *subst;              /* substitution */
63    regex_t preg;                /* regex_t result of regcomp() */
64    regmatch_t regs[BREG_NREGS]; /* contains match */
65    char *eor;                   /* end of regexp in expr */
66
67    char *return_fname(const char *fname, int len); /* return fname as result */
68    char *edit_subst(const char *fname, regmatch_t breg[]);
69    int compute_dest_len(const char *fname, regmatch_t breg[]);
70    bool extract_regexp(const char *motif);
71 };
72
73 /* create new BREGEXP and compile regex_t */
74 BREGEXP *new_bregexp(const char *motif);
75
76 /* launch each bregexp on filename */
77 int run_bregexp(alist *bregexps, const char *fname);
78
79 /* free BREGEXP (and all POOLMEM) */
80 void free_bregexp(BREGEXP *script);
81
82 /* fill an alist with BREGEXP from where */
83 alist *get_bregexps(const char *where);
84
85 /* apply every regexps from the alist */
86 bool apply_bregexps(const char *fname, alist *bregexps, char **result);
87
88 /* foreach_alist free RUNSCRIPT */
89 void free_bregexps(alist *bregexps); /* you have to free alist */
90
91 /* get regexp size */
92 int bregexp_get_build_where_size(char *strip_prefix,
93                                  char *add_prefix,
94                                  char *add_suffix);
95
96 /* get a bregexp string from user arguments
97  * you must allocate it with bregexp_get_build_where_size();
98  */
99 char *bregexp_build_where(char *dest, int str_size,
100                           char *strip_prefix,
101                           char *add_prefix,
102                           char *add_suffix);
103
104 /* escape a string to regexp format (sep and \)
105  * dest must be long enough (dest = 2*src + 1)
106  */
107 char *bregexp_escape_string(char *dest, const char *src, const char sep);
108
109 #endif /* __BREG_H_ */