/* Forward referenced functions */
static int do_label(UAContext *ua, char *cmd, int relabel);
static void label_from_barcodes(UAContext *ua);
-static int is_legal_volume_name(UAContext *ua, char *name);
static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel);
static vol_list_t *get_slot_list_from_SD(UAContext *ua);
/* If relabel get name of Volume to relabel */
if (relabel) {
/* Check for volume=OldVolume */
- i = find_arg(ua, "volume");
- if (i >= 0 && ua->argv[i]) {
+ i = find_arg_with_value(ua, "volume");
+ if (i >= 0) {
memset(&omr, 0, sizeof(omr));
bstrncpy(omr.VolumeName, ua->argv[i], sizeof(omr.VolumeName));
if (db_get_media_record(ua->jcr, ua->db, &omr)) {
}
/* Check for name=NewVolume */
- i = find_arg(ua, "name");
- if (i >= 0 && ua->argv[i]) {
+ i = find_arg_with_value(ua, "name");
+ if (i >= 0) {
pm_strcpy(&ua->cmd, ua->argv[i]);
goto checkName;
}
/* Get a new Volume name */
for ( ;; ) {
- if (!get_cmd(ua, _("Enter new Volume name: ")) || ua->cmd[0] == '.') {
+ if (!get_cmd(ua, _("Enter new Volume name: "))) {
return 1;
}
checkName:
- if (!is_legal_volume_name(ua, ua->cmd)) {
+ if (!is_volume_name_legal(ua, ua->cmd)) {
continue;
}
/* If autochanger, request slot */
if (store->autochanger) {
- int first = 1;
- for ( ;; ) {
- if (first) {
- i = find_arg(ua, "slot");
- if (i >= 0 && ua->argv[i]) {
- mr.Slot = atoi(ua->argv[i]);
- }
- first = 0;
- } else {
- if (!get_cmd(ua, _("Enter slot (0 for none): ")) || ua->cmd[0] == '.') {
- return 1;
- }
- mr.Slot = atoi(ua->cmd);
- }
- if (mr.Slot >= 0) { /* OK */
- break;
- }
- bsendmsg(ua, _("Slot numbers must be positive.\n"));
+ i = find_arg_with_value(ua, "slot");
+ if (i >= 0) {
+ mr.Slot = atoi(ua->argv[i]);
+ } else if (!get_pint(ua, _("Enter slot (0 for none): "))) {
+ return 1;
+ } else {
+ mr.Slot = ua->pint32_val;
}
}
vl->Slot, mr.VolumeName);
continue;
}
+ /*
+ * Deal with creating cleaning tape here. Normal tapes created in
+ * send_label_request() below
+ */
if (is_cleaning_tape(ua, &mr, &pr)) {
set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
if (db_create_media_record(ua->jcr, ua->db, &mr)) {
return;
}
-static int is_legal_volume_name(UAContext *ua, char *name)
+/*
+ * Check if the Volume name has legal characters
+ * If ua is non-NULL send the message
+ */
+int is_volume_name_legal(UAContext *ua, char *name)
{
int len;
+ char *p;
+ char *accept = ":.-_";
+
/* Restrict the characters permitted in the Volume name */
- if (strpbrk(name, "`~!@#$%^&*()[]{}|\\;'\"<>?,/")) {
- bsendmsg(ua, _("Illegal character | in a volume name.\n"));
+ for (p=name; *p; p++) {
+ if (B_ISALPHA(*p) || B_ISDIGIT(*p) || strchr(accept, (int)(*p))) {
+ continue;
+ }
+ if (ua) {
+ bsendmsg(ua, _("Illegal character \"%c\" in a volume name.\n"), *p);
+ }
return 0;
}
len = strlen(name);
if (len >= MAX_NAME_LENGTH) {
- bsendmsg(ua, _("Volume name too long.\n"));
+ if (ua) {
+ bsendmsg(ua, _("Volume name too long.\n"));
+ }
return 0;
}
if (len == 0) {
- bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+ if (ua) {
+ bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+ }
return 0;
}
return 1;
dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
}
- while (bget_dirmsg(sd) >= 0) {
+ while (bnet_recv(sd) >= 0) {
bsendmsg(ua, "%s", sd->msg);
if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
ok = TRUE;
bnet_fsend(sd, _("autochanger list %s \n"), dev_name);
/* Read and organize list of Volumes */
- while (bget_dirmsg(sd) >= 0) {
+ while (bnet_recv(sd) >= 0) {
char *p;
int Slot;
strip_trailing_junk(sd->msg);
continue;
}
Slot = atoi(sd->msg);
- if (Slot <= 0 || !is_legal_volume_name(ua, p)) {
+ if (Slot <= 0 || !is_volume_name_legal(ua, p)) {
continue;
}