Kaydet (Commit) 8de6167e authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile Kaydeden (comit) Caolán McNamara

Resolves: #i122273# - Avoid using tmpfile()

(cherry picked from commit c4ef17d5)

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
üst 39e21050
......@@ -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;
};
}
......
......@@ -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;
}
}
......
......@@ -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.
*/
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment