]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/match_bsr.c
000d6a3504034d2b4e815a6bffd18d664ebbb587
[bacula/bacula] / bacula / src / stored / match_bsr.c
1 /*     
2  *   Match Bootstrap Records (used for restores) against
3  *     Volume Records
4  *  
5  *     Kern Sibbald, June MMII
6  *
7  *   Version $Id$
8  */
9
10 /*
11    Copyright (C) 2002 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30
31 #include "bacula.h"
32 #include "stored.h"
33 #include <fnmatch.h>
34
35 /* Forward references */
36 static int match_volume(BSR_VOLUME *volume, VOLUME_LABEL *volrec);
37 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec);
38 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec);
39 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec);
40 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec);
41 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec);
42 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec);
43 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec);
44 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec);
45 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec);
46 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec);
47 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec);
48
49 /*********************************************************************
50  *
51  *      Match Bootstrap records
52  *
53  */
54 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
55 {
56    if (!bsr) {
57       return 0;
58    }
59    if (match_one_bsr(bsr, rec, volrec, sessrec)) {
60       return 1;
61    }
62    return match_bsr(bsr->next, rec, volrec, sessrec);
63 }
64
65 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
66 {
67    if (!match_volume(bsr->volume, volrec)) {
68       return 0;
69    }
70    if (!match_volfile(bsr->volfile, rec)) {
71       return 0;
72    }
73    if (!match_sesstime(bsr->sesstime, rec)) {
74       return 0;
75    }
76    if (!match_sessid(bsr->sessid, rec)) {
77       return 0;
78    }
79    if (!match_jobid(bsr->JobId, sessrec)) {
80       return 0;
81    }
82    if (!match_job(bsr->job, sessrec)) {
83       return 0;
84    }
85    if (!match_client(bsr->client, sessrec)) {
86       return 0;
87    }
88    if (!match_findex(bsr->FileIndex, rec)) {
89       return 0;
90    }
91    if (!match_job_type(bsr->JobType, sessrec)) {
92       return 0;
93    }
94    if (!match_job_level(bsr->JobLevel, sessrec)) {
95       return 0;
96    }
97    if (!match_stream(bsr->stream, rec)) {
98       return 0;
99    }
100    return 1;
101 }
102
103 static int match_volume(BSR_VOLUME *volume, VOLUME_LABEL *volrec) 
104 {
105    if (!volume) {
106       return 0;                       /* Volume must match */
107    }
108    if (strcmp(volume->VolumeName, volrec->VolName) == 0) {
109       return 1;
110    }
111    if (volume->next) {
112       return match_volume(volume->next, volrec);
113    }
114    return 0;
115 }
116
117 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec)
118 {
119    if (!client) {
120       return 1;                       /* no specification matches all */
121    }
122    if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) {
123       return 1;
124    }
125    if (client->next) {
126       return match_client(client->next, sessrec);
127    }
128    return 0;
129 }
130
131 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec)
132 {
133    if (!job) {
134       return 1;                       /* no specification matches all */
135    }
136    if (fnmatch(job->Job, sessrec->Job, 0) == 0) {
137       job->found++;
138       return 1;
139    }
140    if (job->next) {
141       return match_job(job->next, sessrec);
142    }
143    return 0;
144 }
145
146
147 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec)
148 {
149    if (!job_type) {
150       return 1;                       /* no specification matches all */
151    }
152    if (job_type->JobType == sessrec->JobType) {
153       return 1;
154    }
155    if (job_type->next) {
156       return match_job_type(job_type->next, sessrec);
157    }
158    return 0;
159 }
160
161 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec)
162 {
163    if (!job_level) {
164       return 1;                       /* no specification matches all */
165    }
166    if (job_level->JobLevel == sessrec->JobLevel) {
167       return 1;
168    }
169    if (job_level->next) {
170       return match_job_level(job_level->next, sessrec);
171    }
172    return 0;
173 }
174
175 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec)
176 {
177    if (!jobid) {
178       return 1;                       /* no specification matches all */
179    }
180    if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
181       jobid->found++;
182       return 1;
183    }
184    if (jobid->next) {
185       return match_jobid(jobid->next, sessrec);
186    }
187    return 0;
188 }
189
190
191 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec)
192 {
193    if (!volfile) {
194       return 1;                       /* no specification matches all */
195    }
196    if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
197       volfile->found++;
198       return 1;
199    }
200    if (volfile->next) {
201       return match_volfile(volfile->next, rec);
202    }
203    return 0;
204 }
205
206 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec)
207 {
208    if (!stream) {
209       return 1;                       /* no specification matches all */
210    }
211    if (stream->stream == rec->Stream) {
212       return 1;
213    }
214    if (stream->next) {
215       return match_stream(stream->next, rec);
216    }
217    return 0;
218 }
219
220 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec)
221 {
222    if (!findex) {
223       return 1;                       /* no specification matches all */
224    }
225    if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
226       findex->found++;
227       return 1;
228    }
229    if (findex->next) {
230       return match_findex(findex->next, rec);
231    }
232    return 0;
233 }
234
235
236 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec)
237 {
238    if (!sessid) {
239       return 1;                       /* no specification matches all */
240    }
241    if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
242       sessid->found++;
243       return 1;
244    }
245    if (sessid->next) {
246       return match_sessid(sessid->next, rec);
247    }
248    return 0;
249 }
250
251 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec)
252 {
253    if (!sesstime) {
254       return 1;                       /* no specification matches all */
255    }
256    if (sesstime->sesstime == rec->VolSessionTime) {
257       sesstime->found++;
258       return 1;
259    }
260    if (sesstime->next) {
261       return match_sesstime(sesstime->next, rec);
262    }
263    return 0;
264 }