3 * Bacula Director -- User Agent Input and scanning code
5 * Kern Sibbald, October MMI
9 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of
14 the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public
22 License along with this program; if not, write to the Free
23 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 /* Imported variables */
36 /* Exported functions */
38 int get_cmd(UAContext *ua, char *prompt)
40 BSOCK *sock = ua->UA_sock;
43 if (!sock) { /* No UA */
46 bnet_fsend(sock, "%s", prompt);
47 bnet_sig(sock, BNET_PROMPT); /* request more input */
49 if (bnet_recv(sock) < 0) {
52 ua->cmd = (char *) check_pool_memory_size(ua->cmd, sock->msglen+1);
53 strcpy(ua->cmd, sock->msg);
54 ua->cmd[sock->msglen] = 0;
55 strip_trailing_junk(ua->cmd);
56 if (strcmp(ua->cmd, ".messages") == 0) {
57 qmessagescmd(ua, ua->cmd);
59 /* ****FIXME**** if .command, go off and do it. For now ignore it. */
60 if (ua->cmd[0] == '.' && ua->cmd[1] != 0) {
61 continue; /* dot command */
63 /* Lone dot => break or actual response */
70 * Return next argument from command line. Note, this
71 * routine is destructive.
73 char *next_arg(char **s)
77 /* skip past spaces to next arg */
78 for (p=*s; *p && *p == ' '; p++)
80 /* Determine start of argument */
82 n = p+1; /* skip leading quote */
86 /* Scan argment and terminate it */
87 for ( ; *p && *p != ' '; p++) {
89 for (p++; *p && *p != '"'; p++) {
96 if (*p) { /* if more arguments */
97 *p++ = 0; /* terminate this one */
104 * This routine parses the input command line.
105 * It makes a copy in args, then builds an
106 * argc, argv like list where
108 * argc = count of arguments
109 * argk[i] = argument keyword (part preceding =)
110 * argv[i] = argument value (part after =)
112 * example: arg1 arg2=abc arg3=
123 void parse_command_args(UAContext *ua)
125 BSOCK *sock = ua->UA_sock;
129 ua->args = (char *) check_pool_memory_size(ua->args, sock->msglen+1);
130 strcpy(ua->args, sock->msg);
131 ua->args[sock->msglen] = 0;
132 strip_trailing_junk(ua->args);
135 /* Pick up all arguments */
136 while (ua->argc < MAX_ARGS) {
139 ua->argk[ua->argc++] = n;
144 /* Separate keyword and value */
145 for (i=0; i<ua->argc; i++) {
146 p = strchr(ua->argk[i], '=');
148 *p++ = 0; /* terminate keyword and point to value */
149 if (strlen(p) > MAX_NAME_LENGTH-1) {
150 p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */
153 ua->argv[i] = p; /* save ptr to value or NULL */
156 for (i=0; i<ua->argc; i++) {
157 Dmsg3(000, "Arg %d: kw=%s val=%s\n", i,
158 ua->argk[i], ua->argv[i]?ua->argv[i]:"NULL");