Merge bitcoin/bitcoin#23607: rpc: Pass const char* to evhttp_connection_get_peer for new libevent

c62d763fc313585d79ad833c9d729f6acf2652aa Necessary improvements to make configure work without libevent installed (Perlover)
091ccc38c2e589b649648cbcc99aca4802f98775 The evhttp_connection_get_peer function from libevent changes the type of the second parameter. Fixing the problem. (Perlover)

Pull request description:

  The second parameter of evhttp_connection_get_peer in libevent already has type as `const char **`
  The compilation of bitcoind with the fresh libevent occurs errors

  Details: https://github.com/bitcoin/bitcoin/issues/23606

ACKs for top commit:
  laanwj:
    Code review ACK c62d763fc313585d79ad833c9d729f6acf2652aa
  luke-jr:
    tACK c62d763fc313585d79ad833c9d729f6acf2652aa

Tree-SHA512: d1c8062d90bd0d55c582dae2c3a7e5ee1b6c7ca872bf4aa7fe6f45a52ac4a8f59464215759d961f8efde0efbeeade31b08daf9387d7d50d7622baa1c06992d83
This commit is contained in:
laanwj 2022-01-13 16:43:12 +01:00 committed by pasta
parent 187b3c49fc
commit cac2ae924a
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 31 additions and 0 deletions

View File

@ -1478,6 +1478,26 @@ if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench
fi fi
fi fi
if test x$use_libevent = xyes; then
TEMP_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $EVENT_CFLAGS"
AC_MSG_CHECKING([if evhttp_connection_get_peer expects const char**])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <cstdint>
#include <event2/http.h>
]], [[
evhttp_connection *conn = (evhttp_connection *)1;
const char *host;
uint16_t port;
evhttp_connection_get_peer(conn, &host, &port);
]])],
[ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR], [1], [Define this symbol if evhttp_connection_get_peer expects const char**]) ],
[ AC_MSG_RESULT([no]) ]
)
CXXFLAGS="$TEMP_CXXFLAGS"
fi
dnl QR Code encoding library check dnl QR Code encoding library check
if test "x$use_qr" != xno; then if test "x$use_qr" != xno; then
@ -1787,6 +1807,7 @@ AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL) AC_SUBST(HAVE_STRONG_GETAUXVAL)
AC_SUBST(HAVE_GMTIME_R) AC_SUBST(HAVE_GMTIME_R)
AC_SUBST(ANDROID_ARCH) AC_SUBST(ANDROID_ARCH)
AC_SUBST(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini]) AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh]) AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])]) AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])

View File

@ -2,6 +2,10 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <httpserver.h> #include <httpserver.h>
#include <chainparamsbase.h> #include <chainparamsbase.h>
@ -597,7 +601,13 @@ CService HTTPRequest::GetPeer() const
// evhttp retains ownership over returned address string // evhttp retains ownership over returned address string
const char* address = ""; const char* address = "";
uint16_t port = 0; uint16_t port = 0;
#ifdef HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
evhttp_connection_get_peer(con, &address, &port);
#else
evhttp_connection_get_peer(con, (char**)&address, &port); evhttp_connection_get_peer(con, (char**)&address, &port);
#endif // HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
peer = LookupNumeric(address, port); peer = LookupNumeric(address, port);
} }
return peer; return peer;