]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/parse_conf.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / lib / parse_conf.c
index a0453f647af3289a2cc4cd7eb68a9da8c661d2ea..2c3ac1b43e3c0941b811c02427d695f284453cef 100755 (executable)
@@ -34,7 +34,7 @@
  */
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -115,6 +115,7 @@ static struct s_mtypes msg_types[] = {
    {"skipped",       M_SKIPPED},
    {"mount",         M_MOUNT},
    {"terminate",     M_TERM},
+   {"restored",      M_RESTORED},
    {"all",           M_MAX+1},
    {NULL,           0}
 };
@@ -165,9 +166,10 @@ void init_resource(int type, struct res_items *items)
            *(int *)(items[i].value) = items[i].default_value;
         } else if (items[i].handler == store_int64) {
            *(int64_t *)(items[i].value) = items[i].default_value;
-        } else if (items[i].handler == store_size ||
-                   items[i].handler == store_time) {
-           *(uint64_t *)(items[i].value) = items[i].default_value;
+        } else if (items[i].handler == store_size) {
+           *(uint64_t *)(items[i].value) = (uint64_t)items[i].default_value;
+        } else if (items[i].handler == store_time) {
+           *(utime_t *)(items[i].value) = (utime_t)items[i].default_value;
         }
       }
       /* If this triggers, take a look at lib/parse_conf.h */
@@ -237,8 +239,7 @@ void store_msgs(LEX *lc, struct res_items *item, int index, int pass)
            dest = get_pool_memory(PM_MESSAGE);
            /* Pick up a single destination */
            token = lex_get_token(lc, T_NAME);   /* scan destination */
-           dest = check_pool_memory_size(dest, lc->str_len + 2);
-           strcpy(dest, lc->str);
+           pm_strcpy(&dest, lc->str);
            dest_len = lc->str_len;
            token = lex_get_token(lc, T_ALL);
             Dmsg1(200, "store_msgs dest=%s:\n", NPRT(dest));
@@ -283,7 +284,7 @@ static void scan_types(LEX *lc, MSGS *msg, int dest_code, char *where, char *cmd
         str = &lc->str[0];
       }
       for (i=0; msg_types[i].name; i++) {
-        if (strcmp(str, msg_types[i].name) == 0) {
+        if (strcasecmp(str, msg_types[i].name) == 0) {
            msg_type = msg_types[i].token;
            found = TRUE;
            break;
@@ -367,7 +368,7 @@ void store_dir(LEX *lc, struct res_items *item, int index, int pass)
    lex_get_token(lc, T_STRING);
    if (pass == 1) {
       if (lc->str[0] != '|') {
-        do_shell_expansion(lc->str);
+        do_shell_expansion(lc->str, sizeof(lc->str));
       }
       *(item->value) = bstrdup(lc->str);
    }
@@ -454,65 +455,20 @@ void store_int64(LEX *lc, struct res_items *item, int index, int pass)
 /* Store a size in bytes */
 void store_size(LEX *lc, struct res_items *item, int index, int pass)
 {
-   int token, i, ch;
-   double value;
-   int mod[]  = {'*', 'k', 'm', 'g', 0}; /* first item * not used */
-   uint64_t mult[] = {1,            /* byte */
-                     1024,          /* kilobyte */
-                     1048576,       /* megabyte */
-                     1073741824};   /* gigabyte */
-
-#ifdef we_have_a_compiler_that_works
-   int mod[]  = {'*', 'k', 'm', 'g', 't', 0};
-   uint64_t mult[] = {1,            /* byte */
-                     1024,          /* kilobyte */
-                     1048576,       /* megabyte */
-                     1073741824,    /* gigabyte */
-                     1099511627776};/* terabyte */
-#endif
+   int token;
+   uint64_t uvalue;
 
    Dmsg0(400, "Enter store_size\n");
    token = lex_get_token(lc, T_ALL);
    errno = 0;
    switch (token) {
    case T_NUMBER:
-      Dmsg2(400, "size num=:%s: %f\n", lc->str, strtod(lc->str, NULL)); 
-      value = strtod(lc->str, NULL);
-      if (errno != 0 || token < 0) {
-         scan_err1(lc, "expected a size number, got: %s", lc->str);
-      }
-      *(uint64_t *)(item->value) = (uint64_t)value;
-      break;
    case T_IDENTIFIER:
    case T_UNQUOTED_STRING:
-      /* Look for modifier */
-      ch = lc->str[lc->str_len - 1];
-      i = 0;
-      if (ISALPHA(ch)) {
-        if (ISUPPER(ch)) {
-           ch = tolower(ch);
-        }
-        while (mod[++i] != 0) {
-           if (ch == mod[i]) {
-              lc->str_len--;
-              lc->str[lc->str_len] = 0; /* strip modifier */
-              break;
-           }
-        }
-      }
-      if (mod[i] == 0 || !is_a_number(lc->str)) {
-         scan_err1(lc, "expected a size number, got: %s", lc->str);
-      }
-      Dmsg3(400, "size str=:%s: %f i=%d\n", lc->str, strtod(lc->str, NULL), i);
-
-      value = (uint64_t)strtod(lc->str, NULL);
-      Dmsg1(400, "Int value = %d\n", (int)value);
-      if (errno != 0 || value < 0) {
+      if (!size_to_uint64(lc->str, lc->str_len, &uvalue)) {
          scan_err1(lc, "expected a size number, got: %s", lc->str);
       }
-      *(uint64_t *)(item->value) = (uint64_t)(value * mult[i]);
-      Dmsg2(400, "Full value = %f %" lld "\n", strtod(lc->str, NULL) * mult[i],
-         value *mult[i]);
+      *(uint64_t *)(item->value) = uvalue;
       break;
    default:
       scan_err1(lc, "expected a size, got: %s", lc->str);
@@ -528,31 +484,37 @@ void store_size(LEX *lc, struct res_items *item, int index, int pass)
 void store_time(LEX *lc, struct res_items *item, int index, int pass)
 {
    int token; 
-   double value;
-   btime_t btime;
+   utime_t utime;
+   char period[500];
 
    token = lex_get_token(lc, T_ALL);
    errno = 0;
    switch (token) {
    case T_NUMBER:
-      value = strtod(lc->str, NULL);
-      if (errno != 0 || value < 0) {
-         scan_err1(lc, "expected a time period, got: %s", lc->str);
-      }
-      *(btime_t *)(item->value) = (btime_t)value;
-      break;
    case T_IDENTIFIER:
    case T_UNQUOTED_STRING:
-      if (!string_to_btime(lc->str, &btime)) {
-         scan_err1(lc, "expected a time period, got: %s", lc->str);
+      bstrncpy(period, lc->str, sizeof(period));
+      if (lc->ch == ' ') {
+        token = lex_get_token(lc, T_ALL);
+        switch (token) {
+        case T_IDENTIFIER:
+        case T_UNQUOTED_STRING:
+           bstrncat(period, lc->str, sizeof(period));
+           break;
+        }
+      }
+      if (!duration_to_utime(period, &utime)) {
+         scan_err1(lc, "expected a time period, got: %s", period);
       }
-      *(btime_t *)(item->value) = btime;
+      *(utime_t *)(item->value) = utime;
       break;
    default:
       scan_err1(lc, "expected a time period, got: %s", lc->str);
       break;
    }
-   scan_to_eol(lc);
+   if (token != T_EOL) {
+      scan_to_eol(lc);
+   }
    set_bit(index, res_all.hdr.item_present);
 }
 
@@ -696,11 +658,15 @@ parse_config(char *cf)
                     }
                     for (i=0; items[i].name; i++) {
                        if (strcasecmp(items[i].name, lc->str) == 0) {
-                          token = lex_get_token(lc, T_ALL);
-                           Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
-                          if (token != T_EQUALS) {
-                              scan_err1(lc, "expected an equals, got: %s", lc->str);
-                             /* NOT REACHED */
+                          /* If the ITEM_NO_EQUALS flag is set we do NOT              
+                           *   scan for = after the keyword  */
+                          if (!(items[i].flags & ITEM_NO_EQUALS)) {
+                             token = lex_get_token(lc, T_ALL);
+                              Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
+                             if (token != T_EQUALS) {
+                                 scan_err1(lc, "expected an equals, got: %s", lc->str);
+                                /* NOT REACHED */
+                             }
                           }
                            Dmsg1(150, "calling handler for %s\n", items[i].name);
                           /* Call item handler */
@@ -712,7 +678,8 @@ parse_config(char *cf)
                     if (i >= 0) {
                         Dmsg2(150, "level=%d id=%s\n", level, lc->str);
                         Dmsg1(150, "Keyword = %s\n", lc->str);
-                        scan_err1(lc, "Keyword %s not permitted in this resource", lc->str);
+                        scan_err1(lc, "Keyword \"%s\" not permitted in this resource.\n"
+                           "Perhaps you left the trailing brace off of the previous resource.", lc->str);
                        /* NOT REACHED */
                     }
                     break;
@@ -738,6 +705,9 @@ parse_config(char *cf)
               /* NOT REACHED */
         }
       }
+      if (state != p_none) {
+         scan_err0(lc, "End of conf file reached with unclosed resource.");
+      }
       if (debug_level > 50 && pass == 2) {
         int i;
         for (i=r_first; i<=r_last; i++) {