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

Resolves: #i121947# Default User-Agent

(cherry picked from commit 339d75d9)

Conflicts:
	ucb/source/ucp/webdav/DAVResourceAccess.cxx
	ucb/source/ucp/webdav/makefile.mk

Change-Id: Ie74275cfa9953fdc4fa0801224909efbcecab3a9
üst 5aaa9a0a
......@@ -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 ) );
}
}
......
......@@ -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;
}
......
......@@ -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");
}
......
......@@ -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;
}
}
//=========================================================================
......
/*
* 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
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