summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Castagno <giuseppe.castagno@acca-esse.eu>2016-07-26 11:36:24 +0200
committerGiuseppe Castagno <giuseppe.castagno@acca-esse.eu>2016-07-29 21:33:39 +0000
commit7f32fddb445ef1c1e17f9028f252c21dd83e03af (patch)
treeea3202cc8a1f5cdf49c794a2d372b167fa874b40
parenta3e57b44b26db382b7fe3004aa0211e26c07e6db (diff)
tdf#101094 (19) OPTIONS: Add mechanism to manage not found Web URL: GET
Change-Id: Ie3da55d230631c50968b00cdea176f30051abf37 Reviewed-on: https://gerrit.libreoffice.org/27699 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Giuseppe Castagno <giuseppe.castagno@acca-esse.eu>
-rw-r--r--ucb/source/ucp/webdav-neon/DAVTypes.cxx29
-rw-r--r--ucb/source/ucp/webdav-neon/DAVTypes.hxx15
-rw-r--r--ucb/source/ucp/webdav-neon/webdavcontent.cxx54
3 files changed, 83 insertions, 15 deletions
diff --git a/ucb/source/ucp/webdav-neon/DAVTypes.cxx b/ucb/source/ucp/webdav-neon/DAVTypes.cxx
index 2f4feb3a6a02..8613bdae5a8c 100644
--- a/ucb/source/ucp/webdav-neon/DAVTypes.cxx
+++ b/ucb/source/ucp/webdav-neon/DAVTypes.cxx
@@ -145,4 +145,33 @@ void DAVOptionsCache::addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32
}
+bool DAVOptionsCache::isResourceFound( const OUString & rURL )
+{
+ osl::MutexGuard aGuard( m_aMutex );
+ OUString aEncodedUrl( ucb_impl::urihelper::encodeURI( NeonUri::unescape( rURL ) ) );
+ normalizeURLLastChar( aEncodedUrl );
+
+ DAVOptionsMap::iterator it;
+ it = m_aTheCache.find( aEncodedUrl );
+ if ( it != m_aTheCache.end() )
+ {
+ // first check for stale
+ TimeValue t1;
+ osl_getSystemTime( &t1 );
+ if( (*it).second.getStaleTime() < t1.Seconds )
+ {
+ m_aTheCache.erase( it );
+ return true; // to force again OPTIONS method
+ }
+
+ // check if the resource was present on server
+ return (*it).second.isResourceFound();
+ }
+ // this value is needed because some web server don't implement
+ // OPTIONS method, so the resource is considered found,
+ // until detected otherwise
+ return true;
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/ucb/source/ucp/webdav-neon/DAVTypes.hxx b/ucb/source/ucp/webdav-neon/DAVTypes.hxx
index 6dbdd2025c51..b1a97c22b45a 100644
--- a/ucb/source/ucp/webdav-neon/DAVTypes.hxx
+++ b/ucb/source/ucp/webdav-neon/DAVTypes.hxx
@@ -158,6 +158,21 @@ namespace webdav_ucp
void removeDAVOptions( const OUString & rURL );
void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 nLifeTime );
+ /** Check if the DAV options cached value was found
+ by the last OPTIONS method call.
+ If the cached value is found stale, it is removed.
+
+ @param OUString
+ the resource URL
+
+ @return bool
+ true if resource was found or if the Web resource DAV options
+ are not present (meaning the resource should be checked for
+ presence anyway)
+ false if resource was not found
+ */
+ bool isResourceFound( const OUString & rURL );
+
private:
/// remove the last '/' in aUrl, if it exists
diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
index 01eba4ebf7e1..902bc7671cf2 100644
--- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
@@ -2126,26 +2126,50 @@ uno::Any Content::open(
DAVResource aResource;
std::vector< OUString > aHeaders;
- uno::Reference< io::XInputStream > xIn
- = xResAccess->GET( aHeaders, aResource, xEnv );
- m_bDidGetOrHead = true;
-
+ // check if the resource was present on the server
+ if( aStaticDAVOptionsCache.isResourceFound( aTargetURL ) )
{
- osl::MutexGuard aGuard( m_aMutex );
+ uno::Reference< io::XInputStream > xIn
+ = xResAccess->GET( aHeaders, aResource, xEnv );
+ m_bDidGetOrHead = true;
- // cache headers.
- if ( !m_xCachedProps.get())
- m_xCachedProps.reset(
- new CachableContentProperties( ContentProperties( aResource ) ) );
- else
- m_xCachedProps->addProperties(
- aResource.properties );
+ {
+ osl::MutexGuard aGuard( m_aMutex );
- m_xResAccess.reset(
- new DAVResourceAccess( *xResAccess.get() ) );
+ // cache headers.
+ if ( !m_xCachedProps.get())
+ m_xCachedProps.reset(
+ new CachableContentProperties( ContentProperties( aResource ) ) );
+ else
+ m_xCachedProps->addProperties(
+ aResource.properties );
+
+ m_xResAccess.reset(
+ new DAVResourceAccess( *xResAccess.get() ) );
+ }
+
+ xDataSink->setInputStream( xIn );
}
+ else
+ {
+ // return exception as if the resource was not found
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[ 0 ] <<= beans::PropertyValue(
+ OUString("Uri"), -1,
+ uno::makeAny(aTargetURL),
+ beans::PropertyState_DIRECT_VALUE);
- xDataSink->setInputStream( xIn );
+ ucbhelper::cancelCommandExecution(
+ uno::makeAny(
+ ucb::InteractiveAugmentedIOException(
+ OUString("Not found!"),
+ static_cast< cppu::OWeakObject * >( this ),
+ task::InteractionClassification_ERROR,
+ ucb::IOErrorCode_NOT_EXISTING,
+ aArgs ) ),
+ xEnv );
+ // Unreachable
+ }
}
catch ( DAVException const & e )
{