]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/dird/run_conf.c
authorEric Bollengier <eric@baculasystems.com>
Fri, 24 Apr 2020 15:59:29 +0000 (17:59 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Mar 20 14:53:33 2019 +0100

    Add FD Calls Director feature to ease client behind NAT access

     - Implement scheduler in Client side to activate the feature
     - Refactor Run resource between the director and the file daemon
     - Allow to use the Director resource to connect a Director for the proxy command and the FDCallsDir
     - Add FDCallsDir state in show client
     - Add code to handle permanent connections bsock_meeting

    New Directive
     FileDaemon:Director:FDCallsDir=<yes/no>
     FileDaemon:Director:FDCallsDirReconnect=<time>
     FileDaemon:Director:FDCallsDirSchedule=<resource>

     Director:Client:FDCallsDir=<yes/no>

    New Resource
     FileDaemon:Schedule

bacula/src/dird/run_conf.c

index afcb900518b99495489998753099413b2573c973..4d87ab86eadb9936e20ff619c89fb8945d324a66 100644 (file)
@@ -37,113 +37,57 @@ extern URES res_all;
 #endif
 extern s_jl joblevels[];
 
-/* Forward referenced subroutines */
-
-enum e_state {
-   s_none = 0,
-   s_range,
-   s_mday,
-   s_month,
-   s_time,
-   s_at,
-   s_wday,
-   s_daily,
-   s_weekly,
-   s_monthly,
-   s_hourly,
-   s_wom,                           /* 1st, 2nd, ...*/
-   s_woy,                           /* week of year w00 - w53 */
-   s_ldom                           /* last day of month */
-};
-
-struct s_keyw {
-  const char *name;                   /* keyword */
-  enum e_state state;                 /* parser state */
-  int code;                           /* state value */
-};
-
-/* Keywords understood by parser */
-static struct s_keyw keyw[] = {
-  {NT_("on"),         s_none,    0},
-  {NT_("at"),         s_at,      0},
-  {NT_("lastday"),    s_ldom,    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_("6th"),        s_wom,     5},
-
-  {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},
-  {NT_("sixth"),      s_wom,     5},
-  {NULL,         s_none,    0}
-};
-
-static bool have_hour, have_mday, have_wday, have_month, have_wom;
-static bool have_at, have_woy;
 static RUN lrun;
 
-static void set_defaults()
+void RUN::clearall()
 {
-   have_hour = have_mday = have_wday = have_month = have_wom = have_woy = false;
-   have_at = false;
-   set_bits(0, 23, lrun.hour);
-   set_bits(0, 30, lrun.mday);
-   set_bits(0, 6,  lrun.wday);
-   set_bits(0, 11, lrun.month);
-   set_bits(0, 5,  lrun.wom);
-   set_bits(0, 53, lrun.woy);
+   RUNBASE::clear();
+
+   level=0;
+   Priority=0;
+   job_type=0;
+   MaxRunSchedTime=0;
+   MaxRunSchedTime_set = spool_data =  spool_data_set = accurate = accurate_set = false;
+   write_part_after_job = write_part_after_job_set = priority_set = level_set = false;
+
+   pool = next_pool = full_pool = inc_pool = diff_pool = NULL;
+   storage  = NULL;
+   msgs = NULL;
+   since = NULL;
+   next = NULL;
 }
 
+#define CPY(a) a = src->a
+
+void RUN::copyall(RUN *src)
+{
+   clearall();
+
+   RUNBASE::copy(src);
+   CPY(level);
+   CPY(Priority);
+   CPY(job_type);
+   CPY(MaxRunSchedTime);
+   CPY(MaxRunSchedTime_set);
+   CPY(spool_data);
+   CPY(spool_data_set);
+   CPY(accurate);
+   CPY(accurate_set);
+
+   CPY(write_part_after_job);
+   CPY(write_part_after_job_set);
+   CPY(priority_set);
+   CPY(level_set);
+
+   CPY(pool);
+   CPY(next_pool);
+   CPY(full_pool);
+   CPY(inc_pool);
+   CPY(diff_pool);
+   CPY(storage);
+   CPY(msgs);
+   CPY(since);
+}
 
 /*
  * Keywords (RHS) permitted in Run records
@@ -185,17 +129,16 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass)
    int i, j;
    bool found;
    utime_t utime;
-   int token, state, state2 = 0, code = 0, code2 = 0;
+   int token;
    int options = lc->options;
    RUN **run = (RUN **)(item->value);
-   char *p;
    RES *res;
 
 
    lc->options |= LOPT_NO_IDENT;      /* want only "strings" */
 
    /* clear local copy of run record */
-   memset(&lrun, 0, sizeof(RUN));
+   lrun.clearall();
 
    /* scan for Job level "full", "incremental", ... */
    for (found=true; found; ) {
@@ -360,307 +303,7 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass)
       }
    } /* end for found */
 
-
-   /*
-    * Scan schedule times.
-    * Default is: daily at 0:0
-    */
-   state = s_none;
-   set_defaults();
-
-   for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
-      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 > 30) {
-            scan_err0(lc, _("Day number out of range (1-31)"));
-         }
-         break;
-      case T_NAME:                 /* this handles drop through from keyword */
-      case T_UNQUOTED_STRING:
-         if (strchr(lc->str, (int)'-')) {
-            state = s_range;
-            break;
-         }
-         if (strchr(lc->str, (int)':')) {
-            state = s_time;
-            break;
-         }
-         if (lc->str_len == 3 && (lc->str[0] == 'w' || lc->str[0] == 'W') &&
-             is_an_integer(lc->str+1)) {
-            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;
-         }
-         /* everything else must be a keyword */
-         for (i=0; keyw[i].name; i++) {
-            if (strcasecmp(lc->str, keyw[i].name) == 0) {
-               state = keyw[i].state;
-               code   = keyw[i].code;
-               i = 0;
-               break;
-            }
-         }
-         if (i != 0) {
-            scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
-            /* NOT REACHED */
-         }
-         break;
-      case T_COMMA:
-         continue;
-      default:
-         scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
-         /* NOT REACHED */
-         break;
-      }
-      switch (state) {
-      case s_none:
-         continue;
-      case s_mday:                 /* day of month */
-         if (!have_mday) {
-            clear_bits(0, 30, lrun.mday);
-            have_mday = true;
-         }
-         set_bit(code, lrun.mday);
-         break;
-      case s_month:                /* month of year */
-         if (!have_month) {
-            clear_bits(0, 11, lrun.month);
-            have_month = true;
-         }
-         set_bit(code, lrun.month);
-         break;
-      case s_wday:                 /* week day */
-         if (!have_wday) {
-            clear_bits(0, 6, lrun.wday);
-            have_wday = true;
-         }
-         set_bit(code, lrun.wday);
-         break;
-      case s_wom:                  /* Week of month 1st, ... */
-         if (!have_wom) {
-            clear_bits(0, 5, lrun.wom);
-            have_wom = true;
-         }
-         set_bit(code, lrun.wom);
-         break;
-      case s_woy:
-         if (!have_woy) {
-            clear_bits(0, 53, lrun.woy);
-            have_woy = true;
-         }
-         set_bit(code, lrun.woy);
-         break;
-      case s_time:                 /* time */
-         if (!have_at) {
-            scan_err0(lc, _("Time must be preceded by keyword AT."));
-            /* NOT REACHED */
-         }
-         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"));
-            /* NOT REACHED */
-         }
-         *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 += 2;
-         }
-         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;
-            }
-         /* 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;
-         break;
-      case s_at:
-         have_at = true;
-         break;
-      case s_ldom:
-         if (!have_mday) {
-            clear_bits(0, 30, lrun.mday);
-            have_mday = true;
-         }
-         lrun.last_day_set = true;
-         set_bit(31, lrun.mday);   /* day 32 => last day of month */
-         break;
-      case s_range:
-         p = strchr(lc->str, '-');
-         if (!p) {
-            scan_err0(lc, _("Range logic error.\n"));
-         }
-         *p++ = 0;                 /* separate two halves */
-
-         /* Check for day range */
-         if (is_an_integer(lc->str) && is_an_integer(p)) {
-            code = atoi(lc->str) - 1;
-            code2 = atoi(p) - 1;
-            if (code < 0 || code > 30 || code2 < 0 || code2 > 30) {
-               scan_err0(lc, _("Bad day range specification."));
-            }
-            if (!have_mday) {
-               clear_bits(0, 30, lrun.mday);
-               have_mday = true;
-            }
-            if (code < code2) {
-               set_bits(code, code2, lrun.mday);
-            } else {
-               set_bits(code, 30, lrun.mday);
-               set_bits(0, code2, lrun.mday);
-            }
-            break;
-         }
-         /* Check for week of year range */
-         if (strlen(lc->str) == 3 && strlen(p) == 3 &&
-             (lc->str[0] == 'w' || lc->str[0] == 'W') &&
-             (p[0] == 'w' || p[0] == 'W') &&
-             is_an_integer(lc->str+1) && is_an_integer(p+1)) {
-            code = atoi(lc->str+1);
-            code2 = atoi(p+1);
-            if (code < 0 || code > 53 || code2 < 0 || code2 > 53) {
-               scan_err0(lc, _("Week number out of range (0-53)"));
-            }
-            if (!have_woy) {
-               clear_bits(0, 53, lrun.woy);
-               have_woy = true;
-            }
-            if (code < code2) {
-               set_bits(code, code2, lrun.woy);
-            } else {
-               set_bits(code, 53, lrun.woy);
-               set_bits(0, code2, lrun.woy);
-            }
-            break;
-         }
-         /* lookup first half of keyword range (week days or months) */
-         lcase(lc->str);
-         for (i=0; keyw[i].name; i++) {
-            if (strcasecmp(lc->str, keyw[i].name) == 0) {
-               state = keyw[i].state;
-               code   = keyw[i].code;
-               i = 0;
-               break;
-            }
-         }
-         if (i != 0 || (state != s_month && state != s_wday && state != s_wom)) {
-            scan_err0(lc, _("Invalid month, week or position day range"));
-            /* NOT REACHED */
-         }
-
-         /* Lookup end of range */
-         lcase(p);
-         for (i=0; keyw[i].name; i++) {
-            if (strcasecmp(p, keyw[i].name) == 0) {
-               state2  = keyw[i].state;
-               code2   = keyw[i].code;
-               i = 0;
-               break;
-            }
-         }
-         if (i != 0 || state != state2 || code == code2) {
-            scan_err0(lc, _("Invalid month, weekday or position range"));
-            /* NOT REACHED */
-         }
-         if (state == s_wday) {
-            if (!have_wday) {
-               clear_bits(0, 6, lrun.wday);
-               have_wday = true;
-            }
-            if (code < code2) {
-               set_bits(code, code2, lrun.wday);
-            } else {
-               set_bits(code, 6, lrun.wday);
-               set_bits(0, code2, lrun.wday);
-            }
-         } else if (state == s_month) {
-            if (!have_month) {
-               clear_bits(0, 11, lrun.month);
-               have_month = true;
-            }
-            if (code < code2) {
-               set_bits(code, code2, lrun.month);
-            } else {
-               /* this is a bit odd, but we accept it anyway */
-               set_bits(code, 11, lrun.month);
-               set_bits(0, code2, lrun.month);
-            }
-         } else {
-            /* Must be position */
-            if (!have_wom) {
-               clear_bits(0, 5, lrun.wom);
-               have_wom = true;
-            }
-            if (code < code2) {
-               set_bits(code, code2, lrun.wom);
-            } else {
-               set_bits(code, 5, lrun.wom);
-               set_bits(0, code2, lrun.wom);
-            }
-         }
-         break;
-      case s_hourly:
-         have_hour = true;
-         set_bits(0, 23, lrun.hour);
-         break;
-      case s_weekly:
-         have_mday = have_wom = have_woy = true;
-         set_bits(0, 30, lrun.mday);
-         set_bits(0, 5,  lrun.wom);
-         set_bits(0, 53, lrun.woy);
-         break;
-      case s_daily:
-         have_mday = true;
-         set_bits(0, 6, lrun.wday);
-         break;
-      case s_monthly:
-         have_month = true;
-         set_bits(0, 11, lrun.month);
-         break;
-      default:
-         scan_err0(lc, _("Unexpected run state\n"));
-         /* NOT REACHED */
-         break;
-      }
-   }
+   lrun.store_runbase(lc, token);
 
    /* Allocate run record, copy new stuff into it,
     * and append it to the list of run records
@@ -671,7 +314,7 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass)
 
       /* Create new run record */
       RUN *nrun = (RUN *)malloc(sizeof(RUN));
-      memcpy(nrun, &lrun, sizeof(RUN));
+      nrun->copyall(&lrun);
       nrun ->next = NULL;
 
       if (!*run) {                    /* if empty list */