Port up URI sanitizer from branch.
[shibboleth/sp.git] / shibsp / AbstractSPRequest.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/AbstractSPRequest.h
19  * 
20  * Abstract base for SPRequest implementations  
21  */
22
23 #ifndef __shibsp_abstreq_h__
24 #define __shibsp_abstreq_h__
25
26 #include <shibsp/exceptions.h>
27 #include <shibsp/SPRequest.h>
28 #include <shibsp/util/CGIParser.h>
29
30 namespace shibsp {
31     
32 #if defined (_MSC_VER)
33     #pragma warning( push )
34     #pragma warning( disable : 4251 )
35 #endif
36
37     /**
38      * Abstract base for SPRequest implementations
39      */
40     class SHIBSP_API AbstractSPRequest : public virtual SPRequest
41     {
42     protected:
43         AbstractSPRequest();
44         
45         /**
46          * Stores a normalized request URI to ensure it contains no %-encoded characters
47          * or other undesirable artifacts, such as ;jsessionid appendage.
48          *
49          * @param uri   the request URI as obtained from the client
50          */
51         void setRequestURI(const char* uri);
52
53     public:
54         virtual ~AbstractSPRequest();
55
56         const ServiceProvider& getServiceProvider() const {
57             return *m_sp;
58         }
59
60         RequestMapper::Settings getRequestSettings() const;
61
62         const Application& getApplication() const;
63         
64         Session* getSession(bool checkTimeout=true, bool ignoreAddress=false, bool cache=true) const;
65
66         const char* getRequestURI() const {
67             return m_uri.c_str();
68         }
69
70         const char* getRequestURL() const;
71         
72         const char* getParameter(const char* name) const;
73
74         std::vector<const char*>::size_type getParameters(const char* name, std::vector<const char*>& values) const;
75
76         const char* getCookie(const char* name) const;
77
78         const char* getHandlerURL(const char* resource=NULL) const;
79
80         void log(SPLogLevel level, const std::string& msg) const;
81
82         bool isPriorityEnabled(SPLogLevel level) const;
83
84     private:
85         ServiceProvider* m_sp;
86         mutable RequestMapper* m_mapper;
87         mutable RequestMapper::Settings m_settings;
88         mutable const Application* m_app;
89         mutable bool m_sessionTried;
90         mutable Session* m_session;
91         std::string m_uri;
92         mutable std::string m_url;
93         void* m_log; // declared void* to avoid log4cpp header conflicts in Apache
94         mutable std::string m_handlerURL;
95         mutable std::map<std::string,std::string> m_cookieMap;
96         mutable CGIParser* m_parser;
97     };
98
99 #if defined (_MSC_VER)
100     #pragma warning( pop )
101 #endif
102
103 };
104
105 #endif /* __shibsp_abstreq_h__ */