res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
res->res_client.MaxConcurrentJobs);
sendit(sock, " JobRetention=%s FileRetention=%s AutoPrune=%d\n",
- edit_utime(res->res_client.JobRetention, ed1),
- edit_utime(res->res_client.FileRetention, ed2),
+ edit_utime(res->res_client.JobRetention, ed1, sizeof(ed1)),
+ edit_utime(res->res_client.FileRetention, ed2, sizeof(ed2)),
res->res_client.AutoPrune);
if (res->res_client.catalog) {
sendit(sock, " --> ");
res->res_pool.accept_any_volume, res->res_pool.catalog_files);
sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%s\n",
res->res_pool.max_volumes, res->res_pool.AutoPrune,
- edit_utime(res->res_pool.VolRetention, ed1));
+ edit_utime(res->res_pool.VolRetention, ed1, sizeof(ed1)));
sendit(sock, " VolUse=%s recycle=%d LabelFormat=%s\n",
- edit_utime(res->res_pool.VolUseDuration, ed1),
+ edit_utime(res->res_pool.VolUseDuration, ed1, sizeof(ed1)),
res->res_pool.Recycle,
NPRT(res->res_pool.label_format));
sendit(sock, " CleaningPrefix=%s\n",
static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr)
{
- char ed1[50];
+ char ed1[150];
POOLMEM *query;
if (!duration_to_utime(val, &mr->VolRetention)) {
bsendmsg(ua, _("Invalid retention period specified: %s\n"), val);
if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
- bsendmsg(ua, _("New retention seconds is: %s\n"),
- edit_utime(mr->VolRetention, ed1));
+ bsendmsg(ua, _("New retention period is: %s\n"),
+ edit_utime(mr->VolRetention, ed1, sizeof(ed1)));
}
free_pool_memory(query);
}
static void update_voluseduration(UAContext *ua, char *val, MEDIA_DBR *mr)
{
- char ed1[50];
+ char ed1[150];
POOLMEM *query;
if (!duration_to_utime(val, &mr->VolUseDuration)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New use duration is: %s\n"),
- edit_utime(mr->VolUseDuration, ed1));
+ edit_utime(mr->VolUseDuration, ed1, sizeof(ed1)));
}
free_pool_memory(query);
}
MEDIA_DBR mr;
POOL_DBR pr;
POOLMEM *query;
- char ed1[30];
+ char ed1[130];
bool done = false;
const char *kw[] = {
N_("VolStatus"), /* 0 */
update_volstatus(ua, ua->cmd, &mr);
break;
case 1: /* Retention */
- bsendmsg(ua, _("Current retention seconds is: %s\n"),
- edit_utime(mr.VolRetention, ed1));
+ bsendmsg(ua, _("Current retention period is: %s\n"),
+ edit_utime(mr.VolRetention, ed1, sizeof(ed1)));
if (!get_cmd(ua, _("Enter Volume Retention period: "))) {
return 0;
}
case 2: /* Use Duration */
bsendmsg(ua, _("Current use duration is: %s\n"),
- edit_utime(mr.VolUseDuration, ed1));
+ edit_utime(mr.VolUseDuration, ed1, sizeof(ed1)));
if (!get_cmd(ua, _("Enter Volume Use Duration: "))) {
return 0;
}
* Given a string "str", separate the integer part into
* str, and the modifier into mod.
*/
-static bool get_modifier(char *str, char *mod, int mod_len)
+static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_len)
{
- int i, len;
+ int i, len, num_begin, num_end, mod_begin, mod_end;
+
/*
* Look for modifier by walking back looking for the first
* space or digit.
strip_trailing_junk(str);
len = strlen(str);
- /* Find beginning of the modifier */
- for (i=len; i > 0; i--) {
- if (!B_ISALPHA(str[i-1])) {
+ for (i=0; i<len; i++) {
+ if (!B_ISSPACE(str[i])) {
break;
}
}
+ num_begin = i;
- /* If nothing found, error */
- if (i == 0) {
- Dmsg2(900, "error i=%d len=%d\n", i, len);
+ /* Walk through integer part */
+ for ( ; i<len; i++) {
+ if (!B_ISDIGIT(str[i])) {
+ break;
+ }
+ }
+ num_end = i;
+ if (num_len > (num_end - num_begin + 1)) {
+ num_len = num_end - num_begin + 1;
+ }
+ if (num_len == 0) {
return false;
}
-
- /* Move modifier to its location */
- bstrncpy(mod, &str[i], mod_len);
- Dmsg2(900, "in=%s mod=%s:\n", str, mod);
-
- /* Backup over any spaces in front of modifier */
- for ( ; i > 0; i--) {
- if (B_ISSPACE(str[i-1])) {
- continue;
+ for ( ; i<len; i++) {
+ if (!B_ISSPACE(str[i])) {
+ break;
}
- str[i] = 0;
- break;
}
- /* The remainder (beginning) should be our number */
- if (!is_a_number(str)) {
- Dmsg0(900, "input not a number\n");
+ mod_begin = i;
+ for ( ; i<len; i++) {
+ if (!B_ISALPHA(str[i])) {
+ break;
+ }
+ }
+ mod_end = i;
+ if (mod_len > (mod_end - mod_begin + 1)) {
+ mod_len = mod_end - mod_begin + 1;
+ }
+ Dmsg5(900, "str=%s: num_beg=%d num_end=%d mod_beg=%d mod_end=%d\n",
+ str, num_begin, num_end, mod_begin, mod_end);
+ bstrncpy(num, &str[num_begin], num_len);
+ bstrncpy(mod, &str[mod_begin], mod_len);
+ if (!is_a_number(num)) {
return false;
}
+ bstrncpy(str, &str[mod_end], len);
+
return true;
}
int duration_to_utime(char *str, utime_t *value)
{
int i, mod_len;
- double val;
+ double val, total = 0.0;
char mod_str[20];
+ char num_str[50];
/*
* The "n" = mins and months appears before minutes so that m maps
* to months. These "kludges" make it compatible with pre 1.31
static const int32_t mult[] = {60, 1, 60*60*24*30, 60,
60*60, 60*60*24, 60*60*24*7, 60*60*24*91, 60*60*24*365};
- if (!get_modifier(str, mod_str, sizeof(mod_str))) {
- return 0;
- }
- /* Now find the multiplier corresponding to the modifier */
- mod_len = strlen(mod_str);
- for (i=0; mod[i]; i++) {
- if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
- break;
+ while (*str) {
+ if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
+ return 0;
}
+ /* Now find the multiplier corresponding to the modifier */
+ mod_len = strlen(mod_str);
+ if (mod_len == 0) {
+ i = 1; /* assume seconds */
+ } else {
+ for (i=0; mod[i]; i++) {
+ if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
+ break;
+ }
+ }
+ if (mod[i] == NULL) {
+ i = 1; /* no modifier, assume secs */
+ }
+ }
+ Dmsg2(900, "str=%s: mult=%d\n", num_str, mult[i]);
+ errno = 0;
+ val = strtod(num_str, NULL);
+ if (errno != 0 || val < 0) {
+ return 0;
+ }
+ total += val * mult[i];
}
- if (mod[i] == NULL) {
- i = 1; /* no modifier, assume 1 */
- }
- Dmsg2(900, "str=%s: mult=%d\n", str, mult[i]);
- errno = 0;
- val = strtod(str, NULL);
- if (errno != 0 || val < 0) {
- return 0;
- }
- *value = (utime_t)(val * mult[i]);
+ *value = (utime_t)total;
return 1;
}
/*
* Edit a utime "duration" into ASCII
*/
-char *edit_utime(utime_t val, char *buf)
+char *edit_utime(utime_t val, char *buf, int buf_len)
{
- char mybuf[30];
+ char mybuf[200];
static const int32_t mult[] = {60*60*24*365, 60*60*24*30, 60*60*24, 60*60, 60};
static const char *mod[] = {"year", "month", "day", "hour", "min"};
int i;
times = (uint32_t)(val / mult[i]);
if (times > 0) {
val = val - (utime_t)times * mult[i];
- sprintf(mybuf, "%d %s%s ", times, mod[i], times>1?"s":"");
- strcat(buf, mybuf);
+ bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
+ bstrncat(buf, mybuf, buf_len);
}
}
if (val == 0 && strlen(buf) == 0) {
- strcat(buf, "0 secs");
+ bstrncat(buf, "0 secs", buf_len);
} else if (val != 0) {
- sprintf(mybuf, "%d sec%s", (uint32_t)val, val>1?"s":"");
- strcat(buf, mybuf);
+ bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
+ bstrncat(buf, mybuf, buf_len);
}
return buf;
}
/*
- * Convert a size size in bytes to uint64_t
+ * Convert a size in bytes to uint64_t
* Returns 0: if error
1: if OK, and value stored in value
*/
int i, mod_len;
double val;
char mod_str[20];
+ char num_str[50];
static const char *mod[] = {"*", "k", "kb", "m", "mb", "g", "gb", NULL}; /* first item * not used */
const int64_t mult[] = {1, /* byte */
1024, /* kilobyte */
1073741824, /* gigabyte */
1000000000}; /* gb gigabyte */
- if (!get_modifier(str, mod_str, sizeof(mod_str))) {
+ if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
return 0;
}
/* Now find the multiplier corresponding to the modifier */
}
Dmsg2(900, "str=%s: mult=%d\n", str, mult[i]);
errno = 0;
- val = strtod(str, NULL);
+ val = strtod(num_str, NULL);
if (errno != 0 || val < 0) {
return 0;
}
* Check if specified string is a number or not.
* Taken from SQLite, cool, thanks.
*/
-int is_a_number(const char *n)
+bool is_a_number(const char *n)
{
bool digit_seen = false;
/*
* Check if the specified string is an integer
*/
-int is_an_integer(const char *n)
+bool is_an_integer(const char *n)
{
bool digit_seen = false;
while (B_ISDIGIT(*n)) {