[Libreoffice-commits] core.git: ucb/source
Ariel Constenla-Haile
arielch at apache.org
Sun Jun 23 14:48:41 PDT 2013
ucb/source/ucp/webdav/DAVResourceAccess.cxx | 43 ++++++-----
ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx | 5 +
ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx | 15 ++++
ucb/source/ucp/webdav/webdavprovider.cxx | 76 +++++++++++++++++++++
ucb/source/ucp/webdav/webdavuseragent.hxx | 34 +++++++++
5 files changed, 152 insertions(+), 21 deletions(-)
New commits:
commit ae57695241d41022f4559601addbedea36b88f37
Author: Ariel Constenla-Haile <arielch at apache.org>
Date: Sun Mar 24 12:22:15 2013 +0000
Resolves: #i121947# Default User-Agent
(cherry picked from commit 339d75d9c99462d63234845031f24a42e7ffdd27)
Conflicts:
ucb/source/ucp/webdav/DAVResourceAccess.cxx
ucb/source/ucp/webdav/makefile.mk
Change-Id: Ie74275cfa9953fdc4fa0801224909efbcecab3a9
diff --git a/ucb/source/ucp/webdav/DAVResourceAccess.cxx b/ucb/source/ucp/webdav/DAVResourceAccess.cxx
index 531d6d1..ba6652b 100644
--- a/ucb/source/ucp/webdav/DAVResourceAccess.cxx
+++ b/ucb/source/ucp/webdav/DAVResourceAccess.cxx
@@ -1110,32 +1110,33 @@ void DAVResourceAccess::getUserRequestHeaders(
const OUString & rMethod,
DAVRequestHeaders & rRequestHeaders )
{
- if ( xEnv.is() )
- {
- uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv(
- xEnv, uno::UNO_QUERY );
+ if ( !xEnv.is() )
+ return;
- if ( xDAVEnv.is() )
- {
- uno::Sequence< beans::NamedValue > aRequestHeaders
- = xDAVEnv->getUserRequestHeaders( rURI, rMethod );
+ uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv(
+ xEnv, uno::UNO_QUERY );
- for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n )
- {
- OUString aValue;
- sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue;
+ if ( !xDAVEnv.is() )
+ return;
- if ( !isString )
- {
- OSL_ENSURE( isString,
- "DAVResourceAccess::getUserRequestHeaders :"
- "Value is not a string! Ignoring..." );
- }
+ uno::Sequence< beans::NamedValue > aRequestHeaders
+ = xDAVEnv->getUserRequestHeaders( rURI, rMethod );
- rRequestHeaders.push_back(
- DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) );
- }
+ for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n )
+ {
+ OUString aValue;
+ sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue;
+
+ if ( !isString )
+ {
+ OSL_ENSURE( isString,
+ "DAVResourceAccess::getUserRequestHeaders :"
+ "Value is not a string! Ignoring..." );
+ continue;
}
+
+ rRequestHeaders.push_back(
+ DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) );
}
}
diff --git a/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx b/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx
index 6440318..78b454a 100644
--- a/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx
+++ b/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx
@@ -79,6 +79,11 @@ serf_bucket_t * SerfPutReqProcImpl::createSerfRequestBucket( serf_request_t * in
}
+ // set request header fields
+ serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
+ // general header fields provided by caller
+ setRequestHeaders( hdrs_bkt );
+
return req_bkt;
}
diff --git a/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx b/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx
index 60e3217..9be84da 100644
--- a/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx
+++ b/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx
@@ -18,6 +18,7 @@
*/
#include "SerfRequestProcessorImpl.hxx"
+#include "webdavuseragent.hxx"
namespace http_dav_ucp
{
@@ -51,6 +52,7 @@ bool SerfRequestProcessorImpl::useChunkedEncoding() const
void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t* inoutSerfHeaderBucket )
{
+ bool bHasUserAgent( false );
DAVRequestHeaders::const_iterator aHeaderIter( mrRequestHeaders.begin() );
const DAVRequestHeaders::const_iterator aEnd( mrRequestHeaders.end() );
@@ -61,6 +63,11 @@ void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t* inoutSerfHeader
const OString aValue = OUStringToOString( (*aHeaderIter).second,
RTL_TEXTENCODING_UTF8 );
+ OSL_TRACE( "Request Header - \"%s: %s\"", aHeader.getStr(), aValue.getStr() );
+ if ( !bHasUserAgent )
+ bHasUserAgent = aHeaderIter->first.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM( "User-Agent" ) );
+
serf_bucket_headers_set( inoutSerfHeaderBucket,
aHeader.getStr(),
aValue.getStr() );
@@ -68,6 +75,14 @@ void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t* inoutSerfHeader
++aHeaderIter;
}
+ if ( !bHasUserAgent )
+ {
+ const OUString &rUserAgent = WebDAVUserAgent::get();
+ serf_bucket_headers_set( inoutSerfHeaderBucket,
+ "User-Agent",
+ OUStringToOString( rUserAgent, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+
serf_bucket_headers_set( inoutSerfHeaderBucket, "Accept-Encoding", "gzip");
}
diff --git a/ucb/source/ucp/webdav/webdavprovider.cxx b/ucb/source/ucp/webdav/webdavprovider.cxx
index ad93bf9..b782b04 100644
--- a/ucb/source/ucp/webdav/webdavprovider.cxx
+++ b/ucb/source/ucp/webdav/webdavprovider.cxx
@@ -20,12 +20,39 @@
#include <ucbhelper/contentidentifier.hxx>
#include "webdavprovider.hxx"
#include "webdavcontent.hxx"
+#include "webdavuseragent.hxx"
#include <osl/mutex.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
using namespace com::sun::star;
using namespace http_dav_ucp;
+
+OUString &WebDAVUserAgent::operator()() const
+{
+ OUStringBuffer aBuffer;
+ aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "$ooName/$ooSetupVersion" ));
+#if OSL_DEBUG_LEVEL > 0
+#ifdef APR_VERSION
+ aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " apr/" APR_VERSION ));
+#endif
+
+#ifdef APR_UTIL_VERSION
+ aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " apr-util/" APR_UTIL_VERSION ));
+#endif
+
+#ifdef SERF_VERSION
+ aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " serf/" SERF_VERSION ));
+#endif
+#endif
+ static OUString aUserAgent( aBuffer.makeStringAndClear() );
+ return aUserAgent;
+}
+
//=========================================================================
//=========================================================================
//
@@ -40,6 +67,55 @@ ContentProvider::ContentProvider(
m_xDAVSessionFactory( new DAVSessionFactory() ),
m_pProps( 0 )
{
+ static bool bInit = false;
+ if ( bInit )
+ return;
+ bInit = true;
+ try
+ {
+ uno::Reference< uno::XComponentContext > xContext(
+ ::comphelper::getProcessComponentContext() );
+ uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
+ xContext->getServiceManager()->createInstanceWithContext(
+ OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.ConfigurationProvider")), xContext),
+ uno::UNO_QUERY_THROW );
+
+ beans::NamedValue aNodePath;
+ aNodePath.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
+ aNodePath.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Product"));
+
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= aNodePath;
+
+ uno::Reference< container::XNameAccess > xConfigAccess(
+ xConfigProvider->createInstanceWithArguments(
+ OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.ConfigurationAccess")), aArgs),
+ uno::UNO_QUERY_THROW );
+
+ OUString aVal;
+ xConfigAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("ooName"))) >>= aVal;
+
+ OUString &aUserAgent = WebDAVUserAgent::get();
+ sal_Int32 nIndex = aUserAgent.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "$ooName" ) );
+ if ( !aVal.getLength() || nIndex == -1 )
+ return;
+ aUserAgent = aUserAgent.replaceAt( nIndex, RTL_CONSTASCII_LENGTH( "$ooName" ), aVal );
+
+ xConfigAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupVersion"))) >>= aVal;
+ nIndex = aUserAgent.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "$ooSetupVersion" ) );
+ if ( !aVal.getLength() || nIndex == -1 )
+ return;
+ aUserAgent = aUserAgent.replaceAt( nIndex, RTL_CONSTASCII_LENGTH( "$ooSetupVersion" ), aVal );
+
+ }
+ catch ( const uno::Exception &e )
+ {
+ OSL_TRACE( "ContentProvider -caught exception! %s",
+ OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+ (void) e;
+ }
}
//=========================================================================
diff --git a/ucb/source/ucp/webdav/webdavuseragent.hxx b/ucb/source/ucp/webdav/webdavuseragent.hxx
new file mode 100644
index 0000000..7c954de
--- /dev/null
+++ b/ucb/source/ucp/webdav/webdavuseragent.hxx
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_WEBDAV_UCP_USERAGENT_HXX
+#define INCLUDED_WEBDAV_UCP_USERAGENT_HXX
+
+#include <rtl/ustring.hxx>
+#include <rtl/instance.hxx>
+
+namespace http_dav_ucp {
+
+struct WebDAVUserAgent
+ : public ::rtl::StaticWithInit< OUString, WebDAVUserAgent >
+{
+ OUString &operator()() const;
+};
+
+}
+
+#endif
More information about the Libreoffice-commits
mailing list