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 * Gets a yes or no response
103 * Returns: false if failure
104 * true if success => ua->pint32_val == 1 for yes
105 * ua->pint32_val == 0 for no
107 bool get_yesno(UAContext *ua, const 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);