2 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 * Author: Dustin J. Mitchell <dustin@zmanda.com>
26 * Utility routines for handling command lines.
33 #include "glib-util.h"
35 /* A dumpspec can specify a particular dump (combining host, disk, and
36 * datestamp), or can be less specific by leaving out some components.
37 * Missing components are NULL, except in the special case of an
38 * "wildcard" dumpspec, as detailed below.
40 * All strings in this struct are independently malloc()ed.
42 typedef struct dumpspec_t {
47 char *write_timestamp;
51 * Dumpspec list management
54 /* Create a new dumpspec with the given components
56 * @param host: host name
57 * @param disk: disk name
58 * @param datestamp: datestamp
59 * @param level: level (as a string, allowing regexes)
60 * @param write_timestamp: timestamp written to tape.
61 * @returns: dumpspec, or NULL on error
69 char *write_timestamp);
71 /* Free memory associated with a single dumpspec. (Does not chase
74 * @param dumpspec: the dumpspec to free
78 dumpspec_t *dumpspec);
80 /* Free memory associated with a list of dumpspecs. CAUTION: do not
81 * use glib's g_slist_free directly on a dumpspec list, as it will not
82 * free the elements themselves.
84 * @param dumpspec_list: the GSList of dumpspecs to free
88 GSList *dumpspec_list);
94 /* Parse a command line matching the following syntax, and return
95 * the results as a linked list.
97 * [ host [ disk [ datestamp [ host [ disk [ datestamp .. ] ] ] ] ] ]
99 * If no results are specified, the function either returns NULL (an
100 * empty list) or, if CMDLINE_EMPTY_TO_WILDCARD is given, a list
101 * containing a single dumpspec with all fields set to "".
103 * Calls error() with any fatal errors, e.g., invalid regexes.
105 * @param argc: count of command line arguments
106 * @param argv: command line arguments
107 * @param flags: bitmask of the CMDLINE_* flags
108 * @returns: dumpspec list
111 cmdline_parse_dumpspecs(
115 /* flags values (bitmask): */
116 /* parse datestamps after disks */
117 # define CMDLINE_PARSE_DATESTAMP (1<<0)
118 /* parse levels after datestamps or disks */
119 # define CMDLINE_PARSE_LEVEL (1<<1)
120 /* an empty argv should result in a wildcard dumpspec */
121 # define CMDLINE_EMPTY_TO_WILDCARD (1<<2)
122 /* use exact match instead of host and disk expression */
123 # define CMDLINE_EXACT_MATCH (1<<3)
129 /* Format a dumpspec into a string, with shell-compatible quoting.
131 * Caller is responsible for freeing the string.
133 * @param dumpspec: the dumpspec to format
134 * @returns: newly allocated string, or NULL on error
137 cmdline_format_dumpspec(
138 dumpspec_t *dumpspec);
140 /* Like cmdline_format_dumpspec, but with components supplied
141 * individually. Caller is responsible for freeing the
144 * @param host: host name
145 * @param disk: disk name
146 * @param datestamp: datestamp
147 * @returns: newly allocated string, or NULL on error
150 cmdline_format_dumpspec_components(
160 /* Find all holding files matching the dumpspec list. If
161 * the dumpspec list contains a dumpspec with all blank
162 * entries, all holding files are returned.
164 * Free the resulting list with slist_free_full()
166 * @param dumpspec_list: a list of dumpspecs
167 * @returns: a list of holding disk filenames.
170 cmdline_match_holding(
171 GSList *dumpspec_list);
173 #endif /* CMDLINE_H */