summaryrefslogtreecommitdiff
path: root/core/obex/receiver.cpp
Unidiff
Diffstat (limited to 'core/obex/receiver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/receiver.cpp73
1 files changed, 52 insertions, 21 deletions
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
@@ -3,2 +3,3 @@
3#include <sys/mman.h> 3#include <sys/mman.h>
4#include <stdlib.h> // int system
4#include <unistd.h> 5#include <unistd.h>
@@ -11,2 +12,3 @@
11#include <qhbox.h> 12#include <qhbox.h>
13#include <qregexp.h>
12#include <qtextview.h> 14#include <qtextview.h>
@@ -17,2 +19,3 @@
17#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/global.h>
18 21
@@ -23,2 +26,4 @@ using namespace OpieObex;
23 26
27/* TRANSLATOR OpieObex::Receiver */
28
24Receiver::Receiver() { 29Receiver::Receiver() {
@@ -33,3 +38,4 @@ Receiver::~Receiver() {
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);
@@ -61,9 +67,33 @@ void Receiver::handleOther( const QString& 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
@@ -72,2 +102,13 @@ int Receiver::checkFile( const QString& file ) {
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 );
@@ -76,2 +117,4 @@ int Receiver::checkFile( const QString& file ) {
76 117
118/* TRANSLATOR OpieObex::OtherHandler */
119
77OtherHandler::OtherHandler() 120OtherHandler::OtherHandler()
@@ -135,2 +178,6 @@ QString 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();
@@ -151,21 +198,5 @@ void 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