2 * Copyright (c) 2010-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
30 /* The regular expressions used here are POSIX extended regular expressions;
31 * see http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html
34 /* validate that REGEX is a valid POSIX regular expression by calling regcomp.
35 * Returns a statically allocated error message on failure or NULL on success. */
36 char * validate_regexp(const char *regex);
39 * Match the string "str" against POSIX regex "regex" with regexec(), with
40 * REG_NEWLINE set (match_newline == TRUE) or not.
42 * REG_NEWLINE means two things:
43 * - the dot won't match a newline;
44 * - ^ and $ will match around \n in the input string (as well as the beginning
45 * and end of the input).
48 int do_match(const char *regex, const char *str, gboolean match_newline);
50 #define match(regex, str) do_match(regex, str, TRUE)
51 #define match_no_newline(regex, str) do_match(regex, str, FALSE)
53 /* quote any non-alphanumeric characters in str, so that the result will only
54 * match the original string. If anchor is true, then add ^ and $ to make sure
55 * that substrings will not match. */
56 char * clean_regex(const char *str, gboolean anchor);
63 * A "glob expression" is similar to shell globs; it supports metacharacters
64 * "*" and "?", as well as character classes like "[...]" and "[!...]"
65 * (negated). The "*" and "?" do not match filename separators ("/"). The
66 * entire expression is anchored, so it must match the string, not just a single
70 /* Validate that GLOB is a legal GLOB expression. Returns a statically
71 * allocated error message on failure, or NULL on success. */
72 char * validate_glob(const char *glob);
74 /* Convert a GLOB expression into a dynamically allocated regular expression */
75 char * glob_to_regex(const char *glob);
77 /* Like match(), but with a glob expression */
78 int match_glob(const char *glob, const char *str);
84 /* A "tar expression" is almost the same as a glob, except that "*" can match a
85 * filename separator ("?" cannot). It is used by calcsize to emulate tar's exclude
86 * list patterns, which are actually significantly more complicated than this.
89 /* Like match(), but with a tar expression */
90 int match_tar(const char *glob, const char *str);
96 /* Host expressions are described in amanda(8). */
98 /* Make an Amanda host expression that will match the given string exactly.
99 * There is a little bit of fuzz here involving leading and trailing "."
100 * chararacters, (so "host.org", "host.org.", and ".host.org" will all match
101 * the same expressions) but DNS considers them equivalent, too. */
102 char * make_exact_host_expression(const char *host);
104 /* Like match(), but using a host expression */
105 int match_host(const char *glob, const char *host);
111 /* Disk expressions are described in amanda(8) */
113 /* Make an Amanda disk expression that will match the given string exactly. */
114 char * make_exact_disk_expression(const char *disk);
116 /* Like match(), but using a disk expression */
117 int match_disk(const char *glob, const char *disk);
120 * Datestamp expressions
123 /* Datestamp expressions are described in amanda(8) */
125 int match_datestamp(const char *dateexp, const char *datestamp);
131 /* Level expressions are either prefix matches e.g., "1", which matches "1", "10", and "123",
132 * absolute matches e.g., "3$" which only matches "3", or a range e.g., "3-5" which only
133 * matches levels 3, 4, and 5. */
135 /* Like match(), but using a level expression */
136 int match_level(const char *levelexp, const char *level);