summaryrefslogtreecommitdiff
path: root/core/obex
authorkergoth <kergoth>2003-08-09 17:29:36 (UTC)
committer kergoth <kergoth>2003-08-09 17:29:36 (UTC)
commita0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93 (patch) (unidiff)
tree5ce78e1a5dedd31b7851d53bf9f072bd44edd1b0 /core/obex
parenta7e015198a8c5ad3b6e144a9032b059086253e00 (diff)
downloadopie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.zip
opie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.tar.gz
opie-a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93.tar.bz2
Merge from BRANCH_1_0
Diffstat (limited to 'core/obex') (more/less context) (show whitespace changes)
-rw-r--r--core/obex/obex.cc13
-rw-r--r--core/obex/obexhandler.cpp2
-rw-r--r--core/obex/obeximpl.cpp2
-rw-r--r--core/obex/obexsend.cpp2
-rw-r--r--core/obex/receiver.cpp73
-rw-r--r--core/obex/receiver.h5
6 files changed, 64 insertions, 33 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc
index 595fed9..2a306de 100644
--- a/core/obex/obex.cc
+++ b/core/obex/obex.cc
@@ -8,12 +8,14 @@
8 8
9#include <opie/oprocess.h> 9#include <opie/oprocess.h>
10#include "obex.h" 10#include "obex.h"
11 11
12using namespace OpieObex; 12using namespace OpieObex;
13 13
14/* TRANSLATOR OpieObex::Obex */
15
14Obex::Obex( QObject *parent, const char* name ) 16Obex::Obex( QObject *parent, const char* name )
15 : QObject(parent, name ) 17 : QObject(parent, name )
16{ 18{
17 m_rec = 0; 19 m_rec = 0;
18 m_send=0; 20 m_send=0;
19 m_count = 0; 21 m_count = 0;
@@ -106,35 +108,24 @@ void Obex::slotExited(OProcess* proc ){
106 }else if ( proc == m_send ) { 108 }else if ( proc == m_send ) {
107 sendEnd(); 109 sendEnd();
108 } 110 }
109} 111}
110void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 112void Obex::slotStdOut(OProcess* proc, char* buf, int len){
111 if ( proc == m_rec ) { // only receive 113 if ( proc == m_rec ) { // only receive
112 for (int i = 0; i < len; i++ ) {
113 printf("%c", buf[i] );
114 }
115 printf("\n");
116 QByteArray ar( len ); 114 QByteArray ar( len );
117 memcpy( ar.data(), buf, len ); 115 memcpy( ar.data(), buf, len );
118 qWarning("parsed: %s", ar.data() ); 116 qWarning("parsed: %s", ar.data() );
119 m_outp.append( ar ); 117 m_outp.append( ar );
120 } 118 }
121} 119}
122 120
123void Obex::received() { 121void Obex::received() {
124 if (m_rec->normalExit() ) { 122 if (m_rec->normalExit() ) {
125 if ( m_rec->exitStatus() == 0 ) { // we got one 123 if ( m_rec->exitStatus() == 0 ) { // we got one
126 QString filename = parseOut(); 124 QString filename = parseOut();
127 qWarning("ACHTUNG %s", filename.latin1() ); 125 qWarning("ACHTUNG %s", filename.latin1() );
128 if (filename.contains( 'ö' ) || filename.contains( 'ä' ) || filename.contains('ü' ) ) {
129 qWarning("renaming!!!!");
130 QFileInfo inf( filename );
131 QString newName = "/tmp/opie-obex." + inf.extension();
132 ::rename( QFile::encodeName( filename ).data(), newName );
133 qWarning("name is %s", QFile::encodeName( filename ).data() );
134 }
135 emit receivedFile( filename ); 126 emit receivedFile( filename );
136 } 127 }
137 }else{ 128 }else{
138 emit done(false); 129 emit done(false);
139 }; 130 };
140 delete m_rec; 131 delete m_rec;
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp
index 6509d12..5aaf63c 100644
--- a/core/obex/obexhandler.cpp
+++ b/core/obex/obexhandler.cpp
@@ -5,12 +5,14 @@
5#include "obexsend.h" 5#include "obexsend.h"
6#include "receiver.h" 6#include "receiver.h"
7#include "obexhandler.h" 7#include "obexhandler.h"
8 8
9using namespace OpieObex; 9using namespace OpieObex;
10 10
11/* TRANSLATOR OpieObex::ObexHandler */
12
11ObexHandler::ObexHandler() { 13ObexHandler::ObexHandler() {
12 m_wasRec = false; 14 m_wasRec = false;
13 m_sender = 0l; 15 m_sender = 0l;
14 m_receiver = 0l; 16 m_receiver = 0l;
15 QCopChannel* chan = new QCopChannel("QPE/Obex"); 17 QCopChannel* chan = new QCopChannel("QPE/Obex");
16 connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), 18 connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
diff --git a/core/obex/obeximpl.cpp b/core/obex/obeximpl.cpp
index 12a078f..5bfc779 100644
--- a/core/obex/obeximpl.cpp
+++ b/core/obex/obeximpl.cpp
@@ -1,11 +1,13 @@
1#include "obexhandler.h" 1#include "obexhandler.h"
2#include "obeximpl.h" 2#include "obeximpl.h"
3 3
4using namespace OpieObex; 4using namespace OpieObex;
5 5
6/* TRANSLATOR OpieObex::ObexImpl */
7
6ObexImpl::ObexImpl() { 8ObexImpl::ObexImpl() {
7 m_handler = new ObexHandler; 9 m_handler = new ObexHandler;
8} 10}
9ObexImpl::~ObexImpl() { 11ObexImpl::~ObexImpl() {
10 delete m_handler; 12 delete m_handler;
11} 13}
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index 2931cf7..cf5d958 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -12,12 +12,14 @@
12 12
13#include "obex.h" 13#include "obex.h"
14#include "obexsend.h" 14#include "obexsend.h"
15 15
16using namespace OpieObex; 16using namespace OpieObex;
17 17
18/* TRANSLATOR OpieObex::SendWidget */
19
18 20
19SendWidget::SendWidget( QWidget* parent, const char* name ) 21SendWidget::SendWidget( QWidget* parent, const char* name )
20 : QWidget( parent, name ) { 22 : QWidget( parent, name ) {
21 initUI(); 23 initUI();
22} 24}
23SendWidget::~SendWidget() { 25SendWidget::~SendWidget() {
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index 31c6afe..bf9e30c 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -1,40 +1,46 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/mman.h> 3#include <sys/mman.h>
4#include <stdlib.h> // int system
4#include <unistd.h> 5#include <unistd.h>
5 6
6#include <fcntl.h> 7#include <fcntl.h>
7 8
8#include <qfile.h> 9#include <qfile.h>
9#include <qfileinfo.h> 10#include <qfileinfo.h>
10#include <qlabel.h> 11#include <qlabel.h>
11#include <qhbox.h> 12#include <qhbox.h>
13#include <qregexp.h>
12#include <qtextview.h> 14#include <qtextview.h>
13#include <qpushbutton.h> 15#include <qpushbutton.h>
14 16
15#include <qpe/applnk.h> 17#include <qpe/applnk.h>
16#include <qpe/qpeapplication.h> 18#include <qpe/qpeapplication.h>
17#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/global.h>
18 21
19#include "obex.h" 22#include "obex.h"
20#include "receiver.h" 23#include "receiver.h"
21 24
22using namespace OpieObex; 25using namespace OpieObex;
23 26
27/* TRANSLATOR OpieObex::Receiver */
28
24Receiver::Receiver() { 29Receiver::Receiver() {
25 m_obex = new Obex(this, "Receiver"); 30 m_obex = new Obex(this, "Receiver");
26 connect(m_obex, SIGNAL(receivedFile(const QString& ) ), 31 connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
27 this, SLOT(slotReceived(const QString& ) ) ); 32 this, SLOT(slotReceived(const QString& ) ) );
28 m_obex->receive(); 33 m_obex->receive();
29} 34}
30Receiver::~Receiver() { 35Receiver::~Receiver() {
31 m_obex->setReceiveEnabled( false ); 36 m_obex->setReceiveEnabled( false );
32 delete m_obex; 37 delete m_obex;
33} 38}
34void Receiver::slotReceived( const QString& file ) { 39void Receiver::slotReceived( const QString& _file ) {
40 QString file = _file;
35 int check = checkFile(file); 41 int check = checkFile(file);
36 if ( check == AddressBook ) 42 if ( check == AddressBook )
37 handleAddr( file ); 43 handleAddr( file );
38 else if ( check == Datebook ) 44 else if ( check == Datebook )
39 handleDateTodo( file ); 45 handleDateTodo( file );
40 else 46 else
@@ -56,27 +62,64 @@ void Receiver::handleDateTodo( const QString& str ) {
56 * beamed object and creates a DocLnk 62 * beamed object and creates a DocLnk
57 */ 63 */
58void Receiver::handleOther( const QString& other ) { 64void Receiver::handleOther( const QString& other ) {
59 OtherHandler* hand = new OtherHandler(); 65 OtherHandler* hand = new OtherHandler();
60 hand->handle( other ); 66 hand->handle( other );
61} 67}
62int Receiver::checkFile( const QString& file ) { 68void Receiver::tidyUp( QString& _file, const QString& ending) {
69 /* libversit fails on BASE64 encoding we try to sed it away */
70 QString file = _file;
71 char foo[24]; // big enough
72 (void)::strcpy(foo, "/tmp/opie-XXXXXX");
73
74 int fd = ::mkstemp(foo);
75
76 if ( fd == -1 )
77 return;
78
79 (void)::strncat( foo, ending.latin1(), 4 );
80 _file = QString::fromLatin1( foo );
81 QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) );
82 qWarning("Executing: %s", cmd.latin1() );
83 (void)::system( cmd.latin1() );
84
85 cmd = QString("rm %1").arg( Global::shellQuote(file) );
86 (void)::system( cmd.latin1() );
87}
88int Receiver::checkFile( QString& file ) {
63 qWarning("check file!! %s", file.latin1() ); 89 qWarning("check file!! %s", file.latin1() );
64 int ret; 90 int ret;
91 QString ending;
92
65 if (file.right(4) == ".vcs" ) { 93 if (file.right(4) == ".vcs" ) {
66 ret = Datebook; 94 ret = Datebook;
95 ending = QString::fromLatin1(".vcs");
67 }else if ( file.right(4) == ".vcf") { 96 }else if ( file.right(4) == ".vcf") {
68 ret = AddressBook; 97 ret = AddressBook;
98 ending = QString::fromLatin1(".vcf");
69 }else 99 }else
70 ret = Other; 100 ret = Other;
71 101
72 102
103 if (ending.isEmpty() )
104 return ret;
105
106 /**
107 * currently the parser is broken in regard of BASE64 encoding
108 * and M$ likes to send that. So we will executed a small
109 * tidy up system sed script
110 * At this point we can also remove umlaute from the filename
111 */
112 tidyUp( file, ending );
113
73 qWarning("check it now %d", ret ); 114 qWarning("check it now %d", ret );
74 return ret; 115 return ret;
75} 116}
76 117
118/* TRANSLATOR OpieObex::OtherHandler */
119
77OtherHandler::OtherHandler() 120OtherHandler::OtherHandler()
78 : QVBox() 121 : QVBox()
79{ 122{
80 QHBox* box = new QHBox(this); 123 QHBox* box = new QHBox(this);
81 QLabel* lbl = new QLabel(box); 124 QLabel* lbl = new QLabel(box);
82 lbl->setText(tr("<qt><b>Received:</b></qt>")); 125 lbl->setText(tr("<qt><b>Received:</b></qt>"));
@@ -130,12 +173,16 @@ void OtherHandler::accept() {
130void OtherHandler::deny() { 173void OtherHandler::deny() {
131 QFile::remove( m_file ); 174 QFile::remove( m_file );
132 delete this; 175 delete this;
133} 176}
134QString OtherHandler::targetName( const QString& file ) { 177QString OtherHandler::targetName( const QString& file ) {
135 QFileInfo info( file ); 178 QFileInfo info( file );
179
180 /* $HOME needs to be set!!!! */
181 Global::createDocDir();
182
136 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); 183 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
137 QString newFileBase = newFile; 184 QString newFileBase = newFile;
138 185
139 int trie = 0; 186 int trie = 0;
140 while (QFile::exists(newFile + "."+info.extension() ) ) { 187 while (QFile::exists(newFile + "."+info.extension() ) ) {
141 newFile = newFileBase + "_"+QString::number(trie) ; 188 newFile = newFileBase + "_"+QString::number(trie) ;
@@ -146,27 +193,11 @@ QString OtherHandler::targetName( const QString& file ) {
146 return newFile; 193 return newFile;
147} 194}
148 195
149/* fast cpy */ 196/* fast cpy */
150void OtherHandler::copy(const QString& src, const QString& file) { 197void OtherHandler::copy(const QString& src, const QString& file) {
151 qWarning("src %s, dest %s", src.latin1(),file.latin1() ); 198 qWarning("src %s, dest %s", src.latin1(),file.latin1() );
152 int src_fd = ::open( QFile::encodeName( src ), O_RDONLY ); 199 QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )).
153 int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC, 200 arg( Global::shellQuote( file ) );
154 S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP ); 201 ::system( cmd.latin1() );
155
156 struct stat stater;
157 ::fstat(src_fd, &stater );
158 ::lseek(to_fd, stater.st_size-1, SEEK_SET );
159 ::write(to_fd, "", 1 );
160
161 void *src_addr, *dest_addr;
162 src_addr = ::mmap(0, stater.st_size, PROT_READ,
163 MAP_FILE | MAP_SHARED, src_fd, 0 );
164 dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE,
165 MAP_FILE | MAP_PRIVATE, to_fd, 0 );
166
167 ::memcpy(dest_addr , src_addr, stater.st_size );
168 ::munmap(src_addr , stater.st_size );
169 ::munmap(dest_addr, stater.st_size );
170
171 // done 202 // done
172} 203}
diff --git a/core/obex/receiver.h b/core/obex/receiver.h
index 5b20146..e1d54df 100644
--- a/core/obex/receiver.h
+++ b/core/obex/receiver.h
@@ -18,15 +18,18 @@ namespace OpieObex {
18 ~Receiver(); 18 ~Receiver();
19 19
20 private: 20 private:
21 void handleAddr(const QString& ); 21 void handleAddr(const QString& );
22 void handleDateTodo(const QString& ); 22 void handleDateTodo(const QString& );
23 void handleOther(const QString& ); 23 void handleOther(const QString& );
24 int checkFile( const QString& file ); 24 /* will alter the file name */
25 int checkFile( QString& file );
25 bool testDateTodo(const QString& file); 26 bool testDateTodo(const QString& file);
26 bool testAddressbook(const QString& file); 27 bool testAddressbook(const QString& file);
28 /* called by checkFile */
29 void tidyUp( QString& file, const QString& ending );
27 30
28 private slots: 31 private slots:
29 void slotReceived( const QString& ); 32 void slotReceived( const QString& );
30 33
31 private: 34 private:
32 Obex* m_obex; 35 Obex* m_obex;