cbf6e2f9131796d144dec0c6703188b1eec9a1fb
[shibboleth/cpp-xmltooling.git] / xmltooling / io / GenericRequest.h
1 /*
2  *  Copyright 2001-2010 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/io/GenericRequest.h
19  *
20  * Interface to generic protocol requests that transport XML messages.
21  */
22
23 #ifndef __xmltooling_genreq_h__
24 #define __xmltooling_genreq_h__
25
26 #include <xmltooling/base.h>
27
28 #include <string>
29 #include <vector>
30
31 #ifndef XMLTOOLING_NO_XMLSEC
32 # include <xsec/enc/XSECCryptoX509.hpp>
33 #endif
34
35 namespace xmltooling {
36
37     /**
38      * Interface to generic protocol requests that transport XML messages.
39      *
40      * <p>This interface need not be threadsafe.
41      */
42     class XMLTOOL_API GenericRequest {
43         MAKE_NONCOPYABLE(GenericRequest);
44     protected:
45         GenericRequest();
46     public:
47         virtual ~GenericRequest();
48
49         /**
50          * Returns the URL scheme of the request (http, https, ftp, ldap, etc.)
51          *
52          * @return the URL scheme
53          */
54         virtual const char* getScheme() const=0;
55
56         /**
57          * Returns true iff the request is over a confidential channel.
58          *
59          * @return confidential channel indicator
60          */
61         virtual bool isSecure() const=0;
62
63         /**
64          * Returns hostname of service that received request.
65          *
66          * @return hostname of service
67          */
68         virtual const char* getHostname() const=0;
69
70         /**
71          * Returns incoming port.
72          *
73          * @return  incoming port
74          */
75         virtual int getPort() const=0;
76
77         /**
78          * Returns the MIME type of the request, if known.
79          *
80          * @return the MIME type, or an empty string
81          */
82         virtual std::string getContentType() const=0;
83
84         /**
85          * Returns the length of the request body, if known.
86          *
87          * @return the content length, or -1 if unknown
88          */
89         virtual long getContentLength() const=0;
90
91         /**
92          * Returns the raw request body.
93          *
94          * @return the request body, or nullptr
95          */
96         virtual const char* getRequestBody() const=0;
97
98         /**
99          * Returns a decoded named parameter value from the request.
100          * If a parameter has multiple values, only one will be returned.
101          *
102          * @param name  the name of the parameter to return
103          * @return a single parameter value or nullptr
104          */
105         virtual const char* getParameter(const char* name) const=0;
106
107         /**
108          * Returns all of the decoded values of a named parameter from the request.
109          * All values found will be returned.
110          *
111          * @param name      the name of the parameter to return
112          * @param values    a vector in which to return pointers to the decoded values
113          * @return  the number of values returned
114          */
115         virtual std::vector<const char*>::size_type getParameters(
116             const char* name, std::vector<const char*>& values
117             ) const=0;
118
119         /**
120          * Returns the transport-authenticated identity associated with the request,
121          * if authentication is solely handled by the transport.
122          *
123          * @return the authenticated username or an empty string
124          */
125         virtual std::string getRemoteUser() const=0;
126
127         /**
128          * Gets the authentication type associated with the request.
129          *
130          * @return  the authentication type or nullptr
131          */
132         virtual std::string getAuthType() const {
133             return "";
134         }
135
136         /**
137          * Returns the IP address of the client.
138          *
139          * @return the client's IP address
140          */
141         virtual std::string getRemoteAddr() const=0;
142
143         /**
144          * Returns the chain of certificates sent by the client.
145          * They are not guaranteed to be valid according to any particular definition.
146          *
147          * @return the client's certificate chain
148          */
149         virtual const
150 #ifndef XMLTOOLING_NO_XMLSEC
151             std::vector<XSECCryptoX509*>&
152 #else
153             std::vector<std::string>&
154 #endif
155             getClientCertificates() const=0;
156     };
157 };
158
159 #endif /* __xmltooling_genreq_h__ */