summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-02 21:26:31 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-02 21:26:31 +0000
commit1eaf76d711c2da04b925f381d77fbb5e4c7ed898 (patch)
treeb6d1ccd33036014e3485dcc4410ec32cd9c8bbaf
parentPropergate connection error details into DB::Error and add test (diff)
downloadlibdbpp-postgresql-1eaf76d711c2da04b925f381d77fbb5e4c7ed898.tar.bz2
libdbpp-postgresql-1eaf76d711c2da04b925f381d77fbb5e4c7ed898.tar.xz
libdbpp-postgresql-1eaf76d711c2da04b925f381d77fbb5e4c7ed898.zip
Check for libpq thread safety, disable libcrypto init (fixes crashes with multiple ssl connections) add test
-rw-r--r--libpqpp/connection.cpp8
-rw-r--r--libpqpp/connection.h3
-rw-r--r--libpqpp/unittests/testpq.cpp11
3 files changed, 21 insertions, 1 deletions
diff --git a/libpqpp/connection.cpp b/libpqpp/connection.cpp
index 51aac63..e47d846 100644
--- a/libpqpp/connection.cpp
+++ b/libpqpp/connection.cpp
@@ -3,9 +3,17 @@
#include "selectcommand.h"
#include "modifycommand.h"
#include <unistd.h>
+#include <boost/assert.hpp>
NAMEDFACTORY("postgresql", PQ::Connection, DB::ConnectionFactory);
+static void setup() __attribute__((constructor(101)));
+static void setup()
+{
+ BOOST_ASSERT(PQisthreadsafe() == 1);
+ PQinitOpenSSL(1, 0);
+}
+
static void
noNoticeProcessor(void *, const char *)
{
diff --git a/libpqpp/connection.h b/libpqpp/connection.h
index 40fb00e..618c875 100644
--- a/libpqpp/connection.h
+++ b/libpqpp/connection.h
@@ -3,9 +3,10 @@
#include <connection.h>
#include <libpq-fe.h>
+#include <visibility.h>
namespace PQ {
- class Connection : public DB::Connection {
+ class DLL_PUBLIC Connection : public DB::Connection {
public:
Connection(const std::string & info);
~Connection();
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index 5dc4b2d..002b18c 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -10,6 +10,7 @@
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "../error.h"
+#include "../connection.h"
class StandardMockDatabase : public PQ::Mock {
public:
@@ -175,3 +176,13 @@ BOOST_AUTO_TEST_CASE( connfail )
BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("postgresql", "host=localhost user=no"), PQ::ConnectionError);
}
+BOOST_AUTO_TEST_CASE( ssl )
+{
+ auto conn = DB::ConnectionFactory::createNew("postgresql", "host=randomdan.homeip.net user=gentoo dbname=postgres sslmode=require");
+ BOOST_REQUIRE(conn);
+ auto pqconn = dynamic_cast<PQ::Connection *>(conn);
+ BOOST_REQUIRE(pqconn);
+ BOOST_REQUIRE(PQgetssl(pqconn->conn));
+ delete conn;
+}
+