From a0bab0e281fbaf6f6ebbb1a48e5c06426bfbbb93 Mon Sep 17 00:00:00 2001 From: kergoth Date: Sat, 09 Aug 2003 17:29:36 +0000 Subject: Merge from BRANCH_1_0 --- (limited to 'core/obex/receiver.cpp') 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,6 +1,7 @@ #include #include #include +#include // int system #include #include @@ -9,18 +10,22 @@ #include #include #include +#include #include #include #include #include #include +#include #include "obex.h" #include "receiver.h" using namespace OpieObex; +/* TRANSLATOR OpieObex::Receiver */ + Receiver::Receiver() { m_obex = new Obex(this, "Receiver"); connect(m_obex, SIGNAL(receivedFile(const QString& ) ), @@ -31,7 +36,8 @@ Receiver::~Receiver() { m_obex->setReceiveEnabled( false ); delete m_obex; } -void Receiver::slotReceived( const QString& file ) { +void Receiver::slotReceived( const QString& _file ) { + QString file = _file; int check = checkFile(file); if ( check == AddressBook ) handleAddr( file ); @@ -59,21 +65,58 @@ void Receiver::handleOther( const QString& other ) { OtherHandler* hand = new OtherHandler(); hand->handle( other ); } -int Receiver::checkFile( const QString& file ) { +void Receiver::tidyUp( QString& _file, const QString& ending) { + /* libversit fails on BASE64 encoding we try to sed it away */ + QString file = _file; + char foo[24]; // big enough + (void)::strcpy(foo, "/tmp/opie-XXXXXX"); + + int fd = ::mkstemp(foo); + + if ( fd == -1 ) + return; + + (void)::strncat( foo, ending.latin1(), 4 ); + _file = QString::fromLatin1( foo ); + QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); + qWarning("Executing: %s", cmd.latin1() ); + (void)::system( cmd.latin1() ); + + cmd = QString("rm %1").arg( Global::shellQuote(file) ); + (void)::system( cmd.latin1() ); +} +int Receiver::checkFile( QString& file ) { qWarning("check file!! %s", file.latin1() ); int ret; + QString ending; + if (file.right(4) == ".vcs" ) { ret = Datebook; + ending = QString::fromLatin1(".vcs"); }else if ( file.right(4) == ".vcf") { ret = AddressBook; + ending = QString::fromLatin1(".vcf"); }else ret = Other; + if (ending.isEmpty() ) + return ret; + + /** + * currently the parser is broken in regard of BASE64 encoding + * and M$ likes to send that. So we will executed a small + * tidy up system sed script + * At this point we can also remove umlaute from the filename + */ + tidyUp( file, ending ); + qWarning("check it now %d", ret ); return ret; } +/* TRANSLATOR OpieObex::OtherHandler */ + OtherHandler::OtherHandler() : QVBox() { @@ -133,6 +176,10 @@ void OtherHandler::deny() { } QString OtherHandler::targetName( const QString& file ) { QFileInfo info( file ); + + /* $HOME needs to be set!!!! */ + Global::createDocDir(); + QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); QString newFileBase = newFile; @@ -149,24 +196,8 @@ QString OtherHandler::targetName( const QString& file ) { /* fast cpy */ void OtherHandler::copy(const QString& src, const QString& file) { qWarning("src %s, dest %s", src.latin1(),file.latin1() ); - int src_fd = ::open( QFile::encodeName( src ), O_RDONLY ); - int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC, - S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP ); - - struct stat stater; - ::fstat(src_fd, &stater ); - ::lseek(to_fd, stater.st_size-1, SEEK_SET ); - ::write(to_fd, "", 1 ); - - void *src_addr, *dest_addr; - src_addr = ::mmap(0, stater.st_size, PROT_READ, - MAP_FILE | MAP_SHARED, src_fd, 0 ); - dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE, - MAP_FILE | MAP_PRIVATE, to_fd, 0 ); - - ::memcpy(dest_addr , src_addr, stater.st_size ); - ::munmap(src_addr , stater.st_size ); - ::munmap(dest_addr, stater.st_size ); - + QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )). + arg( Global::shellQuote( file ) ); + ::system( cmd.latin1() ); // done } -- cgit v0.9.0.2