Option to disable host checking.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPTransport.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/soap/SOAPTransport.h
19  * 
20  * Encapsulates a transport layer protocol for sending/receiving messages.
21  */
22
23 #ifndef __xmltooling_soaptrans_h__
24 #define __xmltooling_soaptrans_h__
25
26 #include <xmltooling/base.h>
27 #include <iostream>
28
29 namespace xmltooling {
30     
31     class XMLTOOL_API Credential;
32     class XMLTOOL_API CredentialResolver;
33     class XMLTOOL_API X509TrustEngine;
34     
35     /**
36      * Encapsulates a transport layer protocol for sending/receiving messages.
37      * 
38      * Most of the methods are const, meaning they don't affect the transport
39      * layer until the data is sent.
40      */
41     class XMLTOOL_API SOAPTransport
42     {
43         MAKE_NONCOPYABLE(SOAPTransport);
44     protected:
45         SOAPTransport() {}
46     public:
47         virtual ~SOAPTransport() {}
48         
49         /**
50          * Indicates whether transport provides confidentiality.
51          * 
52          * @return  true iff transport layer provides confidentiality
53          */
54         virtual bool isConfidential() const=0;
55         
56         /**
57          * Sets the connection timeout.
58          * 
59          * @param timeout  time to wait for connection to server in seconds, or -1 for no timeout
60          * @return  true iff the transport supports connection timeouts
61          */
62         virtual bool setConnectTimeout(long timeout)=0;
63         
64         /**
65          * Sets the request timeout.
66          * 
67          * @param timeout  time to wait for a response in seconds, or -1 for no timeout
68          * @return  true iff the transport supports request/response timeouts
69          */
70         virtual bool setTimeout(long timeout)=0;
71         
72         /**
73          * Common types of transport authentication that may be supported.
74          */
75         enum transport_auth_t {
76             transport_auth_none = 0,
77             transport_auth_basic = 1,
78             transport_auth_digest = 2,
79             transport_auth_ntlm = 3,
80             transport_auth_gss = 4
81         };
82         
83         /**
84          * Sets a particular form of transport authentication and credentials.
85          * 
86          * @param authType  type of transport authentication to use
87          * @param username  username for transport authentication
88          * @param password  simple password/credential for transport authentication
89          * @return  true iff the transport supports the indicated form of authentication
90          */
91         virtual bool setAuth(transport_auth_t authType, const char* username=NULL, const char* password=NULL)=0;
92
93         /**
94          * Determines whether TLS/SSL connections include a check of the server's certificate
95          * against the expected hostname or address. Defaults to true, and has no effect for
96          * insecure protocols.
97          * 
98          * @param verify    true iff the hostname should be verified against the server's certificate
99          * @return  true iff the transport supports hostname verification
100          */
101         virtual bool setVerifyHost(bool verify)=0;
102         
103 #ifndef XMLTOOLING_NO_XMLSEC
104         /**
105          * Supplies transport credentials.
106          *
107          * <p>The lifetime of the credential must be longer than the lifetime of this object.
108          * 
109          * @param credential  a Credential instance, or NULL
110          * @return true iff the transport supports the use of the Credential
111          */
112         virtual bool setCredential(const Credential* credential=NULL)=0;
113
114         /**
115          * Provides an X509TrustEngine to the transport to authenticate the transport peer.
116          * The lifetime of the engine must be longer than the lifetime of this object.
117          * 
118          * @param trustEngine   an X509TrustEngine instance, or NULL
119          * @param credResolver  a CredentialResolver to supply the peer's trusted credentials, or NULL
120          * @param criteria      optional criteria for selecting peer credentials
121          * @param mandatory     flag controls whether message is sent at all if the
122          *                      transport isn't authenticated using the TrustEngine
123          * @return true iff the transport supports the use of a TrustEngine
124          */
125         virtual bool setTrustEngine(
126             const X509TrustEngine* trustEngine=NULL,
127             const CredentialResolver* credResolver=NULL,
128             CredentialCriteria* criteria=NULL,
129             bool mandatory=true
130             )=0;
131 #endif
132
133         /**
134          * Sends a stream of data over the transport. The function may return without
135          * having received any data, depending on the nature of the transport.
136          * 
137          * @param in    input stream to send
138          */        
139         virtual void send(std::istream& in)=0;
140         
141         /**
142          * Returns reference to response stream.  The resulting stream must be
143          * checked directly to determine whether data is available.
144          * 
145          * @return  reference to a stream containing the response, if any
146          */
147         virtual std::istream& receive()=0;
148         
149         /**
150          * Returns result of authenticating transport peer.
151          * 
152          * @return true iff TrustEngine or other mechanism successfully authenticated the peer
153          */
154         virtual bool isSecure() const=0;
155
156         /**
157          * Returns the MIME type of the response, if any.
158          * 
159          * @return  MIME type of response, or an empty string
160          */
161         virtual std::string getContentType() const=0;
162     };
163
164 #ifndef XMLTOOLING_NO_XMLSEC
165     /**
166      * Registers SOAPTransport classes into the runtime.
167      */
168     void XMLTOOL_API registerSOAPTransports();
169     
170     /**
171      * Notifies transport infrastructure to initialize. 
172      */
173     void XMLTOOL_API initSOAPTransports();
174     
175     /**
176      * Notifies transport infrastructure to shutdown. 
177      */
178     void XMLTOOL_API termSOAPTransports();
179 #endif
180
181 };
182
183 #endif /* __xmltooling_soaptrans_h__ */