Moved in request/response interfaces from opensaml.
authorScott Cantor <cantor.2@osu.edu>
Sat, 19 May 2007 18:04:53 +0000 (18:04 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sat, 19 May 2007 18:04:53 +0000 (18:04 +0000)
xmltooling/Makefile.am
xmltooling/XMLToolingConfig.cpp
xmltooling/io/GenericRequest.h [new file with mode: 0644]
xmltooling/io/GenericResponse.h [new file with mode: 0644]
xmltooling/io/HTTPRequest.h [new file with mode: 0644]
xmltooling/io/HTTPResponse.h [new file with mode: 0644]
xmltooling/xmltooling.vcproj

index 0703030..a2ae0dc 100644 (file)
@@ -58,7 +58,11 @@ implinclude_HEADERS = \
 
 ioinclude_HEADERS = \
        io/AbstractXMLObjectMarshaller.h \
-       io/AbstractXMLObjectUnmarshaller.h
+       io/AbstractXMLObjectUnmarshaller.h \
+       io/GenericRequest.h \
+       io/GenericResponse.h \
+       io/HTTPRequest.h \
+       io/HTTPResponse.h
 
 secinclude_HEADERS = \
        security/AbstractPKIXTrustEngine.h \
index 80a89fd..4e06f3e 100644 (file)
@@ -25,6 +25,8 @@
 #include "XMLToolingConfig.h"
 #include "encryption/Encryption.h"
 #include "encryption/Encrypter.h"
+#include "io/HTTPRequest.h"
+#include "io/HTTPResponse.h"
 #include "impl/UnknownElement.h"
 #include "security/TrustEngine.h"
 #include "security/OpenSSLCryptoX509CRL.h"
diff --git a/xmltooling/io/GenericRequest.h b/xmltooling/io/GenericRequest.h
new file mode 100644 (file)
index 0000000..af983d5
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * 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
+ *
+ *     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.
+ */
+
+/**
+ * @file xmltooling/io/GenericRequest.h
+ * 
+ * Interface to generic protocol requests that transport XML messages. 
+ */
+
+#ifndef __xmltooling_genreq_h__
+#define __xmltooling_genreq_h__
+
+#include <xmltooling/base.h>
+
+#include <string>
+#include <vector>
+
+#ifndef XMLTOOLING_NO_XMLSEC
+# include <xsec/enc/XSECCryptoX509.hpp>
+#endif
+
+namespace xmltooling {
+    
+    /**
+     * Interface to generic protocol requests that transport XML messages.
+     * 
+     * <p>This interface need not be threadsafe.
+     */
+    class XMLTOOL_API GenericRequest {
+        MAKE_NONCOPYABLE(GenericRequest);
+    protected:
+        GenericRequest() {}
+    public:
+        virtual ~GenericRequest() {}
+        
+        /**
+         * Returns the URL scheme of the request (http, https, ftp, ldap, etc.)
+         * 
+         * @return the URL scheme
+         */
+        virtual const char* getScheme() const=0;
+        
+        /**
+         * Returns true iff the request is over a confidential channel.
+         * 
+         * @return confidential channel indicator
+         */
+        virtual bool isSecure() const=0;
+        
+        /**
+         * Returns hostname of service that received request.
+         * 
+         * @return hostname of service
+         */
+        virtual const char* getHostname() const=0;
+
+        /**
+         * Returns incoming port.
+         * 
+         * @return  incoming port 
+         */
+        virtual int getPort() const=0;
+        
+        /**
+         * Returns the MIME type of the request, if known.
+         * 
+         * @return the MIME type, or an empty string
+         */
+        virtual std::string getContentType() const=0;
+
+        /**
+         * Returns the length of the request body, if known.
+         * 
+         * @return the content length, or -1 if unknown
+         */
+        virtual long getContentLength() const=0;
+
+        /**
+         * Returns the raw request body.
+         * 
+         * @return the request body, or NULL
+         */
+        virtual const char* getRequestBody() const=0;
+        
+        /**
+         * Returns a decoded named parameter value from the request.
+         * 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
+         */
+        virtual const char* getParameter(const char* name) const=0;
+
+        /**
+         * Returns all of the decoded values of a named parameter from the request.
+         * All values found will be returned.
+         * 
+         * @param name      the name of the parameter to return
+         * @param values    a vector in which to return pointers to the decoded values
+         * @return  the number of values returned
+         */            
+        virtual std::vector<const char*>::size_type getParameters(
+            const char* name, std::vector<const char*>& values
+            ) const=0;
+
+        /**
+         * Returns the transport-authenticated identity associated with the request,
+         * if authentication is solely handled by the transport.
+         * 
+         * @return the authenticated username or an empty string
+         */
+        virtual std::string getRemoteUser() const=0;
+
+        /**
+         * Returns the IP address of the client.
+         * 
+         * @return the client's IP address
+         */
+        virtual std::string getRemoteAddr() const=0;
+        
+        /**
+         * Returns the chain of certificates sent by the client.
+         * They are not guaranteed to be valid according to any particular definition.
+         * 
+         * @return the client's certificate chain 
+         */
+        virtual const
+#ifndef XMLTOOLING_NO_XMLSEC
+            std::vector<XSECCryptoX509*>&
+#else
+            std::vector<std::string>& 
+#endif
+            getClientCertificates() const=0;
+    };
+};
+
+#endif /* __xmltooling_genreq_h__ */
diff --git a/xmltooling/io/GenericResponse.h b/xmltooling/io/GenericResponse.h
new file mode 100644 (file)
index 0000000..57a459d
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * 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
+ *
+ *     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.
+ */
+
+/**
+ * @file xmltooling/io/GenericResponse.h
+ * 
+ * Interface to generic protocol responses that transport XML messages. 
+ */
+
+#ifndef __xmltooling_genres_h__
+#define __xmltooling_genres_h__
+
+#include <xmltooling/base.h>
+#include <iostream>
+
+namespace xmltooling {
+    
+    /**
+     * Interface to generic protocol responses that transport XML messages.
+     * 
+     * <p>This interface need not be threadsafe.
+     */
+    class XMLTOOL_API GenericResponse {
+        MAKE_NONCOPYABLE(GenericResponse);
+    protected:
+        GenericResponse() {}
+    public:
+        virtual ~GenericResponse() {}        
+
+        /**
+         * Sets or clears the MIME type of the response.
+         * 
+         * @param type the MIME type, or NULL to clear
+         */
+        virtual void setContentType(const char* type=NULL)=0;
+
+        /**
+         * Sends a completed response to the client along with a
+         * transport-specific "OK" indication. Used for "normal" responses.
+         * 
+         * @param inputStream   reference to source of response data
+         * @return a result code to return from the calling MessageEncoder
+         */
+        virtual long sendResponse(std::istream& inputStream)=0;
+
+        /**
+         * Sends an "error" response to the client along with a
+         * transport-specific error indication.
+         * 
+         * @param inputStream   reference to source of response data
+         * @return a result code to return from the calling MessageEncoder
+         */
+        virtual long sendError(std::istream& inputStream)=0;
+
+        /**
+         * Sends a completed response to the client.
+         * 
+         * @param inputStream   reference to source of response data
+         * @param status        transport-specific status to return
+         * @return a result code to return from the calling MessageEncoder
+         */
+        virtual long sendResponse(std::istream& inputStream, long status)=0;
+    };
+};
+
+#endif /* __xmltooling_genres_h__ */
diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h
new file mode 100644 (file)
index 0000000..caee6d5
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * 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
+ *
+ *     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.
+ */
+
+/**
+ * @file xmltooling/io/HTTPRequest.h
+ * 
+ * Interface to HTTP requests 
+ */
+
+#ifndef __xmltooling_httpreq_h__
+#define __xmltooling_httpreq_h__
+
+#include <xmltooling/io/GenericRequest.h>
+
+namespace xmltooling {
+    
+    /**
+     * Interface to HTTP requests.
+     * 
+     * <p>To supply information from the surrounding web server environment,
+     * a shim must be supplied in the form of this interface to adapt the
+     * library to different proprietary server APIs.
+     * 
+     * <p>This interface need not be threadsafe.
+     */
+    class XMLTOOL_API HTTPRequest : public GenericRequest {
+    protected:
+        HTTPRequest() {}
+    public:
+        virtual ~HTTPRequest() {}
+
+        bool isSecure() const {
+            return strcmp(getScheme(),"https")==0;
+        }
+          
+        /**
+         * Returns the HTTP method of the request (GET, POST, etc.)
+         * 
+         * @return the HTTP method
+         */
+        virtual const char* getMethod() const=0;
+        
+        /**
+         * Returns the request URI.
+         * 
+         * @return the request URI
+         */
+        virtual const char* getRequestURI() const=0;
+        
+        /**
+         * Returns the complete request URL, including scheme, host, port, and URI.
+         * 
+         * @return the request URL
+         */
+        virtual const char* getRequestURL() const=0;
+
+        /**
+         * Returns the HTTP query string appened to the request. The query
+         * string is returned without any decoding applied, everything found
+         * after the ? delimiter. 
+         * 
+         * @return the query string
+         */
+        virtual const char* getQueryString() const=0;
+
+        /**
+         * Returns a request header value.
+         * 
+         * @param name  the name of the header to return
+         * @return the header's value, or an empty string
+         */
+        virtual std::string getHeader(const char* name) const=0;
+    };
+};
+
+#endif /* __xmltooling_httpreq_h__ */
diff --git a/xmltooling/io/HTTPResponse.h b/xmltooling/io/HTTPResponse.h
new file mode 100644 (file)
index 0000000..63e1f4b
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * 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
+ *
+ *     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.
+ */
+
+/**
+ * @file xmltooling/io/HTTPResponse.h
+ * 
+ * Interface to HTTP response.
+ */
+
+#ifndef __xmltooling_httpres_h__
+#define __xmltooling_httpres_h__
+
+#include <xmltooling/io/GenericResponse.h>
+
+namespace xmltooling {
+    
+    /**
+     * Interface to HTTP response.
+     * 
+     * <p>To supply information to the surrounding web server environment,
+     * a shim must be supplied in the form of this interface to adapt the
+     * library to different proprietary server APIs.
+     * 
+     * <p>This interface need not be threadsafe.
+     */
+    class XMLTOOL_API HTTPResponse : public GenericResponse {
+    protected:
+        HTTPResponse() {}
+    public:
+        virtual ~HTTPResponse() {}
+        
+        void setContentType(const char* type) {
+            setResponseHeader("Content-Type", type);
+        }
+        
+        /**
+         * Sets or clears a response header.
+         * 
+         * @param name  header name
+         * @param value value to set, or NULL to clear
+         */
+        virtual void setResponseHeader(const char* name, const char* value)=0;
+
+        /**
+         * Sets a client cookie.
+         * 
+         * @param name  cookie name
+         * @param value value to set, or NULL to clear
+         */
+        virtual void setCookie(const char* name, const char* value) {
+            std::string cookie(name);
+            cookie = cookie + '=' + value;
+            setResponseHeader("Set-Cookie", cookie.c_str());
+        }
+        
+        /**
+         * Redirect the client to the specified URL and complete the response.
+         * Any headers previously set will be sent ahead of the redirect.
+         * 
+         * @param url   location to redirect client
+         * @return a result code to return from the calling MessageEncoder
+         */
+        virtual long sendRedirect(const char* url)=0;
+        
+        /** Some common HTTP status codes. */
+        enum status_t {
+            XMLTOOLING_HTTP_STATUS_OK = 200,
+            XMLTOOLING_HTTP_STATUS_MOVED = 302,
+            XMLTOOLING_HTTP_STATUS_FORBIDDEN = 403,
+            XMLTOOLING_HTTP_STATUS_NOTFOUND = 404,
+            XMLTOOLING_HTTP_STATUS_ERROR = 500
+        };
+        
+        using GenericResponse::sendResponse;
+
+        long sendError(std::istream& inputStream) {
+            return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_ERROR);
+        }
+
+        long sendResponse(std::istream& inputStream) {
+            return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_OK);
+        }
+    };
+};
+
+#endif /* __xmltooling_httpres_h__ */
index 4e94427..a94c737 100644 (file)
                                        RelativePath=".\io\AbstractXMLObjectUnmarshaller.h"\r
                                        >\r
                                </File>\r
+                               <File\r
+                                       RelativePath=".\io\GenericRequest.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\io\GenericResponse.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\io\HTTPRequest.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\io\HTTPResponse.h"\r
+                                       >\r
+                               </File>\r
                        </Filter>\r
                        <Filter\r
                                Name="impl"\r