Changeset 1459
- Timestamp:
- 07/12/05 12:16:07 (3 years ago)
- Files:
-
- hydranode/include/hn/ipfilter.h (modified) (3 diffs)
- hydranode/src/ipfilter.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/include/hn/ipfilter.h
r859 r1459 33 33 * filtering ip addresses. 34 34 */ 35 class IpFilterBase {35 class DLLEXPORT IpFilterBase { 36 36 public: 37 37 IpFilterBase(); … … 48 48 }; 49 49 50 class IpFilter : public IpFilterBase {50 class DLLEXPORT IpFilter : public IpFilterBase { 51 51 public: 52 52 IpFilter(); … … 60 60 void parseMldonkeyLine(const std::string &buf); 61 61 void parseMuleLine(const std::string &buf); 62 void parseGuardianLine(const std::string &buf); 63 62 64 ParseFunc getParseFunc(const std::string &buf); 63 65 std::auto_ptr<RangeList<Range<uint32_t> > > m_list; hydranode/src/ipfilter.cpp
r1440 r1459 55 55 56 56 ParseFunc parseFunc = getParseFunc(buf); 57 if (!parseFunc) { 58 throw std::runtime_error("unknown ipfilter format"); 59 } 60 57 61 ifs.seekg(0); 62 m_list->clear(); 58 63 59 64 uint32_t line = 0; … … 88 93 logMsg(fmt % s1 % m_list->size()); 89 94 } 90 IpFilter::ParseFunc IpFilter::getParseFunc(const std::string &buf) try { 91 CHECK_THROW(buf.size() >= 4); 92 boost::lexical_cast<uint32_t>(buf.substr(0, 3)); 93 logDebug("eMule format IPFilter detected."); 94 return boost::bind(&IpFilter::parseMuleLine, this, _b1); 95 } catch (boost::bad_lexical_cast&) { 96 logDebug("MLDonkey format IPFilter detected."); 97 return boost::bind(&IpFilter::parseMldonkeyLine, this, _b1); 95 96 IpFilter::ParseFunc IpFilter::getParseFunc(const std::string &buf) { 97 try { 98 CHECK_THROW(buf.size() >= 4); 99 parseMuleLine(buf); 100 logDebug("eMule format IPFilter detected."); 101 return boost::bind(&IpFilter::parseMuleLine, this, _b1); 102 } catch (...) {} 103 104 try { 105 parseMldonkeyLine(buf); 106 logDebug("MLDonkey format IPFilter detected."); 107 return boost::bind(&IpFilter::parseMldonkeyLine, this, _b1); 108 } catch (...) {} 109 110 try { 111 parseGuardianLine(buf); 112 logDebug("GuardianP2P format IPFilter detected."); 113 return boost::bind(&IpFilter::parseGuardianLine, this, _b1); 114 } catch (...) {} 115 116 return 0; 98 117 } 99 118 … … 135 154 } 136 155 156 void IpFilter::parseGuardianLine(const std::string &buf) { 157 if (buf[0] == '#') { 158 return; 159 } 160 161 size_t i = buf.find_first_of(','); 162 if (i == std::string::npos) { 163 throw ParseError("Expected ',' token."); 164 } 165 if (parse(buf.substr(0, i).c_str(), parse_one >> '-' >> parse_two).full) { 166 m_list->push(one, two); 167 } else { 168 throw ParseError("unknown error"); 169 } 170 } 171 137 172 bool IpFilter::isAllowed(uint32_t ip) { 138 173 return !m_list->contains(SWAP32_ON_LE(ip));
