diff options
author | Adam <Adam@anope.org> | 2016-11-22 19:44:25 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-11-22 19:44:25 -0500 |
commit | 437a6dbb2997c51c260115e8514c8cd6150cfaf5 (patch) | |
tree | 86db29d7f2c5ac30578c9bc453d19b08fb5d8425 /modules/commands/os_logsearch.cpp | |
parent | d96ca9b8240bcd854995946bdddc46632acc658a (diff) |
os_logsearch: optimize non wildcard searches, allow regex
Diffstat (limited to 'modules/commands/os_logsearch.cpp')
-rw-r--r-- | modules/commands/os_logsearch.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index 37a2f887c..7b23e52d3 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -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(); } |