diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-11 15:17:40 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-11 15:17:40 +0000 |
commit | 69c3a32784b8c638ea10c269c3f63ede86b8aaa0 (patch) | |
tree | ee065fbe0bbeaf3121ff359e2cca3671b426de08 /src/hashcomp.cpp | |
parent | 0b230aa96b81b7a6426e48a509a19699556cf190 (diff) |
Add irc::portparser, a class to parse port ranges in the form "6660,6661,6662-6669,7000".
Needs testing, watch next few commits.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5690 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r-- | src/hashcomp.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 4b3200512..b26fd0841 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -386,3 +386,53 @@ std::string& irc::stringjoiner::GetJoined() return joined; } +irc::portparser::portparser(const std::string &source) : in_range(0), range_begin(0), range_end(0) +{ + sep = new irc::commasepstream(source); +} + +irc::portparser::~portparser() +{ + delete sep; +} + +long irc::portparser::GetToken() +{ + if (in_range > 0) + { + in_range++; + if (in_range <= range_end) + return in_range; + else + in_range = 0; + } + + std::string x = sep->GetToken(); + + if (x == "") + return 0; + + std::string::size_type dash = x.rfind('-'); + if (dash != std::string::npos) + { + std::string sbegin = x.substr(0, dash); + std::string send = x.substr(dash+1, x.length()); + long range_begin = atoi(sbegin.c_str()); + long range_end = atoi(send.c_str()); + + if ((range_begin > 0) && (range_end > 0) && (range_begin < 65536) && (range_end < 65536) && (range_begin < range_end)) + { + in_range = range_begin; + return in_range; + } + else + { + return 0; + } + } + else + { + return atoi(x.c_str()); + } +} + |