修复http文件服务器对特殊字符文件不兼容的bug:#1866

This commit is contained in:
ziyue 2022-08-10 10:37:49 +08:00
parent 099845b329
commit 795b4dbbd3
2 changed files with 19 additions and 26 deletions

View File

@ -19,6 +19,7 @@
#include "HttpSession.h"
#include "Record/HlsMediaSource.h"
#include "Common/Parser.h"
#include "strCoding.h"
using namespace std;
using namespace toolkit;
@ -124,7 +125,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
if (pDirent->d_name[0] == '.') {
continue;
}
file_map.emplace(pDirent->d_name, std::make_pair(pDirent->d_name, strPathPrefix + "/" + pDirent->d_name));
file_map.emplace(strCoding::UrlEncode(pDirent->d_name), std::make_pair(pDirent->d_name, strPathPrefix + "/" + pDirent->d_name));
}
//如果是root目录添加虚拟目录
if (httpPath == "/") {

View File

@ -20,15 +20,14 @@ using namespace std;
namespace mediakit {
//////////////////////////通用///////////////////////
void UTF8ToUnicode(wchar_t* pOut, const char *pText)
{
void UTF8ToUnicode(wchar_t *pOut, const char *pText) {
char *uchar = (char *) pOut;
uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F);
uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F);
return;
}
void UnicodeToUTF8(char* pOut, const wchar_t* pText)
{
void UnicodeToUTF8(char *pOut, const wchar_t *pText) {
// 注意 WCHAR高低字的顺序,低字节在前,高字节在后
const char *pchar = (const char *) pText;
pOut[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4));
@ -37,15 +36,14 @@ void UnicodeToUTF8(char* pOut, const wchar_t* pText)
return;
}
char CharToInt(char ch)
{
char CharToInt(char ch) {
if (ch >= '0' && ch <= '9')return (char) (ch - '0');
if (ch >= 'a' && ch <= 'f')return (char) (ch - 'a' + 10);
if (ch >= 'A' && ch <= 'F')return (char) (ch - 'A' + 10);
return -1;
}
char StrToBin(const char *str)
{
char StrToBin(const char *str) {
char tempWord[2];
char chn;
tempWord[0] = CharToInt(str[0]); //make the B to 11 -- 00001011
@ -69,8 +67,9 @@ string strCoding::UrlEncode(const string &str) {
}
return out;
}
string strCoding::UrlDecode(const string &str) {
string output = "";
string output;
char tmp[2];
size_t i = 0, len = str.length();
while (i < len) {
@ -83,9 +82,6 @@ string strCoding::UrlDecode(const string &str) {
tmp[1] = str[i + 2];
output += StrToBin(tmp);
i = i + 3;
} else if (str[i] == '+') {
output += ' ';
i++;
} else {
output += str[i];
i++;
@ -94,7 +90,6 @@ string strCoding::UrlDecode(const string &str) {
return output;
}
///////////////////////////////windows专用///////////////////////////////////
#if defined(_WIN32)
void UnicodeToGB2312(char* pOut, wchar_t uData)
@ -169,7 +164,4 @@ string strCoding::GB2312ToUTF8(const string &str) {
}
#endif//defined(_WIN32)
} /* namespace mediakit */