2 * Parse a Bootstrap Records (used for restores)
4 * Kern Sibbald, June MMII
10 Copyright (C) 2002 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 typedef BSR * (ITEM_HANDLER)(LEX *lc, BSR *bsr);
35 static BSR *store_vol(LEX *lc, BSR *bsr);
36 static BSR *store_client(LEX *lc, BSR *bsr);
37 static BSR *store_job(LEX *lc, BSR *bsr);
38 static BSR *store_jobid(LEX *lc, BSR *bsr);
39 static BSR *store_jobtype(LEX *lc, BSR *bsr);
40 static BSR *store_joblevel(LEX *lc, BSR *bsr);
41 static BSR *store_file_index(LEX *lc, BSR *bsr);
42 static BSR *store_sessid(LEX *lc, BSR *bsr);
43 static BSR *store_sesstime(LEX *lc, BSR *bsr);
44 static BSR *store_include(LEX *lc, BSR *bsr);
45 static BSR *store_exclude(LEX *lc, BSR *bsr);
49 ITEM_HANDLER *handler;
52 struct kw_items items[] = {
53 {"volume", store_vol},
54 {"client", store_client},
56 {"jobid", store_jobid},
57 {"fileindex", store_file_index},
58 {"jobtype", store_jobtype},
59 {"joblevel", store_joblevel},
60 {"volsessionid", store_sessid},
61 {"volsessiontime", store_sesstime},
62 {"include", store_include},
63 {"exclude", store_exclude},
70 BSR *bsr = (BSR *)malloc(sizeof(BSR));
71 memset(bsr, 0, sizeof(BSR));
75 /*********************************************************************
77 * Parse Bootstrap file
80 BSR *parse_bsr(char *cf)
84 BSR *root_bsr = new_bsr();
87 Dmsg0(200, "Enter parse_bsf()\n");
88 lc = lex_open_file(lc, cf);
89 while ((token=lex_get_token(lc)) != T_EOF) {
90 Dmsg1(150, "parse got token=%s\n", lex_tok_to_str(token));
94 if (token != T_IDENTIFIER) {
95 scan_err1(lc, "Expected a keyword identifier, got: %s", lc->str);
97 for (i=0; items[i].name; i++) {
98 if (strcasecmp(items[i].name, lc->str) == 0) {
99 token = lex_get_token(lc);
100 Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
101 if (token != T_EQUALS) {
102 scan_err1(lc, "expected an equals, got: %s", lc->str);
104 Dmsg1(150, "calling handler for %s\n", items[i].name);
105 /* Call item handler */
106 bsr = items[i].handler(lc, bsr);
112 Dmsg1(150, "Keyword = %s\n", lc->str);
113 scan_err1(lc, "Keyword %s not found", lc->str);
117 lc = lex_close_file(lc);
118 Dmsg0(200, "Leave parse_bsf()\n");
122 static BSR *store_vol(LEX *lc, BSR *bsr)
126 token = lex_get_token(lc);
127 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
128 scan_err1(lc, "expected an identifier or string, got: %s", lc->str);
129 } else if (lc->str_len > MAX_RES_NAME_LENGTH) {
130 scan_err3(lc, "name %s length %d too long, max is %d\n", lc->str,
131 lc->str_len, MAX_RES_NAME_LENGTH);
133 if (bsr->VolumeName) {
134 bsr->next = new_bsr();
137 bsr->VolumeName = bstrdup(lc->str);
143 static BSR *store_client(LEX *lc, BSR *bsr)
148 token = lex_get_token(lc);
149 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
150 scan_err1(lc, "expected an identifier or string, got: %s", lc->str);
151 } else if (lc->str_len > MAX_RES_NAME_LENGTH) {
152 scan_err3(lc, "name %s length %d too long, max is %d\n", lc->str,
153 lc->str_len, MAX_RES_NAME_LENGTH);
155 client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT));
156 memset(client, 0, sizeof(BSR_CLIENT));
157 client->ClientName = bstrdup(lc->str);
158 /* Add it to the end of the client chain */
160 bsr->client = client;
162 BSR_CLIENT *bc = bsr->client;
177 static BSR *store_job(LEX *lc, BSR *bsr)
182 token = lex_get_token(lc);
183 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
184 scan_err1(lc, "expected an identifier or string, got: %s", lc->str);
185 } else if (lc->str_len > MAX_RES_NAME_LENGTH) {
186 scan_err3(lc, "name %s length %d too long, max is %d\n", lc->str,
187 lc->str_len, MAX_RES_NAME_LENGTH);
189 job = (BSR_JOB *)malloc(sizeof(BSR_JOB));
190 memset(job, 0, sizeof(BSR_JOB));
191 job->Job = bstrdup(lc->str);
192 /* Add it to the end of the client chain */
196 /* Add to end of chain */
197 BSR_JOB *bc = bsr->job;
198 for ( ;bc->next; bc=bc->next)
207 static BSR *store_file_index(LEX *lc, BSR *bsr)
214 token = lex_get_token(lc);
215 if (token != T_NUMBER || !is_a_number(lc->str)) {
216 scan_err1(lc, "expected a positive integer number, got: %s", lc->str);
219 FileIndex = strtoul(lc->str, NULL, 10);
221 scan_err1(lc, "expected a integer number, got: %s", lc->str);
223 findex = (BSR_FINDEX *)malloc(sizeof(BSR_FINDEX));
224 memset(findex, 0, sizeof(BSR_FINDEX));
225 findex->FileIndex = FileIndex;
226 /* Add it to the end of the chain */
227 if (!bsr->FileIndex) {
228 bsr->FileIndex = findex;
230 /* Add to end of chain */
231 BSR_FINDEX *bs = bsr->FileIndex;
232 for ( ;bs->next; bs=bs->next)
242 static BSR *store_jobid(LEX *lc, BSR *bsr)
249 token = lex_get_token(lc);
250 if (token != T_NUMBER || !is_a_number(lc->str)) {
251 scan_err1(lc, "expected a positive integer number, got: %s", lc->str);
254 JobId = strtoul(lc->str, NULL, 10);
256 scan_err1(lc, "expected a integer number, got: %s", lc->str);
258 jobid = (BSR_JOBID *)malloc(sizeof(BSR_JOBID));
259 memset(jobid, 0, sizeof(BSR_JOBID));
260 jobid->JobId = JobId;
261 /* Add it to the end of the chain */
265 /* Add to end of chain */
266 BSR_JOBID *bs = bsr->JobId;
267 for ( ;bs->next; bs=bs->next)
276 static BSR *store_jobtype(LEX *lc, BSR *bsr)
278 /* *****FIXME****** */
279 Dmsg0(-1, "JobType not yet implemented\n");
284 static BSR *store_joblevel(LEX *lc, BSR *bsr)
286 /* *****FIXME****** */
287 Dmsg0(-1, "JobLevel not yet implemented\n");
293 static BSR *store_sessid(LEX *lc, BSR *bsr)
300 token = lex_get_token(lc);
301 if (token != T_NUMBER || !is_a_number(lc->str)) {
302 scan_err1(lc, "expected a positive integer number, got: %s", lc->str);
305 sessid1 = strtoul(lc->str, NULL, 10);
307 scan_err1(lc, "expected a integer number, got: %s", lc->str);
309 sid = (BSR_SESSID *)malloc(sizeof(BSR_SESSID));
310 memset(sid, 0, sizeof(BSR_SESSID));
311 sid->sessid1 = sessid1;
312 /* Add it to the end of the chain */
316 /* Add to end of chain */
317 BSR_SESSID *bs = bsr->sessid;
318 for ( ;bs->next; bs=bs->next)
327 static BSR *store_sesstime(LEX *lc, BSR *bsr)
334 token = lex_get_token(lc);
335 if (token != T_NUMBER || !is_a_number(lc->str)) {
336 scan_err1(lc, "expected a positive integer number, got: %s", lc->str);
339 sesstime = strtoul(lc->str, NULL, 10);
341 scan_err1(lc, "expected a integer number, got: %s", lc->str);
343 stime = (BSR_SESSTIME *)malloc(sizeof(BSR_SESSTIME));
344 memset(stime, 0, sizeof(BSR_SESSTIME));
345 stime->sesstime = sesstime;
346 /* Add it to the end of the chain */
347 if (!bsr->sesstime) {
348 bsr->sesstime = stime;
350 /* Add to end of chain */
351 BSR_SESSTIME *bs = bsr->sesstime;
352 for ( ;bs->next; bs=bs->next)
361 static BSR *store_include(LEX *lc, BSR *bsr)
367 static BSR *store_exclude(LEX *lc, BSR *bsr)
373 void dump_bsr(BSR *bsr)
376 Dmsg0(-1, "BSR is NULL\n");
389 bsr->VolumeName ? bsr->VolumeName : "*None*",
390 bsr->client ? bsr->client->ClientName : "*None*",
391 bsr->job ? bsr->job->Job : "*None*",
392 bsr->JobId ? bsr->JobId->JobId : 0,
393 bsr->sessid ? bsr->sessid->sessid1 : 0,
394 bsr->sesstime ? bsr->sesstime->sesstime : 0,
395 bsr->FileIndex ? bsr->FileIndex->FileIndex : 0);
403 /*********************************************************************
408 static void free_bsr_item(BSR *bsr)
413 free_bsr_item(bsr->next);
417 void free_bsr(BSR *bsr)
422 free_bsr_item((BSR *)bsr->client);
423 free_bsr_item((BSR *)bsr->sessid);
424 free_bsr_item((BSR *)bsr->sesstime);
425 if (bsr->VolumeName) {
426 free(bsr->VolumeName);