| 109 | |
| 110 | private: |
| 111 | void Entry() |
| 112 | { |
| 113 | AddLogLineN(_("Loading IP filters 'ipfilter.dat' and 'ipfilter_static.dat'.")); |
| 114 | if ( !LoadFromFile(thePrefs::GetConfigDir() + "ipfilter.dat") && |
| 115 | thePrefs::UseIPFilterSystem() ) { |
| 116 | // Load from system wide IP filter file |
| 117 | wxStandardPathsBase &spb(wxStandardPaths::Get()); |
| 118 | #ifdef __WINDOWS__ |
| 119 | wxString dataDir(spb.GetPluginsDir()); |
| 120 | #elif defined(__WXMAC__) |
| 121 | wxString dataDir(spb.GetDataDir()); |
| 122 | #else |
| 123 | wxString dataDir(spb.GetDataDir().BeforeLast('/') + "/amule"); |
| 124 | #endif |
| 125 | wxString systemwideFile(JoinPaths(dataDir,"ipfilter.dat")); |
| 126 | LoadFromFile(systemwideFile); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | LoadFromFile(thePrefs::GetConfigDir() + "ipfilter_static.dat"); |
| 131 | |
| 132 | uint8 accessLevel = thePrefs::GetIPFilterLevel(); |
| 133 | uint32 size = m_result.size(); |
| 134 | // Reserve a little more so we don't have to resize the vector later. |
| 135 | // (Map ranges can exist that have to be stored in several parts.) |
| 136 | // Extra memory will be freed in the end. |
| 137 | m_rangeIPs.reserve(size + 1000); |
| 138 | m_rangeLengths.reserve(size + 1000); |
| 139 | if (m_storeDescriptions) { |
| 140 | m_rangeNames.reserve(size + 1000); |
| 141 | } |
| 142 | for (IPMap::iterator it = m_result.begin(); it != m_result.end(); ++it) { |
| 143 | if (it->AccessLevel < accessLevel) { |
| 144 | // Calculate range "length" |
| 145 | // (which is included-end - start and thus length - 1) |
| 146 | // Encoding: |
| 147 | // 0 - 0x7fff same |
| 148 | // 0x8000 - 0xffff 0xfff - 0x07ffffff |
| 149 | // that means: remove msb, shift left by 12 bit, add 0xfff |
| 150 | // so it can cover 8 consecutive class A nets |
| 151 | // larger ranges (or theoretical ranges with uneven ends) have to be split |
| 152 | uint32 startIP = it.keyStart(); |
| 153 | uint32 realLength = it.keyEnd() - it.keyStart() + 1; |
| 154 | #ifdef __DEBUG__ |
| 155 | std::string * descp = 0; |
| 156 | #endif |
| 157 | while (realLength) { |
| 158 | m_rangeIPs.push_back(startIP); |
| 159 | uint32 curLength = realLength; |
| 160 | uint16 pushLength; |
| 161 | if (realLength <= 0x8000) { |
| 162 | pushLength = realLength - 1; |
| 163 | } else { |
| 164 | if (curLength >= 0x08000000) { |
| 165 | // range to big, limit |
| 166 | curLength = 0x08000000; |
| 167 | } else { |
| 168 | // cut off LSBs |