Add filter option argument checks.

This commit is contained in:
levlam 2020-11-05 17:55:13 +03:00
parent 2dd7ef910f
commit 91db058809

View File

@ -184,14 +184,17 @@ int main(int argc, char *argv[]) {
options.add_option('d', "dir", "server working directory", td::OptionParser::parse_string(working_directory));
options.add_option('t', "temp-dir", "directory for storing HTTP server temporary files",
td::OptionParser::parse_string(temporary_directory));
options.add_checked_option('\0', "filter",
"\"<remainder>/<modulo>\". Allow only bots with 'bot_user_id % modulo == remainder'",
options.add_checked_option(
'\0', "filter", "\"<remainder>/<modulo>\". Allow only bots with 'bot_user_id % modulo == remainder'",
[&](td::Slice rem_mod) {
td::Slice rem;
td::Slice mod;
std::tie(rem, mod) = td::split(rem_mod, '/');
TRY_RESULT(rem_i, td::to_integer_safe<td::uint64>(rem));
TRY_RESULT(mod_i, td::to_integer_safe<td::uint64>(mod));
if (rem_i < 0 || rem_i >= mod_i) {
return td::Status::Error("Wrong argument specified: ensure that 0 <= remainder < modulo");
}
token_range = {rem_i, mod_i};
return td::Status::OK();
});