Skip to content

Commit

Permalink
Merge pull request #628 from bareos/dev/joergs/master/show-api2-confi…
Browse files Browse the repository at this point in the history
…gparser

configparser fixes
  • Loading branch information
joergsteffens committed Oct 15, 2020
2 parents 3c2f1ff + e9fb081 commit 6f1a66e
Show file tree
Hide file tree
Showing 58 changed files with 1,257 additions and 504 deletions.
25 changes: 9 additions & 16 deletions core/src/dird/dird_conf.cc
Expand Up @@ -1880,12 +1880,10 @@ static std::string PrintConfigRun(RunResource* run)
*/
PmStrcpy(temp, "");
for (i = 0; i < 24; i++) {
if
BitIsSet(i, run->date_time_bitfield.hour)
{
Mmsg(temp, "at %02d:%02d", i, run->minute);
PmStrcat(run_str, temp.c_str());
}
if BitIsSet (i, run->date_time_bitfield.hour) {
Mmsg(temp, "at %02d:%02d", i, run->minute);
PmStrcat(run_str, temp.c_str());
}
}

/*
Expand Down Expand Up @@ -2167,8 +2165,8 @@ bool FilesetResource::PrintConfig(
/*
* File = entries.
*/
send.KeyMultipleStringsOnePerLine("File",
std::addressof(incexe->name_list));
send.KeyMultipleStringsOnePerLine(
"File", std::addressof(incexe->name_list), false, true, true);

/*
* Plugin = entries.
Expand Down Expand Up @@ -2945,20 +2943,17 @@ static void StoreAutopassword(LEX* lc, ResourceItem* item, int index, int pass)

static void StoreAcl(LEX* lc, ResourceItem* item, int index, int pass)
{
int token;
alist* list;

alist** alistvalue = GetItemVariablePointer<alist**>(*item);

if (pass == 1) {
if (!alistvalue[item->code]) {
alistvalue[item->code] = new alist(10, owned_by_alist);
Dmsg1(900, "Defined new ACL alist at %d\n", item->code);
}
}
list = alistvalue[item->code];
alist* list = alistvalue[item->code];
std::vector<char> msg(256);
for (;;) {
int token = BCT_COMMA;
while (token == BCT_COMMA) {
LexGetToken(lc, BCT_STRING);
if (pass == 1) {
if (!IsAclEntryValid(lc->str, msg)) {
Expand All @@ -2969,8 +2964,6 @@ static void StoreAcl(LEX* lc, ResourceItem* item, int index, int pass)
Dmsg2(900, "Appended to %d %s\n", item->code, lc->str);
}
token = LexGetToken(lc, BCT_ALL);
if (token == BCT_COMMA) { continue; /* get another ACL */ }
break;
}
SetBit(index, (*item->allocated_resource)->item_present_);
ClearBit(index, (*item->allocated_resource)->inherit_content_);
Expand Down
37 changes: 28 additions & 9 deletions core/src/dird/inc_conf.cc
Expand Up @@ -412,6 +412,7 @@ static void ScanIncludeOptions(LEX* lc, int keyword, char* opts, int optlen)
if (!IsAnInteger(lc->str)) {
scan_err1(lc, _("Expected a strip path positive integer, got: %s:"),
lc->str);
return;
}
bstrncat(opts, "P", optlen); /* indicate strip path */
bstrncat(opts, lc->str, optlen);
Expand All @@ -420,6 +421,7 @@ static void ScanIncludeOptions(LEX* lc, int keyword, char* opts, int optlen)
} else if (keyword == INC_KW_SIZE) { /* special case */
if (!ParseSizeMatch(lc->str, &size_matching)) {
scan_err1(lc, _("Expected a parseable size, got: %s:"), lc->str);
return;
}
bstrncat(opts, "z", optlen); /* indicate size */
bstrncat(opts, lc->str, optlen);
Expand All @@ -439,6 +441,7 @@ static void ScanIncludeOptions(LEX* lc, int keyword, char* opts, int optlen)
}
if (i != 0) {
scan_err1(lc, _("Expected a FileSet option keyword, got: %s:"), lc->str);
return;
} else { /* add option */
bstrncat(opts, option, optlen);
Dmsg3(900, "Catopts=%s option=%s optlen=%d\n", opts, option, optlen);
Expand Down Expand Up @@ -476,7 +479,7 @@ static void StoreRegex(LEX* lc, ResourceItem* item, int index, int pass)
regerror(rc, &preg, prbuf, sizeof(prbuf));
regfree(&preg);
scan_err1(lc, _("Regex compile error. ERR=%s\n"), prbuf);
break;
return;
}
regfree(&preg);
if (item->code == 1) {
Expand All @@ -497,6 +500,7 @@ static void StoreRegex(LEX* lc, ResourceItem* item, int index, int pass)
break;
default:
scan_err1(lc, _("Expected a regex string, got: %s\n"), lc->str);
return;
}
}
ScanToEol(lc);
Expand Down Expand Up @@ -574,6 +578,7 @@ static void StoreWild(LEX* lc, ResourceItem* item, int index, int pass)
break;
default:
scan_err1(lc, _("Expected a wild-card string, got: %s\n"), lc->str);
return;
}
}
ScanToEol(lc);
Expand All @@ -599,6 +604,7 @@ static void StoreFstype(LEX* lc, ResourceItem* item, int index, int pass)
break;
default:
scan_err1(lc, _("Expected a fstype string, got: %s\n"), lc->str);
return;
}
}
ScanToEol(lc);
Expand All @@ -624,6 +630,7 @@ static void StoreDrivetype(LEX* lc, ResourceItem* item, int index, int pass)
break;
default:
scan_err1(lc, _("Expected a Drivetype string, got: %s\n"), lc->str);
return;
}
}
ScanToEol(lc);
Expand All @@ -646,6 +653,7 @@ static void StoreMeta(LEX* lc, ResourceItem* item, int index, int pass)
break;
default:
scan_err1(lc, _("Expected a meta string, got: %s\n"), lc->str);
return;
}
}
ScanToEol(lc);
Expand Down Expand Up @@ -683,6 +691,7 @@ static void StoreOption(

if (keyword == INC_KW_NONE) {
scan_err1(lc, _("Expected a FileSet keyword, got: %s"), lc->str);
return;
}

/*
Expand Down Expand Up @@ -734,11 +743,12 @@ static void StoreOptionsRes(LEX* lc,

if (exclude) {
scan_err0(lc, _("Options section not permitted in Exclude\n"));
/* NOT REACHED */
return;
}
token = LexGetToken(lc, BCT_SKIP_EOL);
if (token != BCT_BOB) {
scan_err1(lc, _("Expecting open brace. Got %s"), lc->str);
return;
}

if (pass == 1) { SetupCurrentOpts(); }
Expand All @@ -748,13 +758,15 @@ static void StoreOptionsRes(LEX* lc,
if (token == BCT_EOB) { break; }
if (token != BCT_IDENTIFIER) {
scan_err1(lc, _("Expecting keyword, got: %s\n"), lc->str);
return;
}
bool found = false;
for (i = 0; options_items[i].name; i++) {
if (Bstrcasecmp(options_items[i].name, lc->str)) {
token = LexGetToken(lc, BCT_SKIP_EOL);
if (token != BCT_EQUALS) {
scan_err1(lc, _("expected an equals, got: %s"), lc->str);
return;
}
/* Call item handler */
switch (options_items[i].type) {
Expand Down Expand Up @@ -791,6 +803,7 @@ static void StoreOptionsRes(LEX* lc,
}
if (!found) {
scan_err1(lc, _("Keyword %s not permitted in this resource"), lc->str);
return;
}
}

Expand Down Expand Up @@ -845,8 +858,9 @@ static void StoreFname(LEX* lc,
_("Backslash found. Use forward slashes or quote the "
"string.: %s\n"),
lc->str);
/* NOT REACHED */
return;
}
FALLTHROUGH_INTENDED;
case BCT_QUOTED_STRING: {
FilesetResource* res_fs = GetStaticFilesetResource();
if (res_fs->have_MD5) {
Expand All @@ -862,10 +876,11 @@ static void StoreFname(LEX* lc,
}
default:
scan_err1(lc, _("Expected a filename, got: %s"), lc->str);
return;
}
}
ScanToEol(lc);
} // namespace directordaemon
}

/**
* Store Filename info. Note, for minor efficiency reasons, we
Expand All @@ -882,11 +897,12 @@ static void StorePluginName(LEX* lc,

if (exclude) {
scan_err0(lc, _("Plugin directive not permitted in Exclude\n"));
/* NOT REACHED */
return;
}
token = LexGetToken(lc, BCT_SKIP_EOL);
if (pass == 1) {
/* Pickup Filename string
/*
* Pickup Filename string
*/
switch (token) {
case BCT_IDENTIFIER:
Expand All @@ -896,8 +912,9 @@ static void StorePluginName(LEX* lc,
_("Backslash found. Use forward slashes or quote the "
"string.: %s\n"),
lc->str);
/* NOT REACHED */
return;
}
FALLTHROUGH_INTENDED;
case BCT_QUOTED_STRING: {
FilesetResource* res_fs = GetStaticFilesetResource();

Expand All @@ -913,7 +930,7 @@ static void StorePluginName(LEX* lc,
}
default:
scan_err1(lc, _("Expected a filename, got: %s"), lc->str);
/* NOT REACHED */
return;
}
}
ScanToEol(lc);
Expand All @@ -931,7 +948,6 @@ static void StoreExcludedir(LEX* lc,
if (exclude) {
scan_err0(lc,
_("ExcludeDirContaining directive not permitted in Exclude.\n"));
/* NOT REACHED */
return;
}

Expand Down Expand Up @@ -970,6 +986,7 @@ static void StoreNewinc(LEX* lc, ResourceItem* item, int index, int pass)
if (token == BCT_EOB) { break; }
if (token != BCT_IDENTIFIER) {
scan_err1(lc, _("Expecting keyword, got: %s\n"), lc->str);
return;
}
bool found = false;
for (int i = 0; newinc_items[i].name; i++) {
Expand All @@ -979,6 +996,7 @@ static void StoreNewinc(LEX* lc, ResourceItem* item, int index, int pass)
token = LexGetToken(lc, BCT_SKIP_EOL);
if (token != BCT_EQUALS) {
scan_err1(lc, _("expected an equals, got: %s"), lc->str);
return;
}
}
switch (newinc_items[i].type) {
Expand All @@ -1003,6 +1021,7 @@ static void StoreNewinc(LEX* lc, ResourceItem* item, int index, int pass)
}
if (!found) {
scan_err1(lc, _("Keyword %s not permitted in this resource"), lc->str);
return;
}
}

Expand Down
11 changes: 4 additions & 7 deletions core/src/lib/edit.cc
Expand Up @@ -424,7 +424,8 @@ std::string SizeAsSiPrefixFormat(uint64_t value_in)
/*
* convert default value string to numeric value
*/
static const char* modifier[] = {"e", "p", "t", "g", "m", "k", "", NULL};
static const char* modifier[] = {" e", " p", " t", " g",
" m", " k", "", NULL};
const uint64_t multiplier[] = {1152921504606846976, // EiB Exbibyte
1125899906842624, // PiB Pebibyte
1099511627776, // TiB Tebibyte
Expand All @@ -436,19 +437,16 @@ std::string SizeAsSiPrefixFormat(uint64_t value_in)
if (value == 0) {
result += "0";
} else {
for (int t = 0; modifier[t]; t++) {
for (int t = 0; modifier[t] && (value > 0); t++) {
factor = value / multiplier[t];
value = value % multiplier[t];
if (factor > 0) {
result += std::to_string(factor);
result += " ";
result += modifier[t];
if (!(bstrcmp(modifier[t], ""))) { result += " "; }
if (value > 0) { result += " "; }
}
if (value == 0) { break; }
}
}
result.pop_back();
return result;
}

Expand Down Expand Up @@ -699,4 +697,3 @@ bool IsAclEntryValid(const char* acl)
std::vector<char> msg;
return IsAclEntryValid(acl, msg);
}

4 changes: 0 additions & 4 deletions core/src/lib/lex.cc
Expand Up @@ -520,13 +520,11 @@ static uint32_t scan_pint(LEX* lf, char* str)

if (!Is_a_number(str)) {
scan_err1(lf, _("expected a positive integer number, got: %s"), str);
/* NOT REACHED */
} else {
errno = 0;
val = str_to_int64(str);
if (errno != 0 || val < 0) {
scan_err1(lf, _("expected a positive integer number, got: %s"), str);
/* NOT REACHED */
}
}

Expand All @@ -539,13 +537,11 @@ static uint64_t scan_pint64(LEX* lf, char* str)

if (!Is_a_number(str)) {
scan_err1(lf, _("expected a positive integer number, got: %s"), str);
/* NOT REACHED */
} else {
errno = 0;
val = str_to_uint64(str);
if (errno != 0) {
scan_err1(lf, _("expected a positive integer number, got: %s"), str);
/* NOT REACHED */
}
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/lib/output_formatter.cc
Expand Up @@ -991,7 +991,6 @@ void OutputFormatter::JsonFinalizeResult(bool result)
json_t* range_obj = NULL;
PoolMem ErrorMsg;
char* string;
size_t string_length = 0;

/*
* We mimic json-rpc result and error messages,
Expand Down Expand Up @@ -1039,14 +1038,14 @@ void OutputFormatter::JsonFinalizeResult(bool result)
} else {
string = json_dumps(msg_obj, UA_JSON_FLAGS_NORMAL);
}
string_length = strlen(string);
Dmsg1(800, "message length (json): %lld\n", string_length);
if (string == NULL) {
/*
* json_dumps return NULL on failure (this should not happen).
*/
Emsg0(M_ERROR, 0, "Failed to generate json string.\n");
} else {
size_t string_length = strlen(string);
Dmsg1(800, "message length (json): %lld\n", string_length);
/*
* send json string, on failure, send json error message
*/
Expand Down

0 comments on commit 6f1a66e

Please sign in to comment.