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 
23 #ifndef INCLUDED_SERFREQUESTPROCESSOR_HXX
24 #define INCLUDED_SERFREQUESTPROCESSOR_HXX
25 
26 #include <apr_errno.h>
27 #include <apr_pools.h>
28 
29 #include <serf.h>
30 
31 #include "DAVTypes.hxx"
32 #include "DAVResource.hxx"
33 #include "DAVException.hxx"
34 
35 #include "SerfInputStream.hxx"
36 #include <com/sun/star/io/XOutputStream.hpp>
37 
38 namespace http_dav_ucp
39 {
40 
41 class SerfSession;
42 class SerfRequestProcessorImpl;
43 
44 class SerfRequestProcessor
45 {
46 public:
47     SerfRequestProcessor( SerfSession& rSerfSession,
48                           const rtl::OUString & inPath,
49                           const bool bUseChunkedEncoding );
50     ~SerfRequestProcessor();
51 
52     // PROPFIND - allprop & named
53     bool processPropFind( const Depth inDepth,
54                           const std::vector< ::rtl::OUString > & inPropNames,
55                           std::vector< DAVResource > & ioResources,
56                           apr_status_t& outSerfStatus );
57 
58     // PROPFIND - property names
59     bool processPropFind( const Depth inDepth,
60                           std::vector< DAVResourceInfo > & ioResInfo,
61                           apr_status_t& outSerfStatus );
62 
63     // PROPPATCH
64     bool processPropPatch( const std::vector< ProppatchValue > & inProperties,
65                            apr_status_t& outSerfStatus );
66 
67     // GET
68     bool processGet( const com::sun::star::uno::Reference< SerfInputStream >& xioInStrm,
69                      apr_status_t& outSerfStatus );
70 
71     // GET inclusive header fields
72     bool processGet( const com::sun::star::uno::Reference< SerfInputStream >& xioInStrm,
73                      const std::vector< ::rtl::OUString > & inHeaderNames,
74                      DAVResource & ioResource,
75                      apr_status_t& outSerfStatus );
76 
77     // GET
78     bool processGet( const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xioOutStrm,
79                      apr_status_t& outSerfStatus );
80 
81     // GET inclusive header fields
82     bool processGet( const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xioOutStrm,
83                      const std::vector< ::rtl::OUString > & inHeaderNames,
84                      DAVResource & ioResource,
85                      apr_status_t& outSerfStatus );
86 
87     // HEAD
88     bool processHead( const std::vector< ::rtl::OUString > & inHeaderNames,
89                       DAVResource & ioResource,
90                       apr_status_t& outSerfStatus );
91 
92     // PUT
93     bool processPut( const char* inData,
94                      apr_size_t inDataLen,
95                      apr_status_t& outSerfStatus );
96 
97     // POST
98     bool processPost( const char* inData,
99                       apr_size_t inDataLen,
100                       const rtl::OUString & inContentType,
101                       const rtl::OUString & inReferer,
102                       const com::sun::star::uno::Reference< SerfInputStream >& xioInStrm,
103                       apr_status_t& outSerfStatus );
104 
105     // POST
106     bool processPost( const char* inData,
107                       apr_size_t inDataLen,
108                       const rtl::OUString & inContentType,
109                       const rtl::OUString & inReferer,
110                       const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xioOutStrm,
111                       apr_status_t& outSerfStatus );
112 
113     // DELETE
114     bool processDelete( apr_status_t& outSerfStatus );
115 
116     // MKCOL
117     bool processMkCol( apr_status_t& outSerfStatus );
118 
119     // COPY
120     bool processCopy( const rtl::OUString & inDestinationPath,
121                       const bool inOverwrite,
122                       apr_status_t& outSerfStatus );
123 
124     // MOVE
125     bool processMove( const rtl::OUString & inDestinationPath,
126                       const bool inOverwrite,
127                       apr_status_t& outSerfStatus );
128 
129     apr_status_t provideSerfCredentials( char ** outUsername,
130                                          char ** outPassword,
131                                          serf_request_t * inRequest,
132                                          int inCode,
133                                          const char *inAuthProtocol,
134                                          const char *inRealm,
135                                          apr_pool_t *inAprPool );
136 
137     apr_status_t setupSerfRequest( serf_request_t * inSerfRequest,
138                                    serf_bucket_t ** outSerfRequestBucket,
139                                    serf_response_acceptor_t * outSerfResponseAcceptor,
140                                    void ** outSerfResponseAcceptorBaton,
141                                    serf_response_handler_t * outSerfResponseHandler,
142                                    void ** outSerfResponseHandlerBaton,
143                                    apr_pool_t * inAprPool );
144 
145     serf_bucket_t* acceptSerfResponse( serf_request_t * inSerfRequest,
146                                        serf_bucket_t * inSerfStreamBucket,
147                                        apr_pool_t* inAprPool );
148 
149     apr_status_t handleSerfResponse( serf_request_t * inSerfRequest,
150                                      serf_bucket_t * inSerfResponseBucket,
151                                      apr_pool_t * inAprPool );
152 
153 //private:
154     void prepareProcessor();
155     apr_status_t runProcessor();
156     void postprocessProcessor( const apr_status_t inStatus );
157 
158     SerfSession& mrSerfSession;
159     const char* mPathStr;
160     const bool mbUseChunkedEncoding;
161     const char* mDestPathStr;
162     const char* mContentType;
163     const char* mReferer;
164     SerfRequestProcessorImpl* mpProcImpl;
165 
166     bool mbProcessingDone;
167 
168     DAVException* mpDAVException;
169     sal_uInt16 mnHTTPStatusCode;
170     rtl::OUString mHTTPStatusCodeText;
171     rtl::OUString mRedirectLocation;
172 
173     sal_uInt8 mnSuccessfulCredentialAttempts;
174     bool mbInputOfCredentialsAborted;
175     bool mbSetupSerfRequestCalled;
176     bool mbAcceptSerfResponseCalled;
177     bool mbHandleSerfResponseCalled;
178 };
179 
180 } // namespace http_dav_ucp
181 
182 #endif // INCLUDED_SERFREQUESTPROCESSOR_HXX
183