diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-12-04 22:19:06 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-12-04 22:19:06 +0200 |
commit | 977dd9b76ca379b3a16e2656cd080a8c3ee0d214 (patch) | |
tree | 473c158b3e13937d99e9acfdab8e4e718d1504af /contrib | |
parent | Merge pull request #1388 (diff) | |
parent | tests: add unit tests for uri parsing (diff) | |
download | monero-977dd9b76ca379b3a16e2656cd080a8c3ee0d214.tar.xz |
Merge pull request #1385
5783dd8c tests: add unit tests for uri parsing (moneromooo-monero)
82ba2108 wallet: add API and RPC to create/parse monero: URIs (moneromooo-monero)
d9001b43 epee: add functions to convert from URL format (ie, %XX values) (moneromooo-monero)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/include/net/http_client.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index 3e8143738..336153384 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -156,6 +156,17 @@ using namespace std; return csTmp; } + static inline int get_index(const char *s, char c) { const char *ptr = (const char*)memchr(s, c, 16); return ptr ? ptr-s : -1; } + static inline + std::string hex_to_dec_2bytes(const char *s) + { + const char *hex = get_hex_vals(); + int i0 = get_index(hex, toupper(s[0])); + int i1 = get_index(hex, toupper(s[1])); + if (i0 < 0 || i1 < 0) + return std::string("%") + std::string(1, s[0]) + std::string(1, s[1]); + return std::string(1, i0 * 16 | i1); + } static inline std::string convert(char val) { @@ -180,6 +191,25 @@ using namespace std; return result; } + static inline std::string convert_from_url_format(const std::string& uri) + { + + std::string result; + + for(size_t i = 0; i!= uri.size(); i++) + { + if(uri[i] == '%' && i + 2 < uri.size()) + { + result += hex_to_dec_2bytes(uri.c_str() + i + 1); + i += 2; + } + else + result += uri[i]; + + } + + return result; + } static inline std::string convert_to_url_format_force_all(const std::string& uri) { |