summaryrefslogtreecommitdiff
authorar <ar>2004-05-02 21:32:48 (UTC)
committer ar <ar>2004-05-02 21:32:48 (UTC)
commit0a4cac124105a5732e55cb34c6b37be75083a395 (patch) (unidiff)
tree33b4d2cab08c9b58893540b4ddee089b69fc9c61
parent109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95 (diff)
downloadopie-0a4cac124105a5732e55cb34c6b37be75083a395.zip
opie-0a4cac124105a5732e55cb34c6b37be75083a395.tar.gz
opie-0a4cac124105a5732e55cb34c6b37be75083a395.tar.bz2
- convert qWarning to owarn
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.cpp296
-rw-r--r--core/launcher/packageslave.cpp191
-rw-r--r--core/launcher/transferserver.cpp3
-rw-r--r--core/obex/obex.cc47
-rw-r--r--core/opie-login/loginapplication.cpp315
-rw-r--r--core/pim/addressbook/namelineedit.cpp6
-rw-r--r--core/qws/transferserver.cpp6
7 files changed, 439 insertions, 425 deletions
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp
index 6afbcd8..779fe54 100644
--- a/core/launcher/launcher.cpp
+++ b/core/launcher/launcher.cpp
@@ -1,786 +1,786 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "startmenu.h" 21#include "startmenu.h"
22#include "taskbar.h" 22#include "taskbar.h"
23#include "serverinterface.h" 23#include "serverinterface.h"
24#include "launcherview.h" 24#include "launcherview.h"
25#include "launcher.h" 25#include "launcher.h"
26#include "server.h" 26#include "server.h"
27 27
28/* OPIE */ 28/* OPIE */
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30#include <qtopia/global.h> 30#include <qtopia/global.h>
31#ifdef Q_WS_QWS 31#ifdef Q_WS_QWS
32#include <qtopia/qcopenvelope_qws.h> 32#include <qtopia/qcopenvelope_qws.h>
33#endif 33#endif
34#include <qtopia/resource.h> 34#include <qtopia/resource.h>
35#include <qtopia/applnk.h> 35#include <qtopia/applnk.h>
36#include <qtopia/config.h> 36#include <qtopia/config.h>
37#include <qtopia/qpeapplication.h> 37#include <qtopia/qpeapplication.h>
38#include <qtopia/mimetype.h> 38#include <qtopia/mimetype.h>
39#include <qtopia/private/categories.h> 39#include <qtopia/private/categories.h>
40#define QTOPIA_INTERNAL_FSLP 40#define QTOPIA_INTERNAL_FSLP
41#include <qtopia/lnkproperties.h> 41#include <qtopia/lnkproperties.h>
42 42
43/* QT */ 43/* QT */
44#include <qdir.h> 44#include <qdir.h>
45#ifdef Q_WS_QWS 45#ifdef Q_WS_QWS
46#include <qkeyboard_qws.h> 46#include <qkeyboard_qws.h>
47#include <qwindowsystem_qws.h> 47#include <qwindowsystem_qws.h>
48#endif 48#endif
49#include <qtimer.h> 49#include <qtimer.h>
50#include <qcombobox.h> 50#include <qcombobox.h>
51#include <qvbox.h> 51#include <qvbox.h>
52#include <qlayout.h> 52#include <qlayout.h>
53#include <qstyle.h> 53#include <qstyle.h>
54#include <qpushbutton.h> 54#include <qpushbutton.h>
55#include <qtabbar.h> 55#include <qtabbar.h>
56#include <qwidgetstack.h> 56#include <qwidgetstack.h>
57#include <qregexp.h> 57#include <qregexp.h>
58#include <qmessagebox.h> 58#include <qmessagebox.h>
59#include <qframe.h> 59#include <qframe.h>
60#include <qpainter.h> 60#include <qpainter.h>
61#include <qlabel.h> 61#include <qlabel.h>
62#include <qtextstream.h> 62#include <qtextstream.h>
63#include <qpopupmenu.h> 63#include <qpopupmenu.h>
64 64
65/* STD */ 65/* STD */
66#include <stdlib.h> 66#include <stdlib.h>
67#include <assert.h> 67#include <assert.h>
68#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 68#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
69#include <unistd.h> 69#include <unistd.h>
70#include <stdio.h> 70#include <stdio.h>
71#include <sys/vfs.h> 71#include <sys/vfs.h>
72#include <mntent.h> 72#include <mntent.h>
73#endif 73#endif
74 74
75 75
76static bool isVisibleWindow( int ); 76static bool isVisibleWindow( int );
77//=========================================================================== 77//===========================================================================
78 78
79LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : 79LauncherTabWidget::LauncherTabWidget( Launcher* parent ) :
80 QVBox( parent ), docview( 0 ) 80 QVBox( parent ), docview( 0 )
81{ 81{
82 docLoadingWidgetEnabled = false; 82 docLoadingWidgetEnabled = false;
83 docLoadingWidget = 0; 83 docLoadingWidget = 0;
84 docLoadingWidgetProgress = 0; 84 docLoadingWidgetProgress = 0;
85 launcher = parent; 85 launcher = parent;
86 categoryBar = new LauncherTabBar( this ); 86 categoryBar = new LauncherTabBar( this );
87 QPalette pal = categoryBar->palette(); 87 QPalette pal = categoryBar->palette();
88 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 88 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
89 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 89 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
90 categoryBar->setPalette( pal ); 90 categoryBar->setPalette( pal );
91 stack = new QWidgetStack(this); 91 stack = new QWidgetStack(this);
92 connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); 92 connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) );
93 categoryBar->show(); 93 categoryBar->show();
94 stack->show(); 94 stack->show();
95 95
96#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 96#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
97 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); 97 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
98 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 98 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
99 this, SLOT(launcherMessage(const QCString&,const QByteArray&)) ); 99 this, SLOT(launcherMessage(const QCString&,const QByteArray&)) );
100 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 100 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
101 this, SLOT(appMessage(const QCString&,const QByteArray&))); 101 this, SLOT(appMessage(const QCString&,const QByteArray&)));
102#endif 102#endif
103 103
104 createDocLoadingWidget(); 104 createDocLoadingWidget();
105} 105}
106 106
107void LauncherTabWidget::createDocLoadingWidget() 107void LauncherTabWidget::createDocLoadingWidget()
108{ 108{
109 // Construct the 'doc loading widget' shown when finding documents 109 // Construct the 'doc loading widget' shown when finding documents
110 110
111 // ### LauncherView class needs changing to be more generic so 111 // ### LauncherView class needs changing to be more generic so
112 // this widget can change its background similar to the iconviews 112 // this widget can change its background similar to the iconviews
113 // so the background for this matches 113 // so the background for this matches
114 docLoadingWidget = new LauncherView( stack ); 114 docLoadingWidget = new LauncherView( stack );
115 docLoadingWidget->hideIcons(); 115 docLoadingWidget->hideIcons();
116 QVBox *docLoadingVBox = new QVBox( docLoadingWidget ); 116 QVBox *docLoadingVBox = new QVBox( docLoadingWidget );
117 117
118 docLoadingVBox->setSpacing( 20 ); 118 docLoadingVBox->setSpacing( 20 );
119 docLoadingVBox->setMargin( 10 ); 119 docLoadingVBox->setMargin( 10 );
120 120
121 QWidget *space1 = new QWidget( docLoadingVBox ); 121 QWidget *space1 = new QWidget( docLoadingVBox );
122 docLoadingVBox->setStretchFactor( space1, 1 ); 122 docLoadingVBox->setStretchFactor( space1, 1 );
123 123
124 QLabel *waitPixmap = new QLabel( docLoadingVBox ); 124 QLabel *waitPixmap = new QLabel( docLoadingVBox );
125 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); 125 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) );
126 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); 126 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) );
127 waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); 127 waitPixmap->setAlignment( int( QLabel::AlignCenter ) );
128 128
129 Config cfg( "Launcher" ); 129 Config cfg( "Launcher" );
130 cfg.setGroup( "DocTab" ); 130 cfg.setGroup( "DocTab" );
131 bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); 131 bool docTabEnabled = cfg.readBoolEntry( "Enable", true );
132 132
133 QLabel *textLabel = new QLabel( docLoadingVBox ); 133 QLabel *textLabel = new QLabel( docLoadingVBox );
134 textLabel->setAlignment( int( QLabel::AlignCenter ) ); 134 textLabel->setAlignment( int( QLabel::AlignCenter ) );
135 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); 135 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox );
136 docLoadingWidgetProgress->setProgress( 0 ); 136 docLoadingWidgetProgress->setProgress( 0 );
137 docLoadingWidgetProgress->setCenterIndicator( TRUE ); 137 docLoadingWidgetProgress->setCenterIndicator( TRUE );
138 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker 138 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker
139 setProgressStyle(); 139 setProgressStyle();
140 140
141 if ( docTabEnabled ) 141 if ( docTabEnabled )
142 { 142 {
143 textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); 143 textLabel->setText( tr( "<b>Finding Documents...</b>" ) );
144 } 144 }
145 else 145 else
146 { 146 {
147 textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>" 147 textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>"
148 "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) ); 148 "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) );
149 docLoadingWidgetProgress->hide(); 149 docLoadingWidgetProgress->hide();
150 docLoadingWidgetEnabled = true; 150 docLoadingWidgetEnabled = true;
151 } 151 }
152 152
153 QWidget *space2 = new QWidget( docLoadingVBox ); 153 QWidget *space2 = new QWidget( docLoadingVBox );
154 docLoadingVBox->setStretchFactor( space2, 1 ); 154 docLoadingVBox->setStretchFactor( space2, 1 );
155 155
156 cfg.setGroup( "Tab Documents" ); // No tr 156 cfg.setGroup( "Tab Documents" ); // No tr
157 setTabViewAppearance( docLoadingWidget, cfg ); 157 setTabViewAppearance( docLoadingWidget, cfg );
158 158
159 stack->addWidget( docLoadingWidget, 0 ); 159 stack->addWidget( docLoadingWidget, 0 );
160} 160}
161 161
162void LauncherTabWidget::initLayout() 162void LauncherTabWidget::initLayout()
163{ 163{
164 layout()->activate(); 164 layout()->activate();
165 docView()->setFocus(); 165 docView()->setFocus();
166 categoryBar->showTab("Documents"); 166 categoryBar->showTab("Documents");
167} 167}
168 168
169void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) 169void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&)
170{ 170{
171 if ( message == "nextView()" ) 171 if ( message == "nextView()" )
172 categoryBar->nextTab(); 172 categoryBar->nextTab();
173} 173}
174 174
175void LauncherTabWidget::raiseTabWidget() 175void LauncherTabWidget::raiseTabWidget()
176{ 176{
177 if ( categoryBar->currentView() == docView() 177 if ( categoryBar->currentView() == docView()
178 && docLoadingWidgetEnabled ) { 178 && docLoadingWidgetEnabled ) {
179 stack->raiseWidget( docLoadingWidget ); 179 stack->raiseWidget( docLoadingWidget );
180 docLoadingWidget->updateGeometry(); 180 docLoadingWidget->updateGeometry();
181 } else { 181 } else {
182 stack->raiseWidget( categoryBar->currentView() ); 182 stack->raiseWidget( categoryBar->currentView() );
183 } 183 }
184} 184}
185 185
186void LauncherTabWidget::tabProperties() 186void LauncherTabWidget::tabProperties()
187{ 187{
188 LauncherView *view = categoryBar->currentView(); 188 LauncherView *view = categoryBar->currentView();
189 QPopupMenu *m = new QPopupMenu( this ); 189 QPopupMenu *m = new QPopupMenu( this );
190 m->insertItem( tr("Icon View"), LauncherView::Icon ); 190 m->insertItem( tr("Icon View"), LauncherView::Icon );
191 m->insertItem( tr("List View"), LauncherView::List ); 191 m->insertItem( tr("List View"), LauncherView::List );
192 m->setItemChecked( (int)view->viewMode(), TRUE ); 192 m->setItemChecked( (int)view->viewMode(), TRUE );
193 int rv = m->exec( QCursor::pos() ); 193 int rv = m->exec( QCursor::pos() );
194 if ( rv >= 0 && rv != view->viewMode() ) { 194 if ( rv >= 0 && rv != view->viewMode() ) {
195 view->setViewMode( (LauncherView::ViewMode)rv ); 195 view->setViewMode( (LauncherView::ViewMode)rv );
196 } 196 }
197 197
198 delete m; 198 delete m;
199} 199}
200 200
201void LauncherTabWidget::deleteView( const QString& id ) 201void LauncherTabWidget::deleteView( const QString& id )
202{ 202{
203 LauncherTab *t = categoryBar->launcherTab(id); 203 LauncherTab *t = categoryBar->launcherTab(id);
204 if ( t ) { 204 if ( t ) {
205 stack->removeWidget( t->view ); 205 stack->removeWidget( t->view );
206 delete t->view; 206 delete t->view;
207 categoryBar->removeTab( t ); 207 categoryBar->removeTab( t );
208 } 208 }
209} 209}
210 210
211LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) 211LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
212{ 212{
213 LauncherView* view = new LauncherView( stack ); 213 LauncherView* view = new LauncherView( stack );
214 connect( view, SIGNAL(clicked(const AppLnk*)), 214 connect( view, SIGNAL(clicked(const AppLnk*)),
215 this, SIGNAL(clicked(const AppLnk*))); 215 this, SIGNAL(clicked(const AppLnk*)));
216 connect( view, SIGNAL(rightPressed(AppLnk*)), 216 connect( view, SIGNAL(rightPressed(AppLnk*)),
217 this, SIGNAL(rightPressed(AppLnk*))); 217 this, SIGNAL(rightPressed(AppLnk*)));
218 218
219 int n = categoryBar->count(); 219 int n = categoryBar->count();
220 stack->addWidget( view, n ); 220 stack->addWidget( view, n );
221 221
222 LauncherTab *tab = new LauncherTab( id, view, pm, label ); 222 LauncherTab *tab = new LauncherTab( id, view, pm, label );
223 categoryBar->insertTab( tab, n-1 ); 223 categoryBar->insertTab( tab, n-1 );
224 224
225 if ( id == "Documents" ) 225 if ( id == "Documents" )
226 docview = view; 226 docview = view;
227 227
228 odebug << "inserting " << id << " at " << n-1 << "" << oendl; 228 odebug << "inserting " << id << " at " << n-1 << "" << oendl;
229 229
230 Config cfg("Launcher"); 230 Config cfg("Launcher");
231 setTabAppearance( tab, cfg ); 231 setTabAppearance( tab, cfg );
232 232
233 cfg.setGroup( "GUI" ); 233 cfg.setGroup( "GUI" );
234 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) ); 234 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) );
235 235
236 return view; 236 return view;
237} 237}
238 238
239LauncherView *LauncherTabWidget::view( const QString &id ) 239LauncherView *LauncherTabWidget::view( const QString &id )
240{ 240{
241 LauncherTab *t = categoryBar->launcherTab(id); 241 LauncherTab *t = categoryBar->launcherTab(id);
242 if ( !t ) 242 if ( !t )
243 return 0; 243 return 0;
244 return t->view; 244 return t->view;
245} 245}
246 246
247LauncherView *LauncherTabWidget::docView() 247LauncherView *LauncherTabWidget::docView()
248{ 248{
249 return docview; 249 return docview;
250} 250}
251 251
252void LauncherTabWidget::setLoadingWidgetEnabled( bool v ) 252void LauncherTabWidget::setLoadingWidgetEnabled( bool v )
253{ 253{
254 if ( v != docLoadingWidgetEnabled && docLoadingWidget ) { 254 if ( v != docLoadingWidgetEnabled && docLoadingWidget ) {
255 docLoadingWidgetEnabled = v; 255 docLoadingWidgetEnabled = v;
256 raiseTabWidget(); 256 raiseTabWidget();
257 } 257 }
258} 258}
259 259
260void LauncherTabWidget::setLoadingProgress( int percent ) 260void LauncherTabWidget::setLoadingProgress( int percent )
261{ 261{
262 docLoadingWidgetProgress->setProgress( (percent / 4) * 4 ); 262 docLoadingWidgetProgress->setProgress( (percent / 4) * 4 );
263} 263}
264 264
265// ### this function could more to LauncherView 265// ### this function could more to LauncherView
266void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg ) 266void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg )
267{ 267{
268 // View 268 // View
269 QString view = cfg.readEntry( "View", "Icon" ); 269 QString view = cfg.readEntry( "View", "Icon" );
270 if ( view == "List" ) // No tr 270 if ( view == "List" ) // No tr
271 v->setViewMode( LauncherView::List ); 271 v->setViewMode( LauncherView::List );
272 QString bgType = cfg.readEntry( "BackgroundType", "Image" ); 272 QString bgType = cfg.readEntry( "BackgroundType", "Image" );
273 if ( bgType == "Image" ) { // No tr 273 if ( bgType == "Image" ) { // No tr
274 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); 274 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" );
275 v->setBackgroundType( LauncherView::Image, pm ); 275 v->setBackgroundType( LauncherView::Image, pm );
276 } else if ( bgType == "SolidColor" ) { 276 } else if ( bgType == "SolidColor" ) {
277 QString c = cfg.readEntry( "BackgroundColor" ); 277 QString c = cfg.readEntry( "BackgroundColor" );
278 v->setBackgroundType( LauncherView::SolidColor, c ); 278 v->setBackgroundType( LauncherView::SolidColor, c );
279 } else { 279 } else {
280 v->setBackgroundType( LauncherView::Ruled, QString::null ); 280 v->setBackgroundType( LauncherView::Ruled, QString::null );
281 } 281 }
282 QString textCol = cfg.readEntry( "TextColor" ); 282 QString textCol = cfg.readEntry( "TextColor" );
283 if ( textCol.isEmpty() ) 283 if ( textCol.isEmpty() )
284 v->setTextColor( QColor() ); 284 v->setTextColor( QColor() );
285 else 285 else
286 v->setTextColor( QColor(textCol) ); 286 v->setTextColor( QColor(textCol) );
287// bool customFont = cfg.readBoolEntry( "CustomFont", FALSE ); 287// bool customFont = cfg.readBoolEntry( "CustomFont", FALSE );
288 288
289 289
290 QStringList font = cfg.readListEntry( "Font", ',' ); 290 QStringList font = cfg.readListEntry( "Font", ',' );
291 if ( font.count() == 4 ) 291 if ( font.count() == 4 )
292 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); 292 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) );
293 293
294 // ### FIXME TabColor TabTextColor 294 // ### FIXME TabColor TabTextColor
295 295
296} 296}
297 297
298// ### Could move to LauncherTab 298// ### Could move to LauncherTab
299void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg ) 299void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg )
300{ 300{
301 cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr 301 cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr
302 302
303 setTabViewAppearance( tab->view, cfg ); 303 setTabViewAppearance( tab->view, cfg );
304 304
305 // Tabs 305 // Tabs
306 QString tabCol = cfg.readEntry( "TabColor" ); 306 QString tabCol = cfg.readEntry( "TabColor" );
307 if ( tabCol.isEmpty() ) 307 if ( tabCol.isEmpty() )
308 tab->bgColor = QColor(); 308 tab->bgColor = QColor();
309 else 309 else
310 tab->bgColor = QColor(tabCol); 310 tab->bgColor = QColor(tabCol);
311 QString tabTextCol = cfg.readEntry( "TabTextColor" ); 311 QString tabTextCol = cfg.readEntry( "TabTextColor" );
312 if ( tabTextCol.isEmpty() ) 312 if ( tabTextCol.isEmpty() )
313 tab->fgColor = QColor(); 313 tab->fgColor = QColor();
314 else 314 else
315 tab->fgColor = QColor(tabTextCol); 315 tab->fgColor = QColor(tabTextCol);
316} 316}
317 317
318void LauncherTabWidget::paletteChange( const QPalette &p ) 318void LauncherTabWidget::paletteChange( const QPalette &p )
319{ 319{
320 QVBox::paletteChange( p ); 320 QVBox::paletteChange( p );
321 QPalette pal = palette(); 321 QPalette pal = palette();
322 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 322 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
323 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 323 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
324 categoryBar->setPalette( pal ); 324 categoryBar->setPalette( pal );
325 categoryBar->update(); 325 categoryBar->update();
326} 326}
327 327
328void LauncherTabWidget::styleChange( QStyle & ) 328void LauncherTabWidget::styleChange( QStyle & )
329{ 329{
330 QTimer::singleShot( 0, this, SLOT(setProgressStyle()) ); 330 QTimer::singleShot( 0, this, SLOT(setProgressStyle()) );
331} 331}
332 332
333void LauncherTabWidget::setProgressStyle() 333void LauncherTabWidget::setProgressStyle()
334{ 334{
335 if (docLoadingWidgetProgress) { 335 if (docLoadingWidgetProgress) {
336 docLoadingWidgetProgress->setFrameShape( QProgressBar::Box ); 336 docLoadingWidgetProgress->setFrameShape( QProgressBar::Box );
337 docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain ); 337 docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain );
338 docLoadingWidgetProgress->setMargin( 1 ); 338 docLoadingWidgetProgress->setMargin( 1 );
339 docLoadingWidgetProgress->setLineWidth( 1 ); 339 docLoadingWidgetProgress->setLineWidth( 1 );
340 } 340 }
341} 341}
342 342
343void LauncherTabWidget::setBusy(bool on) 343void LauncherTabWidget::setBusy(bool on)
344{ 344{
345 if ( on ) 345 if ( on )
346 currentView()->setBusy(TRUE); 346 currentView()->setBusy(TRUE);
347 else { 347 else {
348 for ( int i = 0; i < categoryBar->count(); i++ ) { 348 for ( int i = 0; i < categoryBar->count(); i++ ) {
349 LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view; 349 LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view;
350 view->setBusy( FALSE ); 350 view->setBusy( FALSE );
351 } 351 }
352 } 352 }
353} 353}
354 354
355void LauncherTabWidget::setBusyIndicatorType( const QString& str ) { 355void LauncherTabWidget::setBusyIndicatorType( const QString& str ) {
356 for (int i = 0; i < categoryBar->count(); i++ ) { 356 for (int i = 0; i < categoryBar->count(); i++ ) {
357 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view; 357 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view;
358 view->setBusyIndicatorType( str ); 358 view->setBusyIndicatorType( str );
359 } 359 }
360} 360}
361 361
362LauncherView *LauncherTabWidget::currentView(void) 362LauncherView *LauncherTabWidget::currentView(void)
363{ 363{
364 return (LauncherView*)stack->visibleWidget(); 364 return (LauncherView*)stack->visibleWidget();
365} 365}
366 366
367 367
368 368
369void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data) 369void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data)
370{ 370{
371 QDataStream stream( data, IO_ReadOnly ); 371 QDataStream stream( data, IO_ReadOnly );
372 if ( msg == "setTabView(QString,int)" ) { 372 if ( msg == "setTabView(QString,int)" ) {
373 QString id; 373 QString id;
374 stream >> id; 374 stream >> id;
375 int mode; 375 int mode;
376 stream >> mode; 376 stream >> mode;
377 if ( view(id) ) 377 if ( view(id) )
378 view(id)->setViewMode( (LauncherView::ViewMode)mode ); 378 view(id)->setViewMode( (LauncherView::ViewMode)mode );
379 } else if ( msg == "setTabBackground(QString,int,QString)" ) { 379 } else if ( msg == "setTabBackground(QString,int,QString)" ) {
380 QString id; 380 QString id;
381 stream >> id; 381 stream >> id;
382 int mode; 382 int mode;
383 stream >> mode; 383 stream >> mode;
384 QString pixmapOrColor; 384 QString pixmapOrColor;
385 stream >> pixmapOrColor; 385 stream >> pixmapOrColor;
386 if ( view(id) ) 386 if ( view(id) )
387 view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); 387 view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
388 if ( id == "Documents" ) 388 if ( id == "Documents" )
389 docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); 389 docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
390 } else if ( msg == "setTextColor(QString,QString)" ) { 390 } else if ( msg == "setTextColor(QString,QString)" ) {
391 QString id; 391 QString id;
392 stream >> id; 392 stream >> id;
393 QString color; 393 QString color;
394 stream >> color; 394 stream >> color;
395 if ( view(id) ) 395 if ( view(id) )
396 view(id)->setTextColor( QColor(color) ); 396 view(id)->setTextColor( QColor(color) );
397 if ( id == "Documents" ) 397 if ( id == "Documents" )
398 docLoadingWidget->setTextColor( QColor(color) ); 398 docLoadingWidget->setTextColor( QColor(color) );
399 } else if ( msg == "setFont(QString,QString,int,int,int)" ) { 399 } else if ( msg == "setFont(QString,QString,int,int,int)" ) {
400 QString id; 400 QString id;
401 stream >> id; 401 stream >> id;
402 QString fam; 402 QString fam;
403 stream >> fam; 403 stream >> fam;
404 int size; 404 int size;
405 stream >> size; 405 stream >> size;
406 int weight; 406 int weight;
407 stream >> weight; 407 stream >> weight;
408 int italic; 408 int italic;
409 stream >> italic; 409 stream >> italic;
410 if ( view(id) ) { 410 if ( view(id) ) {
411 if ( !fam.isEmpty() ) { 411 if ( !fam.isEmpty() ) {
412 view(id)->setViewFont( QFont(fam, size, weight, italic!=0) ); 412 view(id)->setViewFont( QFont(fam, size, weight, italic!=0) );
413 odebug << "setFont: " << fam << ", " << size << ", " << weight << ", " << italic << "" << oendl; 413 odebug << "setFont: " << fam << ", " << size << ", " << weight << ", " << italic << "" << oendl;
414 } else { 414 } else {
415 view(id)->clearViewFont(); 415 view(id)->clearViewFont();
416 } 416 }
417 } 417 }
418 }else if ( msg == "setBusyIndicatorType(QString)" ) { 418 }else if ( msg == "setBusyIndicatorType(QString)" ) {
419 QString type; 419 QString type;
420 stream >> type; 420 stream >> type;
421 setBusyIndicatorType( type ); 421 setBusyIndicatorType( type );
422 }else if ( msg == "home()" ) { 422 }else if ( msg == "home()" ) {
423 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) { 423 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) {
424 if (categoryBar) 424 if (categoryBar)
425 categoryBar->nextTab(); 425 categoryBar->nextTab();
426 }else 426 }else
427 static_cast<QWidget*>(parent())->raise(); 427 static_cast<QWidget*>(parent())->raise();
428 } 428 }
429} 429}
430 430
431 431
432 432
433//--------------------------------------------------------------------------- 433//---------------------------------------------------------------------------
434 434
435Launcher::Launcher() 435Launcher::Launcher()
436 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader ) 436 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader )
437{ 437{
438 tabs = 0; 438 tabs = 0;
439 tb = 0; 439 tb = 0;
440 Config cfg( "Launcher" ); 440 Config cfg( "Launcher" );
441 cfg.setGroup( "DocTab" ); 441 cfg.setGroup( "DocTab" );
442 docTabEnabled = cfg.readBoolEntry( "Enable", true ); 442 docTabEnabled = cfg.readBoolEntry( "Enable", true );
443} 443}
444 444
445void Launcher::createGUI() 445void Launcher::createGUI()
446{ 446{
447 setCaption( tr("Launcher") ); 447 setCaption( tr("Launcher") );
448 448
449 // we have a pretty good idea how big we'll be 449 // we have a pretty good idea how big we'll be
450 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); 450 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() );
451 451
452 tb = new TaskBar; 452 tb = new TaskBar;
453 tabs = new LauncherTabWidget( this ); 453 tabs = new LauncherTabWidget( this );
454 setCentralWidget( tabs ); 454 setCentralWidget( tabs );
455 455
456 ServerInterface::dockWidget( tb, ServerInterface::Bottom ); 456 ServerInterface::dockWidget( tb, ServerInterface::Bottom );
457 tb->show(); 457 tb->show();
458 458
459 qApp->installEventFilter( this ); 459 qApp->installEventFilter( this );
460 460
461 461
462 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); 462 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) );
463 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); 463 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) );
464 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); 464 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) );
465 465
466 connect( tb, SIGNAL(tabSelected(const QString&)), 466 connect( tb, SIGNAL(tabSelected(const QString&)),
467 this, SLOT(showTab(const QString&)) ); 467 this, SLOT(showTab(const QString&)) );
468 connect( tabs, SIGNAL(selected(const QString&)), 468 connect( tabs, SIGNAL(selected(const QString&)),
469 this, SLOT(viewSelected(const QString&)) ); 469 this, SLOT(viewSelected(const QString&)) );
470 connect( tabs, SIGNAL(clicked(const AppLnk*)), 470 connect( tabs, SIGNAL(clicked(const AppLnk*)),
471 this, SLOT(select(const AppLnk*))); 471 this, SLOT(select(const AppLnk*)));
472 connect( tabs, SIGNAL(rightPressed(AppLnk*)), 472 connect( tabs, SIGNAL(rightPressed(AppLnk*)),
473 this, SLOT(properties(AppLnk*))); 473 this, SLOT(properties(AppLnk*)));
474 474
475#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 475#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
476 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 476 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
477 connect( sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), 477 connect( sysChannel, SIGNAL(received(const QCString&,const QByteArray&)),
478 this, SLOT(systemMessage(const QCString&,const QByteArray&)) ); 478 this, SLOT(systemMessage(const QCString&,const QByteArray&)) );
479#endif 479#endif
480 480
481 // all documents 481 // all documents
482 QImage img( Resource::loadImage( "DocsIcon" ) ); 482 QImage img( Resource::loadImage( "DocsIcon" ) );
483 QPixmap pm; 483 QPixmap pm;
484 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 484 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
485 // It could add this itself if it handles docs 485 // It could add this itself if it handles docs
486 486
487 tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE ); 487 tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE );
488 488
489 QTimer::singleShot( 0, tabs, SLOT( initLayout() ) ); 489 QTimer::singleShot( 0, tabs, SLOT( initLayout() ) );
490 qApp->setMainWidget( this ); 490 qApp->setMainWidget( this );
491 QTimer::singleShot( 500, this, SLOT( makeVisible() ) ); 491 QTimer::singleShot( 500, this, SLOT( makeVisible() ) );
492} 492}
493 493
494Launcher::~Launcher() 494Launcher::~Launcher()
495{ 495{
496 if ( tb ) 496 if ( tb )
497 destroyGUI(); 497 destroyGUI();
498} 498}
499 499
500 bool Launcher::requiresDocuments() const 500 bool Launcher::requiresDocuments() const
501 { 501 {
502 Config cfg( "Launcher" ); 502 Config cfg( "Launcher" );
503 cfg.setGroup( "DocTab" ); 503 cfg.setGroup( "DocTab" );
504 return cfg.readBoolEntry( "Enable", true ); 504 return cfg.readBoolEntry( "Enable", true );
505} 505}
506 506
507void Launcher::makeVisible() 507void Launcher::makeVisible()
508{ 508{
509 showMaximized(); 509 showMaximized();
510} 510}
511 511
512void Launcher::destroyGUI() 512void Launcher::destroyGUI()
513{ 513{
514 delete tb; 514 delete tb;
515 tb = 0; 515 tb = 0;
516 delete tabs; 516 delete tabs;
517 tabs =0; 517 tabs =0;
518} 518}
519 519
520bool Launcher::eventFilter( QObject*, QEvent *ev ) 520bool Launcher::eventFilter( QObject*, QEvent *ev )
521{ 521{
522#ifdef QT_QWS_CUSTOM 522#ifdef QT_QWS_CUSTOM
523 if ( ev->type() == QEvent::KeyPress ) { 523 if ( ev->type() == QEvent::KeyPress ) {
524 QKeyEvent *ke = (QKeyEvent *)ev; 524 QKeyEvent *ke = (QKeyEvent *)ev;
525 if ( ke->key() == Qt::Key_F11 ) { // menu key 525 if ( ke->key() == Qt::Key_F11 ) { // menu key
526 QWidget *active = qApp->activeWindow(); 526 QWidget *active = qApp->activeWindow();
527 if ( active && active->isPopup() ) 527 if ( active && active->isPopup() )
528 active->close(); 528 active->close();
529 else { 529 else {
530 Global::terminateBuiltin("calibrate"); // No tr 530 Global::terminateBuiltin("calibrate"); // No tr
531 tb->launchStartMenu(); 531 tb->launchStartMenu();
532 } 532 }
533 return TRUE; 533 return TRUE;
534 } 534 }
535 } 535 }
536#else 536#else
537 Q_UNUSED(ev); 537 Q_UNUSED(ev);
538#endif 538#endif
539 return FALSE; 539 return FALSE;
540} 540}
541 541
542void Launcher::toggleSymbolInput() 542void Launcher::toggleSymbolInput()
543{ 543{
544 tb->toggleSymbolInput(); 544 tb->toggleSymbolInput();
545} 545}
546 546
547void Launcher::toggleNumLockState() 547void Launcher::toggleNumLockState()
548{ 548{
549 tb->toggleNumLockState(); 549 tb->toggleNumLockState();
550} 550}
551 551
552void Launcher::toggleCapsLockState() 552void Launcher::toggleCapsLockState()
553{ 553{
554 tb->toggleCapsLockState(); 554 tb->toggleCapsLockState();
555} 555}
556 556
557static bool isVisibleWindow(int wid) 557static bool isVisibleWindow(int wid)
558{ 558{
559#ifdef Q_WS_QWS 559#ifdef Q_WS_QWS
560 const QList<QWSWindow> &list = qwsServer->clientWindows(); 560 const QList<QWSWindow> &list = qwsServer->clientWindows();
561 QWSWindow* w; 561 QWSWindow* w;
562 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 562 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
563 if ( w->winId() == wid ) 563 if ( w->winId() == wid )
564 return !w->isFullyObscured(); 564 return !w->isFullyObscured();
565 } 565 }
566#endif 566#endif
567 return FALSE; 567 return FALSE;
568} 568}
569 569
570void Launcher::viewSelected(const QString& s) 570void Launcher::viewSelected(const QString& s)
571{ 571{
572 setCaption( s + tr(" - Launcher") ); 572 setCaption( s + tr(" - Launcher") );
573} 573}
574 574
575void Launcher::showTab(const QString& id) 575void Launcher::showTab(const QString& id)
576{ 576{
577 tabs->categoryBar->showTab(id); 577 tabs->categoryBar->showTab(id);
578 raise(); 578 raise();
579} 579}
580 580
581void Launcher::select( const AppLnk *appLnk ) 581void Launcher::select( const AppLnk *appLnk )
582{ 582{
583 if ( appLnk->type() == "Folder" ) { // No tr 583 if ( appLnk->type() == "Folder" ) { // No tr
584 // Not supported: flat is simpler for the user 584 // Not supported: flat is simpler for the user
585 } else { 585 } else {
586 if ( appLnk->exec().isNull() ) { 586 if ( appLnk->exec().isNull() ) {
587 int i = QMessageBox::information(this,tr("No application"), 587 int i = QMessageBox::information(this,tr("No application"),
588 tr("<p>No application is defined for this document." 588 tr("<p>No application is defined for this document."
589 "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1); 589 "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1);
590 590
591 /* ### Fixme */ 591 /* ### Fixme */
592 if ( i == 1 ) 592 if ( i == 1 )
593 Global::execute("textedit",appLnk->file()); 593 Global::execute("textedit",appLnk->file());
594 594
595 return; 595 return;
596 } 596 }
597 tabs->setBusy(TRUE); 597 tabs->setBusy(TRUE);
598 emit executing( appLnk ); 598 emit executing( appLnk );
599 appLnk->execute(); 599 appLnk->execute();
600 } 600 }
601} 601}
602 602
603void Launcher::properties( AppLnk *appLnk ) 603void Launcher::properties( AppLnk *appLnk )
604{ 604{
605 if ( appLnk->type() == "Folder" ) { // No tr 605 if ( appLnk->type() == "Folder" ) { // No tr
606 // Not supported: flat is simpler for the user 606 // Not supported: flat is simpler for the user
607 } else { 607 } else {
608/* ### libqtopia FIXME also moving docLnks... */ 608/* ### libqtopia FIXME also moving docLnks... */
609 LnkProperties prop(appLnk,0 ); 609 LnkProperties prop(appLnk,0 );
610 610
611 QPEApplication::execDialog( &prop ); 611 QPEApplication::execDialog( &prop );
612 } 612 }
613} 613}
614 614
615void Launcher::storageChanged( const QList<FileSystem> &fs ) 615void Launcher::storageChanged( const QList<FileSystem> &fs )
616{ 616{
617 // ### update combo boxes if we had a combo box for the storage type 617 // ### update combo boxes if we had a combo box for the storage type
618} 618}
619 619
620void Launcher::systemMessage( const QCString &msg, const QByteArray &data) 620void Launcher::systemMessage( const QCString &msg, const QByteArray &data)
621{ 621{
622 QDataStream stream( data, IO_ReadOnly ); 622 QDataStream stream( data, IO_ReadOnly );
623 if ( msg == "busy()" ) { 623 if ( msg == "busy()" ) {
624 tb->startWait(); 624 tb->startWait();
625 } else if ( msg == "notBusy(QString)" ) { 625 } else if ( msg == "notBusy(QString)" ) {
626 QString app; 626 QString app;
627 stream >> app; 627 stream >> app;
628 tabs->setBusy(FALSE); 628 tabs->setBusy(FALSE);
629 tb->stopWait(app); 629 tb->stopWait(app);
630 } else if (msg == "applyStyle()") { 630 } else if (msg == "applyStyle()") {
631 tabs->currentView()->relayout(); 631 tabs->currentView()->relayout();
632 } 632 }
633} 633}
634 634
635// These are the update functions from the server 635// These are the update functions from the server
636void Launcher::typeAdded( const QString& type, const QString& name, 636void Launcher::typeAdded( const QString& type, const QString& name,
637 const QPixmap& pixmap, const QPixmap& ) 637 const QPixmap& pixmap, const QPixmap& )
638{ 638{
639 tabs->newView( type, pixmap, name ); 639 tabs->newView( type, pixmap, name );
640 ids.append( type ); 640 ids.append( type );
641 /* this will be called in applicationScanningProgress with value 100! */ 641 /* this will be called in applicationScanningProgress with value 100! */
642// tb->refreshStartMenu(); 642// tb->refreshStartMenu();
643 643
644 static bool first = TRUE; 644 static bool first = TRUE;
645 if ( first ) { 645 if ( first ) {
646 first = FALSE; 646 first = FALSE;
647 tabs->categoryBar->showTab(type); 647 tabs->categoryBar->showTab(type);
648 } 648 }
649 649
650 tabs->view( type )->setUpdatesEnabled( FALSE ); 650 tabs->view( type )->setUpdatesEnabled( FALSE );
651 tabs->view( type )->setSortEnabled( FALSE ); 651 tabs->view( type )->setSortEnabled( FALSE );
652} 652}
653 653
654void Launcher::typeRemoved( const QString& type ) 654void Launcher::typeRemoved( const QString& type )
655{ 655{
656 tabs->view( type )->removeAllItems(); 656 tabs->view( type )->removeAllItems();
657 tabs->deleteView( type ); 657 tabs->deleteView( type );
658 ids.remove( type ); 658 ids.remove( type );
659 /* this will be called in applicationScanningProgress with value 100! */ 659 /* this will be called in applicationScanningProgress with value 100! */
660// tb->refreshStartMenu(); 660// tb->refreshStartMenu();
661} 661}
662 662
663void Launcher::applicationAdded( const QString& type, const AppLnk& app ) 663void Launcher::applicationAdded( const QString& type, const AppLnk& app )
664{ 664{
665 if ( app.type() == "Separator" ) // No tr 665 if ( app.type() == "Separator" ) // No tr
666 return; 666 return;
667 667
668 LauncherView *view = tabs->view( type ); 668 LauncherView *view = tabs->view( type );
669 if ( view ) 669 if ( view )
670 view->addItem( new AppLnk( app ), FALSE ); 670 view->addItem( new AppLnk( app ), FALSE );
671 else 671 else
672 qWarning("addAppLnk: No view for type %s. Can't add app %s!", 672 owarn << "addAppLnk: No view for type " << type.latin1() << ". Can't add app "
673 type.latin1(),app.name().latin1() ); 673 << app.name().latin1() << "!",
674 674
675 MimeType::registerApp( app ); 675 MimeType::registerApp( app );
676} 676}
677 677
678void Launcher::applicationRemoved( const QString& type, const AppLnk& app ) 678void Launcher::applicationRemoved( const QString& type, const AppLnk& app )
679{ 679{
680 LauncherView *view = tabs->view( type ); 680 LauncherView *view = tabs->view( type );
681 if ( view ) 681 if ( view )
682 view->removeLink( app.linkFile() ); 682 view->removeLink( app.linkFile() );
683 else 683 else
684 owarn << "removeAppLnk: No view for " << type << "!" << oendl; 684 owarn << "removeAppLnk: No view for " << type << "!" << oendl;
685} 685}
686 686
687void Launcher::allApplicationsRemoved() 687void Launcher::allApplicationsRemoved()
688{ 688{
689 MimeType::clear(); 689 MimeType::clear();
690 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) 690 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it)
691 tabs->view( (*it) )->removeAllItems(); 691 tabs->view( (*it) )->removeAllItems();
692} 692}
693 693
694void Launcher::documentAdded( const DocLnk& doc ) 694void Launcher::documentAdded( const DocLnk& doc )
695{ 695{
696 tabs->docView()->addItem( new DocLnk( doc ), FALSE ); 696 tabs->docView()->addItem( new DocLnk( doc ), FALSE );
697} 697}
698 698
699void Launcher::aboutToAddBegin() 699void Launcher::aboutToAddBegin()
700{ 700{
701 tabs->docView()->setUpdatesEnabled( false ); 701 tabs->docView()->setUpdatesEnabled( false );
702} 702}
703 703
704void Launcher::aboutToAddEnd() 704void Launcher::aboutToAddEnd()
705{ 705{
706 tabs->docView()->setUpdatesEnabled( true ); 706 tabs->docView()->setUpdatesEnabled( true );
707} 707}
708 708
709void Launcher::showLoadingDocs() 709void Launcher::showLoadingDocs()
710{ 710{
711 tabs->docView()->hide(); 711 tabs->docView()->hide();
712} 712}
713 713
714void Launcher::showDocTab() 714void Launcher::showDocTab()
715{ 715{
716 if ( tabs->categoryBar->currentView() == tabs->docView() ) 716 if ( tabs->categoryBar->currentView() == tabs->docView() )
717 tabs->docView()->show(); 717 tabs->docView()->show();
718} 718}
719 719
720void Launcher::documentRemoved( const DocLnk& doc ) 720void Launcher::documentRemoved( const DocLnk& doc )
721{ 721{
722 tabs->docView()->removeLink( doc.linkFile() ); 722 tabs->docView()->removeLink( doc.linkFile() );
723} 723}
724 724
725void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc ) 725void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc )
726{ 726{
727 documentRemoved( oldDoc ); 727 documentRemoved( oldDoc );
728 documentAdded( newDoc ); 728 documentAdded( newDoc );
729} 729}
730 730
731void Launcher::allDocumentsRemoved() 731void Launcher::allDocumentsRemoved()
732{ 732{
733 tabs->docView()->removeAllItems(); 733 tabs->docView()->removeAllItems();
734} 734}
735 735
736void Launcher::applicationStateChanged( const QString& name, ApplicationState state ) 736void Launcher::applicationStateChanged( const QString& name, ApplicationState state )
737{ 737{
738 tb->setApplicationState( name, state ); 738 tb->setApplicationState( name, state );
739} 739}
740 740
741void Launcher::applicationScanningProgress( int percent ) 741void Launcher::applicationScanningProgress( int percent )
742{ 742{
743 switch ( percent ) { 743 switch ( percent ) {
744 case 0: { 744 case 0: {
745 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { 745 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
746 tabs->view( (*it) )->setUpdatesEnabled( FALSE ); 746 tabs->view( (*it) )->setUpdatesEnabled( FALSE );
747 tabs->view( (*it) )->setSortEnabled( FALSE ); 747 tabs->view( (*it) )->setSortEnabled( FALSE );
748 } 748 }
749 break; 749 break;
750 } 750 }
751 case 100: { 751 case 100: {
752 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { 752 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
753 tabs->view( (*it) )->setUpdatesEnabled( TRUE ); 753 tabs->view( (*it) )->setUpdatesEnabled( TRUE );
754 tabs->view( (*it) )->setSortEnabled( TRUE ); 754 tabs->view( (*it) )->setSortEnabled( TRUE );
755 } 755 }
756 tb->refreshStartMenu(); 756 tb->refreshStartMenu();
757 break; 757 break;
758 } 758 }
759 default: 759 default:
760 break; 760 break;
761 } 761 }
762} 762}
763 763
764void Launcher::documentScanningProgress( int percent ) 764void Launcher::documentScanningProgress( int percent )
765{ 765{
766 switch ( percent ) { 766 switch ( percent ) {
767 case 0: { 767 case 0: {
768 tabs->setLoadingProgress( 0 ); 768 tabs->setLoadingProgress( 0 );
769 tabs->setLoadingWidgetEnabled( TRUE ); 769 tabs->setLoadingWidgetEnabled( TRUE );
770 tabs->docView()->setUpdatesEnabled( FALSE ); 770 tabs->docView()->setUpdatesEnabled( FALSE );
771 tabs->docView()->setSortEnabled( FALSE ); 771 tabs->docView()->setSortEnabled( FALSE );
772 break; 772 break;
773 } 773 }
774 case 100: { 774 case 100: {
775 tabs->docView()->updateTools(); 775 tabs->docView()->updateTools();
776 tabs->docView()->setSortEnabled( TRUE ); 776 tabs->docView()->setSortEnabled( TRUE );
777 tabs->docView()->setUpdatesEnabled( TRUE ); 777 tabs->docView()->setUpdatesEnabled( TRUE );
778 tabs->setLoadingWidgetEnabled( FALSE ); 778 tabs->setLoadingWidgetEnabled( FALSE );
779 break; 779 break;
780 } 780 }
781 default: 781 default:
782 tabs->setLoadingProgress( percent ); 782 tabs->setLoadingProgress( percent );
783 break; 783 break;
784 } 784 }
785} 785}
786 786
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp
index a11ac86..0461432 100644
--- a/core/launcher/packageslave.cpp
+++ b/core/launcher/packageslave.cpp
@@ -1,339 +1,338 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "packageslave.h" 21#include "packageslave.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <qtopia/qprocess.h> 25#include <qtopia/qprocess.h>
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#include <qtopia/qcopenvelope_qws.h> 27#include <qtopia/qcopenvelope_qws.h>
28#endif 28#endif
29using namespace Opie::Core; 29using namespace Opie::Core;
30 30
31/* QT */ 31/* QT */
32#ifdef Q_WS_QWS 32#ifdef Q_WS_QWS
33#include <qcopchannel_qws.h> 33#include <qcopchannel_qws.h>
34#endif 34#endif
35#include <qtextstream.h> 35#include <qtextstream.h>
36 36
37/* STD */ 37/* STD */
38#include <stdlib.h> 38#include <stdlib.h>
39#include <sys/stat.h> // mkdir() 39#include <sys/stat.h> // mkdir()
40#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 40#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/vfs.h> 42#include <sys/vfs.h>
43#include <mntent.h> 43#include <mntent.h>
44#elif defined(Q_OS_MACX) 44#elif defined(Q_OS_MACX)
45#include <unistd.h> 45#include <unistd.h>
46#endif 46#endif
47 47
48 48
49PackageHandler::PackageHandler( QObject *parent, char* name ) 49PackageHandler::PackageHandler( QObject *parent, char* name )
50 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) 50 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE )
51{ 51{
52 // setup qcop channel 52 // setup qcop channel
53#ifndef QT_NO_COP 53#ifndef QT_NO_COP
54 packageChannel = new QCopChannel( "QPE/Package", this ); 54 packageChannel = new QCopChannel( "QPE/Package", this );
55 connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 55 connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
56 this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) ); 56 this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) );
57#endif 57#endif
58} 58}
59 59
60void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) 60void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data )
61{ 61{
62 QDataStream stream( data, IO_ReadOnly ); 62 QDataStream stream( data, IO_ReadOnly );
63 63
64 if ( msg == "installPackage(QString)" ) { 64 if ( msg == "installPackage(QString)" ) {
65 QString file; 65 QString file;
66 stream >> file; 66 stream >> file;
67 installPackage( file ); 67 installPackage( file );
68 } else if ( msg == "removePackage(QString)" ) { 68 } else if ( msg == "removePackage(QString)" ) {
69 QString file; 69 QString file;
70 stream >> file; 70 stream >> file;
71 removePackage( file ); 71 removePackage( file );
72 } else if ( msg == "addPackageFiles(QString,QString)" ) { 72 } else if ( msg == "addPackageFiles(QString,QString)" ) {
73 QString location, listfile; 73 QString location, listfile;
74 stream >> location >> listfile; 74 stream >> location >> listfile;
75 addPackageFiles( location, listfile); 75 addPackageFiles( location, listfile);
76 } else if ( msg == "addPackages(QString)" ) { 76 } else if ( msg == "addPackages(QString)" ) {
77 QString location; 77 QString location;
78 stream >> location; 78 stream >> location;
79 addPackages( location ); 79 addPackages( location );
80 } else if ( msg == "cleanupPackageFiles(QString)" ) { 80 } else if ( msg == "cleanupPackageFiles(QString)" ) {
81 QString listfile; 81 QString listfile;
82 stream >> listfile; 82 stream >> listfile;
83 cleanupPackageFiles( listfile ); 83 cleanupPackageFiles( listfile );
84 } else if ( msg == "cleanupPackages(QString)" ) { 84 } else if ( msg == "cleanupPackages(QString)" ) {
85 QString location; 85 QString location;
86 stream >> location; 86 stream >> location;
87 cleanupPackages( location ); 87 cleanupPackages( location );
88 } else if ( msg == "prepareInstall(QString,QString)" ) { 88 } else if ( msg == "prepareInstall(QString,QString)" ) {
89 QString size, path; 89 QString size, path;
90 stream >> size; 90 stream >> size;
91 stream >> path; 91 stream >> path;
92 prepareInstall( size, path ); 92 prepareInstall( size, path );
93 } 93 }
94} 94}
95 95
96void PackageHandler::installPackage( const QString &package ) 96void PackageHandler::installPackage( const QString &package )
97{ 97{
98 if ( mNoSpaceLeft ) { 98 if ( mNoSpaceLeft ) {
99 mNoSpaceLeft = FALSE; 99 mNoSpaceLeft = FALSE;
100 // Don't emit that for now, I still couldn't test it (Wener) 100 // Don't emit that for now, I still couldn't test it (Wener)
101 //sendReply( "installFailed(QString)", package ); 101 //sendReply( "installFailed(QString)", package );
102 //return; 102 //return;
103 } 103 }
104 104
105 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr 105 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr
106 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); 106 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) );
107 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); 107 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) );
108 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); 108 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) );
109 currentPackage = package; 109 currentPackage = package;
110 110
111 currentProcessError=""; 111 currentProcessError="";
112 sendReply( "installStarted(QString)", package ); 112 sendReply( "installStarted(QString)", package );
113 currentProcess->start(); 113 currentProcess->start();
114} 114}
115 115
116void PackageHandler::removePackage( const QString &package ) 116void PackageHandler::removePackage( const QString &package )
117{ 117{
118 currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr 118 currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr
119 connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); 119 connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) );
120 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); 120 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) );
121 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); 121 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) );
122 currentPackage = package; 122 currentPackage = package;
123 123
124 currentProcessError=""; 124 currentProcessError="";
125 sendReply( "removeStarted(QString)", package ); 125 sendReply( "removeStarted(QString)", package );
126 currentProcess->start(); 126 currentProcess->start();
127} 127}
128 128
129void PackageHandler::sendReply( const QCString& msg, const QString& arg ) 129void PackageHandler::sendReply( const QCString& msg, const QString& arg )
130{ 130{
131#ifndef QT_NO_COP 131#ifndef QT_NO_COP
132 QCopEnvelope e( "QPE/Desktop", msg ); 132 QCopEnvelope e( "QPE/Desktop", msg );
133 e << arg; 133 e << arg;
134#endif 134#endif
135} 135}
136 136
137void PackageHandler::addPackageFiles( const QString &location, 137void PackageHandler::addPackageFiles( const QString &location,
138 const QString &listfile ) 138 const QString &listfile )
139{ 139{
140 QFile f(listfile); 140 QFile f(listfile);
141#ifndef Q_OS_WIN32 141#ifndef Q_OS_WIN32
142 //make a copy so we can remove the symlinks later 142 //make a copy so we can remove the symlinks later
143 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); 143 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 );
144 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 144 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
145#else 145#else
146 QDir d; 146 QDir d;
147 //#### revise 147 //#### revise
148 odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl; 148 odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl;
149 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); 149 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii());
150 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 150 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
151#endif 151#endif
152 152
153
154 if ( f.open(IO_ReadOnly) ) {
155 QTextStream ts(&f);
156 153
157 QString s; 154 if ( f.open(IO_ReadOnly) ) {
158 while ( !ts.eof() ) { // until end of file... 155 QTextStream ts(&f);
159 s = ts.readLine(); // line of text excluding '\n' 156
160 // for s, do link/mkdir. 157 QString s;
161 if ( s.right(1) == "/" ) { 158 while ( !ts.eof() ) { // until end of file...
159 s = ts.readLine(); // line of text excluding '\n'
160 // for s, do link/mkdir.
161 if ( s.right(1) == "/" ) {
162 odebug << "do mkdir for " << s.ascii() << "" << oendl; 162 odebug << "do mkdir for " << s.ascii() << "" << oendl;
163#ifndef Q_OS_WIN32 163#ifndef Q_OS_WIN32
164 mkdir( s.ascii(), 0777 ); 164 mkdir( s.ascii(), 0777 );
165 //possible optimization: symlink directories 165 //possible optimization: symlink directories
166 //that don't exist already. -- Risky. 166 //that don't exist already. -- Risky.
167#else 167#else
168 d.mkdir( s.ascii()); 168 d.mkdir( s.ascii());
169#endif 169#endif
170 170
171 } else { 171 } else {
172#ifndef Q_OS_WIN32 172#ifndef Q_OS_WIN32
173 odebug << "do symlink for " << s.ascii() << "" << oendl; 173 odebug << "do symlink for " << s.ascii() << "" << oendl;
174 symlink( (location + s).ascii(), s.ascii() ); 174 symlink( (location + s).ascii(), s.ascii() );
175#else 175#else
176 odebug << "Copy file instead of a symlink for WIN32" << oendl; 176 odebug << "Copy file instead of a symlink for WIN32" << oendl;
177 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) 177 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE))
178 qWarning("Unable to create symlinkfor %s", 178 owarn << "Unable to create symlinkfor " << (location + s).ascii() << oendl;
179 (location + s).ascii());
180#endif 179#endif
181 } 180 }
182 } 181 }
183 f.close(); 182 f.close();
184 } 183 }
185} 184}
186 185
187void PackageHandler::addPackages( const QString &location ) 186void PackageHandler::addPackages( const QString &location )
188{ 187{
189 // get list of *.list in location/usr/lib/ipkg/info/*.list 188 // get list of *.list in location/usr/lib/ipkg/info/*.list
190 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr 189 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr
191 QDir::Name, QDir::Files); 190 QDir::Name, QDir::Files);
192 if ( !dir.exists() ) 191 if ( !dir.exists() )
193 return; 192 return;
194 193
195 QStringList packages = dir.entryList(); 194 QStringList packages = dir.entryList();
196 for ( QStringList::Iterator it = packages.begin(); 195 for ( QStringList::Iterator it = packages.begin();
197 it != packages.end(); ++it ) { 196 it != packages.end(); ++it ) {
198 addPackageFiles( location, *it ); 197 addPackageFiles( location, *it );
199 } 198 }
200} 199}
201 200
202 201
203void PackageHandler::cleanupPackageFiles( const QString &listfile ) 202void PackageHandler::cleanupPackageFiles( const QString &listfile )
204{ 203{
205 QFile f(listfile); 204 QFile f(listfile);
206 205
207 if ( f.open(IO_ReadOnly) ) { 206 if ( f.open(IO_ReadOnly) ) {
208 QTextStream ts(&f); 207 QTextStream ts(&f);
209 208
210 QString s; 209 QString s;
211 while ( !ts.eof() ) { // until end of file... 210 while ( !ts.eof() ) { // until end of file...
212 s = ts.readLine(); // line of text excluding '\n' 211 s = ts.readLine(); // line of text excluding '\n'
213 // for s, do link/mkdir. 212 // for s, do link/mkdir.
214 if ( s.right(1) == "/" ) { 213 if ( s.right(1) == "/" ) {
215 //should rmdir if empty, after all files have been removed 214 //should rmdir if empty, after all files have been removed
216 } else { 215 } else {
217#ifndef Q_OS_WIN32 216#ifndef Q_OS_WIN32
218 odebug << "remove symlink for " << s.ascii() << "" << oendl; 217 odebug << "remove symlink for " << s.ascii() << "" << oendl;
219 //check if it is a symlink first (don't remove /etc/passwd...) 218 //check if it is a symlink first (don't remove /etc/passwd...)
220 char buf[10]; //we don't care about the contents 219 char buf[10]; //we don't care about the contents
221 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) 220 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) )
222 ::unlink( s.ascii() ); 221 ::unlink( s.ascii() );
223 #else 222#else
224 // ### revise 223 // ### revise
225 owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl; 224 owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl;
226#endif 225#endif
227 } 226 }
228 } 227 }
229 f.close(); 228 f.close();
230 229
231 //remove the list file 230 //remove the list file
232 ::unlink( listfile.ascii() ); 231 ::unlink( listfile.ascii() );
233 232
234 } 233 }
235} 234}
236 235
237void PackageHandler::cleanupPackages( const QString &location ) 236void PackageHandler::cleanupPackages( const QString &location )
238{ 237{
239 // get list of *.list in location/usr/lib/ipkg/info/*.list 238 // get list of *.list in location/usr/lib/ipkg/info/*.list
240 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr 239 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr
241 QDir::Name, QDir::Files); 240 QDir::Name, QDir::Files);
242 if ( !dir.exists() ) 241 if ( !dir.exists() )
243 return; 242 return;
244 243
245 QStringList packages = dir.entryList(); 244 QStringList packages = dir.entryList();
246 for ( QStringList::Iterator it = packages.begin(); 245 for ( QStringList::Iterator it = packages.begin();
247 it != packages.end(); ++it ) { 246 it != packages.end(); ++it ) {
248 cleanupPackageFiles( *it ); 247 cleanupPackageFiles( *it );
249 } 248 }
250 249
251 //remove the backup directory 250 //remove the backup directory
252 //### 251 //###
253} 252}
254 253
255void PackageHandler::prepareInstall( const QString& size, const QString& path ) 254void PackageHandler::prepareInstall( const QString& size, const QString& path )
256{ 255{
257 // Check whether there will be enough space to install the next package. 256 // Check whether there will be enough space to install the next package.
258 bool ok; 257 bool ok;
259 unsigned int s = size.toUInt( &ok ); 258 unsigned int s = size.toUInt( &ok );
260 259
261 if ( !ok ) 260 if ( !ok )
262 return; 261 return;
263 262
264 // Shamelessly stolen from the sysinfo application (Werner) 263 // Shamelessly stolen from the sysinfo application (Werner)
265#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 264#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
266 struct statfs fs; 265 struct statfs fs;
267 if ( statfs( path.latin1(), &fs ) == 0 ) 266 if ( statfs( path.latin1(), &fs ) == 0 )
268 if ( s > fs.f_bsize * fs.f_bavail ) { 267 if ( s > fs.f_bsize * fs.f_bavail ) {
269 //odebug << "############### Not enough space left ###############" << oendl; 268 //odebug << "############### Not enough space left ###############" << oendl;
270 mNoSpaceLeft = TRUE; 269 mNoSpaceLeft = TRUE;
271 } 270 }
272#endif 271#endif
273} 272}
274 273
275void PackageHandler::iProcessExited() 274void PackageHandler::iProcessExited()
276{ 275{
277 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 276 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
278 sendReply( "installDone(QString)", currentPackage ); 277 sendReply( "installDone(QString)", currentPackage );
279 else { 278 else {
280#ifndef QT_NO_COP 279#ifndef QT_NO_COP
281 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); 280 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" );
282 e << currentPackage << currentProcess->exitStatus() 281 e << currentPackage << currentProcess->exitStatus()
283 << currentProcessError; 282 << currentProcessError;
284#endif 283#endif
285 } 284 }
286 285
287 delete currentProcess; 286 delete currentProcess;
288 currentProcess = 0; 287 currentProcess = 0;
289 288
290#ifndef QT_NO_COP 289#ifndef QT_NO_COP
291 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 290 QCopEnvelope e("QPE/System", "linkChanged(QString)");
292 QString lf = QString::null; 291 QString lf = QString::null;
293 e << lf; 292 e << lf;
294#endif 293#endif
295 unlink( currentPackage ); 294 unlink( currentPackage );
296} 295}
297 296
298void PackageHandler::rmProcessExited() 297void PackageHandler::rmProcessExited()
299{ 298{
300 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 299 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
301 sendReply( "removeDone(QString)", currentPackage ); 300 sendReply( "removeDone(QString)", currentPackage );
302 else 301 else
303 sendReply( "removeFailed(QString)", currentPackage ); 302 sendReply( "removeFailed(QString)", currentPackage );
304 303
305#ifndef QT_NO_COP 304#ifndef QT_NO_COP
306 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 305 QCopEnvelope e("QPE/System", "linkChanged(QString)");
307 QString lf = QString::null; 306 QString lf = QString::null;
308 e << lf; 307 e << lf;
309#endif 308#endif
310} 309}
311 310
312void PackageHandler::readyReadStdout() 311void PackageHandler::readyReadStdout()
313{ 312{
314 while ( currentProcess->canReadLineStdout() ) { 313 while ( currentProcess->canReadLineStdout() ) {
315 QString line = currentProcess->readLineStdout(); 314 QString line = currentProcess->readLineStdout();
316 currentProcessError.append("OUT:"+line); 315 currentProcessError.append("OUT:"+line);
317 if ( line.contains( "Unpacking" ) ) // No tr 316 if ( line.contains( "Unpacking" ) ) // No tr
318 sendReply( "installStep(QString)", "one" ); // No tr 317 sendReply( "installStep(QString)", "one" ); // No tr
319 else if ( line.contains( "Configuring" ) ) // No tr 318 else if ( line.contains( "Configuring" ) ) // No tr
320 sendReply( "installStep(QString)", "two" ); // No tr 319 sendReply( "installStep(QString)", "two" ); // No tr
321 } 320 }
322} 321}
323 322
324void PackageHandler::readyReadStderr() 323void PackageHandler::readyReadStderr()
325{ 324{
326 while ( currentProcess->canReadLineStderr() ) { 325 while ( currentProcess->canReadLineStderr() ) {
327 QString line = currentProcess->readLineStderr(); 326 QString line = currentProcess->readLineStderr();
328 currentProcessError.append("ERR:"+line); 327 currentProcessError.append("ERR:"+line);
329 } 328 }
330} 329}
331 330
332void PackageHandler::redoPackages() 331void PackageHandler::redoPackages()
333{ 332{
334 //get list of filesystems 333 //get list of filesystems
335 334
336 //call cleanupPackages for the ones that have disappeared 335 //call cleanupPackages for the ones that have disappeared
337 336
338 //call addPackageFiles for the new ones 337 //call addPackageFiles for the new ones
339} 338}
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index c3f936e..1d4ca40 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1430 +1,1429 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "transferserver.h" 20#include "transferserver.h"
21 21
22/* OPIE */ 22/* OPIE */
23#include <opie2/odebug.h> 23#include <opie2/odebug.h>
24#include <opie2/oglobal.h> 24#include <opie2/oglobal.h>
25#include <qtopia/qprocess.h> 25#include <qtopia/qprocess.h>
26#include <qtopia/process.h> 26#include <qtopia/process.h>
27#include <qtopia/private/contact.h> 27#include <qtopia/private/contact.h>
28#include <qtopia/version.h> 28#include <qtopia/version.h>
29#ifdef Q_WS_QWS 29#ifdef Q_WS_QWS
30#include <qtopia/qcopenvelope_qws.h> 30#include <qtopia/qcopenvelope_qws.h>
31#endif 31#endif
32using namespace Opie::Core; 32using namespace Opie::Core;
33 33
34/* QT */ 34/* QT */
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37 37
38/* STD */ 38/* STD */
39#include <pwd.h> 39#include <pwd.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <time.h> 43#include <time.h>
44 44
45#ifndef Q_OS_MACX 45#ifndef Q_OS_MACX
46#include <shadow.h> 46#include <shadow.h>
47#include <crypt.h> 47#include <crypt.h>
48#endif /* Q_OS_MACX */ 48#endif /* Q_OS_MACX */
49 49
50const int block_size = 51200; 50const int block_size = 51200;
51 51
52TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 52TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
53 const char* name) 53 const char* name)
54 : QServerSocket( port, 1, parent, name ) 54 : QServerSocket( port, 1, parent, name )
55{ 55{
56 connections.setAutoDelete( TRUE ); 56 connections.setAutoDelete( TRUE );
57 if ( !ok() ) 57 if ( !ok() )
58 owarn << "Failed to bind to port " << port << "" << oendl; 58 owarn << "Failed to bind to port " << port << "" << oendl;
59} 59}
60 60
61void TransferServer::authorizeConnections() 61void TransferServer::authorizeConnections()
62{ 62{
63 QListIterator<ServerPI> it(connections); 63 QListIterator<ServerPI> it(connections);
64 while ( it.current() ) { 64 while ( it.current() ) {
65 if ( !it.current()->verifyAuthorised() ) { 65 if ( !it.current()->verifyAuthorised() ) {
66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); 66 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
67 connections.removeRef( it.current() ); 67 connections.removeRef( it.current() );
68 } else 68 } else
69 ++it; 69 ++it;
70 } 70 }
71} 71}
72 72
73void TransferServer::closed(ServerPI *item) 73void TransferServer::closed(ServerPI *item)
74{ 74{
75 connections.removeRef(item); 75 connections.removeRef(item);
76} 76}
77 77
78TransferServer::~TransferServer() 78TransferServer::~TransferServer()
79{ 79{
80} 80}
81 81
82void TransferServer::newConnection( int socket ) 82void TransferServer::newConnection( int socket )
83{ 83{
84 ServerPI *ptr = new ServerPI( socket, this ); 84 ServerPI *ptr = new ServerPI( socket, this );
85 connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); 85 connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
86 connections.append( ptr ); 86 connections.append( ptr );
87} 87}
88 88
89QString SyncAuthentication::serverId() 89QString SyncAuthentication::serverId()
90{ 90{
91 Config cfg("Security"); 91 Config cfg("Security");
92 cfg.setGroup("Sync"); 92 cfg.setGroup("Sync");
93 QString r = cfg.readEntry("serverid"); 93 QString r = cfg.readEntry("serverid");
94 94
95 if ( r.isEmpty() ) { 95 if ( r.isEmpty() ) {
96 r = OGlobal::generateUuid(); 96 r = OGlobal::generateUuid();
97 cfg.writeEntry("serverid", r ); 97 cfg.writeEntry("serverid", r );
98 } 98 }
99 return r; 99 return r;
100} 100}
101 101
102QString SyncAuthentication::ownerName() 102QString SyncAuthentication::ownerName()
103{ 103{
104 QString vfilename = Global::applicationFileName("addressbook", 104 QString vfilename = Global::applicationFileName("addressbook",
105 "businesscard.vcf"); 105 "businesscard.vcf");
106 if (QFile::exists(vfilename)) { 106 if (QFile::exists(vfilename)) {
107 Contact c; 107 Contact c;
108 c = Contact::readVCard( vfilename )[0]; 108 c = Contact::readVCard( vfilename )[0];
109 return c.fullName(); 109 return c.fullName();
110 } 110 }
111 111
112 return QString::null; 112 return QString::null;
113} 113}
114 114
115QString SyncAuthentication::loginName() 115QString SyncAuthentication::loginName()
116{ 116{
117 struct passwd *pw = 0L; 117 struct passwd *pw = 0L;
118#ifndef Q_OS_WIN32 118#ifndef Q_OS_WIN32
119 pw = getpwuid( geteuid() ); 119 pw = getpwuid( geteuid() );
120 return QString::fromLocal8Bit( pw->pw_name ); 120 return QString::fromLocal8Bit( pw->pw_name );
121#else 121#else
122 //### revise 122 //### revise
123 return QString(); 123 return QString();
124#endif 124#endif
125} 125}
126 126
127int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 127int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
128{ 128{
129 Config cfg("Security"); 129 Config cfg("Security");
130 cfg.setGroup("Sync"); 130 cfg.setGroup("Sync");
131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 131 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 132 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
133 133
134 // QHostAddress allowed; 134 // QHostAddress allowed;
135 // allowed.setAddress(allowedstr); 135 // allowed.setAddress(allowedstr);
136 // uint auth_peer = allowed.ip4Addr(); 136 // uint auth_peer = allowed.ip4Addr();
137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 137 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 138 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 139 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
140 140
141 return (peeraddress.ip4Addr() & mask) == auth_peer; 141 return (peeraddress.ip4Addr() & mask) == auth_peer;
142} 142}
143 143
144bool SyncAuthentication::checkUser( const QString& user ) 144bool SyncAuthentication::checkUser( const QString& user )
145{ 145{
146 if ( user.isEmpty() ) return FALSE; 146 if ( user.isEmpty() ) return FALSE;
147 QString euser = loginName(); 147 QString euser = loginName();
148 return user == euser; 148 return user == euser;
149} 149}
150 150
151bool SyncAuthentication::checkPassword( const QString& password ) 151bool SyncAuthentication::checkPassword( const QString& password )
152{ 152{
153#ifdef ALLOW_UNIX_USER_FTP 153#ifdef ALLOW_UNIX_USER_FTP
154 // First, check system password... 154 // First, check system password...
155 155
156 struct passwd *pw = 0; 156 struct passwd *pw = 0;
157 struct spwd *spw = 0; 157 struct spwd *spw = 0;
158 158
159 pw = getpwuid( geteuid() ); 159 pw = getpwuid( geteuid() );
160 spw = getspnam( pw->pw_name ); 160 spw = getspnam( pw->pw_name );
161 161
162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 162 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
163 if ( cpwd == "x" && spw ) 163 if ( cpwd == "x" && spw )
164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 164 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
165 165
166 // Note: some systems use more than crypt for passwords. 166 // Note: some systems use more than crypt for passwords.
167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 167 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
168 if ( cpwd == cpassword ) 168 if ( cpwd == cpassword )
169 return TRUE; 169 return TRUE;
170#endif 170#endif
171 171
172 static int lastdenial=0; 172 static int lastdenial=0;
173 static int denials=0; 173 static int denials=0;
174 int now = time(0); 174 int now = time(0);
175 175
176 Config cfg("Security"); 176 Config cfg("Security");
177 cfg.setGroup("SyncMode"); 177 cfg.setGroup("SyncMode");
178 int mode = cfg.readNumEntry("Mode", 0x02 ); 178 int mode = cfg.readNumEntry("Mode", 0x02 );
179 179
180 //No pass word needed if the user really needs it 180 //No pass word needed if the user really needs it
181 if (mode & 0x04) { 181 if (mode & 0x04) {
182 QMessageBox unauth( 182 QMessageBox unauth(
183 tr("Sync Connection"), 183 tr("Sync Connection"),
184 tr("<qt><p>An unauthorized system is requesting access to this device." 184 tr("<qt><p>An unauthorized system is requesting access to this device."
185 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ), 185 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
186 QMessageBox::Warning, 186 QMessageBox::Warning,
187 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton, 187 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
188 0, QString::null, TRUE, WStyle_StaysOnTop); 188 0, QString::null, TRUE, WStyle_StaysOnTop);
189 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) ); 189 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
190 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 190 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
191 switch( unauth.exec() ) { 191 switch( unauth.exec() ) {
192 case QMessageBox::Ok: 192 case QMessageBox::Ok:
193 return TRUE; 193 return TRUE;
194 break; 194 break;
195 case QMessageBox::Cancel: 195 case QMessageBox::Cancel:
196 default: 196 default:
197 denials++; 197 denials++;
198 lastdenial=now; 198 lastdenial=now;
199 return FALSE; 199 return FALSE;
200 } 200 }
201 } 201 }
202 202
203 // Detect old Qtopia Desktop (no password) and fail 203 // Detect old Qtopia Desktop (no password) and fail
204 if ( password.isEmpty() ) { 204 if ( password.isEmpty() ) {
205 if ( denials < 3 || now > lastdenial+600 ) { 205 if ( denials < 3 || now > lastdenial+600 ) {
206 QMessageBox unauth( 206 QMessageBox unauth(
207 tr("Sync Connection"), 207 tr("Sync Connection"),
208 tr("<p>An unauthorized system is requesting access to this device." 208 tr("<p>An unauthorized system is requesting access to this device."
209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 209 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
210 "please upgrade or change the security setting to use IntelliSync." ), 210 "please upgrade or change the security setting to use IntelliSync." ),
211 QMessageBox::Warning, 211 QMessageBox::Warning,
212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 212 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
213 0, QString::null, TRUE, WStyle_StaysOnTop); 213 0, QString::null, TRUE, WStyle_StaysOnTop);
214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 214 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
215 unauth.exec(); 215 unauth.exec();
216 216
217 denials++; 217 denials++;
218 lastdenial=now; 218 lastdenial=now;
219 } 219 }
220 return FALSE; 220 return FALSE;
221 221
222 } 222 }
223 223
224 // Second, check sync password... 224 // Second, check sync password...
225 225
226 static int lock=0; 226 static int lock=0;
227 if ( lock ) return FALSE; 227 if ( lock ) return FALSE;
228 228
229 ++lock; 229 ++lock;
230 230
231 /* 231 /*
232 * we need to support old Sync software and QtopiaDesktop 232 * we need to support old Sync software and QtopiaDesktop
233 */ 233 */
234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 234 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
235 Config cfg( "Security" ); 235 Config cfg( "Security" );
236 cfg.setGroup("Sync"); 236 cfg.setGroup("Sync");
237 QStringList pwds = cfg.readListEntry("Passwords",' '); 237 QStringList pwds = cfg.readListEntry("Passwords",' ');
238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 238 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
239#ifndef Q_OS_WIN32 239#ifndef Q_OS_WIN32
240 QString cpassword = QString::fromLocal8Bit( 240 QString cpassword = QString::fromLocal8Bit(
241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 241 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
242#else 242#else
243 // ### revise 243 // ### revise
244 QString cpassword(""); 244 QString cpassword("");
245#endif 245#endif
246 if ( *it == cpassword ) { 246 if ( *it == cpassword ) {
247 lock--; 247 lock--;
248 return TRUE; 248 return TRUE;
249 } 249 }
250 } 250 }
251 251
252 // Unrecognized system. Be careful... 252 // Unrecognized system. Be careful...
253 QMessageBox unrecbox( 253 QMessageBox unrecbox(
254 tr("Sync Connection"), 254 tr("Sync Connection"),
255 tr( "<p>An unrecognized system is requesting access to this device." 255 tr( "<p>An unrecognized system is requesting access to this device."
256 "<p>If you have just initiated a Sync for the first time, this is normal."), 256 "<p>If you have just initiated a Sync for the first time, this is normal."),
257 QMessageBox::Warning, 257 QMessageBox::Warning,
258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 258 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
259 0, QString::null, TRUE, WStyle_StaysOnTop); 259 0, QString::null, TRUE, WStyle_StaysOnTop);
260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 260 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 261 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
262 262
263 if ( (denials > 2 && now < lastdenial+600) 263 if ( (denials > 2 && now < lastdenial+600)
264 || unrecbox.exec() != QMessageBox::Yes) 264 || unrecbox.exec() != QMessageBox::Yes)
265 { 265 {
266 denials++; 266 denials++;
267 lastdenial=now; 267 lastdenial=now;
268 lock--; 268 lock--;
269 return FALSE; 269 return FALSE;
270 } else { 270 } else {
271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 271 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
272 char salt[2]; 272 char salt[2];
273 salt[0]= salty[rand() % (sizeof(salty)-1)]; 273 salt[0]= salty[rand() % (sizeof(salty)-1)];
274 salt[1]= salty[rand() % (sizeof(salty)-1)]; 274 salt[1]= salty[rand() % (sizeof(salty)-1)];
275#ifndef Q_OS_WIN32 275#ifndef Q_OS_WIN32
276 QString cpassword = QString::fromLocal8Bit( 276 QString cpassword = QString::fromLocal8Bit(
277 crypt( password.mid(8).local8Bit(), salt ) ); 277 crypt( password.mid(8).local8Bit(), salt ) );
278#else 278#else
279 //### revise 279 //### revise
280 QString cpassword(""); 280 QString cpassword("");
281#endif 281#endif
282 denials=0; 282 denials=0;
283 pwds.prepend(cpassword); 283 pwds.prepend(cpassword);
284 cfg.writeEntry("Passwords",pwds,' '); 284 cfg.writeEntry("Passwords",pwds,' ');
285 lock--; 285 lock--;
286 return TRUE; 286 return TRUE;
287 } 287 }
288 } 288 }
289 lock--; 289 lock--;
290 290
291 return FALSE; 291 return FALSE;
292} 292}
293 293
294 294
295ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 295ServerPI::ServerPI( int socket, QObject *parent, const char* name )
296 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 296 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
297 storFileSize(-1) 297 storFileSize(-1)
298{ 298{
299 state = Connected; 299 state = Connected;
300 300
301 setSocket( socket ); 301 setSocket( socket );
302 302
303 peerport = peerPort(); 303 peerport = peerPort();
304 peeraddress = peerAddress(); 304 peeraddress = peerAddress();
305 305
306#ifndef INSECURE 306#ifndef INSECURE
307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 307 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
308 state = Forbidden; 308 state = Forbidden;
309 startTimer( 0 ); 309 startTimer( 0 );
310 } else 310 } else
311#endif 311#endif
312 { 312 {
313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 313 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 314 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
315 315
316 passiv = FALSE; 316 passiv = FALSE;
317 for( int i = 0; i < 4; i++ ) 317 for( int i = 0; i < 4; i++ )
318 wait[i] = FALSE; 318 wait[i] = FALSE;
319 319
320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 320 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
321 state = Wait_USER; 321 state = Wait_USER;
322 322
323 dtp = new ServerDTP( this ); 323 dtp = new ServerDTP( this );
324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 324 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 325 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); 326 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) );
327 327
328 328
329 directory = QDir::currentDirPath(); 329 directory = QDir::currentDirPath();
330 330
331 static int p = 1024; 331 static int p = 1024;
332 332
333 while ( !serversocket || !serversocket->ok() ) { 333 while ( !serversocket || !serversocket->ok() ) {
334 delete serversocket; 334 delete serversocket;
335 serversocket = new ServerSocket( ++p, this ); 335 serversocket = new ServerSocket( ++p, this );
336 } 336 }
337 connect( serversocket, SIGNAL( newIncomming(int) ), 337 connect( serversocket, SIGNAL( newIncomming(int) ),
338 SLOT( newConnection(int) ) ); 338 SLOT( newConnection(int) ) );
339 } 339 }
340} 340}
341 341
342ServerPI::~ServerPI() 342ServerPI::~ServerPI()
343{ 343{
344 close(); 344 close();
345 345
346 if ( dtp ) 346 if ( dtp )
347 dtp->close(); 347 dtp->close();
348 delete dtp; 348 delete dtp;
349 delete serversocket; 349 delete serversocket;
350} 350}
351 351
352bool ServerPI::verifyAuthorised() 352bool ServerPI::verifyAuthorised()
353{ 353{
354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 354 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
355 state = Forbidden; 355 state = Forbidden;
356 return FALSE; 356 return FALSE;
357 } 357 }
358 return TRUE; 358 return TRUE;
359} 359}
360 360
361void ServerPI::connectionClosed() 361void ServerPI::connectionClosed()
362{ 362{
363 // odebug << "Debug: Connection closed" << oendl; 363 // odebug << "Debug: Connection closed" << oendl;
364 emit connectionClosed(this); 364 emit connectionClosed(this);
365} 365}
366 366
367void ServerPI::send( const QString& msg ) 367void ServerPI::send( const QString& msg )
368{ 368{
369 QTextStream os( this ); 369 QTextStream os( this );
370 os << msg << endl; 370 os << msg << endl;
371 //odebug << "Reply: " << msg << "" << oendl; 371 //odebug << "Reply: " << msg << "" << oendl;
372} 372}
373 373
374void ServerPI::read() 374void ServerPI::read()
375{ 375{
376 while ( canReadLine() ) 376 while ( canReadLine() )
377 process( readLine().stripWhiteSpace() ); 377 process( readLine().stripWhiteSpace() );
378} 378}
379 379
380bool ServerPI::checkReadFile( const QString& file ) 380bool ServerPI::checkReadFile( const QString& file )
381{ 381{
382 QString filename; 382 QString filename;
383 383
384 if ( file[0] != "/" ) 384 if ( file[0] != "/" )
385 filename = directory.path() + "/" + file; 385 filename = directory.path() + "/" + file;
386 else 386 else
387 filename = file; 387 filename = file;
388 388
389 QFileInfo fi( filename ); 389 QFileInfo fi( filename );
390 return ( fi.exists() && fi.isReadable() ); 390 return ( fi.exists() && fi.isReadable() );
391} 391}
392 392
393bool ServerPI::checkWriteFile( const QString& file ) 393bool ServerPI::checkWriteFile( const QString& file )
394{ 394{
395 QString filename; 395 QString filename;
396 396
397 if ( file[0] != "/" ) 397 if ( file[0] != "/" )
398 filename = directory.path() + "/" + file; 398 filename = directory.path() + "/" + file;
399 else 399 else
400 filename = file; 400 filename = file;
401 401
402 QFileInfo fi( filename ); 402 QFileInfo fi( filename );
403 403
404 if ( fi.exists() ) 404 if ( fi.exists() )
405 if ( !QFile( filename ).remove() ) 405 if ( !QFile( filename ).remove() )
406 return FALSE; 406 return FALSE;
407 return TRUE; 407 return TRUE;
408} 408}
409 409
410void ServerPI::process( const QString& message ) 410void ServerPI::process( const QString& message )
411{ 411{
412 //odebug << "Command: " << message << "" << oendl; 412 //odebug << "Command: " << message << "" << oendl;
413 413
414 // split message using "," as separator 414 // split message using "," as separator
415 QStringList msg = QStringList::split( " ", message ); 415 QStringList msg = QStringList::split( " ", message );
416 if ( msg.isEmpty() ) return; 416 if ( msg.isEmpty() ) return;
417 417
418 // command token 418 // command token
419 QString cmd = msg[0].upper(); 419 QString cmd = msg[0].upper();
420 420
421 // argument token 421 // argument token
422 QString arg; 422 QString arg;
423 if ( msg.count() >= 2 ) 423 if ( msg.count() >= 2 )
424 arg = msg[1]; 424 arg = msg[1];
425 425
426 // full argument string 426 // full argument string
427 QString args; 427 QString args;
428 if ( msg.count() >= 2 ) { 428 if ( msg.count() >= 2 ) {
429 QStringList copy( msg ); 429 QStringList copy( msg );
430 // FIXME: for Qt3 430 // FIXME: for Qt3
431 // copy.pop_front() 431 // copy.pop_front()
432 copy.remove( copy.begin() ); 432 copy.remove( copy.begin() );
433 args = copy.join( " " ); 433 args = copy.join( " " );
434 } 434 }
435 435
436 //odebug << "args: " << args << "" << oendl; 436 //odebug << "args: " << args << "" << oendl;
437 437
438 // we always respond to QUIT, regardless of state 438 // we always respond to QUIT, regardless of state
439 if ( cmd == "QUIT" ) { 439 if ( cmd == "QUIT" ) {
440 send( "211 Good bye!" ); // No tr 440 send( "211 Good bye!" ); // No tr
441 close(); 441 close();
442 return; 442 return;
443 } 443 }
444 444
445 // connected to client 445 // connected to client
446 if ( Connected == state ) 446 if ( Connected == state )
447 return; 447 return;
448 448
449 // waiting for user name 449 // waiting for user name
450 if ( Wait_USER == state ) { 450 if ( Wait_USER == state ) {
451 451
452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 452 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
453 send( "530 Please login with USER and PASS" ); // No tr 453 send( "530 Please login with USER and PASS" ); // No tr
454 return; 454 return;
455 } 455 }
456 send( "331 User name ok, need password" ); // No tr 456 send( "331 User name ok, need password" ); // No tr
457 state = Wait_PASS; 457 state = Wait_PASS;
458 return; 458 return;
459 } 459 }
460 460
461 // waiting for password 461 // waiting for password
462 if ( Wait_PASS == state ) { 462 if ( Wait_PASS == state ) {
463 463
464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 464 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
465 send( "530 Please login with USER and PASS" ); // No tr 465 send( "530 Please login with USER and PASS" ); // No tr
466 return; 466 return;
467 } 467 }
468 send( "230 User logged in, proceed" ); // No tr 468 send( "230 User logged in, proceed" ); // No tr
469 state = Ready; 469 state = Ready;
470 return; 470 return;
471 } 471 }
472 472
473 // ACCESS CONTROL COMMANDS 473 // ACCESS CONTROL COMMANDS
474 474
475 // Only an ALLO sent immediately before STOR is valid. 475 // Only an ALLO sent immediately before STOR is valid.
476 if ( cmd != "STOR" ) 476 if ( cmd != "STOR" )
477 storFileSize = -1; 477 storFileSize = -1;
478 478
479 // account (ACCT) 479 // account (ACCT)
480 if ( cmd == "ACCT" ) { 480 if ( cmd == "ACCT" ) {
481 // even wu-ftp does not support it 481 // even wu-ftp does not support it
482 send( "502 Command not implemented" ); // No tr 482 send( "502 Command not implemented" ); // No tr
483 } 483 }
484 484
485 // change working directory (CWD) 485 // change working directory (CWD)
486 else if ( cmd == "CWD" ) { 486 else if ( cmd == "CWD" ) {
487 487
488 if ( !args.isEmpty() ) { 488 if ( !args.isEmpty() ) {
489 if ( directory.cd( args, TRUE ) ) 489 if ( directory.cd( args, TRUE ) )
490 send( "250 Requested file action okay, completed" ); // No tr 490 send( "250 Requested file action okay, completed" ); // No tr
491 else 491 else
492 send( "550 Requested action not taken" ); // No tr 492 send( "550 Requested action not taken" ); // No tr
493 } 493 }
494 else 494 else
495 send( "500 Syntax error, command unrecognized" ); // No tr 495 send( "500 Syntax error, command unrecognized" ); // No tr
496 } 496 }
497 497
498 // change to parent directory (CDUP) 498 // change to parent directory (CDUP)
499 else if ( cmd == "CDUP" ) { 499 else if ( cmd == "CDUP" ) {
500 if ( directory.cdUp() ) 500 if ( directory.cdUp() )
501 send( "250 Requested file action okay, completed" ); // No tr 501 send( "250 Requested file action okay, completed" ); // No tr
502 else 502 else
503 send( "550 Requested action not taken" ); // No tr 503 send( "550 Requested action not taken" ); // No tr
504 } 504 }
505 505
506 // structure mount (SMNT) 506 // structure mount (SMNT)
507 else if ( cmd == "SMNT" ) { 507 else if ( cmd == "SMNT" ) {
508 // even wu-ftp does not support it 508 // even wu-ftp does not support it
509 send( "502 Command not implemented" ); // No tr 509 send( "502 Command not implemented" ); // No tr
510 } 510 }
511 511
512 // reinitialize (REIN) 512 // reinitialize (REIN)
513 else if ( cmd == "REIN" ) { 513 else if ( cmd == "REIN" ) {
514 // even wu-ftp does not support it 514 // even wu-ftp does not support it
515 send( "502 Command not implemented" ); // No tr 515 send( "502 Command not implemented" ); // No tr
516 } 516 }
517 517
518 518
519 // TRANSFER PARAMETER COMMANDS 519 // TRANSFER PARAMETER COMMANDS
520 520
521 521
522 // data port (PORT) 522 // data port (PORT)
523 else if ( cmd == "PORT" ) { 523 else if ( cmd == "PORT" ) {
524 if ( parsePort( arg ) ) 524 if ( parsePort( arg ) )
525 send( "200 Command okay" ); // No tr 525 send( "200 Command okay" ); // No tr
526 else 526 else
527 send( "500 Syntax error, command unrecognized" ); // No tr 527 send( "500 Syntax error, command unrecognized" ); // No tr
528 } 528 }
529 529
530 // passive (PASV) 530 // passive (PASV)
531 else if ( cmd == "PASV" ) { 531 else if ( cmd == "PASV" ) {
532 passiv = TRUE; 532 passiv = TRUE;
533 send( "227 Entering Passive Mode (" // No tr 533 send( "227 Entering Passive Mode (" // No tr
534 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 534 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
535 + QString::number( ( serversocket->port() ) >> 8 ) + "," 535 + QString::number( ( serversocket->port() ) >> 8 ) + ","
536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 536 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
537 } 537 }
538 538
539 // representation type (TYPE) 539 // representation type (TYPE)
540 else if ( cmd == "TYPE" ) { 540 else if ( cmd == "TYPE" ) {
541 if ( arg.upper() == "A" || arg.upper() == "I" ) 541 if ( arg.upper() == "A" || arg.upper() == "I" )
542 send( "200 Command okay" ); // No tr 542 send( "200 Command okay" ); // No tr
543 else 543 else
544 send( "504 Command not implemented for that parameter" ); // No tr 544 send( "504 Command not implemented for that parameter" ); // No tr
545 } 545 }
546 546
547 // file structure (STRU) 547 // file structure (STRU)
548 else if ( cmd == "STRU" ) { 548 else if ( cmd == "STRU" ) {
549 if ( arg.upper() == "F" ) 549 if ( arg.upper() == "F" )
550 send( "200 Command okay" ); // No tr 550 send( "200 Command okay" ); // No tr
551 else 551 else
552 send( "504 Command not implemented for that parameter" ); // No tr 552 send( "504 Command not implemented for that parameter" ); // No tr
553 } 553 }
554 554
555 // transfer mode (MODE) 555 // transfer mode (MODE)
556 else if ( cmd == "MODE" ) { 556 else if ( cmd == "MODE" ) {
557 if ( arg.upper() == "S" ) 557 if ( arg.upper() == "S" )
558 send( "200 Command okay" ); // No tr 558 send( "200 Command okay" ); // No tr
559 else 559 else
560 send( "504 Command not implemented for that parameter" ); // No tr 560 send( "504 Command not implemented for that parameter" ); // No tr
561 } 561 }
562 562
563 563
564 // FTP SERVICE COMMANDS 564 // FTP SERVICE COMMANDS
565 565
566 566
567 // retrieve (RETR) 567 // retrieve (RETR)
568 else if ( cmd == "RETR" ) 568 else if ( cmd == "RETR" )
569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 569 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
570 || backupRestoreGzip( absFilePath( args ) ) ) { 570 || backupRestoreGzip( absFilePath( args ) ) ) {
571 send( "150 File status okay" ); // No tr 571 send( "150 File status okay" ); // No tr
572 sendFile( absFilePath( args ) ); 572 sendFile( absFilePath( args ) );
573 } 573 }
574 else { 574 else {
575 odebug << "550 Requested action not taken" << oendl; 575 odebug << "550 Requested action not taken" << oendl;
576 send( "550 Requested action not taken" ); // No tr 576 send( "550 Requested action not taken" ); // No tr
577 } 577 }
578 578
579 // store (STOR) 579 // store (STOR)
580 else if ( cmd == "STOR" ) 580 else if ( cmd == "STOR" )
581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 581 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
582 send( "150 File status okay" ); // No tr 582 send( "150 File status okay" ); // No tr
583 retrieveFile( absFilePath( args ) ); 583 retrieveFile( absFilePath( args ) );
584 } 584 }
585 else 585 else
586 send( "550 Requested action not taken" ); // No tr 586 send( "550 Requested action not taken" ); // No tr
587 587
588 // store unique (STOU) 588 // store unique (STOU)
589 else if ( cmd == "STOU" ) { 589 else if ( cmd == "STOU" ) {
590 send( "502 Command not implemented" ); // No tr 590 send( "502 Command not implemented" ); // No tr
591 } 591 }
592 592
593 // append (APPE) 593 // append (APPE)
594 else if ( cmd == "APPE" ) { 594 else if ( cmd == "APPE" ) {
595 send( "502 Command not implemented" ); // No tr 595 send( "502 Command not implemented" ); // No tr
596 } 596 }
597 597
598 // allocate (ALLO) 598 // allocate (ALLO)
599 else if ( cmd == "ALLO" ) { 599 else if ( cmd == "ALLO" ) {
600 storFileSize = args.toInt(); 600 storFileSize = args.toInt();
601 send( "200 Command okay" ); // No tr 601 send( "200 Command okay" ); // No tr
602 } 602 }
603 603
604 // restart (REST) 604 // restart (REST)
605 else if ( cmd == "REST" ) { 605 else if ( cmd == "REST" ) {
606 send( "502 Command not implemented" ); // No tr 606 send( "502 Command not implemented" ); // No tr
607 } 607 }
608 608
609 // rename from (RNFR) 609 // rename from (RNFR)
610 else if ( cmd == "RNFR" ) { 610 else if ( cmd == "RNFR" ) {
611 renameFrom = QString::null; 611 renameFrom = QString::null;
612 if ( args.isEmpty() ) 612 if ( args.isEmpty() )
613 send( "500 Syntax error, command unrecognized" ); // No tr 613 send( "500 Syntax error, command unrecognized" ); // No tr
614 else { 614 else {
615 QFile file( absFilePath( args ) ); 615 QFile file( absFilePath( args ) );
616 if ( file.exists() ) { 616 if ( file.exists() ) {
617 send( "350 File exists, ready for destination name" ); // No tr 617 send( "350 File exists, ready for destination name" ); // No tr
618 renameFrom = absFilePath( args ); 618 renameFrom = absFilePath( args );
619 } 619 }
620 else 620 else
621 send( "550 Requested action not taken" ); // No tr 621 send( "550 Requested action not taken" ); // No tr
622 } 622 }
623 } 623 }
624 624
625 // rename to (RNTO) 625 // rename to (RNTO)
626 else if ( cmd == "RNTO" ) { 626 else if ( cmd == "RNTO" ) {
627 if ( lastCommand != "RNFR" ) 627 if ( lastCommand != "RNFR" )
628 send( "503 Bad sequence of commands" ); // No tr 628 send( "503 Bad sequence of commands" ); // No tr
629 else if ( args.isEmpty() ) 629 else if ( args.isEmpty() )
630 send( "500 Syntax error, command unrecognized" ); // No tr 630 send( "500 Syntax error, command unrecognized" ); // No tr
631 else { 631 else {
632 QDir dir( absFilePath( args ) ); 632 QDir dir( absFilePath( args ) );
633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 633 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
634 send( "250 Requested file action okay, completed." ); // No tr 634 send( "250 Requested file action okay, completed." ); // No tr
635 else 635 else
636 send( "550 Requested action not taken" ); // No tr 636 send( "550 Requested action not taken" ); // No tr
637 } 637 }
638 } 638 }
639 639
640 // abort (ABOR) 640 // abort (ABOR)
641 else if ( cmd.contains( "ABOR" ) ) { 641 else if ( cmd.contains( "ABOR" ) ) {
642 dtp->close(); 642 dtp->close();
643 if ( dtp->dtpMode() != ServerDTP::Idle ) 643 if ( dtp->dtpMode() != ServerDTP::Idle )
644 send( "426 Connection closed; transfer aborted" ); // No tr 644 send( "426 Connection closed; transfer aborted" ); // No tr
645 else 645 else
646 send( "226 Closing data connection" ); // No tr 646 send( "226 Closing data connection" ); // No tr
647 } 647 }
648 648
649 // delete (DELE) 649 // delete (DELE)
650 else if ( cmd == "DELE" ) { 650 else if ( cmd == "DELE" ) {
651 if ( args.isEmpty() ) 651 if ( args.isEmpty() )
652 send( "500 Syntax error, command unrecognized" ); // No tr 652 send( "500 Syntax error, command unrecognized" ); // No tr
653 else { 653 else {
654 QFile file( absFilePath( args ) ) ; 654 QFile file( absFilePath( args ) ) ;
655 if ( file.remove() ) { 655 if ( file.remove() ) {
656 send( "250 Requested file action okay, completed" ); // No tr 656 send( "250 Requested file action okay, completed" ); // No tr
657 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 657 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
658 e << file.name(); 658 e << file.name();
659 } else { 659 } else {
660 send( "550 Requested action not taken" ); // No tr 660 send( "550 Requested action not taken" ); // No tr
661 } 661 }
662 } 662 }
663 } 663 }
664 664
665 // remove directory (RMD) 665 // remove directory (RMD)
666 else if ( cmd == "RMD" ) { 666 else if ( cmd == "RMD" ) {
667 if ( args.isEmpty() ) 667 if ( args.isEmpty() )
668 send( "500 Syntax error, command unrecognized" ); // No tr 668 send( "500 Syntax error, command unrecognized" ); // No tr
669 else { 669 else {
670 QDir dir; 670 QDir dir;
671 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 671 if ( dir.rmdir( absFilePath( args ), TRUE ) )
672 send( "250 Requested file action okay, completed" ); // No tr 672 send( "250 Requested file action okay, completed" ); // No tr
673 else 673 else
674 send( "550 Requested action not taken" ); // No tr 674 send( "550 Requested action not taken" ); // No tr
675 } 675 }
676 } 676 }
677 677
678 // make directory (MKD) 678 // make directory (MKD)
679 else if ( cmd == "MKD" ) { 679 else if ( cmd == "MKD" ) {
680 if ( args.isEmpty() ) { 680 if ( args.isEmpty() ) {
681 odebug << " Error: no arg" << oendl; 681 odebug << " Error: no arg" << oendl;
682 send( "500 Syntax error, command unrecognized" ); // No tr 682 send( "500 Syntax error, command unrecognized" ); // No tr
683 } 683 }
684 else { 684 else {
685 QDir dir; 685 QDir dir;
686 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 686 if ( dir.mkdir( absFilePath( args ), TRUE ) )
687 send( "250 Requested file action okay, completed." ); // No tr 687 send( "250 Requested file action okay, completed." ); // No tr
688 else 688 else
689 send( "550 Requested action not taken" ); // No tr 689 send( "550 Requested action not taken" ); // No tr
690 } 690 }
691 } 691 }
692 692
693 // print working directory (PWD) 693 // print working directory (PWD)
694 else if ( cmd == "PWD" ) { 694 else if ( cmd == "PWD" ) {
695 send( "257 \"" + directory.path() +"\"" ); 695 send( "257 \"" + directory.path() +"\"" );
696 } 696 }
697 697
698 // list (LIST) 698 // list (LIST)
699 else if ( cmd == "LIST" ) { 699 else if ( cmd == "LIST" ) {
700 if ( sendList( absFilePath( args ) ) ) 700 if ( sendList( absFilePath( args ) ) )
701 send( "150 File status okay" ); // No tr 701 send( "150 File status okay" ); // No tr
702 else 702 else
703 send( "500 Syntax error, command unrecognized" ); // No tr 703 send( "500 Syntax error, command unrecognized" ); // No tr
704 } 704 }
705 705
706 // size (SIZE) 706 // size (SIZE)
707 else if ( cmd == "SIZE" ) { 707 else if ( cmd == "SIZE" ) {
708 QString filePath = absFilePath( args ); 708 QString filePath = absFilePath( args );
709 QFileInfo fi( filePath ); 709 QFileInfo fi( filePath );
710 bool gzipfile = backupRestoreGzip( filePath ); 710 bool gzipfile = backupRestoreGzip( filePath );
711 if ( !fi.exists() && !gzipfile ) 711 if ( !fi.exists() && !gzipfile )
712 send( "500 Syntax error, command unrecognized" ); // No tr 712 send( "500 Syntax error, command unrecognized" ); // No tr
713 else { 713 else {
714 if ( !gzipfile ) 714 if ( !gzipfile )
715 send( "213 " + QString::number( fi.size() ) ); 715 send( "213 " + QString::number( fi.size() ) );
716 else { 716 else {
717 Process duproc( QString("du") ); 717 Process duproc( QString("du") );
718 duproc.addArgument("-s"); 718 duproc.addArgument("-s");
719 QString in, out; 719 QString in, out;
720 if ( !duproc.exec(in, out) ) { 720 if ( !duproc.exec(in, out) ) {
721 odebug << "du process failed; just sending back 1K" << oendl; 721 odebug << "du process failed; just sending back 1K" << oendl;
722 send( "213 1024"); 722 send( "213 1024");
723 } 723 }
724 else { 724 else {
725 QString size = out.left( out.find("\t") ); 725 QString size = out.left( out.find("\t") );
726 int guess = size.toInt()/5; 726 int guess = size.toInt()/5;
727 if ( filePath.contains("doc") ) // No tr 727 if ( filePath.contains("doc") ) // No tr
728 guess *= 1000; 728 guess *= 1000;
729 odebug << "sending back gzip guess of " << guess << "" << oendl; 729 odebug << "sending back gzip guess of " << guess << "" << oendl;
730 send( "213 " + QString::number(guess) ); 730 send( "213 " + QString::number(guess) );
731 } 731 }
732 } 732 }
733 } 733 }
734 } 734 }
735 // name list (NLST) 735 // name list (NLST)
736 else if ( cmd == "NLST" ) { 736 else if ( cmd == "NLST" ) {
737 send( "502 Command not implemented" ); // No tr 737 send( "502 Command not implemented" ); // No tr
738 } 738 }
739 739
740 // site parameters (SITE) 740 // site parameters (SITE)
741 else if ( cmd == "SITE" ) { 741 else if ( cmd == "SITE" ) {
742 send( "502 Command not implemented" ); // No tr 742 send( "502 Command not implemented" ); // No tr
743 } 743 }
744 744
745 // system (SYST) 745 // system (SYST)
746 else if ( cmd == "SYST" ) { 746 else if ( cmd == "SYST" ) {
747 send( "215 UNIX Type: L8" ); // No tr 747 send( "215 UNIX Type: L8" ); // No tr
748 } 748 }
749 749
750 // status (STAT) 750 // status (STAT)
751 else if ( cmd == "STAT" ) { 751 else if ( cmd == "STAT" ) {
752 send( "502 Command not implemented" ); // No tr 752 send( "502 Command not implemented" ); // No tr
753 } 753 }
754 754
755 // help (HELP ) 755 // help (HELP )
756 else if ( cmd == "HELP" ) { 756 else if ( cmd == "HELP" ) {
757 send( "502 Command not implemented" ); // No tr 757 send( "502 Command not implemented" ); // No tr
758 } 758 }
759 759
760 // noop (NOOP) 760 // noop (NOOP)
761 else if ( cmd == "NOOP" ) { 761 else if ( cmd == "NOOP" ) {
762 send( "200 Command okay" ); // No tr 762 send( "200 Command okay" ); // No tr
763 } 763 }
764 764
765 // not implemented 765 // not implemented
766 else 766 else
767 send( "502 Command not implemented" ); // No tr 767 send( "502 Command not implemented" ); // No tr
768 768
769 lastCommand = cmd; 769 lastCommand = cmd;
770} 770}
771 771
772bool ServerPI::backupRestoreGzip( const QString &file ) 772bool ServerPI::backupRestoreGzip( const QString &file )
773{ 773{
774 return (file.find( "backup" ) != -1 && // No tr 774 return (file.find( "backup" ) != -1 && // No tr
775 file.findRev( ".tgz" ) == (int)file.length()-4 ); 775 file.findRev( ".tgz" ) == (int)file.length()-4 );
776} 776}
777 777
778bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 778bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
779{ 779{
780 if ( file.find( "backup" ) != -1 && // No tr 780 if ( file.find( "backup" ) != -1 && // No tr
781 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 781 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
782 QFileInfo info( file ); 782 QFileInfo info( file );
783 targets = info.dirPath( TRUE ); 783 targets = info.dirPath( TRUE );
784 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl; 784 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl;
785 return true; 785 return true;
786 } 786 }
787 return false; 787 return false;
788} 788}
789 789
790void ServerPI::sendFile( const QString& file ) 790void ServerPI::sendFile( const QString& file )
791{ 791{
792 if ( passiv ) { 792 if ( passiv ) {
793 wait[SendFile] = TRUE; 793 wait[SendFile] = TRUE;
794 waitfile = file; 794 waitfile = file;
795 if ( waitsocket ) 795 if ( waitsocket )
796 newConnection( waitsocket ); 796 newConnection( waitsocket );
797 } 797 }
798 else { 798 else {
799 QStringList targets; 799 QStringList targets;
800 if ( backupRestoreGzip( file, targets ) ) 800 if ( backupRestoreGzip( file, targets ) )
801 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 801 dtp->sendGzipFile( file, targets, peeraddress, peerport );
802 else dtp->sendFile( file, peeraddress, peerport ); 802 else dtp->sendFile( file, peeraddress, peerport );
803 } 803 }
804} 804}
805 805
806void ServerPI::retrieveFile( const QString& file ) 806void ServerPI::retrieveFile( const QString& file )
807{ 807{
808 if ( passiv ) { 808 if ( passiv ) {
809 wait[RetrieveFile] = TRUE; 809 wait[RetrieveFile] = TRUE;
810 waitfile = file; 810 waitfile = file;
811 if ( waitsocket ) 811 if ( waitsocket )
812 newConnection( waitsocket ); 812 newConnection( waitsocket );
813 } 813 }
814 else { 814 else {
815 QStringList targets; 815 QStringList targets;
816 if ( backupRestoreGzip( file, targets ) ) 816 if ( backupRestoreGzip( file, targets ) )
817 dtp->retrieveGzipFile( file, peeraddress, peerport ); 817 dtp->retrieveGzipFile( file, peeraddress, peerport );
818 else 818 else
819 dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); 819 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
820 } 820 }
821} 821}
822 822
823bool ServerPI::parsePort( const QString& pp ) 823bool ServerPI::parsePort( const QString& pp )
824{ 824{
825 QStringList p = QStringList::split( ",", pp ); 825 QStringList p = QStringList::split( ",", pp );
826 if ( p.count() != 6 ) return FALSE; 826 if ( p.count() != 6 ) return FALSE;
827 827
828 // h1,h2,h3,h4,p1,p2 828 // h1,h2,h3,h4,p1,p2
829 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 829 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
830 ( p[2].toInt() << 8 ) + p[3].toInt() ); 830 ( p[2].toInt() << 8 ) + p[3].toInt() );
831 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 831 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
832 return TRUE; 832 return TRUE;
833} 833}
834 834
835void ServerPI::dtpCompleted() 835void ServerPI::dtpCompleted()
836{ 836{
837 send( "226 Closing data connection, file transfer successful" ); // No tr 837 send( "226 Closing data connection, file transfer successful" ); // No tr
838 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 838 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
839 QString fn = dtp->fileName(); 839 QString fn = dtp->fileName();
840 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 840 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
841 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 841 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
842 e << fn; 842 e << fn;
843 } 843 }
844 } 844 }
845 waitsocket = 0; 845 waitsocket = 0;
846 dtp->close(); 846 dtp->close();
847 storFileSize = -1; 847 storFileSize = -1;
848} 848}
849 849
850void ServerPI::dtpFailed() 850void ServerPI::dtpFailed()
851{ 851{
852 dtp->close(); 852 dtp->close();
853 waitsocket = 0; 853 waitsocket = 0;
854 send( "451 Requested action aborted: local error in processing" ); // No tr 854 send( "451 Requested action aborted: local error in processing" ); // No tr
855 storFileSize = -1; 855 storFileSize = -1;
856} 856}
857 857
858void ServerPI::dtpError( int ) 858void ServerPI::dtpError( int )
859{ 859{
860 dtp->close(); 860 dtp->close();
861 waitsocket = 0; 861 waitsocket = 0;
862 send( "451 Requested action aborted: local error in processing" ); // No tr 862 send( "451 Requested action aborted: local error in processing" ); // No tr
863 storFileSize = -1; 863 storFileSize = -1;
864} 864}
865 865
866bool ServerPI::sendList( const QString& arg ) 866bool ServerPI::sendList( const QString& arg )
867{ 867{
868 QByteArray listing; 868 QByteArray listing;
869 QBuffer buffer( listing ); 869 QBuffer buffer( listing );
870 870
871 if ( !buffer.open( IO_WriteOnly ) ) 871 if ( !buffer.open( IO_WriteOnly ) )
872 return FALSE; 872 return FALSE;
873 873
874 QTextStream ts( &buffer ); 874 QTextStream ts( &buffer );
875 QString fn = arg; 875 QString fn = arg;
876 876
877 if ( fn.isEmpty() ) 877 if ( fn.isEmpty() )
878 fn = directory.path(); 878 fn = directory.path();
879 879
880 QFileInfo fi( fn ); 880 QFileInfo fi( fn );
881 if ( !fi.exists() ) return FALSE; 881 if ( !fi.exists() ) return FALSE;
882 882
883 // return file listing 883 // return file listing
884 if ( fi.isFile() ) { 884 if ( fi.isFile() ) {
885 ts << fileListing( &fi ) << endl; 885 ts << fileListing( &fi ) << endl;
886 } 886 }
887 887
888 // return directory listing 888 // return directory listing
889 else if ( fi.isDir() ) { 889 else if ( fi.isDir() ) {
890 QDir dir( fn ); 890 QDir dir( fn );
891 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 891 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
892 892
893 QFileInfoListIterator it( *list ); 893 QFileInfoListIterator it( *list );
894 QFileInfo *info; 894 QFileInfo *info;
895 895
896 unsigned long total = 0; 896 unsigned long total = 0;
897 while ( ( info = it.current() ) ) { 897 while ( ( info = it.current() ) ) {
898 if ( info->fileName() != "." && info->fileName() != ".." ) 898 if ( info->fileName() != "." && info->fileName() != ".." )
899 total += info->size(); 899 total += info->size();
900 ++it; 900 ++it;
901 } 901 }
902 902
903 ts << "total " << QString::number( total / 1024 ) << endl; // No tr 903 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
904 904
905 it.toFirst(); 905 it.toFirst();
906 while ( ( info = it.current() ) ) { 906 while ( ( info = it.current() ) ) {
907 if ( info->fileName() == "." || info->fileName() == ".." ) { 907 if ( info->fileName() == "." || info->fileName() == ".." ) {
908 ++it; 908 ++it;
909 continue; 909 continue;
910 } 910 }
911 ts << fileListing( info ) << endl; 911 ts << fileListing( info ) << endl;
912 ++it; 912 ++it;
913 } 913 }
914 } 914 }
915 915
916 if ( passiv ) { 916 if ( passiv ) {
917 waitarray = buffer.buffer(); 917 waitarray = buffer.buffer();
918 wait[SendByteArray] = TRUE; 918 wait[SendByteArray] = TRUE;
919 if ( waitsocket ) 919 if ( waitsocket )
920 newConnection( waitsocket ); 920 newConnection( waitsocket );
921 } 921 }
922 else 922 else
923 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 923 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
924 return TRUE; 924 return TRUE;
925} 925}
926 926
927QString ServerPI::fileListing( QFileInfo *info ) 927QString ServerPI::fileListing( QFileInfo *info )
928{ 928{
929 if ( !info ) return QString::null; 929 if ( !info ) return QString::null;
930 QString s; 930 QString s;
931 931
932 // type char 932 // type char
933 if ( info->isDir() ) 933 if ( info->isDir() )
934 s += "d"; 934 s += "d";
935 else if ( info->isSymLink() ) 935 else if ( info->isSymLink() )
936 s += "l"; 936 s += "l";
937 else 937 else
938 s += "-"; 938 s += "-";
939 939
940 // permisson string 940 // permisson string
941 s += permissionString( info ) + " "; 941 s += permissionString( info ) + " ";
942 942
943 // number of hardlinks 943 // number of hardlinks
944 int subdirs = 1; 944 int subdirs = 1;
945 945
946 if ( info->isDir() ) 946 if ( info->isDir() )
947 subdirs = 2; 947 subdirs = 2;
948 // FIXME : this is to slow 948 // FIXME : this is to slow
949 //if ( info->isDir() ) 949 //if ( info->isDir() )
950 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 950 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
951 951
952 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 952 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
953 953
954 // owner 954 // owner
955 QString o = info->owner(); 955 QString o = info->owner();
956 if ( o.isEmpty() ) 956 if ( o.isEmpty() )
957 o = QString::number(info->ownerId()); 957 o = QString::number(info->ownerId());
958 s += o.leftJustify( 8, ' ', TRUE ) + " "; 958 s += o.leftJustify( 8, ' ', TRUE ) + " ";
959 959
960 // group 960 // group
961 QString g = info->group(); 961 QString g = info->group();
962 if ( g.isEmpty() ) 962 if ( g.isEmpty() )
963 g = QString::number(info->groupId()); 963 g = QString::number(info->groupId());
964 s += g.leftJustify( 8, ' ', TRUE ) + " "; 964 s += g.leftJustify( 8, ' ', TRUE ) + " ";
965 965
966 // file size in bytes 966 // file size in bytes
967 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 967 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
968 968
969 // last modified date 969 // last modified date
970 QDate date = info->lastModified().date(); 970 QDate date = info->lastModified().date();
971 QTime time = info->lastModified().time(); 971 QTime time = info->lastModified().time();
972 s += date.monthName( date.month() ) + " " 972 s += date.monthName( date.month() ) + " "
973 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 973 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
974 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 974 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
975 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 975 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
976 976
977 // file name 977 // file name
978 s += info->fileName(); 978 s += info->fileName();
979 979
980 return s; 980 return s;
981} 981}
982 982
983QString ServerPI::permissionString( QFileInfo *info ) 983QString ServerPI::permissionString( QFileInfo *info )
984{ 984{
985 if ( !info ) return QString( "---------" ); 985 if ( !info ) return QString( "---------" );
986 QString s; 986 QString s;
987 987
988 // user 988 // user
989 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 989 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
990 else s += "-"; 990 else s += "-";
991 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 991 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
992 else s += "-"; 992 else s += "-";
993 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 993 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
994 else s += "-"; 994 else s += "-";
995 995
996 // group 996 // group
997 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 997 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
998 else s += "-"; 998 else s += "-";
999 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 999 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
1000 else s += "-"; 1000 else s += "-";
1001 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 1001 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
1002 else s += "-"; 1002 else s += "-";
1003 1003
1004 // exec 1004 // exec
1005 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 1005 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
1006 else s += "-"; 1006 else s += "-";
1007 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 1007 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
1008 else s += "-"; 1008 else s += "-";
1009 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 1009 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
1010 else s += "-"; 1010 else s += "-";
1011 1011
1012 return s; 1012 return s;
1013} 1013}
1014 1014
1015void ServerPI::newConnection( int socket ) 1015void ServerPI::newConnection( int socket )
1016{ 1016{
1017 //odebug << "New incomming connection" << oendl; 1017 //odebug << "New incomming connection" << oendl;
1018 1018
1019 if ( !passiv ) return; 1019 if ( !passiv ) return;
1020 1020
1021 if ( wait[SendFile] ) { 1021 if ( wait[SendFile] ) {
1022 QStringList targets; 1022 QStringList targets;
1023 if ( backupRestoreGzip( waitfile, targets ) ) 1023 if ( backupRestoreGzip( waitfile, targets ) )
1024 dtp->sendGzipFile( waitfile, targets ); 1024 dtp->sendGzipFile( waitfile, targets );
1025 else 1025 else
1026 dtp->sendFile( waitfile ); 1026 dtp->sendFile( waitfile );
1027 dtp->setSocket( socket ); 1027 dtp->setSocket( socket );
1028 } 1028 }
1029 else if ( wait[RetrieveFile] ) { 1029 else if ( wait[RetrieveFile] ) {
1030 odebug << "check retrieve file" << oendl; 1030 odebug << "check retrieve file" << oendl;
1031 if ( backupRestoreGzip( waitfile ) ) 1031 if ( backupRestoreGzip( waitfile ) )
1032 dtp->retrieveGzipFile( waitfile ); 1032 dtp->retrieveGzipFile( waitfile );
1033 else 1033 else
1034 dtp->retrieveFile( waitfile, storFileSize ); 1034 dtp->retrieveFile( waitfile, storFileSize );
1035 dtp->setSocket( socket ); 1035 dtp->setSocket( socket );
1036 } 1036 }
1037 else if ( wait[SendByteArray] ) { 1037 else if ( wait[SendByteArray] ) {
1038 dtp->sendByteArray( waitarray ); 1038 dtp->sendByteArray( waitarray );
1039 dtp->setSocket( socket ); 1039 dtp->setSocket( socket );
1040 } 1040 }
1041 else if ( wait[RetrieveByteArray] ) { 1041 else if ( wait[RetrieveByteArray] ) {
1042 odebug << "retrieve byte array" << oendl; 1042 odebug << "retrieve byte array" << oendl;
1043 dtp->retrieveByteArray(); 1043 dtp->retrieveByteArray();
1044 dtp->setSocket( socket ); 1044 dtp->setSocket( socket );
1045 } 1045 }
1046 else 1046 else
1047 waitsocket = socket; 1047 waitsocket = socket;
1048 1048
1049 for( int i = 0; i < 4; i++ ) 1049 for( int i = 0; i < 4; i++ )
1050 wait[i] = FALSE; 1050 wait[i] = FALSE;
1051} 1051}
1052 1052
1053QString ServerPI::absFilePath( const QString& file ) 1053QString ServerPI::absFilePath( const QString& file )
1054{ 1054{
1055 if ( file.isEmpty() ) return file; 1055 if ( file.isEmpty() ) return file;
1056 1056
1057 QString filepath( file ); 1057 QString filepath( file );
1058 if ( file[0] != "/" ) 1058 if ( file[0] != "/" )
1059 filepath = directory.path() + "/" + file; 1059 filepath = directory.path() + "/" + file;
1060 1060
1061 return filepath; 1061 return filepath;
1062} 1062}
1063 1063
1064 1064
1065void ServerPI::timerEvent( QTimerEvent * ) 1065void ServerPI::timerEvent( QTimerEvent * )
1066{ 1066{
1067 connectionClosed(); 1067 connectionClosed();
1068} 1068}
1069 1069
1070 1070
1071ServerDTP::ServerDTP( QObject *parent, const char* name) 1071ServerDTP::ServerDTP( QObject *parent, const char* name)
1072 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1072 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1073 retrieveTargzProc( 0 ) 1073 retrieveTargzProc( 0 )
1074{ 1074{
1075 1075
1076 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1076 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1077 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1077 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1078 connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); 1078 connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) );
1079 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1079 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1080 1080
1081 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr 1081 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
1082 createTargzProc->setCommunication( QProcess::Stdout ); 1082 createTargzProc->setCommunication( QProcess::Stdout );
1083 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1083 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1084 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1084 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1085 1085
1086 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); 1086 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1087 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1087 retrieveTargzProc->setCommunication( QProcess::Stdin );
1088 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1088 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1089 connect( retrieveTargzProc, SIGNAL( processExited() ), 1089 connect( retrieveTargzProc, SIGNAL( processExited() ),
1090 SIGNAL( completed() ) ); 1090 SIGNAL( completed() ) );
1091 connect( retrieveTargzProc, SIGNAL( processExited() ), 1091 connect( retrieveTargzProc, SIGNAL( processExited() ),
1092 SLOT( extractTarDone() ) ); 1092 SLOT( extractTarDone() ) );
1093} 1093}
1094 1094
1095ServerDTP::~ServerDTP() 1095ServerDTP::~ServerDTP()
1096{ 1096{
1097 buf.close(); 1097 buf.close();
1098 if ( RetrieveFile == mode && file.isOpen() ) { 1098 if ( RetrieveFile == mode && file.isOpen() ) {
1099 // We're being shutdown before the client closed. 1099 // We're being shutdown before the client closed.
1100 file.close(); 1100 file.close();
1101 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1101 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1102 odebug << "STOR incomplete" << oendl; 1102 odebug << "STOR incomplete" << oendl;
1103 file.remove(); 1103 file.remove();
1104 } 1104 }
1105 } else { 1105 } else {
1106 file.close(); 1106 file.close();
1107 } 1107 }
1108 createTargzProc->kill(); 1108 createTargzProc->kill();
1109} 1109}
1110 1110
1111void ServerDTP::extractTarDone() 1111void ServerDTP::extractTarDone()
1112{ 1112{
1113 odebug << "extract done" << oendl; 1113 odebug << "extract done" << oendl;
1114#ifndef QT_NO_COP 1114#ifndef QT_NO_COP
1115 QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); 1115 QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
1116 e << file.name(); 1116 e << file.name();
1117#endif 1117#endif
1118} 1118}
1119 1119
1120void ServerDTP::connected() 1120void ServerDTP::connected()
1121{ 1121{
1122 // send file mode 1122 // send file mode
1123 switch ( mode ) { 1123 switch ( mode ) {
1124 case SendFile : 1124 case SendFile :
1125 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1125 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1126 emit failed(); 1126 emit failed();
1127 mode = Idle; 1127 mode = Idle;
1128 return; 1128 return;
1129 } 1129 }
1130 1130
1131 //odebug << "Debug: Sending file '" << file.name() << "'" << oendl; 1131 //odebug << "Debug: Sending file '" << file.name() << "'" << oendl;
1132 1132
1133 bytes_written = 0; 1133 bytes_written = 0;
1134 if ( file.size() == 0 ) { 1134 if ( file.size() == 0 ) {
1135 //make sure it doesn't hang on empty files 1135 //make sure it doesn't hang on empty files
1136 file.close(); 1136 file.close();
1137 emit completed(); 1137 emit completed();
1138 mode = Idle; 1138 mode = Idle;
1139 } else { 1139 } else {
1140 // Don't write more if there is plenty buffered already. 1140 // Don't write more if there is plenty buffered already.
1141 if ( bytesToWrite() <= block_size && !file.atEnd() ) { 1141 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1142 QCString s; 1142 QCString s;
1143 s.resize( block_size ); 1143 s.resize( block_size );
1144 int bytes = file.readBlock( s.data(), block_size ); 1144 int bytes = file.readBlock( s.data(), block_size );
1145 writeBlock( s.data(), bytes ); 1145 writeBlock( s.data(), bytes );
1146 } 1146 }
1147 } 1147 }
1148 break; 1148 break;
1149 case SendGzipFile: 1149 case SendGzipFile:
1150 if ( createTargzProc->isRunning() ) { 1150 if ( createTargzProc->isRunning() ) {
1151 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1151 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1152 owarn << "Previous tar --gzip process is still running; killing it..." << oendl; 1152 owarn << "Previous tar --gzip process is still running; killing it..." << oendl;
1153 createTargzProc->kill(); 1153 createTargzProc->kill();
1154 } 1154 }
1155 1155
1156 bytes_written = 0; 1156 bytes_written = 0;
1157 odebug << "==>start send tar process" << oendl; 1157 odebug << "==>start send tar process" << oendl;
1158 if ( !createTargzProc->start() ) 1158 if ( !createTargzProc->start() )
1159 qWarning("Error starting %s", 1159 owarn << "Error starting " << createTargzProc->arguments().join(" ").latin1() << oendl;
1160 createTargzProc->arguments().join(" ").latin1());
1161 break; 1160 break;
1162 case SendBuffer: 1161 case SendBuffer:
1163 if ( !buf.open( IO_ReadOnly) ) { 1162 if ( !buf.open( IO_ReadOnly) ) {
1164 emit failed(); 1163 emit failed();
1165 mode = Idle; 1164 mode = Idle;
1166 return; 1165 return;
1167 } 1166 }
1168 1167
1169 // odebug << "Debug: Sending byte array" << oendl; 1168 // odebug << "Debug: Sending byte array" << oendl;
1170 bytes_written = 0; 1169 bytes_written = 0;
1171 while( !buf.atEnd() ) 1170 while( !buf.atEnd() )
1172 putch( buf.getch() ); 1171 putch( buf.getch() );
1173 buf.close(); 1172 buf.close();
1174 break; 1173 break;
1175 case RetrieveFile: 1174 case RetrieveFile:
1176 // retrieve file mode 1175 // retrieve file mode
1177 if ( file.exists() && !file.remove() ) { 1176 if ( file.exists() && !file.remove() ) {
1178 emit failed(); 1177 emit failed();
1179 mode = Idle; 1178 mode = Idle;
1180 return; 1179 return;
1181 } 1180 }
1182 1181
1183 if ( !file.open( IO_WriteOnly) ) { 1182 if ( !file.open( IO_WriteOnly) ) {
1184 emit failed(); 1183 emit failed();
1185 mode = Idle; 1184 mode = Idle;
1186 return; 1185 return;
1187 } 1186 }
1188 // odebug << "Debug: Retrieving file " << file.name() << "" << oendl; 1187 // odebug << "Debug: Retrieving file " << file.name() << "" << oendl;
1189 break; 1188 break;
1190 case RetrieveGzipFile: 1189 case RetrieveGzipFile:
1191 odebug << "=-> starting tar process to receive .tgz file" << oendl; 1190 odebug << "=-> starting tar process to receive .tgz file" << oendl;
1192 break; 1191 break;
1193 case RetrieveBuffer: 1192 case RetrieveBuffer:
1194 // retrieve buffer mode 1193 // retrieve buffer mode
1195 if ( !buf.open( IO_WriteOnly) ) { 1194 if ( !buf.open( IO_WriteOnly) ) {
1196 emit failed(); 1195 emit failed();
1197 mode = Idle; 1196 mode = Idle;
1198 return; 1197 return;
1199 } 1198 }
1200 // odebug << "Debug: Retrieving byte array" << oendl; 1199 // odebug << "Debug: Retrieving byte array" << oendl;
1201 break; 1200 break;
1202 case Idle: 1201 case Idle:
1203 odebug << "connection established but mode set to Idle; BUG!" << oendl; 1202 odebug << "connection established but mode set to Idle; BUG!" << oendl;
1204 break; 1203 break;
1205 } 1204 }
1206} 1205}
1207 1206
1208void ServerDTP::connectionClosed() 1207void ServerDTP::connectionClosed()
1209{ 1208{
1210 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; 1209 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl;
1211 1210
1212 // send file mode 1211 // send file mode
1213 if ( SendFile == mode ) { 1212 if ( SendFile == mode ) {
1214 if ( bytes_written == file.size() ) 1213 if ( bytes_written == file.size() )
1215 emit completed(); 1214 emit completed();
1216 else 1215 else
1217 emit failed(); 1216 emit failed();
1218 } 1217 }
1219 1218
1220 // send buffer mode 1219 // send buffer mode
1221 else if ( SendBuffer == mode ) { 1220 else if ( SendBuffer == mode ) {
1222 if ( bytes_written == buf.size() ) 1221 if ( bytes_written == buf.size() )
1223 emit completed(); 1222 emit completed();
1224 else 1223 else
1225 emit failed(); 1224 emit failed();
1226 } 1225 }
1227 1226
1228 // retrieve file mode 1227 // retrieve file mode
1229 else if ( RetrieveFile == mode ) { 1228 else if ( RetrieveFile == mode ) {
1230 file.close(); 1229 file.close();
1231 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1230 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1232 odebug << "STOR incomplete" << oendl; 1231 odebug << "STOR incomplete" << oendl;
1233 file.remove(); 1232 file.remove();
1234 emit failed(); 1233 emit failed();
1235 } else { 1234 } else {
1236 emit completed(); 1235 emit completed();
1237 } 1236 }
1238 } 1237 }
1239 1238
1240 else if ( RetrieveGzipFile == mode ) { 1239 else if ( RetrieveGzipFile == mode ) {
1241 odebug << "Done writing ungzip file; closing input" << oendl; 1240 odebug << "Done writing ungzip file; closing input" << oendl;
1242 retrieveTargzProc->flushStdin(); 1241 retrieveTargzProc->flushStdin();
1243 retrieveTargzProc->closeStdin(); 1242 retrieveTargzProc->closeStdin();
1244 } 1243 }
1245 1244
1246 // retrieve buffer mode 1245 // retrieve buffer mode
1247 else if ( RetrieveBuffer == mode ) { 1246 else if ( RetrieveBuffer == mode ) {
1248 buf.close(); 1247 buf.close();
1249 emit completed(); 1248 emit completed();
1250 } 1249 }
1251 1250
1252 mode = Idle; 1251 mode = Idle;
1253} 1252}
1254 1253
1255void ServerDTP::bytesWritten( int bytes ) 1254void ServerDTP::bytesWritten( int bytes )
1256{ 1255{
1257 bytes_written += bytes; 1256 bytes_written += bytes;
1258 1257
1259 // send file mode 1258 // send file mode
1260 if ( SendFile == mode ) { 1259 if ( SendFile == mode ) {
1261 1260
1262 if ( bytes_written == file.size() ) { 1261 if ( bytes_written == file.size() ) {
1263 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; 1262 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl;
1264 file.close(); 1263 file.close();
1265 emit completed(); 1264 emit completed();
1266 mode = Idle; 1265 mode = Idle;
1267 } 1266 }
1268 else if( !file.atEnd() ) { 1267 else if( !file.atEnd() ) {
1269 QCString s; 1268 QCString s;
1270 s.resize( block_size ); 1269 s.resize( block_size );
1271 int bytes = file.readBlock( s.data(), block_size ); 1270 int bytes = file.readBlock( s.data(), block_size );
1272 writeBlock( s.data(), bytes ); 1271 writeBlock( s.data(), bytes );
1273 } 1272 }
1274 } 1273 }
1275 1274
1276 // send buffer mode 1275 // send buffer mode
1277 if ( SendBuffer == mode ) { 1276 if ( SendBuffer == mode ) {
1278 1277
1279 if ( bytes_written == buf.size() ) { 1278 if ( bytes_written == buf.size() ) {
1280 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; 1279 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl;
1281 emit completed(); 1280 emit completed();
1282 mode = Idle; 1281 mode = Idle;
1283 } 1282 }
1284 } 1283 }
1285} 1284}
1286 1285
1287void ServerDTP::readyRead() 1286void ServerDTP::readyRead()
1288{ 1287{
1289 // retrieve file mode 1288 // retrieve file mode
1290 if ( RetrieveFile == mode ) { 1289 if ( RetrieveFile == mode ) {
1291 QCString s; 1290 QCString s;
1292 s.resize( bytesAvailable() ); 1291 s.resize( bytesAvailable() );
1293 readBlock( s.data(), bytesAvailable() ); 1292 readBlock( s.data(), bytesAvailable() );
1294 file.writeBlock( s.data(), s.size() ); 1293 file.writeBlock( s.data(), s.size() );
1295 } 1294 }
1296 else if ( RetrieveGzipFile == mode ) { 1295 else if ( RetrieveGzipFile == mode ) {
1297 if ( !retrieveTargzProc->isRunning() ) 1296 if ( !retrieveTargzProc->isRunning() )
1298 retrieveTargzProc->start(); 1297 retrieveTargzProc->start();
1299 1298
1300 QByteArray s; 1299 QByteArray s;
1301 s.resize( bytesAvailable() ); 1300 s.resize( bytesAvailable() );
1302 readBlock( s.data(), bytesAvailable() ); 1301 readBlock( s.data(), bytesAvailable() );
1303 retrieveTargzProc->writeToStdin( s ); 1302 retrieveTargzProc->writeToStdin( s );
1304 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; 1303 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl;
1305 } 1304 }
1306 // retrieve buffer mode 1305 // retrieve buffer mode
1307 else if ( RetrieveBuffer == mode ) { 1306 else if ( RetrieveBuffer == mode ) {
1308 QCString s; 1307 QCString s;
1309 s.resize( bytesAvailable() ); 1308 s.resize( bytesAvailable() );
1310 readBlock( s.data(), bytesAvailable() ); 1309 readBlock( s.data(), bytesAvailable() );
1311 buf.writeBlock( s.data(), s.size() ); 1310 buf.writeBlock( s.data(), s.size() );
1312 } 1311 }
1313} 1312}
1314 1313
1315void ServerDTP::writeTargzBlock() 1314void ServerDTP::writeTargzBlock()
1316{ 1315{
1317 QByteArray block = createTargzProc->readStdout(); 1316 QByteArray block = createTargzProc->readStdout();
1318 writeBlock( block.data(), block.size() ); 1317 writeBlock( block.data(), block.size() );
1319 odebug << "writeTargzBlock " << block.size() << "" << oendl; 1318 odebug << "writeTargzBlock " << block.size() << "" << oendl;
1320} 1319}
1321 1320
1322void ServerDTP::targzDone() 1321void ServerDTP::targzDone()
1323{ 1322{
1324 odebug << "tar and gzip done" << oendl; 1323 odebug << "tar and gzip done" << oendl;
1325 emit completed(); 1324 emit completed();
1326 mode = Idle; 1325 mode = Idle;
1327 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1326 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1328 this, SLOT( writeTargzBlock() ) ); 1327 this, SLOT( writeTargzBlock() ) );
1329} 1328}
1330 1329
1331void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1330void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1332{ 1331{
1333 file.setName( fn ); 1332 file.setName( fn );
1334 mode = SendFile; 1333 mode = SendFile;
1335 connectToHost( host.toString(), port ); 1334 connectToHost( host.toString(), port );
1336} 1335}
1337 1336
1338void ServerDTP::sendFile( const QString fn ) 1337void ServerDTP::sendFile( const QString fn )
1339{ 1338{
1340 file.setName( fn ); 1339 file.setName( fn );
1341 mode = SendFile; 1340 mode = SendFile;
1342} 1341}
1343 1342
1344void ServerDTP::sendGzipFile( const QString &fn, 1343void ServerDTP::sendGzipFile( const QString &fn,
1345 const QStringList &archiveTargets, 1344 const QStringList &archiveTargets,
1346 const QHostAddress& host, Q_UINT16 port ) 1345 const QHostAddress& host, Q_UINT16 port )
1347{ 1346{
1348 sendGzipFile( fn, archiveTargets ); 1347 sendGzipFile( fn, archiveTargets );
1349 connectToHost( host.toString(), port ); 1348 connectToHost( host.toString(), port );
1350} 1349}
1351 1350
1352void ServerDTP::sendGzipFile( const QString &fn, 1351void ServerDTP::sendGzipFile( const QString &fn,
1353 const QStringList &archiveTargets ) 1352 const QStringList &archiveTargets )
1354{ 1353{
1355 mode = SendGzipFile; 1354 mode = SendGzipFile;
1356 file.setName( fn ); 1355 file.setName( fn );
1357 1356
1358 QStringList args = "targzip"; 1357 QStringList args = "targzip";
1359 //args += "-cv"; 1358 //args += "-cv";
1360 args += archiveTargets; 1359 args += archiveTargets;
1361 odebug << "sendGzipFile " << args.join(" ") << "" << oendl; 1360 odebug << "sendGzipFile " << args.join(" ") << "" << oendl;
1362 createTargzProc->setArguments( args ); 1361 createTargzProc->setArguments( args );
1363 connect( createTargzProc, 1362 connect( createTargzProc,
1364 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); 1363 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1365} 1364}
1366 1365
1367void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) 1366void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
1368{ 1367{
1369 recvFileSize = fileSize; 1368 recvFileSize = fileSize;
1370 file.setName( fn ); 1369 file.setName( fn );
1371 mode = RetrieveFile; 1370 mode = RetrieveFile;
1372 connectToHost( host.toString(), port ); 1371 connectToHost( host.toString(), port );
1373} 1372}
1374 1373
1375void ServerDTP::retrieveFile( const QString fn, int fileSize ) 1374void ServerDTP::retrieveFile( const QString fn, int fileSize )
1376{ 1375{
1377 recvFileSize = fileSize; 1376 recvFileSize = fileSize;
1378 file.setName( fn ); 1377 file.setName( fn );
1379 mode = RetrieveFile; 1378 mode = RetrieveFile;
1380} 1379}
1381 1380
1382void ServerDTP::retrieveGzipFile( const QString &fn ) 1381void ServerDTP::retrieveGzipFile( const QString &fn )
1383{ 1382{
1384 odebug << "retrieveGzipFile " << fn << "" << oendl; 1383 odebug << "retrieveGzipFile " << fn << "" << oendl;
1385 file.setName( fn ); 1384 file.setName( fn );
1386 mode = RetrieveGzipFile; 1385 mode = RetrieveGzipFile;
1387 1386
1388 retrieveTargzProc->setArguments( "targunzip" ); 1387 retrieveTargzProc->setArguments( "targunzip" );
1389 connect( retrieveTargzProc, SIGNAL( processExited() ), 1388 connect( retrieveTargzProc, SIGNAL( processExited() ),
1390 SLOT( extractTarDone() ) ); 1389 SLOT( extractTarDone() ) );
1391} 1390}
1392 1391
1393void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1392void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1394{ 1393{
1395 retrieveGzipFile( fn ); 1394 retrieveGzipFile( fn );
1396 connectToHost( host.toString(), port ); 1395 connectToHost( host.toString(), port );
1397} 1396}
1398 1397
1399void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1398void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1400{ 1399{
1401 buf.setBuffer( array ); 1400 buf.setBuffer( array );
1402 mode = SendBuffer; 1401 mode = SendBuffer;
1403 connectToHost( host.toString(), port ); 1402 connectToHost( host.toString(), port );
1404} 1403}
1405 1404
1406void ServerDTP::sendByteArray( const QByteArray& array ) 1405void ServerDTP::sendByteArray( const QByteArray& array )
1407{ 1406{
1408 buf.setBuffer( array ); 1407 buf.setBuffer( array );
1409 mode = SendBuffer; 1408 mode = SendBuffer;
1410} 1409}
1411 1410
1412void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1411void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1413{ 1412{
1414 buf.setBuffer( QByteArray() ); 1413 buf.setBuffer( QByteArray() );
1415 mode = RetrieveBuffer; 1414 mode = RetrieveBuffer;
1416 connectToHost( host.toString(), port ); 1415 connectToHost( host.toString(), port );
1417} 1416}
1418 1417
1419void ServerDTP::retrieveByteArray() 1418void ServerDTP::retrieveByteArray()
1420{ 1419{
1421 buf.setBuffer( QByteArray() ); 1420 buf.setBuffer( QByteArray() );
1422 mode = RetrieveBuffer; 1421 mode = RetrieveBuffer;
1423} 1422}
1424 1423
1425void ServerDTP::setSocket( int socket ) 1424void ServerDTP::setSocket( int socket )
1426{ 1425{
1427 QSocket::setSocket( socket ); 1426 QSocket::setSocket( socket );
1428 connected(); 1427 connected();
1429} 1428}
1430 1429
diff --git a/core/obex/obex.cc b/core/obex/obex.cc
index 3c99af6..7c40b90 100644
--- a/core/obex/obex.cc
+++ b/core/obex/obex.cc
@@ -1,200 +1,205 @@
1 1
2#include "obex.h"
3
4/* OPIE */
5#include <opie2/oprocess.h>
6#include <opie2/odebug.h>
7
8/* QT */
2#include <qfileinfo.h> 9#include <qfileinfo.h>
3 10
4 11
5#include <opie2/oprocess.h>
6#include "obex.h"
7 12
8using namespace OpieObex; 13using namespace OpieObex;
9 14
10using namespace Opie::Core; 15using namespace Opie::Core;
11/* TRANSLATOR OpieObex::Obex */ 16/* TRANSLATOR OpieObex::Obex */
12 17
13Obex::Obex( QObject *parent, const char* name ) 18Obex::Obex( QObject *parent, const char* name )
14 : QObject(parent, name ) 19 : QObject(parent, name )
15{ 20{
16 m_rec = 0; 21 m_rec = 0;
17 m_send=0; 22 m_send=0;
18 m_count = 0; 23 m_count = 0;
19 m_receive = false; 24 m_receive = false;
20 connect( this, SIGNAL(error(int) ), // for recovering to receive 25 connect( this, SIGNAL(error(int) ), // for recovering to receive
21 SLOT(slotError() ) ); 26 SLOT(slotError() ) );
22 connect( this, SIGNAL(sent(bool) ), 27 connect( this, SIGNAL(sent(bool) ),
23 SLOT(slotError() ) ); 28 SLOT(slotError() ) );
24}; 29};
25Obex::~Obex() { 30Obex::~Obex() {
26 delete m_rec; 31 delete m_rec;
27 delete m_send; 32 delete m_send;
28} 33}
29void Obex::receive() { 34void Obex::receive() {
30 m_receive = true; 35 m_receive = true;
31 m_outp = QString::null; 36 m_outp = QString::null;
32 qWarning("Receive" ); 37 owarn << "Receive" << oendl;
33 m_rec = new OProcess(); 38 m_rec = new OProcess();
34 *m_rec << "irobex_palm3"; 39 *m_rec << "irobex_palm3";
35 // connect to the necessary slots 40 // connect to the necessary slots
36 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 41 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
37 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 42 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
38 43
39 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 44 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
40 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 45 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
41 46
42 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 47 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
43 qWarning("could not start :("); 48 owarn << "could not start :(" oendl;
44 emit done( false ); 49 emit done( false );
45 delete m_rec; 50 delete m_rec;
46 m_rec = 0; 51 m_rec = 0;
47 } 52 }
48// emit currentTry(m_count ); 53// emit currentTry(m_count );
49 54
50} 55}
51void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 56void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
52 m_count = 0; 57 m_count = 0;
53 m_file = fileName; 58 m_file = fileName;
54 qWarning("send %s", fileName.latin1() ); 59 owarn << "send " << fileName.latin1() << oendl;
55 if (m_rec != 0 ) { 60 if (m_rec != 0 ) {
56 qWarning("running"); 61 owarn << "running" oendl;
57 if (m_rec->isRunning() ) { 62 if (m_rec->isRunning() ) {
58 emit error(-1 ); 63 emit error(-1 );
59 qWarning("is running"); 64 owarn << "is running" << oendl;
60 delete m_rec; 65 delete m_rec;
61 m_rec = 0; 66 m_rec = 0;
62 67
63 }else{ 68 }else{
64 qWarning("is not running"); 69 owarn << "is not running" << oendl;
65 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 70 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
66 return; 71 return;
67 } 72 }
68 } 73 }
69 sendNow(); 74 sendNow();
70} 75}
71void Obex::sendNow(){ 76void Obex::sendNow(){
72 qWarning("sendNow"); 77 owarn << "sendNow" << oendl;
73 if ( m_count >= 25 ) { // could not send 78 if ( m_count >= 25 ) { // could not send
74 emit error(-1 ); 79 emit error(-1 );
75 emit sent(false); 80 emit sent(false);
76 return; 81 return;
77 } 82 }
78 // OProcess inititialisation 83 // OProcess inititialisation
79 m_send = new OProcess(); 84 m_send = new OProcess();
80 *m_send << "irobex_palm3"; 85 *m_send << "irobex_palm3";
81 *m_send << QFile::encodeName(m_file); 86 *m_send << QFile::encodeName(m_file);
82 87
83 // connect to slots Exited and and StdOut 88 // connect to slots Exited and and StdOut
84 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), 89 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ),
85 this, SLOT(slotExited(Opie::Core::OProcess*)) ); 90 this, SLOT(slotExited(Opie::Core::OProcess*)) );
86 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), 91 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )),
87 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 92 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
88 93
89 // now start it 94 // now start it
90 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 95 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
91 qWarning("could not send" ); 96 owarn << "could not send" << oendl;
92 m_count = 25; 97 m_count = 25;
93 emit error(-1 ); 98 emit error(-1 );
94 delete m_send; 99 delete m_send;
95 m_send=0; 100 m_send=0;
96 } 101 }
97 // end 102 // end
98 m_count++; 103 m_count++;
99 emit currentTry( m_count ); 104 emit currentTry( m_count );
100} 105}
101 106
102void Obex::slotExited(OProcess* proc ){ 107void Obex::slotExited(OProcess* proc ){
103 if (proc == m_rec ) { // receive process 108 if (proc == m_rec ) { // receive process
104 received(); 109 received();
105 }else if ( proc == m_send ) { 110 }else if ( proc == m_send ) {
106 sendEnd(); 111 sendEnd();
107 } 112 }
108} 113}
109void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 114void Obex::slotStdOut(OProcess* proc, char* buf, int len){
110 if ( proc == m_rec ) { // only receive 115 if ( proc == m_rec ) { // only receive
111 QByteArray ar( len ); 116 QByteArray ar( len );
112 memcpy( ar.data(), buf, len ); 117 memcpy( ar.data(), buf, len );
113 qWarning("parsed: %s", ar.data() ); 118 owarn << "parsed: " << ar.data() << oendl;
114 m_outp.append( ar ); 119 m_outp.append( ar );
115 } 120 }
116} 121}
117 122
118void Obex::received() { 123void Obex::received() {
119 if (m_rec->normalExit() ) { 124 if (m_rec->normalExit() ) {
120 if ( m_rec->exitStatus() == 0 ) { // we got one 125 if ( m_rec->exitStatus() == 0 ) { // we got one
121 QString filename = parseOut(); 126 QString filename = parseOut();
122 qWarning("ACHTUNG %s", filename.latin1() ); 127 owarn << "ACHTUNG " << filename.latin1() << oendl;
123 emit receivedFile( filename ); 128 emit receivedFile( filename );
124 } 129 }
125 }else{ 130 }else{
126 emit done(false); 131 emit done(false);
127 }; 132 };
128 delete m_rec; 133 delete m_rec;
129 m_rec = 0; 134 m_rec = 0;
130 receive(); 135 receive();
131} 136}
132 137
133void Obex::sendEnd() { 138void Obex::sendEnd() {
134 if (m_send->normalExit() ) { 139 if (m_send->normalExit() ) {
135 if ( m_send->exitStatus() == 0 ) { 140 if ( m_send->exitStatus() == 0 ) {
136 delete m_send; 141 delete m_send;
137 m_send=0; 142 m_send=0;
138 qWarning("done" ); 143 owarn << "done" << oendl;
139 emit sent(true); 144 emit sent(true);
140 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 145 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
141 // let's try it again 146 // let's try it again
142 delete m_send; 147 delete m_send;
143 m_send = 0; 148 m_send = 0;
144 qWarning("try sending again" ); 149 owarn << "try sending again" << oendl;
145 sendNow(); 150 sendNow();
146 } 151 }
147 }else { 152 }else {
148 emit error( -1 ); 153 emit error( -1 );
149 delete m_send; 154 delete m_send;
150 m_send = 0; 155 m_send = 0;
151 } 156 }
152} 157}
153QString Obex::parseOut( ){ 158QString Obex::parseOut( ){
154 QString path; 159 QString path;
155 QStringList list = QStringList::split("\n", m_outp); 160 QStringList list = QStringList::split("\n", m_outp);
156 QStringList::Iterator it; 161 QStringList::Iterator it;
157 for (it = list.begin(); it != list.end(); ++it ) { 162 for (it = list.begin(); it != list.end(); ++it ) {
158 if ( (*it).startsWith("Wrote" ) ) { 163 if ( (*it).startsWith("Wrote" ) ) {
159 int pos = (*it).findRev('(' ); 164 int pos = (*it).findRev('(' );
160 if ( pos > 0 ) { 165 if ( pos > 0 ) {
161 qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ; 166 owarn << pos << " " << (*it).mid(6 ).latin1() << oendl;
162 qWarning("%d %d", (*it).length(), (*it).length()-pos ); 167 owarn << (*it).length() << " " << (*it).length()-pos << oendl;
163 168
164 path = (*it).remove( pos, (*it).length() - pos ); 169 path = (*it).remove( pos, (*it).length() - pos );
165 qWarning("%s", path.latin1() ); 170 owarn << path.latin1() << oendl;
166 path = path.mid(6 ); 171 path = path.mid(6 );
167 path = path.stripWhiteSpace(); 172 path = path.stripWhiteSpace();
168 qWarning("path %s", path.latin1() ); 173 owarn << "path " << path.latin1() << oendl;
169 } 174 }
170 } 175 }
171 } 176 }
172 return path; 177 return path;
173} 178}
174/** 179/**
175 * when sent is done slotError is called we will start receive again 180 * when sent is done slotError is called we will start receive again
176 */ 181 */
177void Obex::slotError() { 182void Obex::slotError() {
178 qWarning("slotError"); 183 owarn << "slotError" << oendl;
179 if ( m_receive ) 184 if ( m_receive )
180 receive(); 185 receive();
181}; 186};
182void Obex::setReceiveEnabled( bool receive ) { 187void Obex::setReceiveEnabled( bool receive ) {
183 if ( !receive ) { // 188 if ( !receive ) { //
184 m_receive = false; 189 m_receive = false;
185 shutDownReceive(); 190 shutDownReceive();
186 } 191 }
187} 192}
188 193
189void Obex::shutDownReceive() { 194void Obex::shutDownReceive() {
190 if (m_rec != 0 ) { 195 if (m_rec != 0 ) {
191 qWarning("running"); 196 owarn << "running" << oendl;
192 if (m_rec->isRunning() ) { 197 if (m_rec->isRunning() ) {
193 emit error(-1 ); 198 emit error(-1 );
194 qWarning("is running"); 199 owarn << "is running" << oendl;
195 delete m_rec; 200 delete m_rec;
196 m_rec = 0; 201 m_rec = 0;
197 } 202 }
198 } 203 }
199 204
200} 205}
diff --git a/core/opie-login/loginapplication.cpp b/core/opie-login/loginapplication.cpp
index 1facf2d..764b24b 100644
--- a/core/opie-login/loginapplication.cpp
+++ b/core/opie-login/loginapplication.cpp
@@ -1,281 +1,288 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can 5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that 12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details. 17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .: 18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU 19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file; 20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the 21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc., 22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27 27
28#include "loginapplication.h"
29
30/* OPIE */
31#include <opie2/odebug.h>
32
33/* QT */
34
35/* STD */
28#include <pwd.h> 36#include <pwd.h>
29#include <grp.h> 37#include <grp.h>
30#include <unistd.h> 38#include <unistd.h>
31#include <stdlib.h> 39#include <stdlib.h>
32#include <signal.h> 40#include <signal.h>
33#include <sys/stat.h> 41#include <sys/stat.h>
34#include <sys/wait.h> 42#include <sys/wait.h>
35 43
36#ifdef USEPAM 44#ifdef USEPAM
37extern "C" { 45extern "C" {
38#include <security/pam_appl.h> 46#include <security/pam_appl.h>
39} 47}
40#else 48#else
41#include <crypt.h> 49#include <crypt.h>
42#include <shadow.h> 50#include <shadow.h>
43#endif 51#endif
44 52
45#include "loginapplication.h"
46 53
47LoginApplication *lApp; 54LoginApplication *lApp;
48 55
49LoginApplication::LoginApplication ( int &argc, char **argv, pid_t parentpid ) 56LoginApplication::LoginApplication ( int &argc, char **argv, pid_t parentpid )
50 : QPEApplication ( argc, argv, GuiServer ) 57 : QPEApplication ( argc, argv, GuiServer )
51{ 58{
52 lApp = this; 59 lApp = this;
53 m_parentpid = parentpid; 60 m_parentpid = parentpid;
54} 61}
55 62
56const char *LoginApplication::s_username = 0; 63const char *LoginApplication::s_username = 0;
57 64
58#ifdef USEPAM 65#ifdef USEPAM
59 66
60const char *LoginApplication::s_pam_password = 0; 67const char *LoginApplication::s_pam_password = 0;
61 68
62int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ) 69int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * )
63{ 70{
64 int replies = 0; 71 int replies = 0;
65 struct pam_response *reply = 0; 72 struct pam_response *reply = 0;
66 int size = sizeof( struct pam_response ); 73 int size = sizeof( struct pam_response );
67 74
68 for ( int i = 0; i < num_msg; i++ ) { 75 for ( int i = 0; i < num_msg; i++ ) {
69 switch ( msg [i]-> msg_style ) { 76 switch ( msg [i]-> msg_style ) {
70 case PAM_PROMPT_ECHO_ON: // user name given to PAM already 77 case PAM_PROMPT_ECHO_ON: // user name given to PAM already
71 return PAM_CONV_ERR; 78 return PAM_CONV_ERR;
72 79
73 case PAM_PROMPT_ECHO_OFF: // wants password 80 case PAM_PROMPT_ECHO_OFF: // wants password
74 reply = (struct pam_response *) ::realloc ( reply, size ); 81 reply = (struct pam_response *) ::realloc ( reply, size );
75 if ( !reply ) 82 if ( !reply )
76 return PAM_CONV_ERR; 83 return PAM_CONV_ERR;
77 size += sizeof( struct pam_response ); 84 size += sizeof( struct pam_response );
78 85
79 reply [replies]. resp_retcode = PAM_SUCCESS; 86 reply [replies]. resp_retcode = PAM_SUCCESS;
80 reply [replies]. resp = ::strdup ( s_pam_password ); 87 reply [replies]. resp = ::strdup ( s_pam_password );
81 replies++; // PAM frees resp 88 replies++; // PAM frees resp
82 break; 89 break;
83 90
84 case PAM_TEXT_INFO: 91 case PAM_TEXT_INFO:
85 break; 92 break;
86 93
87 default: 94 default:
88 /* unknown or PAM_ERROR_MSG */ 95 /* unknown or PAM_ERROR_MSG */
89 if ( reply ) 96 if ( reply )
90 ::free ( reply ); 97 ::free ( reply );
91 return PAM_CONV_ERR; 98 return PAM_CONV_ERR;
92 } 99 }
93 } 100 }
94 if ( reply ) 101 if ( reply )
95 *resp = reply; 102 *resp = reply;
96 return PAM_SUCCESS; 103 return PAM_SUCCESS;
97} 104}
98 105
99 106
100bool LoginApplication::checkPassword ( const char *user, const char *pass ) 107bool LoginApplication::checkPassword ( const char *user, const char *pass )
101{ 108{
102 static struct pam_conv conv = { &LoginApplication::pam_helper, 0 }; 109 static struct pam_conv conv = { &LoginApplication::pam_helper, 0 };
103 110
104 int pam_error; 111 int pam_error;
105 pam_handle_t *pamh = 0; 112 pam_handle_t *pamh = 0;
106 113
107 pam_error = ::pam_start( "xdm", user, &conv, &pamh ); 114 pam_error = ::pam_start( "xdm", user, &conv, &pamh );
108 if ( pam_error == PAM_SUCCESS ) { 115 if ( pam_error == PAM_SUCCESS ) {
109 s_pam_password = pass; 116 s_pam_password = pass;
110 pam_error = ::pam_authenticate ( pamh, 0 ); 117 pam_error = ::pam_authenticate ( pamh, 0 );
111 s_pam_password = 0; 118 s_pam_password = 0;
112 } 119 }
113 ::pam_end ( pamh, pam_error ); 120 ::pam_end ( pamh, pam_error );
114 return ( pam_error == PAM_SUCCESS ); 121 return ( pam_error == PAM_SUCCESS );
115} 122}
116 123
117#else 124#else
118 125
119bool LoginApplication::checkPassword ( const char *user, const char *pass ) 126bool LoginApplication::checkPassword ( const char *user, const char *pass )
120{ 127{
121 char *encrypted, *correct; 128 char *encrypted, *correct;
122 struct passwd *pw; 129 struct passwd *pw;
123 130
124 if ( !user || !pass ) 131 if ( !user || !pass )
125 return false; 132 return false;
126 133
127 pw = ::getpwnam ( user ); 134 pw = ::getpwnam ( user );
128 135
129 if ( !pw ) 136 if ( !pw )
130 return false; 137 return false;
131 138
132 if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) { 139 if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
133 struct spwd *sp = ::getspnam ( pw-> pw_name ); 140 struct spwd *sp = ::getspnam ( pw-> pw_name );
134 141
135 if ( !sp ) 142 if ( !sp )
136 return false; 143 return false;
137 144
138 correct = sp-> sp_pwdp; 145 correct = sp-> sp_pwdp;
139 } 146 }
140 else 147 else
141 correct = pw-> pw_passwd; 148 correct = pw-> pw_passwd;
142 149
143 if ( correct == 0 || correct[0] == '\0' ) 150 if ( correct == 0 || correct[0] == '\0' )
144 return true; 151 return true;
145 152
146 encrypted = ::crypt ( pass, correct ); 153 encrypted = ::crypt ( pass, correct );
147 return ( ::strcmp ( encrypted, correct ) == 0 ); 154 return ( ::strcmp ( encrypted, correct ) == 0 );
148} 155}
149 156
150#endif 157#endif
151 158
152bool LoginApplication::changeIdentity ( ) 159bool LoginApplication::changeIdentity ( )
153{ 160{
154 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; 161 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
155 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; 162 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
156 163
157 if ( !s_username ) 164 if ( !s_username )
158 return false; 165 return false;
159 struct passwd *pw = ::getpwnam ( s_username ); 166 struct passwd *pw = ::getpwnam ( s_username );
160 if ( !pw ) 167 if ( !pw )
161 return false; 168 return false;
162 169
163 // we are still root at this point - try to run the pre-session script 170 // we are still root at this point - try to run the pre-session script
164 if ( !runRootScript ( "OPIEDIR", "share/opie-login/pre-session", s_username )) 171 if ( !runRootScript ( "OPIEDIR", "share/opie-login/pre-session", s_username ))
165 qWarning ( "failed to run $OPIEDIR/share/opie-login/pre-session" ); 172 owarn << "failed to run $OPIEDIR/share/opie-login/pre-session" << oendl;
166 173
167 bool fail = false; 174 bool fail = false;
168 fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); 175 fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid ));
169 ::endgrent ( ); 176 ::endgrent ( );
170 fail |= ( ::setgid ( pw-> pw_gid )); 177 fail |= ( ::setgid ( pw-> pw_gid ));
171 fail |= ( ::setuid ( pw-> pw_uid )); 178 fail |= ( ::setuid ( pw-> pw_uid ));
172 179
173 fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" )); 180 fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" ));
174 181
175 fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 )); 182 fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 ));
176 fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 )); 183 fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 ));
177 fail |= ( ::setenv ( "USER", pw-> pw_name, 1 )); 184 fail |= ( ::setenv ( "USER", pw-> pw_name, 1 ));
178 fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 )); 185 fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 ));
179 fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); 186 fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
180 187
181 return !fail; 188 return !fail;
182} 189}
183 190
184bool LoginApplication::login ( ) 191bool LoginApplication::login ( )
185{ 192{
186 execUserScript ( "HOME", ".opie-session" ); 193 execUserScript ( "HOME", ".opie-session" );
187 execUserScript ( "OPIEDIR", "share/opie-login/opie-session" ); 194 execUserScript ( "OPIEDIR", "share/opie-login/opie-session" );
188 execUserScript ( "OPIEDIR", "bin/qpe" ); 195 execUserScript ( "OPIEDIR", "bin/qpe" );
189 196
190 qWarning ( "failed to start an Opie session" ); 197 owarn << "failed to start an Opie session" << oendl;
191 return false; 198 return false;
192} 199}
193 200
194void LoginApplication::logout ( ) 201void LoginApplication::logout ( )
195{ 202{
196 // we are now root again - try to run the post-session script 203 // we are now root again - try to run the post-session script
197 if ( !runRootScript ( "OPIEDIR", "share/opie-login/post-session" )) 204 if ( !runRootScript ( "OPIEDIR", "share/opie-login/post-session" ))
198 qWarning ( "failed to run $OPIEDIR/scripts/post-session" ); 205 owarn << "failed to run $OPIEDIR/scripts/post-session" << oendl;
199} 206}
200 207
201 208
202static char *buildarg ( const char *base, const char *script ) 209static char *buildarg ( const char *base, const char *script )
203{ 210{
204 const char *dir = base ? ::getenv ( base ) : "/"; 211 const char *dir = base ? ::getenv ( base ) : "/";
205 char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2]; 212 char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2];
206 213
207 ::strcpy ( arg, dir ); 214 ::strcpy ( arg, dir );
208 ::strcat ( arg, "/" ); 215 ::strcat ( arg, "/" );
209 ::strcat ( arg, script ); 216 ::strcat ( arg, script );
210 217
211 return arg; 218 return arg;
212} 219}
213 220
214bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param ) 221bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param )
215{ 222{
216 bool res = false; 223 bool res = false;
217 char *arg = buildarg ( base, script ); 224 char *arg = buildarg ( base, script );
218 225
219 struct stat st; 226 struct stat st;
220 if (( ::stat ( arg, &st ) == 0 ) && ( st. st_uid == 0 )) { 227 if (( ::stat ( arg, &st ) == 0 ) && ( st. st_uid == 0 )) {
221 pid_t child = ::fork ( ); 228 pid_t child = ::fork ( );
222 229
223 if ( child == 0 ) { 230 if ( child == 0 ) {
224 ::execl ( "/bin/sh", "-sh", arg, param, 0 ); 231 ::execl ( "/bin/sh", "-sh", arg, param, 0 );
225 ::_exit ( -1 ); 232 ::_exit ( -1 );
226 } 233 }
227 else if ( child > 0 ) { 234 else if ( child > 0 ) {
228 int status = 0; 235 int status = 0;
229 236
230 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 237 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
231 res = ( WIFEXITED( status )) && ( WEXITSTATUS( status ) == 0 ); 238 res = ( WIFEXITED( status )) && ( WEXITSTATUS( status ) == 0 );
232 } 239 }
233 } 240 }
234 241
235 delete [] arg; 242 delete [] arg;
236 return res; 243 return res;
237} 244}
238 245
239void LoginApplication::execUserScript ( const char *base, const char *script ) 246void LoginApplication::execUserScript ( const char *base, const char *script )
240{ 247{
241 char *arg = buildarg ( base, script ); 248 char *arg = buildarg ( base, script );
242 249
243 struct stat st; 250 struct stat st;
244 if ( ::stat ( arg, &st ) == 0 ) { 251 if ( ::stat ( arg, &st ) == 0 ) {
245 if ( st. st_mode & S_IXUSR ) 252 if ( st. st_mode & S_IXUSR )
246 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); 253 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 );
247 else 254 else
248 ::execl ( "/bin/sh", "-sh", arg, 0 ); 255 ::execl ( "/bin/sh", "-sh", arg, 0 );
249 } 256 }
250} 257}
251 258
252const char *LoginApplication::loginAs ( ) 259const char *LoginApplication::loginAs ( )
253{ 260{
254 return s_username; 261 return s_username;
255} 262}
256 263
257void LoginApplication::setLoginAs ( const char *name ) 264void LoginApplication::setLoginAs ( const char *name )
258{ 265{
259 s_username = name; 266 s_username = name;
260} 267}
261 268
262QStringList LoginApplication::allUsers ( ) 269QStringList LoginApplication::allUsers ( )
263{ 270{
264 struct passwd *pwd; 271 struct passwd *pwd;
265 QStringList sl; 272 QStringList sl;
266 273
267 while (( pwd = ::getpwent ( ))) { 274 while (( pwd = ::getpwent ( ))) {
268 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) 275 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
269 sl << QString ( pwd-> pw_name ); 276 sl << QString ( pwd-> pw_name );
270 } 277 }
271 278
272 ::endpwent ( ); 279 ::endpwent ( );
273 280
274 return sl; 281 return sl;
275} 282}
276 283
277void LoginApplication::quitToConsole ( ) 284void LoginApplication::quitToConsole ( )
278{ 285{
279 QPEApplication::quit ( ); 286 QPEApplication::quit ( );
280 ::kill ( m_parentpid, SIGTERM ); 287 ::kill ( m_parentpid, SIGTERM );
281} 288}
diff --git a/core/pim/addressbook/namelineedit.cpp b/core/pim/addressbook/namelineedit.cpp
index ba16e2c..81b959b 100644
--- a/core/pim/addressbook/namelineedit.cpp
+++ b/core/pim/addressbook/namelineedit.cpp
@@ -1,55 +1,59 @@
1#include "namelineedit.h" 1#include "namelineedit.h"
2 2
3/* OPIE */
4#include <opie2/odebug.h>
5
6
3namespace ABOOK { 7namespace ABOOK {
4NameLineEdit::NameLineEdit( QWidget* parent, const char* name ) 8NameLineEdit::NameLineEdit( QWidget* parent, const char* name )
5 : QLineEdit( parent, name ), m_prevSpace( true ) { 9 : QLineEdit( parent, name ), m_prevSpace( true ) {
6} 10}
7 11
8NameLineEdit::NameLineEdit( const QString& str, QWidget* par, 12NameLineEdit::NameLineEdit( const QString& str, QWidget* par,
9 const char* name ) 13 const char* name )
10 : QLineEdit( str, par, name ),m_prevSpace( true ) { 14 : QLineEdit( str, par, name ),m_prevSpace( true ) {
11} 15}
12 16
13NameLineEdit::~NameLineEdit() { 17NameLineEdit::~NameLineEdit() {
14} 18}
15 19
16void NameLineEdit::keyPressEvent( QKeyEvent* ev ) { 20void NameLineEdit::keyPressEvent( QKeyEvent* ev ) {
17 QString t = ev->text(); 21 QString t = ev->text();
18 int key = ev->key(); 22 int key = ev->key();
19 int ascii = ev->ascii(); 23 int ascii = ev->ascii();
20 24
21 // ### FIXME with composed events 25 // ### FIXME with composed events
22 if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) && 26 if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) &&
23 key != Key_Delete && key != Key_Backspace && 27 key != Key_Delete && key != Key_Backspace &&
24 key != Key_Return && key != Key_Enter ) { 28 key != Key_Return && key != Key_Enter ) {
25 qWarning( "str " + ev->text() + " %d", m_prevSpace ); 29 owarn << "str " << ev->text() << " " << m_prevSpace << oendl;
26 30
27 if ( m_prevSpace ) { 31 if ( m_prevSpace ) {
28 t = t.upper(); 32 t = t.upper();
29 m_prevSpace = false; 33 m_prevSpace = false;
30 } 34 }
31 if ( key == Key_Space ) 35 if ( key == Key_Space )
32 m_prevSpace = true; 36 m_prevSpace = true;
33 37
34 38
35 QKeyEvent nEv(ev->type(), key, ascii, ev->state(), 39 QKeyEvent nEv(ev->type(), key, ascii, ev->state(),
36 t, ev->isAutoRepeat(), ev->count() ); 40 t, ev->isAutoRepeat(), ev->count() );
37 QLineEdit::keyPressEvent( &nEv ); 41 QLineEdit::keyPressEvent( &nEv );
38 if ( !nEv.isAccepted() ) 42 if ( !nEv.isAccepted() )
39 ev->ignore(); 43 ev->ignore();
40 }else { 44 }else {
41 QLineEdit::keyPressEvent( ev ); 45 QLineEdit::keyPressEvent( ev );
42 /* if key was a backspace lets see if we should 46 /* if key was a backspace lets see if we should
43 * capitalize the next letter 47 * capitalize the next letter
44 */ 48 */
45 if ( key == Key_Backspace ) { 49 if ( key == Key_Backspace ) {
46 QString te = text(); 50 QString te = text();
47 /* if string is empty capitalize the first letter */ 51 /* if string is empty capitalize the first letter */
48 /* else see if we're at the end of the string */ 52 /* else see if we're at the end of the string */
49 if ( te.isEmpty() || cursorPosition() == te.length() ) 53 if ( te.isEmpty() || cursorPosition() == te.length() )
50 m_prevSpace = true; 54 m_prevSpace = true;
51 } 55 }
52 } 56 }
53} 57}
54 58
55} 59}
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp
index 777c384..7bf6719 100644
--- a/core/qws/transferserver.cpp
+++ b/core/qws/transferserver.cpp
@@ -1,1440 +1,1440 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23 23
24/* STD */
24#define _XOPEN_SOURCE 25#define _XOPEN_SOURCE
25#include <pwd.h> 26#include <pwd.h>
26#include <sys/types.h> 27#include <sys/types.h>
27#include <unistd.h> 28#include <unistd.h>
28#include <stdlib.h> 29#include <stdlib.h>
29#include <time.h> 30#include <time.h>
30 31
31#ifndef Q_OS_MACX 32#ifndef Q_OS_MACX
32#include <shadow.h> 33#include <shadow.h>
33#endif /* Q_OS_MACX */ 34#endif /* Q_OS_MACX */
34 35
35/* we need the _OS_LINUX stuff first ! */ 36/* we need the _OS_LINUX stuff first ! */
36 37
37#ifndef _OS_LINUX_ 38#ifndef _OS_LINUX_
38// Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found 39// Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found
39// anywhere ? Therfore I removed it completely.. 40// anywhere ? Therfore I removed it completely..
40// I think it should be made permanentyl !? (eilers) 41// I think it should be made permanentyl !? (eilers)
41#warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)" 42#warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)"
42#if 0 43#if 0
43 44
44extern "C" 45extern "C"
45{ 46{
46#include <uuid/uuid.h> 47#include <uuid/uuid.h>
47#define UUID_H_INCLUDED 48#define UUID_H_INCLUDED
48} 49}
49 50
50#endif 51#endif
51 52
52#endif // not defined linux 53#endif // not defined linux
53 54
54#if defined(_OS_LINUX_) 55#if defined(_OS_LINUX_)
55#include <shadow.h> 56#include <shadow.h>
56#elif defined(Q_OS_MACX) 57#elif defined(Q_OS_MACX)
57#include <stdlib.h> 58#include <stdlib.h>
58#endif 59#endif
59 60
60#include <qtextstream.h> 61#include <qtextstream.h>
61#include <qmessagebox.h> 62#include <qmessagebox.h>
62//#include <qpe/qcopchannel_qws.h> 63//#include <qpe/qcopchannel_qws.h>
63#include <qpe/process.h> 64#include <qpe/process.h>
64#include <qpe/global.h> 65#include <qpe/global.h>
65#include <qpe/config.h> 66#include <qpe/config.h>
66#include <qpe/contact.h> 67#include <qpe/contact.h>
67#include <qpe/version.h> 68#include <qpe/version.h>
68#include <qpe/qcopenvelope_qws.h> 69#include <qpe/qcopenvelope_qws.h>
69 70
70#include "transferserver.h" 71#include "transferserver.h"
71#include <opie2/oprocess.h> 72#include <opie2/oprocess.h>
72using namespace Opie::Core; 73using namespace Opie::Core;
73 74
74const int block_size = 51200; 75const int block_size = 51200;
75 76
76TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 77TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
77 const char* name ) 78 const char* name )
78 : QServerSocket( port, 1, parent, name ) 79 : QServerSocket( port, 1, parent, name )
79{ 80{
80 if ( !ok() ) 81 if ( !ok() )
81 owarn << "Failed to bind to port " << port << "" << oendl; 82 owarn << "Failed to bind to port " << port << "" << oendl;
82} 83}
83 84
84TransferServer::~TransferServer() 85TransferServer::~TransferServer()
85{ 86{
86} 87}
87 88
88void TransferServer::newConnection( int socket ) 89void TransferServer::newConnection( int socket )
89{ 90{
90 (void) new ServerPI( socket, this ); 91 (void) new ServerPI( socket, this );
91} 92}
92 93
93/* 94/*
94 * small class in anonymous namespace 95 * small class in anonymous namespace
95 * to generate a QUUid for us 96 * to generate a QUUid for us
96 */ 97 */
97namespace 98namespace
98{ 99{
99struct UidGen 100struct UidGen
100{ 101{
101 QString uuid(); 102 QString uuid();
102}; 103};
103#if defined(Q_OS_MACX) 104#if defined(Q_OS_MACX)
104QString UidGen::uuid() 105QString UidGen::uuid()
105{ 106{
106 srandom( random() ); 107 srandom( random() );
107 QString numStr = QString::number( random() ); 108 QString numStr = QString::number( random() );
108 109
109 return "{" + numStr + "}"; 110 return "{" + numStr + "}";
110} 111}
111#elif defined(_OS_LINUX_) 112#elif defined(_OS_LINUX_)
112/* 113/*
113* linux got a /proc/sys/kernel/random/uuid file 114* linux got a /proc/sys/kernel/random/uuid file
114* it'll generate the uuids for us 115* it'll generate the uuids for us
115*/ 116*/
116QString UidGen::uuid() 117QString UidGen::uuid()
117{ 118{
118 QFile file( "/proc/sys/kernel/random/uuid" ); 119 QFile file( "/proc/sys/kernel/random/uuid" );
119 if (!file.open(IO_ReadOnly ) ) 120 if (!file.open(IO_ReadOnly ) )
120 return QString::null; 121 return QString::null;
121 122
122 QTextStream stream(&file); 123 QTextStream stream(&file);
123 124
124 return "{" + stream.read().stripWhiteSpace() + "}"; 125 return "{" + stream.read().stripWhiteSpace() + "}";
125} 126}
126#else 127#else
127QString UidGen::uuid() 128QString UidGen::uuid()
128{ 129{
129 uuid_t uuid; 130 uuid_t uuid;
130 ::uuid_generate( uuid ); 131 ::uuid_generate( uuid );
131 return QUUid( uuid ).toString(); 132 return QUUid( uuid ).toString();
132} 133}
133#endif 134#endif
134} 135}
135 136
136QString SyncAuthentication::serverId() 137QString SyncAuthentication::serverId()
137{ 138{
138 Config cfg("Security"); 139 Config cfg("Security");
139 cfg.setGroup("Sync"); 140 cfg.setGroup("Sync");
140 QString r = cfg.readEntry("serverid"); 141 QString r = cfg.readEntry("serverid");
141 if ( r.isEmpty() ) { 142 if ( r.isEmpty() ) {
142 UidGen gen; 143 UidGen gen;
143 r = gen.uuid(); 144 r = gen.uuid();
144 cfg.writeEntry("serverid", r ); 145 cfg.writeEntry("serverid", r );
145 } 146 }
146 return r; 147 return r;
147} 148}
148 149
149QString SyncAuthentication::ownerName() 150QString SyncAuthentication::ownerName()
150{ 151{
151 QString vfilename = Global::applicationFileName("addressbook", 152 QString vfilename = Global::applicationFileName("addressbook",
152 "businesscard.vcf"); 153 "businesscard.vcf");
153 if (QFile::exists(vfilename)) { 154 if (QFile::exists(vfilename)) {
154 Contact c; 155 Contact c;
155 c = Contact::readVCard( vfilename )[0]; 156 c = Contact::readVCard( vfilename )[0];
156 return c.fullName(); 157 return c.fullName();
157 } 158 }
158 159
159 return ""; 160 return "";
160} 161}
161 162
162QString SyncAuthentication::loginName() 163QString SyncAuthentication::loginName()
163{ 164{
164 struct passwd *pw; 165 struct passwd *pw;
165 pw = getpwuid( geteuid() ); 166 pw = getpwuid( geteuid() );
166 return QString::fromLocal8Bit( pw->pw_name ); 167 return QString::fromLocal8Bit( pw->pw_name );
167} 168}
168 169
169int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 170int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
170{ 171{
171 Config cfg("Security"); 172 Config cfg("Security");
172 cfg.setGroup("Sync"); 173 cfg.setGroup("Sync");
173 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 174 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
174 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 175 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
175 176
176 // QHostAddress allowed; 177 // QHostAddress allowed;
177 // allowed.setAddress(allowedstr); 178 // allowed.setAddress(allowedstr);
178 // uint auth_peer = allowed.ip4Addr(); 179 // uint auth_peer = allowed.ip4Addr();
179 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 180 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
180 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 181 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
181 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 182 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
182 return (peeraddress.ip4Addr() & mask) == auth_peer; 183 return (peeraddress.ip4Addr() & mask) == auth_peer;
183} 184}
184 185
185bool SyncAuthentication::checkUser( const QString& user ) 186bool SyncAuthentication::checkUser( const QString& user )
186{ 187{
187 if ( user.isEmpty() ) 188 if ( user.isEmpty() )
188 return FALSE; 189 return FALSE;
189 QString euser = loginName(); 190 QString euser = loginName();
190 return user == euser; 191 return user == euser;
191} 192}
192 193
193bool SyncAuthentication::checkPassword( const QString& password ) 194bool SyncAuthentication::checkPassword( const QString& password )
194{ 195{
195#ifdef ALLOW_UNIX_USER_FTP 196#ifdef ALLOW_UNIX_USER_FTP
196 // First, check system password... 197 // First, check system password...
197 198
198 struct passwd *pw = 0; 199 struct passwd *pw = 0;
199 struct spwd *spw = 0; 200 struct spwd *spw = 0;
200 201
201 pw = getpwuid( geteuid() ); 202 pw = getpwuid( geteuid() );
202 spw = getspnam( pw->pw_name ); 203 spw = getspnam( pw->pw_name );
203 204
204 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 205 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
205 if ( cpwd == "x" && spw ) 206 if ( cpwd == "x" && spw )
206 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 207 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
207 208
208 // Note: some systems use more than crypt for passwords. 209 // Note: some systems use more than crypt for passwords.
209 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 210 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
210 if ( cpwd == cpassword ) 211 if ( cpwd == cpassword )
211 return TRUE; 212 return TRUE;
212#endif 213#endif
213 214
214 static int lastdenial = 0; 215 static int lastdenial = 0;
215 static int denials = 0; 216 static int denials = 0;
216 int now = time(0); 217 int now = time(0);
217 218
218 // Detect old Qtopia Desktop (no password) 219 // Detect old Qtopia Desktop (no password)
219 if ( password.isEmpty() ) { 220 if ( password.isEmpty() ) {
220 if ( denials < 1 || now > lastdenial + 600 ) { 221 if ( denials < 1 || now > lastdenial + 600 ) {
221 QMessageBox::warning( 0, tr("Sync Connection"), 222 QMessageBox::warning( 0, tr("Sync Connection"),
222 tr("<p>An unauthorized system is requesting access to this device." 223 tr("<p>An unauthorized system is requesting access to this device."
223 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 224 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
224 "please upgrade."), 225 "please upgrade."),
225 tr("Deny") ); 226 tr("Deny") );
226 denials++; 227 denials++;
227 lastdenial = now; 228 lastdenial = now;
228 } 229 }
229 return FALSE; 230 return FALSE;
230 } 231 }
231 232
232 // Second, check sync password... 233 // Second, check sync password...
233 QString pass = password.left(6); 234 QString pass = password.left(6);
234 /* old QtopiaDesktops are sending 235 /* old QtopiaDesktops are sending
235 * rootme newer versions got a Qtopia 236 * rootme newer versions got a Qtopia
236 * prefixed. Qtopia prefix will suceed 237 * prefixed. Qtopia prefix will suceed
237 * until the sync software syncs up 238 * until the sync software syncs up
238 * FIXME 239 * FIXME
239 */ 240 */
240 if ( pass == "rootme" || pass == "Qtopia") { 241 if ( pass == "rootme" || pass == "Qtopia") {
241 242
242 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 243 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
243 Config cfg("Security"); 244 Config cfg("Security");
244 cfg.setGroup("Sync"); 245 cfg.setGroup("Sync");
245 QString pwds = cfg.readEntry("Passwords"); 246 QString pwds = cfg.readEntry("Passwords");
246 if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) 247 if ( QStringList::split(QChar(' '), pwds).contains(cpassword) )
247 return TRUE; 248 return TRUE;
248 249
249 // Unrecognized system. Be careful... 250 // Unrecognized system. Be careful...
250 251
251 if ( (denials > 2 && now < lastdenial + 600) 252 if ( (denials > 2 && now < lastdenial + 600)
252 || QMessageBox::warning(0, tr("Sync Connection"), 253 || QMessageBox::warning(0, tr("Sync Connection"),
253 tr("<p>An unrecognized system is requesting access to this device." 254 tr("<p>An unrecognized system is requesting access to this device."
254 "<p>If you have just initiated a Sync for the first time, this is normal."), 255 "<p>If you have just initiated a Sync for the first time, this is normal."),
255 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { 256 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) {
256 denials++; 257 denials++;
257 lastdenial = now; 258 lastdenial = now;
258 return FALSE; 259 return FALSE;
259 } 260 }
260 else { 261 else {
261 denials = 0; 262 denials = 0;
262 cfg.writeEntry("Passwords", pwds + " " + cpassword); 263 cfg.writeEntry("Passwords", pwds + " " + cpassword);
263 return TRUE; 264 return TRUE;
264 } 265 }
265 } 266 }
266 267
267 return FALSE; 268 return FALSE;
268} 269}
269 270
270ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 271ServerPI::ServerPI( int socket, QObject *parent , const char* name )
271 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 272 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
272{ 273{
273 state = Connected; 274 state = Connected;
274 275
275 setSocket( socket ); 276 setSocket( socket );
276 277
277 peerport = peerPort(); 278 peerport = peerPort();
278 peeraddress = peerAddress(); 279 peeraddress = peerAddress();
279 280
280#ifndef INSECURE 281#ifndef INSECURE
281 282
282 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 283 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
283 state = Forbidden; 284 state = Forbidden;
284 startTimer( 0 ); 285 startTimer( 0 );
285 } 286 }
286 else 287 else
287#endif 288#endif
288 { 289 {
289 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 290 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
290 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 291 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
291 292
292 passiv = FALSE; 293 passiv = FALSE;
293 for ( int i = 0; i < 4; i++ ) 294 for ( int i = 0; i < 4; i++ )
294 wait[i] = FALSE; 295 wait[i] = FALSE;
295 296
296 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 297 send( "220 Qtopia " QPE_VERSION " FTP Server" );
297 state = Wait_USER; 298 state = Wait_USER;
298 299
299 dtp = new ServerDTP( this ); 300 dtp = new ServerDTP( this );
300 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 301 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
301 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 302 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
302 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); 303 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) );
303 304
304 305
305 directory = QDir::currentDirPath(); 306 directory = QDir::currentDirPath();
306 307
307 static int p = 1024; 308 static int p = 1024;
308 309
309 while ( !serversocket || !serversocket->ok() ) { 310 while ( !serversocket || !serversocket->ok() ) {
310 delete serversocket; 311 delete serversocket;
311 serversocket = new ServerSocket( ++p, this ); 312 serversocket = new ServerSocket( ++p, this );
312 } 313 }
313 connect( serversocket, SIGNAL( newIncomming(int) ), 314 connect( serversocket, SIGNAL( newIncomming(int) ),
314 SLOT( newConnection(int) ) ); 315 SLOT( newConnection(int) ) );
315 } 316 }
316} 317}
317 318
318ServerPI::~ServerPI() 319ServerPI::~ServerPI()
319{ 320{
320} 321}
321 322
322void ServerPI::connectionClosed() 323void ServerPI::connectionClosed()
323{ 324{
324 // odebug << "Debug: Connection closed" << oendl; 325 // odebug << "Debug: Connection closed" << oendl;
325 delete this; 326 delete this;
326} 327}
327 328
328void ServerPI::send( const QString& msg ) 329void ServerPI::send( const QString& msg )
329{ 330{
330 QTextStream os( this ); 331 QTextStream os( this );
331 os << msg << endl; 332 os << msg << endl;
332 //odebug << "Reply: " << msg << "" << oendl; 333 //odebug << "Reply: " << msg << "" << oendl;
333} 334}
334 335
335void ServerPI::read() 336void ServerPI::read()
336{ 337{
337 while ( canReadLine() ) 338 while ( canReadLine() )
338 process( readLine().stripWhiteSpace() ); 339 process( readLine().stripWhiteSpace() );
339} 340}
340 341
341bool ServerPI::checkReadFile( const QString& file ) 342bool ServerPI::checkReadFile( const QString& file )
342{ 343{
343 QString filename; 344 QString filename;
344 345
345 if ( file[0] != "/" ) 346 if ( file[0] != "/" )
346 filename = directory.path() + "/" + file; 347 filename = directory.path() + "/" + file;
347 else 348 else
348 filename = file; 349 filename = file;
349 350
350 QFileInfo fi( filename ); 351 QFileInfo fi( filename );
351 return ( fi.exists() && fi.isReadable() ); 352 return ( fi.exists() && fi.isReadable() );
352} 353}
353 354
354bool ServerPI::checkWriteFile( const QString& file ) 355bool ServerPI::checkWriteFile( const QString& file )
355{ 356{
356 QString filename; 357 QString filename;
357 358
358 if ( file[0] != "/" ) 359 if ( file[0] != "/" )
359 filename = directory.path() + "/" + file; 360 filename = directory.path() + "/" + file;
360 else 361 else
361 filename = file; 362 filename = file;
362 363
363 QFileInfo fi( filename ); 364 QFileInfo fi( filename );
364 365
365 if ( fi.exists() ) 366 if ( fi.exists() )
366 if ( !QFile( filename ).remove() ) 367 if ( !QFile( filename ).remove() )
367 return FALSE; 368 return FALSE;
368 return TRUE; 369 return TRUE;
369} 370}
370 371
371void ServerPI::process( const QString& message ) 372void ServerPI::process( const QString& message )
372{ 373{
373 //odebug << "Command: " << message << "" << oendl; 374 //odebug << "Command: " << message << "" << oendl;
374 375
375 // split message using "," as separator 376 // split message using "," as separator
376 QStringList msg = QStringList::split( " ", message ); 377 QStringList msg = QStringList::split( " ", message );
377 if ( msg.isEmpty() ) 378 if ( msg.isEmpty() )
378 return ; 379 return ;
379 380
380 // command token 381 // command token
381 QString cmd = msg[0].upper(); 382 QString cmd = msg[0].upper();
382 383
383 // argument token 384 // argument token
384 QString arg; 385 QString arg;
385 if ( msg.count() >= 2 ) 386 if ( msg.count() >= 2 )
386 arg = msg[1]; 387 arg = msg[1];
387 388
388 // full argument string 389 // full argument string
389 QString args; 390 QString args;
390 if ( msg.count() >= 2 ) { 391 if ( msg.count() >= 2 ) {
391 QStringList copy( msg ); 392 QStringList copy( msg );
392 // FIXME: for Qt3 393 // FIXME: for Qt3
393 // copy.pop_front() 394 // copy.pop_front()
394 copy.remove( copy.begin() ); 395 copy.remove( copy.begin() );
395 args = copy.join( " " ); 396 args = copy.join( " " );
396 } 397 }
397 398
398 //odebug << "args: " << args << "" << oendl; 399 //odebug << "args: " << args << "" << oendl;
399 400
400 // we always respond to QUIT, regardless of state 401 // we always respond to QUIT, regardless of state
401 if ( cmd == "QUIT" ) { 402 if ( cmd == "QUIT" ) {
402 send( "211 Good bye!" ); 403 send( "211 Good bye!" );
403 delete this; 404 delete this;
404 return ; 405 return ;
405 } 406 }
406 407
407 // connected to client 408 // connected to client
408 if ( Connected == state ) 409 if ( Connected == state )
409 return ; 410 return ;
410 411
411 // waiting for user name 412 // waiting for user name
412 if ( Wait_USER == state ) { 413 if ( Wait_USER == state ) {
413 414
414 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 415 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
415 send( "530 Please login with USER and PASS" ); 416 send( "530 Please login with USER and PASS" );
416 return ; 417 return ;
417 } 418 }
418 send( "331 User name ok, need password" ); 419 send( "331 User name ok, need password" );
419 state = Wait_PASS; 420 state = Wait_PASS;
420 return ; 421 return ;
421 } 422 }
422 423
423 // waiting for password 424 // waiting for password
424 if ( Wait_PASS == state ) { 425 if ( Wait_PASS == state ) {
425 426
426 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 427 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
427 send( "530 Please login with USER and PASS" ); 428 send( "530 Please login with USER and PASS" );
428 return ; 429 return ;
429 } 430 }
430 send( "230 User logged in, proceed" ); 431 send( "230 User logged in, proceed" );
431 state = Ready; 432 state = Ready;
432 return ; 433 return ;
433 } 434 }
434 435
435 // ACCESS CONTROL COMMANDS 436 // ACCESS CONTROL COMMANDS
436 437
437 438
438 // account (ACCT) 439 // account (ACCT)
439 if ( cmd == "ACCT" ) { 440 if ( cmd == "ACCT" ) {
440 // even wu-ftp does not support it 441 // even wu-ftp does not support it
441 send( "502 Command not implemented" ); 442 send( "502 Command not implemented" );
442 } 443 }
443 444
444 // change working directory (CWD) 445 // change working directory (CWD)
445 else if ( cmd == "CWD" ) { 446 else if ( cmd == "CWD" ) {
446 447
447 if ( !args.isEmpty() ) { 448 if ( !args.isEmpty() ) {
448 if ( directory.cd( args, TRUE ) ) 449 if ( directory.cd( args, TRUE ) )
449 send( "250 Requested file action okay, completed" ); 450 send( "250 Requested file action okay, completed" );
450 else 451 else
451 send( "550 Requested action not taken" ); 452 send( "550 Requested action not taken" );
452 } 453 }
453 else 454 else
454 send( "500 Syntax error, command unrecognized" ); 455 send( "500 Syntax error, command unrecognized" );
455 } 456 }
456 457
457 // change to parent directory (CDUP) 458 // change to parent directory (CDUP)
458 else if ( cmd == "CDUP" ) { 459 else if ( cmd == "CDUP" ) {
459 if ( directory.cdUp() ) 460 if ( directory.cdUp() )
460 send( "250 Requested file action okay, completed" ); 461 send( "250 Requested file action okay, completed" );
461 else 462 else
462 send( "550 Requested action not taken" ); 463 send( "550 Requested action not taken" );
463 } 464 }
464 465
465 // structure mount (SMNT) 466 // structure mount (SMNT)
466 else if ( cmd == "SMNT" ) { 467 else if ( cmd == "SMNT" ) {
467 // even wu-ftp does not support it 468 // even wu-ftp does not support it
468 send( "502 Command not implemented" ); 469 send( "502 Command not implemented" );
469 } 470 }
470 471
471 // reinitialize (REIN) 472 // reinitialize (REIN)
472 else if ( cmd == "REIN" ) { 473 else if ( cmd == "REIN" ) {
473 // even wu-ftp does not support it 474 // even wu-ftp does not support it
474 send( "502 Command not implemented" ); 475 send( "502 Command not implemented" );
475 } 476 }
476 477
477 478
478 // TRANSFER PARAMETER COMMANDS 479 // TRANSFER PARAMETER COMMANDS
479 480
480 481
481 // data port (PORT) 482 // data port (PORT)
482 else if ( cmd == "PORT" ) { 483 else if ( cmd == "PORT" ) {
483 if ( parsePort( arg ) ) 484 if ( parsePort( arg ) )
484 send( "200 Command okay" ); 485 send( "200 Command okay" );
485 else 486 else
486 send( "500 Syntax error, command unrecognized" ); 487 send( "500 Syntax error, command unrecognized" );
487 } 488 }
488 489
489 // passive (PASV) 490 // passive (PASV)
490 else if ( cmd == "PASV" ) { 491 else if ( cmd == "PASV" ) {
491 passiv = TRUE; 492 passiv = TRUE;
492 send( "227 Entering Passive Mode (" 493 send( "227 Entering Passive Mode ("
493 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 494 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
494 + QString::number( ( serversocket->port() ) >> 8 ) + "," 495 + QString::number( ( serversocket->port() ) >> 8 ) + ","
495 + QString::number( ( serversocket->port() ) & 0xFF ) + ")" ); 496 + QString::number( ( serversocket->port() ) & 0xFF ) + ")" );
496 } 497 }
497 498
498 // representation type (TYPE) 499 // representation type (TYPE)
499 else if ( cmd == "TYPE" ) { 500 else if ( cmd == "TYPE" ) {
500 if ( arg.upper() == "A" || arg.upper() == "I" ) 501 if ( arg.upper() == "A" || arg.upper() == "I" )
501 send( "200 Command okay" ); 502 send( "200 Command okay" );
502 else 503 else
503 send( "504 Command not implemented for that parameter" ); 504 send( "504 Command not implemented for that parameter" );
504 } 505 }
505 506
506 // file structure (STRU) 507 // file structure (STRU)
507 else if ( cmd == "STRU" ) { 508 else if ( cmd == "STRU" ) {
508 if ( arg.upper() == "F" ) 509 if ( arg.upper() == "F" )
509 send( "200 Command okay" ); 510 send( "200 Command okay" );
510 else 511 else
511 send( "504 Command not implemented for that parameter" ); 512 send( "504 Command not implemented for that parameter" );
512 } 513 }
513 514
514 // transfer mode (MODE) 515 // transfer mode (MODE)
515 else if ( cmd == "MODE" ) { 516 else if ( cmd == "MODE" ) {
516 if ( arg.upper() == "S" ) 517 if ( arg.upper() == "S" )
517 send( "200 Command okay" ); 518 send( "200 Command okay" );
518 else 519 else
519 send( "504 Command not implemented for that parameter" ); 520 send( "504 Command not implemented for that parameter" );
520 } 521 }
521 522
522 523
523 // FTP SERVICE COMMANDS 524 // FTP SERVICE COMMANDS
524 525
525 526
526 // retrieve (RETR) 527 // retrieve (RETR)
527 else if ( cmd == "RETR" ) 528 else if ( cmd == "RETR" )
528 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 529 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
529 || backupRestoreGzip( absFilePath( args ) ) ) { 530 || backupRestoreGzip( absFilePath( args ) ) ) {
530 send( "150 File status okay" ); 531 send( "150 File status okay" );
531 sendFile( absFilePath( args ) ); 532 sendFile( absFilePath( args ) );
532 } 533 }
533 else { 534 else {
534 odebug << "550 Requested action not taken" << oendl; 535 odebug << "550 Requested action not taken" << oendl;
535 send( "550 Requested action not taken" ); 536 send( "550 Requested action not taken" );
536 } 537 }
537 538
538 // store (STOR) 539 // store (STOR)
539 else if ( cmd == "STOR" ) 540 else if ( cmd == "STOR" )
540 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 541 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
541 send( "150 File status okay" ); 542 send( "150 File status okay" );
542 retrieveFile( absFilePath( args ) ); 543 retrieveFile( absFilePath( args ) );
543 } 544 }
544 else 545 else
545 send( "550 Requested action not taken" ); 546 send( "550 Requested action not taken" );
546 547
547 // store unique (STOU) 548 // store unique (STOU)
548 else if ( cmd == "STOU" ) { 549 else if ( cmd == "STOU" ) {
549 send( "502 Command not implemented" ); 550 send( "502 Command not implemented" );
550 } 551 }
551 552
552 // append (APPE) 553 // append (APPE)
553 else if ( cmd == "APPE" ) { 554 else if ( cmd == "APPE" ) {
554 send( "502 Command not implemented" ); 555 send( "502 Command not implemented" );
555 } 556 }
556 557
557 // allocate (ALLO) 558 // allocate (ALLO)
558 else if ( cmd == "ALLO" ) { 559 else if ( cmd == "ALLO" ) {
559 send( "200 Command okay" ); 560 send( "200 Command okay" );
560 } 561 }
561 562
562 // restart (REST) 563 // restart (REST)
563 else if ( cmd == "REST" ) { 564 else if ( cmd == "REST" ) {
564 send( "502 Command not implemented" ); 565 send( "502 Command not implemented" );
565 } 566 }
566 567
567 // rename from (RNFR) 568 // rename from (RNFR)
568 else if ( cmd == "RNFR" ) { 569 else if ( cmd == "RNFR" ) {
569 renameFrom = QString::null; 570 renameFrom = QString::null;
570 if ( args.isEmpty() ) 571 if ( args.isEmpty() )
571 send( "500 Syntax error, command unrecognized" ); 572 send( "500 Syntax error, command unrecognized" );
572 else { 573 else {
573 QFile file( absFilePath( args ) ); 574 QFile file( absFilePath( args ) );
574 if ( file.exists() ) { 575 if ( file.exists() ) {
575 send( "350 File exists, ready for destination name" ); 576 send( "350 File exists, ready for destination name" );
576 renameFrom = absFilePath( args ); 577 renameFrom = absFilePath( args );
577 } 578 }
578 else 579 else
579 send( "550 Requested action not taken" ); 580 send( "550 Requested action not taken" );
580 } 581 }
581 } 582 }
582 583
583 // rename to (RNTO) 584 // rename to (RNTO)
584 else if ( cmd == "RNTO" ) { 585 else if ( cmd == "RNTO" ) {
585 if ( lastCommand != "RNFR" ) 586 if ( lastCommand != "RNFR" )
586 send( "503 Bad sequence of commands" ); 587 send( "503 Bad sequence of commands" );
587 else if ( args.isEmpty() ) 588 else if ( args.isEmpty() )
588 send( "500 Syntax error, command unrecognized" ); 589 send( "500 Syntax error, command unrecognized" );
589 else { 590 else {
590 QDir dir( absFilePath( args ) ); 591 QDir dir( absFilePath( args ) );
591 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 592 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
592 send( "250 Requested file action okay, completed." ); 593 send( "250 Requested file action okay, completed." );
593 else 594 else
594 send( "550 Requested action not taken" ); 595 send( "550 Requested action not taken" );
595 } 596 }
596 } 597 }
597 598
598 // abort (ABOR) 599 // abort (ABOR)
599 else if ( cmd.contains( "ABOR" ) ) { 600 else if ( cmd.contains( "ABOR" ) ) {
600 dtp->close(); 601 dtp->close();
601 if ( dtp->dtpMode() != ServerDTP::Idle ) 602 if ( dtp->dtpMode() != ServerDTP::Idle )
602 send( "426 Connection closed; transfer aborted" ); 603 send( "426 Connection closed; transfer aborted" );
603 else 604 else
604 send( "226 Closing data connection" ); 605 send( "226 Closing data connection" );
605 } 606 }
606 607
607 // delete (DELE) 608 // delete (DELE)
608 else if ( cmd == "DELE" ) { 609 else if ( cmd == "DELE" ) {
609 if ( args.isEmpty() ) 610 if ( args.isEmpty() )
610 send( "500 Syntax error, command unrecognized" ); 611 send( "500 Syntax error, command unrecognized" );
611 else { 612 else {
612 QFile file( absFilePath( args ) ) ; 613 QFile file( absFilePath( args ) ) ;
613 if ( file.remove() ) { 614 if ( file.remove() ) {
614 send( "250 Requested file action okay, completed" ); 615 send( "250 Requested file action okay, completed" );
615 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 616 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
616 e << file.name(); 617 e << file.name();
617 } 618 }
618 else { 619 else {
619 send( "550 Requested action not taken" ); 620 send( "550 Requested action not taken" );
620 } 621 }
621 } 622 }
622 } 623 }
623 624
624 // remove directory (RMD) 625 // remove directory (RMD)
625 else if ( cmd == "RMD" ) { 626 else if ( cmd == "RMD" ) {
626 if ( args.isEmpty() ) 627 if ( args.isEmpty() )
627 send( "500 Syntax error, command unrecognized" ); 628 send( "500 Syntax error, command unrecognized" );
628 else { 629 else {
629 QDir dir; 630 QDir dir;
630 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 631 if ( dir.rmdir( absFilePath( args ), TRUE ) )
631 send( "250 Requested file action okay, completed" ); 632 send( "250 Requested file action okay, completed" );
632 else 633 else
633 send( "550 Requested action not taken" ); 634 send( "550 Requested action not taken" );
634 } 635 }
635 } 636 }
636 637
637 // make directory (MKD) 638 // make directory (MKD)
638 else if ( cmd == "MKD" ) { 639 else if ( cmd == "MKD" ) {
639 if ( args.isEmpty() ) { 640 if ( args.isEmpty() ) {
640 odebug << " Error: no arg" << oendl; 641 odebug << " Error: no arg" << oendl;
641 send( "500 Syntax error, command unrecognized" ); 642 send( "500 Syntax error, command unrecognized" );
642 } 643 }
643 else { 644 else {
644 QDir dir; 645 QDir dir;
645 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 646 if ( dir.mkdir( absFilePath( args ), TRUE ) )
646 send( "250 Requested file action okay, completed." ); 647 send( "250 Requested file action okay, completed." );
647 else 648 else
648 send( "550 Requested action not taken" ); 649 send( "550 Requested action not taken" );
649 } 650 }
650 } 651 }
651 652
652 // print working directory (PWD) 653 // print working directory (PWD)
653 else if ( cmd == "PWD" ) { 654 else if ( cmd == "PWD" ) {
654 send( "257 \"" + directory.path() + "\"" ); 655 send( "257 \"" + directory.path() + "\"" );
655 } 656 }
656 657
657 // list (LIST) 658 // list (LIST)
658 else if ( cmd == "LIST" ) { 659 else if ( cmd == "LIST" ) {
659 if ( sendList( absFilePath( args ) ) ) 660 if ( sendList( absFilePath( args ) ) )
660 send( "150 File status okay" ); 661 send( "150 File status okay" );
661 else 662 else
662 send( "500 Syntax error, command unrecognized" ); 663 send( "500 Syntax error, command unrecognized" );
663 } 664 }
664 665
665 // size (SIZE) 666 // size (SIZE)
666 else if ( cmd == "SIZE" ) { 667 else if ( cmd == "SIZE" ) {
667 QString filePath = absFilePath( args ); 668 QString filePath = absFilePath( args );
668 QFileInfo fi( filePath ); 669 QFileInfo fi( filePath );
669 bool gzipfile = backupRestoreGzip( filePath ); 670 bool gzipfile = backupRestoreGzip( filePath );
670 if ( !fi.exists() && !gzipfile ) 671 if ( !fi.exists() && !gzipfile )
671 send( "500 Syntax error, command unrecognized" ); 672 send( "500 Syntax error, command unrecognized" );
672 else { 673 else {
673 if ( !gzipfile ) 674 if ( !gzipfile )
674 send( "213 " + QString::number( fi.size() ) ); 675 send( "213 " + QString::number( fi.size() ) );
675 else { 676 else {
676 Process duproc( QString("du") ); 677 Process duproc( QString("du") );
677 duproc.addArgument("-s"); 678 duproc.addArgument("-s");
678 QString in, out; 679 QString in, out;
679 if ( !duproc.exec(in, out) ) { 680 if ( !duproc.exec(in, out) ) {
680 odebug << "du process failed; just sending back 1K" << oendl; 681 odebug << "du process failed; just sending back 1K" << oendl;
681 send( "213 1024"); 682 send( "213 1024");
682 } 683 }
683 else { 684 else {
684 QString size = out.left( out.find("\t") ); 685 QString size = out.left( out.find("\t") );
685 int guess = size.toInt() / 5; 686 int guess = size.toInt() / 5;
686 if ( filePath.contains("doc") ) 687 if ( filePath.contains("doc") )
687 guess *= 1000; 688 guess *= 1000;
688 odebug << "sending back gzip guess of " << guess << "" << oendl; 689 odebug << "sending back gzip guess of " << guess << "" << oendl;
689 send( "213 " + QString::number(guess) ); 690 send( "213 " + QString::number(guess) );
690 } 691 }
691 } 692 }
692 } 693 }
693 } 694 }
694 // name list (NLST) 695 // name list (NLST)
695 else if ( cmd == "NLST" ) { 696 else if ( cmd == "NLST" ) {
696 send( "502 Command not implemented" ); 697 send( "502 Command not implemented" );
697 } 698 }
698 699
699 // site parameters (SITE) 700 // site parameters (SITE)
700 else if ( cmd == "SITE" ) { 701 else if ( cmd == "SITE" ) {
701 send( "502 Command not implemented" ); 702 send( "502 Command not implemented" );
702 } 703 }
703 704
704 // system (SYST) 705 // system (SYST)
705 else if ( cmd == "SYST" ) { 706 else if ( cmd == "SYST" ) {
706 send( "215 UNIX Type: L8" ); 707 send( "215 UNIX Type: L8" );
707 } 708 }
708 709
709 // status (STAT) 710 // status (STAT)
710 else if ( cmd == "STAT" ) { 711 else if ( cmd == "STAT" ) {
711 send( "502 Command not implemented" ); 712 send( "502 Command not implemented" );
712 } 713 }
713 714
714 // help (HELP ) 715 // help (HELP )
715 else if ( cmd == "HELP" ) { 716 else if ( cmd == "HELP" ) {
716 send( "502 Command not implemented" ); 717 send( "502 Command not implemented" );
717 } 718 }
718 719
719 // noop (NOOP) 720 // noop (NOOP)
720 else if ( cmd == "NOOP" ) { 721 else if ( cmd == "NOOP" ) {
721 send( "200 Command okay" ); 722 send( "200 Command okay" );
722 } 723 }
723 724
724 // not implemented 725 // not implemented
725 else 726 else
726 send( "502 Command not implemented" ); 727 send( "502 Command not implemented" );
727 728
728 lastCommand = cmd; 729 lastCommand = cmd;
729} 730}
730 731
731bool ServerPI::backupRestoreGzip( const QString &file ) 732bool ServerPI::backupRestoreGzip( const QString &file )
732{ 733{
733 return (file.find( "backup" ) != -1 && 734 return (file.find( "backup" ) != -1 &&
734 file.findRev( ".tgz" ) == (int)file.length() - 4 ); 735 file.findRev( ".tgz" ) == (int)file.length() - 4 );
735} 736}
736 737
737bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 738bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
738{ 739{
739 if ( file.find( "backup" ) != -1 && 740 if ( file.find( "backup" ) != -1 &&
740 file.findRev( ".tgz" ) == (int)file.length() - 4 ) { 741 file.findRev( ".tgz" ) == (int)file.length() - 4 ) {
741 QFileInfo info( file ); 742 QFileInfo info( file );
742 targets = info.dirPath( TRUE ); 743 targets = info.dirPath( TRUE );
743 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " 744 odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = "
744 << targets.join(" ").latin1() << oendl; 745 << targets.join(" ").latin1() << oendl;
745 return true; 746 return true;
746 } 747 }
747 return false; 748 return false;
748} 749}
749 750
750void ServerPI::sendFile( const QString& file ) 751void ServerPI::sendFile( const QString& file )
751{ 752{
752 if ( passiv ) { 753 if ( passiv ) {
753 wait[SendFile] = TRUE; 754 wait[SendFile] = TRUE;
754 waitfile = file; 755 waitfile = file;
755 if ( waitsocket ) 756 if ( waitsocket )
756 newConnection( waitsocket ); 757 newConnection( waitsocket );
757 } 758 }
758 else { 759 else {
759 QStringList targets; 760 QStringList targets;
760 if ( backupRestoreGzip( file, targets ) ) 761 if ( backupRestoreGzip( file, targets ) )
761 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 762 dtp->sendGzipFile( file, targets, peeraddress, peerport );
762 else 763 else
763 dtp->sendFile( file, peeraddress, peerport ); 764 dtp->sendFile( file, peeraddress, peerport );
764 } 765 }
765} 766}
766 767
767void ServerPI::retrieveFile( const QString& file ) 768void ServerPI::retrieveFile( const QString& file )
768{ 769{
769 if ( passiv ) { 770 if ( passiv ) {
770 wait[RetrieveFile] = TRUE; 771 wait[RetrieveFile] = TRUE;
771 waitfile = file; 772 waitfile = file;
772 if ( waitsocket ) 773 if ( waitsocket )
773 newConnection( waitsocket ); 774 newConnection( waitsocket );
774 } 775 }
775 else { 776 else {
776 QStringList targets; 777 QStringList targets;
777 if ( backupRestoreGzip( file, targets ) ) 778 if ( backupRestoreGzip( file, targets ) )
778 dtp->retrieveGzipFile( file, peeraddress, peerport ); 779 dtp->retrieveGzipFile( file, peeraddress, peerport );
779 else 780 else
780 dtp->retrieveFile( file, peeraddress, peerport ); 781 dtp->retrieveFile( file, peeraddress, peerport );
781 } 782 }
782} 783}
783 784
784bool ServerPI::parsePort( const QString& pp ) 785bool ServerPI::parsePort( const QString& pp )
785{ 786{
786 QStringList p = QStringList::split( ",", pp ); 787 QStringList p = QStringList::split( ",", pp );
787 if ( p.count() != 6 ) 788 if ( p.count() != 6 )
788 return FALSE; 789 return FALSE;
789 790
790 // h1,h2,h3,h4,p1,p2 791 // h1,h2,h3,h4,p1,p2
791 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 792 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
792 ( p[2].toInt() << 8 ) + p[3].toInt() ); 793 ( p[2].toInt() << 8 ) + p[3].toInt() );
793 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 794 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
794 return TRUE; 795 return TRUE;
795} 796}
796 797
797void ServerPI::dtpCompleted() 798void ServerPI::dtpCompleted()
798{ 799{
799 send( "226 Closing data connection, file transfer successful" ); 800 send( "226 Closing data connection, file transfer successful" );
800 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 801 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
801 QString fn = dtp->fileName(); 802 QString fn = dtp->fileName();
802 if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { 803 if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) {
803 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 804 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
804 e << fn; 805 e << fn;
805 } 806 }
806 } 807 }
807 waitsocket = 0; 808 waitsocket = 0;
808 dtp->close(); 809 dtp->close();
809} 810}
810 811
811void ServerPI::dtpFailed() 812void ServerPI::dtpFailed()
812{ 813{
813 dtp->close(); 814 dtp->close();
814 waitsocket = 0; 815 waitsocket = 0;
815 send( "451 Requested action aborted: local error in processing" ); 816 send( "451 Requested action aborted: local error in processing" );
816} 817}
817 818
818void ServerPI::dtpError( int ) 819void ServerPI::dtpError( int )
819{ 820{
820 dtp->close(); 821 dtp->close();
821 waitsocket = 0; 822 waitsocket = 0;
822 send( "451 Requested action aborted: local error in processing" ); 823 send( "451 Requested action aborted: local error in processing" );
823} 824}
824 825
825bool ServerPI::sendList( const QString& arg ) 826bool ServerPI::sendList( const QString& arg )
826{ 827{
827 QByteArray listing; 828 QByteArray listing;
828 QBuffer buffer( listing ); 829 QBuffer buffer( listing );
829 830
830 if ( !buffer.open( IO_WriteOnly ) ) 831 if ( !buffer.open( IO_WriteOnly ) )
831 return FALSE; 832 return FALSE;
832 833
833 QTextStream ts( &buffer ); 834 QTextStream ts( &buffer );
834 QString fn = arg; 835 QString fn = arg;
835 836
836 if ( fn.isEmpty() ) 837 if ( fn.isEmpty() )
837 fn = directory.path(); 838 fn = directory.path();
838 839
839 QFileInfo fi( fn ); 840 QFileInfo fi( fn );
840 if ( !fi.exists() ) 841 if ( !fi.exists() )
841 return FALSE; 842 return FALSE;
842 843
843 // return file listing 844 // return file listing
844 if ( fi.isFile() ) { 845 if ( fi.isFile() ) {
845 ts << fileListing( &fi ) << endl; 846 ts << fileListing( &fi ) << endl;
846 } 847 }
847 848
848 // return directory listing 849 // return directory listing
849 else if ( fi.isDir() ) { 850 else if ( fi.isDir() ) {
850 QDir dir( fn ); 851 QDir dir( fn );
851 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 852 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
852 853
853 QFileInfoListIterator it( *list ); 854 QFileInfoListIterator it( *list );
854 QFileInfo *info; 855 QFileInfo *info;
855 856
856 unsigned long total = 0; 857 unsigned long total = 0;
857 while ( ( info = it.current() ) ) { 858 while ( ( info = it.current() ) ) {
858 if ( info->fileName() != "." && info->fileName() != ".." ) 859 if ( info->fileName() != "." && info->fileName() != ".." )
859 total += info->size(); 860 total += info->size();
860 ++it; 861 ++it;
861 } 862 }
862 863
863 ts << "total " << QString::number( total / 1024 ) << endl; 864 ts << "total " << QString::number( total / 1024 ) << endl;
864 865
865 it.toFirst(); 866 it.toFirst();
866 while ( ( info = it.current() ) ) { 867 while ( ( info = it.current() ) ) {
867 if ( info->fileName() == "." || info->fileName() == ".." ) { 868 if ( info->fileName() == "." || info->fileName() == ".." ) {
868 ++it; 869 ++it;
869 continue; 870 continue;
870 } 871 }
871 ts << fileListing( info ) << endl; 872 ts << fileListing( info ) << endl;
872 ++it; 873 ++it;
873 } 874 }
874 } 875 }
875 876
876 if ( passiv ) { 877 if ( passiv ) {
877 waitarray = buffer.buffer(); 878 waitarray = buffer.buffer();
878 wait[SendByteArray] = TRUE; 879 wait[SendByteArray] = TRUE;
879 if ( waitsocket ) 880 if ( waitsocket )
880 newConnection( waitsocket ); 881 newConnection( waitsocket );
881 } 882 }
882 else 883 else
883 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 884 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
884 return TRUE; 885 return TRUE;
885} 886}
886 887
887QString ServerPI::fileListing( QFileInfo *info ) 888QString ServerPI::fileListing( QFileInfo *info )
888{ 889{
889 if ( !info ) 890 if ( !info )
890 return QString::null; 891 return QString::null;
891 QString s; 892 QString s;
892 893
893 // type char 894 // type char
894 if ( info->isDir() ) 895 if ( info->isDir() )
895 s += "d"; 896 s += "d";
896 else if ( info->isSymLink() ) 897 else if ( info->isSymLink() )
897 s += "l"; 898 s += "l";
898 else 899 else
899 s += "-"; 900 s += "-";
900 901
901 // permisson string 902 // permisson string
902 s += permissionString( info ) + " "; 903 s += permissionString( info ) + " ";
903 904
904 // number of hardlinks 905 // number of hardlinks
905 int subdirs = 1; 906 int subdirs = 1;
906 907
907 if ( info->isDir() ) 908 if ( info->isDir() )
908 subdirs = 2; 909 subdirs = 2;
909 // FIXME : this is to slow 910 // FIXME : this is to slow
910 //if ( info->isDir() ) 911 //if ( info->isDir() )
911 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 912 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
912 913
913 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 914 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
914 915
915 // owner 916 // owner
916 s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; 917 s += info->owner().leftJustify( 8, ' ', TRUE ) + " ";
917 918
918 // group 919 // group
919 s += info->group().leftJustify( 8, ' ', TRUE ) + " "; 920 s += info->group().leftJustify( 8, ' ', TRUE ) + " ";
920 921
921 // file size in bytes 922 // file size in bytes
922 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 923 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
923 924
924 // last modified date 925 // last modified date
925 QDate date = info->lastModified().date(); 926 QDate date = info->lastModified().date();
926 QTime time = info->lastModified().time(); 927 QTime time = info->lastModified().time();
927 s += date.monthName( date.month() ) + " " 928 s += date.monthName( date.month() ) + " "
928 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 929 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
929 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 930 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
930 + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; 931 + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " ";
931 932
932 // file name 933 // file name
933 s += info->fileName(); 934 s += info->fileName();
934 935
935 return s; 936 return s;
936} 937}
937 938
938QString ServerPI::permissionString( QFileInfo *info ) 939QString ServerPI::permissionString( QFileInfo *info )
939{ 940{
940 if ( !info ) 941 if ( !info )
941 return QString( "---------" ); 942 return QString( "---------" );
942 QString s; 943 QString s;
943 944
944 // user 945 // user
945 if ( info->permission( QFileInfo::ReadUser ) ) 946 if ( info->permission( QFileInfo::ReadUser ) )
946 s += "r"; 947 s += "r";
947 else 948 else
948 s += "-"; 949 s += "-";
949 if ( info->permission( QFileInfo::WriteUser ) ) 950 if ( info->permission( QFileInfo::WriteUser ) )
950 s += "w"; 951 s += "w";
951 else 952 else
952 s += "-"; 953 s += "-";
953 if ( info->permission( QFileInfo::ExeUser ) ) 954 if ( info->permission( QFileInfo::ExeUser ) )
954 s += "x"; 955 s += "x";
955 else 956 else
956 s += "-"; 957 s += "-";
957 958
958 // group 959 // group
959 if ( info->permission( QFileInfo::ReadGroup ) ) 960 if ( info->permission( QFileInfo::ReadGroup ) )
960 s += "r"; 961 s += "r";
961 else 962 else
962 s += "-"; 963 s += "-";
963 if ( info->permission( QFileInfo::WriteGroup ) ) 964 if ( info->permission( QFileInfo::WriteGroup ) )
964 s += "w"; 965 s += "w";
965 else 966 else
966 s += "-"; 967 s += "-";
967 if ( info->permission( QFileInfo::ExeGroup ) ) 968 if ( info->permission( QFileInfo::ExeGroup ) )
968 s += "x"; 969 s += "x";
969 else 970 else
970 s += "-"; 971 s += "-";
971 972
972 // exec 973 // exec
973 if ( info->permission( QFileInfo::ReadOther ) ) 974 if ( info->permission( QFileInfo::ReadOther ) )
974 s += "r"; 975 s += "r";
975 else 976 else
976 s += "-"; 977 s += "-";
977 if ( info->permission( QFileInfo::WriteOther ) ) 978 if ( info->permission( QFileInfo::WriteOther ) )
978 s += "w"; 979 s += "w";
979 else 980 else
980 s += "-"; 981 s += "-";
981 if ( info->permission( QFileInfo::ExeOther ) ) 982 if ( info->permission( QFileInfo::ExeOther ) )
982 s += "x"; 983 s += "x";
983 else 984 else
984 s += "-"; 985 s += "-";
985 986
986 return s; 987 return s;
987} 988}
988 989
989void ServerPI::newConnection( int socket ) 990void ServerPI::newConnection( int socket )
990{ 991{
991 //odebug << "New incomming connection" << oendl; 992 //odebug << "New incomming connection" << oendl;
992 993
993 if ( !passiv ) 994 if ( !passiv )
994 return ; 995 return ;
995 996
996 if ( wait[SendFile] ) { 997 if ( wait[SendFile] ) {
997 QStringList targets; 998 QStringList targets;
998 if ( backupRestoreGzip( waitfile, targets ) ) 999 if ( backupRestoreGzip( waitfile, targets ) )
999 dtp->sendGzipFile( waitfile, targets ); 1000 dtp->sendGzipFile( waitfile, targets );
1000 else 1001 else
1001 dtp->sendFile( waitfile ); 1002 dtp->sendFile( waitfile );
1002 dtp->setSocket( socket ); 1003 dtp->setSocket( socket );
1003 } 1004 }
1004 else if ( wait[RetrieveFile] ) { 1005 else if ( wait[RetrieveFile] ) {
1005 odebug << "check retrieve file" << oendl; 1006 odebug << "check retrieve file" << oendl;
1006 if ( backupRestoreGzip( waitfile ) ) 1007 if ( backupRestoreGzip( waitfile ) )
1007 dtp->retrieveGzipFile( waitfile ); 1008 dtp->retrieveGzipFile( waitfile );
1008 else 1009 else
1009 dtp->retrieveFile( waitfile ); 1010 dtp->retrieveFile( waitfile );
1010 dtp->setSocket( socket ); 1011 dtp->setSocket( socket );
1011 } 1012 }
1012 else if ( wait[SendByteArray] ) { 1013 else if ( wait[SendByteArray] ) {
1013 dtp->sendByteArray( waitarray ); 1014 dtp->sendByteArray( waitarray );
1014 dtp->setSocket( socket ); 1015 dtp->setSocket( socket );
1015 } 1016 }
1016 else if ( wait[RetrieveByteArray] ) { 1017 else if ( wait[RetrieveByteArray] ) {
1017 odebug << "retrieve byte array" << oendl; 1018 odebug << "retrieve byte array" << oendl;
1018 dtp->retrieveByteArray(); 1019 dtp->retrieveByteArray();
1019 dtp->setSocket( socket ); 1020 dtp->setSocket( socket );
1020 } 1021 }
1021 else 1022 else
1022 waitsocket = socket; 1023 waitsocket = socket;
1023 1024
1024 for ( int i = 0; i < 4; i++ ) 1025 for ( int i = 0; i < 4; i++ )
1025 wait[i] = FALSE; 1026 wait[i] = FALSE;
1026} 1027}
1027 1028
1028QString ServerPI::absFilePath( const QString& file ) 1029QString ServerPI::absFilePath( const QString& file )
1029{ 1030{
1030 if ( file.isEmpty() ) 1031 if ( file.isEmpty() )
1031 return file; 1032 return file;
1032 1033
1033 QString filepath( file ); 1034 QString filepath( file );
1034 if ( file[0] != "/" ) 1035 if ( file[0] != "/" )
1035 filepath = directory.path() + "/" + file; 1036 filepath = directory.path() + "/" + file;
1036 1037
1037 return filepath; 1038 return filepath;
1038} 1039}
1039 1040
1040 1041
1041void ServerPI::timerEvent( QTimerEvent * ) 1042void ServerPI::timerEvent( QTimerEvent * )
1042{ 1043{
1043 connectionClosed(); 1044 connectionClosed();
1044} 1045}
1045 1046
1046 1047
1047ServerDTP::ServerDTP( QObject *parent, const char* name) 1048ServerDTP::ServerDTP( QObject *parent, const char* name)
1048 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1049 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1049 retrieveTargzProc( 0 ), gzipProc( 0 ) 1050 retrieveTargzProc( 0 ), gzipProc( 0 )
1050{ 1051{
1051 1052
1052 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1053 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1053 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1054 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1054 connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); 1055 connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) );
1055 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1056 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1056 1057
1057 gzipProc = new Opie::Core::OProcess( this, "gzipProc" ); 1058 gzipProc = new Opie::Core::OProcess( this, "gzipProc" );
1058 1059
1059 createTargzProc = new Opie::Core::OProcess( QString("tar"), this, "createTargzProc"); 1060 createTargzProc = new Opie::Core::OProcess( QString("tar"), this, "createTargzProc");
1060 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1061 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1061 connect( createTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), SLOT( targzDone() ) ); 1062 connect( createTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), SLOT( targzDone() ) );
1062 1063
1063 QStringList args = "tar"; 1064 QStringList args = "tar";
1064 args += "-xv"; 1065 args += "-xv";
1065 retrieveTargzProc = new Opie::Core::OProcess( args, this, "retrieveTargzProc" ); 1066 retrieveTargzProc = new Opie::Core::OProcess( args, this, "retrieveTargzProc" );
1066 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1067 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1067 connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), 1068 connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ),
1068 SIGNAL( completed() ) ); 1069 SIGNAL( completed() ) );
1069 connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), 1070 connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ),
1070 SLOT( extractTarDone() ) ); 1071 SLOT( extractTarDone() ) );
1071} 1072}
1072 1073
1073ServerDTP::~ServerDTP() 1074ServerDTP::~ServerDTP()
1074{ 1075{
1075 buf.close(); 1076 buf.close();
1076 file.close(); 1077 file.close();
1077 createTargzProc->kill(); 1078 createTargzProc->kill();
1078} 1079}
1079 1080
1080void ServerDTP::extractTarDone() 1081void ServerDTP::extractTarDone()
1081{ 1082{
1082 odebug << "extract done" << oendl; 1083 odebug << "extract done" << oendl;
1083#ifndef QT_NO_COP 1084#ifndef QT_NO_COP
1084 1085
1085 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 1086 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
1086 e << file.name(); 1087 e << file.name();
1087#endif 1088#endif
1088} 1089}
1089 1090
1090void ServerDTP::connected() 1091void ServerDTP::connected()
1091{ 1092{
1092 // send file mode 1093 // send file mode
1093 switch ( mode ) { 1094 switch ( mode ) {
1094 case SendFile : 1095 case SendFile :
1095 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1096 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1096 emit failed(); 1097 emit failed();
1097 mode = Idle; 1098 mode = Idle;
1098 return ; 1099 return ;
1099 } 1100 }
1100 1101
1101 //odebug << "Debug: Sending file '" << file.name() << "'" << oendl; 1102 //odebug << "Debug: Sending file '" << file.name() << "'" << oendl;
1102 1103
1103 bytes_written = 0; 1104 bytes_written = 0;
1104 if ( file.size() == 0 ) { 1105 if ( file.size() == 0 ) {
1105 //make sure it doesn't hang on empty files 1106 //make sure it doesn't hang on empty files
1106 file.close(); 1107 file.close();
1107 emit completed(); 1108 emit completed();
1108 mode = Idle; 1109 mode = Idle;
1109 } 1110 }
1110 else { 1111 else {
1111 1112
1112 if ( !file.atEnd() ) { 1113 if ( !file.atEnd() ) {
1113 QCString s; 1114 QCString s;
1114 s.resize( block_size ); 1115 s.resize( block_size );
1115 int bytes = file.readBlock( s.data(), block_size ); 1116 int bytes = file.readBlock( s.data(), block_size );
1116 writeBlock( s.data(), bytes ); 1117 writeBlock( s.data(), bytes );
1117 } 1118 }
1118 } 1119 }
1119 break; 1120 break;
1120 case SendGzipFile: 1121 case SendGzipFile:
1121 if ( createTargzProc->isRunning() ) { 1122 if ( createTargzProc->isRunning() ) {
1122 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1123 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1123 owarn << "Previous tar --gzip process is still running; killing it..." << oendl; 1124 owarn << "Previous tar --gzip process is still running; killing it..." << oendl;
1124 createTargzProc->kill(); 1125 createTargzProc->kill();
1125 } 1126 }
1126 1127
1127 bytes_written = 0; 1128 bytes_written = 0;
1128 odebug << "==>start send tar process" << oendl; 1129 odebug << "==>start send tar process" << oendl;
1129 if ( !createTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdout) ) 1130 if ( !createTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdout) )
1130 qWarning("Error starting %s or %s", 1131 owarn << "Error starting " << createTargzProc->args()[0].data()
1131 createTargzProc->args()[0].data(), 1132 << " or " << gzipProc->args()[0].data() << oendl;
1132 gzipProc->args()[0].data());
1133 break; 1133 break;
1134 case SendBuffer: 1134 case SendBuffer:
1135 if ( !buf.open( IO_ReadOnly) ) { 1135 if ( !buf.open( IO_ReadOnly) ) {
1136 emit failed(); 1136 emit failed();
1137 mode = Idle; 1137 mode = Idle;
1138 return ; 1138 return ;
1139 } 1139 }
1140 1140
1141 // odebug << "Debug: Sending byte array" << oendl; 1141 // odebug << "Debug: Sending byte array" << oendl;
1142 bytes_written = 0; 1142 bytes_written = 0;
1143 while ( !buf.atEnd() ) 1143 while ( !buf.atEnd() )
1144 putch( buf.getch() ); 1144 putch( buf.getch() );
1145 buf.close(); 1145 buf.close();
1146 break; 1146 break;
1147 case RetrieveFile: 1147 case RetrieveFile:
1148 // retrieve file mode 1148 // retrieve file mode
1149 if ( file.exists() && !file.remove() ) { 1149 if ( file.exists() && !file.remove() ) {
1150 emit failed(); 1150 emit failed();
1151 mode = Idle; 1151 mode = Idle;
1152 return ; 1152 return ;
1153 } 1153 }
1154 1154
1155 if ( !file.open( IO_WriteOnly) ) { 1155 if ( !file.open( IO_WriteOnly) ) {
1156 emit failed(); 1156 emit failed();
1157 mode = Idle; 1157 mode = Idle;
1158 return ; 1158 return ;
1159 } 1159 }
1160 // odebug << "Debug: Retrieving file " << file.name() << "" << oendl; 1160 // odebug << "Debug: Retrieving file " << file.name() << "" << oendl;
1161 break; 1161 break;
1162 case RetrieveGzipFile: 1162 case RetrieveGzipFile:
1163 odebug << "=-> starting tar process to receive .tgz file" << oendl; 1163 odebug << "=-> starting tar process to receive .tgz file" << oendl;
1164 break; 1164 break;
1165 case RetrieveBuffer: 1165 case RetrieveBuffer:
1166 // retrieve buffer mode 1166 // retrieve buffer mode
1167 if ( !buf.open( IO_WriteOnly) ) { 1167 if ( !buf.open( IO_WriteOnly) ) {
1168 emit failed(); 1168 emit failed();
1169 mode = Idle; 1169 mode = Idle;
1170 return ; 1170 return ;
1171 } 1171 }
1172 // odebug << "Debug: Retrieving byte array" << oendl; 1172 // odebug << "Debug: Retrieving byte array" << oendl;
1173 break; 1173 break;
1174 case Idle: 1174 case Idle:
1175 odebug << "connection established but mode set to Idle; BUG!" << oendl; 1175 odebug << "connection established but mode set to Idle; BUG!" << oendl;
1176 break; 1176 break;
1177 } 1177 }
1178} 1178}
1179 1179
1180void ServerDTP::connectionClosed() 1180void ServerDTP::connectionClosed()
1181{ 1181{
1182 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; 1182 //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl;
1183 1183
1184 // send file mode 1184 // send file mode
1185 if ( SendFile == mode ) { 1185 if ( SendFile == mode ) {
1186 if ( bytes_written == file.size() ) 1186 if ( bytes_written == file.size() )
1187 emit completed(); 1187 emit completed();
1188 else 1188 else
1189 emit failed(); 1189 emit failed();
1190 } 1190 }
1191 1191
1192 // send buffer mode 1192 // send buffer mode
1193 else if ( SendBuffer == mode ) { 1193 else if ( SendBuffer == mode ) {
1194 if ( bytes_written == buf.size() ) 1194 if ( bytes_written == buf.size() )
1195 emit completed(); 1195 emit completed();
1196 else 1196 else
1197 emit failed(); 1197 emit failed();
1198 } 1198 }
1199 1199
1200 // retrieve file mode 1200 // retrieve file mode
1201 else if ( RetrieveFile == mode ) { 1201 else if ( RetrieveFile == mode ) {
1202 file.close(); 1202 file.close();
1203 emit completed(); 1203 emit completed();
1204 } 1204 }
1205 1205
1206 else if ( RetrieveGzipFile == mode ) { 1206 else if ( RetrieveGzipFile == mode ) {
1207 odebug << "Done writing ungzip file; closing input" << oendl; 1207 odebug << "Done writing ungzip file; closing input" << oendl;
1208 gzipProc->flushStdin(); 1208 gzipProc->flushStdin();
1209 gzipProc->closeStdin(); 1209 gzipProc->closeStdin();
1210 } 1210 }
1211 1211
1212 // retrieve buffer mode 1212 // retrieve buffer mode
1213 else if ( RetrieveBuffer == mode ) { 1213 else if ( RetrieveBuffer == mode ) {
1214 buf.close(); 1214 buf.close();
1215 emit completed(); 1215 emit completed();
1216 } 1216 }
1217 1217
1218 mode = Idle; 1218 mode = Idle;
1219} 1219}
1220 1220
1221void ServerDTP::bytesWritten( int bytes ) 1221void ServerDTP::bytesWritten( int bytes )
1222{ 1222{
1223 bytes_written += bytes; 1223 bytes_written += bytes;
1224 1224
1225 // send file mode 1225 // send file mode
1226 if ( SendFile == mode ) { 1226 if ( SendFile == mode ) {
1227 1227
1228 if ( bytes_written == file.size() ) { 1228 if ( bytes_written == file.size() ) {
1229 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; 1229 // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl;
1230 file.close(); 1230 file.close();
1231 emit completed(); 1231 emit completed();
1232 mode = Idle; 1232 mode = Idle;
1233 } 1233 }
1234 else if ( !file.atEnd() ) { 1234 else if ( !file.atEnd() ) {
1235 QCString s; 1235 QCString s;
1236 s.resize( block_size ); 1236 s.resize( block_size );
1237 int bytes = file.readBlock( s.data(), block_size ); 1237 int bytes = file.readBlock( s.data(), block_size );
1238 writeBlock( s.data(), bytes ); 1238 writeBlock( s.data(), bytes );
1239 } 1239 }
1240 } 1240 }
1241 1241
1242 // send buffer mode 1242 // send buffer mode
1243 if ( SendBuffer == mode ) { 1243 if ( SendBuffer == mode ) {
1244 1244
1245 if ( bytes_written == buf.size() ) { 1245 if ( bytes_written == buf.size() ) {
1246 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; 1246 // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl;
1247 emit completed(); 1247 emit completed();
1248 mode = Idle; 1248 mode = Idle;
1249 } 1249 }
1250 } 1250 }
1251} 1251}
1252 1252
1253void ServerDTP::readyRead() 1253void ServerDTP::readyRead()
1254{ 1254{
1255 // retrieve file mode 1255 // retrieve file mode
1256 if ( RetrieveFile == mode ) { 1256 if ( RetrieveFile == mode ) {
1257 QCString s; 1257 QCString s;
1258 s.resize( bytesAvailable() ); 1258 s.resize( bytesAvailable() );
1259 readBlock( s.data(), bytesAvailable() ); 1259 readBlock( s.data(), bytesAvailable() );
1260 file.writeBlock( s.data(), s.size() ); 1260 file.writeBlock( s.data(), s.size() );
1261 } 1261 }
1262 else if ( RetrieveGzipFile == mode ) { 1262 else if ( RetrieveGzipFile == mode ) {
1263 if ( !gzipProc->isRunning() ) 1263 if ( !gzipProc->isRunning() )
1264 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); 1264 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout ));
1265 1265
1266 QByteArray s; 1266 QByteArray s;
1267 s.resize( bytesAvailable() ); 1267 s.resize( bytesAvailable() );
1268 readBlock( s.data(), bytesAvailable() ); 1268 readBlock( s.data(), bytesAvailable() );
1269 gzipProc->writeStdin( s.data(), s.size() ); 1269 gzipProc->writeStdin( s.data(), s.size() );
1270 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; 1270 odebug << "wrote " << s.size() << " bytes to ungzip " << oendl;
1271 } 1271 }
1272 // retrieve buffer mode 1272 // retrieve buffer mode
1273 else if ( RetrieveBuffer == mode ) { 1273 else if ( RetrieveBuffer == mode ) {
1274 QCString s; 1274 QCString s;
1275 s.resize( bytesAvailable() ); 1275 s.resize( bytesAvailable() );
1276 readBlock( s.data(), bytesAvailable() ); 1276 readBlock( s.data(), bytesAvailable() );
1277 buf.writeBlock( s.data(), s.size() ); 1277 buf.writeBlock( s.data(), s.size() );
1278 } 1278 }
1279} 1279}
1280 1280
1281void ServerDTP::writeTargzBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1281void ServerDTP::writeTargzBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1282{ 1282{
1283 writeBlock( buffer, buflen ); 1283 writeBlock( buffer, buflen );
1284 odebug << "writeTargzBlock " << buflen << "" << oendl; 1284 odebug << "writeTargzBlock " << buflen << "" << oendl;
1285 if ( !createTargzProc->isRunning() ) { 1285 if ( !createTargzProc->isRunning() ) {
1286 odebug << "tar and gzip done" << oendl; 1286 odebug << "tar and gzip done" << oendl;
1287 emit completed(); 1287 emit completed();
1288 mode = Idle; 1288 mode = Idle;
1289 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1289 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1290 this, SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); 1290 this, SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) );
1291 } 1291 }
1292} 1292}
1293 1293
1294void ServerDTP::targzDone() 1294void ServerDTP::targzDone()
1295{ 1295{
1296 //odebug << "targz done" << oendl; 1296 //odebug << "targz done" << oendl;
1297 disconnect( createTargzProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1297 disconnect( createTargzProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1298 this, SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); 1298 this, SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) );
1299 gzipProc->closeStdin(); 1299 gzipProc->closeStdin();
1300} 1300}
1301 1301
1302void ServerDTP::gzipTarBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1302void ServerDTP::gzipTarBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1303{ 1303{
1304 //odebug << "gzipTarBlock" << oendl; 1304 //odebug << "gzipTarBlock" << oendl;
1305 if ( !gzipProc->isRunning() ) { 1305 if ( !gzipProc->isRunning() ) {
1306 //odebug << "auto start gzip proc" << oendl; 1306 //odebug << "auto start gzip proc" << oendl;
1307 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); 1307 gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout ));
1308 } 1308 }
1309 gzipProc->writeStdin( buffer, buflen ); 1309 gzipProc->writeStdin( buffer, buflen );
1310} 1310}
1311 1311
1312void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1312void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1313{ 1313{
1314 file.setName( fn ); 1314 file.setName( fn );
1315 mode = SendFile; 1315 mode = SendFile;
1316 connectToHost( host.toString(), port ); 1316 connectToHost( host.toString(), port );
1317} 1317}
1318 1318
1319void ServerDTP::sendFile( const QString fn ) 1319void ServerDTP::sendFile( const QString fn )
1320{ 1320{
1321 file.setName( fn ); 1321 file.setName( fn );
1322 mode = SendFile; 1322 mode = SendFile;
1323} 1323}
1324 1324
1325void ServerDTP::sendGzipFile( const QString &fn, 1325void ServerDTP::sendGzipFile( const QString &fn,
1326 const QStringList &archiveTargets, 1326 const QStringList &archiveTargets,
1327 const QHostAddress& host, Q_UINT16 port ) 1327 const QHostAddress& host, Q_UINT16 port )
1328{ 1328{
1329 sendGzipFile( fn, archiveTargets ); 1329 sendGzipFile( fn, archiveTargets );
1330 connectToHost( host.toString(), port ); 1330 connectToHost( host.toString(), port );
1331} 1331}
1332 1332
1333void ServerDTP::sendGzipFile( const QString &fn, 1333void ServerDTP::sendGzipFile( const QString &fn,
1334 const QStringList &archiveTargets ) 1334 const QStringList &archiveTargets )
1335{ 1335{
1336 mode = SendGzipFile; 1336 mode = SendGzipFile;
1337 file.setName( fn ); 1337 file.setName( fn );
1338 1338
1339 QStringList args = "tar"; 1339 QStringList args = "tar";
1340 args += "-cv"; 1340 args += "-cv";
1341 args += archiveTargets; 1341 args += archiveTargets;
1342 odebug << "sendGzipFile " << args.join(" ") << "" << oendl; 1342 odebug << "sendGzipFile " << args.join(" ") << "" << oendl;
1343 createTargzProc->clearArguments( ); 1343 createTargzProc->clearArguments( );
1344 *createTargzProc << args; 1344 *createTargzProc << args;
1345 connect( createTargzProc, 1345 connect( createTargzProc,
1346 SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); 1346 SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) );
1347 1347
1348 gzipProc->clearArguments( ); 1348 gzipProc->clearArguments( );
1349 *gzipProc << "gzip"; 1349 *gzipProc << "gzip";
1350 connect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1350 connect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1351 SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); 1351 SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) );
1352} 1352}
1353 1353
1354void ServerDTP::gunzipDone() 1354void ServerDTP::gunzipDone()
1355{ 1355{
1356 odebug << "gunzipDone" << oendl; 1356 odebug << "gunzipDone" << oendl;
1357 disconnect( gzipProc, SIGNAL( processExited() ), 1357 disconnect( gzipProc, SIGNAL( processExited() ),
1358 this, SLOT( gunzipDone() ) ); 1358 this, SLOT( gunzipDone() ) );
1359 retrieveTargzProc->closeStdin(); 1359 retrieveTargzProc->closeStdin();
1360 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), 1360 disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ),
1361 this, SLOT( tarExtractBlock(Opie::Core::OProcess*,char*,int) ) ); 1361 this, SLOT( tarExtractBlock(Opie::Core::OProcess*,char*,int) ) );
1362} 1362}
1363 1363
1364void ServerDTP::tarExtractBlock(Opie::Core::OProcess *, char *buffer, int buflen) 1364void ServerDTP::tarExtractBlock(Opie::Core::OProcess *, char *buffer, int buflen)
1365{ 1365{
1366 odebug << "tarExtractBlock" << oendl; 1366 odebug << "tarExtractBlock" << oendl;
1367 if ( !retrieveTargzProc->isRunning() ) { 1367 if ( !retrieveTargzProc->isRunning() ) {
1368 odebug << "auto start ungzip proc" << oendl; 1368 odebug << "auto start ungzip proc" << oendl;
1369 if ( !retrieveTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdin) ) 1369 if ( !retrieveTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdin) )
1370 owarn << " failed to start tar -x process" << oendl; 1370 owarn << " failed to start tar -x process" << oendl;
1371 } 1371 }
1372 retrieveTargzProc->writeStdin( buffer, buflen ); 1372 retrieveTargzProc->writeStdin( buffer, buflen );
1373} 1373}
1374 1374
1375 1375
1376void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1376void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1377{ 1377{
1378 file.setName( fn ); 1378 file.setName( fn );
1379 mode = RetrieveFile; 1379 mode = RetrieveFile;
1380 connectToHost( host.toString(), port ); 1380 connectToHost( host.toString(), port );
1381} 1381}
1382 1382
1383void ServerDTP::retrieveFile( const QString fn ) 1383void ServerDTP::retrieveFile( const QString fn )
1384{ 1384{
1385 file.setName( fn ); 1385 file.setName( fn );
1386 mode = RetrieveFile; 1386 mode = RetrieveFile;
1387} 1387}
1388 1388
1389void ServerDTP::retrieveGzipFile( const QString &fn ) 1389void ServerDTP::retrieveGzipFile( const QString &fn )
1390{ 1390{
1391 odebug << "retrieveGzipFile " << fn << "" << oendl; 1391 odebug << "retrieveGzipFile " << fn << "" << oendl;
1392 file.setName( fn ); 1392 file.setName( fn );
1393 mode = RetrieveGzipFile; 1393 mode = RetrieveGzipFile;
1394 1394
1395 gzipProc->clearArguments(); 1395 gzipProc->clearArguments();
1396 *gzipProc << "gunzip"; 1396 *gzipProc << "gunzip";
1397 connect( gzipProc, SIGNAL( readyReadStdout() ), 1397 connect( gzipProc, SIGNAL( readyReadStdout() ),
1398 SLOT( tarExtractBlock() ) ); 1398 SLOT( tarExtractBlock() ) );
1399 connect( gzipProc, SIGNAL( processExited() ), 1399 connect( gzipProc, SIGNAL( processExited() ),
1400 SLOT( gunzipDone() ) ); 1400 SLOT( gunzipDone() ) );
1401} 1401}
1402 1402
1403void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1403void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1404{ 1404{
1405 retrieveGzipFile( fn ); 1405 retrieveGzipFile( fn );
1406 connectToHost( host.toString(), port ); 1406 connectToHost( host.toString(), port );
1407} 1407}
1408 1408
1409void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1409void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1410{ 1410{
1411 buf.setBuffer( array ); 1411 buf.setBuffer( array );
1412 mode = SendBuffer; 1412 mode = SendBuffer;
1413 connectToHost( host.toString(), port ); 1413 connectToHost( host.toString(), port );
1414} 1414}
1415 1415
1416void ServerDTP::sendByteArray( const QByteArray& array ) 1416void ServerDTP::sendByteArray( const QByteArray& array )
1417{ 1417{
1418 buf.setBuffer( array ); 1418 buf.setBuffer( array );
1419 mode = SendBuffer; 1419 mode = SendBuffer;
1420} 1420}
1421 1421
1422void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1422void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1423{ 1423{
1424 buf.setBuffer( QByteArray() ); 1424 buf.setBuffer( QByteArray() );
1425 mode = RetrieveBuffer; 1425 mode = RetrieveBuffer;
1426 connectToHost( host.toString(), port ); 1426 connectToHost( host.toString(), port );
1427} 1427}
1428 1428
1429void ServerDTP::retrieveByteArray() 1429void ServerDTP::retrieveByteArray()
1430{ 1430{
1431 buf.setBuffer( QByteArray() ); 1431 buf.setBuffer( QByteArray() );
1432 mode = RetrieveBuffer; 1432 mode = RetrieveBuffer;
1433} 1433}
1434 1434
1435void ServerDTP::setSocket( int socket ) 1435void ServerDTP::setSocket( int socket )
1436{ 1436{
1437 QSocket::setSocket( socket ); 1437 QSocket::setSocket( socket );
1438 connected(); 1438 connected();
1439} 1439}
1440 1440