Merge branch 'poco-1.8.0' of https://github.com/pocoproject/poco into poco-1.8.0

This commit is contained in:
Günter Obiltschnig 2017-11-08 12:03:09 +01:00
commit 253c46f305
9 changed files with 93 additions and 24 deletions

View File

@ -28,7 +28,7 @@
// from a DLL simpler. All files within this DLL are compiled with the MongoDB_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// MongoDB_API functions as being imported from a DLL, wheras this DLL sees symbols
// MongoDB_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//

View File

@ -47,7 +47,7 @@ public:
explicit ObjectId(const std::string& id);
/// Creates an ObjectId from a string.
///
/// The string must contain a hexidecimal representation
/// The string must contain a hexadecimal representation
/// of an object ID. This means a string of 24 characters.
ObjectId(const ObjectId& copy);

View File

@ -28,24 +28,38 @@ namespace Poco {
template<>
class PoolableObjectFactory<MongoDB::Connection, MongoDB::Connection::Ptr>
/// PoolableObjectFactory specialisation for Connection. New connections
/// are created with the given address.
/// are created with the given address or URI.
///
/// If a Connection::SocketFactory is given, it must live for the entire
/// lifetime of the PoolableObjectFactory.
{
public:
PoolableObjectFactory(Net::SocketAddress& address):
_address(address)
_address(address),
_pSocketFactory(0)
{
}
PoolableObjectFactory(const std::string& address):
_address(address)
_address(address),
_pSocketFactory(0)
{
}
PoolableObjectFactory(const std::string& uri, MongoDB::Connection::SocketFactory& socketFactory):
_uri(uri),
_pSocketFactory(&socketFactory)
{
}
MongoDB::Connection::Ptr createObject()
{
return new MongoDB::Connection(_address);
if (_pSocketFactory)
return new MongoDB::Connection(_uri, *_pSocketFactory);
else
return new MongoDB::Connection(_address);
}
bool validateObject(MongoDB::Connection::Ptr pObject)
{
return true;
@ -65,6 +79,8 @@ public:
private:
Net::SocketAddress _address;
std::string _uri;
MongoDB::Connection::SocketFactory* _pSocketFactory;
};
@ -84,7 +100,10 @@ public:
{
try
{
_pool.returnObject(_connection);
if (_connection)
{
_pool.returnObject(_connection);
}
}
catch (...)
{

View File

@ -52,7 +52,7 @@ private:
};
#endif // MongoDB_ReplicaSet_INCLUDED
} } // namespace Poco::MongoDB
#endif // MongoDB_ReplicaSet_INCLUDED

View File

@ -152,35 +152,38 @@ void Connection::connect(const std::string& uri, SocketFactory& socketFactory)
std::string host = theURI.getHost();
Poco::UInt16 port = theURI.getPort();
if (port == 0) port = 27017;
std::string databaseName = theURI.getPath();
if (!databaseName.empty() && databaseName[0] == '/') databaseName.erase(0, 1);
if (databaseName.empty()) databaseName = "admin";
bool secure = false;
bool ssl = false;
Poco::Timespan connectTimeout;
Poco::Timespan socketTimeout;
std::string authMethod = Database::AUTH_SCRAM_SHA1;
std::string authMechanism = Database::AUTH_SCRAM_SHA1;
Poco::URI::QueryParameters params = theURI.getQueryParameters();
for (Poco::URI::QueryParameters::const_iterator it = params.begin(); it != params.end(); ++it)
{
if (it->first == "ssl")
{
secure = (it->second == "true");
ssl = (it->second == "true");
}
else if (it->first == "connectTimeoutMS")
{
connectTimeout = 1000*Poco::NumberParser::parse(it->second);
connectTimeout = static_cast<Poco::Timespan::TimeDiff>(1000)*Poco::NumberParser::parse(it->second);
}
else if (it->first == "socketTimeoutMS")
{
socketTimeout = 1000*Poco::NumberParser::parse(it->second);
socketTimeout = static_cast<Poco::Timespan::TimeDiff>(1000)*Poco::NumberParser::parse(it->second);
}
else if (it->first == "authMechanism")
{
authMethod = it->second;
authMechanism = it->second;
}
}
connect(socketFactory.createSocket(host, port, connectTimeout, secure));
connect(socketFactory.createSocket(host, port, connectTimeout, ssl));
if (socketTimeout > 0)
{
@ -201,7 +204,7 @@ void Connection::connect(const std::string& uri, SocketFactory& socketFactory)
else username = userInfo;
Database database(databaseName);
if (!database.authenticate(*this, username, password, authMethod))
if (!database.authenticate(*this, username, password, authMechanism))
throw Poco::NoPermissionException(Poco::format("Access to MongoDB database %s denied for user %s", databaseName, username));
}
}

View File

@ -57,7 +57,7 @@ Int64 Document::getInteger(const std::string& name) const
if (ElementTraits<double>::TypeId == element->type())
{
ConcreteElement<double>* concrete = dynamic_cast<ConcreteElement<double>*>(element.get());
if (concrete) return concrete->value();
if (concrete) return static_cast<Int64>(concrete->value());
}
else if (ElementTraits<Int32>::TypeId == element->type())
{

View File

@ -33,7 +33,7 @@ KillCursorsRequest::~KillCursorsRequest()
void KillCursorsRequest::buildRequest(BinaryWriter& writer)
{
writer << 0; // 0 - reserved for future use
writer << _cursors.size();
writer << static_cast<Poco::UInt64>(_cursors.size());
for (std::vector<Int64>::iterator it = _cursors.begin(); it != _cursors.end(); ++it)
{
writer << *it;

View File

@ -221,10 +221,10 @@ void MongoDBTest::testDeleteRequest()
void MongoDBTest::testCursorRequest()
{
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::DeleteRequest> deleteRequest = db.createDeleteRequest("numbers");
_mongo->sendRequest(*deleteRequest);
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
@ -243,7 +243,7 @@ void MongoDBTest::testCursorRequest()
Poco::MongoDB::ResponseMessage& response = cursor.next(*_mongo);
while(1)
{
n += response.documents().size();
n += static_cast<int>(response.documents().size());
if ( response.cursorID() == 0 )
break;
response = cursor.next(*_mongo);
@ -395,6 +395,51 @@ void MongoDBTest::testUUID()
}
void MongoDBTest::testConnectURI()
{
Poco::MongoDB::Connection conn;
Poco::MongoDB::Connection::SocketFactory sf;
conn.connect("mongodb://127.0.0.1", sf);
conn.disconnect();
try
{
conn.connect("http://127.0.0.1", sf);
fail("invalid URI scheme - must throw");
}
catch (Poco::UnknownURISchemeException&)
{
}
try
{
conn.connect("mongodb://127.0.0.1?ssl=true", sf);
fail("SSL not supported, must throw");
}
catch (Poco::NotImplementedException&)
{
}
conn.connect("mongodb://127.0.0.1/admin?ssl=false&connectTimeoutMS=10000&socketTimeoutMS=10000", sf);
conn.disconnect();
try
{
conn.connect("mongodb://127.0.0.1/admin?connectTimeoutMS=foo", sf);
fail("invalid parameter - must throw");
}
catch (Poco::Exception&)
{
}
#ifdef MONGODB_TEST_AUTH
conn.connect("mongodb://admin:admin@127.0.0.1/admin", sf);
conn.disconnect();
#endif
}
CppUnit::Test* MongoDBTest::suite()
{
try
@ -423,6 +468,7 @@ CppUnit::Test* MongoDBTest::suite()
CppUnit_addTest(pSuite, MongoDBTest, testObjectID);
CppUnit_addTest(pSuite, MongoDBTest, testCommand);
CppUnit_addTest(pSuite, MongoDBTest, testUUID);
CppUnit_addTest(pSuite, MongoDBTest, testConnectURI);
return pSuite;
}

View File

@ -39,6 +39,7 @@ public:
void testObjectID();
void testCommand();
void testUUID();
void testConnectURI();
void setUp();
void tearDown();