]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/match_bsr.c
ad869bdffe1edb27f49e9aa9da9efcc1b2b18783
[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
34 /* Forward references */
35 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec);
36 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec);
37 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec);
38 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec);
39 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec);
40 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec);
41 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec);
42 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec);
43 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec);
44 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec);
45 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec);
46
47 /*********************************************************************
48  *
49  *      Match Bootstrap records
50  *
51  */
52 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
53 {
54    if (!bsr) {
55       return 0;
56    }
57    if (match_one_bsr(bsr, rec, volrec, sessrec)) {
58       return 1;
59    }
60    return match_bsr(bsr->next, rec, volrec, sessrec);
61 }
62
63 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
64 {
65    if (strcmp(bsr->VolumeName, volrec->VolName) != 0) {
66       return 0;
67    }
68    if (!match_volfile(bsr->volfile, rec)) {
69       return 0;
70    }
71    if (!match_sesstime(bsr->sesstime, rec)) {
72       return 0;
73    }
74    if (!match_sessid(bsr->sessid, rec)) {
75       return 0;
76    }
77    if (!match_jobid(bsr->JobId, sessrec)) {
78       return 0;
79    }
80    if (!match_job(bsr->job, sessrec)) {
81       return 0;
82    }
83    if (!match_client(bsr->client, sessrec)) {
84       return 0;
85    }
86    if (!match_findex(bsr->FileIndex, rec)) {
87       return 0;
88    }
89    if (!match_job_type(bsr->JobType, sessrec)) {
90       return 0;
91    }
92    if (!match_job_level(bsr->JobLevel, sessrec)) {
93       return 0;
94    }
95    if (!match_stream(bsr->stream, rec)) {
96       return 0;
97    }
98    return 1;
99 }
100
101 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec)
102 {
103    if (!client) {
104       return 1;                       /* no specification matches all */
105    }
106    if (strcmp(client->ClientName, sessrec->ClientName) == 0) {
107       return 1;
108    }
109    if (client->next) {
110       return match_client(client->next, sessrec);
111    }
112    return 0;
113 }
114
115 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec)
116 {
117    if (!job) {
118       return 1;                       /* no specification matches all */
119    }
120    if (strcmp(job->Job, sessrec->Job) == 0) {
121       job->found++;
122       return 1;
123    }
124    if (job->next) {
125       return match_job(job->next, sessrec);
126    }
127    return 0;
128 }
129
130
131 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec)
132 {
133    if (!job_type) {
134       return 1;                       /* no specification matches all */
135    }
136    if (job_type->JobType == sessrec->JobType) {
137       return 1;
138    }
139    if (job_type->next) {
140       return match_job_type(job_type->next, sessrec);
141    }
142    return 0;
143 }
144
145 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec)
146 {
147    if (!job_level) {
148       return 1;                       /* no specification matches all */
149    }
150    if (job_level->JobLevel == sessrec->JobLevel) {
151       return 1;
152    }
153    if (job_level->next) {
154       return match_job_level(job_level->next, sessrec);
155    }
156    return 0;
157 }
158
159 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec)
160 {
161    if (!jobid) {
162       return 1;                       /* no specification matches all */
163    }
164    if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
165       jobid->found++;
166       return 1;
167    }
168    if (jobid->next) {
169       return match_jobid(jobid->next, sessrec);
170    }
171    return 0;
172 }
173
174
175 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec)
176 {
177    if (!volfile) {
178       return 1;                       /* no specification matches all */
179    }
180    if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
181       volfile->found++;
182       return 1;
183    }
184    if (volfile->next) {
185       return match_volfile(volfile->next, rec);
186    }
187    return 0;
188 }
189
190 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec)
191 {
192    if (!stream) {
193       return 1;                       /* no specification matches all */
194    }
195    if (stream->stream == rec->Stream) {
196       return 1;
197    }
198    if (stream->next) {
199       return match_stream(stream->next, rec);
200    }
201    return 0;
202 }
203
204 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec)
205 {
206    if (!findex) {
207       return 1;                       /* no specification matches all */
208    }
209    if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
210       findex->found++;
211       return 1;
212    }
213    if (findex->next) {
214       return match_findex(findex->next, rec);
215    }
216    return 0;
217 }
218
219
220 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec)
221 {
222    if (!sessid) {
223       return 1;                       /* no specification matches all */
224    }
225    if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
226       sessid->found++;
227       return 1;
228    }
229    if (sessid->next) {
230       return match_sessid(sessid->next, rec);
231    }
232    return 0;
233 }
234
235 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec)
236 {
237    if (!sesstime) {
238       return 1;                       /* no specification matches all */
239    }
240    if (sesstime->sesstime == rec->VolSessionTime) {
241       sesstime->found++;
242       return 1;
243    }
244    if (sesstime->next) {
245       return match_sesstime(sesstime->next, rec);
246    }
247    return 0;
248 }