Merge pull request #2 from pocoproject/develop

Updating develop branch
This commit is contained in:
Cristian Thiago Moecke 2014-03-10 10:29:52 -03:00
commit 6296635b72
22 changed files with 254 additions and 49 deletions

View File

@ -67,6 +67,9 @@ public:
const std::string& algorithm() const; const std::string& algorithm() const;
/// Returns the name of the digest algorithm. /// Returns the name of the digest algorithm.
int nid() const;
/// Returns the NID (OpenSSL object identifier) of the digest algorithm.
// DigestEngine // DigestEngine
std::size_t digestLength() const; std::size_t digestLength() const;
void reset(); void reset();

View File

@ -43,9 +43,7 @@
#include "Poco/Crypto/Crypto.h" #include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/RSAKey.h" #include "Poco/Crypto/RSAKey.h"
#include "Poco/DigestEngine.h" #include "Poco/DigestEngine.h"
#include "Poco/MD5Engine.h" #include "Poco/Crypto/DigestEngine.h"
#include "Poco/SHA1Engine.h"
#include <openssl/rsa.h>
#include <istream> #include <istream>
#include <ostream> #include <ostream>
@ -58,10 +56,10 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine
/// This class implements a Poco::DigestEngine that can be /// This class implements a Poco::DigestEngine that can be
/// used to compute a secure digital signature. /// used to compute a secure digital signature.
/// ///
/// First another Poco::DigestEngine (Poco::MD5Engine /// First another Poco::Crypto::DigestEngine is created and
/// or Poco::SHA1Engine) is used to compute a cryptographic /// used to compute a cryptographic hash of the data to be
/// hash of the data to be signed. Then, the hash value is /// signed. Then, the hash value is encrypted, using
/// encrypted, using the RSA private key. /// the RSA private key.
/// ///
/// To verify a signature, pass it to the verify() /// To verify a signature, pass it to the verify()
/// member function. It will decrypt the signature /// member function. It will decrypt the signature
@ -75,9 +73,19 @@ public:
DIGEST_SHA1 DIGEST_SHA1
}; };
//@ deprecated
RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1); RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
/// Creates the RSADigestEngine with the given RSA key, /// Creates the RSADigestEngine with the given RSA key,
/// using the SHA-1 hash algorithm. /// using the MD5 or SHA-1 hash algorithm.
/// Kept for backward compatibility
RSADigestEngine(const RSAKey& key, const std::string &name);
/// Creates the RSADigestEngine with the given RSA key,
/// using the hash algorithm with the given name
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
/// See the OpenSSL documentation for a list of supported digest algorithms.
///
/// Throws a Poco::NotFoundException if no algorithm with the given name exists.
~RSADigestEngine(); ~RSADigestEngine();
/// Destroys the RSADigestEngine. /// Destroys the RSADigestEngine.
@ -113,12 +121,9 @@ protected:
private: private:
RSAKey _key; RSAKey _key;
Poco::DigestEngine& _engine; Poco::Crypto::DigestEngine _engine;
int _type;
Poco::DigestEngine::Digest _digest; Poco::DigestEngine::Digest _digest;
Poco::DigestEngine::Digest _signature; Poco::DigestEngine::Digest _signature;
Poco::MD5Engine _md5Engine;
Poco::SHA1Engine _sha1Engine;
}; };

View File

@ -57,6 +57,10 @@ DigestEngine::~DigestEngine()
EVP_MD_CTX_destroy(_ctx); EVP_MD_CTX_destroy(_ctx);
} }
int DigestEngine::nid() const
{
return EVP_MD_nid(_ctx->digest);
}
std::size_t DigestEngine::digestLength() const std::size_t DigestEngine::digestLength() const
{ {

View File

@ -35,7 +35,7 @@
#include "Poco/Crypto/RSADigestEngine.h" #include "Poco/Crypto/RSADigestEngine.h"
#include <openssl/pem.h> #include <openssl/rsa.h>
namespace Poco { namespace Poco {
@ -44,8 +44,13 @@ namespace Crypto {
RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType): RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType):
_key(key), _key(key),
_engine(digestType == DIGEST_MD5 ? static_cast<Poco::DigestEngine&>(_md5Engine) : static_cast<Poco::DigestEngine&>(_sha1Engine)), _engine(digestType == DIGEST_MD5 ? "MD5" : "SHA1")
_type(digestType == DIGEST_MD5 ? NID_md5 : NID_sha1) {
}
RSADigestEngine::RSADigestEngine(const RSAKey& key, const std::string &name):
_key(key),
_engine(name)
{ {
} }
@ -86,7 +91,7 @@ const DigestEngine::Digest& RSADigestEngine::signature()
digest(); digest();
_signature.resize(_key.size()); _signature.resize(_key.size());
unsigned sigLen = static_cast<unsigned>(_signature.size()); unsigned sigLen = static_cast<unsigned>(_signature.size());
RSA_sign(_type, &_digest[0], static_cast<unsigned>(_digest.size()), &_signature[0], &sigLen, _key.impl()->getRSA()); RSA_sign(_engine.nid(), &_digest[0], static_cast<unsigned>(_digest.size()), &_signature[0], &sigLen, _key.impl()->getRSA());
// truncate _sig to sigLen // truncate _sig to sigLen
if (sigLen < _signature.size()) if (sigLen < _signature.size())
_signature.resize(sigLen); _signature.resize(sigLen);
@ -99,7 +104,7 @@ bool RSADigestEngine::verify(const DigestEngine::Digest& sig)
{ {
digest(); digest();
DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy
int ret = RSA_verify(_type, &_digest[0], static_cast<unsigned>(_digest.size()), &sigCpy[0], static_cast<unsigned>(sigCpy.size()), _key.impl()->getRSA()); int ret = RSA_verify(_engine.nid(), &_digest[0], static_cast<unsigned>(_digest.size()), &sigCpy[0], static_cast<unsigned>(sigCpy.size()), _key.impl()->getRSA());
return ret != 0; return ret != 0;
} }

View File

@ -149,6 +149,27 @@ void RSATest::testSign()
} }
void RSATest::testSignSha256()
{
std::string msg("Test this sign message");
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
RSADigestEngine eng(key,"SHA256");
eng.update(msg.c_str(), static_cast<unsigned>(msg.length()));
const Poco::DigestEngine::Digest& sig = eng.signature();
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
// verify
std::ostringstream strPub;
key.save(&strPub);
std::string pubKey = strPub.str();
std::istringstream iPub(pubKey);
RSAKey keyPub(&iPub);
RSADigestEngine eng2(key,"SHA256");
eng2.update(msg.c_str(), static_cast<unsigned>(msg.length()));
assert (eng2.verify(sig));
}
void RSATest::testSignManipulated() void RSATest::testSignManipulated()
{ {
std::string msg("Test this sign message"); std::string msg("Test this sign message");
@ -244,6 +265,7 @@ CppUnit::Test* RSATest::suite()
CppUnit_addTest(pSuite, RSATest, testNewKeys); CppUnit_addTest(pSuite, RSATest, testNewKeys);
CppUnit_addTest(pSuite, RSATest, testSign); CppUnit_addTest(pSuite, RSATest, testSign);
CppUnit_addTest(pSuite, RSATest, testSignSha256);
CppUnit_addTest(pSuite, RSATest, testSignManipulated); CppUnit_addTest(pSuite, RSATest, testSignManipulated);
CppUnit_addTest(pSuite, RSATest, testRSACipher); CppUnit_addTest(pSuite, RSATest, testRSACipher);
CppUnit_addTest(pSuite, RSATest, testRSACipherLarge); CppUnit_addTest(pSuite, RSATest, testRSACipherLarge);

View File

@ -48,6 +48,7 @@ public:
void testNewKeys(); void testNewKeys();
void testSign(); void testSign();
void testSignSha256();
void testSignManipulated(); void testSignManipulated();
void testRSACipher(); void testRSACipher();
void testRSACipherLarge(); void testRSACipherLarge();

View File

@ -788,7 +788,11 @@ inline bool Var::isEmpty() const
inline bool Var::isArray() const inline bool Var::isArray() const
{ {
return !isEmpty() && !isString(); if (isEmpty() ||
isString()) return false;
VarHolder* pHolder = content();
return pHolder ? pHolder->isArray() : false;
} }

View File

@ -72,7 +72,7 @@
#elif defined(_AIX) || defined(__TOS_AIX__) #elif defined(_AIX) || defined(__TOS_AIX__)
#define POCO_OS_FAMILY_UNIX 1 #define POCO_OS_FAMILY_UNIX 1
#define POCO_OS POCO_OS_AIX #define POCO_OS POCO_OS_AIX
#elif defined(hpux) || defined(_hpux) #elif defined(hpux) || defined(_hpux) || defined(__hpux)
#define POCO_OS_FAMILY_UNIX 1 #define POCO_OS_FAMILY_UNIX 1
#define POCO_OS POCO_OS_HPUX #define POCO_OS POCO_OS_HPUX
#elif defined(__digital__) || defined(__osf__) #elif defined(__digital__) || defined(__osf__)

View File

@ -1863,22 +1863,22 @@ void VarTest::testIsArray()
assert (!d0.isArray()); assert (!d0.isArray());
assert (!d1.isArray()); assert (!d1.isArray());
assert (d2.isArray()); assert (!d2.isArray());
assert (d3.isArray()); assert (!d3.isArray());
assert (d4.isArray()); assert (!d4.isArray());
assert (d5.isArray()); assert (!d5.isArray());
assert (d6.isArray()); assert (!d6.isArray());
assert (d7.isArray()); assert (!d7.isArray());
assert (d8.isArray()); assert (!d8.isArray());
assert (d9.isArray()); assert (!d9.isArray());
assert (d10.isArray()); assert (!d10.isArray());
assert (d11.isArray()); assert (!d11.isArray());
assert (d12.isArray()); assert (!d12.isArray());
assert (d13.isArray()); assert (!d13.isArray());
assert (d14.isArray()); assert (!d14.isArray());
assert (d15.isArray()); assert (!d15.isArray());
assert (d16.isArray()); assert (d16.isArray());
assert (d17.isArray()); assert (!d17.isArray());
} }

View File

@ -1,7 +1,7 @@
// //
// HTTPCookie.h // HTTPCookie.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPCookie.h#1 $ // $Id: //poco/1.4/Net/include/Poco/Net/HTTPCookie.h#2 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
@ -140,9 +140,15 @@ public:
void setPath(const std::string& path); void setPath(const std::string& path);
/// Sets the path for the cookie. /// Sets the path for the cookie.
void setPriority(const std::string& priority);
/// Sets the priority for the cookie.
const std::string& getPath() const; const std::string& getPath() const;
/// Returns the path for the cookie. /// Returns the path for the cookie.
const std::string& getPriority() const;
/// Returns the priority for the cookie.
void setSecure(bool secure); void setSecure(bool secure);
/// Sets the value of the secure flag for /// Sets the value of the secure flag for
/// the cookie. /// the cookie.
@ -210,6 +216,7 @@ private:
std::string _comment; std::string _comment;
std::string _domain; std::string _domain;
std::string _path; std::string _path;
std::string _priority;
bool _secure; bool _secure;
int _maxAge; int _maxAge;
bool _httpOnly; bool _httpOnly;
@ -255,6 +262,12 @@ inline const std::string& HTTPCookie::getPath() const
} }
inline const std::string& HTTPCookie::getPriority() const
{
return _priority;
}
inline bool HTTPCookie::getSecure() const inline bool HTTPCookie::getSecure() const
{ {
return _secure; return _secure;

View File

@ -162,6 +162,9 @@ public:
int currentThreads() const; int currentThreads() const;
/// Returns the number of currently used connection threads. /// Returns the number of currently used connection threads.
int maxThreads() const;
/// Returns the maximum number of threads available.
int totalConnections() const; int totalConnections() const;
/// Returns the total number of handled connections. /// Returns the total number of handled connections.

View File

@ -86,6 +86,9 @@ public:
int currentThreads() const; int currentThreads() const;
/// Returns the number of currently used threads. /// Returns the number of currently used threads.
int maxThreads() const;
/// Returns the maximum number of threads available.
int totalConnections() const; int totalConnections() const;
/// Returns the total number of handled connections. /// Returns the total number of handled connections.

View File

@ -1,7 +1,7 @@
// //
// HTTPCookie.cpp // HTTPCookie.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPCookie.cpp#1 $ // $Id: //poco/1.4/Net/src/HTTPCookie.cpp#3 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
@ -102,6 +102,10 @@ HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
{ {
setPath(value); setPath(value);
} }
else if (icompare(name, "priority") == 0)
{
setPriority(value);
}
else if (icompare(name, "max-age") == 0) else if (icompare(name, "max-age") == 0)
{ {
setMaxAge(NumberParser::parse(value)); setMaxAge(NumberParser::parse(value));
@ -152,6 +156,7 @@ HTTPCookie::HTTPCookie(const HTTPCookie& cookie):
_comment(cookie._comment), _comment(cookie._comment),
_domain(cookie._domain), _domain(cookie._domain),
_path(cookie._path), _path(cookie._path),
_priority(cookie._priority),
_secure(cookie._secure), _secure(cookie._secure),
_maxAge(cookie._maxAge), _maxAge(cookie._maxAge),
_httpOnly(cookie._httpOnly) _httpOnly(cookie._httpOnly)
@ -174,6 +179,7 @@ HTTPCookie& HTTPCookie::operator = (const HTTPCookie& cookie)
_comment = cookie._comment; _comment = cookie._comment;
_domain = cookie._domain; _domain = cookie._domain;
_path = cookie._path; _path = cookie._path;
_priority = cookie._priority;
_secure = cookie._secure; _secure = cookie._secure;
_maxAge = cookie._maxAge; _maxAge = cookie._maxAge;
_httpOnly = cookie._httpOnly; _httpOnly = cookie._httpOnly;
@ -218,6 +224,12 @@ void HTTPCookie::setPath(const std::string& path)
} }
void HTTPCookie::setPriority(const std::string& priority)
{
_priority = priority;
}
void HTTPCookie::setSecure(bool secure) void HTTPCookie::setSecure(bool secure)
{ {
_secure = secure; _secure = secure;
@ -256,6 +268,11 @@ std::string HTTPCookie::toString() const
result.append("; path="); result.append("; path=");
result.append(_path); result.append(_path);
} }
if (!_priority.empty())
{
result.append("; Priority=");
result.append(_priority);
}
if (_maxAge != -1) if (_maxAge != -1)
{ {
Timestamp ts; Timestamp ts;
@ -296,6 +313,13 @@ std::string HTTPCookie::toString() const
result.append(_path); result.append(_path);
result.append("\""); result.append("\"");
} }
if (!_priority.empty())
{
result.append("; Priority=\"");
result.append(_priority);
result.append("\"");
}
if (_maxAge != -1) if (_maxAge != -1)
{ {
result.append("; Max-Age=\""); result.append("; Max-Age=\"");

View File

@ -102,15 +102,17 @@ namespace
Poco::StreamCopier::copyToString(stream, tmp); Poco::StreamCopier::copyToString(stream, tmp);
if (_pMsg) if (_pMsg)
{ {
MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT; MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT;
std::string enc = header[MailMessage::HEADER_CONTENT_TRANSFER_ENCODING]; if (header.has(MailMessage::HEADER_CONTENT_TRANSFER_ENCODING))
if (enc == MailMessage::CTE_8BIT) {
cte = MailMessage::ENCODING_8BIT; std::string enc = header[MailMessage::HEADER_CONTENT_TRANSFER_ENCODING];
else if (enc == MailMessage::CTE_QUOTED_PRINTABLE) if (enc == MailMessage::CTE_8BIT)
cte = MailMessage::ENCODING_QUOTED_PRINTABLE; cte = MailMessage::ENCODING_8BIT;
else if (enc == MailMessage::CTE_BASE64) else if (enc == MailMessage::CTE_QUOTED_PRINTABLE)
cte = MailMessage::ENCODING_BASE64; cte = MailMessage::ENCODING_QUOTED_PRINTABLE;
else if (enc == MailMessage::CTE_BASE64)
cte = MailMessage::ENCODING_BASE64;
}
NameValueCollection::ConstIterator it = header.begin(); NameValueCollection::ConstIterator it = header.begin();
NameValueCollection::ConstIterator end = header.end(); NameValueCollection::ConstIterator end = header.end();

View File

@ -52,19 +52,25 @@ namespace Net {
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::UInt16 portNumber, TCPServerParams::Ptr pParams): TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::UInt16 portNumber, TCPServerParams::Ptr pParams):
_socket(ServerSocket(portNumber)), _socket(ServerSocket(portNumber)),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(_socket)), _thread(threadName(_socket)),
_stopped(true) _stopped(true)
{ {
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
if(pParams) pool.addCapacity(pParams->getMaxThreads() - pool.capacity());
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
} }
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams): TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams):
_socket(socket), _socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(socket)), _thread(threadName(socket)),
_stopped(true) _stopped(true)
{ {
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
if(pParams) pool.addCapacity(pParams->getMaxThreads() - pool.capacity());
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
} }
@ -146,6 +152,11 @@ int TCPServer::currentThreads() const
return _pDispatcher->currentThreads(); return _pDispatcher->currentThreads();
} }
int TCPServer::maxThreads() const
{
return _pDispatcher->maxThreads();
}
int TCPServer::totalConnections() const int TCPServer::totalConnections() const
{ {

View File

@ -197,6 +197,13 @@ int TCPServerDispatcher::currentThreads() const
return _currentThreads; return _currentThreads;
} }
int TCPServerDispatcher::maxThreads() const
{
FastMutex::ScopedLock lock(_mutex);
return _threadPool.capacity();
}
int TCPServerDispatcher::totalConnections() const int TCPServerDispatcher::totalConnections() const
{ {

View File

@ -1,7 +1,7 @@
// //
// HTTPCookieTest.cpp // HTTPCookieTest.cpp
// //
// $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.cpp#1 $ // $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.cpp#2 $
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@ -44,6 +44,7 @@
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
using Poco::Timestamp; using Poco::Timestamp;
using Poco::Timespan; using Poco::Timespan;
using Poco::DateTimeFormatter; using Poco::DateTimeFormatter;
@ -80,6 +81,13 @@ void HTTPCookieTest::testCookie()
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure"); assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure");
cookie.setHttpOnly(true); cookie.setHttpOnly(true);
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure; HttpOnly"); assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure; HttpOnly");
cookie.setPriority("Low");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Low; secure; HttpOnly");
cookie.setPriority("Medium");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Medium; secure; HttpOnly");
cookie.setPriority("High");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=High; secure; HttpOnly");
cookie.setPriority("");
cookie.setHttpOnly(false); cookie.setHttpOnly(false);
cookie.setVersion(1); cookie.setVersion(1);
@ -91,6 +99,13 @@ void HTTPCookieTest::testCookie()
cookie.setHttpOnly(true); cookie.setHttpOnly(true);
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\""); assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("Low");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Low\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("Medium");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Medium\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("High");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"High\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
} }

View File

@ -1,7 +1,7 @@
// //
// HTTPCookieTest.h // HTTPCookieTest.h
// //
// $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.h#1 $ // $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.h#2 $
// //
// Definition of the HTTPCookieTest class. // Definition of the HTTPCookieTest class.
// //

View File

@ -358,6 +358,31 @@ void MailMessageTest::testReadQP()
} }
void MailMessageTest::testReadDefaultTransferEncoding()
{
std::istringstream istr(
"Content-Type: text/plain\r\n"
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"From: poco@appinf.com\r\n"
"Subject: Test Message\r\n"
"To: John Doe <john.doe@no.where>\r\n"
"\r\n"
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
);
MailMessage message;
message.read(istr);
assert (message.getSender() == "poco@appinf.com");
assert (message.getContentType() == "text/plain");
assert (message.getContent() ==
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
);
}
void MailMessageTest::testRead8Bit() void MailMessageTest::testRead8Bit()
{ {
std::istringstream istr( std::istringstream istr(
@ -426,6 +451,47 @@ void MailMessageTest::testReadMultiPart()
} }
void MailMessageTest::testReadMultiPartDefaultTransferEncoding()
{
std::istringstream istr(
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"From: poco@appinf.com\r\n"
"Mime-Version: 1.0\r\n"
"Subject: Test Message\r\n"
"To: John Doe <john.doe@no.where>\r\n"
"\r\n"
"\r\n"
"--MIME_boundary_01234567\r\n"
"Content-Disposition: inline\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"Hello World!\r\n"
"\r\n"
"--MIME_boundary_01234567\r\n"
"Content-Disposition: attachment; filename=sample.dat\r\n"
"Content-Transfer-Encoding: base64\r\n"
"Content-Type: application/octet-stream; name=sample\r\n"
"\r\n"
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
"--MIME_boundary_01234567--\r\n"
);
StringPartHandler handler;
MailMessage message;
message.read(istr, handler);
assert (handler.data().size() == 2);
assert (handler.data()[0] == "Hello World!\r\n");
assert (handler.type()[0] == "text/plain");
assert (handler.disp()[0] == "inline");
assert (handler.data()[1] == "This is some binary data. Really.");
assert (handler.type()[1] == "application/octet-stream; name=sample");
assert (handler.disp()[1] == "attachment; filename=sample.dat");
}
void MailMessageTest::testReadWriteMultiPart() void MailMessageTest::testReadWriteMultiPart()
{ {
std::string msgin( std::string msgin(
@ -573,8 +639,10 @@ CppUnit::Test* MailMessageTest::suite()
CppUnit_addTest(pSuite, MailMessageTest, testWriteManyRecipients); CppUnit_addTest(pSuite, MailMessageTest, testWriteManyRecipients);
CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart); CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testReadQP); CppUnit_addTest(pSuite, MailMessageTest, testReadQP);
CppUnit_addTest(pSuite, MailMessageTest, testReadDefaultTransferEncoding);
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit); CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart); CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartDefaultTransferEncoding);
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPart); CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPartStore); CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPartStore);
CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord); CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord);

View File

@ -53,9 +53,11 @@ public:
void testWriteMultiPart(); void testWriteMultiPart();
void testReadWriteMultiPart(); void testReadWriteMultiPart();
void testReadWriteMultiPartStore(); void testReadWriteMultiPartStore();
void testReadDefaultTransferEncoding();
void testReadQP(); void testReadQP();
void testRead8Bit(); void testRead8Bit();
void testReadMultiPart(); void testReadMultiPart();
void testReadMultiPartDefaultTransferEncoding();
void testEncodeWord(); void testEncodeWord();
void setUp(); void setUp();

View File

@ -175,6 +175,7 @@ void TCPServerTest::testMultiConnections()
srv.start(); srv.start();
assert (srv.currentConnections() == 0); assert (srv.currentConnections() == 0);
assert (srv.currentThreads() == 0); assert (srv.currentThreads() == 0);
assert (srv.maxThreads() >= 4);
assert (srv.queuedConnections() == 0); assert (srv.queuedConnections() == 0);
assert (srv.totalConnections() == 0); assert (srv.totalConnections() == 0);
@ -252,6 +253,16 @@ void TCPServerTest::testMultiConnections()
assert (srv.currentConnections() == 0); assert (srv.currentConnections() == 0);
} }
void TCPServerTest::testThreadCapacity(){
ServerSocket svs(0);
TCPServerParams* pParams = new TCPServerParams;
pParams->setMaxThreads(64);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs, pParams);
srv.start();
assert (srv.maxThreads() >= 64);
}
void TCPServerTest::setUp() void TCPServerTest::setUp()
{ {
@ -270,6 +281,7 @@ CppUnit::Test* TCPServerTest::suite()
CppUnit_addTest(pSuite, TCPServerTest, testOneConnection); CppUnit_addTest(pSuite, TCPServerTest, testOneConnection);
CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections); CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections);
CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections); CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections);
CppUnit_addTest(pSuite, TCPServerTest, testThreadCapacity);
return pSuite; return pSuite;
} }

View File

@ -49,6 +49,7 @@ public:
void testOneConnection(); void testOneConnection();
void testTwoConnections(); void testTwoConnections();
void testMultiConnections(); void testMultiConnections();
void testThreadCapacity();
void setUp(); void setUp();
void tearDown(); void tearDown();