poco/ApacheConnector/include/ApacheConnector.h
Aleksandar Fabijanic d75e68c027 new trunk (base for 1.5)
windows build only
2012-04-23 01:14:34 +00:00

109 lines
4.0 KiB
C++

//
// 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