From: Kern Sibbald Date: Sat, 10 Mar 2007 21:04:23 +0000 (+0000) Subject: kes Extend new GUI API. X-Git-Tag: Release-7.0.0~6770 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=eb621a25daad4cdd5c2e5a15e66aff026a0d9cf7;p=bacula%2Fbacula kes Extend new GUI API. kes Make the ua structure a class, and implement send_msg(), error_msg(), warning_msg(), and info_msg(). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4342 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/console/authenticate.c b/bacula/src/console/authenticate.c index 92093e8a47..04f7c0829a 100644 --- a/bacula/src/console/authenticate.c +++ b/bacula/src/console/authenticate.c @@ -1,19 +1,7 @@ -/* - * - * Bacula UA authentication. Provides authentication with - * the Director. - * - * Kern Sibbald, June MMI - * - * This routine runs as a thread and must be thread reentrant. - * - * Basic tasks done here: - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2006 Free Software Foundation Europe e.V. + Copyright (C) 2001-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -37,6 +25,18 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula UA authentication. Provides authentication with + * the Director. + * + * Kern Sibbald, June MMI + * + * This routine runs as a thread and must be thread reentrant. + * + * Basic tasks done here: + * + */ #include "bacula.h" #include "console_conf.h" diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 07e760cef2..b01dea7b7f 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -1,15 +1,7 @@ -/* - * - * Bacula Console interface to the Director - * - * Kern Sibbald, September MM - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -33,6 +25,14 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula Console interface to the Director + * + * Kern Sibbald, September MM + * + * Version $Id$ + */ #include "bacula.h" #include "console_conf.h" @@ -520,7 +520,8 @@ try_again: /* Initialize TLS context: * Args: CA certfile, CA certdir, Certfile, Keyfile, - * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */ + * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer + */ cons->tls_ctx = new_tls_context(cons->tls_ca_certfile, cons->tls_ca_certdir, cons->tls_certfile, cons->tls_keyfile, tls_pem_callback, &buf, NULL, true); @@ -587,8 +588,8 @@ try_again: read_and_process_input(stdin, UA_sock); if (UA_sock) { - bnet_sig(UA_sock, BNET_TERMINATE); /* send EOF */ - bnet_close(UA_sock); + UA_sock->signal(BNET_TERMINATE); /* send EOF */ + UA_sock->close(); } terminate_console(0); diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 07884fcbc8..6c4fbbc892 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -210,7 +210,10 @@ int get_next_jobid_from_list(char **p, JobId_t *JobId); void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType); /* ua_server.c */ -void bsendmsg(void *sock, const char *fmt, ...); +void bsendmsg(void *ua_ctx, const char *fmt, ...); +void berrormsg(void *ua_ctx, const char *fmt, ...); +void bwarningmsg(void *ua_ctx, const char *fmt, ...); +void binfomsg(void *ua_ctx, const char *fmt, ...); UAContext *new_ua_context(JCR *jcr); JCR *new_control_jcr(const char *base_name, int job_type); void free_ua_context(UAContext *ua); diff --git a/bacula/src/dird/ua.h b/bacula/src/dird/ua.h index eb849b2189..a4145202b3 100644 --- a/bacula/src/dird/ua.h +++ b/bacula/src/dird/ua.h @@ -36,7 +36,8 @@ #ifndef __UA_H_ #define __UA_H_ 1 -struct UAContext { +class UAContext { +public: BSOCK *UA_sock; BSOCK *sd; JCR *jcr; @@ -62,6 +63,14 @@ struct UAContext { uint32_t pint32_val; /* positive integer */ int32_t int32_val; /* positive/negative */ int64_t int64_val; /* big int */ + + void signal(int sig) { UA_sock->signal(sig); }; + + /* The below are in ua_output.c */ + void send_msg(const char *fmt, ...); + void error_msg(const char *fmt, ...); + void warning_msg(const char *fmt, ...); + void info_msg(const char *fmt, ...); }; /* Context for insert_tree_handler() */ diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 48be7c785c..48f9edf27b 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -279,22 +279,27 @@ static int client_backups_handler(void *ctx, int num_field, char **row) */ static bool api_cmd(UAContext *ua, const char *cmd) { - /* Eventually we will probably have several levels or - * capabilities enabled by this. - */ - ua->api = 1; + if (ua->argc == 2) { + ua->api = atoi(ua->argk[1]); + } else { + ua->api = 1; + } return true; } /* * Return the backups for this client + * + * .backups client=xxx fileset=yyy + * */ static bool backupscmd(UAContext *ua, const char *cmd) { if (!open_client_db(ua)) { return true; } - if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 || strcmp(ua->argk[2], "fileset") != 0) { + if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 || + strcmp(ua->argk[2], "fileset") != 0) { return true; } if (!acl_access_ok(ua, Client_ACL, ua->argv[1]) || diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index 71ead60233..b5e569491f 100644 --- a/bacula/src/dird/ua_input.c +++ b/bacula/src/dird/ua_input.c @@ -96,13 +96,13 @@ bool get_pint(UAContext *ua, const char *prompt) return true; } if (!is_a_number(ua->cmd)) { - bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd); + ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd); continue; } errno = 0; dval = strtod(ua->cmd, NULL); if (errno != 0 || dval < 0) { - bsendmsg(ua, _("Expected a positive integer, got: %s\n"), ua->cmd); + ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd); continue; } ua->pint32_val = (uint32_t)dval; @@ -158,7 +158,7 @@ bool get_yesno(UAContext *ua, const char *prompt) ua->pint32_val = ret; return true; } - bsendmsg(ua, _("Invalid response. You must answer yes or no.\n")); + ua->warning_msg(_("Invalid response. You must answer yes or no.\n")); } } @@ -181,7 +181,7 @@ int get_enabled(UAContext *ua, const char *val) Enabled = atoi(val); } if (Enabled < 0 || Enabled > 2) { - bsendmsg(ua, _("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n")); + ua->error_msg(_("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n")); return -1; } return Enabled; diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 3d03199f12..83c4f23180 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -716,10 +716,8 @@ void prtit(void *ctx, const char *msg) * agent, so we are being called from Bacula core. In * that case direct the messages to the Job. */ -void bsendmsg(void *ctx, const char *fmt, ...) +void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) { - va_list arg_ptr; - UAContext *ua = (UAContext *)ctx; BSOCK *bs = ua->UA_sock; int maxlen, len; POOLMEM *msg; @@ -732,9 +730,7 @@ void bsendmsg(void *ctx, const char *fmt, ...) again: maxlen = sizeof_pool_memory(msg) - 1; - va_start(arg_ptr, fmt); len = bvsnprintf(msg, maxlen, fmt, arg_ptr); - va_end(arg_ptr); if (len < 0 || len >= maxlen) { msg = realloc_pool_memory(msg, maxlen + maxlen/2); goto again; @@ -750,3 +746,71 @@ again: } } + +void bsendmsg(void *ctx, const char *fmt, ...) +{ + va_list arg_ptr; + va_start(arg_ptr, fmt); + bmsg((UAContext *)ctx, fmt, arg_ptr); + va_end(arg_ptr); +} + +/* + * The following UA methods are mainly intended for GUI + * programs + */ +/* + * This is a message that should be displayed on the user's + * console. + */ +void UAContext::send_msg(const char *fmt, ...) +{ + va_list arg_ptr; + va_start(arg_ptr, fmt); + bmsg(this, fmt, arg_ptr); + va_end(arg_ptr); +} + + +/* + * This is an error condition with a command. The gui should put + * up an error or critical dialog box. The command is aborted. + */ +void UAContext::error_msg(const char *fmt, ...) +{ + BSOCK *bs = UA_sock; + va_list arg_ptr; + va_start(arg_ptr, fmt); + if (bs && api) bs->signal(BNET_ERROR_MSG); + bmsg(this, fmt, arg_ptr); + va_end(arg_ptr); +} + +/* + * This is a warning message, that should bring up a warning + * dialog box on the GUI. The command is not aborted, but something + * went wrong. + */ +void UAContext::warning_msg(const char *fmt, ...) +{ + BSOCK *bs = UA_sock; + va_list arg_ptr; + va_start(arg_ptr, fmt); + if (bs && api) bs->signal(BNET_WARNING_MSG); + bmsg(this, fmt, arg_ptr); + va_end(arg_ptr); +} + +/* + * This is an information message that should probably be put + * into the status line of a GUI program. + */ +void UAContext::info_msg(const char *fmt, ...) +{ + BSOCK *bs = UA_sock; + va_list arg_ptr; + va_start(arg_ptr, fmt); + if (bs && api) bs->signal(BNET_INFO_MSG); + bmsg(this, fmt, arg_ptr); + va_end(arg_ptr); +} diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 65df3d535c..f5c4595adf 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -95,7 +95,7 @@ int restore_cmd(UAContext *ua, const char *cmd) if (i >= 0) { rx.where = ua->argv[i]; if (!acl_access_ok(ua, Where_ACL, rx.where)) { - bsendmsg(ua, _("Forbidden \"where\" specified.\n")); + ua->error_msg(_("\"where\" specification not authorized.\n")); goto bail_out; } } @@ -116,7 +116,7 @@ int restore_cmd(UAContext *ua, const char *cmd) } UnlockRes(); if (!rx.restore_jobs) { - bsendmsg(ua, _( + ua->error_msg(_( "No Restore Job Resource found in bacula-dir.conf.\n" "You must create at least one before running this command.\n")); goto bail_out; @@ -133,7 +133,7 @@ int restore_cmd(UAContext *ua, const char *cmd) goto bail_out; case 1: /* selected by jobid */ if (!build_directory_tree(ua, &rx)) { - bsendmsg(ua, _("Restore not done.\n")); + ua->send_msg(_("Restore not done.\n")); goto bail_out; } break; @@ -145,11 +145,11 @@ int restore_cmd(UAContext *ua, const char *cmd) uint32_t selected_files; char ed1[50]; if (!complete_bsr(ua, rx.bsr)) { /* find Vol, SessId, SessTime from JobIds */ - bsendmsg(ua, _("Unable to construct a valid BSR. Cannot continue.\n")); + ua->error_msg(_("Unable to construct a valid BSR. Cannot continue.\n")); goto bail_out; } if (!(selected_files = write_bsr_file(ua, rx))) { - bsendmsg(ua, _("No files selected to be restored.\n")); + ua->warning_msg(_("No files selected to be restored.\n")); goto bail_out; } /* If no count of files, use bsr generated value (often wrong) */ @@ -157,14 +157,14 @@ int restore_cmd(UAContext *ua, const char *cmd) rx.selected_files = selected_files; } if (rx.selected_files==1) { - bsendmsg(ua, _("\n1 file selected to be restored.\n\n")); + ua->info_msg(_("\n1 file selected to be restored.\n\n")); } else { - bsendmsg(ua, _("\n%s files selected to be restored.\n\n"), + ua->info_msg(_("\n%s files selected to be restored.\n\n"), edit_uint64_with_commas(rx.selected_files, ed1)); } } else { - bsendmsg(ua, _("No files selected to be restored.\n")); + ua->warning_msg(_("No files selected to be restored.\n")); goto bail_out; } @@ -179,7 +179,7 @@ int restore_cmd(UAContext *ua, const char *cmd) get_client_name(ua, &rx); if (!rx.ClientName) { - bsendmsg(ua, _("No Client resource found!\n")); + ua->error_msg(_("No Client resource found!\n")); goto bail_out; } @@ -189,7 +189,7 @@ int restore_cmd(UAContext *ua, const char *cmd) /* Build run command */ if (rx.where) { if (!acl_access_ok(ua, Where_ACL, rx.where)) { - bsendmsg(ua, _("Forbidden \"where\" specified.\n")); + ua->error_msg(_("\"where\" specification not authorized.\n")); goto bail_out; } @@ -266,7 +266,7 @@ static void free_rx(RESTORE_CTX *rx) static bool has_value(UAContext *ua, int i) { if (!ua->argv[i]) { - bsendmsg(ua, _("Missing value for keyword: %s\n"), ua->argk[i]); + ua->error_msg(_("Missing value for keyword: %s\n"), ua->argk[i]); return false; } return true; @@ -362,7 +362,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } } if (!found_kw) { - bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]); + ua->error_msg(_("Unknown keyword: %s\n"), ua->argk[i]); return 0; } /* Found keyword in kw[] list, process it */ @@ -386,7 +386,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 0; } if (str_to_utime(ua->argv[i]) == 0) { - bsendmsg(ua, _("Improper date format: %s\n"), ua->argv[i]); + ua->error_msg(_("Improper date format: %s\n"), ua->argv[i]); return 0; } bstrncpy(date, ua->argv[i], sizeof(date)); @@ -421,12 +421,12 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]); if (!rx->pool) { - bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]); + ua->error_msg(_("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]); return 0; } if (!acl_access_ok(ua, Pool_ACL, ua->argv[i])) { rx->pool = NULL; - bsendmsg(ua, _("Error: Pool resource \"%s\" access not allowed.\n"), ua->argv[i]); + ua->error_msg(_("Error: Pool resource \"%s\" access not allowed.\n"), ua->argv[i]); return 0; } break; @@ -442,7 +442,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } if (!done) { - bsendmsg(ua, _("\nFirst you select one or more JobIds that contain files\n" + ua->send_msg(_("\nFirst you select one or more JobIds that contain files\n" "to be restored. You will be presented several methods\n" "of specifying the JobIds. Then you will be allowed to\n" "select which files from those JobIds are to be restored.\n\n")); @@ -464,7 +464,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 0; case 0: /* list last 20 Jobs run */ if (!acl_access_ok(ua, Command_ACL, NT_("sqlquery"), 8)) { - bsendmsg(ua, _("SQL query not authorized.\n")); + ua->error_msg(_("SQL query not authorized.\n")); return 0; } gui_save = ua->jcr->gui; @@ -499,7 +499,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) break; case 3: /* Enter an SQL list command */ if (!acl_access_ok(ua, Command_ACL, NT_("sqlquery"), 8)) { - bsendmsg(ua, _("SQL query not authorized.\n")); + ua->error_msg(_("SQL query not authorized.\n")); return 0; } if (!get_cmd(ua, _("Enter SQL list command: "))) { @@ -530,7 +530,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) if (!get_client_name(ua, rx)) { return 0; } - bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n" + ua->send_msg(_("Enter file names with paths, or < to enter a filename\n" "containing a list of file names with paths, and terminate\n" "them with a blank line.\n")); for ( ;; ) { @@ -551,7 +551,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) if (!get_client_name(ua, rx)) { return 0; } - bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n" + ua->send_msg(_("Enter file names with paths, or < to enter a filename\n" "containing a list of file names with paths, and terminate\n" "them with a blank line.\n")); for ( ;; ) { @@ -586,7 +586,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) case 10: /* Enter directories */ if (*rx->JobIds != 0) { - bsendmsg(ua, _("You have already seleted the following JobIds: %s\n"), + ua->send_msg(_("You have already selected the following JobIds: %s\n"), rx->JobIds); } else if (get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) { if (*rx->JobIds != 0 && *ua->cmd) { @@ -601,7 +601,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) if (!get_client_name(ua, rx)) { return 0; } - bsendmsg(ua, _("Enter full directory names or start the name\n" + ua->send_msg(_("Enter full directory names or start the name\n" "with a < to indicate it is a filename containing a list\n" "of directories and terminate them with a blank line.\n")); for ( ;; ) { @@ -636,7 +636,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) char ed1[50]; int stat = get_next_jobid_from_list(&p, &JobId); if (stat < 0) { - bsendmsg(ua, _("Invalid JobId in list.\n")); + ua->error_msg(_("Invalid JobId in list.\n")); free_pool_memory(JobIds); return 0; } @@ -649,13 +649,13 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) memset(&jr, 0, sizeof(JOB_DBR)); jr.JobId = JobId; if (!db_get_job_record(ua->jcr, ua->db, &jr)) { - bsendmsg(ua, _("Unable to get Job record for JobId=%s: ERR=%s\n"), + ua->error_msg(_("Unable to get Job record for JobId=%s: ERR=%s\n"), edit_int64(JobId, ed1), db_strerror(ua->db)); free_pool_memory(JobIds); return 0; } if (!acl_access_ok(ua, Job_ACL, jr.Name)) { - bsendmsg(ua, _("No authorization for JobId=%s (Job \"%s\"). Not selected.\n"), + ua->error_msg(_("Access to JobId=%s (Job \"%s\") not authorized. Not selected.\n"), edit_int64(JobId, ed1), jr.Name); continue; } @@ -668,13 +668,13 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) free_pool_memory(rx->JobIds); rx->JobIds = JobIds; /* Set ACL filtered list */ if (*rx->JobIds == 0) { - bsendmsg(ua, _("No Jobs selected.\n")); + ua->warning_msg(_("No Jobs selected.\n")); return 0; } if (strchr(rx->JobIds,',')) { - bsendmsg(ua, _("You have selected the following JobIds: %s\n"), rx->JobIds); + ua->info_msg(_("You have selected the following JobIds: %s\n"), rx->JobIds); } else { - bsendmsg(ua, _("You have selected the following JobId: %s\n"), rx->JobIds); + ua->info_msg(_("You have selected the following JobId: %s\n"), rx->JobIds); } return 1; } @@ -684,7 +684,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) */ static int get_date(UAContext *ua, char *date, int date_len) { - bsendmsg(ua, _("The restored files will the most current backup\n" + ua->send_msg(_("The restored files will the most current backup\n" "BEFORE the date you specify below.\n\n")); for ( ;; ) { if (!get_cmd(ua, _("Enter date as YYYY-MM-DD HH:MM:SS :"))) { @@ -693,7 +693,7 @@ static int get_date(UAContext *ua, char *date, int date_len) if (str_to_utime(ua->cmd) != 0) { break; } - bsendmsg(ua, _("Improper date format.\n")); + ua->error_msg(_("Improper date format.\n")); } bstrncpy(date, ua->cmd, date_len); return 1; @@ -714,7 +714,7 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b p++; if ((ffd = fopen(p, "rb")) == NULL) { berrno be; - bsendmsg(ua, _("Cannot open file %s: ERR=%s\n"), + ua->error_msg(_("Cannot open file %s: ERR=%s\n"), p, be.strerror()); break; } @@ -722,11 +722,11 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b line++; if (dir) { if (!insert_dir_into_findex_list(ua, rx, file, date)) { - bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p); + ua->error_msg(_("Error occurred on line %d of file \"%s\"\n"), line, p); } } else { if (!insert_file_into_findex_list(ua, rx, file, date)) { - bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p); + ua->error_msg(_("Error occurred on line %d of file \"%s\"\n"), line, p); } } } @@ -766,11 +766,11 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f rx->found = false; /* Find and insert jobid and File Index */ if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) { - bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), + ua->error_msg(_("Query failed: %s. ERR=%s\n"), rx->query, db_strerror(ua->db)); } if (!rx->found) { - bsendmsg(ua, _("No database record found for: %s\n"), file); + ua->error_msg(_("No database record found for: %s\n"), file); return true; } return true; @@ -785,7 +785,7 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di { strip_trailing_junk(dir); if (*rx->JobIds == 0) { - bsendmsg(ua, _("No JobId specified cannot continue.\n")); + ua->error_msg(_("No JobId specified cannot continue.\n")); return false; } else { Mmsg(rx->query, uar_jobid_fileindex_from_dir, rx->JobIds, @@ -794,11 +794,11 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di rx->found = false; /* Find and insert jobid and File Index */ if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) { - bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), + ua->error_msg(_("Query failed: %s. ERR=%s\n"), rx->query, db_strerror(ua->db)); } if (!rx->found) { - bsendmsg(ua, _("No database record found for: %s\n"), dir); + ua->error_msg(_("No database record found for: %s\n"), dir); return true; } return true; @@ -815,11 +815,11 @@ static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char * rx->found = false; /* Find and insert jobid and File Index */ if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) { - bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), + ua->error_msg(_("Query failed: %s. ERR=%s\n"), rx->query, db_strerror(ua->db)); } if (!rx->found) { - bsendmsg(ua, _("No table found: %s\n"), table); + ua->error_msg(_("No table found: %s\n"), table); return true; } return true; @@ -901,7 +901,7 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) /* Use first JobId as estimate of the number of files to restore */ Mmsg(rx->query, uar_count_files, edit_int64(JobId, ed1)); if (!db_sql_query(ua->db, rx->query, count_handler, (void *)rx)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); } if (rx->found) { /* Add about 25% more than this job for over estimate */ @@ -916,7 +916,7 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) continue; /* eliminate duplicate JobIds */ } last_JobId = JobId; - bsendmsg(ua, _("\nBuilding directory tree for JobId %s ... "), + ua->info_msg(_("\nBuilding directory tree for JobId %s ... "), edit_int64(JobId, ed1)); items++; /* @@ -924,11 +924,11 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) */ Mmsg(rx->query, uar_sel_files, edit_int64(JobId, ed1)); if (!db_sql_query(ua->db, rx->query, insert_tree_handler, (void *)&tree)) { - bsendmsg(ua, "%s", db_strerror(ua->db)); + ua->error_msg("%s", db_strerror(ua->db)); } } if (tree.FileCount == 0) { - bsendmsg(ua, _("\nThere were no files inserted into the tree, so file selection\n" + ua->send_msg(_("\nThere were no files inserted into the tree, so file selection\n" "is not possible.Most likely your retention policy pruned the files\n")); if (!get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) { OK = false; @@ -946,21 +946,21 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) char ec1[50]; if (items==1) { if (tree.all) { - bsendmsg(ua, _("\n1 Job, %s files inserted into the tree and marked for extraction.\n"), + ua->info_msg(_("\n1 Job, %s files inserted into the tree and marked for extraction.\n"), edit_uint64_with_commas(tree.FileCount, ec1)); } else { - bsendmsg(ua, _("\n1 Job, %s files inserted into the tree.\n"), + ua->info_msg(_("\n1 Job, %s files inserted into the tree.\n"), edit_uint64_with_commas(tree.FileCount, ec1)); } } else { if (tree.all) { - bsendmsg(ua, _("\n%d Jobs, %s files inserted into the tree and marked for extraction.\n"), + ua->info_msg(_("\n%d Jobs, %s files inserted into the tree and marked for extraction.\n"), items, edit_uint64_with_commas(tree.FileCount, ec1)); } else { - bsendmsg(ua, _("\n%d Jobs, %s files inserted into the tree.\n"), + ua->info_msg(_("\n%d Jobs, %s files inserted into the tree.\n"), items, edit_uint64_with_commas(tree.FileCount, ec1)); } } @@ -1012,10 +1012,10 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat db_sql_query(ua->db, uar_del_temp, NULL, NULL); db_sql_query(ua->db, uar_del_temp1, NULL, NULL); if (!db_sql_query(ua->db, uar_create_temp, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); } if (!db_sql_query(ua->db, uar_create_temp1, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); } /* * Select Client from the Catalog @@ -1034,7 +1034,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat if (i >= 0) { bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet)); if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) { - bsendmsg(ua, _("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet, + ua->error_msg(_("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet, db_strerror(ua->db)); i = -1; } @@ -1044,18 +1044,18 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat Mmsg(rx->query, uar_sel_fileset, ed1, ed1); start_prompt(ua, _("The defined FileSet resources are:\n")); if (!db_sql_query(ua->db, rx->query, fileset_handler, (void *)ua)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); } if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"), fileset_name, sizeof(fileset_name)) < 0) { - bsendmsg(ua, _("No FileSet found for client \"%s\".\n"), cr.Name); + ua->error_msg(_("No FileSet found for client \"%s\".\n"), cr.Name); goto bail_out; } bstrncpy(fsr.FileSet, fileset_name, sizeof(fsr.FileSet)); if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) { - bsendmsg(ua, _("Error getting FileSet record: %s\n"), db_strerror(ua->db)); - bsendmsg(ua, _("This probably means you modified the FileSet.\n" + ua->warning_msg(_("Error getting FileSet record: %s\n"), db_strerror(ua->db)); + ua->send_msg(_("This probably means you modified the FileSet.\n" "Continuing anyway.\n")); } } @@ -1070,7 +1070,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ", edit_int64(pr.PoolId, ed1)); } else { - bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name); + ua->warning_msg(_("Pool \"%s\" not found, using any pool.\n"), pr.Name); } } @@ -1079,13 +1079,13 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat Mmsg(rx->query, uar_last_full, ed1, ed1, date, fsr.FileSet, pool_select); if (!db_sql_query(ua->db, rx->query, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); goto bail_out; } /* Find all Volumes used by that JobId */ if (!db_sql_query(ua->db, uar_full, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->error_msg("%s\n", db_strerror(ua->db)); goto bail_out; } /* Note, this is needed because I don't seem to get the callback @@ -1093,10 +1093,10 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat */ rx->JobTDate = 0; if (!db_sql_query(ua->db, uar_sel_all_temp1, last_full_handler, (void *)rx)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->warning_msg("%s\n", db_strerror(ua->db)); } if (rx->JobTDate == 0) { - bsendmsg(ua, _("No Full backup before %s found.\n"), date); + ua->error_msg(_("No Full backup before %s found.\n"), date); goto bail_out; } @@ -1104,15 +1104,15 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat Mmsg(rx->query, uar_dif, edit_uint64(rx->JobTDate, ed1), date, edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select); if (!db_sql_query(ua->db, rx->query, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->warning_msg("%s\n", db_strerror(ua->db)); } /* Now update JobTDate to lock onto Differental, if any */ rx->JobTDate = 0; if (!db_sql_query(ua->db, uar_sel_all_temp, last_full_handler, (void *)rx)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->warning_msg("%s\n", db_strerror(ua->db)); } if (rx->JobTDate == 0) { - bsendmsg(ua, _("No Full backup before %s found.\n"), date); + ua->error_msg(_("No Full backup before %s found.\n"), date); goto bail_out; } @@ -1120,14 +1120,14 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat Mmsg(rx->query, uar_inc, edit_uint64(rx->JobTDate, ed1), date, edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select); if (!db_sql_query(ua->db, rx->query, NULL, NULL)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->warning_msg("%s\n", db_strerror(ua->db)); } /* Get the JobIds from that list */ rx->JobIds[0] = 0; rx->last_jobid[0] = 0; if (!db_sql_query(ua->db, uar_sel_jobid_temp, jobid_handler, (void *)rx)) { - bsendmsg(ua, "%s\n", db_strerror(ua->db)); + ua->warning_msg("%s\n", db_strerror(ua->db)); } if (rx->JobIds[0] != 0) { @@ -1135,7 +1135,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat db_list_sql_query(ua->jcr, ua->db, uar_list_temp, prtit, ua, 1, HORZ_LIST); ok = true; } else { - bsendmsg(ua, _("No jobs found.\n")); + ua->warning_msg(_("No jobs found.\n")); } bail_out: @@ -1292,7 +1292,7 @@ void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char * } } if (store && (store != rx.store)) { - bsendmsg(ua, _("Warning default storage overridden by \"%s\" on command line.\n"), + ua->info_msg(_("Warning default storage overridden by \"%s\" on command line.\n"), store->name()); rx.store = store; Dmsg1(200, "Set store=%s\n", rx.store->name()); @@ -1308,7 +1308,7 @@ void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char * if (acl_access_ok(ua, Storage_ACL, store->name())) { rx.store = store; Dmsg1(200, "Set store=%s\n", rx.store->name()); - bsendmsg(ua, _("Storage \"%s\" not found, using Storage \"%s\" from MediaType \"%s\".\n"), + ua->warning_msg(_("Storage \"%s\" not found, using Storage \"%s\" from MediaType \"%s\".\n"), Storage, store->name(), MediaType); } UnlockRes(); @@ -1316,7 +1316,7 @@ void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char * } } UnlockRes(); - bsendmsg(ua, _("\nUnable to find Storage resource for\n" + ua->warning_msg(_("\nUnable to find Storage resource for\n" "MediaType \"%s\", needed by the Jobs you selected.\n"), MediaType); } diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 9da828ad06..9ddb351f55 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -133,14 +133,14 @@ int run_cmd(UAContext *ua, const char *cmd) if (strcasecmp(ua->argk[i], kw[j]) == 0) { /* Note, yes and run have no value, so do not fail */ if (!ua->argv[i] && j != YES_POS /*yes*/) { - bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]); + ua->send_msg(_("Value missing for keyword %s\n"), ua->argk[i]); return 1; } Dmsg1(800, "Got keyword=%s\n", NPRT(kw[j])); switch (j) { case 0: /* job */ if (job_name) { - bsendmsg(ua, _("Job name specified twice.\n")); + ua->send_msg(_("Job name specified twice.\n")); return 0; } job_name = ua->argv[i]; @@ -148,7 +148,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 1: /* JobId */ if (jid) { - bsendmsg(ua, _("JobId specified twice.\n")); + ua->send_msg(_("JobId specified twice.\n")); return 0; } jid = ua->argv[i]; @@ -157,7 +157,7 @@ int run_cmd(UAContext *ua, const char *cmd) case 2: /* client */ case 3: /* fd */ if (client_name) { - bsendmsg(ua, _("Client specified twice.\n")); + ua->send_msg(_("Client specified twice.\n")); return 0; } client_name = ua->argv[i]; @@ -165,7 +165,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 4: /* fileset */ if (fileset_name) { - bsendmsg(ua, _("FileSet specified twice.\n")); + ua->send_msg(_("FileSet specified twice.\n")); return 0; } fileset_name = ua->argv[i]; @@ -173,7 +173,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 5: /* level */ if (level_name) { - bsendmsg(ua, _("Level specified twice.\n")); + ua->send_msg(_("Level specified twice.\n")); return 0; } level_name = ua->argv[i]; @@ -182,7 +182,7 @@ int run_cmd(UAContext *ua, const char *cmd) case 6: /* storage */ case 7: /* sd */ if (store_name) { - bsendmsg(ua, _("Storage specified twice.\n")); + ua->send_msg(_("Storage specified twice.\n")); return 0; } store_name = ua->argv[i]; @@ -190,7 +190,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 8: /* pool */ if (pool_name) { - bsendmsg(ua, _("Pool specified twice.\n")); + ua->send_msg(_("Pool specified twice.\n")); return 0; } pool_name = ua->argv[i]; @@ -198,19 +198,19 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 9: /* where */ if (where) { - bsendmsg(ua, _("Where specified twice.\n")); + ua->send_msg(_("Where specified twice.\n")); return 0; } where = ua->argv[i]; if (!acl_access_ok(ua, Where_ACL, where)) { - bsendmsg(ua, _("Forbidden \"where\" specified.\n")); + ua->send_msg(_("Forbidden \"where\" specified.\n")); return 0; } kw_ok = true; break; case 10: /* bootstrap */ if (bootstrap) { - bsendmsg(ua, _("Bootstrap specified twice.\n")); + ua->send_msg(_("Bootstrap specified twice.\n")); return 0; } bootstrap = ua->argv[i]; @@ -218,7 +218,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 11: /* replace */ if (replace) { - bsendmsg(ua, _("Replace specified twice.\n")); + ua->send_msg(_("Replace specified twice.\n")); return 0; } replace = ua->argv[i]; @@ -226,7 +226,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 12: /* When */ if (when) { - bsendmsg(ua, _("When specified twice.\n")); + ua->send_msg(_("When specified twice.\n")); return 0; } when = ua->argv[i]; @@ -234,12 +234,12 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 13: /* Priority */ if (Priority) { - bsendmsg(ua, _("Priority specified twice.\n")); + ua->send_msg(_("Priority specified twice.\n")); return 0; } Priority = atoi(ua->argv[i]); if (Priority <= 0) { - bsendmsg(ua, _("Priority must be positive nonzero setting it to 10.\n")); + ua->send_msg(_("Priority must be positive nonzero setting it to 10.\n")); Priority = 10; } kw_ok = true; @@ -249,7 +249,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 15: /* Verify Job */ if (verify_job_name) { - bsendmsg(ua, _("Verify Job specified twice.\n")); + ua->send_msg(_("Verify Job specified twice.\n")); return 0; } verify_job_name = ua->argv[i]; @@ -281,7 +281,7 @@ int run_cmd(UAContext *ua, const char *cmd) break; case 21: /* Migration Job */ if (previous_job_name) { - bsendmsg(ua, _("Migration Job specified twice.\n")); + ua->send_msg(_("Migration Job specified twice.\n")); return 0; } previous_job_name = ua->argv[i]; @@ -307,7 +307,7 @@ int run_cmd(UAContext *ua, const char *cmd) job_name = ua->argk[i]; /* use keyword as job name */ Dmsg1(800, "Set jobname=%s\n", job_name); } else { - bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]); + ua->send_msg(_("Invalid keyword: %s\n"), ua->argk[i]); return 0; } } @@ -319,11 +319,11 @@ int run_cmd(UAContext *ua, const char *cmd) if (catalog_name != NULL) { catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name); if (catalog == NULL) { - bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name); + ua->error_msg(_("Catalog \"%s\" not found\n"), catalog_name); return 0; } if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) { - bsendmsg(ua, _("No authorization. Catalog \"%s\".\n"), catalog->name()); + ua->error_msg(_("No authorization. Catalog \"%s\".\n"), catalog->name()); return 0; } } @@ -334,20 +334,20 @@ int run_cmd(UAContext *ua, const char *cmd) job = (JOB *)GetResWithName(R_JOB, job_name); if (!job) { if (*job_name != 0) { - bsendmsg(ua, _("Job \"%s\" not found\n"), job_name); + ua->send_msg(_("Job \"%s\" not found\n"), job_name); } job = select_job_resource(ua); } else { Dmsg1(800, "Found job=%s\n", job_name); } } else { - bsendmsg(ua, _("A job name must be specified.\n")); + ua->send_msg(_("A job name must be specified.\n")); job = select_job_resource(ua); } if (!job) { return 0; } else if (!acl_access_ok(ua, Job_ACL, job->name())) { - bsendmsg(ua, _("No authorization. Job \"%s\".\n"), + ua->error_msg( _("No authorization. Job \"%s\".\n"), job->name()); return 0; } @@ -356,7 +356,7 @@ int run_cmd(UAContext *ua, const char *cmd) pool = (POOL *)GetResWithName(R_POOL, pool_name); if (!pool) { if (*pool_name != 0) { - bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name); + ua->warning_msg(_("Pool \"%s\" not found.\n"), pool_name); } pool = select_pool_resource(ua); } @@ -366,7 +366,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (!pool) { return 0; } else if (!acl_access_ok(ua, Pool_ACL, pool->name())) { - bsendmsg(ua, _("No authorization. Pool \"%s\".\n"), + ua->error_msg(_("No authorization. Pool \"%s\".\n"), pool->name()); return 0; } @@ -377,7 +377,7 @@ int run_cmd(UAContext *ua, const char *cmd) pm_strcpy(store.store_source, _("command line")); if (!store.store) { if (*store_name != 0) { - bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name); + ua->warning_msg(_("Storage \"%s\" not found.\n"), store_name); } store.store = select_storage_resource(ua); pm_strcpy(store.store_source, _("user selection")); @@ -386,10 +386,10 @@ int run_cmd(UAContext *ua, const char *cmd) get_job_storage(&store, job, NULL); /* use default */ } if (!store.store) { - bsendmsg(ua, _("No storage specified.\n")); + ua->error_msg(_("No storage specified.\n")); return 1; } else if (!acl_access_ok(ua, Storage_ACL, store.store->name())) { - bsendmsg(ua, _("No authorization. Storage \"%s\".\n"), + ua->error_msg(_("No authorization. Storage \"%s\".\n"), store.store->name()); return 0; } @@ -399,7 +399,7 @@ int run_cmd(UAContext *ua, const char *cmd) client = (CLIENT *)GetResWithName(R_CLIENT, client_name); if (!client) { if (*client_name != 0) { - bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name); + ua->warning_msg(_("Client \"%s\" not found.\n"), client_name); } client = select_client_resource(ua); } @@ -409,7 +409,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (!client) { return 0; } else if (!acl_access_ok(ua, Client_ACL, client->name())) { - bsendmsg(ua, _("No authorization. Client \"%s\".\n"), + ua->error_msg(_("No authorization. Client \"%s\".\n"), client->name()); return 0; } @@ -418,7 +418,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (fileset_name) { fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name); if (!fileset) { - bsendmsg(ua, _("FileSet \"%s\" not found.\n"), fileset_name); + ua->send_msg(_("FileSet \"%s\" not found.\n"), fileset_name); fileset = select_fileset_resource(ua); } } else { @@ -427,7 +427,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (!fileset) { return 0; } else if (!acl_access_ok(ua, FileSet_ACL, fileset->name())) { - bsendmsg(ua, _("No authorization. FileSet \"%s\".\n"), + ua->send_msg(_("No authorization. FileSet \"%s\".\n"), fileset->name()); return 0; } @@ -435,7 +435,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (verify_job_name) { verify_job = (JOB *)GetResWithName(R_JOB, verify_job_name); if (!verify_job) { - bsendmsg(ua, _("Verify Job \"%s\" not found.\n"), verify_job_name); + ua->send_msg(_("Verify Job \"%s\" not found.\n"), verify_job_name); verify_job = select_job_resource(ua); } } else { @@ -445,7 +445,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (previous_job_name) { previous_job = (JOB *)GetResWithName(R_JOB, previous_job_name); if (!previous_job) { - bsendmsg(ua, _("Migration Job \"%s\" not found.\n"), previous_job_name); + ua->send_msg(_("Migration Job \"%s\" not found.\n"), previous_job_name); previous_job = select_job_resource(ua); } } else { @@ -483,7 +483,7 @@ int run_cmd(UAContext *ua, const char *cmd) if (when) { jcr->sched_time = str_to_utime(when); if (jcr->sched_time == 0) { - bsendmsg(ua, _("Invalid time, using current time.\n")); + ua->send_msg(_("Invalid time, using current time.\n")); jcr->sched_time = time(NULL); } } @@ -503,7 +503,7 @@ int run_cmd(UAContext *ua, const char *cmd) } } if (!jcr->replace) { - bsendmsg(ua, _("Invalid replace option: %s\n"), replace); + ua->send_msg(_("Invalid replace option: %s\n"), replace); goto bail_out; } } else if (job->replace) { @@ -545,7 +545,7 @@ try_again: } if (level_name) { if (!get_level_from_name(jcr, level_name)) { - bsendmsg(ua, _("Level %s not valid.\n"), level_name); + ua->send_msg(_("Level %s not valid.\n"), level_name); goto bail_out; } } @@ -647,7 +647,7 @@ try_again: } else { jcr->sched_time = str_to_utime(ua->cmd); if (jcr->sched_time == 0) { - bsendmsg(ua, _("Invalid time, using current time.\n")); + ua->send_msg(_("Invalid time, using current time.\n")); jcr->sched_time = time(NULL); } } @@ -658,7 +658,7 @@ try_again: break; } if (ua->pint32_val == 0) { - bsendmsg(ua, _("Priority must be a positive integer.\n")); + ua->send_msg(_("Priority must be a positive integer.\n")); } else { jcr->JobPriority = ua->pint32_val; } @@ -689,7 +689,7 @@ try_again: jcr->RestoreBootstrap = bstrdup(ua->cmd); fd = fopen(jcr->RestoreBootstrap, "rb"); if (!fd) { - bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"), + ua->send_msg(_("Warning cannot open %s: ERR=%s\n"), jcr->RestoreBootstrap, strerror(errno)); free(jcr->RestoreBootstrap); jcr->RestoreBootstrap = NULL; @@ -736,7 +736,7 @@ try_again: jid = NULL; /* force reprompt */ jcr->RestoreJobId = 0; if (jcr->RestoreBootstrap) { - bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n")); + ua->send_msg(_("You must set the bootstrap file to NULL to be able to specify a JobId.\n")); } goto try_again; case -1: /* error or cancel */ @@ -754,23 +754,23 @@ start_job: Dmsg1(100, "Using pool %s\n", jcr->pool->name()); JobId = run_job(jcr); #if 0 - bsendmsg(ua, "send_msg("\n", time(NULL), jcr->JobStatus, jcr->JobType, jcr->JobId, jcr->Job, jcr->JobLevel, jcr->JobPriority); #endif free_jcr(jcr); /* release jcr */ if (JobId == 0) { - bsendmsg(ua, _("Job failed.\n")); + ua->error_msg(_("Job failed.\n")); } else { char ed1[50]; - bsendmsg(ua, _("Job queued. JobId=%s\n"), edit_int64(JobId,ed1)); + ua->send_msg(_("Job queued. JobId=%s\n"), edit_int64(JobId,ed1)); } return JobId; } bail_out: - bsendmsg(ua, _("Job not run.\n")); + ua->send_msg(_("Job not run.\n")); free_jcr(jcr); return 0; /* do not run */ } @@ -830,7 +830,7 @@ static void select_job_level(UAContext *ua, JCR *jcr) break; } } else { - bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n")); + ua->warning_msg(_("Level not appropriate for this Job. Cannot be changed.\n")); } return; } @@ -843,13 +843,14 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri char ec1[30]; char dt[MAX_TIME_LENGTH]; case JT_ADMIN: - bsendmsg(ua, _("Run %s job\n" - "JobName: %s\n" - "FileSet: %s\n" - "Client: %s\n" - "Storage: %s\n" - "When: %s\n" - "Priority: %d\n"), + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run %s job\n" + "JobName: %s\n" + "FileSet: %s\n" + "Client: %s\n" + "Storage: %s\n" + "When: %s\n" + "Priority: %d\n"), _("Admin"), job->name(), jcr->fileset->name(), @@ -862,7 +863,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri case JT_BACKUP: case JT_VERIFY: if (jcr->JobType == JT_BACKUP) { - bsendmsg(ua, _("Run %s job\n" + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run %s job\n" "JobName: %s\n" "Level: %s\n" "Client: %s\n" @@ -893,7 +895,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri if (!verify_list) { verify_list = ""; } - bsendmsg(ua, _("Run %s job\n" + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run %s job\n" "JobName: %s\n" "Level: %s\n" "Client: %s\n" @@ -931,7 +934,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri jcr->JobLevel = L_FULL; /* default level */ Dmsg1(800, "JobId to restore=%d\n", jcr->RestoreJobId); if (jcr->RestoreJobId == 0) { - bsendmsg(ua, _("Run Restore job\n" + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run Restore job\n" "JobName: %s\n" "Bootstrap: %s\n" "Where: %s\n" @@ -953,7 +957,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri jcr->catalog->name(), jcr->JobPriority); } else { - bsendmsg(ua, _("Run Restore job\n" + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run Restore job\n" "JobName: %s\n" "Bootstrap: %s\n" "Where: %s\n" @@ -978,7 +983,8 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri break; case JT_MIGRATE: jcr->JobLevel = L_FULL; /* default level */ - bsendmsg(ua, _("Run Migration job\n" + if (ua->api) ua->signal(BNET_RUN_CMD); + ua->send_msg(_("Run Migration job\n" "JobName: %s\n" "Bootstrap: %s\n" "Client: %s\n" @@ -1003,7 +1009,7 @@ static bool display_job_parameters(UAContext *ua, JCR *jcr, JOB *job, char *veri jcr->JobPriority); break; default: - bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType); + ua->error_msg(_("Unknown Job Type=%d\n"), jcr->JobType); return false; } return true; diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index 676f8becc9..b29b7e11db 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -136,6 +136,7 @@ static void *handle_UA_client_request(void *arg) } while (!ua->quit) { + if (ua->api) user->signal(BNET_PROMPT); stat = user->recv(); if (stat >= 0) { pm_strcpy(ua->cmd, ua->UA_sock->msg); @@ -153,7 +154,7 @@ static void *handle_UA_client_request(void *arg) ua->user_notified_msg_pending = false; } else if (!ua->gui && !ua->user_notified_msg_pending && console_msg_pending) { if (ua->api) { - user->signal(BNET_MESSAGES_PENDING); + user->signal(BNET_MSGS_PENDING); } else { bsendmsg(ua, _("You have messages.\n")); } diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index fc49f8e671..33a1766680 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -103,6 +103,7 @@ bool user_select_files_from_tree(TREE_CTX *tree) /* Get a new context so we don't destroy restore command args */ UAContext *ua = new_ua_context(tree->ua->jcr); ua->UA_sock = tree->ua->UA_sock; /* patch in UA socket */ + ua->api = tree->ua->api; /* keep API flag too */ BSOCK *user = ua->UA_sock; bsendmsg(tree->ua, _( @@ -327,7 +328,7 @@ static int markcmd(UAContext *ua, TREE_CTX *tree) char ec1[50]; if (ua->argc < 2 || !tree_node_has_child(tree->node)) { - bsendmsg(ua, _("No files marked.\n")); + ua->send_msg(_("No files marked.\n")); return 1; } for (int i=1; i < ua->argc; i++) { @@ -339,11 +340,11 @@ static int markcmd(UAContext *ua, TREE_CTX *tree) } } if (count == 0) { - bsendmsg(ua, _("No files marked.\n")); + ua->send_msg(_("No files marked.\n")); } else if (count == 1) { - bsendmsg(ua, _("1 file marked.\n")); + ua->send_msg(_("1 file marked.\n")); } else { - bsendmsg(ua, _("%s files marked.\n"), + ua->send_msg(_("%s files marked.\n"), edit_uint64_with_commas(count, ec1)); } return 1; @@ -356,7 +357,7 @@ static int markdircmd(UAContext *ua, TREE_CTX *tree) char ec1[50]; if (ua->argc < 2 || !tree_node_has_child(tree->node)) { - bsendmsg(ua, _("No files marked.\n")); + ua->send_msg(_("No files marked.\n")); return 1; } for (int i=1; i < ua->argc; i++) { @@ -371,11 +372,11 @@ static int markdircmd(UAContext *ua, TREE_CTX *tree) } } if (count == 0) { - bsendmsg(ua, _("No directories marked.\n")); + ua->send_msg(_("No directories marked.\n")); } else if (count == 1) { - bsendmsg(ua, _("1 directory marked.\n")); + ua->send_msg(_("1 directory marked.\n")); } else { - bsendmsg(ua, _("%s directories marked.\n"), + ua->send_msg(_("%s directories marked.\n"), edit_uint64_with_commas(count, ec1)); } return 1; @@ -396,7 +397,7 @@ static int countcmd(UAContext *ua, TREE_CTX *tree) } } } - bsendmsg(ua, _("%s total files/dirs. %s marked to be restored.\n"), + ua->send_msg(_("%s total files/dirs. %s marked to be restored.\n"), edit_uint64_with_commas(total, ec1), edit_uint64_with_commas(num_extract, ec2)); return 1; @@ -407,7 +408,7 @@ static int findcmd(UAContext *ua, TREE_CTX *tree) char cwd[2000]; if (ua->argc == 1) { - bsendmsg(ua, _("No file specification given.\n")); + ua->send_msg(_("No file specification given.\n")); return 1; /* make it non-fatal */ } @@ -423,7 +424,7 @@ static int findcmd(UAContext *ua, TREE_CTX *tree) } else { tag = ""; } - bsendmsg(ua, "%s%s\n", tag, cwd); + ua->send_msg("%s%s\n", tag, cwd); } } } @@ -449,7 +450,7 @@ static int lscmd(UAContext *ua, TREE_CTX *tree) } else { tag = ""; } - bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":""); + ua->send_msg("%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":""); } } return 1; @@ -475,7 +476,7 @@ static void rlsmark(UAContext *ua, TREE_NODE *tnode) } else { tag = ""; } - bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":""); + ua->send_msg("%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":""); if (tree_node_has_child(node)) { rlsmark(ua, node); } @@ -558,7 +559,7 @@ static int do_dircmd(UAContext *ua, TREE_CTX *tree, bool dot_cmd) char cwd[1100], *pcwd; if (!tree_node_has_child(tree->node)) { - bsendmsg(ua, _("Node %s has no children.\n"), tree->node->fname); + ua->send_msg(_("Node %s has no children.\n"), tree->node->fname); return 1; } @@ -600,7 +601,7 @@ static int do_dircmd(UAContext *ua, TREE_CTX *tree, bool dot_cmd) memset(&statp, 0, sizeof(statp)); } ls_output(buf, cwd, tag, &statp, dot_cmd); - bsendmsg(ua, "%s\n", buf); + ua->send_msg("%s\n", buf); } } return 1; @@ -649,7 +650,7 @@ static int estimatecmd(UAContext *ua, TREE_CTX *tree) } } } - bsendmsg(ua, _("%d total files; %d marked to be restored; %s bytes.\n"), + ua->send_msg(_("%d total files; %d marked to be restored; %s bytes.\n"), total, num_extract, edit_uint64_with_commas(total_bytes, ec1)); return 1; } @@ -660,14 +661,14 @@ static int helpcmd(UAContext *ua, TREE_CTX *tree) { unsigned int i; - bsendmsg(ua, _(" Command Description\n ======= ===========\n")); + ua->send_msg(_(" Command Description\n ======= ===========\n")); for (i=0; isend_msg(" %-10s %s\n", _(commands[i].key), _(commands[i].help)); } } - bsendmsg(ua, "\n"); + ua->send_msg("\n"); return 1; } @@ -683,7 +684,7 @@ static int cdcmd(UAContext *ua, TREE_CTX *tree) if (ua->argc != 2) { - bsendmsg(ua, _("Too few or too many arguments. Try using double quotes.\n")); + ua->error_msg(_("Too few or too many arguments. Try using double quotes.\n")); return 1; } node = tree_cwd(ua->argk[1], tree->root, tree->node); @@ -695,7 +696,7 @@ static int cdcmd(UAContext *ua, TREE_CTX *tree) node = tree_cwd(cwd, tree->root, tree->node); } if (!node) { - bsendmsg(ua, _("Invalid path given.\n")); + ua->warning_msg(_("Invalid path given.\n")); } else { tree->node = node; } @@ -710,9 +711,9 @@ static int pwdcmd(UAContext *ua, TREE_CTX *tree) char cwd[2000]; tree_getpath(tree->node, cwd, sizeof(cwd)); if (ua->api) { - bsendmsg(ua, "%s", cwd); + ua->send_msg("%s", cwd); } else { - bsendmsg(ua, _("cwd is: %s\n"), cwd); + ua->send_msg(_("cwd is: %s\n"), cwd); } return 1; } @@ -721,7 +722,7 @@ static int dot_pwdcmd(UAContext *ua, TREE_CTX *tree) { char cwd[2000]; tree_getpath(tree->node, cwd, sizeof(cwd)); - bsendmsg(ua, _("%s"), cwd); + ua->send_msg("%s", cwd); return 1; } @@ -731,7 +732,7 @@ static int unmarkcmd(UAContext *ua, TREE_CTX *tree) int count = 0; if (ua->argc < 2 || !tree_node_has_child(tree->node)) { - bsendmsg(ua, _("No files unmarked.\n")); + ua->send_msg(_("No files unmarked.\n")); return 1; } for (int i=1; i < ua->argc; i++) { @@ -743,12 +744,12 @@ static int unmarkcmd(UAContext *ua, TREE_CTX *tree) } } if (count == 0) { - bsendmsg(ua, _("No files unmarked.\n")); + ua->send_msg(_("No files unmarked.\n")); } else if (count == 1) { - bsendmsg(ua, _("1 file unmarked.\n")); + ua->send_msg(_("1 file unmarked.\n")); } else { char ed1[50]; - bsendmsg(ua, _("%s files unmarked.\n"), edit_uint64_with_commas(count, ed1)); + ua->send_msg(_("%s files unmarked.\n"), edit_uint64_with_commas(count, ed1)); } return 1; } @@ -759,7 +760,7 @@ static int unmarkdircmd(UAContext *ua, TREE_CTX *tree) int count = 0; if (ua->argc < 2 || !tree_node_has_child(tree->node)) { - bsendmsg(ua, _("No directories unmarked.\n")); + ua->send_msg(_("No directories unmarked.\n")); return 1; } @@ -776,11 +777,11 @@ static int unmarkdircmd(UAContext *ua, TREE_CTX *tree) } if (count == 0) { - bsendmsg(ua, _("No directories unmarked.\n")); + ua->send_msg(_("No directories unmarked.\n")); } else if (count == 1) { - bsendmsg(ua, _("1 directory unmarked.\n")); + ua->send_msg(_("1 directory unmarked.\n")); } else { - bsendmsg(ua, _("%d directories unmarked.\n"), count); + ua->send_msg(_("%d directories unmarked.\n"), count); } return 1; } diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index dd7154002d..2168ffa5d1 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -92,34 +92,43 @@ public: /* * Signal definitions for use in bnet_sig() - * Note! These must be negative + * Note! These must be negative. There are signals that are generated + * by the software ... */ enum { - BNET_EOD = -1, /* End of data stream, new data may follow */ - BNET_EOD_POLL = -2, /* End of data and poll all in one */ - BNET_STATUS = -3, /* Send full status */ - BNET_TERMINATE = -4, /* Conversation terminated, doing close() */ - BNET_POLL = -5, /* Poll request, I'm hanging on a read */ - BNET_HEARTBEAT = -6, /* Heartbeat Response requested */ - BNET_HB_RESPONSE = -7, /* Only response permited to HB */ - BNET_PROMPT = -8, /* Prompt for UA */ - BNET_BTIME = -9, /* Send UTC btime */ - BNET_BREAK = -10, /* Stop current command -- ctl-c */ - BNET_START_SELECT = -11, /* Start of a selection list */ - BNET_END_SELECT = -12, /* End of a select list */ - BNET_INVALID_CMD = -13, /* Invalid command sent */ - BNET_CMD_FAILED = -14, /* Command failed */ - BNET_CMD_OK = -15, /* Command succeeded */ - BNET_CMD_BEGIN = -16, /* Start command execution */ - BNET_MESSAGES_PENDING = -17, /* Messages pending */ - BNET_SERVER_READY = -18, /* Server ready and waiting */ - BNET_SELECT_INPUT = -19 /* Return selection input */ + BNET_EOD = -1, /* End of data stream, new data may follow */ + BNET_EOD_POLL = -2, /* End of data and poll all in one */ + BNET_STATUS = -3, /* Send full status */ + BNET_TERMINATE = -4, /* Conversation terminated, doing close() */ + BNET_POLL = -5, /* Poll request, I'm hanging on a read */ + BNET_HEARTBEAT = -6, /* Heartbeat Response requested */ + BNET_HB_RESPONSE = -7, /* Only response permited to HB */ + BNET_PROMPT = -8, /* Prompt for UA */ + BNET_BTIME = -9, /* Send UTC btime */ + BNET_BREAK = -10, /* Stop current command -- ctl-c */ + BNET_START_SELECT = -11, /* Start of a selection list */ + BNET_END_SELECT = -12, /* End of a select list */ + BNET_INVALID_CMD = -13, /* Invalid command sent */ + BNET_CMD_FAILED = -14, /* Command failed */ + BNET_CMD_OK = -15, /* Command succeeded */ + BNET_CMD_BEGIN = -16, /* Start command execution */ + BNET_MSGS_PENDING = -17, /* Messages pending */ + BNET_SERVER_READY = -18, /* Server ready and waiting */ + BNET_SELECT_INPUT = -19, /* Return selection input */ + BNET_WARNING_MSG = -20, /* Warning message */ + BNET_ERROR_MSG = -21, /* Error message -- command failed */ + BNET_INFO_MSG = -22, /* Info message -- status line */ + BNET_RUN_CMD = -23 /* Run command follows */ }; #define BNET_SETBUF_READ 1 /* Arg for bnet_set_buffer_size */ #define BNET_SETBUF_WRITE 2 /* Arg for bnet_set_buffer_size */ -/* Return status from bnet_recv() */ +/* + * Return status from bnet_recv() + * Note, the HARDEOF and ERROR refer to comm status/problems + * rather than the BNET_xxx above, which are software signals. + */ enum { BNET_SIGNAL = -1, BNET_HARDEOF = -2, diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index c35dde9770..975811ad73 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -1,16 +1,7 @@ -/* - * Miscellaneous Bacula memory and thread safe routines - * Generally, these are interfaces to system or standard - * library routines. - * - * Bacula utility functions are in util.c - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -34,7 +25,15 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ - +/* + * Miscellaneous Bacula memory and thread safe routines + * Generally, these are interfaces to system or standard + * library routines. + * + * Bacula utility functions are in util.c + * + * Version $Id$ + */ #include "bacula.h" #ifdef HAVE_PWD_H @@ -233,9 +232,6 @@ void bfree(void *buf) #endif } - - - void *brealloc (void *buf, size_t size) { buf = realloc(buf, size); @@ -776,4 +772,3 @@ char *escape_filename(const char *file_path) return escaped_path; } - diff --git a/bacula/src/qt-console/Makefile b/bacula/src/qt-console/Makefile index 6598099a4f..299312c8a3 100644 --- a/bacula/src/qt-console/Makefile +++ b/bacula/src/qt-console/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: bat -# Generated by qmake (2.01a) (Qt 4.2.1) on: Fri Mar 9 09:22:17 2007 +# Generated by qmake (2.01a) (Qt 4.2.1) on: Sat Mar 10 21:24:05 2007 # Project: bat.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile bat.pro @@ -56,6 +56,7 @@ SOURCES = main.cpp \ restore/brestore.cpp \ label/label.cpp \ run/run.cpp \ + run/runcmd.cpp \ select/select.cpp moc/moc_mainwin.cpp \ moc/moc_console.cpp \ moc/moc_restore.cpp \ @@ -74,6 +75,7 @@ OBJECTS = obj/main.o \ obj/brestore.o \ obj/label.o \ obj/run.o \ + obj/runcmd.o \ obj/select.o \ obj/moc_mainwin.o \ obj/moc_console.o \ @@ -127,7 +129,7 @@ first: all all: Makefile $(TARGET) -$(TARGET): ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_select.h $(OBJECTS) +$(TARGET): ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_runcmd.h ui_select.h $(OBJECTS) $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) Makefile: bat.pro /usr/share/qt4/mkspecs/default/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ @@ -172,7 +174,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) obj/bat1.0.0 || $(MKDIR) obj/bat1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h qstd.h console/console.h restore/restore.h label/label.h run/run.h select/select.h obj/bat1.0.0/ && $(COPY_FILE) --parents main.qrc obj/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp qstd.cpp console/authenticate.cpp console/console.cpp restore/prerestore.cpp restore/restore.cpp restore/brestore.cpp label/label.cpp run/run.cpp select/select.cpp obj/bat1.0.0/ && $(COPY_FILE) --parents main.ui label/label.ui console/console.ui restore/restore.ui restore/prerestore.ui restore/brestore.ui run/run.ui select/select.ui obj/bat1.0.0/ && (cd `dirname obj/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname obj/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r obj/bat1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h qstd.h console/console.h restore/restore.h label/label.h run/run.h select/select.h obj/bat1.0.0/ && $(COPY_FILE) --parents main.qrc obj/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp qstd.cpp console/authenticate.cpp console/console.cpp restore/prerestore.cpp restore/restore.cpp restore/brestore.cpp label/label.cpp run/run.cpp run/runcmd.cpp select/select.cpp obj/bat1.0.0/ && $(COPY_FILE) --parents main.ui label/label.ui console/console.ui restore/restore.ui restore/prerestore.ui restore/brestore.ui run/run.ui run/runcmd.ui select/select.ui obj/bat1.0.0/ && (cd `dirname obj/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname obj/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r obj/bat1.0.0 yaccclean: @@ -265,9 +267,9 @@ compiler_image_collection_clean: -$(DEL_FILE) qmake_image_collection.cpp compiler_moc_source_make_all: compiler_moc_source_clean: -compiler_uic_make_all: ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_select.h +compiler_uic_make_all: ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_runcmd.h ui_select.h compiler_uic_clean: - -$(DEL_FILE) ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_select.h + -$(DEL_FILE) ui_main.h ui_label.h ui_console.h ui_restore.h ui_prerestore.h ui_brestore.h ui_run.h ui_runcmd.h ui_select.h ui_main.h: main.ui /usr/bin/uic main.ui -o ui_main.h @@ -289,6 +291,9 @@ ui_brestore.h: restore/brestore.ui ui_run.h: run/run.ui /usr/bin/uic run/run.ui -o ui_run.h +ui_runcmd.h: run/runcmd.ui + /usr/bin/uic run/runcmd.ui -o ui_runcmd.h + ui_select.h: select/select.ui /usr/bin/uic select/select.ui -o ui_select.h @@ -439,6 +444,21 @@ obj/run.o: run/run.cpp bat.h \ qstd.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/run.o run/run.cpp +obj/runcmd.o: run/runcmd.cpp bat.h \ + mainwin.h \ + ui_main.h \ + label/label.h \ + ui_label.h \ + run/run.h \ + ui_run.h \ + restore/restore.h \ + ui_brestore.h \ + ui_restore.h \ + ui_prerestore.h \ + bat_conf.h \ + qstd.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/runcmd.o run/runcmd.cpp + obj/select.o: select/select.cpp bat.h \ mainwin.h \ ui_main.h \ diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index f45400a204..271754f6ca 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -20,7 +20,7 @@ FORMS += main.ui FORMS += label/label.ui FORMS += console/console.ui FORMS += restore/restore.ui restore/prerestore.ui restore/brestore.ui -FORMS += run/run.ui +FORMS += run/run.ui run/runcmd.ui FORMS += select/select.ui @@ -41,7 +41,7 @@ SOURCES += label/label.cpp # Run dialog HEADERS += run/run.h -SOURCES += run/run.cpp +SOURCES += run/run.cpp run/runcmd.cpp # Select dialgo HEADERS += select/select.h diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 1da5d1826d..1594171f41 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -135,7 +135,7 @@ void Console::connect() m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0); QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int))); - write(".api"); + write(".api 1"); discardToPrompt(); beginNewCommand(); @@ -162,14 +162,13 @@ QStringList Console::get_list(char *cmd) QStringList list; int stat; - setEnabled(false); + notify(false); write(cmd); while ((stat = read()) > 0) { strip_trailing_junk(msg()); list << msg(); } - setEnabled(true); -// list.sort(); + notify(true); return list; } @@ -183,7 +182,7 @@ bool Console::get_job_defaults(struct job_defaults &job_defs) int stat; char *def; - setEnabled(false); + notify(false); beginNewCommand(); scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name); write(scmd); @@ -256,11 +255,11 @@ bool Console::get_job_defaults(struct job_defaults &job_defs) job_defs.catalog_name.toUtf8().data(), job_defs.enabled); #endif - setEnabled(true); + notify(true); return true; bail_out: - setEnabled(true); + notify(true); return false; } @@ -382,6 +381,7 @@ void Console::write_dir(const char *msg) mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); QBrush redBrush(Qt::red); m_consoleItem->setForeground(0, redBrush); + m_at_prompt = false; } } @@ -420,23 +420,22 @@ void Console::displayToPrompt() { int stat; if (commDebug) Pmsg0(000, "DisplaytoPrompt\n"); - m_notifier->setEnabled(false); - while ((stat = read()) > 0) { - display_text(msg()); + while (!m_at_prompt) { + if ((stat=read()) > 0) { + display_text(msg()); + } } if (commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat); - m_notifier->setEnabled(true); } void Console::discardToPrompt() { int stat; if (commDebug) Pmsg0(000, "discardToPrompt\n"); - m_notifier->setEnabled(false); - while ((stat = read()) > 0) { + while (!m_at_prompt) { + stat = read(); } if (commDebug) Pmsg1(000, "endDisplayToPrompt=%d\n", stat); - m_notifier->setEnabled(true); } @@ -445,7 +444,7 @@ void Console::discardToPrompt() */ int Console::read() { - int stat = BNET_HARDEOF; + int stat = 0; while (m_sock) { for (;;) { stat = bnet_wait_data_intr(m_sock, 1); @@ -453,10 +452,10 @@ int Console::read() break; } app->processEvents(); -// if (m_api_set && m_messages_pending) { -// write_dir(".messages"); -// m_messages_pending = false; -// } + if (m_api_set && m_messages_pending) { + write_dir(".messages"); + m_messages_pending = false; + } } stat = m_sock->recv(); if (stat >= 0) { @@ -465,25 +464,29 @@ int Console::read() m_at_prompt = false; } if (commDebug) Pmsg1(000, "got: %s", m_sock->msg); - } switch (m_sock->msglen) { case BNET_SERVER_READY: -// if (m_api_set && m_messages_pending) { -// write_dir(".messages"); -// m_messages_pending = false; -// } + if (m_api_set && m_messages_pending) { + write_dir(".messages"); + m_messages_pending = false; + } m_at_prompt = true; continue; - case BNET_MESSAGES_PENDING: + case BNET_MSGS_PENDING: + if (commDebug) Pmsg0(000, "MSGS PENDING\n"); m_messages_pending = true; continue; + case BNET_CMD_OK: + if (commDebug) Pmsg0(000, "CMD OK\n"); + m_at_prompt = false; + continue; case BNET_CMD_BEGIN: + if (commDebug) Pmsg0(000, "CMD BEGIN\n"); m_at_prompt = false; continue; case BNET_PROMPT: - case BNET_CMD_OK: - if (commDebug) Pmsg0(000, "CMD OK/PROMPT\n"); + if (commDebug) Pmsg0(000, "PROMPT\n"); m_at_prompt = true; mainWin->set_status(_("At prompt waiting for input ...")); update_cursor(); @@ -491,11 +494,11 @@ int Console::read() break; case BNET_CMD_FAILED: if (commDebug) Pmsg0(000, "CMD FAIL\n"); - m_at_prompt = true; mainWin->set_status(_("Command failed. At prompt waiting for input ...")); update_cursor(); QApplication::restoreOverrideCursor(); break; + /* We should not get this one */ case BNET_EOD: if (commDebug) Pmsg0(000, "EOD\n"); mainWin->set_status_ready(); @@ -508,6 +511,24 @@ int Console::read() case BNET_START_SELECT: new selectDialog(this); break; + case BNET_RUN_CMD: + new runCmdDialog(this); + break; + case BNET_ERROR_MSG: + m_sock->recv(); /* get the message */ + display_text(msg()); + QMessageBox::critical(this, "Error", msg(), QMessageBox::Ok); + break; + case BNET_WARNING_MSG: + m_sock->recv(); /* get the message */ + display_text(msg()); + QMessageBox::critical(this, "Warning", msg(), QMessageBox::Ok); + break; + case BNET_INFO_MSG: + m_sock->recv(); /* get the message */ + display_text(msg()); + mainWin->set_status(msg()); + break; } if (is_bnet_stop(m_sock)) { /* error or term request */ m_sock->close(); @@ -520,6 +541,7 @@ int Console::read() m_notifier = NULL; mainWin->set_status(_("Director disconnected.")); QApplication::restoreOverrideCursor(); + stat = BNET_HARDEOF; } break; } @@ -538,7 +560,17 @@ void Console::read_dir(int fd) } } -void Console::setEnabled(bool enable) +/* + * When the notifier is enabled, read_dir() will automatically be + * called by the Qt event loop when ever there is any output + * from the Directory, and read_dir() will then display it on + * the console. + * + * When we are in a bat dialog, we want to control *all* output + * from the Directory, so we set notify to off. + * m_console->notifiy(false); + */ +void Console::notify(bool enable) { m_notifier->setEnabled(enable); } diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 29347ed0cf..e0a94a3d6e 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -81,7 +81,7 @@ public: void writeSettings(); void readSettings(); char *msg(); - void setEnabled(bool enable); + void notify(bool enable); QStringList get_list(char *cmd); bool get_job_defaults(struct job_defaults &); void terminate(); diff --git a/bacula/src/qt-console/label/label.cpp b/bacula/src/qt-console/label/label.cpp index 12bd0da72c..7a8e6ce69c 100644 --- a/bacula/src/qt-console/label/label.cpp +++ b/bacula/src/qt-console/label/label.cpp @@ -40,6 +40,7 @@ labelDialog::labelDialog(Console *console) { m_console = console; + m_console->notify(false); setupUi(this); storageCombo->addItems(console->storage_list); poolCombo->addItems(console->pool_list); @@ -60,6 +61,7 @@ void labelDialog::accept() .arg(poolCombo->currentText()).arg(slotSpin->value()); m_console->write_dir(scmd.toUtf8().data()); m_console->displayToPrompt(); + m_console->notify(true); delete this; mainWin->resetFocus(); } @@ -70,4 +72,5 @@ void labelDialog::reject() this->hide(); delete this; mainWin->resetFocus(); + m_console->notify(true); } diff --git a/bacula/src/qt-console/label/label.ui b/bacula/src/qt-console/label/label.ui index c97c139193..a627f5c376 100644 --- a/bacula/src/qt-console/label/label.ui +++ b/bacula/src/qt-console/label/label.ui @@ -2,7 +2,7 @@ labelForm - Qt::ApplicationModal + Qt::WindowModal diff --git a/bacula/src/qt-console/main.cpp b/bacula/src/qt-console/main.cpp index 2777c43fa4..9c04b22997 100644 --- a/bacula/src/qt-console/main.cpp +++ b/bacula/src/qt-console/main.cpp @@ -38,6 +38,10 @@ #include #include "bat.h" +bool commDebug = false; +MainWin *mainWin; +QApplication *app; + /* Forward referenced functions */ void terminate_console(int sig); @@ -49,11 +53,6 @@ static int check_resources(); /* Static variables */ static char *configfile = NULL; -MainWin *mainWin; -QApplication *app; -bool commDebug = false; - - int main(int argc, char *argv[]) { diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 6bfcb67a19..0ffd4f1344 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -242,7 +242,7 @@ void MainWin::input_line() void MainWin::about() { QMessageBox::about(this, tr("About bat"), - tr("

bat 0.1

" + tr("

bat 0.2, by Kern Sibbald

" "

Copyright © " BYEAR " Free Software Foundation Europe e.V." "

The bat is an administrative console" " interface to the Director.")); diff --git a/bacula/src/qt-console/restore/prerestore.cpp b/bacula/src/qt-console/restore/prerestore.cpp index 2aefaeb98f..e366da7a4c 100644 --- a/bacula/src/qt-console/restore/prerestore.cpp +++ b/bacula/src/qt-console/restore/prerestore.cpp @@ -42,6 +42,7 @@ prerestoreDialog::prerestoreDialog(Console *console) { m_console = console; /* keep compiler quiet */ + m_console->notify(false); setupUi(this); jobCombo->addItems(console->job_list); filesetCombo->addItems(console->fileset_list); @@ -70,6 +71,7 @@ void prerestoreDialog::accept() m_console->write(cmd); m_console->display_text(cmd); + /* Note, do not turn notifier back on here ... */ new restoreDialog(m_console); delete this; } @@ -79,6 +81,7 @@ void prerestoreDialog::reject() { mainWin->set_status("Canceled"); this->hide(); + m_console->notify(true); delete this; } diff --git a/bacula/src/qt-console/restore/prerestore.ui b/bacula/src/qt-console/restore/prerestore.ui index d1cf00abd9..a506a251d4 100644 --- a/bacula/src/qt-console/restore/prerestore.ui +++ b/bacula/src/qt-console/restore/prerestore.ui @@ -2,7 +2,7 @@ prerestoreForm - Qt::ApplicationModal + Qt::WindowModal diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index 144a17667a..872dc29b29 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -41,9 +41,10 @@ restoreDialog::restoreDialog(Console *console) { QStringList titles; + m_console = console; - - m_console->setEnabled(false); + m_console->notify(false); /* this should already be off */ + setupUi(this); connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int))); @@ -139,7 +140,7 @@ void restoreDialog::accept() this->hide(); m_console->write("done"); delete this; - m_console->setEnabled(true); + m_console->notify(true); mainWin->resetFocus(); } @@ -150,7 +151,7 @@ void restoreDialog::reject() m_console->write("quit"); mainWin->set_status("Canceled"); delete this; - m_console->setEnabled(true); + m_console->notify(true); mainWin->resetFocus(); } @@ -236,15 +237,16 @@ bool restoreDialog::cwd(const char *dir) bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"", dir); Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd); m_console->write_dir(cd_cmd); + lineEdit->clear(); if ((stat = m_console->read()) > 0) { m_cwd = m_console->msg(); - Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg()); + lineEdit->insert(m_cwd); + Dmsg2(000, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg()); } else { Dmsg1(000, "stat=%d\n", stat); + QMessageBox::critical(this, "Error", "cd command failed", QMessageBox::Ok); } m_console->discardToPrompt(); - lineEdit->clear(); - lineEdit->insert(m_cwd); return true; /* ***FIXME*** return real status */ } @@ -261,7 +263,9 @@ char *restoreDialog::get_cwd() Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg()); } else { Dmsg1(000, "stat=%d\n", stat); + QMessageBox::critical(this, "Error", ".pwd command failed", QMessageBox::Ok); + Dmsg1(000, "stat=%d\n", stat); } - m_console->displayToPrompt(); + m_console->discardToPrompt(); return m_cwd.toUtf8().data(); } diff --git a/bacula/src/qt-console/restore/restore.ui b/bacula/src/qt-console/restore/restore.ui index 6e89bc371d..f98c8d2338 100644 --- a/bacula/src/qt-console/restore/restore.ui +++ b/bacula/src/qt-console/restore/restore.ui @@ -2,7 +2,7 @@ restoreForm - Qt::ApplicationModal + Qt::WindowModal diff --git a/bacula/src/qt-console/run/run.cpp b/bacula/src/qt-console/run/run.cpp index 9f1b65b2f6..2124c0bdd2 100644 --- a/bacula/src/qt-console/run/run.cpp +++ b/bacula/src/qt-console/run/run.cpp @@ -45,6 +45,7 @@ runDialog::runDialog(Console *console) QDateTime dt; m_console = console; + m_console->notify(false); setupUi(this); m_console->beginNewCommand(); jobCombo->addItems(console->job_list); @@ -81,6 +82,7 @@ void runDialog::accept() m_console->write_dir(cmd); m_console->display_text(cmd); m_console->displayToPrompt(); + m_console->notify(true); delete this; mainWin->resetFocus(); } @@ -90,6 +92,7 @@ void runDialog::reject() { mainWin->set_status(" Canceled"); this->hide(); + m_console->notify(true); delete this; mainWin->resetFocus(); } diff --git a/bacula/src/qt-console/run/run.h b/bacula/src/qt-console/run/run.h index 7feb08381e..14d2bbd9a6 100644 --- a/bacula/src/qt-console/run/run.h +++ b/bacula/src/qt-console/run/run.h @@ -23,4 +23,21 @@ private: }; +class runCmdDialog : public QDialog, public Ui::runForm +{ + Q_OBJECT + +public: + runCmdDialog(Console *console); + +public slots: + void accept(); + void reject(); + +private: + Console *m_console; + +}; + + #endif /* _RUN_H_ */ diff --git a/bacula/src/qt-console/run/run.ui b/bacula/src/qt-console/run/run.ui index 5c76ccf061..87c16237b3 100644 --- a/bacula/src/qt-console/run/run.ui +++ b/bacula/src/qt-console/run/run.ui @@ -2,7 +2,7 @@ runForm - Qt::ApplicationModal + Qt::WindowModal diff --git a/bacula/src/qt-console/run/runcmd.cpp b/bacula/src/qt-console/run/runcmd.cpp new file mode 100644 index 0000000000..ab63a7e240 --- /dev/null +++ b/bacula/src/qt-console/run/runcmd.cpp @@ -0,0 +1,73 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ + +/* + * Run Command Dialog class + * + * Kern Sibbald, March MMVII + * + * $Id: $ + */ + +#include "bat.h" +#include "run.h" + +/* + * Setup all the combo boxes and display the dialog + */ +runCmdDialog::runCmdDialog(Console *console) +{ + QDateTime dt; + + m_console = console; + m_console->notify(false); + setupUi(this); + this->show(); +} + +void runCmdDialog::accept() +{ + + this->hide(); + + m_console->write_dir("yes"); + m_console->displayToPrompt(); + m_console->notify(true); + delete this; + mainWin->resetFocus(); +} + + +void runCmdDialog::reject() +{ + mainWin->set_status(" Canceled"); + this->hide(); + m_console->notify(true); + delete this; + mainWin->resetFocus(); +} diff --git a/bacula/src/qt-console/run/runcmd.ui b/bacula/src/qt-console/run/runcmd.ui new file mode 100644 index 0000000000..2e3131ec97 --- /dev/null +++ b/bacula/src/qt-console/run/runcmd.ui @@ -0,0 +1,407 @@ + + runCmdForm + + + Qt::NonModal + + + + 0 + 0 + 590 + 395 + + + + Run Job Command + + + + 9 + + + 6 + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 572 + 16 + + + + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 572 + 16 + + + + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + + 0 + 2 + 0 + 2000 + 1 + 1 + + + + yyyy-mm-dd hh:mm:ss + + + true + + + + + + + When: + + + dateTimeEdit + + + + + + + Bootstrap: + + + true + + + where + + + + + + + Where: + + + bootstrap + + + + + + + + + + + + + Job: + + + jobCombo + + + + + + + false + + + + 200 + 0 + + + + false + + + + + + + Storage: + + + storageCombo + + + + + + + FileSet: + + + filesetCombo + + + + + + + false + + + + 200 + 0 + + + + false + + + + + + + + + + + + + + + + Replace: + + + + + + + + + + Client: + + + clientCombo + + + + + + + Catalog: + + + catalogCombo + + + + + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + 10000 + + + 1 + + + 10 + + + + + + + + 5 + 0 + 0 + 0 + + + + + 150 + 0 + + + + + + + + Priority: + + + prioritySpin + + + + + + + Type: + + + typeCombo + + + + + + + + + Qt::Vertical + + + + 20 + 171 + + + + + + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 131 + 25 + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + buttonBox + accepted() + runCmdForm + accept() + + + 258 + 480 + + + 157 + 274 + + + + + buttonBox + rejected() + runCmdForm + reject() + + + 326 + 480 + + + 286 + 274 + + + + + diff --git a/bacula/src/version.h b/bacula/src/version.h index ce4f11bc22..b121031ab2 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "2.1.4" -#define BDATE "06 March 2007" -#define LSMDATE "06Mar07" +#define VERSION "2.1.5" +#define BDATE "10 March 2007" +#define LSMDATE "10Mar07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 59ff9f4c92..366f4675d5 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,10 @@ Technical notes on version 2.1 General: +10Mar07 +kes Extend new GUI API. +kes Make the ua structure a class, and implement send_msg(), + error_msg(), warning_msg(), and info_msg(). 08Mar07 kes Apply fix from for building wx-console on the Mac from bug #798.