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