mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 11:31:53 +01:00
Net: near complete merge to 1.4.2
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
#include "Poco/Net/IPAddress.h"
|
||||
#include "Poco/Net/HostEntry.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -56,13 +55,13 @@ class Net_API DNS
|
||||
/// This class provides an interface to the
|
||||
/// domain name service.
|
||||
///
|
||||
/// An internal DNS cache is used to speed up name lookups.
|
||||
/// An internal DNS cache is used to speed up name lookups.
|
||||
{
|
||||
public:
|
||||
static HostEntry hostByName(const std::string& hostname);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given name.
|
||||
///
|
||||
static HostEntry hostByName(const std::string& hostname);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given name.
|
||||
///
|
||||
/// Throws a HostNotFoundException if a host with the given
|
||||
/// name cannot be found.
|
||||
///
|
||||
@@ -70,24 +69,24 @@ public:
|
||||
/// found for the hostname.
|
||||
///
|
||||
/// Throws a DNSException in case of a general DNS error.
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
|
||||
static HostEntry hostByAddress(const IPAddress& address);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given IP address.
|
||||
///
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
|
||||
static HostEntry hostByAddress(const IPAddress& address);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given IP address.
|
||||
///
|
||||
/// Throws a HostNotFoundException if a host with the given
|
||||
/// name cannot be found.
|
||||
///
|
||||
/// Throws a DNSException in case of a general DNS error.
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
|
||||
static HostEntry resolve(const std::string& address);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given IP address or host name.
|
||||
///
|
||||
static HostEntry resolve(const std::string& address);
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for the host with the given IP address or host name.
|
||||
///
|
||||
/// Throws a HostNotFoundException if a host with the given
|
||||
/// name cannot be found.
|
||||
///
|
||||
@@ -99,13 +98,13 @@ public:
|
||||
/// Throws an IOException in case of any other error.
|
||||
|
||||
static IPAddress resolveOne(const std::string& address);
|
||||
/// Convenience method that calls resolve(address) and returns
|
||||
/// the first address from the HostInfo.
|
||||
/// Convenience method that calls resolve(address) and returns
|
||||
/// the first address from the HostInfo.
|
||||
|
||||
static HostEntry thisHost();
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for this host.
|
||||
///
|
||||
static HostEntry thisHost();
|
||||
/// Returns a HostEntry object containing the DNS information
|
||||
/// for this host.
|
||||
///
|
||||
/// Throws a HostNotFoundException if DNS information
|
||||
/// for this host cannot be found.
|
||||
///
|
||||
@@ -113,27 +112,28 @@ public:
|
||||
/// found for this host.
|
||||
///
|
||||
/// Throws a DNSException in case of a general DNS error.
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
///
|
||||
/// Throws an IOException in case of any other error.
|
||||
|
||||
static void flushCache();
|
||||
/// Flushes the internal DNS cache.
|
||||
|
||||
static std::string hostName();
|
||||
/// Returns the host name of this host.
|
||||
//@ deprecated
|
||||
static void flushCache();
|
||||
/// Flushes the internal DNS cache.
|
||||
///
|
||||
/// As of 1.4.2, the DNS cache is no longer used
|
||||
/// and this method does not do anything.
|
||||
|
||||
static std::string hostName();
|
||||
/// Returns the host name of this host.
|
||||
|
||||
protected:
|
||||
static int lastError();
|
||||
/// Returns the code of the last error.
|
||||
|
||||
static void error(int code, const std::string& arg);
|
||||
/// Throws an exception according to the error code.
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, HostEntry> DNSCache;
|
||||
|
||||
static DNSCache _cache;
|
||||
static Poco::FastMutex _mutex;
|
||||
static void error(int code, const std::string& arg);
|
||||
/// Throws an exception according to the error code.
|
||||
|
||||
static void aierror(int code, const std::string& arg);
|
||||
/// Throws an exception according to the getaddrinfo() error code.
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@ class Net_API DialogSocket: public StreamSocket
|
||||
///
|
||||
/// Limited support for the TELNET protocol (RFC 854) is
|
||||
/// available.
|
||||
///
|
||||
/// Warning: Do not call receiveBytes() on a DialogSocket.
|
||||
/// Due to internal buffering in DialogSocket, receiveBytes()
|
||||
/// may return an unexpected result and interfere with
|
||||
/// DialogSocket's buffering. Use receiveRawBytes() instead.
|
||||
{
|
||||
public:
|
||||
DialogSocket();
|
||||
@@ -90,6 +95,9 @@ public:
|
||||
/// attaches the SocketImpl from the other socket and
|
||||
/// increments the reference count of the SocketImpl.
|
||||
|
||||
DialogSocket& operator = (const DialogSocket& socket);
|
||||
/// Assignment operator.
|
||||
|
||||
void sendByte(unsigned char ch);
|
||||
/// Sends a single byte over the socket connection.
|
||||
|
||||
@@ -151,6 +159,16 @@ public:
|
||||
///
|
||||
/// Returns -1 (EOF_CHAR) if no more characters are available.
|
||||
|
||||
int receiveRawBytes(void* buffer, int length);
|
||||
/// Read up to length bytes from the connection and place
|
||||
/// them into buffer. If there are data bytes in the internal
|
||||
/// buffer, these bytes are returned first.
|
||||
///
|
||||
/// Use this member function instead of receiveBytes().
|
||||
///
|
||||
/// Returns the number of bytes read, which may be
|
||||
/// less than requested.
|
||||
|
||||
void synch();
|
||||
/// Sends a TELNET SYNCH signal over the connection.
|
||||
///
|
||||
|
||||
@@ -67,6 +67,13 @@ public:
|
||||
///
|
||||
/// Throws an OpenFileException if the file cannot be opened.
|
||||
|
||||
FilePartSource(const std::string& path, const std::string& filename, const std::string& mediaType);
|
||||
/// Creates the FilePartSource for the given
|
||||
/// path and MIME type. The given filename is
|
||||
/// used as part filename (see filename()) only.
|
||||
///
|
||||
/// Throws an OpenFileException if the file cannot be opened.
|
||||
|
||||
~FilePartSource();
|
||||
/// Destroys the FilePartSource.
|
||||
|
||||
|
||||
@@ -77,6 +77,10 @@ class Net_API HTTPClientSession: public HTTPSession
|
||||
///
|
||||
/// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more
|
||||
/// information about the HTTP protocol.
|
||||
///
|
||||
/// Proxies and proxy authorization (only HTTP Basic Authorization)
|
||||
/// is supported. Use setProxy() and setProxyCredentials() to
|
||||
/// set up a session through a proxy.
|
||||
{
|
||||
public:
|
||||
HTTPClientSession();
|
||||
@@ -129,6 +133,24 @@ public:
|
||||
|
||||
Poco::UInt16 getProxyPort() const;
|
||||
/// Returns the proxy port number.
|
||||
|
||||
void setProxyCredentials(const std::string& username, const std::string& password);
|
||||
/// Sets the username and password for proxy authentication.
|
||||
/// Only Basic authentication is supported.
|
||||
|
||||
void setProxyUsername(const std::string& username);
|
||||
/// Sets the username for proxy authentication.
|
||||
/// Only Basic authentication is supported.
|
||||
|
||||
const std::string& getProxyUsername() const;
|
||||
/// Returns the username for proxy authentication.
|
||||
|
||||
void setProxyPassword(const std::string& password);
|
||||
/// Sets the password for proxy authentication.
|
||||
/// Only Basic authentication is supported.
|
||||
|
||||
const std::string& getProxyPassword() const;
|
||||
/// Returns the password for proxy authentication.
|
||||
|
||||
void setKeepAliveTimeout(const Poco::Timespan& timeout);
|
||||
/// Sets the connection timeout for HTTP connections.
|
||||
@@ -147,6 +169,14 @@ public:
|
||||
/// the request body. The stream is valid until
|
||||
/// receiveResponse() is called or the session
|
||||
/// is destroyed.
|
||||
///
|
||||
/// In case a network or server failure happens
|
||||
/// while writing the request body to the returned stream,
|
||||
/// the stream state will change to bad or fail. In this
|
||||
/// case, reset() should be called if the session will
|
||||
/// be reused and persistent connections are enabled
|
||||
/// to ensure a new connection will be set up
|
||||
/// for the next request.
|
||||
|
||||
virtual std::istream& receiveResponse(HTTPResponse& response);
|
||||
/// Receives the header for the response to the previous
|
||||
@@ -156,6 +186,37 @@ public:
|
||||
/// the response body. The stream is valid until
|
||||
/// sendRequest() is called or the session is
|
||||
/// destroyed.
|
||||
///
|
||||
/// It must be ensured that the response stream
|
||||
/// is fully consumed before sending a new request
|
||||
/// and persistent connections are enabled. Otherwise,
|
||||
/// the unread part of the response body may be treated as
|
||||
/// part of the next request's response header, resulting
|
||||
/// in a Poco::Net::MessageException being thrown.
|
||||
///
|
||||
/// In case a network or server failure happens
|
||||
/// while reading the response body from the returned stream,
|
||||
/// the stream state will change to bad or fail. In this
|
||||
/// case, reset() should be called if the session will
|
||||
/// be reused and persistent connections are enabled
|
||||
/// to ensure a new connection will be set up
|
||||
/// for the next request.
|
||||
|
||||
void reset();
|
||||
/// Resets the session and closes the socket.
|
||||
///
|
||||
/// The next request will initiate a new connection,
|
||||
/// even if persistent connections are enabled.
|
||||
///
|
||||
/// This should be called whenever something went
|
||||
/// wrong when sending a request (e.g., sendRequest()
|
||||
/// or receiveResponse() throws an exception, or
|
||||
/// the request or response stream changes into
|
||||
/// fail or bad state, but not eof state).
|
||||
|
||||
virtual bool secure() const;
|
||||
/// Return true iff the session uses SSL or TLS,
|
||||
/// or false otherwise.
|
||||
|
||||
protected:
|
||||
enum
|
||||
@@ -200,14 +261,24 @@ protected:
|
||||
bool getExpectResponseBody() const;
|
||||
/// Returns _expectResponseBody.
|
||||
|
||||
bool mustReconnect() const;
|
||||
virtual bool mustReconnect() const;
|
||||
/// Checks if we can reuse a persistent connection.
|
||||
|
||||
virtual void proxyAuthenticate(HTTPRequest& request);
|
||||
/// Sets the proxy credentials (Proxy-Authorization header), if
|
||||
/// proxy username and password have been set.
|
||||
|
||||
void proxyAuthenticateImpl(HTTPRequest& request);
|
||||
/// Sets the proxy credentials (Proxy-Authorization header), if
|
||||
/// proxy username and password have been set.
|
||||
|
||||
private:
|
||||
std::string _host;
|
||||
Poco::UInt16 _port;
|
||||
std::string _proxyHost;
|
||||
Poco::UInt16 _proxyPort;
|
||||
std::string _proxyUsername;
|
||||
std::string _proxyPassword;
|
||||
Poco::Timespan _keepAliveTimeout;
|
||||
Poco::Timestamp _lastRequest;
|
||||
bool _reconnect;
|
||||
@@ -248,6 +319,18 @@ inline Poco::UInt16 HTTPClientSession::getProxyPort() const
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPClientSession::getProxyUsername() const
|
||||
{
|
||||
return _proxyUsername;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPClientSession::getProxyPassword() const
|
||||
{
|
||||
return _proxyPassword;
|
||||
}
|
||||
|
||||
|
||||
inline std::istream* HTTPClientSession::getResponseStream() const
|
||||
{
|
||||
return _pResponseStream;
|
||||
|
||||
@@ -80,6 +80,10 @@ public:
|
||||
HTTPCookie(const std::string& name, const std::string& value);
|
||||
/// Creates a cookie with the given name and value.
|
||||
/// The cookie never expires.
|
||||
///
|
||||
/// Note: If value contains whitespace or non-alphanumeric
|
||||
/// characters, the value should be escaped by calling escape()
|
||||
/// before passing it to the constructor.
|
||||
|
||||
HTTPCookie(const HTTPCookie& cookie);
|
||||
/// Creates the HTTPCookie by copying another one.
|
||||
@@ -111,6 +115,10 @@ public:
|
||||
///
|
||||
/// According to the cookie specification, the
|
||||
/// size of the value should not exceed 4 Kbytes.
|
||||
///
|
||||
/// Note: If value contains whitespace or non-alphanumeric
|
||||
/// characters, the value should be escaped by calling escape()
|
||||
/// prior to passing it to setName().
|
||||
|
||||
const std::string& getValue() const;
|
||||
/// Returns the value of the cookie.
|
||||
@@ -166,6 +174,34 @@ public:
|
||||
std::string toString() const;
|
||||
/// Returns a string representation of the cookie,
|
||||
/// suitable for use in a Set-Cookie header.
|
||||
|
||||
static std::string escape(const std::string& str);
|
||||
/// Escapes the given string by replacing all
|
||||
/// non-alphanumeric characters with escape
|
||||
/// sequences in the form %xx, where xx is the
|
||||
/// hexadecimal character code.
|
||||
///
|
||||
/// The following characters will be replaced
|
||||
/// with escape sequences:
|
||||
/// - percent sign %
|
||||
/// - less-than and greater-than < and >
|
||||
/// - curly brackets { and }
|
||||
/// - square brackets [ and ]
|
||||
/// - parenthesis ( and )
|
||||
/// - solidus /
|
||||
/// - vertical line |
|
||||
/// - reverse solidus (backslash /)
|
||||
/// - quotation mark "
|
||||
/// - apostrophe '
|
||||
/// - circumflex accent ^
|
||||
/// - grave accent `
|
||||
/// - comma and semicolon , and ;
|
||||
/// - whitespace and control characters
|
||||
|
||||
static std::string unescape(const std::string& str);
|
||||
/// Unescapes the given string by replacing all
|
||||
/// escape sequences in the form %xx with the
|
||||
/// respective characters.
|
||||
|
||||
private:
|
||||
int _version;
|
||||
|
||||
@@ -62,19 +62,19 @@ public:
|
||||
void setVersion(const std::string& version);
|
||||
/// Sets the HTTP version for this message.
|
||||
|
||||
const std::string& getVersion() const;
|
||||
/// Returns the HTTP version for this message.
|
||||
|
||||
void setContentLength(int length);
|
||||
/// Sets the Content-Length header.
|
||||
///
|
||||
/// If length is UNKNOWN_CONTENT_LENGTH, removes
|
||||
/// the Content-Length header.
|
||||
|
||||
int getContentLength() const;
|
||||
/// Returns the content length for this message,
|
||||
/// which may be UNKNOWN_CONTENT_LENGTH if
|
||||
/// no Content-Length header is present.
|
||||
const std::string& getVersion() const;
|
||||
/// Returns the HTTP version for this message.
|
||||
|
||||
void setContentLength(std::streamsize length);
|
||||
/// Sets the Content-Length header.
|
||||
///
|
||||
/// If length is UNKNOWN_CONTENT_LENGTH, removes
|
||||
/// the Content-Length header.
|
||||
|
||||
std::streamsize getContentLength() const;
|
||||
/// Returns the content length for this message,
|
||||
/// which may be UNKNOWN_CONTENT_LENGTH if
|
||||
/// no Content-Length header is present.
|
||||
|
||||
void setTransferEncoding(const std::string& transferEncoding);
|
||||
/// Sets the transfer encoding for this message.
|
||||
|
||||
@@ -91,6 +91,10 @@ public:
|
||||
|
||||
void setHost(const std::string& host, Poco::UInt16 port);
|
||||
/// Sets the value of the Host header field.
|
||||
///
|
||||
/// If the given port number is a non-standard
|
||||
/// port number (other than 80 or 443), it is
|
||||
/// included in the Host header field.
|
||||
|
||||
const std::string& getHost() const;
|
||||
/// Returns the value of the Host header field.
|
||||
|
||||
@@ -1,146 +1,155 @@
|
||||
//
|
||||
// HTTPServerRequestImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServerRequestImpl.h#4 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPServer
|
||||
// Module: HTTPServerRequestImpl
|
||||
//
|
||||
// Definition of the HTTPServerRequestImpl class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, 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 Net_HTTPServerRequestImpl_INCLUDED
|
||||
#define Net_HTTPServerRequestImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
class HTTPServerSession;
|
||||
class HTTPServerParams;
|
||||
|
||||
|
||||
class Net_API HTTPServerRequestImpl: public HTTPServerRequest
|
||||
/// This subclass of HTTPServerRequest is used for
|
||||
/// representing server-side HTTP requests.
|
||||
///
|
||||
/// A HTTPServerRequest is passed to the
|
||||
/// handleRequest() method of HTTPRequestHandler.
|
||||
{
|
||||
public:
|
||||
HTTPServerRequestImpl(HTTPServerResponse& response, HTTPServerSession& session, HTTPServerParams* pParams);
|
||||
/// Creates the HTTPServerRequestImpl, using the
|
||||
/// given HTTPServerSession.
|
||||
|
||||
~HTTPServerRequestImpl();
|
||||
/// Destroys the HTTPServerRequestImpl.
|
||||
|
||||
std::istream& stream();
|
||||
/// Returns the input stream for reading
|
||||
/// the request body.
|
||||
///
|
||||
/// The stream is valid until the HTTPServerRequestImpl
|
||||
/// object is destroyed.
|
||||
|
||||
bool expectContinue() const;
|
||||
/// Returns true if the client expects a
|
||||
/// 100 Continue response.
|
||||
|
||||
const SocketAddress& clientAddress() const;
|
||||
/// Returns the client's address.
|
||||
|
||||
const SocketAddress& serverAddress() const;
|
||||
/// Returns the server's address.
|
||||
|
||||
const HTTPServerParams& serverParams() const;
|
||||
/// Returns a reference to the server parameters.
|
||||
|
||||
HTTPServerResponse& response() const;
|
||||
/// Returns a reference to the associated response.
|
||||
|
||||
protected:
|
||||
static const std::string EXPECT;
|
||||
|
||||
private:
|
||||
HTTPServerResponse& _response;
|
||||
std::istream* _pStream;
|
||||
Poco::AutoPtr<HTTPServerParams> _pParams;
|
||||
SocketAddress _clientAddress;
|
||||
SocketAddress _serverAddress;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline std::istream& HTTPServerRequestImpl::stream()
|
||||
{
|
||||
poco_check_ptr (_pStream);
|
||||
|
||||
return *_pStream;
|
||||
}
|
||||
|
||||
|
||||
inline const SocketAddress& HTTPServerRequestImpl::clientAddress() const
|
||||
{
|
||||
return _clientAddress;
|
||||
}
|
||||
|
||||
|
||||
inline const SocketAddress& HTTPServerRequestImpl::serverAddress() const
|
||||
{
|
||||
return _serverAddress;
|
||||
}
|
||||
|
||||
|
||||
inline const HTTPServerParams& HTTPServerRequestImpl::serverParams() const
|
||||
{
|
||||
return *_pParams;
|
||||
}
|
||||
|
||||
|
||||
inline HTTPServerResponse& HTTPServerRequestImpl::response() const
|
||||
{
|
||||
return _response;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // Net_HTTPServerRequestImpl_INCLUDED
|
||||
//
|
||||
// HTTPServerRequestImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPServerRequestImpl.h#1 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPServer
|
||||
// Module: HTTPServerRequestImpl
|
||||
//
|
||||
// Definition of the HTTPServerRequestImpl class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, 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 Net_HTTPServerRequestImpl_INCLUDED
|
||||
#define Net_HTTPServerRequestImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
class HTTPServerSession;
|
||||
class HTTPServerParams;
|
||||
class StreamSocket;
|
||||
|
||||
|
||||
class Net_API HTTPServerRequestImpl: public HTTPServerRequest
|
||||
/// This subclass of HTTPServerRequest is used for
|
||||
/// representing server-side HTTP requests.
|
||||
///
|
||||
/// A HTTPServerRequest is passed to the
|
||||
/// handleRequest() method of HTTPRequestHandler.
|
||||
{
|
||||
public:
|
||||
HTTPServerRequestImpl(HTTPServerResponse& response, HTTPServerSession& session, HTTPServerParams* pParams);
|
||||
/// Creates the HTTPServerRequestImpl, using the
|
||||
/// given HTTPServerSession.
|
||||
|
||||
~HTTPServerRequestImpl();
|
||||
/// Destroys the HTTPServerRequestImpl.
|
||||
|
||||
std::istream& stream();
|
||||
/// Returns the input stream for reading
|
||||
/// the request body.
|
||||
///
|
||||
/// The stream is valid until the HTTPServerRequestImpl
|
||||
/// object is destroyed.
|
||||
|
||||
bool expectContinue() const;
|
||||
/// Returns true if the client expects a
|
||||
/// 100 Continue response.
|
||||
|
||||
const SocketAddress& clientAddress() const;
|
||||
/// Returns the client's address.
|
||||
|
||||
const SocketAddress& serverAddress() const;
|
||||
/// Returns the server's address.
|
||||
|
||||
const HTTPServerParams& serverParams() const;
|
||||
/// Returns a reference to the server parameters.
|
||||
|
||||
HTTPServerResponse& response() const;
|
||||
/// Returns a reference to the associated response.
|
||||
|
||||
StreamSocket& socket();
|
||||
/// Returns a reference to the underlying socket.
|
||||
|
||||
StreamSocket detachSocket();
|
||||
/// Returns the underlying socket after detaching
|
||||
/// it from the server session.
|
||||
|
||||
protected:
|
||||
static const std::string EXPECT;
|
||||
|
||||
private:
|
||||
HTTPServerResponse& _response;
|
||||
HTTPServerSession& _session;
|
||||
std::istream* _pStream;
|
||||
Poco::AutoPtr<HTTPServerParams> _pParams;
|
||||
SocketAddress _clientAddress;
|
||||
SocketAddress _serverAddress;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline std::istream& HTTPServerRequestImpl::stream()
|
||||
{
|
||||
poco_check_ptr (_pStream);
|
||||
|
||||
return *_pStream;
|
||||
}
|
||||
|
||||
|
||||
inline const SocketAddress& HTTPServerRequestImpl::clientAddress() const
|
||||
{
|
||||
return _clientAddress;
|
||||
}
|
||||
|
||||
|
||||
inline const SocketAddress& HTTPServerRequestImpl::serverAddress() const
|
||||
{
|
||||
return _serverAddress;
|
||||
}
|
||||
|
||||
|
||||
inline const HTTPServerParams& HTTPServerRequestImpl::serverParams() const
|
||||
{
|
||||
return *_pParams;
|
||||
}
|
||||
|
||||
|
||||
inline HTTPServerResponse& HTTPServerRequestImpl::response() const
|
||||
{
|
||||
return _response;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // Net_HTTPServerRequestImpl_INCLUDED
|
||||
|
||||
@@ -112,8 +112,10 @@ public:
|
||||
/// Must not be called after send(), sendFile()
|
||||
/// or redirect() has been called.
|
||||
|
||||
virtual void redirect(const std::string& uri) = 0;
|
||||
/// Sets the status code to 302 (Found)
|
||||
virtual void redirect(const std::string& uri, HTTPStatus status = HTTP_FOUND) = 0;
|
||||
/// 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.
|
||||
|
||||
@@ -110,8 +110,10 @@ public:
|
||||
/// 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)
|
||||
void redirect(const std::string& uri, HTTPStatus status = HTTP_FOUND);
|
||||
/// 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.
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Any.h"
|
||||
#include <ios>
|
||||
|
||||
|
||||
@@ -81,7 +82,7 @@ public:
|
||||
bool connected() const;
|
||||
/// Returns true if the underlying socket is connected.
|
||||
|
||||
void abort();
|
||||
virtual void abort();
|
||||
/// Aborts a session in progress by shutting down
|
||||
/// and closing the underlying socket.
|
||||
|
||||
@@ -92,6 +93,20 @@ public:
|
||||
///
|
||||
/// Otherwise, NULL is returned.
|
||||
|
||||
void attachSessionData(const Poco::Any& data);
|
||||
/// Allows to attach an application-specific data
|
||||
/// item to the session.
|
||||
///
|
||||
/// On the server side, this can be used to manage
|
||||
/// data that must be maintained over the entire
|
||||
/// lifetime of a persistent connection (that is,
|
||||
/// multiple requests sent over the same connection).
|
||||
|
||||
const Poco::Any& sessionData() const;
|
||||
/// Returns the data attached with attachSessionData(),
|
||||
/// or an empty Poco::Any if no user data has been
|
||||
/// attached.
|
||||
|
||||
enum
|
||||
{
|
||||
HTTP_PORT = 80
|
||||
@@ -102,7 +117,10 @@ public:
|
||||
///
|
||||
/// The socket is returned, and a new, uninitialized socket is
|
||||
/// attached to the session.
|
||||
|
||||
|
||||
StreamSocket& socket();
|
||||
/// Returns a reference to the underlying socket.
|
||||
|
||||
protected:
|
||||
HTTPSession();
|
||||
/// Creates a HTTP session using an
|
||||
@@ -150,9 +168,6 @@ protected:
|
||||
int buffered() const;
|
||||
/// Returns the number of bytes in the buffer.
|
||||
|
||||
StreamSocket& socket();
|
||||
/// Returns a reference to the underlying socket.
|
||||
|
||||
void refill();
|
||||
/// Refills the internal buffer.
|
||||
|
||||
@@ -186,6 +201,7 @@ private:
|
||||
bool _keepAlive;
|
||||
Poco::Timespan _timeout;
|
||||
Poco::Exception* _pException;
|
||||
Poco::Any _data;
|
||||
|
||||
friend class HTTPStreamBuf;
|
||||
friend class HTTPHeaderStreamBuf;
|
||||
@@ -227,6 +243,12 @@ inline int HTTPSession::buffered() const
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::Any& HTTPSession::sessionData() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSessionFactory.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/include/Poco/Net/HTTPSessionFactory.h#2 $
|
||||
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPSessionFactory.h#1 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPClient
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/SingletonHolder.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -105,6 +106,15 @@ public:
|
||||
|
||||
void setProxy(const std::string& proxyHost, Poco::UInt16 proxyPort);
|
||||
/// Sets the proxy host and port number.
|
||||
|
||||
void setProxyCredentials(const std::string& username, const std::string& password);
|
||||
/// Sets the username and password for proxy authorization (Basic auth only).
|
||||
|
||||
const std::string& proxyUsername() const;
|
||||
/// Returns the username for proxy authorization.
|
||||
|
||||
const std::string& proxyPassword() const;
|
||||
/// Returns the password for proxy authorization.
|
||||
|
||||
static HTTPSessionFactory& defaultFactory();
|
||||
/// Returns the default HTTPSessionFactory.
|
||||
@@ -127,6 +137,8 @@ private:
|
||||
Instantiators _instantiators;
|
||||
std::string _proxyHost;
|
||||
Poco::UInt16 _proxyPort;
|
||||
std::string _proxyUsername;
|
||||
std::string _proxyPassword;
|
||||
|
||||
mutable Poco::FastMutex _mutex;
|
||||
};
|
||||
@@ -147,6 +159,18 @@ inline Poco::UInt16 HTTPSessionFactory::proxyPort() const
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPSessionFactory::proxyUsername() const
|
||||
{
|
||||
return _proxyUsername;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPSessionFactory::proxyPassword() const
|
||||
{
|
||||
return _proxyPassword;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPSessionInstantiator.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/include/Poco/Net/HTTPSessionInstantiator.h#2 $
|
||||
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPSessionInstantiator.h#1 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPClient
|
||||
@@ -87,9 +87,20 @@ protected:
|
||||
Poco::UInt16 proxyPort() const;
|
||||
/// Returns the proxy port.
|
||||
|
||||
void setProxyCredentials(const std::string& username, const std::string& password);
|
||||
/// Sets the username and password for proxy authorization (Basic auth only).
|
||||
|
||||
const std::string& proxyUsername() const;
|
||||
/// Returns the username for proxy authorization.
|
||||
|
||||
const std::string& proxyPassword() const;
|
||||
/// Returns the password for proxy authorization.
|
||||
|
||||
private:
|
||||
std::string _proxyHost;
|
||||
Poco::UInt16 _proxyPort;
|
||||
std::string _proxyUsername;
|
||||
std::string _proxyPassword;
|
||||
|
||||
friend class HTTPSessionFactory;
|
||||
};
|
||||
@@ -110,6 +121,18 @@ inline Poco::UInt16 HTTPSessionInstantiator::proxyPort() const
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPSessionInstantiator::proxyUsername() const
|
||||
{
|
||||
return _proxyUsername;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPSessionInstantiator::proxyPassword() const
|
||||
{
|
||||
return _proxyPassword;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -62,6 +62,13 @@ public:
|
||||
///
|
||||
/// HTTP connections will use the given proxy.
|
||||
|
||||
HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort, const std::string& proxyUsername, const std::string& proxyPassword);
|
||||
/// Creates the HTTPStreamFactory.
|
||||
///
|
||||
/// HTTP connections will use the given proxy and
|
||||
/// will be authorized against the proxy using Basic authentication
|
||||
/// with the given proxyUsername and proxyPassword.
|
||||
|
||||
virtual ~HTTPStreamFactory();
|
||||
/// Destroys the HTTPStreamFactory.
|
||||
|
||||
@@ -96,6 +103,8 @@ private:
|
||||
|
||||
std::string _proxyHost;
|
||||
Poco::UInt16 _proxyPort;
|
||||
std::string _proxyUsername;
|
||||
std::string _proxyPassword;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/SocketDefs.h"
|
||||
#include "Poco/Net/IPAddress.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -52,60 +50,14 @@ namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
class Net_API HostEntryImpl: public Poco::RefCountedObject
|
||||
/// This class stores information about a host
|
||||
/// such as host name, alias names and a list
|
||||
/// of IP addresses.
|
||||
///
|
||||
/// This class is used internally by HostEntry and is not
|
||||
/// intended for public use.
|
||||
{
|
||||
protected:
|
||||
typedef std::vector<std::string> AliasList;
|
||||
typedef std::vector<IPAddress> AddressList;
|
||||
|
||||
HostEntryImpl();
|
||||
/// Creates an empty HostEntry.
|
||||
|
||||
HostEntryImpl(struct hostent* entry);
|
||||
/// Creates the HostEntry from the data in a hostent structure.
|
||||
|
||||
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
|
||||
HostEntryImpl(struct addrinfo* info);
|
||||
/// Creates the HostEntry from the data in a Windows addrinfo structure.
|
||||
#endif
|
||||
|
||||
~HostEntryImpl();
|
||||
/// Destroys the HostEntryImpl.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the canonical host name.
|
||||
|
||||
const AliasList& aliases() const;
|
||||
/// Returns a vector containing alias names for
|
||||
/// the host name.
|
||||
|
||||
const AddressList& addresses() const;
|
||||
/// Returns a vector containing the IPAddresses
|
||||
/// for the host.
|
||||
|
||||
private:
|
||||
std::string _name;
|
||||
AliasList _aliases;
|
||||
AddressList _addresses;
|
||||
|
||||
friend class HostEntry;
|
||||
};
|
||||
|
||||
|
||||
class Net_API HostEntry
|
||||
/// This class stores information about a host
|
||||
/// such as host name, alias names and a list
|
||||
/// of IP addresses.
|
||||
{
|
||||
public:
|
||||
typedef HostEntryImpl::AliasList AliasList;
|
||||
typedef HostEntryImpl::AddressList AddressList;
|
||||
typedef std::vector<std::string> AliasList;
|
||||
typedef std::vector<IPAddress> AddressList;
|
||||
|
||||
HostEntry();
|
||||
/// Creates an empty HostEntry.
|
||||
@@ -142,52 +94,30 @@ public:
|
||||
/// for the host.
|
||||
|
||||
private:
|
||||
Poco::AutoPtr<HostEntryImpl> _pImpl;
|
||||
std::string _name;
|
||||
AliasList _aliases;
|
||||
AddressList _addresses;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& HostEntryImpl::name() const
|
||||
inline const std::string& HostEntry::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
inline const HostEntryImpl::AliasList& HostEntryImpl::aliases() const
|
||||
inline const HostEntry::AliasList& HostEntry::aliases() const
|
||||
{
|
||||
return _aliases;
|
||||
}
|
||||
|
||||
|
||||
inline const HostEntryImpl::AddressList& HostEntryImpl::addresses() const
|
||||
{
|
||||
return _addresses;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HostEntry::name() const
|
||||
{
|
||||
return _pImpl->name();
|
||||
}
|
||||
|
||||
|
||||
inline const HostEntry::AliasList& HostEntry::aliases() const
|
||||
{
|
||||
return _pImpl->aliases();
|
||||
}
|
||||
|
||||
|
||||
inline const HostEntry::AddressList& HostEntry::addresses() const
|
||||
{
|
||||
return _pImpl->addresses();
|
||||
}
|
||||
|
||||
|
||||
inline void HostEntry::swap(HostEntry& other)
|
||||
{
|
||||
_pImpl.swap(other._pImpl);
|
||||
return _addresses;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include <vector>
|
||||
#undef min // macros collide with valarray::min() and valarray::max()
|
||||
#undef max
|
||||
#include <valarray>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -118,13 +116,12 @@ private:
|
||||
void setError(int index, const std::string& text);
|
||||
ICMPEventArgs& operator ++ ();
|
||||
ICMPEventArgs operator ++ (int);
|
||||
static int zeroVal(int n);
|
||||
|
||||
SocketAddress _address;
|
||||
int _sent;
|
||||
int _dataSize;
|
||||
int _ttl;
|
||||
std::valarray<int> _rtt;
|
||||
std::vector<int> _rtt;
|
||||
std::vector<std::string> _errors;
|
||||
|
||||
friend class ICMPClient;
|
||||
@@ -172,13 +169,13 @@ inline int ICMPEventArgs::sent() const
|
||||
|
||||
inline int ICMPEventArgs::minRTT() const
|
||||
{
|
||||
return _rtt.min();
|
||||
return *std::min_element(_rtt.begin(), _rtt.end());
|
||||
}
|
||||
|
||||
|
||||
inline int ICMPEventArgs::maxRTT() const
|
||||
{
|
||||
return _rtt.max();
|
||||
return *std::max_element(_rtt.begin(), _rtt.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ protected:
|
||||
|
||||
private:
|
||||
ICMPPacket _icmpPacket;
|
||||
int _timeout;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// Definition of the IPAddress class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// Copyright (c) 2005-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
@@ -106,11 +106,18 @@ public:
|
||||
|
||||
IPAddress(const void* addr, poco_socklen_t length);
|
||||
/// Creates an IPAddress from a native internet address.
|
||||
/// A pointer to a in_addr or a in6_addr structure may be
|
||||
/// passed.
|
||||
/// A pointer to a in_addr or a in6_addr structure may be
|
||||
/// passed.
|
||||
|
||||
~IPAddress();
|
||||
/// Destroys the IPAddress.
|
||||
IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope);
|
||||
/// Creates an IPAddress from a native internet address.
|
||||
/// A pointer to a in_addr or a in6_addr structure may be
|
||||
/// passed. Additionally, for an IPv6 address, a scope ID
|
||||
/// may be specified. The scope ID will be ignored if an IPv4
|
||||
/// address is specified.
|
||||
|
||||
~IPAddress();
|
||||
/// Destroys the IPAddress.
|
||||
|
||||
IPAddress& operator = (const IPAddress& addr);
|
||||
/// Assigns an IPAddress.
|
||||
@@ -118,12 +125,17 @@ public:
|
||||
void swap(IPAddress& address);
|
||||
/// Swaps the IPAddress with another one.
|
||||
|
||||
Family family() const;
|
||||
/// Returns the address family (IPv4 or IPv6) of the address.
|
||||
|
||||
std::string toString() const;
|
||||
/// Returns a string containing a representation of the address
|
||||
/// in presentation format.
|
||||
Family family() const;
|
||||
/// Returns the address family (IPv4 or IPv6) of the address.
|
||||
|
||||
Poco::UInt32 scope() const;
|
||||
/// Returns the IPv6 scope identifier of the address. Returns 0 if
|
||||
/// the address is an IPv4 address, or the address is an
|
||||
/// IPv6 address but does not have a scope identifier.
|
||||
|
||||
std::string toString() const;
|
||||
/// Returns a string containing a representation of the address
|
||||
/// in presentation format.
|
||||
///
|
||||
/// For IPv4 addresses the result will be in dotted-decimal
|
||||
/// (d.d.d.d) notation.
|
||||
@@ -145,12 +157,18 @@ public:
|
||||
///
|
||||
/// For dealing with IPv4 compatible addresses in a mixed environment,
|
||||
/// a special syntax is available: x:x:x:x:x:x:d.d.d.d, where the 'x's are the
|
||||
/// hexadecimal values of the six high-order 16-bit pieces of the address,
|
||||
/// hexadecimal values of the six high-order 16-bit pieces of the address,
|
||||
/// and the 'd's are the decimal values of the four low-order 8-bit pieces of the
|
||||
/// standard IPv4 representation address. Example: ::FFFF:192.168.1.120
|
||||
|
||||
bool isWildcard() const;
|
||||
/// Returns true iff the address is a wildcard (all zero)
|
||||
///
|
||||
/// If an IPv6 address contains a non-zero scope identifier, it is added
|
||||
/// to the string, delimited by a percent character. On Windows platforms,
|
||||
/// the numeric value (which specifies an interface index) is directly
|
||||
/// appended. On Unix platforms, the name of the interface corresponding
|
||||
/// to the index (interpretation of the scope identifier) is added.
|
||||
|
||||
bool isWildcard() const;
|
||||
/// Returns true iff the address is a wildcard (all zero)
|
||||
/// address.
|
||||
|
||||
bool isBroadcast() const;
|
||||
@@ -322,6 +340,12 @@ public:
|
||||
///
|
||||
/// Returns false and leaves result unchanged otherwise.
|
||||
|
||||
static IPAddress wildcard(Family family = IPv4);
|
||||
/// Returns a wildcard IPv4 or IPv6 address (0.0.0.0).
|
||||
|
||||
static IPAddress broadcast();
|
||||
/// Returns a broadcast IPv4 address (255.255.255.255).
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_ADDRESS_LENGTH =
|
||||
@@ -344,9 +368,9 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void swap(IPAddress& a1, IPAddress& a2)
|
||||
inline void swap(IPAddress& addr1, IPAddress& addr2)
|
||||
{
|
||||
a1.swap(a2);
|
||||
addr1.swap(addr2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -100,6 +100,11 @@ public:
|
||||
|
||||
void setSubject(const std::string& subject);
|
||||
/// Sets the subject of the message.
|
||||
///
|
||||
/// The subject must not contain any non-ASCII
|
||||
/// characters. To include non-ASCII characters
|
||||
/// in the subject, use RFC 2047 word encoding
|
||||
/// (see encodeWord()).
|
||||
|
||||
const std::string& getSubject() const;
|
||||
/// Returns the subject of the message.
|
||||
@@ -111,7 +116,12 @@ public:
|
||||
/// The sender must either be a valid email
|
||||
/// address, or a real name followed by
|
||||
/// an email address enclosed in < and >.
|
||||
|
||||
///
|
||||
/// The sender must not contain any non-ASCII
|
||||
/// characters. To include non-ASCII characters
|
||||
/// in the sender, use RFC 2047 word encoding
|
||||
/// (see encodeWord()).
|
||||
|
||||
const std::string& getSender() const;
|
||||
/// Returns the sender of the message (taken
|
||||
/// from the From header field).
|
||||
@@ -159,14 +169,29 @@ public:
|
||||
///
|
||||
/// The MailMessage will be converted to a multipart message
|
||||
/// if it is not already one.
|
||||
///
|
||||
/// The part name, and the filename specified in the part source
|
||||
/// must not contain any non-ASCII characters.
|
||||
/// To include non-ASCII characters in the part name or filename,
|
||||
/// use RFC 2047 word encoding (see encodeWord()).
|
||||
|
||||
void addContent(PartSource* pSource, ContentTransferEncoding encoding = ENCODING_QUOTED_PRINTABLE);
|
||||
/// Adds a part to the mail message by calling
|
||||
/// addPart("", pSource, CONTENT_INLINE, encoding);
|
||||
///
|
||||
/// The part name, and the filename specified in the part source
|
||||
/// must not contain any non-ASCII characters.
|
||||
/// To include non-ASCII characters in the part name or filename,
|
||||
/// use RFC 2047 word encoding (see encodeWord()).
|
||||
|
||||
void addAttachment(const std::string& name, PartSource* pSource, ContentTransferEncoding encoding = ENCODING_BASE64);
|
||||
/// Adds an attachment to the mail message by calling
|
||||
/// addPart(name, pSource, CONTENT_ATTACHMENT, encoding);
|
||||
///
|
||||
/// The part name, and the filename specified in the part source
|
||||
/// must not contain any non-ASCII characters.
|
||||
/// To include non-ASCII characters in the part name or filename,
|
||||
/// use RFC 2047 word encoding (see encodeWord()).
|
||||
|
||||
void read(std::istream& istr, PartHandler& handler);
|
||||
/// Reads the MailMessage from the given input stream.
|
||||
@@ -184,6 +209,16 @@ public:
|
||||
|
||||
void write(std::ostream& ostr) const;
|
||||
/// Writes the mail message to the given output stream.
|
||||
|
||||
static std::string encodeWord(const std::string& text, const std::string& charset = "UTF-8");
|
||||
/// If the given string contains non-ASCII characters,
|
||||
/// encodes the given string using RFC 2047 "Q" word encoding.
|
||||
///
|
||||
/// The given text must already be encoded in the character set
|
||||
/// given in charset (default is UTF-8).
|
||||
///
|
||||
/// Returns the encoded string, or the original string if it
|
||||
/// consists only of ASCII characters.
|
||||
|
||||
protected:
|
||||
struct Part
|
||||
|
||||
@@ -125,6 +125,27 @@ public:
|
||||
/// Returns true iff the type matches the given type.
|
||||
/// Matching is case insensitive.
|
||||
|
||||
bool matchesRange(const MediaType& mediaType) const;
|
||||
/// Returns true if the type and subtype match
|
||||
/// the type and subtype of the given media type.
|
||||
/// If the MIME type is a range of types it matches
|
||||
/// any media type withing the range (e.g. "image/*" matches
|
||||
/// any image media type, "*/*" matches anything).
|
||||
/// Matching is case insensitive.
|
||||
|
||||
bool matchesRange(const std::string& type, const std::string& subType) const;
|
||||
/// Returns true if the type and subtype match
|
||||
/// the given type and subtype.
|
||||
/// If the MIME type is a range of types it matches
|
||||
/// any media type withing the range (e.g. "image/*" matches
|
||||
/// any image media type, "*/*" matches anything).
|
||||
/// Matching is case insensitive.
|
||||
|
||||
bool matchesRange(const std::string& type) const;
|
||||
/// Returns true if the type matches the given type or
|
||||
/// the type is a range of types denoted by "*".
|
||||
/// Matching is case insensitive.
|
||||
|
||||
protected:
|
||||
void parse(const std::string& mediaType);
|
||||
|
||||
|
||||
@@ -136,13 +136,13 @@ public:
|
||||
///
|
||||
/// Enclosing quotes of parameter values are removed.
|
||||
|
||||
static void quote(const std::string& value, std::string& result, bool allowSpace = false);
|
||||
/// Checks if the value must be quoted. If so, the value is
|
||||
/// appended to result, enclosed in double-quotes.
|
||||
/// Otherwise. the value is appended to result as-is.
|
||||
|
||||
static void quote(const std::string& value, std::string& result, bool allowSpace = false);
|
||||
/// Checks if the value must be quoted. If so, the value is
|
||||
/// appended to result, enclosed in double-quotes.
|
||||
/// Otherwise, the value is appended to result as-is.
|
||||
|
||||
private:
|
||||
enum Limits
|
||||
enum Limits
|
||||
/// Limits for basic sanity checks when reading a header
|
||||
{
|
||||
MAX_NAME_LENGTH = 256,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//
|
||||
// Library: Net
|
||||
// Package: NetCore
|
||||
// Module: IPAddress
|
||||
// Module: Net
|
||||
//
|
||||
// Basic definitions for the Poco Net library.
|
||||
// This file must be the first file included by every other Net
|
||||
@@ -72,19 +72,7 @@
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Net_EXPORTS)
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoNetd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoNet.lib")
|
||||
#endif
|
||||
#else
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoNetmtd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoNetmt.lib")
|
||||
#endif
|
||||
#endif
|
||||
#pragma comment(lib, "PocoNet" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -93,12 +81,13 @@ namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
void initializeNetwork();
|
||||
void Net_API initializeNetwork();
|
||||
/// Initialize the network subsystem.
|
||||
/// Calls WSAStartup() on Windows, does nothing
|
||||
/// on other platforms.
|
||||
|
||||
void uninitializeNetwork();
|
||||
|
||||
|
||||
void Net_API uninitializeNetwork();
|
||||
/// Uninitialize the network subsystem.
|
||||
/// Calls WSACleanup() on Windows, does nothing
|
||||
/// on other platforms.
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace Net {
|
||||
|
||||
POCO_DECLARE_EXCEPTION(Net_API, NetException, Poco::IOException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, InvalidAddressException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, InvalidSocketException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, ServiceNotFoundException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, ConnectionAbortedException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, ConnectionResetException, NetException)
|
||||
|
||||
@@ -56,12 +56,22 @@ class NetworkInterfaceImpl;
|
||||
class Net_API NetworkInterface
|
||||
/// This class represents a network interface.
|
||||
///
|
||||
/// NetworkInterface is used with MulticastSocket to specify
|
||||
/// multicast interfaces for sending and receiving multicast
|
||||
/// messages.
|
||||
/// NetworkInterface is used with MulticastSocket to specify
|
||||
/// multicast interfaces for sending and receiving multicast
|
||||
/// messages.
|
||||
///
|
||||
/// The class also provides static member functions for
|
||||
/// enumerating or searching network interfaces.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<NetworkInterface> NetworkInterfaceList;
|
||||
typedef std::vector<NetworkInterface> NetworkInterfaceList;
|
||||
|
||||
enum IPVersion
|
||||
{
|
||||
IPv4_ONLY, /// Return interfaces with IPv4 address only
|
||||
IPv6_ONLY, /// Return interfaces with IPv6 address only
|
||||
IPv4_OR_IPv6 /// Return interfaces with IPv4 or IPv6 address
|
||||
};
|
||||
|
||||
NetworkInterface();
|
||||
/// Creates a NetworkInterface representing the
|
||||
@@ -121,12 +131,19 @@ public:
|
||||
/// If requireIPv6 is false, an IPv4 interface is returned.
|
||||
/// Otherwise, an IPv6 interface is returned.
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the give name does not exist.
|
||||
|
||||
static NetworkInterface forAddress(const IPAddress& address);
|
||||
/// Returns the NetworkInterface for the given IP address.
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the give name does not exist.
|
||||
|
||||
static NetworkInterface forName(const std::string& name, IPVersion ipVersion);
|
||||
/// Returns the NetworkInterface for the given name.
|
||||
///
|
||||
/// The ipVersion argument can be used to specify whether
|
||||
/// an IPv4 (IPv4_ONLY) or IPv6 (IPv6_ONLY) interface is required,
|
||||
/// or whether the caller does not care (IPv4_OR_IPv6).
|
||||
|
||||
static NetworkInterface forAddress(const IPAddress& address);
|
||||
/// Returns the NetworkInterface for the given IP address.
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the give address does not exist.
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
@@ -67,6 +68,14 @@ public:
|
||||
|
||||
const std::string& mediaType() const;
|
||||
/// Returns the MIME media type for this part or attachment.
|
||||
|
||||
MessageHeader& headers();
|
||||
/// Returns a MessageHeader containing additional header
|
||||
/// fields for the part.
|
||||
|
||||
const MessageHeader& headers() const;
|
||||
/// Returns a MessageHeader containing additional header
|
||||
/// fields for the part.
|
||||
|
||||
virtual ~PartSource();
|
||||
/// Destroys the PartSource.
|
||||
@@ -85,6 +94,7 @@ private:
|
||||
PartSource& operator = (const PartSource&);
|
||||
|
||||
std::string _mediaType;
|
||||
MessageHeader _headers;
|
||||
};
|
||||
|
||||
|
||||
@@ -97,6 +107,18 @@ inline const std::string& PartSource::mediaType() const
|
||||
}
|
||||
|
||||
|
||||
inline MessageHeader& PartSource::headers()
|
||||
{
|
||||
return _headers;
|
||||
}
|
||||
|
||||
|
||||
inline const MessageHeader& PartSource::headers() const
|
||||
{
|
||||
return _headers;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ namespace Net {
|
||||
class Net_API QuotedPrintableDecoderBuf: public Poco::UnbufferedStreamBuf
|
||||
/// This streambuf decodes all quoted-printable (see RFC 2045)
|
||||
/// encoded data read from the istream connected to it.
|
||||
///
|
||||
/// Note: For performance reasons, the characters
|
||||
/// are read directly from the given istream's
|
||||
/// underlying streambuf, so the state
|
||||
/// of the istream will not reflect that of
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
QuotedPrintableDecoderBuf(std::istream& istr);
|
||||
@@ -60,7 +66,7 @@ public:
|
||||
private:
|
||||
int readFromDevice();
|
||||
|
||||
std::istream& _istr;
|
||||
std::streambuf& _buf;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,6 +89,12 @@ protected:
|
||||
class Net_API QuotedPrintableDecoder: public QuotedPrintableDecoderIOS, public std::istream
|
||||
/// This istream decodes all quoted-printable (see RFC 2045)
|
||||
/// encoded data read from the istream connected to it.
|
||||
///
|
||||
/// Note: For performance reasons, the characters
|
||||
/// are read directly from the given istream's
|
||||
/// underlying streambuf, so the state
|
||||
/// of the istream will not reflect that of
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
QuotedPrintableDecoder(std::istream& istr);
|
||||
|
||||
@@ -42,7 +42,9 @@
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Channel.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Net/DatagramSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -51,11 +53,10 @@ namespace Net {
|
||||
|
||||
class Net_API RemoteSyslogChannel: public Poco::Channel
|
||||
/// This Channel implements remote syslog logging over UDP according
|
||||
/// to the syslog Working Group Internet Draft:
|
||||
/// "The syslog Protocol" <http://www.ietf.org/internet-drafts/draft-ietf-syslog-protocol-17.txt>,
|
||||
/// and "Transmission of syslog messages over UDP" <http://www.ietf.org/internet-drafts/draft-ietf-syslog-transport-udp-07.txt>.
|
||||
/// to RFC 5424 "The Syslog Protocol"
|
||||
/// and RFC 5426 "Transmission of syslog messages over UDP".
|
||||
///
|
||||
/// In addition, RemoteSyslogChannel also supports the "old" BSD syslog
|
||||
/// In addition, RemoteSyslogListener also supports the "old" BSD syslog
|
||||
/// protocol, as described in RFC 3164.
|
||||
{
|
||||
public:
|
||||
@@ -130,7 +131,7 @@ public:
|
||||
/// * name: The name used to identify the source of log messages.
|
||||
/// * facility: The facility added to each log message. See the Facility enumeration for a list of supported values.
|
||||
/// The LOG_ prefix can be omitted and values are case insensitive (e.g. a facility value "mail" is recognized as SYSLOG_MAIL)
|
||||
/// * format: "bsd" (RFC 3164 format) or "new" (default)
|
||||
/// * format: "bsd"/"rfc3164" (RFC 3164 format) or "new"/"rfc5424" (default)
|
||||
/// * loghost: The target IP address or host name where log messages are sent. Optionally, a port number (separated
|
||||
/// by a colon) can also be specified.
|
||||
/// * host: (optional) Host name included in syslog messages. If not specified, the host's real domain name or
|
||||
@@ -159,7 +160,9 @@ private:
|
||||
int _facility;
|
||||
bool _bsdFormat;
|
||||
DatagramSocket _socket;
|
||||
SocketAddress _socketAddress;
|
||||
bool _open;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// Definition of the RemoteSyslogListener class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// Copyright (c) 2007-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
@@ -41,7 +41,8 @@
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/ThreadPool.h"
|
||||
#include "Poco/SplitterChannel.h"
|
||||
#include "Poco/NotificationQueue.h"
|
||||
|
||||
@@ -56,9 +57,8 @@ class SyslogParser;
|
||||
|
||||
class Net_API RemoteSyslogListener: public Poco::SplitterChannel
|
||||
/// RemoteSyslogListener implents listening for syslog messages
|
||||
/// sent over UDP, according to the syslog Working Group Internet Draft:
|
||||
/// "The syslog Protocol" <http://www.ietf.org/internet-drafts/draft-ietf-syslog-protocol-17.txt>,
|
||||
/// and "Transmission of syslog messages over UDP" <http://www.ietf.org/internet-drafts/draft-ietf-syslog-transport-udp-07.txt>.
|
||||
/// sent over UDP, according to RFC 5424 "The Syslog Protocol"
|
||||
/// and RFC 5426 "Transmission of syslog messages over UDP".
|
||||
///
|
||||
/// In addition, RemoteSyslogListener also supports the "old" BSD syslog
|
||||
/// protocol, as described in RFC 3164.
|
||||
@@ -66,19 +66,34 @@ class Net_API RemoteSyslogListener: public Poco::SplitterChannel
|
||||
/// The RemoteSyslogListener is a subclass of Poco::SplitterChannel.
|
||||
/// Every received log message is sent to the channels registered
|
||||
/// with addChannel() or the "channel" property.
|
||||
///
|
||||
/// Poco::Message objects created by RemoteSyslogListener will have
|
||||
/// the following named parameters:
|
||||
/// - addr: IP address of the host/interface sending the message.
|
||||
/// - host: host name; only for "new" syslog messages.
|
||||
/// - app: application name; only for "new" syslog messages.
|
||||
{
|
||||
public:
|
||||
RemoteSyslogListener();
|
||||
/// Creates the RemoteSyslogListener.
|
||||
|
||||
RemoteSyslogListener(Poco::UInt16 port);
|
||||
/// Creates the RemoteSyslogListener.
|
||||
/// Creates the RemoteSyslogListener, listening on the given port number.
|
||||
|
||||
RemoteSyslogListener(Poco::UInt16 port, int threads);
|
||||
/// Creates the RemoteSyslogListener, listening on the given port number
|
||||
/// and using the number of threads for message processing.
|
||||
|
||||
void setProperty(const std::string& name, const std::string& value);
|
||||
/// Sets the property with the given value.
|
||||
///
|
||||
/// The following properties are supported:
|
||||
/// * port: The UDP port number where to listen for UDP.
|
||||
/// * port: The UDP port number where to listen for UDP packets
|
||||
/// containing syslog messages. If 0 is specified, does not
|
||||
/// listen for UDP messages.
|
||||
/// * threads: The number of parser threads processing
|
||||
/// received syslog messages. Defaults to 1. A maximum
|
||||
/// of 16 threads is supported.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
@@ -88,11 +103,20 @@ public:
|
||||
|
||||
void close();
|
||||
/// Stops the listener.
|
||||
|
||||
void processMessage(const std::string& messageText);
|
||||
/// Parses a single line of text containing a syslog message
|
||||
/// and sends it down the filter chain.
|
||||
|
||||
void enqueueMessage(const std::string& messageText, const Poco::Net::SocketAddress& senderAddress);
|
||||
/// Enqueues a single line of text containing a syslog message
|
||||
/// for asynchronous processing by a parser thread.
|
||||
|
||||
static void registerChannel();
|
||||
/// Registers the channel with the global LoggingFactory.
|
||||
|
||||
static const std::string PROP_PORT;
|
||||
static const std::string PROP_THREADS;
|
||||
|
||||
protected:
|
||||
~RemoteSyslogListener();
|
||||
@@ -101,10 +125,10 @@ protected:
|
||||
private:
|
||||
RemoteUDPListener* _pListener;
|
||||
SyslogParser* _pParser;
|
||||
Poco::Thread _listener;
|
||||
Poco::Thread _parser;
|
||||
Poco::ThreadPool _threadPool;
|
||||
Poco::NotificationQueue _queue;
|
||||
Poco::UInt16 _port;
|
||||
int _threads;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/DigestEngine.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
@@ -67,7 +68,9 @@ public:
|
||||
{
|
||||
AUTH_NONE,
|
||||
AUTH_CRAM_MD5,
|
||||
AUTH_LOGIN
|
||||
AUTH_CRAM_SHA1,
|
||||
AUTH_LOGIN,
|
||||
AUTH_PLAIN
|
||||
};
|
||||
|
||||
explicit SMTPClientSession(const StreamSocket& socket);
|
||||
@@ -101,6 +104,10 @@ public:
|
||||
void login();
|
||||
/// Calls login(hostname) with the current host name.
|
||||
|
||||
void login(const std::string& hostname, LoginMethod loginMethod, const std::string& username, const std::string& password);
|
||||
/// Logs in to the SMTP server using the given authentication method and the given
|
||||
/// credentials.
|
||||
|
||||
void login(LoginMethod loginMethod, const std::string& username, const std::string& password);
|
||||
/// Logs in to the SMTP server using the given authentication method and the given
|
||||
/// credentials.
|
||||
@@ -161,9 +168,12 @@ protected:
|
||||
static bool isPermanentNegative(int status);
|
||||
|
||||
void login(const std::string& hostname, std::string& response);
|
||||
void loginUsingCRAM_MD5(const std::string& username, const std::string& password);
|
||||
void loginUsingCRAMMD5(const std::string& username, const std::string& password);
|
||||
void loginUsingCRAMSHA1(const std::string& username, const std::string& password);
|
||||
void loginUsingCRAM(const std::string& username, const std::string& method, Poco::DigestEngine& hmac);
|
||||
void loginUsingLogin(const std::string& username, const std::string& password);
|
||||
void loginUsingPlain(const std::string& username, const std::string& password);
|
||||
DialogSocket& socket();
|
||||
|
||||
private:
|
||||
DialogSocket _socket;
|
||||
@@ -198,6 +208,12 @@ inline bool SMTPClientSession::isPermanentNegative(int status)
|
||||
}
|
||||
|
||||
|
||||
inline DialogSocket& SMTPClientSession::socket()
|
||||
{
|
||||
return _socket;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -108,12 +108,45 @@ public:
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Bind a local IPv6 address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void bind6(Poco::UInt16 port, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Bind a local IPv6 port to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
/// The socket becomes a passive socket that
|
||||
/// can accept incoming connection requests.
|
||||
///
|
||||
|
||||
@@ -133,13 +133,19 @@ public:
|
||||
/// If the total number of sockets passed in readList, writeList and
|
||||
/// exceptList is zero, select() will return immediately and the
|
||||
/// return value will be 0.
|
||||
///
|
||||
/// If one of the sockets passed to select() is closed while
|
||||
/// select() runs, select will return immediately. However,
|
||||
/// the closed socket will not be included in any list.
|
||||
/// In this case, the return value may be greater than the sum
|
||||
/// of all sockets in all list.
|
||||
|
||||
bool poll(const Poco::Timespan& timeout, int mode) const;
|
||||
/// Determines the status of the socket, using a
|
||||
/// call to poll() or select().
|
||||
///
|
||||
/// The mode argument is constructed by combining the values
|
||||
/// of the SelectMode enumeration.
|
||||
bool poll(const Poco::Timespan& timeout, int mode) const;
|
||||
/// Determines the status of the socket, using a
|
||||
/// call to poll() or select().
|
||||
///
|
||||
/// The mode argument is constructed by combining the values
|
||||
/// of the SelectMode enumeration.
|
||||
///
|
||||
/// Returns true if the next operation corresponding to
|
||||
/// mode will not block, false otherwise.
|
||||
@@ -287,12 +293,16 @@ public:
|
||||
SocketAddress peerAddress() const;
|
||||
/// Returns the IP address and port number of the peer socket.
|
||||
|
||||
SocketImpl* impl() const;
|
||||
/// Returns the SocketImpl for this socket.
|
||||
|
||||
static bool supportsIPv4();
|
||||
/// Returns true if the system supports IPv4.
|
||||
|
||||
SocketImpl* impl() const;
|
||||
/// Returns the SocketImpl for this socket.
|
||||
|
||||
bool secure() const;
|
||||
/// Returns true iff the socket's connection is secure
|
||||
/// (using SSL or TLS).
|
||||
|
||||
static bool supportsIPv4();
|
||||
/// Returns true if the system supports IPv4.
|
||||
|
||||
static bool supportsIPv6();
|
||||
/// Returns true if the system supports IPv6.
|
||||
|
||||
@@ -302,27 +312,27 @@ protected:
|
||||
/// The socket takes owership of the SocketImpl.
|
||||
|
||||
poco_socket_t sockfd() const;
|
||||
/// Returns the socket descriptor for this socket.
|
||||
/// Returns the socket descriptor for this socket.
|
||||
|
||||
private:
|
||||
|
||||
#if defined(POCO_HAVE_FD_POLL)
|
||||
class FDCompare
|
||||
/// Utility functor used to compare socket file descriptors.
|
||||
/// Used in poll() member function.
|
||||
{
|
||||
public:
|
||||
FDCompare(int fd): _fd(fd) { }
|
||||
inline bool operator()(const Socket& socket) const
|
||||
{ return socket.sockfd() == _fd; }
|
||||
class FDCompare
|
||||
/// Utility functor used to compare socket file descriptors.
|
||||
/// Used in poll() member function.
|
||||
{
|
||||
public:
|
||||
FDCompare(int fd): _fd(fd) { }
|
||||
inline bool operator()(const Socket& socket) const
|
||||
{ return socket.sockfd() == _fd; }
|
||||
|
||||
private:
|
||||
FDCompare();
|
||||
int _fd;
|
||||
};
|
||||
private:
|
||||
FDCompare();
|
||||
int _fd;
|
||||
};
|
||||
#endif
|
||||
|
||||
SocketImpl* _pImpl;
|
||||
SocketImpl* _pImpl;
|
||||
};
|
||||
|
||||
|
||||
@@ -601,16 +611,16 @@ inline SocketAddress Socket::peerAddress() const
|
||||
|
||||
inline bool Socket::supportsIPv4()
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline bool Socket::supportsIPv6()
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
return true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -126,12 +126,15 @@ public:
|
||||
std::string toString() const;
|
||||
/// Returns a string representation of the address.
|
||||
|
||||
IPAddress::Family family() const;
|
||||
/// Returns the address family of the host's address.
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_ADDRESS_LENGTH =
|
||||
IPAddress::Family family() const;
|
||||
/// Returns the address family of the host's address.
|
||||
|
||||
bool operator == (const SocketAddress& addr) const;
|
||||
bool operator != (const SocketAddress& addr) const;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_ADDRESS_LENGTH =
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
sizeof(struct sockaddr_in6)
|
||||
#else
|
||||
@@ -165,6 +168,18 @@ inline IPAddress::Family SocketAddress::family() const
|
||||
}
|
||||
|
||||
|
||||
inline bool SocketAddress::operator == (const SocketAddress& addr) const
|
||||
{
|
||||
return host() == addr.host() && port() == addr.port();
|
||||
}
|
||||
|
||||
|
||||
inline bool SocketAddress::operator != (const SocketAddress& addr) const
|
||||
{
|
||||
return host() != addr.host() || port() != addr.port();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#define POCO_INVALID_SOCKET INVALID_SOCKET
|
||||
#define poco_socket_t SOCKET
|
||||
#define poco_socklen_t int
|
||||
#define poco_ioctl_request_t int
|
||||
#define poco_closesocket(s) closesocket(s)
|
||||
#define POCO_EINTR WSAEINTR
|
||||
#define POCO_EACCES WSAEACCES
|
||||
@@ -88,6 +89,60 @@
|
||||
#define POCO_TRY_AGAIN WSATRY_AGAIN
|
||||
#define POCO_NO_RECOVERY WSANO_RECOVERY
|
||||
#define POCO_NO_DATA WSANO_DATA
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include <hostLib.h>
|
||||
#include <ifLib.h>
|
||||
#include <inetLib.h>
|
||||
#include <ioLib.h>
|
||||
#include <resolvLib.h>
|
||||
#include <types.h>
|
||||
#include <socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#define POCO_INVALID_SOCKET -1
|
||||
#define poco_socket_t int
|
||||
#define poco_socklen_t int
|
||||
#define poco_ioctl_request_t int
|
||||
#define poco_closesocket(s) ::close(s)
|
||||
#define POCO_EINTR EINTR
|
||||
#define POCO_EACCES EACCES
|
||||
#define POCO_EFAULT EFAULT
|
||||
#define POCO_EINVAL EINVAL
|
||||
#define POCO_EMFILE EMFILE
|
||||
#define POCO_EAGAIN EAGAIN
|
||||
#define POCO_EWOULDBLOCK EWOULDBLOCK
|
||||
#define POCO_EINPROGRESS EINPROGRESS
|
||||
#define POCO_EALREADY EALREADY
|
||||
#define POCO_ENOTSOCK ENOTSOCK
|
||||
#define POCO_EDESTADDRREQ EDESTADDRREQ
|
||||
#define POCO_EMSGSIZE EMSGSIZE
|
||||
#define POCO_EPROTOTYPE EPROTOTYPE
|
||||
#define POCO_ENOPROTOOPT ENOPROTOOPT
|
||||
#define POCO_EPROTONOSUPPORT EPROTONOSUPPORT
|
||||
#define POCO_ESOCKTNOSUPPORT ESOCKTNOSUPPORT
|
||||
#define POCO_ENOTSUP ENOTSUP
|
||||
#define POCO_EPFNOSUPPORT EPFNOSUPPORT
|
||||
#define POCO_EAFNOSUPPORT EAFNOSUPPORT
|
||||
#define POCO_EADDRINUSE EADDRINUSE
|
||||
#define POCO_EADDRNOTAVAIL EADDRNOTAVAIL
|
||||
#define POCO_ENETDOWN ENETDOWN
|
||||
#define POCO_ENETUNREACH ENETUNREACH
|
||||
#define POCO_ENETRESET ENETRESET
|
||||
#define POCO_ECONNABORTED ECONNABORTED
|
||||
#define POCO_ECONNRESET ECONNRESET
|
||||
#define POCO_ENOBUFS ENOBUFS
|
||||
#define POCO_EISCONN EISCONN
|
||||
#define POCO_ENOTCONN ENOTCONN
|
||||
#define POCO_ESHUTDOWN ESHUTDOWN
|
||||
#define POCO_ETIMEDOUT ETIMEDOUT
|
||||
#define POCO_ECONNREFUSED ECONNREFUSED
|
||||
#define POCO_EHOSTDOWN EHOSTDOWN
|
||||
#define POCO_EHOSTUNREACH EHOSTUNREACH
|
||||
#define POCO_ESYSNOTREADY -4
|
||||
#define POCO_ENOTINIT -5
|
||||
#define POCO_HOST_NOT_FOUND HOST_NOT_FOUND
|
||||
#define POCO_TRY_AGAIN TRY_AGAIN
|
||||
#define POCO_NO_RECOVERY NO_RECOVERY
|
||||
#define POCO_NO_DATA NO_DATA
|
||||
#elif defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_VMS)
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
@@ -115,6 +170,11 @@
|
||||
#define POCO_INVALID_SOCKET -1
|
||||
#define poco_socket_t int
|
||||
#define poco_socklen_t socklen_t
|
||||
#if defined(POCO_OS_FAMILY_BSD)
|
||||
#define poco_ioctl_request_t unsigned long
|
||||
#else
|
||||
#define poco_ioctl_request_t int
|
||||
#endif
|
||||
#define poco_closesocket(s) ::close(s)
|
||||
#define POCO_EINTR EINTR
|
||||
#define POCO_EACCES EACCES
|
||||
@@ -176,7 +236,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if (POCO_OS == POCO_OS_HPUX) || (POCO_OS == POCO_OS_SOLARIS)
|
||||
#if (POCO_OS == POCO_OS_HPUX) || (POCO_OS == POCO_OS_SOLARIS) || (POCO_OS == POCO_OS_WINDOWS_CE)
|
||||
#define POCO_BROKEN_TIMEOUTS 1
|
||||
#endif
|
||||
|
||||
|
||||
@@ -103,12 +103,29 @@ public:
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Bind a local IPv6 address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
/// The socket becomes a passive socket that
|
||||
/// can accept incoming connection requests.
|
||||
///
|
||||
@@ -135,12 +152,18 @@ public:
|
||||
///
|
||||
/// Returns the number of bytes sent, which may be
|
||||
/// less than the number of bytes specified.
|
||||
///
|
||||
/// Certain socket implementations may also return a negative
|
||||
/// value denoting a certain condition.
|
||||
|
||||
virtual int receiveBytes(void* buffer, int length, int flags = 0);
|
||||
/// Receives data from the socket and stores it
|
||||
/// in buffer. Up to length bytes are received.
|
||||
///
|
||||
/// Returns the number of bytes received.
|
||||
///
|
||||
/// Certain socket implementations may also return a negative
|
||||
/// value denoting a certain condition.
|
||||
|
||||
virtual int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
|
||||
/// Sends the contents of the given buffer through
|
||||
@@ -329,23 +352,27 @@ public:
|
||||
|
||||
virtual bool getBlocking() const;
|
||||
/// Returns the blocking mode of the socket.
|
||||
/// This method will only work if the blocking modes of
|
||||
/// the socket are changed via the setBlocking method!
|
||||
/// This method will only work if the blocking modes of
|
||||
/// the socket are changed via the setBlocking method!
|
||||
|
||||
virtual bool secure() const;
|
||||
/// Returns true iff the socket's connection is secure
|
||||
/// (using SSL or TLS).
|
||||
|
||||
int socketError();
|
||||
/// Returns the value of the SO_ERROR socket option.
|
||||
|
||||
int socketError();
|
||||
/// Returns the value of the SO_ERROR socket option.
|
||||
|
||||
poco_socket_t sockfd() const;
|
||||
/// Returns the socket descriptor for the
|
||||
/// underlying native socket.
|
||||
|
||||
void ioctl(int request, int& arg);
|
||||
/// A wrapper for the ioctl system call.
|
||||
/// Returns the socket descriptor for the
|
||||
/// underlying native socket.
|
||||
|
||||
void ioctl(poco_ioctl_request_t request, int& arg);
|
||||
/// A wrapper for the ioctl system call.
|
||||
|
||||
void ioctl(int request, void* arg);
|
||||
/// A wrapper for the ioctl system call.
|
||||
|
||||
bool initialized() const;
|
||||
void ioctl(poco_ioctl_request_t request, void* arg);
|
||||
/// A wrapper for the ioctl system call.
|
||||
|
||||
bool initialized() const;
|
||||
/// Returns true iff the underlying socket is initialized.
|
||||
|
||||
protected:
|
||||
@@ -381,13 +408,13 @@ protected:
|
||||
/// or SOCK_RAW.
|
||||
///
|
||||
/// The third argument, proto, is normally set to 0,
|
||||
/// except for raw sockets.
|
||||
/// except for raw sockets.
|
||||
|
||||
void reset(poco_socket_t fd = POCO_INVALID_SOCKET);
|
||||
/// Allows subclasses to set the socket manually, iff no valid socket is set yet!
|
||||
|
||||
static int lastError();
|
||||
/// Returns the last error code.
|
||||
void reset(poco_socket_t fd = POCO_INVALID_SOCKET);
|
||||
/// Allows subclasses to set the socket manually, iff no valid socket is set yet.
|
||||
|
||||
static int lastError();
|
||||
/// Returns the last error code.
|
||||
|
||||
static void error();
|
||||
/// Throws an appropriate exception for the last error.
|
||||
|
||||
@@ -79,6 +79,9 @@ public:
|
||||
|
||||
bool hasObservers() const;
|
||||
/// Returns true if there are subscribers.
|
||||
|
||||
std::size_t countObservers() const;
|
||||
/// Returns the number of subscribers;
|
||||
|
||||
protected:
|
||||
~SocketNotifier();
|
||||
@@ -108,6 +111,12 @@ inline bool SocketNotifier::hasObservers() const
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SocketNotifier::countObservers() const
|
||||
{
|
||||
return _nc.countObservers();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -198,6 +198,13 @@ protected:
|
||||
/// dispatches the ShutdownNotification and thus should be called by overriding
|
||||
/// implementations.
|
||||
|
||||
virtual void onBusy();
|
||||
/// Called when the SocketReactor is busy and at least one notification
|
||||
/// has been dispatched.
|
||||
///
|
||||
/// Can be overridden by subclasses to perform additional
|
||||
/// periodic tasks. The default implementation does nothing.
|
||||
|
||||
void dispatch(const Socket& socket, SocketNotification* pNotification);
|
||||
/// Dispatches the given notification to all observers
|
||||
/// registered for the given socket.
|
||||
|
||||
@@ -124,6 +124,9 @@ public:
|
||||
///
|
||||
/// Returns the number of bytes sent, which may be
|
||||
/// less than the number of bytes specified.
|
||||
///
|
||||
/// Certain socket implementations may also return a negative
|
||||
/// value denoting a certain condition.
|
||||
|
||||
int receiveBytes(void* buffer, int length, int flags = 0);
|
||||
/// Receives data from the socket and stores it
|
||||
|
||||
@@ -63,7 +63,12 @@ public:
|
||||
/// Creates a StreamSocketImpl using the given native socket.
|
||||
|
||||
virtual int sendBytes(const void* buffer, int length, int flags = 0);
|
||||
/// Ensures that all data in buffer is sent.
|
||||
/// Ensures that all data in buffer is sent if the socket
|
||||
/// is blocking. In case of a non-blocking socket, sends as
|
||||
/// many bytes as possible.
|
||||
///
|
||||
/// Returns the number of bytes sent. The return value may also be
|
||||
/// negative to denote some special condition.
|
||||
|
||||
protected:
|
||||
virtual ~StreamSocketImpl();
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
/// If no TCPServerParams object is given, the server's TCPServerDispatcher
|
||||
/// creates its own one.
|
||||
///
|
||||
/// News threads are taken from the default thread pool.
|
||||
/// New threads are taken from the default thread pool.
|
||||
|
||||
TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams::Ptr pParams = 0);
|
||||
/// Creates the TCPServer, using the given ServerSocket.
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
/// If no TCPServerParams object is given, the server's TCPServerDispatcher
|
||||
/// creates its own one.
|
||||
///
|
||||
/// News threads are taken from the given thread pool.
|
||||
/// New threads are taken from the given thread pool.
|
||||
|
||||
virtual ~TCPServer();
|
||||
/// Destroys the TCPServer and its TCPServerConnectionFactory.
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
/// No new connections will be accepted.
|
||||
/// Already handled connections will continue to be served.
|
||||
///
|
||||
/// Once the server is stopped, it cannot be restarted.
|
||||
/// Once the server has been stopped, it cannot be restarted.
|
||||
|
||||
int currentThreads() const;
|
||||
/// Returns the number of currently used connection threads.
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
/// Returns the number of refused connections.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the server socket listens to
|
||||
/// Returns the port the server socket listens on.
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
Reference in New Issue
Block a user