Large reorg of shibsp lib, new SPRequest API, ported modules, shifted code out of...
[shibboleth/sp.git] / shibsp / SPRequest.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 shibsp/SPRequest.h
19  * 
20  * Interface to server request being processed  
21  */
22
23 #ifndef __shibsp_req_h__
24 #define __shibsp_req_h__
25
26 #include <shibsp/base.h>
27 #include <saml/binding/HTTPRequest.h>
28 #include <saml/binding/HTTPResponse.h>
29
30 namespace shibsp {
31     
32     class SHIBSP_API Application;
33     
34     /**
35      * Interface to server request being processed
36      * 
37      * <p>To supply information from the surrounding web server environment,
38      * a shim must be supplied in the form of this interface to adapt the
39      * library to different proprietary server APIs.
40      * 
41      * <p>This interface need not be threadsafe.
42      */
43     class SHIBSP_API SPRequest : public virtual opensaml::HTTPRequest, public virtual opensaml::HTTPResponse
44     {
45     protected:
46         SPRequest() {}
47     public:
48         virtual ~SPRequest() {}
49         
50         /**
51          * Returns the Application governing the request.
52          * 
53          * @return reference to Application
54          */
55         virtual const Application& getSPApplication() const=0;
56         
57         /**
58          * Returns the effective base Handler URL for a resource,
59          * or the current request URL.
60          * 
61          * @param resource  resource URL to compute handler for
62          * @return  base location of handler
63          */
64         virtual const char* getHandlerURL(const char* resource=NULL) const=0;
65
66         /**
67          * Get a cookie value supplied by the client.
68          * 
69          * @param name  name of cookie
70          * @return  cookie value or NULL
71          */
72         virtual const char* getCookie(const char* name) const=0;
73         
74         /**
75          * Returns a non-spoofable request header value, if possible.
76          * Platforms that support environment export can redirect header
77          * lookups by overriding this method.
78          * 
79          * @param name  the name of the secure header to return
80          * @return the header's value, or an empty string
81          */
82         virtual std::string getSecureHeader(const char* name) const {
83             return getHeader(name);
84         }
85
86         /**
87          * Ensures no value exists for a request header.
88          * 
89          * @param name  name of header to clear 
90          */
91         virtual void clearHeader(const char* name)=0;
92
93         /**
94          * Sets a value for a request header.
95          * 
96          * @param name  name of header to set
97          * @param value value to set
98          */
99         virtual void setHeader(const char* name, const char* value)=0;
100
101         /**
102          * Establish REMOTE_USER identity in request.
103          * 
104          * @param user  REMOTE_USER value to set or NULL to clear
105          */
106         virtual void setRemoteUser(const char* user)=0;
107         
108         /** Portable logging levels. */
109         enum SPLogLevel {
110           SPDebug,
111           SPInfo,
112           SPWarn,
113           SPError,
114           SPCrit
115         };
116
117         /**
118          * Log to native server environment.
119          * 
120          * @param level logging level
121          * @param msg   message to log
122          */
123         virtual void log(SPLogLevel level, const std::string& msg) const=0;
124
125         /**
126          * Test logging level.
127          * 
128          * @param level logging level
129          * @return true iff logging level is enabled
130          */
131         virtual bool isPriorityEnabled(SPLogLevel level) const=0;
132     };
133 };
134
135 #endif /* __shibsp_req_h__ */