summaryrefslogtreecommitdiff
Unidiff
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 )
40 : SSHKeysBase( parent, name, fl ) 40 : SSHKeysBase( parent, name, fl )
41{ 41{
42 char *home = getenv("HOME"); 42 char *home = getenv("HOME");
43 unsigned i; 43 unsigned i;
44 44
45 connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); 45 connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton()));
46 connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); 46 connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton()));
47 connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); 47 connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton()));
48 48
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
56 connect(KeyFileName, SIGNAL(textChanged(const QString&)), 56 connect(KeyFileName, SIGNAL(textChanged(const QString&)),
57 this, SLOT(add_text_changed(const QString&))); 57 this, SLOT(add_text_changed(const QString&)));
58 58
59 if (home) { 59 if (home) {
60 for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { 60 for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) {
61 char thiskeyname[32]; 61 char thiskeyname[32];
62 62
63 thiskeyname[31] = 0; 63 thiskeyname[31] = 0;
64 snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); 64 snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]);
@@ -81,38 +81,39 @@ void SSHKeysApp::doRefreshListButton()
81 QListViewItem *t = KeyList->firstChild(); 81 QListViewItem *t = KeyList->firstChild();
82 82
83 while(t) { 83 while(t) {
84 QListViewItem *next = t->nextSibling(); 84 QListViewItem *next = t->nextSibling();
85 KeyList->takeItem(t); 85 KeyList->takeItem(t);
86 delete(t); 86 delete(t);
87 t = next; 87 t = next;
88 } 88 }
89 89
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="";
97 incoming_keysize=""; 97 incoming_keysize="";
98 incoming_keyfingerprint=""; 98 incoming_keyfingerprint="";
99 99
100 //log_text("Running ssh-add -l"); 100 //log_text("Running ssh-add -l");
101 sshadd_process << "ssh-add" << "-l"; 101 sshadd_process << "ssh-add" << "-l";
102 bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); 102 bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput);
103 if (!ret) { 103 if (!ret) {
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 }
110} 111}
111 112
112void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) 113void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
113{ 114{
114 int i; 115 int i;
115 (void) proc; 116 (void) proc;
116 117
117 for (i=0; i<buflen; i++) { 118 for (i=0; i<buflen; i++) {
118 switch(keystate) { 119 switch(keystate) {
@@ -168,30 +169,67 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen)
168 } else { 169 } else {
169 incoming_keysize = ""; 170 incoming_keysize = "";
170 incoming_keyfingerprint = ""; 171 incoming_keyfingerprint = "";
171 incoming_noise = ""; 172 incoming_noise = "";
172 keystate = Noise; 173 keystate = Noise;
173 goto noise; 174 goto noise;
174 } 175 }
175 break; 176 break;
176 } 177 }
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)
189{ 227{
190 (void)proc; 228 (void)proc;
191 229
192 doRefreshListButton(); 230 doRefreshListButton();
193 setEnabled(TRUE); 231 setEnabled(TRUE);
194 if (proc->exitStatus() == 2) { 232 if (proc->exitStatus() == 2) {
195 setEnabled(FALSE); 233 setEnabled(FALSE);
196 } 234 }
197} 235}
@@ -207,48 +245,50 @@ void SSHKeysApp::add_text_changed(const QString &text)
207 else 245 else
208 AddButton->setEnabled(FALSE); 246 AddButton->setEnabled(FALSE);
209} 247}
210 248
211void SSHKeysApp::doAddButton() 249void SSHKeysApp::doAddButton()
212{ 250{
213 addprocess.clearArguments(); 251 addprocess.clearArguments();
214 252
215 setEnabled(FALSE); 253 setEnabled(FALSE);
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) {
226 log_text(tr("Error running ssh-add")); 264 log_text(tr("Error running ssh-add"));
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)
233{ 272{
234 TextOutput->append(text); 273 TextOutput->append(text);
235 TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); 274 TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE);
236} 275}
237 276
238void SSHKeysApp::doRemoveAllButton() 277void SSHKeysApp::doRemoveAllButton()
239{ 278{
240 OProcess sshadd_process; 279 OProcess sshadd_process;
241 280
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
@@ -26,30 +26,35 @@
26#include <opie/oprocess.h> 26#include <opie/oprocess.h>
27 27
28class SSHKeysApp : public SSHKeysBase 28class SSHKeysApp : public SSHKeysBase
29{ 29{
30 Q_OBJECT 30 Q_OBJECT
31 31
32 public: 32 public:
33 SSHKeysApp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 33 SSHKeysApp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
34 ~SSHKeysApp(); 34 ~SSHKeysApp();
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();
47 void doRefreshListButton(); 51 void doRefreshListButton();
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};
54#endif 59#endif
55 60