* Version $Id$
*/
/*
- Copyright (C) 2001-2005 Kern Sibbald
+ Copyright (C) 2001-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
int confirm_retention(UAContext *ua, utime_t *ret, const char *msg)
{
char ed1[100];
+ int val;
for ( ;; ) {
bsendmsg(ua, _("The current %s retention period is: %s\n"),
}
continue;
}
- if (strcasecmp(ua->cmd, _("yes")) == 0) {
- return 1;
- }
- if (strcasecmp(ua->cmd, _("no")) == 0) {
- return 0;
+ if (is_yesno(ua->cmd, &val)) {
+ return val; /* is 1 for yes, 0 for no */
}
}
return 1;
{
for (int i=1; i<ua->argc; i++) {
for(int j=0; list[j]; j++) {
- if (strcasecmp(_(list[j]), ua->argk[i]) == 0) {
+ if (strcasecmp(list[j], ua->argk[i]) == 0) {
return j;
}
}
}
}
UnlockRes();
- do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
store = (STORE *)GetResWithName(R_STORAGE, name);
return store;
}
}
}
UnlockRes();
- do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name));
+ if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
fs = (FILESET *)GetResWithName(R_FILESET, name);
return fs;
}
int i;
for (i=1; i<ua->argc; i++) {
- if (strcasecmp(ua->argk[i], _("catalog")) == 0 && ua->argv[i]) {
+ if (strcasecmp(ua->argk[i], NT_("catalog")) == 0 && ua->argv[i]) {
if (acl_access_ok(ua, Catalog_ACL, ua->argv[i])) {
catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]);
break;
}
}
UnlockRes();
- do_prompt(ua, _("Catalog"), _("Select Catalog resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Catalog"), _("Select Catalog resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
catalog = (CAT *)GetResWithName(R_CATALOG, name);
}
return catalog;
}
}
UnlockRes();
- do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
job = (JOB *)GetResWithName(R_JOB, name);
return job;
}
}
}
UnlockRes();
- do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name));
+ if (do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
job = (JOB *)GetResWithName(R_JOB, name);
return job;
}
}
}
UnlockRes();
- do_prompt(ua, _("Client"), _("Select Client (File daemon) resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Client"), _("Select Client (File daemon) resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
client = (CLIENT *)GetResWithName(R_CLIENT, name);
return client;
}
int i;
for (i=1; i<ua->argc; i++) {
- if ((strcasecmp(ua->argk[i], N_("client")) == 0 ||
- strcasecmp(ua->argk[i], N_("fd")) == 0) && ua->argv[i]) {
+ if ((strcasecmp(ua->argk[i], NT_("client")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("fd")) == 0) && ua->argv[i]) {
if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
break;
}
bsendmsg(ua, _("Could not find Client %s: ERR=%s"), cr->Name, db_strerror(ua->db));
}
for (i=1; i<ua->argc; i++) {
- if ((strcasecmp(ua->argk[i], _("client")) == 0 ||
- strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) {
+ if ((strcasecmp(ua->argk[i], NT_("client")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("fd")) == 0) && ua->argv[i]) {
if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
break;
}
uint32_t *ids;
for (i=1; i<ua->argc; i++) {
- if (strcasecmp(ua->argk[i], N_("pool")) == 0 && ua->argv[i] &&
+ if (strcasecmp(ua->argk[i], NT_("pool")) == 0 && ua->argv[i] &&
acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
bstrncpy(pr->Name, ua->argv[i], sizeof(pr->Name));
if (!db_get_pool_record(ua->jcr, ua->db, pr)) {
}
}
UnlockRes();
- do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
pool = (POOL *)GetResWithName(R_POOL, name);
return pool;
}
int i;
for (i=1; i<ua->argc; i++) {
- if (strcasecmp(ua->argk[i], N_("job")) == 0 && ua->argv[i]) {
+ if (strcasecmp(ua->argk[i], NT_("ujobid")) == 0 && ua->argv[i]) {
jr->JobId = 0;
bstrncpy(jr->Job, ua->argv[i], sizeof(jr->Job));
- } else if (strcasecmp(ua->argk[i], N_("jobid")) == 0 && ua->argv[i]) {
+ } else if (strcasecmp(ua->argk[i], NT_("jobid")) == 0 && ua->argv[i]) {
jr->JobId = str_to_int64(ua->argv[i]);
+ jr->Job[0] = 0;
} else {
continue;
}
return jr->JobId;
}
+ jr->JobId = 0;
+ jr->Job[0] = 0;
+
+ for (i=1; i<ua->argc; i++) {
+ if ((strcasecmp(ua->argk[i], NT_("jobname")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("job")) == 0) && ua->argv[i]) {
+ jr->JobId = 0;
+ bstrncpy(jr->Name, ua->argv[i], sizeof(jr->Name));
+ break;
+ }
+ }
if (!select_job_dbr(ua, jr)) { /* try once more */
return 0;
}
* Returns: -1 on error
* index base 0 on success, and choice
* is copied to prompt if not NULL
+ * prompt is set to the chosen prompt item string
*/
int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt)
{
int i, item;
char pmsg[MAXSTRING];
+ if (prompt) {
+ *prompt = 0;
+ }
if (ua->num_prompts == 2) {
item = 1;
if (prompt) {
item = -1;
goto done;
}
+// bnet_sig(ua->UA_sock, BNET_START_SELECT);
bsendmsg(ua, ua->prompt[0]);
for (i=1; i < ua->num_prompts; i++) {
bsendmsg(ua, "%6d: %s\n", i, ua->prompt[i]);
}
-
- if (prompt) {
- *prompt = 0;
- }
+// bnet_sig(ua->UA_sock, BNET_END_SELECT);
for ( ;; ) {
/* First item is the prompt string, not the items */
if (ua->num_prompts == 1) {
bsendmsg(ua, _("Selection is empty!\n"));
- item = 0; /* list is empty ! */
+ item = -1; /* list is empty ! */
break;
}
if (ua->num_prompts == 2) {
free(ua->prompt[i]);
}
ua->num_prompts = 0;
- return item - 1;
+ return item>0 ? item-1 : item;
}
* If use_default is set, we assume that any keyword without a value
* is the name of the Storage resource wanted.
*/
-STORE *get_storage_resource(UAContext *ua, int use_default)
+STORE *get_storage_resource(UAContext *ua, bool use_default)
{
char *store_name = NULL;
STORE *store = NULL;
int i;
char ed1[50];
-
for (i=1; i<ua->argc; i++) {
if (use_default && !ua->argv[i]) {
/* Ignore slots, scan and barcode(s) keywords */
- if (strncasecmp("scan", ua->argk[i], 4) == 0 ||
- strncasecmp("barcode", ua->argk[i], 7) == 0 ||
- strncasecmp("slots", ua->argk[i], 5) == 0) {
+ if (strcasecmp("scan", ua->argk[i]) == 0 ||
+ strcasecmp("barcode", ua->argk[i]) == 0 ||
+ strcasecmp("barcodes", ua->argk[i]) == 0 ||
+ strcasecmp("slots", ua->argk[i]) == 0) {
continue;
}
/* Default argument is storage */
break;
}
} else {
- if (strcasecmp(ua->argk[i], N_("storage")) == 0 ||
- strcasecmp(ua->argk[i], N_("sd")) == 0) {
+ if (strcasecmp(ua->argk[i], NT_("storage")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("sd")) == 0) {
store_name = ua->argv[i];
break;
- } else if (strcasecmp(ua->argk[i], N_("jobid")) == 0) {
+ } else if (strcasecmp(ua->argk[i], NT_("jobid")) == 0) {
jobid = str_to_int64(ua->argv[i]);
if (jobid <= 0) {
bsendmsg(ua, _("Expecting jobid=nn command, got: %s\n"), ua->argk[i]);
bsendmsg(ua, _("JobId %s is not running.\n"), edit_int64(jobid, ed1));
return NULL;
}
- store = jcr->store;
+ store = jcr->wstore;
free_jcr(jcr);
break;
- } else if (strcasecmp(ua->argk[i], N_("job")) == 0) {
+ } else if (strcasecmp(ua->argk[i], NT_("job")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("jobname")) == 0) {
if (!ua->argv[i]) {
bsendmsg(ua, _("Expecting job=xxx, got: %s.\n"), ua->argk[i]);
return NULL;
bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]);
return NULL;
}
- store = jcr->store;
+ store = jcr->wstore;
+ free_jcr(jcr);
+ break;
+ } else if (strcasecmp(ua->argk[i], NT_("ujobid")) == 0) {
+ if (!ua->argv[i]) {
+ bsendmsg(ua, _("Expecting ujobid=xxx, got: %s.\n"), ua->argk[i]);
+ return NULL;
+ }
+ if (!(jcr=get_jcr_by_full_name(ua->argv[i]))) {
+ bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]);
+ return NULL;
+ }
+ store = jcr->wstore;
free_jcr(jcr);
break;
}
store = NULL;
}
- if (!store && store_name) {
+ if (!store && store_name && store_name[0] != 0) {
store = (STORE *)GetResWithName(R_STORAGE, store_name);
if (!store) {
bsendmsg(ua, _("Storage resource \"%s\": not found\n"), store_name);
return store;
}
+/* Get drive that we are working with for this storage */
+int get_storage_drive(UAContext *ua, STORE *store)
+{
+ int i, drive = -1;
+ /* Get drive for autochanger if possible */
+ i = find_arg_with_value(ua, "drive");
+ if (i >=0) {
+ drive = atoi(ua->argv[i]);
+ } else if (store && store->autochanger) {
+ /* If our structure is not set ask SD for # drives */
+ if (store->drives == 0) {
+ store->drives = get_num_drives_from_SD(ua);
+ }
+ /* If only one drive, default = 0 */
+ if (store->drives == 1) {
+ drive = 0;
+ } else {
+ /* Ask user to enter drive number */
+ ua->cmd[0] = 0;
+ if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) {
+ drive = -1; /* None */
+ } else {
+ drive = atoi(ua->cmd);
+ }
+ }
+ }
+ return drive;
+}
+
+/* Get slot that we are working with for this storage */
+int get_storage_slot(UAContext *ua, STORE *store)
+{
+ int i, slot = -1;
+ /* Get slot for autochanger if possible */
+ i = find_arg_with_value(ua, "slot");
+ if (i >=0) {
+ slot = atoi(ua->argv[i]);
+ } else if (store && store->autochanger) {
+ /* Ask user to enter slot number */
+ ua->cmd[0] = 0;
+ if (!get_cmd(ua, _("Enter autochanger slot: "))) {
+ slot = -1; /* None */
+ } else {
+ slot = atoi(ua->cmd);
+ }
+ }
+ return slot;
+}
+
+
/*
* Scan looking for mediatype=