submitted 1.2.0

This commit is contained in:
Guenter Obiltschnig
2006-08-29 07:10:35 +00:00
parent f476bd6b32
commit 2d4078f392
1428 changed files with 25715 additions and 12456 deletions

View File

@@ -1,7 +1,7 @@
//
// DNS.cpp
//
// $Id: //poco/1.1.0/Net/src/DNS.cpp#2 $
// $Id: //poco/1.2/Net/src/DNS.cpp#1 $
//
// Library: Net
// Package: NetCore
@@ -34,17 +34,17 @@
//
#include "Net/DNS.h"
#include "Net/NetException.h"
#include "Net/SocketAddress.h"
#include "Foundation/Environment.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/DNS.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Environment.h"
#include "Poco/NumberFormatter.h"
using Foundation::FastMutex;
using Foundation::Environment;
using Foundation::NumberFormatter;
using Foundation::IOException;
using Poco::FastMutex;
using Poco::Environment;
using Poco::NumberFormatter;
using Poco::IOException;
//
@@ -74,11 +74,12 @@ namespace
#endif // _WIN32
Net_BEGIN
namespace Poco {
namespace Net {
DNS::DNSCache DNS::_cache;
Foundation::FastMutex DNS::_mutex;
Poco::FastMutex DNS::_mutex;
const HostEntry& DNS::hostByName(const std::string& hostname)
@@ -223,4 +224,4 @@ void DNS::error(int code, const std::string& arg)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// DatagramSocket.cpp
//
// $Id: //poco/1.1.0/Net/src/DatagramSocket.cpp#2 $
// $Id: //poco/1.2/Net/src/DatagramSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,15 +34,16 @@
//
#include "Net/DatagramSocket.h"
#include "Net/DatagramSocketImpl.h"
#include "Foundation/Exception.h"
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/DatagramSocketImpl.h"
#include "Poco/Exception.h"
using Foundation::InvalidArgumentException;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
DatagramSocket::DatagramSocket(): Socket(new DatagramSocketImpl)
@@ -126,4 +127,4 @@ int DatagramSocket::receiveFrom(void* buffer, int length, SocketAddress& address
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// DatagramSocketImpl.cpp
//
// $Id: //poco/1.1.0/Net/src/DatagramSocketImpl.cpp#2 $
// $Id: //poco/1.2/Net/src/DatagramSocketImpl.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,14 +34,15 @@
//
#include "Net/DatagramSocketImpl.h"
#include "Net/NetException.h"
#include "Poco/Net/DatagramSocketImpl.h"
#include "Poco/Net/NetException.h"
using Foundation::InvalidArgumentException;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
DatagramSocketImpl::DatagramSocketImpl()
@@ -79,4 +80,4 @@ void DatagramSocketImpl::init(int af)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// DialogSocket.cpp
//
// $Id: //poco/1.1.0/Net/src/DialogSocket.cpp#2 $
// $Id: //poco/1.2/Net/src/DialogSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,12 +34,13 @@
//
#include "Net/DialogSocket.h"
#include "Poco/Net/DialogSocket.h"
#include <string.h>
#include <ctype.h>
Net_BEGIN
namespace Poco {
namespace Net {
DialogSocket::DialogSocket():
@@ -274,4 +275,4 @@ int DialogSocket::receiveStatusLine(std::string& line)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// FTPClientSession.cpp
//
// $Id: //poco/1.1.0/Net/src/FTPClientSession.cpp#2 $
// $Id: //poco/1.2/Net/src/FTPClientSession.cpp#1 $
//
// Library: Net
// Package: FTP
@@ -34,19 +34,20 @@
//
#include "Net/FTPClientSession.h"
#include "Net/SocketAddress.h"
#include "Net/SocketStream.h"
#include "Net/ServerSocket.h"
#include "Net/NetException.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/FTPClientSession.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include <ctype.h>
using Foundation::NumberFormatter;
using Poco::NumberFormatter;
Net_BEGIN
namespace Poco {
namespace Net {
FTPClientSession::FTPClientSession(const StreamSocket& socket):
@@ -62,7 +63,7 @@ FTPClientSession::FTPClientSession(const StreamSocket& socket):
}
FTPClientSession::FTPClientSession(const std::string& host, Foundation::UInt16 port):
FTPClientSession::FTPClientSession(const std::string& host, Poco::UInt16 port):
_controlSocket(SocketAddress(host, port)),
_pDataStream(0),
_passiveMode(true),
@@ -87,14 +88,14 @@ FTPClientSession::~FTPClientSession()
}
void FTPClientSession::setTimeout(const Foundation::Timespan& timeout)
void FTPClientSession::setTimeout(const Poco::Timespan& timeout)
{
_timeout = timeout;
_controlSocket.setReceiveTimeout(timeout);
}
Foundation::Timespan FTPClientSession::getTimeout() const
Poco::Timespan FTPClientSession::getTimeout() const
{
return _timeout;
}
@@ -415,7 +416,7 @@ void FTPClientSession::sendPORT(const SocketAddress& addr)
if (*it == '.') *it = ',';
}
arg += ',';
Foundation::UInt16 port = addr.port();
Poco::UInt16 port = addr.port();
arg += NumberFormatter::format(port/256);
arg += ',';
arg += NumberFormatter::format(port % 256);
@@ -466,10 +467,10 @@ void FTPClientSession::parseAddress(const std::string& str, SocketAddress& addr)
if (it != end && *it == ',') { host += '.'; ++it; }
while (it != end && isdigit(*it)) host += *it++;
if (it != end && *it == ',') ++it;
Foundation::UInt16 portHi = 0;
Poco::UInt16 portHi = 0;
while (it != end && isdigit(*it)) { portHi *= 10; portHi += *it++ - '0'; }
if (it != end && *it == ',') ++it;
Foundation::UInt16 portLo = 0;
Poco::UInt16 portLo = 0;
while (it != end && isdigit(*it)) { portLo *= 10; portLo += *it++ - '0'; }
addr = SocketAddress(host, portHi*256 + portLo);
}
@@ -485,7 +486,7 @@ void FTPClientSession::parseExtAddress(const std::string& str, SocketAddress& ad
if (it != end) delim = *it++;
if (it != end && *it == delim) ++it;
if (it != end && *it == delim) ++it;
Foundation::UInt16 port = 0;
Poco::UInt16 port = 0;
while (it != end && isdigit(*it)) { port *= 10; port += *it++ - '0'; }
addr = SocketAddress(_controlSocket.peerAddress().host(), port);
}
@@ -504,4 +505,4 @@ void FTPClientSession::endTransfer()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// FTPStreamFactory.cpp
//
// $Id: //poco/1.1.0/Net/src/FTPStreamFactory.cpp#2 $
// $Id: //poco/1.2/Net/src/FTPStreamFactory.cpp#1 $
//
// Library: Net
// Package: FTP
@@ -34,23 +34,24 @@
//
#include "Net/FTPStreamFactory.h"
#include "Net/FTPClientSession.h"
#include "Net/NetException.h"
#include "Foundation/URI.h"
#include "Foundation/URIStreamOpener.h"
#include "Foundation/UnbufferedStreamBuf.h"
#include "Foundation/Path.h"
#include "Poco/Net/FTPStreamFactory.h"
#include "Poco/Net/FTPClientSession.h"
#include "Poco/Net/NetException.h"
#include "Poco/URI.h"
#include "Poco/URIStreamOpener.h"
#include "Poco/UnbufferedStreamBuf.h"
#include "Poco/Path.h"
using Foundation::URIStreamFactory;
using Foundation::URI;
using Foundation::URIStreamOpener;
using Foundation::UnbufferedStreamBuf;
using Foundation::Path;
using Poco::URIStreamFactory;
using Poco::URI;
using Poco::URIStreamOpener;
using Poco::UnbufferedStreamBuf;
using Poco::Path;
Net_BEGIN
namespace Poco {
namespace Net {
class FTPStreamBuf: public UnbufferedStreamBuf
@@ -231,7 +232,7 @@ void FTPStreamFactory::getUserInfo(const URI& uri, std::string& username, std::s
}
void FTPStreamFactory::getPathAndType(const Foundation::URI& uri, std::string& path, char& type)
void FTPStreamFactory::getPathAndType(const Poco::URI& uri, std::string& path, char& type)
{
path = uri.getPath();
type = 'i';
@@ -253,4 +254,4 @@ void FTPStreamFactory::registerFactory()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// FilePartSource.cpp
//
// $Id: //poco/1.1.0/Net/src/FilePartSource.cpp#2 $
// $Id: //poco/1.2/Net/src/FilePartSource.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,16 +34,17 @@
//
#include "Net/FilePartSource.h"
#include "Foundation/Path.h"
#include "Foundation/Exception.h"
#include "Poco/Net/FilePartSource.h"
#include "Poco/Path.h"
#include "Poco/Exception.h"
using Foundation::Path;
using Foundation::OpenFileException;
using Poco::Path;
using Poco::OpenFileException;
Net_BEGIN
namespace Poco {
namespace Net {
FilePartSource::FilePartSource(const std::string& path):
@@ -84,4 +85,4 @@ const std::string& FilePartSource::filename()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTMLForm.cpp
//
// $Id: //poco/1.1.0/Net/src/HTMLForm.cpp#2 $
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#1 $
//
// Library: Net
// Package: HTML
@@ -34,30 +34,31 @@
//
#include "Net/HTMLForm.h"
#include "Net/HTTPRequest.h"
#include "Net/PartSource.h"
#include "Net/PartHandler.h"
#include "Net/MultipartWriter.h"
#include "Net/MultipartReader.h"
#include "Net/NullPartHandler.h"
#include "Foundation/NullStream.h"
#include "Foundation/StreamCopier.h"
#include "Foundation/Exception.h"
#include "Foundation/URI.h"
#include "Foundation/String.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/PartSource.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/MultipartWriter.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Net/NullPartHandler.h"
#include "Poco/NullStream.h"
#include "Poco/StreamCopier.h"
#include "Poco/Exception.h"
#include "Poco/URI.h"
#include "Poco/String.h"
#include <sstream>
#include <ctype.h>
using Foundation::NullInputStream;
using Foundation::StreamCopier;
using Foundation::SyntaxException;
using Foundation::URI;
using Foundation::icompare;
using Poco::NullInputStream;
using Poco::StreamCopier;
using Poco::SyntaxException;
using Poco::URI;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
const std::string HTMLForm::ENCODING_URL = "application/x-www-form-urlencoded";
@@ -76,15 +77,15 @@ HTMLForm::HTMLForm(const std::string& encoding):
}
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& istr, PartHandler& handler)
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler)
{
load(request, istr, handler);
load(request, requestBody, handler);
}
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& istr)
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody)
{
load(request, istr);
load(request, requestBody);
}
@@ -122,13 +123,7 @@ void HTMLForm::addPart(const std::string& name, PartSource* pSource)
void HTMLForm::load(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler)
{
if (request.getMethod() == HTTPRequest::HTTP_GET)
{
URI uri(request.getURI());
std::istringstream istr(uri.getRawQuery());
readUrl(istr);
}
else
if (request.getMethod() == HTTPRequest::HTTP_POST)
{
std::string mediaType;
NameValueCollection params;
@@ -144,6 +139,12 @@ void HTMLForm::load(const HTTPRequest& request, std::istream& requestBody, PartH
readUrl(requestBody);
}
}
else
{
URI uri(request.getURI());
std::istringstream istr(uri.getRawQuery());
readUrl(istr);
}
}
@@ -173,16 +174,7 @@ void HTMLForm::read(std::istream& istr, PartHandler& handler)
void HTMLForm::prepareSubmit(HTTPRequest& request)
{
if (request.getMethod() == HTTPRequest::HTTP_GET)
{
std::string uri = request.getURI();
std::ostringstream ostr;
write(ostr);
uri.append("?");
uri.append(ostr.str());
request.setURI(uri);
}
else if (request.getMethod() == HTTPRequest::HTTP_POST)
if (request.getMethod() == HTTPRequest::HTTP_POST)
{
if (_encoding == ENCODING_URL)
{
@@ -207,6 +199,15 @@ void HTMLForm::prepareSubmit(HTTPRequest& request)
request.setChunkedTransferEncoding(true);
}
}
else
{
std::string uri = request.getURI();
std::ostringstream ostr;
write(ostr);
uri.append("?");
uri.append(ostr.str());
request.setURI(uri);
}
}
@@ -284,7 +285,7 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
std::string cd = header.get("Content-Disposition");
MessageHeader::splitParameters(cd, disp, params);
}
if (icompare(disp, "file") == 0)
if (params.has("filename"))
{
handler.handlePart(header, reader.stream());
}
@@ -355,4 +356,4 @@ void HTMLForm::writeMultipart(std::ostream& ostr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPBasicCredentials.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPBasicCredentials.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPBasicCredentials.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,21 +34,22 @@
//
#include "Net/HTTPBasicCredentials.h"
#include "Net/HTTPRequest.h"
#include "Net/NetException.h"
#include "Foundation/Base64Encoder.h"
#include "Foundation/Base64Decoder.h"
#include "Foundation/String.h"
#include "Poco/Net/HTTPBasicCredentials.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/NetException.h"
#include "Poco/Base64Encoder.h"
#include "Poco/Base64Decoder.h"
#include "Poco/String.h"
#include <sstream>
using Foundation::Base64Decoder;
using Foundation::Base64Encoder;
using Foundation::icompare;
using Poco::Base64Decoder;
using Poco::Base64Encoder;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
const std::string HTTPBasicCredentials::SCHEME = "Basic";
@@ -121,4 +122,4 @@ void HTTPBasicCredentials::authenticate(HTTPRequest& request)
}
Net_END
} } // namespace Poco::Net

View File

@@ -34,13 +34,14 @@
//
#include "Net/HTTPBufferAllocator.h"
#include "Poco/Net/HTTPBufferAllocator.h"
using Foundation::MemoryPool;
using Poco::MemoryPool;
Net_BEGIN
namespace Poco {
namespace Net {
MemoryPool HTTPBufferAllocator::_pool(HTTPBufferAllocator::BUFFER_SIZE, 16);
@@ -62,4 +63,4 @@ void HTTPBufferAllocator::deallocate(char* ptr, std::streamsize size)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPChunkedStream.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPChunkedStream.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPChunkedStream.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,18 +34,19 @@
//
#include "Net/HTTPChunkedStream.h"
#include "Net/HTTPSession.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/NumberParser.h"
#include "Poco/Net/HTTPChunkedStream.h"
#include "Poco/Net/HTTPSession.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include <ctype.h>
using Foundation::NumberFormatter;
using Foundation::NumberParser;
using Poco::NumberFormatter;
using Poco::NumberParser;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -151,7 +152,7 @@ HTTPChunkedStreamBuf* HTTPChunkedIOS::rdbuf()
//
Foundation::MemoryPool HTTPChunkedInputStream::_pool(sizeof(HTTPChunkedInputStream));
Poco::MemoryPool HTTPChunkedInputStream::_pool(sizeof(HTTPChunkedInputStream));
HTTPChunkedInputStream::HTTPChunkedInputStream(HTTPSession& session):
@@ -183,7 +184,7 @@ void HTTPChunkedInputStream::operator delete(void* ptr)
//
Foundation::MemoryPool HTTPChunkedOutputStream::_pool(sizeof(HTTPChunkedOutputStream));
Poco::MemoryPool HTTPChunkedOutputStream::_pool(sizeof(HTTPChunkedOutputStream));
HTTPChunkedOutputStream::HTTPChunkedOutputStream(HTTPSession& session):
@@ -210,4 +211,4 @@ void HTTPChunkedOutputStream::operator delete(void* ptr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPClientSession.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPClientSession.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPClientSession.cpp#1 $
//
// Library: Net
// Package: HTTPClient
@@ -34,22 +34,23 @@
//
#include "Net/HTTPClientSession.h"
#include "Net/HTTPRequest.h"
#include "Net/HTTPResponse.h"
#include "Net/HTTPHeaderStream.h"
#include "Net/HTTPStream.h"
#include "Net/HTTPFixedLengthStream.h"
#include "Net/HTTPChunkedStream.h"
#include "Net/NetException.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPStream.h"
#include "Poco/Net/HTTPFixedLengthStream.h"
#include "Poco/Net/HTTPChunkedStream.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
using Foundation::NumberFormatter;
using Foundation::IllegalStateException;
using Poco::NumberFormatter;
using Poco::IllegalStateException;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPClientSession::HTTPClientSession():
@@ -75,7 +76,19 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket):
}
HTTPClientSession::HTTPClientSession(const std::string& host, Foundation::UInt16 port):
HTTPClientSession::HTTPClientSession(const SocketAddress& address):
_host(address.host().toString()),
_port(address.port()),
_proxyPort(HTTPSession::HTTP_PORT),
_reconnect(false),
_expectResponseBody(false),
_pRequestStream(0),
_pResponseStream(0)
{
}
HTTPClientSession::HTTPClientSession(const std::string& host, Poco::UInt16 port):
_host(host),
_port(port),
_proxyPort(HTTPSession::HTTP_PORT),
@@ -103,7 +116,7 @@ void HTTPClientSession::setHost(const std::string& host)
}
void HTTPClientSession::setPort(Foundation::UInt16 port)
void HTTPClientSession::setPort(Poco::UInt16 port)
{
if (!connected())
_port = port;
@@ -112,7 +125,7 @@ void HTTPClientSession::setPort(Foundation::UInt16 port)
}
void HTTPClientSession::setProxy(const std::string& host, Foundation::UInt16 port)
void HTTPClientSession::setProxy(const std::string& host, Poco::UInt16 port)
{
if (!connected())
{
@@ -132,7 +145,7 @@ void HTTPClientSession::setProxyHost(const std::string& host)
}
void HTTPClientSession::setProxyPort(Foundation::UInt16 port)
void HTTPClientSession::setProxyPort(Poco::UInt16 port)
{
if (!connected())
_proxyPort = port;
@@ -178,9 +191,24 @@ std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response)
delete _pRequestStream;
_pRequestStream = 0;
response.clear();
HTTPHeaderInputStream his(*this);
response.read(his);
do
{
response.clear();
HTTPHeaderInputStream his(*this);
try
{
response.read(his);
}
catch (MessageException&)
{
if (networkException())
networkException()->rethrow();
else
throw;
}
}
while (response.getStatus() == HTTPResponse::HTTP_CONTINUE);
if (!_expectResponseBody)
_pResponseStream = new HTTPFixedLengthInputStream(*this, 0);
else if (response.getChunkedTransferEncoding())
@@ -266,4 +294,4 @@ void HTTPClientSession::setRequestStream(std::ostream* pRequestStream)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPCookie.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPCookie.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPCookie.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,29 +34,30 @@
//
#include "Net/HTTPCookie.h"
#include "Net/NameValueCollection.h"
#include "Foundation/Timestamp.h"
#include "Foundation/DateTime.h"
#include "Foundation/DateTimeFormatter.h"
#include "Foundation/DateTimeFormat.h"
#include "Foundation/DateTimeParser.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/NumberParser.h"
#include "Foundation/String.h"
#include "Poco/Net/HTTPCookie.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Timestamp.h"
#include "Poco/DateTime.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeParser.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/String.h"
using Foundation::Timestamp;
using Foundation::DateTime;
using Foundation::DateTimeFormatter;
using Foundation::DateTimeFormat;
using Foundation::DateTimeParser;
using Foundation::NumberFormatter;
using Foundation::NumberParser;
using Foundation::icompare;
using Poco::Timestamp;
using Poco::DateTime;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
using Poco::DateTimeParser;
using Poco::NumberFormatter;
using Poco::NumberParser;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPCookie::HTTPCookie():
@@ -288,4 +289,4 @@ std::string HTTPCookie::toString() const
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPFixedLengthStream.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPFixedLengthStream.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPFixedLengthStream.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,14 +34,15 @@
//
#include "Net/HTTPFixedLengthStream.h"
#include "Net/HTTPSession.h"
#include "Poco/Net/HTTPFixedLengthStream.h"
#include "Poco/Net/HTTPSession.h"
using Foundation::BufferedStreamBuf;
using Poco::BufferedStreamBuf;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -126,7 +127,7 @@ HTTPFixedLengthStreamBuf* HTTPFixedLengthIOS::rdbuf()
//
Foundation::MemoryPool HTTPFixedLengthInputStream::_pool(sizeof(HTTPFixedLengthInputStream));
Poco::MemoryPool HTTPFixedLengthInputStream::_pool(sizeof(HTTPFixedLengthInputStream));
HTTPFixedLengthInputStream::HTTPFixedLengthInputStream(HTTPSession& session, std::streamsize length):
@@ -158,7 +159,7 @@ void HTTPFixedLengthInputStream::operator delete(void* ptr)
//
Foundation::MemoryPool HTTPFixedLengthOutputStream::_pool(sizeof(HTTPFixedLengthOutputStream));
Poco::MemoryPool HTTPFixedLengthOutputStream::_pool(sizeof(HTTPFixedLengthOutputStream));
HTTPFixedLengthOutputStream::HTTPFixedLengthOutputStream(HTTPSession& session, std::streamsize length):
@@ -185,4 +186,4 @@ void HTTPFixedLengthOutputStream::operator delete(void* ptr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPHeaderStream.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPHeaderStream.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPHeaderStream.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,11 +34,12 @@
//
#include "Net/HTTPHeaderStream.h"
#include "Net/HTTPSession.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPSession.h"
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -123,7 +124,7 @@ HTTPHeaderStreamBuf* HTTPHeaderIOS::rdbuf()
//
Foundation::MemoryPool HTTPHeaderInputStream::_pool(sizeof(HTTPHeaderInputStream));
Poco::MemoryPool HTTPHeaderInputStream::_pool(sizeof(HTTPHeaderInputStream));
HTTPHeaderInputStream::HTTPHeaderInputStream(HTTPSession& session):
@@ -155,7 +156,7 @@ void HTTPHeaderInputStream::operator delete(void* ptr)
//
Foundation::MemoryPool HTTPHeaderOutputStream::_pool(sizeof(HTTPHeaderOutputStream));
Poco::MemoryPool HTTPHeaderOutputStream::_pool(sizeof(HTTPHeaderOutputStream));
HTTPHeaderOutputStream::HTTPHeaderOutputStream(HTTPSession& session):
@@ -182,4 +183,4 @@ void HTTPHeaderOutputStream::operator delete(void* ptr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -34,14 +34,15 @@
//
#include "Net/HTTPIOStream.h"
#include "Net/HTTPClientSession.h"
#include "Poco/Net/HTTPIOStream.h"
#include "Poco/Net/HTTPClientSession.h"
using Foundation::UnbufferedStreamBuf;
using Poco::UnbufferedStreamBuf;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPResponseStreamBuf::HTTPResponseStreamBuf(std::istream& istr):
@@ -81,4 +82,4 @@ HTTPResponseStream::~HTTPResponseStream()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPMessage.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPMessage.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPMessage.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,19 +34,20 @@
//
#include "Net/HTTPMessage.h"
#include "Net/MediaType.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/NumberParser.h"
#include "Foundation/String.h"
#include "Poco/Net/HTTPMessage.h"
#include "Poco/Net/MediaType.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/String.h"
using Foundation::NumberFormatter;
using Foundation::NumberParser;
using Foundation::icompare;
using Poco::NumberFormatter;
using Poco::NumberParser;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
const std::string HTTPMessage::HTTP_1_0 = "HTTP/1.0";
@@ -179,4 +180,4 @@ bool HTTPMessage::getKeepAlive() const
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPRequest.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPRequest.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPRequest.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,18 +34,19 @@
//
#include "Net/HTTPRequest.h"
#include "Net/HTTPSession.h"
#include "Net/NetException.h"
#include "Net/NameValueCollection.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPSession.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/NumberFormatter.h"
#include <ctype.h>
using Foundation::NumberFormatter;
using Poco::NumberFormatter;
Net_BEGIN
namespace Poco {
namespace Net {
const std::string HTTPRequest::HTTP_GET = "GET";
@@ -114,7 +115,7 @@ void HTTPRequest::setHost(const std::string& host)
}
void HTTPRequest::setHost(const std::string& host, Foundation::UInt16 port)
void HTTPRequest::setHost(const std::string& host, Poco::UInt16 port)
{
std::string value(host);
if (port != HTTPSession::HTTP_PORT)
@@ -208,6 +209,7 @@ void HTTPRequest::read(std::istream& istr)
std::string version;
int ch = istr.get();
while (isspace(ch)) ch = istr.get();
if (ch == eof) throw MessageException("No HTTP request header");
while (!isspace(ch) && ch != eof && method.length() < MAX_METHOD_LENGTH) { method += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("HTTP request method too long");
while (isspace(ch)) ch = istr.get();
@@ -226,4 +228,4 @@ void HTTPRequest::read(std::istream& istr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPRequestHandler.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPRequestHandler.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPRequestHandler.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,10 +34,11 @@
//
#include "Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandler.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPRequestHandler::HTTPRequestHandler()
@@ -50,4 +51,4 @@ HTTPRequestHandler::~HTTPRequestHandler()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPRequestHandlerFactory.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPRequestHandlerFactory.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPRequestHandlerFactory.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,10 +34,11 @@
//
#include "Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPRequestHandlerFactory::HTTPRequestHandlerFactory()
@@ -50,4 +51,4 @@ HTTPRequestHandlerFactory::~HTTPRequestHandlerFactory()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPResponse.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPResponse.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPResponse.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,26 +34,27 @@
//
#include "Net/HTTPResponse.h"
#include "Net/NetException.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/NumberParser.h"
#include "Foundation/DateTime.h"
#include "Foundation/DateTimeFormatter.h"
#include "Foundation/DateTimeFormat.h"
#include "Foundation/DateTimeParser.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/DateTime.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeParser.h"
#include <ctype.h>
using Foundation::DateTime;
using Foundation::NumberFormatter;
using Foundation::NumberParser;
using Foundation::DateTimeFormatter;
using Foundation::DateTimeFormat;
using Foundation::DateTimeParser;
using Poco::DateTime;
using Poco::NumberFormatter;
using Poco::NumberParser;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
using Poco::DateTimeParser;
Net_BEGIN
namespace Poco {
namespace Net {
const std::string HTTPResponse::HTTP_REASON_CONTINUE = "Continue";
@@ -175,13 +176,13 @@ void HTTPResponse::setStatusAndReason(HTTPStatus status)
}
void HTTPResponse::setDate(const Foundation::Timestamp& dateTime)
void HTTPResponse::setDate(const Poco::Timestamp& dateTime)
{
set(DATE, DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
}
Foundation::Timestamp HTTPResponse::getDate() const
Poco::Timestamp HTTPResponse::getDate() const
{
const std::string& dateTime = get(DATE);
int tzd;
@@ -224,25 +225,20 @@ void HTTPResponse::read(std::istream& istr)
std::string version;
std::string status;
std::string reason;
int ch = 0;
do
{
version.clear();
status.clear();
reason.clear();
ch = istr.get();
while (isspace(ch)) ch = istr.get();
while (!isspace(ch) && ch != eof && version.length() < MAX_VERSION_LENGTH) { version += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("Invalid HTTP version string");
while (isspace(ch)) ch = istr.get();
while (!isspace(ch) && ch != eof && status.length() < MAX_STATUS_LENGTH) { status += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("Invalid HTTP status code");
while (isspace(ch)) ch = istr.get();
while (ch != '\r' && ch != '\n' && ch != eof && reason.length() < MAX_REASON_LENGTH) { reason += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("HTTP reason string too long");
if (ch == '\r') ch = istr.get();
}
while (ch != eof && status == "100");
int ch = istr.get();
while (isspace(ch)) ch = istr.get();
if (ch == eof) throw MessageException("No HTTP response header");
while (!isspace(ch) && ch != eof && version.length() < MAX_VERSION_LENGTH) { version += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("Invalid HTTP version string");
while (isspace(ch)) ch = istr.get();
while (!isspace(ch) && ch != eof && status.length() < MAX_STATUS_LENGTH) { status += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("Invalid HTTP status code");
while (isspace(ch)) ch = istr.get();
while (ch != '\r' && ch != '\n' && ch != eof && reason.length() < MAX_REASON_LENGTH) { reason += (char) ch; ch = istr.get(); }
if (!isspace(ch)) throw MessageException("HTTP reason string too long");
if (ch == '\r') ch = istr.get();
HTTPMessage::read(istr);
ch = istr.get();
while (ch != '\n' && ch != eof) { ch = istr.get(); }
@@ -342,4 +338,4 @@ const std::string& HTTPResponse::getReasonForStatus(HTTPStatus status)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServer.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServer.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServer.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,12 +34,13 @@
//
#include "Net/HTTPServer.h"
#include "Net/HTTPServerParams.h"
#include "Net/HTTPServerConnectionFactory.h"
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerConnectionFactory.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket& socket, HTTPServerParams* pParams):
@@ -48,7 +49,7 @@ HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket&
}
HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, Foundation::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams):
HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams):
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), threadPool, socket, pParams)
{
}
@@ -59,4 +60,4 @@ HTTPServer::~HTTPServer()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerConnection.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerConnection.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerConnection.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,19 +34,20 @@
//
#include "Net/HTTPServerConnection.h"
#include "Net/HTTPServerSession.h"
#include "Net/HTTPServerRequest.h"
#include "Net/HTTPServerResponse.h"
#include "Net/HTTPRequestHandler.h"
#include "Net/HTTPRequestHandlerFactory.h"
#include "Net/HTTPServerParams.h"
#include "Net/NetException.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/HTTPServerConnection.h"
#include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include <memory>
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerConnection::HTTPServerConnection(const StreamSocket& socket, HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory):
@@ -99,4 +100,4 @@ void HTTPServerConnection::run()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerConnectionFactory.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerConnectionFactory.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerConnectionFactory.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,13 +34,14 @@
//
#include "Net/HTTPServerConnectionFactory.h"
#include "Net/HTTPServerConnection.h"
#include "Net/HTTPServerParams.h"
#include "Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerConnectionFactory.h"
#include "Poco/Net/HTTPServerConnection.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerConnectionFactory::HTTPServerConnectionFactory(HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory):
@@ -67,4 +68,4 @@ TCPServerConnection* HTTPServerConnectionFactory::createConnection(const StreamS
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerParams.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerParams.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerParams.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,10 +34,11 @@
//
#include "Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerParams.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerParams::HTTPServerParams():
@@ -66,7 +67,7 @@ void HTTPServerParams::setSoftwareVersion(const std::string& softwareVersion)
}
void HTTPServerParams::setTimeout(const Foundation::Timespan& timeout)
void HTTPServerParams::setTimeout(const Poco::Timespan& timeout)
{
_timeout = timeout;
}
@@ -78,7 +79,7 @@ void HTTPServerParams::setKeepAlive(bool keepAlive)
}
void HTTPServerParams::setKeepAliveTimeout(const Foundation::Timespan& timeout)
void HTTPServerParams::setKeepAliveTimeout(const Poco::Timespan& timeout)
{
_keepAliveTimeout = timeout;
}
@@ -91,4 +92,4 @@ void HTTPServerParams::setMaxKeepAliveRequests(int maxKeepAliveRequests)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerRequest.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerRequest.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerRequest.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,20 +34,21 @@
//
#include "Net/HTTPServerRequest.h"
#include "Net/HTTPServerSession.h"
#include "Net/HTTPHeaderStream.h"
#include "Net/HTTPStream.h"
#include "Net/HTTPFixedLengthStream.h"
#include "Net/HTTPChunkedStream.h"
#include "Net/HTTPServerParams.h"
#include "Foundation/String.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPStream.h"
#include "Poco/Net/HTTPFixedLengthStream.h"
#include "Poco/Net/HTTPChunkedStream.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/String.h"
using Foundation::icompare;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerRequest::HTTPServerRequest(HTTPServerSession& session, HTTPServerParams* pParams):
@@ -87,4 +88,4 @@ bool HTTPServerRequest::expectContinue() const
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerResponse.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerResponse.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerResponse.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,28 +34,29 @@
//
#include "Net/HTTPServerResponse.h"
#include "Net/HTTPServerSession.h"
#include "Net/HTTPHeaderStream.h"
#include "Net/HTTPStream.h"
#include "Net/HTTPFixedLengthStream.h"
#include "Net/HTTPChunkedStream.h"
#include "Foundation/File.h"
#include "Foundation/Timestamp.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/StreamCopier.h"
#include "Foundation/Exception.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPStream.h"
#include "Poco/Net/HTTPFixedLengthStream.h"
#include "Poco/Net/HTTPChunkedStream.h"
#include "Poco/File.h"
#include "Poco/Timestamp.h"
#include "Poco/NumberFormatter.h"
#include "Poco/StreamCopier.h"
#include "Poco/Exception.h"
#include <fstream>
using Foundation::File;
using Foundation::Timestamp;
using Foundation::NumberFormatter;
using Foundation::StreamCopier;
using Foundation::OpenFileException;
using Poco::File;
using Poco::Timestamp;
using Poco::NumberFormatter;
using Poco::StreamCopier;
using Poco::OpenFileException;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerResponse::HTTPServerResponse(HTTPServerSession& session):
@@ -74,7 +75,7 @@ HTTPServerResponse::~HTTPServerResponse()
void HTTPServerResponse::sendContinue()
{
HTTPHeaderOutputStream hs(_session);
hs << getVersion() << " 100 Continue\r\n";
hs << getVersion() << " 100 Continue\r\n\r\n";
}
@@ -147,4 +148,4 @@ void HTTPServerResponse::requireAuthentication(const std::string& realm)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPServerSession.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPServerSession.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPServerSession.cpp#1 $
//
// Library: Net
// Package: HTTPServer
@@ -34,11 +34,12 @@
//
#include "Net/HTTPServerSession.h"
#include "Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPServerParams.h"
Net_BEGIN
namespace Poco {
namespace Net {
HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams):
@@ -84,4 +85,4 @@ SocketAddress HTTPServerSession::serverAddress()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPSession.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPSession.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPSession.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,16 +34,17 @@
//
#include "Net/HTTPSession.h"
#include "Net/HTTPBufferAllocator.h"
#include "Net/NetException.h"
#include "Poco/Net/HTTPSession.h"
#include "Poco/Net/HTTPBufferAllocator.h"
#include "Poco/Net/NetException.h"
#include <string.h>
using Foundation::TimeoutException;
using Poco::TimeoutException;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPSession::HTTPSession():
@@ -51,7 +52,8 @@ HTTPSession::HTTPSession():
_pCurrent(0),
_pEnd(0),
_keepAlive(false),
_timeout(HTTP_DEFAULT_TIMEOUT)
_timeout(HTTP_DEFAULT_TIMEOUT),
_pException(0)
{
}
@@ -62,7 +64,8 @@ HTTPSession::HTTPSession(const StreamSocket& socket):
_pCurrent(0),
_pEnd(0),
_keepAlive(false),
_timeout(HTTP_DEFAULT_TIMEOUT)
_timeout(HTTP_DEFAULT_TIMEOUT),
_pException(0)
{
}
@@ -73,7 +76,8 @@ HTTPSession::HTTPSession(const StreamSocket& socket, bool keepAlive):
_pCurrent(0),
_pEnd(0),
_keepAlive(keepAlive),
_timeout(HTTP_DEFAULT_TIMEOUT)
_timeout(HTTP_DEFAULT_TIMEOUT),
_pException(0)
{
}
@@ -82,6 +86,7 @@ HTTPSession::~HTTPSession()
{
if (_pBuffer) HTTPBufferAllocator::deallocate(_pBuffer, HTTPBufferAllocator::BUFFER_SIZE);
close();
delete _pException;
}
@@ -91,7 +96,7 @@ void HTTPSession::setKeepAlive(bool keepAlive)
}
void HTTPSession::setTimeout(const Foundation::Timespan& timeout)
void HTTPSession::setTimeout(const Poco::Timespan& timeout)
{
_timeout = timeout;
}
@@ -137,16 +142,32 @@ int HTTPSession::read(char* buffer, std::streamsize length)
int HTTPSession::write(const char* buffer, std::streamsize length)
{
return _socket.sendBytes(buffer, (int) length);
try
{
return _socket.sendBytes(buffer, (int) length);
}
catch (Poco::Exception& exc)
{
setException(exc);
throw;
}
}
int HTTPSession::receive(char* buffer, int length)
{
if (_socket.poll(_timeout, Socket::SELECT_READ))
return _socket.receiveBytes(buffer, length);
else
throw TimeoutException();
try
{
if (_socket.poll(_timeout, Socket::SELECT_READ))
return _socket.receiveBytes(buffer, length);
else
throw TimeoutException();
}
catch (Poco::Exception& exc)
{
setException(exc);
throw;
}
}
@@ -187,4 +208,11 @@ void HTTPSession::close()
}
Net_END
void HTTPSession::setException(const Poco::Exception& exc)
{
delete _pException;
_pException = exc.clone();
}
} } // namespace Poco::Net

View File

@@ -0,0 +1,153 @@
//
// HTTPSessionFactory.cpp
//
// $Id: //poco/1.2/Net/src/HTTPSessionFactory.cpp#1 $
//
// Library: Net
// Package: HTTPClient
// Module: HTTPSessionFactory
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/HTTPSessionFactory.h"
#include "Poco/Net/HTTPSessionInstantiator.h"
#include "Poco/Exception.h"
using Poco::SingletonHolder;
using Poco::FastMutex;
using Poco::NotFoundException;
using Poco::ExistsException;
namespace Poco {
namespace Net {
HTTPSessionFactory::HTTPSessionFactory():
_proxyPort(0)
{
}
HTTPSessionFactory::HTTPSessionFactory(const std::string& proxyHost, Poco::UInt16 proxyPort):
_proxyHost(proxyHost),
_proxyPort(proxyPort)
{
}
HTTPSessionFactory::~HTTPSessionFactory()
{
for (Instantiators::iterator it = _instantiators.begin(); it != _instantiators.end(); ++it)
{
delete it->second.pIn;
}
}
void HTTPSessionFactory::registerProtocol(const std::string& protocol, HTTPSessionInstantiator* pSessionInstantiator)
{
poco_assert_dbg(pSessionInstantiator);
FastMutex::ScopedLock lock(_mutex);
std::pair<Instantiators::iterator, bool> tmp = _instantiators.insert(make_pair(protocol, InstantiatorInfo(pSessionInstantiator)));
if (!tmp.second)
{
++tmp.first->second.cnt;
delete pSessionInstantiator;
}
}
void HTTPSessionFactory::unregisterProtocol(const std::string& protocol)
{
FastMutex::ScopedLock lock(_mutex);
Instantiators::iterator it = _instantiators.find(protocol);
if (it != _instantiators.end())
{
if (it->second.cnt == 1)
{
delete it->second.pIn;
_instantiators.erase(it);
}
else --it->second.cnt;
}
else throw NotFoundException("No HTTPSessionInstantiator registered for", protocol);
}
bool HTTPSessionFactory::supportsProtocol(const std::string& protocol)
{
FastMutex::ScopedLock lock(_mutex);
Instantiators::iterator it = _instantiators.find(protocol);
return it != _instantiators.end();
}
HTTPClientSession* HTTPSessionFactory::createClientSession(const Poco::URI& uri)
{
FastMutex::ScopedLock lock(_mutex);
if (uri.isRelative()) throw Poco::UnknownURISchemeException("Relative URIs are not supported by HTTPSessionFactory.");
Instantiators::iterator it = _instantiators.find(uri.getScheme());
if (it != _instantiators.end())
{
it->second.pIn->setProxy(_proxyHost, _proxyPort);
return it->second.pIn->createClientSession(uri);
}
else throw Poco::UnknownURISchemeException(uri.getScheme());
}
void HTTPSessionFactory::setProxy(const std::string& host, Poco::UInt16 port)
{
FastMutex::ScopedLock lock(_mutex);
_proxyHost = host;
_proxyPort = port;
}
HTTPSessionFactory& HTTPSessionFactory::defaultFactory()
{
static SingletonHolder<HTTPSessionFactory> singleton;
return *singleton.get();
}
HTTPSessionFactory::InstantiatorInfo::InstantiatorInfo(HTTPSessionInstantiator* pInst): pIn(pInst), cnt(1)
{
poco_check_ptr (pIn);
}
} } // namespace Poco::Net

View File

@@ -0,0 +1,88 @@
//
// HTTPSessionInstantiator.cpp
//
// $Id: //poco/1.2/Net/src/HTTPSessionInstantiator.cpp#1 $
//
// Library: Net
// Package: HTTPClient
// Module: HTTPSessionInstantiator
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/HTTPSessionInstantiator.h"
#include "Poco/Net/HTTPSessionFactory.h"
#include "Poco/Net/HTTPClientSession.h"
using Poco::URI;
namespace Poco {
namespace Net {
HTTPSessionInstantiator::HTTPSessionInstantiator():
_proxyPort(0)
{
}
HTTPSessionInstantiator::~HTTPSessionInstantiator()
{
}
HTTPClientSession* HTTPSessionInstantiator::createClientSession(const Poco::URI& uri)
{
poco_assert (uri.getScheme() == "http");
HTTPClientSession* pSession = new HTTPClientSession(uri.getHost(), uri.getPort());
pSession->setProxy(proxyHost(), proxyPort());
return pSession;
}
void HTTPSessionInstantiator::registerInstantiator()
{
HTTPSessionFactory::defaultFactory().registerProtocol("http", new HTTPSessionInstantiator);
}
void HTTPSessionInstantiator::unregisterInstantiator()
{
HTTPSessionFactory::defaultFactory().unregisterProtocol("http");
}
void HTTPSessionInstantiator::setProxy(const std::string& host, Poco::UInt16 port)
{
_proxyHost = host;
_proxyPort = port;
}
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPStream.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPStream.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPStream.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,11 +34,12 @@
//
#include "Net/HTTPStream.h"
#include "Net/HTTPSession.h"
#include "Poco/Net/HTTPStream.h"
#include "Poco/Net/HTTPSession.h"
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -117,7 +118,7 @@ HTTPStreamBuf* HTTPIOS::rdbuf()
//
Foundation::MemoryPool HTTPInputStream::_pool(sizeof(HTTPInputStream));
Poco::MemoryPool HTTPInputStream::_pool(sizeof(HTTPInputStream));
HTTPInputStream::HTTPInputStream(HTTPSession& session):
@@ -149,7 +150,7 @@ void HTTPInputStream::operator delete(void* ptr)
//
Foundation::MemoryPool HTTPOutputStream::_pool(sizeof(HTTPOutputStream));
Poco::MemoryPool HTTPOutputStream::_pool(sizeof(HTTPOutputStream));
HTTPOutputStream::HTTPOutputStream(HTTPSession& session):
@@ -176,4 +177,4 @@ void HTTPOutputStream::operator delete(void* ptr)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HTTPStreamFactory.cpp
//
// $Id: //poco/1.1.0/Net/src/HTTPStreamFactory.cpp#2 $
// $Id: //poco/1.2/Net/src/HTTPStreamFactory.cpp#1 $
//
// Library: Net
// Package: HTTP
@@ -34,24 +34,25 @@
//
#include "Net/HTTPStreamFactory.h"
#include "Net/HTTPClientSession.h"
#include "Net/HTTPIOStream.h"
#include "Net/HTTPRequest.h"
#include "Net/HTTPResponse.h"
#include "Net/NetException.h"
#include "Foundation/URI.h"
#include "Foundation/URIStreamOpener.h"
#include "Foundation/UnbufferedStreamBuf.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPIOStream.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/NetException.h"
#include "Poco/URI.h"
#include "Poco/URIStreamOpener.h"
#include "Poco/UnbufferedStreamBuf.h"
using Foundation::URIStreamFactory;
using Foundation::URI;
using Foundation::URIStreamOpener;
using Foundation::UnbufferedStreamBuf;
using Poco::URIStreamFactory;
using Poco::URI;
using Poco::URIStreamOpener;
using Poco::UnbufferedStreamBuf;
Net_BEGIN
namespace Poco {
namespace Net {
HTTPStreamFactory::HTTPStreamFactory():
@@ -60,7 +61,7 @@ HTTPStreamFactory::HTTPStreamFactory():
}
HTTPStreamFactory::HTTPStreamFactory(const std::string& proxyHost, Foundation::UInt16 proxyPort):
HTTPStreamFactory::HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort):
_proxyHost(proxyHost),
_proxyPort(proxyPort)
{
@@ -98,6 +99,7 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
{
resolvedURI.resolve(res.get("Location"));
delete pSession;
if (resolvedURI.getScheme() != "http") throw UnsupportedRedirectException(uri.toString());
++redirects;
}
else if (res.getStatus() == HTTPResponse::HTTP_OK)
@@ -123,4 +125,4 @@ void HTTPStreamFactory::registerFactory()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// HostEntry.cpp
//
// $Id: //poco/1.1.0/Net/src/HostEntry.cpp#2 $
// $Id: //poco/1.2/Net/src/HostEntry.cpp#1 $
//
// Library: Net
// Package: NetCore
@@ -34,12 +34,13 @@
//
#include "Net/HostEntry.h"
#include "Foundation/Exception.h"
#include "Poco/Net/HostEntry.h"
#include "Poco/Exception.h"
#include <algorithm>
Net_BEGIN
namespace Poco {
namespace Net {
HostEntry::HostEntry()
@@ -126,4 +127,4 @@ HostEntry::~HostEntry()
}
Net_END
} } // namespace Poco::Net

166
Net/src/ICMPClient.cpp Normal file
View File

@@ -0,0 +1,166 @@
//
// ICMPClient.cpp
//
// $Id: //poco/1.2/Net/src/ICMPClient.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPClient
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/ICMPClient.h"
#include "Poco/Net/ICMPSocket.h"
#include "Poco/Net/NetException.h"
#include "Poco/Channel.h"
#include "Poco/Message.h"
#include "Poco/Exception.h"
#include <sstream>
using Poco::Channel;
using Poco::Message;
using Poco::InvalidArgumentException;
using Poco::NotImplementedException;
using Poco::TimeoutException;
using Poco::Exception;
namespace Poco {
namespace Net {
ICMPClient::ICMPClient(IPAddress::Family family):
_family(family)
{
}
ICMPClient::~ICMPClient()
{
}
int ICMPClient::ping(const std::string& address, int repeat) const
{
if (repeat <= 0) return 0;
SocketAddress addr(address, 0);
return ping(addr, repeat);
}
int ICMPClient::ping(SocketAddress& address, int repeat) const
{
if (repeat <= 0) return 0;
ICMPSocket icmpSocket(_family);
SocketAddress returnAddress;
ICMPEventArgs eventArgs(address, repeat, icmpSocket.dataSize(), icmpSocket.ttl());
pingBegin.notify(this, eventArgs);
for (int i = 0; i < repeat; ++i)
{
icmpSocket.sendTo(address);
++eventArgs;
try
{
int t = icmpSocket.receiveFrom(returnAddress);
eventArgs.setReplyTime(i, t);
pingReply.notify(this, eventArgs);
}
catch (TimeoutException&)
{
std::ostringstream os;
os << address.host().toString() << ": Request timed out.";
eventArgs.setError(i, os.str());
pingError.notify(this, eventArgs);
continue;
}
catch (ICMPException& ex)
{
std::ostringstream os;
os << address.host().toString() << ": " << ex.what();
eventArgs.setError(i, os.str());
pingError.notify(this, eventArgs);
continue;
}
catch (Exception& ex)
{
std::ostringstream os;
os << ex.displayText();
eventArgs.setError(i, os.str());
pingError.notify(this, eventArgs);
continue;
}
}
pingEnd.notify(this, eventArgs);
return eventArgs.received();
}
int ICMPClient::pingIPv4(const std::string& address, int repeat)
{
if (repeat <= 0) return 0;
SocketAddress a(address, 0);
return ping(a, IPAddress::IPv4, repeat);
}
int ICMPClient::ping(SocketAddress& address, IPAddress::Family family, int repeat)
{
if (repeat <= 0) return 0;
ICMPSocket icmpSocket(family);
SocketAddress returnAddress;
int received = 0;
for (int i = 0; i < repeat; ++i)
{
icmpSocket.sendTo(address);
try
{
icmpSocket.receiveFrom(returnAddress);
++received;
}
catch (TimeoutException&)
{
}
catch (ICMPException&)
{
}
}
return received;
}
} } // namespace Poco::Net

195
Net/src/ICMPEventArgs.cpp Normal file
View File

@@ -0,0 +1,195 @@
//
// ICMPEventArgs.cpp
//
// $Id: //poco/1.2/Net/src/ICMPEventArgs.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPEventArgs
//
// Implementation of ICMPEventArgs
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPEventArgs.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/DNS.h"
#include "Poco/Exception.h"
#include "Poco/Net/NetException.h"
using Poco::IOException;
using Poco::InvalidArgumentException;
namespace Poco {
namespace Net {
ICMPEventArgs::ICMPEventArgs(const SocketAddress& address, int repetitions, int dataSize, int ttl):
_address(address),
_sent(0),
_dataSize(dataSize),
_ttl(ttl),
_rtt(0, repetitions),
_errors(repetitions)
{
}
ICMPEventArgs::~ICMPEventArgs()
{
}
std::string ICMPEventArgs::hostName() const
{
try
{
return DNS::resolve(_address.host().toString()).name();
}
catch (HostNotFoundException&)
{
}
catch (NoAddressFoundException&)
{
}
catch (DNSException&)
{
}
catch (IOException&)
{
}
return _address.host().toString();
}
std::string ICMPEventArgs::hostAddress() const
{
return _address.host().toString();
}
void ICMPEventArgs::setRepetitions(int repetitions)
{
_rtt.apply(&ICMPEventArgs::zeroVal);
if (_rtt.size() != repetitions) _rtt.resize(repetitions, 0);
_errors.assign(repetitions, "");
}
ICMPEventArgs& ICMPEventArgs::operator ++ ()
{
++_sent;
return *this;
}
ICMPEventArgs ICMPEventArgs::operator ++ (int)
{
ICMPEventArgs prev(*this);
operator ++ ();
return prev;
}
int ICMPEventArgs::received() const
{
int received = 0;
for (int i = 0; i < _rtt.size(); ++i)
{
if (_rtt[i]) ++received;
}
return received;
}
void ICMPEventArgs::setError(int index, const std::string& text)
{
if (index >= _errors.size())
throw InvalidArgumentException("Supplied index exceeds vector capacity.");
_errors[index] = text;
}
const std::string& ICMPEventArgs::error(int index) const
{
if (0 == _errors.size())
throw InvalidArgumentException("Supplied index exceeds vector capacity.");
if (-1 == index) index = _sent - 1;
return _errors[index];
}
void ICMPEventArgs::setReplyTime(int index, int time)
{
if (index >= _rtt.size())
throw InvalidArgumentException("Supplied index exceeds array capacity.");
if (0 == time) time = 1;
_rtt[index] = time;
}
int ICMPEventArgs::replyTime(int index) const
{
if (0 == _rtt.size())
throw InvalidArgumentException("Supplied index exceeds array capacity.");
if (-1 == index) index = _sent - 1;
return _rtt[index];
}
int ICMPEventArgs::avgRTT() const
{
if (0 == _rtt.size()) return 0;
return (int) (_rtt.sum() / _rtt.size());
}
float ICMPEventArgs::percent() const
{
if (0 == _rtt.size()) return 0;
return ((float) received() / (float) _rtt.size()) * (float) 100.0;
}
int ICMPEventArgs::zeroVal(int n)
{
return n*0;
}
} } // namespace Poco::Net

134
Net/src/ICMPPacket.cpp Normal file
View File

@@ -0,0 +1,134 @@
//
// ICMPPacket.cpp
//
// $Id: //poco/1.2/Net/src/ICMPPacket.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPPacket
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPPacket.h"
#include "Poco/Net/ICMPv4PacketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Timestamp.h"
#include "Poco/Timespan.h"
#include "Poco/Process.h"
#include "Poco/NumberFormatter.h"
#include <sstream>
using Poco::InvalidArgumentException;
using Poco::NotImplementedException;
using Poco::Timestamp;
using Poco::Timespan;
using Poco::Process;
using Poco::NumberFormatter;
using Poco::UInt8;
using Poco::UInt16;
using Poco::Int32;
namespace Poco {
namespace Net {
ICMPPacket::ICMPPacket(IPAddress::Family family, int dataSize):_pImpl(0)
{
if (family == IPAddress::IPv4)
_pImpl = new ICMPv4PacketImpl(dataSize);
#if POCO_HAVE_IPv6
else if (family == IPAddress::IPv6)
throw NotImplementedException("ICMPv6 packets not implemented.");
#endif
else throw InvalidArgumentException("Invalid or unsupported address family passed to ICMPPacket");
}
ICMPPacket::~ICMPPacket()
{
delete _pImpl;
}
void ICMPPacket::setDataSize(int dataSize)
{
_pImpl->setDataSize(dataSize);
}
int ICMPPacket::getDataSize() const
{
return _pImpl->getDataSize();
}
int ICMPPacket::packetSize() const
{
return _pImpl->packetSize();
}
int ICMPPacket::maxPacketSize() const
{
return _pImpl->maxPacketSize();
}
const Poco::UInt8* ICMPPacket::packet()
{
return _pImpl->packet();
}
struct timeval ICMPPacket::time(Poco::UInt8* buffer, int length) const
{
return _pImpl->time(buffer, length);
}
bool ICMPPacket::validReplyID(Poco::UInt8* buffer, int length) const
{
return _pImpl->validReplyID(buffer, length);
}
std::string ICMPPacket::errorDescription(Poco::UInt8* buffer, int length)
{
return _pImpl->errorDescription(buffer, length);
}
std::string ICMPPacket::typeDescription(int typeId)
{
return _pImpl->typeDescription(typeId);
}
} } // namespace Poco::Net

127
Net/src/ICMPPacketImpl.cpp Normal file
View File

@@ -0,0 +1,127 @@
//
// ICMPPacketImpl.cpp
//
// $Id: //poco/1.2/Net/src/ICMPPacketImpl.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPPacketImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPPacketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Timestamp.h"
#include "Poco/Timespan.h"
#include "Poco/Process.h"
#include "Poco/NumberFormatter.h"
#include <sstream>
using Poco::InvalidArgumentException;
using Poco::Timestamp;
using Poco::Timespan;
using Poco::Process;
using Poco::NumberFormatter;
using Poco::UInt8;
using Poco::UInt16;
using Poco::Int32;
namespace Poco {
namespace Net {
const UInt16 ICMPPacketImpl::MAX_PACKET_SIZE = 4096;
const UInt16 ICMPPacketImpl::MAX_SEQ_VALUE = 65535;
ICMPPacketImpl::ICMPPacketImpl(int dataSize):
_seq(0),
_pPacket(new UInt8[MAX_PACKET_SIZE]),
_dataSize(dataSize)
{
if (_dataSize > MAX_PACKET_SIZE)
throw InvalidArgumentException("Packet size must be <= " + NumberFormatter::format(MAX_PACKET_SIZE));
}
ICMPPacketImpl::~ICMPPacketImpl()
{
delete _pPacket;
}
void ICMPPacketImpl::setDataSize(int dataSize)
{
_dataSize = dataSize;
initPacket();
}
int ICMPPacketImpl::getDataSize() const
{
return _dataSize;
}
const Poco::UInt8* ICMPPacketImpl::packet(bool init)
{
if (init) initPacket();
return _pPacket;
}
unsigned short ICMPPacketImpl::checksum(UInt16 *addr, Int32 len)
{
Int32 nleft = len;
UInt16* w = addr;
UInt16 answer;
Int32 sum = 0;
while (nleft > 1)
{
sum += *w++;
nleft -= sizeof(UInt16);
}
if (nleft == 1)
{
UInt16 u = 0;
*(UInt8*) (&u) = *(UInt8*) w;
sum += u;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return answer;
}
} } // namespace Poco::Net

101
Net/src/ICMPSocket.cpp Normal file
View File

@@ -0,0 +1,101 @@
//
// ICMPSocket.cpp
//
// $Id: //poco/1.2/Net/src/ICMPSocket.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPSocket
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPSocket.h"
#include "Poco/Net/ICMPSocketImpl.h"
#include "Poco/Exception.h"
using Poco::InvalidArgumentException;
namespace Poco {
namespace Net {
ICMPSocket::ICMPSocket(IPAddress::Family family, int dataSize, int ttl, int timeout):
Socket(new ICMPSocketImpl(family, dataSize, ttl, timeout)),
_dataSize(dataSize),
_ttl(ttl),
_timeout(timeout)
{
}
ICMPSocket::ICMPSocket(const Socket& socket):
Socket(socket)
{
if (!dynamic_cast<ICMPSocketImpl*>(impl()))
throw InvalidArgumentException("Cannot assign incompatible socket");
}
ICMPSocket::ICMPSocket(SocketImpl* pImpl):
Socket(pImpl)
{
if (!dynamic_cast<ICMPSocketImpl*>(impl()))
throw InvalidArgumentException("Cannot assign incompatible socket");
}
ICMPSocket::~ICMPSocket()
{
}
ICMPSocket& ICMPSocket::operator = (const Socket& socket)
{
if (dynamic_cast<ICMPSocketImpl*>(socket.impl()))
Socket::operator = (socket);
else
throw InvalidArgumentException("Cannot assign incompatible socket");
return *this;
}
int ICMPSocket::sendTo(const SocketAddress& address, int flags)
{
return impl()->sendTo(0, 0, address, flags);
}
int ICMPSocket::receiveFrom(SocketAddress& address, int flags)
{
return impl()->receiveFrom(0, 0, address, flags);
}
} } // namespace Poco::Net

111
Net/src/ICMPSocketImpl.cpp Normal file
View File

@@ -0,0 +1,111 @@
//
// ICMPSocketImpl.cpp
//
// $Id: //poco/1.2/Net/src/ICMPSocketImpl.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPSocketImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPSocketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Timespan.h"
#include "Poco/Exception.h"
using Poco::TimeoutException;
using Poco::Timespan;
using Poco::Exception;
namespace Poco {
namespace Net {
ICMPSocketImpl::ICMPSocketImpl(IPAddress::Family family, int dataSize, int ttl, int timeout):
RawSocketImpl(family, IPPROTO_ICMP),
_icmpPacket(family, dataSize)
{
setOption(IPPROTO_IP, IP_TTL, ttl);
setReceiveTimeout(Timespan(timeout));
}
ICMPSocketImpl::~ICMPSocketImpl()
{
}
int ICMPSocketImpl::sendTo(const void*, int, const SocketAddress& address, int flags)
{
int n = SocketImpl::sendTo(_icmpPacket.packet(), _icmpPacket.packetSize(), address, flags);
return n;
}
int ICMPSocketImpl::receiveFrom(void*, int, SocketAddress& address, int flags)
{
int maxPacketSize = _icmpPacket.maxPacketSize();
unsigned char* buffer = new unsigned char[maxPacketSize];
try
{
do
{
SocketImpl::receiveFrom(buffer, maxPacketSize, address, flags);
}
while(!_icmpPacket.validReplyID(buffer, maxPacketSize));
}
catch (TimeoutException&)
{
delete[] buffer;
throw;
}
catch (Exception&)
{
std::string err = _icmpPacket.errorDescription(buffer, maxPacketSize);
delete[] buffer;
if (!err.empty())
throw ICMPException(err);
else
throw;
}
struct timeval then = _icmpPacket.time(buffer, maxPacketSize);
struct timeval now = _icmpPacket.time();
int elapsed = (((now.tv_sec * 1000000) + now.tv_usec) - ((then.tv_sec * 1000000) + then.tv_usec))/1000;
delete[] buffer;
return elapsed;
}
} } // namespace Poco::Net

View File

@@ -0,0 +1,275 @@
//
// ICMPv4PacketImpl.cpp
//
// $Id: //poco/1.2/Net/src/ICMPv4PacketImpl.cpp#1 $
//
// Library: Net
// Package: ICMP
// Module: ICMPv4PacketImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/ICMPv4PacketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Timestamp.h"
#include "Poco/Timespan.h"
#include "Poco/Process.h"
#include "Poco/NumberFormatter.h"
#include <sstream>
using Poco::InvalidArgumentException;
using Poco::Timestamp;
using Poco::Timespan;
using Poco::Process;
using Poco::NumberFormatter;
using Poco::UInt8;
using Poco::UInt16;
using Poco::Int32;
namespace Poco {
namespace Net {
const UInt8 ICMPv4PacketImpl::DESTINATION_UNREACHABLE_TYPE = 3;
const Poco::UInt8 ICMPv4PacketImpl::SOURCE_QUENCH_TYPE = 4;
const Poco::UInt8 ICMPv4PacketImpl::REDIRECT_MESSAGE_TYPE = 5;
const UInt8 ICMPv4PacketImpl::TIME_EXCEEDED_TYPE = 11;
const Poco::UInt8 ICMPv4PacketImpl::PARAMETER_PROBLEM_TYPE = 12;
const std::string ICMPv4PacketImpl::MESSAGE_TYPE[] =
{
"Echo Reply",
"ICMP 1",
"ICMP 2",
"Dest Unreachable",
"Source Quench",
"Redirect",
"ICMP 6",
"ICMP 7",
"Echo",
"ICMP 9",
"ICMP 10",
"Time Exceeded",
"Parameter Problem",
"Timestamp",
"Timestamp Reply",
"Info Request",
"Info Reply",
"Unknown type"
};
const std::string ICMPv4PacketImpl::DESTINATION_UNREACHABLE_CODE[] =
{
"Net unreachable",
"Host unreachable",
"Protocol unreachable",
"Port unreachable",
"Fragmentation needed and DF set",
"Source route failed",
"Unknown code"
};
const std::string ICMPv4PacketImpl::REDIRECT_MESSAGE_CODE[] =
{
"Redirect datagrams for the network",
"Redirect datagrams for the host",
"Redirect datagrams for the type of service and network",
"Redirect datagrams for the type of service and host",
"Unknown code"
};
const std::string ICMPv4PacketImpl::TIME_EXCEEDED_CODE[] =
{
"Time to live exceeded in transit",
"Fragment reassembly time exceeded",
"Unknown code"
};
const std::string ICMPv4PacketImpl::PARAMETER_PROBLEM_CODE[] =
{
"Pointer indicates the error",
"Unknown code"
};
ICMPv4PacketImpl::ICMPv4PacketImpl(int dataSize):
ICMPPacketImpl(dataSize)
{
initPacket();
}
ICMPv4PacketImpl::~ICMPv4PacketImpl()
{
}
int ICMPv4PacketImpl::packetSize() const
{
return getDataSize() + sizeof(Header);
}
void ICMPv4PacketImpl::initPacket()
{
if (_seq >= MAX_SEQ_VALUE) resetSequence();
Header* icp = (Header*) packet(false);
icp->type = ECHO;
icp->code = 0;
icp->checksum = 0;
icp->seq = ++_seq;
icp->id = static_cast<UInt16>(Process::id());
struct timeval* ptp = (struct timeval *) (icp + 1);
*ptp = time();
icp->checksum = checksum((UInt16*) icp, getDataSize() + sizeof(Header));
}
struct timeval ICMPv4PacketImpl::time(Poco::UInt8* buffer, int length) const
{
struct timeval tv;
if (0 == buffer || 0 == length)
{
Timespan value(Timestamp().epochMicroseconds());
tv.tv_sec = (long) value.totalSeconds();
tv.tv_usec = (long) value.useconds();
}
else
{
struct timeval* ptv = (struct timeval*) data(buffer, length);
if (ptv) tv = *ptv;
else throw InvalidArgumentException("Invalid packet.");
}
return tv;
}
ICMPv4PacketImpl::Header* ICMPv4PacketImpl::header(Poco::UInt8* buffer, int length) const
{
poco_check_ptr (buffer);
int offset = (buffer[0] & 0x0F) * 4;
if ((offset + sizeof(Header)) > length) return 0;
buffer += offset;
return (Header *) buffer;
}
Poco::UInt8* ICMPv4PacketImpl::data(Poco::UInt8* buffer, int length) const
{
return ((Poco::UInt8*) header(buffer, length)) + sizeof(Header);
}
bool ICMPv4PacketImpl::validReplyID(Poco::UInt8* buffer, int length) const
{
Header *icp = header(buffer, length);
return icp && (Process::id() == icp->id);
}
std::string ICMPv4PacketImpl::errorDescription(unsigned char* buffer, int length)
{
Header *icp = header(buffer, length);
if (!icp) return "Invalid header.";
if (ECHO_REPLY == icp->type) return std::string(); // not an error
UInt8 pointer = 0;
if (PARAMETER_PROBLEM == icp->type)
{
UInt8 mask = 0x00FF;
pointer = icp->id & mask;
}
MessageType type = static_cast<MessageType>(icp->type);
int code = icp->code;
std::ostringstream err;
switch (type)
{
case DESTINATION_UNREACHABLE_TYPE:
if (code >= NET_UNREACHABLE && code < DESTINATION_UNREACHABLE_UNKNOWN)
err << DESTINATION_UNREACHABLE_CODE[code];
else
err << DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_UNKNOWN];
break;
case SOURCE_QUENCH_TYPE:
err << "Source quench";
break;
case REDIRECT_MESSAGE_TYPE:
if (code >= REDIRECT_NETWORK && code < REDIRECT_MESSAGE_UNKNOWN)
err << REDIRECT_MESSAGE_CODE[code];
else
err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
break;
case TIME_EXCEEDED_TYPE:
if (code >= TIME_TO_LIVE || code < TIME_EXCEEDED_UNKNOWN)
err << TIME_EXCEEDED_CODE[code];
else
err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
break;
case PARAMETER_PROBLEM_TYPE:
if (POINTER_INDICATES_THE_ERROR != code)
code = PARAMETER_PROBLEM_UNKNOWN;
err << PARAMETER_PROBLEM_CODE[code] << ": error in octet #" << pointer;
break;
default:
err << "Unknown type.";
break;
}
return err.str();
}
std::string ICMPv4PacketImpl::typeDescription(int typeId)
{
poco_assert (typeId >= ECHO_REPLY && typeId < MESSAGE_TYPE_LENGTH);
return MESSAGE_TYPE[typeId];
}
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// IPAddress.cpp
//
// $Id: //poco/1.1.0/Net/src/IPAddress.cpp#2 $
// $Id: //poco/1.2/Net/src/IPAddress.cpp#1 $
//
// Library: Net
// Package: NetCore
@@ -34,23 +34,24 @@
//
#include "Net/IPAddress.h"
#include "Net/NetException.h"
#include "Foundation/RefCountedObject.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/Types.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/Net/NetException.h"
#include "Poco/RefCountedObject.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Types.h"
#include <algorithm>
#include <string.h>
using Foundation::RefCountedObject;
using Foundation::NumberFormatter;
using Foundation::UInt8;
using Foundation::UInt16;
using Foundation::UInt32;
using Poco::RefCountedObject;
using Poco::NumberFormatter;
using Poco::UInt8;
using Poco::UInt16;
using Poco::UInt32;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -465,7 +466,7 @@ IPAddress::IPAddress(Family family): _pImpl(0)
else if (family == IPv6)
_pImpl = new IPv6AddressImpl();
#endif
else Foundation::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
else Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
@@ -488,7 +489,7 @@ IPAddress::IPAddress(const std::string& addr, Family family): _pImpl(0)
else if (family == IPv6)
_pImpl = IPv6AddressImpl::parse(addr);
#endif
else throw Foundation::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
@@ -500,7 +501,7 @@ IPAddress::IPAddress(const void* addr, poco_socklen_t length)
else if (length == sizeof(struct in6_addr))
_pImpl = new IPv6AddressImpl(addr);
#endif
else throw Foundation::InvalidArgumentException("Invalid address length passed to IPAddress()");
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
}
@@ -741,4 +742,4 @@ bool IPAddress::tryParse(const std::string& addr, IPAddress& result)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MailMessage.cpp
//
// $Id: //poco/1.1.0/Net/src/MailMessage.cpp#2 $
// $Id: //poco/1.2/Net/src/MailMessage.cpp#1 $
//
// Library: Net
// Package: Mail
@@ -34,35 +34,36 @@
//
#include "Net/MailMessage.h"
#include "Net/MediaType.h"
#include "Net/MultipartReader.h"
#include "Net/MultipartWriter.h"
#include "Net/PartSource.h"
#include "Net/PartHandler.h"
#include "Net/QuotedPrintableEncoder.h"
#include "Net/QuotedPrintableDecoder.h"
#include "Foundation/Base64Encoder.h"
#include "Foundation/Base64Decoder.h"
#include "Foundation/StreamCopier.h"
#include "Foundation/DateTimeFormat.h"
#include "Foundation/DateTimeFormatter.h"
#include "Foundation/DateTimeParser.h"
#include "Foundation/String.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MediaType.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Net/MultipartWriter.h"
#include "Poco/Net/PartSource.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/QuotedPrintableEncoder.h"
#include "Poco/Net/QuotedPrintableDecoder.h"
#include "Poco/Base64Encoder.h"
#include "Poco/Base64Decoder.h"
#include "Poco/StreamCopier.h"
#include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeParser.h"
#include "Poco/String.h"
#include <sstream>
#include <ctype.h>
using Foundation::Base64Encoder;
using Foundation::Base64Decoder;
using Foundation::StreamCopier;
using Foundation::DateTimeFormat;
using Foundation::DateTimeFormatter;
using Foundation::DateTimeParser;
using Foundation::icompare;
using Poco::Base64Encoder;
using Poco::Base64Decoder;
using Poco::StreamCopier;
using Poco::DateTimeFormat;
using Poco::DateTimeFormatter;
using Poco::DateTimeParser;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
namespace
@@ -115,7 +116,7 @@ const std::string MailMessage::CTE_BASE64("base64");
MailMessage::MailMessage()
{
Foundation::Timestamp now;
Poco::Timestamp now;
setDate(now);
setContentType("text/plain");
}
@@ -195,13 +196,13 @@ const std::string& MailMessage::getContentType() const
}
void MailMessage::setDate(const Foundation::Timestamp& dateTime)
void MailMessage::setDate(const Poco::Timestamp& dateTime)
{
set(HEADER_DATE, DateTimeFormatter::format(dateTime, DateTimeFormat::RFC1123_FORMAT));
}
Foundation::Timestamp MailMessage::getDate() const
Poco::Timestamp MailMessage::getDate() const
{
const std::string& dateTime = get(HEADER_DATE);
int tzd;
@@ -489,4 +490,4 @@ void MailMessage::appendRecipient(const MailRecipient& recipient, std::string& s
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MailRecipient.cpp
//
// $Id: //poco/1.1.0/Net/src/MailRecipient.cpp#2 $
// $Id: //poco/1.2/Net/src/MailRecipient.cpp#1 $
//
// Library: Net
// Package: Mail
@@ -34,11 +34,12 @@
//
#include "Net/MailRecipient.h"
#include "Poco/Net/MailRecipient.h"
#include <algorithm>
Net_BEGIN
namespace Poco {
namespace Net {
MailRecipient::MailRecipient():
@@ -48,24 +49,24 @@ MailRecipient::MailRecipient():
MailRecipient::MailRecipient(const MailRecipient& recipient):
_type(recipient._type),
_address(recipient._address),
_realName(recipient._realName)
_realName(recipient._realName),
_type(recipient._type)
{
}
MailRecipient::MailRecipient(RecipientType type, const std::string& address):
_type(type),
_address(address)
_address(address),
_type(type)
{
}
MailRecipient::MailRecipient(RecipientType type, const std::string& address, const std::string& realName):
_type(type),
_address(address),
_realName(realName)
_realName(realName),
_type(type)
{
}
@@ -112,4 +113,4 @@ void MailRecipient::setRealName(const std::string& realName)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MailStream.cpp
//
// $Id: //poco/1.1.0/Net/src/MailStream.cpp#2 $
// $Id: //poco/1.2/Net/src/MailStream.cpp#1 $
//
// Library: Net
// Package: Mail
@@ -34,10 +34,11 @@
//
#include "Net/MailStream.h"
#include "Poco/Net/MailStream.h"
Net_BEGIN
namespace Poco {
namespace Net {
MailStreamBuf::MailStreamBuf(std::istream& istr):
@@ -237,4 +238,4 @@ MailOutputStream::~MailOutputStream()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MediaType.cpp
//
// $Id: //poco/1.1.0/Net/src/MediaType.cpp#2 $
// $Id: //poco/1.2/Net/src/MediaType.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,17 +34,18 @@
//
#include "Net/MediaType.h"
#include "Net/MessageHeader.h"
#include "Foundation/String.h"
#include "Poco/Net/MediaType.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/String.h"
#include <algorithm>
#include <ctype.h>
using Foundation::icompare;
using Poco::icompare;
Net_BEGIN
namespace Poco {
namespace Net {
MediaType::MediaType(const std::string& mediaType)
@@ -187,4 +188,4 @@ void MediaType::parse(const std::string& mediaType)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MessageHeader.cpp
//
// $Id: //poco/1.1.0/Net/src/MessageHeader.cpp#2 $
// $Id: //poco/1.2/Net/src/MessageHeader.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,13 +34,14 @@
//
#include "Net/MessageHeader.h"
#include "Net/NetException.h"
#include "Foundation/String.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/Net/NetException.h"
#include "Poco/String.h"
#include <ctype.h>
Net_BEGIN
namespace Poco {
namespace Net {
MessageHeader::MessageHeader()
@@ -139,7 +140,7 @@ void MessageHeader::splitElements(const std::string& s, std::vector<std::string>
}
else if (*it == ',')
{
Foundation::trimInPlace(elem);
Poco::trimInPlace(elem);
if (!ignoreEmpty || !elem.empty())
elements.push_back(elem);
elem.clear();
@@ -149,7 +150,7 @@ void MessageHeader::splitElements(const std::string& s, std::vector<std::string>
}
if (!elem.empty())
{
Foundation::trimInPlace(elem);
Poco::trimInPlace(elem);
if (!ignoreEmpty || !elem.empty())
elements.push_back(elem);
}
@@ -164,7 +165,7 @@ void MessageHeader::splitParameters(const std::string& s, std::string& value, Na
std::string::const_iterator end = s.end();
while (it != end && isspace(*it)) ++it;
while (it != end && *it != ';') value += *it++;
Foundation::trimRightInPlace(value);
Poco::trimRightInPlace(value);
if (it != end) ++it;
splitParameters(it, end, parameters);
}
@@ -179,7 +180,7 @@ void MessageHeader::splitParameters(const std::string::const_iterator& begin, co
std::string pvalue;
while (it != end && isspace(*it)) ++it;
while (it != end && *it != '=' && *it != ';') pname += *it++;
Foundation::trimRightInPlace(pname);
Poco::trimRightInPlace(pname);
if (it != end && *it != ';') ++it;
while (it != end && isspace(*it)) ++it;
while (it != end && *it != ';')
@@ -205,7 +206,7 @@ void MessageHeader::splitParameters(const std::string::const_iterator& begin, co
}
else pvalue += *it++;
}
Foundation::trimRightInPlace(pvalue);
Poco::trimRightInPlace(pvalue);
if (!pname.empty()) parameters.add(pname, pvalue);
if (it != end) ++it;
}
@@ -226,4 +227,4 @@ void MessageHeader::quote(const std::string& value, std::string& result, bool al
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MulticastSocket.cpp
//
// $Id: //poco/1.1.0/Net/src/MulticastSocket.cpp#2 $
// $Id: //poco/1.2/Net/src/MulticastSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,8 +34,8 @@
//
#include "Net/MulticastSocket.h"
#include "Net/NetException.h"
#include "Poco/Net/MulticastSocket.h"
#include "Poco/Net/NetException.h"
#include <string.h>
@@ -57,7 +57,8 @@ struct ip_mreq
#endif
Net_BEGIN
namespace Poco {
namespace Net {
MulticastSocket::MulticastSocket()
@@ -115,7 +116,7 @@ NetworkInterface MulticastSocket::getInterface() const
impl()->getOption(IPPROTO_IP, IP_MULTICAST_IF, addr);
return NetworkInterface::forAddress(addr);
}
catch (Foundation::Exception&)
catch (Poco::Exception&)
{
#if defined(POCO_HAVE_IPv6)
int ix;
@@ -257,4 +258,4 @@ void MulticastSocket::leaveGroup(const IPAddress& groupAddress, const NetworkInt
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MultipartReader.cpp
//
// $Id: //poco/1.1.0/Net/src/MultipartReader.cpp#2 $
// $Id: //poco/1.2/Net/src/MultipartReader.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,16 +34,17 @@
//
#include "Net/MultipartReader.h"
#include "Net/MessageHeader.h"
#include "Net/NetException.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/Net/NetException.h"
#include <ctype.h>
using Foundation::BufferedStreamBuf;
using Poco::BufferedStreamBuf;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -313,4 +314,4 @@ bool MultipartReader::readLine(std::string& line, std::string::size_type n)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// MultipartWriter.cpp
//
// $Id: //poco/1.1.0/Net/src/MultipartWriter.cpp#2 $
// $Id: //poco/1.2/Net/src/MultipartWriter.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,17 +34,18 @@
//
#include "Net/MultipartWriter.h"
#include "Net/MessageHeader.h"
#include "Foundation/Random.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/MultipartWriter.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/Random.h"
#include "Poco/NumberFormatter.h"
using Foundation::Random;
using Foundation::NumberFormatter;
using Poco::Random;
using Poco::NumberFormatter;
Net_BEGIN
namespace Poco {
namespace Net {
MultipartWriter::MultipartWriter(std::ostream& ostr):
@@ -98,4 +99,4 @@ std::string MultipartWriter::createBoundary()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// NameValueCollection.cpp
//
// $Id: //poco/1.1.0/Net/src/NameValueCollection.cpp#2 $
// $Id: //poco/1.2/Net/src/NameValueCollection.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,15 +34,16 @@
//
#include "Net/NameValueCollection.h"
#include "Foundation/Exception.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Exception.h"
#include <algorithm>
using Foundation::NotFoundException;
using Poco::NotFoundException;
Net_BEGIN
namespace Poco {
namespace Net {
NameValueCollection::NameValueCollection()
@@ -112,6 +113,16 @@ const std::string& NameValueCollection::get(const std::string& name) const
}
const std::string& NameValueCollection::get(const std::string& name, const std::string& defaultValue) const
{
ConstIterator it = _map.find(name);
if (it != _map.end())
return it->second;
else
return defaultValue;
}
bool NameValueCollection::has(const std::string& name) const
{
return _map.find(name) != _map.end();
@@ -160,4 +171,4 @@ void NameValueCollection::clear()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// NetException.cpp
//
// $Id: //poco/1.1.0/Net/src/NetException.cpp#2 $
// $Id: //poco/1.2/Net/src/NetException.cpp#1 $
//
// Library: Net
// Package: NetCore
@@ -34,14 +34,15 @@
//
#include "Net/NetException.h"
#include "Poco/Net/NetException.h"
#include <typeinfo>
using Foundation::IOException;
using Poco::IOException;
Net_BEGIN
namespace Poco {
namespace Net {
POCO_IMPLEMENT_EXCEPTION(NetException, IOException, "Net Exception")
@@ -58,9 +59,11 @@ POCO_IMPLEMENT_EXCEPTION(MessageException, NetException, "Malformed message")
POCO_IMPLEMENT_EXCEPTION(MultipartException, MessageException, "Malformed multipart message")
POCO_IMPLEMENT_EXCEPTION(HTTPException, NetException, "HTTP Exception")
POCO_IMPLEMENT_EXCEPTION(NotAuthenticatedException, HTTPException, "No authentication information found")
POCO_IMPLEMENT_EXCEPTION(UnsupportedRedirectException, HTTPException, "Unsupported HTTP redirect (protocol change)")
POCO_IMPLEMENT_EXCEPTION(FTPException, NetException, "FTP Exception")
POCO_IMPLEMENT_EXCEPTION(SMTPException, NetException, "SMTP Exception")
POCO_IMPLEMENT_EXCEPTION(POP3Exception, NetException, "POP3 Exception")
POCO_IMPLEMENT_EXCEPTION(ICMPException, NetException, "ICMP Exception")
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// NetworkInterface.cpp
//
// $Id: //poco/1.1.0/Net/src/NetworkInterface.cpp#3 $
// $Id: //poco/1.2/Net/src/NetworkInterface.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,18 +34,19 @@
//
#include "Net/NetworkInterface.h"
#include "Net/DatagramSocket.h"
#include "Net/NetException.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/NetworkInterface.h"
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include <string.h>
using Foundation::NumberFormatter;
using Foundation::FastMutex;
using Poco::NumberFormatter;
using Poco::FastMutex;
Net_BEGIN
namespace Poco {
namespace Net {
FastMutex NetworkInterface::_mutex;
@@ -66,9 +67,9 @@ NetworkInterface::NetworkInterface(const std::string& name, const IPAddress& add
NetworkInterface::NetworkInterface(const NetworkInterface& interface):
_index(interface._index),
_name(interface._name),
_address(interface._address)
_address(interface._address),
_index(interface._index)
{
}
@@ -82,9 +83,9 @@ NetworkInterface& NetworkInterface::operator = (const NetworkInterface& interfac
{
if (&interface != this)
{
_index = interface._index;
_name = interface._name;
_address = interface._address;
_index = interface._index;
}
return *this;
}
@@ -154,7 +155,7 @@ NetworkInterface NetworkInterface::forIndex(int i)
}
Foundation_END
} } // namespace Poco::Net
//
@@ -169,7 +170,8 @@ Foundation_END
#include <iphlpapi.h>
Net_BEGIN
namespace Poco {
namespace Net {
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
@@ -212,13 +214,15 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
else throw NetException("cannot get network adapter list");
}
catch (Foundation::Exception&)
catch (Poco::Exception&)
{
delete [] reinterpret_cast<char*>(pAdapterAddresses);
throw;
}
delete [] reinterpret_cast<char*>(pAdapterAddresses);
#else
// Add loopback interface (not returned by GetAdaptersInfo)
result.push_back(NetworkInterface("Loopback", IPAddress("127.0.0.1"), -1));
// On Windows 2000 we use GetAdaptersInfo.
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = 0;
@@ -250,7 +254,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
else throw NetException("cannot get network adapter list");
}
catch (Foundation::Exception&)
catch (Poco::Exception&)
{
delete [] reinterpret_cast<char*>(pAdapterInfo);
throw;
@@ -262,7 +266,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
Net_END
} } // namespace Poco::Net
#elif defined(POCO_OS_FAMILY_BSD) || POCO_OS == POCO_OS_QNX
@@ -275,7 +279,8 @@ Net_END
#include <net/if_dl.h>
Net_BEGIN
namespace Poco {
namespace Net {
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
@@ -310,7 +315,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
Net_END
} } // namespace Poco::Net
#elif POCO_OS == POCO_OS_LINUX
@@ -319,7 +324,8 @@ Net_END
//
Net_BEGIN
namespace Poco {
namespace Net {
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
@@ -396,7 +402,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
Net_END
} } // namespace Poco::Net
#else
@@ -405,7 +411,8 @@ Net_END
//
Net_BEGIN
namespace Poco {
namespace Net {
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
@@ -491,7 +498,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
Net_END
} } // namespace Poco::Net
#endif

View File

@@ -1,7 +1,7 @@
//
// NullPartHandler.cpp
//
// $Id: //poco/1.1.0/Net/src/NullPartHandler.cpp#2 $
// $Id: //poco/1.2/Net/src/NullPartHandler.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,17 +34,18 @@
//
#include "Net/NullPartHandler.h"
#include "Net/MessageHeader.h"
#include "Foundation/NullStream.h"
#include "Foundation/StreamCopier.h"
#include "Poco/Net/NullPartHandler.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/NullStream.h"
#include "Poco/StreamCopier.h"
using Foundation::NullOutputStream;
using Foundation::StreamCopier;
using Poco::NullOutputStream;
using Poco::StreamCopier;
Net_BEGIN
namespace Poco {
namespace Net {
NullPartHandler::NullPartHandler()
@@ -64,4 +65,4 @@ void NullPartHandler::handlePart(const MessageHeader& header, std::istream& stre
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// POP3ClientSession.cpp
//
// $Id: //poco/1.1.0/Net/src/POP3ClientSession.cpp#2 $
// $Id: //poco/1.2/Net/src/POP3ClientSession.cpp#1 $
//
// Library: Net
// Package: Mail
@@ -34,26 +34,27 @@
//
#include "Net/POP3ClientSession.h"
#include "Net/MailMessage.h"
#include "Net/MailStream.h"
#include "Net/SocketAddress.h"
#include "Net/NetException.h"
#include "Foundation/StreamCopier.h"
#include "Foundation/NumberFormatter.h"
#include "Foundation/UnbufferedStreamBuf.h"
#include "Poco/Net/POP3ClientSession.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MailStream.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/NetException.h"
#include "Poco/StreamCopier.h"
#include "Poco/NumberFormatter.h"
#include "Poco/UnbufferedStreamBuf.h"
#include <istream>
#include <ctype.h>
using Foundation::NumberFormatter;
using Foundation::StreamCopier;
using Poco::NumberFormatter;
using Poco::StreamCopier;
Net_BEGIN
namespace Poco {
namespace Net {
class DialogStreamBuf: public Foundation::UnbufferedStreamBuf
class DialogStreamBuf: public Poco::UnbufferedStreamBuf
{
public:
DialogStreamBuf(DialogSocket& socket):
@@ -120,7 +121,7 @@ POP3ClientSession::POP3ClientSession(const StreamSocket& socket):
}
POP3ClientSession::POP3ClientSession(const std::string& host, Foundation::UInt16 port):
POP3ClientSession::POP3ClientSession(const std::string& host, Poco::UInt16 port):
_socket(SocketAddress(host, port)),
_isOpen(true)
{
@@ -139,13 +140,13 @@ POP3ClientSession::~POP3ClientSession()
}
void POP3ClientSession::setTimeout(const Foundation::Timespan& timeout)
void POP3ClientSession::setTimeout(const Poco::Timespan& timeout)
{
_socket.setReceiveTimeout(timeout);
}
Foundation::Timespan POP3ClientSession::getTimeout() const
Poco::Timespan POP3ClientSession::getTimeout() const
{
return _socket.getReceiveTimeout();
}
@@ -296,4 +297,4 @@ bool POP3ClientSession::isPositive(const std::string& response)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// PartHandler.cpp
//
// $Id: //poco/1.1.0/Net/src/PartHandler.cpp#2 $
// $Id: //poco/1.2/Net/src/PartHandler.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,10 +34,11 @@
//
#include "Net/PartHandler.h"
#include "Poco/Net/PartHandler.h"
Net_BEGIN
namespace Poco {
namespace Net {
PartHandler::PartHandler()
@@ -50,4 +51,4 @@ PartHandler::~PartHandler()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// PartSource.cpp
//
// $Id: //poco/1.1.0/Net/src/PartSource.cpp#2 $
// $Id: //poco/1.2/Net/src/PartSource.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,10 +34,11 @@
//
#include "Net/PartSource.h"
#include "Poco/Net/PartSource.h"
Net_BEGIN
namespace Poco {
namespace Net {
PartSource::PartSource():
@@ -64,4 +65,4 @@ const std::string& PartSource::filename()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// QuotedPrintableDecoder.cpp
//
// $Id: //poco/1.1.0/Net/src/QuotedPrintableDecoder.cpp#2 $
// $Id: //poco/1.2/Net/src/QuotedPrintableDecoder.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,18 +34,19 @@
//
#include "Net/QuotedPrintableDecoder.h"
#include "Foundation/NumberParser.h"
#include "Foundation/Exception.h"
#include "Poco/Net/QuotedPrintableDecoder.h"
#include "Poco/NumberParser.h"
#include "Poco/Exception.h"
#include <ctype.h>
using Foundation::UnbufferedStreamBuf;
using Foundation::NumberParser;
using Foundation::DataFormatException;
using Poco::UnbufferedStreamBuf;
using Poco::NumberParser;
using Poco::DataFormatException;
Net_BEGIN
namespace Poco {
namespace Net {
QuotedPrintableDecoderBuf::QuotedPrintableDecoderBuf(std::istream& istr):
@@ -61,8 +62,6 @@ QuotedPrintableDecoderBuf::~QuotedPrintableDecoderBuf()
int QuotedPrintableDecoderBuf::readFromDevice()
{
static const int eof = std::char_traits<char>::eof();
int ch = _istr.get();
while (ch == '=')
{
@@ -122,4 +121,4 @@ QuotedPrintableDecoder::~QuotedPrintableDecoder()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// QuotedPrintableEncoder.cpp
//
// $Id: //poco/1.1.0/Net/src/QuotedPrintableEncoder.cpp#2 $
// $Id: //poco/1.2/Net/src/QuotedPrintableEncoder.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,15 +34,16 @@
//
#include "Net/QuotedPrintableEncoder.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/QuotedPrintableEncoder.h"
#include "Poco/NumberFormatter.h"
using Foundation::UnbufferedStreamBuf;
using Foundation::NumberFormatter;
using Poco::UnbufferedStreamBuf;
using Poco::NumberFormatter;
Net_BEGIN
namespace Poco {
namespace Net {
QuotedPrintableEncoderBuf::QuotedPrintableEncoderBuf(std::ostream& ostr):
@@ -168,4 +169,4 @@ QuotedPrintableEncoder::~QuotedPrintableEncoder()
}
Net_END
} } // namespace Poco::Net

133
Net/src/RawSocket.cpp Normal file
View File

@@ -0,0 +1,133 @@
//
// RawSocket.cpp
//
// $Id: //poco/1.2/Net/src/RawSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
// Module: RawSocket
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/RawSocket.h"
#include "Poco/Net/RawSocketImpl.h"
#include "Poco/Exception.h"
using Poco::InvalidArgumentException;
namespace Poco {
namespace Net {
RawSocket::RawSocket():
Socket(new RawSocketImpl)
{
}
RawSocket::RawSocket(IPAddress::Family family, int proto):
Socket(new RawSocketImpl(family, proto))
{
}
RawSocket::RawSocket(const SocketAddress& address, bool reuseAddress):
Socket(new RawSocketImpl)
{
bind(address, reuseAddress);
}
RawSocket::RawSocket(const Socket& socket): Socket(socket)
{
if (!dynamic_cast<RawSocketImpl*>(impl()))
throw InvalidArgumentException("Cannot assign incompatible socket");
}
RawSocket::RawSocket(SocketImpl* pImpl): Socket(pImpl)
{
if (!dynamic_cast<RawSocketImpl*>(impl()))
throw InvalidArgumentException("Cannot assign incompatible socket");
}
RawSocket::~RawSocket()
{
}
RawSocket& RawSocket::operator = (const Socket& socket)
{
if (dynamic_cast<RawSocketImpl*>(socket.impl()))
Socket::operator = (socket);
else
throw InvalidArgumentException("Cannot assign incompatible socket");
return *this;
}
void RawSocket::connect(const SocketAddress& address)
{
impl()->connect(address);
}
void RawSocket::bind(const SocketAddress& address, bool reuseAddress)
{
impl()->bind(address, reuseAddress);
}
int RawSocket::sendBytes(const void* buffer, int length, int flags)
{
return impl()->sendBytes(buffer, length, flags);
}
int RawSocket::receiveBytes(void* buffer, int length, int flags)
{
return impl()->receiveBytes(buffer, length, flags);
}
int RawSocket::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
{
return impl()->sendTo(buffer, length, address, flags);
}
int RawSocket::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
{
return impl()->receiveFrom(buffer, length, address, flags);
}
} } // namespace Poco::Net

91
Net/src/RawSocketImpl.cpp Normal file
View File

@@ -0,0 +1,91 @@
//
// RawSocketImpl.cpp
//
// $Id: //poco/1.2/Net/src/RawSocketImpl.cpp#1 $
//
// Library: Net
// Package: Sockets
// Module: RawSocketImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Net/RawSocketImpl.h"
#include "Poco/Net/NetException.h"
using Poco::InvalidArgumentException;
namespace Poco {
namespace Net {
RawSocketImpl::RawSocketImpl()
{
init(AF_INET);
}
RawSocketImpl::RawSocketImpl(IPAddress::Family family, int proto)
{
if (family == IPAddress::IPv4)
init2(AF_INET, proto);
#if POCO_HAVE_IPv6
else if (family == IPAddress::IPv6)
init2(AF_INET6, proto);
#endif
else throw InvalidArgumentException("Invalid or unsupported address family passed to RawSocketImpl");
}
RawSocketImpl::RawSocketImpl(poco_socket_t sockfd):
SocketImpl(sockfd)
{
}
RawSocketImpl::~RawSocketImpl()
{
}
void RawSocketImpl::init(int af)
{
init2(af, IPPROTO_RAW);
}
void RawSocketImpl::init2(int af, int proto)
{
initSocket(af, SOCK_RAW, proto);
setOption(IPPROTO_IP, IP_HDRINCL, 0);
}
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SMTPClientSession.cpp
//
// $Id: //poco/1.1.0/Net/src/SMTPClientSession.cpp#2 $
// $Id: //poco/1.2/Net/src/SMTPClientSession.cpp#1 $
//
// Library: Net
// Package: Mail
@@ -34,20 +34,21 @@
//
#include "Net/SMTPClientSession.h"
#include "Net/MailMessage.h"
#include "Net/MailRecipient.h"
#include "Net/MailStream.h"
#include "Net/SocketAddress.h"
#include "Net/SocketStream.h"
#include "Net/NetException.h"
#include "Foundation/Environment.h"
#include "Poco/Net/SMTPClientSession.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MailRecipient.h"
#include "Poco/Net/MailStream.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/NetException.h"
#include "Poco/Environment.h"
using Foundation::Environment;
using Poco::Environment;
Net_BEGIN
namespace Poco {
namespace Net {
SMTPClientSession::SMTPClientSession(const StreamSocket& socket):
@@ -57,7 +58,7 @@ SMTPClientSession::SMTPClientSession(const StreamSocket& socket):
}
SMTPClientSession::SMTPClientSession(const std::string& host, Foundation::UInt16 port):
SMTPClientSession::SMTPClientSession(const std::string& host, Poco::UInt16 port):
_socket(SocketAddress(host, port)),
_isOpen(true)
{
@@ -76,13 +77,13 @@ SMTPClientSession::~SMTPClientSession()
}
void SMTPClientSession::setTimeout(const Foundation::Timespan& timeout)
void SMTPClientSession::setTimeout(const Poco::Timespan& timeout)
{
_socket.setReceiveTimeout(timeout);
}
Foundation::Timespan SMTPClientSession::getTimeout() const
Poco::Timespan SMTPClientSession::getTimeout() const
{
return _socket.getReceiveTimeout();
}
@@ -160,4 +161,4 @@ int SMTPClientSession::sendCommand(const std::string& command, const std::string
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// ServerSocket.cpp
//
// $Id: //poco/1.1.0/Net/src/ServerSocket.cpp#2 $
// $Id: //poco/1.2/Net/src/ServerSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,15 +34,16 @@
//
#include "Net/ServerSocket.h"
#include "Net/ServerSocketImpl.h"
#include "Foundation/Exception.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/ServerSocketImpl.h"
#include "Poco/Exception.h"
using Foundation::InvalidArgumentException;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
ServerSocket::ServerSocket(): Socket(new ServerSocketImpl)
@@ -64,7 +65,7 @@ ServerSocket::ServerSocket(const SocketAddress& address, int backlog): Socket(ne
}
ServerSocket::ServerSocket(Foundation::UInt16 port, int backlog): Socket(new ServerSocketImpl)
ServerSocket::ServerSocket(Poco::UInt16 port, int backlog): Socket(new ServerSocketImpl)
{
IPAddress wildcardAddr;
SocketAddress address(wildcardAddr, port);
@@ -99,7 +100,7 @@ void ServerSocket::bind(const SocketAddress& address, bool reuseAddress)
}
void ServerSocket::bind(Foundation::UInt16 port, bool reuseAddress)
void ServerSocket::bind(Poco::UInt16 port, bool reuseAddress)
{
IPAddress wildcardAddr;
SocketAddress address(wildcardAddr, port);
@@ -126,4 +127,4 @@ StreamSocket ServerSocket::acceptConnection()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// ServerSocketImpl.cpp
//
// $Id: //poco/1.1.0/Net/src/ServerSocketImpl.cpp#2 $
// $Id: //poco/1.2/Net/src/ServerSocketImpl.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,10 +34,11 @@
//
#include "Net/ServerSocketImpl.h"
#include "Poco/Net/ServerSocketImpl.h"
Net_BEGIN
namespace Poco {
namespace Net {
ServerSocketImpl::ServerSocketImpl()
@@ -50,4 +51,4 @@ ServerSocketImpl::~ServerSocketImpl()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// Socket.cpp
//
// $Id: //poco/1.1.0/Net/src/Socket.cpp#2 $
// $Id: //poco/1.2/Net/src/Socket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,13 +34,14 @@
//
#include "Net/Socket.h"
#include "Net/StreamSocketImpl.h"
#include "Poco/Net/Socket.h"
#include "Poco/Net/StreamSocketImpl.h"
#include <algorithm>
#include <string.h>
Net_BEGIN
namespace Poco {
namespace Net {
Socket::Socket():
@@ -83,7 +84,7 @@ Socket::~Socket()
}
int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Foundation::Timespan& timeout)
int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout)
{
fd_set fdRead;
fd_set fdWrite;
@@ -141,4 +142,4 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketAddress.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketAddress.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketAddress.cpp#1 $
//
// Library: Net
// Package: NetCore
@@ -34,24 +34,26 @@
//
#include "Net/SocketAddress.h"
#include "Net/IPAddress.h"
#include "Net/NetException.h"
#include "Net/DNS.h"
#include "Foundation/RefCountedObject.h"
#include "Foundation/NumberParser.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/DNS.h"
#include "Poco/RefCountedObject.h"
#include "Poco/NumberParser.h"
#include "Poco/NumberFormatter.h"
#include <algorithm>
#include <string.h>
using Foundation::RefCountedObject;
using Foundation::NumberParser;
using Foundation::NumberFormatter;
using Foundation::UInt16;
using Poco::RefCountedObject;
using Poco::NumberParser;
using Poco::NumberFormatter;
using Poco::UInt16;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -200,13 +202,13 @@ SocketAddress::SocketAddress()
}
SocketAddress::SocketAddress(const IPAddress& addr, Foundation::UInt16 port)
SocketAddress::SocketAddress(const IPAddress& addr, Poco::UInt16 port)
{
init(addr, port);
}
SocketAddress::SocketAddress(const std::string& addr, Foundation::UInt16 port)
SocketAddress::SocketAddress(const std::string& addr, Poco::UInt16 port)
{
init(addr, port);
}
@@ -218,6 +220,35 @@ SocketAddress::SocketAddress(const std::string& addr, const std::string& port)
}
SocketAddress::SocketAddress(const std::string& hostAndPort)
{
poco_assert (!hostAndPort.empty());
std::string host;
std::string port;
std::string::const_iterator it = hostAndPort.begin();
std::string::const_iterator end = hostAndPort.end();
if (*it == '[')
{
++it;
while (it != end && *it != ']') host += *it++;
if (it == end) throw InvalidArgumentException("Malformed IPv6 address");
++it;
}
else
{
while (it != end && *it != ':') host += *it++;
}
if (it != end && *it == ':')
{
++it;
while (it != end) port += *it++;
}
else throw InvalidArgumentException("Missing port number");
init(host, resolveService(port));
}
SocketAddress::SocketAddress(const SocketAddress& addr)
{
_pImpl = addr._pImpl;
@@ -233,7 +264,7 @@ SocketAddress::SocketAddress(const struct sockaddr* addr, poco_socklen_t length)
else if (length == sizeof(struct sockaddr_in6))
_pImpl = new IPv6SocketAddressImpl(reinterpret_cast<const struct sockaddr_in6*>(addr));
#endif
else throw Foundation::InvalidArgumentException("Invalid address length passed to SocketAddress()");
else throw Poco::InvalidArgumentException("Invalid address length passed to SocketAddress()");
}
@@ -267,7 +298,7 @@ IPAddress SocketAddress::host() const
}
Foundation::UInt16 SocketAddress::port() const
Poco::UInt16 SocketAddress::port() const
{
return ntohs(_pImpl->port());
}
@@ -293,14 +324,19 @@ int SocketAddress::af() const
std::string SocketAddress::toString() const
{
std::string result = host().toString();
std::string result;
if (host().family() == IPAddress::IPv6)
result.append("[");
result.append(host().toString());
if (host().family() == IPAddress::IPv6)
result.append("]");
result.append(":");
result.append(NumberFormatter::format(port()));
return result;
}
void SocketAddress::init(const IPAddress& host, Foundation::UInt16 port)
void SocketAddress::init(const IPAddress& host, Poco::UInt16 port)
{
if (host.family() == IPAddress::IPv4)
_pImpl = new IPv4SocketAddressImpl(host.addr(), htons(port));
@@ -308,11 +344,11 @@ void SocketAddress::init(const IPAddress& host, Foundation::UInt16 port)
else if (host.family() == IPAddress::IPv6)
_pImpl = new IPv6SocketAddressImpl(host.addr(), htons(port));
#endif
else throw Foundation::NotImplementedException("unsupported IP address family");
else throw Poco::NotImplementedException("unsupported IP address family");
}
void SocketAddress::init(const std::string& host, Foundation::UInt16 port)
void SocketAddress::init(const std::string& host, Poco::UInt16 port)
{
IPAddress ip;
if (IPAddress::tryParse(host, ip))
@@ -329,7 +365,7 @@ void SocketAddress::init(const std::string& host, Foundation::UInt16 port)
}
Foundation::UInt16 SocketAddress::resolveService(const std::string& service)
Poco::UInt16 SocketAddress::resolveService(const std::string& service)
{
unsigned port;
if (NumberParser::tryParseUnsigned(service, port) && port <= 0xFFFF)
@@ -347,4 +383,4 @@ Foundation::UInt16 SocketAddress::resolveService(const std::string& service)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketImpl.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketImpl.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketImpl.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,21 +34,22 @@
//
#include "Net/SocketImpl.h"
#include "Net/NetException.h"
#include "Net/StreamSocketImpl.h"
#include "Foundation/NumberFormatter.h"
#include "Poco/Net/SocketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/StreamSocketImpl.h"
#include "Poco/NumberFormatter.h"
#include <string.h>
using Foundation::IOException;
using Foundation::TimeoutException;
using Foundation::InvalidArgumentException;
using Foundation::NumberFormatter;
using Foundation::Timespan;
using Poco::IOException;
using Poco::TimeoutException;
using Poco::InvalidArgumentException;
using Poco::NumberFormatter;
using Poco::Timespan;
Net_BEGIN
namespace Poco {
namespace Net {
SocketImpl::SocketImpl():
@@ -108,7 +109,7 @@ void SocketImpl::connect(const SocketAddress& address)
}
void SocketImpl::connect(const SocketAddress& address, const Foundation::Timespan& timeout)
void SocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
{
poco_assert (_sockfd == POCO_INVALID_SOCKET);
@@ -122,12 +123,12 @@ void SocketImpl::connect(const SocketAddress& address, const Foundation::Timespa
if (lastError() != POCO_EINPROGRESS && lastError() != POCO_EWOULDBLOCK)
error(address.toString());
if (!poll(timeout, SELECT_READ | SELECT_WRITE))
throw Foundation::TimeoutException("connect timed out", address.toString());
throw Poco::TimeoutException("connect timed out", address.toString());
int err = socketError();
if (err != 0) error(err);
}
}
catch (Foundation::Exception&)
catch (Poco::Exception&)
{
setBlocking(true);
throw;
@@ -324,7 +325,7 @@ int SocketImpl::available()
}
bool SocketImpl::poll(const Foundation::Timespan& timeout, int mode)
bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
{
fd_set fdRead;
fd_set fdWrite;
@@ -381,7 +382,7 @@ int SocketImpl::getReceiveBufferSize()
}
void SocketImpl::setSendTimeout(const Foundation::Timespan& timeout)
void SocketImpl::setSendTimeout(const Poco::Timespan& timeout)
{
#if defined(_WIN32)
int value = (int) timeout.totalMilliseconds();
@@ -392,7 +393,7 @@ void SocketImpl::setSendTimeout(const Foundation::Timespan& timeout)
}
Foundation::Timespan SocketImpl::getSendTimeout()
Poco::Timespan SocketImpl::getSendTimeout()
{
Timespan result;
#if defined(_WIN32)
@@ -406,7 +407,7 @@ Foundation::Timespan SocketImpl::getSendTimeout()
}
void SocketImpl::setReceiveTimeout(const Foundation::Timespan& timeout)
void SocketImpl::setReceiveTimeout(const Poco::Timespan& timeout)
{
#if defined(_WIN32)
int value = (int) timeout.totalMilliseconds();
@@ -420,7 +421,7 @@ void SocketImpl::setReceiveTimeout(const Foundation::Timespan& timeout)
}
Foundation::Timespan SocketImpl::getReceiveTimeout()
Poco::Timespan SocketImpl::getReceiveTimeout()
{
Timespan result;
#if defined(_WIN32)
@@ -492,7 +493,7 @@ void SocketImpl::setOption(int level, int option, const IPAddress& value)
}
void SocketImpl::setOption(int level, int option, const Foundation::Timespan& value)
void SocketImpl::setOption(int level, int option, const Poco::Timespan& value)
{
struct timeval tv;
tv.tv_sec = (long) value.totalSeconds();
@@ -532,7 +533,7 @@ void SocketImpl::getOption(int level, int option, unsigned char& value)
}
void SocketImpl::getOption(int level, int option, Foundation::Timespan& value)
void SocketImpl::getOption(int level, int option, Poco::Timespan& value)
{
struct timeval tv;
poco_socklen_t len = sizeof(tv);
@@ -640,6 +641,7 @@ void SocketImpl::setReusePort(bool flag)
#endif
}
bool SocketImpl::getReusePort()
{
#ifdef SO_REUSEPORT
@@ -842,4 +844,4 @@ void SocketImpl::error(int code, const std::string& arg)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketNotification.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketNotification.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketNotification.cpp#1 $
//
// Library: Net
// Package: Reactor
@@ -34,10 +34,11 @@
//
#include "Net/SocketNotification.h"
#include "Poco/Net/SocketNotification.h"
Net_BEGIN
namespace Poco {
namespace Net {
SocketNotification::SocketNotification(SocketReactor* pReactor):
@@ -112,4 +113,4 @@ ShutdownNotification::~ShutdownNotification()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketNotifier.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketNotifier.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketNotifier.cpp#1 $
//
// Library: Net
// Package: Reactor
@@ -34,12 +34,13 @@
//
#include "Net/SocketNotifier.h"
#include "Net/SocketReactor.h"
#include "Net/SocketNotification.h"
#include "Poco/Net/SocketNotifier.h"
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/SocketNotification.h"
Net_BEGIN
namespace Poco {
namespace Net {
SocketNotifier::SocketNotifier(const Socket& socket):
@@ -53,7 +54,7 @@ SocketNotifier::~SocketNotifier()
}
void SocketNotifier::addObserver(SocketReactor* pReactor, const Foundation::AbstractObserver& observer)
void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
{
_nc.addObserver(observer);
if (observer.accepts(pReactor->_pReadableNotification))
@@ -67,7 +68,7 @@ void SocketNotifier::addObserver(SocketReactor* pReactor, const Foundation::Abst
}
void SocketNotifier::removeObserver(SocketReactor* pReactor, const Foundation::AbstractObserver& observer)
void SocketNotifier::removeObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
{
_nc.removeObserver(observer);
EventSet::iterator it = _events.end();
@@ -92,4 +93,4 @@ void SocketNotifier::dispatch(SocketNotification* pNotification)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketReactor.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketReactor.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketReactor.cpp#1 $
//
// Library: Net
// Package: Reactor
@@ -34,19 +34,20 @@
//
#include "Net/SocketReactor.h"
#include "Net/SocketNotification.h"
#include "Net/SocketNotifier.h"
#include "Foundation/ErrorHandler.h"
#include "Foundation/Exception.h"
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/SocketNotification.h"
#include "Poco/Net/SocketNotifier.h"
#include "Poco/ErrorHandler.h"
#include "Poco/Exception.h"
using Foundation::FastMutex;
using Foundation::Exception;
using Foundation::ErrorHandler;
using Poco::FastMutex;
using Poco::Exception;
using Poco::ErrorHandler;
Net_BEGIN
namespace Poco {
namespace Net {
SocketReactor::SocketReactor():
@@ -61,7 +62,7 @@ SocketReactor::SocketReactor():
}
SocketReactor::SocketReactor(const Foundation::Timespan& timeout):
SocketReactor::SocketReactor(const Poco::Timespan& timeout):
_stop(false),
_timeout(timeout),
_pReadableNotification(new ReadableNotification(this)),
@@ -122,19 +123,19 @@ void SocketReactor::stop()
}
void SocketReactor::setTimeout(const Foundation::Timespan& timeout)
void SocketReactor::setTimeout(const Poco::Timespan& timeout)
{
_timeout = timeout;
}
const Foundation::Timespan& SocketReactor::getTimeout() const
const Poco::Timespan& SocketReactor::getTimeout() const
{
return _timeout;
}
void SocketReactor::addEventHandler(const Socket& socket, const Foundation::AbstractObserver& observer)
void SocketReactor::addEventHandler(const Socket& socket, const Poco::AbstractObserver& observer)
{
FastMutex::ScopedLock lock(_mutex);
@@ -150,7 +151,7 @@ void SocketReactor::addEventHandler(const Socket& socket, const Foundation::Abst
}
void SocketReactor::removeEventHandler(const Socket& socket, const Foundation::AbstractObserver& observer)
void SocketReactor::removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer)
{
FastMutex::ScopedLock lock(_mutex);
@@ -229,4 +230,4 @@ void SocketReactor::dispatch(NotifierPtr& pNotifier, SocketNotification* pNotifi
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// SocketStream.cpp
//
// $Id: //poco/1.1.0/Net/src/SocketStream.cpp#2 $
// $Id: //poco/1.2/Net/src/SocketStream.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,16 +34,17 @@
//
#include "Net/SocketStream.h"
#include "Net/StreamSocketImpl.h"
#include "Foundation/Exception.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/StreamSocketImpl.h"
#include "Poco/Exception.h"
using Foundation::BufferedBidirectionalStreamBuf;
using Foundation::InvalidArgumentException;
using Poco::BufferedBidirectionalStreamBuf;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
//
@@ -174,4 +175,4 @@ SocketStream::~SocketStream()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// StreamSocket.cpp
//
// $Id: //poco/1.1.0/Net/src/StreamSocket.cpp#2 $
// $Id: //poco/1.2/Net/src/StreamSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,15 +34,16 @@
//
#include "Net/StreamSocket.h"
#include "Net/StreamSocketImpl.h"
#include "Foundation/Exception.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/StreamSocketImpl.h"
#include "Poco/Exception.h"
using Foundation::InvalidArgumentException;
using Poco::InvalidArgumentException;
Net_BEGIN
namespace Poco {
namespace Net {
StreamSocket::StreamSocket(): Socket(new StreamSocketImpl)
@@ -91,7 +92,7 @@ void StreamSocket::connect(const SocketAddress& address)
}
void StreamSocket::connect(const SocketAddress& address, const Foundation::Timespan& timeout)
void StreamSocket::connect(const SocketAddress& address, const Poco::Timespan& timeout)
{
impl()->connect(address, timeout);
}
@@ -139,4 +140,4 @@ void StreamSocket::sendUrgent(unsigned char data)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// StreamSocketImpl.cpp
//
// $Id: //poco/1.1.0/Net/src/StreamSocketImpl.cpp#2 $
// $Id: //poco/1.2/Net/src/StreamSocketImpl.cpp#1 $
//
// Library: Net
// Package: Sockets
@@ -34,10 +34,11 @@
//
#include "Net/StreamSocketImpl.h"
#include "Poco/Net/StreamSocketImpl.h"
Net_BEGIN
namespace Poco {
namespace Net {
StreamSocketImpl::StreamSocketImpl()
@@ -69,4 +70,4 @@ int StreamSocketImpl::sendBytes(const void* buffer, int length, int flags)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// StringPartSource.cpp
//
// $Id: //poco/1.1.0/Net/src/StringPartSource.cpp#2 $
// $Id: //poco/1.2/Net/src/StringPartSource.cpp#1 $
//
// Library: Net
// Package: Messages
@@ -34,10 +34,11 @@
//
#include "Net/StringPartSource.h"
#include "Poco/Net/StringPartSource.h"
Net_BEGIN
namespace Poco {
namespace Net {
StringPartSource::StringPartSource(const std::string& str):
@@ -79,4 +80,4 @@ const std::string& StringPartSource::filename()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// TCPServer.cpp
//
// $Id: //poco/1.1.0/Net/src/TCPServer.cpp#3 $
// $Id: //poco/1.2/Net/src/TCPServer.cpp#1 $
//
// Library: Net
// Package: TCPServer
@@ -34,33 +34,34 @@
//
#include "Net/TCPServer.h"
#include "Net/TCPServerDispatcher.h"
#include "Net/TCPServerConnection.h"
#include "Net/TCPServerConnectionFactory.h"
#include "Foundation/Timespan.h"
#include "Foundation/Exception.h"
#include "Foundation/ErrorHandler.h"
#include "Poco/Net/TCPServer.h"
#include "Poco/Net/TCPServerDispatcher.h"
#include "Poco/Net/TCPServerConnection.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Timespan.h"
#include "Poco/Exception.h"
#include "Poco/ErrorHandler.h"
using Foundation::ErrorHandler;
using Poco::ErrorHandler;
Net_BEGIN
namespace Poco {
namespace Net {
TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& socket, TCPServerParams* pParams):
_pDispatcher(new TCPServerDispatcher(pFactory, Foundation::ThreadPool::defaultPool(), pParams)),
_socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(socket)),
_stopped(false)
{
}
TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, Foundation::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams):
_pDispatcher(new TCPServerDispatcher(pFactory, threadPool, pParams)),
TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams):
_socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, threadPool, pParams)),
_thread(threadName(socket)),
_stopped(false)
{
@@ -103,7 +104,7 @@ void TCPServer::run()
{
while (!_stopped)
{
Foundation::Timespan timeout(250000);
Poco::Timespan timeout(250000);
if (_socket.poll(timeout, Socket::SELECT_READ))
{
try
@@ -111,7 +112,7 @@ void TCPServer::run()
StreamSocket ss = _socket.acceptConnection();
_pDispatcher->enqueue(ss);
}
catch (Foundation::Exception& exc)
catch (Poco::Exception& exc)
{
ErrorHandler::handle(exc);
}
@@ -172,4 +173,4 @@ std::string TCPServer::threadName(const ServerSocket& socket)
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// TCPServerConnection.cpp
//
// $Id: //poco/1.1.0/Net/src/TCPServerConnection.cpp#2 $
// $Id: //poco/1.2/Net/src/TCPServerConnection.cpp#1 $
//
// Library: Net
// Package: TCPServer
@@ -34,16 +34,17 @@
//
#include "Net/TCPServerConnection.h"
#include "Foundation/Exception.h"
#include "Foundation/ErrorHandler.h"
#include "Poco/Net/TCPServerConnection.h"
#include "Poco/Exception.h"
#include "Poco/ErrorHandler.h"
using Foundation::Exception;
using Foundation::ErrorHandler;
using Poco::Exception;
using Poco::ErrorHandler;
Net_BEGIN
namespace Poco {
namespace Net {
TCPServerConnection::TCPServerConnection(const StreamSocket& socket):
@@ -78,4 +79,4 @@ void TCPServerConnection::start()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// TCPServerConnectionFactory.cpp
//
// $Id: //poco/1.1.0/Net/src/TCPServerConnectionFactory.cpp#2 $
// $Id: //poco/1.2/Net/src/TCPServerConnectionFactory.cpp#1 $
//
// Library: Net
// Package: TCPServer
@@ -34,10 +34,11 @@
//
#include "Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
Net_BEGIN
namespace Poco {
namespace Net {
TCPServerConnectionFactory::TCPServerConnectionFactory()
@@ -50,4 +51,4 @@ TCPServerConnectionFactory::~TCPServerConnectionFactory()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// TCPServerDispatcher.cpp
//
// $Id: //poco/1.1.0/Net/src/TCPServerDispatcher.cpp#2 $
// $Id: //poco/1.2/Net/src/TCPServerDispatcher.cpp#1 $
//
// Library: Net
// Package: TCPServer
@@ -34,20 +34,21 @@
//
#include "Net/TCPServerDispatcher.h"
#include "Net/TCPServerConnectionFactory.h"
#include "Net/TCPServerParams.h"
#include "Foundation/Notification.h"
#include "Foundation/AutoPtr.h"
#include "Poco/Net/TCPServerDispatcher.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerParams.h"
#include "Poco/Notification.h"
#include "Poco/AutoPtr.h"
#include <memory>
using Foundation::Notification;
using Foundation::FastMutex;
using Foundation::AutoPtr;
using Poco::Notification;
using Poco::FastMutex;
using Poco::AutoPtr;
Net_BEGIN
namespace Poco {
namespace Net {
class TCPConnectionNotification: public Notification
@@ -72,7 +73,7 @@ private:
};
TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Foundation::ThreadPool& threadPool, TCPServerParams* pParams):
TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, TCPServerParams* pParams):
_rc(1),
_pParams(pParams),
_currentThreads(0),
@@ -165,7 +166,7 @@ void TCPServerDispatcher::enqueue(const StreamSocket& socket)
_threadPool.start(*this, threadName);
++_currentThreads;
}
catch (Foundation::Exception&)
catch (Poco::Exception&)
{
// no problem here, connection is already queued
// and a new thread might be available later.
@@ -252,4 +253,4 @@ void TCPServerDispatcher::endConnection()
}
Net_END
} } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
//
// TCPServerParams.cpp
//
// $Id: //poco/1.1.0/Net/src/TCPServerParams.cpp#2 $
// $Id: //poco/1.2/Net/src/TCPServerParams.cpp#1 $
//
// Library: Net
// Package: TCPServer
@@ -34,10 +34,11 @@
//
#include "Net/TCPServerParams.h"
#include "Poco/Net/TCPServerParams.h"
Net_BEGIN
namespace Poco {
namespace Net {
TCPServerParams::TCPServerParams():
@@ -53,7 +54,7 @@ TCPServerParams::~TCPServerParams()
}
void TCPServerParams::setThreadIdleTime(const Foundation::Timespan& milliseconds)
void TCPServerParams::setThreadIdleTime(const Poco::Timespan& milliseconds)
{
_threadIdleTime = milliseconds;
}
@@ -77,4 +78,4 @@ void TCPServerParams::setMaxQueued(int count)
Net_END
} } // namespace Poco::Net