CPPXT-104 - Add exception handling to integer conversions
[shibboleth/cpp-xmltooling.git] / xmltooling / io / GenericRequest.h
index a874040..ff24bdb 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2009 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
@@ -23,8 +27,9 @@
 #ifndef __xmltooling_genreq_h__
 #define __xmltooling_genreq_h__
 
-#include <xmltooling/base.h>
+#include <xmltooling/unicode.h>
 
+#include <map>
 #include <string>
 #include <vector>
 
 
 namespace xmltooling {
 
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4251 )
+#endif
+
     /**
      * Interface to generic protocol requests that transport XML messages.
      *
@@ -75,6 +85,13 @@ namespace xmltooling {
         virtual int getPort() const=0;
 
         /**
+         * Returns true iff the request port is the default port for the request protocol.
+         *
+         * @return  default port indicator
+         */
+        virtual bool isDefaultPort() const;
+
+        /**
          * Returns the MIME type of the request, if known.
          *
          * @return the MIME type, or an empty string
@@ -91,7 +108,7 @@ namespace xmltooling {
         /**
          * Returns the raw request body.
          *
-         * @return the request body, or NULL
+         * @return the request body, or nullptr
          */
         virtual const char* getRequestBody() const=0;
 
@@ -100,7 +117,7 @@ namespace xmltooling {
          * If a parameter has multiple values, only one will be returned.
          *
          * @param name  the name of the parameter to return
-         * @return a single parameter value or NULL
+         * @return a single parameter value or nullptr
          */
         virtual const char* getParameter(const char* name) const=0;
 
@@ -127,7 +144,7 @@ namespace xmltooling {
         /**
          * Gets the authentication type associated with the request.
          *
-         * @return  the authentication type or NULL
+         * @return  the authentication type or nullptr
          */
         virtual std::string getAuthType() const {
             return "";
@@ -153,7 +170,76 @@ namespace xmltooling {
             std::vector<std::string>&
 #endif
             getClientCertificates() const=0;
+
+        /**
+         * Converts a relative URL into an absolute one based on the properties of the request.
+         *
+         * @param url   input URL to convert, will be modified in place
+         */
+        virtual void absolutize(std::string& url) const;
+
+        /**
+         * Returns a language range to use in selecting language-specific
+         * content for this request.
+         * <p>The syntax is that of the HTTP 1.1 Accept-Language header, even
+         * if the underlying request is not HTTP.
+         *
+         * @return an HTTP 1.1 syntax language range specifier
+         */
+        virtual std::string getLanguageRange() const {
+            return "";
+        }
+
+        /**
+         * Initializes the language matching process; call this method to begin the
+         * matching process by calling the matchLang method.
+         * <p>The language matching process is not thread-safe and must be externally
+         * syncronized.
+         *
+         * @return  true iff language matching is possible
+         */
+        bool startLangMatching() const;
+
+        /**
+         * Continues the language matching process; additional calls to matchLang can
+         * be done as long as this method returns true.
+         * <p>The language matching process is not thread-safe and must be externally
+         * syncronized.
+         *
+         * @return  true iff more ranges are available to match against
+         */
+        bool continueLangMatching() const;
+
+        /**
+         * Matches a language tag against the currently active range.
+         * <p>The language matching process is not thread-safe and must be externally
+         * syncronized.
+         * 
+         * @param tag   a language tag (e.g., an xml:lang value)
+         * @return  true iff the tag matches the active range
+         */
+        bool matchLang(const XMLCh* tag) const;
+
+        /**
+         * Establish default handling of language ranges.
+         * 
+         * @param langFromClient    honor client's language preferences if any
+         * @param defaultRange      priority list of space-delimited language tags to use by default
+         */
+        static void setLangDefaults(bool langFromClient, const XMLCh* defaultRange);
+
+    private:
+        typedef std::multimap< float,std::vector<xstring> > langrange_t;
+        mutable langrange_t m_langRange;
+        mutable langrange_t::const_reverse_iterator m_langRangeIter;
+        static langrange_t m_defaultRange;
+        static bool m_langFromClient;
     };
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
 };
 
 #endif /* __xmltooling_genreq_h__ */