2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Bacula Director -- User Agent Input and scanning code
23 * Kern Sibbald, October MMI
31 /* Imported variables */
34 /* Exported functions */
37 * If subprompt is set, we send a BNET_SUB_PROMPT signal otherwise
38 * send a BNET_TEXT_INPUT signal.
40 bool get_cmd(UAContext *ua, const char *prompt, bool subprompt)
42 BSOCK *sock = ua->UA_sock;
46 if (!sock || ua->batch) { /* No UA or batch mode */
49 if (!subprompt && ua->api) {
50 sock->signal(BNET_TEXT_INPUT);
52 sock->fsend("%s", prompt);
53 if (!ua->api || subprompt) {
54 sock->signal(BNET_SUB_PROMPT);
58 if (stat == BNET_SIGNAL) {
59 continue; /* ignore signals */
61 if (sock->is_stop()) {
62 return false; /* error or terminate */
64 pm_strcpy(ua->cmd, sock->msg);
65 strip_trailing_junk(ua->cmd);
66 if (strcmp(ua->cmd, ".messages") == 0) {
67 qmessagescmd(ua, ua->cmd);
69 /* Lone dot => break */
70 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
79 * Get a selection list
80 * We get a command from the user, scan it, then
85 bool get_selection_list(UAContext *ua, sellist &sl,
86 const char *prompt, bool subprompt)
89 if (!get_cmd(ua, prompt, subprompt)) {
92 if (!sl.set_string(ua->cmd, true)) {
93 ua->send_msg("%s", sl.get_errmsg());
101 * Get a positive integer
102 * Returns: false if failure
103 * true if success => value in ua->pint32_val
105 bool get_pint(UAContext *ua, const char *prompt)
112 if (!get_cmd(ua, prompt)) {
115 /* Kludge for slots blank line => 0 */
116 if (ua->cmd[0] == 0 && strncmp(prompt, _("Enter slot"), strlen(_("Enter slot"))) == 0) {
119 if (!is_a_number(ua->cmd)) {
120 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
124 dval = strtod(ua->cmd, NULL);
125 if (errno != 0 || dval < 0) {
126 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
129 ua->pint32_val = (uint32_t)dval;
130 ua->int64_val = (int64_t)dval;
136 * Test a yes or no response
137 * Returns: false if failure
138 * true if success => ret == 1 for yes
141 bool is_yesno(char *val, int *ret)
144 if ((strcasecmp(val, _("yes")) == 0) ||
145 (strcasecmp(val, NT_("yes")) == 0))
148 } else if ((strcasecmp(val, _("no")) == 0) ||
149 (strcasecmp(val, NT_("no")) == 0))
160 * Gets a yes or no response
161 * Returns: false if failure
162 * true if success => ua->pint32_val == 1 for yes
163 * ua->pint32_val == 0 for no
165 bool get_yesno(UAContext *ua, const char *prompt)
171 if (ua->api) ua->UA_sock->signal(BNET_YESNO);
172 if (!get_cmd(ua, prompt)) {
175 len = strlen(ua->cmd);
176 if (len < 1 || len > 3) {
179 if (is_yesno(ua->cmd, &ret)) {
180 ua->pint32_val = ret;
183 ua->warning_msg(_("Invalid response. You must answer yes or no.\n"));
188 * Gets an Enabled value => 0, 1, 2, yes, no, archived
189 * Returns: 0, 1, 2 if OK
192 int get_enabled(UAContext *ua, const char *val)
196 if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
198 } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
200 } else if (strcasecmp(val, "archived") == 0) {
205 if (Enabled < 0 || Enabled > 2) {
206 ua->error_msg(_("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
212 void parse_ua_args(UAContext *ua)
214 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);
218 * Check if the comment has legal characters
219 * If ua is non-NULL send the message
221 bool is_comment_legal(UAContext *ua, const char *name)
225 const char *forbid = "'<>&\\\"";
227 /* Restrict the characters permitted in the comment */
228 for (p=name; *p; p++) {
229 if (!strchr(forbid, (int)(*p))) {
233 ua->error_msg(_("Illegal character \"%c\" in a comment.\n"), *p);
238 if (len >= MAX_NAME_LENGTH) {
240 ua->error_msg(_("Comment too long.\n"));
246 ua->error_msg(_("Comment must be at least one character long.\n"));