3 * Configuration parser for Director Run Configuration
4 * directives, which are part of the Schedule Resource
11 Copyright (C) 2000-2004 Kern Sibbald and John Walker
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.
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.
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,
34 extern struct s_jl joblevels[];
36 /* Forward referenced subroutines */
50 s_wom, /* 1st, 2nd, ...*/
51 s_woy /* week of year w00 - w53 */
55 const char *name; /* keyword */
56 enum e_state state; /* parser state */
57 int code; /* state value */
60 /* Keywords understood by parser */
61 static struct s_keyw keyw[] = {
62 {N_("on"), s_none, 0},
65 {N_("sun"), s_wday, 0},
66 {N_("mon"), s_wday, 1},
67 {N_("tue"), s_wday, 2},
68 {N_("wed"), s_wday, 3},
69 {N_("thu"), s_wday, 4},
70 {N_("fri"), s_wday, 5},
71 {N_("sat"), s_wday, 6},
72 {N_("jan"), s_month, 0},
73 {N_("feb"), s_month, 1},
74 {N_("mar"), s_month, 2},
75 {N_("apr"), s_month, 3},
76 {N_("may"), s_month, 4},
77 {N_("jun"), s_month, 5},
78 {N_("jul"), s_month, 6},
79 {N_("aug"), s_month, 7},
80 {N_("sep"), s_month, 8},
81 {N_("oct"), s_month, 9},
82 {N_("nov"), s_month, 10},
83 {N_("dec"), s_month, 11},
85 {N_("sunday"), s_wday, 0},
86 {N_("monday"), s_wday, 1},
87 {N_("tuesday"), s_wday, 2},
88 {N_("wednesday"), s_wday, 3},
89 {N_("thursday"), s_wday, 4},
90 {N_("friday"), s_wday, 5},
91 {N_("saturday"), s_wday, 6},
92 {N_("january"), s_month, 0},
93 {N_("february"), s_month, 1},
94 {N_("march"), s_month, 2},
95 {N_("april"), s_month, 3},
96 {N_("june"), s_month, 5},
97 {N_("july"), s_month, 6},
98 {N_("august"), s_month, 7},
99 {N_("september"), s_month, 8},
100 {N_("october"), s_month, 9},
101 {N_("november"), s_month, 10},
102 {N_("december"), s_month, 11},
104 {N_("daily"), s_daily, 0},
105 {N_("weekly"), s_weekly, 0},
106 {N_("monthly"), s_monthly, 0},
107 {N_("hourly"), s_hourly, 0},
109 {N_("1st"), s_wom, 0},
110 {N_("2nd"), s_wom, 1},
111 {N_("3rd"), s_wom, 2},
112 {N_("4th"), s_wom, 3},
113 {N_("5th"), s_wom, 4},
115 {N_("first"), s_wom, 0},
116 {N_("second"), s_wom, 1},
117 {N_("third"), s_wom, 2},
118 {N_("fourth"), s_wom, 3},
119 {N_("fifth"), s_wom, 4},
123 static bool have_hour, have_mday, have_wday, have_month, have_wom;
124 static bool have_at, have_woy;
127 static void set_defaults()
129 have_hour = have_mday = have_wday = have_month = have_wom = have_woy = false;
131 set_bits(0, 23, lrun.hour);
132 set_bits(0, 30, lrun.mday);
133 set_bits(0, 6, lrun.wday);
134 set_bits(0, 11, lrun.month);
135 set_bits(0, 4, lrun.wom);
136 set_bits(0, 53, lrun.woy);
140 /* Keywords (RHS) permitted in Run records */
141 static struct s_kw RunFields[] = {
144 {"incrementalpool", 'i'},
145 {"differentialpool", 'd'},
155 * Store Schedule Run information
157 * Parse Run statement:
159 * Run <keyword=value ...> [on] 2 january at 23:45
161 * Default Run time is daily at 0:0
163 * There can be multiple run statements, they are simply chained
167 void store_run(LEX *lc, RES_ITEM *item, int index, int pass)
171 int token, state, state2 = 0, code = 0, code2 = 0;
172 int options = lc->options;
173 RUN **run = (RUN **)(item->value);
179 lc->options |= LOPT_NO_IDENT; /* want only "strings" */
181 /* clear local copy of run record */
182 memset(&lrun, 0, sizeof(RUN));
184 /* scan for Job level "full", "incremental", ... */
185 for (found=true; found; ) {
187 token = lex_get_token(lc, T_NAME);
188 for (i=0; RunFields[i].name; i++) {
189 if (strcasecmp(lc->str, RunFields[i].name) == 0) {
191 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
192 scan_err1(lc, "Expected an equals, got: %s", lc->str);
195 switch (RunFields[i].token) {
196 case 's': /* Data spooling */
197 token = lex_get_token(lc, T_NAME);
198 if (strcasecmp(lc->str, "yes") == 0) {
199 lrun.spool_data = true;
200 lrun.spool_data_set = true;
201 } else if (strcasecmp(lc->str, "no") == 0) {
202 lrun.spool_data = false;
203 lrun.spool_data_set = true;
205 scan_err1(lc, _("Expect a YES or NO, got: %s"), lc->str);
208 case 'L': /* level */
209 token = lex_get_token(lc, T_NAME);
210 for (j=0; joblevels[j].level_name; j++) {
211 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
212 lrun.level = joblevels[j].level;
213 lrun.job_type = joblevels[j].job_type;
219 scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
223 case 'p': /* Priority */
224 token = lex_get_token(lc, T_PINT32);
226 lrun.Priority = lc->pint32_val;
230 case 'f': /* FullPool */
231 case 'i': /* IncPool */
232 case 'd': /* DifPool */
233 token = lex_get_token(lc, T_NAME);
235 res = GetResWithName(R_POOL, lc->str);
237 scan_err1(lc, "Could not find specified Pool Resource: %s",
241 switch(RunFields[i].token) {
243 lrun.pool = (POOL *)res;
246 lrun.full_pool = (POOL *)res;
249 lrun.inc_pool = (POOL *)res;
252 lrun.dif_pool = (POOL *)res;
257 case 'S': /* storage */
258 token = lex_get_token(lc, T_NAME);
260 res = GetResWithName(R_STORAGE, lc->str);
262 scan_err1(lc, "Could not find specified Storage Resource: %s",
266 lrun.storage = (STORE *)res;
269 case 'M': /* messages */
270 token = lex_get_token(lc, T_NAME);
272 res = GetResWithName(R_MSGS, lc->str);
274 scan_err1(lc, "Could not find specified Messages Resource: %s",
278 lrun.msgs = (MSGS *)res;
282 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
286 } /* end if strcasecmp */
287 } /* end for RunFields */
289 /* At this point, it is not a keyword. Check for old syle
290 * Job Levels without keyword. This form is depreciated!!!
292 for (j=0; joblevels[j].level_name; j++) {
293 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
294 lrun.level = joblevels[j].level;
295 lrun.job_type = joblevels[j].job_type;
300 } /* end for found */
304 * Scan schedule times.
305 * Default is: daily at 0:0
310 for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
315 code = atoi(lc->str) - 1;
316 if (code < 0 || code > 30) {
317 scan_err0(lc, _("Day number out of range (1-31)"));
320 case T_NAME: /* this handles drop through from keyword */
321 case T_UNQUOTED_STRING:
322 if (strchr(lc->str, (int)'-')) {
326 if (strchr(lc->str, (int)':')) {
330 if (lc->str_len == 3 && (lc->str[0] == 'w' || lc->str[0] == 'W') &&
331 is_an_integer(lc->str+1)) {
332 code = atoi(lc->str+1);
333 if (code < 0 || code > 53) {
334 scan_err0(lc, _("Week number out of range (0-53)"));
336 state = s_woy; /* week of year */
339 /* everything else must be a keyword */
340 for (i=0; keyw[i].name; i++) {
341 if (strcasecmp(lc->str, keyw[i].name) == 0) {
342 state = keyw[i].state;
349 scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
356 scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
363 case s_mday: /* day of month */
365 clear_bits(0, 30, lrun.mday);
368 set_bit(code, lrun.mday);
370 case s_month: /* month of year */
372 clear_bits(0, 11, lrun.month);
375 set_bit(code, lrun.month);
377 case s_wday: /* week day */
379 clear_bits(0, 6, lrun.wday);
382 set_bit(code, lrun.wday);
384 case s_wom: /* Week of month 1st, ... */
386 clear_bits(0, 4, lrun.wom);
389 set_bit(code, lrun.wom);
393 clear_bits(0, 53, lrun.woy);
396 set_bit(code, lrun.woy);
398 case s_time: /* time */
400 scan_err0(lc, _("Time must be preceded by keyword AT."));
404 clear_bits(0, 23, lrun.hour);
406 p = strchr(lc->str, ':');
408 scan_err0(lc, _("Time logic error.\n"));
411 *p++ = 0; /* separate two halves */
412 code = atoi(lc->str);
414 if (len > 2 && p[len-1] == 'm') {
415 if (p[len-2] == 'a') {
417 } else if (p[len-2] == 'p') {
420 scan_err0(lc, _("Bad time specification."));
430 if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
431 scan_err0(lc, _("Bad time specification."));
434 /****FIXME**** convert to UTC */
435 set_bit(code, lrun.hour);
443 p = strchr(lc->str, '-');
445 scan_err0(lc, _("Range logic error.\n"));
447 *p++ = 0; /* separate two halves */
449 /* Check for day range */
450 if (is_an_integer(lc->str) && is_an_integer(p)) {
451 code = atoi(lc->str) - 1;
453 if (code < 0 || code > 30 || code2 < 0 || code2 > 30) {
454 scan_err0(lc, _("Bad day range specification."));
457 clear_bits(0, 30, lrun.mday);
461 set_bits(code, code2, lrun.mday);
463 set_bits(code, 30, lrun.mday);
464 set_bits(0, code2, lrun.mday);
468 /* Check for week of year range */
469 if (strlen(lc->str) == 3 && strlen(p) == 3 &&
470 (lc->str[0] == 'w' || lc->str[0] == 'W') &&
471 (p[0] == 'w' || p[0] == 'W') &&
472 is_an_integer(lc->str+1) && is_an_integer(p+1)) {
473 code = atoi(lc->str+1);
475 if (code < 0 || code > 53 || code2 < 0 || code2 > 53) {
476 scan_err0(lc, _("Week number out of range (0-53)"));
479 clear_bits(0, 53, lrun.woy);
483 set_bits(code, code2, lrun.woy);
485 set_bits(code, 53, lrun.woy);
486 set_bits(0, code2, lrun.woy);
490 /* lookup first half of keyword range (week days or months) */
492 for (i=0; keyw[i].name; i++) {
493 if (strcmp(lc->str, keyw[i].name) == 0) {
494 state = keyw[i].state;
500 if (i != 0 || (state != s_month && state != s_wday && state != s_wom)) {
501 scan_err0(lc, _("Invalid month, week or position day range"));
505 /* Lookup end of range */
507 for (i=0; keyw[i].name; i++) {
508 if (strcmp(p, keyw[i].name) == 0) {
509 state2 = keyw[i].state;
510 code2 = keyw[i].code;
515 if (i != 0 || state != state2 || code == code2) {
516 scan_err0(lc, _("Invalid month, weekday or position range"));
519 if (state == s_wday) {
521 clear_bits(0, 6, lrun.wday);
525 set_bits(code, code2, lrun.wday);
527 set_bits(code, 6, lrun.wday);
528 set_bits(0, code2, lrun.wday);
530 } else if (state == s_month) {
532 clear_bits(0, 11, lrun.month);
536 set_bits(code, code2, lrun.month);
538 /* this is a bit odd, but we accept it anyway */
539 set_bits(code, 11, lrun.month);
540 set_bits(0, code2, lrun.month);
543 /* Must be position */
545 clear_bits(0, 4, lrun.wom);
549 set_bits(code, code2, lrun.wom);
551 set_bits(code, 4, lrun.wom);
552 set_bits(0, code2, lrun.wom);
558 set_bits(0, 23, lrun.hour);
561 have_mday = have_wom = have_woy = true;
562 set_bits(0, 30, lrun.mday);
563 set_bits(0, 4, lrun.wom);
564 set_bits(0, 53, lrun.woy);
568 set_bits(0, 6, lrun.wday);
572 set_bits(0, 11, lrun.month);
575 scan_err0(lc, _("Unexpected run state\n"));
581 /* Allocate run record, copy new stuff into it,
582 * and link it into the list of run records
583 * in the schedule resource.
586 trun = (RUN *)malloc(sizeof(RUN));
587 memcpy(trun, &lrun, sizeof(RUN));
594 lc->options = options; /* restore scanner options */
595 set_bit(index, res_all.res_sch.hdr.item_present);