ucb/source/ucp/ftp/ftpcfunc.cxx | 14 +++-- ucb/source/ucp/ftp/ftpcfunc.hxx | 2 ucb/source/ucp/ftp/ftpinpstr.cxx | 92 +++++++++++++-------------------------- ucb/source/ucp/ftp/ftpinpstr.hxx | 29 ++++-------- ucb/source/ucp/ftp/ftpurl.cxx | 26 ++++++----- ucb/source/ucp/ftp/ftpurl.hxx | 4 - 6 files changed, 70 insertions(+), 97 deletions(-)
New commits: commit c4ef17d5e2844ca8d2459a3bfa1f91d99ac297f2 Author: Ariel Constenla-Haile <arie...@apache.org> Date: Sat Jun 1 17:16:49 2013 +0000 i122273 - Avoid using tmpfile() diff --git a/ucb/source/ucp/ftp/ftpcfunc.cxx b/ucb/source/ucp/ftp/ftpcfunc.cxx index 7146308..f6adc8b 100644 --- a/ucb/source/ucp/ftp/ftpcfunc.cxx +++ b/ucb/source/ucp/ftp/ftpcfunc.cxx @@ -33,7 +33,7 @@ #include "ftpcontentidentifier.hxx" #include "ftpinpstr.hxx" -#include <stdio.h> +#include <osl/file.h> using namespace ftp; using namespace com::sun::star::uno; @@ -42,11 +42,15 @@ extern "C" { int file_write(void *buffer,size_t size,size_t nmemb,void *stream) { - FILE* file = - reinterpret_cast<FILE*>(stream); - if(!file) + oslFileHandle aFile = reinterpret_cast< oslFileHandle >( stream ); + if( !aFile ) return 0; - return fwrite(buffer,size,nmemb,file); + + sal_uInt64 nWritten = 0; + sal_uInt64 nToWrite( size * nmemb ); + osl_writeFile( aFile, buffer, nToWrite, &nWritten ); + + return nWritten != nToWrite ? 0 : nmemb; } } diff --git a/ucb/source/ucp/ftp/ftpcfunc.hxx b/ucb/source/ucp/ftp/ftpcfunc.hxx index 8da6a93..2b31710 100644 --- a/ucb/source/ucp/ftp/ftpcfunc.hxx +++ b/ucb/source/ucp/ftp/ftpcfunc.hxx @@ -48,7 +48,7 @@ extern "C" { /** callback for curl_easy_perform(), * forwarding the written content to the stream. - * stream has to be of type 'FTPStreamContainer'. + * stream has to be of type oslFileHandle. */ diff --git a/ucb/source/ucp/ftp/ftpinpstr.cxx b/ucb/source/ucp/ftp/ftpinpstr.cxx index d44bc0b..be88f35 100644 --- a/ucb/source/ucp/ftp/ftpinpstr.cxx +++ b/ucb/source/ucp/ftp/ftpinpstr.cxx @@ -37,7 +37,6 @@ #include <algorithm> #define STD_ALGORITHM #endif -#include <stdio.h> using namespace ftp; using namespace com::sun::star::uno; @@ -45,53 +44,29 @@ using namespace com::sun::star::lang; using namespace com::sun::star::io; -FTPInputStream::FTPInputStream(FILE* tmpfl) - : m_tmpfl(tmpfl ? tmpfl : tmpfile()) +FTPInputStream::FTPInputStream( oslFileHandle tmpfl ) + : m_tmpfl(tmpfl) + , m_nLength( 0 ) { - fseek(m_tmpfl,0,SEEK_END); -// fpos_t pos; -// fgetpos(m_tmpfl,&pos); - long pos = ftell(m_tmpfl); - rewind(m_tmpfl); - m_nLength = sal_Int64(pos); + if ( !m_tmpfl ) + osl_createTempFile( NULL, &m_tmpfl, NULL ); + OSL_ENSURE( m_tmpfl, "input stream without tempfile!" ); + + if ( osl_setFilePos( m_tmpfl, osl_Pos_End, 0 ) == osl_File_E_None ) + { + sal_uInt64 nFileSize = 0; + if ( osl_getFilePos( m_tmpfl, &nFileSize ) == osl_File_E_None ) + m_nLength = nFileSize; + osl_setFilePos( m_tmpfl, osl_Pos_Absolut, 0 ); + } } - - FTPInputStream::~FTPInputStream() { if ( 0 != m_tmpfl) - fclose(m_tmpfl); -} - - -Any SAL_CALL FTPInputStream::queryInterface( - const Type& rType -) - throw( - RuntimeException - ) -{ - Any aRet = ::cppu::queryInterface(rType, - SAL_STATIC_CAST( XInputStream*,this ), - SAL_STATIC_CAST( XSeekable*,this ) ); - - return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); + osl_closeFile(m_tmpfl); } - - -void SAL_CALL FTPInputStream::acquire( void ) throw() { - OWeakObject::acquire(); -} - - - -void SAL_CALL FTPInputStream::release( void ) throw() { - OWeakObject::release(); -} - - sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(NotConnectedException, @@ -101,23 +76,22 @@ sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, { osl::MutexGuard aGuard(m_aMutex); - if(0 <= nBytesToRead && aData.getLength() < nBytesToRead) - aData.realloc(nBytesToRead); + sal_uInt64 nBeforePos( 0 ); + sal_uInt64 nBytesRequested( nBytesToRead ); + sal_uInt64 nBytesRead( 0 ); -// fpos_t bpos,epos; + osl_getFilePos( m_tmpfl, &nBeforePos ); -// fgetpos(m_tmpfl,&bpos); -// fread(aData.getArray(),nBytesToRead,1,m_tmpfl); -// fgetpos(m_tmpfl,&epos); - long bpos,epos; + if ( 0 == ( nBytesRequested = std::min< sal_uInt64 >( m_nLength - nBeforePos, nBytesRequested ) ) ) + return 0; - bpos = ftell(m_tmpfl); - if (fread(aData.getArray(),nBytesToRead,1,m_tmpfl) != 1) - throw IOException(); + if ( 0 <= nBytesToRead && aData.getLength() < nBytesToRead ) + aData.realloc( nBytesToRead ); - epos = ftell(m_tmpfl); + if ( osl_readFile( m_tmpfl, aData.getArray(), nBytesRequested, &nBytesRead ) != osl_File_E_None ) + throw IOException(); - return sal_Int32(epos-bpos); + return sal_Int32( nBytesRead ); } @@ -143,7 +117,7 @@ void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip) if(!m_tmpfl) throw IOException(); - fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR); + osl_setFilePos( m_tmpfl, osl_Pos_Current, nBytesToSkip ); } @@ -165,7 +139,7 @@ void SAL_CALL FTPInputStream::closeInput(void) { osl::MutexGuard aGuard(m_aMutex); if(m_tmpfl) - fclose(m_tmpfl),m_tmpfl = 0; + osl_closeFile(m_tmpfl),m_tmpfl = 0; } @@ -179,7 +153,7 @@ void SAL_CALL FTPInputStream::seek(sal_Int64 location) if(!m_tmpfl) throw IOException(); - fseek(m_tmpfl,long(location),SEEK_SET); + osl_setFilePos( m_tmpfl, osl_Pos_Absolut, location ); } @@ -194,11 +168,9 @@ FTPInputStream::getPosition( if(!m_tmpfl) throw IOException(); -// fpos_t pos; -// fgetpos(m_tmpfl,&pos); - long pos; - pos = ftell(m_tmpfl); - return sal_Int64(pos); + sal_uInt64 nFilePos = 0; + osl_getFilePos( m_tmpfl, &nFilePos ); + return nFilePos; } diff --git a/ucb/source/ucp/ftp/ftpinpstr.hxx b/ucb/source/ucp/ftp/ftpinpstr.hxx index 24acc01..9195ff4 100644 --- a/ucb/source/ucp/ftp/ftpinpstr.hxx +++ b/ucb/source/ucp/ftp/ftpinpstr.hxx @@ -33,11 +33,11 @@ #include <rtl/ustring.hxx> #include <osl/mutex.hxx> -#include <cppuhelper/weak.hxx> -#include <cppuhelper/queryinterface.hxx> +#include <osl/file.h> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XSeekable.hpp> -#include <stdio.h> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/basemutex.hxx> namespace ftp { @@ -50,11 +50,13 @@ namespace ftp { namespace css = com::sun::star; + typedef ::cppu::WeakImplHelper2< + com::sun::star::io::XInputStream, + com::sun::star::io::XSeekable > FTPInputStream_Base; class FTPInputStream - : public cppu::OWeakObject, - public com::sun::star::io::XInputStream, - public com::sun::star::io::XSeekable + : protected cppu::BaseMutex, + public FTPInputStream_Base { public: @@ -62,17 +64,10 @@ namespace ftp { * on which the inputstream acts. */ - FTPInputStream(FILE* tmpfl = 0); + FTPInputStream(oslFileHandle tmpfl = 0); ~FTPInputStream(); - virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType) - throw(css::uno::RuntimeException); - - virtual void SAL_CALL acquire(void) throw(); - - virtual void SAL_CALL release(void) throw(); - virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) @@ -135,10 +130,8 @@ namespace ftp { // void append(const void* pBuffer,size_t size,size_t nmemb); private: - - osl::Mutex m_aMutex; - FILE* m_tmpfl; - sal_Int64 m_nLength; + oslFileHandle m_tmpfl; + sal_uInt64 m_nLength; }; diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx index 98d2a75..053618d 100644 --- a/ucb/source/ucp/ftp/ftpurl.cxx +++ b/ucb/source/ucp/ftp/ftpurl.cxx @@ -412,7 +412,7 @@ namespace ftp { -FILE* FTPURL::open() +oslFileHandle FTPURL::open() throw(curl_exception) { if(!m_aPathSegmentVec.size()) @@ -423,18 +423,22 @@ FILE* FTPURL::open() SET_CONTROL_CONTAINER; rtl::OUString url(ident(false,true)); SET_URL(url); - FILE *res = tmpfile(); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,file_write); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,res); - curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); - CURLcode err = curl_easy_perform(curl); + oslFileHandle res( NULL ); + if ( osl_createTempFile( NULL, &res, NULL ) == osl_File_E_None ) + { + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,file_write); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,res); - if(err == CURLE_OK) - rewind(res); - else { - fclose(res),res = 0; - throw curl_exception(err); + curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); + CURLcode err = curl_easy_perform(curl); + + if(err == CURLE_OK) + osl_setFilePos( res, osl_Pos_Absolut, 0 ); + else { + osl_closeFile(res),res = 0; + throw curl_exception(err); + } } return res; diff --git a/ucb/source/ucp/ftp/ftpurl.hxx b/ucb/source/ucp/ftp/ftpurl.hxx index 38e6010..ad0746f 100644 --- a/ucb/source/ucp/ftp/ftpurl.hxx +++ b/ucb/source/ucp/ftp/ftpurl.hxx @@ -34,9 +34,9 @@ #include <curl/easy.h> #include <com/sun/star/io/XOutputStream.hpp> -#include <stdio.h> #include <rtl/ustring.hxx> #include <osl/mutex.hxx> +#include <osl/file.h> #include <vector> #include "ftpdirp.hxx" @@ -127,7 +127,7 @@ namespace ftp { // returns a pointer to an open tempfile, // seeked to the beginning of. - FILE* open() throw(curl_exception); + oslFileHandle open() throw(curl_exception); FTPDirentry direntry() const throw(curl_exception); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits