trunk: sync from 1.4.3

make & cmake fixes
This commit is contained in:
Marian Krivos
2012-02-04 17:03:09 +00:00
parent 0afd04898b
commit 8b70c37260
55 changed files with 2797 additions and 2229 deletions

View File

@@ -1,60 +1,78 @@
//
// ApacheApplication.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheApplication.h#2 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheApplication_INCLUDED
#define ApacheConnector_ApacheApplication_INCLUDED
#include "ApacheRequestHandlerFactory.h"
#include "Poco/Util/Application.h"
#include "Poco/Mutex.h"
class ApacheApplication: public Poco::Util::Application
{
public:
ApacheApplication();
/// Creates the ApacheApplication and sets the
/// ApacheChannel as the root logger channel.
~ApacheApplication();
/// Destroys the ApacheApplication.
void setup();
/// Initializes the application if called for the first
/// time; does nothing in later calls.
ApacheRequestHandlerFactory& factory();
/// Returns the ApacheRequestHandlerFactory.
static ApacheApplication& instance();
/// Returns the application instance.
private:
bool _ready;
ApacheRequestHandlerFactory _factory;
Poco::FastMutex _mutex;
};
//
// inlines
//
inline ApacheRequestHandlerFactory& ApacheApplication::factory()
{
return _factory;
}
#endif // ApacheConnector_ApacheApplication_INCLUDED
//
// ApacheApplication.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheApplication.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheApplication_INCLUDED
#define ApacheConnector_ApacheApplication_INCLUDED
#include "ApacheRequestHandlerFactory.h"
#include "Poco/Util/Application.h"
#include "Poco/Mutex.h"
class ApacheApplication: public Poco::Util::Application
{
public:
ApacheApplication();
/// Creates the ApacheApplication and sets the
/// ApacheChannel as the root logger channel.
~ApacheApplication();
/// Destroys the ApacheApplication.
void setup();
/// Initializes the application if called for the first
/// time; does nothing in later calls.
ApacheRequestHandlerFactory& factory();
/// Returns the ApacheRequestHandlerFactory.
static ApacheApplication& instance();
/// Returns the application instance.
private:
bool _ready;
ApacheRequestHandlerFactory _factory;
Poco::FastMutex _mutex;
};
//
// inlines
//
inline ApacheRequestHandlerFactory& ApacheApplication::factory()
{
return _factory;
}
#endif // ApacheConnector_ApacheApplication_INCLUDED

View File

@@ -1,34 +1,52 @@
//
// ApacheChannel.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheChannel.h#1 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheChannel_INCLUDED
#define ApacheConnector_ApacheChannel_INCLUDED
#include "Poco/Channel.h"
class ApacheChannel: public Poco::Channel
/// This class implements a logging channel
/// that uses the Apache logging facilities.
{
public:
ApacheChannel();
~ApacheChannel();
void log(const Poco::Message& msg);
};
#endif // ApacheConnector_ApacheChannel_INCLUDED
//
// ApacheChannel.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheChannel.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheChannel_INCLUDED
#define ApacheConnector_ApacheChannel_INCLUDED
#include "Poco/Channel.h"
class ApacheChannel: public Poco::Channel
/// This class implements a logging channel
/// that uses the Apache logging facilities.
{
public:
ApacheChannel();
~ApacheChannel();
void log(const Poco::Message& msg);
};
#endif // ApacheConnector_ApacheChannel_INCLUDED

View File

@@ -1,90 +1,108 @@
//
// ApacheConnector.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheConnector.h#3 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheConnector_INCLUDED
#define ApacheConnector_ApacheConnector_INCLUDED
#include <string>
struct request_rec;
class ApacheServerRequest;
class ApacheRequestRec
/// This class wraps an Apache request_rec.
{
public:
ApacheRequestRec(request_rec* _pRec);
/// Creates the ApacheRequestRec;
bool haveRequestBody();
/// Returns true if the request contains a body.
int readRequest(char* buffer, int length);
/// Read up to length bytes from request body into buffer.
/// Returns the number of bytes read, 0 if eof or -1 if an error occured.
void writeResponse(const char* buffer, int length);
/// Writes the given characters as response to the given request_rec.
void addHeader(const std::string& key, const std::string& value);
/// Adds the given key / value pair to the outgoing headers of the
/// http response.
void setContentType(const std::string& mediaType);
/// Sets the response content type.
void redirect(const std::string& uri);
/// Redirects the response to the given uri.
void sendErrorResponse(int status);
/// Sends an error response with the given HTTP status code.
int sendFile(const std::string& path, unsigned int fileSize, const std::string& mediaType);
/// Sends the file given by fileName as response.
void copyHeaders(ApacheServerRequest& request);
/// Copies the request uri and header fields from the Apache request
/// to the ApacheServerRequest.
private:
request_rec* _pRec;
};
class ApacheConnector
/// This class provides static methods wrapping the
/// Apache API.
{
public:
enum LogLevel
{
PRIO_FATAL = 1, /// A fatal error. The application will most likely terminate. This is the highest priority.
PRIO_CRITICAL, /// A critical error. The application might not be able to continue running successfully.
PRIO_ERROR, /// An error. An operation did not complete successfully, but the application as a whole is not affected.
PRIO_WARNING, /// A warning. An operation completed with an unexpected result.
PRIO_NOTICE, /// A notice, which is an information with just a higher priority.
PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
PRIO_DEBUG, /// A debugging message.
PRIO_TRACE /// A tracing message. This is the lowest priority.
};
static void log(const char* file, int line, int level, int status, const char* text);
/// Log the given message.
};
#endif // ApacheConnector_ApacheConnector_INCLUDED
//
// ApacheConnector.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheConnector.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheConnector_INCLUDED
#define ApacheConnector_ApacheConnector_INCLUDED
#include <string>
struct request_rec;
class ApacheServerRequest;
class ApacheRequestRec
/// This class wraps an Apache request_rec.
{
public:
ApacheRequestRec(request_rec* _pRec);
/// Creates the ApacheRequestRec;
bool haveRequestBody();
/// Returns true if the request contains a body.
int readRequest(char* buffer, int length);
/// Read up to length bytes from request body into buffer.
/// Returns the number of bytes read, 0 if eof or -1 if an error occured.
void writeResponse(const char* buffer, int length);
/// Writes the given characters as response to the given request_rec.
void addHeader(const std::string& key, const std::string& value);
/// Adds the given key / value pair to the outgoing headers of the
/// http response.
void setContentType(const std::string& mediaType);
/// Sets the response content type.
void redirect(const std::string& uri, int status);
/// Redirects the response to the given uri.
void sendErrorResponse(int status);
/// Sends an error response with the given HTTP status code.
int sendFile(const std::string& path, unsigned int fileSize, const std::string& mediaType);
/// Sends the file given by fileName as response.
void copyHeaders(ApacheServerRequest& request);
/// Copies the request uri and header fields from the Apache request
/// to the ApacheServerRequest.
private:
request_rec* _pRec;
};
class ApacheConnector
/// This class provides static methods wrapping the
/// Apache API.
{
public:
enum LogLevel
{
PRIO_FATAL = 1, /// A fatal error. The application will most likely terminate. This is the highest priority.
PRIO_CRITICAL, /// A critical error. The application might not be able to continue running successfully.
PRIO_ERROR, /// An error. An operation did not complete successfully, but the application as a whole is not affected.
PRIO_WARNING, /// A warning. An operation completed with an unexpected result.
PRIO_NOTICE, /// A notice, which is an information with just a higher priority.
PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
PRIO_DEBUG, /// A debugging message.
PRIO_TRACE /// A tracing message. This is the lowest priority.
};
static void log(const char* file, int line, int level, int status, const char* text);
/// Log the given message.
};
#endif // ApacheConnector_ApacheConnector_INCLUDED

View File

@@ -1,59 +1,77 @@
//
// ApacheRequestHandlerFactory.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheRequestHandlerFactory.h#5 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheRequestHandlerFactory_INCLUDED
#define ApacheConnector_ApacheRequestHandlerFactory_INCLUDED
#include "ApacheServerRequest.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/ClassLoader.h"
#include "Poco/Mutex.h"
#include <map>
class ApacheRequestHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory
{
public:
ApacheRequestHandlerFactory();
/// Constructs the ApacheRequestHandlerFactory
~ApacheRequestHandlerFactory();
/// Destructor of the ApacheRequestHandlerFactory
Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request);
/// Creates a new request handler for the given HTTP request.
bool mustHandle(const std::string& uri);
/// Returns 1 if the given uri must be handled by the
/// poco_mapper module, 0 otherwise.
void handleURIs(const std::string& uris);
/// Parses the given string for dllName, factoryName and the URIs to handle
/// by the request-handler
void addRequestHandlerFactory(const std::string& dllPath, const std::string& factoryName, const std::string& uri);
/// Adds the request handler from the given dll with the given name and
/// registers that handler with the given uri
private:
typedef std::map<std::string, Poco::Net::HTTPRequestHandlerFactory*> RequestHandlerFactories;
RequestHandlerFactories _requestHandlers;
Poco::ClassLoader<Poco::Net::HTTPRequestHandlerFactory> _loader;
Poco::FastMutex _mutex;
};
#endif // ApacheConnector_ApacheRequestHandlerFactory_INCLUDED
//
// ApacheRequestHandlerFactory.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheRequestHandlerFactory.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheRequestHandlerFactory_INCLUDED
#define ApacheConnector_ApacheRequestHandlerFactory_INCLUDED
#include "ApacheServerRequest.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/ClassLoader.h"
#include "Poco/Mutex.h"
#include <map>
class ApacheRequestHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory
{
public:
ApacheRequestHandlerFactory();
/// Constructs the ApacheRequestHandlerFactory
~ApacheRequestHandlerFactory();
/// Destructor of the ApacheRequestHandlerFactory
Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request);
/// Creates a new request handler for the given HTTP request.
bool mustHandle(const std::string& uri);
/// Returns 1 if the given uri must be handled by the
/// poco_mapper module, 0 otherwise.
void handleURIs(const std::string& uris);
/// Parses the given string for dllName, factoryName and the URIs to handle
/// by the request-handler
void addRequestHandlerFactory(const std::string& dllPath, const std::string& factoryName, const std::string& uri);
/// Adds the request handler from the given dll with the given name and
/// registers that handler with the given uri
private:
typedef std::map<std::string, Poco::Net::HTTPRequestHandlerFactory*> RequestHandlerFactories;
RequestHandlerFactories _requestHandlers;
Poco::ClassLoader<Poco::Net::HTTPRequestHandlerFactory> _loader;
Poco::FastMutex _mutex;
};
#endif // ApacheConnector_ApacheRequestHandlerFactory_INCLUDED

View File

@@ -1,102 +1,120 @@
//
// ApacheServerRequest.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheServerRequest.h#6 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheServerRequest_INCLUDED
#define ApacheConnector_ApacheServerRequest_INCLUDED
#include "ApacheConnector.h"
#include "ApacheStream.h"
#include "Poco/Net/HTTPServerRequest.h"
#include <set>
class ApacheServerResponse;
class ApacheServerRequest: public Poco::Net::HTTPServerRequest
{
public:
ApacheServerRequest(
ApacheRequestRec* pApacheRequest,
const char* serverName,
int serverPort,
const char* clientName,
int clientPort);
/// Creates a new ApacheServerRequest.
~ApacheServerRequest();
/// Destroys the ApacheServerRequest.
std::istream& stream();
/// Returns the input stream for reading
/// the request body.
///
/// The stream is valid until the HTTPServerRequest
/// object is destroyed.
bool expectContinue() const;
/// Returns true if the client expects a
/// 100 Continue response.
const Poco::Net::SocketAddress& clientAddress() const;
/// Returns the client's address.
const Poco::Net::SocketAddress& serverAddress() const;
/// Returns the server's address.
const Poco::Net::HTTPServerParams& serverParams() const;
/// Returns a reference to the server parameters.
Poco::Net::HTTPServerResponse& response() const;
/// Returns a reference to the associated response
protected:
void setResponse(ApacheServerResponse* pResponse);
private:
ApacheRequestRec* _pApacheRequest;
ApacheServerResponse* _pResponse;
ApacheInputStream* _pStream;
Poco::Net::SocketAddress _serverAddress;
Poco::Net::SocketAddress _clientAddress;
friend class ApacheServerResponse;
};
//
// inlines
//
inline std::istream& ApacheServerRequest::stream()
{
poco_check_ptr (_pStream);
return *_pStream;
}
inline const Poco::Net::SocketAddress& ApacheServerRequest::clientAddress() const
{
return _clientAddress;
}
inline const Poco::Net::SocketAddress& ApacheServerRequest::serverAddress() const
{
return _serverAddress;
}
#endif // ApacheConnector_ApacheServerRequest_INCLUDED
//
// ApacheServerRequest.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheServerRequest.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheServerRequest_INCLUDED
#define ApacheConnector_ApacheServerRequest_INCLUDED
#include "ApacheConnector.h"
#include "ApacheStream.h"
#include "Poco/Net/HTTPServerRequest.h"
#include <set>
class ApacheServerResponse;
class ApacheServerRequest: public Poco::Net::HTTPServerRequest
{
public:
ApacheServerRequest(
ApacheRequestRec* pApacheRequest,
const char* serverName,
int serverPort,
const char* clientName,
int clientPort);
/// Creates a new ApacheServerRequest.
~ApacheServerRequest();
/// Destroys the ApacheServerRequest.
std::istream& stream();
/// Returns the input stream for reading
/// the request body.
///
/// The stream is valid until the HTTPServerRequest
/// object is destroyed.
bool expectContinue() const;
/// Returns true if the client expects a
/// 100 Continue response.
const Poco::Net::SocketAddress& clientAddress() const;
/// Returns the client's address.
const Poco::Net::SocketAddress& serverAddress() const;
/// Returns the server's address.
const Poco::Net::HTTPServerParams& serverParams() const;
/// Returns a reference to the server parameters.
Poco::Net::HTTPServerResponse& response() const;
/// Returns a reference to the associated response
protected:
void setResponse(ApacheServerResponse* pResponse);
private:
ApacheRequestRec* _pApacheRequest;
ApacheServerResponse* _pResponse;
ApacheInputStream* _pStream;
Poco::Net::SocketAddress _serverAddress;
Poco::Net::SocketAddress _clientAddress;
friend class ApacheServerResponse;
};
//
// inlines
//
inline std::istream& ApacheServerRequest::stream()
{
poco_check_ptr (_pStream);
return *_pStream;
}
inline const Poco::Net::SocketAddress& ApacheServerRequest::clientAddress() const
{
return _clientAddress;
}
inline const Poco::Net::SocketAddress& ApacheServerRequest::serverAddress() const
{
return _serverAddress;
}
#endif // ApacheConnector_ApacheServerRequest_INCLUDED

View File

@@ -1,124 +1,144 @@
//
// ApacheServerResponse.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheServerResponse.h#6 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheServerResponse_INCLUDED
#define ApacheConnector_ApacheServerResponse_INCLUDED
#include "ApacheConnector.h"
#include "ApacheStream.h"
#include "Poco/Net/Net.h"
#include "Poco/Net/HTTPServerResponse.h"
class ApacheServerRequest;
class ApacheServerResponse: public Poco::Net::HTTPServerResponse
/// This subclass of HTTPResponse is used for
/// representing server-side HTTP responses for apache.
///
/// A ApacheServerResponse is passed to the
/// handleRequest() method of HTTPRequestHandler.
///
/// handleRequest() must set a status code
/// and optional reason phrase, set headers
/// as necessary, and provide a message body.
{
public:
ApacheServerResponse(ApacheServerRequest* pRequest);
/// Creates the ApacheServerResponse.
~ApacheServerResponse();
/// Destroys the ApacheServerResponse.
void sendContinue();
/// Sends a 100 Continue response to the
/// client.
void sendErrorResponse(int status);
/// Sends an error response with the given
/// status back to the client.
std::ostream& send();
/// Sends the response header to the client and
/// returns an output stream for sending the
/// response body.
///
/// The returned stream is valid until the response
/// object is destroyed.
///
/// Must not be called after sendFile(), sendBuffer()
/// or redirect() has been called.
void sendFile(const std::string& path, const std::string& mediaType);
/// Sends the response header to the client, followed
/// by the content of the given file.
///
/// Must not be called after send(), sendBuffer()
/// or redirect() has been called.
///
/// Throws a FileNotFoundException if the file
/// cannot be found, or an OpenFileException if
/// the file cannot be opened.
void sendBuffer(const void* pBuffer, std::size_t length);
/// Sends the response header to the client, followed
/// by the contents of the given buffer.
///
/// The Content-Length header of the response is set
/// to length and chunked transfer encoding is disabled.
///
/// If both the HTTP message header and body (from the
/// given buffer) fit into one single network packet, the
/// complete response can be sent in one network packet.
///
/// Must not be called after send(), sendFile()
/// or redirect() has been called.
void redirect(const std::string& uri);
/// Sets the status code to 302 (Found)
/// and sets the "Location" header field
/// to the given URI, which according to
/// the HTTP specification, must be absolute.
///
/// Must not be called after send() has been called.
void requireAuthentication(const std::string& realm);
/// Sets the status code to 401 (Unauthorized)
/// and sets the "WWW-Authenticate" header field
/// according to the given realm.
bool sent() const;
/// Returns true if the response (header) has been sent.
private:
void initApacheOutputStream();
/// Initializes the ApacheOutputStram
ApacheOutputStream* _pStream;
ApacheRequestRec* _pApacheRequest;
};
//
// inlines
//
inline bool ApacheServerResponse::sent() const
{
return _pStream != 0;
}
#endif // ApacheConnector_ApacheServerResponse_INCLUDED
//
// ApacheServerResponse.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheServerResponse.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheServerResponse_INCLUDED
#define ApacheConnector_ApacheServerResponse_INCLUDED
#include "ApacheConnector.h"
#include "ApacheStream.h"
#include "Poco/Net/Net.h"
#include "Poco/Net/HTTPServerResponse.h"
class ApacheServerRequest;
class ApacheServerResponse: public Poco::Net::HTTPServerResponse
/// This subclass of HTTPResponse is used for
/// representing server-side HTTP responses for apache.
///
/// A ApacheServerResponse is passed to the
/// handleRequest() method of HTTPRequestHandler.
///
/// handleRequest() must set a status code
/// and optional reason phrase, set headers
/// as necessary, and provide a message body.
{
public:
ApacheServerResponse(ApacheServerRequest* pRequest);
/// Creates the ApacheServerResponse.
~ApacheServerResponse();
/// Destroys the ApacheServerResponse.
void sendContinue();
/// Sends a 100 Continue response to the
/// client.
void sendErrorResponse(int status);
/// Sends an error response with the given
/// status back to the client.
std::ostream& send();
/// Sends the response header to the client and
/// returns an output stream for sending the
/// response body.
///
/// The returned stream is valid until the response
/// object is destroyed.
///
/// Must not be called after sendFile(), sendBuffer()
/// or redirect() has been called.
void sendFile(const std::string& path, const std::string& mediaType);
/// Sends the response header to the client, followed
/// by the content of the given file.
///
/// Must not be called after send(), sendBuffer()
/// or redirect() has been called.
///
/// Throws a FileNotFoundException if the file
/// cannot be found, or an OpenFileException if
/// the file cannot be opened.
void sendBuffer(const void* pBuffer, std::size_t length);
/// Sends the response header to the client, followed
/// by the contents of the given buffer.
///
/// The Content-Length header of the response is set
/// to length and chunked transfer encoding is disabled.
///
/// If both the HTTP message header and body (from the
/// given buffer) fit into one single network packet, the
/// complete response can be sent in one network packet.
///
/// Must not be called after send(), sendFile()
/// or redirect() has been called.
void redirect(const std::string& uri, Poco::Net::HTTPResponse::HTTPStatus status);
/// Sets the status code, which must be one of
/// HTTP_MOVED_PERMANENTLY (301), HTTP_FOUND (302),
/// or HTTP_SEE_OTHER (303),
/// and sets the "Location" header field
/// to the given URI, which according to
/// the HTTP specification, must be absolute.
///
/// Must not be called after send() has been called.
void requireAuthentication(const std::string& realm);
/// Sets the status code to 401 (Unauthorized)
/// and sets the "WWW-Authenticate" header field
/// according to the given realm.
bool sent() const;
/// Returns true if the response (header) has been sent.
private:
void initApacheOutputStream();
/// Initializes the ApacheOutputStram
ApacheOutputStream* _pStream;
ApacheRequestRec* _pApacheRequest;
};
//
// inlines
//
inline bool ApacheServerResponse::sent() const
{
return _pStream != 0;
}
#endif // ApacheConnector_ApacheServerResponse_INCLUDED

View File

@@ -1,107 +1,125 @@
//
// ApacheStream.h
//
// $Id: //poco/Main/ApacheConnector/include/ApacheStream.h#5 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics.
// The contents of this file may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part.
//
#ifndef ApacheConnector_ApacheStream_INCLUDED
#define ApacheConnector_ApacheStream_INCLUDED
#include "ApacheConnector.h"
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
class ApacheStreamBuf: public Poco::BufferedStreamBuf
/// This is the streambuf class used for reading from and writing to a socket.
{
public:
ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates a ApacheStreamBuf with the given socket.
~ApacheStreamBuf();
/// Destroys the SocketStreamBuf.
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
ApacheRequestRec* _pApacheRequest;
bool _haveData;
};
class ApacheIOS: public virtual std::ios
/// The base class for ApacheStream, ApacheInputStream and
/// ApacheOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates the ApacheIOS with the given socket.
~ApacheIOS();
/// Destroys the ApacheIOS.
///
/// Flushes the buffer, but does not close the socket.
ApacheStreamBuf* rdbuf();
/// Returns a pointer to the internal ApacheStreamBuf.
void close();
/// Flushes the stream.
protected:
ApacheStreamBuf _buf;
};
class ApacheOutputStream: public ApacheIOS, public std::ostream
/// An output stream for writing to an Apache response.
{
public:
ApacheOutputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheOutputStream with the given socket.
~ApacheOutputStream();
/// Destroys the ApacheOutputStream.
///
/// Flushes the buffer.
};
class ApacheInputStream: public ApacheIOS, public std::istream
/// An input stream for reading from an Apache request.
///
/// Using formatted input from a ApacheInputStream
/// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads.
{
public:
ApacheInputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheInputStream with the given socket.
~ApacheInputStream();
/// Destroys the ApacheInputStream.
};
#endif // ApacheConnector_ApacheStream_INCLUDED
//
// ApacheStream.h
//
// $Id: //poco/1.4/ApacheConnector/include/ApacheStream.h#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ApacheConnector_ApacheStream_INCLUDED
#define ApacheConnector_ApacheStream_INCLUDED
#include "ApacheConnector.h"
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
class ApacheStreamBuf: public Poco::BufferedStreamBuf
/// This is the streambuf class used for reading from and writing to a socket.
{
public:
ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates a ApacheStreamBuf with the given socket.
~ApacheStreamBuf();
/// Destroys the SocketStreamBuf.
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
ApacheRequestRec* _pApacheRequest;
bool _haveData;
};
class ApacheIOS: public virtual std::ios
/// The base class for ApacheStream, ApacheInputStream and
/// ApacheOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates the ApacheIOS with the given socket.
~ApacheIOS();
/// Destroys the ApacheIOS.
///
/// Flushes the buffer, but does not close the socket.
ApacheStreamBuf* rdbuf();
/// Returns a pointer to the internal ApacheStreamBuf.
void close();
/// Flushes the stream.
protected:
ApacheStreamBuf _buf;
};
class ApacheOutputStream: public ApacheIOS, public std::ostream
/// An output stream for writing to an Apache response.
{
public:
ApacheOutputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheOutputStream with the given socket.
~ApacheOutputStream();
/// Destroys the ApacheOutputStream.
///
/// Flushes the buffer.
};
class ApacheInputStream: public ApacheIOS, public std::istream
/// An input stream for reading from an Apache request.
///
/// Using formatted input from a ApacheInputStream
/// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads.
{
public:
ApacheInputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheInputStream with the given socket.
~ApacheInputStream();
/// Destroys the ApacheInputStream.
};
#endif // ApacheConnector_ApacheStream_INCLUDED