summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-20 19:22:38 (UTC)
committer josef <josef>2002-10-20 19:22:38 (UTC)
commitd5433091ba9741f0fae104d038b906e353065e2d (patch) (unidiff)
tree70def8957a6b38f8b6cfb45fa352b5a77f2298a1
parent557c615b4b07adb798283981f3769dd817a80bf1 (diff)
downloadopie-d5433091ba9741f0fae104d038b906e353065e2d.zip
opie-d5433091ba9741f0fae104d038b906e353065e2d.tar.gz
opie-d5433091ba9741f0fae104d038b906e353065e2d.tar.bz2
Some fixes for receiving files via {x,y,z}modem:
- let transfer dialog reset progress bar when finished - typo: s/Sent/Received in received confirmation dialog - specify filename for xmodem (the man page is not very clear about this, but it doesn't work without filename!) - add --overwrite Here's the big problem: For user security, I'd rather use --rename than --overwrite (or make it configurable). But: * --rename is not supported at all by rx/rz/... * --overwrite is not supported by ymodem * --overwrite is always used by xmodem even if not used I want to kick the authors of rz now... Anybody knows a solution?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filereceive.cpp7
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp7
2 files changed, 12 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/filereceive.cpp b/noncore/apps/opie-console/filereceive.cpp
index e517862..e387273 100644
--- a/noncore/apps/opie-console/filereceive.cpp
+++ b/noncore/apps/opie-console/filereceive.cpp
@@ -1,152 +1,157 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <fcntl.h> 2#include <fcntl.h>
3#include <signal.h> 3#include <signal.h>
4#include <errno.h> 4#include <errno.h>
5 5
6#include <qsocketnotifier.h> 6#include <qsocketnotifier.h>
7 7
8#include "io_layer.h" 8#include "io_layer.h"
9#include "procctl.h" 9#include "procctl.h"
10#include "filereceive.h" 10#include "filereceive.h"
11 11
12FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir ) 12FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir )
13 : ReceiveLayer(lay, dir ), m_type( t ) 13 : ReceiveLayer(lay, dir ), m_type( t )
14{ 14{
15 m_fd = -1; 15 m_fd = -1;
16 m_not = 0l; 16 m_not = 0l;
17 m_proc = 0l; 17 m_proc = 0l;
18} 18}
19FileReceive::~FileReceive() { 19FileReceive::~FileReceive() {
20} 20}
21void FileReceive::receive() { 21void FileReceive::receive() {
22 receive( currentDir() ); 22 receive( currentDir() );
23} 23}
24void FileReceive::receive( const QString& dir ) { 24void FileReceive::receive( const QString& dir ) {
25 m_prog = -1; 25 m_prog = -1;
26 m_fd = layer()->rawIO(); 26 m_fd = layer()->rawIO();
27 m_curDir = dir; 27 m_curDir = dir;
28 28
29 if (pipe( m_comm ) < 0 ) 29 if (pipe( m_comm ) < 0 )
30 m_comm[0] = m_comm[1] = 0; 30 m_comm[0] = m_comm[1] = 0;
31 if (pipe( m_info ) < 0 ) 31 if (pipe( m_info ) < 0 )
32 m_info[0] = m_info[1] = 0; 32 m_info[0] = m_info[1] = 0;
33 33
34 m_pid = fork(); 34 m_pid = fork();
35 switch( m_pid ) { 35 switch( m_pid ) {
36 case -1: 36 case -1:
37 //emit error 37 //emit error
38 slotExec(); 38 slotExec();
39 break; 39 break;
40 /* child */ 40 /* child */
41 case 0: { 41 case 0: {
42 setupChild(); 42 setupChild();
43 char* typus = NULL; 43 char* typus = NULL;
44 switch(m_type ) { 44 switch(m_type ) {
45 case SZ: 45 case SZ:
46 break; 46 break;
47 case SX: 47 case SX:
48 typus = "-X"; 48 typus = "-X";
49 break; 49 break;
50 case SY: 50 case SY:
51 typus = "--ymodem"; 51 typus = "--ymodem";
52 break; 52 break;
53 } 53 }
54 54
55 /* we should never return from here */ 55 /* we should never return from here */
56 execlp("rz", "rz", typus, NULL ); 56 if( m_type == SX )
57 // FIXME: file name should be configurable - currently we ensure it
58 // doesn't get overwritten by -E (--rename)
59 execlp("rz", "rz", typus, "--overwrite", QObject::tr("SynchronizedFile").latin1(), NULL );
60 else
61 execlp("rz", "rz", typus, "--overwrite", NULL );
57 62
58 char resultByte = 1; 63 char resultByte = 1;
59 if (m_info[1] ) 64 if (m_info[1] )
60 ::write(m_info[1], &resultByte, 1 ); 65 ::write(m_info[1], &resultByte, 1 );
61 66
62 _exit( -1 ); 67 _exit( -1 );
63 break; 68 break;
64 } 69 }
65 default: { 70 default: {
66 if ( m_info[1] ) 71 if ( m_info[1] )
67 close( m_info[1] ); 72 close( m_info[1] );
68 73
69 if ( m_info[0] ) for (;;) { 74 if ( m_info[0] ) for (;;) {
70 char resultByte; int len; 75 char resultByte; int len;
71 len = read(m_info[0], &resultByte, 1 ); 76 len = read(m_info[0], &resultByte, 1 );
72 /* len == 1 start up failed */ 77 /* len == 1 start up failed */
73 if ( len == 1 ) { 78 if ( len == 1 ) {
74 emit error( StartError, tr("Could not start") ); 79 emit error( StartError, tr("Could not start") );
75 return; 80 return;
76 } 81 }
77 if ( len == -1 ) 82 if ( len == -1 )
78 if ( (errno == ECHILD ) || (errno == EINTR ) ) 83 if ( (errno == ECHILD ) || (errno == EINTR ) )
79 continue; 84 continue;
80 85
81 // len == 0 or something like this 86 // len == 0 or something like this
82 break; 87 break;
83 } 88 }
84 89
85 if ( m_info[0] ) 90 if ( m_info[0] )
86 close( m_info[0] ); 91 close( m_info[0] );
87 92
88 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); 93 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
89 connect(m_not, SIGNAL(activated(int) ), 94 connect(m_not, SIGNAL(activated(int) ),
90 this, SLOT(slotRead() ) ); 95 this, SLOT(slotRead() ) );
91 if ( pipe(m_term) < 0 ) 96 if ( pipe(m_term) < 0 )
92 m_term[0] = m_term[1] = 0; 97 m_term[0] = m_term[1] = 0;
93 98
94 ProcCtl::self()->add(m_pid, m_term[1] ); 99 ProcCtl::self()->add(m_pid, m_term[1] );
95 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); 100 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
96 connect(m_proc, SIGNAL(activated(int) ), 101 connect(m_proc, SIGNAL(activated(int) ),
97 this, SLOT(slotExec() ) ); 102 this, SLOT(slotExec() ) );
98 103
99 } 104 }
100 break; 105 break;
101 106
102 } 107 }
103 108
104} 109}
105void FileReceive::cancel() { 110void FileReceive::cancel() {
106 ::kill(m_pid, 9 ); 111 ::kill(m_pid, 9 );
107} 112}
108void FileReceive::setupChild() { 113void FileReceive::setupChild() {
109 changeDir( currentDir() ); 114 changeDir( currentDir() );
110 /* 115 /*
111 * we do not want to read from our 116 * we do not want to read from our
112 * information channel 117 * information channel
113 */ 118 */
114 if (m_info[0] ) 119 if (m_info[0] )
115 close(m_info[0] ); 120 close(m_info[0] );
116 /* 121 /*
117 * FD_CLOEXEC will close the 122 * FD_CLOEXEC will close the
118 * fd on successfull exec 123 * fd on successfull exec
119 */ 124 */
120 if (m_info[1] ) 125 if (m_info[1] )
121 fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); 126 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
122 127
123 if (m_comm[0] ) 128 if (m_comm[0] )
124 close( m_comm[0] ); 129 close( m_comm[0] );
125 /* 130 /*
126 * now set the communication 131 * now set the communication
127 * m_fd STDIN_FILENO 132 * m_fd STDIN_FILENO
128 * STDOUT_FILENO 133 * STDOUT_FILENO
129 * STDERR_FILENO 134 * STDERR_FILENO
130 */ 135 */
131 dup2( m_fd, STDIN_FILENO ); 136 dup2( m_fd, STDIN_FILENO );
132 dup2( m_fd, STDOUT_FILENO ); 137 dup2( m_fd, STDOUT_FILENO );
133 dup2( m_comm[1], STDERR_FILENO ); 138 dup2( m_comm[1], STDERR_FILENO );
134} 139}
135void FileReceive::slotRead() { 140void FileReceive::slotRead() {
136 QByteArray ar(4096); 141 QByteArray ar(4096);
137 int len = read(m_comm[0], ar.data(), 4096 ); 142 int len = read(m_comm[0], ar.data(), 4096 );
138 for (int i = 0; i < len; i++ ) { 143 for (int i = 0; i < len; i++ ) {
139 // printf("%c", ar[i] ); 144 // printf("%c", ar[i] );
140 } 145 }
141 ar.resize( len ); 146 ar.resize( len );
142 QString str( ar ); 147 QString str( ar );
143} 148}
144void FileReceive::slotExec() { 149void FileReceive::slotExec() {
145 char buf[2]; 150 char buf[2];
146 ::read(m_term[0], buf, 1 ); 151 ::read(m_term[0], buf, 1 );
147 delete m_proc; 152 delete m_proc;
148 delete m_not; 153 delete m_not;
149 m_not = m_proc = 0l; 154 m_not = m_proc = 0l;
150 close( m_term[0] ); 155 close( m_term[0] );
151 close( m_term[1] ); 156 close( m_term[1] );
152 close( m_comm[0] ); 157 close( m_comm[0] );
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp
index ac5b1d0..f89723c 100644
--- a/noncore/apps/opie-console/transferdialog.cpp
+++ b/noncore/apps/opie-console/transferdialog.cpp
@@ -137,125 +137,130 @@ void TransferDialog::slotTransfer()
137 m_recvlay->receive(); 137 m_recvlay->receive();
138 138
139 connect(m_recvlay, SIGNAL(progress(const QString&, int, int, int, int, int)), 139 connect(m_recvlay, SIGNAL(progress(const QString&, int, int, int, int, int)),
140 SLOT(slotProgress(const QString&, int, int, int, int, int))); 140 SLOT(slotProgress(const QString&, int, int, int, int, int)));
141 connect(m_recvlay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); 141 connect(m_recvlay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
142 connect(m_recvlay, SIGNAL(received(const QString&)), SLOT(slotReceived(const QString&))); 142 connect(m_recvlay, SIGNAL(received(const QString&)), SLOT(slotReceived(const QString&)));
143 } 143 }
144} 144}
145 145
146void TransferDialog::cleanup() 146void TransferDialog::cleanup()
147{ 147{
148 if(m_lay) 148 if(m_lay)
149 { 149 {
150 m_lay->cancel(); 150 m_lay->cancel();
151 delete m_lay; 151 delete m_lay;
152 m_lay = 0l; 152 m_lay = 0l;
153 } 153 }
154 if(m_recvlay) 154 if(m_recvlay)
155 { 155 {
156 m_recvlay->cancel(); 156 m_recvlay->cancel();
157 delete m_recvlay; 157 delete m_recvlay;
158 m_recvlay = 0l; 158 m_recvlay = 0l;
159 } 159 }
160} 160}
161 161
162void TransferDialog::slotCancel() 162void TransferDialog::slotCancel()
163{ 163{
164 ok->setEnabled(true); 164 ok->setEnabled(true);
165 statusbar->setText(QObject::tr("Ready")); 165 statusbar->setText(QObject::tr("Ready"));
166 166
167 if((m_lay) || (m_recvlay)) 167 if((m_lay) || (m_recvlay))
168 { 168 {
169 cleanup(); 169 cleanup();
170 if(m_autocleanup) close(); 170 if(m_autocleanup) close();
171 else 171 else
172 { 172 {
173 QMessageBox::information(this, 173 QMessageBox::information(this,
174 QObject::tr("Cancelled"), 174 QObject::tr("Cancelled"),
175 QObject::tr("The file transfer has been cancelled.")); 175 QObject::tr("The file transfer has been cancelled."));
176 } 176 }
177 } 177 }
178 else 178 else
179 { 179 {
180 close(); 180 close();
181 } 181 }
182} 182}
183 183
184void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds) 184void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds)
185{ 185{
186 progressbar->setProgress(progress); 186 progressbar->setProgress(progress);
187} 187}
188 188
189void TransferDialog::slotError(int error, const QString& message) 189void TransferDialog::slotError(int error, const QString& message)
190{ 190{
191 statusbar->setText(QObject::tr("Ready")); 191 statusbar->setText(QObject::tr("Ready"));
192 192
193 switch(error) 193 switch(error)
194 { 194 {
195 case FileTransferLayer::NotSupported: 195 case FileTransferLayer::NotSupported:
196 QMessageBox::critical(this, 196 QMessageBox::critical(this,
197 QObject::tr("Error"), 197 QObject::tr("Error"),
198 QObject::tr("Operation not supported.")); 198 QObject::tr("Operation not supported."));
199 break; 199 break;
200 case FileTransferLayer::StartError: 200 case FileTransferLayer::StartError:
201 QMessageBox::critical(this, 201 QMessageBox::critical(this,
202 QObject::tr("Error"), 202 QObject::tr("Error"),
203 QObject::tr("Transfer could not be started.")); 203 QObject::tr("Transfer could not be started."));
204 break; 204 break;
205 case FileTransferLayer::NoError: 205 case FileTransferLayer::NoError:
206 QMessageBox::critical(this, 206 QMessageBox::critical(this,
207 QObject::tr("Error"), 207 QObject::tr("Error"),
208 QObject::tr("No error.")); 208 QObject::tr("No error."));
209 break; 209 break;
210 case FileTransferLayer::Undefined: 210 case FileTransferLayer::Undefined:
211 QMessageBox::critical(this, 211 QMessageBox::critical(this,
212 QObject::tr("Error"), 212 QObject::tr("Error"),
213 QObject::tr("Undefined error occured.")); 213 QObject::tr("Undefined error occured."));
214 break; 214 break;
215 case FileTransferLayer::Incomplete: 215 case FileTransferLayer::Incomplete:
216 QMessageBox::critical(this, 216 QMessageBox::critical(this,
217 QObject::tr("Error"), 217 QObject::tr("Error"),
218 QObject::tr("Incomplete transfer.")); 218 QObject::tr("Incomplete transfer."));
219 break; 219 break;
220 case FileTransferLayer::Unknown: 220 case FileTransferLayer::Unknown:
221 default: 221 default:
222 QMessageBox::critical(this, 222 QMessageBox::critical(this,
223 QObject::tr("Error"), 223 QObject::tr("Error"),
224 QObject::tr("Unknown error occured.")); 224 QObject::tr("Unknown error occured."));
225 break; 225 break;
226 } 226 }
227 227
228 m_autocleanup = 1; 228 m_autocleanup = 1;
229} 229}
230 230
231void TransferDialog::slotSent() 231void TransferDialog::slotSent()
232{ 232{
233 progressbar->setProgress(100);
233 QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); 234 QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent."));
234 ok->setEnabled(true); 235 ok->setEnabled(true);
236 progressbar->setProgress(0);
235 statusbar->setText(QObject::tr("Ready")); 237 statusbar->setText(QObject::tr("Ready"));
236 m_autocleanup = 1; 238 m_autocleanup = 1;
237} 239}
238 240
239void TransferDialog::slotReceived(const QString& file) 241void TransferDialog::slotReceived(const QString& file)
240{ 242{
241 QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been received as %1.").arg(file)); 243 progressbar->setProgress(100);
244 QMessageBox::information(this, QObject::tr("Received"), QObject::tr("File has been received."));
245 //QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been received as %1.").arg(file));
242 ok->setEnabled(true); 246 ok->setEnabled(true);
247 progressbar->setProgress(0);
243 statusbar->setText(QObject::tr("Ready")); 248 statusbar->setText(QObject::tr("Ready"));
244 m_autocleanup = 1; 249 m_autocleanup = 1;
245} 250}
246 251
247void TransferDialog::slotMode(int id) 252void TransferDialog::slotMode(int id)
248{ 253{
249 if(id == id_send) 254 if(id == id_send)
250 { 255 {
251 selector->setEnabled(true); 256 selector->setEnabled(true);
252 filename->setEnabled(true); 257 filename->setEnabled(true);
253 } 258 }
254 else 259 else
255 { 260 {
256 selector->setEnabled(false); 261 selector->setEnabled(false);
257 filename->setEnabled(false); 262 filename->setEnabled(false);
258 } 263 }
259 m_transfermode = id; 264 m_transfermode = id;
260} 265}
261 266