1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SerfPropFindReqProcImpl.hxx"
21 #include "DAVProperties.hxx"
23 #include "webdavresponseparser.hxx"
24 #include <rtl/strbuf.hxx>
27 using namespace com::sun::star
;
29 namespace http_dav_ucp
32 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath
,
33 const DAVRequestHeaders
& inRequestHeaders
,
35 const std::vector
< OUString
> & inPropNames
,
36 std::vector
< DAVResource
> & ioResources
)
37 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
38 , mDepthStr( nullptr )
39 , mpPropNames( &inPropNames
)
40 , mpResources( &ioResources
)
41 , mpResInfo( nullptr )
42 , mbOnlyPropertyNames( false )
43 , xInputStream( new SerfInputStream() )
48 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath
,
49 const DAVRequestHeaders
& inRequestHeaders
,
51 std::vector
< DAVResourceInfo
> & ioResInfo
)
52 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
53 , mDepthStr( nullptr )
54 , mpPropNames( nullptr )
55 , mpResources( nullptr )
56 , mpResInfo( &ioResInfo
)
57 , mbOnlyPropertyNames( true )
58 , xInputStream( new SerfInputStream() )
63 void SerfPropFindReqProcImpl::init( const Depth inDepth
)
74 mDepthStr
= "infinity";
79 SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl()
83 #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">"
84 #define PROPFIND_TRAILER "</propfind>"
86 serf_bucket_t
* SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
88 serf_bucket_alloc_t
* pSerfBucketAlloc
= serf_request_get_alloc( inSerfRequest
);
90 // body bucket - certain properties OR all properties OR only property names
91 serf_bucket_t
* body_bkt
= nullptr;
94 OStringBuffer aBuffer
;
95 aBuffer
.append( PROPFIND_HEADER
);
97 // create and fill body bucket with requested properties
98 const int nPropCount
= ( !mbOnlyPropertyNames
&& mpPropNames
)
101 if ( nPropCount
> 0 )
103 aBuffer
.append( "<prop>" );
104 SerfPropName thePropName
;
105 for ( int theIndex
= 0; theIndex
< nPropCount
; theIndex
++ )
107 // split fullname into namespace and name!
108 DAVProperties::createSerfPropName( (*mpPropNames
)[ theIndex
],
111 /* <*propname* xmlns="*propns*" /> */
112 aBuffer
.append( "<" );
113 aBuffer
.append( thePropName
.name
);
114 aBuffer
.append( " xmlns=\"" );
115 aBuffer
.append( thePropName
.nspace
);
116 aBuffer
.append( "\"/>" );
119 aBuffer
.append( "</prop>" );
123 if ( mbOnlyPropertyNames
)
125 aBuffer
.append( "<propname/>" );
129 aBuffer
.append( "<allprop/>" );
133 aBuffer
.append( PROPFIND_TRAILER
);
134 aBodyText
= aBuffer
.makeStringAndClear();
135 body_bkt
= serf_bucket_simple_copy_create( aBodyText
.getStr(),
136 aBodyText
.getLength(),
140 // create serf request
141 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
146 handleChunkedEncoding(req_bkt
, aBodyText
.getLength());
148 // set request header fields
149 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
150 if (hdrs_bkt
!= nullptr)
152 // general header fields provided by caller
153 setRequestHeaders( hdrs_bkt
);
155 // request specific header fields
156 serf_bucket_headers_set( hdrs_bkt
, "Depth", mDepthStr
);
157 if (hdrs_bkt
!=nullptr && body_bkt
!= nullptr && aBodyText
.getLength() > 0 )
159 serf_bucket_headers_set( hdrs_bkt
, "Content-Type", "application/xml" );
164 assert(!"Headers Bucket missing");
170 void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data
,
173 if ( xInputStream
.is() )
175 xInputStream
->AddToStream( data
, len
);
179 void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t
* /*inSerfResponseBucket*/ )
181 if ( mbOnlyPropertyNames
)
183 const std::vector
< DAVResourceInfo
> rResInfo( parseWebDAVPropNameResponse( xInputStream
.get() ) );
184 *mpResInfo
= rResInfo
;
188 const std::vector
< DAVResource
> rResources( parseWebDAVPropFindResponse( xInputStream
.get() ) );
189 *mpResources
= rResources
;
193 } // namespace http_dav_ucp
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */