summaryrefslogtreecommitdiff
path: root/noncore
authordwmw2 <dwmw2>2002-09-23 08:37:16 (UTC)
committer dwmw2 <dwmw2>2002-09-23 08:37:16 (UTC)
commit8b06ea9e4407628ebae54d63592e8b8c940a62ad (patch) (unidiff)
tree344af00df0e403c5b5d5475e641489213ace46f7 /noncore
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 (limited to 'noncore') (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
@@ -49,7 +49,7 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl )
49 connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), 49 connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)),
50 this, SLOT(log_sshadd_output(OProcess*,char*,int))); 50 this, SLOT(log_sshadd_output(OProcess*,char*,int)));
51 connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), 51 connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)),
52 this, SLOT(log_sshadd_output(OProcess*,char*,int))); 52 this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
53 connect(&addprocess, SIGNAL(processExited(OProcess*)), 53 connect(&addprocess, SIGNAL(processExited(OProcess*)),
54 this, SLOT(ssh_add_exited(OProcess*))); 54 this, SLOT(ssh_add_exited(OProcess*)));
55 55
@@ -90,7 +90,7 @@ void SSHKeysApp::doRefreshListButton()
90 connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), 90 connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
91 this, SLOT(get_list_keys_output(OProcess*,char*,int))); 91 this, SLOT(get_list_keys_output(OProcess*,char*,int)));
92 connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), 92 connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)),
93 this, SLOT(log_sshadd_output(OProcess*,char*,int))); 93 this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
94 94
95 keystate = KeySize; 95 keystate = KeySize;
96 incoming_keyname=""; 96 incoming_keyname="";
@@ -104,6 +104,7 @@ void SSHKeysApp::doRefreshListButton()
104 log_text(tr("Error running ssh-add")); 104 log_text(tr("Error running ssh-add"));
105 return; 105 return;
106 } 106 }
107 flush_sshadd_output();
107 if (sshadd_process.exitStatus() == 2) { 108 if (sshadd_process.exitStatus() == 2) {
108 setEnabled(FALSE); 109 setEnabled(FALSE);
109 } 110 }
@@ -177,12 +178,49 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
177 } 178 }
178} 179}
179 180
181void SSHKeysApp::flush_sshadd_output(void)
182{
183 if (pending_stdout.length()) {
184 log_text(pending_stdout.ascii());
185 }
186 pending_stdout = "";
187
188 if (pending_stderr.length()) {
189 log_text(pending_stderr.ascii());
190 }
191 pending_stderr = "";
192}
193
180void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) 194void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen)
181{ 195{
182 (void)proc; 196 (void) proc;
183 (void)buflen;
184 197
185 log_text(buffer); 198 while (buflen) {
199 if (*buffer == '\n') {
200 log_text(pending_stdout);
201 pending_stdout = "";
202 } else {
203 pending_stdout += *buffer;
204 }
205 buffer++;
206 buflen--;
207 }
208}
209
210void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen)
211{
212 (void) proc;
213
214 while (buflen) {
215 if (*buffer == '\n') {
216 log_text(pending_stderr);
217 pending_stderr = "";
218 } else {
219 pending_stderr += *buffer;
220 }
221 buffer++;
222 buflen--;
223 }
186} 224}
187 225
188void SSHKeysApp::ssh_add_exited(OProcess *proc) 226void SSHKeysApp::ssh_add_exited(OProcess *proc)
@@ -216,10 +254,10 @@ void SSHKeysApp::doAddButton()
216 254
217 if (KeyFileName->currentText().length()) { 255 if (KeyFileName->currentText().length()) {
218 addprocess << "ssh-add" << "--" << KeyFileName->currentText(); 256 addprocess << "ssh-add" << "--" << KeyFileName->currentText();
219 log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); 257 // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText());
220 } else { 258 } else {
221 addprocess << "ssh-add"; 259 addprocess << "ssh-add";
222 log_text(tr("Running ssh-add")); 260 // log_text(tr("Running ssh-add"));
223 } 261 }
224 bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); 262 bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput);
225 if (!ret) { 263 if (!ret) {
@@ -227,6 +265,7 @@ void SSHKeysApp::doAddButton()
227 doRefreshListButton(); 265 doRefreshListButton();
228 setEnabled(TRUE); 266 setEnabled(TRUE);
229 } 267 }
268 flush_sshadd_output();
230} 269}
231 270
232void SSHKeysApp::log_text(const char *text) 271void SSHKeysApp::log_text(const char *text)
@@ -242,13 +281,14 @@ void SSHKeysApp::doRemoveAllButton()
242 connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), 281 connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)),
243 this, SLOT(log_sshadd_output(OProcess*,char*,int))); 282 this, SLOT(log_sshadd_output(OProcess*,char*,int)));
244 connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), 283 connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)),
245 this, SLOT(log_sshadd_output(OProcess*,char*,int))); 284 this, SLOT(log_sshadd_stderr(OProcess*,char*,int)));
246 285
247 log_text(tr("Running ssh-add -D")); 286 //log_text(tr("Running ssh-add -D"));
248 sshadd_process << "ssh-add" << "-D"; 287 sshadd_process << "ssh-add" << "-D";
249 bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); 288 bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
250 if (!ret) { 289 if (!ret) {
251 log_text(tr("Error running ssh-add")); 290 log_text(tr("Error running ssh-add"));
252 } 291 }
292 flush_sshadd_output();
253 doRefreshListButton(); 293 doRefreshListButton();
254} 294}
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
@@ -35,12 +35,16 @@ class SSHKeysApp : public SSHKeysBase
35 35
36 private: 36 private:
37 void log_text(const char *text); 37 void log_text(const char *text);
38 void flush_sshadd_output(void);
39
38 enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; 40 enum { Noise, KeyName, KeySize, KeyFingerprint } keystate;
39 QString incoming_keyname; 41 QString incoming_keyname;
40 QString incoming_keysize; 42 QString incoming_keysize;
41 QString incoming_keyfingerprint; 43 QString incoming_keyfingerprint;
42 QString incoming_noise; 44 QString incoming_noise;
43 OProcess addprocess; 45 OProcess addprocess;
46 QString pending_stdout;
47 QString pending_stderr;
44 48
45 private slots: 49 private slots:
46 void doAddButton(); 50 void doAddButton();
@@ -48,6 +52,7 @@ class SSHKeysApp : public SSHKeysBase
48 void doRemoveAllButton(); 52 void doRemoveAllButton();
49 void get_list_keys_output(OProcess *proc, char *buffer, int buflen); 53 void get_list_keys_output(OProcess *proc, char *buffer, int buflen);
50 void log_sshadd_output(OProcess *proc, char *buffer, int buflen); 54 void log_sshadd_output(OProcess *proc, char *buffer, int buflen);
55 void log_sshadd_stderr(OProcess *proc, char *buffer, int buflen);
51 void ssh_add_exited(OProcess *proc); 56 void ssh_add_exited(OProcess *proc);
52 void add_text_changed(const QString &text); 57 void add_text_changed(const QString &text);
53}; 58};