3 * Bacula Director -- User Agent Commands
4 * These are "dot" commands, i.e. commands preceded
5 * by a period. These commands are meant to be used
6 * by a program, so there is no prompting, and the
7 * returned results are (supposed to be) predictable.
9 * Kern Sibbald, April MMII
15 Copyright (C) 2002 Kern Sibbald and John Walker
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of
20 the License, or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public
28 License along with this program; if not, write to the Free
29 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
38 /* Imported variables */
41 extern struct s_res resources[];
42 extern char my_name[];
44 /* Imported functions */
45 extern int qmessagescmd(UAContext *ua, char *cmd);
46 extern int quitcmd(UAContext *ua, char *cmd);
48 /* Forward referenced functions */
49 static int diecmd(UAContext *ua, char *cmd);
50 static int jobscmd(UAContext *ua, char *cmd);
51 static int filesetscmd(UAContext *ua, char *cmd);
52 static int clientscmd(UAContext *ua, char *cmd);
53 static int msgscmd(UAContext *ua, char *cmd);
55 struct cmdstruct { char *key; int (*func)(UAContext *ua, char *cmd); char *help; };
56 static struct cmdstruct commands[] = {
57 { N_(".die"), diecmd, NULL},
58 { N_(".jobs"), jobscmd, NULL},
59 { N_(".filesets"), filesetscmd, NULL},
60 { N_(".clients"), clientscmd, NULL},
61 { N_(".msgs"), msgscmd, NULL},
62 { N_(".messages"), qmessagescmd, NULL},
63 { N_(".quit"), quitcmd, NULL},
64 { N_(".exit"), quitcmd, NULL}
66 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
69 * Execute a command from the UA
71 int do_a_dot_command(UAContext *ua, char *cmd)
80 Dmsg1(200, "Dot command: %s\n", ua->UA_sock->msg);
85 len = strlen(ua->argk[0]);
89 for (i=0; i<comsize; i++) { /* search for command */
90 if (strncasecmp(ua->argk[0], _(commands[i].key), len) == 0) {
91 stat = (*commands[i].func)(ua, cmd); /* go execute command */
97 strcat(ua->UA_sock->msg, _(": is an illegal command\n"));
98 ua->UA_sock->msglen = strlen(ua->UA_sock->msg);
99 bnet_send(ua->UA_sock);
105 * Create segmentation fault
107 static int diecmd(UAContext *ua, char *cmd)
112 a = jcr->JobId; /* ref NULL pointer */
116 static int jobscmd(UAContext *ua, char *cmd)
120 while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
121 bsendmsg(ua, "%s\n", job->hdr.name);
127 static int filesetscmd(UAContext *ua, char *cmd)
131 while ( (fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs)) ) {
132 bsendmsg(ua, "%s\n", fs->hdr.name);
138 static int clientscmd(UAContext *ua, char *cmd)
140 CLIENT *client = NULL;
142 while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) {
143 bsendmsg(ua, "%s\n", client->hdr.name);
149 static int msgscmd(UAContext *ua, char *cmd)
153 while ( (msgs = (MSGS *)GetNextRes(R_MSGS, (RES *)msgs)) ) {
154 bsendmsg(ua, "%s\n", msgs->hdr.name);