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
32 typedef BSR * (ITEM_HANDLER)(LEX *lc, BSR *bsr);
34 static BSR *store_vol(LEX *lc, BSR *bsr);
35 static BSR *store_client(LEX *lc, BSR *bsr);
36 static BSR *store_job(LEX *lc, BSR *bsr);
37 static BSR *store_jobid(LEX *lc, BSR *bsr);
38 static BSR *store_jobtype(LEX *lc, BSR *bsr);
39 static BSR *store_joblevel(LEX *lc, BSR *bsr);
40 static BSR *store_findex(LEX *lc, BSR *bsr);
41 static BSR *store_sessid(LEX *lc, BSR *bsr);
42 static BSR *store_volfile(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);
46 static BSR *store_stream(LEX *lc, BSR *bsr);
47 static BSR *store_slot(LEX *lc, BSR *bsr);
51 ITEM_HANDLER *handler;
54 struct kw_items items[] = {
55 {"volume", store_vol},
56 {"client", store_client},
58 {"jobid", store_jobid},
59 {"fileindex", store_findex},
60 {"jobtype", store_jobtype},
61 {"joblevel", store_joblevel},
62 {"volsessionid", store_sessid},
63 {"volsessiontime", store_sesstime},
64 {"include", store_include},
65 {"exclude", store_exclude},
66 {"volfile", store_volfile},
67 {"stream", store_stream},
75 BSR *bsr = (BSR *)malloc(sizeof(BSR));
76 memset(bsr, 0, sizeof(BSR));
81 * Format a scanner error message
83 static void s_err(char *file, int line, LEX *lc, char *msg, ...)
88 va_start(arg_ptr, msg);
89 bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
92 e_msg(file, line, M_FATAL, 0, "Config error: %s\n\
93 : Line %d, col %d of file %s\n%s\n",
94 buf, lc->line_no, lc->col_no, lc->fname, lc->line);
98 /*********************************************************************
100 * Parse Bootstrap file
103 BSR *parse_bsr(char *cf)
107 BSR *root_bsr = new_bsr();
110 Dmsg0(200, "Enter parse_bsf()\n");
111 lc = lex_open_file(lc, cf, s_err);
112 while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
113 Dmsg1(150, "parse got token=%s\n", lex_tok_to_str(token));
114 if (token == T_EOL) {
117 for (i=0; items[i].name; i++) {
118 if (strcasecmp(items[i].name, lc->str) == 0) {
119 token = lex_get_token(lc, T_ALL);
120 Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
121 if (token != T_EQUALS) {
122 scan_err1(lc, "expected an equals, got: %s", lc->str);
126 Dmsg1(100, "calling handler for %s\n", items[i].name);
127 /* Call item handler */
128 bsr = items[i].handler(lc, bsr);
134 Dmsg1(150, "Keyword = %s\n", lc->str);
135 scan_err1(lc, "Keyword %s not found", lc->str);
142 lc = lex_close_file(lc);
143 Dmsg0(200, "Leave parse_bsf()\n");
151 static BSR *store_vol(LEX *lc, BSR *bsr)
155 token = lex_get_token(lc, T_NAME);
156 if (token == T_ERROR) {
159 if (bsr->VolumeName) {
160 bsr->next = new_bsr();
163 bsr->VolumeName = bstrdup(lc->str);
168 static BSR *store_client(LEX *lc, BSR *bsr)
174 token = lex_get_token(lc, T_NAME);
175 if (token == T_ERROR) {
178 client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT));
179 memset(client, 0, sizeof(BSR_CLIENT));
180 strcpy(client->ClientName, lc->str);
181 /* Add it to the end of the client chain */
183 bsr->client = client;
185 BSR_CLIENT *bc = bsr->client;
186 for ( ;bc->next; bc=bc->next)
190 token = lex_get_token(lc, T_ALL);
191 if (token != T_COMMA) {
198 static BSR *store_job(LEX *lc, BSR *bsr)
204 token = lex_get_token(lc, T_NAME);
205 if (token == T_ERROR) {
208 job = (BSR_JOB *)malloc(sizeof(BSR_JOB));
209 memset(job, 0, sizeof(BSR_JOB));
210 strcpy(job->Job, lc->str);
211 /* Add it to the end of the client chain */
215 /* Add to end of chain */
216 BSR_JOB *bc = bsr->job;
217 for ( ;bc->next; bc=bc->next)
221 token = lex_get_token(lc, T_ALL);
222 if (token != T_COMMA) {
229 static BSR *store_findex(LEX *lc, BSR *bsr)
235 token = lex_get_token(lc, T_PINT32_RANGE);
236 if (token == T_ERROR) {
239 findex = (BSR_FINDEX *)malloc(sizeof(BSR_FINDEX));
240 memset(findex, 0, sizeof(BSR_FINDEX));
241 findex->findex = lc->pint32_val;
242 findex->findex2 = lc->pint32_val2;
243 /* Add it to the end of the chain */
244 if (!bsr->FileIndex) {
245 bsr->FileIndex = findex;
247 /* Add to end of chain */
248 BSR_FINDEX *bs = bsr->FileIndex;
249 for ( ;bs->next; bs=bs->next)
253 token = lex_get_token(lc, T_ALL);
254 if (token != T_COMMA) {
262 static BSR *store_jobid(LEX *lc, BSR *bsr)
268 token = lex_get_token(lc, T_PINT32_RANGE);
269 if (token == T_ERROR) {
272 jobid = (BSR_JOBID *)malloc(sizeof(BSR_JOBID));
273 memset(jobid, 0, sizeof(BSR_JOBID));
274 jobid->JobId = lc->pint32_val;
275 jobid->JobId2 = lc->pint32_val2;
276 /* Add it to the end of the chain */
280 /* Add to end of chain */
281 BSR_JOBID *bs = bsr->JobId;
282 for ( ;bs->next; bs=bs->next)
286 token = lex_get_token(lc, T_ALL);
287 if (token != T_COMMA) {
294 static BSR *store_jobtype(LEX *lc, BSR *bsr)
296 /* *****FIXME****** */
297 Dmsg0(-1, "JobType not yet implemented\n");
302 static BSR *store_joblevel(LEX *lc, BSR *bsr)
304 /* *****FIXME****** */
305 Dmsg0(-1, "JobLevel not yet implemented\n");
313 * Routine to handle Volume start/end file
315 static BSR *store_volfile(LEX *lc, BSR *bsr)
318 BSR_VOLFILE *volfile;
321 token = lex_get_token(lc, T_PINT32_RANGE);
322 if (token == T_ERROR) {
325 volfile = (BSR_VOLFILE *)malloc(sizeof(BSR_VOLFILE));
326 memset(volfile, 0, sizeof(BSR_VOLFILE));
327 volfile->sfile = lc->pint32_val;
328 volfile->efile = lc->pint32_val2;
329 /* Add it to the end of the chain */
331 bsr->volfile = volfile;
333 /* Add to end of chain */
334 BSR_VOLFILE *bs = bsr->volfile;
335 for ( ;bs->next; bs=bs->next)
339 token = lex_get_token(lc, T_ALL);
340 if (token != T_COMMA) {
349 static BSR *store_sessid(LEX *lc, BSR *bsr)
355 token = lex_get_token(lc, T_PINT32_RANGE);
356 if (token == T_ERROR) {
359 sid = (BSR_SESSID *)malloc(sizeof(BSR_SESSID));
360 memset(sid, 0, sizeof(BSR_SESSID));
361 sid->sessid = lc->pint32_val;
362 sid->sessid2 = lc->pint32_val2;
363 /* Add it to the end of the chain */
367 /* Add to end of chain */
368 BSR_SESSID *bs = bsr->sessid;
369 for ( ;bs->next; bs=bs->next)
373 token = lex_get_token(lc, T_ALL);
374 if (token != T_COMMA) {
381 static BSR *store_sesstime(LEX *lc, BSR *bsr)
387 token = lex_get_token(lc, T_PINT32);
388 if (token == T_ERROR) {
391 stime = (BSR_SESSTIME *)malloc(sizeof(BSR_SESSTIME));
392 memset(stime, 0, sizeof(BSR_SESSTIME));
393 stime->sesstime = lc->pint32_val;
394 /* Add it to the end of the chain */
395 if (!bsr->sesstime) {
396 bsr->sesstime = stime;
398 /* Add to end of chain */
399 BSR_SESSTIME *bs = bsr->sesstime;
400 for ( ;bs->next; bs=bs->next)
404 token = lex_get_token(lc, T_ALL);
405 if (token != T_COMMA) {
413 static BSR *store_stream(LEX *lc, BSR *bsr)
419 token = lex_get_token(lc, T_INT32);
420 if (token == T_ERROR) {
423 stream = (BSR_STREAM *)malloc(sizeof(BSR_STREAM));
424 memset(stream, 0, sizeof(BSR_STREAM));
425 stream->stream = lc->int32_val;
426 /* Add it to the end of the chain */
428 bsr->stream = stream;
430 /* Add to end of chain */
431 BSR_STREAM *bs = bsr->stream;
432 for ( ;bs->next; bs=bs->next)
436 token = lex_get_token(lc, T_ALL);
437 if (token != T_COMMA) {
444 static BSR *store_slot(LEX *lc, BSR *bsr)
448 token = lex_get_token(lc, T_PINT32);
449 if (token == T_ERROR) {
452 bsr->Slot = lc->pint32_val;
457 static BSR *store_include(LEX *lc, BSR *bsr)
463 static BSR *store_exclude(LEX *lc, BSR *bsr)
469 void dump_volfile(BSR_VOLFILE *volfile)
472 Dmsg2(-1, "VolFile : %u-%u\n", volfile->sfile, volfile->efile);
473 dump_volfile(volfile->next);
477 void dump_findex(BSR_FINDEX *FileIndex)
480 if (FileIndex->findex == FileIndex->findex2) {
481 Dmsg1(-1, "FileIndex : %u\n", FileIndex->findex);
483 Dmsg2(-1, "FileIndex : %u-%u\n", FileIndex->findex, FileIndex->findex2);
485 dump_findex(FileIndex->next);
489 void dump_jobid(BSR_JOBID *jobid)
492 if (jobid->JobId == jobid->JobId2) {
493 Dmsg1(-1, "JobId : %u\n", jobid->JobId);
495 Dmsg2(-1, "JobId : %u-%u\n", jobid->JobId, jobid->JobId2);
497 dump_jobid(jobid->next);
501 void dump_sessid(BSR_SESSID *sessid)
504 if (sessid->sessid == sessid->sessid2) {
505 Dmsg1(-1, "SessId : %u\n", sessid->sessid);
507 Dmsg2(-1, "SessId : %u-%u\n", sessid->sessid, sessid->sessid2);
509 dump_sessid(sessid->next);
514 void dump_client(BSR_CLIENT *client)
517 Dmsg1(-1, "Client : %s\n", client->ClientName);
518 dump_client(client->next);
522 void dump_job(BSR_JOB *job)
525 Dmsg1(-1, "Job : %s\n", job->Job);
530 void dump_sesstime(BSR_SESSTIME *sesstime)
533 Dmsg1(-1, "SessTime : %u\n", sesstime->sesstime);
534 dump_sesstime(sesstime->next);
542 void dump_bsr(BSR *bsr)
545 Dmsg0(-1, "BSR is NULL\n");
552 bsr->VolumeName ? bsr->VolumeName : "*None*");
553 dump_sessid(bsr->sessid);
554 dump_sesstime(bsr->sesstime);
555 dump_volfile(bsr->volfile);
556 dump_client(bsr->client);
557 dump_jobid(bsr->JobId);
559 dump_findex(bsr->FileIndex);
568 /*********************************************************************
573 static void free_bsr_item(BSR *bsr)
576 free_bsr_item(bsr->next);
581 void free_bsr(BSR *bsr)
586 free_bsr_item((BSR *)bsr->client);
587 free_bsr_item((BSR *)bsr->sessid);
588 free_bsr_item((BSR *)bsr->sesstime);
589 free_bsr_item((BSR *)bsr->volfile);
590 free_bsr_item((BSR *)bsr->JobId);
591 free_bsr_item((BSR *)bsr->job);
592 free_bsr_item((BSR *)bsr->FileIndex);
593 free_bsr_item((BSR *)bsr->JobType);
594 free_bsr_item((BSR *)bsr->JobLevel);
595 if (bsr->VolumeName) {
596 free(bsr->VolumeName);
602 /*****************************************************************
603 * Routines for handling volumes
608 vol = (VOL_LIST *)malloc(sizeof(VOL_LIST));
609 memset(vol, 0, sizeof(VOL_LIST));
614 * Add current volume to end of list, only if the Volume
615 * is not already in the list.
617 * returns: 1 if volume added
618 * 0 if volume already in list
620 int add_vol(JCR *jcr, VOL_LIST *vol)
622 VOL_LIST *next = jcr->VolList;
624 if (!next) { /* list empty ? */
625 jcr->VolList = vol; /* yes, add volume */
627 for ( ; next->next; next=next->next) {
628 if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
629 return 0; /* already in list */
632 if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
633 return 0; /* already in list */
635 next->next = vol; /* add volume */
640 void free_vol_list(JCR *jcr)
642 VOL_LIST *next = jcr->VolList;
652 void create_vol_list(JCR *jcr)
658 * Build a list of volume to be processed
664 strcpy(jcr->VolumeName, bsr->VolumeName); /* setup first volume */
665 for ( ; bsr; bsr=bsr->next) {
667 strcpy(vol->VolumeName, bsr->VolumeName);
668 if (add_vol(jcr, vol)) {
670 Dmsg1(400, "Added volume %s\n", vol->VolumeName);
672 Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
677 /* This is the old way -- deprecated */
678 for (p = jcr->VolumeName; p && *p; ) {
679 n = strchr(p, '|'); /* volume name separator */
681 *n++ = 0; /* Terminate name */
684 strcpy(vol->VolumeName, p);
685 if (add_vol(jcr, vol)) {