]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/ini.c
Backport from BEE
[bacula/bacula] / bacula / src / lib / ini.c
index 61d9c396296d7e51304baa6528c64aaaae8b1439..7be5a8618dadefcd933713966f586d7d274b2d7a 100644 (file)
@@ -1,35 +1,23 @@
 /*
-   Copyright (C) 2011-2011 Bacula Systems(R) SA
+   Bacula® - The Network Backup Solution
 
-   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 modify it under the terms of
-   version three of the GNU Affero General Public License as published by the 
-   Free Software Foundation, which is listed in the file LICENSE.
+   Copyright (C) 2011-2014 Free Software Foundation Europe e.V.
 
-   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.
+   The main author of Bacula is Kern Sibbald, with contributions from many
+   others, a complete list can be found in the file AUTHORS.
 
-   You should have received a copy of the GNU Affero 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.
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
 
    Bacula® is a registered trademark of Kern Sibbald.
-   Bacula Systems(R) is a trademark of Bacula Systems SA.
-   Bacula Enterprise(TM) is a trademark of Bacula Systems SA.
-
-   The licensor of Bacula Enterprise(TM) is Bacula Systems(R) SA,
-   Rue Galilee 5, 1400 Yverdon-les-Bains, Switzerland.
 */
-
 /*
  * Handle simple configuration file such as "ini" files.
  * key1 = val     # comment
  * key2 = val     # <type>
- * 
+ *
  */
 
 #include "bacula.h"
@@ -57,8 +45,8 @@ static struct ini_store funcs[] = {
    {NULL,       NULL,               NULL}
 };
 
-/* 
- * Get handler code from handler @ 
+/*
+ * Get handler code from handler @
  */
 const char *ini_get_store_code(INI_ITEM_HANDLER *handler)
 {
@@ -70,8 +58,8 @@ const char *ini_get_store_code(INI_ITEM_HANDLER *handler)
    return NULL;
 }
 
-/* 
- * Get handler function from handler name 
+/*
+ * Get handler function from handler name
  */
 INI_ITEM_HANDLER *ini_get_store_handler(const char *key)
 {
@@ -79,7 +67,7 @@ INI_ITEM_HANDLER *ini_get_store_handler(const char *key)
       if (!strcmp(funcs[i].key, key)) {
          return funcs[i].handler;
       }
-   }   
+   }
    return NULL;
 }
 
@@ -108,13 +96,13 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
          buf, lc->line_no, lc->col_no, lc->fname, lc->line);
 
 //   } else if (ini->ctx) {       /* called from plugin */
-//      ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_FATAL, 0, 
+//      ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_FATAL, 0,
 //                    _("Config file error: %s\n"
 //                      "            : Line %d, col %d of file %s\n%s\n"),
 //                            buf, lc->line_no, lc->col_no, lc->fname, lc->line);
 //
    } else {                     /* called from ??? */
-      e_msg(file, line, M_ERROR, 0, 
+      e_msg(file, line, M_ERROR, 0,
             _("Config file error: %s\n"
               "            : Line %d, col %d of file %s\n%s\n"),
             buf, lc->line_no, lc->col_no, lc->fname, lc->line);
@@ -137,7 +125,7 @@ void ConfigFile::clear_items()
 
          } else if (items[i].handler == ini_store_alist_str) {
             delete items[i].val.alistval;
-            items[i].val.alistval = NULL;            
+            items[i].val.alistval = NULL;
          }
          items[i].found = false;
       }
@@ -150,6 +138,7 @@ void ConfigFile::free_items()
       for (int i=0; items[i].name; i++) {
          bfree_and_null_const(items[i].name);
          bfree_and_null_const(items[i].comment);
+         bfree_and_null_const(items[i].default_value);
       }
       free(items);
    }
@@ -184,7 +173,7 @@ bool ConfigFile::dump_string(const char *buf, int32_t len)
       out_fname = get_pool_memory(PM_FNAME);
       make_unique_filename(&out_fname, (int)(intptr_t)this, (char*)"configfile");
    }
-   
+
    fp = fopen(out_fname, "wb");
    if (!fp) {
       return ret;
@@ -209,7 +198,7 @@ bool ConfigFile::serialize(const char *fname)
    if (!items) {
       return ret;
    }
-   
+
    fp = fopen(fname, "w");
    if (!fp) {
       return ret;
@@ -235,18 +224,18 @@ int ConfigFile::serialize(POOLMEM **buf)
       **buf = 0;
       return 0;
    }
-   
+
    len = Mmsg(buf, "# Plugin configuration file\n# Version %d\n", version);
 
    tmp = get_pool_memory(PM_MESSAGE);
 
    for (int i=0; items[i].name ; i++) {
       if (items[i].comment) {
-         Mmsg(tmp, "OptPrompt=%s\n", items[i].comment);
+         Mmsg(tmp, "OptPrompt=\"%s\"\n", items[i].comment);
          pm_strcat(buf, tmp);
       }
       if (items[i].default_value) {
-         Mmsg(tmp, "OptDefault=%s\n", items[i].default_value);
+         Mmsg(tmp, "OptDefault=\"%s\"\n", items[i].default_value);
          pm_strcat(buf, tmp);
       }
       if (items[i].required) {
@@ -255,7 +244,7 @@ int ConfigFile::serialize(POOLMEM **buf)
       }
 
       /* variable = @INT64@ */
-      Mmsg(tmp, "%s=%s\n\n", 
+      Mmsg(tmp, "%s=%s\n\n",
            items[i].name, ini_get_store_code(items[i].handler));
       len = pm_strcat(buf, tmp);
    }
@@ -407,7 +396,7 @@ bool ConfigFile::unserialize(const char *fname)
       } else if (strcasecmp("optdefault", lc->str) == 0) {
          assign = &(items[nb].default_value);
 
-      } else if (strcasecmp("optrequired", lc->str) == 0) { 
+      } else if (strcasecmp("optrequired", lc->str) == 0) {
          items[nb].required = true;               /* Don't use argument */
          scan_to_eol(lc);
          continue;
@@ -507,10 +496,10 @@ bool ini_store_alist_str(LEX *lc, ConfigFile *inifile, ini_items *item)
    if (item->val.alistval == NULL) {
       list = New(alist(10, owned_by_alist));
    } else {
-      list = item->val.alistval;    
+      list = item->val.alistval;
    }
 
-   Dmsg4(900, "Append %s to alist %p size=%d %s\n", 
+   Dmsg4(900, "Append %s to alist %p size=%d %s\n",
          lc->str, list, list->size(), item->name);
    list->append(bstrdup(lc->str));
    item->val.alistval = list;
@@ -584,13 +573,21 @@ bool ini_store_bool(LEX *lc, ConfigFile *inifile, ini_items *item)
    if (lex_get_token(lc, T_NAME) == T_ERROR) {
       return false;
    }
-   if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) {
+   if (strcasecmp(lc->str, "yes")  == 0 ||
+       strcasecmp(lc->str, "true") == 0 ||
+       strcasecmp(lc->str, "on")   == 0)
+   {
       item->val.boolval = true;
-   } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) {
+
+   } else if (strcasecmp(lc->str, "no")    == 0 ||
+              strcasecmp(lc->str, "false") == 0 ||
+              strcasecmp(lc->str, "off")   == 0)
+   {
       item->val.boolval = false;
+
    } else {
       /* YES and NO must not be translated */
-      scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str);
+      scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, ON, OFF, TRUE, or FALSE", lc->str);
       return false;
    }
    scan_to_eol(lc);
@@ -723,12 +720,12 @@ int main()
    fclose(fp);
    ini->clear_items();
    ini->free_items();
-   
+
    /* Test  */
    if ((fp = fopen("test2.cfg", "w")) == NULL) {
       exit (1);
    }
-   fprintf(fp, 
+   fprintf(fp,
            "# this is a comment\n"
            "optprompt=\"Datastore Name\"\n"
            "datastore=@NAME@\n"
@@ -767,7 +764,7 @@ int main()
    ok(ini->items[pos].val.int64val == 10, "Test int");
    ok(ini->items[pos].required == true, "Check required");
 
-   ok((pos = ini->get_item("bool")) == 4, "Check bool definition");   
+   ok((pos = ini->get_item("bool")) == 4, "Check bool definition");
    ok(ini->items[pos].val.boolval == true, "Test bool");
 
    ok(ini->dump_results(&buf), "Test to dump results");
@@ -776,7 +773,7 @@ int main()
    ini->clear_items();
    ini->free_items();
    report();
-   
+
    free_pool_memory(buf);
    exit (0);
 }