+#else
+/*
+ * Test code -- turned on only for debug testing
+ */
+static int version_cmd(UAContext *ua, const char *cmd)
+{
+ dbid_list ids;
+ POOL_MEM query(PM_MESSAGE);
+ open_db(ua);
+ Mmsg(query, "select MediaId from Media,Pool where Pool.PoolId=Media.PoolId and Pool.Name='Full'");
+ db_get_query_dbids(ua->jcr, ua->db, query, ids);
+ ua->send_msg("num_ids=%d max_ids=%d tot_ids=%d\n", ids.num_ids, ids.max_ids, ids.tot_ids);
+ for (int i=0; i < ids.num_ids; i++) {
+ ua->send_msg("id=%d\n", ids.DBId[i]);
+ }
+ close_db(ua);
+ return 1;
+}
+#endif
+
+/*
+ * This call explicitly checks for a catalog=xxx and
+ * if given, opens that catalog. It also checks for
+ * client=xxx and if found, opens the catalog
+ * corresponding to that client. If we still don't
+ * have a catalog, look for a Job keyword and get the
+ * catalog from its client record.
+ */
+bool open_client_db(UAContext *ua)
+{
+ int i;
+ CAT *catalog;
+ CLIENT *client;
+ JOB *job;
+
+ /* Try for catalog keyword */
+ i = find_arg_with_value(ua, NT_("catalog"));
+ if (i >= 0) {
+ if (!acl_access_ok(ua, Catalog_ACL, ua->argv[i])) {
+ ua->error_msg(_("No authorization for Catalog \"%s\"\n"), ua->argv[i]);
+ return false;
+ }
+ catalog = GetCatalogResWithName(ua->argv[i]);
+ if (catalog) {
+ if (ua->catalog && ua->catalog != catalog) {
+ close_db(ua);
+ }
+ ua->catalog = catalog;
+ return open_db(ua);
+ }
+ }
+
+ /* Try for client keyword */
+ i = find_arg_with_value(ua, NT_("client"));
+ if (i >= 0) {
+ if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
+ ua->error_msg(_("No authorization for Client \"%s\"\n"), ua->argv[i]);
+ return false;
+ }
+ client = GetClientResWithName(ua->argv[i]);
+ if (client) {
+ catalog = client->catalog;
+ if (ua->catalog && ua->catalog != catalog) {
+ close_db(ua);
+ }
+ if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) {
+ ua->error_msg(_("No authorization for Catalog \"%s\"\n"), catalog->name());
+ return false;
+ }
+ ua->catalog = catalog;
+ return open_db(ua);
+ }
+ }
+
+ /* Try for Job keyword */
+ i = find_arg_with_value(ua, NT_("job"));
+ if (i >= 0) {
+ if (!acl_access_ok(ua, Job_ACL, ua->argv[i])) {
+ ua->error_msg(_("No authorization for Job \"%s\"\n"), ua->argv[i]);
+ return false;
+ }
+ job = GetJobResWithName(ua->argv[i]);
+ if (job) {
+ catalog = job->client->catalog;
+ if (ua->catalog && ua->catalog != catalog) {
+ close_db(ua);
+ }
+ if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) {
+ ua->error_msg(_("No authorization for Catalog \"%s\"\n"), catalog->name());
+ return false;
+ }
+ ua->catalog = catalog;
+ return open_db(ua);
+ }
+ }
+
+ return open_db(ua);
+}