2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/io/GenericRequest.h
24 * Interface to generic protocol requests that transport XML messages.
27 #ifndef __xmltooling_genreq_h__
28 #define __xmltooling_genreq_h__
30 #include <xmltooling/unicode.h>
36 #ifndef XMLTOOLING_NO_XMLSEC
37 # include <xsec/enc/XSECCryptoX509.hpp>
40 namespace xmltooling {
42 #if defined (_MSC_VER)
43 #pragma warning( push )
44 #pragma warning( disable : 4251 )
48 * Interface to generic protocol requests that transport XML messages.
50 * <p>This interface need not be threadsafe.
52 class XMLTOOL_API GenericRequest {
53 MAKE_NONCOPYABLE(GenericRequest);
57 virtual ~GenericRequest();
60 * Returns the URL scheme of the request (http, https, ftp, ldap, etc.)
62 * @return the URL scheme
64 virtual const char* getScheme() const=0;
67 * Returns true iff the request is over a confidential channel.
69 * @return confidential channel indicator
71 virtual bool isSecure() const=0;
74 * Returns hostname of service that received request.
76 * @return hostname of service
78 virtual const char* getHostname() const=0;
81 * Returns incoming port.
83 * @return incoming port
85 virtual int getPort() const=0;
88 * Returns the MIME type of the request, if known.
90 * @return the MIME type, or an empty string
92 virtual std::string getContentType() const=0;
95 * Returns the length of the request body, if known.
97 * @return the content length, or -1 if unknown
99 virtual long getContentLength() const=0;
102 * Returns the raw request body.
104 * @return the request body, or nullptr
106 virtual const char* getRequestBody() const=0;
109 * Returns a decoded named parameter value from the request.
110 * If a parameter has multiple values, only one will be returned.
112 * @param name the name of the parameter to return
113 * @return a single parameter value or nullptr
115 virtual const char* getParameter(const char* name) const=0;
118 * Returns all of the decoded values of a named parameter from the request.
119 * All values found will be returned.
121 * @param name the name of the parameter to return
122 * @param values a vector in which to return pointers to the decoded values
123 * @return the number of values returned
125 virtual std::vector<const char*>::size_type getParameters(
126 const char* name, std::vector<const char*>& values
130 * Returns the transport-authenticated identity associated with the request,
131 * if authentication is solely handled by the transport.
133 * @return the authenticated username or an empty string
135 virtual std::string getRemoteUser() const=0;
138 * Gets the authentication type associated with the request.
140 * @return the authentication type or nullptr
142 virtual std::string getAuthType() const {
147 * Returns the IP address of the client.
149 * @return the client's IP address
151 virtual std::string getRemoteAddr() const=0;
154 * Returns the chain of certificates sent by the client.
155 * They are not guaranteed to be valid according to any particular definition.
157 * @return the client's certificate chain
160 #ifndef XMLTOOLING_NO_XMLSEC
161 std::vector<XSECCryptoX509*>&
163 std::vector<std::string>&
165 getClientCertificates() const=0;
168 * Returns a language range to use in selecting language-specific
169 * content for this request.
170 * <p>The syntax is that of the HTTP 1.1 Accept-Language header, even
171 * if the underlying request is not HTTP.
173 * @return an HTTP 1.1 syntax language range specifier
175 virtual std::string getLanguageRange() const {
180 * Initializes the language matching process; call this method to begin the
181 * matching process by calling the matchLang method.
182 * <p>The language matching process is not thread-safe and must be externally
185 * @return true iff language matching is possible
187 bool startLangMatching() const;
190 * Continues the language matching process; additional calls to matchLang can
191 * be done as long as this method returns true.
192 * <p>The language matching process is not thread-safe and must be externally
195 * @return true iff more ranges are available to match against
197 bool continueLangMatching() const;
200 * Matches a language tag against the currently active range.
201 * <p>The language matching process is not thread-safe and must be externally
204 * @param tag a language tag (e.g., an xml:lang value)
205 * @return true iff the tag matches the active range
207 bool matchLang(const XMLCh* tag) const;
210 * Establish default handling of language ranges.
212 * @param langFromClient honor client's language preferences if any
213 * @param defaultRange priority list of space-delimited language tags to use by default
215 static void setLangDefaults(bool langFromClient, const XMLCh* defaultRange);
218 typedef std::multimap< float,std::vector<xstring> > langrange_t;
219 mutable langrange_t m_langRange;
220 mutable langrange_t::const_reverse_iterator m_langRangeIter;
221 static langrange_t m_defaultRange;
222 static bool m_langFromClient;
225 #if defined (_MSC_VER)
226 #pragma warning( pop )
231 #endif /* __xmltooling_genreq_h__ */