summaryrefslogtreecommitdiff
path: root/core
Unidiff
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/.cvsignore2
-rw-r--r--core/obex/btobex.cpp60
-rw-r--r--core/obex/btobex.h40
-rw-r--r--core/obex/obex.cpp49
-rw-r--r--core/obex/obex.h40
-rw-r--r--core/obex/obex.pro16
-rw-r--r--core/obex/obexbase.cpp74
-rw-r--r--core/obex/obexbase.h99
-rw-r--r--core/obex/obexhandler.cpp44
-rw-r--r--core/obex/obexhandler.h9
-rw-r--r--core/obex/obexsend.cpp2
-rw-r--r--core/obex/obexserver.cpp514
-rw-r--r--core/obex/obexserver.h83
-rw-r--r--core/obex/receiver.cpp9
-rw-r--r--core/obex/receiver.h12
15 files changed, 985 insertions, 68 deletions
diff --git a/core/obex/.cvsignore b/core/obex/.cvsignore
index ed75078..90f9614 100644
--- a/core/obex/.cvsignore
+++ b/core/obex/.cvsignore
@@ -2,3 +2,5 @@ Makefile
2moc_* 2moc_*
3.moc 3.moc
4.obj 4.obj
5obexsendbase.h
6obexsendbase.cpp
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index a5bfe5f..212a084 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -1,3 +1,33 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Bluetooth OBEX manipulating class implementation
30 */
1 31
2#include "btobex.h" 32#include "btobex.h"
3#include <manager.h> 33#include <manager.h>
@@ -20,16 +50,10 @@ using namespace Opie::Core;
20using namespace OpieTooth; 50using namespace OpieTooth;
21 51
22BtObex::BtObex( QObject *parent, const char* name ) 52BtObex::BtObex( QObject *parent, const char* name )
23 : QObject(parent, name ) 53 : ObexBase(parent, name )
24{ 54{
25 m_rec = 0; 55 m_rec = 0;
26 m_send=0; 56 m_send=0;
27 m_count = 0;
28 m_receive = false;
29 connect( this, SIGNAL(error(int) ), // for recovering to receive
30 SLOT(slotError() ) );
31 connect( this, SIGNAL(sent(bool) ),
32 SLOT(slotError() ) );
33 btManager = NULL; 57 btManager = NULL;
34}; 58};
35 59
@@ -40,12 +64,11 @@ BtObex::~BtObex() {
40} 64}
41 65
42void BtObex::receive() { 66void BtObex::receive() {
43 m_receive = true; 67 ObexBase::receive();
44 m_outp = QString::null; 68 m_rec = new ObexServer();
45 m_rec = new OProcess();
46 69
70 odebug << "BT OBEX do receive" << oendl;
47 // TODO mbhaynie: No idea if this actually works -- maybe opd is better. 71 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
48 *m_rec << "obexftpd" << "-b";
49 // connect to the necessary slots 72 // connect to the necessary slots
50 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 73 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
51 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 74 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
@@ -61,10 +84,8 @@ void BtObex::receive() {
61} 84}
62 85
63void BtObex::send( const QString& fileName, const QString& bdaddr) { 86void BtObex::send( const QString& fileName, const QString& bdaddr) {
87 ObexBase::send(fileName, bdaddr);
64 // if currently receiving stop it send receive 88 // if currently receiving stop it send receive
65 m_count = 0;
66 m_file = fileName;
67 m_bdaddr = bdaddr;
68 if (m_send != 0) { 89 if (m_send != 0) {
69 if (m_send->isSending()) 90 if (m_send->isSending())
70 return; 91 return;
@@ -150,6 +171,10 @@ void BtObex::sendNow(){
150 connect(m_send, SIGNAL(status(QCString&)), 171 connect(m_send, SIGNAL(status(QCString&)),
151 this, SLOT(slotPushStatus(QCString&) ) ); 172 this, SLOT(slotPushStatus(QCString&) ) );
152 173
174 /*
175 * FIXME: this delay is made because some cell phones understands an error
176 * later.
177 */
153 ::sleep(4); 178 ::sleep(4);
154 // now start it 179 // now start it
155 result = m_send->send(m_bdaddr, m_port, m_file, m_dst); 180 result = m_send->send(m_bdaddr, m_port, m_file, m_dst);
@@ -171,12 +196,15 @@ void BtObex::slotExited(OProcess* proc ){
171 << proc->exitStatus() << oendl; 196 << proc->exitStatus() << oendl;
172 if (proc == m_rec ) // receive process 197 if (proc == m_rec ) // receive process
173 received(); 198 received();
199
174} 200}
175void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ 201void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
176 if ( proc == m_rec ) { // only receive 202 if ( proc == m_rec ) { // only receive
177 QByteArray ar( len ); 203 QByteArray ar( len );
178 memcpy( ar.data(), buf, len ); 204 memcpy( ar.data(), buf, len );
179 m_outp.append( ar ); 205 m_outp.append( ar );
206 QCString str(buf, len);
207 odebug << str << oendl;
180 } 208 }
181} 209}
182 210
@@ -207,6 +235,7 @@ void BtObex::received() {
207 if (m_rec->normalExit() ) { 235 if (m_rec->normalExit() ) {
208 if ( m_rec->exitStatus() == 0 ) { // we got one 236 if ( m_rec->exitStatus() == 0 ) { // we got one
209 QString filename = parseOut(); 237 QString filename = parseOut();
238 odebug << "OBEX " << filename << " received" << oendl;
210 emit receivedFile( filename ); 239 emit receivedFile( filename );
211 } 240 }
212 }else{ 241 }else{
@@ -240,10 +269,13 @@ QString BtObex::parseOut(){
240 * when sent is done slotError is called we will start receive again 269 * when sent is done slotError is called we will start receive again
241 */ 270 */
242void BtObex::slotError() { 271void BtObex::slotError() {
272 ObexBase::slotError();
243 if ( m_receive ) 273 if ( m_receive )
244 receive(); 274 receive();
245}; 275};
246void BtObex::setReceiveEnabled( bool receive ) { 276void BtObex::setReceiveEnabled( bool receive ) {
277 odebug << "BT OBEX setReceiveEnabled " << receive << oendl;
278 ObexBase::setReceiveEnabled(receive);
247 if ( !receive ) { // 279 if ( !receive ) { //
248 m_receive = false; 280 m_receive = false;
249 shutDownReceive(); 281 shutDownReceive();
diff --git a/core/obex/btobex.h b/core/obex/btobex.h
index 9c1ab70..7e91c06 100644
--- a/core/obex/btobex.h
+++ b/core/obex/btobex.h
@@ -1,19 +1,51 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Bluetooth OBEX manipulating class declaration
30 */
1 31
2 32
3#ifndef OpieBtObex_H 33#ifndef OpieBtObex_H
4#define OpieBtObex_H 34#define OpieBtObex_H
5 35
36#include "obexbase.h"
6#include <qobject.h> 37#include <qobject.h>
7#include <services.h> 38#include <services.h>
8#include <manager.h> 39#include <manager.h>
9#include <obexpush.h> 40#include <obexpush.h>
41#include "obexserver.h"
10 42
11namespace Opie {namespace Core {class OProcess;}} 43namespace Opie {namespace Core {class OProcess;}}
12class QCopChannel; 44class QCopChannel;
13using namespace OpieTooth; 45using namespace OpieTooth;
14namespace OpieObex { 46namespace OpieObex {
15 // Maybe this should be derved from Obex. 47 // Maybe this should be derved from Obex.
16 class BtObex : public QObject { 48 class BtObex : public ObexBase {
17 Q_OBJECT 49 Q_OBJECT
18 public: 50 public:
19 /** 51 /**
@@ -55,16 +87,12 @@ namespace OpieObex {
55 void done(bool); 87 void done(bool);
56 88
57 private: 89 private:
58 uint m_count;
59 QString m_file;
60 QString m_outp;
61 QString m_bdaddr;
62 int m_port; 90 int m_port;
63 ObexPush* m_send; 91 ObexPush* m_send;
64 Opie::Core::OProcess *m_rec;
65 bool m_receive : 1; 92 bool m_receive : 1;
66 OpieTooth::Manager* btManager; 93 OpieTooth::Manager* btManager;
67 void shutDownReceive(); 94 void shutDownReceive();
95 ObexServer* m_rec;
68 96
69private slots: 97private slots:
70 98
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp
index 36634ec..95c561a 100644
--- a/core/obex/obex.cpp
+++ b/core/obex/obex.cpp
@@ -1,3 +1,33 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Infrared OBEX handling class implementation
30 */
1 31
2#include "obex.h" 32#include "obex.h"
3 33
@@ -16,24 +46,17 @@ using namespace Opie::Core;
16/* TRANSLATOR OpieObex::Obex */ 46/* TRANSLATOR OpieObex::Obex */
17 47
18Obex::Obex( QObject *parent, const char* name ) 48Obex::Obex( QObject *parent, const char* name )
19 : QObject(parent, name ) 49 : ObexBase(parent, name )
20{ 50{
21 m_rec = 0; 51 m_rec = 0;
22 m_send=0; 52 m_send=0;
23 m_count = 0;
24 m_receive = false;
25 connect( this, SIGNAL(error(int) ), // for recovering to receive
26 SLOT(slotError() ) );
27 connect( this, SIGNAL(sent(bool) ),
28 SLOT(slotError() ) );
29}; 53};
30Obex::~Obex() { 54Obex::~Obex() {
31 delete m_rec; 55 delete m_rec;
32 delete m_send; 56 delete m_send;
33} 57}
34void Obex::receive() { 58void Obex::receive() {
35 m_receive = true; 59 ObexBase::receive();
36 m_outp = QString::null;
37 m_rec = new OProcess(); 60 m_rec = new OProcess();
38 *m_rec << "irobex_palm3"; 61 *m_rec << "irobex_palm3";
39 // connect to the necessary slots 62 // connect to the necessary slots
@@ -50,9 +73,9 @@ void Obex::receive() {
50 } 73 }
51} 74}
52 75
53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 76// if currently receiving stop it send receive
54 m_count = 0; 77void Obex::send(const QString& fileName, const QString& addr) {
55 m_file = fileName; 78 ObexBase::send(fileName, addr);
56 if (m_rec != 0 ) { 79 if (m_rec != 0 ) {
57 if (m_rec->isRunning() ) { 80 if (m_rec->isRunning() ) {
58 emit error(-1 ); 81 emit error(-1 );
@@ -165,10 +188,12 @@ QString Obex::parseOut( ){
165 * when sent is done slotError is called we will start receive again 188 * when sent is done slotError is called we will start receive again
166 */ 189 */
167void Obex::slotError() { 190void Obex::slotError() {
191 ObexBase::slotError();
168 if ( m_receive ) 192 if ( m_receive )
169 receive(); 193 receive();
170}; 194};
171void Obex::setReceiveEnabled( bool receive ) { 195void Obex::setReceiveEnabled( bool receive ) {
196 ObexBase::setReceiveEnabled(receive);
172 if ( !receive ) { // 197 if ( !receive ) { //
173 m_receive = false; 198 m_receive = false;
174 shutDownReceive(); 199 shutDownReceive();
diff --git a/core/obex/obex.h b/core/obex/obex.h
index 5993976..36ff29a 100644
--- a/core/obex/obex.h
+++ b/core/obex/obex.h
@@ -1,14 +1,44 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
1 26
27*/
28/*
29 * The Infrared OBEX handling class declaration
30 */
2 31
3#ifndef OpieObex_H 32#ifndef OpieObex_H
4#define OpieObex_H 33#define OpieObex_H
5 34
35#include "obexbase.h"
6#include <qobject.h> 36#include <qobject.h>
7 37
8namespace Opie {namespace Core {class OProcess;}} 38namespace Opie {namespace Core {class OProcess;}}
9class QCopChannel; 39class QCopChannel;
10namespace OpieObex { 40namespace OpieObex {
11 class Obex : public QObject { 41 class Obex : public ObexBase {
12 Q_OBJECT 42 Q_OBJECT
13 public: 43 public:
14 /** 44 /**
@@ -24,9 +54,9 @@ namespace OpieObex {
24 * Starting listening to irda after enabled by the applet 54 * Starting listening to irda after enabled by the applet
25 * a signal gets emitted when received a file 55 * a signal gets emitted when received a file
26 */ 56 */
27 void receive(); 57 virtual void receive();
28 void send( const QString& ); 58 virtual void send(const QString& filename, const QString& addr);
29 void setReceiveEnabled( bool = false ); 59 virtual void setReceiveEnabled( bool = false );
30 signals: 60 signals:
31 61
32 /** 62 /**
@@ -69,7 +99,7 @@ private slots:
69 // the process exited 99 // the process exited
70 void slotExited(Opie::Core::OProcess* proc) ; 100 void slotExited(Opie::Core::OProcess* proc) ;
71 void slotStdOut(Opie::Core::OProcess*, char*, int); 101 void slotStdOut(Opie::Core::OProcess*, char*, int);
72 void slotError(); 102 virtual void slotError();
73 103
74 private: 104 private:
75 void sendNow(); 105 void sendNow();
diff --git a/core/obex/obex.pro b/core/obex/obex.pro
index 33cb957..1fc6958 100644
--- a/core/obex/obex.pro
+++ b/core/obex/obex.pro
@@ -1,14 +1,20 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on 2 CONFIG += qt warn_on
3 HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h 3 HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h obexbase.h obexserver.h
4 SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp 4 SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp obexbase.cpp obexserver.cpp
5 TARGET = opieobex 5 TARGET = opieobex
6 DESTDIR = $(OPIEDIR)/plugins/obex 6 DESTDIR = $(OPIEDIR)/plugins/obex
7INTERFACES = obexsendbase.ui 7INTERFACES = obexsendbase.ui
8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher $(OPIEDIR)/noncore/net/opietooth/lib 8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher
9DEPENDPATH += 9DEPENDPATH +=
10LIBS += -lopietooth1 -lqpe -lopiecore2 10LIBS += -lqpe -lopiecore2
11 VERSION = 0.0.3 11 VERSION = 0.0.4
12 12
13include( $(OPIEDIR)/include.pro ) 13include( $(OPIEDIR)/include.pro )
14target.path = $$prefix/plugins/applets 14target.path = $$prefix/plugins/applets
15
16#FIXME: These parameters are used if bluetooth is used
17INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib
18LIBS += -lopietooth1 -lbluetooth -lopenobex
19DEFINES += BLUETOOTH
20
diff --git a/core/obex/obexbase.cpp b/core/obex/obexbase.cpp
new file mode 100644
index 0000000..8eda04e
--- a/dev/null
+++ b/core/obex/obexbase.cpp
@@ -0,0 +1,74 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The basic class for OBEX manipulating classes implementation
30 */
31
32#include "obexbase.h"
33
34/* OPIE */
35#include <opie2/oprocess.h>
36#include <opie2/odebug.h>
37
38using namespace OpieObex;
39
40using namespace Opie::Core;
41
42ObexBase::ObexBase(QObject *parent, const char* name)
43 : QObject(parent, name)
44{
45 m_count = 0;
46 m_receive = false;
47 connect( this, SIGNAL(error(int) ), // for recovering to receive
48 SLOT(slotError() ) );
49 connect( this, SIGNAL(sent(bool) ),
50 SLOT(slotError() ) );
51}
52
53ObexBase::~ObexBase() {
54}
55
56void ObexBase::receive() {
57 m_receive = true;
58 m_outp = QString::null;
59}
60
61void ObexBase::send( const QString& fileName, const QString& bdaddr) {
62 // if currently receiving stop it send receive
63 m_count = 0;
64 m_file = fileName;
65 m_bdaddr = bdaddr;
66}
67
68void ObexBase::setReceiveEnabled(bool) {
69}
70
71void ObexBase::slotError() {
72}
73
74//eof
diff --git a/core/obex/obexbase.h b/core/obex/obexbase.h
new file mode 100644
index 0000000..f65d922
--- a/dev/null
+++ b/core/obex/obexbase.h
@@ -0,0 +1,99 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The basic class for OBEX manipulating classes declaration
30 */
31#ifndef ObexBase_H
32#define ObexBase_H
33
34#include <qobject.h>
35
36namespace Opie {namespace Core {class OProcess;}}
37class QCopChannel;
38namespace OpieObex {
39 class ObexBase : public QObject {
40 Q_OBJECT
41 public:
42 /**
43 * ObexBase constructor look
44 */
45 ObexBase(QObject *parent, const char* name);
46 /**
47 * d'tor
48 */
49 virtual ~ObexBase();
50 /**
51 * Starting listening to an interface after enabled by the applet
52 * a signal gets emitted when received a file
53 */
54 virtual void receive();
55 /**
56 * Send the file
57 * @param the name of the file
58 * @param the address of the device
59 */
60 virtual void send(const QString&, const QString&);
61 /**
62 * Stop receiving
63 * @param if true - does nothing if false - stops receiving
64 */
65 virtual void setReceiveEnabled(bool = false);
66 signals:
67 /**
68 * Notify the upper level that we have received the file
69 * @param path The path to the received file
70 */
71 void receivedFile(const QString& path);
72 /**
73 * error signal if the program couldn't be started or the
74 * the connection timed out
75 */
76 void error(int);
77 /**
78 * The current try to receive data
79 */
80 void currentTry(unsigned int);
81 /**
82 * signal sent The file got beamed to the remote location
83 */
84 void sent(bool);
85 void done(bool);
86 protected:
87 uint m_count;
88 QString m_file;
89 QString m_outp;
90 QString m_bdaddr;
91 bool m_receive : 1;
92 protected slots:
93 virtual void slotError();
94 };
95};
96
97#endif
98//eof
99
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp
index 28f9b5b..5d98ded 100644
--- a/core/obex/obexhandler.cpp
+++ b/core/obex/obexhandler.cpp
@@ -11,16 +11,20 @@ using namespace OpieObex;
11/* TRANSLATOR OpieObex::ObexHandler */ 11/* TRANSLATOR OpieObex::ObexHandler */
12 12
13ObexHandler::ObexHandler() { 13ObexHandler::ObexHandler() {
14 m_wasRec = false; 14 m_wasRec[REC_IRDA] = false;
15 m_receiver[REC_IRDA] = 0l;
16 m_wasRec[REC_BLUETOOTH] = false;
17 m_receiver[REC_BLUETOOTH] = 0l;
15 m_sender = 0l; 18 m_sender = 0l;
16 m_receiver = 0l; 19 m_type = REC_IRDA; //FIXME: Just to init to something
17 QCopChannel* chan = new QCopChannel("QPE/Obex"); 20 QCopChannel* chan = new QCopChannel("QPE/Obex");
18 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 21 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
19 this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) ); 22 this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) );
20} 23}
21ObexHandler::~ObexHandler() { 24ObexHandler::~ObexHandler() {
22 delete m_sender; 25 delete m_sender;
23 delete m_receiver; 26 delete m_receiver[REC_IRDA];
27 delete m_receiver[REC_BLUETOOTH];
24} 28}
25void ObexHandler::doSend(const QString& str, const QString& desc) { 29void ObexHandler::doSend(const QString& str, const QString& desc) {
26 delete m_sender; 30 delete m_sender;
@@ -31,14 +35,14 @@ void ObexHandler::doSend(const QString& str, const QString& desc) {
31 this, SLOT(slotSent() ) ); 35 this, SLOT(slotSent() ) );
32 m_sender->send( str, desc ); 36 m_sender->send( str, desc );
33} 37}
34void ObexHandler::doReceive(bool b) { 38void ObexHandler::doReceive(RecType type, bool b) {
35 if (m_receiver && b ) return; // we should enable receiver and it is on 39 if (m_receiver[type] && b ) return; // we should enable receiver and it is on
36 else if (!m_receiver && !b ) return; // we should disbale receiver and it is off 40 else if (!m_receiver[type] && !b ) return; // we should disbale receiver and it is off
37 else if (m_receiver && !b ) { 41 else if (m_receiver[type] && !b ) {
38 delete m_receiver; 42 delete m_receiver[type];
39 m_receiver=0; 43 m_receiver[type] = 0;
40 }else if (!m_receiver && b ) { 44 }else if (!m_receiver[type] && b ) {
41 m_receiver= new Receiver; 45 m_receiver[type] = new Receiver(type);
42 } 46 }
43} 47}
44void ObexHandler::slotSent() { 48void ObexHandler::slotSent() {
@@ -47,8 +51,10 @@ void ObexHandler::slotSent() {
47 m_sender = 0; 51 m_sender = 0;
48 QCopEnvelope e ("QPE/Obex", "done(QString)" ); 52 QCopEnvelope e ("QPE/Obex", "done(QString)" );
49 e << file; 53 e << file;
50 doReceive(m_wasRec ); 54 doReceive(REC_IRDA, m_wasRec[REC_IRDA]);
51 m_wasRec = false; 55 doReceive(REC_BLUETOOTH, m_wasRec[REC_BLUETOOTH]);
56 m_wasRec[REC_IRDA] = false;
57 m_wasRec[REC_BLUETOOTH] = false;
52} 58}
53void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { 59void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) {
54 QDataStream stream( data, IO_ReadOnly ); 60 QDataStream stream( data, IO_ReadOnly );
@@ -56,12 +62,18 @@ void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) {
56 QString name, desc; 62 QString name, desc;
57 stream >> desc; 63 stream >> desc;
58 stream >> name; 64 stream >> name;
59 m_wasRec = (m_receiver != 0 ); 65 m_wasRec[REC_IRDA] = (m_receiver[REC_IRDA] != 0 );
60 doReceive( false ); 66 m_wasRec[REC_BLUETOOTH] = (m_receiver[REC_BLUETOOTH] != 0 );
67 doReceive(REC_IRDA, false);
68 doReceive(REC_BLUETOOTH, false);
61 doSend(name, desc); 69 doSend(name, desc);
62 }else if (msg == "receive(int)") { 70 }else if (msg == "receive(int)") {
63 int rec; 71 int rec;
64 stream >> rec; 72 stream >> rec;
65 doReceive(rec); 73 doReceive(REC_IRDA, rec);
74 }else if (msg == "btreceive(int)") {
75 int rec;
76 stream >> rec;
77 doReceive(REC_BLUETOOTH, rec);
66 } 78 }
67} 79}
diff --git a/core/obex/obexhandler.h b/core/obex/obexhandler.h
index 230c4f0..de2232e 100644
--- a/core/obex/obexhandler.h
+++ b/core/obex/obexhandler.h
@@ -3,6 +3,7 @@
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qstring.h> 5#include <qstring.h>
6#include "receiver.h"
6 7
7namespace OpieObex { 8namespace OpieObex {
8 /* 9 /*
@@ -21,7 +22,7 @@ namespace OpieObex {
21 22
22 private slots: 23 private slots:
23 void doSend(const QString&,const QString& ); 24 void doSend(const QString&,const QString& );
24 void doReceive(bool b); 25 void doReceive(RecType type, bool b);
25 void slotSent(); 26 void slotSent();
26 27
27 private slots: // QCOP message 28 private slots: // QCOP message
@@ -29,9 +30,9 @@ namespace OpieObex {
29 30
30 private: 31 private:
31 SendWidget* m_sender; 32 SendWidget* m_sender;
32 Receiver* m_receiver; 33 Receiver* m_receiver[2]; //For IRDA and Bluetooth
33 bool m_wasRec : 1; 34 bool m_wasRec[2];
34 35 RecType m_type; //receiver type (IRDA or Bluetooth)
35 }; 36 };
36} 37}
37 38
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index 8432d16..9a30a0a 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -148,7 +148,7 @@ void SendWidget::slotStartIrda() {
148 return; 148 return;
149 } 149 }
150 setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); 150 setReceiverStatus( m_irDaIt.key(), tr("Start sending") );
151 m_obex->send( m_file ); 151 m_obex->send( m_file, tr("noaddress") );
152} 152}
153 153
154void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 154void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
diff --git a/core/obex/obexserver.cpp b/core/obex/obexserver.cpp
new file mode 100644
index 0000000..95196de
--- a/dev/null
+++ b/core/obex/obexserver.cpp
@@ -0,0 +1,514 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The OBEX server class implementation
30 * Based on OBEX server from GPE (thanks, guys)
31 */
32
33#include "obexserver.h"
34#include <unistd.h>
35#include <opie2/odebug.h>
36#include <sys/types.h>
37#include <sys/wait.h>
38#include <errno.h>
39#include <stdlib.h>
40#include <stdio.h>
41#include <fcntl.h>
42#include <qapplication.h>
43#include <opie2/oprocctrl.h>
44#include <qstring.h>
45#include <qfile.h>
46
47using namespace Opie::Core;
48using namespace Opie::Core::Internal;
49using namespace OpieObex;
50
51ObexServer::ObexServer() :
52 OProcess(tr("ObexServer"), 0, "ObexServer")
53{
54 m_obex = NULL;
55}
56
57ObexServer::~ObexServer()
58{
59 stop();
60}
61
62/**
63 * Function handles the file received
64 * @param name the file name
65 * @param data the file data
66 * @param data_len the data length
67 * @return 0 on success -1 on error
68 */
69static int file_received(uint8_t* name, const uint8_t* data, size_t data_len)
70{
71 QString path("/tmp/");
72 path += (char*)name;
73 QFile out(path);
74 int err = 0;
75
76 if (!out.open(IO_Raw | IO_ReadWrite | IO_Truncate)) {
77 printf("File %s open error %d\n", (const char*)path, errno);
78 err = -1;
79 goto out;
80 }
81 if (out.writeBlock((const char*)data, data_len) < 0) {
82 printf("File %s write error %d\n", (const char*)path, errno);
83 err = -1;
84 goto out;
85 }
86out:
87 out.close();
88 if (err == 0) {
89 printf("Wrote %s (%d bytes)\n", (const char*)path, data_len);
90 fflush(stdout);
91 }
92 return err;
93}
94
95/**
96 * Function handles the situation when the PUT request has been done
97 * @param handle OBEX connection handle
98 * @param object OBEX object itself
99 */
100static int put_done(obex_t* handle, obex_object_t* object)
101{
102 obex_headerdata_t hv; //Received file header
103 uint8_t hi; //Type of the request
104 uint32_t hlen; //File (file name) length
105 int err = 0;
106
107 const uint8_t *body = NULL;
108 int body_len = 0;
109 uint8_t* name = NULL;
110
111 while (OBEX_ObjectGetNextHeader (handle, object, &hi, &hv, &hlen)) {
112 switch(hi) {
113 case OBEX_HDR_BODY:
114 body = hv.bs;
115 body_len = hlen;
116 break;
117
118 case OBEX_HDR_NAME:
119 name = new uint8_t[(hlen / 2) + 1];
120 OBEX_UnicodeToChar(name, hv.bs, hlen);
121 break;
122
123 default:
124 break;
125 }
126 }
127
128 if (body)
129 err = file_received(name, body, body_len);
130
131 if (name)
132 delete[] name;
133 return err;
134}
135
136/**
137 * Function handles OBEX request
138 * @param handle OBEX connection handle
139 * @param object OBEX object itself
140 * @param mode
141 * @param event event code
142 * @param cmd OBEX command itself
143 */
144static void handle_request (obex_t* handle, obex_object_t* object,
145 int event, int cmd)
146{
147 (void)event;
148 switch(cmd){
149 case OBEX_CMD_SETPATH:
150 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
151 break;
152 case OBEX_CMD_PUT:
153 if (put_done (handle, object) < 0)
154 OBEX_ObjectSetRsp (object, OBEX_RSP_INTERNAL_SERVER_ERROR,
155 OBEX_RSP_INTERNAL_SERVER_ERROR);
156 else
157 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
158 break;
159 case OBEX_CMD_CONNECT:
160 OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
161 break;
162 case OBEX_CMD_DISCONNECT:
163 OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
164 break;
165 default:
166 printf("Denied %02x request\n", cmd);
167 fflush(stdout);
168 OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED,
169 OBEX_RSP_NOT_IMPLEMENTED);
170 break;
171 }
172}
173
174
175/**
176 * Function handles OBEX event when a client is connected to the server
177 * @param handle OBEX connection handle
178 * @param object OBEX object itself
179 * @param mode
180 * @param event event code
181 * @param obex_cmd OBEX command itself
182 * @param obex_rsp OBEX responce
183 */
184static void obex_conn_event (obex_t *handle, obex_object_t *object,
185 int mode, int event, int obex_cmd, int obex_rsp)
186{
187 (void)mode;
188 (void)obex_rsp;
189
190 switch(event) {
191 case OBEX_EV_REQHINT:
192 switch(obex_cmd) {
193 case OBEX_CMD_PUT:
194 case OBEX_CMD_CONNECT:
195 case OBEX_CMD_DISCONNECT:
196 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
197 break;
198 default:
199 OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED,
200 OBEX_RSP_NOT_IMPLEMENTED);
201 break;
202 }
203 break;
204
205 case OBEX_EV_REQ:
206 /* Comes when a server-request has been received. */
207 handle_request (handle, object, event, obex_cmd);
208 break;
209
210 case OBEX_EV_LINKERR:
211 break;
212 }
213}
214
215/**
216 * Function handles OBEX event
217 * @param handle OBEX connection handle
218 * @param object OBEX object itself
219 * @param mode
220 * @param event event code
221 * @param obex_cmd OBEX command itself
222 * @param obex_rsp OBEX responce
223 */
224static void obex_event (obex_t* handle, obex_object_t* object, int mode,
225 int event, int obex_cmd, int obex_rsp)
226{
227
228 obex_t *obex; //OBEX connection handle
229
230 switch (event) {
231 case OBEX_EV_ACCEPTHINT:
232 obex = OBEX_ServerAccept (handle, obex_conn_event, NULL);
233 break;
234
235 default:
236 obex_conn_event(handle, object, mode, event, obex_cmd, obex_rsp);
237 }
238}
239
240/**
241 * Function registers OBEX push service on a specified channel
242 * Based on The same function from GPE.
243 * @param session SDP session
244 * @param chan channel to listen
245 * @name name to show
246 */
247sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name)
248{
249 sdp_list_t *svclass_id, *pfseq, *apseq, *root;
250 uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
251 sdp_profile_desc_t profile[1];
252 sdp_list_t *aproto, *proto[3];
253 sdp_record_t record;
254 sdp_data_t *channel;
255 uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
256 //uint8_t formats[] = { 0xff };
257 void *dtds[sizeof(formats)], *values[sizeof(formats)];
258 unsigned int i;
259 uint8_t dtd = SDP_UINT8;
260 sdp_data_t *sflist;
261 int err = 0;
262 sdp_session_t* lsession = 0;
263
264 memset((void *)&record, 0, sizeof(sdp_record_t));
265 record.handle = 0xffffffff;
266 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
267 root = sdp_list_append(0, &root_uuid);
268 sdp_set_browse_groups(&record, root);
269
270 sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID);
271 svclass_id = sdp_list_append(0, &opush_uuid);
272 sdp_set_service_classes(&record, svclass_id);
273
274 sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID);
275 profile[0].version = 0x0100;
276 pfseq = sdp_list_append(0, profile);
277 sdp_set_profile_descs(&record, pfseq);
278
279 sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
280 proto[0] = sdp_list_append(0, &l2cap_uuid);
281 apseq = sdp_list_append(0, proto[0]);
282
283 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
284 proto[1] = sdp_list_append(0, &rfcomm_uuid);
285 channel = sdp_data_alloc(SDP_UINT8, &chan);
286 proto[1] = sdp_list_append(proto[1], channel);
287 apseq = sdp_list_append(apseq, proto[1]);
288
289 sdp_uuid16_create(&obex_uuid, OBEX_UUID);
290 proto[2] = sdp_list_append(0, &obex_uuid);
291 apseq = sdp_list_append(apseq, proto[2]);
292
293 aproto = sdp_list_append(0, apseq);
294 sdp_set_access_protos(&record, aproto);
295
296 for (i = 0; i < sizeof(formats); i++)
297 {
298 dtds[i] = &dtd;
299 values[i] = &formats[i];
300 }
301 sflist = sdp_seq_alloc(dtds, values, sizeof(formats));
302 sdp_attr_add(&record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist);
303
304 sdp_set_info_attr(&record, name, 0, 0);
305
306 // connect to the local SDP server, register the service record, and
307 // disconnect
308 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
309 if (lsession == NULL)
310 goto errout;
311 err = sdp_record_register(lsession, &record, 0);
312 if (err) {
313 sdp_close(lsession);
314 lsession = NULL;
315 }
316errout:
317 sdp_data_free(channel);
318 sdp_list_free(proto[0], 0);
319 sdp_list_free(proto[1], 0);
320 sdp_list_free(proto[2], 0);
321 sdp_list_free(apseq, 0);
322 sdp_list_free(aproto, 0);
323
324 return lsession;
325}
326
327int ObexServer::initObex(void)
328{
329 int channel = 10; //Channel on which we do listen
330 if (m_obex)
331 return 0;
332 m_obex = ::OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0);
333 if (!m_obex) {
334 printf("OBEX initialization error %d\n", errno);
335 return -1;
336 }
337 ::BtOBEX_ServerRegister(m_obex, NULL, channel);
338 m_session = addOpushSvc(channel, "OBEX push service");
339 if (!m_session) {
340 printf("OBEX registration error %d\n", errno);
341 ::OBEX_Cleanup(m_obex);
342 m_obex = NULL;
343 return -1;
344 }
345 return 0;
346}
347
348bool ObexServer::start(RunMode runmode, Communication comm)
349{
350 if ( runs )
351 {
352 return false; // cannot start a process that is already running
353 // or if no executable has been assigned
354 }
355 run_mode = runmode;
356 status = 0;
357
358 if ( !setupCommunication( comm ) )
359 qWarning( "Could not setup Communication!" );
360
361 // We do this in the parent because if we do it in the child process
362 // gdb gets confused when the application runs from gdb.
363 uid_t uid = getuid();
364 gid_t gid = getgid();
365#ifdef HAVE_INITGROUPS
366
367 struct passwd *pw = getpwuid( uid );
368#endif
369
370 int fd[ 2 ];
371 if ( 0 > pipe( fd ) )
372 {
373 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue
374 }
375
376 runs = true;
377
378 QApplication::flushX();
379
380 // WABA: Note that we use fork() and not vfork() because
381 // vfork() has unclear semantics and is not standardized.
382 pid_ = fork();
383
384 if ( 0 == pid_ )
385 {
386 if ( fd[ 0 ] )
387 close( fd[ 0 ] );
388 if ( !runPrivileged() )
389 {
390 setgid( gid );
391#if defined( HAVE_INITGROUPS)
392
393 if ( pw )
394 initgroups( pw->pw_name, pw->pw_gid );
395#endif
396
397 setuid( uid );
398 }
399 // The child process
400 if ( !commSetupDoneC() )
401 qWarning( "Could not finish comm setup in child!" );
402
403 setupEnvironment();
404
405 // Matthias
406 if ( run_mode == DontCare )
407 setpgid( 0, 0 );
408 // restore default SIGPIPE handler (Harri)
409 struct sigaction act;
410 sigemptyset( &( act.sa_mask ) );
411 sigaddset( &( act.sa_mask ), SIGPIPE );
412 act.sa_handler = SIG_DFL;
413 act.sa_flags = 0;
414 sigaction( SIGPIPE, &act, 0L );
415
416 // We set the close on exec flag.
417 // Closing of fd[1] indicates that the execvp succeeded!
418 if ( fd[ 1 ] )
419 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC );
420
421 if (initObex() == 0) {
422 do {
423 int result; //Connection result
424 if ( fd[ 1 ] ) {
425 ::close(fd[1]);
426 fd[1] = 0;
427 }
428 if ((result = OBEX_HandleInput(m_obex, 60)) < 0) {
429 if (errno != ECONNRESET) {
430 printf("OBEX_HandleInput error %d\n", errno);
431 fflush(stdout);
432 _exit(-1);
433 }
434 else
435 _exit(0);
436 }
437 } while(1);
438 }
439 char resultByte = 1;
440 if ( fd[ 1 ] )
441 write( fd[ 1 ], &resultByte, 1 );
442 _exit( -1 );
443 }
444 else if ( -1 == pid_ )
445 {
446 // forking failed
447
448 runs = false;
449 return false;
450 }
451 else
452 {
453 if ( fd[ 1 ] )
454 close( fd[ 1 ] );
455 // the parent continues here
456
457 // Discard any data for stdin that might still be there
458 input_data = 0;
459
460 // Check whether client could be started.
461 if ( fd[ 0 ] )
462 for ( ;; )
463 {
464 char resultByte;
465 int n = ::read( fd[ 0 ], &resultByte, 1 );
466 if ( n == 1 )
467 {
468 // Error
469 runs = false;
470 close( fd[ 0 ] );
471 pid_ = 0;
472 return false;
473 }
474 if ( n == -1 )
475 {
476 if ( ( errno == ECHILD ) || ( errno == EINTR ) )
477 continue; // Ignore
478 }
479 break; // success
480 }
481 if ( fd[ 0 ] )
482 close( fd[ 0 ] );
483
484 if ( !commSetupDoneP() ) // finish communication socket setup for the parent
485 qWarning( "Could not finish comm setup in parent!" );
486
487 if ( run_mode == Block )
488 {
489 commClose();
490
491 // The SIGCHLD handler of the process controller will catch
492 // the exit and set the status
493 while ( runs )
494 {
495 OProcessController::theOProcessController->
496 slotDoHousekeeping( 0 );
497 }
498 runs = FALSE;
499 emit processExited( this );
500 }
501 }
502 return true;
503}
504
505/*
506 * Stop forwarding process
507 */
508int ObexServer::stop()
509{
510 kill(SIGTERM);
511 return 0;
512}
513
514//eof
diff --git a/core/obex/obexserver.h b/core/obex/obexserver.h
new file mode 100644
index 0000000..8567105
--- a/dev/null
+++ b/core/obex/obexserver.h
@@ -0,0 +1,83 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The OBEX server class declaration
30 * Based on OBEX server from GPE (thanks, guys)
31 */
32#ifndef ObexServer_H
33#define ObexServer_H
34
35#include <qobject.h>
36#include <opie2/oprocess.h>
37
38#include <bluetooth/sdp.h>
39#include <bluetooth/sdp_lib.h>
40
41#include <openobex/obex.h>
42
43namespace Opie {
44 namespace Core {
45 class OProcess;
46 namespace Internal {
47 class OProcessController;
48 }
49 }
50};
51
52namespace Opie {namespace Core {class OProcess;}}
53namespace OpieObex {
54 class ObexServer : public Opie::Core::OProcess {
55 Q_OBJECT
56 public:
57 /**
58 * ObexServer constructor
59 */
60 ObexServer();
61 /**
62 *
63 */
64 ~ObexServer();
65 //Function starts the server process
66 virtual bool start( RunMode runmode = NotifyOnExit,
67 Communication comm = NoCommunication );
68 //Stop the server process
69 int stop();
70 protected: //variables
71 obex_t* m_obex; //Obex server handler
72 sdp_session_t* m_session; //SDP session handler;
73 protected: //functions
74 //Funtion initializes obex server return 0 on success and -1 on error
75 int initObex(void);
76 //Function registers an OBEX push service
77 sdp_session_t* addOpushSvc(uint8_t chan, const char* name);
78 signals:
79 protected slots:
80 };
81};
82
83#endif
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index 7d9a42a..e153152 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -1,4 +1,6 @@
1#include "obex.h" 1#include "obex.h"
2#include "btobex.h"
3#include "obexbase.h"
2#include "receiver.h" 4#include "receiver.h"
3using namespace OpieObex; 5using namespace OpieObex;
4 6
@@ -26,8 +28,11 @@ using namespace Opie::Core;
26 28
27/* TRANSLATOR OpieObex::Receiver */ 29/* TRANSLATOR OpieObex::Receiver */
28 30
29Receiver::Receiver() { 31Receiver::Receiver(RecType type) {
30 m_obex = new Obex(this, "Receiver"); 32 if (type == REC_IRDA)
33 m_obex = new Obex(this, "Receiver");
34 else
35 m_obex = new BtObex(this, "Receiver");
31 connect(m_obex, SIGNAL(receivedFile(const QString&) ), 36 connect(m_obex, SIGNAL(receivedFile(const QString&) ),
32 this, SLOT(slotReceived(const QString&) ) ); 37 this, SLOT(slotReceived(const QString&) ) );
33 m_obex->receive(); 38 m_obex->receive();
diff --git a/core/obex/receiver.h b/core/obex/receiver.h
index e1d54df..a10ea13 100644
--- a/core/obex/receiver.h
+++ b/core/obex/receiver.h
@@ -5,16 +5,22 @@
5#include <qvbox.h> 5#include <qvbox.h>
6#include <qstring.h> 6#include <qstring.h>
7 7
8//Receiver type
9typedef enum _RecType {
10 REC_IRDA = 0,
11 REC_BLUETOOTH = 1
12} RecType;
13
8class QLabel; 14class QLabel;
9class QTextView; 15class QTextView;
10namespace OpieObex { 16namespace OpieObex {
11 class Obex; 17 class ObexBase;
12 class OtherHandler; 18 class OtherHandler;
13 class Receiver : public QObject { 19 class Receiver : public QObject {
14 Q_OBJECT 20 Q_OBJECT
15 public: 21 public:
16 enum { Datebook , AddressBook, Other }; 22 enum { Datebook , AddressBook, Other };
17 Receiver(); 23 Receiver(RecType type);
18 ~Receiver(); 24 ~Receiver();
19 25
20 private: 26 private:
@@ -32,7 +38,7 @@ namespace OpieObex {
32 void slotReceived( const QString& ); 38 void slotReceived( const QString& );
33 39
34 private: 40 private:
35 Obex* m_obex; 41 ObexBase* m_obex; //IR obex
36 }; 42 };
37 43
38 class OtherHandler : public QVBox { 44 class OtherHandler : public QVBox {