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 <comphelper/seqstream.hxx>
25 #include <rtl/strbuf.hxx>
28 using namespace com::sun::star
;
30 namespace http_dav_ucp
33 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath
,
34 const DAVRequestHeaders
& inRequestHeaders
,
36 const std::vector
< OUString
> & inPropNames
,
37 std::vector
< DAVResource
> & ioResources
)
38 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
40 , mpPropNames( &inPropNames
)
41 , mpResources( &ioResources
)
43 , mbOnlyPropertyNames( false )
44 , xInputStream( new SerfInputStream() )
49 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath
,
50 const DAVRequestHeaders
& inRequestHeaders
,
52 std::vector
< DAVResourceInfo
> & ioResInfo
)
53 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
57 , mpResInfo( &ioResInfo
)
58 , mbOnlyPropertyNames( true )
59 , xInputStream( new SerfInputStream() )
64 void SerfPropFindReqProcImpl::init( const Depth inDepth
)
75 mDepthStr
= "infinity";
80 SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl()
84 #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">"
85 #define PROPFIND_TRAILER "</propfind>"
87 serf_bucket_t
* SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
89 serf_bucket_alloc_t
* pSerfBucketAlloc
= serf_request_get_alloc( inSerfRequest
);
91 // body bucket - certain properties OR all properties OR only property names
92 serf_bucket_t
* body_bkt
= 0;
95 OStringBuffer aBuffer
;
96 aBuffer
.append( PROPFIND_HEADER
);
98 // create and fill body bucket with requested properties
99 const int nPropCount
= ( !mbOnlyPropertyNames
&& mpPropNames
)
100 ? mpPropNames
->size()
102 if ( nPropCount
> 0 )
104 aBuffer
.append( "<prop>" );
105 SerfPropName thePropName
;
106 for ( int theIndex
= 0; theIndex
< nPropCount
; theIndex
++ )
108 // split fullname into namespace and name!
109 DAVProperties::createSerfPropName( (*mpPropNames
)[ theIndex
],
112 /* <*propname* xmlns="*propns*" /> */
113 aBuffer
.append( "<" );
114 aBuffer
.append( thePropName
.name
);
115 aBuffer
.append( " xmlnx=\"" );
116 aBuffer
.append( thePropName
.nspace
);
117 aBuffer
.append( "\"/>" );
120 aBuffer
.append( "</prop>" );
124 if ( mbOnlyPropertyNames
)
126 aBuffer
.append( "<propname/>" );
130 aBuffer
.append( "<allprop/>" );
134 aBuffer
.append( PROPFIND_TRAILER
);
135 aBodyText
= aBuffer
.makeStringAndClear();
136 body_bkt
= serf_bucket_simple_copy_create( aBodyText
.getStr(),
137 aBodyText
.getLength(),
141 // create serf request
142 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
147 handleChunkedEncoding(req_bkt
, aBodyText
.getLength());
149 // set request header fields
150 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
151 if (hdrs_bkt
!= NULL
)
153 // general header fields provided by caller
154 setRequestHeaders( hdrs_bkt
);
156 // request specific header fields
157 serf_bucket_headers_set( hdrs_bkt
, "Depth", mDepthStr
);
158 if (hdrs_bkt
!=NULL
&& body_bkt
!= 0 && aBodyText
.getLength() > 0 )
160 serf_bucket_headers_set( hdrs_bkt
, "Content-Type", "application/xml" );
165 assert("Headers Bucket missing");
171 void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data
,
174 if ( xInputStream
.is() )
176 xInputStream
->AddToStream( data
, len
);
180 void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t
* /*inSerfResponseBucket*/ )
182 if ( mbOnlyPropertyNames
)
184 const std::vector
< DAVResourceInfo
> rResInfo( parseWebDAVPropNameResponse( xInputStream
.get() ) );
185 *mpResInfo
= rResInfo
;
189 const std::vector
< DAVResource
> rResources( parseWebDAVPropFindResponse( xInputStream
.get() ) );
190 *mpResources
= rResources
;
194 } // namespace http_dav_ucp
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */