/*
Bacula® - The Network Backup Solution
- Copyright (C) 2002-2009 Free Software Foundation Europe e.V.
+ Copyright (C) 2002-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
*
* Kern Sibbald, December MMII
*
- * Version $Id$
*/
#include "bacula.h"
return buf;
}
-/*
- * Convert a size in bytes to uint64_t
- * Returns false: if error
- true: if OK, and value stored in value
- */
-bool size_to_uint64(char *str, int str_len, uint64_t *value)
+static bool strunit_to_uint64(char *str, int str_len, uint64_t *value,
+ const char **mod)
{
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 */
1000, /* kb kilobyte */
return true;
}
+/*
+ * Convert a size in bytes to uint64_t
+ * Returns false: if error
+ true: if OK, and value stored in value
+ */
+bool size_to_uint64(char *str, int str_len, uint64_t *value)
+{
+ /* first item * not used */
+ static const char *mod[] = {"*", "k", "kb", "m", "mb", "g", "gb", NULL};
+ return strunit_to_uint64(str, str_len, value, mod);
+}
+
+/*
+ * Convert a speed in bytes/s to uint64_t
+ * Returns false: if error
+ true: if OK, and value stored in value
+ */
+bool speed_to_uint64(char *str, int str_len, uint64_t *value)
+{
+ /* first item * not used */
+ static const char *mod[] = {"*", "k/s", "kb/s", "m/s", "mb/s", NULL};
+ return strunit_to_uint64(str, str_len, value, mod);
+}
+
/*
* Check if specified string is a number or not.
* Taken from SQLite, cool, thanks.
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
-bool is_name_valid(char *name, POOLMEM **msg)
+bool is_name_valid(const char *name, POOLMEM **msg)
{
int len;
- char *p;
+ const char *p;
/* Special characters to accept */
const char *accept = ":.-_ ";
+ /* No name is invalid */
+ if (!name) {
+ if (msg) {
+ Mmsg(msg, _("Empty name not allowed.\n"));
+ }
+ return false;
+ }
/* Restrict the characters permitted in the Volume name */
for (p=name; *p; p++) {
if (B_ISALPHA(*p) || B_ISDIGIT(*p) || strchr(accept, (int)(*p))) {
}
return false;
}
- len = strlen(name);
+ len = p - name;
if (len >= MAX_NAME_LENGTH) {
if (msg) {
Mmsg(msg, _("Name too long.\n"));