void CLogViewWindow::ProxyEvent(LogProxyEvent Event, const IPv4Address& addr) { CString msg = GetTranslateMessage(ID_PROXYEVENTHEADER, addr.GetPortNumber()).c_str(); switch (Event) { case kLogProxyNewRequest: msg += GetTranslateMessage(ID_PROXYNEWREQUEST).c_str(); break; case kLogProxyEndRequest: msg += GetTranslateMessage(ID_PROXYENDREQUEST).c_str(); break; default: ATLASSERT( FALSE ); return ; } SetWindowText(GetTranslateMessage(IDD_LOGVIEW, CLog::GetActiveRequestCount()).c_str()); if (m_bProxyEvent == false) return; _AppendText(msg, LOG_COLOR_PROXY); }
void CLogViewWindow::HttpEvent(LogHttpEvent Event, const IPv4Address& addr, int RequestNumber, const std::string& text) { CString msg = GetTranslateMessage(ID_HTTPEVENTHEADER, addr.GetPortNumber(), RequestNumber).c_str(); switch (Event) { case kLogHttpNewRequest: { CString url = text.c_str(); CString temp; temp.Format(_T("#%d %s"), RequestNumber, (LPCWSTR)url); int nSel = m_cmbRequest.AddString(temp); m_cmbRequest.SetItemData(nSel, RequestNumber); return; } break; case kLogHttpRecvOut: if (!m_bBrowserToProxy) return ; msg += GetTranslateMessage(ID_HTTPRECVOUT).c_str(); break; case kLogHttpSendOut: if (!m_bProxyToWeb) return ; msg += GetTranslateMessage(ID_HTTPSENDOUT).c_str(); break; case kLogHttpRecvIn: if (!m_bProxyFromWeb) return ; msg += GetTranslateMessage(ID_HTTPRECVIN).c_str(); break; case kLogHttpSendIn: if (!m_bBrowserFromProxy) return ; msg += GetTranslateMessage(ID_HTTPSENDIN).c_str(); break; case kLogHttpPostOut: if (!m_bViewPostData) return ; msg += L"PostData"; break; default: return ; } msg += _T("\n"); msg += UTF16fromUTF8(text).c_str(); msg += _T("\n"); // Colors depends on Outgoing or Incoming COLORREF color = LOG_COLOR_REQUEST; if (Event == kLogHttpRecvIn || Event == kLogHttpSendIn) { color = LOG_COLOR_RESPONSE; } else if (Event == kLogHttpPostOut) { color = LOG_COLOR_DEFAULT; std::string unescText = CUtil::UESC(text); std::string charaCode = DetectCharaCode(unescText); if (charaCode.length()) { UErrorCode err = UErrorCode::U_ZERO_ERROR; auto pConverter = ucnv_open(charaCode.c_str(), &err); if (pConverter) { std::wstring utf16PostData = UTF16fromConverter(unescText, pConverter); msg.AppendFormat(_T(">> Decode Data [%s]\n%s\n"), UTF16fromUTF8(charaCode).c_str(), utf16PostData.c_str()); ucnv_close(pConverter); } } msg += _T("\n"); } { CCritSecLock lock(m_csRequestLog); bool bFound = false; for (auto& reqLog : m_vecRquestLog) { if (reqLog->RequestNumber == RequestNumber) { reqLog->vecLog.emplace_back(new TextLog(msg, color)); lock.Unlock(); int nCurSel = m_cmbRequest.GetCurSel(); if (nCurSel > 0 && m_cmbRequest.GetItemData(nCurSel) == RequestNumber) { _AppendRequestLogText(msg, color); } bFound = true; break; } } if (bFound == false) { m_vecRquestLog.emplace_back(new RequestLog(RequestNumber)); m_vecRquestLog.back()->vecLog.emplace_back(new TextLog(msg, color)); } } _AppendText(msg, color); }