Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[poco] fix PocoNetSSL and PocoNetSSLWin simultaneous usage under Windows #4205

Merged
merged 18 commits into from
Feb 15, 2021
Merged
22 changes: 13 additions & 9 deletions recipes/poco/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import os


required_conan_version = ">=1.32.0"


class PocoConan(ConanFile):
name = "poco"
url = "https://github.com/conan-io/conan-center-index"
Expand Down Expand Up @@ -95,6 +98,7 @@ def source(self):
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.enable_netssl
else:
del self.options.enable_netssl_win
if tools.Version(self.version) < "1.9":
Expand All @@ -104,7 +108,7 @@ def config_options(self):
del self.options.enable_data_postgresql
del self.options.enable_jwt

def configure(self):
def validate(self):
if self.options.enable_apacheconnector:
raise ConanInvalidConfiguration("Apache connector not supported: https://github.com/pocoproject/poco/issues/1764")
if self.settings.compiler == "Visual Studio":
Expand All @@ -119,27 +123,30 @@ def configure(self):
continue
if not self.options.get_safe(self._poco_component_tree[compdep].option, False):
raise ConanInvalidConfiguration("option {} requires also option {}".format(compopt.option, self._poco_component_tree[compdep].option))
if self.options.enable_data_sqlite:
if self.options["sqlite3"].threadsafe == 0:
raise ConanInvalidConfiguration("sqlite3 must be built with threadsafe enabled")

def requirements(self):
self.requires("pcre/8.41")
self.requires("pcre/8.44")
self.requires("zlib/1.2.11")
if self.options.enable_xml:
self.requires("expat/2.2.10")
if self.options.enable_data_sqlite:
self.requires("sqlite3/3.33.0")
self.requires("sqlite3/3.34.0")
if self.options.enable_apacheconnector:
self.requires("apr/1.7.0")
self.requires("apr-util/1.6.1")
# FIXME: missing apache2 recipe
raise ConanInvalidConfiguration("apache2 is not (yet) available on CCI")
if self.options.enable_netssl or \
if self.options.get_safe("enable_netssl", False) or \
self.options.enable_crypto or \
self.options.get_safe("enable_jwt", False):
self.requires("openssl/1.1.1h")
self.requires("openssl/1.1.1i")
if self.options.enable_data_odbc and self.settings.os != "Windows":
self.requires("odbc/2.3.7")
if self.options.get_safe("enable_data_postgresql", False):
self.requires("libpq/11.5")
self.requires("libpq/13.1")
if self.options.get_safe("enable_data_mysql", False):
self.requires("apr/1.7.0")
self.requires('apr-util/1.6.1')
Expand Down Expand Up @@ -186,9 +193,6 @@ def _configure_cmake(self):
return self._cmake

def build(self):
if self.options.enable_data_sqlite:
if self.options["sqlite3"].threadsafe == 0:
raise ConanInvalidConfiguration("sqlite3 must be built with threadsafe enabled")
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()
Expand Down
23 changes: 15 additions & 8 deletions recipes/poco/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

@property
def _with_netssl(self):
return (
("enable_netssl" in self.options["poco"] and self.options["poco"].enable_netssl) or
("enable_netssl_win" in self.options["poco"] and self.options["poco"].enable_netssl_win)
)

@property
def _with_encodings(self):
return "enable_encodings" in self.options["poco"] and self.options["poco"].enable_encodings == True
return "enable_encodings" in self.options["poco"] and self.options["poco"].enable_encodings

@property
def _with_jwt(self):
return "enable_jwt" in self.options["poco"] and self.options["poco"].enable_jwt == True
return "enable_jwt" in self.options["poco"] and self.options["poco"].enable_jwt

def build(self):
cmake = CMake(self)
cmake.definitions["TEST_CRYPTO"] = self.options["poco"].enable_crypto == True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

cmake.definitions["TEST_UTIL"] = self.options["poco"].enable_util == True
cmake.definitions["TEST_NET"] = self.options["poco"].enable_net == True
cmake.definitions["TEST_NETSSL"] = self.options["poco"].enable_netssl == True
cmake.definitions["TEST_SQLITE"] = self.options["poco"].enable_data_sqlite == True
cmake.definitions["TEST_CRYPTO"] = self.options["poco"].enable_crypto
cmake.definitions["TEST_UTIL"] = self.options["poco"].enable_util
cmake.definitions["TEST_NET"] = self.options["poco"].enable_net
cmake.definitions["TEST_NETSSL"] = self._with_netssl
cmake.definitions["TEST_SQLITE"] = self.options["poco"].enable_data_sqlite
cmake.definitions["TEST_ENCODINGS"] = self._with_encodings
cmake.definitions["TEST_JWT"] = self._with_jwt
cmake.configure()
Expand All @@ -36,7 +43,7 @@ def test(self):
if self.options["poco"].enable_net:
self.run(os.path.join("bin", "net"), run_environment=True)
self.run(os.path.join("bin", "net_2"), run_environment=True)
if self.options["poco"].enable_netssl:
if self._with_netssl:
self.run(os.path.join("bin", "netssl"), run_environment=True)
if self.options["poco"].enable_data_sqlite:
self.run(os.path.join("bin", "sqlite"), run_environment=True)
Expand Down
55 changes: 41 additions & 14 deletions recipes/poco/all/test_package/test_netssl.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
#include "Poco/Net/Context.h"
#include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/SSLManager.h"
#include "Poco/StreamCopier.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "Poco/SharedPtr.h"
#include "Poco/Net/SSLManager.h"
#include "Poco/Net/KeyConsoleHandler.h"
#include "Poco/Net/AcceptCertificateHandler.h"
#include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include <memory>
#include <iostream>

using namespace Poco;
using namespace Poco::Net;
using Poco::Net::Context;
using Poco::Net::HTTPSClientSession;
using Poco::URI;

int main()
{
try {
URI uri("https://pocoproject.org/");
const Context::Ptr context = SSLManager::instance().defaultClientContext();
HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
} catch (...) { }
class SSLInitializer {
public:
SSLInitializer() { Poco::Net::initializeSSL(); }

~SSLInitializer() { Poco::Net::uninitializeSSL(); }
};

int main(int argc, char** argv) {
SSLInitializer sslInitializer;

SharedPtr<InvalidCertificateHandler> ptrCert = new AcceptCertificateHandler(false);
Context::Ptr ptrContext = new Context(Context::CLIENT_USE, "", Context::VERIFY_NONE);
SSLManager::instance().initializeClient(0, ptrCert, ptrContext);

try {
URI uri("https://httpbin.org/user-agent");
HTTPSClientSession s(uri.getHost(), uri.getPort());
HTTPRequest request(HTTPRequest::HTTP_GET, uri.getPath());
request.set("user-agent", "Poco HTTPSClientSession");
// FIXME: CCI Jenkins blocks the request making the build fail
//s.sendRequest(request);
//HTTPResponse response;
//std::istream& rs = s.receiveResponse(response);
//StreamCopier::copyStream(rs, std::cout);
} catch (const Exception& ex) {
std::cout << ex.displayText() << std::endl;
return 1;
}

return 0;
return 0;
}