From 40d3b36f9276717ebcff36b83e308c05de6659cc Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Tue, 5 May 2020 22:40:32 +0800 Subject: [PATCH] Enhancements Add support for specifying node rename pattern in URL argument. Optimize codes. --- src/interfaces.cpp | 6 +++++- src/speedtestutil.cpp | 6 ++++-- src/webserver_libevent.cpp | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 282fd98..ca073c6 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1131,6 +1131,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::string include = UrlDecode(getUrlArg(argument, "include")), exclude = UrlDecode(getUrlArg(argument, "exclude")); std::string groups = urlsafe_base64_decode(getUrlArg(argument, "groups")), ruleset = urlsafe_base64_decode(getUrlArg(argument, "ruleset")), config = UrlDecode(getUrlArg(argument, "config")); std::string dev_id = getUrlArg(argument, "dev_id"), filename = getUrlArg(argument, "filename"), interval_str = getUrlArg(argument, "interval"), strict_str = getUrlArg(argument, "strict"); + std::string ext_rename = UrlDecode(getUrlArg(argument, "rename")); /// switches with default value tribool upload = getUrlArg(argument, "upload"), emoji = getUrlArg(argument, "emoji"); @@ -1188,7 +1189,10 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::string proxy = parseProxy(proxy_subscription); ext.emoji_array = safe_get_emojis(); - ext.rename_array = safe_get_renames(); + if(ext_rename.size()) + ext.rename_array = split(ext_rename, "`"); + else + ext.rename_array = safe_get_renames(); //check other flags if(!emoji.is_undef()) diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 451f342..5cfd600 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -2125,14 +2125,16 @@ static inline unsigned long long streamToInt(const std::string &stream) return 0; double streamval = 1.0; std::vector units = {"B", "KB", "MB", "GB", "TB", "PB", "EB"}; - for(size_t index = units.size() - 1; index >= 0; index--) + size_t index = units.size(); + do { + index--; if(endsWith(stream, units[index])) { streamval = std::pow(1024, index) * to_number(stream.substr(0, stream.size() - units[index].size()), 0.0); break; } - } + } while(index != 0); return (unsigned long long)streamval; } diff --git a/src/webserver_libevent.cpp b/src/webserver_libevent.cpp index d7dd83f..2fe1d24 100644 --- a/src/webserver_libevent.cpp +++ b/src/webserver_libevent.cpp @@ -56,7 +56,7 @@ static inline int process_request(const char *method_str, std::string uri, std:: for(responseRoute &x : responses) { - if(strcmp(method_str, "OPTIONS") == 0 && x.method == postdata && x.path == path) + if(strcmp(method_str, "OPTIONS") == 0 && postdata.find(x.method) != 0 && x.path == path) { return 1; }