| 417 | |
| 418 | |
| 419 | bool CIPFilter::IsFiltered(uint32 IPTest, bool isServer) |
| 420 | { |
| 421 | if ((!thePrefs::IsFilteringClients() && !isServer) || (!thePrefs::IsFilteringServers() && isServer)) { |
| 422 | return false; |
| 423 | } |
| 424 | if (!m_ready) { |
| 425 | // Somebody connected before we even started the networks. |
| 426 | // Filter is not up yet, so block him. |
| 427 | AddDebugLogLineN(logIPFilter, CFormat("Filtered IP %s because filter isn't ready yet.") % Uint32toStringIP(IPTest)); |
| 428 | if (isServer) { |
| 429 | theStats::AddFilteredServer(); |
| 430 | } else { |
| 431 | theStats::AddFilteredClient(); |
| 432 | } |
| 433 | return true; |
| 434 | } |
| 435 | wxMutexLocker lock(m_mutex); |
| 436 | // The IP needs to be in host order |
| 437 | uint32 ip = wxUINT32_SWAP_ALWAYS(IPTest); |
| 438 | int imin = 0; |
| 439 | int imax = m_rangeIPs.size() - 1; |
| 440 | int i; |
| 441 | bool found = false; |
| 442 | while (imin <= imax) { |
| 443 | i = (imin + imax) / 2; |
| 444 | uint32 curIP = m_rangeIPs[i]; |
| 445 | if (curIP <= ip) { |
| 446 | uint32 curLength = m_rangeLengths[i]; |
| 447 | if (curLength >= 0x8000) { |
| 448 | curLength = ((curLength & 0x7fff) << 12) + 0xfff; |
| 449 | } |
| 450 | if (curIP + curLength >= ip) { |
| 451 | found = true; |
| 452 | break; |
| 453 | } |
| 454 | } |
| 455 | if (curIP > ip) { |
| 456 | imax = i - 1; |
| 457 | } else { |
| 458 | imin = i + 1; |
| 459 | } |
| 460 | } |
| 461 | if (found) { |
| 462 | AddDebugLogLineN(logIPFilter, CFormat("Filtered IP %s%s") % Uint32toStringIP(IPTest) |
| 463 | % (i < (int)m_rangeNames.size() ? (" (" + wxString(char2unicode(m_rangeNames[i].c_str())) + ")") |
| 464 | : wxString(""))); |
| 465 | if (isServer) { |
| 466 | theStats::AddFilteredServer(); |
| 467 | } else { |
| 468 | theStats::AddFilteredClient(); |
| 469 | } |
| 470 | return true; |
| 471 | } |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | void CIPFilter::Update(const wxString& strURL) |
no test coverage detected