]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/breg.h
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / lib / breg.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2006-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Bacula BREGEXP Structure definition for FileDaemon
22  * Eric Bollengier March 2007
23  */
24
25
26 #ifndef __BREG_H_
27 #define __BREG_H_ 1
28
29 //#undef HAVE_REGEX_H
30
31 #ifndef HAVE_REGEX_H
32 #include "bregex.h"
33 #else
34 #include <regex.h>
35 #endif
36
37 /* Usage:
38  *
39  * #include "lib/breg.h"
40  *
41  * BREGEXP *breg = new_bregexp("!/prod!/test!");
42  * char *filename = breg->replace("/prod/data.dat");
43  *   or
44  * char *filename = breg->result;
45  * free_bregexp(breg);
46  */
47
48 #define BREG_NREGS 11
49
50 /*
51  * Structure for BREGEXP ressource
52  */
53 class BREGEXP {
54 public:
55    POOLMEM *result;             /* match result */
56    bool success;                /* match is ok */
57
58    char *replace(const char *fname); /* return this.result */
59    void debug();
60
61    /* private */
62    POOLMEM *expr;               /* search epression */
63    POOLMEM *subst;              /* substitution */
64    regex_t preg;                /* regex_t result of regcomp() */
65    regmatch_t regs[BREG_NREGS]; /* contains match */
66    char *eor;                   /* end of regexp in expr */
67
68    char *return_fname(const char *fname, int len); /* return fname as result */
69    char *edit_subst(const char *fname, regmatch_t breg[]);
70    int compute_dest_len(const char *fname, regmatch_t breg[]);
71    bool extract_regexp(const char *motif);
72 };
73
74 /* create new BREGEXP and compile regex_t */
75 BREGEXP *new_bregexp(const char *motif);
76
77 /* launch each bregexp on filename */
78 int run_bregexp(alist *bregexps, const char *fname);
79
80 /* free BREGEXP (and all POOLMEM) */
81 void free_bregexp(BREGEXP *script);
82
83 /* fill an alist with BREGEXP from where */
84 alist *get_bregexps(const char *where);
85
86 /* apply every regexps from the alist */
87 bool apply_bregexps(const char *fname, alist *bregexps, char **result);
88
89 /* foreach_alist free RUNSCRIPT */
90 void free_bregexps(alist *bregexps); /* you have to free alist */
91
92 /* get regexp size */
93 int bregexp_get_build_where_size(char *strip_prefix,
94                                  char *add_prefix,
95                                  char *add_suffix);
96
97 /* get a bregexp string from user arguments
98  * you must allocate it with bregexp_get_build_where_size();
99  */
100 char *bregexp_build_where(char *dest, int str_size,
101                           char *strip_prefix,
102                           char *add_prefix,
103                           char *add_suffix);
104
105 /* escape a string to regexp format (sep and \)
106  * dest must be long enough (dest = 2*src + 1)
107  */
108 char *bregexp_escape_string(char *dest, const char *src, const char sep);
109
110 #endif /* __BREG_H_ */