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 bnet_fsend(sock, "%s", prompt);
44 bnet_sig(sock, BNET_PROMPT); /* request more input */
46 if (bnet_recv(sock) < 0) {
49 ua->cmd = (char *) check_pool_memory_size(ua->cmd, sock->msglen+1);
50 strcpy(ua->cmd, sock->msg);
51 ua->cmd[sock->msglen] = 0;
52 strip_trailing_junk(ua->cmd);
53 if (strcmp(ua->cmd, ".messages") == 0) {
54 qmessagescmd(ua, ua->cmd);
56 /* ****FIXME**** if .command, go off and do it. For now ignore it. */
57 if (ua->cmd[0] == '.' && ua->cmd[1] != 0) {
58 continue; /* dot command */
60 /* Lone dot => break or actual response */
67 * Return next argument from command line. Note, this
68 * routine is destructive.
70 char *next_arg(char **s)
74 /* skip past spaces to next arg */
75 for (p=*s; *p && *p == ' '; p++)
77 /* Determine start of argument */
79 n = p+1; /* skip leading quote */
83 /* Scan argment and terminate it */
84 for ( ; *p && *p != ' '; p++) {
86 for (p++; *p && *p != '"'; p++) {
93 if (*p) { /* if more arguments */
94 *p++ = 0; /* terminate this one */
101 * This routine parses the input command line.
102 * It makes a copy in args, then builds an
103 * argc, argv like list where
105 * argc = count of arguments
106 * argk[i] = argument keyword (part preceding =)
107 * argv[i] = argument value (part after =)
109 * example: arg1 arg2=abc arg3=
120 void parse_command_args(UAContext *ua)
122 BSOCK *sock = ua->UA_sock;
126 ua->args = (char *) check_pool_memory_size(ua->args, sock->msglen+1);
127 strcpy(ua->args, sock->msg);
128 ua->args[sock->msglen] = 0;
129 strip_trailing_junk(ua->args);
132 /* Pick up all arguments */
133 while (ua->argc < MAX_ARGS) {
136 ua->argk[ua->argc++] = n;
141 /* Separate keyword and value */
142 for (i=0; i<ua->argc; i++) {
143 p = strchr(ua->argk[i], '=');
145 *p++ = 0; /* terminate keyword and point to value */
146 if (strlen(p) > MAX_NAME_LENGTH-1) {
147 p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */
150 ua->argv[i] = p; /* save ptr to value or NULL */
153 for (i=0; i<ua->argc; i++) {
154 Dmsg3(000, "Arg %d: kw=%s val=%s\n", i,
155 ua->argk[i], ua->argv[i]?ua->argv[i]:"NULL");