]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_dotcmds.c
Massive SD calling sequence reorganization
[bacula/bacula] / bacula / src / dird / ua_dotcmds.c
index 3ecd6eb39e30f475316a31f8facfb28bcf923e9f..291613ccb79950b6ec6023dd943a26177d7bad05 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 /*
-   Copyright (C) 2002 Kern Sibbald and John Walker
+   Copyright (C) 2002-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
 
 #include "bacula.h"
 #include "dird.h"
-#include "ua.h"
 
 /* Imported variables */
 extern int r_first;
 extern int r_last;
 extern struct s_res resources[];
-extern int console_msg_pending;
-extern FILE *con_fd;
 extern char my_name[];
+extern const char *client_backups;
 
 /* Imported functions */
-extern int qmessagescmd(UAContext *ua, char *cmd);
-extern int quitcmd(UAContext *ua, char *cmd);
+extern int qmessagescmd(UAContext *ua, const char *cmd);
+extern int quit_cmd(UAContext *ua, const char *cmd);
+extern int qhelp_cmd(UAContext *ua, const char *cmd);
+extern int qstatus_cmd(UAContext *ua, const char *cmd);
 
 /* Forward referenced functions */
-static int diecmd(UAContext *ua, char *cmd);
-static int jobscmd(UAContext *ua, char *cmd);
-static int filesetscmd(UAContext *ua, char *cmd);
-static int clientscmd(UAContext *ua, char *cmd);
-static int msgscmd(UAContext *ua, char *cmd);
+static int diecmd(UAContext *ua, const char *cmd);
+static int jobscmd(UAContext *ua, const char *cmd);
+static int filesetscmd(UAContext *ua, const char *cmd);
+static int clientscmd(UAContext *ua, const char *cmd);
+static int msgscmd(UAContext *ua, const char *cmd);
+static int poolscmd(UAContext *ua, const char *cmd);
+static int storagecmd(UAContext *ua, const char *cmd);
+static int defaultscmd(UAContext *ua, const char *cmd);
+static int typescmd(UAContext *ua, const char *cmd);
+static int backupscmd(UAContext *ua, const char *cmd);
+static int levelscmd(UAContext *ua, const char *cmd);
 
-struct cmdstruct { char *key; int (*func)(UAContext *ua, char *cmd); char *help; }; 
+struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; }; 
 static struct cmdstruct commands[] = {
  { N_(".die"),        diecmd,       NULL},
  { N_(".jobs"),       jobscmd,      NULL},
  { N_(".filesets"),   filesetscmd,  NULL},
  { N_(".clients"),    clientscmd,   NULL},
  { N_(".msgs"),       msgscmd,      NULL},
+ { N_(".pools"),      poolscmd,     NULL},
+ { N_(".types"),      typescmd,     NULL},
+ { N_(".backups"),    backupscmd,   NULL},
+ { N_(".levels"),     levelscmd,    NULL},
+ { N_(".status"),     qstatus_cmd,  NULL},
+ { N_(".storage"),    storagecmd,   NULL},
+ { N_(".defaults"),   defaultscmd,  NULL},
  { N_(".messages"),   qmessagescmd, NULL},
- { N_(".quit"),       quitcmd,      NULL},
- { N_(".exit"),       quitcmd,      NULL} 
+ { N_(".help"),       qhelp_cmd,    NULL},
+ { N_(".quit"),       quit_cmd,     NULL},
+ { N_(".exit"),       quit_cmd,     NULL} 
             };
 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
 
 /*
  * Execute a command from the UA
  */
-int do_a_dot_command(UAContext *ua, char *cmd)
+int do_a_dot_command(UAContext *ua, const char *cmd)
 {
-   unsigned int i;
+   int i;
    int len, stat;  
-   int found;
+   bool found = false;
 
-   found = 0;
    stat = 1;
 
-   Dmsg1(200, "Dot command: %s\n", ua->UA_sock->msg);
+   Dmsg1(400, "Dot command: %s\n", ua->UA_sock->msg);
    if (ua->argc == 0) {
       return 1;
    }
@@ -88,15 +101,15 @@ int do_a_dot_command(UAContext *ua, char *cmd)
    if (len == 1) {
       return 1;                      /* no op */
    }
-   for (i=0; i<comsize; i++) {    /* search for command */
+   for (i=0; i<(int)comsize; i++) {    /* search for command */
       if (strncasecmp(ua->argk[0],  _(commands[i].key), len) == 0) {
         stat = (*commands[i].func)(ua, cmd);   /* go execute command */
-        found = 1;
+        found = true;
         break;
       }
    }
    if (!found) {
-      strcat(ua->UA_sock->msg, _(": is an illegal command\n"));
+      pm_strcat(ua->UA_sock->msg, _(": is an illegal command\n"));
       ua->UA_sock->msglen = strlen(ua->UA_sock->msg);
       bnet_send(ua->UA_sock);
    }
@@ -106,16 +119,18 @@ int do_a_dot_command(UAContext *ua, char *cmd)
 /*
  * Create segmentation fault 
  */
-static int diecmd(UAContext *ua, char *cmd)
+static int diecmd(UAContext *ua, const char *cmd)
 {
    JCR *jcr = NULL;
    int a;
    
+   bsendmsg(ua, "The Director will segment fault.\n");
    a = jcr->JobId; /* ref NULL pointer */
+   jcr->JobId = 1000; /* another ref NULL pointer */
    return 0;
 }
 
-static int jobscmd(UAContext *ua, char *cmd)
+static int jobscmd(UAContext *ua, const char *cmd)
 {
    JOB *job = NULL;
    LockRes();
@@ -126,7 +141,7 @@ static int jobscmd(UAContext *ua, char *cmd)
    return 1;
 }
 
-static int filesetscmd(UAContext *ua, char *cmd)
+static int filesetscmd(UAContext *ua, const char *cmd)
 {
    FILESET *fs = NULL;
    LockRes();
@@ -137,7 +152,7 @@ static int filesetscmd(UAContext *ua, char *cmd)
    return 1;
 }
 
-static int clientscmd(UAContext *ua, char *cmd)
+static int clientscmd(UAContext *ua, const char *cmd)
 {
    CLIENT *client = NULL;
    LockRes();
@@ -148,7 +163,7 @@ static int clientscmd(UAContext *ua, char *cmd)
    return 1;
 }
 
-static int msgscmd(UAContext *ua, char *cmd)
+static int msgscmd(UAContext *ua, const char *cmd)
 {
    MSGS *msgs = NULL;
    LockRes();
@@ -158,3 +173,98 @@ static int msgscmd(UAContext *ua, char *cmd)
    UnlockRes();
    return 1;
 }
+
+static int poolscmd(UAContext *ua, const char *cmd)
+{
+   POOL *pool = NULL;
+   LockRes();
+   while ( (pool = (POOL *)GetNextRes(R_POOL, (RES *)pool)) ) {
+      bsendmsg(ua, "%s\n", pool->hdr.name);
+   }
+   UnlockRes();
+   return 1;
+}
+
+static int storagecmd(UAContext *ua, const char *cmd)
+{
+   STORE *store = NULL;
+   LockRes();
+   while ( (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)) ) {
+      bsendmsg(ua, "%s\n", store->hdr.name);
+   }
+   UnlockRes();
+   return 1;
+}
+
+
+static int typescmd(UAContext *ua, const char *cmd)
+{
+   bsendmsg(ua, "Backup\n");
+   bsendmsg(ua, "Restore\n");
+   bsendmsg(ua, "Admin\n");
+   bsendmsg(ua, "Verify\n");
+   return 1;
+}
+
+static int client_backups_handler(void *ctx, int num_field, char **row)
+{
+   UAContext *ua = (UAContext *)ctx;
+   bsendmsg(ua, "| %s | %s | %s | %s | %s | %s | %s |\n",
+      row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
+   return 0;
+}
+
+static int backupscmd(UAContext *ua, const char *cmd)
+{
+   if (!open_db(ua)) {
+      return 1;
+   }
+   if (ua->argc == 2 && strcmp(ua->argk[1], "client") != 0) {
+      return 1;
+   }
+   Mmsg(ua->cmd, client_backups, ua->argv[1]);
+   if (!db_sql_query(ua->db, ua->cmd, client_backups_handler, (void *)ua)) {
+      bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), ua->cmd, db_strerror(ua->db));
+      return 1;
+   }
+   return 1;
+}
+
+
+static int levelscmd(UAContext *ua, const char *cmd)
+{
+   bsendmsg(ua, "Incremental\n");
+   bsendmsg(ua, "Full\n");
+   bsendmsg(ua, "Differential\n");
+   bsendmsg(ua, "Catalog\n");
+   bsendmsg(ua, "InitCatalog\n");
+   bsendmsg(ua, "VolumeToCatalog\n");
+   return 1;
+}
+
+
+
+/*
+ * Return default values for a job
+ */
+static int defaultscmd(UAContext *ua, const char *cmd)
+{
+   JOB *job;      
+   if (ua->argc == 2 && strcmp(ua->argk[1], "job") == 0) {
+      job = (JOB *)GetResWithName(R_JOB, ua->argv[1]);
+      if (job) {
+        STORE *store;
+         bsendmsg(ua, "job=%s", job->hdr.name);
+         bsendmsg(ua, "pool=%s", job->pool->hdr.name);
+         bsendmsg(ua, "messages=%s", job->messages->hdr.name);
+         bsendmsg(ua, "client=%s", job->client->hdr.name);
+        store = (STORE *)job->storage[0]->first();
+         bsendmsg(ua, "storage=%s", store->hdr.name);
+         bsendmsg(ua, "where=%s", job->RestoreWhere?job->RestoreWhere:"");
+         bsendmsg(ua, "level=%s", level_to_str(job->JobLevel));
+         bsendmsg(ua, "type=%s", job_type_to_str(job->JobType));
+         bsendmsg(ua, "fileset=%s", job->fileset->hdr.name);
+      }
+   }
+   return 1;
+}