/*
Bacula® - The Network Backup Solution
- Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2010 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.
Switzerland, email:ftf@fsfeurope.org.
*/
/*
- * Version $Id$
- *
- * Console Class
+ * DirComm, Director communications,class
*
* Kern Sibbald, January MMVII
*
#include "console.h"
#include "restore.h"
#include "select.h"
+#include "textinput.h"
#include "run/run.h"
static int tls_pem_callback(char *buf, int size, const void *userdata);
-DirComm::DirComm(Console *parent, int conn):
-m_notifier(NULL),
-m_api_set(false)
+DirComm::DirComm(Console *parent, int conn): m_notifier(NULL), m_api_set(false)
{
m_console = parent;
m_sock = NULL;
m_at_main_prompt = false;
m_conn = conn;
m_in_command = 0;
+ m_in_select = false;
}
DirComm::~DirComm()
delete m_notifier;
m_notifier = NULL;
}
+ if (mainWin->m_connDebug)
+ Pmsg2(000, "DirComm %i terminating connections %s\n", m_conn, m_console->m_dir->name());
m_sock->close();
m_sock = NULL;
}
mainWin->set_status( tr("Already connected."));
m_console->display_textf(_("Already connected\"%s\".\n"),
m_console->m_dir->name());
- if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i BAILING already connected\n", m_conn);
+ if (mainWin->m_connDebug) {
+ Pmsg2(000, "DirComm %i BAILING already connected %s\n", m_conn, m_console->m_dir->name());
+ }
goto bail_out;
}
+ if (mainWin->m_connDebug) {
+ Pmsg2(000, "DirComm %i connecting %s\n", m_conn, m_console->m_dir->name());
+ }
memset(jcr, 0, sizeof(JCR));
mainWin->set_statusf(_("Connecting to Director %s:%d"), m_console->m_dir->address, m_console->m_dir->DIRport);
- m_console->display_textf(_("Connecting to Director %s:%d\n\n"), m_console->m_dir->address, m_console->m_dir->DIRport);
+ if (m_conn == 0) {
+ m_console->display_textf(_("Connecting to Director %s:%d\n\n"), m_console->m_dir->address, m_console->m_dir->DIRport);
+ }
/* Give GUI a chance */
app->processEvents();
m_console->display_textf(_("Failed to initialize TLS context for Console \"%s\".\n"),
m_console->m_dir->name());
if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i BAILING Failed to initialize TLS context for Console \n", m_conn);
+ Pmsg2(000, "DirComm %i BAILING Failed to initialize TLS context for Console %s\n", m_conn, m_console->m_dir->name());
goto bail_out;
}
}
m_console->m_dir->name());
mainWin->set_status("Connection failed");
if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i BAILING Failed to initialize TLS context for Director \n", m_conn);
+ Pmsg2(000, "DirComm %i BAILING Failed to initialize TLS context for Director %s\n", m_conn, m_console->m_dir->name());
goto bail_out;
}
}
if (m_sock == NULL) {
mainWin->set_status("Connection failed");
if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i BAILING Connection failed\n", m_conn);
+ Pmsg2(000, "DirComm %i BAILING Connection failed %s\n", m_conn, m_console->m_dir->name());
goto bail_out;
} else {
/* Update page selector to green to indicate that Console is connected */
if (!authenticate_director(jcr, m_console->m_dir, cons, buf, sizeof(buf))) {
m_console->display_text(buf);
if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i BAILING Connection failed\n", m_conn);
+ Pmsg2(000, "DirComm %i BAILING Connection failed %s\n", m_conn, m_console->m_dir->name());
goto bail_out;
}
mainWin->set_status(_("Initializing ..."));
-#ifndef HAVE_WIN32
- /* Set up input notifier */
+ /*
+ * Set up input notifier
+ */
m_notifier = new QSocketNotifier(m_sock->m_fd, QSocketNotifier::Read, 0);
QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
-#endif
+ m_notifier->setEnabled(false);
write(".api 1");
m_api_set = true;
mainWin->set_status(_("Connected"));
- if (mainWin->m_connDebug)
- Pmsg1(000, "Returning TRUE from DirComm->connect_dir : %i\n", m_conn);
+ if (mainWin->m_connDebug) {
+ Pmsg2(000, "Returning TRUE from DirComm->connect_dir : %i %s\n", m_conn, m_console->m_dir->name());
+ }
return true;
bail_out:
- if (mainWin->m_connDebug)
- Pmsg1(000, "Returning FALSE from DirComm->connect_dir : %i\n", m_conn);
+ if (mainWin->m_connDebug) {
+ Pmsg2(000, "Returning FALSE from DirComm->connect_dir : %i %s\n", m_conn, m_console->m_dir->name());
+ }
delete jcr;
return false;
}
m_sock->msglen = pm_strcpy(m_sock->msg, msg);
m_at_prompt = false;
m_at_main_prompt = false;
- if (mainWin->m_commDebug) Pmsg1(000, "send: %s\n", msg);
+ if (mainWin->m_commDebug) Pmsg2(000, "conn %i send: %s\n", m_conn, msg);
return m_sock->send();
}
*/
int DirComm::read()
{
- int stat = 0;
+ int stat = -1;
+
+ if (!m_sock) {
+ return -1;
+ }
while (m_sock) {
for (;;) {
+ if (!m_sock) break;
stat = m_sock->wait_data_intr(0, 50000);
if (stat > 0) {
break;
}
app->processEvents();
if (m_api_set && m_console->is_messagesPending() && is_notify_enabled() && m_console->hasFocus()) {
- m_console->write_dir(m_conn, ".messages");
+ m_console->write_dir(m_conn, ".messages", false);
m_console->messagesPending(false);
}
}
+ if (!m_sock) {
+ return -1;
+ }
m_sock->msg[0] = 0;
stat = sock_read();
if (stat >= 0) {
- if (mainWin->m_commDebug) Pmsg1(000, "got: %s\n", m_sock->msg);
+ if (mainWin->m_commDebug) Pmsg2(000, "conn %i got: %s\n", m_conn, m_sock->msg);
if (m_at_prompt) {
m_console->display_text("\n");
m_at_prompt = false;
switch (m_sock->msglen) {
case BNET_MSGS_PENDING :
if (is_notify_enabled() && m_console->hasFocus()) {
- if (mainWin->m_commDebug) Pmsg0(000, "MSGS PENDING\n");
- m_console->write_dir(m_conn, ".messages");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i MSGS PENDING\n", m_conn);
+ m_console->write_dir(m_conn, ".messages", false);
m_console->displayToPrompt(m_conn);
m_console->messagesPending(false);
}
m_console->messagesPending(true);
continue;
case BNET_CMD_OK:
- if (mainWin->m_commDebug) Pmsg0(000, "CMD OK\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i CMD OK\n", m_conn);
m_at_prompt = false;
m_at_main_prompt = false;
-// Pmsg1(000, "before dec m_in_command=%d\n", m_in_command);
if (--m_in_command < 0) {
-// Pmsg0(000, "m_in_command < 0\n");
m_in_command = 0;
}
mainWin->set_status(_("Command completed ..."));
continue;
case BNET_CMD_BEGIN:
- if (mainWin->m_commDebug) Pmsg0(000, "CMD BEGIN\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i CMD BEGIN\n", m_conn);
m_at_prompt = false;
m_at_main_prompt = false;
m_in_command++;
-// Pmsg1(000, "after inc m_in_command=%d\n", m_in_command);
mainWin->set_status(_("Processing command ..."));
continue;
case BNET_MAIN_PROMPT:
- if (mainWin->m_commDebug) Pmsg0(000, "MAIN PROMPT\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i MAIN PROMPT\n", m_conn);
m_at_prompt = true;
m_at_main_prompt = true;
mainWin->set_status(_("At main prompt waiting for input ..."));
- QApplication::restoreOverrideCursor();
break;
case BNET_PROMPT:
- if (mainWin->m_commDebug) Pmsg0(000, "PROMPT\n");
+ if (mainWin->m_commDebug) Pmsg2(000, "conn %i PROMPT m_in_select %i\n", m_conn, m_in_select);
m_at_prompt = true;
m_at_main_prompt = false;
mainWin->set_status(_("At prompt waiting for input ..."));
- QApplication::restoreOverrideCursor();
+ /***** FIXME *****/
+ /* commented out until the prompt communication issue with the director is resolved
+ * This is where I call a new text input dialog class to prevent the connection issues
+ * when a text input is requited.
+ * if (!m_in_select) {
+ * new textInputDialog(m_console, m_conn);
+ * }
+ */
break;
case BNET_CMD_FAILED:
- if (mainWin->m_commDebug) Pmsg0(000, "CMD FAILED\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "CMD FAILED\n", m_conn);
if (--m_in_command < 0) {
- Pmsg0(000, "m_in_command < 0\n");
+ m_in_command = 0;
}
mainWin->set_status(_("Command failed."));
- QApplication::restoreOverrideCursor();
break;
/* We should not get this one */
case BNET_EOD:
- if (mainWin->m_commDebug) Pmsg0(000, "EOD\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i EOD\n", m_conn);
mainWin->set_status_ready();
- QApplication::restoreOverrideCursor();
if (!m_api_set) {
break;
}
continue;
case BNET_START_SELECT:
- if (mainWin->m_commDebug) Pmsg0(000, "START SELECT\n");
- new selectDialog(m_console);
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i START SELECT\n", m_conn);
+ m_in_select = true;
+ new selectDialog(m_console, m_conn);
+ m_in_select = false;
break;
case BNET_YESNO:
- if (mainWin->m_commDebug) Pmsg0(000, "YESNO\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i YESNO\n", m_conn);
new yesnoPopUp(m_console, m_conn);
break;
case BNET_RUN_CMD:
- if (mainWin->m_commDebug) Pmsg0(000, "RUN CMD\n");
- new runCmdPage();
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i RUN CMD\n", m_conn);
+ new runCmdPage(m_conn);
break;
case BNET_START_RTREE:
- if (mainWin->m_commDebug) Pmsg0(000, "START RTREE CMD\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i START RTREE CMD\n", m_conn);
new restorePage(m_conn);
break;
case BNET_END_RTREE:
- if (mainWin->m_commDebug) Pmsg0(000, "END RTREE CMD\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i END RTREE CMD\n", m_conn);
break;
case BNET_ERROR_MSG:
- if (mainWin->m_commDebug) Pmsg0(000, "ERROR MSG\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i ERROR MSG\n", m_conn);
stat = sock_read(); /* get the message */
m_console->display_text(msg());
QMessageBox::critical(m_console, "Error", msg(), QMessageBox::Ok);
break;
case BNET_WARNING_MSG:
- if (mainWin->m_commDebug) Pmsg0(000, "WARNING MSG\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i WARNING MSG\n", m_conn);
stat = sock_read(); /* get the message */
- m_console->display_text(msg());
- QMessageBox::critical(m_console, "Warning", msg(), QMessageBox::Ok);
+ if (!m_console->m_warningPrevent) {
+ QMessageBox::critical(m_console, "Warning", msg(), QMessageBox::Ok);
+ }
break;
case BNET_INFO_MSG:
- if (mainWin->m_commDebug) Pmsg0(000, "INFO MSG\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i INFO MSG\n", m_conn);
stat = sock_read(); /* get the message */
m_console->display_text(msg());
mainWin->set_status(msg());
break;
}
if (is_bnet_stop(m_sock)) { /* error or term request */
- if (mainWin->m_commDebug) Pmsg0(000, "BNET STOP\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "conn %i BNET STOP\n", m_conn);
m_console->stopTimer();
m_sock->close();
m_sock = NULL;
m_notifier = NULL;
}
mainWin->set_status(_("Director disconnected."));
- QApplication::restoreOverrideCursor();
stat = BNET_HARDEOF;
}
break;
/* Called by signal when the Director has output for us */
void DirComm::read_dir(int /* fd */)
{
- if (mainWin->m_commDebug) Pmsg0(000, "read_dir\n");
- while (read() >= 0) {
- m_console->display_text(msg());
+ int stat;
+ if (mainWin->m_commDebug) Pmsg1(000, "enter read_dir conn %i read_dir\n", m_conn);
+ stat = m_sock->wait_data(0, 5000);
+ if (stat > 0) {
+ if (mainWin->m_commDebug) Pmsg2(000, "read_dir conn %i stat=%d\n", m_conn, stat);
+ while (read() >= 0) {
+ m_console->display_text(msg());
+ }
}
+ if (mainWin->m_commDebug) Pmsg2(000, "exit read_dir conn %i stat=%d\n", m_conn, stat);
}
/*
if (m_notifier) {
prev_enabled = m_notifier->isEnabled();
m_notifier->setEnabled(enable);
- if (mainWin->m_connDebug)
- if (prev_enabled && !enable)
- Pmsg1(000, "m_notifier Disabling notifier: %i\n", m_conn);
- else if (!prev_enabled && enable)
- Pmsg1(000, "m_notifier Enabling notifier: %i\n", m_conn);
- } else if (mainWin->m_connDebug)
- Pmsg1(000, "m_notifier does not exist: %i\n", m_conn);
+ if (mainWin->m_connDebug) {
+ Pmsg3(000, "conn=%i notify=%d prev=%d\n", m_conn, enable, prev_enabled);
+ }
+ } else if (mainWin->m_connDebug)
+ Pmsg2(000, "m_notifier does not exist: %i %s\n", m_conn, m_console->m_dir->name());
return prev_enabled;
}
bool DirComm::is_notify_enabled() const
{
bool enabled = false;
- if (m_notifier)
+ if (m_notifier) {
enabled = m_notifier->isEnabled();
+ }
return enabled;
}
(void)size;
(void)userdata;
#ifdef HAVE_TLS
- const char *prompt = (const char *)userdata;
# if defined(HAVE_WIN32)
//sendit(prompt);
if (win32_cgets(buf, size) == NULL) {
return strlen(buf);
}
# else
+ const char *prompt = (const char *)userdata;
char *passwd;
passwd = getpass(prompt);