3 * Bacula Director -- User Agent Input and scanning code
5 * Kern Sibbald, October MMI
11 Copyright (C) 2000-2003 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34 /* Imported variables */
37 /* Exported functions */
39 int get_cmd(UAContext *ua, char *prompt)
41 BSOCK *sock = ua->UA_sock;
45 if (!sock) { /* No UA */
48 bnet_fsend(sock, "%s", prompt);
49 bnet_sig(sock, BNET_PROMPT); /* request more input */
51 stat = bnet_recv(sock);
52 if (stat == BNET_SIGNAL) {
53 continue; /* ignore signals */
55 if (is_bnet_stop(sock)) {
56 return 0; /* error or terminate */
58 ua->cmd = check_pool_memory_size(ua->cmd, sock->msglen+1);
59 bstrncpy(ua->cmd, sock->msg, sock->msglen+1);
60 strip_trailing_junk(ua->cmd);
61 if (strcmp(ua->cmd, ".messages") == 0) {
62 qmessagescmd(ua, ua->cmd);
64 /* Lone dot => break */
65 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
74 * Get a positive integer
75 * Returns: 0 if failure
76 * 1 if success => value in ua->pint32_val
78 int get_pint(UAContext *ua, char *prompt)
83 if (!get_cmd(ua, prompt)) {
86 if (!is_a_number(ua->cmd)) {
87 bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
91 dval = strtod(ua->cmd, NULL);
92 if (errno != 0 || dval < 0) {
93 bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
96 ua->pint32_val = (uint32_t)dval;
102 * Gets a yes or no response
103 * Returns: 0 if failure
104 * 1 if success => ua->pint32_val == 1 for yes
105 * ua->pint32_val == 0 for no
107 int get_yesno(UAContext *ua, char *prompt)
113 if (!get_cmd(ua, prompt)) {
116 len = strlen(ua->cmd);
117 if (len < 1 || len > 3) {
120 if (strncasecmp(ua->cmd, _("yes"), len) == 0) {
124 if (strncasecmp(ua->cmd, _("no"), len) == 0) {
127 bsendmsg(ua, _("Invalid response. You must answer yes or no.\n"));
132 void parse_ua_args(UAContext *ua)
134 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);