]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_label.c
Add new files
[bacula/bacula] / bacula / src / dird / ua_label.c
index 9020445e4f59cca909c96fafa082cb7a03eaca3d..be0746b3239ce59e3acc3980181855fe44e3fa10 100644 (file)
@@ -41,7 +41,6 @@ typedef struct s_vol_list {
 /* 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);
@@ -173,8 +172,8 @@ static int do_label(UAContext *ua, char *cmd, int relabel)
    /* 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)) {
@@ -197,19 +196,19 @@ checkVol:
    }
 
    /* 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;
       }
 
@@ -225,24 +224,13 @@ checkName:
 
    /* 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;
       }
    }
 
@@ -348,6 +336,10 @@ static void label_from_barcodes(UAContext *ua)
             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)) {
@@ -395,21 +387,37 @@ bail_out:
    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;
@@ -443,7 +451,7 @@ static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
         dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
    }
 
-   while (bget_msg(sd, 0) >= 0) {
+   while (bnet_recv(sd) >= 0) {
       bsendmsg(ua, "%s", sd->msg);
       if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
         ok = TRUE;
@@ -491,7 +499,7 @@ static vol_list_t *get_slot_list_from_SD(UAContext *ua)
    bnet_fsend(sd, _("autochanger list %s \n"), dev_name);
 
    /* Read and organize list of Volumes */
-   while (bget_msg(sd, 0) >= 0) {
+   while (bnet_recv(sd) >= 0) {
       char *p;
       int Slot;
       strip_trailing_junk(sd->msg);
@@ -515,7 +523,7 @@ static vol_list_t *get_slot_list_from_SD(UAContext *ua)
         continue;
       }
       Slot = atoi(sd->msg);
-      if (Slot <= 0 || !is_legal_volume_name(ua, p)) {
+      if (Slot <= 0 || !is_volume_name_legal(ua, p)) {
         continue;
       }