Basic SOAP client, reworked transport streams.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPTransport.h
1 /*
2  *  Copyright 2001-2006 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 xmlsignature {
30     class XMLTOOL_API CredentialResolver;
31     class XMLTOOL_API KeyResolver;
32 };
33
34 namespace xmltooling {
35     
36     class XMLTOOL_API X509TrustEngine;
37     
38     /**
39      * Encapsulates a transport layer protocol for sending/receiving messages.
40      * 
41      * Most of the methods are const, meaning they don't affect the transport
42      * layer until the data is sent.
43      */
44     class XMLTOOL_API SOAPTransport
45     {
46         MAKE_NONCOPYABLE(SOAPTransport);
47     protected:
48         SOAPTransport() {}
49     public:
50         virtual ~SOAPTransport() {}
51         
52         /**
53          * Sets the connection timeout.
54          * 
55          * @param timeout  time to wait for connection to server in seconds, or -1 for no timeout
56          * @return  true iff the transport supports connection timeouts
57          */
58         virtual bool setConnectTimeout(long timeout) const=0;
59         
60         /**
61          * Sets the request timeout.
62          * 
63          * @param timeout  time to wait for a response in seconds, or -1 for no timeout
64          * @return  true iff the transport supports request/response timeouts
65          */
66         virtual bool setTimeout(long timeout) const=0;
67         
68         /**
69          * Common types of transport authentication that may be supported.
70          */
71         enum transport_auth_t {
72             transport_auth_none = 0,
73             transport_auth_basic = 1,
74             transport_auth_digest = 2,
75             transport_auth_ntlm = 3,
76             transport_auth_gss = 4
77         };
78         
79         /**
80          * Sets a particular form of transport authentication and credentials.
81          * 
82          * @param authType  type of transport authentication to use
83          * @param username  username for transport authentication
84          * @param password  simple password/credential for transport authentication
85          * @return  true iff the transport supports the indicated form of authentication
86          */
87         virtual bool setAuth(transport_auth_t authType, const char* username=NULL, const char* password=NULL) const=0;
88
89 #ifndef XMLTOOLING_NO_XMLSEC 
90         /**
91          * Provides a CredentialResolver to the transport to supply transport credentials.
92          * The lifetime of the resolver must be longer than the lifetime of this object.
93          * 
94          * <p>The CredentialResolver <strong>MUST</strong> be locked by the caller. 
95          * 
96          * @param credResolver  a locked CredentialResolver instance, or NULL
97          * @return true iff the transport supports the use of a CredentialResolver
98          */
99         virtual bool setCredentialResolver(const xmlsignature::CredentialResolver* credResolver) const=0;
100
101         /**
102          * Provides a TrustEngine to the transport to authenticate the transport peer.
103          * The lifetime of the engine must be longer than the lifetime of this object.
104          * 
105          * @param trustEngine   a TrustEngine instance, or NULL
106          * @param keyResolver   optional externally supplied KeyResolver, or NULL
107          * @return true iff the transport supports the use of a TrustEngine
108          */
109         virtual bool setTrustEngine(const X509TrustEngine* trustEngine, const xmlsignature::KeyResolver* keyResolver=NULL) const=0;
110 #endif
111
112         /**
113          * Sends a stream of data over the transport. The function may return without
114          * having received any data, depending on the nature of the transport.
115          * 
116          * @param in    input stream to send
117          */        
118         virtual void send(std::istream& in)=0;
119         
120         /**
121          * Returns reference to response stream.  The resulting stream must be
122          * checked directly to determine whether data is available.
123          * 
124          * @return  reference to a stream containing the response, if any
125          */
126         virtual std::istream& receive()=0;
127         
128         /**
129          * Returns the MIME type of the response, if any.
130          * 
131          * @return  MIME type of response, or an empty string
132          */
133         virtual std::string getContentType() const=0;
134     };
135
136     /**
137      * Registers SOAPTransport classes into the runtime.
138      */
139     void XMLTOOL_API registerSOAPTransports();
140     
141     /**
142      * Notifies transport infrastructure to initialize. 
143      */
144     void XMLTOOL_API initSOAPTransports();
145     
146     /**
147      * Notifies transport infrastructure to shutdown. 
148      */
149     void XMLTOOL_API termSOAPTransports();
150
151 };
152
153 #endif /* __xmltooling_soaptrans_h__ */