]> git.sur5r.net Git - bacula/bacula/commitdiff
Next cut barcode labeling
authorKern Sibbald <kern@sibbald.com>
Sat, 5 Apr 2003 16:46:27 +0000 (16:46 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 5 Apr 2003 16:46:27 +0000 (16:46 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@421 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/ua_label.c
bacula/src/dird/ua_select.c
bacula/src/lib/edit.c
bacula/src/lib/lex.c
bacula/src/lib/protos.h
bacula/src/stored/autochanger.c

index 871d141a378b713a5cc19b4b2a82b08d5b9bde44..42c76522350f0d2a8172ba9fa634e82198f51d6a 100644 (file)
 #include "bacula.h"
 #include "dird.h"
 
-/* Imported subroutines */
-
-/* Imported variables */
-
-
-/* Imported functions */
-
 /* 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);
 
 /*
  * Label a tape 
@@ -137,17 +131,7 @@ checkVol:
         return 1;
       }
 checkName:
-      /* Restrict the characters permitted in the Volume name */
-      if (strpbrk(ua->cmd, "`~!@#$%^&*()[]{}|\\;'\"<>?,/")) {
-         bsendmsg(ua, _("Illegal character | in a volume name.\n"));
-        continue;
-      }
-      if (strlen(ua->cmd) >= MAX_NAME_LENGTH) {
-         bsendmsg(ua, _("Volume name too long.\n"));
-        continue;
-      }
-      if (strlen(ua->cmd) == 0) {
-         bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+      if (!is_legal_volume_name(ua, ua->cmd)) {
         continue;
       }
 
@@ -161,7 +145,7 @@ checkName:
       break;                         /* Got it */
    }
 
-   /* Do some more checking on slot ****FIXME**** */
+   /* If autochanger, request slot */
    if (store->autochanger) {
       for ( ;; ) {
          if (!get_cmd(ua, _("Enter slot (0 for none): "))) {
@@ -237,22 +221,20 @@ checkName:
                *  3001 OK mount. Device=xxx      or
                *  3001 Mounted Volume vvvv
                */
-               if (strncmp(sd->msg, "3001 ", 5) == 0) {
-                 mounted = TRUE;
-                 /***** ****FIXME***** find job waiting for  
-                  ***** mount, and change to waiting for SD  
-                  */
-              }
+               mounted = strncmp(sd->msg, "3001 ", 5) == 0;
            }
         }
       } else {
          bsendmsg(ua, "%s", db_strerror(ua->db));
       }
-      if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
-         bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
-           omr.VolumeName, db_strerror(ua->db));
-      } else {
-         bsendmsg(ua, _("Volume \"%s\" deleted from catalog.\n"));
+      if (relabel) {
+        if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
+            bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
+              omr.VolumeName, db_strerror(ua->db));
+        } else {
+            bsendmsg(ua, _("Old volume \"%s\" deleted from catalog.\n"), 
+              omr.VolumeName);
+        }
       }
    }
    if (!mounted) {
@@ -265,6 +247,10 @@ checkName:
    return 1;
 }
 
+/*
+ * Request SD to send us the slot:barcodes, then wiffle
+ *  through them all labeling them.
+ */
 static void label_from_barcodes(UAContext *ua)
 {
    STORE *store = ua->jcr->store;
@@ -284,12 +270,32 @@ static void label_from_barcodes(UAContext *ua)
    sd = ua->jcr->store_bsock;
    bnet_fsend(sd, _("autochanger list %s \n"), dev_name);
    while (bget_msg(sd, 0) >= 0) {
-      bsendmsg(ua, "%s", sd->msg);
+      char *p;
+      int slot;
+      strip_trailing_junk(sd->msg);
+      if (strncmp(sd->msg, "3902 Issuing", 12) == 0 ||
+          strncmp(sd->msg, "3903 Issuing", 12) == 0) {
+         bsendmsg(ua, "%s\n", sd->msg);
+        continue;
+      }
+      p = strchr(sd->msg, ':');
+      if (p && strlen(p) > 1) {
+        *p++ = 0;
+        if (!is_an_integer(sd->msg)) {
+           continue;
+        }
+      } else {
+        continue;
+      }
+      slot = atoi(sd->msg);
+      bsendmsg(ua, "Got slot=%d label: %s\n", slot, p);
    }
    bnet_sig(sd, BNET_TERMINATE);
    bnet_close(sd);
    ua->jcr->store_bsock = NULL;
 
+   return;
+
    memset(&pr, 0, sizeof(pr));
    if (!select_pool_dbr(ua, &pr)) {
       return;
@@ -297,3 +303,23 @@ static void label_from_barcodes(UAContext *ua)
 
    return;
 }
+
+static int is_legal_volume_name(UAContext *ua, char *name)
+{
+   int len;
+   /* Restrict the characters permitted in the Volume name */
+   if (strpbrk(name, "`~!@#$%^&*()[]{}|\\;'\"<>?,/")) {
+      bsendmsg(ua, _("Illegal character | in a volume name.\n"));
+      return 0;
+   }
+   len = strlen(name);
+   if (len >= MAX_NAME_LENGTH) {
+      bsendmsg(ua, _("Volume name too long.\n"));
+      return 0;
+   }
+   if (len == 0) {
+      bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+      return 0;
+   }
+   return 1;
+}
index c6ccc313a258837a463f7909ab418d6bd8bc8c37..2835bef76bb6a0ab8de77878e44360b192f7e918 100644 (file)
@@ -718,11 +718,7 @@ STORE *get_storage_resource(UAContext *ua, char *cmd)
            store = jcr->store;
            free_jcr(jcr);
            return store;
-
-        } else {
-            bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]);
-           return NULL;
-        }
+       }
       }
    }
 
index c7757f4bcd9b6819b7237d6967113d3495a9bd7e..28ea49bb4a3359fa2c52fb08b99f8237dfd96ab7 100644 (file)
@@ -248,6 +248,19 @@ int is_a_number(const char *n)
    return digit_seen && *n==0;
 }
 
+/*
+ * Check if the specified string is an integer  
+ */
+int is_an_integer(const char *n)
+{
+   int digit_seen = 0;
+   while (B_ISDIGIT(*n)) {
+      digit_seen = 1;
+      n++;
+   }
+   return digit_seen && *n==0;
+}
+
 /*
  * Add commas to a string, which is presumably
  * a number.  
@@ -277,4 +290,3 @@ char *add_commas(char *val, char *buf)
    }   
    return buf;
 }
-
index 9474ab64443c215b3b687eb7bf56f4e8c58d28de..88dcfe1b4e7cd7bb885d86c4e175854fd15dd4c1 100644 (file)
@@ -71,8 +71,7 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...)
  * Free the current file, and retrieve the contents
  * of the previous packet if any.
  */
-LEX *
-lex_close_file(LEX *lf)
+LEX *lex_close_file(LEX *lf)
 {
    LEX *of;
 
@@ -107,8 +106,7 @@ lex_close_file(LEX *lf)
  * the next field.
  *
  */
-LEX *
-lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) 
+LEX *lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) 
              
 {
    LEX *nf;
@@ -150,8 +148,7 @@ lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error)
  *    L_EOF if end of file
  *    L_EOL if end of line
  */
-int
-lex_get_char(LEX *lf)
+int lex_get_char(LEX *lf)
 {
    if (lf->ch == L_EOF) {
       Emsg0(M_ABORT, 0, "get_char: called after EOF\n");
@@ -177,8 +174,7 @@ lex_get_char(LEX *lf)
    return lf->ch;
 }
 
-void
-lex_unget_char(LEX *lf)
+void lex_unget_char(LEX *lf)
 {
    lf->col_no--;      
    if (lf->ch == L_EOL)
@@ -214,8 +210,7 @@ static void begin_str(LEX *lf, int ch)
 }
 
 #ifdef DEBUG
-static char *
-lex_state_to_str(int state)
+static char *lex_state_to_str(int state)
 {
    switch (state) {
       case lex_none:          return "none";
@@ -234,8 +229,7 @@ lex_state_to_str(int state)
  * Convert a lex token to a string
  * used for debug/error printing.
  */
-char *
-lex_tok_to_str(int token)
+char *lex_tok_to_str(int token)
 {
    switch(token) {
       case L_EOF:             return "L_EOF";
index 4041e8488fbd25d0e5f390cb508204c602f06e6f..350c9e6df42d4ea4a7e636f20457031ad5551b6f 100644 (file)
@@ -91,6 +91,7 @@ int            duration_to_utime       (char *str, utime_t *value);
 int             size_to_uint64(char *str, int str_len, uint64_t *rtn_value);
 char            *edit_utime             (utime_t val, char *buf);
 int             is_a_number             (const char *num);
+int             is_an_integer           (const char *n);
 
 /* lex.c */
 LEX *    lex_close_file         (LEX *lf);
index 76d1e00e35738ae365019880c1abd9cbe6f8e142..1f5f271f3813115f16add28c52c5e3a0d12e1a46 100644 (file)
@@ -136,6 +136,10 @@ int autoload_device(JCR *jcr, DEVICE *dev, int writing, BSOCK *dir)
    return rtn_stat;
 }
 
+/*
+ * List the Volumes that are in the autoloader possibly
+ *   with their barcodes.
+ */
 int autochanger_list(JCR *jcr, DEVICE *dev, BSOCK *dir)
 {
    uint32_t timeout = jcr->device->max_changer_wait;