1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_ucb.hxx"
24 
25 #include "SerfTypes.hxx"
26 #include "SerfLockRefreshProcImpl.hxx"
27 #include "DAVProperties.hxx"
28 
29 #include "webdavresponseparser.hxx"
30 #include <serf.h>
31 #include <rtl/ustrbuf.hxx>
32 #include <apr_strings.h>
33 
34 namespace http_dav_ucp
35 {
36 
SerfLockRefreshProcImpl(const char * inSourcePath,const DAVRequestHeaders & inRequestHeaders,const ucb::Lock & inLock,const char * inLockToken,const char * inTimeout,DAVPropertyValue & outLock)37 SerfLockRefreshProcImpl::SerfLockRefreshProcImpl( const char* inSourcePath,
38                                                   const DAVRequestHeaders& inRequestHeaders, // on debug the header look empty
39                                                   const ucb::Lock& inLock,
40                                                   const char* inLockToken,
41                                                   const char* inTimeout,
42                                           DAVPropertyValue & outLock)
43     : SerfLockReqProcImpl( inSourcePath, inRequestHeaders, inLock, inTimeout, outLock )
44     , mpLockToken( inLockToken )
45 {
46 }
47 
~SerfLockRefreshProcImpl()48 SerfLockRefreshProcImpl::~SerfLockRefreshProcImpl()
49 {
50 }
51 
createSerfRequestBucket(serf_request_t * inSerfRequest)52 serf_bucket_t * SerfLockRefreshProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
53 {
54     // create serf request
55     serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
56                                                                  "LOCK",
57                                                                  getPathStr(),
58                                                                  0,
59                                                                  serf_request_get_alloc( inSerfRequest ) );
60     // set request header fields
61     serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
62     if (hdrs_bkt != NULL)
63     {
64         // general header fields provided by caller
65         setRequestHeaders( hdrs_bkt );
66 
67         // request specific header fields
68         if(mTimeout != 0)
69         {
70             serf_bucket_headers_set( hdrs_bkt, "Timeout", mTimeout );
71         }
72         if(mpLockToken != 0)
73         {
74             serf_bucket_headers_set( hdrs_bkt, "if", mpLockToken );
75         }
76     }
77     return req_bkt;
78 }
79 
80 } // namespace http_dav_ucp
81