2 * Copyright (c) 2007, 2008, 2009, 2010 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 {
42 char *write_timestamp;
47 dumpspec_t(char *host, char *disk, char *datestamp, char *level, char *write_timestamp) {
48 return dumpspec_new(host, disk, datestamp, level, write_timestamp);
57 return cmdline_format_dumpspec(self);
62 %rename(format_dumpspec_components) cmdline_format_dumpspec_components;
63 char *cmdline_format_dumpspec_components(char *host, char *disk, char *datestamp, char *level);
65 /* Typemap to convert a perl list of strings to the strv that
66 * cmdline_parse_dumpspecs expects.
68 %typemap(in, numinputs=1) (int argc, char **argv) {
72 if (!SvROK($input) || SvTYPE(SvRV($input)) != SVt_PVAV) {
73 SWIG_exception(SWIG_TypeError, "Expected an arrayref");
75 av = (AV *)SvRV($input);
77 $1 = av_len(av)+1; /* av_len(av) is like $#av */
78 $2 = malloc(sizeof(char *) * $1);
79 for (i = 0; i < $1; i++) {
80 SV **elt = av_fetch(av, i, 0);
81 if (!elt || !SvPOK(*elt)) {
82 SWIG_exception(SWIG_TypeError, "Non-string in arrayref");
84 $2[i] = SvPV_nolen(*elt); /* TODO: handle unicode here */
88 /* Free the space allocated by the previous typemap */
89 %typemap(freearg) (int argc, char **argv) {
93 amglue_add_flag_tag_fns(cmdline_parse_dumpspecs_flags);
94 amglue_add_constant(CMDLINE_PARSE_DATESTAMP, cmdline_parse_dumpspecs_flags);
95 amglue_add_constant(CMDLINE_PARSE_LEVEL, cmdline_parse_dumpspecs_flags);
96 amglue_add_constant(CMDLINE_EMPTY_TO_WILDCARD, cmdline_parse_dumpspecs_flags);
97 amglue_copy_to_tag(cmdline_parse_dumpspecs_flags, constants);
99 %rename(parse_dumpspecs) cmdline_parse_dumpspecs;
100 amglue_dumpspec_list *cmdline_parse_dumpspecs(int argc, char **argv, int flags);
103 * convert AV back to GSList as input, convert resulting GSList into an AV of strings
106 /* amglue_dumpspec_list * cmdline_match_holding(amglue_dumpspec_list *dumpspec_list); */
109 gboolean header_matches_dumpspecs(dumpfile_t *dumpfile, amglue_dumpspec_list *dumpspecs) {
112 /* ignore anything that's not a (split) dumpfile */
113 if(dumpfile->type != F_DUMPFILE && dumpfile->type != F_SPLIT_DUMPFILE)
116 g_snprintf(level_str, sizeof(level_str), "%d", dumpfile->dumplevel);
119 dumpspec_t *ds = (dumpspec_t *)dumpspecs->data;
120 dumpspecs = g_slist_next(dumpspecs);
122 if (ds->host && *ds->host
123 && !match_host(ds->host, dumpfile->name))
126 if (ds->disk && *ds->disk
127 && !match_disk(ds->disk, dumpfile->disk))
130 if (ds->datestamp && *ds->datestamp
131 && !match_datestamp(ds->datestamp, dumpfile->datestamp))
134 if (ds->level && *ds->level
135 && !match_level(ds->level, level_str))
138 /* passed all the checks, so it's a match */
146 amglue_export_ok(header_matches_dumpspecs parse_dumpspecs format_dumpspec_components);