1
0
mirror of https://github.com/anope/anope.git synced 2026-07-05 06:53:12 +02:00

os_logsearch: optimize non wildcard searches, allow regex

This commit is contained in:
Adam
2016-11-22 19:44:25 -05:00
parent d96ca9b824
commit 437a6dbb29
+15 -1
View File
@@ -91,6 +91,9 @@ class CommandOSLogSearch : public Command
Log(LOG_ADMIN, source, this) << "for " << search_string;
bool wildcard = search_string.find_first_of("?*") != Anope::string::npos;
bool regex = search_string.empty() == false && search_string[0] == '/' && search_string[search_string.length() - 1] == '/';
const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<const Anope::string>("logname");
std::vector<Anope::string> matches;
for (int d = days - 1; d >= 0; --d)
@@ -102,13 +105,24 @@ class CommandOSLogSearch : public Command
continue;
for (Anope::string buf, token; std::getline(fd, buf.str());)
if (Anope::Match(buf, "*" + search_string + "*"))
{
bool match = false;
if (regex)
match = Anope::Match(buf, search_string, false, true);
else if (wildcard)
match = Anope::Match(buf, "*" + search_string + "*");
else
match = buf.find_first_of_ci(search_string) != Anope::string::npos;
if (match)
{
matches.push_back(buf);
if (matches.size() >= HARDMAX)
break;
}
}
fd.close();
}