Skip to content

Commit

Permalink
lib: provide simple resource validation callback
Browse files Browse the repository at this point in the history
Previously only JobResource had a method called Validate() to check the
resource for completeness and correctness.
This patch adds a virtual Validate() method to BareosResource that can
be overridden by every resource that needs to do additional checks.
  • Loading branch information
arogge committed Aug 7, 2020
1 parent 5a30ee5 commit d9c7f23
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/src/dird/dird_conf.cc
Expand Up @@ -1260,8 +1260,8 @@ bool ValidateResource(int res_type, ResourceItem* items, BareosResource* res)
* a jobdef don't have to be fully defined.
*/
return true;
} else if (res_type == R_JOB) {
if (!((JobResource*)res)->Validate()) { return false; }
} else if (!res->Validate()) {
return false;
}

for (int i = 0; items[i].name; i++) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/dird_conf.h
Expand Up @@ -535,7 +535,7 @@ class JobResource : public BareosResource {
runtime_job_status_t* rjs = nullptr; /**< Runtime Job Status */

/* Methods */
bool Validate();
virtual bool Validate() override;
};
/* clang-format on */

Expand Down
4 changes: 4 additions & 0 deletions core/src/lib/bareos_resource.cc
Expand Up @@ -48,6 +48,10 @@ BareosResource::BareosResource(const BareosResource& other)
::memcpy(inherit_content_, other.inherit_content_, MAX_RES_ITEMS);
}

bool BareosResource::Validate() {
return true;
}

BareosResource& BareosResource::operator=(const BareosResource& rhs)
{
next_ = rhs.next_;
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib/bareos_resource.h
Expand Up @@ -52,6 +52,8 @@ class BareosResource {
const ConfigurationParser& my_config,
bool hide_sensitive_data = false,
bool verbose = false);

virtual bool Validate();
};

#endif /* BAREOS_LIB_BAREOS_RESOURCE_H_ */

0 comments on commit d9c7f23

Please sign in to comment.