diff options
| author | 2020-05-07 23:10:54 +0100 | |
|---|---|---|
| committer | 2020-05-07 23:10:54 +0100 | |
| commit | eb0f385c8dbb1fb7a6c78551ff597303adfc78e0 (patch) | |
| tree | dc13ebda8ee0c8572188ca4a8369f92c5313dab4 /include/modules | |
| parent | Fix not being able to set more than one extban. (diff) | |
Deduplicate extban parsing.
Diffstat (limited to 'include/modules')
| -rw-r--r-- | include/modules/extban.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/modules/extban.h b/include/modules/extban.h index f3024c870..9172c053d 100644 --- a/include/modules/extban.h +++ b/include/modules/extban.h @@ -38,6 +38,14 @@ namespace ExtBan /** The extban matches against a specific pattern (e.g. sslfp). */ MATCHING }; + + /** Parses a ban entry and extracts an extban from it. + * @param banentry The ban entry to parse. + * @param name The parsed name of the extban. + * @param value The parsed value of the extban. + * @return True if an extban was extracted from the ban entry; otherwise, false. + */ + inline bool Parse(const std::string& banentry, std::string& name, std::string& value); } /** Manager for the extban system. */ @@ -252,3 +260,15 @@ class ExtBan::EventListener */ virtual ModResult OnExtBanCheck(User* user, Channel* chan, ExtBan::Base* extban) = 0; }; + +inline bool ExtBan::Parse(const std::string& banentry, std::string& name, std::string& value) +{ + // The mask must be in the format <letter>:<value> or <name>:<value>. + size_t endpos = banentry.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); + if (endpos == std::string::npos || banentry[endpos] != ':') + return false; + + name.assign(banentry, 0, endpos); + value.assign(banentry, endpos + 1); + return true; +} |
