Skip to content

Commit

Permalink
http://local.ptron/ へのアクセスができなくなっていたバグを修正 #62
Browse files Browse the repository at this point in the history
http://local.ptron/blocklistinfo/ へのアクセスでCPUを過度に消費してしまうバグを修正 #63http://local.ptron への$JUMPが$RDIR相当になっていたのを再修正 #60
  • Loading branch information
amate committed May 5, 2019
1 parent ea75201 commit cfee419
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
7 changes: 5 additions & 2 deletions Proxydomo.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.352
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Proxydomo", "Proxydomo\Proxydomo.vcxproj", "{DDADC3EE-73B1-4DED-9073-F4AF4755B6D4}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -68,4 +68,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2026CDD7-49F8-40E4-94ED-155D031FE97A}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Proxydomo/AppConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#endif

/// アプリケーションのバージョン
#define APP_VERSION _T("1.108")
#define APP_VERSION _T("1.109")



Expand Down
4 changes: 2 additions & 2 deletions Proxydomo/BlockListDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ bool CBlockListDatabase::ManageBlockListInfoAPI(const CUrl& url, SocketIF* sockB
"Connection: close" + CRLF CRLF;
sendInBuf += content;

while (sockBrowser->Write(sendInBuf.data(), sendInBuf.length()));
while (sockBrowser->Write(sendInBuf.data(), sendInBuf.length()) > 0);
sockBrowser->Close();

return true;
Expand Down Expand Up @@ -420,7 +420,7 @@ bool CBlockListDatabase::ManageBlockListInfoAPI(const CUrl& url, SocketIF* sockB
"Connection: close" + CRLF CRLF;
sendInBuf += content;

while (sockBrowser->Write(sendInBuf.data(), sendInBuf.length()));
while (sockBrowser->Write(sendInBuf.data(), sendInBuf.length()) > 0);
sockBrowser->Close();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Proxydomo/FilterOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CFilterOwner::Reset()
variables.clear();

contactHost.clear();
rdirMode = 0;
rdirMode = RedirectMode::kNone;
rdirToHost.clear();

outHeaders.clear();
Expand Down
6 changes: 5 additions & 1 deletion Proxydomo/FilterOwner.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class CFilterOwner

std::wstring contactHost; // can be overridden by $SETPROXY
std::wstring rdirToHost; // set by $RDIR and $JUMP
int rdirMode; // 0: 302 response, 1: transparent
enum class RedirectMode {
kNone,
kJump, // 302 response
kRdir, // transparent
} rdirMode;

bool bypassIn; // tells if we can filter incoming headers
bool bypassOut; // tells if we can filter outgoing headers
Expand Down
4 changes: 2 additions & 2 deletions Proxydomo/Nodes_.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,14 +1419,14 @@ const UChar* CNode_Command::match(const UChar* start, const UChar* stop, MatchDa
case CMD_JUMP:
owner.rdirToHost = CExpander::expand(m_content, filter);
CUtil::trim(owner.rdirToHost);
owner.rdirMode = 0;
owner.rdirMode = CFilterOwner::RedirectMode::kJump;
CLog::FilterEvent(kLogFilterJump, owner.requestNumber, UTF8fromUTF16(filter.title), UTF8fromUTF16(owner.rdirToHost));
break;

case CMD_RDIR:
owner.rdirToHost = CExpander::expand(m_content, filter);
CUtil::trim(owner.rdirToHost);
owner.rdirMode = 1;
owner.rdirMode = CFilterOwner::RedirectMode::kRdir;
CLog::FilterEvent(kLogFilterRdir, owner.requestNumber, UTF8fromUTF16(filter.title), UTF8fromUTF16(owner.rdirToHost));
break;

Expand Down
29 changes: 19 additions & 10 deletions Proxydomo/RequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void CRequestManager::_ProcessOutHeaderFilter()
if (changeHost) m_filterOwner.contactHost = m_filterOwner.url.getHostPort();
}
}
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == 1) {
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == CFilterOwner::RedirectMode::kRdir) {
if (CUrl(m_filterOwner.rdirToHost).getBypassOut())
break;
}
Expand Down Expand Up @@ -612,9 +612,10 @@ void CRequestManager::_ProcessOut()
// CONNECTリクエストはリダイレクトしないようにする
if (m_requestLine.method == "CONNECT" && m_filterOwner.killed == false && m_filterOwner.rdirToHost.size() > 0) {
WARN_LOG << L"CONNECT redirect clear, src : " << m_filterOwner.url.getHost()
<< L" rdirToHost : " << m_filterOwner.rdirToHost << L" rdirMode : " << m_filterOwner.rdirMode;
<< L" rdirToHost : " << m_filterOwner.rdirToHost
<< L" rdirMode : " << static_cast<int>(m_filterOwner.rdirMode);
m_filterOwner.rdirToHost.clear();
m_filterOwner.rdirMode = 0;
m_filterOwner.rdirMode = CFilterOwner::RedirectMode::kNone;
}

// If we haven't connected to ths host yet, we do it now.
Expand Down Expand Up @@ -983,15 +984,23 @@ void CRequestManager::_ConnectWebsite()

bool CRequestManager::_HandleLocalPtron()
{
// $JUMP( local.ptron/... )は無視する
if (m_filterOwner.rdirMode == CFilterOwner::RedirectMode::kJump &&
CUtil::noCaseBeginsWith(L"http://local.ptron", m_filterOwner.rdirToHost)) {
return false;
}

if (m_filterOwner.url.getHost() == L"local.ptron") {
if (m_filterOwner.rdirMode != CFilterOwner::RedirectMode::kNone) {
WARN_LOG << L"_HandleLocalPtron override rdirToHost : " << m_filterOwner.rdirToHost
<< L" rdirMode : " << static_cast<int>(m_filterOwner.rdirMode);
}
m_filterOwner.rdirToHost = m_filterOwner.url.getUrl();
}
if (CUtil::noCaseBeginsWith(L"http://local.ptron", m_filterOwner.rdirToHost)) {
WARN_LOG << L"rdirToHost is local.ptron : " << m_filterOwner.rdirToHost;
//m_filterOwner.rdirToHost = L"http://file//./html" + CUrl(m_filterOwner.rdirToHost).getPath();
m_filterOwner.rdirToHost = L"http://file//./html" + CUrl(m_filterOwner.rdirToHost).getPath();
}


// https://local.ptron/ への接続
if (CSettings::s_SSLFilter && CUtil::noCaseBeginsWith(L"https://local.ptron", m_filterOwner.rdirToHost)) {
wstring subpath;
Expand Down Expand Up @@ -1080,7 +1089,7 @@ bool CRequestManager::_HandleLocalPtron()
// フォルダが存在するかつ URLの末尾が '/' で終わっていなければ フォルダ名 + L'/' へリダイレクトさせる
if (filepath.native().back() != L'\\') {
m_filterOwner.rdirToHost = L"http://local.ptron/" + filepath.native().substr(7) + L'/';
m_filterOwner.rdirMode = 0;
m_filterOwner.rdirMode = CFilterOwner::RedirectMode::kJump;
return false;
}

Expand Down Expand Up @@ -1119,7 +1128,7 @@ bool CRequestManager::_HandleLocalPtron()
bool CRequestManager::_HandleRedirectToHost()
{
// Test for non-transparent redirection ($JUMP)
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == 0) {
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == CFilterOwner::RedirectMode::kJump) {
// We'll keep browser's socket, for persistent connections, and
// continue processing outgoing data (which will not be moved to
// send buffer).
Expand All @@ -1139,7 +1148,7 @@ bool CRequestManager::_HandleRedirectToHost()

// Test for transparent redirection to URL ($RDIR)
// Note: new URL will not go through URL* OUT filters
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == 1) {
if (m_filterOwner.rdirToHost.size() > 0 && m_filterOwner.rdirMode == CFilterOwner::RedirectMode::kRdir) {

// Change URL
m_filterOwner.url.parseUrl(m_filterOwner.rdirToHost);
Expand Down Expand Up @@ -1251,7 +1260,7 @@ void CRequestManager::_ProcessInHeaderFilter()
m_filterOwner.rdirToHost = L"http://file//./html/killed.gif";
else
m_filterOwner.rdirToHost = L"http://file//./html/killed.html";
m_filterOwner.rdirMode = 0; // (to use non-transp code below)
m_filterOwner.rdirMode = CFilterOwner::RedirectMode::kJump; // (to use non-transp code below)
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Proxydomo/proximodo/expander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ std::wstring CExpander::expand(const std::wstring& pattern, CFilter& filter) {

filter.owner.rdirToHost = expand(content, filter);
CUtil::trim(filter.owner.rdirToHost);
filter.owner.rdirMode = 0;
filter.owner.rdirMode = CFilterOwner::RedirectMode::kJump;
CLog::FilterEvent(kLogFilterJump, filter.owner.requestNumber, UTF8fromUTF16(filter.title), UTF8fromUTF16(filter.owner.rdirToHost));

} else if (command == L"RDIR") {

filter.owner.rdirToHost = expand(content, filter);
CUtil::trim(filter.owner.rdirToHost);
filter.owner.rdirMode = 1;
filter.owner.rdirMode = CFilterOwner::RedirectMode::kRdir;
CLog::FilterEvent(kLogFilterRdir, filter.owner.requestNumber, UTF8fromUTF16(filter.title), UTF8fromUTF16(filter.owner.rdirToHost));

} else if (command == L"FILTER") {
Expand Down

0 comments on commit cfee419

Please sign in to comment.