]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_select.c
Update technotes and version
[bacula/bacula] / bacula / src / dird / ua_select.c
index 9021229956ac0fdb42efdbf3d1efd185c0b04ae8..ae5f9b989d3302f403ed5ee26dff4fb4300d7261 100644 (file)
@@ -1,15 +1,7 @@
-/*
- *
- *   Bacula Director -- User Agent Prompt and Selection code
- *
- *     Kern Sibbald, October MMI
- *
- *   Version  $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Director -- User Agent Prompt and Selection code
+ *
+ *     Kern Sibbald, October MMI
+ *
+ *   Version  $Id$
+ */
 
 #include "bacula.h"
 #include "dird.h"
@@ -160,8 +160,8 @@ STORE *select_storage_resource(UAContext *ua)
    start_prompt(ua, _("The defined Storage resources are:\n"));
    LockRes();
    foreach_res(store, R_STORAGE) {
-      if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
-         add_prompt(ua, store->hdr.name);
+      if (acl_access_ok(ua, Storage_ACL, store->name())) {
+         add_prompt(ua, store->name());
       }
    }
    UnlockRes();
@@ -183,8 +183,8 @@ FILESET *select_fileset_resource(UAContext *ua)
    start_prompt(ua, _("The defined FileSet resources are:\n"));
    LockRes();
    foreach_res(fs, R_FILESET) {
-      if (acl_access_ok(ua, FileSet_ACL, fs->hdr.name)) {
-         add_prompt(ua, fs->hdr.name);
+      if (acl_access_ok(ua, FileSet_ACL, fs->name())) {
+         add_prompt(ua, fs->name());
       }
    }
    UnlockRes();
@@ -220,7 +220,7 @@ CAT *get_catalog_resource(UAContext *ua)
       if (!catalog) {
          bsendmsg(ua, _("Could not find a Catalog resource\n"));
          return NULL;
-      } else if (!acl_access_ok(ua, Catalog_ACL, ua->catalog->hdr.name)) {
+      } else if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) {
          bsendmsg(ua, _("You must specify a \"use <catalog-name>\" command before continuing.\n"));
          return NULL;
       }
@@ -230,8 +230,8 @@ CAT *get_catalog_resource(UAContext *ua)
       start_prompt(ua, _("The defined Catalog resources are:\n"));
       LockRes();
       foreach_res(catalog, R_CATALOG) {
-         if (acl_access_ok(ua, Catalog_ACL, catalog->hdr.name)) {
-            add_prompt(ua, catalog->hdr.name);
+         if (acl_access_ok(ua, Catalog_ACL, catalog->name())) {
+            add_prompt(ua, catalog->name());
          }
       }
       UnlockRes();
@@ -255,8 +255,8 @@ JOB *select_job_resource(UAContext *ua)
    start_prompt(ua, _("The defined Job resources are:\n"));
    LockRes();
    foreach_res(job, R_JOB) {
-      if (acl_access_ok(ua, Job_ACL, job->hdr.name)) {
-         add_prompt(ua, job->hdr.name);
+      if (acl_access_ok(ua, Job_ACL, job->name())) {
+         add_prompt(ua, job->name());
       }
    }
    UnlockRes();
@@ -278,8 +278,8 @@ JOB *select_restore_job_resource(UAContext *ua)
    start_prompt(ua, _("The defined Restore Job resources are:\n"));
    LockRes();
    foreach_res(job, R_JOB) {
-      if (job->JobType == JT_RESTORE && acl_access_ok(ua, Job_ACL, job->hdr.name)) {
-         add_prompt(ua, job->hdr.name);
+      if (job->JobType == JT_RESTORE && acl_access_ok(ua, Job_ACL, job->name())) {
+         add_prompt(ua, job->name());
       }
    }
    UnlockRes();
@@ -303,8 +303,8 @@ CLIENT *select_client_resource(UAContext *ua)
    start_prompt(ua, _("The defined Client resources are:\n"));
    LockRes();
    foreach_res(client, R_CLIENT) {
-      if (acl_access_ok(ua, Client_ACL, client->hdr.name)) {
-         add_prompt(ua, client->hdr.name);
+      if (acl_access_ok(ua, Client_ACL, client->name())) {
+         add_prompt(ua, client->name());
       }
    }
    UnlockRes();
@@ -431,11 +431,11 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr)
    return 1;
 }
 
-
-
 /* Scan what the user has entered looking for:
  *
- *  pool=<pool-name>
+ *  argk=<pool-name>
+ *
+ *  where argk can be : pool, recyclepool, scratchpool, nextpool etc..
  *
  *  if error or not found, put up a list of pool DBRs
  *  to choose from.
@@ -443,7 +443,7 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr)
  *   returns: false on error
  *            true  on success and fills in POOL_DBR
  */
-bool get_pool_dbr(UAContext *ua, POOL_DBR *pr)
+bool get_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
 {
    if (pr->Name[0]) {                 /* If name already supplied */
       if (db_get_pool_record(ua->jcr, ua->db, pr) &&
@@ -452,16 +452,17 @@ bool get_pool_dbr(UAContext *ua, POOL_DBR *pr)
       }
       bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), pr->Name, db_strerror(ua->db));
    }
-   if (!select_pool_dbr(ua, pr)) {  /* try once more */
+   if (!select_pool_dbr(ua, pr, argk)) {  /* try once more */
       return false;
    }
    return true;
 }
 
 /*
- * Select a Pool record from the catalog
+ * Select a Pool record from catalog
+ * argk can be pool, recyclepool, scratchpool etc..
  */
-bool select_pool_dbr(UAContext *ua, POOL_DBR *pr)
+bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
 {
    POOL_DBR opr;
    char name[MAX_NAME_LENGTH];
@@ -469,7 +470,7 @@ bool select_pool_dbr(UAContext *ua, POOL_DBR *pr)
    uint32_t *ids;
 
    for (i=1; i<ua->argc; i++) {
-      if (strcasecmp(ua->argk[i], NT_("pool")) == 0 && ua->argv[i] &&
+      if (strcasecmp(ua->argk[i], argk) == 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)) {
@@ -587,8 +588,8 @@ POOL *select_pool_resource(UAContext *ua)
    start_prompt(ua, _("The defined Pool resources are:\n"));
    LockRes();
    foreach_res(pool, R_POOL) {
-      if (acl_access_ok(ua, Pool_ACL, pool->hdr.name)) {
-         add_prompt(ua, pool->hdr.name);
+      if (acl_access_ok(ua, Pool_ACL, pool->name())) {
+         add_prompt(ua, pool->name());
       }
    }
    UnlockRes();
@@ -730,10 +731,12 @@ void add_prompt(UAContext *ua, const char *prompt)
  *               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 do_prompt(UAContext *ua, const char *automsg, const char *msg, 
+              char *prompt, int max_prompt)
 {
    int i, item;
    char pmsg[MAXSTRING];
+   BSOCK *user = ua->UA_sock;
 
    if (prompt) {
       *prompt = 0;
@@ -752,12 +755,16 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt,
       item = -1;
       goto done;
    }
-// bnet_sig(ua->UA_sock, BNET_START_SELECT);
+   if (ua->api) user->signal(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 (ua->api) {
+         bsendmsg(ua, "%s", ua->prompt[i]);
+      } else {
+         bsendmsg(ua, "%6d: %s\n", i, ua->prompt[i]);
+      }
    }
-// bnet_sig(ua->UA_sock, BNET_END_SELECT);
+   if (ua->api) user->signal(BNET_END_SELECT);
 
    for ( ;; ) {
       /* First item is the prompt string, not the items */
@@ -768,7 +775,7 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt,
       }
       if (ua->num_prompts == 2) {
          item = 1;
-         bsendmsg(ua, _("Item 1 selected automatically.\n"));
+         bsendmsg(ua, _("Automatically selected: %s\n"), ua->prompt[1]);
          if (prompt) {
             bstrncpy(prompt, ua->prompt[1], max_prompt);
          }
@@ -777,6 +784,7 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt,
          sprintf(pmsg, "%s (1-%d): ", msg, ua->num_prompts-1);
       }
       /* Either a . or an @ will get you out of the loop */
+      if (ua->api) user->signal(BNET_SELECT_INPUT);
       if (!get_pint(ua, pmsg)) {
          item = -1;                   /* error */
          bsendmsg(ua, _("Selection aborted, nothing done.\n"));
@@ -889,7 +897,7 @@ STORE *get_storage_resource(UAContext *ua, bool use_default)
         }
       }
    }
-   if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+   if (store && !acl_access_ok(ua, Storage_ACL, store->name())) {
       store = NULL;
    }
 
@@ -899,7 +907,7 @@ STORE *get_storage_resource(UAContext *ua, bool use_default)
          bsendmsg(ua, _("Storage resource \"%s\": not found\n"), store_name);
       }
    }
-   if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+   if (store && !acl_access_ok(ua, Storage_ACL, store->name())) {
       store = NULL;
    }
    /* No keywords found, so present a selection list */