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