diff options
author | fanquake <fanquake@gmail.com> | 2022-10-14 13:55:53 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-10-31 10:17:04 +0000 |
commit | 3a0b352c63db543833e0f919a004cf2c5093fe9c (patch) | |
tree | 039448fe79ddaa2b74cc23629238f01ee181523e /src/common | |
parent | 058eb69ce47c17205a41fc667ce66429f09a332a (diff) |
refactor: move url.h/cpp from lib util to lib common
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/url.cpp | 22 | ||||
-rw-r--r-- | src/common/url.h | 14 |
2 files changed, 36 insertions, 0 deletions
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 <common/url.h> + +#include <event2/http.h> + +#include <cstdlib> +#include <string> + +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 <string> + +using UrlDecodeFn = std::string(const std::string& url_encoded); +UrlDecodeFn urlDecode; +extern UrlDecodeFn* const URL_DECODE; + +#endif // BITCOIN_COMMON_URL_H |