/*
- 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"
{NULL, NULL, NULL}
};
-/*
- * Get handler code from handler @
+/*
+ * Get handler code from handler @
*/
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)
{
if (!strcmp(funcs[i].key, key)) {
return funcs[i].handler;
}
- }
+ }
return NULL;
}
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);
} 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;
}
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);
}
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;
if (!items) {
return ret;
}
-
+
fp = fopen(fname, "w");
if (!fp) {
return ret;
**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) {
}
/* 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);
}
} 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;
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;
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);
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"
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");
ini->clear_items();
ini->free_items();
report();
-
+
free_pool_memory(buf);
exit (0);
}