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 <SerfTypes.hxx>
22 #include <DAVProperties.hxx>
24 #include <webdavresponseparser.hxx>
25 #include <comphelper/seqstream.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
)
39 , mpPropNames( &inPropNames
)
40 , mpResources( &ioResources
)
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
)
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
= 0;
94 // create and fill body bucket with requested properties
95 const int nPropCount
= ( !mbOnlyPropertyNames
&& mpPropNames
)
100 SerfPropName thePropName
;
101 for ( int theIndex
= 0; theIndex
< nPropCount
; theIndex
++ )
103 // split fullname into namespace and name!
104 DAVProperties::createSerfPropName( (*mpPropNames
)[ theIndex
],
107 /* <*propname* xmlns="*propns*" /> */
108 aBodyText
+= OUString::createFromAscii( "<" );
109 aBodyText
+= OUString::createFromAscii( thePropName
.name
);
110 aBodyText
+= OUString::createFromAscii( " xmlnx=\"" );
111 aBodyText
+= OUString::createFromAscii( thePropName
.nspace
);
112 aBodyText
+= OUString::createFromAscii( "\"/>" );
115 aBodyText
= OUString::createFromAscii( "<prop>" ) +
117 OUString::createFromAscii( "</prop>" );
121 if ( mbOnlyPropertyNames
)
123 aBodyText
= OUString::createFromAscii( "<propname/>" );
127 aBodyText
= OUString::createFromAscii( "<allprop/>" );
131 aBodyText
= OUString::createFromAscii( PROPFIND_HEADER
) +
133 OUString::createFromAscii( PROPFIND_TRAILER
);
134 body_bkt
= SERF_BUCKET_SIMPLE_STRING( OUStringToOString( aBodyText
, RTL_TEXTENCODING_UTF8
),
136 if ( useChunkedEncoding() )
138 body_bkt
= serf_bucket_chunk_create( body_bkt
, pSerfBucketAlloc
);
142 // create serf request
143 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
149 // set request header fields
150 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
151 // general header fields provided by caller
152 setRequestHeaders( hdrs_bkt
);
154 // request specific header fields
155 serf_bucket_headers_set( hdrs_bkt
, "Depth", mDepthStr
);
156 if ( body_bkt
!= 0 && aBodyText
.getLength() > 0 )
158 if ( useChunkedEncoding() )
160 serf_bucket_headers_set( hdrs_bkt
, "Transfer-Encoding", "chunked");
162 serf_bucket_headers_set( hdrs_bkt
, "Content-Type", "application/xml" );
163 serf_bucket_headers_set( hdrs_bkt
, "Content-Length",
164 OUStringToOString( OUString::valueOf( aBodyText
.getLength() ), RTL_TEXTENCODING_UTF8
) );
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: */