2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Bacula Director -- User Agent Input and scanning code
32 * Kern Sibbald, October MMI
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 sock->fsend("%s", prompt);
56 sock->signal(BNET_PROMPT); /* request more input */
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 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
103 dval = strtod(ua->cmd, NULL);
104 if (errno != 0 || dval < 0) {
105 ua->warning_msg(_("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 ua->warning_msg(_("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 ua->error_msg(_("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);