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