From 59c157faaa679197529fdca80a40b4b8b947663a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 10 Apr 2020 12:52:32 -0400 Subject: [PATCH] Merge #18504: build: Drop bitcoin-tx and bitcoin-wallet dependencies on libevent 01a3392b1b778fa4fcf568013326d6ea1de4fb3b Drop bitcoin-wallet dependency on libevent (Russell Yanofsky) 0660119ac372c2863d14060ac1bc9bc243771f94 Drop unintended bitcoin-tx dependency on libevent (Russell Yanofsky) Pull request description: This fixes compile errors trying to build bitcoin-tx and bitcoin-wallet without libevent, which were reported by Luke Dashjr in https://github.com/bitcoin/bitcoin/issues/18465 The fix avoiding `bitcoin-tx` dependency on libevent just adds a conditional build rule. This is implemented in the first commit (more details in commit description). The fix avoiding `bitcoin-wallet` dependency on libevent requires minor code changes, because `bitcoin-wallet` (unlike `bitcoin-tx`) links against code that calls `urlDecode` / `evhttp_uridecode`. This fix is implemented in the second commit (again details in the commit description). ACKs for top commit: jonasschnelli: utACK 01a3392b1b778fa4fcf568013326d6ea1de4fb3b. Tree-SHA512: d2245e912ab494cccceeb427a1eca8e55b01a0006ff93eebcfb5461ae7cecd1083ac2de443d9db036b18bdc6f0fb615546caaa20c585046f66d234937f74870a --- configure.ac | 3 ++- src/Makefile.am | 5 ++++- src/bitcoin-cli.cpp | 2 ++ src/bitcoin-wallet.cpp | 2 ++ src/bitcoind.cpp | 2 ++ src/qt/main.cpp | 2 ++ src/test/util/setup_common.cpp | 2 ++ src/util/url.h | 4 +++- src/wallet/rpcwallet.cpp | 4 ++-- 9 files changed, 21 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 2e1bf83a61..9442dee4b9 100644 --- a/configure.ac +++ b/configure.ac @@ -1500,7 +1500,7 @@ if test x$use_pkgconfig = xyes; then else if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then - AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),) + AC_CHECK_HEADER([event2/event.h], [use_libevent=yes], AC_MSG_ERROR(libevent headers missing),) AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing)) if test x$TARGET_OS != xwindows; then AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing)) @@ -1749,6 +1749,7 @@ AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes]) AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes]) AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes]) AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes]) +AM_CONDITIONAL([USE_LIBEVENT],[test x$use_libevent = xyes]) AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes]) AM_CONDITIONAL([ENABLE_SSE42],[test x$enable_sse42 = xyes]) AM_CONDITIONAL([ENABLE_SSE41],[test x$enable_sse41 = xyes]) diff --git a/src/Makefile.am b/src/Makefile.am index d12ecaf5f2..b8d268b419 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -751,9 +751,12 @@ libbitcoin_util_a_SOURCES = \ util/serfloat.cpp \ util/string.cpp \ util/threadnames.cpp \ - util/url.cpp \ $(BITCOIN_CORE_H) +if USE_LIBEVENT +libbitcoin_util_a_SOURCES += util/url.cpp +endif + # cli: shared between dash-cli and dash-qt libbitcoin_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index d237006c8b..cd185ad927 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = urlDecode; static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index e4a6b1b437..67f4b85d50 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -12,9 +12,11 @@ #include #include #include +#include #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = nullptr; static void SetupWalletToolArgs(ArgsManager& argsman) { diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index cdbb72abba..b8d7b38149 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -23,12 +23,14 @@ #include #include #include +#include #include #include #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = urlDecode; ////////////////////////////////////////////////////////////////////////////// // diff --git a/src/qt/main.cpp b/src/qt/main.cpp index a05234589f..552ca8a5b9 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -15,5 +16,6 @@ extern const std::function G_TRANSLATION_FUN = [](const char* psz) { return QCoreApplication::translate("dash-core", psz).toStdString(); }; +UrlDecodeFn* const URL_DECODE = urlDecode; int main(int argc, char* argv[]) { return GuiMain(argc, argv); } diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 96eca1f50e..484604a2b7 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = nullptr; FastRandomContext g_insecure_rand_ctx; /** Random context to get unique temp data dirs. Separate from g_insecure_rand_ctx, which can be seeded from a const env var */ diff --git a/src/util/url.h b/src/util/url.h index 3d7315a338..6c3dfde055 100644 --- a/src/util/url.h +++ b/src/util/url.h @@ -7,6 +7,8 @@ #include -std::string urlDecode(const std::string &urlEncoded); +using UrlDecodeFn = std::string(const std::string& url_encoded); +UrlDecodeFn urlDecode; +extern UrlDecodeFn* const URL_DECODE; #endif // BITCOIN_UTIL_URL_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e8602e3248..4e70a928df 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -93,9 +93,9 @@ bool HaveKey(const SigningProvider& wallet, const CKey& key) bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name) { - if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) { + if (URL_DECODE && request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) { // wallet endpoint was used - wallet_name = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); + wallet_name = URL_DECODE(request.URI.substr(WALLET_ENDPOINT_BASE.size())); return true; } return false;