summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriel Constenla-Haile <arielch@apache.org>2013-06-01 17:16:49 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-06-04 11:09:20 +0100
commit8de6167e36506a5cba21f6a35d4f064e9c9ea368 (patch)
tree33cf12274da8ff1f4bfeda2ea7c5d456bf4d34b9
parent39e21050fe9e47b0496b0f4cc9e85f6577f0f6ce (diff)
Resolves: #i122273# - Avoid using tmpfile()
(cherry picked from commit c4ef17d5e2844ca8d2459a3bfa1f91d99ac297f2) Conflicts: ucb/source/ucp/ftp/ftpcfunc.cxx ucb/source/ucp/ftp/ftpinpstr.cxx ucb/source/ucp/ftp/ftpinpstr.hxx ucb/source/ucp/ftp/ftpurl.cxx Change-Id: I267a9191f9b922380bef8653ac74543662ebf3ef
-rw-r--r--include/ucbhelper/fd_inputstream.hxx35
-rw-r--r--ucb/source/ucp/ftp/ftpcfunc.cxx16
-rw-r--r--ucb/source/ucp/ftp/ftpcfunc.hxx2
-rw-r--r--ucb/source/ucp/ftp/ftpurl.cxx26
-rw-r--r--ucb/source/ucp/ftp/ftpurl.hxx4
-rw-r--r--ucbhelper/source/provider/fd_inputstream.cxx79
6 files changed, 72 insertions, 90 deletions
diff --git a/include/ucbhelper/fd_inputstream.hxx b/include/ucbhelper/fd_inputstream.hxx
index df3d6e386b67..6246af048780 100644
--- a/include/ucbhelper/fd_inputstream.hxx
+++ b/include/ucbhelper/fd_inputstream.hxx
@@ -22,23 +22,26 @@
#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>
#include "ucbhelper/ucbhelperdllapi.h"
namespace ucbhelper
{
+ typedef ::cppu::WeakImplHelper2<
+ com::sun::star::io::XInputStream,
+ com::sun::star::io::XSeekable > FdInputStream_Base;
+
/** Implements a seekable InputStream
* working on a buffer.
*/
class UCBHELPER_DLLPUBLIC FdInputStream
- : public cppu::OWeakObject,
- public com::sun::star::io::XInputStream,
- public com::sun::star::io::XSeekable
+ : protected cppu::BaseMutex,
+ public FdInputStream_Base
{
public:
@@ -46,16 +49,9 @@ namespace ucbhelper
* on which the inputstream acts.
*/
- FdInputStream(FILE* tmpfl = 0);
-
- ~FdInputStream();
-
- virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType)
- throw(css::uno::RuntimeException);
+ FdInputStream(oslFileHandle tmpfl = 0);
- virtual void SAL_CALL acquire(void) throw();
-
- virtual void SAL_CALL release(void) throw();
+ virtual ~FdInputStream();
virtual sal_Int32 SAL_CALL
readBytes(css::uno::Sequence< sal_Int8 >& aData,
@@ -114,14 +110,9 @@ namespace ucbhelper
throw(css::io::IOException,
css::uno::RuntimeException);
- // additional
-// 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/ftpcfunc.cxx b/ucb/source/ucp/ftp/ftpcfunc.cxx
index 1a445ab77337..93e11b92ae6c 100644
--- a/ucb/source/ucp/ftp/ftpcfunc.cxx
+++ b/ucb/source/ucp/ftp/ftpcfunc.cxx
@@ -23,10 +23,8 @@
**************************************************************************
*************************************************************************/
-#include <string.h>
-
+#include <osl/file.h>
#include "ftpcontentidentifier.hxx"
-#include <stdio.h>
using namespace ftp;
using namespace com::sun::star::uno;
@@ -35,11 +33,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 27eced59eb49..127d04b1a0b8 100644
--- a/ucb/source/ucp/ftp/ftpcfunc.hxx
+++ b/ucb/source/ucp/ftp/ftpcfunc.hxx
@@ -46,7 +46,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/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index ecee9edbcffe..50309e9d37f9 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -389,7 +389,7 @@ namespace ftp {
CURLOPT_URL, \
urlParAscii.getStr());
-FILE* FTPURL::open()
+oslFileHandle FTPURL::open()
throw(curl_exception)
{
if(m_aPathSegmentVec.empty())
@@ -400,18 +400,22 @@ FILE* FTPURL::open()
SET_CONTROL_CONTAINER;
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 76603d2d9d82..7d13b5ccc2c2 100644
--- a/ucb/source/ucp/ftp/ftpurl.hxx
+++ b/ucb/source/ucp/ftp/ftpurl.hxx
@@ -30,9 +30,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"
@@ -124,7 +124,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);
diff --git a/ucbhelper/source/provider/fd_inputstream.cxx b/ucbhelper/source/provider/fd_inputstream.cxx
index 835fd38b6ef1..f70a6e9478eb 100644
--- a/ucbhelper/source/provider/fd_inputstream.cxx
+++ b/ucbhelper/source/provider/fd_inputstream.cxx
@@ -21,7 +21,6 @@
#include <rtl/alloc.h>
#include <algorithm>
-#include <stdio.h>
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
@@ -29,48 +28,29 @@ using namespace com::sun::star::io;
namespace ucbhelper
{
- FdInputStream::FdInputStream(FILE* tmpfl)
- : m_tmpfl(tmpfl ? tmpfl : tmpfile())
+ FdInputStream:::FdInputStream:( oslFileHandle tmpfl )
+ : m_tmpfl(tmpfl)
+ , m_nLength( 0 )
{
- fseek(m_tmpfl,0,SEEK_END);
- 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 );
+ }
}
-
-
FdInputStream::~FdInputStream()
{
if ( 0 != m_tmpfl)
- fclose(m_tmpfl);
+ osl_closeFile(m_tmpfl);
}
-
- Any SAL_CALL FdInputStream::queryInterface(
- const Type& rType
- )
- throw(
- RuntimeException
- )
- {
- Any aRet = ::cppu::queryInterface(rType,
- (static_cast< XInputStream* >(this)),
- (static_cast< XSeekable* >(this)) );
-
- return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
- }
-
-
- void SAL_CALL FdInputStream::acquire( void ) throw() {
- OWeakObject::acquire();
- }
-
- void SAL_CALL FdInputStream::release( void ) throw() {
- OWeakObject::release();
- }
-
-
sal_Int32 SAL_CALL FdInputStream::readBytes(Sequence< sal_Int8 >& aData,
sal_Int32 nBytesToRead)
throw(NotConnectedException,
@@ -80,15 +60,22 @@ namespace ucbhelper
{
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 );
+
+ osl_getFilePos( m_tmpfl, &nBeforePos );
+
+ if ( 0 == ( nBytesRequested = std::min< sal_uInt64 >( m_nLength - nBeforePos, nBytesRequested ) ) )
+ return 0;
+
+ if ( 0 <= nBytesToRead && aData.getLength() < nBytesToRead )
+ aData.realloc( nBytesToRead );
- size_t nWanted = static_cast<size_t>(nBytesToRead);
- size_t nRead = fread(aData.getArray(), 1, nWanted, m_tmpfl);
- if (nRead != nWanted && ferror(m_tmpfl))
+ if ( osl_readFile( m_tmpfl, aData.getArray(), nBytesRequested, &nBytesRead ) != osl_File_E_None )
throw IOException();
- return static_cast<sal_Int32>(nRead);
+ return sal_Int32( nBytesRead );
}
@@ -114,7 +101,7 @@ namespace ucbhelper
if(!m_tmpfl)
throw IOException();
- fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR);
+ osl_setFilePos( m_tmpfl, osl_Pos_Current, nBytesToSkip );
}
@@ -165,11 +152,9 @@ namespace ucbhelper
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;
}