From e972ec5a22d631798832c2a08a9bb9442300037c Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Fri, 22 Mar 2024 20:35:11 +0800 Subject: [PATCH] Remove deprecated code --- src/Common/Parser.cpp | 4 +-- src/Common/strCoding.cpp | 63 ---------------------------------------- src/Common/strCoding.h | 2 -- src/Http/HttpSession.cpp | 12 -------- src/Http/HttpSession.h | 1 - 5 files changed, 2 insertions(+), 80 deletions(-) diff --git a/src/Common/Parser.cpp b/src/Common/Parser.cpp index ab41c53e..7e7de860 100644 --- a/src/Common/Parser.cpp +++ b/src/Common/Parser.cpp @@ -294,8 +294,8 @@ void RtspUrl::setup(bool is_ssl, const string &url, const string &user, const st splitUrl(ip, ip, port); _url = std::move(url); - _user = strCoding::UrlDecode(std::move(user)); - _passwd = strCoding::UrlDecode(std::move(passwd)); + _user = strCoding::UrlDecodeComponent(user); + _passwd = strCoding::UrlDecodeComponent(passwd); _host = std::move(ip); _port = port; _is_ssl = is_ssl; diff --git a/src/Common/strCoding.cpp b/src/Common/strCoding.cpp index 59a0b7e4..1a0f0236 100644 --- a/src/Common/strCoding.cpp +++ b/src/Common/strCoding.cpp @@ -53,22 +53,6 @@ char HexStrToBin(const char *str) { return (high << 4) | low; } -string strCoding::UrlEncode(const string &str) { - string out; - size_t len = str.size(); - for (size_t i = 0; i < len; ++i) { - char ch = str[i]; - if (isalnum((uint8_t) ch)) { - out.push_back(ch); - } else { - char buf[4]; - sprintf(buf, "%%%X%X", (uint8_t) ch >> 4, (uint8_t) ch & 0x0F); - out.append(buf); - } - } - return out; -} - string strCoding::UrlEncodePath(const string &str) { const char *dont_escape = "!#&'*+:=?@/._-$,;~()"; string out; @@ -103,32 +87,6 @@ string strCoding::UrlEncodeComponent(const string &str) { return out; } -string strCoding::UrlDecode(const string &str) { - string output; - size_t i = 0, len = str.length(); - while (i < len) { - if (str[i] == '%') { - if (i + 3 > len) { - // %后面必须还有两个字节才会反转义 - output.append(str, i, len - i); - break; - } - char ch = HexStrToBin(&(str[i + 1])); - if (ch == -1) { - // %后面两个字节不是16进制字符串,转义失败;直接拼接3个原始字符 - output.append(str, i, 3); - } else { - output += ch; - } - i += 3; - } else { - output += str[i]; - ++i; - } - } - return output; -} - string strCoding::UrlDecodePath(const string &str) { const char *dont_unescape = "#$&+,/:;=?@"; string output; @@ -185,27 +143,6 @@ std::string strCoding::UrlDecodeComponent(const std::string &str) { return output; } -#if 0 -#include "Util/onceToken.h" -static toolkit::onceToken token([]() { - auto str0 = strCoding::UrlDecode( - "rtsp%3A%2F%2Fadmin%3AJm13317934%25jm%40111.47.84.69%3A554%2FStreaming%2FChannels%2F101%3Ftransportmode%3Dunicast%26amp%3Bprofile%3DProfile_1"); - auto str1 = strCoding::UrlDecode("%j1"); // 测试%后面两个字节不是16进制字符串 - auto str2 = strCoding::UrlDecode("%a"); // 测试%后面字节数不够 - auto str3 = strCoding::UrlDecode("%"); // 测试只有% - auto str4 = strCoding::UrlDecode("%%%"); // 测试多个% - auto str5 = strCoding::UrlDecode("%%%%40"); // 测试多个非法%后恢复正常解析 - auto str6 = strCoding::UrlDecode("Jm13317934%jm"); // 测试多个非法%后恢复正常解析 - cout << str0 << endl; - cout << str1 << endl; - cout << str2 << endl; - cout << str3 << endl; - cout << str4 << endl; - cout << str5 << endl; - cout << str6 << endl; -}); -#endif - ///////////////////////////////windows专用/////////////////////////////////// #if defined(_WIN32) void UnicodeToGB2312(char* pOut, wchar_t uData) diff --git a/src/Common/strCoding.h b/src/Common/strCoding.h index 14371704..e715e74d 100644 --- a/src/Common/strCoding.h +++ b/src/Common/strCoding.h @@ -18,10 +18,8 @@ namespace mediakit { class strCoding { public: - [[deprecated]] static std::string UrlEncode(const std::string &str); //url utf8编码, deprecated static std::string UrlEncodePath(const std::string &str); //url路径 utf8编码 static std::string UrlEncodeComponent(const std::string &str); // url参数 utf8编码 - [[deprecated]] static std::string UrlDecode(const std::string &str); //url utf8解码, deprecated static std::string UrlDecodePath(const std::string &str); //url路径 utf8解码 static std::string UrlDecodeComponent(const std::string &str); // url参数 utf8解码 #if defined(_WIN32) diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 3c34a661..ba74d803 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -683,18 +683,6 @@ void HttpSession::sendResponse(int code, AsyncSender::onSocketFlushed(data); } -string HttpSession::urlDecode(const string &str) { - auto ret = strCoding::UrlDecode(str); -#ifdef _WIN32 - GET_CONFIG(string, charSet, Http::kCharSet); - bool isGb2312 = !strcasecmp(charSet.data(), "gb2312"); - if (isGb2312) { - ret = strCoding::UTF8ToGB2312(ret); - } -#endif // _WIN32 - return ret; -} - string HttpSession::urlDecodePath(const string &str) { auto ret = strCoding::UrlDecodePath(str); #ifdef _WIN32 diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 2bc1c353..0ffbf137 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -44,7 +44,6 @@ public: void onRecv(const toolkit::Buffer::Ptr &) override; void onError(const toolkit::SockException &err) override; void onManager() override; - [[deprecated]] static std::string urlDecode(const std::string &str); static std::string urlDecodePath(const std::string &str); static std::string urlDecodeComponent(const std::string &str); void setTimeoutSec(size_t second);