From 3a0b352c63db543833e0f919a004cf2c5093fe9c Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 14 Oct 2022 13:55:53 +0800 Subject: refactor: move url.h/cpp from lib util to lib common --- src/common/url.cpp | 22 ++++++++++++++++++++++ src/common/url.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/common/url.cpp create mode 100644 src/common/url.h (limited to 'src/common') diff --git a/src/common/url.cpp b/src/common/url.cpp new file mode 100644 index 0000000000..5200d55096 --- /dev/null +++ b/src/common/url.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2015-2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +#include +#include + +std::string urlDecode(const std::string &urlEncoded) { + std::string res; + if (!urlEncoded.empty()) { + char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr); + if (decoded) { + res = std::string(decoded); + free(decoded); + } + } + return res; +} diff --git a/src/common/url.h b/src/common/url.h new file mode 100644 index 0000000000..7bbd8b60de --- /dev/null +++ b/src/common/url.h @@ -0,0 +1,14 @@ +// Copyright (c) 2015-2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_COMMON_URL_H +#define BITCOIN_COMMON_URL_H + +#include + +using UrlDecodeFn = std::string(const std::string& url_encoded); +UrlDecodeFn urlDecode; +extern UrlDecodeFn* const URL_DECODE; + +#endif // BITCOIN_COMMON_URL_H -- cgit v1.2.3