2 * Copyright (c) 2007,2008,2009 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
21 %module "Amanda::Cmdline"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24 %include "amglue/dumpspecs.swg"
26 %include "Amanda/Cmdline.pod"
32 #include "fileheader.h"
35 /* Add a few methods to make this type act like a class */
36 typedef struct dumpspec_t {
46 dumpspec_t(char *host, char *disk, char *datestamp, char *level) {
47 return dumpspec_new(host, disk, datestamp, level);
56 return cmdline_format_dumpspec(self);
61 %rename(format_dumpspec_components) cmdline_format_dumpspec_components;
62 char *cmdline_format_dumpspec_components(char *host, char *disk, char *datestamp, char *level);
64 /* Typemap to convert a perl list of strings to the strv that
65 * cmdline_parse_dumpspecs expects.
67 %typemap(in, numinputs=1) (int argc, char **argv) {
71 if (!SvROK($input) || SvTYPE(SvRV($input)) != SVt_PVAV) {
72 SWIG_exception(SWIG_TypeError, "Expected an arrayref");
74 av = (AV *)SvRV($input);
76 $1 = av_len(av)+1; /* av_len(av) is like $#av */
77 $2 = malloc(sizeof(char *) * $1);
78 for (i = 0; i < $1; i++) {
79 SV **elt = av_fetch(av, i, 0);
80 if (!elt || !SvPOK(*elt)) {
81 SWIG_exception(SWIG_TypeError, "Non-string in arrayref");
83 $2[i] = SvPV_nolen(*elt); /* TODO: handle unicode here */
87 /* Free the space allocated by the previous typemap */
88 %typemap(freearg) (int argc, char **argv) {
92 amglue_add_flag_tag_fns(cmdline_parse_dumpspecs_flags);
93 amglue_add_constant(CMDLINE_PARSE_DATESTAMP, cmdline_parse_dumpspecs_flags);
94 amglue_add_constant(CMDLINE_PARSE_LEVEL, cmdline_parse_dumpspecs_flags);
95 amglue_add_constant(CMDLINE_EMPTY_TO_WILDCARD, cmdline_parse_dumpspecs_flags);
97 %rename(parse_dumpspecs) cmdline_parse_dumpspecs;
98 amglue_dumpspec_list *cmdline_parse_dumpspecs(int argc, char **argv, int flags);
101 * convert AV back to GSList as input, convert resulting GSList into an AV of strings
104 /* amglue_dumpspec_list * cmdline_match_holding(amglue_dumpspec_list *dumpspec_list); */
107 gboolean header_matches_dumpspecs(dumpfile_t *dumpfile, amglue_dumpspec_list *dumpspecs) {
110 /* ignore anything that's not a (split) dumpfile */
111 if(dumpfile->type != F_DUMPFILE && dumpfile->type != F_SPLIT_DUMPFILE)
114 g_snprintf(level_str, sizeof(level_str), "%d", dumpfile->dumplevel);
117 dumpspec_t *ds = (dumpspec_t *)dumpspecs->data;
118 dumpspecs = g_slist_next(dumpspecs);
120 if (ds->host && *ds->host
121 && !match_host(ds->host, dumpfile->name))
124 if (ds->disk && *ds->disk
125 && !match_disk(ds->disk, dumpfile->disk))
128 if (ds->datestamp && *ds->datestamp
129 && !match_datestamp(ds->datestamp, dumpfile->datestamp))
132 if (ds->level && *ds->level
133 && !match_level(ds->level, level_str))
136 /* passed all the checks, so it's a match */
144 amglue_export_ok(header_matches_dumpspecs);