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