3 * Bacula Director -- User Agent Input and scanning code
5 * Kern Sibbald, October MMI
10 Copyright (C) 2001-2005 Kern Sibbald
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 the file LICENSE for additional details.
28 /* Imported variables */
31 /* Exported functions */
33 int get_cmd(UAContext *ua, const char *prompt)
35 BSOCK *sock = ua->UA_sock;
39 if (!sock) { /* No UA */
42 bnet_fsend(sock, "%s", prompt);
43 bnet_sig(sock, BNET_PROMPT); /* request more input */
45 stat = bnet_recv(sock);
46 if (stat == BNET_SIGNAL) {
47 continue; /* ignore signals */
49 if (is_bnet_stop(sock)) {
50 return 0; /* error or terminate */
52 pm_strcpy(ua->cmd, sock->msg);
53 strip_trailing_junk(ua->cmd);
54 if (strcmp(ua->cmd, ".messages") == 0) {
55 qmessagescmd(ua, ua->cmd);
57 /* Lone dot => break */
58 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
67 * Get a positive integer
68 * Returns: false if failure
69 * true if success => value in ua->pint32_val
71 bool get_pint(UAContext *ua, const char *prompt)
78 if (!get_cmd(ua, prompt)) {
81 /* Kludge for slots blank line => 0 */
82 if (ua->cmd[0] == 0 && strncmp(prompt, _("Enter slot"), strlen(_("Enter slot"))) == 0) {
85 if (!is_a_number(ua->cmd)) {
86 bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd);
90 dval = strtod(ua->cmd, NULL);
91 if (errno != 0 || dval < 0) {
92 bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd);
95 ua->pint32_val = (uint32_t)dval;
96 ua->int64_val = (int64_t)dval;
102 * Test a yes or no response
103 * Returns: false if failure
104 * true if success => ret == 1 for yes
107 bool is_yesno(char *val, int *ret)
110 if ((strcasecmp(val, _("yes")) == 0) ||
111 (strcasecmp(val, NT_("yes")) == 0))
114 } else if ((strcasecmp(val, _("no")) == 0) ||
115 (strcasecmp(val, NT_("no")) == 0))
126 * Gets a yes or no response
127 * Returns: false if failure
128 * true if success => ua->pint32_val == 1 for yes
129 * ua->pint32_val == 0 for no
131 bool get_yesno(UAContext *ua, const char *prompt)
137 if (!get_cmd(ua, prompt)) {
140 len = strlen(ua->cmd);
141 if (len < 1 || len > 3) {
144 if (is_yesno(ua->cmd, &ret)) {
145 ua->pint32_val = ret;
148 bsendmsg(ua, _("Invalid response. You must answer yes or no.\n"));
153 * Gets an Enabled value => 0, 1, 2, yes, no, archived
154 * Returns: 0, 1, 2 if OK
157 int get_enabled(UAContext *ua, const char *val)
161 if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
163 } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
165 } else if (strcasecmp(val, "archived") == 0) {
170 if (Enabled < 0 || Enabled > 2) {
171 bsendmsg(ua, _("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
177 void parse_ua_args(UAContext *ua)
179 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);