set eol-style to native

This commit is contained in:
Guenter Obiltschnig 2006-10-23 16:25:09 +00:00
parent 1ecd4a8a9e
commit 0c24077c43
338 changed files with 49884 additions and 49884 deletions

View File

@ -1,37 +1,37 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.2/Net/Makefile#1 $ # $Id: //poco/1.2/Net/Makefile#1 $
# #
# Makefile for Poco Net # Makefile for Poco Net
# #
include $(POCO_BASE)/build/rules/global include $(POCO_BASE)/build/rules/global
SHAREDOPT_CXX += -DNet_EXPORTS SHAREDOPT_CXX += -DNet_EXPORTS
objects = \ objects = \
DNS HTTPResponse HostEntry Socket \ DNS HTTPResponse HostEntry Socket \
DatagramSocket HTTPServer IPAddress SocketAddress \ DatagramSocket HTTPServer IPAddress SocketAddress \
HTTPBasicCredentials HTTPCookie HTMLForm MediaType DialogSocket \ HTTPBasicCredentials HTTPCookie HTMLForm MediaType DialogSocket \
DatagramSocketImpl FilePartSource HTTPServerConnection MessageHeader \ DatagramSocketImpl FilePartSource HTTPServerConnection MessageHeader \
HTTPChunkedStream HTTPServerConnectionFactory MulticastSocket SocketStream \ HTTPChunkedStream HTTPServerConnectionFactory MulticastSocket SocketStream \
HTTPClientSession HTTPServerParams MultipartReader StreamSocket SocketImpl \ HTTPClientSession HTTPServerParams MultipartReader StreamSocket SocketImpl \
HTTPFixedLengthStream HTTPServerRequest MultipartWriter StreamSocketImpl \ HTTPFixedLengthStream HTTPServerRequest MultipartWriter StreamSocketImpl \
HTTPHeaderStream HTTPServerResponse NameValueCollection TCPServer \ HTTPHeaderStream HTTPServerResponse NameValueCollection TCPServer \
HTTPMessage HTTPServerSession NetException TCPServerConnection HTTPBufferAllocator \ HTTPMessage HTTPServerSession NetException TCPServerConnection HTTPBufferAllocator \
HTTPRequest HTTPSession HTTPSessionInstantiator HTTPSessionFactory NetworkInterface TCPServerConnectionFactory \ HTTPRequest HTTPSession HTTPSessionInstantiator HTTPSessionFactory NetworkInterface TCPServerConnectionFactory \
HTTPRequestHandler HTTPStream HTTPIOStream ServerSocket TCPServerDispatcher \ HTTPRequestHandler HTTPStream HTTPIOStream ServerSocket TCPServerDispatcher \
HTTPRequestHandlerFactory HTTPStreamFactory ServerSocketImpl TCPServerParams \ HTTPRequestHandlerFactory HTTPStreamFactory ServerSocketImpl TCPServerParams \
QuotedPrintableEncoder QuotedPrintableDecoder StringPartSource \ QuotedPrintableEncoder QuotedPrintableDecoder StringPartSource \
FTPClientSession FTPStreamFactory PartHandler PartSource NullPartHandler \ FTPClientSession FTPStreamFactory PartHandler PartSource NullPartHandler \
SocketReactor SocketNotifier SocketNotification \ SocketReactor SocketNotifier SocketNotification \
MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \ MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \
RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \ RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \
ICMPSocket ICMPSocketImpl ICMPv4PacketImpl ICMPSocket ICMPSocketImpl ICMPv4PacketImpl
target = PocoNet target = PocoNet
target_version = $(LIBVERSION) target_version = $(LIBVERSION)
target_libs = PocoFoundation target_libs = PocoFoundation
include $(POCO_BASE)/build/rules/lib include $(POCO_BASE)/build/rules/lib

View File

@ -1,7 +1,7 @@
# #
# Net.vmsbuild # Net.vmsbuild
# #
# $Id: //poco/1.2/Net/Net.vmsbuild#1 $ # $Id: //poco/1.2/Net/Net.vmsbuild#1 $
# #
LIB=PocoNet LIB=PocoNet
<SourceFilesHere> <SourceFilesHere>

View File

@ -1,30 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 8.00 Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Net", "Net_vs71.vcproj", "{B057A1FE-09F7-465E-B8B5-E1B659051D76}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Net", "Net_vs71.vcproj", "{B057A1FE-09F7-465E-B8B5-E1B659051D76}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs71.vcproj", "{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs71.vcproj", "{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{B057A1FE-09F7-465E-B8B5-E1B659051D76} = {B057A1FE-09F7-465E-B8B5-E1B659051D76} {B057A1FE-09F7-465E-B8B5-E1B659051D76} = {B057A1FE-09F7-465E-B8B5-E1B659051D76}
EndProjectSection EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfiguration) = preSolution GlobalSection(SolutionConfiguration) = preSolution
debug_shared = debug_shared debug_shared = debug_shared
release_shared = release_shared release_shared = release_shared
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution GlobalSection(ProjectConfiguration) = postSolution
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared.ActiveCfg = debug_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared.ActiveCfg = debug_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared.Build.0 = debug_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared.Build.0 = debug_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared.ActiveCfg = release_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared.ActiveCfg = release_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared.Build.0 = release_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared.Build.0 = release_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared.ActiveCfg = debug_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared.ActiveCfg = debug_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared.Build.0 = debug_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared.Build.0 = debug_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared.ActiveCfg = release_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared.ActiveCfg = release_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared.Build.0 = release_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared.Build.0 = release_shared|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 9.00 Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005 # Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Net", "Net_vs80.vcproj", "{B057A1FE-09F7-465E-B8B5-E1B659051D76}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Net", "Net_vs80.vcproj", "{B057A1FE-09F7-465E-B8B5-E1B659051D76}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs80.vcproj", "{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs80.vcproj", "{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{B057A1FE-09F7-465E-B8B5-E1B659051D76} = {B057A1FE-09F7-465E-B8B5-E1B659051D76} {B057A1FE-09F7-465E-B8B5-E1B659051D76} = {B057A1FE-09F7-465E-B8B5-E1B659051D76}
EndProjectSection EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32 debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32 release_shared|Win32 = release_shared|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared|Win32.Build.0 = debug_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.debug_shared|Win32.Build.0 = debug_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared|Win32.ActiveCfg = release_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared|Win32.ActiveCfg = release_shared|Win32
{B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared|Win32.Build.0 = release_shared|Win32 {B057A1FE-09F7-465E-B8B5-E1B659051D76}.release_shared|Win32.Build.0 = release_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared|Win32.Build.0 = debug_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.debug_shared|Win32.Build.0 = debug_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared|Win32.ActiveCfg = release_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared|Win32.ActiveCfg = release_shared|Win32
{D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared|Win32.Build.0 = release_shared|Win32 {D5EFBF27-B934-4B8D-8AE5-6EC00374819C}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

File diff suppressed because it is too large Load Diff

View File

@ -1,140 +1,140 @@
// //
// DNS.h // DNS.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/DNS.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/DNS.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: DNS // Module: DNS
// //
// Definition of the DNS class. // Definition of the DNS class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_DNS_INCLUDED #ifndef Net_DNS_INCLUDED
#define Net_DNS_INCLUDED #define Net_DNS_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h" #include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
#include "Poco/Net/HostEntry.h" #include "Poco/Net/HostEntry.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include <map> #include <map>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API DNS class Net_API DNS
/// This class provides an interface to the /// This class provides an interface to the
/// domain name service. /// 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: public:
static const HostEntry& hostByName(const std::string& hostname); static const HostEntry& hostByName(const std::string& hostname);
/// Returns a HostEntry object containing the DNS information /// Returns a HostEntry object containing the DNS information
/// for the host with the given name. /// for the host with the given name.
/// ///
/// Throws a HostNotFoundException if a host with the given /// Throws a HostNotFoundException if a host with the given
/// name cannot be found. /// name cannot be found.
/// ///
/// Throws a NoAddressFoundException if no address can be /// Throws a NoAddressFoundException if no address can be
/// found for the hostname. /// found for the hostname.
/// ///
/// Throws a DNSException in case of a general DNS error. /// 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 const HostEntry& hostByAddress(const IPAddress& address); static const HostEntry& hostByAddress(const IPAddress& address);
/// Returns a HostEntry object containing the DNS information /// Returns a HostEntry object containing the DNS information
/// for the host with the given IP address. /// for the host with the given IP address.
/// ///
/// Throws a HostNotFoundException if a host with the given /// Throws a HostNotFoundException if a host with the given
/// name cannot be found. /// name cannot be found.
/// ///
/// Throws a DNSException in case of a general DNS error. /// 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 const HostEntry& resolve(const std::string& address); static const HostEntry& resolve(const std::string& address);
/// Returns a HostEntry object containing the DNS information /// Returns a HostEntry object containing the DNS information
/// for the host with the given IP address or host name. /// for the host with the given IP address or host name.
/// ///
/// Throws a HostNotFoundException if a host with the given /// Throws a HostNotFoundException if a host with the given
/// name cannot be found. /// name cannot be found.
/// ///
/// Throws a NoAddressFoundException if no address can be /// Throws a NoAddressFoundException if no address can be
/// found for the hostname. /// found for the hostname.
/// ///
/// Throws a DNSException in case of a general DNS error. /// 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 IPAddress resolveOne(const std::string& address); static IPAddress resolveOne(const std::string& address);
/// Convenience method that calls resolve(address) and returns /// Convenience method that calls resolve(address) and returns
/// the first address from the HostInfo. /// the first address from the HostInfo.
static const HostEntry& thisHost(); static const HostEntry& thisHost();
/// Returns a HostEntry object containing the DNS information /// Returns a HostEntry object containing the DNS information
/// for this host. /// for this host.
/// ///
/// Throws a HostNotFoundException if DNS information /// Throws a HostNotFoundException if DNS information
/// for this host cannot be found. /// for this host cannot be found.
/// ///
/// Throws a NoAddressFoundException if no address can be /// Throws a NoAddressFoundException if no address can be
/// found for this host. /// found for this host.
/// ///
/// Throws a DNSException in case of a general DNS error. /// 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(); static void flushCache();
/// Flushes the internal DNS cache. /// Flushes the internal DNS cache.
protected: protected:
static int lastError(); static int lastError();
/// Returns the code of the last error. /// Returns the code of the last error.
static void error(int code, const std::string& arg); static void error(int code, const std::string& arg);
/// Throws an exception according to the error code. /// Throws an exception according to the error code.
private: private:
typedef std::map<std::string, HostEntry> DNSCache; typedef std::map<std::string, HostEntry> DNSCache;
static DNSCache _cache; static DNSCache _cache;
static Poco::FastMutex _mutex; static Poco::FastMutex _mutex;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_DNS_INCLUDED #endif // Net_DNS_INCLUDED

View File

@ -1,169 +1,169 @@
// //
// DatagramSocket.h // DatagramSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/DatagramSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/DatagramSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: DatagramSocket // Module: DatagramSocket
// //
// Definition of the DatagramSocket class. // Definition of the DatagramSocket class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_DatagramSocket_INCLUDED #ifndef Net_DatagramSocket_INCLUDED
#define Net_DatagramSocket_INCLUDED #define Net_DatagramSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API DatagramSocket: public Socket class Net_API DatagramSocket: public Socket
/// This class provides an interface to an /// This class provides an interface to an
/// UDP stream socket. /// UDP stream socket.
{ {
public: public:
DatagramSocket(); DatagramSocket();
/// Creates an unconnected IPv4 datagram socket. /// Creates an unconnected IPv4 datagram socket.
DatagramSocket(IPAddress::Family family); DatagramSocket(IPAddress::Family family);
/// Creates an unconnected datagram socket. /// Creates an unconnected datagram socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
DatagramSocket(const SocketAddress& address, bool reuseAddress = false); DatagramSocket(const SocketAddress& address, bool reuseAddress = false);
/// Creates a datagram socket and binds it /// Creates a datagram socket and binds it
/// to the given address. /// to the given address.
/// ///
/// Depending on the address family, the socket /// Depending on the address family, the socket
/// will be either an IPv4 or an IPv6 socket. /// will be either an IPv4 or an IPv6 socket.
DatagramSocket(const Socket& socket); DatagramSocket(const Socket& socket);
/// Creates the DatagramSocket with the SocketImpl /// Creates the DatagramSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a DatagramSocketImpl, otherwise an InvalidArgumentException /// a DatagramSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
~DatagramSocket(); ~DatagramSocket();
/// Destroys the DatagramSocket. /// Destroys the DatagramSocket.
DatagramSocket& operator = (const Socket& socket); DatagramSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
void connect(const SocketAddress& address); void connect(const SocketAddress& address);
/// Restricts incoming and outgoing /// Restricts incoming and outgoing
/// packets to the specified address. /// packets to the specified address.
/// ///
/// Cannot be used together with bind(). /// Cannot be used together with bind().
void bind(const SocketAddress& address, bool reuseAddress = false); void bind(const SocketAddress& address, bool reuseAddress = false);
/// Bind a local address to the socket. /// Bind a local address to the socket.
/// ///
/// This is usually only done when establishing a server /// This is usually only done when establishing a server
/// socket. /// socket.
/// ///
/// If reuseAddress is true, sets the SO_REUSEADDR /// If reuseAddress is true, sets the SO_REUSEADDR
/// socket option. /// socket option.
/// ///
/// Cannot be used together with connect(). /// Cannot be used together with connect().
int sendBytes(const void* buffer, int length, int flags = 0); int sendBytes(const void* buffer, int length, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket. /// the socket.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
int receiveBytes(void* buffer, int length, int flags = 0); int receiveBytes(void* buffer, int length, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0); int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket to the given address. /// the socket to the given address.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0); int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// Stores the address of the sender in address. /// Stores the address of the sender in address.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
void setBroadcast(bool flag); void setBroadcast(bool flag);
/// Sets the value of the SO_BROADCAST socket option. /// Sets the value of the SO_BROADCAST socket option.
/// ///
/// Setting this flag allows sending datagrams to /// Setting this flag allows sending datagrams to
/// the broadcast address. /// the broadcast address.
bool getBroadcast() const; bool getBroadcast() const;
/// Returns the value of the SO_BROADCAST socket option. /// Returns the value of the SO_BROADCAST socket option.
protected: protected:
DatagramSocket(SocketImpl* pImpl); DatagramSocket(SocketImpl* pImpl);
/// Creates the Socket and attaches the given SocketImpl. /// Creates the Socket and attaches the given SocketImpl.
/// The socket takes owership of the SocketImpl. /// The socket takes owership of the SocketImpl.
/// ///
/// The SocketImpl must be a StreamSocketImpl, otherwise /// The SocketImpl must be a StreamSocketImpl, otherwise
/// an InvalidArgumentException will be thrown. /// an InvalidArgumentException will be thrown.
}; };
// //
// inlines // inlines
// //
inline void DatagramSocket::setBroadcast(bool flag) inline void DatagramSocket::setBroadcast(bool flag)
{ {
impl()->setBroadcast(flag); impl()->setBroadcast(flag);
} }
inline bool DatagramSocket::getBroadcast() const inline bool DatagramSocket::getBroadcast() const
{ {
return impl()->getBroadcast(); return impl()->getBroadcast();
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_DatagramSocket_INCLUDED #endif // Net_DatagramSocket_INCLUDED

View File

@ -1,81 +1,81 @@
// //
// DatagramSocketImpl.h // DatagramSocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/DatagramSocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/DatagramSocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: DatagramSocketImpl // Module: DatagramSocketImpl
// //
// Definition of the DatagramSocketImpl class. // Definition of the DatagramSocketImpl class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_DatagramSocketImpl_INCLUDED #ifndef Net_DatagramSocketImpl_INCLUDED
#define Net_DatagramSocketImpl_INCLUDED #define Net_DatagramSocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketImpl.h" #include "Poco/Net/SocketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API DatagramSocketImpl: public SocketImpl class Net_API DatagramSocketImpl: public SocketImpl
/// This class implements an UDP socket. /// This class implements an UDP socket.
{ {
public: public:
DatagramSocketImpl(); DatagramSocketImpl();
/// Creates a StreamSocketImpl. /// Creates a StreamSocketImpl.
/// ///
/// If the system supports IPv6, the socket will /// If the system supports IPv6, the socket will
/// be an IPv6 socket. Otherwise, it will be /// be an IPv6 socket. Otherwise, it will be
/// an IPv4 socket. /// an IPv4 socket.
DatagramSocketImpl(IPAddress::Family family); DatagramSocketImpl(IPAddress::Family family);
/// Creates an unconnected datagram socket. /// Creates an unconnected datagram socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
DatagramSocketImpl(poco_socket_t sockfd); DatagramSocketImpl(poco_socket_t sockfd);
/// Creates a StreamSocketImpl using the given native socket. /// Creates a StreamSocketImpl using the given native socket.
protected: protected:
void init(int af); void init(int af);
~DatagramSocketImpl(); ~DatagramSocketImpl();
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_DatagramSocketImpl_INCLUDED #endif // Net_DatagramSocketImpl_INCLUDED

View File

@ -1,210 +1,210 @@
// //
// DialogSocket.h // DialogSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/DialogSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/DialogSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: DialogSocket // Module: DialogSocket
// //
// Definition of the DialogSocket class. // Definition of the DialogSocket class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_DialogSocket_INCLUDED #ifndef Net_DialogSocket_INCLUDED
#define Net_DialogSocket_INCLUDED #define Net_DialogSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API DialogSocket: public StreamSocket class Net_API DialogSocket: public StreamSocket
/// DialogSocket is a subclass of StreamSocket that /// DialogSocket is a subclass of StreamSocket that
/// can be used for implementing request-response /// can be used for implementing request-response
/// based client server connections. /// based client server connections.
/// ///
/// A request is always a single-line command terminated /// A request is always a single-line command terminated
/// by CR-LF. /// by CR-LF.
/// ///
/// A response can either be a single line of text terminated /// A response can either be a single line of text terminated
/// by CR-LF, or multiple lines of text in the format used /// by CR-LF, or multiple lines of text in the format used
/// by the FTP and SMTP protocols. /// by the FTP and SMTP protocols.
/// ///
/// Limited support for the TELNET protocol (RFC 854) is /// Limited support for the TELNET protocol (RFC 854) is
/// available. /// available.
{ {
public: public:
DialogSocket(); DialogSocket();
/// Creates an unconnected stream socket. /// Creates an unconnected stream socket.
/// ///
/// Before sending or receiving data, the socket /// Before sending or receiving data, the socket
/// must be connected with a call to connect(). /// must be connected with a call to connect().
DialogSocket(const SocketAddress& address); DialogSocket(const SocketAddress& address);
/// Creates a stream socket and connects it to /// Creates a stream socket and connects it to
/// the socket specified by address. /// the socket specified by address.
DialogSocket(const Socket& socket); DialogSocket(const Socket& socket);
/// Creates the DialogSocket with the SocketImpl /// Creates the DialogSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a StreamSocketImpl, otherwise an InvalidArgumentException /// a StreamSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
~DialogSocket(); ~DialogSocket();
/// Destroys the DialogSocket. /// Destroys the DialogSocket.
DialogSocket& operator = (const Socket& socket); DialogSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
void sendByte(unsigned char ch); void sendByte(unsigned char ch);
/// Sends a single byte over the socket connection. /// Sends a single byte over the socket connection.
void sendString(const char* str); void sendString(const char* str);
/// Sends the given null-terminated string over /// Sends the given null-terminated string over
/// the socket connection. /// the socket connection.
void sendString(const std::string& str); void sendString(const std::string& str);
/// Sends the given string over the socket connection. /// Sends the given string over the socket connection.
void sendMessage(const std::string& message); void sendMessage(const std::string& message);
/// Appends a CR-LF sequence to the message and sends it /// Appends a CR-LF sequence to the message and sends it
/// over the socket connection. /// over the socket connection.
void sendMessage(const std::string& message, const std::string& arg); void sendMessage(const std::string& message, const std::string& arg);
/// Concatenates message and arg, separated by a space, appends a /// Concatenates message and arg, separated by a space, appends a
/// CR-LF sequence, and sends the result over the socket connection. /// CR-LF sequence, and sends the result over the socket connection.
void sendMessage(const std::string& message, const std::string& arg1, const std::string& arg2); void sendMessage(const std::string& message, const std::string& arg1, const std::string& arg2);
/// Concatenates message and args, separated by a space, appends a /// Concatenates message and args, separated by a space, appends a
/// CR-LF sequence, and sends the result over the socket connection. /// CR-LF sequence, and sends the result over the socket connection.
bool receiveMessage(std::string& message); bool receiveMessage(std::string& message);
/// Receives a single-line message, terminated by CR-LF, /// Receives a single-line message, terminated by CR-LF,
/// from the socket connection and appends it to response. /// from the socket connection and appends it to response.
/// ///
/// Returns true if a message has been read or false if /// Returns true if a message has been read or false if
/// the connection has been closed by the peer. /// the connection has been closed by the peer.
int receiveStatusMessage(std::string& message); int receiveStatusMessage(std::string& message);
/// Receives a single-line or multi-line response from /// Receives a single-line or multi-line response from
/// the socket connection. The format must be according to /// the socket connection. The format must be according to
/// one of the response formats specified in the FTP (RFC 959) /// one of the response formats specified in the FTP (RFC 959)
/// or SMTP (RFC 2821) specifications. /// or SMTP (RFC 2821) specifications.
/// ///
/// The first line starts with a 3-digit status code. /// The first line starts with a 3-digit status code.
/// Following the status code is either a space character (' ' ) /// Following the status code is either a space character (' ' )
/// (in case of a single-line response) or a minus character ('-') /// (in case of a single-line response) or a minus character ('-')
/// in case of a multi-line response. The following lines can have /// in case of a multi-line response. The following lines can have
/// a three-digit status code followed by a minus-sign and some /// a three-digit status code followed by a minus-sign and some
/// text, or some arbitrary text only. The last line again begins /// text, or some arbitrary text only. The last line again begins
/// with a three-digit status code (which must be the same as the /// with a three-digit status code (which must be the same as the
/// one in the first line), followed by a space and some arbitrary /// one in the first line), followed by a space and some arbitrary
/// text. All lines must be terminated by a CR-LF sequence. /// text. All lines must be terminated by a CR-LF sequence.
/// ///
/// The response contains all response lines, separated by a newline /// The response contains all response lines, separated by a newline
/// character, including the status code. The status code is returned. /// character, including the status code. The status code is returned.
/// If the response line does not contain a status code, 0 is returned. /// If the response line does not contain a status code, 0 is returned.
int get(); int get();
/// Reads one character from the connection. /// Reads one character from the connection.
/// ///
/// Returns -1 (EOF_CHAR) if no more characters are available. /// Returns -1 (EOF_CHAR) if no more characters are available.
int peek(); int peek();
/// Returns the character that would be returned by the next call /// Returns the character that would be returned by the next call
/// to get(), without actually extracting the character from the /// to get(), without actually extracting the character from the
/// buffer. /// buffer.
/// ///
/// Returns -1 (EOF_CHAR) if no more characters are available. /// Returns -1 (EOF_CHAR) if no more characters are available.
void synch(); void synch();
/// Sends a TELNET SYNCH signal over the connection. /// Sends a TELNET SYNCH signal over the connection.
/// ///
/// According to RFC 854, a TELNET_DM char is sent /// According to RFC 854, a TELNET_DM char is sent
/// via sendUrgent(). /// via sendUrgent().
void sendTelnetCommand(unsigned char command); void sendTelnetCommand(unsigned char command);
/// Sends a TELNET command sequence (TELNET_IAC followed /// Sends a TELNET command sequence (TELNET_IAC followed
/// by the given command) over the connection. /// by the given command) over the connection.
void sendTelnetCommand(unsigned char command, unsigned char arg); void sendTelnetCommand(unsigned char command, unsigned char arg);
/// Sends a TELNET command sequence (TELNET_IAC followed /// Sends a TELNET command sequence (TELNET_IAC followed
/// by the given command, followed by arg) over the connection. /// by the given command, followed by arg) over the connection.
enum TelnetCodes enum TelnetCodes
{ {
TELNET_SE = 240, TELNET_SE = 240,
TELNET_NOP = 241, TELNET_NOP = 241,
TELNET_DM = 242, TELNET_DM = 242,
TELNET_BRK = 243, TELNET_BRK = 243,
TELNET_IP = 244, TELNET_IP = 244,
TELNET_AO = 245, TELNET_AO = 245,
TELNET_AYT = 246, TELNET_AYT = 246,
TELNET_EC = 247, TELNET_EC = 247,
TELNET_EL = 248, TELNET_EL = 248,
TELNET_GA = 249, TELNET_GA = 249,
TELNET_SB = 250, TELNET_SB = 250,
TELNET_WILL = 251, TELNET_WILL = 251,
TELNET_WONT = 252, TELNET_WONT = 252,
TELNET_DO = 253, TELNET_DO = 253,
TELNET_DONT = 254, TELNET_DONT = 254,
TELNET_IAC = 255 TELNET_IAC = 255
}; };
protected: protected:
void allocBuffer(); void allocBuffer();
void refill(); void refill();
bool receiveLine(std::string& line); bool receiveLine(std::string& line);
int receiveStatusLine(std::string& line); int receiveStatusLine(std::string& line);
private: private:
enum enum
{ {
RECEIVE_BUFFER_SIZE = 1024, RECEIVE_BUFFER_SIZE = 1024,
EOF_CHAR = -1 EOF_CHAR = -1
}; };
char* _pBuffer; char* _pBuffer;
char* _pNext; char* _pNext;
char* _pEnd; char* _pEnd;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_DialogSocket_INCLUDED #endif // Net_DialogSocket_INCLUDED

View File

@ -1,382 +1,382 @@
// //
// FTPClientSession.h // FTPClientSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/FTPClientSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/FTPClientSession.h#1 $
// //
// Library: Net // Library: Net
// Package: FTP // Package: FTP
// Module: FTPClientSession // Module: FTPClientSession
// //
// Definition of the FTPClientSession class. // Definition of the FTPClientSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_FTPClientSession_INCLUDED #ifndef Net_FTPClientSession_INCLUDED
#define Net_FTPClientSession_INCLUDED #define Net_FTPClientSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/DialogSocket.h" #include "Poco/Net/DialogSocket.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class SocketStream; class SocketStream;
class Net_API FTPClientSession class Net_API FTPClientSession
/// This class implements an File Transfer Protocol /// This class implements an File Transfer Protocol
/// (FTP, RFC 959) client. /// (FTP, RFC 959) client.
/// ///
/// Most of the features of the FTP protocol, as specified /// Most of the features of the FTP protocol, as specified
/// in RFC 959, are supported. Not supported are EBCDIC and /// in RFC 959, are supported. Not supported are EBCDIC and
/// LOCAL data types and format control and structured files. /// LOCAL data types and format control and structured files.
/// ///
/// Also supported are the EPRT and EPSV commands from /// Also supported are the EPRT and EPSV commands from
/// RFC 1738 (FTP Extensions for IPv6 and NAT). /// RFC 1738 (FTP Extensions for IPv6 and NAT).
/// The client will first attempt to use the EPRT and EPSV /// The client will first attempt to use the EPRT and EPSV
/// commands. If the server does not supports these commands, /// commands. If the server does not supports these commands,
/// the client will fall back to PORT and PASV. /// the client will fall back to PORT and PASV.
{ {
public: public:
enum enum
{ {
FTP_PORT = 21 FTP_PORT = 21
}; };
enum FileType enum FileType
{ {
TYPE_TEXT, // TYPE A (ASCII) TYPE_TEXT, // TYPE A (ASCII)
TYPE_BINARY // TYPE I (Image) TYPE_BINARY // TYPE I (Image)
}; };
explicit FTPClientSession(const StreamSocket& socket); explicit FTPClientSession(const StreamSocket& socket);
/// Creates an FTPClientSession using the given /// Creates an FTPClientSession using the given
/// connected socket for the control connection. /// connected socket for the control connection.
/// ///
/// Passive mode will be used for data transfers. /// Passive mode will be used for data transfers.
FTPClientSession(const std::string& host, Poco::UInt16 port = FTP_PORT); FTPClientSession(const std::string& host, Poco::UInt16 port = FTP_PORT);
/// Creates an FTPClientSession using a socket connected /// Creates an FTPClientSession using a socket connected
/// to the given host and port. /// to the given host and port.
/// ///
/// Passive mode will be used for data transfers. /// Passive mode will be used for data transfers.
virtual ~FTPClientSession(); virtual ~FTPClientSession();
/// Destroys the FTPClientSession. /// Destroys the FTPClientSession.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the timeout for socket operations. /// Sets the timeout for socket operations.
Poco::Timespan getTimeout() const; Poco::Timespan getTimeout() const;
/// Returns the timeout for socket operations. /// Returns the timeout for socket operations.
void setPassive(bool flag); void setPassive(bool flag);
/// Enables (default) or disables FTP passive mode for this session. /// Enables (default) or disables FTP passive mode for this session.
bool getPassive() const; bool getPassive() const;
/// Returns true iff passive mode is enabled for this connection. /// Returns true iff passive mode is enabled for this connection.
void login(const std::string& username, const std::string& password); void login(const std::string& username, const std::string& password);
/// Authenticates the user against the FTP server. Must be /// Authenticates the user against the FTP server. Must be
/// called before any other commands (except QUIT) can be sent. /// called before any other commands (except QUIT) can be sent.
/// ///
/// Sends a USER command followed by a PASS command with the /// Sends a USER command followed by a PASS command with the
/// respective arguments to the server. /// respective arguments to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void close(); void close();
/// Sends a QUIT command and closes the connection to the server. /// Sends a QUIT command and closes the connection to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
std::string systemType(); std::string systemType();
/// Returns the system type of the FTP server. /// Returns the system type of the FTP server.
/// ///
/// Sends a SYST command to the server and returns the result. /// Sends a SYST command to the server and returns the result.
void setFileType(FileType type); void setFileType(FileType type);
/// Sets the file type for transferring files. /// Sets the file type for transferring files.
/// ///
/// Sends a TYPE command with a corresponsing argument to the /// Sends a TYPE command with a corresponsing argument to the
/// server. /// server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
FileType getFileType() const; FileType getFileType() const;
/// Returns the file type for transferring files. /// Returns the file type for transferring files.
void setWorkingDirectory(const std::string& path); void setWorkingDirectory(const std::string& path);
/// Changes the current working directory on the server. /// Changes the current working directory on the server.
/// ///
/// Sends a CWD command with the given path as argument to the /// Sends a CWD command with the given path as argument to the
/// server. /// server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
std::string getWorkingDirectory(); std::string getWorkingDirectory();
/// Returns the current working directory on the server. /// Returns the current working directory on the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void cdup(); void cdup();
/// Moves one directory up from the current working directory /// Moves one directory up from the current working directory
/// on teh server. /// on teh server.
/// ///
/// Sends a CDUP command to the server. /// Sends a CDUP command to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void rename(const std::string& oldName, const std::string& newName); void rename(const std::string& oldName, const std::string& newName);
/// Renames the file on the server given by oldName to newName. /// Renames the file on the server given by oldName to newName.
/// ///
/// Sends a RNFR command, followed by a RNTO command to the server. /// Sends a RNFR command, followed by a RNTO command to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void remove(const std::string& path); void remove(const std::string& path);
/// Deletes the file specified by path on the server. /// Deletes the file specified by path on the server.
/// ///
/// Sends a DELE command with path as argument to the server. /// Sends a DELE command with path as argument to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void createDirectory(const std::string& path); void createDirectory(const std::string& path);
/// Creates a new directory with the given path on the server. /// Creates a new directory with the given path on the server.
/// ///
/// Sends a MKD command with path as argument to the server. /// Sends a MKD command with path as argument to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void removeDirectory(const std::string& path); void removeDirectory(const std::string& path);
/// Removes the directory specified by path from the server. /// Removes the directory specified by path from the server.
/// ///
/// Sends a RMD command with path as argument to the server. /// Sends a RMD command with path as argument to the server.
/// ///
/// Throws a FTPException in case of a FTP-specific error, or a /// Throws a FTPException in case of a FTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
std::istream& beginDownload(const std::string& path); std::istream& beginDownload(const std::string& path);
/// Starts downloading the file with the given name. /// Starts downloading the file with the given name.
/// After all data has been read from the returned stream, /// After all data has been read from the returned stream,
/// endDownload() must be called to finish the download. /// endDownload() must be called to finish the download.
/// ///
/// A stream for reading the file's content is returned. /// A stream for reading the file's content is returned.
/// The stream is valid until endDownload() is called. /// The stream is valid until endDownload() is called.
/// ///
/// Creates a data connection between the client and the /// Creates a data connection between the client and the
/// server. If passive mode is on, then the server waits for /// server. If passive mode is on, then the server waits for
/// a connection request from the client. Otherwise, the /// a connection request from the client. Otherwise, the
/// client waits for a connection request from the server. /// client waits for a connection request from the server.
/// After establishing the data connection, a SocketStream /// After establishing the data connection, a SocketStream
/// for transferring the data is created. /// for transferring the data is created.
/// ///
/// If ASCII transfer mode is selected, the caller is /// If ASCII transfer mode is selected, the caller is
/// responsible for converting the received data to /// responsible for converting the received data to
/// the native text file format. /// the native text file format.
/// The InputLineEndingConverter class from the Foundation /// The InputLineEndingConverter class from the Foundation
/// library can be used for that purpose. /// library can be used for that purpose.
void endDownload(); void endDownload();
/// Must be called to complete a download initiated with /// Must be called to complete a download initiated with
/// beginDownload(). /// beginDownload().
std::ostream& beginUpload(const std::string& path); std::ostream& beginUpload(const std::string& path);
/// Starts uploading the file with the given name. /// Starts uploading the file with the given name.
/// After all data has been written to the returned stream, /// After all data has been written to the returned stream,
/// endUpload() must be called to finish the download. /// endUpload() must be called to finish the download.
/// ///
/// A stream for reading the file's content is returned. /// A stream for reading the file's content is returned.
/// The stream is valid until endUpload() is called. /// The stream is valid until endUpload() is called.
/// ///
/// Creates a data connection between the client and the /// Creates a data connection between the client and the
/// server. If passive mode is on, then the server waits for /// server. If passive mode is on, then the server waits for
/// a connection request from the client. Otherwise, the /// a connection request from the client. Otherwise, the
/// client waits for a connection request from the server. /// client waits for a connection request from the server.
/// After establishing the data connection, a SocketStream /// After establishing the data connection, a SocketStream
/// for transferring the data is created. /// for transferring the data is created.
/// ///
/// If ASCII transfer mode is selected, the caller is /// If ASCII transfer mode is selected, the caller is
/// responsible for converting the data to be sent /// responsible for converting the data to be sent
/// into network (CR-LF line endings) format. /// into network (CR-LF line endings) format.
/// The OutputLineEndingConverter class from the Foundation /// The OutputLineEndingConverter class from the Foundation
/// library can be used for that purpose. /// library can be used for that purpose.
void endUpload(); void endUpload();
/// Must be called to complete an upload initiated with /// Must be called to complete an upload initiated with
/// beginUpload(). /// beginUpload().
std::istream& beginList(const std::string& path = "", bool extended = false); std::istream& beginList(const std::string& path = "", bool extended = false);
/// Starts downloading a directory listing. /// Starts downloading a directory listing.
/// After all data has been read from the returned stream, /// After all data has been read from the returned stream,
/// endList() must be called to finish the download. /// endList() must be called to finish the download.
/// ///
/// A stream for reading the directory data is returned. /// A stream for reading the directory data is returned.
/// The stream is valid until endList() is called. /// The stream is valid until endList() is called.
/// ///
/// Optionally, a path to a directory or file can be specified. /// Optionally, a path to a directory or file can be specified.
/// According to the FTP prototol, if a path to a filename is /// According to the FTP prototol, if a path to a filename is
/// given, only information for the specific file is returned. /// given, only information for the specific file is returned.
/// If a path to a directory is given, a listing of that directory /// If a path to a directory is given, a listing of that directory
/// is returned. If no path is given, a listing of the current /// is returned. If no path is given, a listing of the current
/// working directory is returned. /// working directory is returned.
/// ///
/// If extended is false, only a filenames (one per line) are /// If extended is false, only a filenames (one per line) are
/// returned. Otherwise, a full directory listing including /// returned. Otherwise, a full directory listing including
/// file attributes is returned. The format of this listing /// file attributes is returned. The format of this listing
/// depends on the FTP server. No attempt is made to interpret /// depends on the FTP server. No attempt is made to interpret
/// this data. /// this data.
/// ///
/// Creates a data connection between the client and the /// Creates a data connection between the client and the
/// server. If passive mode is on, then the server waits for /// server. If passive mode is on, then the server waits for
/// a connection request from the client. Otherwise, the /// a connection request from the client. Otherwise, the
/// client waits for a connection request from the server. /// client waits for a connection request from the server.
/// After establishing the data connection, a SocketStream /// After establishing the data connection, a SocketStream
/// for transferring the data is created. /// for transferring the data is created.
void endList(); void endList();
/// Must be called to complete a directory listing download /// Must be called to complete a directory listing download
/// initiated with beginList(). /// initiated with beginList().
void abort(); void abort();
/// Aborts the download or upload currently in progress. /// Aborts the download or upload currently in progress.
/// ///
/// Sends a TELNET IP/SYNCH sequence, followed by an ABOR /// Sends a TELNET IP/SYNCH sequence, followed by an ABOR
/// command to the server. /// command to the server.
/// ///
/// A separate call to endDownload() or endUpload() is /// A separate call to endDownload() or endUpload() is
/// not necessary. /// not necessary.
int sendCommand(const std::string& command, std::string& response); int sendCommand(const std::string& command, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
int sendCommand(const std::string& command, const std::string& arg, std::string& response); int sendCommand(const std::string& command, const std::string& arg, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
protected: protected:
enum StatusClass enum StatusClass
{ {
FTP_POSITIVE_PRELIMINARY = 1, FTP_POSITIVE_PRELIMINARY = 1,
FTP_POSITIVE_COMPLETION = 2, FTP_POSITIVE_COMPLETION = 2,
FTP_POSITIVE_INTERMEDIATE = 3, FTP_POSITIVE_INTERMEDIATE = 3,
FTP_TRANSIENT_NEGATIVE = 4, FTP_TRANSIENT_NEGATIVE = 4,
FTP_PERMANENT_NEGATIVE = 5 FTP_PERMANENT_NEGATIVE = 5
}; };
enum enum
{ {
DEFAULT_TIMEOUT = 30000000 // 30 seconds default timeout for socket operations DEFAULT_TIMEOUT = 30000000 // 30 seconds default timeout for socket operations
}; };
static bool isPositivePreliminary(int status); static bool isPositivePreliminary(int status);
static bool isPositiveCompletion(int status); static bool isPositiveCompletion(int status);
static bool isPositiveIntermediate(int status); static bool isPositiveIntermediate(int status);
static bool isTransientNegative(int status); static bool isTransientNegative(int status);
static bool isPermanentNegative(int status); static bool isPermanentNegative(int status);
std::string extractPath(const std::string& response); std::string extractPath(const std::string& response);
StreamSocket establishDataConnection(const std::string& command, const std::string& arg); StreamSocket establishDataConnection(const std::string& command, const std::string& arg);
StreamSocket activeDataConnection(const std::string& command, const std::string& arg); StreamSocket activeDataConnection(const std::string& command, const std::string& arg);
StreamSocket passiveDataConnection(const std::string& command, const std::string& arg); StreamSocket passiveDataConnection(const std::string& command, const std::string& arg);
void sendPortCommand(const SocketAddress& addr); void sendPortCommand(const SocketAddress& addr);
SocketAddress sendPassiveCommand(); SocketAddress sendPassiveCommand();
bool sendEPRT(const SocketAddress& addr); bool sendEPRT(const SocketAddress& addr);
void sendPORT(const SocketAddress& addr); void sendPORT(const SocketAddress& addr);
bool sendEPSV(SocketAddress& addr); bool sendEPSV(SocketAddress& addr);
void sendPASV(SocketAddress& addr); void sendPASV(SocketAddress& addr);
void parseAddress(const std::string& str, SocketAddress& addr); void parseAddress(const std::string& str, SocketAddress& addr);
void parseExtAddress(const std::string& str, SocketAddress& addr); void parseExtAddress(const std::string& str, SocketAddress& addr);
void endTransfer(); void endTransfer();
private: private:
FTPClientSession(); FTPClientSession();
FTPClientSession(const FTPClientSession&); FTPClientSession(const FTPClientSession&);
FTPClientSession& operator = (const FTPClientSession&); FTPClientSession& operator = (const FTPClientSession&);
DialogSocket _controlSocket; DialogSocket _controlSocket;
SocketStream* _pDataStream; SocketStream* _pDataStream;
bool _passiveMode; bool _passiveMode;
FileType _fileType; FileType _fileType;
bool _supports1738; bool _supports1738;
bool _isOpen; bool _isOpen;
Poco::Timespan _timeout; Poco::Timespan _timeout;
}; };
// //
// inlines // inlines
// //
inline bool FTPClientSession::isPositivePreliminary(int status) inline bool FTPClientSession::isPositivePreliminary(int status)
{ {
return status/100 == FTP_POSITIVE_PRELIMINARY; return status/100 == FTP_POSITIVE_PRELIMINARY;
} }
inline bool FTPClientSession::isPositiveCompletion(int status) inline bool FTPClientSession::isPositiveCompletion(int status)
{ {
return status/100 == FTP_POSITIVE_COMPLETION; return status/100 == FTP_POSITIVE_COMPLETION;
} }
inline bool FTPClientSession::isPositiveIntermediate(int status) inline bool FTPClientSession::isPositiveIntermediate(int status)
{ {
return status/100 == FTP_POSITIVE_INTERMEDIATE; return status/100 == FTP_POSITIVE_INTERMEDIATE;
} }
inline bool FTPClientSession::isTransientNegative(int status) inline bool FTPClientSession::isTransientNegative(int status)
{ {
return status/100 == FTP_TRANSIENT_NEGATIVE; return status/100 == FTP_TRANSIENT_NEGATIVE;
} }
inline bool FTPClientSession::isPermanentNegative(int status) inline bool FTPClientSession::isPermanentNegative(int status)
{ {
return status/100 == FTP_PERMANENT_NEGATIVE; return status/100 == FTP_PERMANENT_NEGATIVE;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_FTPClientSession_INCLUDED #endif // Net_FTPClientSession_INCLUDED

View File

@ -1,138 +1,138 @@
// //
// FTPStreamFactory.h // FTPStreamFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/FTPStreamFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/FTPStreamFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: FTP // Package: FTP
// Module: FTPStreamFactory // Module: FTPStreamFactory
// //
// Definition of the FTPStreamFactory class. // Definition of the FTPStreamFactory class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_FTPStreamFactory_INCLUDED #ifndef Net_FTPStreamFactory_INCLUDED
#define Net_FTPStreamFactory_INCLUDED #define Net_FTPStreamFactory_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPSession.h" #include "Poco/Net/HTTPSession.h"
#include "Poco/URIStreamFactory.h" #include "Poco/URIStreamFactory.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API FTPPasswordProvider class Net_API FTPPasswordProvider
/// The base class for all password providers. /// The base class for all password providers.
/// An instance of a subclass of this class can be /// An instance of a subclass of this class can be
/// registered with the FTPStreamFactory to /// registered with the FTPStreamFactory to
/// provide a password /// provide a password
{ {
public: public:
virtual std::string password(const std::string& username, const std::string& host) = 0; virtual std::string password(const std::string& username, const std::string& host) = 0;
/// Provide the password for the given user on the given host. /// Provide the password for the given user on the given host.
protected: protected:
FTPPasswordProvider(); FTPPasswordProvider();
virtual ~FTPPasswordProvider(); virtual ~FTPPasswordProvider();
}; };
class Net_API FTPStreamFactory: public Poco::URIStreamFactory class Net_API FTPStreamFactory: public Poco::URIStreamFactory
/// An implementation of the URIStreamFactory interface /// An implementation of the URIStreamFactory interface
/// that handles File Transfer Protocol (ftp) URIs. /// that handles File Transfer Protocol (ftp) URIs.
/// ///
/// The URI's path may end with an optional type specification /// The URI's path may end with an optional type specification
/// in the form (;type=<typecode>), where <typecode> is /// in the form (;type=<typecode>), where <typecode> is
/// one of a, i or d. If type=a, the file identified by the path /// one of a, i or d. If type=a, the file identified by the path
/// is transferred in ASCII (text) mode. If type=i, the file /// is transferred in ASCII (text) mode. If type=i, the file
/// is transferred in Image (binary) mode. If type=d, a directory /// is transferred in Image (binary) mode. If type=d, a directory
/// listing (in NLST format) is returned. This corresponds with /// listing (in NLST format) is returned. This corresponds with
/// the FTP URL format specified in RFC 1738. /// the FTP URL format specified in RFC 1738.
/// ///
/// If the URI does not contain a username and password, the /// If the URI does not contain a username and password, the
/// username "anonymous" and the password " /// username "anonymous" and the password "
{ {
public: public:
FTPStreamFactory(); FTPStreamFactory();
/// Creates the FTPStreamFactory. /// Creates the FTPStreamFactory.
~FTPStreamFactory(); ~FTPStreamFactory();
/// Destroys the FTPStreamFactory. /// Destroys the FTPStreamFactory.
std::istream* open(const Poco::URI& uri); std::istream* open(const Poco::URI& uri);
/// Creates and opens a HTTP stream for the given URI. /// Creates and opens a HTTP stream for the given URI.
/// The URI must be a ftp://... URI. /// The URI must be a ftp://... URI.
/// ///
/// Throws a NetException if anything goes wrong. /// Throws a NetException if anything goes wrong.
static void setAnonymousPassword(const std::string& password); static void setAnonymousPassword(const std::string& password);
/// Sets the password used for anonymous FTP. /// Sets the password used for anonymous FTP.
/// ///
/// WARNING: Setting the anonymous password is not /// WARNING: Setting the anonymous password is not
/// thread-safe, so it's best to call this method /// thread-safe, so it's best to call this method
/// during application initialization, before the /// during application initialization, before the
/// FTPStreamFactory is used for the first time. /// FTPStreamFactory is used for the first time.
static const std::string& getAnonymousPassword(); static const std::string& getAnonymousPassword();
/// Returns the password used for anonymous FTP. /// Returns the password used for anonymous FTP.
static void setPasswordProvider(FTPPasswordProvider* pProvider); static void setPasswordProvider(FTPPasswordProvider* pProvider);
/// Sets the FTPPasswordProvider. If NULL is given, /// Sets the FTPPasswordProvider. If NULL is given,
/// no password provider is used. /// no password provider is used.
/// ///
/// WARNING: Setting the password provider is not /// WARNING: Setting the password provider is not
/// thread-safe, so it's best to call this method /// thread-safe, so it's best to call this method
/// during application initialization, before the /// during application initialization, before the
/// FTPStreamFactory is used for the first time. /// FTPStreamFactory is used for the first time.
static FTPPasswordProvider* getPasswordProvider(); static FTPPasswordProvider* getPasswordProvider();
/// Returns the FTPPasswordProvider currently in use, /// Returns the FTPPasswordProvider currently in use,
/// or NULL if no one has been set. /// or NULL if no one has been set.
static void registerFactory(); static void registerFactory();
/// Registers the FTPStreamFactory with the /// Registers the FTPStreamFactory with the
/// default URIStreamOpener instance. /// default URIStreamOpener instance.
protected: protected:
static void splitUserInfo(const std::string& userInfo, std::string& username, std::string& password); static void splitUserInfo(const std::string& userInfo, std::string& username, std::string& password);
static void getUserInfo(const Poco::URI& uri, std::string& username, std::string& password); static void getUserInfo(const Poco::URI& uri, std::string& username, std::string& password);
static void getPathAndType(const Poco::URI& uri, std::string& path, char& type); static void getPathAndType(const Poco::URI& uri, std::string& path, char& type);
private: private:
static std::string _anonymousPassword; static std::string _anonymousPassword;
static FTPPasswordProvider* _pPasswordProvider; static FTPPasswordProvider* _pPasswordProvider;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_FTPStreamFactory_INCLUDED #endif // Net_FTPStreamFactory_INCLUDED

View File

@ -1,88 +1,88 @@
// //
// FilePartSource.h // FilePartSource.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/FilePartSource.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/FilePartSource.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: FilePartSource // Module: FilePartSource
// //
// Definition of the FilePartSource class. // Definition of the FilePartSource class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_FilePartSource_INCLUDED #ifndef Net_FilePartSource_INCLUDED
#define Net_FilePartSource_INCLUDED #define Net_FilePartSource_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/PartSource.h" #include "Poco/Net/PartSource.h"
#include <fstream> #include <fstream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API FilePartSource: public PartSource class Net_API FilePartSource: public PartSource
/// An implementation of PartSource for /// An implementation of PartSource for
/// plain files. /// plain files.
{ {
public: public:
FilePartSource(const std::string& path); FilePartSource(const std::string& path);
/// Creates the FilePartSource for the given path. /// Creates the FilePartSource for the given path.
/// ///
/// The MIME type is set to application/octet-stream. /// The MIME type is set to application/octet-stream.
/// ///
/// Throws an OpenFileException if the file cannot be opened. /// Throws an OpenFileException if the file cannot be opened.
FilePartSource(const std::string& path, const std::string& mediaType); FilePartSource(const std::string& path, const std::string& mediaType);
/// Creates the FilePartSource for the given /// Creates the FilePartSource for the given
/// path and MIME type. /// path and MIME type.
/// ///
/// Throws an OpenFileException if the file cannot be opened. /// Throws an OpenFileException if the file cannot be opened.
~FilePartSource(); ~FilePartSource();
/// Destroys the FilePartSource. /// Destroys the FilePartSource.
std::istream& stream(); std::istream& stream();
/// Returns a file input stream for the given file. /// Returns a file input stream for the given file.
const std::string& filename(); const std::string& filename();
/// Returns the filename portion of the path. /// Returns the filename portion of the path.
private: private:
std::ifstream _istr; std::ifstream _istr;
std::string _filename; std::string _filename;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_FilePartSource_INCLUDED #endif // Net_FilePartSource_INCLUDED

View File

@ -1,212 +1,212 @@
// //
// HTMLForm.h // HTMLForm.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTMLForm.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTMLForm.h#1 $
// //
// Library: Net // Library: Net
// Package: HTML // Package: HTML
// Module: HTMLForm // Module: HTMLForm
// //
// Definition of the HTMLForm class. // Definition of the HTMLForm class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTMLForm_INCLUDED #ifndef Net_HTMLForm_INCLUDED
#define Net_HTMLForm_INCLUDED #define Net_HTMLForm_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/NameValueCollection.h" #include "Poco/Net/NameValueCollection.h"
#include <ostream> #include <ostream>
#include <istream> #include <istream>
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPRequest; class HTTPRequest;
class PartHandler; class PartHandler;
class PartSource; class PartSource;
class Net_API HTMLForm: public NameValueCollection class Net_API HTMLForm: public NameValueCollection
/// HTMLForm is a helper class for working with HTML forms, /// HTMLForm is a helper class for working with HTML forms,
/// both on the client and on the server side. /// both on the client and on the server side.
{ {
public: public:
HTMLForm(); HTMLForm();
/// Creates an empty HTMLForm and sets the /// Creates an empty HTMLForm and sets the
/// encoding to "application/x-www-form-urlencoded". /// encoding to "application/x-www-form-urlencoded".
explicit HTMLForm(const std::string& encoding); explicit HTMLForm(const std::string& encoding);
/// Creates an empty HTMLForm that uses /// Creates an empty HTMLForm that uses
/// the given encoding. /// the given encoding.
/// ///
/// Encoding must be either "application/x-www-form-urlencoded" /// Encoding must be either "application/x-www-form-urlencoded"
/// (which is the default) or "multipart/form-data". /// (which is the default) or "multipart/form-data".
HTMLForm(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler); HTMLForm(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler);
/// Creates a HTMLForm from the given HTTP request. /// Creates a HTMLForm from the given HTTP request.
/// ///
/// Uploaded files are passed to the given PartHandler. /// Uploaded files are passed to the given PartHandler.
HTMLForm(const HTTPRequest& request, std::istream& requestBody); HTMLForm(const HTTPRequest& request, std::istream& requestBody);
/// Creates a HTMLForm from the given HTTP request. /// Creates a HTMLForm from the given HTTP request.
/// ///
/// Uploaded files are silently discarded. /// Uploaded files are silently discarded.
explicit HTMLForm(const HTTPRequest& request); explicit HTMLForm(const HTTPRequest& request);
/// Creates a HTMLForm from the given HTTP request. /// Creates a HTMLForm from the given HTTP request.
/// ///
/// The request must be a GET request and the form data /// The request must be a GET request and the form data
/// must be in the query string (URL encoded). /// must be in the query string (URL encoded).
/// ///
/// For POST requests, you must use one of the constructors /// For POST requests, you must use one of the constructors
/// taking an additional input stream for the request body. /// taking an additional input stream for the request body.
~HTMLForm(); ~HTMLForm();
/// Destroys the HTMLForm. /// Destroys the HTMLForm.
void setEncoding(const std::string& encoding); void setEncoding(const std::string& encoding);
/// Sets the encoding used for posting the form. /// Sets the encoding used for posting the form.
/// ///
/// Encoding must be either "application/x-www-form-urlencoded" /// Encoding must be either "application/x-www-form-urlencoded"
/// (which is the default) or "multipart/form-data". /// (which is the default) or "multipart/form-data".
const std::string& getEncoding() const; const std::string& getEncoding() const;
/// Returns the encoding used for posting the form. /// Returns the encoding used for posting the form.
void addPart(const std::string& name, PartSource* pSource); void addPart(const std::string& name, PartSource* pSource);
/// Adds an part/attachment (file upload) to the form. /// Adds an part/attachment (file upload) to the form.
/// ///
/// The form takes ownership of the PartSource and deletes it /// The form takes ownership of the PartSource and deletes it
/// when it is no longer needed. /// when it is no longer needed.
/// ///
/// The part will only be sent if the encoding /// The part will only be sent if the encoding
/// set for the form is "multipart/form-data" /// set for the form is "multipart/form-data"
void load(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler); void load(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler);
/// Reads the form data from the given HTTP request. /// Reads the form data from the given HTTP request.
/// ///
/// Uploaded files are passed to the given PartHandler. /// Uploaded files are passed to the given PartHandler.
void load(const HTTPRequest& request, std::istream& requestBody); void load(const HTTPRequest& request, std::istream& requestBody);
/// Reads the form data from the given HTTP request. /// Reads the form data from the given HTTP request.
/// ///
/// Uploaded files are silently discarded. /// Uploaded files are silently discarded.
void load(const HTTPRequest& request); void load(const HTTPRequest& request);
/// Reads the form data from the given HTTP request. /// Reads the form data from the given HTTP request.
/// ///
/// The request must be a GET request and the form data /// The request must be a GET request and the form data
/// must be in the query string (URL encoded). /// must be in the query string (URL encoded).
/// ///
/// For POST requests, you must use one of the overloads /// For POST requests, you must use one of the overloads
/// taking an additional input stream for the request body. /// taking an additional input stream for the request body.
void read(std::istream& istr, PartHandler& handler); void read(std::istream& istr, PartHandler& handler);
/// Reads the form data from the given input stream. /// Reads the form data from the given input stream.
/// ///
/// The form data read from the stream must be /// The form data read from the stream must be
/// in the encoding specified for the form. /// in the encoding specified for the form.
void prepareSubmit(HTTPRequest& request); void prepareSubmit(HTTPRequest& request);
/// Fills out the request object for submitting the form. /// Fills out the request object for submitting the form.
/// ///
/// If the request method is GET, the encoded form is appended to the /// If the request method is GET, the encoded form is appended to the
/// request URI as query string. Otherwise (the method is /// request URI as query string. Otherwise (the method is
/// POST), the form's content type is set to the form's encoding. /// POST), the form's content type is set to the form's encoding.
/// The form's parameters must be written to the /// The form's parameters must be written to the
/// request body separately, with a call to write. /// request body separately, with a call to write.
/// If the request's HTTP version is HTTP/1.0: /// If the request's HTTP version is HTTP/1.0:
/// - persistent connections are disabled /// - persistent connections are disabled
/// - the content transfer encoding is set to identity encoding /// - the content transfer encoding is set to identity encoding
/// Otherwise, if the request's HTTP version is HTTP/1.1: /// Otherwise, if the request's HTTP version is HTTP/1.1:
/// - the request's persistent connection state is left unchanged /// - the request's persistent connection state is left unchanged
/// - the content transfer encoding is set to chunked /// - the content transfer encoding is set to chunked
void write(std::ostream& ostr, const std::string& boundary); void write(std::ostream& ostr, const std::string& boundary);
/// Writes the form data to the given output stream, /// Writes the form data to the given output stream,
/// using the specified encoding. /// using the specified encoding.
void write(std::ostream& ostr); void write(std::ostream& ostr);
/// Writes the form data to the given output stream, /// Writes the form data to the given output stream,
/// using the specified encoding. /// using the specified encoding.
const std::string& boundary() const; const std::string& boundary() const;
/// Returns the MIME boundary used for writing /// Returns the MIME boundary used for writing
/// multipart form data. /// multipart form data.
static const std::string ENCODING_URL; /// "application/x-www-form-urlencoded" static const std::string ENCODING_URL; /// "application/x-www-form-urlencoded"
static const std::string ENCODING_MULTIPART; /// "multipart/form-data" static const std::string ENCODING_MULTIPART; /// "multipart/form-data"
protected: protected:
void readUrl(std::istream& istr); void readUrl(std::istream& istr);
void readMultipart(std::istream& istr, PartHandler& handler); void readMultipart(std::istream& istr, PartHandler& handler);
void writeUrl(std::ostream& ostr); void writeUrl(std::ostream& ostr);
void writeMultipart(std::ostream& ostr); void writeMultipart(std::ostream& ostr);
private: private:
HTMLForm(const HTMLForm&); HTMLForm(const HTMLForm&);
HTMLForm& operator = (const HTMLForm&); HTMLForm& operator = (const HTMLForm&);
struct Part struct Part
{ {
std::string name; std::string name;
PartSource* pSource; PartSource* pSource;
}; };
typedef std::vector<Part> PartVec; typedef std::vector<Part> PartVec;
std::string _encoding; std::string _encoding;
std::string _boundary; std::string _boundary;
PartVec _parts; PartVec _parts;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTMLForm::getEncoding() const inline const std::string& HTMLForm::getEncoding() const
{ {
return _encoding; return _encoding;
} }
inline const std::string& HTMLForm::boundary() const inline const std::string& HTMLForm::boundary() const
{ {
return _boundary; return _boundary;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTMLForm_INCLUDED #endif // Net_HTMLForm_INCLUDED

View File

@ -1,119 +1,119 @@
// //
// HTTPBasicCredentials.h // HTTPBasicCredentials.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPBasicCredentials.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPBasicCredentials.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPBasicCredentials // Module: HTTPBasicCredentials
// //
// Definition of the HTTPBasicCredentials class. // Definition of the HTTPBasicCredentials class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPBasicCredentials_INCLUDED #ifndef Net_HTTPBasicCredentials_INCLUDED
#define Net_HTTPBasicCredentials_INCLUDED #define Net_HTTPBasicCredentials_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPRequest; class HTTPRequest;
class Net_API HTTPBasicCredentials class Net_API HTTPBasicCredentials
/// This is a utility class for working with /// This is a utility class for working with
/// HTTP Basic Authentication in HTTPRequest /// HTTP Basic Authentication in HTTPRequest
/// objects. /// objects.
{ {
public: public:
HTTPBasicCredentials(); HTTPBasicCredentials();
/// Creates an empty HTTPBasicCredentials object. /// Creates an empty HTTPBasicCredentials object.
HTTPBasicCredentials(const std::string& username, const std::string& password); HTTPBasicCredentials(const std::string& username, const std::string& password);
/// Creates a HTTPBasicCredentials object with the given username and password. /// Creates a HTTPBasicCredentials object with the given username and password.
explicit HTTPBasicCredentials(const HTTPRequest& request); explicit HTTPBasicCredentials(const HTTPRequest& request);
/// Creates a HTTPBasicCredentials object with the authentication information /// Creates a HTTPBasicCredentials object with the authentication information
/// from the given request. /// from the given request.
/// ///
/// Throws a NotAuthenticatedException if the request does /// Throws a NotAuthenticatedException if the request does
/// not contain basic authentication information. /// not contain basic authentication information.
~HTTPBasicCredentials(); ~HTTPBasicCredentials();
/// Destroys the HTTPBasicCredentials. /// Destroys the HTTPBasicCredentials.
void setUsername(const std::string& username); void setUsername(const std::string& username);
/// Sets the username. /// Sets the username.
const std::string& getUsername() const; const std::string& getUsername() const;
/// Returns the username. /// Returns the username.
void setPassword(const std::string& password); void setPassword(const std::string& password);
/// Sets the password. /// Sets the password.
const std::string& getPassword() const; const std::string& getPassword() const;
/// Returns the password. /// Returns the password.
void authenticate(HTTPRequest& request); void authenticate(HTTPRequest& request);
/// Adds authentication information to the given HTTPRequest. /// Adds authentication information to the given HTTPRequest.
static const std::string SCHEME; static const std::string SCHEME;
private: private:
HTTPBasicCredentials(const HTTPBasicCredentials&); HTTPBasicCredentials(const HTTPBasicCredentials&);
HTTPBasicCredentials& operator = (const HTTPBasicCredentials); HTTPBasicCredentials& operator = (const HTTPBasicCredentials);
std::string _username; std::string _username;
std::string _password; std::string _password;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPBasicCredentials::getUsername() const inline const std::string& HTTPBasicCredentials::getUsername() const
{ {
return _username; return _username;
} }
inline const std::string& HTTPBasicCredentials::getPassword() const inline const std::string& HTTPBasicCredentials::getPassword() const
{ {
return _password; return _password;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPBasicCredentials_INCLUDED #endif // Net_HTTPBasicCredentials_INCLUDED

View File

@ -1,58 +1,58 @@
// //
// HTTPBasicStreamBuf.h // HTTPBasicStreamBuf.h
// //
// $Id: //poco/Main/template/class.h#4 $ // $Id: //poco/Main/template/class.h#4 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPBasicStreamBuf // Module: HTTPBasicStreamBuf
// //
// Definition of the HTTPBasicStreamBuf class. // Definition of the HTTPBasicStreamBuf class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPBasicStreamBuf_INCLUDED #ifndef Net_HTTPBasicStreamBuf_INCLUDED
#define Net_HTTPBasicStreamBuf_INCLUDED #define Net_HTTPBasicStreamBuf_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/BufferedStreamBuf.h" #include "Poco/BufferedStreamBuf.h"
#include "Poco/Net/HTTPBufferAllocator.h" #include "Poco/Net/HTTPBufferAllocator.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
typedef Poco::BasicBufferedStreamBuf<char, std::char_traits<char>, HTTPBufferAllocator> HTTPBasicStreamBuf; typedef Poco::BasicBufferedStreamBuf<char, std::char_traits<char>, HTTPBufferAllocator> HTTPBasicStreamBuf;
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPBasicStreamBuf_INCLUDED #endif // Net_HTTPBasicStreamBuf_INCLUDED

View File

@ -1,72 +1,72 @@
// //
// HTTPBufferAllocator.h // HTTPBufferAllocator.h
// //
// $Id: //poco/Main/template/class.h#4 $ // $Id: //poco/Main/template/class.h#4 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPBufferAllocator // Module: HTTPBufferAllocator
// //
// Definition of the HTTPBufferAllocator class. // Definition of the HTTPBufferAllocator class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPBufferAllocator_INCLUDED #ifndef Net_HTTPBufferAllocator_INCLUDED
#define Net_HTTPBufferAllocator_INCLUDED #define Net_HTTPBufferAllocator_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/MemoryPool.h" #include "Poco/MemoryPool.h"
#include <ios> #include <ios>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HTTPBufferAllocator class Net_API HTTPBufferAllocator
/// A BufferAllocator for HTTP streams. /// A BufferAllocator for HTTP streams.
{ {
public: public:
static char* allocate(std::streamsize size); static char* allocate(std::streamsize size);
static void deallocate(char* ptr, std::streamsize size); static void deallocate(char* ptr, std::streamsize size);
enum enum
{ {
BUFFER_SIZE = 4096 BUFFER_SIZE = 4096
}; };
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPBufferAllocator_INCLUDED #endif // Net_HTTPBufferAllocator_INCLUDED

View File

@ -1,125 +1,125 @@
// //
// HTTPChunkedStream.h // HTTPChunkedStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPChunkedStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPChunkedStream.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPChunkedStream // Module: HTTPChunkedStream
// //
// Definition of the HTTPChunkedStream class. // Definition of the HTTPChunkedStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPChunkedStream_INCLUDED #ifndef Net_HTTPChunkedStream_INCLUDED
#define Net_HTTPChunkedStream_INCLUDED #define Net_HTTPChunkedStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPBasicStreamBuf.h" #include "Poco/Net/HTTPBasicStreamBuf.h"
#include "Poco/MemoryPool.h" #include "Poco/MemoryPool.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPSession; class HTTPSession;
class Net_API HTTPChunkedStreamBuf: public HTTPBasicStreamBuf class Net_API HTTPChunkedStreamBuf: public HTTPBasicStreamBuf
/// This is the streambuf class used for reading and writing /// This is the streambuf class used for reading and writing
/// HTTP message bodies in chunked transfer coding. /// HTTP message bodies in chunked transfer coding.
{ {
public: public:
typedef HTTPBasicStreamBuf::openmode openmode; typedef HTTPBasicStreamBuf::openmode openmode;
HTTPChunkedStreamBuf(HTTPSession& session, openmode mode); HTTPChunkedStreamBuf(HTTPSession& session, openmode mode);
~HTTPChunkedStreamBuf(); ~HTTPChunkedStreamBuf();
void close(); void close();
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length); int writeToDevice(const char* buffer, std::streamsize length);
private: private:
HTTPSession& _session; HTTPSession& _session;
openmode _mode; openmode _mode;
std::streamsize _chunk; std::streamsize _chunk;
}; };
class Net_API HTTPChunkedIOS: public virtual std::ios class Net_API HTTPChunkedIOS: public virtual std::ios
/// The base class for HTTPInputStream. /// The base class for HTTPInputStream.
{ {
public: public:
HTTPChunkedIOS(HTTPSession& session, HTTPChunkedStreamBuf::openmode mode); HTTPChunkedIOS(HTTPSession& session, HTTPChunkedStreamBuf::openmode mode);
~HTTPChunkedIOS(); ~HTTPChunkedIOS();
HTTPChunkedStreamBuf* rdbuf(); HTTPChunkedStreamBuf* rdbuf();
protected: protected:
HTTPChunkedStreamBuf _buf; HTTPChunkedStreamBuf _buf;
}; };
class Net_API HTTPChunkedInputStream: public HTTPChunkedIOS, public std::istream class Net_API HTTPChunkedInputStream: public HTTPChunkedIOS, public std::istream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPChunkedInputStream(HTTPSession& session); HTTPChunkedInputStream(HTTPSession& session);
~HTTPChunkedInputStream(); ~HTTPChunkedInputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
class Net_API HTTPChunkedOutputStream: public HTTPChunkedIOS, public std::ostream class Net_API HTTPChunkedOutputStream: public HTTPChunkedIOS, public std::ostream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPChunkedOutputStream(HTTPSession& session); HTTPChunkedOutputStream(HTTPSession& session);
~HTTPChunkedOutputStream(); ~HTTPChunkedOutputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPChunkedStream_INCLUDED #endif // Net_HTTPChunkedStream_INCLUDED

View File

@ -1,263 +1,263 @@
// //
// HTTPClientSession.h // HTTPClientSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPClientSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPClientSession.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPClient // Package: HTTPClient
// Module: HTTPClientSession // Module: HTTPClientSession
// //
// Definition of the HTTPClientSession class. // Definition of the HTTPClientSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPClientSession_INCLUDED #ifndef Net_HTTPClientSession_INCLUDED
#define Net_HTTPClientSession_INCLUDED #define Net_HTTPClientSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPSession.h" #include "Poco/Net/HTTPSession.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPRequest; class HTTPRequest;
class HTTPResponse; class HTTPResponse;
class Net_API HTTPClientSession: public HTTPSession class Net_API HTTPClientSession: public HTTPSession
/// This class implements the client-side of /// This class implements the client-side of
/// a HTTP session. /// a HTTP session.
/// ///
/// To send a HTTP request to a HTTP server, first /// To send a HTTP request to a HTTP server, first
/// instantiate a HTTPClientSession object and /// instantiate a HTTPClientSession object and
/// specify the server's host name and port number. /// specify the server's host name and port number.
/// ///
/// Then create a HTTPRequest object, fill it accordingly, /// Then create a HTTPRequest object, fill it accordingly,
/// and pass it as argument to the sendRequst() method. /// and pass it as argument to the sendRequst() method.
/// ///
/// sendRequest() will return an output stream that can /// sendRequest() will return an output stream that can
/// be used to send the request body, if there is any. /// be used to send the request body, if there is any.
/// ///
/// After you are done sending the request body, create /// After you are done sending the request body, create
/// a HTTPResponse object and pass it to receiveResponse(). /// a HTTPResponse object and pass it to receiveResponse().
/// ///
/// This will return an input stream that can be used to /// This will return an input stream that can be used to
/// read the response body. /// read the response body.
/// ///
/// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more /// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more
/// information about the HTTP protocol. /// information about the HTTP protocol.
{ {
public: public:
HTTPClientSession(); HTTPClientSession();
/// Creates an unconnected HTTPClientSession. /// Creates an unconnected HTTPClientSession.
explicit HTTPClientSession(const StreamSocket& socket); explicit HTTPClientSession(const StreamSocket& socket);
/// Creates a HTTPClientSession using the given socket. /// Creates a HTTPClientSession using the given socket.
/// The socket must not be connected. The session /// The socket must not be connected. The session
/// takes ownership of the socket. /// takes ownership of the socket.
explicit HTTPClientSession(const SocketAddress& address); explicit HTTPClientSession(const SocketAddress& address);
/// Creates a HTTPClientSession using the given address. /// Creates a HTTPClientSession using the given address.
HTTPClientSession(const std::string& host, Poco::UInt16 port = HTTPSession::HTTP_PORT); HTTPClientSession(const std::string& host, Poco::UInt16 port = HTTPSession::HTTP_PORT);
/// Creates a HTTPClientSession using the given host and port. /// Creates a HTTPClientSession using the given host and port.
virtual ~HTTPClientSession(); virtual ~HTTPClientSession();
/// Destroys the HTTPClientSession and closes /// Destroys the HTTPClientSession and closes
/// the underlying socket. /// the underlying socket.
void setHost(const std::string& host); void setHost(const std::string& host);
/// Sets the host name of the target HTTP server. /// Sets the host name of the target HTTP server.
/// ///
/// The host must not be changed once there is an /// The host must not be changed once there is an
/// open connection to the server. /// open connection to the server.
const std::string& getHost() const; const std::string& getHost() const;
/// Returns the host name of the target HTTP server. /// Returns the host name of the target HTTP server.
void setPort(Poco::UInt16 port); void setPort(Poco::UInt16 port);
/// Sets the port number of the target HTTP server. /// Sets the port number of the target HTTP server.
/// ///
/// The port number must not be changed once there is an /// The port number must not be changed once there is an
/// open connection to the server. /// open connection to the server.
Poco::UInt16 getPort() const; Poco::UInt16 getPort() const;
/// Returns the port number of the target HTTP server. /// Returns the port number of the target HTTP server.
void setProxy(const std::string& host, Poco::UInt16 port = HTTPSession::HTTP_PORT); void setProxy(const std::string& host, Poco::UInt16 port = HTTPSession::HTTP_PORT);
/// Sets the proxy host name and port number. /// Sets the proxy host name and port number.
void setProxyHost(const std::string& host); void setProxyHost(const std::string& host);
/// Sets the host name of the proxy server. /// Sets the host name of the proxy server.
void setProxyPort(Poco::UInt16 port); void setProxyPort(Poco::UInt16 port);
/// Sets the port number of the proxy server. /// Sets the port number of the proxy server.
const std::string& getProxyHost() const; const std::string& getProxyHost() const;
/// Returns the proxy host name. /// Returns the proxy host name.
Poco::UInt16 getProxyPort() const; Poco::UInt16 getProxyPort() const;
/// Returns the proxy port number. /// Returns the proxy port number.
virtual std::ostream& sendRequest(HTTPRequest& request); virtual std::ostream& sendRequest(HTTPRequest& request);
/// Sends the header for the given HTTP request to /// Sends the header for the given HTTP request to
/// the server. /// the server.
/// ///
/// The HTTPClientSession will set the request's /// The HTTPClientSession will set the request's
/// Host and Keep-Alive headers accordingly. /// Host and Keep-Alive headers accordingly.
/// ///
/// The returned output stream can be used to write /// The returned output stream can be used to write
/// the request body. The stream is valid until /// the request body. The stream is valid until
/// receiveResponse() is called or the session /// receiveResponse() is called or the session
/// is destroyed. /// is destroyed.
virtual std::istream& receiveResponse(HTTPResponse& response); virtual std::istream& receiveResponse(HTTPResponse& response);
/// Receives the header for the response to the previous /// Receives the header for the response to the previous
/// HTTP request. /// HTTP request.
/// ///
/// The returned input stream can be used to read /// The returned input stream can be used to read
/// the response body. The stream is valid until /// the response body. The stream is valid until
/// sendRequest() is called or the session is /// sendRequest() is called or the session is
/// destroyed. /// destroyed.
protected: protected:
void reconnect(); void reconnect();
/// Connects the underlying socket to the HTTP server. /// Connects the underlying socket to the HTTP server.
int write(const char* buffer, std::streamsize length); int write(const char* buffer, std::streamsize length);
/// Tries to re-connect if keep-alive is on. /// Tries to re-connect if keep-alive is on.
virtual std::string getHostInfo() const; virtual std::string getHostInfo() const;
/// Returns the target host and port number for proxy requests. /// Returns the target host and port number for proxy requests.
void deleteResponseStream(); void deleteResponseStream();
/// Deletes the response stream and sets it to 0. /// Deletes the response stream and sets it to 0.
void deleteRequestStream(); void deleteRequestStream();
/// Deletes the request stream and sets it to 0. /// Deletes the request stream and sets it to 0.
void setResponseStream(std::istream* pRespStream); void setResponseStream(std::istream* pRespStream);
/// Sets the response stream iff _pResponseStream is 0. /// Sets the response stream iff _pResponseStream is 0.
void setRequestStream(std::ostream* pRequestStream); void setRequestStream(std::ostream* pRequestStream);
/// Sets the request stream iff _pRequestStream is 0. /// Sets the request stream iff _pRequestStream is 0.
std::istream* getResponseStream() const; std::istream* getResponseStream() const;
/// Returns the currently set response stream. Can return 0. /// Returns the currently set response stream. Can return 0.
std::ostream* getRequestStream() const; std::ostream* getRequestStream() const;
/// Returns the currently set request stream. Can return 0. /// Returns the currently set request stream. Can return 0.
void setReconnect(bool recon); void setReconnect(bool recon);
/// Sets _reconnect. /// Sets _reconnect.
void setExpectResponseBody(bool expect); void setExpectResponseBody(bool expect);
/// Sets _expectResponseBody. /// Sets _expectResponseBody.
bool getExpectResponseBody() const; bool getExpectResponseBody() const;
/// Returns _expectResponseBody. /// Returns _expectResponseBody.
private: private:
std::string _host; std::string _host;
Poco::UInt16 _port; Poco::UInt16 _port;
std::string _proxyHost; std::string _proxyHost;
Poco::UInt16 _proxyPort; Poco::UInt16 _proxyPort;
bool _reconnect; bool _reconnect;
bool _expectResponseBody; bool _expectResponseBody;
std::ostream* _pRequestStream; std::ostream* _pRequestStream;
std::istream* _pResponseStream; std::istream* _pResponseStream;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPClientSession::getHost() const inline const std::string& HTTPClientSession::getHost() const
{ {
return _host; return _host;
} }
inline Poco::UInt16 HTTPClientSession::getPort() const inline Poco::UInt16 HTTPClientSession::getPort() const
{ {
return _port; return _port;
} }
inline const std::string& HTTPClientSession::getProxyHost() const inline const std::string& HTTPClientSession::getProxyHost() const
{ {
return _proxyHost; return _proxyHost;
} }
inline Poco::UInt16 HTTPClientSession::getProxyPort() const inline Poco::UInt16 HTTPClientSession::getProxyPort() const
{ {
return _proxyPort; return _proxyPort;
} }
inline std::istream* HTTPClientSession::getResponseStream() const inline std::istream* HTTPClientSession::getResponseStream() const
{ {
return _pResponseStream; return _pResponseStream;
} }
inline std::ostream* HTTPClientSession::getRequestStream() const inline std::ostream* HTTPClientSession::getRequestStream() const
{ {
return _pRequestStream; return _pRequestStream;
} }
inline void HTTPClientSession::setReconnect(bool recon) inline void HTTPClientSession::setReconnect(bool recon)
{ {
_reconnect = recon; _reconnect = recon;
} }
inline void HTTPClientSession::setExpectResponseBody(bool expect) inline void HTTPClientSession::setExpectResponseBody(bool expect)
{ {
_expectResponseBody = expect; _expectResponseBody = expect;
} }
inline bool HTTPClientSession::getExpectResponseBody() const inline bool HTTPClientSession::getExpectResponseBody() const
{ {
return _expectResponseBody; return _expectResponseBody;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPClientSession_INCLUDED #endif // Net_HTTPClientSession_INCLUDED

View File

@ -1,230 +1,230 @@
// //
// HTTPCookie.h // HTTPCookie.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPCookie.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPCookie.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPCookie // Module: HTTPCookie
// //
// Definition of the HTTPCookie class. // Definition of the HTTPCookie class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPCookie_INCLUDED #ifndef Net_HTTPCookie_INCLUDED
#define Net_HTTPCookie_INCLUDED #define Net_HTTPCookie_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class NameValueCollection; class NameValueCollection;
class Net_API HTTPCookie class Net_API HTTPCookie
/// This class represents a HTTP Cookie. /// This class represents a HTTP Cookie.
/// ///
/// A cookie is a small amount of information sent by a Web /// A cookie is a small amount of information sent by a Web
/// server to a Web browser, saved by the browser, and later sent back /// server to a Web browser, saved by the browser, and later sent back
/// to the server. A cookie's value can uniquely identify a client, so /// to the server. A cookie's value can uniquely identify a client, so
/// cookies are commonly used for session management. /// cookies are commonly used for session management.
/// ///
/// A cookie has a name, a single value, and optional attributes such /// A cookie has a name, a single value, and optional attributes such
/// as a comment, path and domain qualifiers, a maximum age, and a /// as a comment, path and domain qualifiers, a maximum age, and a
/// version number. /// version number.
/// ///
/// This class supports both the Version 0 (by Netscape) and Version 1 /// This class supports both the Version 0 (by Netscape) and Version 1
/// (by RFC 2109) cookie specifications. By default, cookies are created /// (by RFC 2109) cookie specifications. By default, cookies are created
/// using Version 0 to ensure the best interoperability. /// using Version 0 to ensure the best interoperability.
{ {
public: public:
HTTPCookie(); HTTPCookie();
/// Creates an empty HTTPCookie. /// Creates an empty HTTPCookie.
explicit HTTPCookie(const std::string& name); explicit HTTPCookie(const std::string& name);
/// Creates a cookie with the given name. /// Creates a cookie with the given name.
/// The cookie never expires. /// The cookie never expires.
explicit HTTPCookie(const NameValueCollection& nvc); explicit HTTPCookie(const NameValueCollection& nvc);
/// Creates a cookie from the given NameValueCollection. /// Creates a cookie from the given NameValueCollection.
HTTPCookie(const std::string& name, const std::string& value); HTTPCookie(const std::string& name, const std::string& value);
/// Creates a cookie with the given name and value. /// Creates a cookie with the given name and value.
/// The cookie never expires. /// The cookie never expires.
HTTPCookie(const HTTPCookie& cookie); HTTPCookie(const HTTPCookie& cookie);
/// Creates the HTTPCookie by copying another one. /// Creates the HTTPCookie by copying another one.
~HTTPCookie(); ~HTTPCookie();
/// Destroys the HTTPCookie. /// Destroys the HTTPCookie.
HTTPCookie& operator = (const HTTPCookie& cookie); HTTPCookie& operator = (const HTTPCookie& cookie);
/// Assigns a cookie. /// Assigns a cookie.
void setVersion(int version); void setVersion(int version);
/// Sets the version of the cookie. /// Sets the version of the cookie.
/// ///
/// Version must be either 0 (denoting a Netscape cookie) /// Version must be either 0 (denoting a Netscape cookie)
/// or 1 (denoting a RFC 2109 cookie). /// or 1 (denoting a RFC 2109 cookie).
int getVersion() const; int getVersion() const;
/// Returns the version of the cookie, which is /// Returns the version of the cookie, which is
/// either 0 or 1. /// either 0 or 1.
void setName(const std::string& name); void setName(const std::string& name);
/// Sets the name of the cookie. /// Sets the name of the cookie.
const std::string& getName() const; const std::string& getName() const;
/// Returns the name of the cookie. /// Returns the name of the cookie.
void setValue(const std::string& value); void setValue(const std::string& value);
/// Sets the value of the cookie. /// Sets the value of the cookie.
/// ///
/// According to the cookie specification, the /// According to the cookie specification, the
/// size of the value should not exceed 4 Kbytes. /// size of the value should not exceed 4 Kbytes.
const std::string& getValue() const; const std::string& getValue() const;
/// Returns the value of the cookie. /// Returns the value of the cookie.
void setComment(const std::string& comment); void setComment(const std::string& comment);
/// Sets the comment for the cookie. /// Sets the comment for the cookie.
/// ///
/// Comments are only supported for version 1 cookies. /// Comments are only supported for version 1 cookies.
const std::string& getComment() const; const std::string& getComment() const;
/// Returns the comment for the cookie. /// Returns the comment for the cookie.
void setDomain(const std::string& domain); void setDomain(const std::string& domain);
/// Sets the domain for the cookie. /// Sets the domain for the cookie.
const std::string& getDomain() const; const std::string& getDomain() const;
/// Returns the domain for the cookie. /// Returns the domain for the cookie.
void setPath(const std::string& path); void setPath(const std::string& path);
/// Sets the path for the cookie. /// Sets the path for the cookie.
const std::string& getPath() const; const std::string& getPath() const;
/// Returns the path for the cookie. /// Returns the path for the cookie.
void setSecure(bool secure); void setSecure(bool secure);
/// Sets the value of the secure flag for /// Sets the value of the secure flag for
/// the cookie. /// the cookie.
bool getSecure() const; bool getSecure() const;
/// Returns the value of the secure flag /// Returns the value of the secure flag
/// for the cookie. /// for the cookie.
void setMaxAge(int maxAge); void setMaxAge(int maxAge);
/// Sets the maximum age in seconds for /// Sets the maximum age in seconds for
/// the cookie. /// the cookie.
/// ///
/// A value of -1 causes the cookie to /// A value of -1 causes the cookie to
/// never expire on the client. /// never expire on the client.
/// ///
/// A value of 0 deletes the cookie on /// A value of 0 deletes the cookie on
/// the client. /// the client.
int getMaxAge() const; int getMaxAge() const;
/// Returns the maximum age in seconds for /// Returns the maximum age in seconds for
/// the cookie. /// the cookie.
std::string toString() const; std::string toString() const;
/// Returns a string representation of the cookie, /// Returns a string representation of the cookie,
/// suitable for use in a Set-Cookie header. /// suitable for use in a Set-Cookie header.
private: private:
int _version; int _version;
std::string _name; std::string _name;
std::string _value; std::string _value;
std::string _comment; std::string _comment;
std::string _domain; std::string _domain;
std::string _path; std::string _path;
bool _secure; bool _secure;
int _maxAge; int _maxAge;
}; };
// //
// inlines // inlines
// //
inline int HTTPCookie::getVersion() const inline int HTTPCookie::getVersion() const
{ {
return _version; return _version;
} }
inline const std::string& HTTPCookie::getName() const inline const std::string& HTTPCookie::getName() const
{ {
return _name; return _name;
} }
inline const std::string& HTTPCookie::getValue() const inline const std::string& HTTPCookie::getValue() const
{ {
return _value; return _value;
} }
inline const std::string& HTTPCookie::getComment() const inline const std::string& HTTPCookie::getComment() const
{ {
return _comment; return _comment;
} }
inline const std::string& HTTPCookie::getDomain() const inline const std::string& HTTPCookie::getDomain() const
{ {
return _domain; return _domain;
} }
inline const std::string& HTTPCookie::getPath() const inline const std::string& HTTPCookie::getPath() const
{ {
return _path; return _path;
} }
inline bool HTTPCookie::getSecure() const inline bool HTTPCookie::getSecure() const
{ {
return _secure; return _secure;
} }
inline int HTTPCookie::getMaxAge() const inline int HTTPCookie::getMaxAge() const
{ {
return _maxAge; return _maxAge;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPCookie_INCLUDED #endif // Net_HTTPCookie_INCLUDED

View File

@ -1,125 +1,125 @@
// //
// HTTPFixedLengthStream.h // HTTPFixedLengthStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPFixedLengthStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPFixedLengthStream.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPFixedLengthStream // Module: HTTPFixedLengthStream
// //
// Definition of the HTTPFixedLengthStream class. // Definition of the HTTPFixedLengthStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPFixedLengthStream_INCLUDED #ifndef Net_HTTPFixedLengthStream_INCLUDED
#define Net_HTTPFixedLengthStream_INCLUDED #define Net_HTTPFixedLengthStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPBasicStreamBuf.h" #include "Poco/Net/HTTPBasicStreamBuf.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPSession; class HTTPSession;
class Net_API HTTPFixedLengthStreamBuf: public HTTPBasicStreamBuf class Net_API HTTPFixedLengthStreamBuf: public HTTPBasicStreamBuf
/// This is the streambuf class used for reading and writing fixed-size /// This is the streambuf class used for reading and writing fixed-size
/// HTTP message bodies. /// HTTP message bodies.
/// ///
/// At most a given number of bytes are read or written. /// At most a given number of bytes are read or written.
{ {
public: public:
typedef HTTPBasicStreamBuf::openmode openmode; typedef HTTPBasicStreamBuf::openmode openmode;
HTTPFixedLengthStreamBuf(HTTPSession& session, std::streamsize length, openmode mode); HTTPFixedLengthStreamBuf(HTTPSession& session, std::streamsize length, openmode mode);
~HTTPFixedLengthStreamBuf(); ~HTTPFixedLengthStreamBuf();
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length); int writeToDevice(const char* buffer, std::streamsize length);
private: private:
HTTPSession& _session; HTTPSession& _session;
std::streamsize _length; std::streamsize _length;
std::streamsize _count; std::streamsize _count;
}; };
class Net_API HTTPFixedLengthIOS: public virtual std::ios class Net_API HTTPFixedLengthIOS: public virtual std::ios
/// The base class for HTTPFixedLengthInputStream. /// The base class for HTTPFixedLengthInputStream.
{ {
public: public:
HTTPFixedLengthIOS(HTTPSession& session, std::streamsize length, HTTPFixedLengthStreamBuf::openmode mode); HTTPFixedLengthIOS(HTTPSession& session, std::streamsize length, HTTPFixedLengthStreamBuf::openmode mode);
~HTTPFixedLengthIOS(); ~HTTPFixedLengthIOS();
HTTPFixedLengthStreamBuf* rdbuf(); HTTPFixedLengthStreamBuf* rdbuf();
protected: protected:
HTTPFixedLengthStreamBuf _buf; HTTPFixedLengthStreamBuf _buf;
}; };
class Net_API HTTPFixedLengthInputStream: public HTTPFixedLengthIOS, public std::istream class Net_API HTTPFixedLengthInputStream: public HTTPFixedLengthIOS, public std::istream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPFixedLengthInputStream(HTTPSession& session, std::streamsize length); HTTPFixedLengthInputStream(HTTPSession& session, std::streamsize length);
~HTTPFixedLengthInputStream(); ~HTTPFixedLengthInputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
class Net_API HTTPFixedLengthOutputStream: public HTTPFixedLengthIOS, public std::ostream class Net_API HTTPFixedLengthOutputStream: public HTTPFixedLengthIOS, public std::ostream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPFixedLengthOutputStream(HTTPSession& session, std::streamsize length); HTTPFixedLengthOutputStream(HTTPSession& session, std::streamsize length);
~HTTPFixedLengthOutputStream(); ~HTTPFixedLengthOutputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPFixedLengthStream_INCLUDED #endif // Net_HTTPFixedLengthStream_INCLUDED

View File

@ -1,123 +1,123 @@
// //
// HTTPHeaderStream.h // HTTPHeaderStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPHeaderStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPHeaderStream.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPHeaderStream // Module: HTTPHeaderStream
// //
// Definition of the HTTPHeaderStream class. // Definition of the HTTPHeaderStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPHeaderStream_INCLUDED #ifndef Net_HTTPHeaderStream_INCLUDED
#define Net_HTTPHeaderStream_INCLUDED #define Net_HTTPHeaderStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPBasicStreamBuf.h" #include "Poco/Net/HTTPBasicStreamBuf.h"
#include "Poco/MemoryPool.h" #include "Poco/MemoryPool.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPSession; class HTTPSession;
class Net_API HTTPHeaderStreamBuf: public HTTPBasicStreamBuf class Net_API HTTPHeaderStreamBuf: public HTTPBasicStreamBuf
/// This is the streambuf class used for reading from a HTTP header /// This is the streambuf class used for reading from a HTTP header
/// in a HTTPSession. /// in a HTTPSession.
{ {
public: public:
typedef HTTPBasicStreamBuf::openmode openmode; typedef HTTPBasicStreamBuf::openmode openmode;
HTTPHeaderStreamBuf(HTTPSession& session, openmode mode); HTTPHeaderStreamBuf(HTTPSession& session, openmode mode);
~HTTPHeaderStreamBuf(); ~HTTPHeaderStreamBuf();
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length); int writeToDevice(const char* buffer, std::streamsize length);
private: private:
HTTPSession& _session; HTTPSession& _session;
bool _end; bool _end;
}; };
class Net_API HTTPHeaderIOS: public virtual std::ios class Net_API HTTPHeaderIOS: public virtual std::ios
/// The base class for HTTPHeaderInputStream. /// The base class for HTTPHeaderInputStream.
{ {
public: public:
HTTPHeaderIOS(HTTPSession& session, HTTPHeaderStreamBuf::openmode mode); HTTPHeaderIOS(HTTPSession& session, HTTPHeaderStreamBuf::openmode mode);
~HTTPHeaderIOS(); ~HTTPHeaderIOS();
HTTPHeaderStreamBuf* rdbuf(); HTTPHeaderStreamBuf* rdbuf();
protected: protected:
HTTPHeaderStreamBuf _buf; HTTPHeaderStreamBuf _buf;
}; };
class Net_API HTTPHeaderInputStream: public HTTPHeaderIOS, public std::istream class Net_API HTTPHeaderInputStream: public HTTPHeaderIOS, public std::istream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPHeaderInputStream(HTTPSession& session); HTTPHeaderInputStream(HTTPSession& session);
~HTTPHeaderInputStream(); ~HTTPHeaderInputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
class Net_API HTTPHeaderOutputStream: public HTTPHeaderIOS, public std::ostream class Net_API HTTPHeaderOutputStream: public HTTPHeaderIOS, public std::ostream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPHeaderOutputStream(HTTPSession& session); HTTPHeaderOutputStream(HTTPSession& session);
~HTTPHeaderOutputStream(); ~HTTPHeaderOutputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPHeaderStream_INCLUDED #endif // Net_HTTPHeaderStream_INCLUDED

View File

@ -1,110 +1,110 @@
// //
// HTTPIOStream.h // HTTPIOStream.h
// //
// $Id: //poco/Main/template/class.h#4 $ // $Id: //poco/Main/template/class.h#4 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPIOStream // Module: HTTPIOStream
// //
// Definition of the HTTPIOStream class. // Definition of the HTTPIOStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPIOStream_INCLUDED #ifndef Net_HTTPIOStream_INCLUDED
#define Net_HTTPIOStream_INCLUDED #define Net_HTTPIOStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPResponse.h"
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPClientSession; class HTTPClientSession;
class Net_API HTTPResponseStreamBuf: public Poco::UnbufferedStreamBuf class Net_API HTTPResponseStreamBuf: public Poco::UnbufferedStreamBuf
{ {
public: public:
HTTPResponseStreamBuf(std::istream& istr); HTTPResponseStreamBuf(std::istream& istr);
~HTTPResponseStreamBuf(); ~HTTPResponseStreamBuf();
private: private:
int readFromDevice(); int readFromDevice();
std::istream& _istr; std::istream& _istr;
}; };
inline int HTTPResponseStreamBuf::readFromDevice() inline int HTTPResponseStreamBuf::readFromDevice()
{ {
return _istr.get(); return _istr.get();
} }
class Net_API HTTPResponseIOS: public virtual std::ios class Net_API HTTPResponseIOS: public virtual std::ios
{ {
public: public:
HTTPResponseIOS(std::istream& istr); HTTPResponseIOS(std::istream& istr);
~HTTPResponseIOS(); ~HTTPResponseIOS();
HTTPResponseStreamBuf* rdbuf(); HTTPResponseStreamBuf* rdbuf();
protected: protected:
HTTPResponseStreamBuf _buf; HTTPResponseStreamBuf _buf;
}; };
inline HTTPResponseStreamBuf* HTTPResponseIOS::rdbuf() inline HTTPResponseStreamBuf* HTTPResponseIOS::rdbuf()
{ {
return &_buf; return &_buf;
} }
class Net_API HTTPResponseStream: public HTTPResponseIOS, public std::istream class Net_API HTTPResponseStream: public HTTPResponseIOS, public std::istream
{ {
public: public:
HTTPResponseStream(std::istream& istr, HTTPClientSession* pSession); HTTPResponseStream(std::istream& istr, HTTPClientSession* pSession);
~HTTPResponseStream(); ~HTTPResponseStream();
private: private:
HTTPClientSession* _pSession; HTTPClientSession* _pSession;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPIOStream_INCLUDED #endif // Net_HTTPIOStream_INCLUDED

View File

@ -1,177 +1,177 @@
// //
// HTTPMessage.h // HTTPMessage.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPMessage.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPMessage.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPMessage // Module: HTTPMessage
// //
// Definition of the HTTPMessage class. // Definition of the HTTPMessage class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPMessage_INCLUDED #ifndef Net_HTTPMessage_INCLUDED
#define Net_HTTPMessage_INCLUDED #define Net_HTTPMessage_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/MessageHeader.h" #include "Poco/Net/MessageHeader.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MediaType; class MediaType;
class Net_API HTTPMessage: public MessageHeader class Net_API HTTPMessage: public MessageHeader
/// The base class for HTTPRequest and HTTPResponse. /// The base class for HTTPRequest and HTTPResponse.
/// ///
/// Defines the common properties of all HTTP messages. /// Defines the common properties of all HTTP messages.
/// These are version, content length, content type /// These are version, content length, content type
/// and transfer encoding. /// and transfer encoding.
{ {
public: public:
void setVersion(const std::string& version); void setVersion(const std::string& version);
/// Sets the HTTP version for this message. /// Sets the HTTP version for this message.
const std::string& getVersion() const; const std::string& getVersion() const;
/// Returns the HTTP version for this message. /// Returns the HTTP version for this message.
void setContentLength(int length); void setContentLength(int length);
/// Sets the Content-Length header. /// Sets the Content-Length header.
/// ///
/// If length is UNKNOWN_CONTENT_LENGTH, removes /// If length is UNKNOWN_CONTENT_LENGTH, removes
/// the Content-Length header. /// the Content-Length header.
int getContentLength() const; int getContentLength() const;
/// Returns the content length for this message, /// Returns the content length for this message,
/// which may be UNKNOWN_CONTENT_LENGTH if /// which may be UNKNOWN_CONTENT_LENGTH if
/// no Content-Length header is present. /// no Content-Length header is present.
void setTransferEncoding(const std::string& transferEncoding); void setTransferEncoding(const std::string& transferEncoding);
/// Sets the transfer encoding for this message. /// Sets the transfer encoding for this message.
/// ///
/// The value should be either IDENTITY_TRANSFER_CODING /// The value should be either IDENTITY_TRANSFER_CODING
/// or CHUNKED_TRANSFER_CODING. /// or CHUNKED_TRANSFER_CODING.
const std::string& getTransferEncoding() const; const std::string& getTransferEncoding() const;
/// Returns the transfer encoding used for this /// Returns the transfer encoding used for this
/// message. /// message.
/// ///
/// Normally, this is the value of the Transfer-Encoding /// Normally, this is the value of the Transfer-Encoding
/// header field. If no such field is present, /// header field. If no such field is present,
/// returns IDENTITY_TRANSFER_CODING. /// returns IDENTITY_TRANSFER_CODING.
void setChunkedTransferEncoding(bool flag); void setChunkedTransferEncoding(bool flag);
/// If flag is true, sets the Transfer-Encoding header to /// If flag is true, sets the Transfer-Encoding header to
/// chunked. Otherwise, removes the Transfer-Encoding /// chunked. Otherwise, removes the Transfer-Encoding
/// header. /// header.
bool getChunkedTransferEncoding() const; bool getChunkedTransferEncoding() const;
/// Returns true if the Transfer-Encoding header is set /// Returns true if the Transfer-Encoding header is set
/// and its value is chunked. /// and its value is chunked.
void setContentType(const std::string& mediaType); void setContentType(const std::string& mediaType);
/// Sets the content type for this message. /// Sets the content type for this message.
/// ///
/// Specify NO_CONTENT_TYPE to remove the /// Specify NO_CONTENT_TYPE to remove the
/// Content-Type header. /// Content-Type header.
void setContentType(const MediaType& mediaType); void setContentType(const MediaType& mediaType);
/// Sets the content type for this message. /// Sets the content type for this message.
const std::string& getContentType() const; const std::string& getContentType() const;
/// Returns the content type for this message. /// Returns the content type for this message.
/// ///
/// If no Content-Type header is present, /// If no Content-Type header is present,
/// returns UNKNOWN_CONTENT_TYPE. /// returns UNKNOWN_CONTENT_TYPE.
void setKeepAlive(bool keepAlive); void setKeepAlive(bool keepAlive);
/// Sets the value of the Connection header field. /// Sets the value of the Connection header field.
/// ///
/// The value is set to "Keep-Alive" if keepAlive is /// The value is set to "Keep-Alive" if keepAlive is
/// true, or to "Close" otherwise. /// true, or to "Close" otherwise.
bool getKeepAlive() const; bool getKeepAlive() const;
/// Returns true if /// Returns true if
/// * the message has a Connection header field and its value is "Keep-Alive" /// * the message has a Connection header field and its value is "Keep-Alive"
/// * the message is a HTTP/1.1 message and not Connection header is set /// * the message is a HTTP/1.1 message and not Connection header is set
/// Returns false otherwise. /// Returns false otherwise.
static const std::string HTTP_1_0; static const std::string HTTP_1_0;
static const std::string HTTP_1_1; static const std::string HTTP_1_1;
static const std::string IDENTITY_TRANSFER_ENCODING; static const std::string IDENTITY_TRANSFER_ENCODING;
static const std::string CHUNKED_TRANSFER_ENCODING; static const std::string CHUNKED_TRANSFER_ENCODING;
static const int UNKNOWN_CONTENT_LENGTH; static const int UNKNOWN_CONTENT_LENGTH;
static const std::string UNKNOWN_CONTENT_TYPE; static const std::string UNKNOWN_CONTENT_TYPE;
static const std::string CONTENT_LENGTH; static const std::string CONTENT_LENGTH;
static const std::string CONTENT_TYPE; static const std::string CONTENT_TYPE;
static const std::string TRANSFER_ENCODING; static const std::string TRANSFER_ENCODING;
static const std::string CONNECTION; static const std::string CONNECTION;
static const std::string CONNECTION_KEEP_ALIVE; static const std::string CONNECTION_KEEP_ALIVE;
static const std::string CONNECTION_CLOSE; static const std::string CONNECTION_CLOSE;
protected: protected:
HTTPMessage(); HTTPMessage();
/// Creates the HTTPMessage with version HTTP/1.0. /// Creates the HTTPMessage with version HTTP/1.0.
HTTPMessage(const std::string& version); HTTPMessage(const std::string& version);
/// Creates the HTTPMessage and sets /// Creates the HTTPMessage and sets
/// the version. /// the version.
virtual ~HTTPMessage(); virtual ~HTTPMessage();
/// Destroys the HTTPMessage. /// Destroys the HTTPMessage.
private: private:
HTTPMessage(const HTTPMessage&); HTTPMessage(const HTTPMessage&);
HTTPMessage& operator = (const HTTPMessage&); HTTPMessage& operator = (const HTTPMessage&);
std::string _version; std::string _version;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPMessage::getVersion() const inline const std::string& HTTPMessage::getVersion() const
{ {
return _version; return _version;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPMessage_INCLUDED #endif // Net_HTTPMessage_INCLUDED

View File

@ -1,176 +1,176 @@
// //
// HTTPRequest.h // HTTPRequest.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequest.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequest.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPRequest // Module: HTTPRequest
// //
// Definition of the HTTPRequest class. // Definition of the HTTPRequest class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPRequest_INCLUDED #ifndef Net_HTTPRequest_INCLUDED
#define Net_HTTPRequest_INCLUDED #define Net_HTTPRequest_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPMessage.h" #include "Poco/Net/HTTPMessage.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HTTPRequest: public HTTPMessage class Net_API HTTPRequest: public HTTPMessage
/// This class encapsulates an HTTP request /// This class encapsulates an HTTP request
/// message. /// message.
/// ///
/// In addition to the properties common to /// In addition to the properties common to
/// all HTTP messages, a HTTP request has /// all HTTP messages, a HTTP request has
/// a method (e.g. GET, HEAD, POST, etc.) and /// a method (e.g. GET, HEAD, POST, etc.) and
/// a request URI. /// a request URI.
{ {
public: public:
HTTPRequest(); HTTPRequest();
/// Creates a GET / HTTP/1.0 HTTP request. /// Creates a GET / HTTP/1.0 HTTP request.
HTTPRequest(const std::string& version); HTTPRequest(const std::string& version);
/// Creates a GET / HTTP/1.x request with /// Creates a GET / HTTP/1.x request with
/// the given version (HTTP/1.0 or HTTP/1.1). /// the given version (HTTP/1.0 or HTTP/1.1).
HTTPRequest(const std::string& method, const std::string& uri); HTTPRequest(const std::string& method, const std::string& uri);
/// Creates a HTTP/1.0 request with the given method and URI. /// Creates a HTTP/1.0 request with the given method and URI.
HTTPRequest(const std::string& method, const std::string& uri, const std::string& version); HTTPRequest(const std::string& method, const std::string& uri, const std::string& version);
/// Creates a HTTP request with the given method, URI and version. /// Creates a HTTP request with the given method, URI and version.
virtual ~HTTPRequest(); virtual ~HTTPRequest();
/// Destroys the HTTPRequest. /// Destroys the HTTPRequest.
void setMethod(const std::string& method); void setMethod(const std::string& method);
/// Sets the method. /// Sets the method.
const std::string& getMethod() const; const std::string& getMethod() const;
/// Returns the method. /// Returns the method.
void setURI(const std::string& uri); void setURI(const std::string& uri);
/// Sets the request URI. /// Sets the request URI.
const std::string& getURI() const; const std::string& getURI() const;
/// Returns the request URI. /// Returns the request URI.
void setHost(const std::string& host); void setHost(const std::string& host);
/// Sets the value of the Host header field. /// Sets the value of the Host header field.
void setHost(const std::string& host, Poco::UInt16 port); void setHost(const std::string& host, Poco::UInt16 port);
/// Sets the value of the Host header field. /// Sets the value of the Host header field.
const std::string& getHost() const; const std::string& getHost() const;
/// Returns the value of the Host header field. /// Returns the value of the Host header field.
/// ///
/// Throws a NotFoundException if the request /// Throws a NotFoundException if the request
/// does not have a Host header field. /// does not have a Host header field.
void setCookies(const NameValueCollection& cookies); void setCookies(const NameValueCollection& cookies);
/// Adds a Cookie header with the names and /// Adds a Cookie header with the names and
/// values from cookies. /// values from cookies.
void getCookies(NameValueCollection& cookies) const; void getCookies(NameValueCollection& cookies) const;
/// Fills cookies with the cookies extracted /// Fills cookies with the cookies extracted
/// from the Cookie headers in the request. /// from the Cookie headers in the request.
bool hasCredentials() const; bool hasCredentials() const;
/// Returns true iff the request contains authentication /// Returns true iff the request contains authentication
/// information in the form of an Authorization header. /// information in the form of an Authorization header.
void getCredentials(std::string& scheme, std::string& authInfo) const; void getCredentials(std::string& scheme, std::string& authInfo) const;
/// Returns the authentication scheme and additional authentication /// Returns the authentication scheme and additional authentication
/// information contained in this request. /// information contained in this request.
/// ///
/// Throws a NotAuthenticatedException if no authentication information /// Throws a NotAuthenticatedException if no authentication information
/// is contained in the request. /// is contained in the request.
void setCredentials(const std::string& scheme, const std::string& authInfo); void setCredentials(const std::string& scheme, const std::string& authInfo);
/// Sets the authentication scheme and information for /// Sets the authentication scheme and information for
/// this request. /// this request.
void write(std::ostream& ostr) const; void write(std::ostream& ostr) const;
/// Writes the HTTP request to the given /// Writes the HTTP request to the given
/// output stream. /// output stream.
void read(std::istream& istr); void read(std::istream& istr);
/// Reads the HTTP request from the /// Reads the HTTP request from the
/// given input stream. /// given input stream.
static const std::string HTTP_GET; static const std::string HTTP_GET;
static const std::string HTTP_HEAD; static const std::string HTTP_HEAD;
static const std::string HTTP_PUT; static const std::string HTTP_PUT;
static const std::string HTTP_POST; static const std::string HTTP_POST;
static const std::string HTTP_OPTIONS; static const std::string HTTP_OPTIONS;
static const std::string HTTP_DELETE; static const std::string HTTP_DELETE;
static const std::string HTTP_TRACE; static const std::string HTTP_TRACE;
static const std::string HTTP_CONNECT; static const std::string HTTP_CONNECT;
static const std::string HOST; static const std::string HOST;
static const std::string COOKIE; static const std::string COOKIE;
static const std::string AUTHORIZATION; static const std::string AUTHORIZATION;
private: private:
enum Limits enum Limits
{ {
MAX_METHOD_LENGTH = 32, MAX_METHOD_LENGTH = 32,
MAX_URI_LENGTH = 4096, MAX_URI_LENGTH = 4096,
MAX_VERSION_LENGTH = 8 MAX_VERSION_LENGTH = 8
}; };
std::string _method; std::string _method;
std::string _uri; std::string _uri;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPRequest::getMethod() const inline const std::string& HTTPRequest::getMethod() const
{ {
return _method; return _method;
} }
inline const std::string& HTTPRequest::getURI() const inline const std::string& HTTPRequest::getURI() const
{ {
return _uri; return _uri;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPRequest_INCLUDED #endif // Net_HTTPRequest_INCLUDED

View File

@ -1,89 +1,89 @@
// //
// HTTPRequestHandler.h // HTTPRequestHandler.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequestHandler.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequestHandler.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPRequestHandler // Module: HTTPRequestHandler
// //
// Definition of the HTTPRequestHandler class. // Definition of the HTTPRequestHandler class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPRequestHandler_INCLUDED #ifndef Net_HTTPRequestHandler_INCLUDED
#define Net_HTTPRequestHandler_INCLUDED #define Net_HTTPRequestHandler_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerRequest; class HTTPServerRequest;
class HTTPServerResponse; class HTTPServerResponse;
class Net_API HTTPRequestHandler class Net_API HTTPRequestHandler
/// The abstract base class for HTTPRequestHandlers /// The abstract base class for HTTPRequestHandlers
/// created by HTTPServer. /// created by HTTPServer.
/// ///
/// Derived classes must override the handleRequest() method. /// Derived classes must override the handleRequest() method.
/// Furthermore, a HTTPRequestHandlerFactory must be provided. /// Furthermore, a HTTPRequestHandlerFactory must be provided.
/// ///
/// The handleRequest() method must perform the complete handling /// The handleRequest() method must perform the complete handling
/// of the HTTP request connection. As soon as the handleRequest() /// of the HTTP request connection. As soon as the handleRequest()
/// method returns, the request handler object is destroyed. /// method returns, the request handler object is destroyed.
/// ///
/// A new HTTPRequestHandler object will be created for /// A new HTTPRequestHandler object will be created for
/// each new HTTP request that is received by the HTTPServer. /// each new HTTP request that is received by the HTTPServer.
{ {
public: public:
HTTPRequestHandler(); HTTPRequestHandler();
/// Creates the HTTPRequestHandler. /// Creates the HTTPRequestHandler.
virtual ~HTTPRequestHandler(); virtual ~HTTPRequestHandler();
/// Destroys the HTTPRequestHandler. /// Destroys the HTTPRequestHandler.
virtual void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) = 0; virtual void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) = 0;
/// Must be overridden by subclasses. /// Must be overridden by subclasses.
/// ///
/// Handles the given request. /// Handles the given request.
private: private:
HTTPRequestHandler(const HTTPRequestHandler&); HTTPRequestHandler(const HTTPRequestHandler&);
HTTPRequestHandler& operator = (const HTTPRequestHandler&); HTTPRequestHandler& operator = (const HTTPRequestHandler&);
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPRequestHandler_INCLUDED #endif // Net_HTTPRequestHandler_INCLUDED

View File

@ -1,80 +1,80 @@
// //
// HTTPRequestHandlerFactory.h // HTTPRequestHandlerFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequestHandlerFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPRequestHandlerFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPRequestHandlerFactory // Module: HTTPRequestHandlerFactory
// //
// Definition of the HTTPRequestHandlerFactory class. // Definition of the HTTPRequestHandlerFactory class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPRequestHandlerFactory_INCLUDED #ifndef Net_HTTPRequestHandlerFactory_INCLUDED
#define Net_HTTPRequestHandlerFactory_INCLUDED #define Net_HTTPRequestHandlerFactory_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerRequest; class HTTPServerRequest;
class HTTPRequestHandler; class HTTPRequestHandler;
class Net_API HTTPRequestHandlerFactory class Net_API HTTPRequestHandlerFactory
/// A factory for HTTPRequestHandler objects. /// A factory for HTTPRequestHandler objects.
/// Subclasses must override the createRequstHandler() /// Subclasses must override the createRequstHandler()
/// method. /// method.
{ {
public: public:
HTTPRequestHandlerFactory(); HTTPRequestHandlerFactory();
/// Creates the HTTPRequestHandlerFactory. /// Creates the HTTPRequestHandlerFactory.
virtual ~HTTPRequestHandlerFactory(); virtual ~HTTPRequestHandlerFactory();
/// Destroys the HTTPRequestHandlerFactory. /// Destroys the HTTPRequestHandlerFactory.
virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) = 0; virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) = 0;
/// Must be overridden by sublasses. /// Must be overridden by sublasses.
/// ///
/// Creates a new request handler for the given HTTP request. /// Creates a new request handler for the given HTTP request.
private: private:
HTTPRequestHandlerFactory(const HTTPRequestHandlerFactory&); HTTPRequestHandlerFactory(const HTTPRequestHandlerFactory&);
HTTPRequestHandlerFactory& operator = (const HTTPRequestHandlerFactory&); HTTPRequestHandlerFactory& operator = (const HTTPRequestHandlerFactory&);
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPRequestHandlerFactory_INCLUDED #endif // Net_HTTPRequestHandlerFactory_INCLUDED

View File

@ -1,268 +1,268 @@
// //
// HTTPResponse.h // HTTPResponse.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPResponse.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPResponse.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPResponse // Module: HTTPResponse
// //
// Definition of the HTTPResponse class. // Definition of the HTTPResponse class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPResponse_INCLUDED #ifndef Net_HTTPResponse_INCLUDED
#define Net_HTTPResponse_INCLUDED #define Net_HTTPResponse_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPMessage.h" #include "Poco/Net/HTTPMessage.h"
#include "Poco/Net/HTTPCookie.h" #include "Poco/Net/HTTPCookie.h"
#include "Poco/Timestamp.h" #include "Poco/Timestamp.h"
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPCookie; class HTTPCookie;
class Net_API HTTPResponse: public HTTPMessage class Net_API HTTPResponse: public HTTPMessage
/// This class encapsulates an HTTP response /// This class encapsulates an HTTP response
/// message. /// message.
/// ///
/// In addition to the properties common to /// In addition to the properties common to
/// all HTTP messages, a HTTP response has /// all HTTP messages, a HTTP response has
/// status code and a reason phrase. /// status code and a reason phrase.
{ {
public: public:
enum HTTPStatus enum HTTPStatus
{ {
HTTP_CONTINUE = 100, HTTP_CONTINUE = 100,
HTTP_SWITCHING_PROTOCOLS = 101, HTTP_SWITCHING_PROTOCOLS = 101,
HTTP_OK = 200, HTTP_OK = 200,
HTTP_CREATED = 201, HTTP_CREATED = 201,
HTTP_ACCEPTED = 202, HTTP_ACCEPTED = 202,
HTTP_NONAUTHORITATIVE = 203, HTTP_NONAUTHORITATIVE = 203,
HTTP_NO_CONTENT = 204, HTTP_NO_CONTENT = 204,
HTTP_RESET_CONTENT = 205, HTTP_RESET_CONTENT = 205,
HTTP_PARTIAL_CONTENT = 206, HTTP_PARTIAL_CONTENT = 206,
HTTP_MULTIPLE_CHOICES = 300, HTTP_MULTIPLE_CHOICES = 300,
HTTP_MOVED_PERMANENTLY = 301, HTTP_MOVED_PERMANENTLY = 301,
HTTP_FOUND = 302, HTTP_FOUND = 302,
HTTP_SEE_OTHER = 303, HTTP_SEE_OTHER = 303,
HTTP_NOT_MODIFIED = 304, HTTP_NOT_MODIFIED = 304,
HTTP_USEPROXY = 305, HTTP_USEPROXY = 305,
// UNUSED: 306 // UNUSED: 306
HTTP_TEMPORARY_REDIRECT = 307, HTTP_TEMPORARY_REDIRECT = 307,
HTTP_BAD_REQUEST = 400, HTTP_BAD_REQUEST = 400,
HTTP_UNAUTHORIZED = 401, HTTP_UNAUTHORIZED = 401,
HTTP_PAYMENT_REQUIRED = 402, HTTP_PAYMENT_REQUIRED = 402,
HTTP_FORBIDDEN = 403, HTTP_FORBIDDEN = 403,
HTTP_NOT_FOUND = 404, HTTP_NOT_FOUND = 404,
HTTP_METHOD_NOT_ALLOWED = 405, HTTP_METHOD_NOT_ALLOWED = 405,
HTTP_NOT_ACCEPTABLE = 406, HTTP_NOT_ACCEPTABLE = 406,
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407, HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
HTTP_REQUEST_TIMEOUT = 408, HTTP_REQUEST_TIMEOUT = 408,
HTTP_CONFLICT = 409, HTTP_CONFLICT = 409,
HTTP_GONE = 410, HTTP_GONE = 410,
HTTP_LENGTH_REQUIRED = 411, HTTP_LENGTH_REQUIRED = 411,
HTTP_PRECONDITION_FAILED = 412, HTTP_PRECONDITION_FAILED = 412,
HTTP_REQUESTENTITYTOOLARGE = 413, HTTP_REQUESTENTITYTOOLARGE = 413,
HTTP_REQUESTURITOOLONG = 414, HTTP_REQUESTURITOOLONG = 414,
HTTP_UNSUPPORTEDMEDIATYPE = 415, HTTP_UNSUPPORTEDMEDIATYPE = 415,
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416, HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
HTTP_EXPECTATION_FAILED = 417, HTTP_EXPECTATION_FAILED = 417,
HTTP_INTERNAL_SERVER_ERROR = 500, HTTP_INTERNAL_SERVER_ERROR = 500,
HTTP_NOT_IMPLEMENTED = 501, HTTP_NOT_IMPLEMENTED = 501,
HTTP_BAD_GATEWAY = 502, HTTP_BAD_GATEWAY = 502,
HTTP_SERVICE_UNAVAILABLE = 503, HTTP_SERVICE_UNAVAILABLE = 503,
HTTP_GATEWAY_TIMEOUT = 504, HTTP_GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505 HTTP_VERSION_NOT_SUPPORTED = 505
}; };
HTTPResponse(); HTTPResponse();
/// Creates the HTTPResponse with OK status. /// Creates the HTTPResponse with OK status.
HTTPResponse(HTTPStatus status, const std::string& reason); HTTPResponse(HTTPStatus status, const std::string& reason);
/// Creates the HTTPResponse with the given status /// Creates the HTTPResponse with the given status
/// and reason phrase. /// and reason phrase.
HTTPResponse(const std::string& version, HTTPStatus status, const std::string& reason); HTTPResponse(const std::string& version, HTTPStatus status, const std::string& reason);
/// Creates the HTTPResponse with the given version, status /// Creates the HTTPResponse with the given version, status
/// and reason phrase. /// and reason phrase.
HTTPResponse(HTTPStatus status); HTTPResponse(HTTPStatus status);
/// Creates the HTTPResponse with the given status /// Creates the HTTPResponse with the given status
/// an an appropriate reason phrase. /// an an appropriate reason phrase.
HTTPResponse(const std::string& version, HTTPStatus status); HTTPResponse(const std::string& version, HTTPStatus status);
/// Creates the HTTPResponse with the given version, status /// Creates the HTTPResponse with the given version, status
/// an an appropriate reason phrase. /// an an appropriate reason phrase.
virtual ~HTTPResponse(); virtual ~HTTPResponse();
/// Destroys the HTTPResponse. /// Destroys the HTTPResponse.
void setStatus(HTTPStatus status); void setStatus(HTTPStatus status);
/// Sets the HTTP status code. /// Sets the HTTP status code.
/// ///
/// Does not change the reason phrase. /// Does not change the reason phrase.
HTTPStatus getStatus() const; HTTPStatus getStatus() const;
/// Returns the HTTP status code. /// Returns the HTTP status code.
void setStatus(const std::string& status); void setStatus(const std::string& status);
/// Sets the HTTP status code. /// Sets the HTTP status code.
/// ///
/// The string must contain a valid /// The string must contain a valid
/// HTTP numerical status code. /// HTTP numerical status code.
void setReason(const std::string& reason); void setReason(const std::string& reason);
/// Sets the HTTP reason phrase. /// Sets the HTTP reason phrase.
const std::string& getReason() const; const std::string& getReason() const;
/// Returns the HTTP reason phrase. /// Returns the HTTP reason phrase.
void setStatusAndReason(HTTPStatus status, const std::string& reason); void setStatusAndReason(HTTPStatus status, const std::string& reason);
/// Sets the HTTP status code and reason phrase. /// Sets the HTTP status code and reason phrase.
void setStatusAndReason(HTTPStatus status); void setStatusAndReason(HTTPStatus status);
/// Sets the HTTP status code and reason phrase. /// Sets the HTTP status code and reason phrase.
/// ///
/// The reason phrase is set according to the status code. /// The reason phrase is set according to the status code.
void setDate(const Poco::Timestamp& dateTime); void setDate(const Poco::Timestamp& dateTime);
/// Sets the Date header to the given date/time value. /// Sets the Date header to the given date/time value.
Poco::Timestamp getDate() const; Poco::Timestamp getDate() const;
/// Returns the value of the Date header. /// Returns the value of the Date header.
void addCookie(const HTTPCookie& cookie); void addCookie(const HTTPCookie& cookie);
/// Adds the cookie to the response by /// Adds the cookie to the response by
/// adding a Set-Cookie header. /// adding a Set-Cookie header.
void getCookies(std::vector<HTTPCookie>& cookies) const; void getCookies(std::vector<HTTPCookie>& cookies) const;
/// Returns a vector with all the cookies /// Returns a vector with all the cookies
/// set in the response header. /// set in the response header.
/// ///
/// May throw an exception in case of a malformed /// May throw an exception in case of a malformed
/// Set-Cookie header. /// Set-Cookie header.
void write(std::ostream& ostr) const; void write(std::ostream& ostr) const;
/// Writes the HTTP response to the given /// Writes the HTTP response to the given
/// output stream. /// output stream.
void read(std::istream& istr); void read(std::istream& istr);
/// Reads the HTTP response from the /// Reads the HTTP response from the
/// given input stream. /// given input stream.
/// ///
/// 100 Continue responses are ignored. /// 100 Continue responses are ignored.
static const std::string& getReasonForStatus(HTTPStatus status); static const std::string& getReasonForStatus(HTTPStatus status);
/// Returns an appropriate reason phrase /// Returns an appropriate reason phrase
/// for the given status code. /// for the given status code.
static const std::string HTTP_REASON_CONTINUE; static const std::string HTTP_REASON_CONTINUE;
static const std::string HTTP_REASON_SWITCHING_PROTOCOLS; static const std::string HTTP_REASON_SWITCHING_PROTOCOLS;
static const std::string HTTP_REASON_OK; static const std::string HTTP_REASON_OK;
static const std::string HTTP_REASON_CREATED; static const std::string HTTP_REASON_CREATED;
static const std::string HTTP_REASON_ACCEPTED; static const std::string HTTP_REASON_ACCEPTED;
static const std::string HTTP_REASON_NONAUTHORITATIVE; static const std::string HTTP_REASON_NONAUTHORITATIVE;
static const std::string HTTP_REASON_NO_CONTENT; static const std::string HTTP_REASON_NO_CONTENT;
static const std::string HTTP_REASON_RESET_CONTENT; static const std::string HTTP_REASON_RESET_CONTENT;
static const std::string HTTP_REASON_PARTIAL_CONTENT; static const std::string HTTP_REASON_PARTIAL_CONTENT;
static const std::string HTTP_REASON_MULTIPLE_CHOICES; static const std::string HTTP_REASON_MULTIPLE_CHOICES;
static const std::string HTTP_REASON_MOVED_PERMANENTLY; static const std::string HTTP_REASON_MOVED_PERMANENTLY;
static const std::string HTTP_REASON_FOUND; static const std::string HTTP_REASON_FOUND;
static const std::string HTTP_REASON_SEE_OTHER; static const std::string HTTP_REASON_SEE_OTHER;
static const std::string HTTP_REASON_NOT_MODIFIED; static const std::string HTTP_REASON_NOT_MODIFIED;
static const std::string HTTP_REASON_USEPROXY; static const std::string HTTP_REASON_USEPROXY;
static const std::string HTTP_REASON_TEMPORARY_REDIRECT; static const std::string HTTP_REASON_TEMPORARY_REDIRECT;
static const std::string HTTP_REASON_BAD_REQUEST; static const std::string HTTP_REASON_BAD_REQUEST;
static const std::string HTTP_REASON_UNAUTHORIZED; static const std::string HTTP_REASON_UNAUTHORIZED;
static const std::string HTTP_REASON_PAYMENT_REQUIRED; static const std::string HTTP_REASON_PAYMENT_REQUIRED;
static const std::string HTTP_REASON_FORBIDDEN; static const std::string HTTP_REASON_FORBIDDEN;
static const std::string HTTP_REASON_NOT_FOUND; static const std::string HTTP_REASON_NOT_FOUND;
static const std::string HTTP_REASON_METHOD_NOT_ALLOWED; static const std::string HTTP_REASON_METHOD_NOT_ALLOWED;
static const std::string HTTP_REASON_NOT_ACCEPTABLE; static const std::string HTTP_REASON_NOT_ACCEPTABLE;
static const std::string HTTP_REASON_PROXY_AUTHENTICATION_REQUIRED; static const std::string HTTP_REASON_PROXY_AUTHENTICATION_REQUIRED;
static const std::string HTTP_REASON_REQUEST_TIMEOUT; static const std::string HTTP_REASON_REQUEST_TIMEOUT;
static const std::string HTTP_REASON_CONFLICT; static const std::string HTTP_REASON_CONFLICT;
static const std::string HTTP_REASON_GONE; static const std::string HTTP_REASON_GONE;
static const std::string HTTP_REASON_LENGTH_REQUIRED; static const std::string HTTP_REASON_LENGTH_REQUIRED;
static const std::string HTTP_REASON_PRECONDITION_FAILED; static const std::string HTTP_REASON_PRECONDITION_FAILED;
static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE; static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE;
static const std::string HTTP_REASON_REQUESTURITOOLONG; static const std::string HTTP_REASON_REQUESTURITOOLONG;
static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE; static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE;
static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE; static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE;
static const std::string HTTP_REASON_EXPECTATION_FAILED; static const std::string HTTP_REASON_EXPECTATION_FAILED;
static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR; static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR;
static const std::string HTTP_REASON_NOT_IMPLEMENTED; static const std::string HTTP_REASON_NOT_IMPLEMENTED;
static const std::string HTTP_REASON_BAD_GATEWAY; static const std::string HTTP_REASON_BAD_GATEWAY;
static const std::string HTTP_REASON_SERVICE_UNAVAILABLE; static const std::string HTTP_REASON_SERVICE_UNAVAILABLE;
static const std::string HTTP_REASON_GATEWAY_TIMEOUT; static const std::string HTTP_REASON_GATEWAY_TIMEOUT;
static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED; static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED;
static const std::string HTTP_REASON_UNKNOWN; static const std::string HTTP_REASON_UNKNOWN;
static const std::string DATE; static const std::string DATE;
static const std::string SET_COOKIE; static const std::string SET_COOKIE;
private: private:
enum Limits enum Limits
{ {
MAX_VERSION_LENGTH = 8, MAX_VERSION_LENGTH = 8,
MAX_STATUS_LENGTH = 3, MAX_STATUS_LENGTH = 3,
MAX_REASON_LENGTH = 512 MAX_REASON_LENGTH = 512
}; };
HTTPStatus _status; HTTPStatus _status;
std::string _reason; std::string _reason;
}; };
// //
// inlines // inlines
// //
inline HTTPResponse::HTTPStatus HTTPResponse::getStatus() const inline HTTPResponse::HTTPStatus HTTPResponse::getStatus() const
{ {
return _status; return _status;
} }
inline const std::string& HTTPResponse::getReason() const inline const std::string& HTTPResponse::getReason() const
{ {
return _reason; return _reason;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPResponse_INCLUDED #endif // Net_HTTPResponse_INCLUDED

View File

@ -1,106 +1,106 @@
// //
// HTTPServer.h // HTTPServer.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServer.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServer.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServer // Module: HTTPServer
// //
// Definition of the HTTPServer class. // Definition of the HTTPServer class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServer_INCLUDED #ifndef Net_HTTPServer_INCLUDED
#define Net_HTTPServer_INCLUDED #define Net_HTTPServer_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/TCPServer.h" #include "Poco/Net/TCPServer.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPRequestHandlerFactory; class HTTPRequestHandlerFactory;
class HTTPServerParams; class HTTPServerParams;
class Net_API HTTPServer: public TCPServer class Net_API HTTPServer: public TCPServer
/// A subclass of TCPServer that implements a /// A subclass of TCPServer that implements a
/// full-featured multithreaded HTTP server. /// full-featured multithreaded HTTP server.
/// ///
/// A HTTPRequestHandlerFactory must be supplied. /// A HTTPRequestHandlerFactory must be supplied.
/// The ServerSocket must be bound and in listening state. /// The ServerSocket must be bound and in listening state.
/// ///
/// To configure various aspects of the server, a HTTPServerParams /// To configure various aspects of the server, a HTTPServerParams
/// object can be passed to the constructor. /// object can be passed to the constructor.
/// ///
/// The server supports: /// The server supports:
/// - HTTP/1.0 and HTTP/1.1 /// - HTTP/1.0 and HTTP/1.1
/// - automatic handling of persistent connections. /// - automatic handling of persistent connections.
/// - automatic decoding/encoding of request/response message bodies /// - automatic decoding/encoding of request/response message bodies
/// using chunked transfer encoding. /// using chunked transfer encoding.
/// ///
/// Please see the TCPServer class for information about /// Please see the TCPServer class for information about
/// connection and thread handling. /// connection and thread handling.
/// ///
/// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more /// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more
/// information about the HTTP protocol. /// information about the HTTP protocol.
{ {
public: public:
HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket& socket, HTTPServerParams* pParams); HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket& socket, HTTPServerParams* pParams);
/// Creates the HTTPServer, using the given ServerSocket. /// Creates the HTTPServer, using the given ServerSocket.
/// ///
/// The server takes ownership of the HTTPRequstHandlerFactory /// The server takes ownership of the HTTPRequstHandlerFactory
/// and deletes it when it's no longer needed. /// and deletes it when it's no longer needed.
/// ///
/// The server also takes ownership of the HTTPServerParams object. /// The server also takes ownership of the HTTPServerParams object.
/// ///
/// News threads are taken from the default thread pool. /// News threads are taken from the default thread pool.
HTTPServer(HTTPRequestHandlerFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams); HTTPServer(HTTPRequestHandlerFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams);
/// Creates the HTTPServer, using the given ServerSocket. /// Creates the HTTPServer, using the given ServerSocket.
/// ///
/// The server takes ownership of the HTTPRequstHandlerFactory /// The server takes ownership of the HTTPRequstHandlerFactory
/// and deletes it when it's no longer needed. /// and deletes it when it's no longer needed.
/// ///
/// The server also takes ownership of the HTTPServerParams object. /// The server also takes ownership of the HTTPServerParams object.
/// ///
/// News threads are taken from the given thread pool. /// News threads are taken from the given thread pool.
~HTTPServer(); ~HTTPServer();
/// Destroys the HTTPServer and its HTTPRequestHandlerFactory. /// Destroys the HTTPServer and its HTTPRequestHandlerFactory.
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServer_INCLUDED #endif // Net_HTTPServer_INCLUDED

View File

@ -1,78 +1,78 @@
// //
// HTTPServerConnection.h // HTTPServerConnection.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerConnection.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerConnection.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerConnection // Module: HTTPServerConnection
// //
// Definition of the HTTPServerConnection class. // Definition of the HTTPServerConnection class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerConnection_INCLUDED #ifndef Net_HTTPServerConnection_INCLUDED
#define Net_HTTPServerConnection_INCLUDED #define Net_HTTPServerConnection_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnection.h" #include "Poco/Net/TCPServerConnection.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerParams; class HTTPServerParams;
class HTTPRequestHandlerFactory; class HTTPRequestHandlerFactory;
class Net_API HTTPServerConnection: public TCPServerConnection class Net_API HTTPServerConnection: public TCPServerConnection
/// This subclass of TCPServerConnection handles HTTP /// This subclass of TCPServerConnection handles HTTP
/// connections. /// connections.
{ {
public: public:
HTTPServerConnection(const StreamSocket& socket, HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory); HTTPServerConnection(const StreamSocket& socket, HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory);
/// Creates the HTTPServerConnection. /// Creates the HTTPServerConnection.
virtual ~HTTPServerConnection(); virtual ~HTTPServerConnection();
/// Destroys the HTTPServerConnection. /// Destroys the HTTPServerConnection.
void run(); void run();
/// Handles all HTTP requests coming in. /// Handles all HTTP requests coming in.
private: private:
HTTPServerParams* _pParams; HTTPServerParams* _pParams;
HTTPRequestHandlerFactory* _pFactory; HTTPRequestHandlerFactory* _pFactory;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerConnection_INCLUDED #endif // Net_HTTPServerConnection_INCLUDED

View File

@ -1,79 +1,79 @@
// //
// HTTPServerConnectionFactory.h // HTTPServerConnectionFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerConnectionFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerConnectionFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerConnectionFactory // Module: HTTPServerConnectionFactory
// //
// Definition of the HTTPServerConnectionFactory class. // Definition of the HTTPServerConnectionFactory class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerConnectionFactory_INCLUDED #ifndef Net_HTTPServerConnectionFactory_INCLUDED
#define Net_HTTPServerConnectionFactory_INCLUDED #define Net_HTTPServerConnectionFactory_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnectionFactory.h" #include "Poco/Net/TCPServerConnectionFactory.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerParams; class HTTPServerParams;
class HTTPRequestHandlerFactory; class HTTPRequestHandlerFactory;
class Net_API HTTPServerConnectionFactory: public TCPServerConnectionFactory class Net_API HTTPServerConnectionFactory: public TCPServerConnectionFactory
/// This implementation of a TCPServerConnectionFactory /// This implementation of a TCPServerConnectionFactory
/// is used by HTTPServer to create HTTPServerConnection objects. /// is used by HTTPServer to create HTTPServerConnection objects.
{ {
public: public:
HTTPServerConnectionFactory(HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory); HTTPServerConnectionFactory(HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory);
/// Creates the HTTPServerConnectionFactory. /// Creates the HTTPServerConnectionFactory.
~HTTPServerConnectionFactory(); ~HTTPServerConnectionFactory();
/// Destroys the HTTPServerConnectionFactory. /// Destroys the HTTPServerConnectionFactory.
TCPServerConnection* createConnection(const StreamSocket& socket); TCPServerConnection* createConnection(const StreamSocket& socket);
/// Creates an instance of HTTPServerConnection /// Creates an instance of HTTPServerConnection
/// using the given StreamSocket. /// using the given StreamSocket.
private: private:
HTTPServerParams* _pParams; HTTPServerParams* _pParams;
HTTPRequestHandlerFactory* _pFactory; HTTPRequestHandlerFactory* _pFactory;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerConnectionFactory_INCLUDED #endif // Net_HTTPServerConnectionFactory_INCLUDED

View File

@ -1,174 +1,174 @@
// //
// HTTPServerParams.h // HTTPServerParams.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerParams.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerParams.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerParams // Module: HTTPServerParams
// //
// Definition of the HTTPServerParams class. // Definition of the HTTPServerParams class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerParams_INCLUDED #ifndef Net_HTTPServerParams_INCLUDED
#define Net_HTTPServerParams_INCLUDED #define Net_HTTPServerParams_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerParams.h" #include "Poco/Net/TCPServerParams.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HTTPServerParams: public TCPServerParams class Net_API HTTPServerParams: public TCPServerParams
/// This class is used to specify parameters to both the /// This class is used to specify parameters to both the
/// HTTPServer, as well as to HTTPRequestHandler objects. /// HTTPServer, as well as to HTTPRequestHandler objects.
/// ///
/// Subclasses may add new parameters to the class. /// Subclasses may add new parameters to the class.
{ {
public: public:
HTTPServerParams(); HTTPServerParams();
/// Creates the HTTPServerParams. /// Creates the HTTPServerParams.
/// ///
/// Sets the following default values: /// Sets the following default values:
/// - timeout: 60 seconds /// - timeout: 60 seconds
/// - keepAlive: true /// - keepAlive: true
/// - maxKeepAliveRequests: 0 /// - maxKeepAliveRequests: 0
/// - keepAliveTimeout: 10 seconds /// - keepAliveTimeout: 10 seconds
void setServerName(const std::string& serverName); void setServerName(const std::string& serverName);
/// Sets the name and port (name:port) that the server uses to identify itself. /// Sets the name and port (name:port) that the server uses to identify itself.
/// ///
/// If this is not set to valid DNS name for your host, server-generated /// If this is not set to valid DNS name for your host, server-generated
/// redirections will not work. /// redirections will not work.
const std::string& getServerName() const; const std::string& getServerName() const;
/// Returns the name and port (name:port) that the server uses to identify itself. /// Returns the name and port (name:port) that the server uses to identify itself.
void setSoftwareVersion(const std::string& softwareVersion); void setSoftwareVersion(const std::string& softwareVersion);
/// Sets the server software name and version that the server uses to identify /// Sets the server software name and version that the server uses to identify
/// itself. If this is set to a non-empty string, the server will /// itself. If this is set to a non-empty string, the server will
/// automatically include a Server header field with the value given /// automatically include a Server header field with the value given
/// here in every response it sends. /// here in every response it sends.
/// ///
/// The format of the softwareVersion string should be name/version /// The format of the softwareVersion string should be name/version
/// (e.g. MyHTTPServer/1.0). /// (e.g. MyHTTPServer/1.0).
const std::string& getSoftwareVersion() const; const std::string& getSoftwareVersion() const;
/// Returns the server software name and version that the server uses to /// Returns the server software name and version that the server uses to
/// identify itself. /// identify itself.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the connection timeout for HTTP connections. /// Sets the connection timeout for HTTP connections.
const Poco::Timespan& getTimeout() const; const Poco::Timespan& getTimeout() const;
/// Returns the connection timeout for HTTP connections. /// Returns the connection timeout for HTTP connections.
void setKeepAlive(bool keepAlive); void setKeepAlive(bool keepAlive);
/// Enables (keepAlive == true) or disables (keepAlive == false) /// Enables (keepAlive == true) or disables (keepAlive == false)
/// persistent connections. /// persistent connections.
bool getKeepAlive() const; bool getKeepAlive() const;
/// Returns true iff persistent connections are enabled. /// Returns true iff persistent connections are enabled.
void setKeepAliveTimeout(const Poco::Timespan& timeout); void setKeepAliveTimeout(const Poco::Timespan& timeout);
/// Sets the connection timeout for HTTP connections. /// Sets the connection timeout for HTTP connections.
const Poco::Timespan& getKeepAliveTimeout() const; const Poco::Timespan& getKeepAliveTimeout() const;
/// Returns the connection timeout for HTTP connections. /// Returns the connection timeout for HTTP connections.
void setMaxKeepAliveRequests(int maxKeepAliveRequests); void setMaxKeepAliveRequests(int maxKeepAliveRequests);
/// Specifies the maximun number of requests allowed /// Specifies the maximun number of requests allowed
/// during a persistent connection. 0 means unlimited /// during a persistent connection. 0 means unlimited
/// connections. /// connections.
int getMaxKeepAliveRequests() const; int getMaxKeepAliveRequests() const;
/// Returns the maximum number of requests allowed /// Returns the maximum number of requests allowed
/// during a persistent connection, or 0 if /// during a persistent connection, or 0 if
/// unlimited connections are allowed. /// unlimited connections are allowed.
protected: protected:
virtual ~HTTPServerParams(); virtual ~HTTPServerParams();
/// Destroys the HTTPServerParams. /// Destroys the HTTPServerParams.
private: private:
std::string _serverName; std::string _serverName;
std::string _softwareVersion; std::string _softwareVersion;
Poco::Timespan _timeout; Poco::Timespan _timeout;
bool _keepAlive; bool _keepAlive;
int _maxKeepAliveRequests; int _maxKeepAliveRequests;
Poco::Timespan _keepAliveTimeout; Poco::Timespan _keepAliveTimeout;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPServerParams::getServerName() const inline const std::string& HTTPServerParams::getServerName() const
{ {
return _serverName; return _serverName;
} }
inline const std::string& HTTPServerParams::getSoftwareVersion() const inline const std::string& HTTPServerParams::getSoftwareVersion() const
{ {
return _softwareVersion; return _softwareVersion;
} }
inline const Poco::Timespan& HTTPServerParams::getTimeout() const inline const Poco::Timespan& HTTPServerParams::getTimeout() const
{ {
return _timeout; return _timeout;
} }
inline bool HTTPServerParams::getKeepAlive() const inline bool HTTPServerParams::getKeepAlive() const
{ {
return _keepAlive; return _keepAlive;
} }
inline int HTTPServerParams::getMaxKeepAliveRequests() const inline int HTTPServerParams::getMaxKeepAliveRequests() const
{ {
return _maxKeepAliveRequests; return _maxKeepAliveRequests;
} }
inline const Poco::Timespan& HTTPServerParams::getKeepAliveTimeout() const inline const Poco::Timespan& HTTPServerParams::getKeepAliveTimeout() const
{ {
return _keepAliveTimeout; return _keepAliveTimeout;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerParams_INCLUDED #endif // Net_HTTPServerParams_INCLUDED

View File

@ -1,132 +1,132 @@
// //
// HTTPServerRequest.h // HTTPServerRequest.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerRequest.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerRequest.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerRequest // Module: HTTPServerRequest
// //
// Definition of the HTTPServerRequest class. // Definition of the HTTPServerRequest class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerRequest_INCLUDED #ifndef Net_HTTPServerRequest_INCLUDED
#define Net_HTTPServerRequest_INCLUDED #define Net_HTTPServerRequest_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPRequest.h" #include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include <istream> #include <istream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerSession; class HTTPServerSession;
class HTTPServerParams; class HTTPServerParams;
class Net_API HTTPServerRequest: public HTTPRequest class Net_API HTTPServerRequest: public HTTPRequest
/// This subclass of HTTPRequest is used for /// This subclass of HTTPRequest is used for
/// representing server-side HTTP requests. /// representing server-side HTTP requests.
/// ///
/// A HTTPServerRequest is passed to the /// A HTTPServerRequest is passed to the
/// handleRequest() method of HTTPRequestHandler. /// handleRequest() method of HTTPRequestHandler.
{ {
public: public:
HTTPServerRequest(HTTPServerSession& session, HTTPServerParams* pParams); HTTPServerRequest(HTTPServerSession& session, HTTPServerParams* pParams);
/// Creates the HTTPServerRequest, using the /// Creates the HTTPServerRequest, using the
/// given HTTPServerSession. /// given HTTPServerSession.
~HTTPServerRequest(); ~HTTPServerRequest();
/// Destroys the HTTPServerRequest. /// Destroys the HTTPServerRequest.
std::istream& stream(); std::istream& stream();
/// Returns the input stream for reading /// Returns the input stream for reading
/// the request body. /// the request body.
/// ///
/// The stream is valid until the HTTPServerRequest /// The stream is valid until the HTTPServerRequest
/// object is destroyed. /// object is destroyed.
bool expectContinue() const; bool expectContinue() const;
/// Returns true if the client expects a /// Returns true if the client expects a
/// 100 Continue response. /// 100 Continue response.
const SocketAddress& clientAddress() const; const SocketAddress& clientAddress() const;
/// Returns the client's address. /// Returns the client's address.
const SocketAddress& serverAddress() const; const SocketAddress& serverAddress() const;
/// Returns the server's address. /// Returns the server's address.
const HTTPServerParams& serverParams() const; const HTTPServerParams& serverParams() const;
/// Returns a reference to the server parameters. /// Returns a reference to the server parameters.
private: private:
std::istream* _pStream; std::istream* _pStream;
HTTPServerParams* _pParams; HTTPServerParams* _pParams;
SocketAddress _clientAddress; SocketAddress _clientAddress;
SocketAddress _serverAddress; SocketAddress _serverAddress;
}; };
// //
// inlines // inlines
// //
inline std::istream& HTTPServerRequest::stream() inline std::istream& HTTPServerRequest::stream()
{ {
poco_check_ptr (_pStream); poco_check_ptr (_pStream);
return *_pStream; return *_pStream;
} }
inline const SocketAddress& HTTPServerRequest::clientAddress() const inline const SocketAddress& HTTPServerRequest::clientAddress() const
{ {
return _clientAddress; return _clientAddress;
} }
inline const SocketAddress& HTTPServerRequest::serverAddress() const inline const SocketAddress& HTTPServerRequest::serverAddress() const
{ {
return _serverAddress; return _serverAddress;
} }
inline const HTTPServerParams& HTTPServerRequest::serverParams() const inline const HTTPServerParams& HTTPServerRequest::serverParams() const
{ {
return *_pParams; return *_pParams;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerRequest_INCLUDED #endif // Net_HTTPServerRequest_INCLUDED

View File

@ -1,122 +1,122 @@
// //
// HTTPServerResponse.h // HTTPServerResponse.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerResponse.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerResponse.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerResponse // Module: HTTPServerResponse
// //
// Definition of the HTTPServerResponse class. // Definition of the HTTPServerResponse class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerResponse_INCLUDED #ifndef Net_HTTPServerResponse_INCLUDED
#define Net_HTTPServerResponse_INCLUDED #define Net_HTTPServerResponse_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPResponse.h"
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerSession; class HTTPServerSession;
class HTTPCookie; class HTTPCookie;
class Net_API HTTPServerResponse: public HTTPResponse class Net_API HTTPServerResponse: public HTTPResponse
/// This subclass of HTTPResponse is used for /// This subclass of HTTPResponse is used for
/// representing server-side HTTP responses. /// representing server-side HTTP responses.
/// ///
/// A HTTPServerResponse is passed to the /// A HTTPServerResponse is passed to the
/// handleRequest() method of HTTPRequestHandler. /// handleRequest() method of HTTPRequestHandler.
/// ///
/// handleRequest() must set a status code /// handleRequest() must set a status code
/// and optional reason phrase, set headers /// and optional reason phrase, set headers
/// as necessary, and provide a message body. /// as necessary, and provide a message body.
{ {
public: public:
HTTPServerResponse(HTTPServerSession& session); HTTPServerResponse(HTTPServerSession& session);
/// Creates the HTTPServerResponse. /// Creates the HTTPServerResponse.
~HTTPServerResponse(); ~HTTPServerResponse();
/// Destroys the HTTPServerResponse. /// Destroys the HTTPServerResponse.
void sendContinue(); void sendContinue();
/// Sends a 100 Continue response to the /// Sends a 100 Continue response to the
/// client. /// client.
std::ostream& send(); std::ostream& send();
/// Sends the response header to the client and /// Sends the response header to the client and
/// returns an output stream for sending the /// returns an output stream for sending the
/// response body. /// response body.
/// ///
/// The returned stream is valid until the response /// The returned stream is valid until the response
/// object is destroyed. /// object is destroyed.
/// ///
/// Must not be called after sendFile() or redirect() /// Must not be called after sendFile() or redirect()
/// has been called. /// has been called.
void sendFile(const std::string& path, const std::string& mediaType); void sendFile(const std::string& path, const std::string& mediaType);
/// Sends the response header to the client, followed /// Sends the response header to the client, followed
/// by the content of the given file. /// by the content of the given file.
/// ///
/// Must not be called after send() or redirect() /// Must not be called after send() or redirect()
/// has been called. /// has been called.
/// ///
/// Throws a FileNotFoundException if the file /// Throws a FileNotFoundException if the file
/// cannot be found, or an OpenFileException if /// cannot be found, or an OpenFileException if
/// the file cannot be opened. /// the file cannot be opened.
void redirect(const std::string& uri); void redirect(const std::string& uri);
/// Sets the status code to 302 (Found) /// Sets the status code to 302 (Found)
/// and sets the "Location" header field /// and sets the "Location" header field
/// to the given URI, which according to /// to the given URI, which according to
/// the HTTP specification, must be absolute. /// the HTTP specification, must be absolute.
/// ///
/// Must not be called after send() has been called. /// Must not be called after send() has been called.
void requireAuthentication(const std::string& realm); void requireAuthentication(const std::string& realm);
/// Sets the status code to 401 (Unauthorized) /// Sets the status code to 401 (Unauthorized)
/// and sets the "WWW-Authenticate" header field /// and sets the "WWW-Authenticate" header field
/// according to the given realm. /// according to the given realm.
private: private:
HTTPServerSession& _session; HTTPServerSession& _session;
std::ostream* _pStream; std::ostream* _pStream;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerResponse_INCLUDED #endif // Net_HTTPServerResponse_INCLUDED

View File

@ -1,87 +1,87 @@
// //
// HTTPServerSession.h // HTTPServerSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPServerSession.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
// Module: HTTPServerSession // Module: HTTPServerSession
// //
// Definition of the HTTPServerSession class. // Definition of the HTTPServerSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPServerSession_INCLUDED #ifndef Net_HTTPServerSession_INCLUDED
#define Net_HTTPServerSession_INCLUDED #define Net_HTTPServerSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPSession.h" #include "Poco/Net/HTTPSession.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPServerParams; class HTTPServerParams;
class Net_API HTTPServerSession: public HTTPSession class Net_API HTTPServerSession: public HTTPSession
/// This class handles the server side of a /// This class handles the server side of a
/// HTTP session. It is used internally by /// HTTP session. It is used internally by
/// HTTPServer. /// HTTPServer.
{ {
public: public:
HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams); HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams);
/// Creates the HTTPServerSession. /// Creates the HTTPServerSession.
virtual ~HTTPServerSession(); virtual ~HTTPServerSession();
/// Destroys the HTTPServerSession. /// Destroys the HTTPServerSession.
bool hasMoreRequests(); bool hasMoreRequests();
/// Returns true if there are requests available. /// Returns true if there are requests available.
SocketAddress clientAddress(); SocketAddress clientAddress();
/// Returns the client's address. /// Returns the client's address.
SocketAddress serverAddress(); SocketAddress serverAddress();
/// Returns the server's address. /// Returns the server's address.
private: private:
bool _firstRequest; bool _firstRequest;
Poco::Timespan _keepAliveTimeout; Poco::Timespan _keepAliveTimeout;
int _maxKeepAliveRequests; int _maxKeepAliveRequests;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPServerSession_INCLUDED #endif // Net_HTTPServerSession_INCLUDED

View File

@ -1,214 +1,214 @@
// //
// HTTPSession.h // HTTPSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPSession.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPSession // Module: HTTPSession
// //
// Definition of the HTTPSession class. // Definition of the HTTPSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPSession_INCLUDED #ifndef Net_HTTPSession_INCLUDED
#define Net_HTTPSession_INCLUDED #define Net_HTTPSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <ios> #include <ios>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HTTPSession class Net_API HTTPSession
/// HTTPSession implements basic HTTP session management /// HTTPSession implements basic HTTP session management
/// for both HTTP clients and HTTP servers. /// for both HTTP clients and HTTP servers.
/// ///
/// HTTPSession implements buffering for HTTP connections, as well /// HTTPSession implements buffering for HTTP connections, as well
/// as specific support for the various HTTP stream classes. /// as specific support for the various HTTP stream classes.
/// ///
/// This class can not be instantiated. HTTPClientSession or /// This class can not be instantiated. HTTPClientSession or
/// HTTPServerSession must be used instead. /// HTTPServerSession must be used instead.
{ {
public: public:
void setKeepAlive(bool keepAlive); void setKeepAlive(bool keepAlive);
/// Sets the keep-alive flag for this session. /// Sets the keep-alive flag for this session.
/// ///
/// If the keep-alive flag is enabled, persistent /// If the keep-alive flag is enabled, persistent
/// HTTP/1.1 connections are supported. /// HTTP/1.1 connections are supported.
bool getKeepAlive() const; bool getKeepAlive() const;
/// Returns the value of the keep-alive flag for /// Returns the value of the keep-alive flag for
/// this session. /// this session.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the timeout for the HTTP session. /// Sets the timeout for the HTTP session.
Poco::Timespan getTimeout() const; Poco::Timespan getTimeout() const;
/// Returns the timeout for the HTTP session. /// Returns the timeout for the HTTP session.
bool connected() const; bool connected() const;
/// Returns true if the underlying socket is connected. /// Returns true if the underlying socket is connected.
void abort(); void abort();
/// Aborts a session in progress by shutting down /// Aborts a session in progress by shutting down
/// and closing the underlying socket. /// and closing the underlying socket.
const Poco::Exception* networkException() const; const Poco::Exception* networkException() const;
/// If sending or receiving data over the underlying /// If sending or receiving data over the underlying
/// socket connection resulted in an exception, a /// socket connection resulted in an exception, a
/// pointer to this exception is returned. /// pointer to this exception is returned.
/// ///
/// Otherwise, NULL is returned. /// Otherwise, NULL is returned.
enum enum
{ {
HTTP_PORT = 80 HTTP_PORT = 80
}; };
protected: protected:
HTTPSession(); HTTPSession();
/// Creates a HTTP session using an /// Creates a HTTP session using an
/// unconnected stream socket. /// unconnected stream socket.
HTTPSession(const StreamSocket& socket); HTTPSession(const StreamSocket& socket);
/// Creates a HTTP session using the /// Creates a HTTP session using the
/// given socket. The session takes ownership /// given socket. The session takes ownership
/// of the socket and closes it when it's no /// of the socket and closes it when it's no
/// longer used. /// longer used.
HTTPSession(const StreamSocket& socket, bool keepAlive); HTTPSession(const StreamSocket& socket, bool keepAlive);
/// Creates a HTTP session using the /// Creates a HTTP session using the
/// given socket. The session takes ownership /// given socket. The session takes ownership
/// of the socket and closes it when it's no /// of the socket and closes it when it's no
/// longer used. /// longer used.
virtual ~HTTPSession(); virtual ~HTTPSession();
/// Destroys the HTTPSession and closes the /// Destroys the HTTPSession and closes the
/// underlying socket. /// underlying socket.
int get(); int get();
/// Returns the next byte in the buffer. /// Returns the next byte in the buffer.
/// Reads more data from the socket if there are /// Reads more data from the socket if there are
/// no bytes left in the buffer. /// no bytes left in the buffer.
int peek(); int peek();
/// Peeks at the next character in the buffer. /// Peeks at the next character in the buffer.
/// Reads more data from the socket if there are /// Reads more data from the socket if there are
/// no bytes left in the buffer. /// no bytes left in the buffer.
virtual int read(char* buffer, std::streamsize length); virtual int read(char* buffer, std::streamsize length);
/// Reads up to length bytes. /// Reads up to length bytes.
/// ///
/// If there is data in the buffer, this data /// If there is data in the buffer, this data
/// is returned. Otherwise, data is read from /// is returned. Otherwise, data is read from
/// the socket to avoid unnecessary buffering. /// the socket to avoid unnecessary buffering.
virtual int write(const char* buffer, std::streamsize length); virtual int write(const char* buffer, std::streamsize length);
/// Writes data to the socket. /// Writes data to the socket.
int receive(char* buffer, int length); int receive(char* buffer, int length);
/// Reads up to length bytes. /// Reads up to length bytes.
StreamSocket& socket(); StreamSocket& socket();
/// Returns a reference to the underlying socket. /// Returns a reference to the underlying socket.
void refill(); void refill();
/// Refills the internal buffer. /// Refills the internal buffer.
virtual void connect(const SocketAddress& address); virtual void connect(const SocketAddress& address);
/// Connects the underlying socket to the given address /// Connects the underlying socket to the given address
/// and sets the socket's receive timeout. /// and sets the socket's receive timeout.
void close(); void close();
/// Closes the underlying socket. /// Closes the underlying socket.
void setException(const Poco::Exception& exc); void setException(const Poco::Exception& exc);
/// Stores a clone of the exception. /// Stores a clone of the exception.
private: private:
enum enum
{ {
HTTP_DEFAULT_TIMEOUT = 60000000 HTTP_DEFAULT_TIMEOUT = 60000000
}; };
HTTPSession(const HTTPSession&); HTTPSession(const HTTPSession&);
HTTPSession& operator = (const HTTPSession&); HTTPSession& operator = (const HTTPSession&);
StreamSocket _socket; StreamSocket _socket;
char* _pBuffer; char* _pBuffer;
char* _pCurrent; char* _pCurrent;
char* _pEnd; char* _pEnd;
bool _keepAlive; bool _keepAlive;
Poco::Timespan _timeout; Poco::Timespan _timeout;
Poco::Exception* _pException; Poco::Exception* _pException;
friend class HTTPStreamBuf; friend class HTTPStreamBuf;
friend class HTTPHeaderStreamBuf; friend class HTTPHeaderStreamBuf;
friend class HTTPFixedLengthStreamBuf; friend class HTTPFixedLengthStreamBuf;
friend class HTTPChunkedStreamBuf; friend class HTTPChunkedStreamBuf;
}; };
// //
// inlines // inlines
// //
inline bool HTTPSession::getKeepAlive() const inline bool HTTPSession::getKeepAlive() const
{ {
return _keepAlive; return _keepAlive;
} }
inline Poco::Timespan HTTPSession::getTimeout() const inline Poco::Timespan HTTPSession::getTimeout() const
{ {
return _timeout; return _timeout;
} }
inline StreamSocket& HTTPSession::socket() inline StreamSocket& HTTPSession::socket()
{ {
return _socket; return _socket;
} }
inline const Poco::Exception* HTTPSession::networkException() const inline const Poco::Exception* HTTPSession::networkException() const
{ {
return _pException; return _pException;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPSession_INCLUDED #endif // Net_HTTPSession_INCLUDED

View File

@ -1,154 +1,154 @@
// //
// HTTPSessionFactory.h // HTTPSessionFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPSessionFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPSessionFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPClient // Package: HTTPClient
// Module: HTTPSessionFactory // Module: HTTPSessionFactory
// //
// Definition of the HTTPSessionFactory class. // Definition of the HTTPSessionFactory class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPSessionFactoryMgr_INCLUDED #ifndef Net_HTTPSessionFactoryMgr_INCLUDED
#define Net_HTTPSessionFactoryMgr_INCLUDED #define Net_HTTPSessionFactoryMgr_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include "Poco/URI.h" #include "Poco/URI.h"
#include "Poco/SingletonHolder.h" #include "Poco/SingletonHolder.h"
#include "Poco/SharedPtr.h" #include "Poco/SharedPtr.h"
#include <map> #include <map>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPSessionInstantiator; class HTTPSessionInstantiator;
class HTTPClientSession; class HTTPClientSession;
class Net_API HTTPSessionFactory class Net_API HTTPSessionFactory
/// A factory for HTTPClientSession objects. /// A factory for HTTPClientSession objects.
/// ///
/// Given a URI, this class creates a HTTPClientSession /// Given a URI, this class creates a HTTPClientSession
/// (for http) or a HTTPSClientSession (for https) for /// (for http) or a HTTPSClientSession (for https) for
/// accessing the URI. /// accessing the URI.
/// ///
/// The actual work of creating the session is done by /// The actual work of creating the session is done by
/// HTTPSessionInstantiator objects that must be registered /// HTTPSessionInstantiator objects that must be registered
/// with a HTTPSessionFactory. /// with a HTTPSessionFactory.
{ {
public: public:
HTTPSessionFactory(); HTTPSessionFactory();
/// Creates the HTTPSessionFactory. /// Creates the HTTPSessionFactory.
HTTPSessionFactory(const std::string& proxyHost, Poco::UInt16 proxyPort); HTTPSessionFactory(const std::string& proxyHost, Poco::UInt16 proxyPort);
/// Creates the HTTPSessionFactory and sets the proxy host and port. /// Creates the HTTPSessionFactory and sets the proxy host and port.
~HTTPSessionFactory(); ~HTTPSessionFactory();
/// Destroys the HTTPSessionFactory. /// Destroys the HTTPSessionFactory.
void registerProtocol(const std::string& protocol, HTTPSessionInstantiator* pSessionInstantiator); void registerProtocol(const std::string& protocol, HTTPSessionInstantiator* pSessionInstantiator);
/// Registers the session instantiator for the given protocol. /// Registers the session instantiator for the given protocol.
/// The factory takes ownership of the SessionInstantiator. /// The factory takes ownership of the SessionInstantiator.
/// ///
/// A protocol can be registered more than once. However, only the instantiator /// A protocol can be registered more than once. However, only the instantiator
/// that has been registered first is used. Also, for each call to /// that has been registered first is used. Also, for each call to
/// registerProtocol(), a corresponding call to unregisterProtocol() must /// registerProtocol(), a corresponding call to unregisterProtocol() must
/// be made. /// be made.
void unregisterProtocol(const std::string& protocol); void unregisterProtocol(const std::string& protocol);
/// Removes the registration of a protocol. /// Removes the registration of a protocol.
/// ///
/// Throws a NotFoundException if no instantiator has been registered /// Throws a NotFoundException if no instantiator has been registered
/// for the given protocol. /// for the given protocol.
bool supportsProtocol(const std::string& protocol); bool supportsProtocol(const std::string& protocol);
/// Returns true if a session instantiator for the given protocol has been registered. /// Returns true if a session instantiator for the given protocol has been registered.
HTTPClientSession* createClientSession(const Poco::URI& uri); HTTPClientSession* createClientSession(const Poco::URI& uri);
/// Creates a client session for the given uri scheme. Throws exception if no factory is registered for the given scheme /// Creates a client session for the given uri scheme. Throws exception if no factory is registered for the given scheme
const std::string& proxyHost() const; const std::string& proxyHost() const;
/// Returns the proxy host, if one has been set, or an empty string otherwise. /// Returns the proxy host, if one has been set, or an empty string otherwise.
Poco::UInt16 proxyPort() const; Poco::UInt16 proxyPort() const;
/// Returns the proxy port number, if one has been set, or zero otherwise. /// Returns the proxy port number, if one has been set, or zero otherwise.
void setProxy(const std::string& proxyHost, Poco::UInt16 proxyPort); void setProxy(const std::string& proxyHost, Poco::UInt16 proxyPort);
/// Sets the proxy host and port number. /// Sets the proxy host and port number.
static HTTPSessionFactory& defaultFactory(); static HTTPSessionFactory& defaultFactory();
/// Returns the default HTTPSessionFactory. /// Returns the default HTTPSessionFactory.
private: private:
struct InstantiatorInfo struct InstantiatorInfo
{ {
HTTPSessionInstantiator* pIn; HTTPSessionInstantiator* pIn;
int cnt; int cnt;
InstantiatorInfo(HTTPSessionInstantiator* pInst); InstantiatorInfo(HTTPSessionInstantiator* pInst);
// no destructor!!! this is by purpose, don't add one! // no destructor!!! this is by purpose, don't add one!
}; };
HTTPSessionFactory(const HTTPSessionFactory&); HTTPSessionFactory(const HTTPSessionFactory&);
HTTPSessionFactory& operator = (const HTTPSessionFactory&); HTTPSessionFactory& operator = (const HTTPSessionFactory&);
typedef std::map<std::string, InstantiatorInfo> Instantiators; typedef std::map<std::string, InstantiatorInfo> Instantiators;
Instantiators _instantiators; Instantiators _instantiators;
std::string _proxyHost; std::string _proxyHost;
Poco::UInt16 _proxyPort; Poco::UInt16 _proxyPort;
mutable Poco::FastMutex _mutex; mutable Poco::FastMutex _mutex;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPSessionFactory::proxyHost() const inline const std::string& HTTPSessionFactory::proxyHost() const
{ {
return _proxyHost; return _proxyHost;
} }
inline Poco::UInt16 HTTPSessionFactory::proxyPort() const inline Poco::UInt16 HTTPSessionFactory::proxyPort() const
{ {
return _proxyPort; return _proxyPort;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPSessionFactoryMgr_INCLUDED #endif // Net_HTTPSessionFactoryMgr_INCLUDED

View File

@ -1,116 +1,116 @@
// //
// HTTPSessionInstantiator.h // HTTPSessionInstantiator.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPSessionInstantiator.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPSessionInstantiator.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTPClient // Package: HTTPClient
// Module: HTTPSessionInstantiator // Module: HTTPSessionInstantiator
// //
// Definition of the HTTPSessionInstantiator class. // Definition of the HTTPSessionInstantiator class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPSessionInstantiator_INCLUDED #ifndef Net_HTTPSessionInstantiator_INCLUDED
#define Net_HTTPSessionInstantiator_INCLUDED #define Net_HTTPSessionInstantiator_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPSession.h" #include "Poco/Net/HTTPSession.h"
#include "Poco/URI.h" #include "Poco/URI.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPClientSession; class HTTPClientSession;
class Net_API HTTPSessionInstantiator class Net_API HTTPSessionInstantiator
/// A factory for HTTPClientSession objects. /// A factory for HTTPClientSession objects.
/// ///
/// Creates a HTTP session for a given URI. /// Creates a HTTP session for a given URI.
/// A HTTPSessionInstantiator is not used directly. /// A HTTPSessionInstantiator is not used directly.
/// Instances are registered with a HTTPSessionFactory, /// Instances are registered with a HTTPSessionFactory,
/// and used through it. /// and used through it.
{ {
public: public:
HTTPSessionInstantiator(); HTTPSessionInstantiator();
/// Creates the HTTPSessionInstantiator. /// Creates the HTTPSessionInstantiator.
virtual ~HTTPSessionInstantiator(); virtual ~HTTPSessionInstantiator();
/// Destroys the HTTPSessionInstantiator. /// Destroys the HTTPSessionInstantiator.
virtual HTTPClientSession* createClientSession(const Poco::URI& uri); virtual HTTPClientSession* createClientSession(const Poco::URI& uri);
/// Creates a HTTPClientSession for the given URI. /// Creates a HTTPClientSession for the given URI.
static void registerInstantiator(); static void registerInstantiator();
/// Registers the instantiator with the global HTTPSessionFactory. /// Registers the instantiator with the global HTTPSessionFactory.
static void unregisterInstantiator(); static void unregisterInstantiator();
/// Unregisters the factory with the global HTTPSessionFactory. /// Unregisters the factory with the global HTTPSessionFactory.
protected: protected:
void setProxy(const std::string& host, Poco::UInt16 port); void setProxy(const std::string& host, Poco::UInt16 port);
/// Sets the proxy host and port. /// Sets the proxy host and port.
/// Called by HTTPSessionFactory. /// Called by HTTPSessionFactory.
const std::string& proxyHost() const; const std::string& proxyHost() const;
/// Returns the proxy post. /// Returns the proxy post.
Poco::UInt16 proxyPort() const; Poco::UInt16 proxyPort() const;
/// Returns the proxy port. /// Returns the proxy port.
private: private:
std::string _proxyHost; std::string _proxyHost;
Poco::UInt16 _proxyPort; Poco::UInt16 _proxyPort;
friend class HTTPSessionFactory; friend class HTTPSessionFactory;
}; };
// //
// inlines // inlines
// //
inline const std::string& HTTPSessionInstantiator::proxyHost() const inline const std::string& HTTPSessionInstantiator::proxyHost() const
{ {
return _proxyHost; return _proxyHost;
} }
inline Poco::UInt16 HTTPSessionInstantiator::proxyPort() const inline Poco::UInt16 HTTPSessionInstantiator::proxyPort() const
{ {
return _proxyPort; return _proxyPort;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPSessionInstantiator_INCLUDED #endif // Net_HTTPSessionInstantiator_INCLUDED

View File

@ -1,124 +1,124 @@
// //
// HTTPStream.h // HTTPStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPStream.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPStream // Module: HTTPStream
// //
// Definition of the HTTPStream class. // Definition of the HTTPStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPStream_INCLUDED #ifndef Net_HTTPStream_INCLUDED
#define Net_HTTPStream_INCLUDED #define Net_HTTPStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPBasicStreamBuf.h" #include "Poco/Net/HTTPBasicStreamBuf.h"
#include "Poco/MemoryPool.h" #include "Poco/MemoryPool.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class HTTPSession; class HTTPSession;
class Net_API HTTPStreamBuf: public HTTPBasicStreamBuf class Net_API HTTPStreamBuf: public HTTPBasicStreamBuf
/// This is the streambuf class used for reading and writing /// This is the streambuf class used for reading and writing
/// HTTP message bodies. /// HTTP message bodies.
{ {
public: public:
typedef HTTPBasicStreamBuf::openmode openmode; typedef HTTPBasicStreamBuf::openmode openmode;
HTTPStreamBuf(HTTPSession& session, openmode mode); HTTPStreamBuf(HTTPSession& session, openmode mode);
~HTTPStreamBuf(); ~HTTPStreamBuf();
void close(); void close();
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length); int writeToDevice(const char* buffer, std::streamsize length);
private: private:
HTTPSession& _session; HTTPSession& _session;
openmode _mode; openmode _mode;
}; };
class Net_API HTTPIOS: public virtual std::ios class Net_API HTTPIOS: public virtual std::ios
/// The base class for HTTPInputStream. /// The base class for HTTPInputStream.
{ {
public: public:
HTTPIOS(HTTPSession& session, HTTPStreamBuf::openmode mode); HTTPIOS(HTTPSession& session, HTTPStreamBuf::openmode mode);
~HTTPIOS(); ~HTTPIOS();
HTTPStreamBuf* rdbuf(); HTTPStreamBuf* rdbuf();
protected: protected:
HTTPStreamBuf _buf; HTTPStreamBuf _buf;
}; };
class Net_API HTTPInputStream: public HTTPIOS, public std::istream class Net_API HTTPInputStream: public HTTPIOS, public std::istream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPInputStream(HTTPSession& session); HTTPInputStream(HTTPSession& session);
~HTTPInputStream(); ~HTTPInputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
class Net_API HTTPOutputStream: public HTTPIOS, public std::ostream class Net_API HTTPOutputStream: public HTTPIOS, public std::ostream
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPOutputStream(HTTPSession& session); HTTPOutputStream(HTTPSession& session);
~HTTPOutputStream(); ~HTTPOutputStream();
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void* ptr); void operator delete(void* ptr);
private: private:
static Poco::MemoryPool _pool; static Poco::MemoryPool _pool;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPStream_INCLUDED #endif // Net_HTTPStream_INCLUDED

View File

@ -1,101 +1,101 @@
// //
// HTTPStreamFactory.h // HTTPStreamFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPStreamFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HTTPStreamFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPStreamFactory // Module: HTTPStreamFactory
// //
// Definition of the HTTPStreamFactory class. // Definition of the HTTPStreamFactory class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HTTPStreamFactory_INCLUDED #ifndef Net_HTTPStreamFactory_INCLUDED
#define Net_HTTPStreamFactory_INCLUDED #define Net_HTTPStreamFactory_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPSession.h" #include "Poco/Net/HTTPSession.h"
#include "Poco/URIStreamFactory.h" #include "Poco/URIStreamFactory.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HTTPStreamFactory: public Poco::URIStreamFactory class Net_API HTTPStreamFactory: public Poco::URIStreamFactory
/// An implementation of the URIStreamFactory interface /// An implementation of the URIStreamFactory interface
/// that handles Hyper-Text Transfer Protocol (http) URIs. /// that handles Hyper-Text Transfer Protocol (http) URIs.
{ {
public: public:
HTTPStreamFactory(); HTTPStreamFactory();
/// Creates the HTTPStreamFactory. /// Creates the HTTPStreamFactory.
HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort = HTTPSession::HTTP_PORT); HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort = HTTPSession::HTTP_PORT);
/// Creates the HTTPStreamFactory. /// Creates the HTTPStreamFactory.
/// ///
/// HTTP connections will use the given proxy. /// HTTP connections will use the given proxy.
virtual ~HTTPStreamFactory(); virtual ~HTTPStreamFactory();
/// Destroys the HTTPStreamFactory. /// Destroys the HTTPStreamFactory.
virtual std::istream* open(const Poco::URI& uri); virtual std::istream* open(const Poco::URI& uri);
/// Creates and opens a HTTP stream for the given URI. /// Creates and opens a HTTP stream for the given URI.
/// The URI must be a http://... URI. /// The URI must be a http://... URI.
/// ///
/// Throws a NetException if anything goes wrong. /// Throws a NetException if anything goes wrong.
/// ///
/// Redirect responses are handled and the redirect /// Redirect responses are handled and the redirect
/// location is automatically resolved, as long /// location is automatically resolved, as long
/// as the redirect location is still accessible /// as the redirect location is still accessible
/// via the HTTP protocol. If a redirection to /// via the HTTP protocol. If a redirection to
/// a non http://... URI is received, a /// a non http://... URI is received, a
/// UnsupportedRedirectException exception is thrown. /// UnsupportedRedirectException exception is thrown.
/// The offending URI can then be obtained via the message() /// The offending URI can then be obtained via the message()
/// method of UnsupportedRedirectException. /// method of UnsupportedRedirectException.
static void registerFactory(); static void registerFactory();
/// Registers the HTTPStreamFactory with the /// Registers the HTTPStreamFactory with the
/// default URIStreamOpener instance. /// default URIStreamOpener instance.
private: private:
enum enum
{ {
MAX_REDIRECTS = 10 MAX_REDIRECTS = 10
}; };
std::string _proxyHost; std::string _proxyHost;
Poco::UInt16 _proxyPort; Poco::UInt16 _proxyPort;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HTTPStreamFactory_INCLUDED #endif // Net_HTTPStreamFactory_INCLUDED

View File

@ -1,133 +1,133 @@
// //
// HostEntry.h // HostEntry.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/HostEntry.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/HostEntry.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: HostEntry // Module: HostEntry
// //
// Definition of the HostEntry class. // Definition of the HostEntry class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_HostEntry_INCLUDED #ifndef Net_HostEntry_INCLUDED
#define Net_HostEntry_INCLUDED #define Net_HostEntry_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h" #include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API HostEntry class Net_API HostEntry
/// This class stores information about a host /// This class stores information about a host
/// such as host name, alias names and a list /// such as host name, alias names and a list
/// of IP addresses. /// of IP addresses.
{ {
public: public:
typedef std::vector<std::string> AliasList; typedef std::vector<std::string> AliasList;
typedef std::vector<IPAddress> AddressList; typedef std::vector<IPAddress> AddressList;
HostEntry(); HostEntry();
/// Creates an empty HostEntry. /// Creates an empty HostEntry.
HostEntry(struct hostent* entry); HostEntry(struct hostent* entry);
/// Creates the HostEntry from the data in a hostent structure. /// Creates the HostEntry from the data in a hostent structure.
#if defined(_WIN32) && defined(POCO_HAVE_IPv6) #if defined(_WIN32) && defined(POCO_HAVE_IPv6)
HostEntry(struct addrinfo* info); HostEntry(struct addrinfo* info);
/// Creates the HostEntry from the data in a Windows addrinfo structure. /// Creates the HostEntry from the data in a Windows addrinfo structure.
#endif #endif
HostEntry(const HostEntry& entry); HostEntry(const HostEntry& entry);
/// Creates the HostEntry by copying another one. /// Creates the HostEntry by copying another one.
HostEntry& operator = (const HostEntry& entry); HostEntry& operator = (const HostEntry& entry);
/// Assigns another HostEntry. /// Assigns another HostEntry.
void swap(HostEntry& hostEntry); void swap(HostEntry& hostEntry);
/// Swaps the HostEntry with another one. /// Swaps the HostEntry with another one.
~HostEntry(); ~HostEntry();
/// Destroys the HostEntry. /// Destroys the HostEntry.
const std::string& name() const; const std::string& name() const;
/// Returns the canonical host name. /// Returns the canonical host name.
const AliasList& aliases() const; const AliasList& aliases() const;
/// Returns a vector containing alias names for /// Returns a vector containing alias names for
/// the host name. /// the host name.
const AddressList& addresses() const; const AddressList& addresses() const;
/// Returns a vector containing the IPAddresses /// Returns a vector containing the IPAddresses
/// for the host. /// for the host.
private: private:
std::string _name; std::string _name;
AliasList _aliases; AliasList _aliases;
AddressList _addresses; AddressList _addresses;
}; };
// //
// inlines // inlines
// //
inline const std::string& HostEntry::name() const inline const std::string& HostEntry::name() const
{ {
return _name; return _name;
} }
inline const HostEntry::AliasList& HostEntry::aliases() const inline const HostEntry::AliasList& HostEntry::aliases() const
{ {
return _aliases; return _aliases;
} }
inline const HostEntry::AddressList& HostEntry::addresses() const inline const HostEntry::AddressList& HostEntry::addresses() const
{ {
return _addresses; return _addresses;
} }
inline void swap(HostEntry& h1, HostEntry& h2) inline void swap(HostEntry& h1, HostEntry& h2)
{ {
h1.swap(h2); h1.swap(h2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_HostEntry_INCLUDED #endif // Net_HostEntry_INCLUDED

View File

@ -1,107 +1,107 @@
// //
// ICMPClient.h // ICMPClient.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPClient.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPClient.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPClient // Module: ICMPClient
// //
// Definition of the ICMPClient class. // Definition of the ICMPClient class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPClient_INCLUDED #ifndef Net_ICMPClient_INCLUDED
#define Net_ICMPClient_INCLUDED #define Net_ICMPClient_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/ICMPSocket.h" #include "Poco/Net/ICMPSocket.h"
#include "Poco/Net/ICMPEventArgs.h" #include "Poco/Net/ICMPEventArgs.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include "Poco/BasicEvent.h" #include "Poco/BasicEvent.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPClient class Net_API ICMPClient
/// This class provides ICMP Ping functionality. /// This class provides ICMP Ping functionality.
/// ///
/// The events are available when class is instantiated /// The events are available when class is instantiated
/// and non-static member functions are called. /// and non-static member functions are called.
/// ///
/// A "lightweight" alternative is direct (without instantiation) /// A "lightweight" alternative is direct (without instantiation)
/// use of static member functions. /// use of static member functions.
{ {
public: public:
mutable Poco::BasicEvent<ICMPEventArgs> pingBegin; mutable Poco::BasicEvent<ICMPEventArgs> pingBegin;
mutable Poco::BasicEvent<ICMPEventArgs> pingReply; mutable Poco::BasicEvent<ICMPEventArgs> pingReply;
mutable Poco::BasicEvent<ICMPEventArgs> pingError; mutable Poco::BasicEvent<ICMPEventArgs> pingError;
mutable Poco::BasicEvent<ICMPEventArgs> pingEnd; mutable Poco::BasicEvent<ICMPEventArgs> pingEnd;
explicit ICMPClient(IPAddress::Family family); explicit ICMPClient(IPAddress::Family family);
/// Creates an ICMP client. /// Creates an ICMP client.
~ICMPClient(); ~ICMPClient();
/// Destroys the ICMP client. /// Destroys the ICMP client.
int ping(SocketAddress& address, int repeat = 1) const; int ping(SocketAddress& address, int repeat = 1) const;
/// Pings the specified address [repeat] times. /// Pings the specified address [repeat] times.
/// Notifications are posted for events. /// Notifications are posted for events.
/// ///
/// Returns the number of valid replies. /// Returns the number of valid replies.
int ping(const std::string& address, int repeat = 1) const; int ping(const std::string& address, int repeat = 1) const;
/// Calls ICMPClient::ping(SocketAddress&, int) and /// Calls ICMPClient::ping(SocketAddress&, int) and
/// returns the result. /// returns the result.
/// ///
/// Returns the number of valid replies. /// Returns the number of valid replies.
static int ping(SocketAddress& address, IPAddress::Family family, int repeat = 1); static int ping(SocketAddress& address, IPAddress::Family family, int repeat = 1);
/// Pings the specified address [repeat] times. /// Pings the specified address [repeat] times.
/// Notifications are not posted for events. /// Notifications are not posted for events.
/// ///
/// Returns the number of valid replies. /// Returns the number of valid replies.
static int pingIPv4(const std::string& address, int repeat = 1); static int pingIPv4(const std::string& address, int repeat = 1);
/// Calls ICMPClient::ping(SocketAddress&, int) and /// Calls ICMPClient::ping(SocketAddress&, int) and
/// returns the result. /// returns the result.
/// ///
/// Returns the number of valid replies. /// Returns the number of valid replies.
private: private:
mutable IPAddress::Family _family; mutable IPAddress::Family _family;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPClient_INCLUDED #endif // Net_ICMPClient_INCLUDED

View File

@ -1,188 +1,188 @@
// //
// ICMPEventArgs.h // ICMPEventArgs.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPEventArgs.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPEventArgs.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPEventArgs // Module: ICMPEventArgs
// //
// Definition of ICMPEventArgs. // Definition of ICMPEventArgs.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPEventArgs_INCLUDED #ifndef Net_ICMPEventArgs_INCLUDED
#define Net_ICMPEventArgs_INCLUDED #define Net_ICMPEventArgs_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include <vector> #include <vector>
#undef min // macros collide with valarray::min() and valarray::max() #undef min // macros collide with valarray::min() and valarray::max()
#undef max #undef max
#include <valarray> #include <valarray>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPEventArgs class Net_API ICMPEventArgs
/// The purpose of the ICMPEventArgs class is to be used as template parameter /// The purpose of the ICMPEventArgs class is to be used as template parameter
/// to instantiate event members in ICMPClient class. /// to instantiate event members in ICMPClient class.
/// When clients register for an event notification, the reference to the class is /// When clients register for an event notification, the reference to the class is
/// passed to the handler function to provide information about the event. /// passed to the handler function to provide information about the event.
{ {
public: public:
ICMPEventArgs(const SocketAddress& address, int repetitions, int dataSize, int ttl); ICMPEventArgs(const SocketAddress& address, int repetitions, int dataSize, int ttl);
/// Creates ICMPEventArgs. /// Creates ICMPEventArgs.
virtual ~ICMPEventArgs(); virtual ~ICMPEventArgs();
/// Destroys ICMPEventArgs. /// Destroys ICMPEventArgs.
std::string hostName() const; std::string hostName() const;
/// Tries to resolve the target IP address into host name. /// Tries to resolve the target IP address into host name.
/// If unsuccessful, all exceptions are silently ignored and /// If unsuccessful, all exceptions are silently ignored and
/// the IP address is returned. /// the IP address is returned.
std::string hostAddress() const; std::string hostAddress() const;
/// Returns the target IP address. /// Returns the target IP address.
int repetitions() const; int repetitions() const;
/// Returns the number of repetitions for the ping operation. /// Returns the number of repetitions for the ping operation.
int dataSize() const; int dataSize() const;
/// Returns the packet data size in bytes. /// Returns the packet data size in bytes.
int ttl() const; int ttl() const;
/// Returns time to live. /// Returns time to live.
int sent() const; int sent() const;
/// Returns the number of packets sent. /// Returns the number of packets sent.
int received() const; int received() const;
/// Returns the number of packets received. /// Returns the number of packets received.
int replyTime(int index = -1) const; int replyTime(int index = -1) const;
/// Returns the reply time for the request specified with index. /// Returns the reply time for the request specified with index.
/// If index == -1 (default), returns the most recent reply time. /// If index == -1 (default), returns the most recent reply time.
const std::string& error(int index = -1) const; const std::string& error(int index = -1) const;
/// Returns the error string for the request specified with index. /// Returns the error string for the request specified with index.
/// If index == -1 (default), returns the most recent error string. /// If index == -1 (default), returns the most recent error string.
int minRTT() const; int minRTT() const;
/// Returns the minimum round trip time for a sequence of requests. /// Returns the minimum round trip time for a sequence of requests.
int maxRTT() const; int maxRTT() const;
/// Returns the maximum round trip time for a sequence of requests. /// Returns the maximum round trip time for a sequence of requests.
int avgRTT() const; int avgRTT() const;
/// Returns the average round trip time for a sequence of requests. /// Returns the average round trip time for a sequence of requests.
float percent() const; float percent() const;
/// Returns the success percentage for a sequence of requests. /// Returns the success percentage for a sequence of requests.
private: private:
ICMPEventArgs(); ICMPEventArgs();
void setRepetitions(int repetitions); void setRepetitions(int repetitions);
void setDataSize(int dataSize); void setDataSize(int dataSize);
void setTTL(int ttl); void setTTL(int ttl);
void setReplyTime(int index, int time); void setReplyTime(int index, int time);
void setError(int index, const std::string& text); void setError(int index, const std::string& text);
ICMPEventArgs& operator ++ (); ICMPEventArgs& operator ++ ();
ICMPEventArgs operator ++ (int); ICMPEventArgs operator ++ (int);
static int zeroVal(int n); static int zeroVal(int n);
SocketAddress _address; SocketAddress _address;
int _sent; int _sent;
int _dataSize; int _dataSize;
int _ttl; int _ttl;
std::valarray<int> _rtt; std::valarray<int> _rtt;
std::vector<std::string> _errors; std::vector<std::string> _errors;
friend class ICMPClient; friend class ICMPClient;
}; };
// //
// inlines // inlines
// //
inline int ICMPEventArgs::repetitions() const inline int ICMPEventArgs::repetitions() const
{ {
return (int) _rtt.size(); return (int) _rtt.size();
} }
inline void ICMPEventArgs::setDataSize(int dataSize) inline void ICMPEventArgs::setDataSize(int dataSize)
{ {
_dataSize = dataSize; _dataSize = dataSize;
} }
inline int ICMPEventArgs::dataSize() const inline int ICMPEventArgs::dataSize() const
{ {
return _dataSize; return _dataSize;
} }
inline void ICMPEventArgs::setTTL(int ttl) inline void ICMPEventArgs::setTTL(int ttl)
{ {
_ttl = ttl; _ttl = ttl;
} }
inline int ICMPEventArgs::ttl() const inline int ICMPEventArgs::ttl() const
{ {
return _ttl; return _ttl;
} }
inline int ICMPEventArgs::sent() const inline int ICMPEventArgs::sent() const
{ {
return _sent; return _sent;
} }
inline int ICMPEventArgs::minRTT() const inline int ICMPEventArgs::minRTT() const
{ {
return _rtt.min(); return _rtt.min();
} }
inline int ICMPEventArgs::maxRTT() const inline int ICMPEventArgs::maxRTT() const
{ {
return _rtt.max(); return _rtt.max();
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif #endif

View File

@ -1,111 +1,111 @@
// //
// ICMPPacket.h // ICMPPacket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPPacket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPPacket.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPPacket // Module: ICMPPacket
// //
// Definition of the ICMPPacket class. // Definition of the ICMPPacket class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPPacket_INCLUDED #ifndef Net_ICMPPacket_INCLUDED
#define Net_ICMPPacket_INCLUDED #define Net_ICMPPacket_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/Net/ICMPPacketImpl.h" #include "Poco/Net/ICMPPacketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPPacket class Net_API ICMPPacket
/// This class is the ICMP packet abstraction. /// This class is the ICMP packet abstraction.
{ {
public: public:
ICMPPacket(IPAddress::Family family, int dataSize = 48); ICMPPacket(IPAddress::Family family, int dataSize = 48);
/// Creates an ICMPPacket of specified family. /// Creates an ICMPPacket of specified family.
~ICMPPacket(); ~ICMPPacket();
/// Destroys the ICMPPacket. /// Destroys the ICMPPacket.
const Poco::UInt8* packet(); const Poco::UInt8* packet();
/// Returns raw ICMP packet. ICMP header and data are included in the returned packet. /// Returns raw ICMP packet. ICMP header and data are included in the returned packet.
int packetSize() const; int packetSize() const;
/// Returns the total length of packet (header + data); /// Returns the total length of packet (header + data);
Poco::UInt16 sequence() const; Poco::UInt16 sequence() const;
/// Returns the most recent sequence number generated. /// Returns the most recent sequence number generated.
void setDataSize(int dataSize); void setDataSize(int dataSize);
/// Sets data size. /// Sets data size.
int getDataSize() const; int getDataSize() const;
/// Returns data size. /// Returns data size.
int maxPacketSize() const; int maxPacketSize() const;
/// Returns the total length of packet (header + data); /// Returns the total length of packet (header + data);
struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const; struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const;
/// Returns current epoch time if either buffer or length are equal to zero. /// Returns current epoch time if either buffer or length are equal to zero.
/// Otherwise, it extracts the time value from the supplied buffer and /// Otherwise, it extracts the time value from the supplied buffer and
/// returns the extracted value. /// returns the extracted value.
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
bool validReplyID(Poco::UInt8* buffer, int length) const; bool validReplyID(Poco::UInt8* buffer, int length) const;
/// Returns true if the extracted id is recognized /// Returns true if the extracted id is recognized
/// (equals the process id). /// (equals the process id).
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
std::string errorDescription(Poco::UInt8* buffer, int length); std::string errorDescription(Poco::UInt8* buffer, int length);
/// Returns error description string. /// Returns error description string.
/// If supplied buffer contains an ICMP echo reply packet, an /// If supplied buffer contains an ICMP echo reply packet, an
/// empty string is returned indicating the absence of error. /// empty string is returned indicating the absence of error.
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
std::string typeDescription(int typeId); std::string typeDescription(int typeId);
/// Returns the description of the packet type. /// Returns the description of the packet type.
private: private:
ICMPPacketImpl* _pImpl; ICMPPacketImpl* _pImpl;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPPacket_INCLUDED #endif // Net_ICMPPacket_INCLUDED

View File

@ -1,163 +1,163 @@
// //
// ICMPPacketImpl.h // ICMPPacketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPPacketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPPacketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPPacketImpl // Module: ICMPPacketImpl
// //
// Definition of the ICMPPacketImpl class. // Definition of the ICMPPacketImpl class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPPacketImpl_INCLUDED #ifndef Net_ICMPPacketImpl_INCLUDED
#define Net_ICMPPacketImpl_INCLUDED #define Net_ICMPPacketImpl_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPPacketImpl class Net_API ICMPPacketImpl
/// This is the abstract class for ICMP packet implementations. /// This is the abstract class for ICMP packet implementations.
{ {
public: public:
ICMPPacketImpl(int dataSize = 48); ICMPPacketImpl(int dataSize = 48);
/// Constructor. Creates an ICMPPacketImpl. /// Constructor. Creates an ICMPPacketImpl.
virtual ~ICMPPacketImpl(); virtual ~ICMPPacketImpl();
/// Destructor. /// Destructor.
const Poco::UInt8* packet(bool init = true); const Poco::UInt8* packet(bool init = true);
/// Returns raw ICMP packet. /// Returns raw ICMP packet.
/// ICMP header and data are included in the packet. /// ICMP header and data are included in the packet.
/// If init is true, initPacket() is called. /// If init is true, initPacket() is called.
virtual int packetSize() const = 0; virtual int packetSize() const = 0;
/// Returns the total size of packet (ICMP header + data) in number of octets. /// Returns the total size of packet (ICMP header + data) in number of octets.
/// Must be overriden. /// Must be overriden.
virtual int maxPacketSize() const; virtual int maxPacketSize() const;
/// Returns the maximum permitted size of packet in number of octets. /// Returns the maximum permitted size of packet in number of octets.
Poco::UInt16 sequence() const; Poco::UInt16 sequence() const;
/// Returns the most recent sequence number generated. /// Returns the most recent sequence number generated.
void setDataSize(int dataSize); void setDataSize(int dataSize);
/// Sets data size. /// Sets data size.
int getDataSize() const; int getDataSize() const;
/// Returns data size. /// Returns data size.
virtual struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const = 0; virtual struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const = 0;
/// Returns current epoch time if either argument is equal to zero. /// Returns current epoch time if either argument is equal to zero.
/// Otherwise, it extracts the time value from the supplied buffer. /// Otherwise, it extracts the time value from the supplied buffer.
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
/// Must be overriden. /// Must be overriden.
virtual bool validReplyID(unsigned char* buffer, int length) const = 0; virtual bool validReplyID(unsigned char* buffer, int length) const = 0;
/// Returns true if the extracted id is recognized /// Returns true if the extracted id is recognized
/// (i.e. equals the process id). /// (i.e. equals the process id).
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
/// Must be overriden. /// Must be overriden.
virtual std::string errorDescription(Poco::UInt8* buffer, int length) = 0; virtual std::string errorDescription(Poco::UInt8* buffer, int length) = 0;
/// Returns error description string. /// Returns error description string.
/// If supplied buffer contains an ICMP echo reply packet, an /// If supplied buffer contains an ICMP echo reply packet, an
/// empty string is returned indicating the absence of error. /// empty string is returned indicating the absence of error.
/// ///
/// Supplied buffer includes IP header, ICMP header and data. /// Supplied buffer includes IP header, ICMP header and data.
/// Must be overriden. /// Must be overriden.
virtual std::string typeDescription(int typeId) = 0; virtual std::string typeDescription(int typeId) = 0;
/// Returns the description of the packet type. /// Returns the description of the packet type.
/// Must be overriden. /// Must be overriden.
static const Poco::UInt16 MAX_PACKET_SIZE; static const Poco::UInt16 MAX_PACKET_SIZE;
static const Poco::UInt16 MAX_SEQ_VALUE; static const Poco::UInt16 MAX_SEQ_VALUE;
protected: protected:
Poco::UInt16 nextSequence(); Poco::UInt16 nextSequence();
/// Increments sequence number and returns the new value. /// Increments sequence number and returns the new value.
void resetSequence(); void resetSequence();
/// Resets the sequence to zero. /// Resets the sequence to zero.
virtual void initPacket() = 0; virtual void initPacket() = 0;
/// (Re)assembles the packet. /// (Re)assembles the packet.
/// Must be overriden. /// Must be overriden.
Poco::UInt16 checksum(Poco::UInt16 *addr, Poco::Int32 len); Poco::UInt16 checksum(Poco::UInt16 *addr, Poco::Int32 len);
/// Calculates the checksum for supplied buffer. /// Calculates the checksum for supplied buffer.
private: private:
Poco::UInt16 _seq; Poco::UInt16 _seq;
Poco::UInt8* _pPacket; Poco::UInt8* _pPacket;
int _dataSize; int _dataSize;
}; };
// //
// inlines // inlines
// //
inline Poco::UInt16 ICMPPacketImpl::sequence() const inline Poco::UInt16 ICMPPacketImpl::sequence() const
{ {
return _seq; return _seq;
} }
inline Poco::UInt16 ICMPPacketImpl::nextSequence() inline Poco::UInt16 ICMPPacketImpl::nextSequence()
{ {
return ++_seq; return ++_seq;
} }
inline void ICMPPacketImpl::resetSequence() inline void ICMPPacketImpl::resetSequence()
{ {
_seq = 0; _seq = 0;
} }
inline int ICMPPacketImpl::maxPacketSize() const inline int ICMPPacketImpl::maxPacketSize() const
{ {
return MAX_PACKET_SIZE; return MAX_PACKET_SIZE;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPPacketImpl_INCLUDED #endif // Net_ICMPPacketImpl_INCLUDED

View File

@ -1,139 +1,139 @@
// //
// ICMPSocket.h // ICMPSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPSocket // Module: ICMPSocket
// //
// Definition of the ICMPSocket class. // Definition of the ICMPSocket class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPSocket_INCLUDED #ifndef Net_ICMPSocket_INCLUDED
#define Net_ICMPSocket_INCLUDED #define Net_ICMPSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPSocket: public Socket class Net_API ICMPSocket: public Socket
/// This class provides an interface to an /// This class provides an interface to an
/// ICMP client socket. /// ICMP client socket.
{ {
public: public:
ICMPSocket(IPAddress::Family family, int dataSize = 48, int ttl = 128, int timeout = 500000); ICMPSocket(IPAddress::Family family, int dataSize = 48, int ttl = 128, int timeout = 500000);
/// Creates an unconnected ICMP socket. /// Creates an unconnected ICMP socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
ICMPSocket(const Socket& socket); ICMPSocket(const Socket& socket);
/// Creates the ICMPSocket with the SocketImpl /// Creates the ICMPSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a DatagramSocketImpl, otherwise an InvalidArgumentException /// a DatagramSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
~ICMPSocket(); ~ICMPSocket();
/// Destroys the ICMPSocket. /// Destroys the ICMPSocket.
ICMPSocket& operator = (const Socket& socket); ICMPSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
int sendTo(const SocketAddress& address, int flags = 0); int sendTo(const SocketAddress& address, int flags = 0);
/// Sends an ICMP request through /// Sends an ICMP request through
/// the socket to the given address. /// the socket to the given address.
/// ///
/// Returns the number of bytes sent. /// Returns the number of bytes sent.
int receiveFrom(SocketAddress& address, int flags = 0); int receiveFrom(SocketAddress& address, int flags = 0);
/// Receives data from the socket. /// Receives data from the socket.
/// Stores the address of the sender in address. /// Stores the address of the sender in address.
/// ///
/// Returns the time elapsed since the originating /// Returns the time elapsed since the originating
/// request was sent. /// request was sent.
int dataSize() const; int dataSize() const;
/// Returns the data size in bytes. /// Returns the data size in bytes.
int ttl() const; int ttl() const;
/// Returns the Time-To-Live value. /// Returns the Time-To-Live value.
int timeout() const; int timeout() const;
/// Returns the socket timeout value. /// Returns the socket timeout value.
protected: protected:
ICMPSocket(SocketImpl* pImpl); ICMPSocket(SocketImpl* pImpl);
/// Creates the Socket and attaches the given SocketImpl. /// Creates the Socket and attaches the given SocketImpl.
/// The socket takes owership of the SocketImpl. /// The socket takes owership of the SocketImpl.
/// ///
/// The SocketImpl must be a ICMPSocketImpl, otherwise /// The SocketImpl must be a ICMPSocketImpl, otherwise
/// an InvalidArgumentException will be thrown. /// an InvalidArgumentException will be thrown.
private: private:
int _dataSize; int _dataSize;
int _ttl; int _ttl;
int _timeout; int _timeout;
}; };
// //
// inlines // inlines
// //
inline int ICMPSocket::dataSize() const inline int ICMPSocket::dataSize() const
{ {
return _dataSize; return _dataSize;
} }
inline int ICMPSocket::ttl() const inline int ICMPSocket::ttl() const
{ {
return _ttl; return _ttl;
} }
inline int ICMPSocket::timeout() const inline int ICMPSocket::timeout() const
{ {
return _timeout; return _timeout;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPSocket_INCLUDED #endif // Net_ICMPSocket_INCLUDED

View File

@ -1,84 +1,84 @@
// //
// ICMPSocketImpl.h // ICMPSocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPSocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPSocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPSocketImpl // Module: ICMPSocketImpl
// //
// Definition of the ICMPSocketImpl class. // Definition of the ICMPSocketImpl class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPSocketImpl_INCLUDED #ifndef Net_ICMPSocketImpl_INCLUDED
#define Net_ICMPSocketImpl_INCLUDED #define Net_ICMPSocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/RawSocketImpl.h" #include "Poco/Net/RawSocketImpl.h"
#include "Poco/Net/ICMPPacket.h" #include "Poco/Net/ICMPPacket.h"
#include "Poco/Timestamp.h" #include "Poco/Timestamp.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPSocketImpl: public RawSocketImpl class Net_API ICMPSocketImpl: public RawSocketImpl
/// This class implements an ICMP socket. /// This class implements an ICMP socket.
{ {
public: public:
ICMPSocketImpl(IPAddress::Family family, int dataSize, int ttl, int timeout); ICMPSocketImpl(IPAddress::Family family, int dataSize, int ttl, int timeout);
/// Creates an unconnected ICMP socket. /// Creates an unconnected ICMP socket.
/// ///
/// The socket will be created for the given address family. /// The socket will be created for the given address family.
int sendTo(const void*, int, const SocketAddress& address, int flags = 0); int sendTo(const void*, int, const SocketAddress& address, int flags = 0);
/// Sends an ICMP request through the socket to the given address. /// Sends an ICMP request through the socket to the given address.
/// ///
/// Returns the number of bytes sent. /// Returns the number of bytes sent.
int receiveFrom(void*, int, SocketAddress& address, int flags = 0); int receiveFrom(void*, int, SocketAddress& address, int flags = 0);
/// Receives data from the socket. /// Receives data from the socket.
/// Stores the address of the sender in address. /// Stores the address of the sender in address.
/// ///
/// Returns the time elapsed since the originating request was sent. /// Returns the time elapsed since the originating request was sent.
protected: protected:
~ICMPSocketImpl(); ~ICMPSocketImpl();
private: private:
ICMPPacket _icmpPacket; ICMPPacket _icmpPacket;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPSocketImpl_INCLUDED #endif // Net_ICMPSocketImpl_INCLUDED

View File

@ -1,186 +1,186 @@
// //
// ICMPv4PacketImpl.h // ICMPv4PacketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ICMPv4PacketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ICMPv4PacketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: ICMP // Package: ICMP
// Module: ICMPv4PacketImpl // Module: ICMPv4PacketImpl
// //
// Definition of the ICMPv4PacketImpl class. // Definition of the ICMPv4PacketImpl class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ICMPv4PacketImpl_INCLUDED #ifndef Net_ICMPv4PacketImpl_INCLUDED
#define Net_ICMPv4PacketImpl_INCLUDED #define Net_ICMPv4PacketImpl_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/Net/ICMPPacketImpl.h" #include "Poco/Net/ICMPPacketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ICMPv4PacketImpl : public ICMPPacketImpl class Net_API ICMPv4PacketImpl : public ICMPPacketImpl
/// This class implements the ICMPv4 packet. /// This class implements the ICMPv4 packet.
/// Parts are based on original ICMP code by /// Parts are based on original ICMP code by
/// Mike Muuss /// Mike Muuss
/// U. S. Army Ballistic Research Laboratory /// U. S. Army Ballistic Research Laboratory
/// December, 1983 /// December, 1983
{ {
public: public:
// ICMPv4 header // ICMPv4 header
struct Header struct Header
{ {
Poco::UInt8 type; // ICMP packet type Poco::UInt8 type; // ICMP packet type
Poco::UInt8 code; // Type sub code Poco::UInt8 code; // Type sub code
Poco::UInt16 checksum; Poco::UInt16 checksum;
Poco::UInt16 id; Poco::UInt16 id;
Poco::UInt16 seq; Poco::UInt16 seq;
}; };
enum MessageType enum MessageType
{ {
ECHO_REPLY, ECHO_REPLY,
ICMP_1, ICMP_1,
ICMP_2, ICMP_2,
DESTINATION_UNREACHABLE, DESTINATION_UNREACHABLE,
SOURCE_QUENCH, SOURCE_QUENCH,
REDIRECT, REDIRECT,
ICMP_6, ICMP_6,
ICMP_7, ICMP_7,
ECHO, ECHO,
ICMP_9, ICMP_9,
ICMP_10, ICMP_10,
TIME_EXCEEDED, TIME_EXCEEDED,
PARAMETER_PROBLEM, PARAMETER_PROBLEM,
TIMESTAMP, TIMESTAMP,
TIMESTAMP_REPLY, TIMESTAMP_REPLY,
INFORMATION_REQUEST, INFORMATION_REQUEST,
INFORMATION_REPLY, INFORMATION_REPLY,
MESSAGE_TYPE_UNKNOWN, // non-standard default, must remain last but one MESSAGE_TYPE_UNKNOWN, // non-standard default, must remain last but one
MESSAGE_TYPE_LENGTH // length indicator, must remain last MESSAGE_TYPE_LENGTH // length indicator, must remain last
}; };
enum DestinationUnreachableCode enum DestinationUnreachableCode
{ {
NET_UNREACHABLE, NET_UNREACHABLE,
HOST_UNREACHABLE, HOST_UNREACHABLE,
PROTOCOL_UNREACHABLE, PROTOCOL_UNREACHABLE,
PORT_UNREACHABLE, PORT_UNREACHABLE,
FRAGMENTATION_NEEDED_AND_DF_SET, FRAGMENTATION_NEEDED_AND_DF_SET,
SOURCE_ROUTE_FAILED, SOURCE_ROUTE_FAILED,
DESTINATION_UNREACHABLE_UNKNOWN, // non-standard default, must remain last but one DESTINATION_UNREACHABLE_UNKNOWN, // non-standard default, must remain last but one
DESTINATION_UNREACHABLE_LENGTH // length indicator, must remain last DESTINATION_UNREACHABLE_LENGTH // length indicator, must remain last
}; };
enum RedirectMessageCode enum RedirectMessageCode
{ {
REDIRECT_NETWORK, REDIRECT_NETWORK,
REDIRECT_HOST, REDIRECT_HOST,
REDIRECT_SERVICE_NETWORK, REDIRECT_SERVICE_NETWORK,
REDIRECT_SERVICE_HOST, REDIRECT_SERVICE_HOST,
REDIRECT_MESSAGE_UNKNOWN, // non-standard default, must remain last but one REDIRECT_MESSAGE_UNKNOWN, // non-standard default, must remain last but one
REDIRECT_MESSAGE_LENGTH // length indicator, must remain last REDIRECT_MESSAGE_LENGTH // length indicator, must remain last
}; };
enum TimeExceededCode enum TimeExceededCode
{ {
TIME_TO_LIVE, TIME_TO_LIVE,
FRAGMENT_REASSEMBLY, FRAGMENT_REASSEMBLY,
TIME_EXCEEDED_UNKNOWN, // non-standard default, must remain last but one TIME_EXCEEDED_UNKNOWN, // non-standard default, must remain last but one
TIME_EXCEEDED_LENGTH // length indicator, must remain last TIME_EXCEEDED_LENGTH // length indicator, must remain last
}; };
enum ParameterProblemCode enum ParameterProblemCode
{ {
POINTER_INDICATES_THE_ERROR, POINTER_INDICATES_THE_ERROR,
PARAMETER_PROBLEM_UNKNOWN, // non-standard default, must remain last but one PARAMETER_PROBLEM_UNKNOWN, // non-standard default, must remain last but one
PARAMETER_PROBLEM_LENGTH // length indicator, must remain last PARAMETER_PROBLEM_LENGTH // length indicator, must remain last
}; };
ICMPv4PacketImpl(int dataSize = 48); ICMPv4PacketImpl(int dataSize = 48);
/// Constructor. Creates an ICMPv4PacketImpl. /// Constructor. Creates an ICMPv4PacketImpl.
~ICMPv4PacketImpl(); ~ICMPv4PacketImpl();
/// Destructor. /// Destructor.
int packetSize() const; int packetSize() const;
/// Returns the total length of packet (header + data); /// Returns the total length of packet (header + data);
struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const; struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const;
/// Returns current epoch time if either buffer or length are equal to zero. /// Returns current epoch time if either buffer or length are equal to zero.
/// Otherwise, it extracts the time value from the supplied buffer. /// Otherwise, it extracts the time value from the supplied buffer.
/// ///
/// Buffer includes IP header, ICMP header and data. /// Buffer includes IP header, ICMP header and data.
bool validReplyID(Poco::UInt8* buffer, int length) const; bool validReplyID(Poco::UInt8* buffer, int length) const;
/// Returns true if the extracted id is recognized /// Returns true if the extracted id is recognized
/// (i.e. equals the process id). /// (i.e. equals the process id).
/// ///
/// Buffer includes IP header, ICMP header and data. /// Buffer includes IP header, ICMP header and data.
virtual std::string errorDescription(Poco::UInt8* buffer, int length); virtual std::string errorDescription(Poco::UInt8* buffer, int length);
/// Returns error description string. /// Returns error description string.
/// If supplied buffer contains ICMPv4 echo reply packet, an /// If supplied buffer contains ICMPv4 echo reply packet, an
/// empty string is returned indicating the absence of error. /// empty string is returned indicating the absence of error.
/// ///
/// Buffer includes IP header, ICMP header and data. /// Buffer includes IP header, ICMP header and data.
virtual std::string typeDescription(int typeId); virtual std::string typeDescription(int typeId);
/// Returns the description of the packet type. /// Returns the description of the packet type.
static const Poco::UInt16 MAX_PACKET_SIZE; static const Poco::UInt16 MAX_PACKET_SIZE;
static const std::string MESSAGE_TYPE[MESSAGE_TYPE_LENGTH]; static const std::string MESSAGE_TYPE[MESSAGE_TYPE_LENGTH];
static const Poco::UInt8 DESTINATION_UNREACHABLE_TYPE; // 3 static const Poco::UInt8 DESTINATION_UNREACHABLE_TYPE; // 3
static const Poco::UInt8 SOURCE_QUENCH_TYPE; // 4 static const Poco::UInt8 SOURCE_QUENCH_TYPE; // 4
static const Poco::UInt8 REDIRECT_MESSAGE_TYPE; // 5 static const Poco::UInt8 REDIRECT_MESSAGE_TYPE; // 5
static const Poco::UInt8 TIME_EXCEEDED_TYPE; // 11 static const Poco::UInt8 TIME_EXCEEDED_TYPE; // 11
static const Poco::UInt8 PARAMETER_PROBLEM_TYPE; // 12 static const Poco::UInt8 PARAMETER_PROBLEM_TYPE; // 12
private: private:
void initPacket(); void initPacket();
Header* header(Poco::UInt8* buffer, int length) const; Header* header(Poco::UInt8* buffer, int length) const;
Poco::UInt8* data(Poco::UInt8* buffer, int length) const; Poco::UInt8* data(Poco::UInt8* buffer, int length) const;
static const std::string DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_LENGTH]; static const std::string DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_LENGTH];
static const std::string REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_LENGTH]; static const std::string REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_LENGTH];
static const std::string TIME_EXCEEDED_CODE[TIME_EXCEEDED_LENGTH]; static const std::string TIME_EXCEEDED_CODE[TIME_EXCEEDED_LENGTH];
static const std::string PARAMETER_PROBLEM_CODE[PARAMETER_PROBLEM_LENGTH]; static const std::string PARAMETER_PROBLEM_CODE[PARAMETER_PROBLEM_LENGTH];
Poco::UInt16 _seq; Poco::UInt16 _seq;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ICMPv4PacketImpl_INCLUDED #endif // Net_ICMPv4PacketImpl_INCLUDED

View File

@ -1,344 +1,344 @@
// //
// IPAddress.h // IPAddress.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/IPAddress.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/IPAddress.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: IPAddress // Module: IPAddress
// //
// Definition of the IPAddress class. // Definition of the IPAddress class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_IPAddress_INCLUDED #ifndef Net_IPAddress_INCLUDED
#define Net_IPAddress_INCLUDED #define Net_IPAddress_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h" #include "Poco/Net/SocketDefs.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class IPAddressImpl; class IPAddressImpl;
class Net_API IPAddress class Net_API IPAddress
/// This class represents an internet (IP) host /// This class represents an internet (IP) host
/// address. The address can belong either to the /// address. The address can belong either to the
/// IPv4 or the IPv6 address family. /// IPv4 or the IPv6 address family.
/// ///
/// Relational operators (==, !=, <, <=, >, >=) are /// Relational operators (==, !=, <, <=, >, >=) are
/// supported. However, you must not interpret any /// supported. However, you must not interpret any
/// special meaning into the result of these /// special meaning into the result of these
/// operations, other than that the results are /// operations, other than that the results are
/// consistent. /// consistent.
/// ///
/// Especially, an IPv4 address is never equal to /// Especially, an IPv4 address is never equal to
/// an IPv6 address, even if the IPv6 address is /// an IPv6 address, even if the IPv6 address is
/// IPv4 compatible and the addresses are the same. /// IPv4 compatible and the addresses are the same.
/// ///
/// IPv6 addresses are supported only if the target platform /// IPv6 addresses are supported only if the target platform
/// supports IPv6. /// supports IPv6.
{ {
public: public:
enum Family enum Family
/// Possible address families for IP addresses. /// Possible address families for IP addresses.
{ {
IPv4, IPv4,
IPv6 IPv6
}; };
IPAddress(); IPAddress();
/// Creates a wildcard (zero) IPv4 IPAddress. /// Creates a wildcard (zero) IPv4 IPAddress.
IPAddress(const IPAddress& addr); IPAddress(const IPAddress& addr);
/// Creates an IPAddress by copying another one. /// Creates an IPAddress by copying another one.
explicit IPAddress(Family family); explicit IPAddress(Family family);
/// Creates a wildcard (zero) IPAddress for the /// Creates a wildcard (zero) IPAddress for the
/// given address family. /// given address family.
explicit IPAddress(const std::string& addr); explicit IPAddress(const std::string& addr);
/// Creates an IPAddress from the string containing /// Creates an IPAddress from the string containing
/// an IP address in presentation format (dotted decimal /// an IP address in presentation format (dotted decimal
/// for IPv4, hex string for IPv6). /// for IPv4, hex string for IPv6).
/// ///
/// Depending on the format of addr, either an IPv4 or /// Depending on the format of addr, either an IPv4 or
/// an IPv6 address is created. /// an IPv6 address is created.
/// ///
/// See toString() for details on the supported formats. /// See toString() for details on the supported formats.
/// ///
/// Throws an InvalidAddressException if the address cannot be parsed. /// Throws an InvalidAddressException if the address cannot be parsed.
IPAddress(const std::string& addr, Family family); IPAddress(const std::string& addr, Family family);
/// Creates an IPAddress from the string containing /// Creates an IPAddress from the string containing
/// an IP address in presentation format (dotted decimal /// an IP address in presentation format (dotted decimal
/// for IPv4, hex string for IPv6). /// for IPv4, hex string for IPv6).
IPAddress(const void* addr, poco_socklen_t length); IPAddress(const void* addr, poco_socklen_t length);
/// Creates an IPAddress from a native internet address. /// Creates an IPAddress from a native internet address.
/// A pointer to a in_addr or a in6_addr structure may be /// A pointer to a in_addr or a in6_addr structure may be
/// passed. /// passed.
~IPAddress(); ~IPAddress();
/// Destroys the IPAddress. /// Destroys the IPAddress.
IPAddress& operator = (const IPAddress& addr); IPAddress& operator = (const IPAddress& addr);
/// Assigns an IPAddress. /// Assigns an IPAddress.
void swap(IPAddress& address); void swap(IPAddress& address);
/// Swaps the IPAddress with another one. /// Swaps the IPAddress with another one.
Family family() const; Family family() const;
/// Returns the address family (IPv4 or IPv6) of the address. /// Returns the address family (IPv4 or IPv6) of the address.
std::string toString() const; std::string toString() const;
/// Returns a string containing a representation of the address /// Returns a string containing a representation of the address
/// in presentation format. /// in presentation format.
/// ///
/// For IPv4 addresses the result will be in dotted-decimal /// For IPv4 addresses the result will be in dotted-decimal
/// (d.d.d.d) notation. /// (d.d.d.d) notation.
/// ///
/// Textual representation of IPv6 address is one of the following forms: /// Textual representation of IPv6 address is one of the following forms:
/// ///
/// The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the hexadecimal /// The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the hexadecimal
/// values of the eight 16-bit pieces of the address. This is the full form. /// values of the eight 16-bit pieces of the address. This is the full form.
/// Example: 1080:0:0:0:8:600:200A:425C /// Example: 1080:0:0:0:8:600:200A:425C
/// ///
/// It is not necessary to write the leading zeros in an individual field. /// It is not necessary to write the leading zeros in an individual field.
/// However, there must be at least one numeral in every field, except as described below. /// However, there must be at least one numeral in every field, except as described below.
/// ///
/// It is common for IPv6 addresses to contain long strings of zero bits. /// It is common for IPv6 addresses to contain long strings of zero bits.
/// In order to make writing addresses containing zero bits easier, a special syntax is /// In order to make writing addresses containing zero bits easier, a special syntax is
/// available to compress the zeros. The use of "::" indicates multiple groups of 16-bits of zeros. /// available to compress the zeros. The use of "::" indicates multiple groups of 16-bits of zeros.
/// The "::" can only appear once in an address. The "::" can also be used to compress the leading /// The "::" can only appear once in an address. The "::" can also be used to compress the leading
/// and/or trailing zeros in an address. Example: 1080::8:600:200A:425C /// and/or trailing zeros in an address. Example: 1080::8:600:200A:425C
/// ///
/// For dealing with IPv4 compatible addresses in a mixed environment, /// 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 /// 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 /// 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 /// standard IPv4 representation address. Example: ::FFFF:192.168.1.120
bool isWildcard() const; bool isWildcard() const;
/// Returns true iff the address is a wildcard (all zero) /// Returns true iff the address is a wildcard (all zero)
/// address. /// address.
bool isBroadcast() const; bool isBroadcast() const;
/// Returns true iff the address is a broadcast address. /// Returns true iff the address is a broadcast address.
/// ///
/// Only IPv4 addresses can be broadcast addresses. In a broadcast /// Only IPv4 addresses can be broadcast addresses. In a broadcast
/// address, all bits are one. /// address, all bits are one.
/// ///
/// For a IPv6 address, returns always false. /// For a IPv6 address, returns always false.
bool isLoopback() const; bool isLoopback() const;
/// Returns true iff the address is a loopback address. /// Returns true iff the address is a loopback address.
/// ///
/// For IPv4, the loopback address is 127.0.0.1. /// For IPv4, the loopback address is 127.0.0.1.
/// ///
/// For IPv6, the loopback address is ::1. /// For IPv6, the loopback address is ::1.
bool isMulticast() const; bool isMulticast() const;
/// Returns true iff the address is a multicast address. /// Returns true iff the address is a multicast address.
/// ///
/// IPv4 multicast addresses are in the /// IPv4 multicast addresses are in the
/// 224.0.0.0 to 239.255.255.255 range /// 224.0.0.0 to 239.255.255.255 range
/// (the first four bits have the value 1110). /// (the first four bits have the value 1110).
/// ///
/// IPv6 multicast addresses are in the /// IPv6 multicast addresses are in the
/// FFxx:x:x:x:x:x:x:x range. /// FFxx:x:x:x:x:x:x:x range.
bool isUnicast() const; bool isUnicast() const;
/// Returns true iff the address is a unicast address. /// Returns true iff the address is a unicast address.
/// ///
/// An address is unicast if it is neither a wildcard, /// An address is unicast if it is neither a wildcard,
/// broadcast or multicast address. /// broadcast or multicast address.
bool isLinkLocal() const; bool isLinkLocal() const;
/// Returns true iff the address is a link local unicast address. /// Returns true iff the address is a link local unicast address.
/// ///
/// IPv4 link local addresses are in the 169.254.0.0/16 range, /// IPv4 link local addresses are in the 169.254.0.0/16 range,
/// according to RFC 3927. /// according to RFC 3927.
/// ///
/// IPv6 link local addresses have 1111 1110 10 as the first /// IPv6 link local addresses have 1111 1110 10 as the first
/// 10 bits, followed by 54 zeros. /// 10 bits, followed by 54 zeros.
bool isSiteLocal() const; bool isSiteLocal() const;
/// Returns true iff the address is a site local unicast address. /// Returns true iff the address is a site local unicast address.
/// ///
/// IPv4 site local addresses are in on of the 10.0.0.0/24, /// IPv4 site local addresses are in on of the 10.0.0.0/24,
/// 192.168.0.0/16 or 172.16.0.0 to 172.31.255.255 ranges. /// 192.168.0.0/16 or 172.16.0.0 to 172.31.255.255 ranges.
/// ///
/// IPv6 site local addresses have 1111 1110 11 as the first /// IPv6 site local addresses have 1111 1110 11 as the first
/// 10 bits, followed by 38 zeros. /// 10 bits, followed by 38 zeros.
bool isIPv4Compatible() const; bool isIPv4Compatible() const;
/// Returns true iff the address is IPv4 compatible. /// Returns true iff the address is IPv4 compatible.
/// ///
/// For IPv4 addresses, this is always true. /// For IPv4 addresses, this is always true.
/// ///
/// For IPv6, the address must be in the ::x:x range (the /// For IPv6, the address must be in the ::x:x range (the
/// first 96 bits are zero). /// first 96 bits are zero).
bool isIPv4Mapped() const; bool isIPv4Mapped() const;
/// Returns true iff the address is an IPv4 mapped IPv6 address. /// Returns true iff the address is an IPv4 mapped IPv6 address.
/// ///
/// For IPv4 addresses, this is always true. /// For IPv4 addresses, this is always true.
/// ///
/// For IPv6, the address must be in the ::FFFF:x:x range. /// For IPv6, the address must be in the ::FFFF:x:x range.
bool isWellKnownMC() const; bool isWellKnownMC() const;
/// Returns true iff the address is a well-known multicast address. /// Returns true iff the address is a well-known multicast address.
/// ///
/// For IPv4, well-known multicast addresses are in the /// For IPv4, well-known multicast addresses are in the
/// 224.0.0.0/8 range. /// 224.0.0.0/8 range.
/// ///
/// For IPv6, well-known multicast addresses are in the /// For IPv6, well-known multicast addresses are in the
/// FF0x:x:x:x:x:x:x:x range. /// FF0x:x:x:x:x:x:x:x range.
bool isNodeLocalMC() const; bool isNodeLocalMC() const;
/// Returns true iff the address is a node-local multicast address. /// Returns true iff the address is a node-local multicast address.
/// ///
/// IPv4 does not support node-local addresses, thus the result is /// IPv4 does not support node-local addresses, thus the result is
/// always false for an IPv4 address. /// always false for an IPv4 address.
/// ///
/// For IPv6, node-local multicast addresses are in the /// For IPv6, node-local multicast addresses are in the
/// FFx1:x:x:x:x:x:x:x range. /// FFx1:x:x:x:x:x:x:x range.
bool isLinkLocalMC() const; bool isLinkLocalMC() const;
/// Returns true iff the address is a link-local multicast address. /// Returns true iff the address is a link-local multicast address.
/// ///
/// For IPv4, link-local multicast addresses are in the /// For IPv4, link-local multicast addresses are in the
/// 224.0.0.0/24 range. Note that this overlaps with the range for well-known /// 224.0.0.0/24 range. Note that this overlaps with the range for well-known
/// multicast addresses. /// multicast addresses.
/// ///
/// For IPv6, link-local multicast addresses are in the /// For IPv6, link-local multicast addresses are in the
/// FFx2:x:x:x:x:x:x:x range. /// FFx2:x:x:x:x:x:x:x range.
bool isSiteLocalMC() const; bool isSiteLocalMC() const;
/// Returns true iff the address is a site-local multicast address. /// Returns true iff the address is a site-local multicast address.
/// ///
/// For IPv4, site local multicast addresses are in the /// For IPv4, site local multicast addresses are in the
/// 239.255.0.0/16 range. /// 239.255.0.0/16 range.
/// ///
/// For IPv6, site-local multicast addresses are in the /// For IPv6, site-local multicast addresses are in the
/// FFx5:x:x:x:x:x:x:x range. /// FFx5:x:x:x:x:x:x:x range.
bool isOrgLocalMC() const; bool isOrgLocalMC() const;
/// Returns true iff the address is a organization-local multicast address. /// Returns true iff the address is a organization-local multicast address.
/// ///
/// For IPv4, organization-local multicast addresses are in the /// For IPv4, organization-local multicast addresses are in the
/// 239.192.0.0/16 range. /// 239.192.0.0/16 range.
/// ///
/// For IPv6, organization-local multicast addresses are in the /// For IPv6, organization-local multicast addresses are in the
/// FFx8:x:x:x:x:x:x:x range. /// FFx8:x:x:x:x:x:x:x range.
bool isGlobalMC() const; bool isGlobalMC() const;
/// Returns true iff the address is a global multicast address. /// Returns true iff the address is a global multicast address.
/// ///
/// For IPv4, global multicast addresses are in the /// For IPv4, global multicast addresses are in the
/// 224.0.1.0 to 238.255.255.255 range. /// 224.0.1.0 to 238.255.255.255 range.
/// ///
/// For IPv6, global multicast addresses are in the /// For IPv6, global multicast addresses are in the
/// FFxF:x:x:x:x:x:x:x range. /// FFxF:x:x:x:x:x:x:x range.
bool operator == (const IPAddress& addr) const; bool operator == (const IPAddress& addr) const;
bool operator != (const IPAddress& addr) const; bool operator != (const IPAddress& addr) const;
bool operator < (const IPAddress& addr) const; bool operator < (const IPAddress& addr) const;
bool operator <= (const IPAddress& addr) const; bool operator <= (const IPAddress& addr) const;
bool operator > (const IPAddress& addr) const; bool operator > (const IPAddress& addr) const;
bool operator >= (const IPAddress& addr) const; bool operator >= (const IPAddress& addr) const;
poco_socklen_t length() const; poco_socklen_t length() const;
/// Returns the length in bytes of the internal socket address structure. /// Returns the length in bytes of the internal socket address structure.
const void* addr() const; const void* addr() const;
/// Returns the internal address structure. /// Returns the internal address structure.
int af() const; int af() const;
/// Returns the address family (AF_INET or AF_INET6) of the address. /// Returns the address family (AF_INET or AF_INET6) of the address.
static IPAddress parse(const std::string& addr); static IPAddress parse(const std::string& addr);
/// Creates an IPAddress from the string containing /// Creates an IPAddress from the string containing
/// an IP address in presentation format (dotted decimal /// an IP address in presentation format (dotted decimal
/// for IPv4, hex string for IPv6). /// for IPv4, hex string for IPv6).
/// ///
/// Depending on the format of addr, either an IPv4 or /// Depending on the format of addr, either an IPv4 or
/// an IPv6 address is created. /// an IPv6 address is created.
/// ///
/// See toString() for details on the supported formats. /// See toString() for details on the supported formats.
/// ///
/// Throws an InvalidAddressException if the address cannot be parsed. /// Throws an InvalidAddressException if the address cannot be parsed.
static bool tryParse(const std::string& addr, IPAddress& result); static bool tryParse(const std::string& addr, IPAddress& result);
/// Tries to interpret the given address string as an /// Tries to interpret the given address string as an
/// IP address in presentation format (dotted decimal /// IP address in presentation format (dotted decimal
/// for IPv4, hex string for IPv6). /// for IPv4, hex string for IPv6).
/// ///
/// Returns true and stores the IPAddress in result if the /// Returns true and stores the IPAddress in result if the
/// string contains a valid address. /// string contains a valid address.
/// ///
/// Returns false and leaves result unchanged otherwise. /// Returns false and leaves result unchanged otherwise.
enum enum
{ {
MAX_ADDRESS_LENGTH = MAX_ADDRESS_LENGTH =
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
sizeof(struct in6_addr) sizeof(struct in6_addr)
#else #else
sizeof(struct in_addr) sizeof(struct in_addr)
#endif #endif
/// Maximum length in bytes of a socket address. /// Maximum length in bytes of a socket address.
}; };
protected: protected:
void init(IPAddressImpl* pImpl); void init(IPAddressImpl* pImpl);
private: private:
IPAddressImpl* _pImpl; IPAddressImpl* _pImpl;
}; };
// //
// inlines // inlines
// //
inline void swap(IPAddress& a1, IPAddress& a2) inline void swap(IPAddress& a1, IPAddress& a2)
{ {
a1.swap(a2); a1.swap(a2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_IPAddress_INCLUDED #endif // Net_IPAddress_INCLUDED

View File

@ -1,254 +1,254 @@
// //
// MailMessage.h // MailMessage.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#2 $ // $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#2 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
// Module: MailMessage // Module: MailMessage
// //
// Definition of the MailMessage class. // Definition of the MailMessage class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MailMessage_INCLUDED #ifndef Net_MailMessage_INCLUDED
#define Net_MailMessage_INCLUDED #define Net_MailMessage_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/MessageHeader.h" #include "Poco/Net/MessageHeader.h"
#include "Poco/Net/MailRecipient.h" #include "Poco/Net/MailRecipient.h"
#include "Poco/Timestamp.h" #include "Poco/Timestamp.h"
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MediaType; class MediaType;
class PartSource; class PartSource;
class PartHandler; class PartHandler;
class MultipartWriter; class MultipartWriter;
class Net_API MailMessage: public MessageHeader class Net_API MailMessage: public MessageHeader
/// This class represents an e-mail message for /// This class represents an e-mail message for
/// use with the SMTPClientSession and POPClientSession /// use with the SMTPClientSession and POPClientSession
/// classes. /// classes.
/// ///
/// MailMessage supports both old-style plain text messages, /// MailMessage supports both old-style plain text messages,
/// as well as MIME multipart mail messages with attachments. /// as well as MIME multipart mail messages with attachments.
/// ///
/// For multi-part messages, the following content transfer /// For multi-part messages, the following content transfer
/// encodings are supported: 7bit, 8bit, quoted-printable /// encodings are supported: 7bit, 8bit, quoted-printable
/// and base64. /// and base64.
{ {
public: public:
typedef std::vector<MailRecipient> Recipients; typedef std::vector<MailRecipient> Recipients;
enum ContentDisposition enum ContentDisposition
{ {
CONTENT_INLINE, CONTENT_INLINE,
CONTENT_ATTACHMENT CONTENT_ATTACHMENT
}; };
enum ContentTransferEncoding enum ContentTransferEncoding
{ {
ENCODING_7BIT, ENCODING_7BIT,
ENCODING_8BIT, ENCODING_8BIT,
ENCODING_QUOTED_PRINTABLE, ENCODING_QUOTED_PRINTABLE,
ENCODING_BASE64 ENCODING_BASE64
}; };
MailMessage(); MailMessage();
/// Creates an empty MailMessage. /// Creates an empty MailMessage.
virtual ~MailMessage(); virtual ~MailMessage();
/// Destroys the MailMessage. /// Destroys the MailMessage.
void addRecipient(const MailRecipient& recipient); void addRecipient(const MailRecipient& recipient);
/// Adds a recipient for the message. /// Adds a recipient for the message.
const Recipients& recipients() const; const Recipients& recipients() const;
/// Returns the recipients of the message. /// Returns the recipients of the message.
void setSubject(const std::string& subject); void setSubject(const std::string& subject);
/// Sets the subject of the message. /// Sets the subject of the message.
const std::string& getSubject() const; const std::string& getSubject() const;
/// Returns the subject of the message. /// Returns the subject of the message.
void setSender(const std::string& sender); void setSender(const std::string& sender);
/// Sets the sender of the message (which /// Sets the sender of the message (which
/// ends up in the From header field). /// ends up in the From header field).
const std::string& getSender() const; const std::string& getSender() const;
/// Returns the sender of the message (taken /// Returns the sender of the message (taken
/// from the From header field). /// from the From header field).
void setContent(const std::string& content, ContentTransferEncoding encoding = ENCODING_QUOTED_PRINTABLE); void setContent(const std::string& content, ContentTransferEncoding encoding = ENCODING_QUOTED_PRINTABLE);
/// Sets the content of the mail message. /// Sets the content of the mail message.
/// ///
/// If the content transfer encoding is ENCODING_7BIT or /// If the content transfer encoding is ENCODING_7BIT or
/// ENCODING_8BIT, the content string must be formatted /// ENCODING_8BIT, the content string must be formatted
/// according to the rules of an internet email message. /// according to the rules of an internet email message.
/// ///
/// The message will be sent as a single-part /// The message will be sent as a single-part
/// message. /// message.
const std::string& getContent() const; const std::string& getContent() const;
/// Returns the content of the mail message. /// Returns the content of the mail message.
/// ///
/// A content will only be returned for single-part /// A content will only be returned for single-part
/// messages. The content of multi-part mail messages /// messages. The content of multi-part mail messages
/// will be reported through the registered PartHandler. /// will be reported through the registered PartHandler.
void setContentType(const std::string& mediaType); void setContentType(const std::string& mediaType);
/// Sets the content type for the message. /// Sets the content type for the message.
void setContentType(const MediaType& mediaType); void setContentType(const MediaType& mediaType);
/// Sets the content type for the message. /// Sets the content type for the message.
const std::string& getContentType() const; const std::string& getContentType() const;
/// Returns the content type for the message. /// Returns the content type for the message.
void setDate(const Poco::Timestamp& dateTime); void setDate(const Poco::Timestamp& dateTime);
/// Sets the Date header to the given date/time value. /// Sets the Date header to the given date/time value.
Poco::Timestamp getDate() const; Poco::Timestamp getDate() const;
/// Returns the value of the Date header. /// Returns the value of the Date header.
bool isMultipart() const; bool isMultipart() const;
/// Returns true iff the message is a multipart message. /// Returns true iff the message is a multipart message.
void addPart(const std::string& name, PartSource* pSource, ContentDisposition disposition, ContentTransferEncoding encoding); void addPart(const std::string& name, PartSource* pSource, ContentDisposition disposition, ContentTransferEncoding encoding);
/// Adds a part/attachment to the mail message. /// Adds a part/attachment to the mail message.
/// ///
/// The MailMessage takes ownership of the PartSource and deletes it /// The MailMessage takes ownership of the PartSource and deletes it
/// when it is no longer needed. /// when it is no longer needed.
/// ///
/// The MailMessage will be converted to a multipart message /// The MailMessage will be converted to a multipart message
/// if it is not already one. /// if it is not already one.
void addContent(PartSource* pSource, ContentTransferEncoding encoding = ENCODING_QUOTED_PRINTABLE); void addContent(PartSource* pSource, ContentTransferEncoding encoding = ENCODING_QUOTED_PRINTABLE);
/// Adds a part to the mail message by calling /// Adds a part to the mail message by calling
/// addPart("", pSource, CONTENT_INLINE, encoding); /// addPart("", pSource, CONTENT_INLINE, encoding);
void addAttachment(const std::string& name, PartSource* pSource, ContentTransferEncoding encoding = ENCODING_BASE64); void addAttachment(const std::string& name, PartSource* pSource, ContentTransferEncoding encoding = ENCODING_BASE64);
/// Adds an attachment to the mail message by calling /// Adds an attachment to the mail message by calling
/// addPart(name, pSource, CONTENT_ATTACHMENT, encoding); /// addPart(name, pSource, CONTENT_ATTACHMENT, encoding);
void read(std::istream& istr, PartHandler& handler); void read(std::istream& istr, PartHandler& handler);
/// Reads the MailMessage from the given input stream. /// Reads the MailMessage from the given input stream.
/// ///
/// If the message has multiple parts, the parts /// If the message has multiple parts, the parts
/// are reported to the PartHandler. If the message /// are reported to the PartHandler. If the message
/// is not a multi-part message, the content is stored /// is not a multi-part message, the content is stored
/// in a string available by calling getContent(). /// in a string available by calling getContent().
void read(std::istream& istr); void read(std::istream& istr);
/// Reads the MailMessage from the given input stream. /// Reads the MailMessage from the given input stream.
/// ///
/// The raw message (including all MIME parts) is stored /// The raw message (including all MIME parts) is stored
/// in a string and available by calling getContent(). /// in a string and available by calling getContent().
void write(std::ostream& ostr) const; void write(std::ostream& ostr) const;
/// Writes the mail message to the given output stream. /// Writes the mail message to the given output stream.
protected: protected:
struct Part struct Part
{ {
std::string name; std::string name;
PartSource* pSource; PartSource* pSource;
ContentDisposition disposition; ContentDisposition disposition;
ContentTransferEncoding encoding; ContentTransferEncoding encoding;
}; };
typedef std::vector<Part> PartVec; typedef std::vector<Part> PartVec;
void makeMultipart(); void makeMultipart();
void writeHeader(const MessageHeader& header, std::ostream& ostr) const; void writeHeader(const MessageHeader& header, std::ostream& ostr) const;
void writeMultipart(MessageHeader& header, std::ostream& ostr) const; void writeMultipart(MessageHeader& header, std::ostream& ostr) const;
void writePart(MultipartWriter& writer, const Part& part) const; void writePart(MultipartWriter& writer, const Part& part) const;
void writeEncoded(std::istream& istr, std::ostream& ostr, ContentTransferEncoding encoding) const; void writeEncoded(std::istream& istr, std::ostream& ostr, ContentTransferEncoding encoding) const;
void setRecipientHeaders(MessageHeader& headers) const; void setRecipientHeaders(MessageHeader& headers) const;
void readHeader(std::istream& istr); void readHeader(std::istream& istr);
void readMultipart(std::istream& istr, PartHandler& handler); void readMultipart(std::istream& istr, PartHandler& handler);
void readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler); void readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
void handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler); void handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
static const std::string& contentTransferEncodingToString(ContentTransferEncoding encoding); static const std::string& contentTransferEncodingToString(ContentTransferEncoding encoding);
static int lineLength(const std::string& str); static int lineLength(const std::string& str);
static void appendRecipient(const MailRecipient& recipient, std::string& str); static void appendRecipient(const MailRecipient& recipient, std::string& str);
static const std::string HEADER_SUBJECT; static const std::string HEADER_SUBJECT;
static const std::string HEADER_FROM; static const std::string HEADER_FROM;
static const std::string HEADER_TO; static const std::string HEADER_TO;
static const std::string HEADER_CC; static const std::string HEADER_CC;
static const std::string HEADER_BCC; static const std::string HEADER_BCC;
static const std::string HEADER_DATE; static const std::string HEADER_DATE;
static const std::string HEADER_CONTENT_TYPE; static const std::string HEADER_CONTENT_TYPE;
static const std::string HEADER_CONTENT_TRANSFER_ENCODING; static const std::string HEADER_CONTENT_TRANSFER_ENCODING;
static const std::string HEADER_CONTENT_DISPOSITION; static const std::string HEADER_CONTENT_DISPOSITION;
static const std::string HEADER_MIME_VERSION; static const std::string HEADER_MIME_VERSION;
static const std::string EMPTY_HEADER; static const std::string EMPTY_HEADER;
static const std::string TEXT_PLAIN; static const std::string TEXT_PLAIN;
static const std::string CTE_7BIT; static const std::string CTE_7BIT;
static const std::string CTE_8BIT; static const std::string CTE_8BIT;
static const std::string CTE_QUOTED_PRINTABLE; static const std::string CTE_QUOTED_PRINTABLE;
static const std::string CTE_BASE64; static const std::string CTE_BASE64;
private: private:
MailMessage(const MailMessage&); MailMessage(const MailMessage&);
MailMessage& operator = (const MailMessage&); MailMessage& operator = (const MailMessage&);
Recipients _recipients; Recipients _recipients;
PartVec _parts; PartVec _parts;
std::string _content; std::string _content;
ContentTransferEncoding _encoding; ContentTransferEncoding _encoding;
}; };
// //
// inlines // inlines
// //
inline const MailMessage::Recipients& MailMessage::recipients() const inline const MailMessage::Recipients& MailMessage::recipients() const
{ {
return _recipients; return _recipients;
} }
inline const std::string& MailMessage::getContent() const inline const std::string& MailMessage::getContent() const
{ {
return _content; return _content;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MailMessage_INCLUDED #endif // Net_MailMessage_INCLUDED

View File

@ -1,142 +1,142 @@
// //
// MailRecipient.h // MailRecipient.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MailRecipient.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MailRecipient.h#1 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
// Module: MailRecipient // Module: MailRecipient
// //
// Definition of the MailRecipient class. // Definition of the MailRecipient class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MailRecipient_INCLUDED #ifndef Net_MailRecipient_INCLUDED
#define Net_MailRecipient_INCLUDED #define Net_MailRecipient_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API MailRecipient class Net_API MailRecipient
/// The recipient of an e-mail message. /// The recipient of an e-mail message.
/// ///
/// A recipient has a type (primary recipient, /// A recipient has a type (primary recipient,
/// carbon-copy recipient, blind-carbon-copy /// carbon-copy recipient, blind-carbon-copy
/// recipient), an e-mail address and an optional /// recipient), an e-mail address and an optional
/// real name. /// real name.
{ {
public: public:
enum RecipientType enum RecipientType
{ {
PRIMARY_RECIPIENT, PRIMARY_RECIPIENT,
CC_RECIPIENT, CC_RECIPIENT,
BCC_RECIPIENT BCC_RECIPIENT
}; };
MailRecipient(); MailRecipient();
/// Creates an empty MailRecipient. /// Creates an empty MailRecipient.
MailRecipient(const MailRecipient& recipient); MailRecipient(const MailRecipient& recipient);
/// Creates a MailRecipient by copying another one. /// Creates a MailRecipient by copying another one.
MailRecipient(RecipientType type, const std::string& address); MailRecipient(RecipientType type, const std::string& address);
/// Creates a MailRecipient of the given type. /// Creates a MailRecipient of the given type.
MailRecipient(RecipientType type, const std::string& address, const std::string& realName); MailRecipient(RecipientType type, const std::string& address, const std::string& realName);
/// Creates a MailRecipient of the given type. /// Creates a MailRecipient of the given type.
~MailRecipient(); ~MailRecipient();
/// Destroys the MailRecipient. /// Destroys the MailRecipient.
MailRecipient& operator = (const MailRecipient& recipient); MailRecipient& operator = (const MailRecipient& recipient);
/// Assigns another recipient. /// Assigns another recipient.
void swap(MailRecipient& recipient); void swap(MailRecipient& recipient);
/// Exchanges the content of two recipients. /// Exchanges the content of two recipients.
RecipientType getType() const; RecipientType getType() const;
/// Returns the type of the recipient. /// Returns the type of the recipient.
void setType(RecipientType type); void setType(RecipientType type);
/// Sets the type of the recipient. /// Sets the type of the recipient.
const std::string& getAddress() const; const std::string& getAddress() const;
/// Returns the address of the recipient. /// Returns the address of the recipient.
void setAddress(const std::string& address); void setAddress(const std::string& address);
/// Sets the address of the recipient. /// Sets the address of the recipient.
const std::string& getRealName() const; const std::string& getRealName() const;
/// Returns the real name of the recipient. /// Returns the real name of the recipient.
void setRealName(const std::string& realName); void setRealName(const std::string& realName);
/// Sets the real name of the recipient. /// Sets the real name of the recipient.
private: private:
std::string _address; std::string _address;
std::string _realName; std::string _realName;
RecipientType _type; RecipientType _type;
}; };
// //
// inlines // inlines
// //
inline MailRecipient::RecipientType MailRecipient::getType() const inline MailRecipient::RecipientType MailRecipient::getType() const
{ {
return _type; return _type;
} }
inline const std::string& MailRecipient::getAddress() const inline const std::string& MailRecipient::getAddress() const
{ {
return _address; return _address;
} }
inline const std::string& MailRecipient::getRealName() const inline const std::string& MailRecipient::getRealName() const
{ {
return _realName; return _realName;
} }
inline void swap(MailRecipient& r1, MailRecipient& r2) inline void swap(MailRecipient& r1, MailRecipient& r2)
{ {
r1.swap(r2); r1.swap(r2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MailRecipient_INCLUDED #endif // Net_MailRecipient_INCLUDED

View File

@ -1,168 +1,168 @@
// //
// MailStream.h // MailStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MailStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MailStream.h#1 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
// Module: MailStream // Module: MailStream
// //
// Definition of the MailStream class. // Definition of the MailStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MailStream_INCLUDED #ifndef Net_MailStream_INCLUDED
#define Net_MailStream_INCLUDED #define Net_MailStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API MailStreamBuf: public Poco::UnbufferedStreamBuf class Net_API MailStreamBuf: public Poco::UnbufferedStreamBuf
/// The sole purpose of this stream buffer is to replace /// The sole purpose of this stream buffer is to replace
/// a "\r\n.\r\n" character sequence with a "\r\n..\r\n" sequence for /// a "\r\n.\r\n" character sequence with a "\r\n..\r\n" sequence for
/// output streams and vice-versa for input streams. /// output streams and vice-versa for input streams.
/// ///
/// This is used when sending mail messages to SMTP servers, or /// This is used when sending mail messages to SMTP servers, or
/// receiving mail messages from POP servers. /// receiving mail messages from POP servers.
/// ///
/// See RFC 2181 (Simple Mail Transfer Protocol) and RFC 1939 /// See RFC 2181 (Simple Mail Transfer Protocol) and RFC 1939
/// (Post Office Protocol - Version 3) for more information. /// (Post Office Protocol - Version 3) for more information.
{ {
public: public:
MailStreamBuf(std::istream& istr); MailStreamBuf(std::istream& istr);
/// Creates the MailStreamBuf and connects it /// Creates the MailStreamBuf and connects it
/// to the given input stream. /// to the given input stream.
MailStreamBuf(std::ostream& ostr); MailStreamBuf(std::ostream& ostr);
/// Creates the MailStreamBuf and connects it /// Creates the MailStreamBuf and connects it
/// to the given output stream. /// to the given output stream.
~MailStreamBuf(); ~MailStreamBuf();
/// Destroys the MailStreamBuf. /// Destroys the MailStreamBuf.
void close(); void close();
/// Writes the terminating period, followed by /// Writes the terminating period, followed by
/// CR-LF. /// CR-LF.
protected: protected:
int readFromDevice(); int readFromDevice();
int writeToDevice(char c); int writeToDevice(char c);
int readOne(); int readOne();
private: private:
enum State enum State
{ {
ST_DATA, ST_DATA,
ST_CR, ST_CR,
ST_CR_LF, ST_CR_LF,
ST_CR_LF_DOT, ST_CR_LF_DOT,
ST_CR_LF_DOT_DOT, ST_CR_LF_DOT_DOT,
ST_CR_LF_DOT_CR, ST_CR_LF_DOT_CR,
ST_CR_LF_DOT_CR_LF ST_CR_LF_DOT_CR_LF
}; };
std::istream* _pIstr; std::istream* _pIstr;
std::ostream* _pOstr; std::ostream* _pOstr;
std::string _buffer; std::string _buffer;
State _state; State _state;
}; };
class Net_API MailIOS: public virtual std::ios class Net_API MailIOS: public virtual std::ios
/// The base class for MailInputStream and MailOutputStream. /// The base class for MailInputStream and MailOutputStream.
/// ///
/// This class provides common methods and is also needed to ensure /// This class provides common methods and is also needed to ensure
/// the correct initialization order of the stream buffer and base classes. /// the correct initialization order of the stream buffer and base classes.
{ {
public: public:
MailIOS(std::istream& istr); MailIOS(std::istream& istr);
/// Creates the MailIOS and connects it /// Creates the MailIOS and connects it
/// to the given input stream. /// to the given input stream.
MailIOS(std::ostream& ostr); MailIOS(std::ostream& ostr);
/// Creates the MailIOS and connects it /// Creates the MailIOS and connects it
/// to the given output stream. /// to the given output stream.
~MailIOS(); ~MailIOS();
/// Destroys the stream. /// Destroys the stream.
void close(); void close();
/// Writes the terminating period, followed by /// Writes the terminating period, followed by
/// CR-LF. /// CR-LF.
MailStreamBuf* rdbuf(); MailStreamBuf* rdbuf();
/// Returns a pointer to the underlying streambuf. /// Returns a pointer to the underlying streambuf.
protected: protected:
MailStreamBuf _buf; MailStreamBuf _buf;
}; };
class Net_API MailInputStream: public MailIOS, public std::istream class Net_API MailInputStream: public MailIOS, public std::istream
/// This class is used for reading E-Mail messages from a /// This class is used for reading E-Mail messages from a
/// POP3 server. All occurences of "\r\n..\r\n" are replaced with /// POP3 server. All occurences of "\r\n..\r\n" are replaced with
/// "\r\n.\r\n". The first occurence of "\r\n.\r\n" denotes the end /// "\r\n.\r\n". The first occurence of "\r\n.\r\n" denotes the end
/// of the stream. /// of the stream.
{ {
public: public:
MailInputStream(std::istream& istr); MailInputStream(std::istream& istr);
/// Creates the MailInputStream and connects it /// Creates the MailInputStream and connects it
/// to the given input stream. /// to the given input stream.
~MailInputStream(); ~MailInputStream();
/// Destroys the MailInputStream. /// Destroys the MailInputStream.
}; };
class Net_API MailOutputStream: public MailIOS, public std::ostream class Net_API MailOutputStream: public MailIOS, public std::ostream
/// This class is used for writing E-Mail messages to a /// This class is used for writing E-Mail messages to a
/// SMTP server. All occurences of "\r\n.\r\n" are replaced with /// SMTP server. All occurences of "\r\n.\r\n" are replaced with
/// "\r\n..\r\n". /// "\r\n..\r\n".
{ {
public: public:
MailOutputStream(std::ostream& ostr); MailOutputStream(std::ostream& ostr);
/// Creates the MailOutputStream and connects it /// Creates the MailOutputStream and connects it
/// to the given input stream. /// to the given input stream.
~MailOutputStream(); ~MailOutputStream();
/// Destroys the MailOutputStream. /// Destroys the MailOutputStream.
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MailStream_INCLUDED #endif // Net_MailStream_INCLUDED

View File

@ -1,170 +1,170 @@
// //
// MediaType.h // MediaType.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MediaType.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MediaType.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: MediaType // Module: MediaType
// //
// Definition of the MediaType class. // Definition of the MediaType class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MediaType_INCLUDED #ifndef Net_MediaType_INCLUDED
#define Net_MediaType_INCLUDED #define Net_MediaType_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/NameValueCollection.h" #include "Poco/Net/NameValueCollection.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API MediaType class Net_API MediaType
/// This class represents a MIME media type, consisting of /// This class represents a MIME media type, consisting of
/// a top-level type, a subtype and an optional set of /// a top-level type, a subtype and an optional set of
/// parameters. /// parameters.
/// ///
/// The implementation conforms with RFC 2045 and RFC 2046. /// The implementation conforms with RFC 2045 and RFC 2046.
{ {
public: public:
MediaType(const std::string& mediaType); MediaType(const std::string& mediaType);
/// Creates the MediaType from the given string, which /// Creates the MediaType from the given string, which
/// must have the format <type>/<subtype>{;<parameter>=<value>}. /// must have the format <type>/<subtype>{;<parameter>=<value>}.
MediaType(const std::string& type, const std::string& subType); MediaType(const std::string& type, const std::string& subType);
/// Creates the MediaType, using the given type and subtype. /// Creates the MediaType, using the given type and subtype.
MediaType(const MediaType& mediaType); MediaType(const MediaType& mediaType);
/// Creates a MediaType from another one. /// Creates a MediaType from another one.
~MediaType(); ~MediaType();
/// Destroys the MediaType. /// Destroys the MediaType.
MediaType& operator = (const MediaType& mediaType); MediaType& operator = (const MediaType& mediaType);
/// Assigns another media type. /// Assigns another media type.
MediaType& operator = (const std::string& mediaType); MediaType& operator = (const std::string& mediaType);
/// Assigns another media type. /// Assigns another media type.
void swap(MediaType& mediaType); void swap(MediaType& mediaType);
/// Swaps the MediaType with another one. /// Swaps the MediaType with another one.
void setType(const std::string& type); void setType(const std::string& type);
/// Sets the top-level type. /// Sets the top-level type.
const std::string& getType() const; const std::string& getType() const;
/// Returns the top-level type. /// Returns the top-level type.
void setSubType(const std::string& subType); void setSubType(const std::string& subType);
/// Sets the sub type. /// Sets the sub type.
const std::string& getSubType() const; const std::string& getSubType() const;
/// Returns the sub type. /// Returns the sub type.
void setParameter(const std::string& name, const std::string& value); void setParameter(const std::string& name, const std::string& value);
/// Sets the parameter with the given name. /// Sets the parameter with the given name.
const std::string& getParameter(const std::string& name) const; const std::string& getParameter(const std::string& name) const;
/// Returns the parameter with the given name. /// Returns the parameter with the given name.
/// ///
/// Throws a NotFoundException if the parameter does not exist. /// Throws a NotFoundException if the parameter does not exist.
bool hasParameter(const std::string& name) const; bool hasParameter(const std::string& name) const;
/// Returns true iff a parameter with the given name exists. /// Returns true iff a parameter with the given name exists.
void removeParameter(const std::string& name); void removeParameter(const std::string& name);
/// Removes the parameter with the given name. /// Removes the parameter with the given name.
const NameValueCollection& parameters() const; const NameValueCollection& parameters() const;
/// Returns the parameters. /// Returns the parameters.
std::string toString() const; std::string toString() const;
/// Returns the string representation of the media type /// Returns the string representation of the media type
/// which is <type>/<subtype>{;<parameter>=<value>} /// which is <type>/<subtype>{;<parameter>=<value>}
bool matches(const MediaType& mediaType) const; bool matches(const MediaType& mediaType) const;
/// Returns true iff the type and subtype match /// Returns true iff the type and subtype match
/// the type and subtype of the given media type. /// the type and subtype of the given media type.
/// Matching is case insensitive. /// Matching is case insensitive.
bool matches(const std::string& type, const std::string& subType) const; bool matches(const std::string& type, const std::string& subType) const;
/// Returns true iff the type and subtype match /// Returns true iff the type and subtype match
/// the given type and subtype. /// the given type and subtype.
/// Matching is case insensitive. /// Matching is case insensitive.
bool matches(const std::string& type) const; bool matches(const std::string& type) const;
/// Returns true iff the type matches the given type. /// Returns true iff the type matches the given type.
/// Matching is case insensitive. /// Matching is case insensitive.
protected: protected:
void parse(const std::string& mediaType); void parse(const std::string& mediaType);
private: private:
MediaType(); MediaType();
std::string _type; std::string _type;
std::string _subType; std::string _subType;
NameValueCollection _parameters; NameValueCollection _parameters;
}; };
// //
// inlines // inlines
// //
inline const std::string& MediaType::getType() const inline const std::string& MediaType::getType() const
{ {
return _type; return _type;
} }
inline const std::string& MediaType::getSubType() const inline const std::string& MediaType::getSubType() const
{ {
return _subType; return _subType;
} }
inline const NameValueCollection& MediaType::parameters() const inline const NameValueCollection& MediaType::parameters() const
{ {
return _parameters; return _parameters;
} }
inline void swap(MediaType& m1, MediaType& m2) inline void swap(MediaType& m1, MediaType& m2)
{ {
m1.swap(m2); m1.swap(m2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MediaType_INCLUDED #endif // Net_MediaType_INCLUDED

View File

@ -1,157 +1,157 @@
// //
// MessageHeader.h // MessageHeader.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MessageHeader.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MessageHeader.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: MessageHeader // Module: MessageHeader
// //
// Definition of the MessageHeader class. // Definition of the MessageHeader class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MessageHeader_INCLUDED #ifndef Net_MessageHeader_INCLUDED
#define Net_MessageHeader_INCLUDED #define Net_MessageHeader_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/NameValueCollection.h" #include "Poco/Net/NameValueCollection.h"
#include <ostream> #include <ostream>
#include <istream> #include <istream>
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API MessageHeader: public NameValueCollection class Net_API MessageHeader: public NameValueCollection
/// A collection of name-value pairs that are used in /// A collection of name-value pairs that are used in
/// various internet protocols like HTTP and SMTP. /// various internet protocols like HTTP and SMTP.
/// ///
/// The name is case-insensitive. /// The name is case-insensitive.
/// ///
/// There can be more than one name-value pair with the /// There can be more than one name-value pair with the
/// same name. /// same name.
/// ///
/// MessageHeader supports writing and reading the /// MessageHeader supports writing and reading the
/// header data in RFC 2822 format. /// header data in RFC 2822 format.
{ {
public: public:
MessageHeader(); MessageHeader();
/// Creates the MessageHeader. /// Creates the MessageHeader.
MessageHeader(const MessageHeader& messageHeader); MessageHeader(const MessageHeader& messageHeader);
/// Creates the MessageHeader by copying /// Creates the MessageHeader by copying
/// another one. /// another one.
virtual ~MessageHeader(); virtual ~MessageHeader();
/// Destroys the MessageHeader. /// Destroys the MessageHeader.
MessageHeader& operator = (const MessageHeader& messageHeader); MessageHeader& operator = (const MessageHeader& messageHeader);
/// Assigns the content of another MessageHeader. /// Assigns the content of another MessageHeader.
virtual void write(std::ostream& ostr) const; virtual void write(std::ostream& ostr) const;
/// Writes the message header to the given output stream. /// Writes the message header to the given output stream.
/// ///
/// The format is one name-value pair per line, with /// The format is one name-value pair per line, with
/// name and value separated by a colon and lines /// name and value separated by a colon and lines
/// delimited by a carriage return and a linefeed /// delimited by a carriage return and a linefeed
/// character. See RFC 2822 for details. /// character. See RFC 2822 for details.
virtual void read(std::istream& istr); virtual void read(std::istream& istr);
/// Reads the message header from the given input stream. /// Reads the message header from the given input stream.
/// ///
/// See write() for the expected format. /// See write() for the expected format.
/// Also supported is folding of field content, according /// Also supported is folding of field content, according
/// to section 2.2.3 of RFC 2822. /// to section 2.2.3 of RFC 2822.
/// ///
/// Reading stops at the first empty line (a line only /// Reading stops at the first empty line (a line only
/// containing \r\n or \n), as well as at the end of /// containing \r\n or \n), as well as at the end of
/// the stream. /// the stream.
/// ///
/// Some basic sanity checking of the input stream is /// Some basic sanity checking of the input stream is
/// performed. /// performed.
/// ///
/// Throws a MessageException if the input stream is /// Throws a MessageException if the input stream is
/// malformed. /// malformed.
static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true); static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
/// Splits the given string into separate elements. Elements are expected /// Splits the given string into separate elements. Elements are expected
/// to be separated by commas. /// to be separated by commas.
/// ///
/// For example, the string /// For example, the string
/// text/plain; q=0.5, text/html, text/x-dvi; q=0.8 /// text/plain; q=0.5, text/html, text/x-dvi; q=0.8
/// is split into the elements /// is split into the elements
/// text/plain; q=0.5 /// text/plain; q=0.5
/// text/html /// text/html
/// text/x-dvi; q=0.8 /// text/x-dvi; q=0.8
/// ///
/// Commas enclosed in double quotes do not split elements. /// Commas enclosed in double quotes do not split elements.
/// ///
/// If ignoreEmpty is true, empty elements are not returned. /// If ignoreEmpty is true, empty elements are not returned.
static void splitParameters(const std::string& s, std::string& value, NameValueCollection& parameters); static void splitParameters(const std::string& s, std::string& value, NameValueCollection& parameters);
/// Splits the given string into a value and a collection of parameters. /// Splits the given string into a value and a collection of parameters.
/// Parameters are expected to be separated by semicolons. /// Parameters are expected to be separated by semicolons.
/// ///
/// Enclosing quotes of parameter values are removed. /// Enclosing quotes of parameter values are removed.
/// ///
/// For example, the string /// For example, the string
/// multipart/mixed; boundary="MIME_boundary_01234567" /// multipart/mixed; boundary="MIME_boundary_01234567"
/// is split into the value /// is split into the value
/// multipart/mixed /// multipart/mixed
/// and the parameter /// and the parameter
/// boundary -> MIME_boundary_01234567 /// boundary -> MIME_boundary_01234567
static void splitParameters(const std::string::const_iterator& begin, const std::string::const_iterator& end, NameValueCollection& parameters); static void splitParameters(const std::string::const_iterator& begin, const std::string::const_iterator& end, NameValueCollection& parameters);
/// Splits the given string into a collection of parameters. /// Splits the given string into a collection of parameters.
/// Parameters are expected to be separated by semicolons. /// Parameters are expected to be separated by semicolons.
/// ///
/// Enclosing quotes of parameter values are removed. /// Enclosing quotes of parameter values are removed.
static void quote(const std::string& value, std::string& result, bool allowSpace = false); 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 /// Checks if the value must be quoted. If so, the value is
/// appended to result, enclosed in double-quotes. /// appended to result, enclosed in double-quotes.
/// Otherwise. the value is appended to result as-is. /// Otherwise. the value is appended to result as-is.
private: private:
enum Limits enum Limits
/// Limits for basic sanity checks when reading a header /// Limits for basic sanity checks when reading a header
{ {
MAX_NAME_LENGTH = 256, MAX_NAME_LENGTH = 256,
MAX_VALUE_LENGTH = 4096 MAX_VALUE_LENGTH = 4096
}; };
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MessageHeader_INCLUDED #endif // Net_MessageHeader_INCLUDED

View File

@ -1,138 +1,138 @@
// //
// MulticastSocket.h // MulticastSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MulticastSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MulticastSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: MulticastSocket // Module: MulticastSocket
// //
// Definition of the MulticastSocket class. // Definition of the MulticastSocket class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MulticastSocket_INCLUDED #ifndef Net_MulticastSocket_INCLUDED
#define Net_MulticastSocket_INCLUDED #define Net_MulticastSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/DatagramSocket.h" #include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/NetworkInterface.h" #include "Poco/Net/NetworkInterface.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API MulticastSocket: public DatagramSocket class Net_API MulticastSocket: public DatagramSocket
/// A MulticastSocket is a special DatagramSocket /// A MulticastSocket is a special DatagramSocket
/// that can be used to send packets to and receive /// that can be used to send packets to and receive
/// packets from multicast groups. /// packets from multicast groups.
{ {
public: public:
MulticastSocket(); MulticastSocket();
/// Creates the MulticastSocket. /// Creates the MulticastSocket.
MulticastSocket(IPAddress::Family family); MulticastSocket(IPAddress::Family family);
/// Creates an unconnected datagram socket. /// Creates an unconnected datagram socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
MulticastSocket(const SocketAddress& address, bool reuseAddress = false); MulticastSocket(const SocketAddress& address, bool reuseAddress = false);
/// Creates a datagram socket and binds it /// Creates a datagram socket and binds it
/// to the given address. /// to the given address.
/// ///
/// Depending on the address family, the socket /// Depending on the address family, the socket
/// will be either an IPv4 or an IPv6 socket. /// will be either an IPv4 or an IPv6 socket.
MulticastSocket(const Socket& socket); MulticastSocket(const Socket& socket);
/// Creates the DatagramSocket with the SocketImpl /// Creates the DatagramSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a DatagramSocketImpl, otherwise an InvalidArgumentException /// a DatagramSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
~MulticastSocket(); ~MulticastSocket();
/// Destroys the DatagramSocket. /// Destroys the DatagramSocket.
MulticastSocket& operator = (const Socket& socket); MulticastSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
void setInterface(const NetworkInterface& interface); void setInterface(const NetworkInterface& interface);
/// Sets the interface used for sending multicast packets. /// Sets the interface used for sending multicast packets.
/// ///
/// To select the default interface, specify an empty /// To select the default interface, specify an empty
/// interface. /// interface.
/// ///
/// This is done by setting the IP_MULTICAST_IF/IPV6_MULTICAST_IF /// This is done by setting the IP_MULTICAST_IF/IPV6_MULTICAST_IF
/// socket option. /// socket option.
NetworkInterface getInterface() const; NetworkInterface getInterface() const;
/// Returns the interface used for sending multicast packets. /// Returns the interface used for sending multicast packets.
void setLoopback(bool flag); void setLoopback(bool flag);
/// Enable or disable loopback for multicast packets. /// Enable or disable loopback for multicast packets.
/// ///
/// Sets the value of the IP_MULTICAST_LOOP/IPV6_MULTICAST_LOOP /// Sets the value of the IP_MULTICAST_LOOP/IPV6_MULTICAST_LOOP
/// socket option. /// socket option.
bool getLoopback() const; bool getLoopback() const;
/// Returns true iff loopback for multicast packets is enabled, /// Returns true iff loopback for multicast packets is enabled,
/// false otherwise. /// false otherwise.
void setTimeToLive(unsigned value); void setTimeToLive(unsigned value);
/// Specifies the TTL/hop limit for outgoing packets. /// Specifies the TTL/hop limit for outgoing packets.
/// ///
/// Sets the value of the IP_MULTICAST_TTL/IPV6_MULTICAST_HOPS /// Sets the value of the IP_MULTICAST_TTL/IPV6_MULTICAST_HOPS
/// socket option. /// socket option.
unsigned getTimeToLive() const; unsigned getTimeToLive() const;
/// Returns the TTL/hop limit for outgoing packets. /// Returns the TTL/hop limit for outgoing packets.
void joinGroup(const IPAddress& groupAddress); void joinGroup(const IPAddress& groupAddress);
/// Joins the specified multicast group at the default interface. /// Joins the specified multicast group at the default interface.
void joinGroup(const IPAddress& groupAddress, const NetworkInterface& interface); void joinGroup(const IPAddress& groupAddress, const NetworkInterface& interface);
/// Joins the specified multicast group at the given interface. /// Joins the specified multicast group at the given interface.
void leaveGroup(const IPAddress& groupAddress); void leaveGroup(const IPAddress& groupAddress);
/// Leaves the specified multicast group at the default interface. /// Leaves the specified multicast group at the default interface.
void leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interface); void leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interface);
/// Leaves the specified multicast group at the given interface. /// Leaves the specified multicast group at the given interface.
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MulticastSocket_INCLUDED #endif // Net_MulticastSocket_INCLUDED

View File

@ -1,182 +1,182 @@
// //
// MultipartReader.h // MultipartReader.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#2 $ // $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#2 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: MultipartReader // Module: MultipartReader
// //
// Definition of the MultipartReader class. // Definition of the MultipartReader class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MultipartReader_INCLUDED #ifndef Net_MultipartReader_INCLUDED
#define Net_MultipartReader_INCLUDED #define Net_MultipartReader_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/BufferedStreamBuf.h" #include "Poco/BufferedStreamBuf.h"
#include <istream> #include <istream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MessageHeader; class MessageHeader;
class Net_API MultipartStreamBuf: public Poco::BufferedStreamBuf class Net_API MultipartStreamBuf: public Poco::BufferedStreamBuf
/// This is the streambuf class used for reading from a multipart message stream. /// This is the streambuf class used for reading from a multipart message stream.
{ {
public: public:
MultipartStreamBuf(std::istream& istr, const std::string& boundary); MultipartStreamBuf(std::istream& istr, const std::string& boundary);
~MultipartStreamBuf(); ~MultipartStreamBuf();
bool lastPart() const; bool lastPart() const;
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
private: private:
enum enum
{ {
STREAM_BUFFER_SIZE = 1024 STREAM_BUFFER_SIZE = 1024
}; };
std::istream& _istr; std::istream& _istr;
std::string _boundary; std::string _boundary;
bool _lastPart; bool _lastPart;
}; };
class Net_API MultipartIOS: public virtual std::ios class Net_API MultipartIOS: public virtual std::ios
/// The base class for MultipartInputStream. /// The base class for MultipartInputStream.
{ {
public: public:
MultipartIOS(std::istream& istr, const std::string& boundary); MultipartIOS(std::istream& istr, const std::string& boundary);
~MultipartIOS(); ~MultipartIOS();
MultipartStreamBuf* rdbuf(); MultipartStreamBuf* rdbuf();
bool lastPart() const; bool lastPart() const;
protected: protected:
MultipartStreamBuf _buf; MultipartStreamBuf _buf;
}; };
class Net_API MultipartInputStream: public MultipartIOS, public std::istream class Net_API MultipartInputStream: public MultipartIOS, public std::istream
/// This class is for internal use by MultipartReader only. /// This class is for internal use by MultipartReader only.
{ {
public: public:
MultipartInputStream(std::istream& istr, const std::string& boundary); MultipartInputStream(std::istream& istr, const std::string& boundary);
~MultipartInputStream(); ~MultipartInputStream();
}; };
class Net_API MultipartReader class Net_API MultipartReader
/// This class is used to split a MIME multipart /// This class is used to split a MIME multipart
/// message into its single parts. /// message into its single parts.
/// ///
/// The format of multipart messages is described /// The format of multipart messages is described
/// in section 7.2 of RFC 1341. /// in section 7.2 of RFC 1341.
/// ///
/// To split a multipart message into its parts, /// To split a multipart message into its parts,
/// do the following: /// do the following:
/// - Create a MultipartReader object, passing it /// - Create a MultipartReader object, passing it
/// an input stream and optionally a boundary string. /// an input stream and optionally a boundary string.
/// - while hasNextPart() returns true, call nextPart() /// - while hasNextPart() returns true, call nextPart()
/// and read the part from stream(). /// and read the part from stream().
/// ///
/// Always ensure that you read all data from the part /// Always ensure that you read all data from the part
/// stream, otherwise the MultipartReader will fail to /// stream, otherwise the MultipartReader will fail to
/// find the next part. /// find the next part.
{ {
public: public:
explicit MultipartReader(std::istream& istr); explicit MultipartReader(std::istream& istr);
/// Creates the MultipartReader and attaches it to the /// Creates the MultipartReader and attaches it to the
/// given input stream. /// given input stream.
/// ///
/// The boundary string is determined from the input /// The boundary string is determined from the input
/// stream. The message must not contain a preamble /// stream. The message must not contain a preamble
/// preceding the first encapsulation boundary. /// preceding the first encapsulation boundary.
MultipartReader(std::istream& istr, const std::string& boundary); MultipartReader(std::istream& istr, const std::string& boundary);
/// Creates the MultipartReader and attaches it to the /// Creates the MultipartReader and attaches it to the
/// given input stream. The given boundary string is /// given input stream. The given boundary string is
/// used to find message boundaries. /// used to find message boundaries.
~MultipartReader(); ~MultipartReader();
/// Destroys the MultipartReader. /// Destroys the MultipartReader.
void nextPart(MessageHeader& messageHeader); void nextPart(MessageHeader& messageHeader);
/// Moves to the next part in the message and stores the /// Moves to the next part in the message and stores the
/// part's header fields in messageHeader. /// part's header fields in messageHeader.
/// ///
/// Throws an MultipartException if there are no more parts /// Throws an MultipartException if there are no more parts
/// available, or if no boundary line can be found in /// available, or if no boundary line can be found in
/// the input stream. /// the input stream.
bool hasNextPart(); bool hasNextPart();
/// Returns true iff more parts are available. /// Returns true iff more parts are available.
/// ///
/// Before the first call to nextPart(), returns /// Before the first call to nextPart(), returns
/// always true. /// always true.
std::istream& stream() const; std::istream& stream() const;
/// Returns a reference to the reader's stream that /// Returns a reference to the reader's stream that
/// can be used to read the current part. /// can be used to read the current part.
/// ///
/// The returned reference will be valid until /// The returned reference will be valid until
/// nextPart() is called or the MultipartReader /// nextPart() is called or the MultipartReader
/// object is destroyed. /// object is destroyed.
const std::string& boundary() const; const std::string& boundary() const;
/// Returns the multipart boundary used by this reader. /// Returns the multipart boundary used by this reader.
protected: protected:
void findFirstBoundary(); void findFirstBoundary();
void guessBoundary(); void guessBoundary();
void parseHeader(MessageHeader& messageHeader); void parseHeader(MessageHeader& messageHeader);
bool readLine(std::string& line, std::string::size_type n); bool readLine(std::string& line, std::string::size_type n);
private: private:
MultipartReader(); MultipartReader();
MultipartReader(const MultipartReader&); MultipartReader(const MultipartReader&);
MultipartReader& operator = (const MultipartReader&); MultipartReader& operator = (const MultipartReader&);
std::istream& _istr; std::istream& _istr;
std::string _boundary; std::string _boundary;
MultipartInputStream* _pMPI; MultipartInputStream* _pMPI;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MultipartReader_INCLUDED #endif // Net_MultipartReader_INCLUDED

View File

@ -1,130 +1,130 @@
// //
// MultipartWriter.h // MultipartWriter.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MultipartWriter.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MultipartWriter.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: MultipartWriter // Module: MultipartWriter
// //
// Definition of the MultipartWriter class. // Definition of the MultipartWriter class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_MultipartWriter_INCLUDED #ifndef Net_MultipartWriter_INCLUDED
#define Net_MultipartWriter_INCLUDED #define Net_MultipartWriter_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MessageHeader; class MessageHeader;
class Net_API MultipartWriter class Net_API MultipartWriter
/// This class is used to write MIME multipart /// This class is used to write MIME multipart
/// messages to an output stream. /// messages to an output stream.
/// ///
/// The format of multipart messages is described /// The format of multipart messages is described
/// in section 7.2 of RFC 1341. /// in section 7.2 of RFC 1341.
/// ///
/// To create a multipart message, first create /// To create a multipart message, first create
/// a MultipartWriter object. /// a MultipartWriter object.
/// Then, for each part, call nextPart() and /// Then, for each part, call nextPart() and
/// write the content to the output stream. /// write the content to the output stream.
/// Repeat for all parts. /// Repeat for all parts.
/// After the last part has been written, /// After the last part has been written,
/// call close() to finish the multipart message. /// call close() to finish the multipart message.
{ {
public: public:
explicit MultipartWriter(std::ostream& ostr); explicit MultipartWriter(std::ostream& ostr);
/// Creates the MultipartWriter, using the /// Creates the MultipartWriter, using the
/// given output stream. /// given output stream.
/// ///
/// Creates a random boundary string. /// Creates a random boundary string.
MultipartWriter(std::ostream& ostr, const std::string& boundary); MultipartWriter(std::ostream& ostr, const std::string& boundary);
/// Creates the MultipartWriter, using the /// Creates the MultipartWriter, using the
/// given output stream and boundary string. /// given output stream and boundary string.
~MultipartWriter(); ~MultipartWriter();
/// Destroys the MultipartWriter. /// Destroys the MultipartWriter.
void nextPart(const MessageHeader& header); void nextPart(const MessageHeader& header);
/// Opens a new message part and writes /// Opens a new message part and writes
/// the message boundary string, followed /// the message boundary string, followed
/// by the message header to the stream. /// by the message header to the stream.
void close(); void close();
/// Closes the multipart message and writes /// Closes the multipart message and writes
/// the terminating boundary string. /// the terminating boundary string.
/// ///
/// Does not close the underlying stream. /// Does not close the underlying stream.
std::ostream& stream(); std::ostream& stream();
/// Returns the writer's stream. /// Returns the writer's stream.
const std::string& boundary() const; const std::string& boundary() const;
/// Returns the multipart boundary used by this writer. /// Returns the multipart boundary used by this writer.
static std::string createBoundary(); static std::string createBoundary();
/// Creates a random boundary string. /// Creates a random boundary string.
/// ///
/// The string always has the form /// The string always has the form
/// MIME_boundary_XXXXXXXXXXXX, where /// MIME_boundary_XXXXXXXXXXXX, where
/// XXXXXXXXXXXX is a random hexadecimal /// XXXXXXXXXXXX is a random hexadecimal
/// number. /// number.
private: private:
MultipartWriter(); MultipartWriter();
MultipartWriter(const MultipartWriter&); MultipartWriter(const MultipartWriter&);
MultipartWriter& operator = (const MultipartWriter&); MultipartWriter& operator = (const MultipartWriter&);
std::ostream& _ostr; std::ostream& _ostr;
std::string _boundary; std::string _boundary;
}; };
// //
// inlines // inlines
// //
inline std::ostream& MultipartWriter::stream() inline std::ostream& MultipartWriter::stream()
{ {
return _ostr; return _ostr;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_MultipartWriter_INCLUDED #endif // Net_MultipartWriter_INCLUDED

View File

@ -1,155 +1,155 @@
// //
// NameValueCollection.h // NameValueCollection.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/NameValueCollection.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/NameValueCollection.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: NameValueCollection // Module: NameValueCollection
// //
// Definition of the NameValueCollection class. // Definition of the NameValueCollection class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_NameValueCollection_INCLUDED #ifndef Net_NameValueCollection_INCLUDED
#define Net_NameValueCollection_INCLUDED #define Net_NameValueCollection_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/String.h" #include "Poco/String.h"
#include <map> #include <map>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API NameValueCollection class Net_API NameValueCollection
/// A collection of name-value pairs that are used in /// A collection of name-value pairs that are used in
/// various internet protocols like HTTP and SMTP. /// various internet protocols like HTTP and SMTP.
/// ///
/// The name is case-insensitive. /// The name is case-insensitive.
/// ///
/// There can be more than one name-value pair with the /// There can be more than one name-value pair with the
/// same name. /// same name.
{ {
public: public:
struct ILT struct ILT
{ {
bool operator() (const std::string& s1, const std::string& s2) const bool operator() (const std::string& s1, const std::string& s2) const
{ {
return Poco::icompare(s1, s2) < 0; return Poco::icompare(s1, s2) < 0;
} }
}; };
typedef std::multimap<std::string, std::string, ILT> HeaderMap; typedef std::multimap<std::string, std::string, ILT> HeaderMap;
typedef HeaderMap::iterator Iterator; typedef HeaderMap::iterator Iterator;
typedef HeaderMap::const_iterator ConstIterator; typedef HeaderMap::const_iterator ConstIterator;
NameValueCollection(); NameValueCollection();
/// Creates an empty NameValueCollection. /// Creates an empty NameValueCollection.
NameValueCollection(const NameValueCollection& nvc); NameValueCollection(const NameValueCollection& nvc);
/// Creates a NameValueCollection by copying another one. /// Creates a NameValueCollection by copying another one.
virtual ~NameValueCollection(); virtual ~NameValueCollection();
/// Destroys the NameValueCollection. /// Destroys the NameValueCollection.
NameValueCollection& operator = (const NameValueCollection& nvc); NameValueCollection& operator = (const NameValueCollection& nvc);
/// Assigns the name-value pairs of another NameValueCollection to this one. /// Assigns the name-value pairs of another NameValueCollection to this one.
void swap(NameValueCollection& nvc); void swap(NameValueCollection& nvc);
/// Swaps the NameValueCollection with another one. /// Swaps the NameValueCollection with another one.
const std::string& operator [] (const std::string& name) const; const std::string& operator [] (const std::string& name) const;
/// Returns the value of the (first) name-value pair with the given name. /// Returns the value of the (first) name-value pair with the given name.
/// ///
/// Throws a NotFoundException if the name-value pair does not exist. /// Throws a NotFoundException if the name-value pair does not exist.
void set(const std::string& name, const std::string& value); void set(const std::string& name, const std::string& value);
/// Sets the value of the (first) name-value pair with the given name. /// Sets the value of the (first) name-value pair with the given name.
void add(const std::string& name, const std::string& value); void add(const std::string& name, const std::string& value);
/// Adds a new name-value pair with the given name and value. /// Adds a new name-value pair with the given name and value.
const std::string& get(const std::string& name) const; const std::string& get(const std::string& name) const;
/// Returns the value of the first name-value pair with the given name. /// Returns the value of the first name-value pair with the given name.
/// ///
/// Throws a NotFoundException if the name-value pair does not exist. /// Throws a NotFoundException if the name-value pair does not exist.
const std::string& get(const std::string& name, const std::string& defaultValue) const; const std::string& get(const std::string& name, const std::string& defaultValue) const;
/// Returns the value of the first name-value pair with the given name. /// Returns the value of the first name-value pair with the given name.
/// If no value with the given name has been found, the defaultValue is returned. /// If no value with the given name has been found, the defaultValue is returned.
bool has(const std::string& name) const; bool has(const std::string& name) const;
/// Returns true if there is at least one name-value pair /// Returns true if there is at least one name-value pair
/// with the given name. /// with the given name.
ConstIterator find(const std::string& name) const; ConstIterator find(const std::string& name) const;
/// Returns an iterator pointing to the first name-value pair /// Returns an iterator pointing to the first name-value pair
/// with the given name. /// with the given name.
ConstIterator begin() const; ConstIterator begin() const;
/// Returns an iterator pointing to the begin of /// Returns an iterator pointing to the begin of
/// the name-value pair collection. /// the name-value pair collection.
ConstIterator end() const; ConstIterator end() const;
/// Returns an iterator pointing to the end of /// Returns an iterator pointing to the end of
/// the name-value pair collection. /// the name-value pair collection.
bool empty() const; bool empty() const;
/// Returns true iff the header does not have any content. /// Returns true iff the header does not have any content.
int size() const; int size() const;
/// Returns the number of name-value pairs in the /// Returns the number of name-value pairs in the
/// collection. /// collection.
void erase(const std::string& name); void erase(const std::string& name);
/// Removes all name-value pairs with the given name. /// Removes all name-value pairs with the given name.
void clear(); void clear();
/// Removes all name-value pairs and their values. /// Removes all name-value pairs and their values.
private: private:
HeaderMap _map; HeaderMap _map;
}; };
// //
// inlines // inlines
// //
inline void swap(NameValueCollection& nvc1, NameValueCollection& nvc2) inline void swap(NameValueCollection& nvc1, NameValueCollection& nvc2)
{ {
nvc1.swap(nvc2); nvc1.swap(nvc2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_NameValueCollection_INCLUDED #endif // Net_NameValueCollection_INCLUDED

View File

@ -1,70 +1,70 @@
// //
// Net.h // Net.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/Net.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/Net.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: IPAddress // Module: IPAddress
// //
// Basic definitions for the Poco Net library. // Basic definitions for the Poco Net library.
// This file must be the first file included by every other Net // This file must be the first file included by every other Net
// header file. // header file.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_Net_INCLUDED #ifndef Net_Net_INCLUDED
#define Net_Net_INCLUDED #define Net_Net_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
// //
// The following block is the standard way of creating macros which make exporting // The following block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the Net_EXPORTS // from a DLL simpler. All files within this DLL are compiled with the Net_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project // symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see // that uses this DLL. This way any other project whose source files include this file see
// Net_API functions as being imported from a DLL, wheras this DLL sees symbols // Net_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported. // defined with this macro as being exported.
// //
#if defined(_WIN32) && defined(POCO_DLL) #if defined(_WIN32) && defined(POCO_DLL)
#if defined(Net_EXPORTS) #if defined(Net_EXPORTS)
#define Net_API __declspec(dllexport) #define Net_API __declspec(dllexport)
#else #else
#define Net_API __declspec(dllimport) #define Net_API __declspec(dllimport)
#endif #endif
#endif #endif
#if !defined(Net_API) #if !defined(Net_API)
#define Net_API #define Net_API
#endif #endif
#endif // Net_Net_INCLUDED #endif // Net_Net_INCLUDED

View File

@ -1,75 +1,75 @@
// //
// NetException.h // NetException.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/NetException.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/NetException.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: NetException // Module: NetException
// //
// Definition of the NetException class. // Definition of the NetException class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_NetException_INCLUDED #ifndef Net_NetException_INCLUDED
#define Net_NetException_INCLUDED #define Net_NetException_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
POCO_DECLARE_EXCEPTION(Net_API, NetException, Poco::IOException) POCO_DECLARE_EXCEPTION(Net_API, NetException, Poco::IOException)
POCO_DECLARE_EXCEPTION(Net_API, InvalidAddressException, NetException) POCO_DECLARE_EXCEPTION(Net_API, InvalidAddressException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ServiceNotFoundException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ServiceNotFoundException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ConnectionAbortedException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ConnectionAbortedException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ConnectionResetException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ConnectionResetException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ConnectionRefusedException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ConnectionRefusedException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, DNSException, NetException) POCO_DECLARE_EXCEPTION(Net_API, DNSException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, HostNotFoundException, DNSException) POCO_DECLARE_EXCEPTION(Net_API, HostNotFoundException, DNSException)
POCO_DECLARE_EXCEPTION(Net_API, NoAddressFoundException, DNSException) POCO_DECLARE_EXCEPTION(Net_API, NoAddressFoundException, DNSException)
POCO_DECLARE_EXCEPTION(Net_API, InterfaceNotFoundException, NetException) POCO_DECLARE_EXCEPTION(Net_API, InterfaceNotFoundException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, MessageException, NetException) POCO_DECLARE_EXCEPTION(Net_API, MessageException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, MultipartException, MessageException) POCO_DECLARE_EXCEPTION(Net_API, MultipartException, MessageException)
POCO_DECLARE_EXCEPTION(Net_API, HTTPException, NetException) POCO_DECLARE_EXCEPTION(Net_API, HTTPException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, NotAuthenticatedException, HTTPException) POCO_DECLARE_EXCEPTION(Net_API, NotAuthenticatedException, HTTPException)
POCO_DECLARE_EXCEPTION(Net_API, UnsupportedRedirectException, HTTPException) POCO_DECLARE_EXCEPTION(Net_API, UnsupportedRedirectException, HTTPException)
POCO_DECLARE_EXCEPTION(Net_API, FTPException, NetException) POCO_DECLARE_EXCEPTION(Net_API, FTPException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, SMTPException, NetException) POCO_DECLARE_EXCEPTION(Net_API, SMTPException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException) POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException)
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_NetException_INCLUDED #endif // Net_NetException_INCLUDED

View File

@ -1,185 +1,185 @@
// //
// NetworkInterface.h // NetworkInterface.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/NetworkInterface.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/NetworkInterface.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: NetworkInterface // Module: NetworkInterface
// //
// Definition of the NetworkInterface class. // Definition of the NetworkInterface class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_NetworkInterface_INCLUDED #ifndef Net_NetworkInterface_INCLUDED
#define Net_NetworkInterface_INCLUDED #define Net_NetworkInterface_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API NetworkInterface class Net_API NetworkInterface
/// This class represents a network interface. /// This class represents a network interface.
/// ///
/// NetworkInterface is used with MulticastSocket to specify /// NetworkInterface is used with MulticastSocket to specify
/// multicast interfaces for sending and receiving multicast /// multicast interfaces for sending and receiving multicast
/// messages. /// messages.
{ {
public: public:
typedef std::vector<NetworkInterface> NetworkInterfaceList; typedef std::vector<NetworkInterface> NetworkInterfaceList;
NetworkInterface(); NetworkInterface();
/// Creates a NetworkInterface representing the /// Creates a NetworkInterface representing the
/// default interface. /// default interface.
/// ///
/// The name is empty, the IP address is the wildcard /// The name is empty, the IP address is the wildcard
/// address and the index is zero. /// address and the index is zero.
NetworkInterface(const NetworkInterface& interface); NetworkInterface(const NetworkInterface& interface);
/// Creates the NetworkInterface by copying another one. /// Creates the NetworkInterface by copying another one.
~NetworkInterface(); ~NetworkInterface();
/// Destroys the NetworkInterface. /// Destroys the NetworkInterface.
NetworkInterface& operator = (const NetworkInterface& interface); NetworkInterface& operator = (const NetworkInterface& interface);
/// Assigns another NetworkInterface. /// Assigns another NetworkInterface.
int index() const; int index() const;
/// Returns the interface index. /// Returns the interface index.
/// ///
/// Only supported if IPv6 is available. /// Only supported if IPv6 is available.
/// Returns -1 if IPv6 is not available. /// Returns -1 if IPv6 is not available.
const std::string& name() const; const std::string& name() const;
/// Returns the interface name. /// Returns the interface name.
const IPAddress& address() const; const IPAddress& address() const;
/// Returns the IP address bound to the interface. /// Returns the IP address bound to the interface.
bool supportsIPv4() const; bool supportsIPv4() const;
/// Returns true if the interface supports IPv4. /// Returns true if the interface supports IPv4.
bool supportsIPv6() const; bool supportsIPv6() const;
/// Returns true if the interface supports IPv6. /// Returns true if the interface supports IPv6.
static NetworkInterface forName(const std::string& name, bool requireIPv6 = false); static NetworkInterface forName(const std::string& name, bool requireIPv6 = false);
/// Returns the NetworkInterface for the given name. /// Returns the NetworkInterface for the given name.
/// ///
/// If requireIPv6 is false, an IPv4 interface is returned. /// If requireIPv6 is false, an IPv4 interface is returned.
/// Otherwise, an IPv6 interface is returned. /// Otherwise, an IPv6 interface is returned.
/// ///
/// Throws an InterfaceNotFoundException if an interface /// Throws an InterfaceNotFoundException if an interface
/// with the give name does not exist. /// with the give name does not exist.
static NetworkInterface forAddress(const IPAddress& address); static NetworkInterface forAddress(const IPAddress& address);
/// Returns the NetworkInterface for the given IP address. /// Returns the NetworkInterface for the given IP address.
/// ///
/// Throws an InterfaceNotFoundException if an interface /// Throws an InterfaceNotFoundException if an interface
/// with the give address does not exist. /// with the give address does not exist.
static NetworkInterface forIndex(int index); static NetworkInterface forIndex(int index);
/// Returns the NetworkInterface for the given interface index. /// Returns the NetworkInterface for the given interface index.
/// If an index of 0 is specified, a NetworkInterface instance /// If an index of 0 is specified, a NetworkInterface instance
/// representing the default interface (empty name and /// representing the default interface (empty name and
/// wildcard address) is returned. /// wildcard address) is returned.
/// ///
/// Throws an InterfaceNotFoundException if an interface /// Throws an InterfaceNotFoundException if an interface
/// with the given index does not exist (or IPv6 is not /// with the given index does not exist (or IPv6 is not
/// available). /// available).
static NetworkInterfaceList list(); static NetworkInterfaceList list();
/// Returns a list with all network interfaces /// Returns a list with all network interfaces
/// on the system. /// on the system.
/// ///
/// If there are multiple addresses bound to one interface, /// If there are multiple addresses bound to one interface,
/// multiple NetworkInterface instances are created for /// multiple NetworkInterface instances are created for
/// the same interface. /// the same interface.
protected: protected:
NetworkInterface(const std::string& name, const IPAddress& address, int index = -1); NetworkInterface(const std::string& name, const IPAddress& address, int index = -1);
/// Creates the NetworkInterface. /// Creates the NetworkInterface.
IPAddress interfaceNameToAddress(const std::string& interfaceName) const; IPAddress interfaceNameToAddress(const std::string& interfaceName) const;
/// Determines the IPAddress bound to the interface with the given name. /// Determines the IPAddress bound to the interface with the given name.
int interfaceNameToIndex(const std::string& interfaceName) const; int interfaceNameToIndex(const std::string& interfaceName) const;
/// Determines the interface index of the interface with the given name. /// Determines the interface index of the interface with the given name.
private: private:
std::string _name; std::string _name;
IPAddress _address; IPAddress _address;
int _index; int _index;
static Poco::FastMutex _mutex; static Poco::FastMutex _mutex;
}; };
// //
// inlines // inlines
// //
inline int NetworkInterface::index() const inline int NetworkInterface::index() const
{ {
return _index; return _index;
} }
inline const std::string& NetworkInterface::name() const inline const std::string& NetworkInterface::name() const
{ {
return _name; return _name;
} }
inline const IPAddress& NetworkInterface::address() const inline const IPAddress& NetworkInterface::address() const
{ {
return _address; return _address;
} }
inline bool NetworkInterface::supportsIPv4() const inline bool NetworkInterface::supportsIPv4() const
{ {
return _index == -1; return _index == -1;
} }
inline bool NetworkInterface::supportsIPv6() const inline bool NetworkInterface::supportsIPv6() const
{ {
return _index != -1; return _index != -1;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_NetworkInterface_INCLUDED #endif // Net_NetworkInterface_INCLUDED

View File

@ -1,69 +1,69 @@
// //
// NullPartHandler.h // NullPartHandler.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/NullPartHandler.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/NullPartHandler.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: NullPartHandler // Module: NullPartHandler
// //
// Definition of the NullPartHandler class. // Definition of the NullPartHandler class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_NullPartHandler_INCLUDED #ifndef Net_NullPartHandler_INCLUDED
#define Net_NullPartHandler_INCLUDED #define Net_NullPartHandler_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/PartHandler.h" #include "Poco/Net/PartHandler.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API NullPartHandler: public PartHandler class Net_API NullPartHandler: public PartHandler
/// A very special PartHandler that simply discards all data. /// A very special PartHandler that simply discards all data.
{ {
public: public:
NullPartHandler(); NullPartHandler();
/// Creates the NullPartHandler. /// Creates the NullPartHandler.
~NullPartHandler(); ~NullPartHandler();
/// Destroys the NullPartHandler. /// Destroys the NullPartHandler.
void handlePart(const MessageHeader& header, std::istream& stream); void handlePart(const MessageHeader& header, std::istream& stream);
/// Reads and discards all data from the stream. /// Reads and discards all data from the stream.
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_NullPartHandler_INCLUDED #endif // Net_NullPartHandler_INCLUDED

View File

@ -1,207 +1,207 @@
// //
// POP3ClientSession.h // POP3ClientSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/POP3ClientSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/POP3ClientSession.h#1 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
// Module: POP3ClientSession // Module: POP3ClientSession
// //
// Definition of the POP3ClientSession class. // Definition of the POP3ClientSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_POP3ClientSession_INCLUDED #ifndef Net_POP3ClientSession_INCLUDED
#define Net_POP3ClientSession_INCLUDED #define Net_POP3ClientSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/DialogSocket.h" #include "Poco/Net/DialogSocket.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include <ostream> #include <ostream>
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MessageHeader; class MessageHeader;
class MailMessage; class MailMessage;
class PartHandler; class PartHandler;
class Net_API POP3ClientSession class Net_API POP3ClientSession
/// This class implements an Post Office Protocol /// This class implements an Post Office Protocol
/// Version 3 (POP3, RFC 1939) /// Version 3 (POP3, RFC 1939)
/// client for receiving e-mail messages. /// client for receiving e-mail messages.
{ {
public: public:
enum enum
{ {
POP3_PORT = 110 POP3_PORT = 110
}; };
struct MessageInfo struct MessageInfo
/// Information returned by listMessages(). /// Information returned by listMessages().
{ {
int id; int id;
int size; int size;
}; };
typedef std::vector<MessageInfo> MessageInfoVec; typedef std::vector<MessageInfo> MessageInfoVec;
POP3ClientSession(const StreamSocket& socket); POP3ClientSession(const StreamSocket& socket);
/// Creates the POP3ClientSession using /// Creates the POP3ClientSession using
/// the given socket, which must be connected /// the given socket, which must be connected
/// to a POP3 server. /// to a POP3 server.
POP3ClientSession(const std::string& host, Poco::UInt16 port = POP3_PORT); POP3ClientSession(const std::string& host, Poco::UInt16 port = POP3_PORT);
/// Creates the POP3ClientSession using a socket connected /// Creates the POP3ClientSession using a socket connected
/// to the given host and port. /// to the given host and port.
virtual ~POP3ClientSession(); virtual ~POP3ClientSession();
/// Destroys the SMTPClientSession. /// Destroys the SMTPClientSession.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the timeout for socket read operations. /// Sets the timeout for socket read operations.
Poco::Timespan getTimeout() const; Poco::Timespan getTimeout() const;
/// Returns the timeout for socket read operations. /// Returns the timeout for socket read operations.
void login(const std::string& username, const std::string& password); void login(const std::string& username, const std::string& password);
/// Logs in to the POP3 server by sending a USER command /// Logs in to the POP3 server by sending a USER command
/// followed by a PASS command. /// followed by a PASS command.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void close(); void close();
/// Sends a QUIT command and closes the connection to the server. /// Sends a QUIT command and closes the connection to the server.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
int messageCount(); int messageCount();
/// Sends a STAT command to determine the number of messages /// Sends a STAT command to determine the number of messages
/// available on the server and returns that number. /// available on the server and returns that number.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void listMessages(MessageInfoVec& messages); void listMessages(MessageInfoVec& messages);
/// Fills the given vector with the ids and sizes of all /// Fills the given vector with the ids and sizes of all
/// messages available on the server. /// messages available on the server.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void retrieveMessage(int id, MailMessage& message); void retrieveMessage(int id, MailMessage& message);
/// Retrieves the message with the given id from the server and /// Retrieves the message with the given id from the server and
/// stores the raw message content in the message's /// stores the raw message content in the message's
/// content string, available with message.getContent(). /// content string, available with message.getContent().
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void retrieveMessage(int id, MailMessage& message, PartHandler& handler); void retrieveMessage(int id, MailMessage& message, PartHandler& handler);
/// Retrieves the message with the given id from the server and /// Retrieves the message with the given id from the server and
/// stores it in message. /// stores it in message.
/// ///
/// If the message has multiple parts, the parts /// If the message has multiple parts, the parts
/// are reported to the PartHandler. If the message /// are reported to the PartHandler. If the message
/// is not a multi-part message, the content is stored /// is not a multi-part message, the content is stored
/// in a string available by calling message.getContent(). /// in a string available by calling message.getContent().
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void retrieveMessage(int id, std::ostream& ostr); void retrieveMessage(int id, std::ostream& ostr);
/// Retrieves the raw message with the given id from the /// Retrieves the raw message with the given id from the
/// server and copies it to the given output stream. /// server and copies it to the given output stream.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void retrieveHeader(int id, MessageHeader& header); void retrieveHeader(int id, MessageHeader& header);
/// Retrieves the message header of the message with the /// Retrieves the message header of the message with the
/// given id and stores it in header. /// given id and stores it in header.
/// ///
/// For this to work, the server must support the TOP command. /// For this to work, the server must support the TOP command.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void deleteMessage(int id); void deleteMessage(int id);
/// Marks the message with the given ID for deletion. The message /// Marks the message with the given ID for deletion. The message
/// will be deleted when the connection to the server is /// will be deleted when the connection to the server is
/// closed by calling close(). /// closed by calling close().
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
bool sendCommand(const std::string& command, std::string& response); bool sendCommand(const std::string& command, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
/// ///
/// Returns true if the response is positive, false otherwise. /// Returns true if the response is positive, false otherwise.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
bool sendCommand(const std::string& command, const std::string& arg, std::string& response); bool sendCommand(const std::string& command, const std::string& arg, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
/// ///
/// Returns true if the response is positive, false otherwise. /// Returns true if the response is positive, false otherwise.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
bool sendCommand(const std::string& command, const std::string& arg1, const std::string& arg2, std::string& response); bool sendCommand(const std::string& command, const std::string& arg1, const std::string& arg2, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
/// ///
/// Returns true if the response is positive, false otherwise. /// Returns true if the response is positive, false otherwise.
/// ///
/// Throws a POP3Exception in case of a POP3-specific error, or a /// Throws a POP3Exception in case of a POP3-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
protected: protected:
static bool isPositive(const std::string& response); static bool isPositive(const std::string& response);
private: private:
DialogSocket _socket; DialogSocket _socket;
bool _isOpen; bool _isOpen;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_POP3ClientSession_INCLUDED #endif // Net_POP3ClientSession_INCLUDED

View File

@ -1,90 +1,90 @@
// //
// PartHandler.h // PartHandler.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/PartHandler.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/PartHandler.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: PartHandler // Module: PartHandler
// //
// Definition of the PartHandler class. // Definition of the PartHandler class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_PartHandler_INCLUDED #ifndef Net_PartHandler_INCLUDED
#define Net_PartHandler_INCLUDED #define Net_PartHandler_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include <istream> #include <istream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MessageHeader; class MessageHeader;
class Net_API PartHandler class Net_API PartHandler
/// The base class for all part or attachment handlers. /// The base class for all part or attachment handlers.
/// ///
/// Part handlers are used for handling email parts and /// Part handlers are used for handling email parts and
/// attachments in MIME multipart messages, as well as file /// attachments in MIME multipart messages, as well as file
/// uploads via HTML forms. /// uploads via HTML forms.
/// ///
/// Subclasses must override handlePart(). /// Subclasses must override handlePart().
{ {
public: public:
virtual void handlePart(const MessageHeader& header, std::istream& stream) = 0; virtual void handlePart(const MessageHeader& header, std::istream& stream) = 0;
/// Called for every part encountered during the processing /// Called for every part encountered during the processing
/// of an email message or an uploaded HTML form. /// of an email message or an uploaded HTML form.
/// ///
/// Information about the part can be extracted from /// Information about the part can be extracted from
/// the given message header. What information can be obtained /// the given message header. What information can be obtained
/// from header depends on the kind of part. /// from header depends on the kind of part.
/// ///
/// The content of the part can be read from stream. /// The content of the part can be read from stream.
protected: protected:
PartHandler(); PartHandler();
/// Creates the PartHandler. /// Creates the PartHandler.
virtual ~PartHandler(); virtual ~PartHandler();
/// Destroys the PartHandler. /// Destroys the PartHandler.
private: private:
PartHandler(const PartHandler&); PartHandler(const PartHandler&);
PartHandler& operator = (const PartHandler&); PartHandler& operator = (const PartHandler&);
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_PartHandler_INCLUDED #endif // Net_PartHandler_INCLUDED

View File

@ -1,103 +1,103 @@
// //
// PartSource.h // PartSource.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/PartSource.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/PartSource.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: PartSource // Module: PartSource
// //
// Definition of the PartSource class. // Definition of the PartSource class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_PartSource_INCLUDED #ifndef Net_PartSource_INCLUDED
#define Net_PartSource_INCLUDED #define Net_PartSource_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include <istream> #include <istream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API PartSource class Net_API PartSource
/// This abstract class is used for adding parts or attachments /// This abstract class is used for adding parts or attachments
/// to mail messages, as well as for uploading files as part of a HTML form. /// to mail messages, as well as for uploading files as part of a HTML form.
{ {
public: public:
virtual std::istream& stream() = 0; virtual std::istream& stream() = 0;
/// Returns an input stream for reading the /// Returns an input stream for reading the
/// part data. /// part data.
/// ///
/// Subclasses must override this method. /// Subclasses must override this method.
virtual const std::string& filename(); virtual const std::string& filename();
/// Returns the filename for the part or attachment. /// Returns the filename for the part or attachment.
/// ///
/// May be overridded by subclasses. The default /// May be overridded by subclasses. The default
/// implementation returns an empty string. /// implementation returns an empty string.
const std::string& mediaType() const; const std::string& mediaType() const;
/// Returns the MIME media type for this part or attachment. /// Returns the MIME media type for this part or attachment.
virtual ~PartSource(); virtual ~PartSource();
/// Destroys the PartSource. /// Destroys the PartSource.
protected: protected:
PartSource(); PartSource();
/// Creates the PartSource, using /// Creates the PartSource, using
/// the application/octet-stream MIME type. /// the application/octet-stream MIME type.
PartSource(const std::string& mediaType); PartSource(const std::string& mediaType);
/// Creates the PartSource, using the /// Creates the PartSource, using the
/// given MIME type. /// given MIME type.
private: private:
PartSource(const PartSource&); PartSource(const PartSource&);
PartSource& operator = (const PartSource&); PartSource& operator = (const PartSource&);
std::string _mediaType; std::string _mediaType;
}; };
// //
// inlines // inlines
// //
inline const std::string& PartSource::mediaType() const inline const std::string& PartSource::mediaType() const
{ {
return _mediaType; return _mediaType;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_PartSource_INCLUDED #endif // Net_PartSource_INCLUDED

View File

@ -1,96 +1,96 @@
// //
// QuotedPrintableDecoder.h // QuotedPrintableDecoder.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/QuotedPrintableDecoder.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/QuotedPrintableDecoder.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: QuotedPrintableDecoder // Module: QuotedPrintableDecoder
// //
// Definition of the QuotedPrintableDecoder class. // Definition of the QuotedPrintableDecoder class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_QuotedPrintableDecoder_INCLUDED #ifndef Net_QuotedPrintableDecoder_INCLUDED
#define Net_QuotedPrintableDecoder_INCLUDED #define Net_QuotedPrintableDecoder_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
#include <istream> #include <istream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API QuotedPrintableDecoderBuf: public Poco::UnbufferedStreamBuf class Net_API QuotedPrintableDecoderBuf: public Poco::UnbufferedStreamBuf
/// This streambuf decodes all quoted-printable (see RFC 2045) /// This streambuf decodes all quoted-printable (see RFC 2045)
/// encoded data read from the istream connected to it. /// encoded data read from the istream connected to it.
{ {
public: public:
QuotedPrintableDecoderBuf(std::istream& istr); QuotedPrintableDecoderBuf(std::istream& istr);
~QuotedPrintableDecoderBuf(); ~QuotedPrintableDecoderBuf();
private: private:
int readFromDevice(); int readFromDevice();
std::istream& _istr; std::istream& _istr;
}; };
class Net_API QuotedPrintableDecoderIOS: public virtual std::ios class Net_API QuotedPrintableDecoderIOS: public virtual std::ios
/// The base class for QuotedPrintableDecoder. /// The base class for QuotedPrintableDecoder.
/// ///
/// This class is needed to ensure the correct initialization /// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes. /// order of the stream buffer and base classes.
{ {
public: public:
QuotedPrintableDecoderIOS(std::istream& istr); QuotedPrintableDecoderIOS(std::istream& istr);
~QuotedPrintableDecoderIOS(); ~QuotedPrintableDecoderIOS();
QuotedPrintableDecoderBuf* rdbuf(); QuotedPrintableDecoderBuf* rdbuf();
protected: protected:
QuotedPrintableDecoderBuf _buf; QuotedPrintableDecoderBuf _buf;
}; };
class Net_API QuotedPrintableDecoder: public QuotedPrintableDecoderIOS, public std::istream class Net_API QuotedPrintableDecoder: public QuotedPrintableDecoderIOS, public std::istream
/// This istream decodes all quoted-printable (see RFC 2045) /// This istream decodes all quoted-printable (see RFC 2045)
/// encoded data read from the istream connected to it. /// encoded data read from the istream connected to it.
{ {
public: public:
QuotedPrintableDecoder(std::istream& istr); QuotedPrintableDecoder(std::istream& istr);
~QuotedPrintableDecoder(); ~QuotedPrintableDecoder();
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_QuotedPrintableDecoder_INCLUDED #endif // Net_QuotedPrintableDecoder_INCLUDED

View File

@ -1,107 +1,107 @@
// //
// QuotedPrintableEncoder.h // QuotedPrintableEncoder.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/QuotedPrintableEncoder.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/QuotedPrintableEncoder.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: QuotedPrintableEncoder // Module: QuotedPrintableEncoder
// //
// Definition of the QuotedPrintableEncoder class. // Definition of the QuotedPrintableEncoder class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_QuotedPrintableEncoder_INCLUDED #ifndef Net_QuotedPrintableEncoder_INCLUDED
#define Net_QuotedPrintableEncoder_INCLUDED #define Net_QuotedPrintableEncoder_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API QuotedPrintableEncoderBuf: public Poco::UnbufferedStreamBuf class Net_API QuotedPrintableEncoderBuf: public Poco::UnbufferedStreamBuf
/// This streambuf encodes all data written /// This streambuf encodes all data written
/// to it in quoted-printable encoding (see RFC 2045) /// to it in quoted-printable encoding (see RFC 2045)
/// and forwards it to a connected ostream. /// and forwards it to a connected ostream.
{ {
public: public:
QuotedPrintableEncoderBuf(std::ostream& ostr); QuotedPrintableEncoderBuf(std::ostream& ostr);
~QuotedPrintableEncoderBuf(); ~QuotedPrintableEncoderBuf();
int close(); int close();
private: private:
int writeToDevice(char c); int writeToDevice(char c);
void writeEncoded(char c); void writeEncoded(char c);
void writeRaw(char c); void writeRaw(char c);
int _pending; int _pending;
int _lineLength; int _lineLength;
std::ostream& _ostr; std::ostream& _ostr;
}; };
class Net_API QuotedPrintableEncoderIOS: public virtual std::ios class Net_API QuotedPrintableEncoderIOS: public virtual std::ios
/// The base class for QuotedPrintableEncoder. /// The base class for QuotedPrintableEncoder.
/// ///
/// This class is needed to ensure the correct initialization /// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes. /// order of the stream buffer and base classes.
{ {
public: public:
QuotedPrintableEncoderIOS(std::ostream& ostr); QuotedPrintableEncoderIOS(std::ostream& ostr);
~QuotedPrintableEncoderIOS(); ~QuotedPrintableEncoderIOS();
int close(); int close();
QuotedPrintableEncoderBuf* rdbuf(); QuotedPrintableEncoderBuf* rdbuf();
protected: protected:
QuotedPrintableEncoderBuf _buf; QuotedPrintableEncoderBuf _buf;
}; };
class Net_API QuotedPrintableEncoder: public QuotedPrintableEncoderIOS, public std::ostream class Net_API QuotedPrintableEncoder: public QuotedPrintableEncoderIOS, public std::ostream
/// This ostream encodes all data /// This ostream encodes all data
/// written to it in quoted-printable encoding /// written to it in quoted-printable encoding
/// (see RFC 2045) and forwards it to a connected ostream. /// (see RFC 2045) and forwards it to a connected ostream.
/// Always call close() when done /// Always call close() when done
/// writing data, to ensure proper /// writing data, to ensure proper
/// completion of the encoding operation. /// completion of the encoding operation.
{ {
public: public:
QuotedPrintableEncoder(std::ostream& ostr); QuotedPrintableEncoder(std::ostream& ostr);
~QuotedPrintableEncoder(); ~QuotedPrintableEncoder();
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_QuotedPrintableEncoder_INCLUDED #endif // Net_QuotedPrintableEncoder_INCLUDED

View File

@ -1,169 +1,169 @@
// //
// RawSocket.h // RawSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/RawSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/RawSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: RawSocket // Module: RawSocket
// //
// Definition of the RawSocket class. // Definition of the RawSocket class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_RawSocket_INCLUDED #ifndef Net_RawSocket_INCLUDED
#define Net_RawSocket_INCLUDED #define Net_RawSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API RawSocket: public Socket class Net_API RawSocket: public Socket
/// This class provides an interface to a /// This class provides an interface to a
/// raw IP socket. /// raw IP socket.
{ {
public: public:
RawSocket(); RawSocket();
/// Creates an unconnected IPv4 raw socket. /// Creates an unconnected IPv4 raw socket.
RawSocket(IPAddress::Family family, int proto = IPPROTO_RAW); RawSocket(IPAddress::Family family, int proto = IPPROTO_RAW);
/// Creates an unconnected raw socket. /// Creates an unconnected raw socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
RawSocket(const SocketAddress& address, bool reuseAddress = false); RawSocket(const SocketAddress& address, bool reuseAddress = false);
/// Creates a raw socket and binds it /// Creates a raw socket and binds it
/// to the given address. /// to the given address.
/// ///
/// Depending on the address family, the socket /// Depending on the address family, the socket
/// will be either an IPv4 or an IPv6 socket. /// will be either an IPv4 or an IPv6 socket.
RawSocket(const Socket& socket); RawSocket(const Socket& socket);
/// Creates the RawSocket with the SocketImpl /// Creates the RawSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a RawSocketImpl, otherwise an InvalidArgumentException /// a RawSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
~RawSocket(); ~RawSocket();
/// Destroys the RawSocket. /// Destroys the RawSocket.
RawSocket& operator = (const Socket& socket); RawSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
void connect(const SocketAddress& address); void connect(const SocketAddress& address);
/// Restricts incoming and outgoing /// Restricts incoming and outgoing
/// packets to the specified address. /// packets to the specified address.
/// ///
/// Cannot be used together with bind(). /// Cannot be used together with bind().
void bind(const SocketAddress& address, bool reuseAddress = false); void bind(const SocketAddress& address, bool reuseAddress = false);
/// Bind a local address to the socket. /// Bind a local address to the socket.
/// ///
/// This is usually only done when establishing a server /// This is usually only done when establishing a server
/// socket. /// socket.
/// ///
/// If reuseAddress is true, sets the SO_REUSEADDR /// If reuseAddress is true, sets the SO_REUSEADDR
/// socket option. /// socket option.
/// ///
/// Cannot be used together with connect(). /// Cannot be used together with connect().
int sendBytes(const void* buffer, int length, int flags = 0); int sendBytes(const void* buffer, int length, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket. /// the socket.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
int receiveBytes(void* buffer, int length, int flags = 0); int receiveBytes(void* buffer, int length, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0); int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket to the given address. /// the socket to the given address.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0); int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// Stores the address of the sender in address. /// Stores the address of the sender in address.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
void setBroadcast(bool flag); void setBroadcast(bool flag);
/// Sets the value of the SO_BROADCAST socket option. /// Sets the value of the SO_BROADCAST socket option.
/// ///
/// Setting this flag allows sending datagrams to /// Setting this flag allows sending datagrams to
/// the broadcast address. /// the broadcast address.
bool getBroadcast() const; bool getBroadcast() const;
/// Returns the value of the SO_BROADCAST socket option. /// Returns the value of the SO_BROADCAST socket option.
protected: protected:
RawSocket(SocketImpl* pImpl); RawSocket(SocketImpl* pImpl);
/// Creates the Socket and attaches the given SocketImpl. /// Creates the Socket and attaches the given SocketImpl.
/// The socket takes owership of the SocketImpl. /// The socket takes owership of the SocketImpl.
/// ///
/// The SocketImpl must be a StreamSocketImpl, otherwise /// The SocketImpl must be a StreamSocketImpl, otherwise
/// an InvalidArgumentException will be thrown. /// an InvalidArgumentException will be thrown.
}; };
// //
// inlines // inlines
// //
inline void RawSocket::setBroadcast(bool flag) inline void RawSocket::setBroadcast(bool flag)
{ {
impl()->setBroadcast(flag); impl()->setBroadcast(flag);
} }
inline bool RawSocket::getBroadcast() const inline bool RawSocket::getBroadcast() const
{ {
return impl()->getBroadcast(); return impl()->getBroadcast();
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_RawSocket_INCLUDED #endif // Net_RawSocket_INCLUDED

View File

@ -1,78 +1,78 @@
// //
// RawSocketImpl.h // RawSocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/RawSocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/RawSocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: RawSocketImpl // Module: RawSocketImpl
// //
// Definition of the RawSocketImpl class. // Definition of the RawSocketImpl class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_RawSocketImpl_INCLUDED #ifndef Net_RawSocketImpl_INCLUDED
#define Net_RawSocketImpl_INCLUDED #define Net_RawSocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketImpl.h" #include "Poco/Net/SocketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API RawSocketImpl: public SocketImpl class Net_API RawSocketImpl: public SocketImpl
/// This class implements a raw socket. /// This class implements a raw socket.
{ {
public: public:
RawSocketImpl(); RawSocketImpl();
/// Creates an unconnected IPv4 raw socket with IPPROTO_RAW. /// Creates an unconnected IPv4 raw socket with IPPROTO_RAW.
RawSocketImpl(IPAddress::Family family, int proto = IPPROTO_RAW); RawSocketImpl(IPAddress::Family family, int proto = IPPROTO_RAW);
/// Creates an unconnected raw socket. /// Creates an unconnected raw socket.
/// ///
/// The socket will be created for the /// The socket will be created for the
/// given address family. /// given address family.
RawSocketImpl(poco_socket_t sockfd); RawSocketImpl(poco_socket_t sockfd);
/// Creates a RawSocketImpl using the given native socket. /// Creates a RawSocketImpl using the given native socket.
protected: protected:
void init(int af); void init(int af);
void init2(int af, int proto); void init2(int af, int proto);
~RawSocketImpl(); ~RawSocketImpl();
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_RawSocketImpl_INCLUDED #endif // Net_RawSocketImpl_INCLUDED

View File

@ -1,179 +1,179 @@
// //
// SMTPClientSession.h // SMTPClientSession.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SMTPClientSession.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SMTPClientSession.h#1 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
// Module: SMTPClientSession // Module: SMTPClientSession
// //
// Definition of the SMTPClientSession class. // Definition of the SMTPClientSession class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SMTPClientSession_INCLUDED #ifndef Net_SMTPClientSession_INCLUDED
#define Net_SMTPClientSession_INCLUDED #define Net_SMTPClientSession_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/DialogSocket.h" #include "Poco/Net/DialogSocket.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class MailMessage; class MailMessage;
class Net_API SMTPClientSession class Net_API SMTPClientSession
/// This class implements an Simple Mail /// This class implements an Simple Mail
/// Transfer Procotol (SMTP, RFC 2821) /// Transfer Procotol (SMTP, RFC 2821)
/// client for sending e-mail messages. /// client for sending e-mail messages.
{ {
public: public:
enum enum
{ {
SMTP_PORT = 25 SMTP_PORT = 25
}; };
SMTPClientSession(const StreamSocket& socket); SMTPClientSession(const StreamSocket& socket);
/// Creates the SMTPClientSession using /// Creates the SMTPClientSession using
/// the given socket, which must be connected /// the given socket, which must be connected
/// to a SMTP server. /// to a SMTP server.
SMTPClientSession(const std::string& host, Poco::UInt16 port = SMTP_PORT); SMTPClientSession(const std::string& host, Poco::UInt16 port = SMTP_PORT);
/// Creates the SMTPClientSession using a socket connected /// Creates the SMTPClientSession using a socket connected
/// to the given host and port. /// to the given host and port.
virtual ~SMTPClientSession(); virtual ~SMTPClientSession();
/// Destroys the SMTPClientSession. /// Destroys the SMTPClientSession.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the timeout for socket read operations. /// Sets the timeout for socket read operations.
Poco::Timespan getTimeout() const; Poco::Timespan getTimeout() const;
/// Returns the timeout for socket read operations. /// Returns the timeout for socket read operations.
void login(const std::string& hostname); void login(const std::string& hostname);
/// Greets the SMTP server by sending a EHLO command /// Greets the SMTP server by sending a EHLO command
/// with the given hostname as argument. /// with the given hostname as argument.
/// ///
/// If the server does not understand the EHLO command, /// If the server does not understand the EHLO command,
/// a HELO command is sent instead. /// a HELO command is sent instead.
/// ///
/// Throws a SMTPException in case of a SMTP-specific error, or a /// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void login(); void login();
/// Calls login(hostname) with the current host name. /// Calls login(hostname) with the current host name.
void close(); void close();
/// Sends a QUIT command and closes the connection to the server. /// Sends a QUIT command and closes the connection to the server.
/// ///
/// Throws a SMTPException in case of a SMTP-specific error, or a /// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
void sendMessage(const MailMessage& message); void sendMessage(const MailMessage& message);
/// Sends the given mail message by sending a MAIL FROM command, /// Sends the given mail message by sending a MAIL FROM command,
/// a RCPT TO command for every recipient, and a DATA command with /// a RCPT TO command for every recipient, and a DATA command with
/// the message headers and content. /// the message headers and content.
/// ///
/// Throws a SMTPException in case of a SMTP-specific error, or a /// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
int sendCommand(const std::string& command, std::string& response); int sendCommand(const std::string& command, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
/// ///
/// Throws a SMTPException in case of a SMTP-specific error, or a /// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
int sendCommand(const std::string& command, const std::string& arg, std::string& response); int sendCommand(const std::string& command, const std::string& arg, std::string& response);
/// Sends the given command verbatim to the server /// Sends the given command verbatim to the server
/// and waits for a response. /// and waits for a response.
/// ///
/// Throws a SMTPException in case of a SMTP-specific error, or a /// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure. /// NetException in case of a general network communication failure.
protected: protected:
enum StatusClass enum StatusClass
{ {
SMTP_POSITIVE_COMPLETION = 2, SMTP_POSITIVE_COMPLETION = 2,
SMTP_POSITIVE_INTERMEDIATE = 3, SMTP_POSITIVE_INTERMEDIATE = 3,
SMTP_TRANSIENT_NEGATIVE = 4, SMTP_TRANSIENT_NEGATIVE = 4,
SMTP_PERMANENT_NEGATIVE = 5 SMTP_PERMANENT_NEGATIVE = 5
}; };
enum enum
{ {
DEFAULT_TIMEOUT = 30000000 // 30 seconds default timeout for socket operations DEFAULT_TIMEOUT = 30000000 // 30 seconds default timeout for socket operations
}; };
static bool isPositiveCompletion(int status); static bool isPositiveCompletion(int status);
static bool isPositiveIntermediate(int status); static bool isPositiveIntermediate(int status);
static bool isTransientNegative(int status); static bool isTransientNegative(int status);
static bool isPermanentNegative(int status); static bool isPermanentNegative(int status);
private: private:
DialogSocket _socket; DialogSocket _socket;
bool _isOpen; bool _isOpen;
}; };
// //
// inlines // inlines
// //
inline bool SMTPClientSession::isPositiveCompletion(int status) inline bool SMTPClientSession::isPositiveCompletion(int status)
{ {
return status/100 == SMTP_POSITIVE_COMPLETION; return status/100 == SMTP_POSITIVE_COMPLETION;
} }
inline bool SMTPClientSession::isPositiveIntermediate(int status) inline bool SMTPClientSession::isPositiveIntermediate(int status)
{ {
return status/100 == SMTP_POSITIVE_INTERMEDIATE; return status/100 == SMTP_POSITIVE_INTERMEDIATE;
} }
inline bool SMTPClientSession::isTransientNegative(int status) inline bool SMTPClientSession::isTransientNegative(int status)
{ {
return status/100 == SMTP_TRANSIENT_NEGATIVE; return status/100 == SMTP_TRANSIENT_NEGATIVE;
} }
inline bool SMTPClientSession::isPermanentNegative(int status) inline bool SMTPClientSession::isPermanentNegative(int status)
{ {
return status/100 == SMTP_PERMANENT_NEGATIVE; return status/100 == SMTP_PERMANENT_NEGATIVE;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SMTPClientSession_INCLUDED #endif // Net_SMTPClientSession_INCLUDED

View File

@ -1,156 +1,156 @@
// //
// ServerSocket.h // ServerSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ServerSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ServerSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: ServerSocket // Module: ServerSocket
// //
// Definition of the ServerSocket class. // Definition of the ServerSocket class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ServerSocket_INCLUDED #ifndef Net_ServerSocket_INCLUDED
#define Net_ServerSocket_INCLUDED #define Net_ServerSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ServerSocket: public Socket class Net_API ServerSocket: public Socket
/// This class provides an interface to a /// This class provides an interface to a
/// TCP server socket. /// TCP server socket.
{ {
public: public:
ServerSocket(); ServerSocket();
/// Creates a server socket. /// Creates a server socket.
/// ///
/// The server socket must be bound to /// The server socket must be bound to
/// and address and put into listening state. /// and address and put into listening state.
ServerSocket(const Socket& socket); ServerSocket(const Socket& socket);
/// Creates the ServerSocket with the SocketImpl /// Creates the ServerSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a ServerSocketImpl, otherwise an InvalidArgumentException /// a ServerSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
ServerSocket(const SocketAddress& address, int backlog = 64); ServerSocket(const SocketAddress& address, int backlog = 64);
/// Creates a server socket, binds it /// Creates a server socket, binds it
/// to the given address and puts it in listening /// to the given address and puts it in listening
/// state. /// state.
/// ///
/// After successful construction, the server socket /// After successful construction, the server socket
/// is ready to accept connections. /// is ready to accept connections.
ServerSocket(Poco::UInt16 port, int backlog = 64); ServerSocket(Poco::UInt16 port, int backlog = 64);
/// Creates a server socket, binds it /// Creates a server socket, binds it
/// to the given port and puts it in listening /// to the given port and puts it in listening
/// state. /// state.
/// ///
/// After successful construction, the server socket /// After successful construction, the server socket
/// is ready to accept connections. /// is ready to accept connections.
virtual ~ServerSocket(); virtual ~ServerSocket();
/// Destroys the StreamSocket. /// Destroys the StreamSocket.
ServerSocket& operator = (const Socket& socket); ServerSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
virtual void bind(const SocketAddress& address, bool reuseAddress = false); virtual void bind(const SocketAddress& address, bool reuseAddress = false);
/// Bind a local address to the socket. /// Bind a local address to the socket.
/// ///
/// This is usually only done when establishing a server /// This is usually only done when establishing a server
/// socket. TCP clients should not bind a socket to a /// socket. TCP clients should not bind a socket to a
/// specific address. /// specific address.
/// ///
/// If reuseAddress is true, sets the SO_REUSEADDR /// If reuseAddress is true, sets the SO_REUSEADDR
/// socket option. /// socket option.
virtual void bind(Poco::UInt16 port, bool reuseAddress = false); virtual void bind(Poco::UInt16 port, bool reuseAddress = false);
/// Bind a local port to the socket. /// Bind a local port to the socket.
/// ///
/// This is usually only done when establishing a server /// This is usually only done when establishing a server
/// socket. /// socket.
/// ///
/// If reuseAddress is true, sets the SO_REUSEADDR /// If reuseAddress is true, sets the SO_REUSEADDR
/// socket option. /// socket option.
virtual void listen(int backlog = 64); virtual void listen(int backlog = 64);
/// Puts the socket into listening state. /// Puts the socket into listening state.
/// ///
/// The socket becomes a passive socket that /// The socket becomes a passive socket that
/// can accept incoming connection requests. /// can accept incoming connection requests.
/// ///
/// The backlog argument specifies the maximum /// The backlog argument specifies the maximum
/// number of connections that can be queued /// number of connections that can be queued
/// for this socket. /// for this socket.
virtual StreamSocket acceptConnection(SocketAddress& clientAddr); virtual StreamSocket acceptConnection(SocketAddress& clientAddr);
/// Get the next completed connection from the /// Get the next completed connection from the
/// socket's completed connection queue. /// socket's completed connection queue.
/// ///
/// If the queue is empty, waits until a connection /// If the queue is empty, waits until a connection
/// request completes. /// request completes.
/// ///
/// Returns a new TCP socket for the connection /// Returns a new TCP socket for the connection
/// with the client. /// with the client.
/// ///
/// The client socket's address is returned in clientAddr. /// The client socket's address is returned in clientAddr.
virtual StreamSocket acceptConnection(); virtual StreamSocket acceptConnection();
/// Get the next completed connection from the /// Get the next completed connection from the
/// socket's completed connection queue. /// socket's completed connection queue.
/// ///
/// If the queue is empty, waits until a connection /// If the queue is empty, waits until a connection
/// request completes. /// request completes.
/// ///
/// Returns a new TCP socket for the connection /// Returns a new TCP socket for the connection
/// with the client. /// with the client.
protected: protected:
ServerSocket(SocketImpl* pImpl, bool); ServerSocket(SocketImpl* pImpl, bool);
/// The bool argument is to resolve an ambiguity with /// The bool argument is to resolve an ambiguity with
/// another constructor (Microsoft Visual C++ 2005) /// another constructor (Microsoft Visual C++ 2005)
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ServerSocket_INCLUDED #endif // Net_ServerSocket_INCLUDED

View File

@ -1,67 +1,67 @@
// //
// ServerSocketImpl.h // ServerSocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/ServerSocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/ServerSocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: ServerSocketImpl // Module: ServerSocketImpl
// //
// Definition of the ServerSocketImpl class. // Definition of the ServerSocketImpl class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_ServerSocketImpl_INCLUDED #ifndef Net_ServerSocketImpl_INCLUDED
#define Net_ServerSocketImpl_INCLUDED #define Net_ServerSocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketImpl.h" #include "Poco/Net/SocketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API ServerSocketImpl: public SocketImpl class Net_API ServerSocketImpl: public SocketImpl
/// This class implements a TCP server socket. /// This class implements a TCP server socket.
{ {
public: public:
ServerSocketImpl(); ServerSocketImpl();
/// Creates the ServerSocketImpl. /// Creates the ServerSocketImpl.
protected: protected:
virtual ~ServerSocketImpl(); virtual ~ServerSocketImpl();
/// Destroys the ServerSocketImpl. /// Destroys the ServerSocketImpl.
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_ServerSocketImpl_INCLUDED #endif // Net_ServerSocketImpl_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -1,184 +1,184 @@
// //
// SocketAcceptor.h // SocketAcceptor.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketAcceptor.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketAcceptor.h#1 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
// Module: SocketAcceptor // Module: SocketAcceptor
// //
// Definition of the SocketAcceptor class. // Definition of the SocketAcceptor class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketAcceptor_INCLUDED #ifndef Net_SocketAcceptor_INCLUDED
#define Net_SocketAcceptor_INCLUDED #define Net_SocketAcceptor_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketNotification.h" #include "Poco/Net/SocketNotification.h"
#include "Poco/Net/ServerSocket.h" #include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Observer.h" #include "Poco/Observer.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
template <class ServiceHandler> template <class ServiceHandler>
class SocketAcceptor class SocketAcceptor
/// This class implements the Acceptor part of the /// This class implements the Acceptor part of the
/// Acceptor-Connector design pattern. /// Acceptor-Connector design pattern.
/// ///
/// The Acceptor-Connector pattern has been described in the book /// The Acceptor-Connector pattern has been described in the book
/// "Pattern Languages of Program Design 3", edited by Robert Martin, /// "Pattern Languages of Program Design 3", edited by Robert Martin,
/// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997). /// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997).
/// ///
/// The Acceptor-Connector design pattern decouples connection /// The Acceptor-Connector design pattern decouples connection
/// establishment and service initialization in a distributed system /// establishment and service initialization in a distributed system
/// from the processing performed once a service is initialized. /// from the processing performed once a service is initialized.
/// This decoupling is achieved with three components: Acceptors, /// This decoupling is achieved with three components: Acceptors,
/// Connectors and Service Handlers. /// Connectors and Service Handlers.
/// The SocketAcceptor passively waits for connection requests (usually /// The SocketAcceptor passively waits for connection requests (usually
/// from a remote Connector) and establishes a connection upon /// from a remote Connector) and establishes a connection upon
/// arrival of a connection requests. Also, a Service Handler is /// arrival of a connection requests. Also, a Service Handler is
/// initialized to process the data arriving via the connection in /// initialized to process the data arriving via the connection in
/// an application-specific way. /// an application-specific way.
/// ///
/// The SocketAcceptor sets up a ServerSocket and registers itself /// The SocketAcceptor sets up a ServerSocket and registers itself
/// for a ReadableNotification, denoting an incoming connection request. /// for a ReadableNotification, denoting an incoming connection request.
/// ///
/// When the ServerSocket becomes readable the SocketAcceptor accepts /// When the ServerSocket becomes readable the SocketAcceptor accepts
/// the connection request and creates a ServiceHandler to /// the connection request and creates a ServiceHandler to
/// service the connection. /// service the connection.
/// ///
/// The ServiceHandler class must provide a constructor that /// The ServiceHandler class must provide a constructor that
/// takes a StreamSocket and a SocketReactor as arguments, /// takes a StreamSocket and a SocketReactor as arguments,
/// e.g.: /// e.g.:
/// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor) /// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor)
/// ///
/// When the ServiceHandler is done, it must destroy itself. /// When the ServiceHandler is done, it must destroy itself.
/// ///
/// Subclasses can override the createServiceHandler() factory method /// Subclasses can override the createServiceHandler() factory method
/// if special steps are necessary to create a ServiceHandler object. /// if special steps are necessary to create a ServiceHandler object.
{ {
public: public:
SocketAcceptor(ServerSocket& socket): SocketAcceptor(ServerSocket& socket):
_socket(socket), _socket(socket),
_pReactor(0) _pReactor(0)
/// Creates an SocketAcceptor, using the given ServerSocket. /// Creates an SocketAcceptor, using the given ServerSocket.
{ {
} }
SocketAcceptor(ServerSocket& socket, SocketReactor& reactor): SocketAcceptor(ServerSocket& socket, SocketReactor& reactor):
_socket(socket), _socket(socket),
_pReactor(0) _pReactor(0)
/// Creates an SocketAcceptor, using the given ServerSocket. /// Creates an SocketAcceptor, using the given ServerSocket.
/// The SocketAcceptor registers itself with the given SocketReactor. /// The SocketAcceptor registers itself with the given SocketReactor.
{ {
registerAcceptor(reactor); registerAcceptor(reactor);
} }
virtual ~SocketAcceptor() virtual ~SocketAcceptor()
/// Destroys the SocketAcceptor. /// Destroys the SocketAcceptor.
{ {
unregisterAcceptor(); unregisterAcceptor();
} }
virtual void registerAcceptor(SocketReactor& reactor) virtual void registerAcceptor(SocketReactor& reactor)
/// Registers the SocketAcceptor with a SocketReactor. /// Registers the SocketAcceptor with a SocketReactor.
/// ///
/// A subclass can override this and, for example, also register /// A subclass can override this and, for example, also register
/// an event handler for a timeout event. /// an event handler for a timeout event.
/// ///
/// The overriding method must call the baseclass implementation first. /// The overriding method must call the baseclass implementation first.
{ {
_pReactor = &reactor; _pReactor = &reactor;
_pReactor->addEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept)); _pReactor->addEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept));
} }
virtual void unregisterAcceptor() virtual void unregisterAcceptor()
/// Unregisters the SocketAcceptor. /// Unregisters the SocketAcceptor.
/// ///
/// A subclass can override this and, for example, also unregister /// A subclass can override this and, for example, also unregister
/// its event handler for a timeout event. /// its event handler for a timeout event.
/// ///
/// The overriding method must call the baseclass implementation first. /// The overriding method must call the baseclass implementation first.
{ {
if (_pReactor) if (_pReactor)
{ {
_pReactor->removeEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept)); _pReactor->removeEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept));
} }
} }
void onAccept(ReadableNotification* pNotification) void onAccept(ReadableNotification* pNotification)
{ {
pNotification->release(); pNotification->release();
StreamSocket sock = _socket.acceptConnection(); StreamSocket sock = _socket.acceptConnection();
createServiceHandler(sock); createServiceHandler(sock);
} }
protected: protected:
virtual ServiceHandler* createServiceHandler(StreamSocket& socket) virtual ServiceHandler* createServiceHandler(StreamSocket& socket)
/// Create and initialize a new ServiceHandler instance. /// Create and initialize a new ServiceHandler instance.
/// ///
/// Subclasses can override this method. /// Subclasses can override this method.
{ {
return new ServiceHandler(socket, *_pReactor); return new ServiceHandler(socket, *_pReactor);
} }
SocketReactor* reactor() SocketReactor* reactor()
/// Returns a pointer to the SocketReactor where /// Returns a pointer to the SocketReactor where
/// this SocketAcceptor is registered. /// this SocketAcceptor is registered.
/// ///
/// The pointer may be null. /// The pointer may be null.
{ {
return _pReactor; return _pReactor;
} }
Socket& socket() Socket& socket()
/// Returns a reference to the SocketAcceptor's socket. /// Returns a reference to the SocketAcceptor's socket.
{ {
return _socket; return _socket;
} }
private: private:
SocketAcceptor(); SocketAcceptor();
SocketAcceptor(const SocketAcceptor&); SocketAcceptor(const SocketAcceptor&);
SocketAcceptor& operator = (const SocketAcceptor&); SocketAcceptor& operator = (const SocketAcceptor&);
ServerSocket _socket; ServerSocket _socket;
SocketReactor* _pReactor; SocketReactor* _pReactor;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketAcceptor_INCLUDED #endif // Net_SocketAcceptor_INCLUDED

View File

@ -1,162 +1,162 @@
// //
// SocketAddress.h // SocketAddress.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketAddress.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketAddress.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: SocketAddress // Module: SocketAddress
// //
// Definition of the SocketAddress class. // Definition of the SocketAddress class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketAddress_INCLUDED #ifndef Net_SocketAddress_INCLUDED
#define Net_SocketAddress_INCLUDED #define Net_SocketAddress_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h" #include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class IPAddress; class IPAddress;
class SocketAddressImpl; class SocketAddressImpl;
class Net_API SocketAddress class Net_API SocketAddress
/// This class represents an internet (IP) endpoint/socket /// This class represents an internet (IP) endpoint/socket
/// address. The address can belong either to the /// address. The address can belong either to the
/// IPv4 or the IPv6 address family and consists of a /// IPv4 or the IPv6 address family and consists of a
/// host address and a port number. /// host address and a port number.
{ {
public: public:
SocketAddress(); SocketAddress();
/// Creates a wildcard (all zero) IPv4 SocketAddress. /// Creates a wildcard (all zero) IPv4 SocketAddress.
SocketAddress(const IPAddress& host, Poco::UInt16 port); SocketAddress(const IPAddress& host, Poco::UInt16 port);
/// Creates a SocketAddress from an IP address and a port number. /// Creates a SocketAddress from an IP address and a port number.
SocketAddress(const std::string& host, Poco::UInt16 port); SocketAddress(const std::string& host, Poco::UInt16 port);
/// Creates a SocketAddress from an IP address and a port number. /// Creates a SocketAddress from an IP address and a port number.
/// ///
/// The IP address must either be a domain name, or it must /// The IP address must either be a domain name, or it must
/// be in dotted decimal (IPv4) or hex string (IPv6) format. /// be in dotted decimal (IPv4) or hex string (IPv6) format.
SocketAddress(const std::string& host, const std::string& port); SocketAddress(const std::string& host, const std::string& port);
/// Creates a SocketAddress from an IP address and a /// Creates a SocketAddress from an IP address and a
/// service name or port number. /// service name or port number.
/// ///
/// The IP address must either be a domain name, or it must /// The IP address must either be a domain name, or it must
/// be in dotted decimal (IPv4) or hex string (IPv6) format. /// be in dotted decimal (IPv4) or hex string (IPv6) format.
/// ///
/// The given port must either be a decimal port number, or /// The given port must either be a decimal port number, or
/// a service name. /// a service name.
explicit SocketAddress(const std::string& hostAndPort); explicit SocketAddress(const std::string& hostAndPort);
/// Creates a SocketAddress from an IP address or host name and a /// Creates a SocketAddress from an IP address or host name and a
/// port number/service name. Host name/address and port number must /// port number/service name. Host name/address and port number must
/// be separated by a colon. In case of an IPv6 address, /// be separated by a colon. In case of an IPv6 address,
/// the address part must be enclosed in brackets. /// the address part must be enclosed in brackets.
/// ///
/// Examples: /// Examples:
/// 192.168.1.10:80 /// 192.168.1.10:80
/// [::FFFF:192.168.1.120]:2040 /// [::FFFF:192.168.1.120]:2040
/// www.appinf.com:8080 /// www.appinf.com:8080
SocketAddress(const SocketAddress& addr); SocketAddress(const SocketAddress& addr);
/// Creates a SocketAddress by copying another one. /// Creates a SocketAddress by copying another one.
SocketAddress(const struct sockaddr* addr, poco_socklen_t length); SocketAddress(const struct sockaddr* addr, poco_socklen_t length);
/// Creates a SocketAddress from a native socket address. /// Creates a SocketAddress from a native socket address.
~SocketAddress(); ~SocketAddress();
/// Destroys the SocketAddress. /// Destroys the SocketAddress.
SocketAddress& operator = (const SocketAddress& addr); SocketAddress& operator = (const SocketAddress& addr);
/// Assigns another SocketAddress. /// Assigns another SocketAddress.
void swap(SocketAddress& addr); void swap(SocketAddress& addr);
/// Swaps the SocketAddress with another one. /// Swaps the SocketAddress with another one.
IPAddress host() const; IPAddress host() const;
/// Returns the host IP address. /// Returns the host IP address.
Poco::UInt16 port() const; Poco::UInt16 port() const;
/// Returns the port number. /// Returns the port number.
poco_socklen_t length() const; poco_socklen_t length() const;
/// Returns the length of the internal native socket address. /// Returns the length of the internal native socket address.
const struct sockaddr* addr() const; const struct sockaddr* addr() const;
/// Returns a pointer to the internal native socket address. /// Returns a pointer to the internal native socket address.
int af() const; int af() const;
/// Returns the address family (AF_INET or AF_INET6) of the address. /// Returns the address family (AF_INET or AF_INET6) of the address.
std::string toString() const; std::string toString() const;
/// Returns a string representation of the address. /// Returns a string representation of the address.
enum enum
{ {
MAX_ADDRESS_LENGTH = MAX_ADDRESS_LENGTH =
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
sizeof(struct sockaddr_in6) sizeof(struct sockaddr_in6)
#else #else
sizeof(struct sockaddr_in) sizeof(struct sockaddr_in)
#endif #endif
/// Maximum length in bytes of a socket address. /// Maximum length in bytes of a socket address.
}; };
protected: protected:
void init(const IPAddress& host, Poco::UInt16 port); void init(const IPAddress& host, Poco::UInt16 port);
void init(const std::string& host, Poco::UInt16 port); void init(const std::string& host, Poco::UInt16 port);
Poco::UInt16 resolveService(const std::string& service); Poco::UInt16 resolveService(const std::string& service);
private: private:
SocketAddressImpl* _pImpl; SocketAddressImpl* _pImpl;
}; };
// //
// inlines // inlines
// //
inline void swap(SocketAddress& a1, SocketAddress& a2) inline void swap(SocketAddress& a1, SocketAddress& a2)
{ {
a1.swap(a2); a1.swap(a2);
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketAddress_INCLUDED #endif // Net_SocketAddress_INCLUDED

View File

@ -1,227 +1,227 @@
// //
// SocketConnector.h // SocketConnector.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketConnector.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketConnector.h#1 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
// Module: SocketConnector // Module: SocketConnector
// //
// Definition of the SocketConnector class. // Definition of the SocketConnector class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketConnector_INCLUDED #ifndef Net_SocketConnector_INCLUDED
#define Net_SocketConnector_INCLUDED #define Net_SocketConnector_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketNotification.h" #include "Poco/Net/SocketNotification.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Observer.h" #include "Poco/Observer.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
template <class ServiceHandler> template <class ServiceHandler>
class SocketConnector class SocketConnector
/// This class implements the Connector part of the /// This class implements the Connector part of the
/// Acceptor-Connector design pattern. /// Acceptor-Connector design pattern.
/// ///
/// The Acceptor-Connector pattern has been described in the book /// The Acceptor-Connector pattern has been described in the book
/// "Pattern Languages of Program Design 3", edited by Robert Martin, /// "Pattern Languages of Program Design 3", edited by Robert Martin,
/// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997). /// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997).
/// ///
/// The Acceptor-Connector design pattern decouples connection /// The Acceptor-Connector design pattern decouples connection
/// establishment and service initialization in a distributed system /// establishment and service initialization in a distributed system
/// from the processing performed once a service is initialized. /// from the processing performed once a service is initialized.
/// This decoupling is achieved with three components: Acceptors, /// This decoupling is achieved with three components: Acceptors,
/// Connectors and Service Handlers. /// Connectors and Service Handlers.
/// The Connector actively establishes a connection with a remote /// The Connector actively establishes a connection with a remote
/// server socket (usually managed by an Acceptor) and initializes /// server socket (usually managed by an Acceptor) and initializes
/// a Service Handler to manage the connection. /// a Service Handler to manage the connection.
/// ///
/// The SocketConnector sets up a StreamSocket, initiates a non-blocking /// The SocketConnector sets up a StreamSocket, initiates a non-blocking
/// connect operation and registers itself for ReadableNotification, WritableNotification /// connect operation and registers itself for ReadableNotification, WritableNotification
/// and ErrorNotification. ReadableNotification or WritableNotification denote the successful /// and ErrorNotification. ReadableNotification or WritableNotification denote the successful
/// establishment of the connection. /// establishment of the connection.
/// ///
/// When the StreamSocket becomes readable or writeable, the SocketConnector /// When the StreamSocket becomes readable or writeable, the SocketConnector
/// creates a ServiceHandler to service the connection and unregisters /// creates a ServiceHandler to service the connection and unregisters
/// itself. /// itself.
/// ///
/// In case of an error (ErrorNotification), the SocketConnector unregisters itself /// In case of an error (ErrorNotification), the SocketConnector unregisters itself
/// and calls the onError() method, which can be overridden by subclasses /// and calls the onError() method, which can be overridden by subclasses
/// to perform custom error handling. /// to perform custom error handling.
/// ///
/// The ServiceHandler class must provide a constructor that /// The ServiceHandler class must provide a constructor that
/// takes a StreamSocket and a SocketReactor as arguments, /// takes a StreamSocket and a SocketReactor as arguments,
/// e.g.: /// e.g.:
/// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor) /// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor)
/// ///
/// When the ServiceHandler is done, it must destroy itself. /// When the ServiceHandler is done, it must destroy itself.
/// ///
/// Subclasses can override the createServiceHandler() factory method /// Subclasses can override the createServiceHandler() factory method
/// if special steps are necessary to create a ServiceHandler object. /// if special steps are necessary to create a ServiceHandler object.
{ {
public: public:
SocketConnector(SocketAddress& address): SocketConnector(SocketAddress& address):
_pReactor(0) _pReactor(0)
/// Creates a SocketConnector, using the given Socket. /// Creates a SocketConnector, using the given Socket.
{ {
_socket.connectNB(address); _socket.connectNB(address);
} }
SocketConnector(SocketAddress& address, SocketReactor& reactor): SocketConnector(SocketAddress& address, SocketReactor& reactor):
_pReactor(0) _pReactor(0)
/// Creates an acceptor, using the given ServerSocket. /// Creates an acceptor, using the given ServerSocket.
/// The SocketConnector registers itself with the given SocketReactor. /// The SocketConnector registers itself with the given SocketReactor.
{ {
_socket.connectNB(address); _socket.connectNB(address);
registerConnector(reactor); registerConnector(reactor);
} }
virtual ~SocketConnector() virtual ~SocketConnector()
/// Destroys the SocketConnector. /// Destroys the SocketConnector.
{ {
unregisterConnector(); unregisterConnector();
} }
virtual void registerConnector(SocketReactor& reactor) virtual void registerConnector(SocketReactor& reactor)
/// Registers the SocketConnector with a SocketReactor. /// Registers the SocketConnector with a SocketReactor.
/// ///
/// A subclass can override this and, for example, also register /// A subclass can override this and, for example, also register
/// an event handler for a timeout event. /// an event handler for a timeout event.
/// ///
/// The overriding method must call the baseclass implementation first. /// The overriding method must call the baseclass implementation first.
{ {
_pReactor = &reactor; _pReactor = &reactor;
_pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable)); _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable));
_pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable)); _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable));
_pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError)); _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError));
} }
virtual void unregisterConnector() virtual void unregisterConnector()
/// Unregisters the SocketConnector. /// Unregisters the SocketConnector.
/// ///
/// A subclass can override this and, for example, also unregister /// A subclass can override this and, for example, also unregister
/// its event handler for a timeout event. /// its event handler for a timeout event.
/// ///
/// The overriding method must call the baseclass implementation first. /// The overriding method must call the baseclass implementation first.
{ {
if (_pReactor) if (_pReactor)
{ {
_pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable)); _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable));
_pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable)); _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable));
_pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError)); _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError));
} }
} }
void onReadable(ReadableNotification* pNotification) void onReadable(ReadableNotification* pNotification)
{ {
pNotification->release(); pNotification->release();
int err = _socket.impl()->socketError(); int err = _socket.impl()->socketError();
if (err) if (err)
{ {
onError(err); onError(err);
unregisterConnector(); unregisterConnector();
} }
else else
{ {
onConnect(); onConnect();
} }
} }
void onWritable(WritableNotification* pNotification) void onWritable(WritableNotification* pNotification)
{ {
pNotification->release(); pNotification->release();
onConnect(); onConnect();
} }
void onConnect() void onConnect()
{ {
_socket.setBlocking(true); _socket.setBlocking(true);
createServiceHandler(); createServiceHandler();
unregisterConnector(); unregisterConnector();
} }
void onError(ErrorNotification* pNotification) void onError(ErrorNotification* pNotification)
{ {
pNotification->release(); pNotification->release();
onError(_socket.impl()->socketError()); onError(_socket.impl()->socketError());
unregisterConnector(); unregisterConnector();
} }
protected: protected:
virtual ServiceHandler* createServiceHandler() virtual ServiceHandler* createServiceHandler()
/// Create and initialize a new ServiceHandler instance. /// Create and initialize a new ServiceHandler instance.
/// ///
/// Subclasses can override this method. /// Subclasses can override this method.
{ {
return new ServiceHandler(_socket, *_pReactor); return new ServiceHandler(_socket, *_pReactor);
} }
virtual void onError(int errorCode) virtual void onError(int errorCode)
/// Called when the socket cannot be connected. /// Called when the socket cannot be connected.
/// ///
/// Subclasses can override this method. /// Subclasses can override this method.
{ {
} }
SocketReactor* reactor() SocketReactor* reactor()
/// Returns a pointer to the SocketReactor where /// Returns a pointer to the SocketReactor where
/// this SocketConnector is registered. /// this SocketConnector is registered.
/// ///
/// The pointer may be null. /// The pointer may be null.
{ {
return _pReactor; return _pReactor;
} }
Socket& socket() Socket& socket()
/// Returns a reference to the SocketConnector's socket. /// Returns a reference to the SocketConnector's socket.
{ {
return _socket; return _socket;
} }
private: private:
SocketConnector(); SocketConnector();
SocketConnector(const SocketConnector&); SocketConnector(const SocketConnector&);
SocketConnector& operator = (const SocketConnector&); SocketConnector& operator = (const SocketConnector&);
StreamSocket _socket; StreamSocket _socket;
SocketReactor* _pReactor; SocketReactor* _pReactor;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketConnector_INCLUDED #endif // Net_SocketConnector_INCLUDED

View File

@ -1,201 +1,201 @@
// //
// SocketDefs.h // SocketDefs.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketDefs.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketDefs.h#1 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
// Module: SocketDefs // Module: SocketDefs
// //
// Include platform-specific header files for sockets. // Include platform-specific header files for sockets.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketDefs_INCLUDED #ifndef Net_SocketDefs_INCLUDED
#define Net_SocketDefs_INCLUDED #define Net_SocketDefs_INCLUDED
#if defined(POCO_OS_FAMILY_WINDOWS) #if defined(POCO_OS_FAMILY_WINDOWS)
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#define POCO_INVALID_SOCKET INVALID_SOCKET #define POCO_INVALID_SOCKET INVALID_SOCKET
#define poco_socket_t SOCKET #define poco_socket_t SOCKET
#define poco_socklen_t int #define poco_socklen_t int
#define poco_closesocket(s) closesocket(s) #define poco_closesocket(s) closesocket(s)
#define POCO_EINTR WSAEINTR #define POCO_EINTR WSAEINTR
#define POCO_EACCES WSAEACCES #define POCO_EACCES WSAEACCES
#define POCO_EFAULT WSAEFAULT #define POCO_EFAULT WSAEFAULT
#define POCO_EINVAL WSAEINVAL #define POCO_EINVAL WSAEINVAL
#define POCO_EMFILE WSAEMFILE #define POCO_EMFILE WSAEMFILE
#define POCO_EAGAIN WSAEWOULDBLOCK #define POCO_EAGAIN WSAEWOULDBLOCK
#define POCO_EWOULDBLOCK WSAEWOULDBLOCK #define POCO_EWOULDBLOCK WSAEWOULDBLOCK
#define POCO_EINPROGRESS WSAEINPROGRESS #define POCO_EINPROGRESS WSAEINPROGRESS
#define POCO_EALREADY WSAEALREADY #define POCO_EALREADY WSAEALREADY
#define POCO_ENOTSOCK WSAENOTSOCK #define POCO_ENOTSOCK WSAENOTSOCK
#define POCO_EDESTADDRREQ WSAEDESTADDRREQ #define POCO_EDESTADDRREQ WSAEDESTADDRREQ
#define POCO_EMSGSIZE WSAEMSGSIZE #define POCO_EMSGSIZE WSAEMSGSIZE
#define POCO_EPROTOTYPE WSAEPROTOTYPE #define POCO_EPROTOTYPE WSAEPROTOTYPE
#define POCO_ENOPROTOOPT WSAENOPROTOOPT #define POCO_ENOPROTOOPT WSAENOPROTOOPT
#define POCO_EPROTONOSUPPORT WSAEPROTONOSUPPORT #define POCO_EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define POCO_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT #define POCO_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#define POCO_ENOTSUP WSAEOPNOTSUPP #define POCO_ENOTSUP WSAEOPNOTSUPP
#define POCO_EPFNOSUPPORT WSAEPFNOSUPPORT #define POCO_EPFNOSUPPORT WSAEPFNOSUPPORT
#define POCO_EAFNOSUPPORT WSAEAFNOSUPPORT #define POCO_EAFNOSUPPORT WSAEAFNOSUPPORT
#define POCO_EADDRINUSE WSAEADDRINUSE #define POCO_EADDRINUSE WSAEADDRINUSE
#define POCO_EADDRNOTAVAIL WSAEADDRNOTAVAIL #define POCO_EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define POCO_ENETDOWN WSAENETDOWN #define POCO_ENETDOWN WSAENETDOWN
#define POCO_ENETUNREACH WSAENETUNREACH #define POCO_ENETUNREACH WSAENETUNREACH
#define POCO_ENETRESET WSAENETRESET #define POCO_ENETRESET WSAENETRESET
#define POCO_ECONNABORTED WSAECONNABORTED #define POCO_ECONNABORTED WSAECONNABORTED
#define POCO_ECONNRESET WSAECONNRESET #define POCO_ECONNRESET WSAECONNRESET
#define POCO_ENOBUFS WSAENOBUFS #define POCO_ENOBUFS WSAENOBUFS
#define POCO_EISCONN WSAEISCONN #define POCO_EISCONN WSAEISCONN
#define POCO_ENOTCONN WSAENOTCONN #define POCO_ENOTCONN WSAENOTCONN
#define POCO_ESHUTDOWN WSAESHUTDOWN #define POCO_ESHUTDOWN WSAESHUTDOWN
#define POCO_ETIMEDOUT WSAETIMEDOUT #define POCO_ETIMEDOUT WSAETIMEDOUT
#define POCO_ECONNREFUSED WSAECONNREFUSED #define POCO_ECONNREFUSED WSAECONNREFUSED
#define POCO_EHOSTDOWN WSAEHOSTDOWN #define POCO_EHOSTDOWN WSAEHOSTDOWN
#define POCO_EHOSTUNREACH WSAEHOSTUNREACH #define POCO_EHOSTUNREACH WSAEHOSTUNREACH
#define POCO_ESYSNOTREADY WSASYSNOTREADY #define POCO_ESYSNOTREADY WSASYSNOTREADY
#define POCO_ENOTINIT WSANOTINITIALISED #define POCO_ENOTINIT WSANOTINITIALISED
#define POCO_HOST_NOT_FOUND WSAHOST_NOT_FOUND #define POCO_HOST_NOT_FOUND WSAHOST_NOT_FOUND
#define POCO_TRY_AGAIN WSATRY_AGAIN #define POCO_TRY_AGAIN WSATRY_AGAIN
#define POCO_NO_RECOVERY WSANO_RECOVERY #define POCO_NO_RECOVERY WSANO_RECOVERY
#define POCO_NO_DATA WSANO_DATA #define POCO_NO_DATA WSANO_DATA
#elif defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_VMS) #elif defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_VMS)
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#if POCO_OS != POCO_OS_HPUX #if POCO_OS != POCO_OS_HPUX
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#if defined(POCO_OS_FAMILY_VMS) #if defined(POCO_OS_FAMILY_VMS)
#include <inet.h> #include <inet.h>
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <netdb.h> #include <netdb.h>
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
#include <net/if.h> #include <net/if.h>
#endif #endif
#if defined(sun) || defined(__APPLE__) #if defined(sun) || defined(__APPLE__)
#include <sys/sockio.h> #include <sys/sockio.h>
#include <sys/filio.h> #include <sys/filio.h>
#endif #endif
#define POCO_INVALID_SOCKET -1 #define POCO_INVALID_SOCKET -1
#define poco_socket_t int #define poco_socket_t int
#define poco_socklen_t socklen_t #define poco_socklen_t socklen_t
#define poco_closesocket(s) ::close(s) #define poco_closesocket(s) ::close(s)
#define POCO_EINTR EINTR #define POCO_EINTR EINTR
#define POCO_EACCES EACCES #define POCO_EACCES EACCES
#define POCO_EFAULT EFAULT #define POCO_EFAULT EFAULT
#define POCO_EINVAL EINVAL #define POCO_EINVAL EINVAL
#define POCO_EMFILE EMFILE #define POCO_EMFILE EMFILE
#define POCO_EAGAIN EAGAIN #define POCO_EAGAIN EAGAIN
#define POCO_EWOULDBLOCK EWOULDBLOCK #define POCO_EWOULDBLOCK EWOULDBLOCK
#define POCO_EINPROGRESS EINPROGRESS #define POCO_EINPROGRESS EINPROGRESS
#define POCO_EALREADY EALREADY #define POCO_EALREADY EALREADY
#define POCO_ENOTSOCK ENOTSOCK #define POCO_ENOTSOCK ENOTSOCK
#define POCO_EDESTADDRREQ EDESTADDRREQ #define POCO_EDESTADDRREQ EDESTADDRREQ
#define POCO_EMSGSIZE EMSGSIZE #define POCO_EMSGSIZE EMSGSIZE
#define POCO_EPROTOTYPE EPROTOTYPE #define POCO_EPROTOTYPE EPROTOTYPE
#define POCO_ENOPROTOOPT ENOPROTOOPT #define POCO_ENOPROTOOPT ENOPROTOOPT
#define POCO_EPROTONOSUPPORT EPROTONOSUPPORT #define POCO_EPROTONOSUPPORT EPROTONOSUPPORT
#if defined(ESOCKTNOSUPPORT) #if defined(ESOCKTNOSUPPORT)
#define POCO_ESOCKTNOSUPPORT ESOCKTNOSUPPORT #define POCO_ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#else #else
#define POCO_ESOCKTNOSUPPORT -1 #define POCO_ESOCKTNOSUPPORT -1
#endif #endif
#define POCO_ENOTSUP ENOTSUP #define POCO_ENOTSUP ENOTSUP
#define POCO_EPFNOSUPPORT EPFNOSUPPORT #define POCO_EPFNOSUPPORT EPFNOSUPPORT
#define POCO_EAFNOSUPPORT EAFNOSUPPORT #define POCO_EAFNOSUPPORT EAFNOSUPPORT
#define POCO_EADDRINUSE EADDRINUSE #define POCO_EADDRINUSE EADDRINUSE
#define POCO_EADDRNOTAVAIL EADDRNOTAVAIL #define POCO_EADDRNOTAVAIL EADDRNOTAVAIL
#define POCO_ENETDOWN ENETDOWN #define POCO_ENETDOWN ENETDOWN
#define POCO_ENETUNREACH ENETUNREACH #define POCO_ENETUNREACH ENETUNREACH
#define POCO_ENETRESET ENETRESET #define POCO_ENETRESET ENETRESET
#define POCO_ECONNABORTED ECONNABORTED #define POCO_ECONNABORTED ECONNABORTED
#define POCO_ECONNRESET ECONNRESET #define POCO_ECONNRESET ECONNRESET
#define POCO_ENOBUFS ENOBUFS #define POCO_ENOBUFS ENOBUFS
#define POCO_EISCONN EISCONN #define POCO_EISCONN EISCONN
#define POCO_ENOTCONN ENOTCONN #define POCO_ENOTCONN ENOTCONN
#if defined(ESHUTDOWN) #if defined(ESHUTDOWN)
#define POCO_ESHUTDOWN ESHUTDOWN #define POCO_ESHUTDOWN ESHUTDOWN
#else #else
#define POCO_ESHUTDOWN -2 #define POCO_ESHUTDOWN -2
#endif #endif
#define POCO_ETIMEDOUT ETIMEDOUT #define POCO_ETIMEDOUT ETIMEDOUT
#define POCO_ECONNREFUSED ECONNREFUSED #define POCO_ECONNREFUSED ECONNREFUSED
#if defined(EHOSTDOWN) #if defined(EHOSTDOWN)
#define POCO_EHOSTDOWN EHOSTDOWN #define POCO_EHOSTDOWN EHOSTDOWN
#else #else
#define POCO_EHOSTDOWN -3 #define POCO_EHOSTDOWN -3
#endif #endif
#define POCO_EHOSTUNREACH EHOSTUNREACH #define POCO_EHOSTUNREACH EHOSTUNREACH
#define POCO_ESYSNOTREADY -4 #define POCO_ESYSNOTREADY -4
#define POCO_ENOTINIT -5 #define POCO_ENOTINIT -5
#define POCO_HOST_NOT_FOUND HOST_NOT_FOUND #define POCO_HOST_NOT_FOUND HOST_NOT_FOUND
#define POCO_TRY_AGAIN TRY_AGAIN #define POCO_TRY_AGAIN TRY_AGAIN
#define POCO_NO_RECOVERY NO_RECOVERY #define POCO_NO_RECOVERY NO_RECOVERY
#define POCO_NO_DATA NO_DATA #define POCO_NO_DATA NO_DATA
#endif #endif
#if defined(POCO_OS_FAMILY_BSD) || (POCO_OS == POCO_OS_TRU64) || (POCO_OS == POCO_OS_AIX) || (POCO_OS == POCO_OS_IRIX) || (POCO_OS == POCO_OS_QNX) || (POCO_OS == POCO_OS_VXWORKS) #if defined(POCO_OS_FAMILY_BSD) || (POCO_OS == POCO_OS_TRU64) || (POCO_OS == POCO_OS_AIX) || (POCO_OS == POCO_OS_IRIX) || (POCO_OS == POCO_OS_QNX) || (POCO_OS == POCO_OS_VXWORKS)
#define POCO_HAVE_SALEN 1 #define POCO_HAVE_SALEN 1
#endif #endif
#if (POCO_OS == POCO_OS_HPUX) #if (POCO_OS == POCO_OS_HPUX)
#define POCO_BROKEN_TIMEOUTS 1 #define POCO_BROKEN_TIMEOUTS 1
#endif #endif
#if defined(POCO_HAVE_SALEN) #if defined(POCO_HAVE_SALEN)
#define poco_set_sa_len(pSA, len) (pSA)->sa_len = (len) #define poco_set_sa_len(pSA, len) (pSA)->sa_len = (len)
#define poco_set_sin_len(pSA) (pSA)->sin_len = sizeof(struct sockaddr_in) #define poco_set_sin_len(pSA) (pSA)->sin_len = sizeof(struct sockaddr_in)
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)
#define poco_set_sin6_len(pSA) (pSA)->sin6_len = sizeof(struct sockaddr_in6) #define poco_set_sin6_len(pSA) (pSA)->sin6_len = sizeof(struct sockaddr_in6)
#endif #endif
#else #else
#define poco_set_sa_len(pSA, len) (void) 0 #define poco_set_sa_len(pSA, len) (void) 0
#define poco_set_sin_len(pSA) (void) 0 #define poco_set_sin_len(pSA) (void) 0
#define poco_set_sin6_len(pSA) (void) 0 #define poco_set_sin6_len(pSA) (void) 0
#endif #endif
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE 0xFFFFFFFF #define INADDR_NONE 0xFFFFFFFF
#endif #endif
#endif // Net_SocketDefs_INCLUDED #endif // Net_SocketDefs_INCLUDED

View File

@ -1,451 +1,451 @@
// //
// SocketImpl.h // SocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: SocketImpl // Module: SocketImpl
// //
// Definition of the SocketImpl class. // Definition of the SocketImpl class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketImpl_INCLUDED #ifndef Net_SocketImpl_INCLUDED
#define Net_SocketImpl_INCLUDED #define Net_SocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h" #include "Poco/Net/SocketDefs.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include "Poco/RefCountedObject.h" #include "Poco/RefCountedObject.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API SocketImpl: public Poco::RefCountedObject class Net_API SocketImpl: public Poco::RefCountedObject
/// This class encapsulates the Berkeley sockets API. /// This class encapsulates the Berkeley sockets API.
/// ///
/// Subclasses implement specific socket types like /// Subclasses implement specific socket types like
/// stream or datagram sockets. /// stream or datagram sockets.
/// ///
/// You should not create any instances of this class. /// You should not create any instances of this class.
{ {
public: public:
enum SelectMode enum SelectMode
{ {
SELECT_READ = 1, SELECT_READ = 1,
SELECT_WRITE = 2, SELECT_WRITE = 2,
SELECT_ERROR = 4 SELECT_ERROR = 4
}; };
virtual SocketImpl* acceptConnection(SocketAddress& clientAddr); virtual SocketImpl* acceptConnection(SocketAddress& clientAddr);
/// Get the next completed connection from the /// Get the next completed connection from the
/// socket's completed connection queue. /// socket's completed connection queue.
/// ///
/// If the queue is empty, waits until a connection /// If the queue is empty, waits until a connection
/// request completes. /// request completes.
/// ///
/// Returns a new TCP socket for the connection /// Returns a new TCP socket for the connection
/// with the client. /// with the client.
/// ///
/// The client socket's address is returned in clientAddr. /// The client socket's address is returned in clientAddr.
virtual void connect(const SocketAddress& address); virtual void connect(const SocketAddress& address);
/// Initializes the socket and establishes a connection to /// Initializes the socket and establishes a connection to
/// the TCP server at the given address. /// the TCP server at the given address.
/// ///
/// Can also be used for UDP sockets. In this case, no /// Can also be used for UDP sockets. In this case, no
/// connection is established. Instead, incoming and outgoing /// connection is established. Instead, incoming and outgoing
/// packets are restricted to the specified address. /// packets are restricted to the specified address.
virtual void connect(const SocketAddress& address, const Poco::Timespan& timeout); virtual void connect(const SocketAddress& address, const Poco::Timespan& timeout);
/// Initializes the socket, sets the socket timeout and /// Initializes the socket, sets the socket timeout and
/// establishes a connection to the TCP server at the given address. /// establishes a connection to the TCP server at the given address.
virtual void connectNB(const SocketAddress& address); virtual void connectNB(const SocketAddress& address);
/// Initializes the socket and establishes a connection to /// Initializes the socket and establishes a connection to
/// the TCP server at the given address. Prior to opening the /// the TCP server at the given address. Prior to opening the
/// connection the socket is set to nonblocking mode. /// connection the socket is set to nonblocking mode.
virtual void bind(const SocketAddress& address, bool reuseAddress = false); virtual void bind(const SocketAddress& address, bool reuseAddress = false);
/// Bind a local address to the socket. /// Bind a local address to the socket.
/// ///
/// This is usually only done when establishing a server /// This is usually only done when establishing a server
/// socket. TCP clients should not bind a socket to a /// socket. TCP clients should not bind a socket to a
/// specific address. /// specific address.
/// ///
/// If reuseAddress is true, sets the SO_REUSEADDR /// If reuseAddress is true, sets the SO_REUSEADDR
/// socket option. /// socket option.
virtual void listen(int backlog = 64); virtual void listen(int backlog = 64);
/// Puts the socket into listening state. /// Puts the socket into listening state.
/// ///
/// The socket becomes a passive socket that /// The socket becomes a passive socket that
/// can accept incoming connection requests. /// can accept incoming connection requests.
/// ///
/// The backlog argument specifies the maximum /// The backlog argument specifies the maximum
/// number of connections that can be queued /// number of connections that can be queued
/// for this socket. /// for this socket.
virtual void close(); virtual void close();
/// Close the socket. /// Close the socket.
virtual void shutdownReceive(); virtual void shutdownReceive();
/// Shuts down the receiving part of the socket connection. /// Shuts down the receiving part of the socket connection.
virtual void shutdownSend(); virtual void shutdownSend();
/// Shuts down the sending part of the socket connection. /// Shuts down the sending part of the socket connection.
virtual void shutdown(); virtual void shutdown();
/// Shuts down both the receiving and the sending part /// Shuts down both the receiving and the sending part
/// of the socket connection. /// of the socket connection.
virtual int sendBytes(const void* buffer, int length, int flags = 0); virtual int sendBytes(const void* buffer, int length, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket. /// the socket.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
virtual int receiveBytes(void* buffer, int length, int flags = 0); virtual int receiveBytes(void* buffer, int length, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
virtual int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0); virtual int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket to the given address. /// the socket to the given address.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
virtual int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0); virtual int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// Stores the address of the sender in address. /// Stores the address of the sender in address.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
virtual void sendUrgent(unsigned char data); virtual void sendUrgent(unsigned char data);
/// Sends one byte of urgent data through /// Sends one byte of urgent data through
/// the socket. /// the socket.
/// ///
/// The data is sent with the MSG_OOB flag. /// The data is sent with the MSG_OOB flag.
/// ///
/// The preferred way for a socket to receive urgent data /// The preferred way for a socket to receive urgent data
/// is by enabling the SO_OOBINLINE option. /// is by enabling the SO_OOBINLINE option.
virtual int available(); virtual int available();
/// Returns the number of bytes available that can be read /// Returns the number of bytes available that can be read
/// without causing the socket to block. /// without causing the socket to block.
virtual bool poll(const Poco::Timespan& timeout, int mode); virtual bool poll(const Poco::Timespan& timeout, int mode);
/// Determines the status of the socket, using a /// Determines the status of the socket, using a
/// call to select(). /// call to select().
/// ///
/// The mode argument is constructed by combining the values /// The mode argument is constructed by combining the values
/// of the SelectMode enumeration. /// of the SelectMode enumeration.
/// ///
/// Returns true if the next operation corresponding to /// Returns true if the next operation corresponding to
/// mode will not block, false otherwise. /// mode will not block, false otherwise.
virtual void setSendBufferSize(int size); virtual void setSendBufferSize(int size);
/// Sets the size of the send buffer. /// Sets the size of the send buffer.
virtual int getSendBufferSize(); virtual int getSendBufferSize();
/// Returns the size of the send buffer. /// Returns the size of the send buffer.
/// ///
/// The returned value may be different than the /// The returned value may be different than the
/// value previously set with setSendBufferSize(), /// value previously set with setSendBufferSize(),
/// as the system is free to adjust the value. /// as the system is free to adjust the value.
virtual void setReceiveBufferSize(int size); virtual void setReceiveBufferSize(int size);
/// Sets the size of the receive buffer. /// Sets the size of the receive buffer.
virtual int getReceiveBufferSize(); virtual int getReceiveBufferSize();
/// Returns the size of the receive buffer. /// Returns the size of the receive buffer.
/// ///
/// The returned value may be different than the /// The returned value may be different than the
/// value previously set with setReceiveBufferSize(), /// value previously set with setReceiveBufferSize(),
/// as the system is free to adjust the value. /// as the system is free to adjust the value.
virtual void setSendTimeout(const Poco::Timespan& timeout); virtual void setSendTimeout(const Poco::Timespan& timeout);
/// Sets the send timeout for the socket. /// Sets the send timeout for the socket.
virtual Poco::Timespan getSendTimeout(); virtual Poco::Timespan getSendTimeout();
/// Returns the send timeout for the socket. /// Returns the send timeout for the socket.
/// ///
/// The returned timeout may be different than the /// The returned timeout may be different than the
/// timeout previously set with setSendTimeout(), /// timeout previously set with setSendTimeout(),
/// as the system is free to adjust the value. /// as the system is free to adjust the value.
virtual void setReceiveTimeout(const Poco::Timespan& timeout); virtual void setReceiveTimeout(const Poco::Timespan& timeout);
/// Sets the send timeout for the socket. /// Sets the send timeout for the socket.
/// ///
/// On systems that do not support SO_RCVTIMEO, a /// On systems that do not support SO_RCVTIMEO, a
/// workaround using poll() is provided. /// workaround using poll() is provided.
virtual Poco::Timespan getReceiveTimeout(); virtual Poco::Timespan getReceiveTimeout();
/// Returns the receive timeout for the socket. /// Returns the receive timeout for the socket.
/// ///
/// The returned timeout may be different than the /// The returned timeout may be different than the
/// timeout previously set with setReceiveTimeout(), /// timeout previously set with setReceiveTimeout(),
/// as the system is free to adjust the value. /// as the system is free to adjust the value.
virtual SocketAddress address(); virtual SocketAddress address();
/// Returns the IP address and port number of the socket. /// Returns the IP address and port number of the socket.
virtual SocketAddress peerAddress(); virtual SocketAddress peerAddress();
/// Returns the IP address and port number of the peer socket. /// Returns the IP address and port number of the peer socket.
void setOption(int level, int option, int value); void setOption(int level, int option, int value);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given integer value. /// to the given integer value.
void setOption(int level, int option, unsigned value); void setOption(int level, int option, unsigned value);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given integer value. /// to the given integer value.
void setOption(int level, int option, unsigned char value); void setOption(int level, int option, unsigned char value);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given integer value. /// to the given integer value.
void setOption(int level, int option, const Poco::Timespan& value); void setOption(int level, int option, const Poco::Timespan& value);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given time value. /// to the given time value.
void setOption(int level, int option, const IPAddress& value); void setOption(int level, int option, const IPAddress& value);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given time value. /// to the given time value.
virtual void setRawOption(int level, int option, const void* value, poco_socklen_t length); virtual void setRawOption(int level, int option, const void* value, poco_socklen_t length);
/// Sets the socket option specified by level and option /// Sets the socket option specified by level and option
/// to the given time value. /// to the given time value.
void getOption(int level, int option, int& value); void getOption(int level, int option, int& value);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
void getOption(int level, int option, unsigned& value); void getOption(int level, int option, unsigned& value);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
void getOption(int level, int option, unsigned char& value); void getOption(int level, int option, unsigned char& value);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
void getOption(int level, int option, Poco::Timespan& value); void getOption(int level, int option, Poco::Timespan& value);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
void getOption(int level, int option, IPAddress& value); void getOption(int level, int option, IPAddress& value);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
virtual void getRawOption(int level, int option, void* value, poco_socklen_t& length); virtual void getRawOption(int level, int option, void* value, poco_socklen_t& length);
/// Returns the value of the socket option /// Returns the value of the socket option
/// specified by level and option. /// specified by level and option.
void setLinger(bool on, int seconds); void setLinger(bool on, int seconds);
/// Sets the value of the SO_LINGER socket option. /// Sets the value of the SO_LINGER socket option.
void getLinger(bool& on, int& seconds); void getLinger(bool& on, int& seconds);
/// Returns the value of the SO_LINGER socket option. /// Returns the value of the SO_LINGER socket option.
void setNoDelay(bool flag); void setNoDelay(bool flag);
/// Sets the value of the TCP_NODELAY socket option. /// Sets the value of the TCP_NODELAY socket option.
bool getNoDelay(); bool getNoDelay();
/// Returns the value of the TCP_NODELAY socket option. /// Returns the value of the TCP_NODELAY socket option.
void setKeepAlive(bool flag); void setKeepAlive(bool flag);
/// Sets the value of the SO_KEEPALIVE socket option. /// Sets the value of the SO_KEEPALIVE socket option.
bool getKeepAlive(); bool getKeepAlive();
/// Returns the value of the SO_KEEPALIVE socket option. /// Returns the value of the SO_KEEPALIVE socket option.
void setReuseAddress(bool flag); void setReuseAddress(bool flag);
/// Sets the value of the SO_REUSEADDR socket option. /// Sets the value of the SO_REUSEADDR socket option.
bool getReuseAddress(); bool getReuseAddress();
/// Returns the value of the SO_REUSEADDR socket option. /// Returns the value of the SO_REUSEADDR socket option.
void setReusePort(bool flag); void setReusePort(bool flag);
/// Sets the value of the SO_REUSEPORT socket option. /// Sets the value of the SO_REUSEPORT socket option.
/// Does nothing if the socket implementation does not /// Does nothing if the socket implementation does not
/// support SO_REUSEPORT. /// support SO_REUSEPORT.
bool getReusePort(); bool getReusePort();
/// Returns the value of the SO_REUSEPORT socket option. /// Returns the value of the SO_REUSEPORT socket option.
/// ///
/// Returns false if the socket implementation does not /// Returns false if the socket implementation does not
/// support SO_REUSEPORT. /// support SO_REUSEPORT.
void setOOBInline(bool flag); void setOOBInline(bool flag);
/// Sets the value of the SO_OOBINLINE socket option. /// Sets the value of the SO_OOBINLINE socket option.
bool getOOBInline(); bool getOOBInline();
/// Returns the value of the SO_OOBINLINE socket option. /// Returns the value of the SO_OOBINLINE socket option.
void setBroadcast(bool flag); void setBroadcast(bool flag);
/// Sets the value of the SO_BROADCAST socket option. /// Sets the value of the SO_BROADCAST socket option.
bool getBroadcast(); bool getBroadcast();
/// Returns the value of the SO_BROADCAST socket option. /// Returns the value of the SO_BROADCAST socket option.
void setBlocking(bool flag); void setBlocking(bool flag);
/// Sets the socket in blocking mode if flag is true, /// Sets the socket in blocking mode if flag is true,
/// disables blocking mode if flag is false. /// disables blocking mode if flag is false.
int socketError(); int socketError();
/// Returns the value of the SO_ERROR socket option. /// Returns the value of the SO_ERROR socket option.
poco_socket_t sockfd(); poco_socket_t sockfd();
/// Returns the socket descriptor for the /// Returns the socket descriptor for the
/// underlying native socket. /// underlying native socket.
void ioctl(int request, int& arg); void ioctl(int request, int& arg);
/// A wrapper for the ioctl system call. /// A wrapper for the ioctl system call.
void ioctl(int request, void* arg); void ioctl(int request, void* arg);
/// A wrapper for the ioctl system call. /// A wrapper for the ioctl system call.
bool initialized() const; bool initialized() const;
/// Returns true iff the underlying socket is initialized. /// Returns true iff the underlying socket is initialized.
protected: protected:
SocketImpl(); SocketImpl();
/// Creates a SocketImpl. /// Creates a SocketImpl.
SocketImpl(poco_socket_t sockfd); SocketImpl(poco_socket_t sockfd);
/// Creates a SocketImpl using the given native socket. /// Creates a SocketImpl using the given native socket.
virtual ~SocketImpl(); virtual ~SocketImpl();
/// Destroys the SocketImpl. /// Destroys the SocketImpl.
/// Closes the socket if it is still open. /// Closes the socket if it is still open.
virtual void init(int af); virtual void init(int af);
/// Creates the underlying native socket. /// Creates the underlying native socket.
/// ///
/// Subclasses must implement this method so /// Subclasses must implement this method so
/// that it calls initSocket() with the /// that it calls initSocket() with the
/// appropriate arguments. /// appropriate arguments.
/// ///
/// The default implementation creates a /// The default implementation creates a
/// stream socket. /// stream socket.
void initSocket(int af, int type, int proto = 0); void initSocket(int af, int type, int proto = 0);
/// Creates the underlying native socket. /// Creates the underlying native socket.
/// ///
/// The first argument, af, specifies the address family /// The first argument, af, specifies the address family
/// used by the socket, which should be either AF_INET or /// used by the socket, which should be either AF_INET or
/// AF_INET6. /// AF_INET6.
/// ///
/// The second argument, type, specifies the type of the /// The second argument, type, specifies the type of the
/// socket, which can be one of SOCK_STREAM, SOCK_DGRAM /// socket, which can be one of SOCK_STREAM, SOCK_DGRAM
/// or SOCK_RAW. /// or SOCK_RAW.
/// ///
/// The third argument, proto, is normally set to 0, /// The third argument, proto, is normally set to 0,
/// except for raw sockets. /// except for raw sockets.
void setSockfd(poco_socket_t aSocket); void setSockfd(poco_socket_t aSocket);
/// Allows subclasses to set the socket manually, iff no valid socket is set yet! /// Allows subclasses to set the socket manually, iff no valid socket is set yet!
void invalidate(); void invalidate();
/// Sets a socket to POCO_INVALID_SOCKET. It is assumed that the socket was closed /// Sets a socket to POCO_INVALID_SOCKET. It is assumed that the socket was closed
/// via a prior operation. /// via a prior operation.
static int lastError(); static int lastError();
/// Returns the last error code. /// Returns the last error code.
static void error(); static void error();
/// Throws an appropriate exception for the last error. /// Throws an appropriate exception for the last error.
static void error(const std::string& arg); static void error(const std::string& arg);
/// Throws an appropriate exception for the last error. /// Throws an appropriate exception for the last error.
static void error(int code); static void error(int code);
/// Throws an appropriate exception for the given error code. /// Throws an appropriate exception for the given error code.
static void error(int code, const std::string& arg); static void error(int code, const std::string& arg);
/// Throws an appropriate exception for the given error code. /// Throws an appropriate exception for the given error code.
private: private:
SocketImpl(const SocketImpl&); SocketImpl(const SocketImpl&);
SocketImpl& operator = (const SocketImpl&); SocketImpl& operator = (const SocketImpl&);
poco_socket_t _sockfd; poco_socket_t _sockfd;
#if defined(POCO_BROKEN_TIMEOUTS) #if defined(POCO_BROKEN_TIMEOUTS)
Poco::Timespan _recvTimeout; Poco::Timespan _recvTimeout;
#endif #endif
friend class Socket; friend class Socket;
friend class SecureSocketImpl; friend class SecureSocketImpl;
}; };
// //
// inlines // inlines
// //
inline poco_socket_t SocketImpl::sockfd() inline poco_socket_t SocketImpl::sockfd()
{ {
return _sockfd; return _sockfd;
} }
inline bool SocketImpl::initialized() const inline bool SocketImpl::initialized() const
{ {
return _sockfd != POCO_INVALID_SOCKET; return _sockfd != POCO_INVALID_SOCKET;
} }
inline int SocketImpl::lastError() inline int SocketImpl::lastError()
{ {
#if defined(_WIN32) #if defined(_WIN32)
return WSAGetLastError(); return WSAGetLastError();
#else #else
return errno; return errno;
#endif #endif
} }
inline void SocketImpl::invalidate() inline void SocketImpl::invalidate()
{ {
_sockfd = POCO_INVALID_SOCKET; _sockfd = POCO_INVALID_SOCKET;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketImpl_INCLUDED #endif // Net_SocketImpl_INCLUDED

View File

@ -1,162 +1,162 @@
// //
// SocketNotification.h // SocketNotification.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketNotification.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketNotification.h#1 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
// Module: SocketNotification // Module: SocketNotification
// //
// Definition of the SocketNotification class. // Definition of the SocketNotification class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketNotification_INCLUDED #ifndef Net_SocketNotification_INCLUDED
#define Net_SocketNotification_INCLUDED #define Net_SocketNotification_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/Notification.h" #include "Poco/Notification.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class SocketReactor; class SocketReactor;
class Net_API SocketNotification: public Poco::Notification class Net_API SocketNotification: public Poco::Notification
/// The base class for all notifications generated by /// The base class for all notifications generated by
/// the SocketReactor. /// the SocketReactor.
{ {
public: public:
SocketNotification(SocketReactor* pReactor); SocketNotification(SocketReactor* pReactor);
/// Creates the SocketNotification for the given SocketReactor. /// Creates the SocketNotification for the given SocketReactor.
virtual ~SocketNotification(); virtual ~SocketNotification();
/// Destroys the SocketNotification. /// Destroys the SocketNotification.
SocketReactor& source(); SocketReactor& source();
/// Returns the SocketReactor that generated the notification. /// Returns the SocketReactor that generated the notification.
Socket& socket(); Socket& socket();
/// Returns the socket that caused the notification. /// Returns the socket that caused the notification.
private: private:
void setSocket(const Socket& socket); void setSocket(const Socket& socket);
SocketReactor* _pReactor; SocketReactor* _pReactor;
Socket _socket; Socket _socket;
friend class SocketNotifier; friend class SocketNotifier;
}; };
class Net_API ReadableNotification: public SocketNotification class Net_API ReadableNotification: public SocketNotification
/// This notification is sent if a socket has become readable. /// This notification is sent if a socket has become readable.
{ {
public: public:
ReadableNotification(SocketReactor* pReactor); ReadableNotification(SocketReactor* pReactor);
/// Creates the ReadableNotification for the given SocketReactor. /// Creates the ReadableNotification for the given SocketReactor.
~ReadableNotification(); ~ReadableNotification();
/// Destroys the ReadableNotification. /// Destroys the ReadableNotification.
}; };
class Net_API WritableNotification: public SocketNotification class Net_API WritableNotification: public SocketNotification
/// This notification is sent if a socket has become writable. /// This notification is sent if a socket has become writable.
{ {
public: public:
WritableNotification(SocketReactor* pReactor); WritableNotification(SocketReactor* pReactor);
/// Creates the WritableNotification for the given SocketReactor. /// Creates the WritableNotification for the given SocketReactor.
~WritableNotification(); ~WritableNotification();
/// Destroys the WritableNotification. /// Destroys the WritableNotification.
}; };
class Net_API ErrorNotification: public SocketNotification class Net_API ErrorNotification: public SocketNotification
/// This notification is sent if a socket has signalled an error. /// This notification is sent if a socket has signalled an error.
{ {
public: public:
ErrorNotification(SocketReactor* pReactor); ErrorNotification(SocketReactor* pReactor);
/// Creates the ErrorNotification for the given SocketReactor. /// Creates the ErrorNotification for the given SocketReactor.
~ErrorNotification(); ~ErrorNotification();
/// Destroys the ErrorNotification. /// Destroys the ErrorNotification.
}; };
class Net_API TimeoutNotification: public SocketNotification class Net_API TimeoutNotification: public SocketNotification
/// This notification is sent if no other event has occured /// This notification is sent if no other event has occured
/// for a specified time. /// for a specified time.
{ {
public: public:
TimeoutNotification(SocketReactor* pReactor); TimeoutNotification(SocketReactor* pReactor);
/// Creates the TimeoutNotification for the given SocketReactor. /// Creates the TimeoutNotification for the given SocketReactor.
~TimeoutNotification(); ~TimeoutNotification();
/// Destroys the TimeoutNotification. /// Destroys the TimeoutNotification.
}; };
class Net_API ShutdownNotification: public SocketNotification class Net_API ShutdownNotification: public SocketNotification
/// This notification is sent when the SocketReactor is /// This notification is sent when the SocketReactor is
/// about to shut down. /// about to shut down.
{ {
public: public:
ShutdownNotification(SocketReactor* pReactor); ShutdownNotification(SocketReactor* pReactor);
/// Creates the ShutdownNotification for the given SocketReactor. /// Creates the ShutdownNotification for the given SocketReactor.
~ShutdownNotification(); ~ShutdownNotification();
/// Destroys the ShutdownNotification. /// Destroys the ShutdownNotification.
}; };
// //
// inlines // inlines
// //
inline SocketReactor& SocketNotification::source() inline SocketReactor& SocketNotification::source()
{ {
return *_pReactor; return *_pReactor;
} }
inline Socket& SocketNotification::socket() inline Socket& SocketNotification::socket()
{ {
return _socket; return _socket;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketNotification_INCLUDED #endif // Net_SocketNotification_INCLUDED

View File

@ -1,114 +1,114 @@
// //
// SocketNotifier.h // SocketNotifier.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketNotifier.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketNotifier.h#1 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
// Module: SocketNotifier // Module: SocketNotifier
// //
// Definition of the SocketNotifier class. // Definition of the SocketNotifier class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketNotifier_INCLUDED #ifndef Net_SocketNotifier_INCLUDED
#define Net_SocketNotifier_INCLUDED #define Net_SocketNotifier_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/RefCountedObject.h" #include "Poco/RefCountedObject.h"
#include "Poco/NotificationCenter.h" #include "Poco/NotificationCenter.h"
#include "Poco/Observer.h" #include "Poco/Observer.h"
#include <set> #include <set>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Socket; class Socket;
class SocketReactor; class SocketReactor;
class SocketNotification; class SocketNotification;
class Net_API SocketNotifier: public Poco::RefCountedObject class Net_API SocketNotifier: public Poco::RefCountedObject
/// This class is used internally by SocketReactor /// This class is used internally by SocketReactor
/// to notify registered event handlers of socket events. /// to notify registered event handlers of socket events.
{ {
public: public:
SocketNotifier(const Socket& socket); SocketNotifier(const Socket& socket);
/// Creates the SocketNotifier for the given socket. /// Creates the SocketNotifier for the given socket.
void addObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer); void addObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer);
/// Adds the given observer. /// Adds the given observer.
void removeObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer); void removeObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer);
/// Removes the given observer. /// Removes the given observer.
bool accepts(SocketNotification* pNotification); bool accepts(SocketNotification* pNotification);
/// Returns true if there is at least one observer for the given notification. /// Returns true if there is at least one observer for the given notification.
void dispatch(SocketNotification* pNotification); void dispatch(SocketNotification* pNotification);
/// Dispatches the notification to all observers. /// Dispatches the notification to all observers.
bool hasObservers() const; bool hasObservers() const;
/// Returns true if there are subscribers. /// Returns true if there are subscribers.
protected: protected:
~SocketNotifier(); ~SocketNotifier();
/// Destroys the SocketNotifier. /// Destroys the SocketNotifier.
private: private:
typedef std::multiset<SocketNotification*> EventSet; typedef std::multiset<SocketNotification*> EventSet;
EventSet _events; EventSet _events;
Poco::NotificationCenter _nc; Poco::NotificationCenter _nc;
Socket _socket; Socket _socket;
}; };
// //
// inlines // inlines
// //
inline bool SocketNotifier::accepts(SocketNotification* pNotification) inline bool SocketNotifier::accepts(SocketNotification* pNotification)
{ {
return _events.find(pNotification) != _events.end(); return _events.find(pNotification) != _events.end();
} }
inline bool SocketNotifier::hasObservers() const inline bool SocketNotifier::hasObservers() const
{ {
return _nc.hasObservers(); return _nc.hasObservers();
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketNotifier_INCLUDED #endif // Net_SocketNotifier_INCLUDED

View File

@ -1,221 +1,221 @@
// //
// SocketReactor.h // SocketReactor.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketReactor.h#2 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketReactor.h#2 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
// Module: SocketReactor // Module: SocketReactor
// //
// Definition of the SocketReactor class. // Definition of the SocketReactor class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketReactor_INCLUDED #ifndef Net_SocketReactor_INCLUDED
#define Net_SocketReactor_INCLUDED #define Net_SocketReactor_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
#include "Poco/Runnable.h" #include "Poco/Runnable.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include "Poco/Observer.h" #include "Poco/Observer.h"
#include "Poco/AutoPtr.h" #include "Poco/AutoPtr.h"
#include <map> #include <map>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Socket; class Socket;
class SocketNotification; class SocketNotification;
class SocketNotifier; class SocketNotifier;
class Net_API SocketReactor: public Poco::Runnable class Net_API SocketReactor: public Poco::Runnable
/// This class, which is part of the Reactor pattern, /// This class, which is part of the Reactor pattern,
/// implements the "Initiation Dispatcher". /// implements the "Initiation Dispatcher".
/// ///
/// The Reactor pattern has been described in the book /// The Reactor pattern has been described in the book
/// "Pattern Languages of Program Design" by Jim Coplien /// "Pattern Languages of Program Design" by Jim Coplien
/// and Douglas C. Schmidt (Addison Wesley, 1995). /// and Douglas C. Schmidt (Addison Wesley, 1995).
/// ///
/// The Reactor design pattern handles service requests that /// The Reactor design pattern handles service requests that
/// are delivered concurrently to an application by one or more /// are delivered concurrently to an application by one or more
/// clients. Each service in an application may consist of several /// clients. Each service in an application may consist of several
/// methods and is represented by a separate event handler. The event /// methods and is represented by a separate event handler. The event
/// handler is responsible for servicing service-specific requests. /// handler is responsible for servicing service-specific requests.
/// The SocketReactor dispatches the event handlers. /// The SocketReactor dispatches the event handlers.
/// ///
/// Event handlers (any class can be an event handler - there /// Event handlers (any class can be an event handler - there
/// is no base class for event handlers) can be registered /// is no base class for event handlers) can be registered
/// with the addEventHandler() method and deregistered with /// with the addEventHandler() method and deregistered with
/// the removeEventHandler() method. /// the removeEventHandler() method.
/// ///
/// An event handler is always registered for a certain socket, /// An event handler is always registered for a certain socket,
/// which is given in the call to addEventHandler(). Any method /// which is given in the call to addEventHandler(). Any method
/// of the event handler class can be registered to handle the /// of the event handler class can be registered to handle the
/// event - the only requirement is that the method takes /// event - the only requirement is that the method takes
/// a pointer to an instance of SocketNotification (or a subclass of it) /// a pointer to an instance of SocketNotification (or a subclass of it)
/// as argument. /// as argument.
/// ///
/// Once started, the SocketReactor waits for events /// Once started, the SocketReactor waits for events
/// on the registered sockets, using Socket::select(). /// on the registered sockets, using Socket::select().
/// If an event is detected, the corresponding event handler /// If an event is detected, the corresponding event handler
/// is invoked. There are five event types (and corresponding /// is invoked. There are five event types (and corresponding
/// notification classes) defined: ReadableNotification, WritableNotification, /// notification classes) defined: ReadableNotification, WritableNotification,
/// ErrorNotification, TimeoutNotification and ShutdownNotification. /// ErrorNotification, TimeoutNotification and ShutdownNotification.
/// ///
/// The ReadableNotification will be dispatched if a socket becomes /// The ReadableNotification will be dispatched if a socket becomes
/// readable. The WritableNotification will be dispatched if a socket /// readable. The WritableNotification will be dispatched if a socket
/// becomes writable. The ErrorNotification will be dispatched if /// becomes writable. The ErrorNotification will be dispatched if
/// there is an error condition on a socket. /// there is an error condition on a socket.
/// ///
/// If the timeout expires and no event has occured, a /// If the timeout expires and no event has occured, a
/// TimeoutNotification will be dispatched to all event handlers /// TimeoutNotification will be dispatched to all event handlers
/// registered for it. This is done in the onTimeout() method /// registered for it. This is done in the onTimeout() method
/// which can be overridded by subclasses to perform custom /// which can be overridded by subclasses to perform custom
/// timeout processing. /// timeout processing.
/// ///
/// Finally, when the SocketReactor is about to shut down (as a result /// Finally, when the SocketReactor is about to shut down (as a result
/// of stop() being called), it dispatches a ShutdownNotification /// of stop() being called), it dispatches a ShutdownNotification
/// to all event handlers. This is done in the onShutdown() method /// to all event handlers. This is done in the onShutdown() method
/// which can be overridded by subclasses to perform custom /// which can be overridded by subclasses to perform custom
/// shutdown processing. /// shutdown processing.
/// ///
/// The SocketReactor is implemented so that it can /// The SocketReactor is implemented so that it can
/// run in its own thread. It is also possible to run /// run in its own thread. It is also possible to run
/// multiple SocketReactors in parallel, as long as /// multiple SocketReactors in parallel, as long as
/// they work on different sockets. /// they work on different sockets.
/// ///
/// It is safe to call addEventHandler() and removeEventHandler() /// It is safe to call addEventHandler() and removeEventHandler()
/// from another thread while the SocketReactor is running. Also, /// from another thread while the SocketReactor is running. Also,
/// it is safe to call addEventHandler() and removeEventHandler() /// it is safe to call addEventHandler() and removeEventHandler()
/// from event handlers. /// from event handlers.
{ {
public: public:
SocketReactor(); SocketReactor();
/// Creates the SocketReactor. /// Creates the SocketReactor.
SocketReactor(const Poco::Timespan& timeout); SocketReactor(const Poco::Timespan& timeout);
/// Creates the SocketReactor, using the given timeout. /// Creates the SocketReactor, using the given timeout.
virtual ~SocketReactor(); virtual ~SocketReactor();
/// Destroys the SocketReactor. /// Destroys the SocketReactor.
void run(); void run();
/// Runs the SocketReactor. The reactor will run /// Runs the SocketReactor. The reactor will run
/// until stop() is called (in a separate thread). /// until stop() is called (in a separate thread).
void stop(); void stop();
/// Stops the SocketReactor. /// Stops the SocketReactor.
/// ///
/// The reactor will be stopped when the next event /// The reactor will be stopped when the next event
/// (including a timeout event) occurs. /// (including a timeout event) occurs.
void setTimeout(const Poco::Timespan& timeout); void setTimeout(const Poco::Timespan& timeout);
/// Sets the timeout. /// Sets the timeout.
/// ///
/// If no other event occurs for the given timeout /// If no other event occurs for the given timeout
/// interval, a timeout event is sent to all event listeners. /// interval, a timeout event is sent to all event listeners.
/// ///
/// The default timeout is 250 milliseconds; /// The default timeout is 250 milliseconds;
/// ///
/// The timeout is passed to the Socket::select() /// The timeout is passed to the Socket::select()
/// method. /// method.
const Poco::Timespan& getTimeout() const; const Poco::Timespan& getTimeout() const;
/// Returns the timeout. /// Returns the timeout.
void addEventHandler(const Socket& socket, const Poco::AbstractObserver& observer); void addEventHandler(const Socket& socket, const Poco::AbstractObserver& observer);
/// Registers an event handler with the SocketReactor. /// Registers an event handler with the SocketReactor.
/// ///
/// Usage: /// Usage:
/// Poco::Observer<MyEventHandler, SocketNotification> obs(*this, &MyEventHandler::handleMyEvent); /// Poco::Observer<MyEventHandler, SocketNotification> obs(*this, &MyEventHandler::handleMyEvent);
/// reactor.addEventHandler(obs); /// reactor.addEventHandler(obs);
void removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer); void removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer);
/// Unregisters an event handler with the SocketReactor. /// Unregisters an event handler with the SocketReactor.
/// ///
/// Usage: /// Usage:
/// Poco::Observer<MyEventHandler, SocketNotification> obs(*this, &MyEventHandler::handleMyEvent); /// Poco::Observer<MyEventHandler, SocketNotification> obs(*this, &MyEventHandler::handleMyEvent);
/// reactor.removeEventHandler(obs); /// reactor.removeEventHandler(obs);
protected: protected:
virtual void onTimeout(); virtual void onTimeout();
/// Called if the timeout expires and no other events are available. /// Called if the timeout expires and no other events are available.
/// ///
/// Can be overridden by subclasses. The default implementation /// Can be overridden by subclasses. The default implementation
/// dispatches the TimeoutNotification and thus should be called by overriding /// dispatches the TimeoutNotification and thus should be called by overriding
/// implementations. /// implementations.
virtual void onShutdown(); virtual void onShutdown();
/// Called when the SocketReactor is about to terminate. /// Called when the SocketReactor is about to terminate.
/// ///
/// Can be overridden by subclasses. The default implementation /// Can be overridden by subclasses. The default implementation
/// dispatches the ShutdownNotification and thus should be called by overriding /// dispatches the ShutdownNotification and thus should be called by overriding
/// implementations. /// implementations.
void dispatch(const Socket& socket, SocketNotification* pNotification); void dispatch(const Socket& socket, SocketNotification* pNotification);
/// Dispatches the given notification to all observers /// Dispatches the given notification to all observers
/// registered for the given socket. /// registered for the given socket.
void dispatch(SocketNotification* pNotification); void dispatch(SocketNotification* pNotification);
/// Dispatches the given notification to all observers. /// Dispatches the given notification to all observers.
private: private:
typedef Poco::AutoPtr<SocketNotifier> NotifierPtr; typedef Poco::AutoPtr<SocketNotifier> NotifierPtr;
typedef Poco::AutoPtr<SocketNotification> NotificationPtr; typedef Poco::AutoPtr<SocketNotification> NotificationPtr;
typedef std::map<Socket, NotifierPtr> EventHandlerMap; typedef std::map<Socket, NotifierPtr> EventHandlerMap;
void dispatch(NotifierPtr& pNotifier, SocketNotification* pNotification); void dispatch(NotifierPtr& pNotifier, SocketNotification* pNotification);
enum enum
{ {
DEFAULT_TIMEOUT = 250000 DEFAULT_TIMEOUT = 250000
}; };
bool _stop; bool _stop;
Poco::Timespan _timeout; Poco::Timespan _timeout;
EventHandlerMap _handlers; EventHandlerMap _handlers;
NotificationPtr _pReadableNotification; NotificationPtr _pReadableNotification;
NotificationPtr _pWritableNotification; NotificationPtr _pWritableNotification;
NotificationPtr _pErrorNotification; NotificationPtr _pErrorNotification;
NotificationPtr _pTimeoutNotification; NotificationPtr _pTimeoutNotification;
NotificationPtr _pShutdownNotification; NotificationPtr _pShutdownNotification;
Poco::FastMutex _mutex; Poco::FastMutex _mutex;
friend class SocketNotifier; friend class SocketNotifier;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketReactor_INCLUDED #endif // Net_SocketReactor_INCLUDED

View File

@ -1,199 +1,199 @@
// //
// SocketStream.h // SocketStream.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/SocketStream.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/SocketStream.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: SocketStream // Module: SocketStream
// //
// Definition of the SocketStream class. // Definition of the SocketStream class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_SocketStream_INCLUDED #ifndef Net_SocketStream_INCLUDED
#define Net_SocketStream_INCLUDED #define Net_SocketStream_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/BufferedBidirectionalStreamBuf.h" #include "Poco/BufferedBidirectionalStreamBuf.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class StreamSocketImpl; class StreamSocketImpl;
class Net_API SocketStreamBuf: public Poco::BufferedBidirectionalStreamBuf class Net_API SocketStreamBuf: public Poco::BufferedBidirectionalStreamBuf
/// This is the streambuf class used for reading from and writing to a socket. /// This is the streambuf class used for reading from and writing to a socket.
{ {
public: public:
SocketStreamBuf(const Socket& socket); SocketStreamBuf(const Socket& socket);
/// Creates a SocketStreamBuf with the given socket. /// Creates a SocketStreamBuf with the given socket.
/// ///
/// The socket's SocketImpl must be a StreamSocketImpl, /// The socket's SocketImpl must be a StreamSocketImpl,
/// otherwise an InvalidArgumentException is thrown. /// otherwise an InvalidArgumentException is thrown.
~SocketStreamBuf(); ~SocketStreamBuf();
/// Destroys the SocketStreamBuf. /// Destroys the SocketStreamBuf.
StreamSocketImpl* socketImpl() const; StreamSocketImpl* socketImpl() const;
/// Returns the internal SocketImpl. /// Returns the internal SocketImpl.
protected: protected:
int readFromDevice(char* buffer, std::streamsize length); int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length); int writeToDevice(const char* buffer, std::streamsize length);
private: private:
enum enum
{ {
STREAM_BUFFER_SIZE = 1024 STREAM_BUFFER_SIZE = 1024
}; };
StreamSocketImpl* _pImpl; StreamSocketImpl* _pImpl;
}; };
class Net_API SocketIOS: public virtual std::ios class Net_API SocketIOS: public virtual std::ios
/// The base class for SocketStream, SocketInputStream and /// The base class for SocketStream, SocketInputStream and
/// SocketOutputStream. /// SocketOutputStream.
/// ///
/// This class is needed to ensure the correct initialization /// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes. /// order of the stream buffer and base classes.
{ {
public: public:
SocketIOS(const Socket& socket); SocketIOS(const Socket& socket);
/// Creates the SocketIOS with the given socket. /// Creates the SocketIOS with the given socket.
/// ///
/// The socket's SocketImpl must be a StreamSocketImpl, /// The socket's SocketImpl must be a StreamSocketImpl,
/// otherwise an InvalidArgumentException is thrown. /// otherwise an InvalidArgumentException is thrown.
~SocketIOS(); ~SocketIOS();
/// Destroys the SocketIOS. /// Destroys the SocketIOS.
/// ///
/// Flushes the buffer, but does not close the socket. /// Flushes the buffer, but does not close the socket.
SocketStreamBuf* rdbuf(); SocketStreamBuf* rdbuf();
/// Returns a pointer to the internal SocketStreamBuf. /// Returns a pointer to the internal SocketStreamBuf.
void close(); void close();
/// Flushes the stream and closes the socket. /// Flushes the stream and closes the socket.
StreamSocket socket() const; StreamSocket socket() const;
/// Returns the underlying socket. /// Returns the underlying socket.
protected: protected:
SocketStreamBuf _buf; SocketStreamBuf _buf;
}; };
class Net_API SocketOutputStream: public SocketIOS, public std::ostream class Net_API SocketOutputStream: public SocketIOS, public std::ostream
/// An output stream for writing to a socket. /// An output stream for writing to a socket.
{ {
public: public:
SocketOutputStream(const Socket& socket); SocketOutputStream(const Socket& socket);
/// Creates the SocketOutputStream with the given socket. /// Creates the SocketOutputStream with the given socket.
/// ///
/// The socket's SocketImpl must be a StreamSocketImpl, /// The socket's SocketImpl must be a StreamSocketImpl,
/// otherwise an InvalidArgumentException is thrown. /// otherwise an InvalidArgumentException is thrown.
~SocketOutputStream(); ~SocketOutputStream();
/// Destroys the SocketOutputStream. /// Destroys the SocketOutputStream.
/// ///
/// Flushes the buffer, but does not close the socket. /// Flushes the buffer, but does not close the socket.
}; };
class Net_API SocketInputStream: public SocketIOS, public std::istream class Net_API SocketInputStream: public SocketIOS, public std::istream
/// An input stream for reading from a socket. /// An input stream for reading from a socket.
/// ///
/// When using formatted input from a SocketInputStream, /// When using formatted input from a SocketInputStream,
/// always ensure that a receive timeout is set for the /// always ensure that a receive timeout is set for the
/// socket. Otherwise your program might unexpectedly /// socket. Otherwise your program might unexpectedly
/// hang. /// hang.
/// ///
/// However, using formatted input from a SocketInputStream /// However, using formatted input from a SocketInputStream
/// is not recommended, due to the read-ahead behavior of /// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads. /// istream with formatted reads.
{ {
public: public:
SocketInputStream(const Socket& socket); SocketInputStream(const Socket& socket);
/// Creates the SocketInputStream with the given socket. /// Creates the SocketInputStream with the given socket.
/// ///
/// The socket's SocketImpl must be a StreamSocketImpl, /// The socket's SocketImpl must be a StreamSocketImpl,
/// otherwise an InvalidArgumentException is thrown. /// otherwise an InvalidArgumentException is thrown.
~SocketInputStream(); ~SocketInputStream();
/// Destroys the SocketInputStream. /// Destroys the SocketInputStream.
}; };
class Net_API SocketStream: public SocketIOS, public std::iostream class Net_API SocketStream: public SocketIOS, public std::iostream
/// An bidirectional stream for reading from and writing to a socket. /// An bidirectional stream for reading from and writing to a socket.
/// ///
/// When using formatted input from a SocketStream, /// When using formatted input from a SocketStream,
/// always ensure that a receive timeout is set for the /// always ensure that a receive timeout is set for the
/// socket. Otherwise your program might unexpectedly /// socket. Otherwise your program might unexpectedly
/// hang. /// hang.
/// ///
/// However, using formatted input from a SocketStream /// However, using formatted input from a SocketStream
/// is not recommended, due to the read-ahead behavior of /// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads. /// istream with formatted reads.
{ {
public: public:
SocketStream(const Socket& socket); SocketStream(const Socket& socket);
/// Creates the SocketStream with the given socket. /// Creates the SocketStream with the given socket.
/// ///
/// The socket's SocketImpl must be a StreamSocketImpl, /// The socket's SocketImpl must be a StreamSocketImpl,
/// otherwise an InvalidArgumentException is thrown. /// otherwise an InvalidArgumentException is thrown.
~SocketStream(); ~SocketStream();
/// Destroys the SocketStream. /// Destroys the SocketStream.
/// ///
/// Flushes the buffer, but does not close the socket. /// Flushes the buffer, but does not close the socket.
}; };
// //
// inlines // inlines
// //
inline StreamSocketImpl* SocketStreamBuf::socketImpl() const inline StreamSocketImpl* SocketStreamBuf::socketImpl() const
{ {
return _pImpl; return _pImpl;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_SocketStream_INCLUDED #endif // Net_SocketStream_INCLUDED

View File

@ -1,156 +1,156 @@
// //
// StreamSocket.h // StreamSocket.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/StreamSocket.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/StreamSocket.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: StreamSocket // Module: StreamSocket
// //
// Definition of the StreamSocket class. // Definition of the StreamSocket class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_StreamSocket_INCLUDED #ifndef Net_StreamSocket_INCLUDED
#define Net_StreamSocket_INCLUDED #define Net_StreamSocket_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/Socket.h" #include "Poco/Net/Socket.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class StreamSocketImpl; class StreamSocketImpl;
class Net_API StreamSocket: public Socket class Net_API StreamSocket: public Socket
/// This class provides an interface to a /// This class provides an interface to a
/// TCP stream socket. /// TCP stream socket.
{ {
public: public:
StreamSocket(); StreamSocket();
/// Creates an unconnected stream socket. /// Creates an unconnected stream socket.
/// ///
/// Before sending or receiving data, the socket /// Before sending or receiving data, the socket
/// must be connected with a call to connect(). /// must be connected with a call to connect().
StreamSocket(const SocketAddress& address); StreamSocket(const SocketAddress& address);
/// Creates a stream socket and connects it to /// Creates a stream socket and connects it to
/// the socket specified by address. /// the socket specified by address.
StreamSocket(const Socket& socket); StreamSocket(const Socket& socket);
/// Creates the StreamSocket with the SocketImpl /// Creates the StreamSocket with the SocketImpl
/// from another socket. The SocketImpl must be /// from another socket. The SocketImpl must be
/// a StreamSocketImpl, otherwise an InvalidArgumentException /// a StreamSocketImpl, otherwise an InvalidArgumentException
/// will be thrown. /// will be thrown.
virtual ~StreamSocket(); virtual ~StreamSocket();
/// Destroys the StreamSocket. /// Destroys the StreamSocket.
StreamSocket& operator = (const Socket& socket); StreamSocket& operator = (const Socket& socket);
/// Assignment operator. /// Assignment operator.
/// ///
/// Releases the socket's SocketImpl and /// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and /// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl. /// increments the reference count of the SocketImpl.
void connect(const SocketAddress& address); void connect(const SocketAddress& address);
/// Initializes the socket and establishes a connection to /// Initializes the socket and establishes a connection to
/// the TCP server at the given address. /// the TCP server at the given address.
/// ///
/// Can also be used for UDP sockets. In this case, no /// Can also be used for UDP sockets. In this case, no
/// connection is established. Instead, incoming and outgoing /// connection is established. Instead, incoming and outgoing
/// packets are restricted to the specified address. /// packets are restricted to the specified address.
void connect(const SocketAddress& address, const Poco::Timespan& timeout); void connect(const SocketAddress& address, const Poco::Timespan& timeout);
/// Initializes the socket, sets the socket timeout and /// Initializes the socket, sets the socket timeout and
/// establishes a connection to the TCP server at the given address. /// establishes a connection to the TCP server at the given address.
void connectNB(const SocketAddress& address); void connectNB(const SocketAddress& address);
/// Initializes the socket and establishes a connection to /// Initializes the socket and establishes a connection to
/// the TCP server at the given address. Prior to opening the /// the TCP server at the given address. Prior to opening the
/// connection the socket is set to nonblocking mode. /// connection the socket is set to nonblocking mode.
void shutdownReceive(); void shutdownReceive();
/// Shuts down the receiving part of the socket connection. /// Shuts down the receiving part of the socket connection.
void shutdownSend(); void shutdownSend();
/// Shuts down the sending part of the socket connection. /// Shuts down the sending part of the socket connection.
void shutdown(); void shutdown();
/// Shuts down both the receiving and the sending part /// Shuts down both the receiving and the sending part
/// of the socket connection. /// of the socket connection.
int sendBytes(const void* buffer, int length, int flags = 0); int sendBytes(const void* buffer, int length, int flags = 0);
/// Sends the contents of the given buffer through /// Sends the contents of the given buffer through
/// the socket. /// the socket.
/// ///
/// Returns the number of bytes sent, which may be /// Returns the number of bytes sent, which may be
/// less than the number of bytes specified. /// less than the number of bytes specified.
int receiveBytes(void* buffer, int length, int flags = 0); int receiveBytes(void* buffer, int length, int flags = 0);
/// Receives data from the socket and stores it /// Receives data from the socket and stores it
/// in buffer. Up to length bytes are received. /// in buffer. Up to length bytes are received.
/// ///
/// Returns the number of bytes received. /// Returns the number of bytes received.
/// A return value of 0 means a graceful shutdown /// A return value of 0 means a graceful shutdown
/// of the connection from the peer. /// of the connection from the peer.
/// ///
/// Throws a TimeoutException if a receive timeout has /// Throws a TimeoutException if a receive timeout has
/// been set and nothing is received within that interval. /// been set and nothing is received within that interval.
/// Throws a NetException (or a subclass) in case of other errors. /// Throws a NetException (or a subclass) in case of other errors.
void sendUrgent(unsigned char data); void sendUrgent(unsigned char data);
/// Sends one byte of urgent data through /// Sends one byte of urgent data through
/// the socket. /// the socket.
/// ///
/// The data is sent with the MSG_OOB flag. /// The data is sent with the MSG_OOB flag.
/// ///
/// The preferred way for a socket to receive urgent data /// The preferred way for a socket to receive urgent data
/// is by enabling the SO_OOBINLINE option. /// is by enabling the SO_OOBINLINE option.
public: public:
StreamSocket(SocketImpl* pImpl); StreamSocket(SocketImpl* pImpl);
/// Creates the Socket and attaches the given SocketImpl. /// Creates the Socket and attaches the given SocketImpl.
/// The socket takes owership of the SocketImpl. /// The socket takes owership of the SocketImpl.
/// ///
/// The SocketImpl must be a StreamSocketImpl, otherwise /// The SocketImpl must be a StreamSocketImpl, otherwise
/// an InvalidArgumentException will be thrown. /// an InvalidArgumentException will be thrown.
friend class ServerSocket; friend class ServerSocket;
friend class SocketIOS; friend class SocketIOS;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_StreamSocket_INCLUDED #endif // Net_StreamSocket_INCLUDED

View File

@ -1,72 +1,72 @@
// //
// StreamSocketImpl.h // StreamSocketImpl.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/StreamSocketImpl.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/StreamSocketImpl.h#1 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
// Module: StreamSocketImpl // Module: StreamSocketImpl
// //
// Definition of the StreamSocketImpl class. // Definition of the StreamSocketImpl class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_StreamSocketImpl_INCLUDED #ifndef Net_StreamSocketImpl_INCLUDED
#define Net_StreamSocketImpl_INCLUDED #define Net_StreamSocketImpl_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/SocketImpl.h" #include "Poco/Net/SocketImpl.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API StreamSocketImpl: public SocketImpl class Net_API StreamSocketImpl: public SocketImpl
/// This class implements a TCP socket. /// This class implements a TCP socket.
{ {
public: public:
StreamSocketImpl(); StreamSocketImpl();
/// Creates a StreamSocketImpl. /// Creates a StreamSocketImpl.
StreamSocketImpl(poco_socket_t sockfd); StreamSocketImpl(poco_socket_t sockfd);
/// Creates a StreamSocketImpl using the given native socket. /// Creates a StreamSocketImpl using the given native socket.
virtual int sendBytes(const void* buffer, int length, int flags = 0); 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.
protected: protected:
virtual ~StreamSocketImpl(); virtual ~StreamSocketImpl();
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_StreamSocketImpl_INCLUDED #endif // Net_StreamSocketImpl_INCLUDED

View File

@ -1,87 +1,87 @@
// //
// StringPartSource.h // StringPartSource.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/StringPartSource.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/StringPartSource.h#1 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
// Module: StringPartSource // Module: StringPartSource
// //
// Definition of the StringPartSource class. // Definition of the StringPartSource class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_StringPartSource_INCLUDED #ifndef Net_StringPartSource_INCLUDED
#define Net_StringPartSource_INCLUDED #define Net_StringPartSource_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/PartSource.h" #include "Poco/Net/PartSource.h"
#include <sstream> #include <sstream>
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API StringPartSource: public PartSource class Net_API StringPartSource: public PartSource
/// An implementation of PartSource for strings. /// An implementation of PartSource for strings.
{ {
public: public:
StringPartSource(const std::string& str); StringPartSource(const std::string& str);
/// Creates the StringPartSource for the given string. /// Creates the StringPartSource for the given string.
/// ///
/// The MIME type is set to text/plain. /// The MIME type is set to text/plain.
StringPartSource(const std::string& str, const std::string& mediaType); StringPartSource(const std::string& str, const std::string& mediaType);
/// Creates the StringPartSource for the given /// Creates the StringPartSource for the given
/// string and MIME type. /// string and MIME type.
StringPartSource(const std::string& str, const std::string& mediaType, const std::string& filename); StringPartSource(const std::string& str, const std::string& mediaType, const std::string& filename);
/// Creates the StringPartSource for the given /// Creates the StringPartSource for the given
/// string, MIME type and filename. /// string, MIME type and filename.
~StringPartSource(); ~StringPartSource();
/// Destroys the StringPartSource. /// Destroys the StringPartSource.
std::istream& stream(); std::istream& stream();
/// Returns a string input stream for the string. /// Returns a string input stream for the string.
const std::string& filename(); const std::string& filename();
/// Returns the filename portion of the path. /// Returns the filename portion of the path.
private: private:
std::istringstream _istr; std::istringstream _istr;
std::string _filename; std::string _filename;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_StringPartSource_INCLUDED #endif // Net_StringPartSource_INCLUDED

View File

@ -1,191 +1,191 @@
// //
// TCPServer.h // TCPServer.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/TCPServer.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/TCPServer.h#1 $
// //
// Library: Net // Library: Net
// Package: TCPServer // Package: TCPServer
// Module: TCPServer // Module: TCPServer
// //
// Definition of the TCPServer class. // Definition of the TCPServer class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_TCPServer_INCLUDED #ifndef Net_TCPServer_INCLUDED
#define Net_TCPServer_INCLUDED #define Net_TCPServer_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/ServerSocket.h" #include "Poco/Net/ServerSocket.h"
#include "Poco/Runnable.h" #include "Poco/Runnable.h"
#include "Poco/Thread.h" #include "Poco/Thread.h"
#include "Poco/ThreadPool.h" #include "Poco/ThreadPool.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class TCPServerParams; class TCPServerParams;
class TCPServerDispatcher; class TCPServerDispatcher;
class TCPServerConnectionFactory; class TCPServerConnectionFactory;
class Net_API TCPServer: public Poco::Runnable class Net_API TCPServer: public Poco::Runnable
/// This class implements a multithreaded TCP server. /// This class implements a multithreaded TCP server.
/// ///
/// The server uses a ServerSocket to listen for incoming /// The server uses a ServerSocket to listen for incoming
/// connections. The ServerSocket must have been bound to /// connections. The ServerSocket must have been bound to
/// an address before it is passed to the TCPServer constructor. /// an address before it is passed to the TCPServer constructor.
/// Additionally, the ServerSocket must be put into listening /// Additionally, the ServerSocket must be put into listening
/// state before the TCPServer is started by calling the start() /// state before the TCPServer is started by calling the start()
/// method. /// method.
/// ///
/// The server uses a thread pool to assign threads to incoming /// The server uses a thread pool to assign threads to incoming
/// connections. Before incoming connections are assigned to /// connections. Before incoming connections are assigned to
/// a connection thread, they are put into a queue. /// a connection thread, they are put into a queue.
/// Connection threads fetch new connections from the queue as soon /// Connection threads fetch new connections from the queue as soon
/// as they become free. Thus, a connection thread may serve more /// as they become free. Thus, a connection thread may serve more
/// than one connection. /// than one connection.
/// ///
/// As soon as a connection thread fetches the next connection from /// As soon as a connection thread fetches the next connection from
/// the queue, it creates a TCPServerConnection object for it /// the queue, it creates a TCPServerConnection object for it
/// (using the TCPServerConnectionFactory passed to the constructor) /// (using the TCPServerConnectionFactory passed to the constructor)
/// and calls the TCPServerConnection's start() method. When the /// and calls the TCPServerConnection's start() method. When the
/// start() method returns, the connection object is deleted. /// start() method returns, the connection object is deleted.
/// ///
/// The number of connection threads is adjusted dynamically, depending /// The number of connection threads is adjusted dynamically, depending
/// on the number of connections waiting to be served. /// on the number of connections waiting to be served.
/// ///
/// It is possible to specify a maximum number of queued connections. /// It is possible to specify a maximum number of queued connections.
/// This prevents the connection queue from overflowing in the /// This prevents the connection queue from overflowing in the
/// case of an extreme server load. In such a case, connections that /// case of an extreme server load. In such a case, connections that
/// cannot be queued are silently and immediately closed. /// cannot be queued are silently and immediately closed.
/// ///
/// TCPServer uses a separate thread to accept incoming connections. /// TCPServer uses a separate thread to accept incoming connections.
/// Thus, the call to start() returns immediately, and the server /// Thus, the call to start() returns immediately, and the server
/// continues to run in the background. /// continues to run in the background.
/// ///
/// To stop the server from accepting new connections, call stop(). /// To stop the server from accepting new connections, call stop().
/// ///
/// After calling stop(), no new connections will be accepted and /// After calling stop(), no new connections will be accepted and
/// all queued connections will be discarded. /// all queued connections will be discarded.
/// Already served connections, however, will continue being served. /// Already served connections, however, will continue being served.
{ {
public: public:
TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& socket, TCPServerParams* pParams = 0); TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& socket, TCPServerParams* pParams = 0);
/// Creates the TCPServer, using the given ServerSocket. /// Creates the TCPServer, using the given ServerSocket.
/// ///
/// The server takes ownership of the TCPServerConnectionFactory /// The server takes ownership of the TCPServerConnectionFactory
/// and deletes it when it's no longer needed. /// and deletes it when it's no longer needed.
/// ///
/// The server also takes ownership of the TCPServerParams object. /// The server also takes ownership of the TCPServerParams object.
/// If no TCPServerParams object is given, the server's TCPServerDispatcher /// If no TCPServerParams object is given, the server's TCPServerDispatcher
/// creates its own one. /// creates its own one.
/// ///
/// News threads are taken from the default thread pool. /// News threads are taken from the default thread pool.
TCPServer(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams = 0); TCPServer(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams = 0);
/// Creates the TCPServer, using the given ServerSocket. /// Creates the TCPServer, using the given ServerSocket.
/// ///
/// The server takes ownership of the TCPServerConnectionFactory /// The server takes ownership of the TCPServerConnectionFactory
/// and deletes it when it's no longer needed. /// and deletes it when it's no longer needed.
/// ///
/// The server also takes ownership of the TCPServerParams object. /// The server also takes ownership of the TCPServerParams object.
/// If no TCPServerParams object is given, the server's TCPServerDispatcher /// If no TCPServerParams object is given, the server's TCPServerDispatcher
/// creates its own one. /// creates its own one.
/// ///
/// News threads are taken from the given thread pool. /// News threads are taken from the given thread pool.
virtual ~TCPServer(); virtual ~TCPServer();
/// Destroys the TCPServer and its TCPServerConnectionFactory. /// Destroys the TCPServer and its TCPServerConnectionFactory.
const TCPServerParams& params() const; const TCPServerParams& params() const;
/// Returns a const reference to the TCPServerParam object /// Returns a const reference to the TCPServerParam object
/// used by the server's TCPServerDispatcher. /// used by the server's TCPServerDispatcher.
void start(); void start();
/// Starts the server. A new thread will be /// Starts the server. A new thread will be
/// created that waits for and accepts incoming /// created that waits for and accepts incoming
/// connections. /// connections.
/// ///
/// Before start() is called, the ServerSocket passed to /// Before start() is called, the ServerSocket passed to
/// TCPServer must have been bound and put into listening state. /// TCPServer must have been bound and put into listening state.
void stop(); void stop();
/// Stops the server. /// Stops the server.
/// ///
/// No new connections will be accepted. /// No new connections will be accepted.
/// Already handled connections will continue to be served. /// Already handled connections will continue to be served.
/// ///
/// Once the server is stopped, it cannot be restarted. /// Once the server is stopped, it cannot be restarted.
int currentThreads() const; int currentThreads() const;
/// Returns the number of currently used connection threads. /// Returns the number of currently used connection threads.
int totalConnections() const; int totalConnections() const;
/// Returns the total number of handled connections. /// Returns the total number of handled connections.
int currentConnections() const; int currentConnections() const;
/// Returns the number of currently handled connections. /// Returns the number of currently handled connections.
int maxConcurrentConnections() const; int maxConcurrentConnections() const;
/// Returns the maximum number of concurrently handled connections. /// Returns the maximum number of concurrently handled connections.
int queuedConnections() const; int queuedConnections() const;
/// Returns the number of queued connections. /// Returns the number of queued connections.
int refusedConnections() const; int refusedConnections() const;
/// Returns the number of refused connections. /// Returns the number of refused connections.
protected: protected:
void run(); void run();
/// Runs the server. The server will run until /// Runs the server. The server will run until
/// the stop() method is called, or the server /// the stop() method is called, or the server
/// object is destroyed, which implicitly calls /// object is destroyed, which implicitly calls
/// the stop() method. /// the stop() method.
static std::string threadName(const ServerSocket& socket); static std::string threadName(const ServerSocket& socket);
/// Returns a thread name for the server thread. /// Returns a thread name for the server thread.
private: private:
TCPServer(); TCPServer();
TCPServer(const TCPServer&); TCPServer(const TCPServer&);
TCPServer& operator = (const TCPServer&); TCPServer& operator = (const TCPServer&);
ServerSocket _socket; ServerSocket _socket;
TCPServerDispatcher* _pDispatcher; TCPServerDispatcher* _pDispatcher;
Poco::Thread _thread; Poco::Thread _thread;
bool _stopped; bool _stopped;
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_TCPServer_INCLUDED #endif // Net_TCPServer_INCLUDED

View File

@ -1,108 +1,108 @@
// //
// TCPServerConnection.h // TCPServerConnection.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/TCPServerConnection.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/TCPServerConnection.h#1 $
// //
// Library: Net // Library: Net
// Package: TCPServer // Package: TCPServer
// Module: TCPServerConnection // Module: TCPServerConnection
// //
// Definition of the TCPServerConnection class. // Definition of the TCPServerConnection class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_TCPServerConnection_INCLUDED #ifndef Net_TCPServerConnection_INCLUDED
#define Net_TCPServerConnection_INCLUDED #define Net_TCPServerConnection_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Runnable.h" #include "Poco/Runnable.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API TCPServerConnection: public Poco::Runnable class Net_API TCPServerConnection: public Poco::Runnable
/// The abstract base class for TCP server connections /// The abstract base class for TCP server connections
/// created by TCPServer. /// created by TCPServer.
/// ///
/// Derived classes must override the run() method /// Derived classes must override the run() method
/// (inherited from Runnable). Furthermore, a /// (inherited from Runnable). Furthermore, a
/// TCPServerConnectionFactory must be provided for the subclass. /// TCPServerConnectionFactory must be provided for the subclass.
/// ///
/// The run() method must perform the complete handling /// The run() method must perform the complete handling
/// of the client connection. As soon as the run() method /// of the client connection. As soon as the run() method
/// returns, the server connection object is destroyed and /// returns, the server connection object is destroyed and
/// the connection is automatically closed. /// the connection is automatically closed.
/// ///
/// A new TCPServerConnection object will be created for /// A new TCPServerConnection object will be created for
/// each new client connection that is accepted by /// each new client connection that is accepted by
/// TCPServer. /// TCPServer.
{ {
public: public:
TCPServerConnection(const StreamSocket& socket); TCPServerConnection(const StreamSocket& socket);
/// Creates the TCPServerConnection using the given /// Creates the TCPServerConnection using the given
/// stream socket. /// stream socket.
virtual ~TCPServerConnection(); virtual ~TCPServerConnection();
/// Destroys the TCPServerConnection. /// Destroys the TCPServerConnection.
protected: protected:
StreamSocket& socket(); StreamSocket& socket();
/// Returns a reference to the underlying socket. /// Returns a reference to the underlying socket.
void start(); void start();
/// Calls run() and catches any exceptions that /// Calls run() and catches any exceptions that
/// might be thrown by run(). /// might be thrown by run().
private: private:
TCPServerConnection(); TCPServerConnection();
TCPServerConnection(const TCPServerConnection&); TCPServerConnection(const TCPServerConnection&);
TCPServerConnection& operator = (const TCPServerConnection&); TCPServerConnection& operator = (const TCPServerConnection&);
StreamSocket _socket; StreamSocket _socket;
friend class TCPServerDispatcher; friend class TCPServerDispatcher;
}; };
// //
// inlines // inlines
// //
inline StreamSocket& TCPServerConnection::socket() inline StreamSocket& TCPServerConnection::socket()
{ {
return _socket; return _socket;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_TCPServerConnection_INCLUDED #endif // Net_TCPServerConnection_INCLUDED

View File

@ -1,108 +1,108 @@
// //
// TCPServerConnectionFactory.h // TCPServerConnectionFactory.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/TCPServerConnectionFactory.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/TCPServerConnectionFactory.h#1 $
// //
// Library: Net // Library: Net
// Package: TCPServer // Package: TCPServer
// Module: TCPServerConnectionFactory // Module: TCPServerConnectionFactory
// //
// Definition of the TCPServerConnectionFactory class. // Definition of the TCPServerConnectionFactory class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_TCPServerConnectionFactory_INCLUDED #ifndef Net_TCPServerConnectionFactory_INCLUDED
#define Net_TCPServerConnectionFactory_INCLUDED #define Net_TCPServerConnectionFactory_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnection.h" #include "Poco/Net/TCPServerConnection.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API TCPServerConnectionFactory class Net_API TCPServerConnectionFactory
/// A factory for TCPServerConnection objects. /// A factory for TCPServerConnection objects.
/// ///
/// The TCPServer class uses a TCPServerConnectionFactory /// The TCPServer class uses a TCPServerConnectionFactory
/// to create a connection object for each new connection /// to create a connection object for each new connection
/// it accepts. /// it accepts.
/// ///
/// Subclasses must override the createConnection() /// Subclasses must override the createConnection()
/// method. /// method.
/// ///
/// The TCPServerConnectionFactoryImpl template class /// The TCPServerConnectionFactoryImpl template class
/// can be used to automatically instantiate a /// can be used to automatically instantiate a
/// TCPServerConnectionFactory for a given subclass /// TCPServerConnectionFactory for a given subclass
/// of TCPServerConnection. /// of TCPServerConnection.
{ {
public: public:
virtual ~TCPServerConnectionFactory(); virtual ~TCPServerConnectionFactory();
/// Destroys the TCPServerConnectionFactory. /// Destroys the TCPServerConnectionFactory.
virtual TCPServerConnection* createConnection(const StreamSocket& socket) = 0; virtual TCPServerConnection* createConnection(const StreamSocket& socket) = 0;
/// Creates an instance of a subclass of TCPServerConnection, /// Creates an instance of a subclass of TCPServerConnection,
/// using the given StreamSocket. /// using the given StreamSocket.
protected: protected:
TCPServerConnectionFactory(); TCPServerConnectionFactory();
/// Creates the TCPServerConnectionFactory. /// Creates the TCPServerConnectionFactory.
private: private:
TCPServerConnectionFactory(const TCPServerConnectionFactory&); TCPServerConnectionFactory(const TCPServerConnectionFactory&);
TCPServerConnectionFactory& operator = (const TCPServerConnectionFactory&); TCPServerConnectionFactory& operator = (const TCPServerConnectionFactory&);
}; };
template <class S> template <class S>
class TCPServerConnectionFactoryImpl: public TCPServerConnectionFactory class TCPServerConnectionFactoryImpl: public TCPServerConnectionFactory
/// This template provides a basic implementation of /// This template provides a basic implementation of
/// TCPServerConnectionFactory. /// TCPServerConnectionFactory.
{ {
public: public:
TCPServerConnectionFactoryImpl() TCPServerConnectionFactoryImpl()
{ {
} }
~TCPServerConnectionFactoryImpl() ~TCPServerConnectionFactoryImpl()
{ {
} }
TCPServerConnection* createConnection(const StreamSocket& socket) TCPServerConnection* createConnection(const StreamSocket& socket)
{ {
return new S(socket); return new S(socket);
} }
}; };
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_TCPServerConnectionFactory_INCLUDED #endif // Net_TCPServerConnectionFactory_INCLUDED

View File

@ -1,151 +1,151 @@
// //
// TCPServerDispatcher.h // TCPServerDispatcher.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/TCPServerDispatcher.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/TCPServerDispatcher.h#1 $
// //
// Library: Net // Library: Net
// Package: TCPServer // Package: TCPServer
// Module: TCPServerDispatcher // Module: TCPServerDispatcher
// //
// Definition of the TCPServerDispatcher class. // Definition of the TCPServerDispatcher class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_TCPServerDispatcher_INCLUDED #ifndef Net_TCPServerDispatcher_INCLUDED
#define Net_TCPServerDispatcher_INCLUDED #define Net_TCPServerDispatcher_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Runnable.h" #include "Poco/Runnable.h"
#include "Poco/NotificationQueue.h" #include "Poco/NotificationQueue.h"
#include "Poco/ThreadPool.h" #include "Poco/ThreadPool.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class TCPServerParams; class TCPServerParams;
class TCPServerConnectionFactory; class TCPServerConnectionFactory;
class Net_API TCPServerDispatcher: public Poco::Runnable class Net_API TCPServerDispatcher: public Poco::Runnable
/// A helper class for TCPServer that dispatches /// A helper class for TCPServer that dispatches
/// connections to server connection threads. /// connections to server connection threads.
{ {
public: public:
TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, TCPServerParams* pParams); TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, TCPServerParams* pParams);
/// Creates the TCPServerDispatcher. /// Creates the TCPServerDispatcher.
/// ///
/// The dispatcher takes ownership of the TCPServerParams object. /// The dispatcher takes ownership of the TCPServerParams object.
/// If no TCPServerParams object is supplied, the TCPServerDispatcher /// If no TCPServerParams object is supplied, the TCPServerDispatcher
/// creates one. /// creates one.
void duplicate(); void duplicate();
/// Increments the object's reference count. /// Increments the object's reference count.
void release(); void release();
/// Decrements the object's reference count /// Decrements the object's reference count
/// and deletes the object if the count /// and deletes the object if the count
/// reaches zero. /// reaches zero.
void run(); void run();
/// Runs the dispatcher. /// Runs the dispatcher.
void enqueue(const StreamSocket& socket); void enqueue(const StreamSocket& socket);
/// Queues the given socket connection. /// Queues the given socket connection.
void stop(); void stop();
/// Stops the dispatcher. /// Stops the dispatcher.
int currentThreads() const; int currentThreads() const;
/// Returns the number of currently used threads. /// Returns the number of currently used threads.
int totalConnections() const; int totalConnections() const;
/// Returns the total number of handled connections. /// Returns the total number of handled connections.
int currentConnections() const; int currentConnections() const;
/// Returns the number of currently handled connections. /// Returns the number of currently handled connections.
int maxConcurrentConnections() const; int maxConcurrentConnections() const;
/// Returns the maximum number of concurrently handled connections. /// Returns the maximum number of concurrently handled connections.
int queuedConnections() const; int queuedConnections() const;
/// Returns the number of queued connections. /// Returns the number of queued connections.
int refusedConnections() const; int refusedConnections() const;
/// Returns the number of refused connections. /// Returns the number of refused connections.
const TCPServerParams& params() const; const TCPServerParams& params() const;
/// Returns a const reference to the TCPServerParam object. /// Returns a const reference to the TCPServerParam object.
protected: protected:
~TCPServerDispatcher(); ~TCPServerDispatcher();
/// Destroys the TCPServerDispatcher. /// Destroys the TCPServerDispatcher.
void beginConnection(); void beginConnection();
/// Updates the performance counters. /// Updates the performance counters.
void endConnection(); void endConnection();
/// Updates the performance counters. /// Updates the performance counters.
private: private:
TCPServerDispatcher(); TCPServerDispatcher();
TCPServerDispatcher(const TCPServerDispatcher&); TCPServerDispatcher(const TCPServerDispatcher&);
TCPServerDispatcher& operator = (const TCPServerDispatcher&); TCPServerDispatcher& operator = (const TCPServerDispatcher&);
int _rc; int _rc;
TCPServerParams* _pParams; TCPServerParams* _pParams;
int _currentThreads; int _currentThreads;
int _totalConnections; int _totalConnections;
int _currentConnections; int _currentConnections;
int _maxConcurrentConnections; int _maxConcurrentConnections;
int _refusedConnections; int _refusedConnections;
bool _stopped; bool _stopped;
Poco::NotificationQueue _queue; Poco::NotificationQueue _queue;
TCPServerConnectionFactory* _pConnectionFactory; TCPServerConnectionFactory* _pConnectionFactory;
Poco::ThreadPool& _threadPool; Poco::ThreadPool& _threadPool;
mutable Poco::FastMutex _mutex; mutable Poco::FastMutex _mutex;
}; };
// //
// inlines // inlines
// //
inline const TCPServerParams& TCPServerDispatcher::params() const inline const TCPServerParams& TCPServerDispatcher::params() const
{ {
return *_pParams; return *_pParams;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_TCPServerDispatcher_INCLUDED #endif // Net_TCPServerDispatcher_INCLUDED

View File

@ -1,140 +1,140 @@
// //
// TCPServerParams.h // TCPServerParams.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/TCPServerParams.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/TCPServerParams.h#1 $
// //
// Library: Net // Library: Net
// Package: TCPServer // Package: TCPServer
// Module: TCPServerParams // Module: TCPServerParams
// //
// Definition of the TCPServerParams class. // Definition of the TCPServerParams class.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Net_TCPServerParams_INCLUDED #ifndef Net_TCPServerParams_INCLUDED
#define Net_TCPServerParams_INCLUDED #define Net_TCPServerParams_INCLUDED
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/RefCountedObject.h" #include "Poco/RefCountedObject.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
namespace Poco { namespace Poco {
namespace Net { namespace Net {
class Net_API TCPServerParams: public Poco::RefCountedObject class Net_API TCPServerParams: public Poco::RefCountedObject
/// This class is used to specify parameters to both the /// This class is used to specify parameters to both the
/// TCPServer, as well as to TCPServerDispatcher objects. /// TCPServer, as well as to TCPServerDispatcher objects.
/// ///
/// Subclasses may add new parameters to the class. /// Subclasses may add new parameters to the class.
{ {
public: public:
TCPServerParams(); TCPServerParams();
/// Creates the TCPServerParams. /// Creates the TCPServerParams.
/// ///
/// Sets the following default values: /// Sets the following default values:
/// - threadIdleTime: 10 seconds /// - threadIdleTime: 10 seconds
/// - maxThreads: 0 /// - maxThreads: 0
/// - maxQueued: 64 /// - maxQueued: 64
void setThreadIdleTime(const Poco::Timespan& idleTime); void setThreadIdleTime(const Poco::Timespan& idleTime);
/// Sets the maximum idle time for a thread before /// Sets the maximum idle time for a thread before
/// it is terminated. /// it is terminated.
/// ///
/// The default idle time is 10 seconds; /// The default idle time is 10 seconds;
const Poco::Timespan& getThreadIdleTime() const; const Poco::Timespan& getThreadIdleTime() const;
/// Returns the maximum thread idle time. /// Returns the maximum thread idle time.
void setMaxQueued(int count); void setMaxQueued(int count);
/// Sets the maximum number of queued connections. /// Sets the maximum number of queued connections.
/// Must be greater than 0. /// Must be greater than 0.
/// ///
/// If there are already the maximum number of connections /// If there are already the maximum number of connections
/// in the queue, new connections will be silently discarded. /// in the queue, new connections will be silently discarded.
/// ///
/// The default number is 64. /// The default number is 64.
int getMaxQueued() const; int getMaxQueued() const;
/// Returns the maximum number of queued connections. /// Returns the maximum number of queued connections.
void setMaxThreads(int count); void setMaxThreads(int count);
/// Sets the maximum number of simultaneous threads /// Sets the maximum number of simultaneous threads
/// available for this TCPServerDispatcher. /// available for this TCPServerDispatcher.
/// ///
/// Must be greater than or equal to 0. /// Must be greater than or equal to 0.
/// If 0 is specified, the TCPServerDispatcher will /// If 0 is specified, the TCPServerDispatcher will
/// set this parameter to the number of available threads /// set this parameter to the number of available threads
/// in its thread pool. /// in its thread pool.
/// ///
/// The thread pool used by the TCPServerDispatcher /// The thread pool used by the TCPServerDispatcher
/// must at least have the capacity for the given /// must at least have the capacity for the given
/// number of threads. /// number of threads.
int getMaxThreads() const; int getMaxThreads() const;
/// Returns the maximum number of simultaneous threads /// Returns the maximum number of simultaneous threads
/// available for this TCPServerDispatcher. /// available for this TCPServerDispatcher.
protected: protected:
virtual ~TCPServerParams(); virtual ~TCPServerParams();
/// Destroys the TCPServerParams. /// Destroys the TCPServerParams.
private: private:
Poco::Timespan _threadIdleTime; Poco::Timespan _threadIdleTime;
int _maxThreads; int _maxThreads;
int _maxQueued; int _maxQueued;
}; };
// //
// inlines // inlines
// //
inline const Poco::Timespan& TCPServerParams::getThreadIdleTime() const inline const Poco::Timespan& TCPServerParams::getThreadIdleTime() const
{ {
return _threadIdleTime; return _threadIdleTime;
} }
inline int TCPServerParams::getMaxThreads() const inline int TCPServerParams::getMaxThreads() const
{ {
return _maxThreads; return _maxThreads;
} }
inline int TCPServerParams::getMaxQueued() const inline int TCPServerParams::getMaxQueued() const
{ {
return _maxQueued; return _maxQueued;
} }
} } // namespace Poco::Net } } // namespace Poco::Net
#endif // Net_TCPServerParams_INCLUDED #endif // Net_TCPServerParams_INCLUDED

View File

@ -1,10 +1,10 @@
# This is a sample configuration file for EchoServer # This is a sample configuration file for EchoServer
logging.loggers.root.channel.class = ConsoleChannel logging.loggers.root.channel.class = ConsoleChannel
logging.loggers.app.name = Application logging.loggers.app.name = Application
logging.loggers.app.channel = c1 logging.loggers.app.channel = c1
logging.formatters.f1.class = PatternFormatter logging.formatters.f1.class = PatternFormatter
logging.formatters.f1.pattern = [%p] %t logging.formatters.f1.pattern = [%p] %t
logging.channels.c1.class = ConsoleChannel logging.channels.c1.class = ConsoleChannel
logging.channels.c1.formatter = f1 logging.channels.c1.formatter = f1
# EchoServer.port = 9911 # EchoServer.port = 9911

View File

@ -1,8 +1,8 @@
# #
# sample.vmsbuild # sample.vmsbuild
# #
# $Id: //poco/1.2/Net/samples/EchoServer/EchoServer.vmsbuild#1 $ # $Id: //poco/1.2/Net/samples/EchoServer/EchoServer.vmsbuild#1 $
# #
EXE=EchoServer EXE=EchoServer
EchoServer EchoServer
<SourceFilesHere> <SourceFilesHere>

View File

@ -1,152 +1,152 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="7.10" Version="7.10"
Name="EchoServer" Name="EchoServer"
ProjectGUID="{7339ED24-9950-4B74-8519-E8DC66C0524E}" ProjectGUID="{7339ED24-9950-4B74-8519-E8DC66C0524E}"
Keyword="Win32Proj"> Keyword="Win32Proj">
<Platforms> <Platforms>
<Platform <Platform
Name="Win32"/> Name="Win32"/>
</Platforms> </Platforms>
<Configurations> <Configurations>
<Configuration <Configuration
Name="debug_shared|Win32" Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared" OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared" IntermediateDirectory="obj\debug_shared"
ConfigurationType="1" ConfigurationType="1"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
BufferSecurityCheck="TRUE" BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE" ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE" RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/> DebugInformationFormat="4"/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib" AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/EchoServerd.exe" OutputFile="bin/EchoServerd.exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/EchoServerd.pdb" ProgramDatabaseFile="bin/EchoServerd.pdb"
SubSystem="1" SubSystem="1"
TargetMachine="1"/> TargetMachine="1"/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool"/> Name="VCPostBuildEventTool"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool
Name="VCPreLinkEventTool"/> Name="VCPreLinkEventTool"/>
<Tool <Tool
Name="VCResourceCompilerTool"/> Name="VCResourceCompilerTool"/>
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool"/> Name="VCWebServiceProxyGeneratorTool"/>
<Tool <Tool
Name="VCXMLDataGeneratorTool"/> Name="VCXMLDataGeneratorTool"/>
<Tool <Tool
Name="VCWebDeploymentTool"/> Name="VCWebDeploymentTool"/>
<Tool <Tool
Name="VCManagedWrapperGeneratorTool"/> Name="VCManagedWrapperGeneratorTool"/>
<Tool <Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
<Configuration <Configuration
Name="release_shared|Win32" Name="release_shared|Win32"
OutputDirectory="obj\release_shared" OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared" IntermediateDirectory="obj\release_shared"
ConfigurationType="1" ConfigurationType="1"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="4" Optimization="4"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE" EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE" OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="2" RuntimeLibrary="2"
BufferSecurityCheck="FALSE" BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE" ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE" RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/> DebugInformationFormat="3"/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib" AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/EchoServer.exe" OutputFile="bin/EchoServer.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE" GenerateDebugInformation="FALSE"
ProgramDatabaseFile="" ProgramDatabaseFile=""
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
TargetMachine="1"/> TargetMachine="1"/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool"/> Name="VCPostBuildEventTool"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool
Name="VCPreLinkEventTool"/> Name="VCPreLinkEventTool"/>
<Tool <Tool
Name="VCResourceCompilerTool"/> Name="VCResourceCompilerTool"/>
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool"/> Name="VCWebServiceProxyGeneratorTool"/>
<Tool <Tool
Name="VCXMLDataGeneratorTool"/> Name="VCXMLDataGeneratorTool"/>
<Tool <Tool
Name="VCWebDeploymentTool"/> Name="VCWebDeploymentTool"/>
<Tool <Tool
Name="VCManagedWrapperGeneratorTool"/> Name="VCManagedWrapperGeneratorTool"/>
<Tool <Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
</Configurations> </Configurations>
<References> <References>
</References> </References>
<Files> <Files>
<Filter <Filter
Name="Configuration Files" Name="Configuration Files"
Filter=""> Filter="">
<File <File
RelativePath=".\EchoServer.properties"> RelativePath=".\EchoServer.properties">
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Source Files" Name="Source Files"
Filter=""> Filter="">
<File <File
RelativePath=".\src\EchoServer.cpp"> RelativePath=".\src\EchoServer.cpp">
</File> </File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>
</VisualStudioProject> </VisualStudioProject>

View File

@ -1,218 +1,218 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8.00" Version="8.00"
Name="EchoServer" Name="EchoServer"
ProjectGUID="{7339ED24-9950-4B74-8519-E8DC66C0524E}" ProjectGUID="{7339ED24-9950-4B74-8519-E8DC66C0524E}"
RootNamespace="EchoServer" RootNamespace="EchoServer"
Keyword="Win32Proj" Keyword="Win32Proj"
> >
<Platforms> <Platforms>
<Platform <Platform
Name="Win32" Name="Win32"
/> />
</Platforms> </Platforms>
<ToolFiles> <ToolFiles>
</ToolFiles> </ToolFiles>
<Configurations> <Configurations>
<Configuration <Configuration
Name="debug_shared|Win32" Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared" OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared" IntermediateDirectory="obj\debug_shared"
ConfigurationType="1" ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
/> />
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool" Name="VCWebServiceProxyGeneratorTool"
/> />
<Tool <Tool
Name="VCMIDLTool" Name="VCMIDLTool"
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
BufferSecurityCheck="true" BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true" TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true" ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true" Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
/> />
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib" AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/EchoServerd.exe" OutputFile="bin/EchoServerd.exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="bin/EchoServerd.pdb" ProgramDatabaseFile="bin/EchoServerd.pdb"
SubSystem="1" SubSystem="1"
TargetMachine="1" TargetMachine="1"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
/> />
<Tool <Tool
Name="VCManifestTool" Name="VCManifestTool"
/> />
<Tool <Tool
Name="VCXDCMakeTool" Name="VCXDCMakeTool"
/> />
<Tool <Tool
Name="VCBscMakeTool" Name="VCBscMakeTool"
/> />
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
/> />
<Tool <Tool
Name="VCAppVerifierTool" Name="VCAppVerifierTool"
/> />
<Tool <Tool
Name="VCWebDeploymentTool" Name="VCWebDeploymentTool"
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
/> />
</Configuration> </Configuration>
<Configuration <Configuration
Name="release_shared|Win32" Name="release_shared|Win32"
OutputDirectory="obj\release_shared" OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared" IntermediateDirectory="obj\release_shared"
ConfigurationType="1" ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
/> />
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool" Name="VCWebServiceProxyGeneratorTool"
/> />
<Tool <Tool
Name="VCMIDLTool" Name="VCMIDLTool"
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="4" Optimization="4"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="true" OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true" StringPooling="true"
RuntimeLibrary="2" RuntimeLibrary="2"
BufferSecurityCheck="false" BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true" TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true" ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true" Detect64BitPortabilityProblems="true"
DebugInformationFormat="3" DebugInformationFormat="3"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
/> />
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib" AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/EchoServer.exe" OutputFile="bin/EchoServer.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false" GenerateDebugInformation="false"
ProgramDatabaseFile="" ProgramDatabaseFile=""
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
TargetMachine="1" TargetMachine="1"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
/> />
<Tool <Tool
Name="VCManifestTool" Name="VCManifestTool"
/> />
<Tool <Tool
Name="VCXDCMakeTool" Name="VCXDCMakeTool"
/> />
<Tool <Tool
Name="VCBscMakeTool" Name="VCBscMakeTool"
/> />
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
/> />
<Tool <Tool
Name="VCAppVerifierTool" Name="VCAppVerifierTool"
/> />
<Tool <Tool
Name="VCWebDeploymentTool" Name="VCWebDeploymentTool"
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
/> />
</Configuration> </Configuration>
</Configurations> </Configurations>
<References> <References>
</References> </References>
<Files> <Files>
<Filter <Filter
Name="Configuration Files" Name="Configuration Files"
> >
<File <File
RelativePath=".\EchoServer.properties" RelativePath=".\EchoServer.properties"
> >
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Source Files" Name="Source Files"
> >
<File <File
RelativePath=".\src\EchoServer.cpp" RelativePath=".\src\EchoServer.cpp"
> >
</File> </File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>
</VisualStudioProject> </VisualStudioProject>

View File

@ -1,17 +1,17 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.2/Net/samples/EchoServer/Makefile#1 $ # $Id: //poco/1.2/Net/samples/EchoServer/Makefile#1 $
# #
# Makefile for Poco EchoServer # Makefile for Poco EchoServer
# #
include $(POCO_BASE)/build/rules/global include $(POCO_BASE)/build/rules/global
objects = EchoServer objects = EchoServer
target = EchoServer target = EchoServer
target_version = 1 target_version = 1
target_libs = PocoUtil PocoNet PocoXML PocoFoundation target_libs = PocoUtil PocoNet PocoXML PocoFoundation
include $(POCO_BASE)/build/rules/exec include $(POCO_BASE)/build/rules/exec

View File

@ -1,228 +1,228 @@
// //
// EchoServer.cpp // EchoServer.cpp
// //
// $Id: //poco/1.2/Net/samples/EchoServer/src/EchoServer.cpp#3 $ // $Id: //poco/1.2/Net/samples/EchoServer/src/EchoServer.cpp#3 $
// //
// This sample demonstrates the SocketReactor and SocketAcceptor classes. // This sample demonstrates the SocketReactor and SocketAcceptor classes.
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // 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 // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // 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 // 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 // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // 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 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#include "Poco/Net/SocketReactor.h" #include "Poco/Net/SocketReactor.h"
#include "Poco/Net/SocketAcceptor.h" #include "Poco/Net/SocketAcceptor.h"
#include "Poco/Net/SocketNotification.h" #include "Poco/Net/SocketNotification.h"
#include "Poco/Net/StreamSocket.h" #include "Poco/Net/StreamSocket.h"
#include "Poco/Net/ServerSocket.h" #include "Poco/Net/ServerSocket.h"
#include "Poco/NObserver.h" #include "Poco/NObserver.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/Thread.h" #include "Poco/Thread.h"
#include "Poco/Util/ServerApplication.h" #include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h" #include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h" #include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h" #include "Poco/Util/HelpFormatter.h"
#include <iostream> #include <iostream>
using Poco::Net::SocketReactor; using Poco::Net::SocketReactor;
using Poco::Net::SocketAcceptor; using Poco::Net::SocketAcceptor;
using Poco::Net::ReadableNotification; using Poco::Net::ReadableNotification;
using Poco::Net::ShutdownNotification; using Poco::Net::ShutdownNotification;
using Poco::Net::ServerSocket; using Poco::Net::ServerSocket;
using Poco::Net::StreamSocket; using Poco::Net::StreamSocket;
using Poco::NObserver; using Poco::NObserver;
using Poco::AutoPtr; using Poco::AutoPtr;
using Poco::Thread; using Poco::Thread;
using Poco::Util::ServerApplication; using Poco::Util::ServerApplication;
using Poco::Util::Application; using Poco::Util::Application;
using Poco::Util::Option; using Poco::Util::Option;
using Poco::Util::OptionSet; using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter; using Poco::Util::HelpFormatter;
class EchoServiceHandler class EchoServiceHandler
{ {
public: public:
EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor): EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
_socket(socket), _socket(socket),
_reactor(reactor), _reactor(reactor),
_pBuffer(new char[BUFFER_SIZE]) _pBuffer(new char[BUFFER_SIZE])
{ {
Application& app = Application::instance(); Application& app = Application::instance();
app.logger().information("Connection from " + socket.peerAddress().toString()); app.logger().information("Connection from " + socket.peerAddress().toString());
_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable)); _reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown)); _reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
} }
~EchoServiceHandler() ~EchoServiceHandler()
{ {
Application& app = Application::instance(); Application& app = Application::instance();
try try
{ {
app.logger().information("Disconnecting " + _socket.peerAddress().toString()); app.logger().information("Disconnecting " + _socket.peerAddress().toString());
} }
catch (...) catch (...)
{ {
} }
_reactor.removeEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable)); _reactor.removeEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
_reactor.removeEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown)); _reactor.removeEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
delete [] _pBuffer; delete [] _pBuffer;
} }
void onReadable(const AutoPtr<ReadableNotification>& pNf) void onReadable(const AutoPtr<ReadableNotification>& pNf)
{ {
int n = _socket.receiveBytes(_pBuffer, BUFFER_SIZE); int n = _socket.receiveBytes(_pBuffer, BUFFER_SIZE);
if (n > 0) if (n > 0)
_socket.sendBytes(_pBuffer, n); _socket.sendBytes(_pBuffer, n);
else else
delete this; delete this;
} }
void onShutdown(const AutoPtr<ShutdownNotification>& pNf) void onShutdown(const AutoPtr<ShutdownNotification>& pNf)
{ {
delete this; delete this;
} }
private: private:
enum enum
{ {
BUFFER_SIZE = 1024 BUFFER_SIZE = 1024
}; };
StreamSocket _socket; StreamSocket _socket;
SocketReactor& _reactor; SocketReactor& _reactor;
char* _pBuffer; char* _pBuffer;
}; };
class EchoServer: public Poco::Util::ServerApplication class EchoServer: public Poco::Util::ServerApplication
/// The main application class. /// The main application class.
/// ///
/// This class handles command-line arguments and /// This class handles command-line arguments and
/// configuration files. /// configuration files.
/// Start the EchoServer executable with the help /// Start the EchoServer executable with the help
/// option (/help on Windows, --help on Unix) for /// option (/help on Windows, --help on Unix) for
/// the available command line options. /// the available command line options.
/// ///
/// To use the sample configuration file (EchoServer.properties), /// To use the sample configuration file (EchoServer.properties),
/// copy the file to the directory where the EchoServer executable /// copy the file to the directory where the EchoServer executable
/// resides. If you start the debug version of the EchoServer /// resides. If you start the debug version of the EchoServer
/// (EchoServerd[.exe]), you must also create a copy of the configuration /// (EchoServerd[.exe]), you must also create a copy of the configuration
/// file named EchoServerd.properties. In the configuration file, you /// file named EchoServerd.properties. In the configuration file, you
/// can specify the port on which the server is listening (default /// can specify the port on which the server is listening (default
/// 9977) and the format of the date/time string sent back to the client. /// 9977) and the format of the date/time string sent back to the client.
/// ///
/// To test the EchoServer you can use any telnet client (telnet localhost 9977). /// To test the EchoServer you can use any telnet client (telnet localhost 9977).
{ {
public: public:
EchoServer(): _helpRequested(false) EchoServer(): _helpRequested(false)
{ {
} }
~EchoServer() ~EchoServer()
{ {
} }
protected: protected:
void initialize(Application& self) void initialize(Application& self)
{ {
loadConfiguration(); // load default configuration files, if present loadConfiguration(); // load default configuration files, if present
ServerApplication::initialize(self); ServerApplication::initialize(self);
} }
void uninitialize() void uninitialize()
{ {
ServerApplication::uninitialize(); ServerApplication::uninitialize();
} }
void defineOptions(OptionSet& options) void defineOptions(OptionSet& options)
{ {
ServerApplication::defineOptions(options); ServerApplication::defineOptions(options);
options.addOption( options.addOption(
Option("help", "h", "display help information on command line arguments") Option("help", "h", "display help information on command line arguments")
.required(false) .required(false)
.repeatable(false)); .repeatable(false));
} }
void handleOption(const std::string& name, const std::string& value) void handleOption(const std::string& name, const std::string& value)
{ {
ServerApplication::handleOption(name, value); ServerApplication::handleOption(name, value);
if (name == "help") if (name == "help")
_helpRequested = true; _helpRequested = true;
} }
void displayHelp() void displayHelp()
{ {
HelpFormatter helpFormatter(options()); HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName()); helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS"); helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("An echo server implemented using the Reactor and Acceptor patterns."); helpFormatter.setHeader("An echo server implemented using the Reactor and Acceptor patterns.");
helpFormatter.format(std::cout); helpFormatter.format(std::cout);
} }
int main(const std::vector<std::string>& args) int main(const std::vector<std::string>& args)
{ {
if (_helpRequested) if (_helpRequested)
{ {
displayHelp(); displayHelp();
} }
else else
{ {
// get parameters from configuration file // get parameters from configuration file
unsigned short port = (unsigned short) config().getInt("EchoServer.port", 9977); unsigned short port = (unsigned short) config().getInt("EchoServer.port", 9977);
// set-up a server socket // set-up a server socket
ServerSocket svs(port); ServerSocket svs(port);
// set-up a SocketReactor... // set-up a SocketReactor...
SocketReactor reactor; SocketReactor reactor;
// ... and a SocketAcceptor // ... and a SocketAcceptor
SocketAcceptor<EchoServiceHandler> acceptor(svs, reactor); SocketAcceptor<EchoServiceHandler> acceptor(svs, reactor);
// run the reactor in its own thread so that we can wait for // run the reactor in its own thread so that we can wait for
// a termination request // a termination request
Thread thread; Thread thread;
thread.start(reactor); thread.start(reactor);
// wait for CTRL-C or kill // wait for CTRL-C or kill
waitForTerminationRequest(); waitForTerminationRequest();
// Stop the SocketReactor // Stop the SocketReactor
reactor.stop(); reactor.stop();
thread.join(); thread.join();
} }
return Application::EXIT_OK; return Application::EXIT_OK;
} }
private: private:
bool _helpRequested; bool _helpRequested;
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
EchoServer app; EchoServer app;
return app.run(argc, argv); return app.run(argc, argv);
} }

View File

@ -1,10 +1,10 @@
# This is a sample configuration file for HTTPFormServer # This is a sample configuration file for HTTPFormServer
logging.loggers.root.channel.class = ConsoleChannel logging.loggers.root.channel.class = ConsoleChannel
logging.loggers.app.name = Application logging.loggers.app.name = Application
logging.loggers.app.channel = c1 logging.loggers.app.channel = c1
logging.formatters.f1.class = PatternFormatter logging.formatters.f1.class = PatternFormatter
logging.formatters.f1.pattern = [%p] %t logging.formatters.f1.pattern = [%p] %t
logging.channels.c1.class = ConsoleChannel logging.channels.c1.class = ConsoleChannel
logging.channels.c1.formatter = f1 logging.channels.c1.formatter = f1
HTTPFormServer.port = 9980 HTTPFormServer.port = 9980

View File

@ -1,8 +1,8 @@
# #
# sample.vmsbuild # sample.vmsbuild
# #
# $Id: //poco/1.2/Net/samples/HTTPFormServer/HTTPFormServer.vmsbuild#1 $ # $Id: //poco/1.2/Net/samples/HTTPFormServer/HTTPFormServer.vmsbuild#1 $
# #
EXE=HTTPFormServer EXE=HTTPFormServer
HTTPFormServer HTTPFormServer
<SourceFilesHere> <SourceFilesHere>

View File

@ -1,152 +1,152 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="7.10" Version="7.10"
Name="HTTPFormServer" Name="HTTPFormServer"
ProjectGUID="{45A054E6-44EC-4943-809A-BA8B2A25DA21}" ProjectGUID="{45A054E6-44EC-4943-809A-BA8B2A25DA21}"
Keyword="Win32Proj"> Keyword="Win32Proj">
<Platforms> <Platforms>
<Platform <Platform
Name="Win32"/> Name="Win32"/>
</Platforms> </Platforms>
<Configurations> <Configurations>
<Configuration <Configuration
Name="debug_shared|Win32" Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared" OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared" IntermediateDirectory="obj\debug_shared"
ConfigurationType="1" ConfigurationType="1"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
BufferSecurityCheck="TRUE" BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE" ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE" RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/> DebugInformationFormat="4"/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib" AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/HTTPFormServerd.exe" OutputFile="bin/HTTPFormServerd.exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/HTTPFormServerd.pdb" ProgramDatabaseFile="bin/HTTPFormServerd.pdb"
SubSystem="1" SubSystem="1"
TargetMachine="1"/> TargetMachine="1"/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool"/> Name="VCPostBuildEventTool"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool
Name="VCPreLinkEventTool"/> Name="VCPreLinkEventTool"/>
<Tool <Tool
Name="VCResourceCompilerTool"/> Name="VCResourceCompilerTool"/>
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool"/> Name="VCWebServiceProxyGeneratorTool"/>
<Tool <Tool
Name="VCXMLDataGeneratorTool"/> Name="VCXMLDataGeneratorTool"/>
<Tool <Tool
Name="VCWebDeploymentTool"/> Name="VCWebDeploymentTool"/>
<Tool <Tool
Name="VCManagedWrapperGeneratorTool"/> Name="VCManagedWrapperGeneratorTool"/>
<Tool <Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
<Configuration <Configuration
Name="release_shared|Win32" Name="release_shared|Win32"
OutputDirectory="obj\release_shared" OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared" IntermediateDirectory="obj\release_shared"
ConfigurationType="1" ConfigurationType="1"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="4" Optimization="4"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE" EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE" OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="2" RuntimeLibrary="2"
BufferSecurityCheck="FALSE" BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE" ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE" RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/> DebugInformationFormat="3"/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib" AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/HTTPFormServer.exe" OutputFile="bin/HTTPFormServer.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE" GenerateDebugInformation="FALSE"
ProgramDatabaseFile="" ProgramDatabaseFile=""
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
TargetMachine="1"/> TargetMachine="1"/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool"/> Name="VCPostBuildEventTool"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool
Name="VCPreLinkEventTool"/> Name="VCPreLinkEventTool"/>
<Tool <Tool
Name="VCResourceCompilerTool"/> Name="VCResourceCompilerTool"/>
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool"/> Name="VCWebServiceProxyGeneratorTool"/>
<Tool <Tool
Name="VCXMLDataGeneratorTool"/> Name="VCXMLDataGeneratorTool"/>
<Tool <Tool
Name="VCWebDeploymentTool"/> Name="VCWebDeploymentTool"/>
<Tool <Tool
Name="VCManagedWrapperGeneratorTool"/> Name="VCManagedWrapperGeneratorTool"/>
<Tool <Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
</Configurations> </Configurations>
<References> <References>
</References> </References>
<Files> <Files>
<Filter <Filter
Name="Configuration Files" Name="Configuration Files"
Filter=""> Filter="">
<File <File
RelativePath=".\HTTPFormServer.properties"> RelativePath=".\HTTPFormServer.properties">
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Source Files" Name="Source Files"
Filter=""> Filter="">
<File <File
RelativePath=".\src\HTTPFormServer.cpp"> RelativePath=".\src\HTTPFormServer.cpp">
</File> </File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>
</VisualStudioProject> </VisualStudioProject>

View File

@ -1,217 +1,217 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8.00" Version="8.00"
Name="HTTPFormServer" Name="HTTPFormServer"
ProjectGUID="{5363487F-1F23-4F9E-B6A7-5471B0F2373F}" ProjectGUID="{5363487F-1F23-4F9E-B6A7-5471B0F2373F}"
Keyword="Win32Proj" Keyword="Win32Proj"
> >
<Platforms> <Platforms>
<Platform <Platform
Name="Win32" Name="Win32"
/> />
</Platforms> </Platforms>
<ToolFiles> <ToolFiles>
</ToolFiles> </ToolFiles>
<Configurations> <Configurations>
<Configuration <Configuration
Name="debug_shared|Win32" Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared" OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared" IntermediateDirectory="obj\debug_shared"
ConfigurationType="1" ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
/> />
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool" Name="VCWebServiceProxyGeneratorTool"
/> />
<Tool <Tool
Name="VCMIDLTool" Name="VCMIDLTool"
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
BufferSecurityCheck="true" BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true" TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true" ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true" Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
/> />
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib" AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/HTTPFormServerd.exe" OutputFile="bin/HTTPFormServerd.exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="bin/HTTPFormServerd.pdb" ProgramDatabaseFile="bin/HTTPFormServerd.pdb"
SubSystem="1" SubSystem="1"
TargetMachine="1" TargetMachine="1"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
/> />
<Tool <Tool
Name="VCManifestTool" Name="VCManifestTool"
/> />
<Tool <Tool
Name="VCXDCMakeTool" Name="VCXDCMakeTool"
/> />
<Tool <Tool
Name="VCBscMakeTool" Name="VCBscMakeTool"
/> />
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
/> />
<Tool <Tool
Name="VCAppVerifierTool" Name="VCAppVerifierTool"
/> />
<Tool <Tool
Name="VCWebDeploymentTool" Name="VCWebDeploymentTool"
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
/> />
</Configuration> </Configuration>
<Configuration <Configuration
Name="release_shared|Win32" Name="release_shared|Win32"
OutputDirectory="obj\release_shared" OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared" IntermediateDirectory="obj\release_shared"
ConfigurationType="1" ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2" UseOfMFC="2"
CharacterSet="2" CharacterSet="2"
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
/> />
<Tool <Tool
Name="VCWebServiceProxyGeneratorTool" Name="VCWebServiceProxyGeneratorTool"
/> />
<Tool <Tool
Name="VCMIDLTool" Name="VCMIDLTool"
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="4" Optimization="4"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="true" OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include" AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true" StringPooling="true"
RuntimeLibrary="2" RuntimeLibrary="2"
BufferSecurityCheck="false" BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true" TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true" ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true" Detect64BitPortabilityProblems="true"
DebugInformationFormat="3" DebugInformationFormat="3"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
/> />
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib" AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/HTTPFormServer.exe" OutputFile="bin/HTTPFormServer.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib" AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false" GenerateDebugInformation="false"
ProgramDatabaseFile="" ProgramDatabaseFile=""
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
TargetMachine="1" TargetMachine="1"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
/> />
<Tool <Tool
Name="VCManifestTool" Name="VCManifestTool"
/> />
<Tool <Tool
Name="VCXDCMakeTool" Name="VCXDCMakeTool"
/> />
<Tool <Tool
Name="VCBscMakeTool" Name="VCBscMakeTool"
/> />
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
/> />
<Tool <Tool
Name="VCAppVerifierTool" Name="VCAppVerifierTool"
/> />
<Tool <Tool
Name="VCWebDeploymentTool" Name="VCWebDeploymentTool"
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
/> />
</Configuration> </Configuration>
</Configurations> </Configurations>
<References> <References>
</References> </References>
<Files> <Files>
<Filter <Filter
Name="Configuration Files" Name="Configuration Files"
> >
<File <File
RelativePath=".\HTTPFormServer.properties" RelativePath=".\HTTPFormServer.properties"
> >
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Source Files" Name="Source Files"
> >
<File <File
RelativePath=".\src\HTTPFormServer.cpp" RelativePath=".\src\HTTPFormServer.cpp"
> >
</File> </File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>
</VisualStudioProject> </VisualStudioProject>

Some files were not shown because too many files have changed in this diff Show More