Author: arielch Date: Sun Mar 24 13:22:15 2013 New Revision: 1460360 URL: http://svn.apache.org/r1460360 Log: i121947 - Default User-Agent
Added: openoffice/trunk/main/ucb/source/ucp/webdav/webdavuseragent.hxx Modified: openoffice/trunk/main/ucb/source/ucp/webdav/DAVResourceAccess.cxx openoffice/trunk/main/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx openoffice/trunk/main/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx openoffice/trunk/main/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx openoffice/trunk/main/ucb/source/ucp/webdav/makefile.mk openoffice/trunk/main/ucb/source/ucp/webdav/webdavprovider.cxx Modified: openoffice/trunk/main/ucb/source/ucp/webdav/DAVResourceAccess.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/DAVResourceAccess.cxx?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/DAVResourceAccess.cxx (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/DAVResourceAccess.cxx Sun Mar 24 13:22:15 2013 @@ -1117,32 +1117,33 @@ void DAVResourceAccess::getUserRequestHe const rtl::OUString & rMethod, DAVRequestHeaders & rRequestHeaders ) { - if ( xEnv.is() ) + if ( !xEnv.is() ) + return; + + uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv( + xEnv, uno::UNO_QUERY ); + + if ( !xDAVEnv.is() ) + return; + + uno::Sequence< beans::NamedValue > aRequestHeaders + = xDAVEnv->getUserRequestHeaders( rURI, rMethod ); + + for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n ) { - uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv( - xEnv, uno::UNO_QUERY ); + rtl::OUString aValue; + sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue; - if ( xDAVEnv.is() ) + if ( !isString ) { - uno::Sequence< beans::NamedValue > aRequestHeaders - = xDAVEnv->getUserRequestHeaders( rURI, rMethod ); - - for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n ) - { - rtl::OUString aValue; - sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue; - - if ( !isString ) - { - OSL_ENSURE( isString, - "DAVResourceAccess::getUserRequestHeaders :" - "Value is not a string! Ignoring..." ); - } - - rRequestHeaders.push_back( - DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) ); - } + OSL_ENSURE( isString, + "DAVResourceAccess::getUserRequestHeaders :" + "Value is not a string! Ignoring..." ); + continue; } + + rRequestHeaders.push_back( + DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) ); } } Modified: openoffice/trunk/main/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx Sun Mar 24 13:22:15 2013 @@ -165,7 +165,7 @@ serf_bucket_t * SerfPropPatchReqProcImpl { // general header fields provided by caller setRequestHeaders( hdrs_bkt ); - + // request specific header fields if ( body_bkt != 0 && aBodyText.getLength() > 0 ) { Modified: openoffice/trunk/main/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/SerfPutReqProcImpl.cxx Sun Mar 24 13:22:15 2013 @@ -64,6 +64,11 @@ serf_bucket_t * SerfPutReqProcImpl::crea serf_request_get_alloc( inSerfRequest ) ); handleChunkedEncoding(req_bkt, mnDataLen); + // 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; } Modified: openoffice/trunk/main/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/SerfRequestProcessorImpl.cxx Sun Mar 24 13:22:15 2013 @@ -20,6 +20,7 @@ *************************************************************/ #include "SerfRequestProcessorImpl.hxx" +#include "webdavuseragent.hxx" namespace { @@ -82,6 +83,7 @@ void SerfRequestProcessorImpl::handleChu void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t* inoutSerfHeaderBucket ) { + bool bHasUserAgent( false ); DAVRequestHeaders::const_iterator aHeaderIter( mrRequestHeaders.begin() ); const DAVRequestHeaders::const_iterator aEnd( mrRequestHeaders.end() ); @@ -92,6 +94,11 @@ void SerfRequestProcessorImpl::setReques const rtl::OString aValue = rtl::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() ); @@ -99,6 +106,14 @@ void SerfRequestProcessorImpl::setReques ++aHeaderIter; } + if ( !bHasUserAgent ) + { + const rtl::OUString &rUserAgent = WebDAVUserAgent::get(); + serf_bucket_headers_set( inoutSerfHeaderBucket, + "User-Agent", + rtl::OUStringToOString( rUserAgent, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + serf_bucket_headers_set( inoutSerfHeaderBucket, "Accept-Encoding", "gzip"); } Modified: openoffice/trunk/main/ucb/source/ucp/webdav/makefile.mk URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/makefile.mk?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/makefile.mk (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/makefile.mk Sun Mar 24 13:22:15 2013 @@ -61,6 +61,9 @@ SHL1STDLIBS+=$(APR_LIBS) .ELSE CFLAGS+= -I$(SOLARINCDIR)$/$(APRINCDIR) SHL1STDLIBS+=$(INTERNAL_APR_LIBS) +.INCLUDE : apr_version.mk +CFLAGS+=\ + -DAPR_VERSION=\"$(APR_MAJOR).$(APR_MINOR).$(APR_MICRO)\" .ENDIF .IF "$(SYSTEM_APR_UTIL)" == "YES" @@ -69,6 +72,9 @@ SHL1STDLIBS+=$(APR_UTIL_LIBS) .ELSE CFLAGS+= -I$(SOLARINCDIR)$/$(APRUTILINCDIR) SHL1STDLIBS+=$(INTERNAL_APR_UTIL_LIBS) +.INCLUDE : aprutil_version.mk +CFLAGS+=\ + -DAPR_UTIL_VERSION=\"$(APR_UTIL_MAJOR).$(APR_UTIL_MINOR).$(APR_UTIL_MICRO)\" .ENDIF .IF "$(SYSTEM_SERF)" == "YES" @@ -77,6 +83,9 @@ SHL1STDLIBS+=$(SERF_LIBS) .ELSE CFLAGS+= -I$(SOLARINCDIR)$/$(SERFINCDIR) SHL1STDLIBS+=$(INTERNAL_SERF_LIBS) +.INCLUDE : serf_version.mk +CFLAGS+=\ + -DSERF_VERSION=\"$(SERF_MAJOR).$(SERF_MINOR).$(SERF_MICRO)\" .ENDIF .IF "$(SYSTEM_LIBXML)" == "YES" Modified: openoffice/trunk/main/ucb/source/ucp/webdav/webdavprovider.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/webdavprovider.cxx?rev=1460360&r1=1460359&r2=1460360&view=diff ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/webdavprovider.cxx (original) +++ openoffice/trunk/main/ucb/source/ucp/webdav/webdavprovider.cxx Sun Mar 24 13:22:15 2013 @@ -32,12 +32,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; + +rtl::OUString &WebDAVUserAgent::operator()() const +{ + rtl::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 rtl::OUString aUserAgent( aBuffer.makeStringAndClear() ); + return aUserAgent; +} + //========================================================================= //========================================================================= // @@ -52,6 +79,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( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.configuration.ConfigurationProvider")), xContext), + uno::UNO_QUERY_THROW ); + + beans::NamedValue aNodePath; + aNodePath.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aNodePath.Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Product")); + + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[0] <<= aNodePath; + + uno::Reference< container::XNameAccess > xConfigAccess( + xConfigProvider->createInstanceWithArguments( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.configuration.ConfigurationAccess")), aArgs), + uno::UNO_QUERY_THROW ); + + rtl::OUString aVal; + xConfigAccess->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooName"))) >>= aVal; + + rtl::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(rtl::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", + rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + (void) e; + } } //========================================================================= Added: openoffice/trunk/main/ucb/source/ucp/webdav/webdavuseragent.hxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ucb/source/ucp/webdav/webdavuseragent.hxx?rev=1460360&view=auto ============================================================================== --- openoffice/trunk/main/ucb/source/ucp/webdav/webdavuseragent.hxx (added) +++ openoffice/trunk/main/ucb/source/ucp/webdav/webdavuseragent.hxx Sun Mar 24 13:22:15 2013 @@ -0,0 +1,38 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#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< rtl::OUString, WebDAVUserAgent > +{ + rtl::OUString &operator()() const; +}; + +} + +#endif