b26be6e29eb273400114948b7d036b40811ac163
[shibboleth/cpp-sp.git] / shibsp / handler / RemotedHandler.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 shibsp/handler/RemotedHandler.h
19  * 
20  * Base class for handlers that need SP request/response layer to be remoted. 
21  */
22
23 #ifndef __shibsp_remhandler_h__
24 #define __shibsp_remhandler_h__
25
26 #include <shibsp/SPRequest.h>
27 #include <shibsp/handler/Handler.h>
28 #include <shibsp/remoting/ListenerService.h>
29
30 namespace shibsp {
31
32     /**
33      * Base class for handlers that need HTTP request/response layer to be remoted.
34      */
35     class SHIBSP_API RemotedHandler : public virtual Handler, public Remoted 
36     {
37     public:
38         virtual ~RemotedHandler();
39
40     protected:
41         RemotedHandler() {}
42
43         /**
44          * Establishes message remoting using the supplied address.
45          * 
46          * @param address   a unique "address" for remote message handling
47          */
48         void setAddress(const char* address);
49
50         /**
51          * Wraps a request by creating an outgoing data flow with the data needed
52          * to remote the request information.
53          *
54          * @param request   an SPRequest to remote
55          * @param headers   array of request headers to copy to remote request
56          * @param certs     true iff client certificates should be available for the remote request
57          * @return  the input dataflow object
58          */
59         DDF wrap(const SPRequest& request, const std::vector<std::string>* headers=NULL, bool certs=false) const;
60         
61         /**
62          * Unwraps a response by examining an incoming data flow to determine
63          * whether a response was produced by the remoted handler. 
64          * 
65          * @param request   SP request context
66          * @param out       the dataflow object to unpack
67          * @return  a pair containing a "request completed" indicator and a server-specific response code
68          */
69         virtual std::pair<bool,long> unwrap(SPRequest& request, DDF& out) const;
70         
71         /**
72          * Builds a new request instance around a remoted data object.
73          * 
74          * @param in    the dataflow object containing the remoted request
75          * @return  a call-specific request object based on the input, to be freed by the caller 
76          */
77         opensaml::HTTPRequest* getRequest(DDF& in) const;
78         
79         /**
80          * Builds a new response instance around an outgoing data object.
81          * 
82          * @param out   the dataflow object to be returned by the caller
83          * @return  a call-specific response object, to be freed by the caller 
84          */
85         opensaml::HTTPResponse* getResponse(DDF& out) const;
86         
87         /** Message address for remote half. */
88         std::string m_address;
89     };
90 };
91
92 #endif /* __shibsp_remhandler_h__ */