* Bacula Director -- User Agent Input and scanning code
*
* Kern Sibbald, October MMI
+ *
+ * Version $Id$
*/
/*
BSOCK *sock = ua->UA_sock;
ua->cmd[0] = 0;
+ if (!sock) { /* No UA */
+ return 0;
+ }
bnet_fsend(sock, "%s", prompt);
bnet_sig(sock, BNET_PROMPT); /* request more input */
- if (bnet_recv(sock) < 0) {
- return 0;
+ for ( ;; ) {
+ if (bnet_recv(sock) <= 0) {
+ return 0;
+ }
+ ua->cmd = check_pool_memory_size(ua->cmd, sock->msglen+1);
+ bstrncpy(ua->cmd, sock->msg, sock->msglen+1);
+ strip_trailing_junk(ua->cmd);
+ if (strcmp(ua->cmd, ".messages") == 0) {
+ qmessagescmd(ua, ua->cmd);
+ }
+ /* ****FIXME**** if .command, go off and do it. For now ignore it. */
+ if (ua->cmd[0] == '.' && ua->cmd[1] != 0) {
+ continue; /* dot command */
+ }
+ /* Lone dot => break or actual response */
+ break;
}
- ua->cmd = (char *) check_pool_memory_size(ua->cmd, sock->msglen+1);
- strcpy(ua->cmd, sock->msg);
- ua->cmd[sock->msglen] = 0;
- strip_trailing_junk(ua->cmd);
return 1;
}
*/
char *next_arg(char **s)
{
- char *p, *n;
+ char *p, *q, *n;
+ Dmsg1(400, "Next arg=%s\n", *s);
/* skip past spaces to next arg */
- for (p=*s; *p && *p == ' '; p++)
- {}
+ for (p=*s; *p && *p == ' '; ) {
+ p++;
+ }
/* Determine start of argument */
if (*p == '"') {
- n = p+1; /* skip leading quote */
+ Dmsg0(400, "Start with quote.\n");
+ for (n = q = ++p; *p && *p != '"'; ) {
+ if (*p == '\\') {
+ p++;
+ }
+ *q++ = *p++;
+ }
+ p++; /* skip terminating quote */
+ for ( ; *p && *p != ' '; ) {
+ *q++ = *p++;
+ }
+ *q = 0;
} else {
+ /* Scan argment and terminate it */
n = p;
- }
- /* Scan argment and terminate it */
- for ( ; *p && *p != ' '; p++) {
- if (*p == '"') {
- for (p++; *p && *p != '"'; p++) {
- *(p-1) = *p;
- *p = 0;
- }
- break;
+ for ( ; *p && *p != ' '; ) {
+ p++;
+ }
+ if (*p == ' ') {
+ *p++ = 0;
}
- }
- if (*p) { /* if more arguments */
- *p++ = 0; /* terminate this one */
}
*s = p;
+ Dmsg2(400, "End arg=%s next=%s\n", n, p);
return n;
}
void parse_command_args(UAContext *ua)
{
- BSOCK *sock = ua->UA_sock;
- char *p, *n;
- int i;
+ char *p, *q, *n;
+ int i, len;
- ua->args = (char *) check_pool_memory_size(ua->args, sock->msglen+1);
- strcpy(ua->args, sock->msg);
- ua->args[sock->msglen] = 0;
+ len = strlen(ua->cmd) + 1;
+ ua->args = check_pool_memory_size(ua->args, len);
+ bstrncpy(ua->args, ua->cmd, len);
strip_trailing_junk(ua->args);
ua->argc = 0;
p = ua->args;
p = strchr(ua->argk[i], '=');
if (p) {
*p++ = 0; /* terminate keyword and point to value */
+ /* Unquote quoted values */
+ if (*p == '"') {
+ Dmsg0(400, "Start with quote.\n");
+ for (n = q = ++p; *p && *p != '"'; ) {
+ if (*p == '\\') {
+ p++;
+ }
+ *q++ = *p++;
+ }
+ p++; /* skip terminating quote */
+ for ( ; *p && *p != ' '; ) {
+ *q++ = *p++;
+ }
+ *q = 0;
+ p = n;
+ }
if (strlen(p) > MAX_NAME_LENGTH-1) {
p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */
}
}
ua->argv[i] = p; /* save ptr to value or NULL */
}
-#ifdef xxxxxxxxx
+#ifdef xxxx
for (i=0; i<ua->argc; i++) {
Dmsg3(000, "Arg %d: kw=%s val=%s\n", i,
ua->argk[i], ua->argv[i]?ua->argv[i]:"NULL");