+static void do_storage_status(UAContext *ua, STORE *store, char *cmd);
+static void do_client_status(UAContext *ua, CLIENT *client, char *cmd);
+static void do_director_status(UAContext *ua);
+static void do_all_status(UAContext *ua);
+
+static char OKqstatus[] = "1000 OK .status\n";
+static char DotStatusJob[] = "JobId=%s JobStatus=%c JobErrors=%d\n";
+
+/*
+ * .status command
+ */
+
+bool dot_status_cmd(UAContext *ua, const char *cmd)
+{
+ STORE *store;
+ CLIENT *client;
+ JCR* njcr = NULL;
+ s_last_job* job;
+ char ed1[50];
+
+ Dmsg2(20, "status=\"%s\" argc=%d\n", cmd, ua->argc);
+
+ if (ua->argc < 3) {
+ ua->send_msg("1900 Bad .status command, missing arguments.\n");
+ return false;
+ }
+
+ if (strcasecmp(ua->argk[1], "dir") == 0) {
+ if (strcasecmp(ua->argk[2], "current") == 0) {
+ ua->send_msg(OKqstatus, ua->argk[2]);
+ foreach_jcr(njcr) {
+ if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) {
+ ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1),
+ njcr->JobStatus, njcr->JobErrors);
+ }
+ }
+ endeach_jcr(njcr);
+ } else if (strcasecmp(ua->argk[2], "last") == 0) {
+ ua->send_msg(OKqstatus, ua->argk[2]);
+ if ((last_jobs) && (last_jobs->size() > 0)) {
+ job = (s_last_job*)last_jobs->last();
+ if (acl_access_ok(ua, Job_ACL, job->Job)) {
+ ua->send_msg(DotStatusJob, edit_int64(job->JobId, ed1),
+ job->JobStatus, job->Errors);
+ }
+ }
+ } else if (strcasecmp(ua->argk[2], "header") == 0) {
+ list_dir_status_header(ua);
+ } else if (strcasecmp(ua->argk[2], "scheduled") == 0) {
+ list_scheduled_jobs(ua);
+ } else if (strcasecmp(ua->argk[2], "running") == 0) {
+ list_running_jobs(ua);
+ } else if (strcasecmp(ua->argk[2], "terminated") == 0) {
+ list_terminated_jobs(ua);
+ } else {
+ ua->send_msg("1900 Bad .status command, wrong argument.\n");
+ return false;
+ }
+ } else if (strcasecmp(ua->argk[1], "client") == 0) {
+ client = get_client_resource(ua);
+ if (client) {
+ Dmsg2(200, "Client=%s arg=%s\n", client->name(), NPRT(ua->argk[2]));
+ do_client_status(ua, client, ua->argk[2]);
+ }
+ } else if (strcasecmp(ua->argk[1], "storage") == 0) {
+ store = get_storage_resource(ua, false /*no default*/);
+ if (store) {
+ do_storage_status(ua, store, ua->argk[2]);
+ }
+ } else {
+ ua->send_msg("1900 Bad .status command, wrong argument.\n");
+ return false;
+ }
+
+ return true;
+}
+
+/* This is the *old* command handler, so we must return
+ * 1 or it closes the connection
+ */
+int qstatus_cmd(UAContext *ua, const char *cmd)
+{
+ dot_status_cmd(ua, cmd);
+ return 1;
+}