From ace133ae0b41b819ab380f7e9c461debbfd766fa Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 5 Apr 2003 16:46:27 +0000 Subject: [PATCH] Next cut barcode labeling git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@421 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/ua_label.c | 88 +++++++++++++++++++++------------ bacula/src/dird/ua_select.c | 6 +-- bacula/src/lib/edit.c | 14 +++++- bacula/src/lib/lex.c | 18 +++---- bacula/src/lib/protos.h | 1 + bacula/src/stored/autochanger.c | 4 ++ 6 files changed, 82 insertions(+), 49 deletions(-) diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c index 871d141a37..42c7652235 100644 --- a/bacula/src/dird/ua_label.c +++ b/bacula/src/dird/ua_label.c @@ -30,16 +30,10 @@ #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; +} diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index c6ccc313a2..2835bef76b 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -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; - } + } } } diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index c7757f4bcd..28ea49bb4a 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -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; } - diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 9474ab6444..88dcfe1b4e 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -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"; diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 4041e8488f..350c9e6df4 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -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); diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 76d1e00e35..1f5f271f38 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -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; -- 2.39.5