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 94085, USA, or: http://www.zmanda.com
22 %module "Amanda::Cmdline"
23 %include "amglue/amglue.swg"
24 %include "exception.i"
25 %include "amglue/dumpspecs.swg"
27 %include "Amanda/Cmdline.pod"
33 #include "fileheader.h"
36 /* Add a few methods to make this type act like a class */
37 typedef struct dumpspec_t {
43 char *write_timestamp;
48 dumpspec_t(char *host, char *disk, char *datestamp, char *level, char *write_timestamp) {
49 return dumpspec_new(host, disk, datestamp, level, write_timestamp);
58 return cmdline_format_dumpspec(self);
63 %rename(format_dumpspec_components) cmdline_format_dumpspec_components;
64 char *cmdline_format_dumpspec_components(char *host, char *disk, char *datestamp, char *level);
66 /* Typemap to convert a perl list of strings to the strv that
67 * cmdline_parse_dumpspecs expects.
69 %typemap(in, numinputs=1) (int argc, char **argv) {
73 if (!SvROK($input) || SvTYPE(SvRV($input)) != SVt_PVAV) {
74 SWIG_exception(SWIG_TypeError, "Expected an arrayref");
76 av = (AV *)SvRV($input);
78 $1 = av_len(av)+1; /* av_len(av) is like $#av */
79 $2 = malloc(sizeof(char *) * $1);
80 for (i = 0; i < $1; i++) {
81 SV **elt = av_fetch(av, i, 0);
82 if (!elt || !SvPOK(*elt)) {
83 SWIG_exception(SWIG_TypeError, "Non-string in arrayref");
85 $2[i] = SvPV_nolen(*elt); /* TODO: handle unicode here */
89 /* Free the space allocated by the previous typemap */
90 %typemap(freearg) (int argc, char **argv) {
94 amglue_add_flag_tag_fns(cmdline_parse_dumpspecs_flags);
95 amglue_add_constant(CMDLINE_PARSE_DATESTAMP, cmdline_parse_dumpspecs_flags);
96 amglue_add_constant(CMDLINE_PARSE_LEVEL, cmdline_parse_dumpspecs_flags);
97 amglue_add_constant(CMDLINE_EMPTY_TO_WILDCARD, cmdline_parse_dumpspecs_flags);
98 amglue_add_constant(CMDLINE_EXACT_MATCH, cmdline_parse_dumpspecs_flags);
99 amglue_copy_to_tag(cmdline_parse_dumpspecs_flags, constants);
101 %rename(parse_dumpspecs) cmdline_parse_dumpspecs;
102 amglue_dumpspec_list *cmdline_parse_dumpspecs(int argc, char **argv, int flags);
105 * convert AV back to GSList as input, convert resulting GSList into an AV of strings
108 /* amglue_dumpspec_list * cmdline_match_holding(amglue_dumpspec_list *dumpspec_list); */
111 gboolean header_matches_dumpspecs(dumpfile_t *dumpfile, amglue_dumpspec_list *dumpspecs) {
114 /* ignore anything that's not a (split) dumpfile */
115 if(dumpfile->type != F_DUMPFILE && dumpfile->type != F_SPLIT_DUMPFILE)
118 g_snprintf(level_str, sizeof(level_str), "%d", dumpfile->dumplevel);
121 dumpspec_t *ds = (dumpspec_t *)dumpspecs->data;
122 dumpspecs = g_slist_next(dumpspecs);
124 if (ds->host && *ds->host
125 && !match_host(ds->host, dumpfile->name))
128 if (ds->disk && *ds->disk
129 && !match_disk(ds->disk, dumpfile->disk))
132 if (ds->datestamp && *ds->datestamp
133 && !match_datestamp(ds->datestamp, dumpfile->datestamp))
136 if (ds->level && *ds->level
137 && !match_level(ds->level, level_str))
140 /* passed all the checks, so it's a match */
148 amglue_export_ok(header_matches_dumpspecs parse_dumpspecs format_dumpspec_components);