summaryrefslogtreecommitdiff
path: root/extensions/source/update/check/download.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/source/update/check/download.cxx')
-rw-r--r--extensions/source/update/check/download.cxx132
1 files changed, 66 insertions, 66 deletions
diff --git a/extensions/source/update/check/download.cxx b/extensions/source/update/check/download.cxx
index 68123924c567..ff1905be1cf2 100644
--- a/extensions/source/update/check/download.cxx
+++ b/extensions/source/update/check/download.cxx
@@ -2,7 +2,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -73,17 +73,17 @@ static void openFile( OutData& out )
{
char * effective_url;
curl_easy_getinfo(out.curl, CURLINFO_EFFECTIVE_URL, &effective_url);
-
+
double fDownloadSize;
curl_easy_getinfo(out.curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fDownloadSize);
-
+
rtl::OString aURL(effective_url);
-
+
// ensure no trailing '/'
sal_Int32 nLen = aURL.getLength();
while( (nLen > 0) && ('/' == aURL[nLen-1]) )
aURL = aURL.copy(0, --nLen);
-
+
// extract file name last '/'
sal_Int32 nIndex = aURL.lastIndexOf('/');
if( nIndex > 0 )
@@ -91,48 +91,48 @@ static void openFile( OutData& out )
out.File = out.DestinationDir + rtl::OStringToOUString(aURL.copy(nIndex), RTL_TEXTENCODING_UTF8);
oslFileError rc;
-
+
// Give the user an overwrite warning if the target file exists
const sal_Int32 openFlags = osl_File_OpenFlag_Write | osl_File_OpenFlag_Create;
do
{
rc = osl_openFile(out.File.pData, &out.FileHandle, openFlags);
-
+
if( osl_File_E_EXIST == rc && ! out.Handler->downloadTargetExists(out.File) )
{
out.StopCondition.set();
break;
}
-
+
} while( osl_File_E_EXIST == rc );
-
+
if( osl_File_E_None == rc )
out.Handler->downloadStarted(out.File, (sal_Int64) fDownloadSize);
- }
+ }
}
//------------------------------------------------------------------------------
-static inline rtl::OString
+static inline rtl::OString
getStringValue(const uno::Reference< container::XNameAccess >& xNameAccess, const rtl::OUString& aName)
{
rtl::OString aRet;
-
+
OSL_ASSERT(xNameAccess->hasByName(aName));
uno::Any aValue = xNameAccess->getByName(aName);
-
+
return rtl::OUStringToOString(aValue.get<rtl::OUString>(), RTL_TEXTENCODING_UTF8);
}
//------------------------------------------------------------------------------
-static inline sal_Int32
-getInt32Value(const uno::Reference< container::XNameAccess >& xNameAccess,
+static inline sal_Int32
+getInt32Value(const uno::Reference< container::XNameAccess >& xNameAccess,
const rtl::OUString& aName, sal_Int32 nDefault=-1)
{
OSL_ASSERT(xNameAccess->hasByName(aName));
uno::Any aValue = xNameAccess->getByName(aName);
-
+
sal_Int32 n=nDefault;
aValue >>= n;
return n;
@@ -140,19 +140,19 @@ getInt32Value(const uno::Reference< container::XNameAccess >& xNameAccess,
//------------------------------------------------------------------------------
-static size_t
+static size_t
write_function( void *ptr, size_t size, size_t nmemb, void *stream )
{
OutData *out = reinterpret_cast < OutData * > (stream);
-
+
if( NULL == out->FileHandle )
openFile(*out);
-
+
sal_uInt64 nBytesWritten = 0;
-
+
if( NULL != out->FileHandle )
osl_writeFile(out->FileHandle, ptr, size * nmemb, &nBytesWritten);
-
+
return (size_t) nBytesWritten;
}
@@ -165,9 +165,9 @@ progress_callback( void *clientp, double dltotal, double dlnow, double ultotal,
(void) ulnow;
OutData *out = reinterpret_cast < OutData * > (clientp);
-
+
OSL_ASSERT( out );
-
+
if( ! out->StopCondition.check() )
{
double fPercent = 0;
@@ -175,56 +175,56 @@ progress_callback( void *clientp, double dltotal, double dlnow, double ultotal,
fPercent = (dlnow + out->Offset) * 100 / (dltotal + out->Offset);
if( fPercent < 0 )
fPercent = 0;
-
+
// Do not report progress for redirection replies
long nCode;
curl_easy_getinfo(out->curl, CURLINFO_RESPONSE_CODE, &nCode);
if( (nCode != 302) && (nCode != 303) && (dltotal > 0) )
out->Handler->downloadProgressAt((sal_Int8)fPercent);
-
+
return 0;
}
-
+
// If stop condition is set, return non 0 value to abort
return -1;
}
//------------------------------------------------------------------------------
-void
+void
Download::getProxyForURL(const rtl::OUString& rURL, rtl::OString& rHost, sal_Int32& rPort) const
{
if( !m_xContext.is() )
- throw uno::RuntimeException(
- UNISTRING( "Download: empty component context" ),
+ throw uno::RuntimeException(
+ UNISTRING( "Download: empty component context" ),
uno::Reference< uno::XInterface >() );
-
+
uno::Reference< lang::XMultiComponentFactory > xServiceManager(m_xContext->getServiceManager());
-
+
if( !xServiceManager.is() )
- throw uno::RuntimeException(
- UNISTRING( "Download: unable to obtain service manager from component context" ),
+ throw uno::RuntimeException(
+ UNISTRING( "Download: unable to obtain service manager from component context" ),
uno::Reference< uno::XInterface >() );
-
- uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
- xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), m_xContext ),
- uno::UNO_QUERY_THROW);
-
+
+ uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
+ xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), m_xContext ),
+ uno::UNO_QUERY_THROW);
+
beans::PropertyValue aProperty;
aProperty.Name = UNISTRING( "nodepath" );
aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Inet/Settings") );
uno::Sequence< uno::Any > aArgumentList( 1 );
aArgumentList[0] = uno::makeAny( aProperty );
-
- uno::Reference< container::XNameAccess > xNameAccess(
- xConfigProvider->createInstanceWithArguments(
+
+ uno::Reference< container::XNameAccess > xNameAccess(
+ xConfigProvider->createInstanceWithArguments(
UNISTRING("com.sun.star.configuration.ConfigurationAccess"), aArgumentList ),
uno::UNO_QUERY_THROW );
-
+
OSL_ASSERT(xNameAccess->hasByName(UNISTRING("ooInetProxyType")));
uno::Any aValue = xNameAccess->getByName(UNISTRING("ooInetProxyType"));
-
+
sal_Int32 nProxyType = aValue.get< sal_Int32 >();
if( 0 != nProxyType ) // type 0 means "direct connection to the internet
{
@@ -250,62 +250,62 @@ Download::getProxyForURL(const rtl::OUString& rURL, rtl::OString& rHost, sal_Int
bool curl_run(const rtl::OUString& rURL, OutData& out, const rtl::OString& aProxyHost, sal_Int32 nProxyPort)
{
- /* Need to investigate further whether it is necessary to call
+ /* Need to investigate further whether it is necessary to call
* curl_global_init or not - leave it for now (as the ftp UCB content
* provider does as well).
*/
-
+
CURL * pCURL = curl_easy_init();
bool ret = false;
-
+
if( NULL != pCURL )
{
out.curl = pCURL;
-
+
rtl::OString aURL(rtl::OUStringToOString(rURL, RTL_TEXTENCODING_UTF8));
curl_easy_setopt(pCURL, CURLOPT_URL, aURL.getStr());
-
+
// abort on http errors
curl_easy_setopt(pCURL, CURLOPT_FAILONERROR, 1);
// enable redirection
curl_easy_setopt(pCURL, CURLOPT_FOLLOWLOCATION, 1);
-
+
// write function
curl_easy_setopt(pCURL, CURLOPT_WRITEDATA, &out);
curl_easy_setopt(pCURL, CURLOPT_WRITEFUNCTION, &write_function);
-
+
// progress handler - Condition::check unfortunatly is not defined const
curl_easy_setopt(pCURL, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(pCURL, CURLOPT_PROGRESSFUNCTION, &progress_callback);
curl_easy_setopt(pCURL, CURLOPT_PROGRESSDATA, &out);
-
+
// proxy
curl_easy_setopt(pCURL, CURLOPT_PROXY, aProxyHost.getStr());
curl_easy_setopt(pCURL, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if( -1 != nProxyPort )
curl_easy_setopt(pCURL, CURLOPT_PROXYPORT, nProxyPort);
-
+
if( out.Offset > 0 )
{
- // curl_off_t offset = nOffset; libcurl seems to be compiled with large
+ // curl_off_t offset = nOffset; libcurl seems to be compiled with large
// file support (and we not) ..
sal_Int64 offset = (sal_Int64) out.Offset;
curl_easy_setopt(pCURL, CURLOPT_RESUME_FROM_LARGE, offset);
}
-
+
CURLcode cc = curl_easy_perform(pCURL);
// treat zero byte downloads as errors
if( NULL == out.FileHandle )
openFile(out);
-
+
if( CURLE_OK == cc )
{
out.Handler->downloadFinished(out.File);
ret = true;
}
-
+
if ( CURLE_PARTIAL_FILE == cc )
{
// this sometimes happens, when a user throws away his user data, but has already
@@ -318,7 +318,7 @@ bool curl_run(const rtl::OUString& rURL, OutData& out, const rtl::OString& aProx
ret = true;
}
}
-
+
// Avoid target file being removed
else if( (CURLE_ABORTED_BY_CALLBACK == cc) || out.StopCondition.check() )
ret = true;
@@ -327,7 +327,7 @@ bool curl_run(const rtl::OUString& rURL, OutData& out, const rtl::OString& aProx
else
{
rtl::OString aMessage(RTL_CONSTASCII_STRINGPARAM("Unknown error"));
-
+
const char * error_message = curl_easy_strerror(cc);
if( NULL != error_message )
aMessage = error_message;
@@ -357,20 +357,20 @@ bool curl_run(const rtl::OUString& rURL, OutData& out, const rtl::OString& aProx
if ( !ret )
out.Handler->downloadStalled( rtl::OStringToOUString(aMessage, RTL_TEXTENCODING_UTF8) );
}
-
+
curl_easy_cleanup(pCURL);
}
-
+
return ret;
}
//------------------------------------------------------------------------------
-bool
+bool
Download::start(const rtl::OUString& rURL, const rtl::OUString& rFile, const rtl::OUString& rDestinationDir)
{
OSL_ASSERT( m_aHandler.is() );
-
+
OutData out(m_aCondition);
rtl::OUString aFile( rFile );
@@ -430,13 +430,13 @@ Download::start(const rtl::OUString& rURL, const rtl::OUString& rFile, const rtl
else if( osl_File_E_NOENT == rc ) // file has been deleted meanwhile ..
out.File = rtl::OUString();
}
-
+
rtl::OString aProxyHost;
sal_Int32 nProxyPort = -1;
getProxyForURL(rURL, aProxyHost, nProxyPort);
bool ret = curl_run(rURL, out, aProxyHost, nProxyPort);
-
+
if( NULL != out.FileHandle )
{
osl_syncFile(out.FileHandle);
@@ -447,14 +447,14 @@ Download::start(const rtl::OUString& rURL, const rtl::OUString& rFile, const rtl
// if( ! ret )
// osl_removeFile(out.File.pData);
}
-
+
m_aCondition.reset();
return ret;
}
//------------------------------------------------------------------------------
-void
+void
Download::stop()
{
m_aCondition.set();