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 <rtl/ustring.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include "DAVProperties.hxx"
23 #include "UCBDeadPropertyValue.hxx"
25 #include "SerfPropPatchReqProcImpl.hxx"
27 namespace http_dav_ucp
30 SerfPropPatchReqProcImpl::SerfPropPatchReqProcImpl( const char* inPath
,
31 const DAVRequestHeaders
& inRequestHeaders
,
32 const std::vector
< ProppatchValue
> & inProperties
)
33 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
34 , mpProperties( &inProperties
)
38 SerfPropPatchReqProcImpl::~SerfPropPatchReqProcImpl()
42 #define PROPPATCH_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propertyupdate xmlns=\"DAV:\">"
43 #define PROPPATCH_TRAILER "</propertyupdate>"
45 serf_bucket_t
* SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
47 serf_bucket_alloc_t
* pSerfBucketAlloc
= serf_request_get_alloc( inSerfRequest
);
50 serf_bucket_t
* body_bkt
= 0;
53 // create and fill body bucket with properties to be set or removed
60 { RTL_CONSTASCII_STRINGPARAM( "set" ) },
61 { RTL_CONSTASCII_STRINGPARAM( "remove" ) }
63 const int nPropCount
= ( mpProperties
!= 0 )
64 ? mpProperties
->size()
68 rtl::OUStringBuffer aBuffer
;
69 // add PropPatch xml header in front
70 aBuffer
.append( PROPPATCH_HEADER
);
72 // <*operation code*><prop>
74 ProppatchOperation lastOp
= (*mpProperties
)[ 0 ].operation
;
75 aBuffer
.append( "<" );
76 aBuffer
.appendAscii( OpCode
[lastOp
].str
, OpCode
[lastOp
].len
);
77 aBuffer
.append( "><prop>" );
79 SerfPropName thePropName
;
80 for ( int n
= 0; n
< nPropCount
; ++n
)
82 const ProppatchValue
& rProperty
= (*mpProperties
)[ n
];
83 // split fullname into namespace and name!
84 DAVProperties::createSerfPropName( rProperty
.name
,
87 if ( rProperty
.operation
!= lastOp
)
89 // </prop></*last operation code*><*operation code><prop>
90 aBuffer
.append( "</prop></" );
91 aBuffer
.appendAscii( OpCode
[lastOp
].str
, OpCode
[lastOp
].len
);
92 aBuffer
.append( "><" );
93 aBuffer
.appendAscii( OpCode
[rProperty
.operation
].str
, OpCode
[rProperty
.operation
].len
);
94 aBuffer
.append( "><prop>" );
97 // <*propname* xmlns="*propns*"
98 aBuffer
.append( "<" );
99 aBuffer
.appendAscii( thePropName
.name
);
100 aBuffer
.append( " xmlns=\"" );
101 aBuffer
.appendAscii( thePropName
.nspace
);
102 aBuffer
.append( "\"" );
104 if ( rProperty
.operation
== PROPSET
)
106 // >*property value*</*propname*>
107 aBuffer
.append( ">" );
109 OUString aStringValue
;
110 if ( DAVProperties::isUCBDeadProperty( thePropName
) )
112 UCBDeadPropertyValue::toXML( rProperty
.value
,
117 rProperty
.value
>>= aStringValue
;
119 aBuffer
.append( aStringValue
);
120 aBuffer
.append( "</" );
121 aBuffer
.appendAscii( thePropName
.name
);
122 aBuffer
.append( ">" );
127 aBuffer
.append( "/>" );
130 lastOp
= rProperty
.operation
;
133 // </prop></*last operation code*>
134 aBuffer
.append( "</prop></" );
135 aBuffer
.appendAscii( OpCode
[lastOp
].str
, OpCode
[lastOp
].len
);
136 aBuffer
.append( ">" );
138 // add PropPatch xml trailer at end
139 aBuffer
.append( PROPPATCH_TRAILER
);
141 aBodyText
= rtl::OUStringToOString( aBuffer
.makeStringAndClear(), RTL_TEXTENCODING_UTF8
);
142 body_bkt
= serf_bucket_simple_copy_create( aBodyText
.getStr(),
143 aBodyText
.getLength(),
148 // create serf request
149 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
154 handleChunkedEncoding(req_bkt
, aBodyText
.getLength());
156 // set request header fields
157 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
158 if (hdrs_bkt
!= NULL
)
160 // general header fields provided by caller
161 setRequestHeaders( hdrs_bkt
);
163 // request specific header fields
164 if ( body_bkt
!= 0 && aBodyText
.getLength() > 0 )
166 serf_bucket_headers_set( hdrs_bkt
, "Content-Type", "application/xml" );
171 assert("Headers Bucket missing");
177 void SerfPropPatchReqProcImpl::processChunkOfResponseData( const char* /*data*/,
183 void SerfPropPatchReqProcImpl::handleEndOfResponseData( serf_bucket_t
* /*inSerfResponseBucket*/ )
188 } // namespace http_dav_ucp
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */