mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-07-31 05:01:47 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
56
vendor/POCO/ApacheConnector/include/ApacheApplication.h
vendored
Normal file
56
vendor/POCO/ApacheConnector/include/ApacheApplication.h
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// ApacheApplication.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
30
vendor/POCO/ApacheConnector/include/ApacheChannel.h
vendored
Normal file
30
vendor/POCO/ApacheConnector/include/ApacheChannel.h
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// ApacheChannel.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
95
vendor/POCO/ApacheConnector/include/ApacheConnector.h
vendored
Normal file
95
vendor/POCO/ApacheConnector/include/ApacheConnector.h
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// ApacheConnector.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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.
|
||||
|
||||
bool secure();
|
||||
/// Returns true if the request is using a secure
|
||||
/// connection. Returns false if no secure connection
|
||||
/// is used, or if it is not known whether a secure
|
||||
/// connection is used.
|
||||
|
||||
void setStatus(int status);
|
||||
/// Set specific HTTP status code for the request.
|
||||
|
||||
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
|
55
vendor/POCO/ApacheConnector/include/ApacheRequestHandlerFactory.h
vendored
Normal file
55
vendor/POCO/ApacheConnector/include/ApacheRequestHandlerFactory.h
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// ApacheRequestHandlerFactory.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
104
vendor/POCO/ApacheConnector/include/ApacheServerRequest.h
vendored
Normal file
104
vendor/POCO/ApacheConnector/include/ApacheServerRequest.h
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ApacheServerRequest.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
||||
|
||||
bool secure() const;
|
||||
/// Returns true if the request is using a secure
|
||||
/// connection. Returns false if no secure connection
|
||||
/// is used, or if it is not known whether a secure
|
||||
/// connection is used.
|
||||
|
||||
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
|
122
vendor/POCO/ApacheConnector/include/ApacheServerResponse.h
vendored
Normal file
122
vendor/POCO/ApacheConnector/include/ApacheServerResponse.h
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// ApacheServerResponse.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
103
vendor/POCO/ApacheConnector/include/ApacheStream.h
vendored
Normal file
103
vendor/POCO/ApacheConnector/include/ApacheStream.h
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// ApacheStream.h
|
||||
//
|
||||
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#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
|
Reference in New Issue
Block a user