Imported Upstream version 2.5.2p1
[debian/amanda] / server-src / cmdline.h
1 /*
2  * Copyright (c) 2005 Zmanda Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  * 
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
12  * for more details.
13  * 
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
17  * 
18  * Contact information: Zmanda Inc, 505 N Mathlida Ave, Suite 120
19  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20  *
21  * Author: Dustin J. Mitchell <dustin@zmanda.com>
22  */
23 /*
24  * $Id$
25  *
26  * Utility routines for handling command lines.
27  */
28
29 #ifndef CMDLINE_H
30 #define CMDLINE_H
31
32 #include "sl.h"
33
34 /* TODO: use glib's linked lists instead; dumpspec_list_t provides basic
35  * type-checking to allow that to be implemented with a simple search and
36  * replace. */
37
38 /* A dumpspec can specify a particular dump (combining host, disk, and 
39  * datestamp), or can be less specific by leaving out some components.
40  * In some cases (such as selecting DLEs), the datestamp is not relevant.
41  * Functions for these cases leave the datestamp NULL.
42  */
43 typedef struct dumpspec_s {
44     char *host;
45     char *disk;
46     char *datestamp;
47
48     struct dumpspec_s * next;
49 } dumpspec_t;
50
51 /* temporary */
52 typedef dumpspec_t dumpspec_list_t;
53 #define dumpspec_list_first(dsl) ((dumpspec_t *)(dsl))
54
55 /*
56  * Dumpspec list management
57  */
58
59 /* Create a new dumpspec with the given components
60  *
61  * @param host: host name
62  * @param disk: disk name
63  * @param datestamp: datestamp
64  * @returns: dumpspec, or NULL on error
65  */
66 dumpspec_t *
67 dumpspec_new(
68     char *host, 
69     char *disk, 
70     char *datestamp);
71
72 /* Free memory associated with a single dumpspec.  (Does not chase 
73  * next pointers)
74  *
75  * @param dumpspec: the dumpspec to free
76  */
77 void
78 dumpspec_free(
79     dumpspec_t *dumpspec);
80
81 /* Free memory associated with a list of dumpspecs.
82  *
83  * @param dumpspec_list: the dumpspec list to free
84  */
85 void
86 dumpspec_free_list(
87     dumpspec_list_t *dumpspec_list);
88
89 /*
90  * Parsing
91  */
92
93 /* Parse a command line matching the following syntax, and return
94  * the results as a linked list.  
95  *
96  *  [ host [ disk [ datestamp [ host [ disk [ datestamp .. ] ] ] ] ] ]
97  *
98  * If no results are specified, a dumpspec with all entries set to ""
99  * is returned; the caller may treat this as a wildcard or an error, as
100  * appropriate.
101  *
102  * Prints a message to stderr and returns NULL if an error occurs.
103  *
104  * @param argc: count of command line arguments
105  * @param argv: command line arguments
106  * @returns: dumpspec list, or NULL on error
107  */
108 dumpspec_list_t *
109 cmdline_parse_dumpspecs(
110     int argc,
111     char **argv);
112
113 /* TODO: new name for match_disklist */
114 int
115 cmdline_parse_disk_list_entries(
116     int argc,
117     char **argv);
118
119 /*
120  * Formatting
121  */
122
123 /* Format a dumpspec into a string, with shell-compatible quoting.
124  *
125  * Caller is responsible for freeing the string.
126  *
127  * @param dumpspec: the dumpspec to format
128  * @returns: newly allocated string, or NULL on error
129  */
130 char *
131 cmdline_format_dumpspec(
132     dumpspec_t *dumpspec);
133
134 /* Like cmdline_format_dumpspec, but with components supplied 
135  * individually.  Caller is responsible for freeing the 
136  * string.
137  *
138  * @param host: host name
139  * @param disk: disk name
140  * @param datestamp: datestamp
141  * @returns: newly allocated string, or NULL on error
142  */
143 char *
144 cmdline_format_dumpspec_components(
145     char *host,
146     char *disk,
147     char *datestamp);
148
149 /*
150  * Searching
151  */
152
153 /* TODO: use glib here too */
154
155 /* Find all holding files matching the dumpspec list.  
156  *
157  * @param dumpspec_list: a list of dumpspecs
158  * @returns: a list of holding disk filenames.
159  */
160 sl_t *
161 cmdline_match_holding(
162     dumpspec_list_t *dumpspec_list);
163
164 #endif /* CMDLINE_H */
165