-rw-r--r-- | core/obex/.cvsignore | 2 | ||||
-rw-r--r-- | core/obex/btobex.cpp | 60 | ||||
-rw-r--r-- | core/obex/btobex.h | 40 | ||||
-rw-r--r-- | core/obex/obex.cpp | 49 | ||||
-rw-r--r-- | core/obex/obex.h | 40 | ||||
-rw-r--r-- | core/obex/obex.pro | 16 | ||||
-rw-r--r-- | core/obex/obexbase.cpp | 74 | ||||
-rw-r--r-- | core/obex/obexbase.h | 99 | ||||
-rw-r--r-- | core/obex/obexhandler.cpp | 44 | ||||
-rw-r--r-- | core/obex/obexhandler.h | 9 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 2 | ||||
-rw-r--r-- | core/obex/obexserver.cpp | 514 | ||||
-rw-r--r-- | core/obex/obexserver.h | 83 | ||||
-rw-r--r-- | core/obex/receiver.cpp | 9 | ||||
-rw-r--r-- | core/obex/receiver.h | 12 |
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 | |||
@@ -4 +4,3 @@ moc_* | |||
4 | .obj | 4 | .obj |
5 | obexsendbase.h | ||
6 | obexsendbase.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 +1,31 @@ | |||
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 | ||
@@ -22,3 +52,3 @@ using namespace OpieTooth; | |||
22 | BtObex::BtObex( QObject *parent, const char* name ) | 52 | BtObex::BtObex( QObject *parent, const char* name ) |
23 | : QObject(parent, name ) | 53 | : ObexBase(parent, name ) |
24 | { | 54 | { |
@@ -26,8 +56,2 @@ BtObex::BtObex( QObject *parent, const char* name ) | |||
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; |
@@ -42,8 +66,7 @@ BtObex::~BtObex() { | |||
42 | void BtObex::receive() { | 66 | void 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 |
@@ -63,6 +86,4 @@ void BtObex::receive() { | |||
63 | void BtObex::send( const QString& fileName, const QString& bdaddr) { | 86 | void 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) { |
@@ -152,2 +173,6 @@ void BtObex::sendNow(){ | |||
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); |
@@ -173,2 +198,3 @@ void BtObex::slotExited(OProcess* proc ){ | |||
173 | received(); | 198 | received(); |
199 | |||
174 | } | 200 | } |
@@ -179,2 +205,4 @@ void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ | |||
179 | m_outp.append( ar ); | 205 | m_outp.append( ar ); |
206 | QCString str(buf, len); | ||
207 | odebug << str << oendl; | ||
180 | } | 208 | } |
@@ -209,2 +237,3 @@ void BtObex::received() { | |||
209 | QString filename = parseOut(); | 237 | QString filename = parseOut(); |
238 | odebug << "OBEX " << filename << " received" << oendl; | ||
210 | emit receivedFile( filename ); | 239 | emit receivedFile( filename ); |
@@ -242,2 +271,3 @@ QString BtObex::parseOut(){ | |||
242 | void BtObex::slotError() { | 271 | void BtObex::slotError() { |
272 | ObexBase::slotError(); | ||
243 | if ( m_receive ) | 273 | if ( m_receive ) |
@@ -246,2 +276,4 @@ void BtObex::slotError() { | |||
246 | void BtObex::setReceiveEnabled( bool receive ) { | 276 | void BtObex::setReceiveEnabled( bool receive ) { |
277 | odebug << "BT OBEX setReceiveEnabled " << receive << oendl; | ||
278 | ObexBase::setReceiveEnabled(receive); | ||
247 | if ( !receive ) { // | 279 | if ( !receive ) { // |
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 +1,31 @@ | |||
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 | ||
@@ -5,2 +35,3 @@ | |||
5 | 35 | ||
36 | #include "obexbase.h" | ||
6 | #include <qobject.h> | 37 | #include <qobject.h> |
@@ -9,2 +40,3 @@ | |||
9 | #include <obexpush.h> | 40 | #include <obexpush.h> |
41 | #include "obexserver.h" | ||
10 | 42 | ||
@@ -15,3 +47,3 @@ namespace 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 |
@@ -57,9 +89,4 @@ namespace OpieObex { | |||
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; |
@@ -67,2 +94,3 @@ namespace OpieObex { | |||
67 | void shutDownReceive(); | 94 | void shutDownReceive(); |
95 | ObexServer* m_rec; | ||
68 | 96 | ||
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 +1,31 @@ | |||
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 | ||
@@ -18,3 +48,3 @@ using namespace Opie::Core; | |||
18 | Obex::Obex( QObject *parent, const char* name ) | 48 | Obex::Obex( QObject *parent, const char* name ) |
19 | : QObject(parent, name ) | 49 | : ObexBase(parent, name ) |
20 | { | 50 | { |
@@ -22,8 +52,2 @@ Obex::Obex( QObject *parent, const char* name ) | |||
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 | }; |
@@ -34,4 +58,3 @@ Obex::~Obex() { | |||
34 | void Obex::receive() { | 58 | void Obex::receive() { |
35 | m_receive = true; | 59 | ObexBase::receive(); |
36 | m_outp = QString::null; | ||
37 | m_rec = new OProcess(); | 60 | m_rec = new OProcess(); |
@@ -52,5 +75,5 @@ void Obex::receive() { | |||
52 | 75 | ||
53 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive | 76 | // if currently receiving stop it send receive |
54 | m_count = 0; | 77 | void 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 ) { |
@@ -167,2 +190,3 @@ QString Obex::parseOut( ){ | |||
167 | void Obex::slotError() { | 190 | void Obex::slotError() { |
191 | ObexBase::slotError(); | ||
168 | if ( m_receive ) | 192 | if ( m_receive ) |
@@ -171,2 +195,3 @@ void Obex::slotError() { | |||
171 | void Obex::setReceiveEnabled( bool receive ) { | 195 | void Obex::setReceiveEnabled( bool receive ) { |
196 | ObexBase::setReceiveEnabled(receive); | ||
172 | if ( !receive ) { // | 197 | if ( !receive ) { // |
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,2 +1,31 @@ | |||
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 | ||
@@ -5,2 +34,3 @@ | |||
5 | 34 | ||
35 | #include "obexbase.h" | ||
6 | #include <qobject.h> | 36 | #include <qobject.h> |
@@ -10,3 +40,3 @@ class QCopChannel; | |||
10 | namespace OpieObex { | 40 | namespace OpieObex { |
11 | class Obex : public QObject { | 41 | class Obex : public ObexBase { |
12 | Q_OBJECT | 42 | Q_OBJECT |
@@ -26,5 +56,5 @@ namespace OpieObex { | |||
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: |
@@ -71,3 +101,3 @@ private slots: | |||
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 | ||
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 | |||
@@ -2,4 +2,4 @@ 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 |
@@ -7,6 +7,6 @@ DESTDIR = $(OPIEDIR)/plugins/obex | |||
7 | INTERFACES = obexsendbase.ui | 7 | INTERFACES = obexsendbase.ui |
8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher $(OPIEDIR)/noncore/net/opietooth/lib | 8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher |
9 | DEPENDPATH += | 9 | DEPENDPATH += |
10 | LIBS += -lopietooth1 -lqpe -lopiecore2 | 10 | LIBS += -lqpe -lopiecore2 |
11 | VERSION = 0.0.3 | 11 | VERSION = 0.0.4 |
12 | 12 | ||
@@ -14 +14,7 @@ include( $(OPIEDIR)/include.pro ) | |||
14 | target.path = $$prefix/plugins/applets | 14 | target.path = $$prefix/plugins/applets |
15 | |||
16 | #FIXME: These parameters are used if bluetooth is used | ||
17 | INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib | ||
18 | LIBS += -lopietooth1 -lbluetooth -lopenobex | ||
19 | DEFINES += 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 | |||
38 | using namespace OpieObex; | ||
39 | |||
40 | using namespace Opie::Core; | ||
41 | |||
42 | ObexBase::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 | |||
53 | ObexBase::~ObexBase() { | ||
54 | } | ||
55 | |||
56 | void ObexBase::receive() { | ||
57 | m_receive = true; | ||
58 | m_outp = QString::null; | ||
59 | } | ||
60 | |||
61 | void 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 | |||
68 | void ObexBase::setReceiveEnabled(bool) { | ||
69 | } | ||
70 | |||
71 | void 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 | |||
36 | namespace Opie {namespace Core {class OProcess;}} | ||
37 | class QCopChannel; | ||
38 | namespace 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 | |||
@@ -13,5 +13,8 @@ using namespace OpieObex; | |||
13 | ObexHandler::ObexHandler() { | 13 | ObexHandler::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"); |
@@ -22,3 +25,4 @@ ObexHandler::~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 | } |
@@ -33,10 +37,10 @@ void ObexHandler::doSend(const QString& str, const QString& desc) { | |||
33 | } | 37 | } |
34 | void ObexHandler::doReceive(bool b) { | 38 | void 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 | } |
@@ -49,4 +53,6 @@ void ObexHandler::slotSent() { | |||
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 | } |
@@ -58,4 +64,6 @@ void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { | |||
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); |
@@ -64,3 +72,7 @@ void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { | |||
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 | } |
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 | |||
@@ -5,2 +5,3 @@ | |||
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include "receiver.h" | ||
6 | 7 | ||
@@ -23,3 +24,3 @@ namespace OpieObex { | |||
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(); |
@@ -31,5 +32,5 @@ namespace OpieObex { | |||
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 | }; |
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 | |||
@@ -150,3 +150,3 @@ void SendWidget::slotStartIrda() { | |||
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 | } |
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 | |||
47 | using namespace Opie::Core; | ||
48 | using namespace Opie::Core::Internal; | ||
49 | using namespace OpieObex; | ||
50 | |||
51 | ObexServer::ObexServer() : | ||
52 | OProcess(tr("ObexServer"), 0, "ObexServer") | ||
53 | { | ||
54 | m_obex = NULL; | ||
55 | } | ||
56 | |||
57 | ObexServer::~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 | */ | ||
69 | static 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 | } | ||
86 | out: | ||
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 | */ | ||
100 | static 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 | */ | ||
144 | static 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 | */ | ||
184 | static 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 | */ | ||
224 | static 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 | */ | ||
247 | sdp_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 | } | ||
316 | errout: | ||
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 | |||
327 | int 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 | |||
348 | bool 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 | */ | ||
508 | int 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 | |||
43 | namespace Opie { | ||
44 | namespace Core { | ||
45 | class OProcess; | ||
46 | namespace Internal { | ||
47 | class OProcessController; | ||
48 | } | ||
49 | } | ||
50 | }; | ||
51 | |||
52 | namespace Opie {namespace Core {class OProcess;}} | ||
53 | namespace 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,2 +1,4 @@ | |||
1 | #include "obex.h" | 1 | #include "obex.h" |
2 | #include "btobex.h" | ||
3 | #include "obexbase.h" | ||
2 | #include "receiver.h" | 4 | #include "receiver.h" |
@@ -28,4 +30,7 @@ using namespace Opie::Core; | |||
28 | 30 | ||
29 | Receiver::Receiver() { | 31 | Receiver::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&) ), |
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 | |||
@@ -7,2 +7,8 @@ | |||
7 | 7 | ||
8 | //Receiver type | ||
9 | typedef enum _RecType { | ||
10 | REC_IRDA = 0, | ||
11 | REC_BLUETOOTH = 1 | ||
12 | } RecType; | ||
13 | |||
8 | class QLabel; | 14 | class QLabel; |
@@ -10,3 +16,3 @@ class QTextView; | |||
10 | namespace OpieObex { | 16 | namespace OpieObex { |
11 | class Obex; | 17 | class ObexBase; |
12 | class OtherHandler; | 18 | class OtherHandler; |
@@ -16,3 +22,3 @@ namespace OpieObex { | |||
16 | enum { Datebook , AddressBook, Other }; | 22 | enum { Datebook , AddressBook, Other }; |
17 | Receiver(); | 23 | Receiver(RecType type); |
18 | ~Receiver(); | 24 | ~Receiver(); |
@@ -34,3 +40,3 @@ namespace OpieObex { | |||
34 | private: | 40 | private: |
35 | Obex* m_obex; | 41 | ObexBase* m_obex; //IR obex |
36 | }; | 42 | }; |