Skip to content

Commit

Permalink
refactor: make query_range a std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and BareosBot committed Oct 6, 2023
1 parent 5d91727 commit 8da0f1a
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions core/src/dird/ua_output.cc
Expand Up @@ -61,8 +61,8 @@ static bool ParseListBackupsCmd(UaContext* ua,
e_list_type llist);

// Some defaults.
#define DEFAULT_LOG_LINES 5
#define DEFAULT_NR_DAYS 50
const int kDefaultLogLines = 5;
const int kDefaultNumberOfDays = 50;

// Turn auto display of console messages on/off
bool AutodisplayCmd(UaContext* ua, const char*)
Expand Down Expand Up @@ -447,40 +447,31 @@ static inline void SetHiddenColumn(UaContext* ua, int column)
ua->send->AddHiddenColumn(column);
}

static void SetQueryRange(PoolMem& query_range, UaContext* ua, JobDbRecord* jr)
static void SetQueryRange(std::string& query_range,
UaContext* ua,
JobDbRecord* jr)
{
int i;

/* Ensure query range is an empty string instead of NULL
* to avoid any issues. */
if (query_range.c_str() == NULL) { PmStrcpy(query_range, ""); }

/* See if this is a second call to SetQueryRange() if so and any acl
* filters have been set we setup a new query_range filter including a
* limit filter. */
if (query_range.strlen()) {
if (!query_range.empty()) {
if (!ua->send->has_acl_filters()) { return; }
PmStrcpy(query_range, "");
query_range.clear();
}

// Apply any limit
i = FindArgWithValue(ua, NT_("limit"));
int i = FindArgWithValue(ua, NT_("limit"));
if (i >= 0) {
PoolMem temp(PM_MESSAGE);

jr->limit = atoi(ua->argv[i]);
ua->send->AddLimitFilterTuple(jr->limit);

temp.bsprintf(" LIMIT %d", jr->limit);
PmStrcat(query_range, temp.c_str());
query_range.append(" LIMIT " + std::to_string(jr->limit));

// offset is only valid, if limit is given
i = FindArgWithValue(ua, NT_("offset"));
if (i >= 0) {
jr->offset = atoi(ua->argv[i]);
ua->send->AddOffsetFilterTuple(jr->offset);
temp.bsprintf(" OFFSET %d", atoi(ua->argv[i]));
PmStrcat(query_range, temp.c_str());
query_range.append(" OFFSET " + std::to_string(jr->offset));
}
}
}
Expand All @@ -507,9 +498,7 @@ static bool ListMedia(UaContext* ua,
ListCmdOptions optionslist)
{
JobDbRecord jr;
PoolMem query_range;

PmStrcpy(query_range, "");
std::string query_range;
SetQueryRange(query_range, ua, &jr);

// List MEDIA or VOLUMES
Expand Down Expand Up @@ -641,12 +630,10 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
schedtime = now - secs_in_hour * hours; /* Hours in the past */
}

PoolMem query_range(PM_MESSAGE);
std::string query_range;
JobDbRecord jr;
PmStrcpy(query_range, "");
SetQueryRange(query_range, ua, &jr);


char* clientname = nullptr;
argument = FindArgWithValue(ua, NT_("client"));
if (argument >= 0) {
Expand Down Expand Up @@ -872,8 +859,8 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
* default is DEFAULT_LOG_LINES entries */
reverse = FindArg(ua, NT_("reverse")) >= 0;

if (strlen(query_range.c_str()) == 0) {
Mmsg(query_range, " LIMIT %d", DEFAULT_LOG_LINES);
if (query_range.empty()) {
query_range = " LIMIT " + std::to_string(kDefaultLogLines);
}

if (ua->api != API_MODE_JSON) {
Expand Down Expand Up @@ -970,9 +957,9 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
argument = FindArgWithValue(ua, NT_("days"));
if (argument >= 0) {
days = atoi(ua->argv[argument]);
if ((days < 0) || (days > DEFAULT_NR_DAYS)) {
if ((days < 0) || (days > kDefaultNumberOfDays)) {
ua->WarningMsg(_("Ignoring invalid value for days. Max is %d.\n"),
DEFAULT_NR_DAYS);
kDefaultNumberOfDays);
days = 1;
}
}
Expand Down

0 comments on commit 8da0f1a

Please sign in to comment.