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 "SerfCallbacks.hxx"
26 
27 #include "SerfSession.hxx"
28 #include "SerfRequestProcessor.hxx"
29 
30 using namespace http_dav_ucp;
31 
Serf_ConnectSetup(apr_socket_t * skt,serf_bucket_t ** read_bkt,serf_bucket_t ** write_bkt,void * setup_baton,apr_pool_t * pool)32 extern "C" apr_status_t Serf_ConnectSetup( apr_socket_t *skt,
33                                            serf_bucket_t **read_bkt,
34                                            serf_bucket_t **write_bkt,
35                                            void *setup_baton,
36                                            apr_pool_t *pool )
37 {
38     SerfSession* pSerfSession = static_cast< SerfSession* >( setup_baton );
39     OSL_TRACE("Serf_ConnectSetup");
40     return pSerfSession->setupSerfConnection( skt,
41                                               read_bkt,
42                                               write_bkt,
43                                               pool );
44 }
45 
Serf_Credentials(char ** username,char ** password,serf_request_t * request,void * baton,int code,const char * authn_type,const char * realm,apr_pool_t * pool)46 extern "C" apr_status_t Serf_Credentials( char **username,
47                                           char **password,
48                                           serf_request_t *request,
49                                           void *baton,
50                                           int code,
51                                           const char *authn_type,
52                                           const char *realm,
53                                           apr_pool_t *pool )
54 {
55     SerfRequestProcessor* pReqProc = static_cast< SerfRequestProcessor* >( baton );
56     OSL_TRACE("Serf_Credential");
57     return pReqProc->provideSerfCredentials( username,
58                                              password,
59                                              request,
60                                              code,
61                                              authn_type,
62                                              realm,
63                                              pool );
64 }
65 
Serf_CertificateChainValidation(void * pSerfSession,int nFailures,int nErrorCode,const serf_ssl_certificate_t * const * pCertificateChainBase64Encoded,apr_size_t nCertificateChainLength)66 extern "C" apr_status_t Serf_CertificateChainValidation(
67     void* pSerfSession,
68     int nFailures,
69     int nErrorCode,
70     const serf_ssl_certificate_t * const * pCertificateChainBase64Encoded,
71     apr_size_t nCertificateChainLength)
72 {
73     OSL_TRACE("Serf_CertificateChainValidation");
74     return static_cast<SerfSession*>(pSerfSession)
75         ->verifySerfCertificateChain(nFailures, pCertificateChainBase64Encoded, nCertificateChainLength);
76 }
77 
Serf_SetupRequest(serf_request_t * request,void * setup_baton,serf_bucket_t ** req_bkt,serf_response_acceptor_t * acceptor,void ** acceptor_baton,serf_response_handler_t * handler,void ** handler_baton,apr_pool_t * pool)78 extern "C" apr_status_t Serf_SetupRequest( serf_request_t *request,
79                                            void *setup_baton,
80                                            serf_bucket_t **req_bkt,
81                                            serf_response_acceptor_t *acceptor,
82                                            void **acceptor_baton,
83                                            serf_response_handler_t *handler,
84                                            void **handler_baton,
85                                            apr_pool_t * pool )
86 {
87     SerfRequestProcessor* pReqProc = static_cast< SerfRequestProcessor* >( setup_baton );
88     OSL_TRACE("Serf_SetupRequest");
89     return pReqProc->setupSerfRequest( request,
90                                        req_bkt,
91                                        acceptor,
92                                        acceptor_baton,
93                                        handler,
94                                        handler_baton,
95                                        pool );
96 }
97 
Serf_AcceptResponse(serf_request_t * request,serf_bucket_t * stream,void * acceptor_baton,apr_pool_t * pool)98 extern "C" serf_bucket_t* Serf_AcceptResponse( serf_request_t *request,
99                                                serf_bucket_t *stream,
100                                                void *acceptor_baton,
101                                                apr_pool_t *pool )
102 {
103     SerfRequestProcessor* pReqProc = static_cast< SerfRequestProcessor* >( acceptor_baton );
104     OSL_TRACE("Serf_AcceptResponse");
105     return pReqProc->acceptSerfResponse( request,
106                                          stream,
107                                          pool );
108 }
109 
Serf_HandleResponse(serf_request_t * request,serf_bucket_t * response,void * handler_baton,apr_pool_t * pool)110 extern "C" apr_status_t Serf_HandleResponse( serf_request_t *request,
111                                              serf_bucket_t *response,
112                                              void *handler_baton,
113                                              apr_pool_t *pool )
114 {
115     SerfRequestProcessor* pReqProc = static_cast< SerfRequestProcessor* >( handler_baton );
116     OSL_TRACE("Serf_HandleResponse");
117     return pReqProc->handleSerfResponse( request,
118                                          response,
119                                          pool );
120 }
121 
122