summaryrefslogtreecommitdiff
authorchicken <chicken>2004-03-01 17:44:52 (UTC)
committer chicken <chicken>2004-03-01 17:44:52 (UTC)
commit5b640d3f070b0b2de361421abf93949410546e19 (patch) (unidiff)
tree98d6ebb158e780a299cca27cbb7c7105a8dedef3
parentbdac663be648746b868757a6fc9e6c443e6f51b1 (diff)
downloadopie-5b640d3f070b0b2de361421abf93949410546e19.zip
opie-5b640d3f070b0b2de361421abf93949410546e19.tar.gz
opie-5b640d3f070b0b2de361421abf93949410546e19.tar.bz2
fix includes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/qws/main.cpp2
-rw-r--r--core/qws/oqwsserver.cpp15
-rw-r--r--core/qws/qcopbridge.cpp6
-rw-r--r--core/qws/transferserver.cpp8
4 files changed, 0 insertions, 31 deletions
diff --git a/core/qws/main.cpp b/core/qws/main.cpp
index bfed283..1c3c621 100644
--- a/core/qws/main.cpp
+++ b/core/qws/main.cpp
@@ -1,71 +1,69 @@
1#include <qwindowsystem_qws.h>
2#include <qapplication.h>
3 1
4#include "oqwsserver.h" 2#include "oqwsserver.h"
5 3
6#include <sys/types.h> 4#include <sys/types.h>
7#include <sys/stat.h> 5#include <sys/stat.h>
8#include <fcntl.h> 6#include <fcntl.h>
9#include <unistd.h> 7#include <unistd.h>
10 8
11#include <syslog.h> 9#include <syslog.h>
12#include <stdio.h> 10#include <stdio.h>
13 11
14#define APPNAME "op-qws" 12#define APPNAME "op-qws"
15 13
16void toSyslog(QtMsgType type, const char *msg) 14void toSyslog(QtMsgType type, const char *msg)
17{ 15{
18 int level = LOG_INFO; 16 int level = LOG_INFO;
19 switch (type) { 17 switch (type) {
20 case QtDebugMsg: 18 case QtDebugMsg:
21 level = LOG_DEBUG; 19 level = LOG_DEBUG;
22 break; 20 break;
23 case QtWarningMsg: 21 case QtWarningMsg:
24 level = LOG_WARNING; 22 level = LOG_WARNING;
25 break; 23 break;
26 case QtFatalMsg: 24 case QtFatalMsg:
27 level = LOG_ERR; 25 level = LOG_ERR;
28 break; 26 break;
29 } 27 }
30 syslog (LOG_DAEMON | level, msg); 28 syslog (LOG_DAEMON | level, msg);
31} 29}
32 30
33int daemon_init(void) 31int daemon_init(void)
34{ 32{
35 pid_t pid; 33 pid_t pid;
36 34
37 if ((pid = fork()) < 0) 35 if ((pid = fork()) < 0)
38 return(-1); 36 return(-1);
39 else if (pid != 0) 37 else if (pid != 0)
40 exit(0); 38 exit(0);
41 39
42 setsid(); 40 setsid();
43 41
44 chdir("/"); 42 chdir("/");
45 43
46 umask(0); 44 umask(0);
47 45
48 fclose(stdout); 46 fclose(stdout);
49 fclose(stderr); 47 fclose(stderr);
50 fclose(stdin); 48 fclose(stdin);
51 49
52 return(0); 50 return(0);
53} 51}
54 52
55int main( int argc, char ** argv ) 53int main( int argc, char ** argv )
56{ 54{
57 while (argc > 1) { 55 while (argc > 1) {
58 if (strcmp(argv[--argc], "-d") == 0) { 56 if (strcmp(argv[--argc], "-d") == 0) {
59 // daemonize 57 // daemonize
60 openlog(APPNAME, 0, LOG_DAEMON); 58 openlog(APPNAME, 0, LOG_DAEMON);
61 qInstallMsgHandler(toSyslog); 59 qInstallMsgHandler(toSyslog);
62 if (daemon_init() != 0) { 60 if (daemon_init() != 0) {
63 fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME); 61 fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME);
64 return 1; 62 return 1;
65 } 63 }
66 } 64 }
67 } 65 }
68 66
69 OQWSServer a(argc, argv, QApplication::GuiServer); 67 OQWSServer a(argc, argv, QApplication::GuiServer);
70 return a.exec(); 68 return a.exec();
71} 69}
diff --git a/core/qws/oqwsserver.cpp b/core/qws/oqwsserver.cpp
index 1c61d19..907686a 100644
--- a/core/qws/oqwsserver.cpp
+++ b/core/qws/oqwsserver.cpp
@@ -1,196 +1,181 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 <syslog.h> 21#include <syslog.h>
22 22
23#include "oqwsserver.h" 23#include "oqwsserver.h"
24#include "qcopbridge.h" 24#include "qcopbridge.h"
25#include "transferserver.h" 25#include "transferserver.h"
26 26
27#include <qpe/applnk.h>
28#include <qpe/mimetype.h>
29#include <qpe/password.h>
30#include <qpe/config.h>
31#include <qpe/power.h>
32#include <qpe/timeconversion.h>
33#include <qpe/qcopenvelope_qws.h>
34#include <qpe/network.h>
35#include <qpe/global.h>
36 27
37#if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) 28#if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ )
38#include <qpe/custom.h> 29#include <qpe/custom.h>
39#endif 30#endif
40 31
41#include <opie/odevice.h> 32#include <opie/odevice.h>
42 33
43#include <qgfx_qws.h>
44#include <qmainwindow.h>
45#include <qmessagebox.h>
46#include <qtimer.h>
47#include <qwindowsystem_qws.h>
48 34
49#include <qvaluelist.h>
50 35
51#include <stdlib.h> 36#include <stdlib.h>
52#include <unistd.h> 37#include <unistd.h>
53#include <fcntl.h> 38#include <fcntl.h>
54 39
55using namespace Opie; 40using namespace Opie;
56 41
57OQWSServer::OQWSServer( int& argc, char **argv, Type appType ) 42OQWSServer::OQWSServer( int& argc, char **argv, Type appType )
58 : QPEApplication( argc, argv, appType ) 43 : QPEApplication( argc, argv, appType )
59{ 44{
60 startServers(); 45 startServers();
61} 46}
62 47
63OQWSServer::~OQWSServer() 48OQWSServer::~OQWSServer()
64{ 49{
65 terminateServers(); 50 terminateServers();
66} 51}
67 52
68bool OQWSServer::eventFilter ( QObject *o, QEvent *e ) 53bool OQWSServer::eventFilter ( QObject *o, QEvent *e )
69{ 54{
70#if 0 55#if 0
71 if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { 56 if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) {
72 QKeyEvent *ke = (QKeyEvent *) e; 57 QKeyEvent *ke = (QKeyEvent *) e;
73 58
74 const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); 59 const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( ));
75 60
76 if ( db ) { 61 if ( db ) {
77 if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) 62 if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( )))
78 return true; //checkButtonAction retrune false if events should be routed through 63 return true; //checkButtonAction retrune false if events should be routed through
79 } 64 }
80 } 65 }
81#endif 66#endif
82 return QPEApplication::eventFilter ( o, e ); 67 return QPEApplication::eventFilter ( o, e );
83} 68}
84 69
85#ifdef Q_WS_QWS 70#ifdef Q_WS_QWS
86 71
87bool OQWSServer::qwsEventFilter( QWSEvent *e ) 72bool OQWSServer::qwsEventFilter( QWSEvent *e )
88{ 73{
89#if 0 74#if 0
90 qpedesktop->checkMemory(); 75 qpedesktop->checkMemory();
91 76
92 if ( e->type == QWSEvent::Key ) { 77 if ( e->type == QWSEvent::Key ) {
93 QWSKeyEvent * ke = (QWSKeyEvent *) e; 78 QWSKeyEvent * ke = (QWSKeyEvent *) e;
94 ushort keycode = ke-> simpleData. keycode; 79 ushort keycode = ke-> simpleData. keycode;
95 80
96 if ( !loggedin && keycode != Key_F34 ) 81 if ( !loggedin && keycode != Key_F34 )
97 return true; 82 return true;
98 83
99 bool press = ke-> simpleData. is_press; 84 bool press = ke-> simpleData. is_press;
100 bool autoRepeat = ke-> simpleData. is_auto_repeat; 85 bool autoRepeat = ke-> simpleData. is_auto_repeat;
101 86
102 if ( !keyboardGrabbed ( )) { 87 if ( !keyboardGrabbed ( )) {
103 // app that registers key/message to be sent back to the app, when it doesn't have focus, 88 // app that registers key/message to be sent back to the app, when it doesn't have focus,
104 // when user presses key, unless keyboard has been requested from app. 89 // when user presses key, unless keyboard has been requested from app.
105 // will not send multiple repeats if user holds key 90 // will not send multiple repeats if user holds key
106 // i.e. one shot 91 // i.e. one shot
107 92
108 if ( keycode != 0 && press && !autoRepeat ) { 93 if ( keycode != 0 && press && !autoRepeat ) {
109 for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 94 for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
110 if (( *it ). getKeyCode ( ) == keycode ) { 95 if (( *it ). getKeyCode ( ) == keycode ) {
111 QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); 96 QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( ));
112 return true; 97 return true;
113 } 98 }
114 } 99 }
115 } 100 }
116 } 101 }
117 102
118 if ( keycode == HardKey_Suspend ) { 103 if ( keycode == HardKey_Suspend ) {
119 if ( press ) 104 if ( press )
120 emit power ( ); 105 emit power ( );
121 return true; 106 return true;
122 } 107 }
123 else if ( keycode == HardKey_Backlight ) { 108 else if ( keycode == HardKey_Backlight ) {
124 if ( press ) 109 if ( press )
125 emit backlight ( ); 110 emit backlight ( );
126 return true; 111 return true;
127 } 112 }
128 else if ( keycode == Key_F32 ) { 113 else if ( keycode == Key_F32 ) {
129 if ( press ) 114 if ( press )
130 QCopEnvelope e( "QPE/Desktop", "startSync()" ); 115 QCopEnvelope e( "QPE/Desktop", "startSync()" );
131 return true; 116 return true;
132 } 117 }
133 else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM 118 else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM
134 if ( press ) 119 if ( press )
135 emit symbol ( ); 120 emit symbol ( );
136 return true; 121 return true;
137 } 122 }
138 else if ( keycode == Key_NumLock ) { 123 else if ( keycode == Key_NumLock ) {
139 if ( press ) 124 if ( press )
140 emit numLockStateToggle ( ); 125 emit numLockStateToggle ( );
141 } 126 }
142 else if ( keycode == Key_CapsLock ) { 127 else if ( keycode == Key_CapsLock ) {
143 if ( press ) 128 if ( press )
144 emit capsLockStateToggle(); 129 emit capsLockStateToggle();
145 } 130 }
146 if (( press && !autoRepeat ) || ( !press && autoRepeat )) { 131 if (( press && !autoRepeat ) || ( !press && autoRepeat )) {
147 if ( m_keyclick_sound ) 132 if ( m_keyclick_sound )
148 ODevice::inst ( )-> keySound ( ); 133 ODevice::inst ( )-> keySound ( );
149 } 134 }
150 } 135 }
151 else if ( e-> type == QWSEvent::Mouse ) { 136 else if ( e-> type == QWSEvent::Mouse ) {
152 QWSMouseEvent * me = ( QWSMouseEvent * ) e; 137 QWSMouseEvent * me = ( QWSMouseEvent * ) e;
153 static bool up = true; 138 static bool up = true;
154 139
155 if ( me-> simpleData. state & LeftButton ) { 140 if ( me-> simpleData. state & LeftButton ) {
156 if ( up ) { 141 if ( up ) {
157 up = false; 142 up = false;
158 if ( m_screentap_sound ) 143 if ( m_screentap_sound )
159 ODevice::inst ( ) -> touchSound ( ); 144 ODevice::inst ( ) -> touchSound ( );
160 } 145 }
161 } 146 }
162 else { 147 else {
163 up = true; 148 up = true;
164 } 149 }
165 } 150 }
166#endif 151#endif
167 return QPEApplication::qwsEventFilter ( e ); 152 return QPEApplication::qwsEventFilter ( e );
168} 153}
169 154
170#endif 155#endif
171 156
172void OQWSServer::startServers() 157void OQWSServer::startServers()
173{ 158{
174 // start qcop bridge server 159 // start qcop bridge server
175 m_qcopBridge = new QCopBridge( 4243 ); 160 m_qcopBridge = new QCopBridge( 4243 );
176 if ( !m_qcopBridge->ok() ) { 161 if ( !m_qcopBridge->ok() ) {
177 delete m_qcopBridge; 162 delete m_qcopBridge;
178 m_qcopBridge = 0; 163 m_qcopBridge = 0;
179 } 164 }
180 // start transfer server 165 // start transfer server
181 m_transferServer = new TransferServer( 4242 ); 166 m_transferServer = new TransferServer( 4242 );
182 if ( !m_transferServer->ok() ) { 167 if ( !m_transferServer->ok() ) {
183 delete m_transferServer; 168 delete m_transferServer;
184 m_transferServer = 0; 169 m_transferServer = 0;
185 } 170 }
186 //if ( !transferServer || !qcopBridge ) 171 //if ( !transferServer || !qcopBridge )
187 // startTimer( 2000 ); 172 // startTimer( 2000 );
188} 173}
189 174
190void OQWSServer::terminateServers() 175void OQWSServer::terminateServers()
191{ 176{
192 delete m_transferServer; 177 delete m_transferServer;
193 delete m_qcopBridge; 178 delete m_qcopBridge;
194 m_transferServer = 0; 179 m_transferServer = 0;
195 m_qcopBridge = 0; 180 m_qcopBridge = 0;
196} 181}
diff --git a/core/qws/qcopbridge.cpp b/core/qws/qcopbridge.cpp
index 6177a7c..c0c52e8 100644
--- a/core/qws/qcopbridge.cpp
+++ b/core/qws/qcopbridge.cpp
@@ -1,226 +1,220 @@
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 "qcopbridge.h" 21#include "qcopbridge.h"
22#include "transferserver.h" 22#include "transferserver.h"
23 23
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/version.h> 26#include <qpe/version.h>
27 27
28#include <qdir.h>
29#include <qfile.h>
30#include <qtextstream.h> 28#include <qtextstream.h>
31#include <qdatastream.h>
32#include <qstringlist.h>
33#include <qfileinfo.h>
34#include <qregexp.h>
35#ifdef QWS 29#ifdef QWS
36#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
37#endif 31#endif
38 32
39#define _XOPEN_SOURCE 33#define _XOPEN_SOURCE
40#include <pwd.h> 34#include <pwd.h>
41#include <sys/types.h> 35#include <sys/types.h>
42#include <unistd.h> 36#include <unistd.h>
43 37
44#if defined(_OS_LINUX_) 38#if defined(_OS_LINUX_)
45#include <shadow.h> 39#include <shadow.h>
46#endif 40#endif
47 41
48//#define INSECURE 42//#define INSECURE
49 43
50const int block_size = 51200; 44const int block_size = 51200;
51 45
52QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , 46QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
53 const char* name ) 47 const char* name )
54 : QServerSocket( port, 1, parent, name ), 48 : QServerSocket( port, 1, parent, name ),
55 desktopChannel( 0 ), 49 desktopChannel( 0 ),
56 cardChannel( 0 ) 50 cardChannel( 0 )
57{ 51{
58 if ( !ok() ) 52 if ( !ok() )
59 qWarning( "Failed to bind to port %d", port ); 53 qWarning( "Failed to bind to port %d", port );
60 else { 54 else {
61#ifndef QT_NO_COP 55#ifndef QT_NO_COP
62 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 56 desktopChannel = new QCopChannel( "QPE/Desktop", this );
63 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 57 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
64 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 58 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
65 cardChannel = new QCopChannel( "QPE/Card", this ); 59 cardChannel = new QCopChannel( "QPE/Card", this );
66 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 60 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
67 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 61 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
68#endif 62#endif
69 } 63 }
70 sendSync = FALSE; 64 sendSync = FALSE;
71} 65}
72 66
73QCopBridge::~QCopBridge() 67QCopBridge::~QCopBridge()
74{ 68{
75#ifndef QT_NO_COP 69#ifndef QT_NO_COP
76 delete desktopChannel; 70 delete desktopChannel;
77#endif 71#endif
78} 72}
79 73
80void QCopBridge::newConnection( int socket ) 74void QCopBridge::newConnection( int socket )
81{ 75{
82 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 76 QCopBridgePI *pi = new QCopBridgePI( socket, this );
83 openConnections.append( pi ); 77 openConnections.append( pi );
84 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); 78 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
85#ifndef QT_NO_COP 79#ifndef QT_NO_COP
86 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 80 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
87#endif 81#endif
88 82
89 if ( sendSync ) { 83 if ( sendSync ) {
90 pi ->startSync(); 84 pi ->startSync();
91 sendSync = FALSE; 85 sendSync = FALSE;
92 } 86 }
93} 87}
94 88
95void QCopBridge::connectionClosed( QCopBridgePI *pi ) 89void QCopBridge::connectionClosed( QCopBridgePI *pi )
96{ 90{
97 openConnections.remove( pi ); 91 openConnections.remove( pi );
98 if ( openConnections.count() == 0 ) { 92 if ( openConnections.count() == 0 ) {
99#ifndef QT_NO_COP 93#ifndef QT_NO_COP
100 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 94 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
101#endif 95#endif
102 } 96 }
103} 97}
104 98
105void QCopBridge::closeOpenConnections() 99void QCopBridge::closeOpenConnections()
106{ 100{
107 QCopBridgePI *pi; 101 QCopBridgePI *pi;
108 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 102 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
109 pi->close(); 103 pi->close();
110} 104}
111 105
112 106
113void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) 107void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args )
114{ 108{
115 command.stripWhiteSpace(); 109 command.stripWhiteSpace();
116 110
117 int paren = command.find( "(" ); 111 int paren = command.find( "(" );
118 if ( paren <= 0 ) { 112 if ( paren <= 0 ) {
119 qDebug("DesktopMessage: bad qcop syntax"); 113 qDebug("DesktopMessage: bad qcop syntax");
120 return; 114 return;
121 } 115 }
122 116
123 QString params = command.mid( paren + 1 ); 117 QString params = command.mid( paren + 1 );
124 if ( params[params.length()-1] != ')' ) { 118 if ( params[params.length()-1] != ')' ) {
125 qDebug("DesktopMessage: bad qcop syntax"); 119 qDebug("DesktopMessage: bad qcop syntax");
126 return; 120 return;
127 } 121 }
128 122
129 params.truncate( params.length()-1 ); 123 params.truncate( params.length()-1 );
130 124
131 QStringList paramList = QStringList::split( ",", params ); 125 QStringList paramList = QStringList::split( ",", params );
132 QString data; 126 QString data;
133 if ( paramList.count() ) { 127 if ( paramList.count() ) {
134 QDataStream stream( args, IO_ReadOnly ); 128 QDataStream stream( args, IO_ReadOnly );
135 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 129 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
136 QString str; 130 QString str;
137 if ( *it == "QString" ) { 131 if ( *it == "QString" ) {
138 stream >> str; 132 stream >> str;
139 } else if ( *it == "QCString" ) { 133 } else if ( *it == "QCString" ) {
140 QCString cstr; 134 QCString cstr;
141 stream >> cstr; 135 stream >> cstr;
142 str = QString::fromLocal8Bit( cstr ); 136 str = QString::fromLocal8Bit( cstr );
143 } else if ( *it == "int" ) { 137 } else if ( *it == "int" ) {
144 int i; 138 int i;
145 stream >> i; 139 stream >> i;
146 str = QString::number( i ); 140 str = QString::number( i );
147 } else if ( *it == "bool" ) { 141 } else if ( *it == "bool" ) {
148 int i; 142 int i;
149 stream >> i; 143 stream >> i;
150 str = QString::number( i ); 144 str = QString::number( i );
151 } else { 145 } else {
152 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 146 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
153 return; 147 return;
154 } 148 }
155 QString estr; 149 QString estr;
156 for (int i=0; i<(int)str.length(); i++) { 150 for (int i=0; i<(int)str.length(); i++) {
157 QChar ch = str[i]; 151 QChar ch = str[i];
158 if ( ch.row() ) 152 if ( ch.row() )
159 goto quick; 153 goto quick;
160 switch (ch.cell()) { 154 switch (ch.cell()) {
161 case '&': 155 case '&':
162 estr.append( "&amp;" ); 156 estr.append( "&amp;" );
163 break; 157 break;
164 case ' ': 158 case ' ':
165 estr.append( "&0x20;" ); 159 estr.append( "&0x20;" );
166 break; 160 break;
167 case '\n': 161 case '\n':
168 estr.append( "&0x0d;" ); 162 estr.append( "&0x0d;" );
169 break; 163 break;
170 case '\r': 164 case '\r':
171 estr.append( "&0x0a;" ); 165 estr.append( "&0x0a;" );
172 break; 166 break;
173 default: quick: 167 default: quick:
174 estr.append(ch); 168 estr.append(ch);
175 } 169 }
176 } 170 }
177 data += " " + estr; 171 data += " " + estr;
178 } 172 }
179 } 173 }
180 QString sendCommand = QString(command.data()) + data; 174 QString sendCommand = QString(command.data()) + data;
181 // send the command to all open connections 175 // send the command to all open connections
182 if ( command == "startSync()" ) { 176 if ( command == "startSync()" ) {
183 // we need to buffer it a bit 177 // we need to buffer it a bit
184 sendSync = TRUE; 178 sendSync = TRUE;
185 startTimer( 20000 ); 179 startTimer( 20000 );
186 } 180 }
187 181
188 QCopBridgePI *pi; 182 QCopBridgePI *pi;
189 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 183 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
190 pi->sendDesktopMessage( sendCommand ); 184 pi->sendDesktopMessage( sendCommand );
191 } 185 }
192} 186}
193 187
194void QCopBridge::timerEvent( QTimerEvent * ) 188void QCopBridge::timerEvent( QTimerEvent * )
195{ 189{
196 sendSync = FALSE; 190 sendSync = FALSE;
197 killTimers(); 191 killTimers();
198} 192}
199 193
200 194
201QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) 195QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
202 : QSocket( parent, name ) 196 : QSocket( parent, name )
203{ 197{
204 setSocket( socket ); 198 setSocket( socket );
205 199
206 peerport = peerPort(); 200 peerport = peerPort();
207 peeraddress = peerAddress(); 201 peeraddress = peerAddress();
208 202
209#ifndef INSECURE 203#ifndef INSECURE
210 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 204 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
211 state = Forbidden; 205 state = Forbidden;
212 startTimer( 0 ); 206 startTimer( 0 );
213 } else 207 } else
214 #endif 208 #endif
215 { 209 {
216 state = Connected; 210 state = Connected;
217 sendSync = FALSE; 211 sendSync = FALSE;
218 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 212 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
219 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 213 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
220 214
221 QString intro="220 Qtopia "; 215 QString intro="220 Qtopia ";
222 intro += QPE_VERSION; intro += ";"; 216 intro += QPE_VERSION; intro += ";";
223 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; 217 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
224 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; 218 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
225 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; 219 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
226 send( intro ); 220 send( intro );
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp
index 239c824..30bf438 100644
--- a/core/qws/transferserver.cpp
+++ b/core/qws/transferserver.cpp
@@ -1,262 +1,254 @@
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#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h> 25#include <time.h>
26 26
27#ifndef Q_OS_MACX 27#ifndef Q_OS_MACX
28#include <shadow.h> 28#include <shadow.h>
29#endif /* Q_OS_MACX */ 29#endif /* Q_OS_MACX */
30 30
31/* we need the _OS_LINUX stuff first ! */ 31/* we need the _OS_LINUX stuff first ! */
32#include <qglobal.h>
33 32
34#ifndef _OS_LINUX_ 33#ifndef _OS_LINUX_
35// Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found 34// Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found
36// anywhere ? Therfore I removed it completely.. 35// anywhere ? Therfore I removed it completely..
37// I think it should be made permanentyl !? (eilers) 36// I think it should be made permanentyl !? (eilers)
38#warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)" 37#warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)"
39#if 0 38#if 0
40 39
41extern "C" 40extern "C"
42{ 41{
43#include <uuid/uuid.h> 42#include <uuid/uuid.h>
44#define UUID_H_INCLUDED 43#define UUID_H_INCLUDED
45} 44}
46 45
47#endif 46#endif
48 47
49#endif // not defined linux 48#endif // not defined linux
50 49
51#if defined(_OS_LINUX_) 50#if defined(_OS_LINUX_)
52#include <shadow.h> 51#include <shadow.h>
53#elif defined(Q_OS_MACX) 52#elif defined(Q_OS_MACX)
54#include <stdlib.h> 53#include <stdlib.h>
55#endif 54#endif
56 55
57#include <qdir.h>
58#include <qfile.h>
59#include <qtextstream.h> 56#include <qtextstream.h>
60#include <qdatastream.h>
61#include <qmessagebox.h> 57#include <qmessagebox.h>
62#include <qstringlist.h>
63#include <qfileinfo.h>
64#include <qregexp.h>
65//#include <qpe/qcopchannel_qws.h> 58//#include <qpe/qcopchannel_qws.h>
66#include <qpe/process.h> 59#include <qpe/process.h>
67#include <qpe/global.h> 60#include <qpe/global.h>
68#include <qpe/config.h> 61#include <qpe/config.h>
69#include <qpe/contact.h> 62#include <qpe/contact.h>
70#include <qpe/quuid.h>
71#include <qpe/version.h> 63#include <qpe/version.h>
72#include <qpe/qcopenvelope_qws.h> 64#include <qpe/qcopenvelope_qws.h>
73 65
74#include "transferserver.h" 66#include "transferserver.h"
75#include <opie/oprocess.h> 67#include <opie/oprocess.h>
76 68
77const int block_size = 51200; 69const int block_size = 51200;
78 70
79TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 71TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
80 const char* name ) 72 const char* name )
81 : QServerSocket( port, 1, parent, name ) 73 : QServerSocket( port, 1, parent, name )
82{ 74{
83 if ( !ok() ) 75 if ( !ok() )
84 qWarning( "Failed to bind to port %d", port ); 76 qWarning( "Failed to bind to port %d", port );
85} 77}
86 78
87TransferServer::~TransferServer() 79TransferServer::~TransferServer()
88{ 80{
89} 81}
90 82
91void TransferServer::newConnection( int socket ) 83void TransferServer::newConnection( int socket )
92{ 84{
93 (void) new ServerPI( socket, this ); 85 (void) new ServerPI( socket, this );
94} 86}
95 87
96/* 88/*
97 * small class in anonymous namespace 89 * small class in anonymous namespace
98 * to generate a QUUid for us 90 * to generate a QUUid for us
99 */ 91 */
100namespace 92namespace
101{ 93{
102struct UidGen 94struct UidGen
103{ 95{
104 QString uuid(); 96 QString uuid();
105}; 97};
106#if defined(Q_OS_MACX) 98#if defined(Q_OS_MACX)
107QString UidGen::uuid() 99QString UidGen::uuid()
108{ 100{
109 srandom( random() ); 101 srandom( random() );
110 QString numStr = QString::number( random() ); 102 QString numStr = QString::number( random() );
111 103
112 return "{" + numStr + "}"; 104 return "{" + numStr + "}";
113} 105}
114#elif defined(_OS_LINUX_) 106#elif defined(_OS_LINUX_)
115/* 107/*
116* linux got a /proc/sys/kernel/random/uuid file 108* linux got a /proc/sys/kernel/random/uuid file
117* it'll generate the uuids for us 109* it'll generate the uuids for us
118*/ 110*/
119QString UidGen::uuid() 111QString UidGen::uuid()
120{ 112{
121 QFile file( "/proc/sys/kernel/random/uuid" ); 113 QFile file( "/proc/sys/kernel/random/uuid" );
122 if (!file.open(IO_ReadOnly ) ) 114 if (!file.open(IO_ReadOnly ) )
123 return QString::null; 115 return QString::null;
124 116
125 QTextStream stream(&file); 117 QTextStream stream(&file);
126 118
127 return "{" + stream.read().stripWhiteSpace() + "}"; 119 return "{" + stream.read().stripWhiteSpace() + "}";
128} 120}
129#else 121#else
130QString UidGen::uuid() 122QString UidGen::uuid()
131{ 123{
132 uuid_t uuid; 124 uuid_t uuid;
133 ::uuid_generate( uuid ); 125 ::uuid_generate( uuid );
134 return QUUid( uuid ).toString(); 126 return QUUid( uuid ).toString();
135} 127}
136#endif 128#endif
137} 129}
138 130
139QString SyncAuthentication::serverId() 131QString SyncAuthentication::serverId()
140{ 132{
141 Config cfg("Security"); 133 Config cfg("Security");
142 cfg.setGroup("Sync"); 134 cfg.setGroup("Sync");
143 QString r = cfg.readEntry("serverid"); 135 QString r = cfg.readEntry("serverid");
144 if ( r.isEmpty() ) { 136 if ( r.isEmpty() ) {
145 UidGen gen; 137 UidGen gen;
146 r = gen.uuid(); 138 r = gen.uuid();
147 cfg.writeEntry("serverid", r ); 139 cfg.writeEntry("serverid", r );
148 } 140 }
149 return r; 141 return r;
150} 142}
151 143
152QString SyncAuthentication::ownerName() 144QString SyncAuthentication::ownerName()
153{ 145{
154 QString vfilename = Global::applicationFileName("addressbook", 146 QString vfilename = Global::applicationFileName("addressbook",
155 "businesscard.vcf"); 147 "businesscard.vcf");
156 if (QFile::exists(vfilename)) { 148 if (QFile::exists(vfilename)) {
157 Contact c; 149 Contact c;
158 c = Contact::readVCard( vfilename )[0]; 150 c = Contact::readVCard( vfilename )[0];
159 return c.fullName(); 151 return c.fullName();
160 } 152 }
161 153
162 return ""; 154 return "";
163} 155}
164 156
165QString SyncAuthentication::loginName() 157QString SyncAuthentication::loginName()
166{ 158{
167 struct passwd *pw; 159 struct passwd *pw;
168 pw = getpwuid( geteuid() ); 160 pw = getpwuid( geteuid() );
169 return QString::fromLocal8Bit( pw->pw_name ); 161 return QString::fromLocal8Bit( pw->pw_name );
170} 162}
171 163
172int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 164int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
173{ 165{
174 Config cfg("Security"); 166 Config cfg("Security");
175 cfg.setGroup("Sync"); 167 cfg.setGroup("Sync");
176 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 168 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
177 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 169 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
178 170
179 // QHostAddress allowed; 171 // QHostAddress allowed;
180 // allowed.setAddress(allowedstr); 172 // allowed.setAddress(allowedstr);
181 // uint auth_peer = allowed.ip4Addr(); 173 // uint auth_peer = allowed.ip4Addr();
182 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 174 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
183 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 175 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
184 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 176 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
185 return (peeraddress.ip4Addr() & mask) == auth_peer; 177 return (peeraddress.ip4Addr() & mask) == auth_peer;
186} 178}
187 179
188bool SyncAuthentication::checkUser( const QString& user ) 180bool SyncAuthentication::checkUser( const QString& user )
189{ 181{
190 if ( user.isEmpty() ) 182 if ( user.isEmpty() )
191 return FALSE; 183 return FALSE;
192 QString euser = loginName(); 184 QString euser = loginName();
193 return user == euser; 185 return user == euser;
194} 186}
195 187
196bool SyncAuthentication::checkPassword( const QString& password ) 188bool SyncAuthentication::checkPassword( const QString& password )
197{ 189{
198#ifdef ALLOW_UNIX_USER_FTP 190#ifdef ALLOW_UNIX_USER_FTP
199 // First, check system password... 191 // First, check system password...
200 192
201 struct passwd *pw = 0; 193 struct passwd *pw = 0;
202 struct spwd *spw = 0; 194 struct spwd *spw = 0;
203 195
204 pw = getpwuid( geteuid() ); 196 pw = getpwuid( geteuid() );
205 spw = getspnam( pw->pw_name ); 197 spw = getspnam( pw->pw_name );
206 198
207 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 199 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
208 if ( cpwd == "x" && spw ) 200 if ( cpwd == "x" && spw )
209 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 201 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
210 202
211 // Note: some systems use more than crypt for passwords. 203 // Note: some systems use more than crypt for passwords.
212 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 204 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
213 if ( cpwd == cpassword ) 205 if ( cpwd == cpassword )
214 return TRUE; 206 return TRUE;
215#endif 207#endif
216 208
217 static int lastdenial = 0; 209 static int lastdenial = 0;
218 static int denials = 0; 210 static int denials = 0;
219 int now = time(0); 211 int now = time(0);
220 212
221 // Detect old Qtopia Desktop (no password) 213 // Detect old Qtopia Desktop (no password)
222 if ( password.isEmpty() ) { 214 if ( password.isEmpty() ) {
223 if ( denials < 1 || now > lastdenial + 600 ) { 215 if ( denials < 1 || now > lastdenial + 600 ) {
224 QMessageBox::warning( 0, tr("Sync Connection"), 216 QMessageBox::warning( 0, tr("Sync Connection"),
225 tr("<p>An unauthorized system is requesting access to this device." 217 tr("<p>An unauthorized system is requesting access to this device."
226 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 218 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
227 "please upgrade."), 219 "please upgrade."),
228 tr("Deny") ); 220 tr("Deny") );
229 denials++; 221 denials++;
230 lastdenial = now; 222 lastdenial = now;
231 } 223 }
232 return FALSE; 224 return FALSE;
233 } 225 }
234 226
235 // Second, check sync password... 227 // Second, check sync password...
236 QString pass = password.left(6); 228 QString pass = password.left(6);
237 /* old QtopiaDesktops are sending 229 /* old QtopiaDesktops are sending
238 * rootme newer versions got a Qtopia 230 * rootme newer versions got a Qtopia
239 * prefixed. Qtopia prefix will suceed 231 * prefixed. Qtopia prefix will suceed
240 * until the sync software syncs up 232 * until the sync software syncs up
241 * FIXME 233 * FIXME
242 */ 234 */
243 if ( pass == "rootme" || pass == "Qtopia") { 235 if ( pass == "rootme" || pass == "Qtopia") {
244 236
245 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 237 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
246 Config cfg("Security"); 238 Config cfg("Security");
247 cfg.setGroup("Sync"); 239 cfg.setGroup("Sync");
248 QString pwds = cfg.readEntry("Passwords"); 240 QString pwds = cfg.readEntry("Passwords");
249 if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) 241 if ( QStringList::split(QChar(' '), pwds).contains(cpassword) )
250 return TRUE; 242 return TRUE;
251 243
252 // Unrecognized system. Be careful... 244 // Unrecognized system. Be careful...
253 245
254 if ( (denials > 2 && now < lastdenial + 600) 246 if ( (denials > 2 && now < lastdenial + 600)
255 || QMessageBox::warning(0, tr("Sync Connection"), 247 || QMessageBox::warning(0, tr("Sync Connection"),
256 tr("<p>An unrecognized system is requesting access to this device." 248 tr("<p>An unrecognized system is requesting access to this device."
257 "<p>If you have just initiated a Sync for the first time, this is normal."), 249 "<p>If you have just initiated a Sync for the first time, this is normal."),
258 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { 250 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) {
259 denials++; 251 denials++;
260 lastdenial = now; 252 lastdenial = now;
261 return FALSE; 253 return FALSE;
262 } 254 }