]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/breg.h
5ac23759a663bd8ad056b537552d625b7737fa03
[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-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bacula is Kern Sibbald, with contributions from
12    many others, a complete list can be found in the file AUTHORS.
13    This program is Free Software; you can redistribute it and/or
14    modify it under the terms of version two of the GNU General Public
15    License as published by the Free Software Foundation plus additions
16    that are listed in the file LICENSE.
17
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26    02110-1301, USA.
27
28    Bacula® is a registered trademark of John Walker.
29    The licensor of Bacula is the Free Software Foundation Europe
30    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31    Switzerland, email:ftf@fsfeurope.org.
32 */
33
34
35 #ifndef __BREG_H_
36 #define __BREG_H_ 1
37
38 //#undef HAVE_REGEX_H
39
40 #ifndef HAVE_REGEX_H
41 #include "bregex.h"
42 #else
43 #include <regex.h>
44 #endif
45
46 /* Usage:
47  *
48  * #include "lib/breg.h"
49  * 
50  * BREGEXP *breg = new_bregexp("!/prod!/test!");
51  * char *filename = breg->replace("/prod/data.dat");
52  *   or
53  * char *filename = breg->result;
54  * free_bregexp(breg);
55  */
56
57 /*
58  * Structure for BREGEXP ressource
59  */
60 class BREGEXP {
61 public:
62    POOLMEM *result;             /* match result */
63    bool success;                /* match is ok */
64
65    char *replace(const char *fname); /* return this.result */
66    void debug();
67
68    /* private */
69    POOLMEM *expr;               /* search epression */
70    POOLMEM *subst;              /* substitution */
71    regex_t preg;                /* regex_t result of regcomp() */
72    regmatch_t regs[RE_NREGS];   /* contains match */
73    char *eor;                   /* end of regexp in expr */
74
75    char *return_fname(const char *fname, int len); /* return fname as result */
76    char *edit_subst(const char *fname, regmatch_t regs[]);
77    int compute_dest_len(const char *fname, regmatch_t regs[]);
78    bool extract_regexp(const char *motif);
79 };
80
81 /* create new BREGEXP and compile regex_t */
82 BREGEXP *new_bregexp(const char *motif); 
83
84 /* launch each bregexp on filename */
85 int run_bregexp(alist *bregexps, const char *fname); 
86
87 /* free BREGEXP (and all POOLMEM) */
88 void free_bregexp(BREGEXP *script);
89
90 /* fill an alist with BREGEXP from where */
91 alist *get_bregexps(const char *where);
92
93 /* apply every regexps from the alist */
94 bool apply_bregexps(const char *fname, alist *bregexps, char **result);
95
96 /* foreach_alist free RUNSCRIPT */
97 void free_bregexps(alist *bregexps); /* you have to free alist */
98
99 /* get regexp size */
100 int bregexp_get_build_where_size(char *strip_prefix, 
101                                  char *add_prefix, 
102                                  char *add_suffix);
103
104 /* get a bregexp string from user arguments 
105  * you must allocate it with bregexp_get_build_where_size();
106  */
107 char *bregexp_build_where(char *dest, int str_size,
108                           char *strip_prefix, 
109                           char *add_prefix, 
110                           char *add_suffix);
111
112 /* escape a string to regexp format (sep and \) 
113  * dest must be long enough (dest = 2*src + 1)
114  */
115 char *bregexp_escape_string(char *dest, char *src, char sep);
116
117 #endif /* __BREG_H_ */