webdavcontent.cxx (f7fef0fa) webdavcontent.cxx (c5b3447d)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 73 unchanged lines hidden (view full) ---

82#include "webdavresultset.hxx"
83#include "ContentProperties.hxx"
84#include "SerfUri.hxx"
85#include "UCBDeadPropertyValue.hxx"
86
87using namespace com::sun::star;
88using namespace http_dav_ucp;
89
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 73 unchanged lines hidden (view full) ---

82#include "webdavresultset.hxx"
83#include "ContentProperties.hxx"
84#include "SerfUri.hxx"
85#include "UCBDeadPropertyValue.hxx"
86
87using namespace com::sun::star;
88using namespace http_dav_ucp;
89
90namespace
91{
92static void lcl_sendPartialGETRequest( bool &bError,
93 DAVException &aLastException,
94 const std::vector< rtl::OUString > aProps,
95 std::vector< rtl::OUString > &aHeaderNames,
96 const std::auto_ptr< DAVResourceAccess > &xResAccess,
97 std::auto_ptr< ContentProperties > &xProps,
98 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
99{
100 bool bIsRequestSize = false;
101 DAVResource aResource;
102 DAVRequestHeaders aPartialGet;
103 aPartialGet.push_back(
104 DAVRequestHeader(
105 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Range" ) ),
106 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "bytes=0-0" ))));
107
108 for ( std::vector< rtl::OUString >::const_iterator it = aHeaderNames.begin();
109 it != aHeaderNames.end(); it++ )
110 {
111 if ( it->equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
112 {
113 bIsRequestSize = true;
114 break;
115 }
116 }
117
118 if ( bIsRequestSize )
119 {
120 // we need to know if the server accepts range requests for a resource
121 // and the range unit it uses
122 aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Accept-Ranges" ) ) );
123 aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Content-Range" ) ) );
124 }
125 try
126 {
127 uno::Reference< io::XInputStream > xIn = xResAccess->GET( aPartialGet,
128 aHeaderNames,
129 aResource,
130 xEnv );
131 bError = false;
132
133 if ( bIsRequestSize )
134 {
135 // the ContentProperties maps "Content-Length" to the UCB "Size" property
136 // This would have an unrealistic value of 1 byte because we did only a partial GET
137 // Solution: if "Content-Range" is present, map it with UCB "Size" property
138 rtl::OUString aAcceptRanges, aContentRange, aContentLength;
139 std::vector< DAVPropertyValue > &aResponseProps = aResource.properties;
140 for ( std::vector< DAVPropertyValue >::const_iterator it = aResponseProps.begin();
141 it != aResponseProps.end(); it++ )
142 {
143 if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Accept-Ranges" ) ) )
144 it->Value >>= aAcceptRanges;
145 else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Range" ) ) )
146 it->Value >>= aContentRange;
147 else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
148 it->Value >>= aContentLength;
149 }
150
151 sal_Int64 nSize = 1;
152 if ( aContentLength.getLength() )
153 {
154 nSize = aContentLength.toInt64();
155 }
156
157 // according to http://tools.ietf.org/html/rfc2616#section-3.12
158 // the only range unit defined is "bytes" and implementations
159 // MAY ignore ranges specified using other units.
160 if ( nSize == 1 &&
161 aContentRange.getLength() &&
162 aAcceptRanges.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "bytes" ) ) )
163 {
164 // Parse the Content-Range to get the size
165 // vid. http://tools.ietf.org/html/rfc2616#section-14.16
166 // Content-Range: <range unit> <bytes range>/<size>
167 sal_Int32 nSlash = aContentRange.lastIndexOf( sal_Unicode('/'));
168 if ( nSlash != -1 )
169 {
170 rtl::OUString aSize = aContentRange.copy( nSlash + 1 );
171 // "*" means that the instance-length is unknown at the time when the response was generated
172 if ( !aSize.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "*" )))
173 {
174 for ( std::vector< DAVPropertyValue >::iterator it = aResponseProps.begin();
175 it != aResponseProps.end(); it++ )
176 {
177 if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
178 {
179 it->Value <<= aSize;
180 break;
181 }
182 }
183 }
184 }
185 }
186 }
187
188 if ( xProps.get() )
189 xProps->addProperties(
190 aProps,
191 ContentProperties( aResource ) );
192 else
193 xProps.reset ( new ContentProperties( aResource ) );
194 }
195 catch ( DAVException const & ex )
196 {
197 aLastException = ex;
198 }
199}
200}
201
90//=========================================================================
91//=========================================================================
92//
93// Content Implementation.
94//
95//=========================================================================
96//=========================================================================
97

--- 1261 unchanged lines hidden (view full) ---

1359 if ( m_eResourceType == NON_DAV )
1360 xProps->addProperties( aMissingProps,
1361 ContentProperties(
1362 aUnescapedTitle,
1363 false ) );
1364 }
1365 catch ( DAVException const & e )
1366 {
202//=========================================================================
203//=========================================================================
204//
205// Content Implementation.
206//
207//=========================================================================
208//=========================================================================
209

--- 1261 unchanged lines hidden (view full) ---

1471 if ( m_eResourceType == NON_DAV )
1472 xProps->addProperties( aMissingProps,
1473 ContentProperties(
1474 aUnescapedTitle,
1475 false ) );
1476 }
1477 catch ( DAVException const & e )
1478 {
1367 bNetworkAccessAllowed
1368 = shouldAccessNetworkAfterException( e );
1479 // non "general-purpose servers" may not support HEAD requests
1480 // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1
1481 // In this case, perform a partial GET only to get the header info
1482 // vid. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
1483 // WARNING if the server does not support partial GETs,
1484 // the GET will transfer the whole content
1485 bool bError = true;
1486 DAVException aLastException = e;
1369
1487
1370 if ( !bNetworkAccessAllowed )
1488 // According to the spec. the origin server SHOULD return
1489 // * 405 (Method Not Allowed):
1490 // the method is known but not allowed for the requested resource
1491 // * 501 (Not Implemented):
1492 // the method is unrecognized or not implemented
1493 // TODO SC_NOT_FOUND is only for google-code server
1494 if ( aLastException.getStatus() == SC_NOT_IMPLEMENTED ||
1495 aLastException.getStatus() == SC_METHOD_NOT_ALLOWED ||
1496 aLastException.getStatus() == SC_NOT_FOUND )
1371 {
1497 {
1372 cancelCommandExecution( e, xEnv );
1373 // unreachable
1498 lcl_sendPartialGETRequest( bError,
1499 aLastException,
1500 aMissingProps,
1501 aHeaderNames,
1502 xResAccess,
1503 xProps,
1504 xEnv );
1505 m_bDidGetOrHead = !bError;
1374 }
1506 }
1507
1508 if ( bError )
1509 {
1510 if ( !(bNetworkAccessAllowed
1511 = shouldAccessNetworkAfterException( aLastException )) )
1512 {
1513 cancelCommandExecution( aLastException, xEnv );
1514 // unreachable
1515 }
1516 }
1375 }
1376 }
1377 }
1378 }
1379
1380 // might trigger HTTP redirect.
1381 // Therefore, title must be updated here.
1382 SerfUri aUri( xResAccess->getURL() );

--- 1863 unchanged lines hidden ---
1517 }
1518 }
1519 }
1520 }
1521
1522 // might trigger HTTP redirect.
1523 // Therefore, title must be updated here.
1524 SerfUri aUri( xResAccess->getURL() );

--- 1863 unchanged lines hidden ---