summaryrefslogtreecommitdiff
authordwmw2 <dwmw2>2002-09-23 08:37:16 (UTC)
committer dwmw2 <dwmw2>2002-09-23 08:37:16 (UTC)
commit8b06ea9e4407628ebae54d63592e8b8c940a62ad (patch) (side-by-side diff)
tree344af00df0e403c5b5d5475e641489213ace46f7
parentd7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f (diff)
downloadopie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.zip
opie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.tar.gz
opie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.tar.bz2
Log stderr more sanely, fix buffer abuse. It is really sane to use '+=' on
a QString? Do I care? It's C++, let it do what it does best -- hide implementation details like the fact that some stuff _really_ sucks and encourage the programmer to do those things :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sshkeys/sshkeys.cpp58
-rw-r--r--noncore/settings/sshkeys/sshkeys.h5
2 files changed, 54 insertions, 9 deletions
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp
index c5e1170..43e02af 100644
--- a/noncore/settings/sshkeys/sshkeys.cpp
+++ b/noncore/settings/sshkeys/sshkeys.cpp
@@ -40,25 +40,25 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl )
: SSHKeysBase( parent, name, fl )
{
char *home = getenv("HOME");
unsigned i;
connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton()));
connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton()));
connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton()));
connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)),
this, SLOT(log_sshadd_output(OProcess*,char*,int)));
connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)),
- this, SLOT(log_sshadd_output(OProcess*,char*,int)));
+ this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
connect(&addprocess, SIGNAL(processExited(OProcess*)),
this, SLOT(ssh_add_exited(OProcess*)));
connect(KeyFileName, SIGNAL(textChanged(const QString&)),
this, SLOT(add_text_changed(const QString&)));
if (home) {
for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) {
char thiskeyname[32];
thiskeyname[31] = 0;
snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]);
@@ -81,38 +81,39 @@ void SSHKeysApp::doRefreshListButton()
QListViewItem *t = KeyList->firstChild();
while(t) {
QListViewItem *next = t->nextSibling();
KeyList->takeItem(t);
delete(t);
t = next;
}
connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
this, SLOT(get_list_keys_output(OProcess*,char*,int)));
connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)),
- this, SLOT(log_sshadd_output(OProcess*,char*,int)));
+ this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
keystate = KeySize;
incoming_keyname="";
incoming_keysize="";
incoming_keyfingerprint="";
// log_text("Running ssh-add -l");
sshadd_process << "ssh-add" << "-l";
bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
if (!ret) {
log_text(tr("Error running ssh-add"));
return;
}
+ flush_sshadd_output();
if (sshadd_process.exitStatus() == 2) {
setEnabled(FALSE);
}
}
void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
{
int i;
(void) proc;
for (i=0; i<buflen; i++) {
switch(keystate) {
@@ -168,30 +169,67 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
} else {
incoming_keysize = "";
incoming_keyfingerprint = "";
incoming_noise = "";
keystate = Noise;
goto noise;
}
break;
}
}
}
+void SSHKeysApp::flush_sshadd_output(void)
+{
+ if (pending_stdout.length()) {
+ log_text(pending_stdout.ascii());
+ }
+ pending_stdout = "";
+
+ if (pending_stderr.length()) {
+ log_text(pending_stderr.ascii());
+ }
+ pending_stderr = "";
+}
+
void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen)
{
- (void)proc;
- (void)buflen;
+ (void) proc;
- log_text(buffer);
+ while (buflen) {
+ if (*buffer == '\n') {
+ log_text(pending_stdout);
+ pending_stdout = "";
+ } else {
+ pending_stdout += *buffer;
+ }
+ buffer++;
+ buflen--;
+ }
+}
+
+void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen)
+{
+ (void) proc;
+
+ while (buflen) {
+ if (*buffer == '\n') {
+ log_text(pending_stderr);
+ pending_stderr = "";
+ } else {
+ pending_stderr += *buffer;
+ }
+ buffer++;
+ buflen--;
+ }
}
void SSHKeysApp::ssh_add_exited(OProcess *proc)
{
(void)proc;
doRefreshListButton();
setEnabled(TRUE);
if (proc->exitStatus() == 2) {
setEnabled(FALSE);
}
}
@@ -207,48 +245,50 @@ void SSHKeysApp::add_text_changed(const QString &text)
else
AddButton->setEnabled(FALSE);
}
void SSHKeysApp::doAddButton()
{
addprocess.clearArguments();
setEnabled(FALSE);
if (KeyFileName->currentText().length()) {
addprocess << "ssh-add" << "--" << KeyFileName->currentText();
- log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText());
+// log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText());
} else {
addprocess << "ssh-add";
- log_text(tr("Running ssh-add"));
+// log_text(tr("Running ssh-add"));
}
bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput);
if (!ret) {
log_text(tr("Error running ssh-add"));
doRefreshListButton();
setEnabled(TRUE);
}
+ flush_sshadd_output();
}
void SSHKeysApp::log_text(const char *text)
{
TextOutput->append(text);
TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE);
}
void SSHKeysApp::doRemoveAllButton()
{
OProcess sshadd_process;
connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
this, SLOT(log_sshadd_output(OProcess*,char*,int)));
connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)),
- this, SLOT(log_sshadd_output(OProcess*,char*,int)));
+ this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
- log_text(tr("Running ssh-add -D"));
+// log_text(tr("Running ssh-add -D"));
sshadd_process << "ssh-add" << "-D";
bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
if (!ret) {
log_text(tr("Error running ssh-add"));
}
+ flush_sshadd_output();
doRefreshListButton();
}
diff --git a/noncore/settings/sshkeys/sshkeys.h b/noncore/settings/sshkeys/sshkeys.h
index 5e306d1..bbc6993 100644
--- a/noncore/settings/sshkeys/sshkeys.h
+++ b/noncore/settings/sshkeys/sshkeys.h
@@ -26,30 +26,35 @@
#include <opie/oprocess.h>
class SSHKeysApp : public SSHKeysBase
{
Q_OBJECT
public:
SSHKeysApp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~SSHKeysApp();
private:
void log_text(const char *text);
+ void flush_sshadd_output(void);
+
enum { Noise, KeyName, KeySize, KeyFingerprint } keystate;
QString incoming_keyname;
QString incoming_keysize;
QString incoming_keyfingerprint;
QString incoming_noise;
OProcess addprocess;
+ QString pending_stdout;
+ QString pending_stderr;
private slots:
void doAddButton();
void doRefreshListButton();
void doRemoveAllButton();
void get_list_keys_output(OProcess *proc, char *buffer, int buflen);
void log_sshadd_output(OProcess *proc, char *buffer, int buflen);
+ void log_sshadd_stderr(OProcess *proc, char *buffer, int buflen);
void ssh_add_exited(OProcess *proc);
void add_text_changed(const QString &text);
};
#endif