aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/url.cpp22
-rw-r--r--src/common/url.h14
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