xref: /AOO41X/main/ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx (revision 726e226911a7d8cbfb0c58486555c585c7d014fa)
13edf6992SAndrea Pescetti /**************************************************************
23edf6992SAndrea Pescetti  *
33edf6992SAndrea Pescetti  * Licensed to the Apache Software Foundation (ASF) under one
43edf6992SAndrea Pescetti  * or more contributor license agreements.  See the NOTICE file
53edf6992SAndrea Pescetti  * distributed with this work for additional information
63edf6992SAndrea Pescetti  * regarding copyright ownership.  The ASF licenses this file
73edf6992SAndrea Pescetti  * to you under the Apache License, Version 2.0 (the
83edf6992SAndrea Pescetti  * "License"); you may not use this file except in compliance
93edf6992SAndrea Pescetti  * with the License.  You may obtain a copy of the License at
103edf6992SAndrea Pescetti  *
113edf6992SAndrea Pescetti  *   http://www.apache.org/licenses/LICENSE-2.0
123edf6992SAndrea Pescetti  *
133edf6992SAndrea Pescetti  * Unless required by applicable law or agreed to in writing,
143edf6992SAndrea Pescetti  * software distributed under the License is distributed on an
153edf6992SAndrea Pescetti  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163edf6992SAndrea Pescetti  * KIND, either express or implied.  See the License for the
173edf6992SAndrea Pescetti  * specific language governing permissions and limitations
183edf6992SAndrea Pescetti  * under the License.
193edf6992SAndrea Pescetti  *
203edf6992SAndrea Pescetti  *************************************************************/
213edf6992SAndrea Pescetti 
223edf6992SAndrea Pescetti // MARKER(update_precomp.py): autogen include statement, do not remove
233edf6992SAndrea Pescetti #include "precompiled_ucb.hxx"
243edf6992SAndrea Pescetti 
253edf6992SAndrea Pescetti #include "SerfTypes.hxx"
263edf6992SAndrea Pescetti #include "SerfLockReqProcImpl.hxx"
273edf6992SAndrea Pescetti #include "DAVProperties.hxx"
283edf6992SAndrea Pescetti 
293edf6992SAndrea Pescetti #include "webdavresponseparser.hxx"
30*726e2269SPedro Giffuni #include <serf.h>
313edf6992SAndrea Pescetti #include <rtl/ustrbuf.hxx>
32*726e2269SPedro Giffuni #include <apr_strings.h>
333edf6992SAndrea Pescetti 
343edf6992SAndrea Pescetti namespace http_dav_ucp
353edf6992SAndrea Pescetti {
363edf6992SAndrea Pescetti 
SerfLockReqProcImpl(const char * inSourcePath,const DAVRequestHeaders & inRequestHeaders,const ucb::Lock & inLock,const char * inTimeout,DAVPropertyValue & outLock)373edf6992SAndrea Pescetti SerfLockReqProcImpl::SerfLockReqProcImpl( const char* inSourcePath,
383edf6992SAndrea Pescetti                                           const DAVRequestHeaders& inRequestHeaders, // on debug the header look empty
393edf6992SAndrea Pescetti                                           const ucb::Lock& inLock,
403edf6992SAndrea Pescetti                                           const char* inTimeout,
413edf6992SAndrea Pescetti                                           DAVPropertyValue & outLock)
423edf6992SAndrea Pescetti     : SerfRequestProcessorImpl( inSourcePath, inRequestHeaders )
433edf6992SAndrea Pescetti     , mLock( inLock )
443edf6992SAndrea Pescetti     , mTimeout(inTimeout)
453edf6992SAndrea Pescetti     , mLockObtained( &outLock )
463edf6992SAndrea Pescetti     , xInputStream( new SerfInputStream() )
473edf6992SAndrea Pescetti {
483edf6992SAndrea Pescetti     switch ( inLock.Depth )
493edf6992SAndrea Pescetti     {
503edf6992SAndrea Pescetti         //i126305 TODO investigate on this case...
513edf6992SAndrea Pescetti     case ucb::LockDepth_MAKE_FIXED_SIZE:
523edf6992SAndrea Pescetti 
533edf6992SAndrea Pescetti     case ucb::LockDepth_ZERO:
543edf6992SAndrea Pescetti         mDepthStr = "0";
553edf6992SAndrea Pescetti         break;
563edf6992SAndrea Pescetti     case ucb::LockDepth_ONE:
573edf6992SAndrea Pescetti             mDepthStr = "1";
583edf6992SAndrea Pescetti             break;
593edf6992SAndrea Pescetti     case ucb::LockDepth_INFINITY:
603edf6992SAndrea Pescetti             mDepthStr = "infinity";
613edf6992SAndrea Pescetti             break;
623edf6992SAndrea Pescetti     }
633edf6992SAndrea Pescetti 
643edf6992SAndrea Pescetti     switch ( inLock.Scope )
653edf6992SAndrea Pescetti     {
663edf6992SAndrea Pescetti         //i126305 TODO investigate on this case...
673edf6992SAndrea Pescetti     case ucb::LockScope_MAKE_FIXED_SIZE:
683edf6992SAndrea Pescetti 
693edf6992SAndrea Pescetti     case ucb::LockScope_EXCLUSIVE:
703edf6992SAndrea Pescetti         mLockScope = "<lockscope><exclusive/></lockscope>";
713edf6992SAndrea Pescetti         break;
723edf6992SAndrea Pescetti     case ucb::LockScope_SHARED:
733edf6992SAndrea Pescetti         mLockScope = "<lockscope><shared/></lockscope>";
743edf6992SAndrea Pescetti         break;
753edf6992SAndrea Pescetti     }
763edf6992SAndrea Pescetti }
773edf6992SAndrea Pescetti 
~SerfLockReqProcImpl()783edf6992SAndrea Pescetti SerfLockReqProcImpl::~SerfLockReqProcImpl()
793edf6992SAndrea Pescetti {
803edf6992SAndrea Pescetti }
813edf6992SAndrea Pescetti 
823edf6992SAndrea Pescetti #define LOCK_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><lockinfo xmlns=\"DAV:\">"
833edf6992SAndrea Pescetti #define LOCK_TYPE "<locktype><write/></locktype>"
843edf6992SAndrea Pescetti #define LOCK_TRAILER "</lockinfo>"
853edf6992SAndrea Pescetti 
createSerfRequestBucket(serf_request_t * inSerfRequest)863edf6992SAndrea Pescetti serf_bucket_t * SerfLockReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
873edf6992SAndrea Pescetti {
883edf6992SAndrea Pescetti   //prepare body of request:
893edf6992SAndrea Pescetti     serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest );
903edf6992SAndrea Pescetti     serf_bucket_t* body_bkt = 0;
913edf6992SAndrea Pescetti     rtl::OString aBodyText;
923edf6992SAndrea Pescetti     {
933edf6992SAndrea Pescetti        rtl::OUStringBuffer aBuffer;
943edf6992SAndrea Pescetti         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( LOCK_HEADER ));
953edf6992SAndrea Pescetti         aBuffer.appendAscii( mLockScope );
963edf6992SAndrea Pescetti         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( LOCK_TYPE ));
973edf6992SAndrea Pescetti         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<owner>" ));
983edf6992SAndrea Pescetti         rtl::OUString aStr;
993edf6992SAndrea Pescetti         mLock.Owner >>= aStr;
1003edf6992SAndrea Pescetti         aBuffer.appendAscii( rtl::OUStringToOString( aStr, RTL_TEXTENCODING_UTF8 ).getStr() );
1013edf6992SAndrea Pescetti         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</owner>" ));
1023edf6992SAndrea Pescetti         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( LOCK_TRAILER ));
1033edf6992SAndrea Pescetti         aBodyText = rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
1043edf6992SAndrea Pescetti         body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(),
1053edf6992SAndrea Pescetti                                                    aBodyText.getLength(),
1063edf6992SAndrea Pescetti                                                    pSerfBucketAlloc );
1073edf6992SAndrea Pescetti     }
1083edf6992SAndrea Pescetti 
1093edf6992SAndrea Pescetti     // create serf request
1103edf6992SAndrea Pescetti     serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
1113edf6992SAndrea Pescetti                                                                  "LOCK",
1123edf6992SAndrea Pescetti                                                                  getPathStr(),
1133edf6992SAndrea Pescetti                                                                  body_bkt,
1143edf6992SAndrea Pescetti                                                                  pSerfBucketAlloc );
1153edf6992SAndrea Pescetti     handleChunkedEncoding(req_bkt, aBodyText.getLength());
1163edf6992SAndrea Pescetti 
1173edf6992SAndrea Pescetti     // set request header fields
1183edf6992SAndrea Pescetti     serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
1193edf6992SAndrea Pescetti     if (hdrs_bkt != NULL)
1203edf6992SAndrea Pescetti     {
1213edf6992SAndrea Pescetti         // general header fields provided by caller
1223edf6992SAndrea Pescetti         setRequestHeaders( hdrs_bkt );
1233edf6992SAndrea Pescetti 
1243edf6992SAndrea Pescetti         // request specific header fields
1253edf6992SAndrea Pescetti         serf_bucket_headers_set( hdrs_bkt, "Timeout", mTimeout );
1263edf6992SAndrea Pescetti         serf_bucket_headers_set( hdrs_bkt, "Depth", mDepthStr );
1273edf6992SAndrea Pescetti         if (hdrs_bkt!=NULL && body_bkt != 0 && aBodyText.getLength() > 0 )
1283edf6992SAndrea Pescetti         {
1293edf6992SAndrea Pescetti             serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" );
1303edf6992SAndrea Pescetti         }
1313edf6992SAndrea Pescetti     }
1323edf6992SAndrea Pescetti     else
1333edf6992SAndrea Pescetti     {
1343edf6992SAndrea Pescetti         OSL_ASSERT("Headers Bucket missing");
1353edf6992SAndrea Pescetti     }
1363edf6992SAndrea Pescetti 
1373edf6992SAndrea Pescetti     return req_bkt;
1383edf6992SAndrea Pescetti }
1393edf6992SAndrea Pescetti 
processChunkOfResponseData(const char * data,apr_size_t len)1403edf6992SAndrea Pescetti void SerfLockReqProcImpl::processChunkOfResponseData( const char* data,
1413edf6992SAndrea Pescetti                                                       apr_size_t len )
1423edf6992SAndrea Pescetti {
1433edf6992SAndrea Pescetti     if ( xInputStream.is() )
1443edf6992SAndrea Pescetti     {
1453edf6992SAndrea Pescetti         xInputStream->AddToStream( data, len );
1463edf6992SAndrea Pescetti     }
1473edf6992SAndrea Pescetti }
1483edf6992SAndrea Pescetti 
handleEndOfResponseData(serf_bucket_t *)1493edf6992SAndrea Pescetti void SerfLockReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
1503edf6992SAndrea Pescetti {
1513edf6992SAndrea Pescetti     const DAVPropertyValue rLocksValue( parseWebDAVLockResponse( xInputStream.get() ) );
1523edf6992SAndrea Pescetti     *mLockObtained = rLocksValue;
1533edf6992SAndrea Pescetti }
1543edf6992SAndrea Pescetti 
1553edf6992SAndrea Pescetti } // namespace http_dav_ucp
156