3 * Bacula Director -- User Agent Input and scanning code
5 * Kern Sibbald, October MMI
10 Bacula® - The Network Backup Solution
12 Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
14 The main author of Bacula is Kern Sibbald, with contributions from
15 many others, a complete list can be found in the file AUTHORS.
16 This program is Free Software; you can redistribute it and/or
17 modify it under the terms of version two of the GNU General Public
18 License as published by the Free Software Foundation plus additions
19 that are listed in the file LICENSE.
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 Bacula® is a registered trademark of John Walker.
32 The licensor of Bacula is the Free Software Foundation Europe
33 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34 Switzerland, email:ftf@fsfeurope.org.
41 /* Imported variables */
44 /* Exported functions */
46 int get_cmd(UAContext *ua, const char *prompt)
48 BSOCK *sock = ua->UA_sock;
52 if (!sock) { /* No UA */
55 bnet_fsend(sock, "%s", prompt);
56 bnet_sig(sock, BNET_PROMPT); /* request more input */
58 stat = bnet_recv(sock);
59 if (stat == BNET_SIGNAL) {
60 continue; /* ignore signals */
62 if (is_bnet_stop(sock)) {
63 return 0; /* error or terminate */
65 pm_strcpy(ua->cmd, sock->msg);
66 strip_trailing_junk(ua->cmd);
67 if (strcmp(ua->cmd, ".messages") == 0) {
68 qmessagescmd(ua, ua->cmd);
70 /* Lone dot => break */
71 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
80 * Get a positive integer
81 * Returns: false if failure
82 * true if success => value in ua->pint32_val
84 bool get_pint(UAContext *ua, const char *prompt)
91 if (!get_cmd(ua, prompt)) {
94 /* Kludge for slots blank line => 0 */
95 if (ua->cmd[0] == 0 && strncmp(prompt, _("Enter slot"), strlen(_("Enter slot"))) == 0) {
98 if (!is_a_number(ua->cmd)) {
99 bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd);
103 dval = strtod(ua->cmd, NULL);
104 if (errno != 0 || dval < 0) {
105 bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd);
108 ua->pint32_val = (uint32_t)dval;
109 ua->int64_val = (int64_t)dval;
115 * Test a yes or no response
116 * Returns: false if failure
117 * true if success => ret == 1 for yes
120 bool is_yesno(char *val, int *ret)
123 if ((strcasecmp(val, _("yes")) == 0) ||
124 (strcasecmp(val, NT_("yes")) == 0))
127 } else if ((strcasecmp(val, _("no")) == 0) ||
128 (strcasecmp(val, NT_("no")) == 0))
139 * Gets a yes or no response
140 * Returns: false if failure
141 * true if success => ua->pint32_val == 1 for yes
142 * ua->pint32_val == 0 for no
144 bool get_yesno(UAContext *ua, const char *prompt)
150 if (!get_cmd(ua, prompt)) {
153 len = strlen(ua->cmd);
154 if (len < 1 || len > 3) {
157 if (is_yesno(ua->cmd, &ret)) {
158 ua->pint32_val = ret;
161 bsendmsg(ua, _("Invalid response. You must answer yes or no.\n"));
166 * Gets an Enabled value => 0, 1, 2, yes, no, archived
167 * Returns: 0, 1, 2 if OK
170 int get_enabled(UAContext *ua, const char *val)
174 if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
176 } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
178 } else if (strcasecmp(val, "archived") == 0) {
183 if (Enabled < 0 || Enabled > 2) {
184 bsendmsg(ua, _("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
190 void parse_ua_args(UAContext *ua)
192 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);