+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of Kern Sibbald.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/*
*
* Configuration parser for Director Run Configuration
*
* Version $Id$
*/
-/*
- Copyright (C) 2000-2005 Kern Sibbald
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as ammended with additional clauses defined in the
- file LICENSE in the main source directory.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
-
- */
#include "bacula.h"
#include "dird.h"
+#if defined(_MSC_VER)
+extern "C" { // work around visual compiler mangling variables
+ extern URES res_all;
+}
+#else
extern URES res_all;
+#endif
extern struct s_jl joblevels[];
/* Forward referenced subroutines */
};
struct s_keyw {
- const char *name; /* keyword */
+ const char *name; /* keyword */
enum e_state state; /* parser state */
int code; /* state value */
};
/* Keywords understood by parser */
static struct s_keyw keyw[] = {
- {N_("on"), s_none, 0},
- {N_("at"), s_at, 0},
-
- {N_("sun"), s_wday, 0},
- {N_("mon"), s_wday, 1},
- {N_("tue"), s_wday, 2},
- {N_("wed"), s_wday, 3},
- {N_("thu"), s_wday, 4},
- {N_("fri"), s_wday, 5},
- {N_("sat"), s_wday, 6},
- {N_("jan"), s_month, 0},
- {N_("feb"), s_month, 1},
- {N_("mar"), s_month, 2},
- {N_("apr"), s_month, 3},
- {N_("may"), s_month, 4},
- {N_("jun"), s_month, 5},
- {N_("jul"), s_month, 6},
- {N_("aug"), s_month, 7},
- {N_("sep"), s_month, 8},
- {N_("oct"), s_month, 9},
- {N_("nov"), s_month, 10},
- {N_("dec"), s_month, 11},
-
- {N_("sunday"), s_wday, 0},
- {N_("monday"), s_wday, 1},
- {N_("tuesday"), s_wday, 2},
- {N_("wednesday"), s_wday, 3},
- {N_("thursday"), s_wday, 4},
- {N_("friday"), s_wday, 5},
- {N_("saturday"), s_wday, 6},
- {N_("january"), s_month, 0},
- {N_("february"), s_month, 1},
- {N_("march"), s_month, 2},
- {N_("april"), s_month, 3},
- {N_("june"), s_month, 5},
- {N_("july"), s_month, 6},
- {N_("august"), s_month, 7},
- {N_("september"), s_month, 8},
- {N_("october"), s_month, 9},
- {N_("november"), s_month, 10},
- {N_("december"), s_month, 11},
-
- {N_("daily"), s_daily, 0},
- {N_("weekly"), s_weekly, 0},
- {N_("monthly"), s_monthly, 0},
- {N_("hourly"), s_hourly, 0},
-
- {N_("1st"), s_wom, 0},
- {N_("2nd"), s_wom, 1},
- {N_("3rd"), s_wom, 2},
- {N_("4th"), s_wom, 3},
- {N_("5th"), s_wom, 4},
-
- {N_("first"), s_wom, 0},
- {N_("second"), s_wom, 1},
- {N_("third"), s_wom, 2},
- {N_("fourth"), s_wom, 3},
- {N_("fifth"), s_wom, 4},
+ {NT_("on"), s_none, 0},
+ {NT_("at"), s_at, 0},
+
+ {NT_("sun"), s_wday, 0},
+ {NT_("mon"), s_wday, 1},
+ {NT_("tue"), s_wday, 2},
+ {NT_("wed"), s_wday, 3},
+ {NT_("thu"), s_wday, 4},
+ {NT_("fri"), s_wday, 5},
+ {NT_("sat"), s_wday, 6},
+ {NT_("jan"), s_month, 0},
+ {NT_("feb"), s_month, 1},
+ {NT_("mar"), s_month, 2},
+ {NT_("apr"), s_month, 3},
+ {NT_("may"), s_month, 4},
+ {NT_("jun"), s_month, 5},
+ {NT_("jul"), s_month, 6},
+ {NT_("aug"), s_month, 7},
+ {NT_("sep"), s_month, 8},
+ {NT_("oct"), s_month, 9},
+ {NT_("nov"), s_month, 10},
+ {NT_("dec"), s_month, 11},
+
+ {NT_("sunday"), s_wday, 0},
+ {NT_("monday"), s_wday, 1},
+ {NT_("tuesday"), s_wday, 2},
+ {NT_("wednesday"), s_wday, 3},
+ {NT_("thursday"), s_wday, 4},
+ {NT_("friday"), s_wday, 5},
+ {NT_("saturday"), s_wday, 6},
+ {NT_("january"), s_month, 0},
+ {NT_("february"), s_month, 1},
+ {NT_("march"), s_month, 2},
+ {NT_("april"), s_month, 3},
+ {NT_("june"), s_month, 5},
+ {NT_("july"), s_month, 6},
+ {NT_("august"), s_month, 7},
+ {NT_("september"), s_month, 8},
+ {NT_("october"), s_month, 9},
+ {NT_("november"), s_month, 10},
+ {NT_("december"), s_month, 11},
+
+ {NT_("daily"), s_daily, 0},
+ {NT_("weekly"), s_weekly, 0},
+ {NT_("monthly"), s_monthly, 0},
+ {NT_("hourly"), s_hourly, 0},
+
+ {NT_("1st"), s_wom, 0},
+ {NT_("2nd"), s_wom, 1},
+ {NT_("3rd"), s_wom, 2},
+ {NT_("4th"), s_wom, 3},
+ {NT_("5th"), s_wom, 4},
+
+ {NT_("first"), s_wom, 0},
+ {NT_("second"), s_wom, 1},
+ {NT_("third"), s_wom, 2},
+ {NT_("fourth"), s_wom, 3},
+ {NT_("fifth"), s_wom, 4},
{NULL, s_none, 0}
};
int token, state, state2 = 0, code = 0, code2 = 0;
int options = lc->options;
RUN **run = (RUN **)(item->value);
- RUN *trun;
char *p;
RES *res;
if (strcasecmp(lc->str, RunFields[i].name) == 0) {
found = true;
if (lex_get_token(lc, T_ALL) != T_EQUALS) {
- scan_err1(lc, "Expected an equals, got: %s", lc->str);
+ scan_err1(lc, _("Expected an equals, got: %s"), lc->str);
/* NOT REACHED */
}
switch (RunFields[i].token) {
case 's': /* Data spooling */
token = lex_get_token(lc, T_NAME);
- if (strcasecmp(lc->str, "yes") == 0) {
+ if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) {
lrun.spool_data = true;
lrun.spool_data_set = true;
- } else if (strcasecmp(lc->str, "no") == 0) {
+ } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) {
lrun.spool_data = false;
lrun.spool_data_set = true;
} else {
break;
case 'W': /* Write part after job */
token = lex_get_token(lc, T_NAME);
- if (strcasecmp(lc->str, "yes") == 0) {
+ if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) {
lrun.write_part_after_job = true;
lrun.write_part_after_job_set = true;
- } else if (strcasecmp(lc->str, "no") == 0) {
+ } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) {
lrun.write_part_after_job = false;
lrun.write_part_after_job_set = true;
} else {
if (pass == 2) {
res = GetResWithName(R_POOL, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Pool Resource: %s",
+ scan_err1(lc, _("Could not find specified Pool Resource: %s"),
lc->str);
/* NOT REACHED */
}
lrun.inc_pool = (POOL *)res;
break;
case 'd':
- lrun.dif_pool = (POOL *)res;
+ lrun.diff_pool = (POOL *)res;
break;
}
}
if (pass == 2) {
res = GetResWithName(R_STORAGE, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Storage Resource: %s",
+ scan_err1(lc, _("Could not find specified Storage Resource: %s"),
lc->str);
/* NOT REACHED */
}
if (pass == 2) {
res = GetResWithName(R_MSGS, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Messages Resource: %s",
+ scan_err1(lc, _("Could not find specified Messages Resource: %s"),
lc->str);
/* NOT REACHED */
}
}
break;
default:
- scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
+ scan_err1(lc, _("Expected a keyword name, got: %s"), lc->str);
/* NOT REACHED */
break;
} /* end switch */
/* At this point, it is not a keyword. Check for old syle
* Job Levels without keyword. This form is depreciated!!!
*/
- for (j=0; joblevels[j].level_name; j++) {
- if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
- lrun.level = joblevels[j].level;
- lrun.job_type = joblevels[j].job_type;
- found = true;
- break;
+ if (!found) {
+ for (j=0; joblevels[j].level_name; j++) {
+ if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
+ lrun.level = joblevels[j].level;
+ lrun.job_type = joblevels[j].job_type;
+ found = true;
+ break;
+ }
}
}
} /* end for found */
set_defaults();
for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
- int len, pm = 0;
+ int len;
+ bool pm = false;
+ bool am = false;
switch (token) {
case T_NUMBER:
state = s_mday;
code = atoi(lc->str+1);
if (code < 0 || code > 53) {
scan_err0(lc, _("Week number out of range (0-53)"));
+ /* NOT REACHED */
}
state = s_woy; /* week of year */
break;
if (!have_hour) {
clear_bits(0, 23, lrun.hour);
}
+// Dmsg1(000, "s_time=%s\n", lc->str);
p = strchr(lc->str, ':');
if (!p) {
scan_err0(lc, _("Time logic error.\n"));
}
*p++ = 0; /* separate two halves */
code = atoi(lc->str); /* pick up hour */
+ code2 = atoi(p); /* pick up minutes */
len = strlen(p);
- if (len > 2 && p[len-1] == 'm') {
- if (p[len-2] == 'a') {
- pm = 0;
- } else if (p[len-2] == 'p') {
- pm = 1;
- } else {
- scan_err0(lc, _("Bad time specification."));
- /* NOT REACHED */
- }
- } else {
- pm = 0;
+ if (len >= 2) {
+ p += 2;
}
- code2 = atoi(p); /* pick up minutes */
+ if (strcasecmp(p, "pm") == 0) {
+ pm = true;
+ } else if (strcasecmp(p, "am") == 0) {
+ am = true;
+ } else if (len != 2) {
+ scan_err0(lc, _("Bad time specification."));
+ /* NOT REACHED */
+ }
+ /*
+ * Note, according to NIST, 12am and 12pm are ambiguous and
+ * can be defined to anything. However, 12:01am is the same
+ * as 00:01 and 12:01pm is the same as 12:01, so we define
+ * 12am as 00:00 and 12pm as 12:00.
+ */
if (pm) {
/* Convert to 24 hour time */
- if (code == 12) {
- code -= 12;
- } else {
+ if (code != 12) {
code += 12;
}
+ /* am */
+ } else if (am && code == 12) {
+ code -= 12;
}
if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
scan_err0(lc, _("Bad time specification."));
/* NOT REACHED */
}
+// Dmsg2(000, "hour=%d min=%d\n", code, code2);
set_bit(code, lrun.hour);
lrun.minute = code2;
have_hour = true;
}
/* Allocate run record, copy new stuff into it,
- * and link it into the list of run records
+ * and append it to the list of run records
* in the schedule resource.
*/
if (pass == 2) {
- trun = (RUN *)malloc(sizeof(RUN));
- memcpy(trun, &lrun, sizeof(RUN));
- if (*run) {
- trun->next = *run;
+ RUN *tail;
+
+ /* Create new run record */
+ RUN *nrun = (RUN *)malloc(sizeof(RUN));
+ memcpy(nrun, &lrun, sizeof(RUN));
+ nrun ->next = NULL;
+
+ if (!*run) { /* if empty list */
+ *run = nrun; /* add new record */
+ } else {
+ for (tail = *run; tail->next; tail=tail->next)
+ { }
+ tail->next = nrun;
}
- *run = trun;
}
lc->options = options; /* restore scanner options */